import {z} from 'zod' export type GetApiApiV2CustomersCustomerIdAddressesIdArgs = {customerId: string, id: 'masterdata' | 'billingaddress' | string}; export type GetApiApiV2CustomersCustomerIdAddressesIdOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV2CustomersCustomerIdAddressesIdResponse = z.object({data: z.object({id: z.string(), type: z.enum(["masterdata", "billingaddress", "deliveryaddress"]), name: z.string().nullable(), street: z.string().nullable(), addressSupplement: z.string().nullable(), zip: z.string().nullable(), city: z.string().nullable(), country: z.string().nullable(), state: z.string().nullable(), department: z.string().nullable(), subDepartment: z.string().nullable(), contactDetails: z.object({phone: z.string().nullable().optional(), email: z.string().nullable().optional(), gln: z.string().nullable().optional()}), deliveryDetails: z.object({defaultDeliveryAddress: z.boolean().optional(), termsOfDelivery: z.string().nullable().optional(), vatId: z.string().nullable().optional(), taxType: z.enum(["domestic", "eu-delivery", "export", "free"]).nullable().optional(), internalComment: z.string().nullable().optional(), note: z.string().nullable().optional()}).nullable().optional()}), links: z.object({self: z.string().optional(), customer: z.string().optional()}).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 }; /** * View address * * GET /api/v2/customers/{customerId}/addresses/{id} */ export const getApiApiV2CustomersCustomerIdAddressesId = async (args: GetApiApiV2CustomersCustomerIdAddressesIdArgs, options?: GetApiApiV2CustomersCustomerIdAddressesIdOptions) => { const {baseUrl = "https://xentral.xentral.biz", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/customers/${encodeURIComponent(String(args.customerId))}/addresses/${encodeURIComponent(String(args.id))}${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(getApiApiV2CustomersCustomerIdAddressesIdResponse, await res.json()) };