import {z} from 'zod' export type GetApiShopsSHOPIDCustomersCUSTOMERIDArgs = {SHOP_ID: number, CUSTOMER_ID: string}; export type GetApiShopsSHOPIDCustomersCUSTOMERIDOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const customer = z.object({id: z.string().optional(), name: z.string().optional(), gender: z.string().optional(), emails: z.array(z.string()).optional(), phone_numbers: z.array(z.string()).optional(), pages_customers: z.array(z.object({id: z.string().optional(), name: z.string().optional(), platform: z.string().optional()})).optional(), date_of_birth: z.string().optional(), reward_point: z.number().optional(), is_discount_by_level: z.boolean().optional(), tags: z.array(z.string()).optional(), is_block: z.boolean().optional(), assigned_user_id: z.string().optional(), level_id: z.string().optional(), notes: z.array(z.object({id: z.string().optional(), message: z.string().optional(), images: z.array(z.object({url: z.string().optional()})).optional()})).optional(), shop_customer_address: z.array(z.object({id: z.string().optional(), country_code: z.number().int().optional(), province_id: z.string().optional(), district_id: z.string().optional(), commune_id: z.string().optional(), address: z.string().optional(), full_address: z.string().optional(), full_name: z.string().optional(), phone_number: z.string().optional()})).optional(), order_count: z.number().int().optional(), purchased_amount: z.number().int().optional(), succeed_order_count: z.number().int().optional(), last_order_at: z.string().optional(), conversation_link: z.string().optional(), referral_code: z.string().optional(), fb_id: z.string().optional(), customer_id: z.string().optional()}); export const getApiShopsSHOPIDCustomersCUSTOMERIDResponse = z.object({data: customer.optional(), success: z.boolean().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 }; /** * Customer detail * * GET /shops/{SHOP_ID}/customers/{CUSTOMER_ID} */ export const getApiShopsSHOPIDCustomersCUSTOMERID = async (args: GetApiShopsSHOPIDCustomersCUSTOMERIDArgs, options?: GetApiShopsSHOPIDCustomersCUSTOMERIDOptions) => { const {baseUrl = "https://pos.pages.fm/api/v1", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) query.set("api_key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/shops/${encodeURIComponent(String(args.SHOP_ID))}/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(getApiShopsSHOPIDCustomersCUSTOMERIDResponse, await res.json()) };