UNPKG

spur-monocle-manager

Version:
56 lines (54 loc) 1.71 kB
type MonocleEvents = 'assessment' | 'error' | 'load'; interface MonocleOptions { token: string; initTimeout?: number; debug?: boolean; } /** * Monocle integration loader and manager. * Dynamically injects the Monocle script and provides methods to interact with it. */ declare class Monocle { private token; private initTimeout; private _initialized; private _readyPromise; private _script; private _monocle; private _eventTarget; private _handlers; private _debug; /** * @param options Configuration options, requiring a valid token * @throws Error if no token is provided */ constructor(options: MonocleOptions); /** * Dispatches a custom Monocle event on the internal EventTarget. */ private _dispatch; /** * Load the Monocle script into the document. * Returns a promise that resolves when the script is loaded or rejects on failure or timeout. */ init(): Promise<void>; /** * Returns the assessment JWT from Monocle. * This method should only be called after the script is loaded and initialized. * @throws Error if called on the server side or if no data is returned */ getAssessment(): Promise<string>; /** * Register an event listener for Monocle events. */ on(event: MonocleEvents, handler: (detail: any) => void): void; /** * Unregister a previously added event listener. */ off(event: MonocleEvents, handler: (detail: any) => void): void; /** * Clean up the Monocle script and all associated resources. */ destroy(): void; } export { type MonocleEvents, type MonocleOptions, Monocle as default };