import { canIUse } from '@/api'; import { createCommands, EventEmitter } from '@jolibox/common'; import { ResponseType } from '@jolibox/types'; export interface BaseSDKEventMap { _baseSDKMarker?: never; } export abstract class BaseSDK { /** * @private * Instance for executing commands. Intended for internal SDK use. */ readonly commands = createCommands(); /** * @private * Event emitter instance for handling internal events. Intended for internal SDK use. */ readonly _emitter = new EventEmitter(); addEventListener(event: K, callback: (data: T[K]) => void) { this._emitter.on(event, (...args) => callback(args[0] as T[K])); } triggerEvent(event: K, params: T[K]) { this._emitter.emit(event, params); } canUse(command: string) { return canIUse(command); } canIUseIfThrow(command: string) { if (!this.canUse(command)) { return { code: 'FAILURE' as ResponseType, message: `[Jolibox SDK] ${command} is not supported in this platform` }; } } }