import {z} from 'zod' export type GetApiV1ExceptionsArgs = {'X-Request-Id'?: string | undefined, status?: ('OPEN' | 'ASSIGNED' | 'PENDING_RESOLUTION' | 'RESOLVED') | undefined, severity?: ('LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL') | undefined, assigned_to?: string | undefined, external_system?: ('JIRA' | 'SERVICENOW' | 'WEBHOOK') | undefined, date_from?: string | undefined, date_to?: string | undefined, cursor?: string | undefined, limit?: number | undefined, sort_by?: ('id' | 'created_at' | 'updated_at' | 'severity' | 'status') | undefined, sort_order?: ('asc' | 'desc') | undefined}; export type GetApiV1ExceptionsOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const exceptionResponse = z.object({assignedTo: z.string().optional(), createdAt: z.string().optional(), dueAt: z.string().optional(), externalIssueId: z.string().optional(), externalSystem: z.string().optional(), id: z.string().optional(), reason: z.string().optional(), resolutionNotes: z.string().optional(), resolutionReason: z.string().optional(), resolutionType: z.enum(["FORCE_MATCH", "ADJUST_ENTRY"]).optional(), severity: z.enum(["LOW", "MEDIUM", "HIGH", "CRITICAL"]).optional(), status: z.enum(["OPEN", "ASSIGNED", "PENDING_RESOLUTION", "RESOLVED"]).optional(), transactionId: z.string().optional(), updatedAt: z.string().optional()}); export const listExceptionsResponse = z.object({hasMore: z.boolean().optional(), items: z.array(exceptionResponse).optional(), limit: z.number().int().gte(1).lte(200).optional(), nextCursor: z.string().optional(), prevCursor: 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 }; /** * List exceptions * * GET /v1/exceptions */ export const getApiV1Exceptions = async (args: GetApiV1ExceptionsArgs, options?: GetApiV1ExceptionsOptions) => { 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.status != null) query.append("status", String(args.status)) if (args.severity != null) query.append("severity", String(args.severity)) 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.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.cursor != null) query.append("cursor", String(args.cursor)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.sort_by != null) query.append("sort_by", String(args.sort_by)) if (args.sort_order != null) query.append("sort_order", String(args.sort_order)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/exceptions${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(listExceptionsResponse, await res.json()) };