import {z} from 'zod' export type Address = {address1?: (string | null) | undefined, address2?: (string | null) | undefined, address3?: (string | null) | undefined, address4?: (string | null) | undefined, city?: (string | null) | undefined, state?: (string | null) | undefined, postcode?: (string | null) | undefined, countryCode: string, locality?: (string | null) | undefined, county?: (string | null) | undefined}; export type UpdateCustomerRequest = {name?: (string | null) | undefined, billingAddress?: (Address | null) | undefined, shippingAddress?: (Address | null) | undefined, emailAddress?: (string | null) | undefined, phoneNumber?: (string | null) | undefined, vatNumber?: (string | null) | undefined}; export type PatchApiCustomersCustomerIdArgs = {customerId: string | null, version: string | null, body: UpdateCustomerRequest}; export type PatchApiCustomersCustomerIdOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const address = z.object({address1: z.string().max(100).nullable().optional(), address2: z.string().max(100).nullable().optional(), address3: z.string().max(100).nullable().optional(), address4: z.string().max(100).nullable().optional(), city: z.string().max(100).nullable().optional(), state: z.string().max(100).nullable().optional(), postcode: z.string().max(50).nullable().optional(), countryCode: z.string().max(10), locality: z.string().max(100).nullable().optional(), county: z.string().max(100).nullable().optional()}); export const customerFull = z.object({id: z.string().nullable().optional(), name: z.string().nullable().optional(), shippingAddress: address.nullable().optional(), billingAddress: address.nullable().optional(), emailAddress: z.string().nullable().optional(), phoneNumber: z.string().nullable().optional(), vatNumber: z.string().nullable().optional(), createdAt: z.string().nullable().optional(), updatedAt: z.string().nullable().optional(), documentVersion: z.number().int().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 }; /** * Update information about a customer * * PATCH /customers/{customerId} */ export const patchApiCustomersCustomerId = async (args: PatchApiCustomersCustomerIdArgs, options?: PatchApiCustomersCustomerIdOptions) => { const {baseUrl = "https://api.dojo.tech", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.version != null) headers.set("version", String(args.version)) if (ApiKeyAuth !== undefined) headers.set("Authorization", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/customers/${encodeURIComponent(String(args.customerId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(customerFull, await res.json()) };