import {z} from 'zod' export type PurchaseReference = {id?: number | undefined, href?: string | undefined, name?: string | undefined, type?: ('Subscription' | 'OneTime') | undefined}; export type Currency = 'Invalid' | 'ALL' | 'DZD' | 'ARS' | 'AUD' | 'BSD' | 'BHD' | 'BDT' | 'AMD' | 'BBD' | 'BMD' | 'BTN' | 'BOB' | 'BWP' | 'BZD' | 'SBD' | 'BND' | 'MMK' | 'BIF' | 'KHR' | 'CAD' | 'CVE' | 'KYD' | 'LKR' | 'CLP' | 'CNY' | 'COP' | 'KMF' | 'CRC' | 'HRK' | 'CUP' | 'CZK' | 'DKK' | 'DOP' | 'SVC' | 'ETB' | 'ERN' | 'FKP' | 'FJD' | 'DJF' | 'GMD' | 'GIP' | 'GTQ' | 'GNF' | 'GYD' | 'HTG' | 'HNL' | 'HKD' | 'HUF' | 'ISK' | 'INR' | 'IDR' | 'IRR' | 'IQD' | 'ILS' | 'JMD' | 'JPY' | 'KZT' | 'JOD' | 'KES' | 'KPW' | 'KRW' | 'KWD' | 'KGS' | 'LAK' | 'LBP' | 'LSL' | 'LVL' | 'LRD' | 'LYD' | 'LTL' | 'MOP' | 'MWK' | 'MYR' | 'MVR' | 'MRO' | 'MUR' | 'MXN' | 'MNT' | 'MDL' | 'MAD' | 'OMR' | 'NAD' | 'NPR' | 'ANG' | 'AWG' | 'VUV' | 'NZD' | 'NIO' | 'NGN' | 'NOK' | 'PKR' | 'PAB' | 'PGK' | 'PYG' | 'PEN' | 'PHP' | 'QAR' | 'RUB' | 'RWF' | 'SHP' | 'STD' | 'SAR' | 'SCR' | 'SLL' | 'SGD' | 'VND' | 'SOS' | 'ZAR' | 'SSP' | 'SZL' | 'SEK' | 'CHF' | 'SYP' | 'THB' | 'TOP' | 'TTD' | 'AED' | 'TND' | 'UGX' | 'MKD' | 'EGP' | 'GBP' | 'TZS' | 'USD' | 'UYU' | 'UZS' | 'WST' | 'YER' | 'ZMK' | 'TWD' | 'UYW' | 'VES' | 'MRU' | 'STN' | 'CUC' | 'ZWL' | 'BYN' | 'TMT' | 'GHS' | 'VEF' | 'SDG' | 'UYI' | 'RSD' | 'MZN' | 'AZN' | 'RON' | 'CHE' | 'CHW' | 'TRY' | 'XAF' | 'XCD' | 'XOF' | 'XPF' | 'XBA' | 'XBB' | 'XBC' | 'XBD' | 'XAU' | 'XDR' | 'XAG' | 'XPT' | 'XTS' | 'XPD' | 'XUA' | 'ZMW' | 'SRD' | 'MGA' | 'COU' | 'AFN' | 'TJS' | 'AOA' | 'BYR' | 'BGN' | 'CDF' | 'BAM' | 'EUR' | 'MXV' | 'UAH' | 'GEL' | 'BOV' | 'PLN' | 'BRL' | 'CLF' | 'XSU' | 'USN' | 'XXX'; export type Amount = {value?: number | undefined, currency?: Currency | undefined}; export type TaxedAmount = {excludingTaxes?: Amount | undefined, taxes?: (Array<{rateTypeId?: number | undefined, value?: number | undefined, currency?: Currency | undefined}>) | undefined, includingTaxes?: Amount | undefined}; export type PaymentMethod = 'BankTransfer' | 'PhysicalCard' | 'Check' | 'DirectDebit' | 'SingleUseCard'; export type InboxDocumentEdition = {document?: ({ownerId?: number | undefined, type?: ('Invoice' | 'CreditNote') | undefined, context?: ({purchase?: PurchaseReference | undefined} | null) | undefined, documentDate?: (string | null) | undefined, documentNumber?: (string | null) | undefined, amountIncludingTaxes?: TaxedAmount | undefined, accountingLabel?: (string | null) | undefined, comment?: (string | null) | undefined, intraCommunityTaxes?: boolean | undefined, dueDate?: (string | null) | undefined, paymentDetails?: ({paymentMethod?: PaymentMethod | undefined, bankAccount?: ({iban?: (string | null) | undefined, bic?: (string | null) | undefined} | null) | undefined} | null) | undefined}) | undefined, action?: ({type?: 'AttachPurchase' | undefined, purchaseId?: number | undefined, paymentId?: (number | null) | undefined, installmentId?: (number | null) | undefined, disputeId?: (number | null) | undefined, autoConfirmation?: boolean | undefined} | {type?: 'CreatePurchase' | undefined, title?: (string | null) | undefined, ownerId?: number | undefined, establishmentId?: (number | null) | undefined, departmentId?: (number | null) | undefined, natureId?: (number | null) | undefined, costCenterId?: (number | null) | undefined, paymentId?: (number | null) | undefined, autoConfirmation?: boolean | undefined} | null) | undefined}; export type UpdateApiCleemyProcurementServicesInboxDocumentsIdArgs = {body: InboxDocumentEdition}; export type UpdateApiCleemyProcurementServicesInboxDocumentsIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const purchaseReference = z.object({id: z.number().int().optional(), href: z.string().optional(), name: z.string().optional(), type: z.enum(["Subscription", "OneTime"]).optional()}); export const documentBreakdownReference = z.object({id: z.number().int().gte(1).optional(), href: z.string().optional(), name: z.string().optional()}); export const currency = z.enum(["Invalid", "ALL", "DZD", "ARS", "AUD", "BSD", "BHD", "BDT", "AMD", "BBD", "BMD", "BTN", "BOB", "BWP", "BZD", "SBD", "BND", "MMK", "BIF", "KHR", "CAD", "CVE", "KYD", "LKR", "CLP", "CNY", "COP", "KMF", "CRC", "HRK", "CUP", "CZK", "DKK", "DOP", "SVC", "ETB", "ERN", "FKP", "FJD", "DJF", "GMD", "GIP", "GTQ", "GNF", "GYD", "HTG", "HNL", "HKD", "HUF", "ISK", "INR", "IDR", "IRR", "IQD", "ILS", "JMD", "JPY", "KZT", "JOD", "KES", "KPW", "KRW", "KWD", "KGS", "LAK", "LBP", "LSL", "LVL", "LRD", "LYD", "LTL", "MOP", "MWK", "MYR", "MVR", "MRO", "MUR", "MXN", "MNT", "MDL", "MAD", "OMR", "NAD", "NPR", "ANG", "AWG", "VUV", "NZD", "NIO", "NGN", "NOK", "PKR", "PAB", "PGK", "PYG", "PEN", "PHP", "QAR", "RUB", "RWF", "SHP", "STD", "SAR", "SCR", "SLL", "SGD", "VND", "SOS", "ZAR", "SSP", "SZL", "SEK", "CHF", "SYP", "THB", "TOP", "TTD", "AED", "TND", "UGX", "MKD", "EGP", "GBP", "TZS", "USD", "UYU", "UZS", "WST", "YER", "ZMK", "TWD", "UYW", "VES", "MRU", "STN", "CUC", "ZWL", "BYN", "TMT", "GHS", "VEF", "SDG", "UYI", "RSD", "MZN", "AZN", "RON", "CHE", "CHW", "TRY", "XAF", "XCD", "XOF", "XPF", "XBA", "XBB", "XBC", "XBD", "XAU", "XDR", "XAG", "XPT", "XTS", "XPD", "XUA", "ZMW", "SRD", "MGA", "COU", "AFN", "TJS", "AOA", "BYR", "BGN", "CDF", "BAM", "EUR", "MXV", "UAH", "GEL", "BOV", "PLN", "BRL", "CLF", "XSU", "USN", "XXX"]).min(3); export const amount = z.object({value: z.number().optional(), currency: currency.optional()}); export const taxedAmount = z.object({excludingTaxes: amount.optional(), taxes: z.array(z.object({rateTypeId: z.number().int().optional(), value: z.number().optional(), currency: currency.optional()})).optional(), includingTaxes: amount.optional()}); export const file = z.object({id: z.string().optional(), href: z.string().optional(), name: z.string().optional(), displayHref: z.string().optional()}); export const attachment = z.object({id: z.number().int().optional(), file: file.optional(), createdAt: z.string().optional(), pages: z.object({displayHrefTemplate: z.string().optional(), count: z.number().int().optional()}).optional()}); export const paymentMethod = z.enum(["BankTransfer", "PhysicalCard", "Check", "DirectDebit", "SingleUseCard"]); export const document = z.object({id: z.number().int().optional(), owner: z.object({id: z.number().int().optional(), href: z.string().optional(), name: z.string().optional(), firstName: z.string().optional(), lastName: z.string().optional(), pictureHref: z.string().nullable().optional()}).optional(), type: z.enum(["Invoice", "CreditNote"]).optional(), context: z.object({purchase: purchaseReference.optional()}).nullable().optional(), documentBreakdown: documentBreakdownReference.optional(), documentDate: z.string().nullable().optional(), documentNumber: z.string().nullable().optional(), amountIncludingTaxes: taxedAmount.optional(), accountingLabel: z.string().nullable().optional(), comment: z.string().nullable().optional(), intraCommunityTaxes: z.boolean().optional(), attachments: z.array(attachment).optional(), ocrStatus: z.enum(["Pending", "Processing", "Processed", "Failed", "NotApplicable"]).optional(), dueDate: z.string().nullable().optional(), paymentDetails: z.object({paymentMethod: paymentMethod.optional(), bankAccount: z.object({iban: z.string().nullable().optional(), bic: z.string().nullable().optional()}).nullable().optional()}).nullable().optional(), createdAt: z.string().optional(), modifiedAt: z.string().optional(), author: z.object({id: z.number().int().optional(), href: z.string().optional(), name: z.string().optional(), firstName: z.string().optional(), lastName: z.string().optional(), pictureHref: z.string().nullable().optional()}).optional(), modifier: z.object({id: z.number().int().optional(), href: z.string().optional(), name: z.string().optional(), firstName: z.string().optional(), lastName: z.string().optional(), pictureHref: z.string().nullable().optional()}).optional()}); export const inboxDocument = z.object({id: z.number().int().optional(), document: document.optional(), source: z.object({type: z.string().optional()}).optional(), action: z.object({}).nullable().optional(), createdAt: z.string().optional(), modifiedAt: z.string().optional(), author: z.object({id: z.number().int().optional(), href: z.string().optional(), name: z.string().optional(), firstName: z.string().optional(), lastName: z.string().optional(), pictureHref: z.string().nullable().optional()}).optional(), modifier: z.object({id: z.number().int().optional(), href: z.string().optional(), name: z.string().optional(), firstName: z.string().optional(), lastName: z.string().optional(), pictureHref: z.string().nullable().optional()}).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 Inbox Document * * PUT /cleemy-procurement/services/inbox-documents/{id} */ export const updateApiCleemyProcurementServicesInboxDocumentsId = async (args: UpdateApiCleemyProcurementServicesInboxDocumentsIdArgs, options?: UpdateApiCleemyProcurementServicesInboxDocumentsIdOptions) => { 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/services/inbox-documents/${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(inboxDocument, await res.json()) };