import { type AuthorizedEventStreamObserver, type AuthorizedEventStreamSubscription } from "./client.js"; import { type DeviceSdkBridge, type DeviceSdkLoader } from "./device.js"; import type { DecisionConfig, DecisionResponse } from "./decision/decision.types.js"; import type { DataVerificationConfig, DataVerificationResult, DataState } from "./data/data.types.js"; import type { EidVerificationConfig, EidVerificationResult, EidPrepareResult, EidState } from "./eid/eid.types.js"; import type { AuthorizedGetEndpoint, AuthorizedPostEndpoint, AuthorizedUploadEndpoint, AuthRequestOptions, AuthUploadRequestOptions, DeviceEventResponse, DeviceSeedResponse, DeviceSubjectReference, RelativeEndpoint, SessionConfigurationResponse } from "./types.js"; /** * Optional lifecycle callbacks for web initialization and background device collection. */ export interface TruliooInitializationHandlers { /** Called when initialization completes successfully. */ onComplete?(result: TruliooInitializationResult): void; /** Called when background device-information collection resolves. */ onDeviceInformation?(device: TruliooDevice | undefined): void; /** Called when initialization or background collection fails. */ onError?(error: unknown): void; } /** * Options used when initializing a Trulioo Device session from a shortcode. * * Field summary: * - `allowLocalDevelopment?: boolean` permits `local@...` and `emulator@...` shortcodes. Omit or set `false` * for normal hosted environments. * - `deviceIntelligence?: TruliooDeviceIntelligenceOptions` enables Web auto-collection when present. * This is an options object, not a boolean flag. Pass `{}` to enable auto-collection with defaults. * - `fetch?: typeof fetch` overrides the fetch implementation used by bootstrap and authorized requests. * - `sdkVersion?: string` forwards the caller SDK version into runtime metadata. * - `runtime?: Partial` overrides runtime metadata such as locale or app identity. * * Examples: * ```ts * await Trulioo.initialize("shortcode", {}, { * allowLocalDevelopment: false, * sdkVersion: "1.2.3", * }); * ``` * * ```ts * await Trulioo.initialize("shortcode", {}, { * deviceIntelligence: {}, * }); * ``` * * ```ts * await Trulioo.initialize("shortcode", {}, { * deviceIntelligence: { * userId: "customer-123", * polling: { maxAttempts: 10, intervalMs: 1000 }, * }, * runtime: { * locale: "en-US", * }, * }); * ``` */ export interface TruliooInitializationOptions { /** Permits local or emulator shortcode hosts. Defaults to `false`. */ allowLocalDevelopment?: boolean; /** * Web-only auto-collection options for device intelligence. * * Presence enables background DI collection after `initialize(...)` succeeds. * Pass `{}` to opt in with default behavior, or provide nested options to customize the run. */ deviceIntelligence?: TruliooDeviceIntelligenceOptions; /** Optional fetch override used during bootstrap and later authorized calls. */ fetch?: typeof fetch; /** Optional caller SDK version forwarded into runtime metadata. */ sdkVersion?: string; /** Optional runtime metadata overrides such as locale or app identity. */ runtime?: Partial; } /** Result returned from shortcode initialization and, when collected, device-intelligence processing. */ export interface TruliooInitializationResult { baseUrl: string; accessToken: string; configuration: SessionConfigurationResponse; fromDesktop: boolean; deviceEvent?: DeviceEventResponse; deviceSeed?: DeviceSeedResponse; debugTrace?: TruliooDebugTraceEntry[]; } /** Options used to create an initialized, token-owning session HTTP client. */ export interface TruliooSessionClientOptions { fetch?: typeof fetch; allowedEndpoints?: RelativeEndpoint[]; } /** Authorized session HTTP client for plugin SDKs. The bearer token remains owned by Trulioo SDK state. */ export interface TruliooSessionClient { authorizedPostWithoutResponse(endpoint: AuthorizedPostEndpoint, request: Request, options?: Omit): Promise; authorizedPost(endpoint: AuthorizedPostEndpoint, request: Request, options?: Omit): Promise; authorizedPostWithoutBody(endpoint: AuthorizedPostEndpoint, options?: Omit): Promise; authorizedGetWithoutResponse(endpoint: AuthorizedGetEndpoint, options?: Omit): Promise; authorizedGet(endpoint: AuthorizedGetEndpoint, options?: Omit): Promise; authorizedGetText(endpoint: AuthorizedGetEndpoint, options?: Omit): Promise; authorizedGetEventStream(endpoint: AuthorizedGetEndpoint, observer: AuthorizedEventStreamObserver, options?: Omit): AuthorizedEventStreamSubscription; authorizedUpload(endpoint: AuthorizedUploadEndpoint, body: Uint8Array, options?: Omit): Promise; } /** Ordered diagnostic entry describing one stage of initialization or device collection. */ export interface TruliooDebugTraceEntry { stage: string; target: string; outcome: "started" | "succeeded" | "failed"; detail?: string; timestampEpochMs?: number; } /** Failure codes returned by the fire-and-forget send API. */ export type TruliooSendDeviceInformationFailureCode = "device_intelligence_disabled" | "device_intelligence_configuration_invalid" | "device_runtime_initialize_failed" | "device_runtime_submit_failed" | "device_event_accept_failed" | "unexpected"; /** Structured failure payload returned by the fire-and-forget send API. */ export interface TruliooSendDeviceInformationFailure { code: TruliooSendDeviceInformationFailureCode; stage: string; message: string; transactionId?: string; eventId?: string; debugTrace: TruliooDebugTraceEntry[]; } /** Accepted result returned by the fire-and-forget send API. */ export interface TruliooSendDeviceInformationAccepted { status: "accepted"; transactionId: string; eventId: string; debugTrace: TruliooDebugTraceEntry[]; } /** Failed result returned by the fire-and-forget send API. */ export interface TruliooSendDeviceInformationFailed { status: "failed"; error: TruliooSendDeviceInformationFailure; } /** Fire-and-forget send result for device intelligence submission. */ export type TruliooSendDeviceInformationResult = TruliooSendDeviceInformationAccepted | TruliooSendDeviceInformationFailed; /** * Options for device-intelligence collection on Web. * * This object is used in two ways: * - passed to `Trulioo.initialize(..., { deviceIntelligence: ... })` to auto-run DI in the background * - passed to explicit DI APIs to customize bridge loading, polling, or user identity * * Important: * - this object is not itself the DI configuration returned by Trulioo APIs * - the server-side `/device/configuration` response must still enable device intelligence and provide * a credential identifier, otherwise DI collection is skipped or fails with a configuration error */ export interface TruliooDeviceIntelligenceOptions { /** Optional fetch override for device-intelligence follow-up requests. */ fetch?: typeof fetch; /** * Optional third-party device bridge loader. * * Defaults to the installed runtime path. Pass `loadBundledDeviceBridge` to opt into the bundled loader, * or provide a custom loader for advanced host control. */ loadBridge?: DeviceSdkLoader; /** Polling controls for Trulioo device-event resolution. Defaults to 32 attempts with a 1250 ms interval. */ polling?: DeviceIntelligencePollingOptions; /** Optional runtime-specific user identifier forwarded to the runtime when the downstream configuration expects it. */ userId?: string; } /** Polling configuration for Trulioo Device event resolution. Defaults to `maxAttempts: 32` and `intervalMs: 1250`. */ export interface DeviceIntelligencePollingOptions { /** Maximum number of poll attempts before timing out the DI wait loop. */ maxAttempts?: number; /** Delay in milliseconds between poll attempts. */ intervalMs?: number; } /** Options for fire-and-forget device-information sending on Web. */ export interface TruliooSendDeviceInformationOptions { fetch?: typeof fetch; loadBridge?: DeviceSdkLoader; reference?: DeviceSubjectReference; /** Optional runtime-specific user identifier forwarded to the runtime when the downstream configuration expects it. */ userId?: string; } /** Normalized device seed returned by Trulioo device-intelligence collection. */ export type TruliooDevice = DeviceSeedResponse; /** Error thrown when a capability is called before Trulioo.initialize(). */ export declare class TruliooNotInitializedError extends Error { constructor(); } /** Public Web entry point for Trulioo Device session initialization, fire-and-forget sending, and debug collection. */ export declare class Trulioo { private static _session; private static _eidInstance; private static _dataInstance; private static _decisionClient; /** Returns the current stored session, or throws TruliooNotInitializedError if not initialized. */ private static requireSession; /** Clears internal session state. Useful for testing or logout flows. */ static reset(): void; /** * Starts a Trulioo Device session for the provided shortcode. * * On Web, device intelligence may optionally auto-queue after initialization when * `handlers.onDeviceInformation` or `options.deviceIntelligence` is supplied. * * Auto-collection behavior: * - no `handlers.onDeviceInformation` and no `options.deviceIntelligence`: initialization only * - `deviceIntelligence: {}`: auto-collect with default DI options * - `deviceIntelligence: { ... }`: auto-collect with the supplied DI options * * `options.deviceIntelligence` is therefore an options object whose presence acts as the auto-DI opt-in signal. * * @param shortcode Session shortcode used to resolve the environment host and bootstrap authorization. * @param handlers Optional lifecycle callbacks for initialization and background collection. * @param options Initialization controls such as local-development allowance and device-intelligence settings. * @returns Initialized Trulioo session state. */ static initialize(shortcode: string, handlers?: TruliooInitializationHandlers, options?: TruliooInitializationOptions): Promise; /** * Creates an authorized session HTTP client for plugin SDKs. * * Plugins provide the endpoint allowlist they own; the Trulioo SDK keeps the * initialization token inside this client and attaches it to authorized calls. */ static sessionClient(initialization: TruliooInitializationResult, options?: TruliooSessionClientOptions): TruliooSessionClient; /** * Sends device information without waiting for terminal device-event resolution. * * This is the simplest production integration path. The SDK submits device * information and returns either an accepted result or a structured failure * payload. Use `collectDeviceIntelligence(...)` only when the integration * intentionally needs to wait for the resolved device event and seed. * * @param initialization Initialized session state returned from `initialize(...)`. * @param options Send options such as subject reference data, bridge loading, and optional user id. * @returns Accepted or failed fire-and-forget send result. */ static sendDeviceInformation(initialization: TruliooInitializationResult, options?: TruliooSendDeviceInformationOptions): Promise; /** * Collects device intelligence for an initialized session. * * `reference` only accepts subject data. The SDK generates device basic * information internally and submits it independently from subject data. * This is the debug-oriented path because it waits for terminal device-event * resolution and returns the normalized device seed when available. * * @param initialization Initialized session state returned from `initialize(...)`. * @param options Collection controls such as polling behavior, bridge loading, subject reference data, and optional user id. * @returns Initialization result extended with device-event and device-seed data. */ static collectDeviceIntelligence(initialization: TruliooInitializationResult, options?: TruliooDeviceIntelligenceOptions & { reference?: DeviceSubjectReference; }): Promise; /** * Convenience callback API that resolves the normalized device seed for an initialized session. * * @param initialization Initialized session state returned from `initialize(...)`. * @param onComplete Callback invoked with the normalized device seed, or `undefined` when device intelligence is disabled. * @param onError Optional callback invoked when device collection fails. * @param options Collection controls such as polling behavior, bridge loading, and optional user id. */ static getDeviceInformation(initialization: TruliooInitializationResult, onComplete: (device: TruliooDevice | undefined) => void, onError?: (error: unknown) => void, options?: TruliooDeviceIntelligenceOptions): void; /** * Submits data for KYC verification and polls until terminal result. * * Uses the internally stored session from `initialize()`. Throws `TruliooNotInitializedError` * if called before initialization. PII isolation is enforced via allowedEndpoints — the SDK * never calls the result endpoint. * * @param config Verification configuration with PII fields and country code. * @returns Terminal result with outcome and match status -- no PII returned. */ static verifyData(config: DataVerificationConfig): Promise; /** * @deprecated Pass config only. The initialization parameter is no longer needed. */ static verifyData(initialization: TruliooInitializationResult, config: DataVerificationConfig): Promise; /** Current state of the Data Verification module. */ static get dataState(): DataState; /** Subscribe to data verification state changes. Returns unsubscribe function. */ static onDataStateChange(listener: (state: DataState) => void): () => void; /** Resets data verification state to IDLE. */ static resetData(): void; /** * Pre-warms EID verification. Call when the EID UI screen appears. * * Uses the internally stored session from `initialize()`. Throws `TruliooNotInitializedError` * if called before initialization. * * @param config EID verification configuration with country code. * @returns Prepare result indicating readiness. */ static prepareEid(config: EidVerificationConfig): Promise; /** * Starts an interactive EID verification. * * Opens the provider URL in a popup/redirect. Waits for completion and polls until * terminal result. Uses internally stored session. * * @param config EID verification configuration. * @returns Terminal EID verification result (outcome + match, no PII). */ static verifyEid(config: EidVerificationConfig): Promise; /** Current EID verification state. */ static get eidState(): EidState; /** Subscribe to EID verification state changes. Returns unsubscribe function. */ static onEidStateChange(listener: (state: EidState) => void): () => void; /** Resets EID verification state to IDLE. */ static resetEid(): void; private static ensureEidInstance; private static ensureDataInstance; /** Maximum time (ms) to wait for capabilities before proceeding with decision. */ private static readonly CAPABILITY_AWAIT_TIMEOUT_MS; /** * Waits for in-progress EID and Data capabilities to reach terminal state. * Resolves immediately if no capabilities are active. * Each waiter owns its own deadline and subscription cleanup, so no listener * is leaked even when the caller does not observe the individual promise. * * Terminal states: EID = COMPLETED | FAILED | IDLE, Data = COMPLETED | FAILED | IDLE */ private static awaitActiveCapabilities; /** * Resolves when EID reaches a terminal state (COMPLETED, FAILED, or IDLE). * Owns a self-managed deadline: on expiry the subscription is unsubscribed and the * promise resolves, so no listener is leaked regardless of the call site. */ private static waitForEidTerminal; /** * Resolves when Data reaches a terminal state (COMPLETED, FAILED, or IDLE). * Owns a self-managed deadline: on expiry the subscription is unsubscribed and the * promise resolves, so no listener is leaked regardless of the call site. */ private static waitForDataTerminal; /** * Get the transaction decision using account-default weights. * * Reads all completed capability signals (Device, EID, Data, Document) from the * transaction and returns a weighted aggregate decision. No PII is returned. * * Uses the internally stored session from `initialize()`. The transactionId is * read from the session configuration response. * * @param config Optional weight/threshold overrides. If omitted, uses server defaults. * @returns Decision response with outcome, confidence, reasoning, and signals. */ static getDecision(config?: DecisionConfig): Promise; } /** Optional runtime metadata overrides for browser integrations. */ export interface TruliooRuntimeMetadata { sdkVersion: string; locale: string; languageCode: string; deviceModel: string; deviceManufacturer: string; deviceSoftware: string; appVersion: string; appDomain: string; } export type { DeviceSdkBridge };