import {z} from 'zod' export type GetApiV1ReportsContextsContextIdSummaryArgs = {'X-Request-Id'?: string | undefined, contextId: string, date_from: string, date_to: string, source_id?: string | undefined}; export type GetApiV1ReportsContextsContextIdSummaryOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const summaryReportResponse = z.object({matchedCount: z.number().int().optional(), unmatchedCount: z.number().int().optional(), totalAmount: z.string().optional(), matchedAmount: z.string().optional(), unmatchedAmount: z.string().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 reconciliation summary report * * GET /v1/reports/contexts/{contextId}/summary */ export const getApiV1ReportsContextsContextIdSummary = async (args: GetApiV1ReportsContextsContextIdSummaryArgs, options?: GetApiV1ReportsContextsContextIdSummaryOptions) => { const {baseUrl = "https://identity.sandbox.lerian.net", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-Request-Id'] != null) headers.set("X-Request-Id", String(args['X-Request-Id'])) if (args.date_from != null) query.append("date_from", String(args.date_from)) if (args.date_to != null) query.append("date_to", String(args.date_to)) if (args.source_id != null) query.append("source_id", String(args.source_id)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/reports/contexts/${encodeURIComponent(String(args.contextId))}/summary${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(summaryReportResponse, await res.json()) };