UNPKG

@flagship.io/js-sdk

Version:
1,280 lines (1,231 loc) 311 kB
import * as __WEBPACK_EXTERNAL_MODULE_events__ from "events"; /******/ var __webpack_modules__ = ({ /***/ 121: /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ VisitorEvent: () => (/* binding */ VisitorEvent) /* harmony export */ }); class VisitorEvent { _customerAccountId; _visitorId; _currentUrl; _clickPath; _clickPosition; _screenSize; _scrollPosition; get customerAccountId() { return this._customerAccountId; } get visitorId() { return this._visitorId; } get currentUrl() { return this._currentUrl; } get clickPath() { return this._clickPath; } get clickPosition() { return this._clickPosition; } get screenSize() { return this._screenSize; } get scrollPosition() { return this._scrollPosition; } constructor({ customerAccountId, visitorId, currentUrl, clickPath, clickPosition, screenSize, scrollPosition }) { this._customerAccountId = customerAccountId; this._visitorId = visitorId; this._currentUrl = currentUrl; this._clickPath = clickPath; this._clickPosition = clickPosition; this._screenSize = screenSize; this._scrollPosition = scrollPosition; } toApiKeys() { const apiKeys = { cid: this._customerAccountId, vid: this._visitorId, dl: this._currentUrl, sr: this._screenSize, t: 'VISITOREVENT' }; if (this._clickPath) { apiKeys.cp = this._clickPath; } if (this._clickPosition) { apiKeys.cpo = this._clickPosition; } if (this._scrollPosition) { apiKeys.sp = this._scrollPosition; } return apiKeys; } } /***/ }), /***/ 221: /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ PageView: () => (/* binding */ PageView) /* harmony export */ }); class PageView { _customerAccountId; _visitorId; _hasAdBlocker; _screenDepth; _screenSize; _doNotTrack; _fonts; _hasFakeBrowserInfos; _hasFakeLanguageInfos; _hasFakeOsInfos; _hasFakeResolutionInfos; _userLanguage; _deviceCategory; _pixelRatio; _plugins; _documentReferer; _viewportSize; _touchSupport; _currentUrl; _userAgent; _customerUserId; _timezoneOffset; _eventCategory; get customerAccountId() { return this._customerAccountId; } get visitorId() { return this._visitorId; } get hasAdBlocker() { return this._hasAdBlocker; } get screenDepth() { return this._screenDepth; } get screenSize() { return this._screenSize; } get doNotTrack() { return this._doNotTrack; } get fonts() { return this._fonts; } get hasFakeBrowserInfos() { return this._hasFakeBrowserInfos; } get hasFakeLanguageInfos() { return this._hasFakeLanguageInfos; } get hasFakeOsInfos() { return this._hasFakeOsInfos; } get hasFakeResolutionInfos() { return this._hasFakeResolutionInfos; } get userLanguage() { return this._userLanguage; } get deviceCategory() { return this._deviceCategory; } get pixelRatio() { return this._pixelRatio; } get plugins() { return this._plugins; } get documentReferer() { return this._documentReferer; } get viewportSize() { return this._viewportSize; } get touchSupport() { return this._touchSupport; } get currentUrl() { return this._currentUrl; } get userAgent() { return this._userAgent; } get customerUserId() { return this._customerUserId; } get timezoneOffset() { return this._timezoneOffset; } get eventCategory() { return this._eventCategory; } constructor({ customerAccountId, visitorId, hasAdBlocker, screenDepth, screenSize, doNotTrack, fonts, hasFakeBrowserInfos, hasFakeLanguageInfos, hasFakeOsInfos, hasFakeResolutionInfos, userLanguage, deviceCategory, pixelRatio, plugins, documentReferer, viewportSize, touchSupport, currentUrl, userAgent, customerUserId, timezoneOffset, eventCategory }) { this._customerAccountId = customerAccountId; this._visitorId = visitorId; this._hasAdBlocker = hasAdBlocker; this._screenDepth = screenDepth; this._screenSize = screenSize; this._doNotTrack = doNotTrack; this._fonts = fonts; this._hasFakeBrowserInfos = hasFakeBrowserInfos; this._hasFakeLanguageInfos = hasFakeLanguageInfos; this._hasFakeOsInfos = hasFakeOsInfos; this._hasFakeResolutionInfos = hasFakeResolutionInfos; this._userLanguage = userLanguage; this._deviceCategory = deviceCategory; this._pixelRatio = pixelRatio; this._plugins = plugins; this._documentReferer = documentReferer; this._viewportSize = viewportSize; this._touchSupport = touchSupport; this._currentUrl = currentUrl; this._userAgent = userAgent; this._customerUserId = customerUserId; this._timezoneOffset = timezoneOffset; this._eventCategory = eventCategory; } toApiKeys() { const apiKeys = { cid: this._customerAccountId, vid: this._visitorId, adb: this._hasAdBlocker, sd: this._screenDepth, sr: this._screenSize, dnt: this._doNotTrack, fnt: this._fonts, hlb: this._hasFakeBrowserInfos, hll: this._hasFakeLanguageInfos, hlo: this._hasFakeOsInfos, hlr: this._hasFakeResolutionInfos, ul: this._userLanguage, dc: this._deviceCategory, pxr: this._pixelRatio, dr: this._documentReferer, vp: this._viewportSize, tof: this._timezoneOffset, tsp: this._touchSupport, dl: this._currentUrl, ua: this._userAgent, ec: this._eventCategory, t: 'PAGEVIEW' }; if (this._plugins) { apiKeys.plu = this._plugins; } if (this._customerUserId) { apiKeys.cuid = this._customerUserId; } return apiKeys; } } /***/ }), /***/ 259: /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ ABTastyQAEventBus: () => (/* binding */ ABTastyQAEventBus) /* harmony export */ }); /* harmony import */ var _depsNode_native__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(551); /* harmony import */ var _common_types__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(461); /** * Global, type-safe Event Bus for QA Assistant ↔ SDK communication. * Implements singleton pattern to ensure a single shared instance. */ class QAEventBus extends _depsNode_native__WEBPACK_IMPORTED_MODULE_0__.EventEmitter { static instance; /** * SDK and QA Assistant modules. */ constructor() { super(); this.setMaxListeners(100); } /** * Return the singleton instance of the QAEventBus. * * Usage: * const bus = QAEventBus.getInstance(); */ static getInstance() { if (!QAEventBus.instance) { QAEventBus.instance = new QAEventBus(); } return QAEventBus.instance; } /** * Emit a QA event (typed across both directions). * * @template K - Key of QAEventMap * @param event - Event name (union of QAAToSDKEvents | SDKToQAAEvents) * @param data - Payload associated with the event */ emitQAEvent(event, data) { this.emit(event, data); } /** * Emit an event originating from the QA Assistant to the SDK. * * @template K - Key of QAAToSDKEvents * @param event - Event name in QAAToSDKEvents * @param data - Payload for the SDK listener */ emitQAEventToSDK(event, data) { this.emit(event, data); } /** * Emit an event originating from the SDK to the QA Assistant. * * @template K - Key of SDKToQAAEvents * @param event - Event name in SDKToQAAEvents * @param data - Payload for the QA Assistant listener */ emitQAEventToQAA(event, data) { this.emit(event, data); } /** * Register a typed listener for any QA event (both directions). * * Returns a cleanup function that removes the registered listener. * * @template K - Key of QAEventMap * @param event - Event name * @param listener - Callback invoked with the event payload * @returns cleanup function to remove this listener */ onQAEvent(event, listener) { this.on(event, listener); // Return cleanup function return () => this.off(event, listener); } /** * Register a typed listener for events coming from the QA Assistant to the SDK. * * Returns a cleanup function that removes the registered listener. * * @template K - Key of SDKToQAAEvents * @param event - Event name from the QA Assistant * @param listener - Callback invoked with the event payload * @returns cleanup function to remove this listener */ onQAEventFromSDK(event, listener) { this.on(event, listener); // Return cleanup function return () => this.off(event, listener); } /** * Register a typed listener for events coming from the SDK to the QA Assistant. * * Returns a cleanup function that removes the registered listener. * * @template K - Key of QAAToSDKEvents * @param event - Event name from the SDK * @param listener - Callback invoked with the event payload * @returns cleanup function to remove this listener */ onQAEventFromQAA(event, listener) { this.on(event, listener); // Return cleanup function return () => this.off(event, listener); } /** * Remove a specific typed listener for a QA event. * * @template K - Key of QAEventMap * @param event - Event name * @param listener - Previously registered listener to remove */ offQAEvent(event, listener) { this.off(event, listener); } /** * Remove all listeners for a given QA event. * * @template K - Key of QAEventMap * @param event - Event name to clear listeners for */ removeAllListenersForEvent(event) { this.removeAllListeners(event); } /** * Quick check to determine if QA Assistant is currently active/listening. * * @returns true if there are active listeners for QA events, false otherwise */ isQAActive() { return this.listenerCount(_common_types__WEBPACK_IMPORTED_MODULE_1__.QAEventSdkName.SDK_ALLOCATED_VARIATIONS) > 0; } } const ABTastyQAEventBus = QAEventBus.getInstance(); /***/ }), /***/ 290: /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ sendFsHitToQA: () => (/* binding */ sendFsHitToQA), /* harmony export */ sendVisitorAllocatedVariations: () => (/* binding */ sendVisitorAllocatedVariations), /* harmony export */ sendVisitorExposedVariations: () => (/* binding */ sendVisitorExposedVariations) /* harmony export */ }); /* harmony import */ var _common_types__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(461); /* harmony import */ var _QAEventBus__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(259); function sendVisitorAllocatedVariations(visitorVariationState) { if (!visitorVariationState?.visitorVariations) { return; } _QAEventBus__WEBPACK_IMPORTED_MODULE_0__.ABTastyQAEventBus.emitQAEventToQAA(_common_types__WEBPACK_IMPORTED_MODULE_1__.QAEventSdkName.SDK_ALLOCATED_VARIATIONS, { value: visitorVariationState.visitorVariations, visitorData: visitorVariationState.visitorData, sdkInfo: visitorVariationState.sdkInfo }); } function sendVisitorExposedVariations(visitorVariationState) { if (!visitorVariationState?.exposedVariations) { return; } const navigationDetected = visitorVariationState.navigationDetected; if (visitorVariationState.navigationDetected) { visitorVariationState.navigationDetected = false; } _QAEventBus__WEBPACK_IMPORTED_MODULE_0__.ABTastyQAEventBus.emitQAEventToQAA(_common_types__WEBPACK_IMPORTED_MODULE_1__.QAEventSdkName.SDK_EXPOSED_VARIATIONS, { value: visitorVariationState.exposedVariations, param: navigationDetected ? _common_types__WEBPACK_IMPORTED_MODULE_1__.VisitorVariationUpdateParam.NewNavigation : undefined }); } function sendFsHitToQA(hit) { const hitWithTimestamps = hit.map(item => { return { ...item, timestamp: Date.now() - item.qt }; }); _QAEventBus__WEBPACK_IMPORTED_MODULE_0__.ABTastyQAEventBus.emitQAEventToQAA(_common_types__WEBPACK_IMPORTED_MODULE_1__.QAEventSdkName.SDK_HIT_SENT, { value: hitWithTimestamps }); } /***/ }), /***/ 461: /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ QAEventQaAssistantName: () => (/* binding */ QAEventQaAssistantName), /* harmony export */ QAEventSdkName: () => (/* binding */ QAEventSdkName), /* harmony export */ VisitorVariationUpdateParam: () => (/* binding */ VisitorVariationUpdateParam) /* harmony export */ }); var VisitorVariationUpdateParam; (function (VisitorVariationUpdateParam) { VisitorVariationUpdateParam["NewNavigation"] = "newNavigation"; })(VisitorVariationUpdateParam || (VisitorVariationUpdateParam = {})); var QAEventSdkName; (function (QAEventSdkName) { QAEventSdkName["SDK_ALLOCATED_VARIATIONS"] = "sdk:allocated-variations"; QAEventSdkName["SDK_EXPOSED_VARIATIONS"] = "sdk:exposed-variations"; QAEventSdkName["SDK_HIT_SENT"] = "sdk:hit-sent"; })(QAEventSdkName || (QAEventSdkName = {})); var QAEventQaAssistantName; (function (QAEventQaAssistantName) { QAEventQaAssistantName["QA_READY"] = "qa:ready"; QAEventQaAssistantName["QA_CLOSE"] = "qa:close"; QAEventQaAssistantName["QA_RESET_FORCED_VARIATIONS"] = "qa:reset-forced-variations"; QAEventQaAssistantName["QA_MINIMIZE_QA_ASSISTANT"] = "qa:minimize-qa-assistant"; QAEventQaAssistantName["QA_TRIGGER_RENDER"] = "qa:trigger-render"; QAEventQaAssistantName["QA_APPLY_FORCED_VARIATIONS"] = "qa:apply-forced-variations"; QAEventQaAssistantName["QA_APPLY_FORCED_ALLOCATION"] = "qa:apply-forced-allocation"; QAEventQaAssistantName["QA_APPLY_FORCED_UNALLOCATION"] = "qa:apply-forced-unallocation"; QAEventQaAssistantName["QA_REMOVE_FORCED_VARIATION"] = "qa:remove-forced-variation"; })(QAEventQaAssistantName || (QAEventQaAssistantName = {})); /***/ }), /***/ 551: /***/ ((module, __unused_webpack_exports, __webpack_require__) => { var x = (y) => { var x = {}; __webpack_require__.d(x, y); return x } var y = (x) => (() => (x)) module.exports = x({ ["EventEmitter"]: () => (__WEBPACK_EXTERNAL_MODULE_events__.EventEmitter) }); /***/ }), /***/ 777: /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ sendFsHitToQA: () => (/* binding */ sendFsHitToQA), /* harmony export */ sendVisitorAllocatedVariations: () => (/* binding */ sendVisitorAllocatedVariations), /* harmony export */ sendVisitorExposedVariations: () => (/* binding */ sendVisitorExposedVariations) /* harmony export */ }); /* harmony import */ var _mobile_handleSdkMessage__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(290); function sendVisitorAllocatedVariations(visitorVariationState) { if (false) {} if (true) { (0,_mobile_handleSdkMessage__WEBPACK_IMPORTED_MODULE_0__.sendVisitorAllocatedVariations)(visitorVariationState); } } function sendVisitorExposedVariations(visitorVariationState) { if (false) {} if (true) { (0,_mobile_handleSdkMessage__WEBPACK_IMPORTED_MODULE_0__.sendVisitorExposedVariations)(visitorVariationState); } } function sendFsHitToQA(hit) { if (false) {} if (true) { (0,_mobile_handleSdkMessage__WEBPACK_IMPORTED_MODULE_0__.sendFsHitToQA)(hit); } } /***/ }) /******/ }); /************************************************************************/ /******/ // The module cache /******/ var __webpack_module_cache__ = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ // Check if module is in cache /******/ var cachedModule = __webpack_module_cache__[moduleId]; /******/ if (cachedModule !== undefined) { /******/ return cachedModule.exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = __webpack_module_cache__[moduleId] = { /******/ // no module.id needed /******/ // no module.loaded needed /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /************************************************************************/ /******/ /* webpack/runtime/define property getters */ /******/ (() => { /******/ // define getter functions for harmony exports /******/ __webpack_require__.d = (exports, definition) => { /******/ for(var key in definition) { /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); /******/ } /******/ } /******/ }; /******/ })(); /******/ /******/ /* webpack/runtime/hasOwnProperty shorthand */ /******/ (() => { /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) /******/ })(); /******/ /******/ /* webpack/runtime/make namespace object */ /******/ (() => { /******/ // define __esModule on exports /******/ __webpack_require__.r = (exports) => { /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); /******/ } /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ })(); /******/ /************************************************************************/ var __webpack_exports__ = {}; // EXPORTS __webpack_require__.d(__webpack_exports__, { ABTastyQAEventBus: () => (/* reexport */ QAEventBus.ABTastyQAEventBus), ABTastyWebSDKPostMessageType: () => (/* reexport */ ABTastyWebSDKPostMessageType), APP_VERSION_CODE: () => (/* reexport */ APP_VERSION_CODE), APP_VERSION_NAME: () => (/* reexport */ APP_VERSION_NAME), CARRIER_NAME: () => (/* reexport */ CARRIER_NAME), CacheStrategy: () => (/* reexport */ CacheStrategy), DEVICE_LOCALE: () => (/* reexport */ DEVICE_LOCALE), DEVICE_MODEL: () => (/* reexport */ DEVICE_MODEL), DEVICE_TYPE: () => (/* reexport */ DEVICE_TYPE), DecisionApiConfig: () => (/* reexport */ DecisionApiConfig), DecisionMode: () => (/* reexport */ DecisionMode), EventCategory: () => (/* reexport */ EventCategory), FLAGSHIP_CLIENT: () => (/* reexport */ FLAGSHIP_CLIENT), FLAGSHIP_CONTEXT: () => (/* reexport */ FLAGSHIP_CONTEXT), FLAGSHIP_VERSION: () => (/* reexport */ FLAGSHIP_VERSION), FLAGSHIP_VISITOR: () => (/* reexport */ FLAGSHIP_VISITOR), FSFetchReasons: () => (/* reexport */ FSFetchReasons), FSFetchStatus: () => (/* reexport */ FSFetchStatus), FSFlag: () => (/* reexport */ FSFlag), FSFlagCollection: () => (/* reexport */ FSFlagCollection), FSFlagMetadata: () => (/* reexport */ FSFlagMetadata), FSFlagStatus: () => (/* reexport */ FSFlagStatus), FSSdkStatus: () => (/* reexport */ FSSdkStatus), Flagship: () => (/* reexport */ Flagship), HitType: () => (/* reexport */ HitType), INTERFACE_NAME: () => (/* reexport */ INTERFACE_NAME), INTERNET_CONNECTION: () => (/* reexport */ INTERNET_CONNECTION), IP: () => (/* reexport */ IP), LOCATION_CITY: () => (/* reexport */ LOCATION_CITY), LOCATION_COUNTRY: () => (/* reexport */ LOCATION_COUNTRY), LOCATION_LAT: () => (/* reexport */ LOCATION_LAT), LOCATION_LONG: () => (/* reexport */ LOCATION_LONG), LOCATION_REGION: () => (/* reexport */ LOCATION_REGION), LogLevel: () => (/* reexport */ LogLevel), OS_NAME: () => (/* reexport */ OS_NAME), OS_VERSION_CODE: () => (/* reexport */ OS_VERSION_CODE), OS_VERSION_NAME: () => (/* reexport */ OS_VERSION_NAME), QAEventQaAssistantName: () => (/* reexport */ types.QAEventQaAssistantName), QAEventSdkName: () => (/* reexport */ types.QAEventSdkName), TargetingOperator: () => (/* reexport */ TargetingOperator), TroubleshootingLabel: () => (/* reexport */ TroubleshootingLabel), Visitor: () => (/* reexport */ Visitor), VisitorCacheStatus: () => (/* reexport */ VisitorCacheStatus), VisitorVariationUpdateParam: () => (/* reexport */ types.VisitorVariationUpdateParam), "default": () => (/* binding */ src) }); // EXTERNAL MODULE: external "events" var external_events_ = __webpack_require__(551); ;// ./src/sdkVersion.ts // Generated by genversion. const sdkVersion_version = '5.2.1'; ;// ./src/enum/FlagshipConstant.ts /** * SDK language */ const SDK_INFO = { name: 'TypeScript', version: sdkVersion_version, tag: 'flagship-ts-sdk' }; /** * Default request timeout in second */ const REQUEST_TIME_OUT = 2; const FETCH_FLAG_BUFFERING_DEFAULT_TIME = 2; const DEFAULT_DEDUPLICATION_TIME = 2.5; const DEFAULT_POLLING_INTERVAL = 5; const DEFAULT_SERVER_TIME_INTERVAL = 10; const DEFAULT_SERVER_POOL_MAX_SIZE = 100; const DEFAULT_BROWSER_TIME_INTERVAL = 5; const DEFAULT_BROWSER_POOL_MAX_SIZE = 10; const BATCH_MAX_SIZE = 2500000; const ANALYTIC_HIT_ALLOCATION = 1; const MAX_COLLECTING_TIME_MS = 30000; const MAX_LAST_COLLECTING_TIME_MS = 120000; const MAX_CLICK_PATH_LENGTH = 1900; const MAX_SCORING_POLLING_TIME = 120000; const SCROLL_END_DELAY_MS = 200; const CLICK_PATH_DELAY_MS = 500; const SCORING_INTERVAL = 5000; /** * Decision api base url */ const BASE_API_URL = 'https://decision.flagship.io/v2/'; const HIT_API_URL = 'https://ariane.abtasty.com'; const HIT_EVENT_URL = 'https://events.flagship.io'; const TROUBLESHOOTING_HIT_URL = 'https://events.flagship.io/troubleshooting'; const USAGE_HIT_URL = 'https://events.flagship.io/analytics'; const BUCKETING_API_URL = 'https://cdn.flagship.io/{0}/bucketing.json'; const BUCKETING_API_CONTEXT_URL = 'https://decision.flagship.io/v2/{0}/events'; const THIRD_PARTY_SEGMENT_URL = 'https://api-data-connector.flagship.io/accounts/{0}/segments/{1}'; const HIT_CONSENT_URL = 'https://ariane.abtasty.com'; const URL_CAMPAIGNS = '/campaigns'; const URL_ACTIVATE_MODIFICATION = 'activate'; const QA_ASSISTANT_PROD_URL = 'https://qa-assistant.flagship.io/bundle.js'; const QA_ASSISTANT_STAGING_URL = 'https://staging-qa-assistant.flagship.io/bundle.js'; const QA_ASSISTANT_LOCAL_URL = 'https://local-qa-assistant.flagship.io:5000/bundle.js'; const FS_QA_ASSISTANT = 'fs_qa_assistant'; const FS_QA_ASSISTANT_STAGING = 'fs_qa_assistant_staging'; const FS_QA_ASSISTANT_LOCAL = 'fs_qa_assistant_local'; const TAG_QA_ASSISTANT = 'abtasty_qa_assistant'; const TAG_QA_ASSISTANT_STAGING = 'abtasty_qa_assistant_staging'; const TAG_QA_ASSISTANT_LOCAL = 'abtasty_qa_assistant_local'; const TAG_QA_URL = 'qa-assistant.abtasty.com'; const FS_QA_URL = 'qa-assistant.flagship.io'; const EXPOSE_ALL_KEYS = 'exposeAllKeys'; const SEND_CONTEXT_EVENT = 'sendContextEvent'; const FS_CONSENT = 'fs_consent'; const FS_IS_QA_MODE_ENABLED = 'FS_IS_QA_MODE_ENABLED'; const FS_FORCED_VARIATIONS = 'FS_FORCED_VARIATIONS'; const FS_QA_ASSISTANT_SCRIPT_TAG_ID = 'FS_QA_ASSISTANT_SCRIPT_TAG_ID'; const FS_VARIATIONS_FORCED_ALLOCATION = 'FS_VARIATIONS_FORCED_ALLOCATION'; const FS_VARIATIONS_FORCED_UNALLOCATION = 'FS_VARIATIONS_FORCED_UNALLOCATION'; const EMOTION_AI_UC_URL = 'https://uc-info.flagship.io/v1/segments/clients/{0}/visitors/{1}'; const CDN_ACCOUNT_SETTINGS_URL = 'https://cdn.flagship.io/{0}/accountSettings.json'; const VISITOR_EAI_SCORE_KEY = '{0}_EAIScore'; const EMOTION_AI_EVENT_URL = 'https://events.flagship.io/emotionsai'; const SEND_EAI_EVENT = 'sendEAIEvent'; const SEND_EAI_EVENT_ERROR = 'Failed to send Emotion AI event: {0}'; const SEND_EAI_EVENT_SUCCESS = 'Emotion AI event sent: {0}'; const FETCH_EAI_SCORE = 'fetchEAIScore'; const FETCH_EAI_SCORE_ERROR = 'visitor {0}, Failed to fetch EAIScore: {1}'; const FETCH_EAI_SCORE_SUCCESS = 'visitor {0}, EAIScore fetched: {1}'; const EAI_SCORE_CONTEXT_KEY = 'eai::eas'; const CLIENT_CACHE_KEY = 'FS_CLIENT_VISITOR'; /** * SDK version */ const SDK_VERSION = (/* unused pure expression or super */ null && (version)); const VISITOR_CACHE_VERSION = 1; const HIT_CACHE_VERSION = 1; const DEFAULT_HIT_CACHE_TIME_MS = 14400000; const MAX_ACTIVATE_HIT_PER_BATCH = 100; /** * Message Info */ const SDK_STARTED_INFO = 'Flagship SDK (version: {0}) {1} in **{2}** mode'; const FLAGSHIP_SDK = 'Flagship SDK'; const EMIT_READY = 'ready'; const EMIT_STATUS = 'status'; const NO_BATCHING_WITH_CONTINUOUS_CACHING_STRATEGY = 3; const JS_DOC_URL = 'https://docs.developers.flagship.io/docs/js-v3'; const PANIC_MODE_DOC_URL = 'https://docs.developers.flagship.io/docs/glossary#panic-mode'; /** * Message Error */ const INITIALIZATION_PARAM_ERROR = `Params 'envId' and 'apiKey' must not be null or empty. Learn more: ${JS_DOC_URL}#initialization`; const ERROR = 'error'; const CONTEXT_NULL_ERROR = 'Context must not to be null'; const CONTEXT_PARAM_ERROR = "params {0} must be a non null String, and 'value' must be one of the following types , Number, Boolean"; const GET_MODIFICATION_CAST_ERROR = 'Modification for key {0} has a different type. Default value is returned.'; const GET_MODIFICATION_MISSING_ERROR = 'No modification for key {0}. Default value is returned.'; const GET_MODIFICATION_KEY_ERROR = 'Key {0} must not be null. Default value is returned.'; const ACTIVATE_MODIFICATION_KEY_ERROR = 'Key {0} must not be null, no activate will be sent.'; const GET_MODIFICATION_ERROR = 'No modification for key {0}.'; const GET_FLAG_ERROR = 'No flag for key {0}.'; const ACTIVATE_MODIFICATION_ERROR = 'No modification for key {0}, no activate will be sent.'; const DECISION_MANAGER_MISSING_ERROR = 'decisionManager must not be null.'; const TRACKER_MANAGER_MISSING_ERROR = 'trackerManager must not be null.'; const CURL_LIBRARY_IS_NOT_LOADED = 'curl library is not loaded'; const TYPE_ERROR = '{0} must be a {1}'; const TYPE_INTEGER_ERROR = 'value of {0} is not an {1}, it will be truncated to {1}'; const VISITOR_ID_ERROR = 'visitorId must not be null or empty'; const PANIC_MODE_ERROR = '{0} deactivated while panic mode is on.'; const METHOD_DEACTIVATED_CONSENT_ERROR = 'Method {0} is deactivated for visitor {1} : visitor did not consent.'; const METHOD_DEACTIVATED_ERROR = 'Visitor {0}, method {1} is deactivated while SDK status is: {2}.'; const METHOD_DEACTIVATED_SEND_CONSENT_ERROR = 'Send consent hit is deactivated while SDK status is: {1}.'; const TROUBLESHOOTING_HIT_ADDED_IN_QUEUE = 'The TROUBLESHOOTING HIT has been added to the pool queue : {0}'; const ANALYTICS_HIT_ADDED_IN_QUEUE = 'The USAGE HIT has been added to the pool queue : {0}'; const ACTIVATE_ADDED_IN_QUEUE = 'The ACTIVATE has been added to the pool queue : {0}'; const HIT_ADDED_IN_QUEUE = 'The HIT has been added into the pool queue : {0}'; const ADD_HIT = 'ADD HIT'; const ADD_TROUBLESHOOTING_HIT = 'ADD TROUBLESHOOTING HIT'; const ADD_USAGE_HIT = 'ADD USAGE HIT'; const ADD_ACTIVATE = 'ADD ACTIVATE'; const BATCH_SENT_SUCCESS = 'Batch hit has been sent : {0}'; const TROUBLESHOOTING_SENT_SUCCESS = 'Troubleshooting hit has been sent : {0}'; const ANALYTICS_HIT_SENT_SUCCESS = 'Usage hit has been sent : {0}'; const ACTIVATE_SENT_SUCCESS = 'Activate hit has been sent : {0}'; const SEND_BATCH = 'SEND BATCH'; const SEND_TROUBLESHOOTING = 'SEND TROUBLESHOOTING'; const SEND_USAGE_HIT = 'SEND USAGE HIT'; const SEND_ACTIVATE = 'SEND ACTIVATE'; const SEND_SEGMENT_HIT = 'SEND SEGMENT HIT'; const SEND_HIT = 'SEND HIT'; const EVENT_SUFFIX = 'events'; const FETCH_FLAGS_BUFFERING_MESSAGE = 'Visitor {0}, fetchFlags has been ignored and will continue to be ignored for the next {1}ms, this delay can be changed with `fetchFlagsBufferingTime` option in the SDK config'; const VISITOR_SYNC_FLAGS_MESSAGE = 'without calling `fetchFlags` method afterwards. So, the value of the flag `{1}` might be outdated'; const NEW_VISITOR_NOT_READY = `You can't create a new visitor without first calling the "Flagship.start" method. Learn more: ${JS_DOC_URL}#initialization `; const LOOKUP_HITS_JSON_OBJECT_ERROR = 'JSON DATA must fit the type HitCacheDTO'; const ACTIVATE_BATCH_LENGTH = 5; // Process const PROCESS = 'process'; const PROCESS_INITIALIZATION = 'INITIALIZATION'; const PROCESS_UPDATE_CONTEXT = 'UPDATE CONTEXT'; const PROCESS_GET_MODIFICATION = 'GET MODIFICATION'; const PROCESS_GET_MODIFICATION_INFO = 'GET MODIFICATION INFO'; const PROCESS_NEW_VISITOR = 'NEW VISITOR'; const PROCESS_ACTIVE_MODIFICATION = 'ACTIVE MODIFICATION'; const PROCESS_SYNCHRONIZED_MODIFICATION = 'SYNCHRONIZED MODIFICATION'; const PROCESS_SEND_HIT = 'ADD HIT'; const PROCESS_SEND_ACTIVATE = 'SEND ACTIVATE'; const PROCESS_GET_CAMPAIGNS = 'GET CAMPAIGNS'; const PROCESS_GET_ALL_MODIFICATION = 'GET ALL MODIFICATIONS'; const PROCESS_MODIFICATIONS_FOR_CAMPAIGN = 'GET MODIFICATION FOR CAMPAIGN'; const PROCESS_CACHE_HIT = 'CACHE HIT'; const PROCESS_FLUSH_HIT = 'FLUSH HIT'; const PROCESS_LOOKUP_HIT = 'LOOKUP HIT'; // Api items const BATCH = 'batch'; const CUSTOMER_ENV_ID_API_ITEM = 'cid'; const CUSTOMER_ENV_ID_API_ACTIVATE = 'cid'; const CUSTOMER_UID = 'cuid'; const ANONYMOUS_ID = 'aid'; const VISITOR_ID_API_ITEM = 'vid'; const VARIATION_GROUP_ID_API_ITEM = 'caid'; const VARIATION_GROUP_ID_API_ITEM_ACTIVATE = 'caid'; const VISITOR_CONSENT = 'vc'; const CAMPAIGN_ID = 'caid'; const VARIATION_ID_API_ITEM = 'vaid'; const DS_API_ITEM = 'ds'; const T_API_ITEM = 't'; const QT_API_ITEM = 'qt'; const QA_MODE_API_ITEM = 'qa'; const DL_API_ITEM = 'dl'; const SL_ITEM = 'sl'; const SDK_APP = 'APP'; const TID_API_ITEM = 'tid'; const TA_API_ITEM = 'ta'; const TT_API_ITEM = 'tt'; const TC_API_ITEM = 'tc'; const TCC_API_ITEM = 'tcc'; const ICN_API_ITEM = 'icn'; const SM_API_ITEM = 'sm'; const PM_API_ITEM = 'pm'; const TR_API_ITEM = 'tr'; const TS_API_ITEM = 'ts'; const IN_API_ITEM = 'in'; const IC_API_ITEM = 'ic'; const IP_API_ITEM = 'ip'; const IQ_API_ITEM = 'iq'; const IV_API_ITEM = 'iv'; const S_API_ITEM = 's'; const EVENT_CATEGORY_API_ITEM = 'ec'; const EVENT_ACTION_API_ITEM = 'ea'; const EVENT_LABEL_API_ITEM = 'el'; const EVENT_VALUE_API_ITEM = 'ev'; const USER_IP_API_ITEM = 'uip'; const SCREEN_RESOLUTION_API_ITEM = 'sr'; const USER_LANGUAGE = 'ul'; const SESSION_NUMBER = 'sn'; const HEADER_X_API_KEY = 'x-api-key'; const HEADER_X_ENV_ID = 'x-env-id'; const HEADER_CONTENT_TYPE = 'Content-Type'; const HEADER_X_SDK_CLIENT = 'x-sdk-client'; const HEADER_X_SDK_VERSION = 'x-sdk-version'; const HEADER_APPLICATION_JSON = 'application/json'; // Log const INITIALIZATION_STARTING = 'Flagship SDK version {0} is starting in {1} mode with config {2}'; const BUCKETING_POOLING_STARTED = 'Bucketing polling process has been started'; const BUCKETING_POOLING_STOPPED = 'Bucketing polling process has been stopped'; const PROCESS_BUCKETING = 'BUCKETING'; const POLLING_EVENT_200 = 'Polling event with code status 200 : {0}'; const POLLING_EVENT_300 = 'Polling event with code status 304'; const POLLING_EVENT_FAILED = 'Polling event failed with error'; const PROCESS_SDK_STATUS = 'SDK STATUS'; const SDK_STATUS_CHANGED = 'SDK status has changed: {0}'; const SAVE_VISITOR_INSTANCE = 'Visitor {0} has been saved in SDK instance'; const VISITOR_CREATED = 'Visitor {0} has been created with context {1}, isAuthenticated:{2} and hasConsented {3}'; const VISITOR_PROFILE_LOADED = 'Visitor profile has been loaded {0}'; const VISITOR_ID_FROM_AB_TASTY_TAG = "The visitor ID '{0}' has been retrieved from ABTasty tag"; const VISITOR_ID_GENERATED = 'Visitor identifier is empty. A UUID {0} has been generated.'; const PREDEFINED_CONTEXT_LOADED = 'Predefined Context have been loaded {0}'; const CONTEXT_KEY_ERROR = `Visitor {0}, the key '{1}' must be a non null String. Learn more: ${JS_DOC_URL}#updating-the-visitor-context`; const CONTEXT_VALUE_ERROR = `Visitor {0}, 'value' for key '{1}[], must be one of the following types : String, Number, Boolean Learn more: ${JS_DOC_URL}#updating-the-visitor-context`; const PREDEFINED_CONTEXT_TYPE_ERROR = `visitor {0}, Predefined Context {0} must be of type {1} Learn more: ${JS_DOC_URL}#predefined-user-context-keys-`; const CONTEXT_KEY_VALUE_UPDATE = 'visitor `{0}`, context have been updated: key {1}, value {2}, Context {3}'; const CONTEXT_OBJET_PARAM_UPDATE = 'visitor `{0}`, context have been updated: key/value {1}, Context {2}'; const CLEAR_CONTEXT = 'visitor `{0}`, context has been cleared cleared `{1}`'; const PROCESS_CLEAR_CONTEXT = 'CLEAR_CONTEXT'; const CONSENT_CHANGED = 'Visitor `{0}` consent has been changed : {1}'; const PROCESS_SET_CONSENT = 'SET_CONSENT'; const FETCH_CAMPAIGNS_SUCCESS = 'Visitor {0}, anonymousId {1} with context {2} has just fetched campaigns {3} in {4} ms'; const FETCH_CAMPAIGNS_FROM_CACHE = 'Visitor {0}, anonymousId {1} with context {2} has just fetched campaigns from cache {3} in {4} ms'; const FETCH_FLAGS_FROM_CAMPAIGNS = 'Visitor {0}, anonymousId {1} with context {2} has just fetched flags {3} from Campaigns'; const FETCH_FLAGS_STARTED = 'visitor `{0}` fetchFlags process is started'; const FETCH_FLAGS_PANIC_MODE = 'Panic mode is enabled : all feature are disabled except fetchFlags.'; const PROCESS_FETCHING_FLAGS = 'FETCH_FLAGS'; const GET_FLAG_MISSING_ERROR = 'For the visitor "{0}", no flags were found with the key "{1}". Therefore, the default value "{2}" has been returned.'; const GET_FLAG_NOT_FOUND = 'For the visitor "{0}", no flags were found with the key "{1}". Therefore, an empty flag has been returned.'; const FETCH_FLAGS_MISSING = 'Visitor {0} has {1} without calling fetchFlags method, '; const FLAG_VALUE = 'FLAG_VALUE'; const GET_FLAG = 'GET_FLAG'; const GET_FLAG_CAST_ERROR = 'For the visitor "{0}", the flag with key "{1}" has a different type compared to the default value. Therefore, the default value "{2}" has been returned.'; const GET_FLAG_VALUE = 'Visitor {0}, Flag for key {1} returns value {2}'; const USER_EXPOSED_FLAG_ERROR = 'For the visitor "{0}", no flags were found with the key "{1}". As a result, user exposure will not be sent.'; const VISITOR_EXPOSED_VALUE_NOT_CALLED = 'For the visitor `{0}`,assuming the getValue() method has not previously been invoked for the flag `{0}`. Therefore, the exposure is canceled'; const FLAG_VISITOR_EXPOSED = 'FLAG_VISITOR_EXPOSED'; const USER_EXPOSED_CAST_ERROR = 'For the visitor `{0}, the flag with the key `{0}` has a different type compared to the default value. Therefore, the exposure is interrupted'; const GET_METADATA_CAST_ERROR = 'Visitor {0}, Flag for key {1} has a different type with default value: Empty metadata object is returned {2}'; const FLAG_METADATA = 'FLAG_METADATA'; const NO_FLAG_METADATA = 'Visitor {0}, No Flags found for key {1}: Empty metadata object is returned'; const METADATA_SDK_NOT_READY = `Visitor {0}, Flag for key {1} Method Flag.metadata is deactivated while SDK status is NOT_READY: Empty metadata object is returned {2} Learn more: ${JS_DOC_URL}#getting-flags-campaigns-metadata`; const METADATA_PANIC_MODE = `Visitor {0}, Flag for key {1} Method Flag.metadata is deactivated while SDK status is PANIC: Empty metadata object is returned {2} Learn more: ${PANIC_MODE_DOC_URL}`; const AUTHENTICATE = 'AUTHENTICATE'; const VISITOR_AUTHENTICATE = 'The visitor is authenticated with new visitor ID {0} anonymous ID {1}'; const VISITOR_ALREADY_AUTHENTICATE = 'The visitor is already authenticated with visitor ID {0}'; const METHOD_DEACTIVATED_BUCKETING_ERROR = 'Visitor {0}, Method {1} is deactivated on Bucketing mode'; const VISITOR_AUTHENTICATE_VISITOR_ID_ERROR = `Visitor {0}, visitorId must not be null or empty Learn more: ${JS_DOC_URL}#authenticate`; const VISITOR_UNAUTHENTICATE = 'The visitor is unauthenticated with visitor ID {0}'; const UNAUTHENTICATE = 'UNAUTHENTICATE'; const FLAGSHIP_VISITOR_NOT_AUTHENTICATE = 'Visitor {0} is not authenticated yet'; const ALLOCATION = 'ALLOCATION'; const BUCKETING_VARIATION_CACHE = 'Visitor {0}, Variation {1} selected from cache.'; const BUCKETING_NEW_ALLOCATION = 'Visitor {0}, Variation {1} selected with allocation {2}.'; const LOOKUP_VISITOR_JSON_OBJECT_ERROR = `lookupVisitor method has loaded a bad format version ({0}) for visitor {1}. Learn more: ${JS_DOC_URL}#managing-visitor-cache`; const PROCESS_CACHE = 'CACHE'; const VISITOR_CACHE_ERROR = 'visitor {0}. {1} threw an exception {2}'; const HIT_CACHE_ERROR = '{0} threw an exception {1}'; const VISITOR_CACHE_LOADED = 'Visitor {0}, visitor cache has been loaded from database: {1}'; const VISITOR_CACHE_SAVED = 'Visitor {0}, visitor cache has been saved into database : {0}'; const VISITOR_CACHE_FLUSHED = 'Visitor {0}, visitor cache has been flushed from database.'; const HIT_CACHE_LOADED = 'Hits cache has been loaded from database: {0}'; const HIT_CACHE_SAVED = 'Hit cache has been saved into database : {0}'; const HIT_DATA_FLUSHED = 'The following hit keys have been flushed from database : {0}'; const ALL_HITS_FLUSHED = 'All hits cache has been flushed from database'; const BATCH_LOOP_STARTED = 'The Batch Loop has been started with a time interval of {0} ms'; const TRACKING_MANAGER = 'TRACKING_MANAGER'; const BATCH_LOOP_STOPPED = 'The Batch Loop has been stopped'; const TRACKING_MANAGER_ERROR = '{0} Unexpected Error occurred {1}'; const HIT_SENT_SUCCESS = '{0} has been sent : {1}'; const ACTIVATE_HIT = 'ACTIVATE HIT'; const BATCH_HIT = 'BATCH HIT'; const DIRECT_HIT = 'HIT'; const GET_THIRD_PARTY_SEGMENT = 'GET_THIRD_PARTY_SEGMENT'; const CONSENT_NOT_SPECIFY_WARNING = 'Consent has not been specified. By default, consent is set to false, which may result in some features being deactivated.'; const ACTION_TRACKING = 'Action Tracking'; const ACTION_TRACKING_HIT_RECEIVED = 'Hit received: {0}'; const ACTION_TRACKING_INVALID_HIT = 'Invalid hit data: {0}'; const ACTION_TRACKING_INVALID_NONCE = 'Invalid nonce: {0}'; const ACTION_TRACKING_SENDING_HIT = 'Sending hit: {0}'; const ACTION_TRACKING_SENDING_HIT_ERROR = 'Failed to send hit: {0}'; const ACTION_TRACKING_DISPATCHED = 'action tracking hits have been dispatched {0}'; const TRUSTED_QA_ORIGINS = (/* unused pure expression or super */ null && ([ 'https://local-qa-assistant.abtasty.com:5000', 'https://staging-qa-assistant.abtasty.com', 'https://qa-assistant.abtasty.com', 'https://qa-assistant.flagship.io', 'https://local-qa-assistant.flagship.io:5000', 'https://staging-qa-assistant.flagship.io' ])); ;// ./src/visitor/Visitor.ts /** * The `Visitor` class represents a unique user within your application. It aids in * managing the visitor's data and fetching the corresponding flags for the visitor * from the [Flagship platform](https://app.flagship.io/login) . */ class Visitor extends external_events_.EventEmitter { visitorDelegate; // eslint-disable-next-line @typescript-eslint/no-explicit-any _onReady; constructor(visitorDelegate) { super(); this.visitorDelegate = visitorDelegate; // eslint-disable-next-line @typescript-eslint/no-explicit-any this._onReady = (err) => { this.emit(EMIT_READY, err); }; this.visitorDelegate.on(EMIT_READY, this._onReady); const instance = this; instance.sendEaiVisitorEvent = (event) => { this.visitorDelegate.sendEaiVisitorEvent(event); }; instance.sendEaiPageView = (pageView) => { this.visitorDelegate.sendEaiPageView(pageView); }; instance.onEAICollectStatusChange = (callback) => { this.visitorDelegate.onEAICollectStatusChange(callback); }; } /** * @inheritdoc */ get visitorId() { return this.visitorDelegate.visitorId; } /** * @inheritdoc */ set visitorId(v) { this.visitorDelegate.visitorId = v; } /** * @inheritdoc */ get anonymousId() { return this.visitorDelegate.anonymousId; } /** * @inheritdoc */ get config() { return this.visitorDelegate.config; } /** * @inheritdoc */ get context() { return this.visitorDelegate.context; } /** * @inheritdoc */ get flagsStatus() { return this.visitorDelegate.flagsStatus; } /** * @inheritdoc */ get hasConsented() { return this.visitorDelegate.hasConsented; } /** * @inheritdoc */ setConsent(hasConsented) { this.visitorDelegate.setConsent(hasConsented); } updateContext(context, value) { this.visitorDelegate.updateContext(context, value); } /** * @inheritdoc */ clearContext() { this.visitorDelegate.clearContext(); } /** * @inheritdoc */ getFlag(key) { return this.visitorDelegate.getFlag(key); } /** * @inheritdoc */ getFlags() { return this.visitorDelegate.getFlags(); } /** * @inheritdoc */ fetchFlags() { return this.visitorDelegate.fetchFlags(); } sendHit(hit) { return this.visitorDelegate.sendHit(hit); } sendHits(hits) { return this.visitorDelegate.sendHits(hits); } /** * @inheritdoc */ authenticate(visitorId) { this.visitorDelegate.authenticate(visitorId); } /** * @inheritdoc */ unauthenticate() { this.visitorDelegate.unauthenticate(); } /** * @inheritdoc */ collectEAIEventsAsync(...args) { let currentPage; if (args.length > 0) { currentPage = args[0]; } return this.visitorDelegate.collectEAIEventsAsync(currentPage); } /** * @inheritdoc */ cleanup() { this.visitorDelegate.cleanup(); this.visitorDelegate.off(EMIT_READY, this._onReady); } } ;// ./src/enum/FSSdkStatus.ts /** * Enum representing the status of the Flagship SDK. */ var FSSdkStatus; (function (FSSdkStatus) { /** * It is the default initial status. This status remains until the sdk has been initialized successfully. */ FSSdkStatus[FSSdkStatus["SDK_NOT_INITIALIZED"] = 0] = "SDK_NOT_INITIALIZED"; /** * The SDK is currently initializing. */ FSSdkStatus[FSSdkStatus["SDK_INITIALIZING"] = 1] = "SDK_INITIALIZING"; /** * Flagship SDK is ready but is running in Panic mode: All features are disabled except the one which refresh this status. */ FSSdkStatus[FSSdkStatus["SDK_PANIC"] = 2] = "SDK_PANIC"; /** * The Initialization is done, and Flagship SDK is ready to use. */ FSSdkStatus[FSSdkStatus["SDK_INITIALIZED"] = 3] = "SDK_INITIALIZED"; })(FSSdkStatus || (FSSdkStatus = {})); ;// ./src/config/DecisionMode.ts var DecisionMode; (function (DecisionMode) { /** * /** * Flagship SDK mode decision api */ DecisionMode["DECISION_API"] = "DECISION-API"; /** * Flagship SDK mode bucketing */ DecisionMode["BUCKETING"] = "BUCKETING"; DecisionMode["BUCKETING_EDGE"] = "BUCKETING_EDGE"; })(DecisionMode || (DecisionMode = {})); ;// ./src/enum/LogLevel.ts var LogLevel; (function (LogLevel) { /** * NONE = 0: Logging will be disabled. */ LogLevel[LogLevel["NONE"] = 0] = "NONE"; /** * EMERGENCY = 1: Only emergencies will be logged. */ LogLevel[LogLevel["EMERGENCY"] = 1] = "EMERGENCY"; /** * ALERT = 2: Only alerts and above will be logged. */ LogLevel[LogLevel["ALERT"] = 2] = "ALERT"; /** * CRITICAL = 3: Only critical and above will be logged. */ LogLevel[LogLevel["CRITICAL"] = 3] = "CRITICAL"; /** * ERROR = 4: Only errors and above will be logged. */ LogLevel[LogLevel["ERROR"] = 4] = "ERROR"; /** * WARNING = 5: Only warnings and above will be logged. */ LogLevel[LogLevel["WARNING"] = 5] = "WARNING"; /** * NOTICE = 6: Only notices and above will be logged. */ LogLevel[LogLevel["NOTICE"] = 6] = "NOTICE"; /** * INFO = 7: Only info logs and above will be logged. */ LogLevel[LogLevel["INFO"] = 7] = "INFO"; /** * DEBUG = 8: Only debug logs and above will be logged. */ LogLevel[LogLevel["DEBUG"] = 8] = "DEBUG"; /** * ALL = 9: All logs will be logged. */ LogLevel[LogLevel["ALL"] = 9] = "ALL"; })(LogLevel || (LogLevel = {})); ;// ./src/enum/FSFetchReasons.ts /** * Enum representing the reasons for fetching Flags. */ var FSFetchReasons; (function (FSFetchReasons) { /** * Indicates that a context has been updated or changed. */ FSFetchReasons["UPDATE_CONTEXT"] = "UPDATE_CONTEXT"; /** * Indicates that the XPC method 'authenticate' has been called. */ FSFetchReasons["AUTHENTICATE"] = "AUTHENTICATE"; /** * Indicates that the XPC method 'unauthenticate' has been called. */ FSFetchReasons["UNAUTHENTICATE"] = "UNAUTHENTICATE"; /** * Indicates that fetching flags has failed. */ FSFetchReasons["FLAGS_FETCHING_ERROR"] = "FLAGS_FETCHING_ERROR"; /** * Indicates that flags have been fetched from the cache. */ FSFetchReasons["FLAGS_FETCHED_FROM_CACHE"] = "FLAGS_FETCHED_FROM_CACHE"; /** * Indicates that the visitor has been created. */ FSFetchReasons["FLAGS_NEVER_FETCHED"] = "FLAGS_NEVER_FETCHED"; /** * Indicates that there is no specific reason for fetching flags. */ FSFetchReasons["NONE"] = "NONE"; })(FSFetchReasons || (FSFetchReasons = {})); ;// ./src/utils/utils.ts /** * Return a formatted string */ // eslint-disable-next-line @typescript-eslint/no-explicit-any function sprintf(format, ...value) { let formatted = format; for (let i = 0; i < value.length; i++) { const item = value[i]; const element = typeof item === 'string' ? item : JSON.stringify(item instanceof Map ? Array.from(item.values()) : item); formatted = formatted.replace(new RegExp(`\\{${i}\\}`, 'g'), element); } return formatted; } function logErrorSprintf(config, tag, message, ...arg) { if (!config || !config.logLevel || config.logLevel < LogLevel.ERROR) { return; } const customMessage = sprintf(message, ...arg); logError(config, customMessage, tag); } function logError(config, message, tag) { if (!config || !config.logLevel || config.logLevel < LogLevel.ERROR) { return; } if (typeof config.onLog === 'function') { config.onLog(LogLevel.ERROR, tag, message); } if (config.logManager && typeof config.logManager.error === 'function') { config.logManager.error(message, tag); } } function logWarningSprintf(config, tag, message, ...arg) { if (!config || !config.logLevel || config.logLevel < LogLevel.WARNING) { return; } const customMessage = sprintf(message, ...arg); logWarning(config, customMessage, tag); } function logWarning(config, message, tag) { if (!config || !config.logLevel || config.logLevel < LogLevel.WARNING) { return; } if (typeof config.onLog === 'function') { config.onLog(LogLevel.WARNING, tag, message); } if (config.logManager && typeof config.logManager.warning === 'function') { config.logManager.warning(message, tag); } } function logInfoSprintf(config, tag, message, ...arg) { if (!config || !config.logLevel || config.logLevel < LogLevel.INFO) { return; } const customMessage = sprintf(message, ...arg); logInfo(config, customMessage, tag); } function logInfo(config, message, tag) { if (!config || !config.logLevel || config.logLevel < LogLevel.INFO) { return; } if (typeof config.onLog === 'function') { config.onLog(LogLevel.INFO, tag, message); } if (config.logManager && typeof config.logManager.info === 'function') { config.logManager.info(message, tag); } } function logDebugSprintf(config, tag, message, ...arg) { if (!config || !config.logLevel || config.logLevel < LogLevel.DEBUG) { return; } const customMessage = sprintf(message, ...arg); logDebug(config, customMessage, tag); } function logDebug(config, message, tag) { if (!config || !config.logLevel || config.logLevel < LogLevel.DEBUG) { return; } if (typeof config.onLog === 'function') { config.onLog(LogLevel.DEBUG, tag, message); } if (config.logManager && typeof config.logManager.debug === 'function') { config.logManager.debug(message, tag);