import {z} from 'zod' export type GetApiCompaniesCompanyIdConnectionsConnectionIdDataItemReceiptsArgs = {page?: number | undefined, pageSize?: number | undefined, query?: string | undefined, orderBy?: string | undefined}; export type GetApiCompaniesCompanyIdConnectionsConnectionIdDataItemReceiptsOptions = {baseUrl?: string | undefined, authHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const metadata = z.object({isDeleted: z.boolean().nullable().optional()}); export const supplementalData = z.object({content: z.record(z.string(), z.record(z.string(), z.unknown())).nullable().optional()}); export const itemReceipt = z.object({id: z.string().optional(), supplierRef: z.unknown().optional(), purchaseOrderRefs: z.array(z.unknown()).nullable().optional(), status: z.unknown().optional(), note: z.string().nullable().optional(), reference: z.string().nullable().optional(), currency: z.unknown().optional(), currencyRate: z.unknown().optional(), receivedDate: z.string().optional(), lineItems: z.array(z.unknown()).nullable().optional(), subTotal: z.number().optional(), totalAmount: z.number().optional(), metadata: metadata.optional(), supplementalData: supplementalData.optional(), modifiedDate: z.string().optional(), sourceModifiedDate: z.string().optional()}).nullable(); export const itemReceipts = z.object({results: z.array(itemReceipt).optional(), pageNumber: z.number().int(), pageSize: z.number().int().lte(2000), totalResults: z.number().int(), _links: z.unknown()}); 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 item receipts * * GET /companies/{companyId}/connections/{connectionId}/data/itemReceipts */ export const getApiCompaniesCompanyIdConnectionsConnectionIdDataItemReceipts = async (args: GetApiCompaniesCompanyIdConnectionsConnectionIdDataItemReceiptsArgs, options?: GetApiCompaniesCompanyIdConnectionsConnectionIdDataItemReceiptsOptions) => { const {baseUrl = "https://api.codat.io", fetch: fetchFn = fetch, authHeader} = 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 (args.query != null) query.append("query", String(args.query)) if (args.orderBy != null) query.append("orderBy", String(args.orderBy)) if (authHeader !== undefined) headers.set("Authorization", authHeader) const url = `${baseUrl.replace(/\/+$/, '')}/companies/${encodeURIComponent(String(args.companyId))}/connections/${encodeURIComponent(String(args.connectionId))}/data/itemReceipts${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(itemReceipts, await res.json()) };