import {z} from 'zod' export type DeleteApiApiV1CustomersCustomerIdAddressesAddressIdArgs = {customerId: number, addressId: number}; export type DeleteApiApiV1CustomersCustomerIdAddressesAddressIdOptions = {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 tempestResponseV1CustomerAddress = 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: v1CustomerAddress.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 }; /** * Delete a Customer Address * * DELETE /api/v1/customers/{customerId}/addresses/{addressId} */ export const deleteApiApiV1CustomersCustomerIdAddressesAddressId = async (args: DeleteApiApiV1CustomersCustomerIdAddressesAddressIdArgs, options?: DeleteApiApiV1CustomersCustomerIdAddressesAddressIdOptions) => { const {baseUrl = "https://api.ekm.net", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() 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: "DELETE", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(tempestResponseV1CustomerAddress, await res.json()) };