import {z} from 'zod' export type GetApiApiV1LiabilitiesArgs = {filter?: ({id?: Array | undefined} | Array<{key?: ('supplier' | 'status' | 'project' | 'createdAt' | 'dueDate' | 'fromDate' | 'missingPaymentApproval' | 'goodsReceiptInspectionMissing' | 'incomingInvoiceVerificationMissing' | 'noAccountAssignment' | 'missingPayment' | 'paidLiability' | 'canceledLiability' | 'missingDocument' | 'invoiceDateAndReceiptVariousMonths') | undefined, op?: ('equals' | 'notEquals' | 'in' | 'notIn' | 'allIn' | 'allNotIn' | 'greaterThan' | 'lessThan') | undefined, value?: (string | Array) | undefined}>) | undefined, page?: {number: string, size: string} | undefined, order?: (Array<{field?: ('id' | 'documentNumber' | 'status' | 'project' | 'createdAt') | undefined, dir?: ('asc' | 'desc') | undefined}>) | undefined}; export type GetApiApiV1LiabilitiesOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV1LiabilitiesResponse = z.object({data: z.array(z.object({id: z.string().optional(), documentNumber: z.string().nullable().optional(), date: z.string().optional(), createdAt: z.string().nullable().optional(), createdBy: z.object({name: z.string().nullable()}).nullable().optional(), updatedAt: z.string().optional(), status: z.enum(["PENDING", "PAID", "PARTIALLY_PAID", "CANCELLED"]).optional(), supplier: z.object({id: z.string(), name: z.string().nullable().optional(), number: z.string().nullable().optional()}).optional(), supplierInvoiceNumber: z.string().optional(), receiptDate: z.string().nullable().optional(), financials: z.object({amountGross: z.object({amount: z.string(), currency: z.string()}).optional(), freightCharge: z.number().nullable().optional(), taxation: z.string().optional(), taxes: z.object({normalTax: z.object({rate: z.number().nullable(), amount: z.number().nullable()}).nullable(), reducedTax: z.object({rate: z.number().nullable(), amount: z.number().nullable()}).nullable(), customTax1: z.object({rate: z.number().nullable(), amount: z.number().nullable()}).nullable(), customTax2: z.object({rate: z.number().nullable(), amount: z.number().nullable()}).nullable()}).optional(), bookingText: z.string().optional(), paymentTerms: z.object({dueDate: z.string().nullable(), earlyPaymentDate: z.string().nullable(), earlyPaymentDiscount: z.number()}).optional(), payment: z.object({methodName: z.string(), paidAmount: z.number(), paidOnDate: z.string().nullable(), discountReceived: z.number()}).optional(), bank: z.object({iban: z.string().optional(), bic: z.string().optional()}).optional(), amountNet: z.object({amount: z.string(), currency: z.string()}).optional(), remainingSum: z.object({amount: z.string(), currency: z.string()}).optional(), totalAmount: z.object({amount: z.string(), currency: z.string()}).optional()}).optional(), purchaseOrder: z.object({id: z.string()}).nullable().optional(), project: z.object({id: z.string()}).optional(), icons: z.object({goodsReceiptCheck: z.string().optional(), invoiceCheck: z.string().optional(), accountAssignment: z.string().optional(), paymentStatus: z.string().optional(), accountLink: z.string().optional()}).optional(), tags: z.array(z.object({id: z.string().optional(), name: z.string().optional(), color: z.string().optional()})).optional()})).optional(), extra: z.object({totalCount: z.number().int(), page: z.object({number: z.number().int(), size: z.number().int()})}).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 }; /** * List liabilities * * GET /api/v1/liabilities */ export const getApiApiV1Liabilities = async (args: GetApiApiV1LiabilitiesArgs, options?: GetApiApiV1LiabilitiesOptions) => { 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 (args.filter != null) query.append("filter", String(args.filter)) if (args.page != null) query.append("page", JSON.stringify(args.page)) if (args.order != null) query.append("order", args.order.join(',')) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/liabilities${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(getApiApiV1LiabilitiesResponse, await res.json()) };