import {z} from 'zod' export type GetApiAdminCustomersIdDJsonArgs = {customer_id: number, fields?: string | undefined}; export type GetApiAdminCustomersIdDJsonOptions = {baseUrl?: string | undefined, APPACCESSTOKEN?: string | undefined, fetch?: typeof fetch | undefined}; export const customerAddressDetail = z.object({address1: z.string().optional(), address2: z.string().optional(), city: z.string().optional(), company: z.string().optional(), country: z.string().optional(), country_code: z.string().optional(), country_id: z.number().int().optional(), country_name: z.string().optional(), cpf_number: z.string().optional(), cpf_or_cnpj_number: z.string().optional(), created_at: z.string().optional(), default: z.boolean().optional(), first_name: z.string().optional(), id: z.number().int().optional(), last_name: z.string().optional(), latitude: z.number().optional(), longitude: z.number().optional(), name: z.string().optional(), phone: z.string().optional(), province: z.string().optional(), province_code: z.string().optional(), updated_at: z.string().optional(), zip: z.string().optional()}); export const customerDto = z.object({accepts_marketing: z.boolean().optional(), addresses: z.array(customerAddressDetail).optional(), average_spent: z.number().optional(), created_at: z.string().optional(), currency: z.string().optional(), default_address: customerAddressDetail.optional(), email: z.string().optional(), first_name: z.string().optional(), id: z.number().int().optional(), last_name: z.string().optional(), last_order_at: z.string().optional(), last_order_id: z.number().int().optional(), last_order_name: z.string().optional(), last_sent_abandoned_email_at: z.string().optional(), note: z.string().optional(), orders_count: z.number().int().optional(), phone: z.string().optional(), state: z.string().optional(), tags: z.string().optional(), tax_exempt: z.boolean().optional(), total_spent: z.number().optional(), updated_at: z.string().optional(), verified_email: 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 }; /** * Retrieves a single customer. * * GET /admin/customers/{id:\\d+}.json */ export const getApiAdminCustomersIdDJson = async (args: GetApiAdminCustomersIdDJsonArgs, options?: GetApiAdminCustomersIdDJsonOptions) => { const {baseUrl = "https://shop-name.onshopbase.com", fetch: fetchFn = fetch, APPACCESSTOKEN} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.fields != null) query.append("fields", String(args.fields)) if (APPACCESSTOKEN !== undefined) headers.set("APP_ACCESS_TOKEN", APPACCESSTOKEN) const url = `${baseUrl.replace(/\/+$/, '')}/admin/customers/${encodeURIComponent(String(args['id:\\\\d+']))}.json${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(customerDto, await res.json()) };