import {z} from 'zod' export type GetApiApiV1PurchaseOrdersIdArgs = {id: string}; export type GetApiApiV1PurchaseOrdersIdOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV1PurchaseOrdersIdResponse = z.object({data: z.object({id: z.string().optional(), date: z.string().optional(), project: z.object({id: z.string()}).optional(), status: z.string().optional(), documentNumber: z.string().optional(), supplier: z.object({id: z.string().optional(), number: z.string().optional(), customerNumberAtSupplier: z.string().optional(), honorific: z.string().optional(), name: z.string().optional(), department: z.string().optional(), subDepartment: z.string().optional(), extraAddressLine: z.string().optional(), street: z.string().optional(), zipCode: z.string().optional(), city: z.string().optional(), state: z.string().optional(), country: z.string().optional(), contactPerson: z.string().optional(), telephone: z.string().optional(), telefax: z.string().optional(), email: z.string().optional()}).optional(), requestForQuotation: z.object({id: z.string()}).nullable().optional(), bodyIntroduction: z.string().optional(), bodyOutroduction: z.string().optional(), salesOrderConfirmationReference: z.string().optional(), isConfirmationRequested: z.boolean().optional(), suppliersOfferReference: z.string().optional(), internalDesignation: z.string().optional(), language: z.object({iso2: z.string().optional()}).optional(), isConfirmed: z.boolean().optional(), confirmedVia: z.string().optional(), financials: z.object({paymentMethod: z.object({id: z.string().optional()}).nullable().optional(), total: z.object({amount: z.string().optional(), currency: z.enum(["EUR", "USD", "JPY", "BGN", "CZK", "DKK", "GBP", "HUF", "PLN", "RON", "SEK", "CHF", "ISK", "NOK", "HRK", "RUB", "TRY", "AUD", "BRL", "CAD", "CNY", "HKD", "IDR", "ILS", "INR", "KRW", "MXN", "MYR", "NZD", "PHP", "SGD", "THB", "ZAR", "ARS", "CLP", "SAR", "AED", "QAR"]).optional()}).optional(), paymentTerms: z.object({paymentTargetDiscount: z.number().optional(), paymentTargetDays: z.number().optional(), paymentTargetDiscountDays: z.number().optional(), paymentTargetDiscountAmount: z.number().optional(), isPaymentTargetDiscountApplied: z.boolean().optional()}).optional(), costCenter: z.string().optional(), tax: z.object({taxation: z.string().optional(), vatId: z.string().optional(), taxDisplay: z.string().optional()}).optional()}).optional(), delivery: z.object({deliveryTerms: z.object({id: z.string()}).nullable().optional(), hasDifferentDeliveryAddress: z.boolean().optional(), deliveryAddress: z.object({honorific: z.string().optional(), name: z.string().optional(), department: z.string().optional(), subDepartment: z.string().optional(), extraAddressLine: z.string().optional(), street: z.string().optional(), zipCode: z.string().optional(), city: z.string().optional(), state: z.string().optional(), country: z.string().optional(), contactPerson: z.string().optional()}).optional(), dates: z.object({desiredDeliveryDate: z.string().nullable().optional(), confirmedDeliveryDate: z.string().nullable().optional()}).optional()}).optional(), formatting: z.object({hideLetterHead: z.boolean().optional(), hidePrices: z.boolean().optional(), hideProductNumbers: z.boolean().optional(), showLongProductNumbers: z.boolean().optional(), hideProductDescriptions: z.boolean().optional(), showOwnProductNumberInColumn: z.boolean().optional()}).optional(), internalComment: z.string().optional(), liabilitiesInfo: z.string().optional(), positions: z.array(z.object({id: z.string().optional(), project: z.object({id: z.string()}).optional(), product: z.object({id: z.string()}).optional(), name: z.string().optional(), description: z.string().optional(), quantity: z.number().optional(), delivered: z.number().optional(), salesOrderPosition: z.object({id: z.string().optional(), salesOrder: z.object({id: z.string().optional()}).optional()}).nullable().optional(), price: z.object({amount: z.string().optional(), currency: z.enum(["EUR", "USD", "JPY", "BGN", "CZK", "DKK", "GBP", "HUF", "PLN", "RON", "SEK", "CHF", "ISK", "NOK", "HRK", "RUB", "TRY", "AUD", "BRL", "CAD", "CNY", "HKD", "IDR", "ILS", "INR", "KRW", "MXN", "MYR", "NZD", "PHP", "SGD", "THB", "ZAR", "ARS", "CLP", "SAR", "AED", "QAR"]).optional()}).optional(), tax: z.object({vatCategory: z.enum(["standard", "reduced", "free", "custom"]).optional(), taxText: z.string().optional(), rate: z.number().optional()}).optional()})).optional(), log: z.object({createdAt: z.string().nullable().optional(), isSent: z.boolean().optional(), sentAt: z.string().nullable().optional(), sentBy: z.string().optional(), sentVia: z.string().optional()}).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 }; /** * View purchase order * * GET /api/v1/purchaseOrders/{id} */ export const getApiApiV1PurchaseOrdersId = async (args: GetApiApiV1PurchaseOrdersIdArgs, options?: GetApiApiV1PurchaseOrdersIdOptions) => { const {baseUrl = "https://xentral.xentral.biz", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/purchaseOrders/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiApiV1PurchaseOrdersIdResponse, await res.json()) };