import {z} from 'zod' export type GetApiV1ExceptionsIdsArgs = {contextId?: string | undefined, status?: ('OPEN' | 'ASSIGNED' | 'RESOLVED') | undefined, severity?: ('LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL') | undefined, reason?: ('UNMATCHED' | 'FX_RATE_UNAVAILABLE' | 'MISSING_BASE_AMOUNT' | 'MISSING_BASE_CURRENCY' | 'SPLIT_INCOMPLETE' | 'VALIDATION_FAILED' | 'SOURCE_MISMATCH' | 'DUPLICATE_TRANSACTION' | 'FEE_VARIANCE' | 'FEE_DATA_MISSING' | 'FEE_CURRENCY_MISMATCH' | 'FX_RATE_VARIANCE' | 'AGED_BREAK' | 'OVER_SETTLED') | undefined, assigned_to?: string | undefined, external_system?: string | undefined, search?: string | undefined, date_from?: string | undefined, date_to?: string | undefined, min_age_days?: number | undefined}; export type GetApiV1ExceptionsIdsOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const selectExceptionIDsResponse = z.object({ids: z.array(z.string()).nullable(), total: z.number().int(), truncated: z.boolean()}); 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 }; /** * Select exception ids by filter * * GET /v1/exceptions/ids */ export const getApiV1ExceptionsIds = async (args: GetApiV1ExceptionsIdsArgs, options?: GetApiV1ExceptionsIdsOptions) => { 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.contextId != null) query.append("contextId", String(args.contextId)) if (args.status != null) query.append("status", String(args.status)) if (args.severity != null) query.append("severity", String(args.severity)) if (args.reason != null) query.append("reason", String(args.reason)) if (args.assigned_to != null) query.append("assigned_to", String(args.assigned_to)) if (args.external_system != null) query.append("external_system", String(args.external_system)) if (args.search != null) query.append("search", String(args.search)) 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.min_age_days != null) query.append("min_age_days", String(args.min_age_days)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/exceptions/ids${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(selectExceptionIDsResponse, await res.json()) };