import {z} from 'zod' export type SupplierState = 'Active' | 'Archived'; export type TimeUnit = 'Day' | 'Week' | 'Month' | 'Year'; export type PaymentMethod = 'BankTransfer' | 'PhysicalCard' | 'Check' | 'DirectDebit' | 'SingleUseCard'; export type CostCenterReference = {id?: number | undefined, name?: string | undefined, code?: string | undefined, href?: string | undefined}; export type EstablishmentReference = {id?: number | undefined, name?: string | undefined, href?: string | undefined}; export type Supplier = {id?: number | undefined, name?: string | undefined, state?: SupplierState | undefined, territory?: ({id?: number | undefined, name?: string | undefined, href?: string | undefined}) | undefined, territoryId?: string | undefined, legalRegistration?: ({identifier?: (string | null) | undefined, vatNumber?: (string | null) | undefined}) | undefined, contacts?: (Array<{firstName?: (string | null) | undefined, lastName?: (string | null) | undefined, email?: (string | null) | undefined, phone?: (string | null) | undefined}>) | undefined, paymentTerm?: ({value?: number | undefined, unit?: TimeUnit | undefined} | null) | undefined, bankAccount?: ({iban?: (string | null) | undefined, bic?: (string | null) | undefined} | null) | undefined, preferredNature?: ({id?: number | undefined, name?: string | undefined, href?: string | undefined} | null) | undefined, preferredNatureId?: (number | null) | undefined, preferredPaymentMethod?: (PaymentMethod | null) | undefined, preferredCostCenter?: CostCenterReference | undefined, preferredCostCenterId?: (number | null) | undefined, establishments?: Array | undefined, flag?: ('Unflagged' | 'Flagged') | undefined}; export type UpdateApiCleemyProcurementApiSuppliersIdArgs = {body: Supplier}; export type UpdateApiCleemyProcurementApiSuppliersIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const supplierState = z.enum(["Active", "Archived"]); export const timeUnit = z.enum(["Day", "Week", "Month", "Year"]); export const paymentMethod = z.enum(["BankTransfer", "PhysicalCard", "Check", "DirectDebit", "SingleUseCard"]); export const costCenterReference = z.object({id: z.number().int().optional(), name: z.string().optional(), code: z.string().optional(), href: z.string().optional()}); export const establishmentReference = z.object({id: z.number().int().optional(), name: z.string().optional(), href: z.string().optional()}); export const supplier = z.object({id: z.number().int().optional(), name: z.string().optional(), state: supplierState.optional(), territory: z.object({id: z.number().int().optional(), name: z.string().optional(), href: z.string().optional()}).optional(), territoryId: z.string().optional(), legalRegistration: z.object({identifier: z.string().nullable().optional(), vatNumber: z.string().nullable().optional()}).optional(), contacts: z.array(z.object({firstName: z.string().nullable().optional(), lastName: z.string().nullable().optional(), email: z.string().nullable().optional(), phone: z.string().nullable().optional()})).optional(), paymentTerm: z.object({value: z.number().int().optional(), unit: timeUnit.optional()}).nullable().optional(), bankAccount: z.object({iban: z.string().nullable().optional(), bic: z.string().nullable().optional()}).nullable().optional(), preferredNature: z.object({id: z.number().int().optional(), name: z.string().optional(), href: z.string().optional()}).nullable().optional(), preferredNatureId: z.number().int().nullable().optional(), preferredPaymentMethod: paymentMethod.nullable().optional(), preferredCostCenter: costCenterReference.optional(), preferredCostCenterId: z.number().int().nullable().optional(), establishments: z.array(establishmentReference).optional(), flag: z.enum(["Unflagged", "Flagged"]).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 Supplier * * PUT /cleemy-procurement/api/suppliers/{id} */ export const updateApiCleemyProcurementApiSuppliersId = async (args: UpdateApiCleemyProcurementApiSuppliersIdArgs, options?: UpdateApiCleemyProcurementApiSuppliersIdOptions) => { const {baseUrl = "https://example.ilucca.net", 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(/\/+$/, '')}/cleemy-procurement/api/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()) };