/** load implement at very first time */ /** * global error catch */ import './events'; import './loader'; /** * @public Jolibox JS SDK Entry */ import { getSystemInfoSync, isNativeSupport, canIUse, login, checkSession, request, onCustomEvent, offCustomEvent, onceCustomEvent, callHostMethod, track } from './api'; import { RuntimeSDK } from './sdks/runtime'; import { LifecycleSDK } from './sdks/lifecycle'; import { StorageSDK } from './sdks/storage'; import { JoliboxAds } from './sdks/ads'; import { KeyboardSDK } from './sdks/keyboard'; import { TaskTrackerSDK } from './sdks/task'; import { RouterSDK } from './sdks/router'; import { PaymentSDK } from './sdks/payment'; import { RewardsSDK } from './sdks/rewards'; declare global { interface Window { JoliboxSDK: typeof JoliboxSDK; joliboxsdk: { runtime: InstanceType; ads: InstanceType; lifecycle: InstanceType; storage: InstanceType; keyboard: InstanceType; task: InstanceType; router: InstanceType; }; } } /** * @public * The main entry point and facade for the Jolibox JavaScript SDK. * Provides access to various SDK modules and global API functions. * This class is a singleton. */ export class JoliboxSDK { private static instance: JoliboxSDK | null = null; /** * @public * @readonly * The current version of the Jolibox JSSDK. */ readonly jssdkVersion = '__JOLIBOX_LOCAL_SDK_VERSION__'; /** * @public * @readonly * Access to the Runtime SDK module. * @see {@link RuntimeSDK} for more details. * @type {RuntimeSDK} */ readonly runtime = new RuntimeSDK(); /** * @public * @readonly * Access to the Ads SDK module. * @see {@link JoliboxAds} for more details. * @type {JoliboxAds} */ readonly ads = new JoliboxAds(); /** * @public * @readonly * Access to the Lifecycle SDK module. * @see {@link LifecycleSDK} for more details. * @type {LifecycleSDK} */ readonly lifecycle = new LifecycleSDK(); /** * @private * @readonly * Access to the Storage SDK module. * @see {@link StorageSDK} for more details. * @type {StorageSDK} */ readonly storage = new StorageSDK(); /** * @private * @readonly * Access to the Keyboard SDK module. * @see {@link KeyboardSDK} for more details. * @type {KeyboardSDK} */ readonly keyboard = new KeyboardSDK(); /** * @public * @readonly * Access to the Task Tracker SDK module. * @see {@link TaskTrackerSDK} for more details. * @type {TaskTrackerSDK} */ readonly task = new TaskTrackerSDK(); /** * @private * @readonly * Access to the Router SDK module. * @see {@link RouterSDK} for more details. * @type {RouterSDK} */ readonly router = new RouterSDK(); /** * @private * @readonly * Access to the Payment SDK module. * @see {@link PaymentSDK} for more details. * @type {PaymentSDK} */ readonly payment = new PaymentSDK(); /** * @public * @readonly * Access to the Rewards SDK module. * @see {@link RewardsSDK} for more details. * @type {RewardsSDK} */ readonly rewards = new RewardsSDK(); //global API /** * @public * Synchronously gets system information. * @see {@link getSystemInfoSync} for more details. * @returns {ISystemInfo} The system information. */ getSystemInfoSync = getSystemInfoSync.bind(this); /** * @public * Checks if a specific API, component, or capability is available in the current environment. * @see {@link canIUse} for more details. * @param {string} schema - The schema string to check (e.g., "component.button", "api.request"). * @returns {boolean} True if available, false otherwise. */ canIUse = canIUse.bind(this); /** * @public * Initiates the login process. * @see {@link login} for more details. * @returns {Promise} A promise that resolves with login success data. */ login = login.bind(this); /** * @public * Checks the current session status. * @see {@link checkSession} for more details. * @returns {Promise} A promise that resolves with session status data. */ checkSession = checkSession.bind(this); /** * @private * Makes an HTTP request. * @see {@link request} for more details. * @param {IRequestParams} params - Parameters for the HTTP request. * @returns {Promise} A promise that resolves with the request response. */ request = request.bind(this); /** * @public * Registers a listener for a custom event. * @see {@link onCustomEvent} for more details. * @param {string} eventName - The name of the event to listen for. * @param {(data: any) => void} callback - The callback function to execute when the event is triggered. */ on = onCustomEvent.bind(this); /** * @public * Unregisters a listener for a custom event. * @see {@link offCustomEvent} for more details. * @param {string} eventName - The name of the event. * @param {(data: any) => void} [callback] - The specific callback to remove. If not provided, all listeners for the event are removed. */ off = offCustomEvent.bind(this); /** * @public * Registers a one-time listener for a custom event. The listener is automatically removed after being invoked once. * @see {@link onceCustomEvent} for more details. * @param {string} eventName - The name of the event to listen for. * @param {(data: any) => void} callback - The callback function to execute. */ once = onceCustomEvent.bind(this); /** * @private */ isNativeSupport = isNativeSupport.bind(this); /** * @private * Calls a host method. * @see {@link callHostMethod} for more details. * @param {ICallHostMethodParams} params - Parameters for the host method. * @returns {Promise} A promise that resolves with the host method response. */ callHostMethod = callHostMethod.bind(this); /** * @private * Track a event. * @see {@link track} for more details. * @param {ITrackParams} params - Parameters for the track. * @returns {Promise} A promise that resolves with the host method response. */ track = track.bind(this); /** * @public * Constructs a new JoliboxSDK instance or returns the existing singleton instance. */ constructor() { if (JoliboxSDK.instance) { return JoliboxSDK.instance; } window.joliboxsdk = { runtime: this.runtime, ads: this.ads, lifecycle: this.lifecycle, storage: this.storage, keyboard: this.keyboard, task: this.task, router: this.router }; JoliboxSDK.instance = this; console.log(`JoliboxSDK ${this.jssdkVersion} init`); } /** * @public * Gets the singleton instance of the JoliboxSDK. * @returns {JoliboxSDK} The singleton JoliboxSDK instance. */ public static getInstance(): JoliboxSDK { if (!JoliboxSDK.instance) { JoliboxSDK.instance = new JoliboxSDK(); } return JoliboxSDK.instance; } } window.JoliboxSDK = JoliboxSDK;