import {z} from 'zod' export type Customer = {id?: string | undefined, name?: string | undefined, gender?: string | undefined, emails?: Array | undefined, phone_numbers?: Array | undefined, pages_customers?: (Array<{id?: string | undefined, name?: string | undefined, platform?: string | undefined}>) | undefined, date_of_birth?: string | undefined, reward_point?: number | undefined, is_discount_by_level?: boolean | undefined, tags?: Array | undefined, is_block?: boolean | undefined, assigned_user_id?: string | undefined, level_id?: string | undefined, notes?: (Array<{id?: string | undefined, message?: string | undefined, images?: (Array<{url?: string | undefined}>) | undefined}>) | undefined, shop_customer_address?: (Array<{id?: string | undefined, country_code?: number | undefined, province_id?: string | undefined, district_id?: string | undefined, commune_id?: string | undefined, address?: string | undefined, full_address?: string | undefined, full_name?: string | undefined, phone_number?: string | undefined}>) | undefined, order_count?: number | undefined, purchased_amount?: number | undefined, succeed_order_count?: number | undefined, last_order_at?: string | undefined, conversation_link?: string | undefined, referral_code?: string | undefined, fb_id?: string | undefined, customer_id?: string | undefined}; export type UpdateApiShopsSHOPIDCustomersCUSTOMERIDArgs = {SHOP_ID: number, CUSTOMER_ID: string, body: {customer: Customer}}; export type UpdateApiShopsSHOPIDCustomersCUSTOMERIDOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiShopsSHOPIDCustomersCUSTOMERIDResponse = z.object({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 }; /** * Update customer * * PUT /shops/{SHOP_ID}/customers/{CUSTOMER_ID} */ export const updateApiShopsSHOPIDCustomersCUSTOMERID = async (args: UpdateApiShopsSHOPIDCustomersCUSTOMERIDArgs, options?: UpdateApiShopsSHOPIDCustomersCUSTOMERIDOptions) => { const {baseUrl = "https://pos.pages.fm/api/v1", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") 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: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(updateApiShopsSHOPIDCustomersCUSTOMERIDResponse, await res.json()) };