import {z} from 'zod' export type CustomerAddressDetail = {address1?: string | undefined, address2?: string | undefined, city?: string | undefined, company?: string | undefined, country?: string | undefined, country_code?: string | undefined, country_id?: number | undefined, country_name?: string | undefined, cpf_number?: string | undefined, cpf_or_cnpj_number?: string | undefined, created_at?: string | undefined, default?: boolean | undefined, first_name?: string | undefined, id?: number | undefined, last_name?: string | undefined, latitude?: number | undefined, longitude?: number | undefined, name?: string | undefined, phone?: string | undefined, province?: string | undefined, province_code?: string | undefined, updated_at?: string | undefined, zip?: string | undefined}; export type CustomerDto = {accepts_marketing?: boolean | undefined, addresses?: Array | undefined, average_spent?: number | undefined, created_at?: string | undefined, currency?: string | undefined, default_address?: CustomerAddressDetail | undefined, email?: string | undefined, first_name?: string | undefined, id?: number | undefined, last_name?: string | undefined, last_order_at?: string | undefined, last_order_id?: number | undefined, last_order_name?: string | undefined, last_sent_abandoned_email_at?: string | undefined, note?: string | undefined, orders_count?: number | undefined, phone?: string | undefined, state?: string | undefined, tags?: string | undefined, tax_exempt?: boolean | undefined, total_spent?: number | undefined, updated_at?: string | undefined, verified_email?: boolean | undefined}; export type UpdateApiAdminCustomersIdDJsonArgs = {body: CustomerDto}; export type UpdateApiAdminCustomersIdDJsonOptions = {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 customerSwaggerResponse = z.object({customer: customerDto.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 }; /** * Updates a customer. * * PUT /admin/customers/{id:\\d+}.json */ export const updateApiAdminCustomersIdDJson = async (args: UpdateApiAdminCustomersIdDJsonArgs, options?: UpdateApiAdminCustomersIdDJsonOptions) => { const {baseUrl = "https://shop-name.onshopbase.com", fetch: fetchFn = fetch, APPACCESSTOKEN} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") 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: "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(customerSwaggerResponse, await res.json()) };