@splitsoftware/splitio-commons 2.11.1-rc.2 → 3.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGES.txt +15 -2
- package/cjs/evaluator/condition/engineUtils.js +2 -2
- package/cjs/evaluator/fallbackConfigsCalculator/fallbackSanitizer/index.js +70 -0
- package/cjs/evaluator/fallbackConfigsCalculator/index.js +25 -0
- package/cjs/evaluator/fallbackTreatmentsCalculator/fallbackSanitizer/index.js +5 -8
- package/cjs/evaluator/fallbackTreatmentsCalculator/index.js +21 -32
- package/cjs/evaluator/index.js +67 -42
- package/cjs/evaluator/matchers/whitelist.js +1 -1
- package/cjs/integrations/pluggable.js +1 -1
- package/cjs/listeners/browser.js +4 -3
- package/cjs/listeners/node.js +4 -4
- package/cjs/logger/constants.js +14 -20
- package/cjs/logger/index.js +1 -1
- package/cjs/logger/messages/debug.js +6 -7
- package/cjs/logger/messages/error.js +4 -4
- package/cjs/logger/messages/info.js +2 -4
- package/cjs/logger/messages/warn.js +9 -9
- package/cjs/platform/browser.js +15 -0
- package/cjs/platform/getEventSource/browser.js +8 -0
- package/cjs/platform/getEventSource/eventsource.js +480 -0
- package/cjs/platform/getEventSource/node.js +26 -0
- package/cjs/platform/getFetch/browser.js +9 -0
- package/cjs/platform/getFetch/node.js +27 -0
- package/cjs/platform/getOptions/node.js +25 -0
- package/cjs/platform/node.js +17 -0
- package/cjs/readiness/constants.js +2 -1
- package/cjs/sdkClient/client.js +9 -35
- package/cjs/sdkClient/clientAttributesDecoration.js +3 -3
- package/cjs/sdkClient/clientInputValidation.js +38 -81
- package/cjs/sdkClient/identity.js +1 -1
- package/cjs/sdkClient/sdkClient.js +4 -49
- package/cjs/sdkClient/sdkLifecycle.js +70 -0
- package/cjs/sdkClient/trackMethod.js +56 -0
- package/cjs/sdkFactory/index.js +8 -45
- package/cjs/sdkManager/index.js +3 -3
- package/cjs/services/splitApi.js +18 -13
- package/cjs/services/splitHttpClient.js +1 -1
- package/cjs/storages/AbstractSplitsCacheAsync.js +1 -1
- package/cjs/storages/AbstractSplitsCacheSync.js +1 -1
- package/cjs/storages/KeyBuilder.js +12 -12
- package/cjs/storages/KeyBuilderCS.js +13 -13
- package/cjs/storages/KeyBuilderSS.js +15 -15
- package/cjs/storages/getRolloutPlan.js +1 -1
- package/cjs/storages/inLocalStorage/MySegmentsCacheInLocal.js +1 -1
- package/cjs/storages/inLocalStorage/RBSegmentsCacheInLocal.js +1 -1
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +1 -1
- package/cjs/storages/inMemory/ImpressionCountsCacheInMemory.js +1 -1
- package/cjs/storages/inMemory/MySegmentsCacheInMemory.js +1 -1
- package/cjs/storages/inMemory/RBSegmentsCacheInMemory.js +1 -1
- package/cjs/storages/inMemory/SplitsCacheInMemory.js +1 -1
- package/cjs/storages/inMemory/TelemetryCacheInMemory.js +2 -2
- package/cjs/storages/inRedis/EventsCacheInRedis.js +1 -1
- package/cjs/storages/inRedis/ImpressionCountsCacheInRedis.js +5 -5
- package/cjs/storages/inRedis/ImpressionsCacheInRedis.js +1 -1
- package/cjs/storages/inRedis/RBSegmentsCacheInRedis.js +1 -1
- package/cjs/storages/inRedis/RedisAdapter.js +8 -8
- package/cjs/storages/inRedis/SplitsCacheInRedis.js +6 -6
- package/cjs/storages/inRedis/TelemetryCacheInRedis.js +7 -7
- package/cjs/storages/inRedis/UniqueKeysCacheInRedis.js +3 -3
- package/cjs/storages/pluggable/EventsCachePluggable.js +1 -1
- package/cjs/storages/pluggable/ImpressionCountsCachePluggable.js +6 -6
- package/cjs/storages/pluggable/RBSegmentsCachePluggable.js +1 -1
- package/cjs/storages/pluggable/SplitsCachePluggable.js +4 -4
- package/cjs/storages/pluggable/TelemetryCachePluggable.js +7 -7
- package/cjs/storages/pluggable/UniqueKeysCachePluggable.js +2 -2
- package/cjs/storages/pluggable/index.js +3 -3
- package/cjs/storages/pluggable/wrapperAdapter.js +1 -1
- package/cjs/storages/setRolloutPlan.js +1 -1
- package/cjs/storages/utils.js +6 -6
- package/cjs/sync/offline/splitsParser/parseCondition.js +1 -1
- package/cjs/sync/polling/fetchers/segmentChangesFetcher.js +1 -1
- package/cjs/sync/polling/fetchers/splitChangesFetcher.js +23 -14
- package/cjs/sync/polling/pollingManagerCS.js +11 -11
- package/cjs/sync/polling/pollingManagerSS.js +13 -13
- package/cjs/sync/polling/syncTasks/definitionsSyncTask.js +12 -0
- package/cjs/sync/polling/updaters/{splitChangesUpdater.js → definitionChangesUpdater.js} +67 -59
- package/cjs/sync/polling/updaters/mySegmentsUpdater.js +1 -1
- package/cjs/sync/polling/updaters/segmentChangesUpdater.js +6 -6
- package/cjs/sync/streaming/SSEClient/index.js +2 -2
- package/cjs/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.js +2 -2
- package/cjs/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.js +2 -2
- package/cjs/sync/streaming/UpdateWorkers/SplitsUpdateWorker.js +4 -4
- package/cjs/sync/streaming/parseUtils.js +12 -12
- package/cjs/sync/streaming/pushManager.js +2 -2
- package/cjs/sync/submitters/impressionsSubmitter.js +6 -6
- package/cjs/sync/submitters/submitter.js +1 -1
- package/cjs/sync/syncManagerOnline.js +5 -2
- package/cjs/trackers/eventTracker.js +10 -12
- package/cjs/trackers/impressionObserver/buildKey.js +1 -1
- package/cjs/trackers/impressionsTracker.js +37 -20
- package/cjs/trackers/uniqueKeysTracker.js +1 -1
- package/cjs/utils/EventEmitter.js +391 -0
- package/cjs/utils/filter/bloomFilter.js +37 -0
- package/cjs/utils/inputValidation/apiKey.js +1 -1
- package/cjs/utils/inputValidation/attribute.js +2 -2
- package/cjs/utils/inputValidation/{split.js → definition.js} +10 -10
- package/cjs/utils/inputValidation/{splitExistence.js → definitionExistence.js} +6 -6
- package/cjs/utils/inputValidation/definitions.js +25 -0
- package/cjs/utils/inputValidation/eventProperties.js +1 -1
- package/cjs/utils/inputValidation/index.js +7 -7
- package/cjs/utils/inputValidation/isOperational.js +4 -4
- package/cjs/utils/inputValidation/target.js +22 -0
- package/cjs/utils/labels/index.js +3 -3
- package/cjs/utils/lang/index.js +1 -1
- package/cjs/utils/promise/timeout.js +1 -1
- package/cjs/utils/settingsValidation/splitFilters.js +4 -4
- package/cjs/utils/settingsValidation/url.js +5 -5
- package/esm/evaluator/condition/engineUtils.js +2 -2
- package/esm/evaluator/fallbackConfigsCalculator/fallbackSanitizer/index.js +64 -0
- package/esm/evaluator/fallbackConfigsCalculator/index.js +21 -0
- package/esm/evaluator/fallbackTreatmentsCalculator/fallbackSanitizer/index.js +5 -8
- package/esm/evaluator/fallbackTreatmentsCalculator/index.js +21 -33
- package/esm/evaluator/index.js +66 -42
- package/esm/evaluator/matchers/whitelist.js +1 -1
- package/esm/integrations/pluggable.js +1 -1
- package/esm/listeners/browser.js +4 -3
- package/esm/listeners/node.js +4 -4
- package/esm/logger/constants.js +11 -17
- package/esm/logger/index.js +1 -1
- package/esm/logger/messages/debug.js +5 -6
- package/esm/logger/messages/error.js +3 -3
- package/esm/logger/messages/info.js +1 -3
- package/esm/logger/messages/warn.js +8 -8
- package/esm/platform/browser.js +12 -0
- package/esm/platform/getEventSource/browser.js +4 -0
- package/esm/platform/getEventSource/eventsource.js +480 -0
- package/esm/platform/getEventSource/node.js +20 -0
- package/esm/platform/getFetch/browser.js +5 -0
- package/esm/platform/getFetch/node.js +22 -0
- package/esm/platform/getOptions/node.js +20 -0
- package/esm/platform/node.js +14 -0
- package/esm/readiness/constants.js +1 -0
- package/esm/sdkClient/client.js +10 -37
- package/esm/sdkClient/clientAttributesDecoration.js +3 -3
- package/esm/sdkClient/clientInputValidation.js +40 -83
- package/esm/sdkClient/identity.js +1 -1
- package/esm/sdkClient/sdkClient.js +4 -49
- package/esm/sdkClient/sdkLifecycle.js +66 -0
- package/esm/sdkClient/trackMethod.js +52 -0
- package/esm/sdkFactory/index.js +8 -45
- package/esm/sdkManager/index.js +4 -4
- package/esm/services/splitApi.js +18 -13
- package/esm/services/splitHttpClient.js +1 -1
- package/esm/storages/AbstractSplitsCacheAsync.js +1 -1
- package/esm/storages/AbstractSplitsCacheSync.js +1 -1
- package/esm/storages/KeyBuilder.js +12 -12
- package/esm/storages/KeyBuilderCS.js +12 -12
- package/esm/storages/KeyBuilderSS.js +14 -14
- package/esm/storages/getRolloutPlan.js +1 -1
- package/esm/storages/inLocalStorage/RBSegmentsCacheInLocal.js +1 -1
- package/esm/storages/inMemory/ImpressionCountsCacheInMemory.js +1 -1
- package/esm/storages/inMemory/RBSegmentsCacheInMemory.js +1 -1
- package/esm/storages/inMemory/TelemetryCacheInMemory.js +2 -2
- package/esm/storages/inRedis/EventsCacheInRedis.js +1 -1
- package/esm/storages/inRedis/ImpressionCountsCacheInRedis.js +4 -4
- package/esm/storages/inRedis/RBSegmentsCacheInRedis.js +1 -1
- package/esm/storages/inRedis/RedisAdapter.js +7 -7
- package/esm/storages/inRedis/SplitsCacheInRedis.js +4 -4
- package/esm/storages/inRedis/TelemetryCacheInRedis.js +7 -7
- package/esm/storages/inRedis/UniqueKeysCacheInRedis.js +1 -1
- package/esm/storages/pluggable/EventsCachePluggable.js +1 -1
- package/esm/storages/pluggable/ImpressionCountsCachePluggable.js +5 -5
- package/esm/storages/pluggable/RBSegmentsCachePluggable.js +1 -1
- package/esm/storages/pluggable/SplitsCachePluggable.js +2 -2
- package/esm/storages/pluggable/TelemetryCachePluggable.js +7 -7
- package/esm/storages/pluggable/UniqueKeysCachePluggable.js +1 -1
- package/esm/storages/pluggable/index.js +2 -2
- package/esm/storages/pluggable/wrapperAdapter.js +1 -1
- package/esm/storages/setRolloutPlan.js +1 -1
- package/esm/storages/utils.js +6 -6
- package/esm/sync/offline/splitsParser/parseCondition.js +1 -1
- package/esm/sync/polling/fetchers/splitChangesFetcher.js +24 -15
- package/esm/sync/polling/pollingManagerCS.js +11 -11
- package/esm/sync/polling/pollingManagerSS.js +13 -13
- package/esm/sync/polling/syncTasks/definitionsSyncTask.js +8 -0
- package/esm/sync/polling/updaters/{splitChangesUpdater.js → definitionChangesUpdater.js} +67 -59
- package/esm/sync/polling/updaters/mySegmentsUpdater.js +2 -2
- package/esm/sync/polling/updaters/segmentChangesUpdater.js +7 -7
- package/esm/sync/streaming/SSEClient/index.js +2 -2
- package/esm/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.js +2 -2
- package/esm/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.js +2 -2
- package/esm/sync/streaming/UpdateWorkers/SplitsUpdateWorker.js +4 -4
- package/esm/sync/streaming/parseUtils.js +10 -10
- package/esm/sync/streaming/pushManager.js +3 -3
- package/esm/sync/submitters/impressionsSubmitter.js +6 -6
- package/esm/sync/submitters/submitter.js +1 -1
- package/esm/sync/syncManagerOnline.js +5 -2
- package/esm/trackers/eventTracker.js +10 -12
- package/esm/trackers/impressionObserver/buildKey.js +1 -1
- package/esm/trackers/impressionsTracker.js +38 -21
- package/esm/trackers/uniqueKeysTracker.js +1 -1
- package/esm/utils/EventEmitter.js +387 -0
- package/esm/utils/filter/bloomFilter.js +33 -0
- package/esm/utils/inputValidation/apiKey.js +1 -1
- package/esm/utils/inputValidation/attribute.js +2 -2
- package/esm/utils/inputValidation/{split.js → definition.js} +8 -8
- package/esm/utils/inputValidation/definitionExistence.js +15 -0
- package/esm/utils/inputValidation/definitions.js +21 -0
- package/esm/utils/inputValidation/index.js +3 -3
- package/esm/utils/inputValidation/isOperational.js +4 -4
- package/esm/utils/inputValidation/target.js +18 -0
- package/esm/utils/labels/index.js +2 -2
- package/esm/utils/promise/timeout.js +1 -1
- package/esm/utils/settingsValidation/splitFilters.js +4 -4
- package/esm/utils/settingsValidation/url.js +5 -5
- package/package.json +15 -6
- package/src/dtos/types.ts +65 -70
- package/src/evaluator/Engine.ts +4 -4
- package/src/evaluator/combiners/and.ts +3 -3
- package/src/evaluator/combiners/ifelseif.ts +2 -2
- package/src/evaluator/condition/engineUtils.ts +2 -2
- package/src/evaluator/condition/index.ts +3 -3
- package/src/evaluator/fallbackConfigsCalculator/fallbackSanitizer/index.ts +76 -0
- package/src/evaluator/fallbackConfigsCalculator/index.ts +24 -0
- package/src/evaluator/fallbackTreatmentsCalculator/fallbackSanitizer/index.ts +5 -7
- package/src/evaluator/fallbackTreatmentsCalculator/index.ts +27 -41
- package/src/evaluator/index.ts +80 -45
- package/src/evaluator/matchers/dependency.ts +2 -2
- package/src/evaluator/matchers/matcherTypes.ts +2 -2
- package/src/evaluator/matchers/prerequisites.ts +4 -4
- package/src/evaluator/matchers/rbsegment.ts +2 -2
- package/src/evaluator/matchers/whitelist.ts +2 -2
- package/src/evaluator/matchersTransform/index.ts +2 -2
- package/src/evaluator/matchersTransform/whitelist.ts +2 -2
- package/src/evaluator/parser/index.ts +4 -4
- package/src/evaluator/treatments/index.ts +2 -2
- package/src/evaluator/types.ts +6 -6
- package/src/evaluator/value/index.ts +1 -1
- package/src/integrations/pluggable.ts +1 -1
- package/src/listeners/browser.ts +11 -8
- package/src/listeners/node.ts +2 -5
- package/src/logger/constants.ts +11 -17
- package/src/logger/messages/debug.ts +5 -6
- package/src/logger/messages/error.ts +3 -3
- package/src/logger/messages/info.ts +1 -3
- package/src/logger/messages/warn.ts +8 -8
- package/src/platform/browser.ts +14 -0
- package/src/platform/getEventSource/browser.ts +4 -0
- package/src/platform/getEventSource/eventsource.js +519 -0
- package/src/platform/getEventSource/node.ts +23 -0
- package/src/platform/getFetch/browser.ts +5 -0
- package/src/platform/getFetch/node.ts +27 -0
- package/src/platform/getOptions/node.ts +24 -0
- package/src/platform/node.ts +16 -0
- package/src/readiness/constants.ts +1 -0
- package/src/sdkClient/client.ts +11 -41
- package/src/sdkClient/clientInputValidation.ts +44 -84
- package/src/sdkClient/sdkClient.ts +5 -54
- package/src/sdkClient/sdkLifecycle.ts +78 -0
- package/src/sdkClient/trackMethod.ts +59 -0
- package/src/sdkFactory/index.ts +10 -54
- package/src/sdkFactory/types.ts +19 -16
- package/src/sdkManager/index.ts +9 -9
- package/src/services/splitApi.ts +6 -0
- package/src/services/types.ts +3 -2
- package/src/storages/AbstractSplitsCacheAsync.ts +7 -7
- package/src/storages/AbstractSplitsCacheSync.ts +10 -10
- package/src/storages/inLocalStorage/RBSegmentsCacheInLocal.ts +2 -2
- package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +6 -6
- package/src/storages/inMemory/RBSegmentsCacheInMemory.ts +2 -2
- package/src/storages/inMemory/SplitsCacheInMemory.ts +5 -5
- package/src/storages/inMemory/TelemetryCacheInMemory.ts +2 -2
- package/src/storages/inRedis/RBSegmentsCacheInRedis.ts +2 -2
- package/src/storages/inRedis/SplitsCacheInRedis.ts +9 -9
- package/src/storages/pluggable/RBSegmentsCachePluggable.ts +2 -2
- package/src/storages/pluggable/SplitsCachePluggable.ts +9 -9
- package/src/storages/types.ts +21 -16
- package/src/sync/offline/splitsParser/parseCondition.ts +2 -2
- package/src/sync/offline/splitsParser/splitsParserFromSettings.ts +3 -3
- package/src/sync/offline/splitsParser/types.ts +6 -3
- package/src/sync/offline/syncManagerOffline.ts +2 -2
- package/src/sync/offline/syncTasks/fromObjectSyncTask.ts +6 -6
- package/src/sync/polling/fetchers/splitChangesFetcher.ts +57 -22
- package/src/sync/polling/fetchers/types.ts +5 -3
- package/src/sync/polling/pollingManagerCS.ts +12 -10
- package/src/sync/polling/pollingManagerSS.ts +15 -13
- package/src/sync/polling/syncTasks/{splitsSyncTask.ts → definitionsSyncTask.ts} +10 -11
- package/src/sync/polling/types.ts +3 -3
- package/src/sync/polling/updaters/{splitChangesUpdater.ts → definitionChangesUpdater.ts} +77 -68
- package/src/sync/polling/updaters/mySegmentsUpdater.ts +2 -2
- package/src/sync/polling/updaters/segmentChangesUpdater.ts +7 -7
- package/src/sync/streaming/UpdateWorkers/SplitsUpdateWorker.ts +6 -6
- package/src/sync/streaming/parseUtils.ts +12 -12
- package/src/sync/streaming/pushManager.ts +3 -3
- package/src/sync/submitters/impressionsSubmitter.ts +9 -9
- package/src/sync/submitters/types.ts +3 -0
- package/src/sync/syncManagerOnline.ts +6 -2
- package/src/trackers/eventTracker.ts +7 -10
- package/src/trackers/impressionsTracker.ts +42 -26
- package/src/trackers/types.ts +3 -1
- package/src/utils/EventEmitter.js +444 -0
- package/src/utils/filter/bloomFilter.ts +38 -0
- package/src/utils/inputValidation/definition.ts +27 -0
- package/src/utils/inputValidation/definitionExistence.ts +19 -0
- package/src/utils/inputValidation/definitions.ts +21 -0
- package/src/utils/inputValidation/index.ts +3 -3
- package/src/utils/inputValidation/isOperational.ts +4 -4
- package/src/utils/inputValidation/target.ts +21 -0
- package/src/utils/labels/index.ts +2 -2
- package/src/utils/settingsValidation/splitFilters.ts +3 -3
- package/types/splitio.d.ts +202 -9
- package/cjs/sync/polling/syncTasks/splitsSyncTask.js +0 -13
- package/cjs/utils/inputValidation/splits.js +0 -25
- package/esm/sync/polling/syncTasks/splitsSyncTask.js +0 -9
- package/esm/utils/inputValidation/splitExistence.js +0 -15
- package/esm/utils/inputValidation/splits.js +0 -21
- package/src/utils/inputValidation/split.ts +0 -27
- package/src/utils/inputValidation/splitExistence.ts +0 -19
- package/src/utils/inputValidation/splits.ts +0 -21
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getFetch = exports.__setFetch = void 0;
|
|
4
|
+
var nodeFetch;
|
|
5
|
+
try {
|
|
6
|
+
nodeFetch = require('node-fetch');
|
|
7
|
+
// Handle node-fetch issue https://github.com/node-fetch/node-fetch/issues/1037
|
|
8
|
+
if (typeof nodeFetch !== 'function')
|
|
9
|
+
nodeFetch = nodeFetch.default;
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
// Try to access global fetch if `node-fetch` package couldn't be imported (e.g., not in a Node environment)
|
|
13
|
+
// eslint-disable-next-line no-undef
|
|
14
|
+
nodeFetch = typeof fetch === 'function' ? fetch : undefined;
|
|
15
|
+
}
|
|
16
|
+
// This function is only exposed for testing purposes.
|
|
17
|
+
function __setFetch(fetch) {
|
|
18
|
+
nodeFetch = fetch;
|
|
19
|
+
}
|
|
20
|
+
exports.__setFetch = __setFetch;
|
|
21
|
+
/**
|
|
22
|
+
* Retrieves 'node-fetch', a Fetch API polyfill for Node.js, with fallback to global 'fetch' if available.
|
|
23
|
+
*/
|
|
24
|
+
function getFetch() {
|
|
25
|
+
return nodeFetch;
|
|
26
|
+
}
|
|
27
|
+
exports.getFetch = getFetch;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getOptions = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
// @TODO
|
|
6
|
+
// 1- handle multiple protocols automatically
|
|
7
|
+
// 2- destroy it once the sdk is destroyed
|
|
8
|
+
var https_1 = tslib_1.__importDefault(require("https"));
|
|
9
|
+
var lang_1 = require("../../utils/lang");
|
|
10
|
+
var agent = new https_1.default.Agent({
|
|
11
|
+
keepAlive: true,
|
|
12
|
+
keepAliveMsecs: 1500
|
|
13
|
+
});
|
|
14
|
+
function getOptions(settings) {
|
|
15
|
+
// User provided options take precedence
|
|
16
|
+
if (settings.sync.requestOptions)
|
|
17
|
+
return settings.sync.requestOptions;
|
|
18
|
+
// If some URL is not HTTPS, we don't use the agent, to let the SDK connect to HTTP endpoints
|
|
19
|
+
if ((0, lang_1.find)(settings.urls, function (url) { return !url.startsWith('https:'); }))
|
|
20
|
+
return;
|
|
21
|
+
return {
|
|
22
|
+
agent: agent
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
exports.getOptions = getOptions;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.platform = void 0;
|
|
4
|
+
var events_1 = require("events");
|
|
5
|
+
var node_1 = require("../platform/getFetch/node");
|
|
6
|
+
var node_2 = require("../platform/getEventSource/node");
|
|
7
|
+
var node_3 = require("../platform/getOptions/node");
|
|
8
|
+
var node_4 = require("../listeners/node");
|
|
9
|
+
var node_5 = require("../utils/timeTracker/now/node");
|
|
10
|
+
exports.platform = {
|
|
11
|
+
getFetch: node_1.getFetch,
|
|
12
|
+
getEventSource: node_2.getEventSource,
|
|
13
|
+
getOptions: node_3.getOptions,
|
|
14
|
+
EventEmitter: events_1.EventEmitter,
|
|
15
|
+
now: node_5.now,
|
|
16
|
+
SignalListener: node_4.NodeSignalListener
|
|
17
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SEGMENTS_UPDATE = exports.FLAGS_UPDATE = exports.SDK_UPDATE = exports.SDK_READY_FROM_CACHE = exports.SDK_READY = exports.SDK_READY_TIMED_OUT = exports.SDK_SEGMENTS_ARRIVED = exports.SDK_SPLITS_CACHE_LOADED = exports.SDK_SPLITS_ARRIVED = void 0;
|
|
3
|
+
exports.CONFIGS_UPDATE = exports.SEGMENTS_UPDATE = exports.FLAGS_UPDATE = exports.SDK_UPDATE = exports.SDK_READY_FROM_CACHE = exports.SDK_READY = exports.SDK_READY_TIMED_OUT = exports.SDK_SEGMENTS_ARRIVED = exports.SDK_SPLITS_CACHE_LOADED = exports.SDK_SPLITS_ARRIVED = void 0;
|
|
4
4
|
// Splits events:
|
|
5
5
|
exports.SDK_SPLITS_ARRIVED = 'state::splits-arrived';
|
|
6
6
|
exports.SDK_SPLITS_CACHE_LOADED = 'state::splits-cache-loaded';
|
|
@@ -14,3 +14,4 @@ exports.SDK_UPDATE = 'state::update';
|
|
|
14
14
|
// SdkUpdateMetadata types:
|
|
15
15
|
exports.FLAGS_UPDATE = 'FLAGS_UPDATE';
|
|
16
16
|
exports.SEGMENTS_UPDATE = 'SEGMENTS_UPDATE';
|
|
17
|
+
exports.CONFIGS_UPDATE = 'CONFIGS_UPDATE';
|
package/cjs/sdkClient/client.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.clientFactory = void 0;
|
|
3
|
+
exports.clientFactory = exports.stringify = void 0;
|
|
4
4
|
var evaluator_1 = require("../evaluator");
|
|
5
5
|
var thenable_1 = require("../utils/promise/thenable");
|
|
6
6
|
var key_1 = require("../utils/key");
|
|
7
|
-
var
|
|
8
|
-
var trafficTypeExistence_1 = require("../utils/inputValidation/trafficTypeExistence");
|
|
7
|
+
var definitionExistence_1 = require("../utils/inputValidation/definitionExistence");
|
|
9
8
|
var labels_1 = require("../utils/labels");
|
|
10
9
|
var constants_1 = require("../utils/constants");
|
|
11
10
|
var constants_2 = require("../logger/constants");
|
|
12
11
|
var mode_1 = require("../utils/settingsValidation/mode");
|
|
12
|
+
var trackMethod_1 = require("./trackMethod");
|
|
13
13
|
var treatmentNotReady = { treatment: constants_1.CONTROL, label: labels_1.SDK_NOT_READY };
|
|
14
14
|
function treatmentsNotReady(featureFlagNames) {
|
|
15
15
|
var evaluations = {};
|
|
@@ -26,11 +26,12 @@ function stringify(options) {
|
|
|
26
26
|
catch ( /* JSON.stringify should never throw with validated options, but handling just in case */_a) { /* JSON.stringify should never throw with validated options, but handling just in case */ }
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
+
exports.stringify = stringify;
|
|
29
30
|
/**
|
|
30
31
|
* Creator of base client with getTreatments and track methods.
|
|
31
32
|
*/
|
|
32
33
|
function clientFactory(params) {
|
|
33
|
-
var readinessManager = params.sdkReadinessManager.readinessManager, storage = params.storage, settings = params.settings, impressionsTracker = params.impressionsTracker,
|
|
34
|
+
var readinessManager = params.sdkReadinessManager.readinessManager, storage = params.storage, settings = params.settings, impressionsTracker = params.impressionsTracker, telemetryTracker = params.telemetryTracker, fallbackCalculator = params.fallbackCalculator;
|
|
34
35
|
var log = settings.log, mode = settings.mode;
|
|
35
36
|
var isAsync = (0, mode_1.isConsumerMode)(mode);
|
|
36
37
|
function getTreatment(key, featureFlagName, attributes, options, withConfig, methodName) {
|
|
@@ -118,14 +119,13 @@ function clientFactory(params) {
|
|
|
118
119
|
var changeNumber = evaluation.changeNumber, impressionsDisabled = evaluation.impressionsDisabled;
|
|
119
120
|
var treatment = evaluation.treatment, label = evaluation.label, _a = evaluation.config, config = _a === void 0 ? null : _a;
|
|
120
121
|
if (treatment === constants_1.CONTROL) {
|
|
121
|
-
var fallbackTreatment =
|
|
122
|
+
var fallbackTreatment = fallbackCalculator(featureFlagName, label);
|
|
122
123
|
treatment = fallbackTreatment.treatment;
|
|
123
124
|
label = fallbackTreatment.label;
|
|
124
125
|
config = fallbackTreatment.config;
|
|
125
126
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
log.info(constants_2.IMPRESSION_QUEUEING);
|
|
127
|
+
if ((0, definitionExistence_1.validateDefinitionExistence)(log, readinessManager, featureFlagName, label, invokingMethodName)) {
|
|
128
|
+
log.info(constants_2.IMPRESSION_QUEUEING, ['Feature flag', featureFlagName, matchingKey, treatment, label]);
|
|
129
129
|
queue.push({
|
|
130
130
|
imp: {
|
|
131
131
|
feature: featureFlagName,
|
|
@@ -148,33 +148,7 @@ function clientFactory(params) {
|
|
|
148
148
|
}
|
|
149
149
|
return treatment;
|
|
150
150
|
}
|
|
151
|
-
|
|
152
|
-
if (size === void 0) { size = 1024; }
|
|
153
|
-
var stopTelemetryTracker = telemetryTracker.trackEval(constants_1.TRACK);
|
|
154
|
-
var matchingKey = (0, key_1.getMatching)(key);
|
|
155
|
-
var timestamp = Date.now();
|
|
156
|
-
var eventData = {
|
|
157
|
-
eventTypeId: eventTypeId,
|
|
158
|
-
trafficTypeName: trafficTypeName,
|
|
159
|
-
value: value,
|
|
160
|
-
timestamp: timestamp,
|
|
161
|
-
key: matchingKey,
|
|
162
|
-
properties: properties
|
|
163
|
-
};
|
|
164
|
-
// This may be async but we only warn, we don't actually care if it is valid or not in terms of queueing the event.
|
|
165
|
-
(0, trafficTypeExistence_1.validateTrafficTypeExistence)(log, readinessManager, storage.splits, mode, trafficTypeName, constants_1.TRACK_FN_LABEL);
|
|
166
|
-
var result = eventTracker.track(eventData, size);
|
|
167
|
-
if ((0, thenable_1.thenable)(result)) {
|
|
168
|
-
return result.then(function (result) {
|
|
169
|
-
stopTelemetryTracker();
|
|
170
|
-
return result;
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
else {
|
|
174
|
-
stopTelemetryTracker();
|
|
175
|
-
return result;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
151
|
+
var track = (0, trackMethod_1.trackMethodFactory)(params);
|
|
178
152
|
return {
|
|
179
153
|
getTreatment: getTreatment,
|
|
180
154
|
getTreatmentWithConfig: getTreatmentWithConfig,
|
|
@@ -69,7 +69,7 @@ function clientAttributesDecoration(log, client) {
|
|
|
69
69
|
attribute[attributeName] = attributeValue;
|
|
70
70
|
if (!(0, attributes_1.validateAttributesDeep)(log, attribute, 'setAttribute'))
|
|
71
71
|
return false;
|
|
72
|
-
log.debug("stored "
|
|
72
|
+
log.debug("stored ".concat(attributeValue, " for attribute ").concat(attributeName));
|
|
73
73
|
return attributeStorage.setAttribute(attributeName, attributeValue);
|
|
74
74
|
},
|
|
75
75
|
/**
|
|
@@ -79,7 +79,7 @@ function clientAttributesDecoration(log, client) {
|
|
|
79
79
|
* @returns Attribute with the given name
|
|
80
80
|
*/
|
|
81
81
|
getAttribute: function (attributeName) {
|
|
82
|
-
log.debug("retrieved attribute "
|
|
82
|
+
log.debug("retrieved attribute ".concat(attributeName));
|
|
83
83
|
return attributeStorage.getAttribute(attributeName + '');
|
|
84
84
|
},
|
|
85
85
|
/**
|
|
@@ -108,7 +108,7 @@ function clientAttributesDecoration(log, client) {
|
|
|
108
108
|
* @returns true if attribute was removed and false otherways
|
|
109
109
|
*/
|
|
110
110
|
removeAttribute: function (attributeName) {
|
|
111
|
-
log.debug("removed attribute "
|
|
111
|
+
log.debug("removed attribute ".concat(attributeName));
|
|
112
112
|
return attributeStorage.removeAttribute(attributeName + '');
|
|
113
113
|
},
|
|
114
114
|
/**
|
|
@@ -10,7 +10,7 @@ var splitFilters_1 = require("../utils/settingsValidation/splitFilters");
|
|
|
10
10
|
* Decorator that validates the input before actually executing the client methods.
|
|
11
11
|
* We should "guard" the client here, while not polluting the "real" implementation of those methods.
|
|
12
12
|
*/
|
|
13
|
-
function clientInputValidationDecorator(settings, client, readinessManager,
|
|
13
|
+
function clientInputValidationDecorator(settings, client, readinessManager, fallbackCalculator) {
|
|
14
14
|
var log = settings.log, mode = settings.mode;
|
|
15
15
|
var isAsync = (0, mode_1.isConsumerMode)(mode);
|
|
16
16
|
/**
|
|
@@ -21,12 +21,12 @@ function clientInputValidationDecorator(settings, client, readinessManager, fall
|
|
|
21
21
|
var nameOrNames = methodName.indexOf('ByFlagSet') > -1 ?
|
|
22
22
|
(0, splitFilters_1.validateFlagSets)(log, methodName, maybeNameOrNames, settings.sync.__splitFiltersValidation.groupedFilters.bySet) :
|
|
23
23
|
(0, lang_1.startsWith)(methodName, constants_1.GET_TREATMENTS) ?
|
|
24
|
-
(0, inputValidation_1.
|
|
25
|
-
(0, inputValidation_1.
|
|
24
|
+
(0, inputValidation_1.validateDefinitions)(log, maybeNameOrNames, methodName) :
|
|
25
|
+
(0, inputValidation_1.validateDefinition)(log, maybeNameOrNames, methodName);
|
|
26
26
|
var attributes = (0, inputValidation_1.validateAttributes)(log, maybeAttributes, methodName);
|
|
27
27
|
var isNotDestroyed = (0, inputValidation_1.validateIfNotDestroyed)(log, readinessManager, methodName);
|
|
28
28
|
var options = (0, inputValidation_1.validateEvaluationOptions)(log, maybeOptions, methodName);
|
|
29
|
-
(0, inputValidation_1.validateIfReadyFromCache)(log, readinessManager, methodName
|
|
29
|
+
(0, inputValidation_1.validateIfReadyFromCache)(log, readinessManager, methodName);
|
|
30
30
|
var valid = isNotDestroyed && key && nameOrNames && attributes !== false;
|
|
31
31
|
return {
|
|
32
32
|
valid: valid,
|
|
@@ -37,111 +37,68 @@ function clientInputValidationDecorator(settings, client, readinessManager, fall
|
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
39
|
function evaluateFallBackTreatment(featureFlagName, withConfig) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return
|
|
40
|
+
if (Array.isArray(featureFlagName)) {
|
|
41
|
+
var res_1 = {};
|
|
42
|
+
featureFlagName.forEach(function (split) { return res_1[split] = evaluateFallBackTreatment(split, withConfig); });
|
|
43
|
+
return res_1;
|
|
44
|
+
}
|
|
45
|
+
var _a = fallbackCalculator(featureFlagName), treatment = _a.treatment, config = _a.config;
|
|
46
|
+
return withConfig ?
|
|
47
|
+
{
|
|
43
48
|
treatment: treatment,
|
|
44
49
|
config: config
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
return treatment;
|
|
50
|
+
} : treatment;
|
|
48
51
|
}
|
|
49
52
|
function wrapResult(value) {
|
|
50
53
|
return isAsync ? Promise.resolve(value) : value;
|
|
51
54
|
}
|
|
52
55
|
function getTreatment(maybeKey, maybeFeatureFlagName, maybeAttributes, maybeOptions) {
|
|
53
56
|
var params = validateEvaluationParams(constants_1.GET_TREATMENT, maybeKey, maybeFeatureFlagName, maybeAttributes, maybeOptions);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
else {
|
|
58
|
-
var result = evaluateFallBackTreatment(params.nameOrNames, false);
|
|
59
|
-
return wrapResult(result);
|
|
60
|
-
}
|
|
57
|
+
return params.valid ?
|
|
58
|
+
client.getTreatment(params.key, params.nameOrNames, params.attributes, params.options) :
|
|
59
|
+
wrapResult(evaluateFallBackTreatment(params.nameOrNames, false));
|
|
61
60
|
}
|
|
62
61
|
function getTreatmentWithConfig(maybeKey, maybeFeatureFlagName, maybeAttributes, maybeOptions) {
|
|
63
62
|
var params = validateEvaluationParams(constants_1.GET_TREATMENT_WITH_CONFIG, maybeKey, maybeFeatureFlagName, maybeAttributes, maybeOptions);
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
else {
|
|
68
|
-
var result = evaluateFallBackTreatment(params.nameOrNames, true);
|
|
69
|
-
return wrapResult(result);
|
|
70
|
-
}
|
|
63
|
+
return params.valid ?
|
|
64
|
+
client.getTreatmentWithConfig(params.key, params.nameOrNames, params.attributes, params.options) :
|
|
65
|
+
wrapResult(evaluateFallBackTreatment(params.nameOrNames, true));
|
|
71
66
|
}
|
|
72
67
|
function getTreatments(maybeKey, maybeFeatureFlagNames, maybeAttributes, maybeOptions) {
|
|
73
68
|
var params = validateEvaluationParams(constants_1.GET_TREATMENTS, maybeKey, maybeFeatureFlagNames, maybeAttributes, maybeOptions);
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
else {
|
|
78
|
-
var res_1 = {};
|
|
79
|
-
if (params.nameOrNames)
|
|
80
|
-
params.nameOrNames.forEach(function (split) { return res_1[split] = evaluateFallBackTreatment(split, false); });
|
|
81
|
-
return wrapResult(res_1);
|
|
82
|
-
}
|
|
69
|
+
return params.valid ?
|
|
70
|
+
client.getTreatments(params.key, params.nameOrNames, params.attributes, params.options) :
|
|
71
|
+
wrapResult(evaluateFallBackTreatment(params.nameOrNames || [], false));
|
|
83
72
|
}
|
|
84
73
|
function getTreatmentsWithConfig(maybeKey, maybeFeatureFlagNames, maybeAttributes, maybeOptions) {
|
|
85
74
|
var params = validateEvaluationParams(constants_1.GET_TREATMENTS_WITH_CONFIG, maybeKey, maybeFeatureFlagNames, maybeAttributes, maybeOptions);
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
else {
|
|
90
|
-
var res_2 = {};
|
|
91
|
-
if (params.nameOrNames)
|
|
92
|
-
params.nameOrNames.forEach(function (split) { return res_2[split] = evaluateFallBackTreatment(split, true); });
|
|
93
|
-
return wrapResult(res_2);
|
|
94
|
-
}
|
|
75
|
+
return params.valid ?
|
|
76
|
+
client.getTreatmentsWithConfig(params.key, params.nameOrNames, params.attributes, params.options) :
|
|
77
|
+
wrapResult(evaluateFallBackTreatment(params.nameOrNames || [], true));
|
|
95
78
|
}
|
|
96
79
|
function getTreatmentsByFlagSets(maybeKey, maybeFlagSets, maybeAttributes, maybeOptions) {
|
|
97
80
|
var params = validateEvaluationParams(constants_1.GET_TREATMENTS_BY_FLAG_SETS, maybeKey, maybeFlagSets, maybeAttributes, maybeOptions);
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
else {
|
|
102
|
-
return wrapResult({});
|
|
103
|
-
}
|
|
81
|
+
return params.valid ?
|
|
82
|
+
client.getTreatmentsByFlagSets(params.key, params.nameOrNames, params.attributes, params.options) :
|
|
83
|
+
wrapResult({});
|
|
104
84
|
}
|
|
105
85
|
function getTreatmentsWithConfigByFlagSets(maybeKey, maybeFlagSets, maybeAttributes, maybeOptions) {
|
|
106
86
|
var params = validateEvaluationParams(constants_1.GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, maybeKey, maybeFlagSets, maybeAttributes, maybeOptions);
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
else {
|
|
111
|
-
return wrapResult({});
|
|
112
|
-
}
|
|
87
|
+
return params.valid ?
|
|
88
|
+
client.getTreatmentsWithConfigByFlagSets(params.key, params.nameOrNames, params.attributes, params.options) :
|
|
89
|
+
wrapResult({});
|
|
113
90
|
}
|
|
114
91
|
function getTreatmentsByFlagSet(maybeKey, maybeFlagSet, maybeAttributes, maybeOptions) {
|
|
115
92
|
var params = validateEvaluationParams(constants_1.GET_TREATMENTS_BY_FLAG_SET, maybeKey, [maybeFlagSet], maybeAttributes, maybeOptions);
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
else {
|
|
120
|
-
return wrapResult({});
|
|
121
|
-
}
|
|
93
|
+
return params.valid ?
|
|
94
|
+
client.getTreatmentsByFlagSet(params.key, params.nameOrNames[0], params.attributes, params.options) :
|
|
95
|
+
wrapResult({});
|
|
122
96
|
}
|
|
123
97
|
function getTreatmentsWithConfigByFlagSet(maybeKey, maybeFlagSet, maybeAttributes, maybeOptions) {
|
|
124
98
|
var params = validateEvaluationParams(constants_1.GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET, maybeKey, [maybeFlagSet], maybeAttributes, maybeOptions);
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
else {
|
|
129
|
-
return wrapResult({});
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
function track(maybeKey, maybeTT, maybeEvent, maybeEventValue, maybeProperties) {
|
|
133
|
-
var key = (0, inputValidation_1.validateKey)(log, maybeKey, constants_1.TRACK_FN_LABEL);
|
|
134
|
-
var tt = (0, inputValidation_1.validateTrafficType)(log, maybeTT, constants_1.TRACK_FN_LABEL);
|
|
135
|
-
var event = (0, inputValidation_1.validateEvent)(log, maybeEvent, constants_1.TRACK_FN_LABEL);
|
|
136
|
-
var eventValue = (0, inputValidation_1.validateEventValue)(log, maybeEventValue, constants_1.TRACK_FN_LABEL);
|
|
137
|
-
var _a = (0, inputValidation_1.validateEventProperties)(log, maybeProperties, constants_1.TRACK_FN_LABEL), properties = _a.properties, size = _a.size;
|
|
138
|
-
var isNotDestroyed = (0, inputValidation_1.validateIfNotDestroyed)(log, readinessManager, constants_1.TRACK_FN_LABEL);
|
|
139
|
-
if (isNotDestroyed && key && tt && event && eventValue !== false && properties !== false) { // @ts-expect-error
|
|
140
|
-
return client.track(key, tt, event, eventValue, properties, size);
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
return isAsync ? Promise.resolve(false) : false;
|
|
144
|
-
}
|
|
99
|
+
return params.valid ?
|
|
100
|
+
client.getTreatmentsWithConfigByFlagSet(params.key, params.nameOrNames[0], params.attributes, params.options) :
|
|
101
|
+
wrapResult({});
|
|
145
102
|
}
|
|
146
103
|
return {
|
|
147
104
|
getTreatment: getTreatment,
|
|
@@ -152,7 +109,7 @@ function clientInputValidationDecorator(settings, client, readinessManager, fall
|
|
|
152
109
|
getTreatmentsWithConfigByFlagSets: getTreatmentsWithConfigByFlagSets,
|
|
153
110
|
getTreatmentsByFlagSet: getTreatmentsByFlagSet,
|
|
154
111
|
getTreatmentsWithConfigByFlagSet: getTreatmentsWithConfigByFlagSet,
|
|
155
|
-
track: track
|
|
112
|
+
track: client.track,
|
|
156
113
|
};
|
|
157
114
|
}
|
|
158
115
|
exports.clientInputValidationDecorator = clientInputValidationDecorator;
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.buildInstanceId = void 0;
|
|
4
4
|
function buildInstanceId(key, trafficType) {
|
|
5
|
-
return (key.matchingKey ? key.matchingKey : key
|
|
5
|
+
return "".concat(key.matchingKey ? key.matchingKey : key, "-").concat(key.bucketingKey ? key.bucketingKey : key, "-").concat(trafficType ? trafficType : '');
|
|
6
6
|
}
|
|
7
7
|
exports.buildInstanceId = buildInstanceId;
|
|
@@ -2,63 +2,18 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.sdkClientFactory = void 0;
|
|
4
4
|
var objectAssign_1 = require("../utils/lang/objectAssign");
|
|
5
|
-
var apiKey_1 = require("../utils/inputValidation/apiKey");
|
|
6
5
|
var client_1 = require("./client");
|
|
7
6
|
var clientInputValidation_1 = require("./clientInputValidation");
|
|
8
|
-
var
|
|
7
|
+
var sdkLifecycle_1 = require("./sdkLifecycle");
|
|
9
8
|
/**
|
|
10
|
-
* Creates an Sdk client, i.e., a base client with status and destroy interface
|
|
9
|
+
* Creates an Sdk client, i.e., a base client with status, init, flush and destroy interface
|
|
11
10
|
*/
|
|
12
11
|
function sdkClientFactory(params, isSharedClient) {
|
|
13
|
-
var sdkReadinessManager = params.sdkReadinessManager,
|
|
14
|
-
var lastActionTime = 0;
|
|
15
|
-
function __cooldown(func, time) {
|
|
16
|
-
var now = Date.now();
|
|
17
|
-
//get the actual time elapsed in ms
|
|
18
|
-
var timeElapsed = now - lastActionTime;
|
|
19
|
-
//check if the time elapsed is less than desired cooldown
|
|
20
|
-
if (timeElapsed < time) {
|
|
21
|
-
//if yes, return message with remaining time in seconds
|
|
22
|
-
settings.log.warn("Flush cooldown, remaining time " + (time - timeElapsed) / 1000 + " seconds");
|
|
23
|
-
return Promise.resolve();
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
//Do the requested action and re-assign the lastActionTime
|
|
27
|
-
lastActionTime = now;
|
|
28
|
-
return func();
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
function __flush() {
|
|
32
|
-
return syncManager ? syncManager.flush() : Promise.resolve();
|
|
33
|
-
}
|
|
12
|
+
var sdkReadinessManager = params.sdkReadinessManager, settings = params.settings;
|
|
34
13
|
return (0, objectAssign_1.objectAssign)(
|
|
35
14
|
// Proto-linkage of the readiness Event Emitter
|
|
36
15
|
Object.create(sdkReadinessManager.sdkStatus),
|
|
37
16
|
// Client API (getTreatment* & track methods)
|
|
38
|
-
(0, clientInputValidation_1.clientInputValidationDecorator)(settings, (0, client_1.clientFactory)(params), sdkReadinessManager.readinessManager, params.
|
|
39
|
-
// Sdk destroy
|
|
40
|
-
{
|
|
41
|
-
flush: function () {
|
|
42
|
-
// @TODO define cooldown time
|
|
43
|
-
return __cooldown(__flush, COOLDOWN_TIME_IN_MILLIS);
|
|
44
|
-
},
|
|
45
|
-
destroy: function () {
|
|
46
|
-
// Mark the SDK as destroyed immediately
|
|
47
|
-
sdkReadinessManager.readinessManager.destroy();
|
|
48
|
-
// For main client, cleanup the SDK Key, listeners and scheduled jobs, and record stat before flushing data
|
|
49
|
-
if (!isSharedClient) {
|
|
50
|
-
(0, apiKey_1.releaseApiKey)(settings.core.authorizationKey);
|
|
51
|
-
telemetryTracker.sessionLength();
|
|
52
|
-
signalListener && signalListener.stop();
|
|
53
|
-
uniqueKeysTracker.stop();
|
|
54
|
-
}
|
|
55
|
-
// Stop background jobs
|
|
56
|
-
syncManager && syncManager.stop();
|
|
57
|
-
return __flush().then(function () {
|
|
58
|
-
// Cleanup storage
|
|
59
|
-
return storage.destroy();
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
});
|
|
17
|
+
(0, clientInputValidation_1.clientInputValidationDecorator)(settings, (0, client_1.clientFactory)(params), sdkReadinessManager.readinessManager, params.fallbackCalculator), (0, sdkLifecycle_1.sdkLifecycleFactory)(params, isSharedClient));
|
|
63
18
|
}
|
|
64
19
|
exports.sdkClientFactory = sdkClientFactory;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sdkLifecycleFactory = void 0;
|
|
4
|
+
var apiKey_1 = require("../utils/inputValidation/apiKey");
|
|
5
|
+
var COOLDOWN_TIME_IN_MILLIS = 1000;
|
|
6
|
+
/**
|
|
7
|
+
* Creates an Sdk client, i.e., a base client with status, init, flush and destroy interface
|
|
8
|
+
*/
|
|
9
|
+
function sdkLifecycleFactory(params, isSharedClient) {
|
|
10
|
+
var sdkReadinessManager = params.sdkReadinessManager, syncManager = params.syncManager, storage = params.storage, settings = params.settings, telemetryTracker = params.telemetryTracker, impressionsTracker = params.impressionsTracker, platform = params.platform;
|
|
11
|
+
var hasInit = false;
|
|
12
|
+
var lastActionTime = 0;
|
|
13
|
+
var signalListener = platform.SignalListener && new platform.SignalListener(params);
|
|
14
|
+
function __cooldown(func, time) {
|
|
15
|
+
var now = Date.now();
|
|
16
|
+
//get the actual time elapsed in ms
|
|
17
|
+
var timeElapsed = now - lastActionTime;
|
|
18
|
+
//check if the time elapsed is less than desired cooldown
|
|
19
|
+
if (timeElapsed < time) {
|
|
20
|
+
//if yes, return message with remaining time in seconds
|
|
21
|
+
settings.log.warn("Flush cooldown, remaining time ".concat((time - timeElapsed) / 1000, " seconds"));
|
|
22
|
+
return Promise.resolve();
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
//Do the requested action and re-assign the lastActionTime
|
|
26
|
+
lastActionTime = now;
|
|
27
|
+
return func();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function __flush() {
|
|
31
|
+
return syncManager ? syncManager.flush() : Promise.resolve();
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
init: function () {
|
|
35
|
+
if (hasInit)
|
|
36
|
+
return;
|
|
37
|
+
hasInit = true;
|
|
38
|
+
if (!isSharedClient) {
|
|
39
|
+
(0, apiKey_1.validateAndTrackApiKey)(settings.log, settings.core.authorizationKey);
|
|
40
|
+
sdkReadinessManager.readinessManager.init();
|
|
41
|
+
impressionsTracker.start();
|
|
42
|
+
syncManager && syncManager.start();
|
|
43
|
+
signalListener && signalListener.start();
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
flush: function () {
|
|
47
|
+
// @TODO define cooldown time
|
|
48
|
+
return __cooldown(__flush, COOLDOWN_TIME_IN_MILLIS);
|
|
49
|
+
},
|
|
50
|
+
destroy: function () {
|
|
51
|
+
hasInit = false;
|
|
52
|
+
// Mark the SDK as destroyed immediately
|
|
53
|
+
sdkReadinessManager.readinessManager.destroy();
|
|
54
|
+
// For main client, cleanup the SDK Key, listeners and scheduled jobs, and record stat before flushing data
|
|
55
|
+
if (!isSharedClient) {
|
|
56
|
+
(0, apiKey_1.releaseApiKey)(settings.core.authorizationKey);
|
|
57
|
+
telemetryTracker.sessionLength();
|
|
58
|
+
signalListener && signalListener.stop();
|
|
59
|
+
impressionsTracker.stop();
|
|
60
|
+
}
|
|
61
|
+
// Stop background jobs
|
|
62
|
+
syncManager && syncManager.stop();
|
|
63
|
+
return __flush().then(function () {
|
|
64
|
+
// Cleanup storage
|
|
65
|
+
return storage.destroy();
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
exports.sdkLifecycleFactory = sdkLifecycleFactory;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.trackMethodFactory = void 0;
|
|
4
|
+
var thenable_1 = require("../utils/promise/thenable");
|
|
5
|
+
var key_1 = require("../utils/key");
|
|
6
|
+
var trafficTypeExistence_1 = require("../utils/inputValidation/trafficTypeExistence");
|
|
7
|
+
var inputValidation_1 = require("../utils/inputValidation");
|
|
8
|
+
var constants_1 = require("../utils/constants");
|
|
9
|
+
var mode_1 = require("../utils/settingsValidation/mode");
|
|
10
|
+
/**
|
|
11
|
+
* Creates a standalone `track` function with input validation.
|
|
12
|
+
* Reusable by FF SDK client, Configs SDK, and thin-client SDK.
|
|
13
|
+
*/
|
|
14
|
+
function trackMethodFactory(params, warnTTExistence) {
|
|
15
|
+
if (warnTTExistence === void 0) { warnTTExistence = true; }
|
|
16
|
+
var settings = params.settings, splits = params.storage.splits, telemetryTracker = params.telemetryTracker, eventTracker = params.eventTracker, readinessManager = params.sdkReadinessManager.readinessManager;
|
|
17
|
+
var log = settings.log, mode = settings.mode;
|
|
18
|
+
var isAsync = (0, mode_1.isConsumerMode)(mode);
|
|
19
|
+
return function track(maybeKey, maybeTT, maybeEvent, maybeEventValue, maybeProperties) {
|
|
20
|
+
// Input validation
|
|
21
|
+
var key = (0, inputValidation_1.validateKey)(log, maybeKey, constants_1.TRACK_FN_LABEL);
|
|
22
|
+
var trafficTypeName = (0, inputValidation_1.validateTrafficType)(log, maybeTT, constants_1.TRACK_FN_LABEL);
|
|
23
|
+
var eventTypeId = (0, inputValidation_1.validateEvent)(log, maybeEvent, constants_1.TRACK_FN_LABEL);
|
|
24
|
+
var value = (0, inputValidation_1.validateEventValue)(log, maybeEventValue, constants_1.TRACK_FN_LABEL);
|
|
25
|
+
var _a = (0, inputValidation_1.validateEventProperties)(log, maybeProperties, constants_1.TRACK_FN_LABEL), properties = _a.properties, size = _a.size;
|
|
26
|
+
var isNotDestroyed = (0, inputValidation_1.validateIfNotDestroyed)(log, readinessManager, constants_1.TRACK_FN_LABEL);
|
|
27
|
+
if (!(isNotDestroyed && key && trafficTypeName && eventTypeId && value !== false && properties !== false)) {
|
|
28
|
+
return isAsync ? Promise.resolve(false) : false;
|
|
29
|
+
}
|
|
30
|
+
// Core logic
|
|
31
|
+
var stopTelemetryTracker = telemetryTracker.trackEval(constants_1.TRACK);
|
|
32
|
+
var eventData = {
|
|
33
|
+
eventTypeId: eventTypeId,
|
|
34
|
+
trafficTypeName: trafficTypeName,
|
|
35
|
+
value: value,
|
|
36
|
+
timestamp: Date.now(),
|
|
37
|
+
key: (0, key_1.getMatching)(key),
|
|
38
|
+
properties: properties
|
|
39
|
+
};
|
|
40
|
+
// This may be async but we only warn, we don't actually care if it is valid or not in terms of queueing the event.
|
|
41
|
+
if (warnTTExistence)
|
|
42
|
+
(0, trafficTypeExistence_1.validateTrafficTypeExistence)(log, readinessManager, splits, mode, trafficTypeName, constants_1.TRACK_FN_LABEL);
|
|
43
|
+
var result = eventTracker.track(eventData, size);
|
|
44
|
+
if ((0, thenable_1.thenable)(result)) {
|
|
45
|
+
return result.then(function (result) {
|
|
46
|
+
stopTelemetryTracker();
|
|
47
|
+
return result;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
stopTelemetryTracker();
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
exports.trackMethodFactory = trackMethodFactory;
|