UNPKG

ocular-widget-sdk

Version:

Ocular's widget SDK

82 lines (69 loc) 2.39 kB
export interface InitOptions { code: string; } export interface EventData { type?: string; msg?: string; [key: string]: any; } export type EventCallback = (eventData?: EventData) => void; export declare class OcularWidget { /** * Registers an event listener for widget events * @param event - The event name to listen for * @param callback - The callback function to execute when the event occurs */ on(event: string, callback: EventCallback): void; /** * Removes all event listeners for a specific event * @param event - The event name to remove listeners for */ off(event: string): void; /** * Shows the widget on the page * @param opened - If true, opens the widget completely. If false, shows only the floating button * @returns Promise that resolves with "success" when completed */ show(opened?: boolean): Promise<string>; /** * Hides the widget from the page * @returns Promise that resolves with "success" when completed */ hide(): Promise<string>; /** * Toggles the widget visibility * @returns Promise that resolves with "success" when completed */ toggle(): Promise<string>; /** * Sets customer information in the widget * @param customer - Customer data object * @returns Promise that resolves with "success" when completed */ setCustomer(customer: any): Promise<string>; /** * Sets the widget locale/language * @param locale - Language code (e.g., 'es', 'en', 'fr') * @returns Promise that resolves with "success" when completed */ setLocale(locale: string): Promise<string>; } /** * EventTarget for widget events (browser only) */ export declare const ocularEvents: EventTarget | null; /** * Main widget instance for controlling and listening to events */ export declare const ocularWidgetInstance: OcularWidget; /** * Initializes the Ocular widget on the page * @param options - Configuration options including the widget code * @returns Promise that resolves when the widget script has been loaded successfully */ export declare function initOcularWidget(options: InitOptions): Promise<string>; /** * Waits for the widget to be ready for use * @returns Promise that resolves when the widget is ready */ export declare function waitForReady(): Promise<void>;