import {z} from 'zod' export type GetApiApiV1CreditNotesIdArgs = {id: string}; export type GetApiApiV1CreditNotesIdOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV1CreditNotesIdResponse = z.object({data: z.object({id: z.string().optional(), number: z.string().nullable().optional(), date: z.string().optional(), createdAt: z.string().optional(), createdBy: z.object({name: z.string()}).nullable().optional(), sentAt: z.string().nullable().optional(), sentBy: z.object({name: z.string()}).nullable().optional(), updatedAt: z.string().optional(), grossValue: 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(), netValue: 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(), costCenter: z.string().optional(), status: z.enum(["approved", "sent", "created", "closed", "canceled"]).optional(), project: z.object({id: z.string().optional(), name: z.string().optional()}).optional(), customer: z.object({id: z.string().optional(), name: z.string().optional()}).optional(), tags: z.array(z.object({id: z.string().optional(), name: z.string().optional(), color: z.string().optional()})).optional(), externalOrderReference: z.string().nullable().optional(), devCustomer: z.string().nullable().optional(), billingAddress: z.object({id: z.string().optional(), name: z.string(), contactPerson: z.string(), department: z.string().nullable(), subdivision: z.string().nullable(), street: z.string(), additionalDetails: z.string().nullable(), city: z.string(), zipCode: z.string(), country: z.string(), email: z.string().nullable().optional()}).nullable().optional(), paymentMethodName: z.string().optional(), paymentStatus: z.enum(["pending", "paid", "partlyPaid", "canceled", "partialCancellation", "badDebt", "debited", "unknown"]).optional(), gln: z.string().nullable().optional(), taxation: z.number().optional(), positions: z.array(z.object({id: z.number().optional(), position: z.number().optional(), salesOrderPosition: z.object({id: z.string()}).nullable().optional(), createdAt: z.string().optional(), productId: z.number().optional(), productNumber: z.string().optional(), description: z.string().optional(), quantity: z.number().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(), vatCategory: z.string().optional(), taxRate: z.number().optional(), discount: z.number().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 }; /** * View credit note * * GET /api/v1/creditNotes/{id} */ export const getApiApiV1CreditNotesId = async (args: GetApiApiV1CreditNotesIdArgs, options?: GetApiApiV1CreditNotesIdOptions) => { 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/creditNotes/${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(getApiApiV1CreditNotesIdResponse, await res.json()) };