import {z} from 'zod' export type GetApiV1CustomersBusinessesArgs = {match?: string | undefined, ids?: Array | undefined, typeIds?: Array | undefined, customerGroupIds?: Array | undefined, businessAreaIds?: Array | undefined, changed?: number | undefined, customerManagerIds?: Array | undefined, eInvoiceEmail?: string | undefined, eInvoicesViaEmailEnabled?: boolean | undefined, eInvoiceReference?: string | undefined, invoicesViaEmailEnabled?: boolean | undefined, invoicesViaDocuraEnabled?: boolean | undefined, paperMailsEnabled?: boolean | undefined, operatorId?: string | undefined, ediCode?: string | undefined, ediType?: ('2DOC' | '4DOC' | 'SPECIAL') | undefined, name?: string | undefined, displayedName?: string | undefined, fullName?: string | undefined, code?: string | undefined, vatNumber?: string | undefined, bankName?: string | undefined, bankAccountNumber?: string | undefined, bankSwiftCode?: string | undefined, bankIban?: string | undefined, phone?: string | undefined, mobile?: string | undefined, fax?: string | undefined, mail?: string | undefined, skype?: string | undefined, website?: string | undefined, notes?: string | undefined, webShopUsername?: string | undefined, salesForCashOnly?: boolean | undefined, creditLimit?: number | undefined, defaultPaymentDeadLine?: number | undefined, penaltyForOverdue?: number | undefined, payerIds?: Array | undefined, countryIds?: Array | undefined, referenceNumber?: string | undefined, integrationCode?: string | undefined, loyaltyCardNumber?: string | undefined, factoringContractNumber?: string | undefined, type?: ('DOMESTIC' | 'EU' | 'OUTSIDE_EU' | 'EU_WITH_VAT') | undefined, priceListIds?: Array | undefined, priceListIds2?: Array | undefined, priceListIds3?: Array | undefined, priceListIds4?: Array | undefined, priceListIds5?: Array | undefined, partialTaxExemption?: boolean | undefined, doNotSell?: boolean | undefined, taxOfficeIds?: Array | undefined, homeStoreCustomIds?: Array | undefined, color?: string | undefined, isStarred?: boolean | undefined, orderBy?: string | undefined, orderByDirection?: ('ASC' | 'DESC') | undefined, skip?: number | undefined, take?: number | undefined, withTotalCount?: boolean | undefined}; export type GetApiV1CustomersBusinessesOptions = {baseUrl: string, sk?: string | undefined, fetch?: typeof fetch | undefined}; export const customersApiInternalModelsBusinessCustomerResponse = z.object({GLN: z.string().optional(), added: z.number().int().optional(), bankAccountNumber: z.string().optional(), bankIban: z.string().optional(), bankName: z.string().optional(), bankSwiftCode: z.string().optional(), businessAreaId: z.number().int().optional(), changed: z.number().int().optional(), changedBy: z.string().optional(), changedByEmployeeId: z.number().int().optional(), code: z.string().optional(), color: z.string().optional(), countryId: z.number().int().optional(), creditLimit: z.number().int().optional(), customerBalanceDisabled: z.boolean().optional(), customerGroupId: z.number().int().optional(), customerManagerId: z.number().int().optional(), defaultPaymentDeadLine: z.number().int().optional(), deliveryTypeId: z.number().int().optional(), displayedName: z.string().optional(), doNotSell: z.boolean().optional(), eInvoiceEmail: z.string().optional(), eInvoiceReference: z.string().optional(), eInvoicesViaEmailEnabled: z.boolean().optional(), ediCode: z.string().optional(), ediType: z.string().optional(), emailOptOut: z.boolean().optional(), facebookName: z.string().optional(), factoringContractNumber: z.string().optional(), fax: z.string().optional(), fullName: z.string().optional(), gender: z.string().optional(), homeStoreCustomId: z.number().int().optional(), homeStoreId: z.number().int().optional(), id: z.number().int().optional(), integrationCode: z.string().optional(), invoicesViaDocuraEnabled: z.boolean().optional(), invoicesViaEmailEnabled: z.boolean().optional(), isStarred: z.boolean().optional(), loyaltyCardNumber: z.string().optional(), mail: z.string().optional(), mobile: z.string().optional(), name: z.string().optional(), notes: z.string().optional(), operatorId: z.string().optional(), paperMailsEnabled: z.boolean().optional(), partialTaxExemption: z.boolean().optional(), payerId: z.number().int().optional(), paysViaFactoring: z.boolean().optional(), penaltyForOverdue: z.number().optional(), peppolId: z.string().optional(), phone: z.string().optional(), posCouponsDisabled: z.boolean().optional(), pricelistId: z.number().int().optional(), pricelistId2: z.number().int().optional(), pricelistId3: z.number().int().optional(), pricelistId4: z.number().int().optional(), pricelistId5: z.number().int().optional(), primaryStoreId: z.number().int().optional(), referenceNumber: z.string().optional(), rewardPointsDisabled: z.boolean().optional(), salesForCashOnly: z.boolean().optional(), secondaryStoreId: z.number().int().optional(), shipGoodsWithWaybills: z.boolean().optional(), signUpStoreId: z.number().int().optional(), skype: z.string().optional(), taxExempt: z.boolean().optional(), taxofficeId: z.number().int().optional(), twitterId: z.string().optional(), type: z.string().optional(), typeId: z.number().int().optional(), vatNumber: z.string().optional(), webShopUsername: z.string().optional(), website: z.string().optional()}); export const getApiV1CustomersBusinessesResponse = z.array(customersApiInternalModelsBusinessCustomerResponse); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Get business customers * * GET /v1/customers/businesses * * Also accepts auth: cc, jwt */ export const getApiV1CustomersBusinesses = async (args: GetApiV1CustomersBusinessesArgs, options: GetApiV1CustomersBusinessesOptions) => { const {baseUrl, fetch: fetchFn = fetch, sk} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.match != null) query.append("match", String(args.match)) for (const item of args.ids ?? []) query.append("ids", String(item)) for (const item of args.typeIds ?? []) query.append("typeIds", String(item)) for (const item of args.customerGroupIds ?? []) query.append("customerGroupIds", String(item)) for (const item of args.businessAreaIds ?? []) query.append("businessAreaIds", String(item)) if (args.changed != null) query.append("changed", String(args.changed)) for (const item of args.customerManagerIds ?? []) query.append("customerManagerIds", String(item)) if (args.eInvoiceEmail != null) query.append("eInvoiceEmail", String(args.eInvoiceEmail)) if (args.eInvoicesViaEmailEnabled != null) query.append("eInvoicesViaEmailEnabled", String(args.eInvoicesViaEmailEnabled)) if (args.eInvoiceReference != null) query.append("eInvoiceReference", String(args.eInvoiceReference)) if (args.invoicesViaEmailEnabled != null) query.append("invoicesViaEmailEnabled", String(args.invoicesViaEmailEnabled)) if (args.invoicesViaDocuraEnabled != null) query.append("invoicesViaDocuraEnabled", String(args.invoicesViaDocuraEnabled)) if (args.paperMailsEnabled != null) query.append("paperMailsEnabled", String(args.paperMailsEnabled)) if (args.operatorId != null) query.append("operatorId", String(args.operatorId)) if (args.ediCode != null) query.append("ediCode", String(args.ediCode)) if (args.ediType != null) query.append("ediType", String(args.ediType)) if (args.name != null) query.append("name", String(args.name)) if (args.displayedName != null) query.append("displayedName", String(args.displayedName)) if (args.fullName != null) query.append("fullName", String(args.fullName)) if (args.code != null) query.append("code", String(args.code)) if (args.vatNumber != null) query.append("vatNumber", String(args.vatNumber)) if (args.bankName != null) query.append("bankName", String(args.bankName)) if (args.bankAccountNumber != null) query.append("bankAccountNumber", String(args.bankAccountNumber)) if (args.bankSwiftCode != null) query.append("bankSwiftCode", String(args.bankSwiftCode)) if (args.bankIban != null) query.append("bankIban", String(args.bankIban)) if (args.phone != null) query.append("phone", String(args.phone)) if (args.mobile != null) query.append("mobile", String(args.mobile)) if (args.fax != null) query.append("fax", String(args.fax)) if (args.mail != null) query.append("mail", String(args.mail)) if (args.skype != null) query.append("skype", String(args.skype)) if (args.website != null) query.append("website", String(args.website)) if (args.notes != null) query.append("notes", String(args.notes)) if (args.webShopUsername != null) query.append("webShopUsername", String(args.webShopUsername)) if (args.salesForCashOnly != null) query.append("salesForCashOnly", String(args.salesForCashOnly)) if (args.creditLimit != null) query.append("creditLimit", String(args.creditLimit)) if (args.defaultPaymentDeadLine != null) query.append("defaultPaymentDeadLine", String(args.defaultPaymentDeadLine)) if (args.penaltyForOverdue != null) query.append("penaltyForOverdue", String(args.penaltyForOverdue)) for (const item of args.payerIds ?? []) query.append("payerIds", String(item)) for (const item of args.countryIds ?? []) query.append("countryIds", String(item)) if (args.referenceNumber != null) query.append("referenceNumber", String(args.referenceNumber)) if (args.integrationCode != null) query.append("integrationCode", String(args.integrationCode)) if (args.loyaltyCardNumber != null) query.append("loyaltyCardNumber", String(args.loyaltyCardNumber)) if (args.factoringContractNumber != null) query.append("factoringContractNumber", String(args.factoringContractNumber)) if (args.type != null) query.append("type", String(args.type)) for (const item of args.priceListIds ?? []) query.append("priceListIds", String(item)) for (const item of args.priceListIds2 ?? []) query.append("priceListIds2", String(item)) for (const item of args.priceListIds3 ?? []) query.append("priceListIds3", String(item)) for (const item of args.priceListIds4 ?? []) query.append("priceListIds4", String(item)) for (const item of args.priceListIds5 ?? []) query.append("priceListIds5", String(item)) if (args.partialTaxExemption != null) query.append("partialTaxExemption", String(args.partialTaxExemption)) if (args.doNotSell != null) query.append("doNotSell", String(args.doNotSell)) for (const item of args.taxOfficeIds ?? []) query.append("taxOfficeIds", String(item)) for (const item of args.homeStoreCustomIds ?? []) query.append("homeStoreCustomIds", String(item)) if (args.color != null) query.append("color", String(args.color)) if (args.isStarred != null) query.append("isStarred", String(args.isStarred)) if (args.orderBy != null) query.append("orderBy", String(args.orderBy)) if (args.orderByDirection != null) query.append("orderByDirection", String(args.orderByDirection)) if (args.skip != null) query.append("skip", String(args.skip)) if (args.take != null) query.append("take", String(args.take)) if (args.withTotalCount != null) query.append("withTotalCount", String(args.withTotalCount)) if (sk !== undefined) headers.set("sessionKey", sk) const url = `${baseUrl.replace(/\/+$/, '')}/v1/customers/businesses${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiV1CustomersBusinessesResponse, await res.json()) };