import {z} from 'zod' export type GetApiCustomersCustomerIdOptions = {baseUrl?: string | undefined, identity?: string | undefined, authorization?: string | undefined, fetch?: typeof fetch | undefined}; export const address = z.object({address_id: z.string().optional(), address_type: z.enum(["MAILING", "PHYSICAL"]), street: z.string(), street2: z.string().optional(), city: z.string().min(2).max(40), state: z.string(), zip_code: z.string(), country: z.string(), is_primary: z.boolean(), date_created: z.string().optional()}); export const customer = z.object({customer_id: z.string().optional(), brand_person_id: z.string().optional(), bond_brand_id: z.string().optional(), business_id: z.string().nullable().optional(), dob: z.string().nullable().optional(), first_name: z.string(), middle_name: z.string().optional(), last_name: z.string().optional(), ssn: z.string().optional(), phone: z.string().optional(), phone_country_code: z.string().optional(), email: z.string().optional(), addresses: z.array(address), date_created: z.string().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 }; /** * Retrieve a customer * * GET /customers/{customer_id} */ export const getApiCustomersCustomerId = async (options?: GetApiCustomersCustomerIdOptions) => { const {baseUrl = "https://sandbox.bond.tech/api/v0", fetch: fetchFn = fetch, identity, authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (identity !== undefined) headers.set("Identity", identity) if (authorization !== undefined) headers.set("Authorization", authorization) const url = `${baseUrl.replace(/\/+$/, '')}/customers/${encodeURIComponent(String(args.customer_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(customer, await res.json()) };