UNPKG

@perceptr/web-sdk

Version:

Perceptr Web SDK for recording and monitoring user sessions

53 lines (52 loc) 1.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const SessionCore_1 = require("./SessionCore"); const logger_1 = require("./utils/logger"); class PerceptrSDK { constructor() { this.initialized = false; // Private constructor to prevent direct instantiation } static getInstance() { if (!PerceptrSDK.instance) { PerceptrSDK.instance = new PerceptrSDK(); } return PerceptrSDK.instance; } init(config) { if (this.initialized) { logger_1.logger.forceLog("warn", "SDK already initialized"); return; } this.core = new SessionCore_1.Core(config); this.initialized = true; logger_1.logger.configure({ debug: !!config.debug }); } start() { this.ensureInitialized(); return this.core.start(); } stop() { this.ensureInitialized(); return this.core.stop(); } pause() { this.ensureInitialized(); this.core.pause(); } resume() { this.ensureInitialized(); this.core.resume(); } identify(distinctId, traits = {}) { this.ensureInitialized(); return this.core.identify(distinctId, traits); } ensureInitialized() { if (!this.initialized) { throw new Error("[SDK] SDK not initialized. Call init() first"); } } } // Export a singleton instance exports.default = PerceptrSDK.getInstance();