import {z} from 'zod' export type AddressFields = {city?: (string | null) | undefined, countryIso?: (string | null) | undefined, countryName?: (string | null) | undefined, formattedAddress?: (string | null) | undefined, inlineAddress?: (string | null) | undefined, street?: (string | null) | undefined, zipcode?: (string | null) | undefined}; export type DiscountType = 'Percent' | 'Fixed'; export type Discount = {type?: DiscountType | undefined, value?: number | undefined}; export type CommitmentStatus = 'Unpaid' | 'Paid' | 'PartiallyPaid' | 'Balanced'; export type PaymentMethod = 'Transfer' | 'Order' | 'Check' | 'Cash' | 'Card' | 'Bill' | 'Usec' | 'Other'; export type BillingOptions = {allowed?: (boolean | null) | undefined, bankAccountId?: (number | null) | undefined, buyerReference?: (string | null) | undefined, colleagueId?: (number | null) | undefined, discount?: Discount | undefined, initialCommitmentAmount?: (number | null) | undefined, initialCommitmentDate?: (string | null) | undefined, initialCommitmentStatus?: CommitmentStatus | undefined, liableToVat?: (boolean | null) | undefined, paymentMethod?: PaymentMethod | undefined, sendDocumentAsAttachment?: (boolean | null) | undefined, settlementTermId?: (number | null) | undefined, useTaxIncludedPrices?: (boolean | null) | undefined, vatReverseCharge?: (boolean | null) | undefined, vendorReference?: (string | null) | undefined}; export type CompanyInfo = {effectiveElectronicAddress?: (string | null) | undefined, electronicAddress?: (string | null) | undefined, siret?: (string | null) | undefined, vatNumber?: (string | null) | undefined}; export type CustomerFamily = {id?: number | undefined, internalId?: (string | null) | undefined, label?: (string | null) | undefined, number?: (string | null) | undefined}; export type CustomerType = 'Business' | 'Consumer' | 'Government'; export type Customer = {active?: boolean | undefined, billingAddress?: AddressFields | undefined, billingOptions?: BillingOptions | undefined, cellPhone?: (string | null) | undefined, companyInformations?: CompanyInfo | undefined, companyName?: (string | null) | undefined, email?: (string | null) | undefined, family?: CustomerFamily | undefined, firstName?: (string | null) | undefined, id?: number | undefined, internalId?: (string | null) | undefined, internalNotes?: (string | null) | undefined, lastName?: (string | null) | undefined, metadata?: ({[key: string]: string | null} | null) | undefined, name?: (string | null) | undefined, number?: (string | null) | undefined, phone?: (string | null) | undefined, shippingAddress?: AddressFields | undefined, title?: (string | null) | undefined, type?: CustomerType | undefined}; export type UpdateApiV1CustomersIdArgs = {id: number, body: Customer}; export type UpdateApiV1CustomersIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const addressFields = z.object({city: z.string().nullable().optional(), countryIso: z.string().nullable().optional(), countryName: z.string().nullable().optional(), formattedAddress: z.string().nullable().optional(), inlineAddress: z.string().nullable().optional(), street: z.string().nullable().optional(), zipcode: z.string().nullable().optional()}); export const discountType = z.enum(["Percent", "Fixed"]); export const discount = z.object({type: discountType.optional(), value: z.number().optional()}); export const commitmentStatus = z.enum(["Unpaid", "Paid", "PartiallyPaid", "Balanced"]); export const paymentMethod = z.enum(["Transfer", "Order", "Check", "Cash", "Card", "Bill", "Usec", "Other"]); export const billingOptions = z.object({allowed: z.boolean().nullable().optional(), bankAccountId: z.number().int().nullable().optional(), buyerReference: z.string().nullable().optional(), colleagueId: z.number().int().nullable().optional(), discount: discount.optional(), initialCommitmentAmount: z.number().nullable().optional(), initialCommitmentDate: z.string().nullable().optional(), initialCommitmentStatus: commitmentStatus.optional(), liableToVat: z.boolean().nullable().optional(), paymentMethod: paymentMethod.optional(), sendDocumentAsAttachment: z.boolean().nullable().optional(), settlementTermId: z.number().int().nullable().optional(), useTaxIncludedPrices: z.boolean().nullable().optional(), vatReverseCharge: z.boolean().nullable().optional(), vendorReference: z.string().nullable().optional()}); export const companyInfo = z.object({effectiveElectronicAddress: z.string().nullable().optional(), electronicAddress: z.string().nullable().optional(), siret: z.string().nullable().optional(), vatNumber: z.string().nullable().optional()}); export const customerFamily = z.object({id: z.number().int().optional(), internalId: z.string().nullable().optional(), label: z.string().nullable().optional(), number: z.string().nullable().optional()}); export const customerType = z.enum(["Business", "Consumer", "Government"]); export const customer = z.object({active: z.boolean().optional(), billingAddress: addressFields.optional(), billingOptions: billingOptions.optional(), cellPhone: z.string().nullable().optional(), companyInformations: companyInfo.optional(), companyName: z.string().nullable().optional(), email: z.string().nullable().optional(), family: customerFamily.optional(), firstName: z.string().nullable().optional(), id: z.number().int().optional(), internalId: z.string().nullable().optional(), internalNotes: z.string().nullable().optional(), lastName: z.string().nullable().optional(), metadata: z.record(z.string(), z.string().nullable()).nullable().optional(), name: z.string().nullable().optional(), number: z.string().nullable().optional(), phone: z.string().nullable().optional(), shippingAddress: addressFields.optional(), title: z.string().nullable().optional(), type: customerType.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 a customer * * PUT /v1/customers/{id} */ export const updateApiV1CustomersId = async (args: UpdateApiV1CustomersIdArgs, options?: UpdateApiV1CustomersIdOptions) => { const {baseUrl = "https://api.altoviz.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/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(customer, await res.json()) };