import {z} from 'zod' export type UpdateApiApiV1CustomersCustomerIdAddressesAddressIdArgs = {customerId: number, addressId: number, body: Record | null}; export type UpdateApiApiV1CustomersCustomerIdAddressesAddressIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const tempestLink = z.object({rel: z.string().nullable().optional(), href: z.string().nullable().optional()}); export const tempestValidationError = z.object({member_names: z.array(z.string()).nullable().optional(), error_message: z.string().nullable().optional()}); export const v1CustomerAddress = z.object({id: z.number().int().optional(), created_date: z.string().nullable().optional(), modified_date: z.string().nullable().optional(), customer_id: z.number().int().optional(), is_preferred_billing_address: z.boolean().optional(), is_preferred_shipping_address: z.boolean().optional(), first_name: z.string().nullable().optional(), last_name: z.string().nullable().optional(), company: z.string().nullable().optional(), address: z.string(), address2: z.string().nullable().optional(), town: z.string(), county: z.string().nullable().optional(), country: z.string(), friendly_country: z.string().nullable().optional(), post_code: z.string(), telephone: z.string().nullable().optional(), fax: z.string().nullable().optional()}); export const v1Customer = z.object({id: z.number().int().optional(), email_address: z.string().nullable().optional(), first_name: z.string(), last_name: z.string(), order_count: z.number().int().optional(), loyalty_points: z.number().optional(), created_date: z.string().optional(), modified_date: z.string().optional(), last_login_date: z.string().optional(), last_login_attempt_date: z.string().optional(), locked: z.boolean().optional(), locked_date: z.string().nullable().optional(), locked_end_date: z.string().nullable().optional(), is_subscribed_to_newsletter: z.boolean().optional(), addresses: z.array(v1CustomerAddress).nullable().optional()}); export const tempestResponseV1Customer = z.object({meta: z.record(z.string(), z.object({})).nullable().optional(), links: z.array(tempestLink).nullable().optional(), validation_result: z.array(tempestValidationError).nullable().optional(), errors: z.record(z.string(), z.string()).nullable().optional(), data: v1Customer.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 a Customer Address * * PUT /api/v1/customers/{customerId}/addresses/{addressId} */ export const updateApiApiV1CustomersCustomerIdAddressesAddressId = async (args: UpdateApiApiV1CustomersCustomerIdAddressesAddressIdArgs, options?: UpdateApiApiV1CustomersCustomerIdAddressesAddressIdOptions) => { const {baseUrl = "https://api.ekm.net", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/customers/${encodeURIComponent(String(args.customerId))}/addresses/${encodeURIComponent(String(args.addressId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(tempestResponseV1Customer, await res.json()) };