import {z} from 'zod' export type AddressDetailDto = {line1?: string | undefined, line2?: string | undefined, city?: string | undefined, state?: string | undefined, postalCode?: string | undefined, country?: string | undefined}; export type FullAddressDetailDto = {name?: string | undefined, email?: string | undefined, phone?: string | undefined, organizationName?: string | undefined, address?: AddressDetailDto | undefined}; export type EntityVisibility = string; export type CreateTaxIdDto = {name?: string | undefined, value?: string | undefined, country?: string | undefined}; export type CreateTaxIdsDto = {object?: string | undefined, data?: Array | undefined}; export type UpdateCustomerDto = {name?: string | undefined, phone?: string | undefined, organizationName?: string | undefined, address?: AddressDetailDto | undefined, shipping?: FullAddressDetailDto | undefined, visibility?: EntityVisibility | undefined, metadata?: Record | undefined, email: string, taxIds?: CreateTaxIdsDto | undefined}; export type UpdateApiApiV1CustomersIdArgs = {id: string, body: UpdateCustomerDto}; export type UpdateApiApiV1CustomersIdOptions = {baseUrl?: string | undefined, bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const addressDetailDto = z.object({line1: z.string().optional(), line2: z.string().optional(), city: z.string().optional(), state: z.string().optional(), postalCode: z.string().optional(), country: z.string().optional()}); export const fullAddressDetailDto = z.object({name: z.string().optional(), email: z.string().optional(), phone: z.string().optional(), organizationName: z.string().optional(), address: addressDetailDto.optional()}); export const taxIdDto = z.object({id: z.string(), createdAt: z.string().optional(), updatedAt: z.string().optional(), name: z.string().optional(), value: z.string().optional(), country: z.string().optional(), customerId: z.string()}); export const taxIdsDto = z.object({object: z.string().optional(), data: z.array(taxIdDto).optional()}); export const entityVisibility = z.string(); export const customerDto = z.object({name: z.string().optional(), email: z.string().optional(), phone: z.string().optional(), organizationName: z.string().optional(), address: addressDetailDto.optional(), id: z.string(), createdAt: z.string().optional(), updatedAt: z.string().optional(), customerReferenceId: z.string().optional(), shipping: fullAddressDetailDto.optional(), taxIds: taxIdsDto.optional(), visibility: entityVisibility.optional(), metadata: z.object({}).optional(), customerNumber: z.string()}); 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 a customer * * PUT /api/v1/customers/{id} */ export const updateApiApiV1CustomersId = async (args: UpdateApiApiV1CustomersIdArgs, options?: UpdateApiApiV1CustomersIdOptions) => { const {baseUrl = "https://api.copperx.dev", fetch: fetchFn = fetch, bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearer !== undefined) headers.set('authorization', `Bearer ${bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/customers/${encodeURIComponent(String(args.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(customerDto, await res.json()) };