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 CompanyInfo = {effectiveElectronicAddress?: (string | null) | undefined, electronicAddress?: (string | null) | undefined, siret?: (string | null) | undefined, vatNumber?: (string | null) | undefined}; export type PaymentMethod = 'Transfer' | 'Order' | 'Check' | 'Cash' | 'Card' | 'Bill' | 'Usec' | 'Other'; export type Supplier = {active?: boolean | undefined, address?: AddressFields | undefined, cellPhone?: (string | null) | undefined, companyInformations?: CompanyInfo | undefined, createdAt?: (string | null) | undefined, createdById?: (string | null) | undefined, defaultPaymentMethod?: PaymentMethod | undefined, email?: (string | null) | undefined, firstName?: (string | null) | undefined, id?: number | undefined, internalId?: (string | null) | undefined, internalNotes?: (string | null) | undefined, lastName?: (string | null) | undefined, name?: (string | null) | undefined, number?: (string | null) | undefined, phone?: (string | null) | undefined, title?: (string | null) | undefined, updatedAt?: (string | null) | undefined, updatedById?: (string | null) | undefined}; export type UpdateApiV1SuppliersIdArgs = {id: number, body: Supplier}; export type UpdateApiV1SuppliersIdOptions = {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 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 paymentMethod = z.enum(["Transfer", "Order", "Check", "Cash", "Card", "Bill", "Usec", "Other"]); export const supplier = z.object({active: z.boolean().optional(), address: addressFields.optional(), cellPhone: z.string().nullable().optional(), companyInformations: companyInfo.optional(), createdAt: z.string().nullable().optional(), createdById: z.string().nullable().optional(), defaultPaymentMethod: paymentMethod.optional(), email: z.string().nullable().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(), name: z.string().nullable().optional(), number: z.string().nullable().optional(), phone: z.string().nullable().optional(), title: z.string().nullable().optional(), updatedAt: z.string().nullable().optional(), updatedById: z.string().nullable().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 supplier * * PUT /v1/suppliers/{id} */ export const updateApiV1SuppliersId = async (args: UpdateApiV1SuppliersIdArgs, options?: UpdateApiV1SuppliersIdOptions) => { 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/suppliers/${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(supplier, await res.json()) };