import {z} from 'zod' export type GetApiV2ShopsShopIdentifierCustomersIdArgs = {shop_identifier: string, id: number}; export type GetApiV2ShopsShopIdentifierCustomersIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const customersv2Label = z.object({id: z.number().int().optional(), customer_id: z.number().int().optional(), name: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().nullable().optional(), deleted_at: z.string().nullable().optional()}); export const v2Group = z.object({id: z.number().int().optional(), name: z.string().optional(), description: z.string().optional(), shop_identifier: z.string().optional(), platform_id: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().nullable().optional(), deleted_at: z.string().nullable().optional()}); export const v2Address = z.object({city: z.string().optional(), province: z.string().optional(), province_code: z.string().optional(), country: z.string().optional(), created_at: z.string().optional(), zip: z.string().optional(), address_type: z.string().optional(), platform_customer_id: z.string().optional(), deleted_at: z.string().nullable().optional(), address_use: z.enum(["shipping", "billing"]).optional(), company: z.string().optional(), street_2: z.string().optional(), platform_id: z.string().optional(), shop_identifier: z.string().optional(), platform_type: z.string().optional(), first_name: z.string().optional(), address_source: z.enum(["platform", "bold"]).optional(), last_name: z.string().optional(), updated_at: z.string().optional(), phone: z.string().optional(), is_default: z.boolean().optional(), bold_customer_id: z.number().int().optional(), country_iso2: z.string().optional(), street_1: z.string().optional(), id: z.number().int().optional()}); export const v2Customer = z.object({tags: z.string().optional(), deleted_at: z.string().nullable().optional(), shop_identifier: z.string().optional(), platform_created_at: z.string().optional(), id: z.number().int().optional(), platform_type: z.string().optional(), last_name: z.string().optional(), first_name: z.string().optional(), labels: z.array(customersv2Label).optional(), groups: z.array(v2Group).optional(), updated_at: z.string().nullable().optional(), phone: z.string().optional(), platform_id: z.string().optional(), addresses: z.array(v2Address).optional(), created_at: z.string().optional(), email: z.string().optional(), default_address: v2Address.optional()}); export const v2CustomerByXIDResponse = z.object({customer: v2Customer.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 }; /** * Get Customer by ID * * GET /v2/shops/{shop_identifier}/customers/{id} */ export const getApiV2ShopsShopIdentifierCustomersId = async (args: GetApiV2ShopsShopIdentifierCustomersIdArgs, options?: GetApiV2ShopsShopIdentifierCustomersIdOptions) => { const {baseUrl = "http://customer-api.prod.svc.cluster.local:9000", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v2/shops/${encodeURIComponent(String(args.shop_identifier))}/customers/${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(v2CustomerByXIDResponse, await res.json()) };