import {z} from 'zod' export type GetApiFinanceSalereportMatchingerrorsArgs = {'options.queueId'?: number | undefined, 'options.pageNumber'?: number | undefined, 'options.pageSize'?: number | undefined, 'options.orderByProperty'?: string | undefined, 'options.orderByDescending'?: boolean | undefined, 'options.searchText'?: string | undefined}; export type GetApiFinanceSalereportMatchingerrorsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const saleItemsMatchingErrorDTO = z.object({report: z.string().optional(), track: z.string().optional(), release: z.string().optional(), artist: z.string().optional(), label: z.string().optional(), deliveryType: z.string().optional(), country: z.string().optional(), matchedContract: z.string().optional(), totalNet: z.number().optional(), releaseId: z.number().int().optional(), statementId: z.number().int().optional(), trackId: z.number().int().optional(), artistId: z.number().int().optional(), labelId: z.number().int().optional(), contractId: z.number().int().optional(), errorTypeId: z.number().int().optional(), id: z.number().int().optional()}); export const pagedListSaleItemsMatchingErrorDTO = z.object({totalItemsCount: z.number().int().optional(), pageNumber: z.number().int().optional(), pageSize: z.number().int().optional(), items: z.array(saleItemsMatchingErrorDTO).optional(), additionalCounters: z.record(z.string(), z.number()).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 }; /** * GET /finance/salereport/matchingerrors */ export const getApiFinanceSalereportMatchingerrors = async (args: GetApiFinanceSalereportMatchingerrorsArgs, options?: GetApiFinanceSalereportMatchingerrorsOptions) => { const {baseUrl = "http://api.revelator.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['options.queueId'] != null) query.append("options.queueId", String(args['options.queueId'])) if (args['options.pageNumber'] != null) query.append("options.pageNumber", String(args['options.pageNumber'])) if (args['options.pageSize'] != null) query.append("options.pageSize", String(args['options.pageSize'])) if (args['options.orderByProperty'] != null) query.append("options.orderByProperty", String(args['options.orderByProperty'])) if (args['options.orderByDescending'] != null) query.append("options.orderByDescending", String(args['options.orderByDescending'])) if (args['options.searchText'] != null) query.append("options.searchText", String(args['options.searchText'])) const url = `${baseUrl.replace(/\/+$/, '')}/finance/salereport/matchingerrors${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(pagedListSaleItemsMatchingErrorDTO, await res.json()) };