import {z} from 'zod' export type GetApiApiV1MerchantsIdAccountInformationSessionsSessionIdArgs = {id: string, sessionId: string}; export type GetApiApiV1MerchantsIdAccountInformationSessionsSessionIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const accountInformationSessionResponse = z.object({success: z.boolean(), data: z.object({id: z.string(), merchant_id: z.string(), provider_name: z.string(), status: z.union([z.literal("pending"), z.literal("completed"), z.literal("failed"), z.literal("expired"), z.literal("cancelled")]), connect_url: z.string(), redirect_url: z.string().optional(), 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(), retrieved_accounts: z.array(z.object({provider_account_id: z.string(), account_number_masked: z.string(), account_type: z.string(), holder_name: z.string().optional(), institution_name: z.string(), currency: z.string(), country: z.string()}).and(z.record(z.string(), z.unknown()))).optional(), error_message: z.string().optional(), created_at: z.string(), updated_at: z.string()})}); 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 account information session status and details (including retrieved accounts when completed). * * GET /api/v1/merchants/{id}/account-information/sessions/{sessionId} */ export const getApiApiV1MerchantsIdAccountInformationSessionsSessionId = async (args: GetApiApiV1MerchantsIdAccountInformationSessionsSessionIdArgs, options?: GetApiApiV1MerchantsIdAccountInformationSessionsSessionIdOptions) => { 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 (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/merchants/${encodeURIComponent(String(args.id))}/account-information/sessions/${encodeURIComponent(String(args.sessionId))}${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(accountInformationSessionResponse, await res.json()) };