import {z} from 'zod' export type GetApiApiV1PartnerKycSessionsArgs = {status?: ('email_sent' | 'link_ready' | 'opened' | 'in_progress' | 'kyc_completed' | 'revoked') | undefined, account_auth_id?: string | undefined, page?: number | undefined, size?: number | undefined}; export type GetApiApiV1PartnerKycSessionsOptions = {baseUrl?: string | undefined, AuthID?: string | undefined, AuthToken?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV1PartnerKycSessionsResponse = z.object({sessions: z.array(z.object({id: z.string(), account_auth_id: z.string(), customer_email: z.string().nullable(), kyc_type: z.string().nullable(), status: z.string(), expires_at: z.string(), first_opened_at: z.string().nullable(), completed_at: z.string().nullable(), webhook_url: z.string().nullable(), redirect_url: z.string().nullable(), reminder_schedule: z.array(z.object({value: z.number().int(), trigger: z.string()})), metadata: z.union([z.unknown(), z.object({plan: z.string(), customer_ref: z.string()})]), verified_data: z.union([z.unknown(), z.object({pan_type: z.string().optional(), pan_number: z.string().optional(), pan_name_match: z.boolean().optional(), completed_steps: z.array(z.string()).optional(), pan_registered_name: z.string().optional(), gender: z.string().optional(), address: z.string().optional(), aadhaar_dob: z.string().optional(), aadhaar_name: z.string().optional(), masked_aadhaar: z.string().optional(), pan_name: z.string().optional()})]), created_at: z.string(), updated_at: z.string()})), total: z.number().int(), page: z.number().int(), size: z.number().int()}); 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 KYC sessions * * GET /api/v1/partner/kyc-sessions */ export const getApiApiV1PartnerKycSessions = async (args: GetApiApiV1PartnerKycSessionsArgs, options?: GetApiApiV1PartnerKycSessionsOptions) => { const {baseUrl = "https://api.vobiz.ai", fetch: fetchFn = fetch, AuthID, AuthToken} = 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.account_auth_id != null) query.append("account_auth_id", String(args.account_auth_id)) if (args.page != null) query.append("page", String(args.page)) if (args.size != null) query.append("size", String(args.size)) if (AuthID !== undefined) headers.set("X-Auth-ID", AuthID) if (AuthToken !== undefined) headers.set("X-Auth-Token", AuthToken) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/partner/kyc-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(getApiApiV1PartnerKycSessionsResponse, await res.json()) };