import {z} from 'zod' export type GetApiCustomersCustomerIdArgs = {customer_id: string}; export type GetApiCustomersCustomerIdOptions = {baseUrl?: string | undefined, publicApiKey?: string | undefined, privateSecretKey?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiCustomersCustomerIdResponse = z.object({id: z.string().optional(), merchant_customer_id: z.string().optional(), first_name: z.string().optional(), last_name: z.string().optional(), gender: z.string().optional(), date_of_birth: z.string().optional(), email: z.string().optional(), nationality: z.string().optional(), country: z.string().optional(), document: z.object({document_type: z.string().optional(), document_number: z.string().optional()}).optional(), phone: z.object({number: z.string().optional(), country_code: z.string().optional()}).optional(), billing_address: z.object({address_line_1: z.string().optional(), address_line_2: z.string().optional(), country: z.string().optional(), state: z.string().optional(), city: z.string().optional(), zip_code: z.string().optional(), neighborhood: z.string().optional()}).optional(), shipping_address: z.object({address_line_1: z.string().optional(), address_line_2: z.string().optional(), country: z.string().optional(), state: z.string().optional(), city: z.string().optional(), zip_code: z.string().optional(), neighborhood: z.string().optional()}).optional(), metadata: z.array(z.object({key: z.string().optional(), value: z.string().optional()})).optional(), created_at: z.string().optional(), updated_at: z.string().optional(), merchant_customer_created_at: 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 Customer * * GET /customers/{customer_id} */ export const getApiCustomersCustomerId = async (args: GetApiCustomersCustomerIdArgs, options?: GetApiCustomersCustomerIdOptions) => { const {baseUrl = "https://api-sandbox.y.uno/v1", fetch: fetchFn = fetch, publicApiKey, privateSecretKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (publicApiKey !== undefined) headers.set("PUBLIC-API-KEY", publicApiKey) if (privateSecretKey !== undefined) headers.set("PRIVATE-SECRET-KEY", privateSecretKey) 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(getApiCustomersCustomerIdResponse, await res.json()) };