import {z} from 'zod' export type CustomersApiInternalModelsCreateCompanyRequest = {GLN?: string | undefined, bankAccountNumber?: string | undefined, bankIban?: string | undefined, bankName?: string | undefined, bankSwiftCode?: string | undefined, businessAreaId?: number | undefined, code?: string | undefined, color?: string | undefined, countryId?: number | undefined, creditLimit?: number | undefined, customerBalanceDisabled?: boolean | undefined, customerGroupId?: number | undefined, customerManagerId?: number | undefined, defaultPaymentDeadLine?: number | undefined, deliveryTypeId?: number | undefined, doNotSell?: boolean | undefined, eInvoiceEmail?: string | undefined, eInvoiceReference?: string | undefined, eInvoicesViaEmailEnabled?: boolean | undefined, ediCode?: string | undefined, ediType?: string | undefined, emailOptOut?: boolean | undefined, employeeId?: number | undefined, facebookName?: string | undefined, factoringContractNumber?: string | undefined, fax?: string | undefined, gender?: string | undefined, homeStoreCustomId?: number | undefined, homeStoreId?: number | undefined, integrationCode?: string | undefined, invoicesViaDocuraEnabled?: boolean | undefined, invoicesViaEmailEnabled?: boolean | undefined, isStarred?: boolean | undefined, loyaltyCardNumber?: string | undefined, mail?: string | undefined, mobile?: string | undefined, name?: string | undefined, notes?: string | undefined, operatorId?: string | undefined, paperMailsEnabled?: boolean | undefined, partialTaxExemption?: boolean | undefined, payerId?: number | undefined, paysViaFactoring?: boolean | undefined, penaltyForOverdue?: number | undefined, peppolId?: string | undefined, phone?: string | undefined, posCouponsDisabled?: boolean | undefined, pricelistId?: number | undefined, pricelistId2?: number | undefined, pricelistId3?: number | undefined, pricelistId4?: number | undefined, pricelistId5?: number | undefined, primaryStoreId?: number | undefined, referenceNumber?: string | undefined, rewardPointsDisabled?: boolean | undefined, salesForCashOnly?: boolean | undefined, secondaryStoreId?: number | undefined, shipGoodsWithWaybills?: boolean | undefined, signUpStoreId?: number | undefined, skype?: string | undefined, taxExempt?: boolean | undefined, taxofficeId?: number | undefined, twitterId?: string | undefined, type?: string | undefined, typeId?: number | undefined, vatNumber?: string | undefined, webShopPassword?: string | undefined, webShopUsername?: string | undefined, website?: string | undefined}; export type CustomersApiInternalServicesCustomersBulkCreateCompanyRequest = {requests?: Array | undefined}; export type CreateApiV1CustomersBusinessesBulkArgs = {body: CustomersApiInternalServicesCustomersBulkCreateCompanyRequest}; export type CreateApiV1CustomersBusinessesBulkOptions = {baseUrl: string, sk?: string | undefined, fetch?: typeof fetch | undefined}; export const customersApiInternalServicesCustomersBulkResult = z.object({message: z.string().optional(), resourceID: z.number().int().optional(), resultID: z.number().int().optional()}); export const customersApiInternalServicesCustomersBulkResponseWithResults = z.object({results: z.array(customersApiInternalServicesCustomersBulkResult).optional()}); 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 }; /** * Create business customers in bulk * * POST /v1/customers/businesses/bulk * * Also accepts auth: cc, jwt */ export const createApiV1CustomersBusinessesBulk = async (args: CreateApiV1CustomersBusinessesBulkArgs, options: CreateApiV1CustomersBusinessesBulkOptions) => { const {baseUrl, fetch: fetchFn = fetch, sk} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (sk !== undefined) headers.set("sessionKey", sk) const url = `${baseUrl.replace(/\/+$/, '')}/v1/customers/businesses/bulk${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(customersApiInternalServicesCustomersBulkResponseWithResults, await res.json()) };