import {z} from 'zod' export type GetApiApiV1InvoicesOrganizationIdArgs = {organizationId: number, Page?: number | undefined, PageSize?: number | undefined}; export type GetApiApiV1InvoicesOrganizationIdOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const invoice = z.object({invoiceId: z.string().nullable().optional(), orderId: z.string().nullable().optional(), salesCurrencyCode: z.string().nullable().optional(), salesAmount: z.number().optional(), invoiceCustomerId: z.string().nullable().optional(), invoiceCustomerName: z.string().nullable().optional(), orderCustomerId: z.string().nullable().optional(), orderCustomerName: z.string().nullable().optional(), customerReference: z.string().nullable().optional(), customerRequisition: z.string().nullable().optional(), invoiceDate: z.string().nullable().optional()}); export const getApiApiV1InvoicesOrganizationIdResponse = z.array(invoice); 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 }; /** * GET /api/v1/Invoices/{organizationId} */ export const getApiApiV1InvoicesOrganizationId = async (args: GetApiApiV1InvoicesOrganizationIdArgs, options: GetApiApiV1InvoicesOrganizationIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.Page != null) query.append("Page", String(args.Page)) if (args.PageSize != null) query.append("PageSize", String(args.PageSize)) if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/Invoices/${encodeURIComponent(String(args.organizationId))}${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(getApiApiV1InvoicesOrganizationIdResponse, await res.json()) };