import {z} from 'zod' export type GetApiOmniB2bV1SessionsListingArgs = {loginHint: string, maxItems?: number | undefined, 'api-version': string}; export type GetApiOmniB2bV1SessionsListingOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const sessionListingDto = z.object({sessionId: z.string().optional(), updatedAt: z.number().int().optional(), onboardingStatus: z.enum(["UNKNOWN", "ID_VALIDATION_FINISHED", "POST_PROCESSING_FINISHED", "FACE_VALIDATION_FINISHED", "GOVERNMENT_VALIDATION_FINISHED", "EKYC_VALIDATION_FINISHED", "ONBOARDING_FINISHED", "MANUAL_REVIEW_APPROVED", "MANUAL_REVIEW_REJECTED", "MANUAL_REVIEW_PENDING", "EXPIRED", "DELETED", "QES_FINISHED"]).optional(), totalScoreStatus: z.enum(["OK", "WARN", "FAIL", "UNKNOWN", "MANUAL", "MANUAL_OK", "MANUAL_FAIL", "MANUAL_PENDING"]).optional()}); export const getApiOmniB2bV1SessionsListingResponse = z.array(sessionListingDto); 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 }; /** * Fetch session listing * * GET /omni/b2b/v1/sessions/listing */ export const getApiOmniB2bV1SessionsListing = async (args: GetApiOmniB2bV1SessionsListingArgs, options?: GetApiOmniB2bV1SessionsListingOptions) => { const {baseUrl = "https://demo-api.incodesmile.com", fetch: fetchFn = fetch, ApiKeyAuth, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.loginHint != null) query.append("loginHint", String(args.loginHint)) if (args.maxItems != null) query.append("maxItems", String(args.maxItems)) if (args['api-version'] != null) headers.set("api-version", String(args['api-version'])) if (ApiKeyAuth !== undefined) headers.set("x-api-key", ApiKeyAuth) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/omni/b2b/v1/sessions/listing${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(getApiOmniB2bV1SessionsListingResponse, await res.json()) };