import {z} from 'zod' export type GetApiApiV1MerchantsIdAccountInformationSessionsArgs = {id: string, status?: ('pending' | 'completed' | 'failed' | 'expired' | 'cancelled') | undefined, limit?: number | undefined, cursor?: string | undefined}; export type GetApiApiV1MerchantsIdAccountInformationSessionsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const accountInformationListSessionsResponse = z.object({success: z.boolean(), data: z.object({sessions: z.array(z.object({id: z.string(), status: z.union([z.literal("pending"), z.literal("completed"), z.literal("failed"), z.literal("expired"), z.literal("cancelled")]), created_at: z.string(), expires_at: z.string(), requested_data_types: z.object({account_identity: z.boolean(), holder_identity: z.boolean(), transaction_history: z.boolean(), statements: z.boolean()}).optional(), verification_url: z.string().nullable()})), next_cursor: z.string().nullable()})}); 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 account information sessions with optional status filter and cursor pagination. * * GET /api/v1/merchants/{id}/account-information/sessions */ export const getApiApiV1MerchantsIdAccountInformationSessions = async (args: GetApiApiV1MerchantsIdAccountInformationSessionsArgs, options?: GetApiApiV1MerchantsIdAccountInformationSessionsOptions) => { const {baseUrl = "https://core.quidkey.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.status != null) query.append("status", String(args.status)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/merchants/${encodeURIComponent(String(args.id))}/account-information/sessions${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(accountInformationListSessionsResponse, await res.json()) };