@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
|
@@ -66,7 +66,7 @@ export function clientAttributesDecoration(log, client) {
|
|
|
66
66
|
attribute[attributeName] = attributeValue;
|
|
67
67
|
if (!validateAttributesDeep(log, attribute, 'setAttribute'))
|
|
68
68
|
return false;
|
|
69
|
-
log.debug("stored "
|
|
69
|
+
log.debug("stored ".concat(attributeValue, " for attribute ").concat(attributeName));
|
|
70
70
|
return attributeStorage.setAttribute(attributeName, attributeValue);
|
|
71
71
|
},
|
|
72
72
|
/**
|
|
@@ -76,7 +76,7 @@ export function clientAttributesDecoration(log, client) {
|
|
|
76
76
|
* @returns Attribute with the given name
|
|
77
77
|
*/
|
|
78
78
|
getAttribute: function (attributeName) {
|
|
79
|
-
log.debug("retrieved attribute "
|
|
79
|
+
log.debug("retrieved attribute ".concat(attributeName));
|
|
80
80
|
return attributeStorage.getAttribute(attributeName + '');
|
|
81
81
|
},
|
|
82
82
|
/**
|
|
@@ -105,7 +105,7 @@ export function clientAttributesDecoration(log, client) {
|
|
|
105
105
|
* @returns true if attribute was removed and false otherways
|
|
106
106
|
*/
|
|
107
107
|
removeAttribute: function (attributeName) {
|
|
108
|
-
log.debug("removed attribute "
|
|
108
|
+
log.debug("removed attribute ".concat(attributeName));
|
|
109
109
|
return attributeStorage.removeAttribute(attributeName + '');
|
|
110
110
|
},
|
|
111
111
|
/**
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { validateAttributes,
|
|
1
|
+
import { validateAttributes, validateKey, validateDefinition, validateDefinitions, validateIfNotDestroyed, validateIfReadyFromCache, validateEvaluationOptions } from '../utils/inputValidation';
|
|
2
2
|
import { startsWith } from '../utils/lang';
|
|
3
|
-
import { GET_TREATMENT, GET_TREATMENTS, GET_TREATMENTS_BY_FLAG_SET, GET_TREATMENTS_BY_FLAG_SETS, GET_TREATMENTS_WITH_CONFIG, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, GET_TREATMENT_WITH_CONFIG
|
|
3
|
+
import { GET_TREATMENT, GET_TREATMENTS, GET_TREATMENTS_BY_FLAG_SET, GET_TREATMENTS_BY_FLAG_SETS, GET_TREATMENTS_WITH_CONFIG, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, GET_TREATMENT_WITH_CONFIG } from '../utils/constants';
|
|
4
4
|
import { isConsumerMode } from '../utils/settingsValidation/mode';
|
|
5
5
|
import { validateFlagSets } from '../utils/settingsValidation/splitFilters';
|
|
6
6
|
/**
|
|
7
7
|
* Decorator that validates the input before actually executing the client methods.
|
|
8
8
|
* We should "guard" the client here, while not polluting the "real" implementation of those methods.
|
|
9
9
|
*/
|
|
10
|
-
export function clientInputValidationDecorator(settings, client, readinessManager,
|
|
10
|
+
export function clientInputValidationDecorator(settings, client, readinessManager, fallbackCalculator) {
|
|
11
11
|
var log = settings.log, mode = settings.mode;
|
|
12
12
|
var isAsync = isConsumerMode(mode);
|
|
13
13
|
/**
|
|
@@ -18,12 +18,12 @@ export function clientInputValidationDecorator(settings, client, readinessManage
|
|
|
18
18
|
var nameOrNames = methodName.indexOf('ByFlagSet') > -1 ?
|
|
19
19
|
validateFlagSets(log, methodName, maybeNameOrNames, settings.sync.__splitFiltersValidation.groupedFilters.bySet) :
|
|
20
20
|
startsWith(methodName, GET_TREATMENTS) ?
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
validateDefinitions(log, maybeNameOrNames, methodName) :
|
|
22
|
+
validateDefinition(log, maybeNameOrNames, methodName);
|
|
23
23
|
var attributes = validateAttributes(log, maybeAttributes, methodName);
|
|
24
24
|
var isNotDestroyed = validateIfNotDestroyed(log, readinessManager, methodName);
|
|
25
25
|
var options = validateEvaluationOptions(log, maybeOptions, methodName);
|
|
26
|
-
validateIfReadyFromCache(log, readinessManager, methodName
|
|
26
|
+
validateIfReadyFromCache(log, readinessManager, methodName);
|
|
27
27
|
var valid = isNotDestroyed && key && nameOrNames && attributes !== false;
|
|
28
28
|
return {
|
|
29
29
|
valid: valid,
|
|
@@ -34,111 +34,68 @@ export function clientInputValidationDecorator(settings, client, readinessManage
|
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
36
|
function evaluateFallBackTreatment(featureFlagName, withConfig) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return
|
|
37
|
+
if (Array.isArray(featureFlagName)) {
|
|
38
|
+
var res_1 = {};
|
|
39
|
+
featureFlagName.forEach(function (split) { return res_1[split] = evaluateFallBackTreatment(split, withConfig); });
|
|
40
|
+
return res_1;
|
|
41
|
+
}
|
|
42
|
+
var _a = fallbackCalculator(featureFlagName), treatment = _a.treatment, config = _a.config;
|
|
43
|
+
return withConfig ?
|
|
44
|
+
{
|
|
40
45
|
treatment: treatment,
|
|
41
46
|
config: config
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
return treatment;
|
|
47
|
+
} : treatment;
|
|
45
48
|
}
|
|
46
49
|
function wrapResult(value) {
|
|
47
50
|
return isAsync ? Promise.resolve(value) : value;
|
|
48
51
|
}
|
|
49
52
|
function getTreatment(maybeKey, maybeFeatureFlagName, maybeAttributes, maybeOptions) {
|
|
50
53
|
var params = validateEvaluationParams(GET_TREATMENT, maybeKey, maybeFeatureFlagName, maybeAttributes, maybeOptions);
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
else {
|
|
55
|
-
var result = evaluateFallBackTreatment(params.nameOrNames, false);
|
|
56
|
-
return wrapResult(result);
|
|
57
|
-
}
|
|
54
|
+
return params.valid ?
|
|
55
|
+
client.getTreatment(params.key, params.nameOrNames, params.attributes, params.options) :
|
|
56
|
+
wrapResult(evaluateFallBackTreatment(params.nameOrNames, false));
|
|
58
57
|
}
|
|
59
58
|
function getTreatmentWithConfig(maybeKey, maybeFeatureFlagName, maybeAttributes, maybeOptions) {
|
|
60
59
|
var params = validateEvaluationParams(GET_TREATMENT_WITH_CONFIG, maybeKey, maybeFeatureFlagName, maybeAttributes, maybeOptions);
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
else {
|
|
65
|
-
var result = evaluateFallBackTreatment(params.nameOrNames, true);
|
|
66
|
-
return wrapResult(result);
|
|
67
|
-
}
|
|
60
|
+
return params.valid ?
|
|
61
|
+
client.getTreatmentWithConfig(params.key, params.nameOrNames, params.attributes, params.options) :
|
|
62
|
+
wrapResult(evaluateFallBackTreatment(params.nameOrNames, true));
|
|
68
63
|
}
|
|
69
64
|
function getTreatments(maybeKey, maybeFeatureFlagNames, maybeAttributes, maybeOptions) {
|
|
70
65
|
var params = validateEvaluationParams(GET_TREATMENTS, maybeKey, maybeFeatureFlagNames, maybeAttributes, maybeOptions);
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
else {
|
|
75
|
-
var res_1 = {};
|
|
76
|
-
if (params.nameOrNames)
|
|
77
|
-
params.nameOrNames.forEach(function (split) { return res_1[split] = evaluateFallBackTreatment(split, false); });
|
|
78
|
-
return wrapResult(res_1);
|
|
79
|
-
}
|
|
66
|
+
return params.valid ?
|
|
67
|
+
client.getTreatments(params.key, params.nameOrNames, params.attributes, params.options) :
|
|
68
|
+
wrapResult(evaluateFallBackTreatment(params.nameOrNames || [], false));
|
|
80
69
|
}
|
|
81
70
|
function getTreatmentsWithConfig(maybeKey, maybeFeatureFlagNames, maybeAttributes, maybeOptions) {
|
|
82
71
|
var params = validateEvaluationParams(GET_TREATMENTS_WITH_CONFIG, maybeKey, maybeFeatureFlagNames, maybeAttributes, maybeOptions);
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
else {
|
|
87
|
-
var res_2 = {};
|
|
88
|
-
if (params.nameOrNames)
|
|
89
|
-
params.nameOrNames.forEach(function (split) { return res_2[split] = evaluateFallBackTreatment(split, true); });
|
|
90
|
-
return wrapResult(res_2);
|
|
91
|
-
}
|
|
72
|
+
return params.valid ?
|
|
73
|
+
client.getTreatmentsWithConfig(params.key, params.nameOrNames, params.attributes, params.options) :
|
|
74
|
+
wrapResult(evaluateFallBackTreatment(params.nameOrNames || [], true));
|
|
92
75
|
}
|
|
93
76
|
function getTreatmentsByFlagSets(maybeKey, maybeFlagSets, maybeAttributes, maybeOptions) {
|
|
94
77
|
var params = validateEvaluationParams(GET_TREATMENTS_BY_FLAG_SETS, maybeKey, maybeFlagSets, maybeAttributes, maybeOptions);
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
else {
|
|
99
|
-
return wrapResult({});
|
|
100
|
-
}
|
|
78
|
+
return params.valid ?
|
|
79
|
+
client.getTreatmentsByFlagSets(params.key, params.nameOrNames, params.attributes, params.options) :
|
|
80
|
+
wrapResult({});
|
|
101
81
|
}
|
|
102
82
|
function getTreatmentsWithConfigByFlagSets(maybeKey, maybeFlagSets, maybeAttributes, maybeOptions) {
|
|
103
83
|
var params = validateEvaluationParams(GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, maybeKey, maybeFlagSets, maybeAttributes, maybeOptions);
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
else {
|
|
108
|
-
return wrapResult({});
|
|
109
|
-
}
|
|
84
|
+
return params.valid ?
|
|
85
|
+
client.getTreatmentsWithConfigByFlagSets(params.key, params.nameOrNames, params.attributes, params.options) :
|
|
86
|
+
wrapResult({});
|
|
110
87
|
}
|
|
111
88
|
function getTreatmentsByFlagSet(maybeKey, maybeFlagSet, maybeAttributes, maybeOptions) {
|
|
112
89
|
var params = validateEvaluationParams(GET_TREATMENTS_BY_FLAG_SET, maybeKey, [maybeFlagSet], maybeAttributes, maybeOptions);
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
else {
|
|
117
|
-
return wrapResult({});
|
|
118
|
-
}
|
|
90
|
+
return params.valid ?
|
|
91
|
+
client.getTreatmentsByFlagSet(params.key, params.nameOrNames[0], params.attributes, params.options) :
|
|
92
|
+
wrapResult({});
|
|
119
93
|
}
|
|
120
94
|
function getTreatmentsWithConfigByFlagSet(maybeKey, maybeFlagSet, maybeAttributes, maybeOptions) {
|
|
121
95
|
var params = validateEvaluationParams(GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET, maybeKey, [maybeFlagSet], maybeAttributes, maybeOptions);
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
else {
|
|
126
|
-
return wrapResult({});
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
function track(maybeKey, maybeTT, maybeEvent, maybeEventValue, maybeProperties) {
|
|
130
|
-
var key = validateKey(log, maybeKey, TRACK_FN_LABEL);
|
|
131
|
-
var tt = validateTrafficType(log, maybeTT, TRACK_FN_LABEL);
|
|
132
|
-
var event = validateEvent(log, maybeEvent, TRACK_FN_LABEL);
|
|
133
|
-
var eventValue = validateEventValue(log, maybeEventValue, TRACK_FN_LABEL);
|
|
134
|
-
var _a = validateEventProperties(log, maybeProperties, TRACK_FN_LABEL), properties = _a.properties, size = _a.size;
|
|
135
|
-
var isNotDestroyed = validateIfNotDestroyed(log, readinessManager, TRACK_FN_LABEL);
|
|
136
|
-
if (isNotDestroyed && key && tt && event && eventValue !== false && properties !== false) { // @ts-expect-error
|
|
137
|
-
return client.track(key, tt, event, eventValue, properties, size);
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
return isAsync ? Promise.resolve(false) : false;
|
|
141
|
-
}
|
|
96
|
+
return params.valid ?
|
|
97
|
+
client.getTreatmentsWithConfigByFlagSet(params.key, params.nameOrNames[0], params.attributes, params.options) :
|
|
98
|
+
wrapResult({});
|
|
142
99
|
}
|
|
143
100
|
return {
|
|
144
101
|
getTreatment: getTreatment,
|
|
@@ -149,6 +106,6 @@ export function clientInputValidationDecorator(settings, client, readinessManage
|
|
|
149
106
|
getTreatmentsWithConfigByFlagSets: getTreatmentsWithConfigByFlagSets,
|
|
150
107
|
getTreatmentsByFlagSet: getTreatmentsByFlagSet,
|
|
151
108
|
getTreatmentsWithConfigByFlagSet: getTreatmentsWithConfigByFlagSet,
|
|
152
|
-
track: track
|
|
109
|
+
track: client.track,
|
|
153
110
|
};
|
|
154
111
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export function buildInstanceId(key, trafficType) {
|
|
2
|
-
return (key.matchingKey ? key.matchingKey : key
|
|
2
|
+
return "".concat(key.matchingKey ? key.matchingKey : key, "-").concat(key.bucketingKey ? key.bucketingKey : key, "-").concat(trafficType ? trafficType : '');
|
|
3
3
|
}
|
|
@@ -1,60 +1,15 @@
|
|
|
1
1
|
import { objectAssign } from '../utils/lang/objectAssign';
|
|
2
|
-
import { releaseApiKey } from '../utils/inputValidation/apiKey';
|
|
3
2
|
import { clientFactory } from './client';
|
|
4
3
|
import { clientInputValidationDecorator } from './clientInputValidation';
|
|
5
|
-
|
|
4
|
+
import { sdkLifecycleFactory } from './sdkLifecycle';
|
|
6
5
|
/**
|
|
7
|
-
* Creates an Sdk client, i.e., a base client with status and destroy interface
|
|
6
|
+
* Creates an Sdk client, i.e., a base client with status, init, flush and destroy interface
|
|
8
7
|
*/
|
|
9
8
|
export function sdkClientFactory(params, isSharedClient) {
|
|
10
|
-
var sdkReadinessManager = params.sdkReadinessManager,
|
|
11
|
-
var lastActionTime = 0;
|
|
12
|
-
function __cooldown(func, time) {
|
|
13
|
-
var now = Date.now();
|
|
14
|
-
//get the actual time elapsed in ms
|
|
15
|
-
var timeElapsed = now - lastActionTime;
|
|
16
|
-
//check if the time elapsed is less than desired cooldown
|
|
17
|
-
if (timeElapsed < time) {
|
|
18
|
-
//if yes, return message with remaining time in seconds
|
|
19
|
-
settings.log.warn("Flush cooldown, remaining time " + (time - timeElapsed) / 1000 + " seconds");
|
|
20
|
-
return Promise.resolve();
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
//Do the requested action and re-assign the lastActionTime
|
|
24
|
-
lastActionTime = now;
|
|
25
|
-
return func();
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
function __flush() {
|
|
29
|
-
return syncManager ? syncManager.flush() : Promise.resolve();
|
|
30
|
-
}
|
|
9
|
+
var sdkReadinessManager = params.sdkReadinessManager, settings = params.settings;
|
|
31
10
|
return objectAssign(
|
|
32
11
|
// Proto-linkage of the readiness Event Emitter
|
|
33
12
|
Object.create(sdkReadinessManager.sdkStatus),
|
|
34
13
|
// Client API (getTreatment* & track methods)
|
|
35
|
-
clientInputValidationDecorator(settings, clientFactory(params), sdkReadinessManager.readinessManager, params.
|
|
36
|
-
// Sdk destroy
|
|
37
|
-
{
|
|
38
|
-
flush: function () {
|
|
39
|
-
// @TODO define cooldown time
|
|
40
|
-
return __cooldown(__flush, COOLDOWN_TIME_IN_MILLIS);
|
|
41
|
-
},
|
|
42
|
-
destroy: function () {
|
|
43
|
-
// Mark the SDK as destroyed immediately
|
|
44
|
-
sdkReadinessManager.readinessManager.destroy();
|
|
45
|
-
// For main client, cleanup the SDK Key, listeners and scheduled jobs, and record stat before flushing data
|
|
46
|
-
if (!isSharedClient) {
|
|
47
|
-
releaseApiKey(settings.core.authorizationKey);
|
|
48
|
-
telemetryTracker.sessionLength();
|
|
49
|
-
signalListener && signalListener.stop();
|
|
50
|
-
uniqueKeysTracker.stop();
|
|
51
|
-
}
|
|
52
|
-
// Stop background jobs
|
|
53
|
-
syncManager && syncManager.stop();
|
|
54
|
-
return __flush().then(function () {
|
|
55
|
-
// Cleanup storage
|
|
56
|
-
return storage.destroy();
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
});
|
|
14
|
+
clientInputValidationDecorator(settings, clientFactory(params), sdkReadinessManager.readinessManager, params.fallbackCalculator), sdkLifecycleFactory(params, isSharedClient));
|
|
60
15
|
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { releaseApiKey, validateAndTrackApiKey } from '../utils/inputValidation/apiKey';
|
|
2
|
+
var COOLDOWN_TIME_IN_MILLIS = 1000;
|
|
3
|
+
/**
|
|
4
|
+
* Creates an Sdk client, i.e., a base client with status, init, flush and destroy interface
|
|
5
|
+
*/
|
|
6
|
+
export function sdkLifecycleFactory(params, isSharedClient) {
|
|
7
|
+
var sdkReadinessManager = params.sdkReadinessManager, syncManager = params.syncManager, storage = params.storage, settings = params.settings, telemetryTracker = params.telemetryTracker, impressionsTracker = params.impressionsTracker, platform = params.platform;
|
|
8
|
+
var hasInit = false;
|
|
9
|
+
var lastActionTime = 0;
|
|
10
|
+
var signalListener = platform.SignalListener && new platform.SignalListener(params);
|
|
11
|
+
function __cooldown(func, time) {
|
|
12
|
+
var now = Date.now();
|
|
13
|
+
//get the actual time elapsed in ms
|
|
14
|
+
var timeElapsed = now - lastActionTime;
|
|
15
|
+
//check if the time elapsed is less than desired cooldown
|
|
16
|
+
if (timeElapsed < time) {
|
|
17
|
+
//if yes, return message with remaining time in seconds
|
|
18
|
+
settings.log.warn("Flush cooldown, remaining time ".concat((time - timeElapsed) / 1000, " seconds"));
|
|
19
|
+
return Promise.resolve();
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
//Do the requested action and re-assign the lastActionTime
|
|
23
|
+
lastActionTime = now;
|
|
24
|
+
return func();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function __flush() {
|
|
28
|
+
return syncManager ? syncManager.flush() : Promise.resolve();
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
init: function () {
|
|
32
|
+
if (hasInit)
|
|
33
|
+
return;
|
|
34
|
+
hasInit = true;
|
|
35
|
+
if (!isSharedClient) {
|
|
36
|
+
validateAndTrackApiKey(settings.log, settings.core.authorizationKey);
|
|
37
|
+
sdkReadinessManager.readinessManager.init();
|
|
38
|
+
impressionsTracker.start();
|
|
39
|
+
syncManager && syncManager.start();
|
|
40
|
+
signalListener && signalListener.start();
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
flush: function () {
|
|
44
|
+
// @TODO define cooldown time
|
|
45
|
+
return __cooldown(__flush, COOLDOWN_TIME_IN_MILLIS);
|
|
46
|
+
},
|
|
47
|
+
destroy: function () {
|
|
48
|
+
hasInit = false;
|
|
49
|
+
// Mark the SDK as destroyed immediately
|
|
50
|
+
sdkReadinessManager.readinessManager.destroy();
|
|
51
|
+
// For main client, cleanup the SDK Key, listeners and scheduled jobs, and record stat before flushing data
|
|
52
|
+
if (!isSharedClient) {
|
|
53
|
+
releaseApiKey(settings.core.authorizationKey);
|
|
54
|
+
telemetryTracker.sessionLength();
|
|
55
|
+
signalListener && signalListener.stop();
|
|
56
|
+
impressionsTracker.stop();
|
|
57
|
+
}
|
|
58
|
+
// Stop background jobs
|
|
59
|
+
syncManager && syncManager.stop();
|
|
60
|
+
return __flush().then(function () {
|
|
61
|
+
// Cleanup storage
|
|
62
|
+
return storage.destroy();
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { thenable } from '../utils/promise/thenable';
|
|
2
|
+
import { getMatching } from '../utils/key';
|
|
3
|
+
import { validateTrafficTypeExistence } from '../utils/inputValidation/trafficTypeExistence';
|
|
4
|
+
import { validateKey, validateTrafficType, validateEvent, validateEventValue, validateEventProperties, validateIfNotDestroyed } from '../utils/inputValidation';
|
|
5
|
+
import { TRACK, TRACK_FN_LABEL } from '../utils/constants';
|
|
6
|
+
import { isConsumerMode } from '../utils/settingsValidation/mode';
|
|
7
|
+
/**
|
|
8
|
+
* Creates a standalone `track` function with input validation.
|
|
9
|
+
* Reusable by FF SDK client, Configs SDK, and thin-client SDK.
|
|
10
|
+
*/
|
|
11
|
+
export function trackMethodFactory(params, warnTTExistence) {
|
|
12
|
+
if (warnTTExistence === void 0) { warnTTExistence = true; }
|
|
13
|
+
var settings = params.settings, splits = params.storage.splits, telemetryTracker = params.telemetryTracker, eventTracker = params.eventTracker, readinessManager = params.sdkReadinessManager.readinessManager;
|
|
14
|
+
var log = settings.log, mode = settings.mode;
|
|
15
|
+
var isAsync = isConsumerMode(mode);
|
|
16
|
+
return function track(maybeKey, maybeTT, maybeEvent, maybeEventValue, maybeProperties) {
|
|
17
|
+
// Input validation
|
|
18
|
+
var key = validateKey(log, maybeKey, TRACK_FN_LABEL);
|
|
19
|
+
var trafficTypeName = validateTrafficType(log, maybeTT, TRACK_FN_LABEL);
|
|
20
|
+
var eventTypeId = validateEvent(log, maybeEvent, TRACK_FN_LABEL);
|
|
21
|
+
var value = validateEventValue(log, maybeEventValue, TRACK_FN_LABEL);
|
|
22
|
+
var _a = validateEventProperties(log, maybeProperties, TRACK_FN_LABEL), properties = _a.properties, size = _a.size;
|
|
23
|
+
var isNotDestroyed = validateIfNotDestroyed(log, readinessManager, TRACK_FN_LABEL);
|
|
24
|
+
if (!(isNotDestroyed && key && trafficTypeName && eventTypeId && value !== false && properties !== false)) {
|
|
25
|
+
return isAsync ? Promise.resolve(false) : false;
|
|
26
|
+
}
|
|
27
|
+
// Core logic
|
|
28
|
+
var stopTelemetryTracker = telemetryTracker.trackEval(TRACK);
|
|
29
|
+
var eventData = {
|
|
30
|
+
eventTypeId: eventTypeId,
|
|
31
|
+
trafficTypeName: trafficTypeName,
|
|
32
|
+
value: value,
|
|
33
|
+
timestamp: Date.now(),
|
|
34
|
+
key: getMatching(key),
|
|
35
|
+
properties: properties
|
|
36
|
+
};
|
|
37
|
+
// 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.
|
|
38
|
+
if (warnTTExistence)
|
|
39
|
+
validateTrafficTypeExistence(log, readinessManager, splits, mode, trafficTypeName, TRACK_FN_LABEL);
|
|
40
|
+
var result = eventTracker.track(eventData, size);
|
|
41
|
+
if (thenable(result)) {
|
|
42
|
+
return result.then(function (result) {
|
|
43
|
+
stopTelemetryTracker();
|
|
44
|
+
return result;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
stopTelemetryTracker();
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
package/esm/sdkFactory/index.js
CHANGED
|
@@ -2,16 +2,10 @@ import { sdkReadinessManagerFactory } from '../readiness/sdkReadinessManager';
|
|
|
2
2
|
import { impressionsTrackerFactory } from '../trackers/impressionsTracker';
|
|
3
3
|
import { eventTrackerFactory } from '../trackers/eventTracker';
|
|
4
4
|
import { telemetryTrackerFactory } from '../trackers/telemetryTracker';
|
|
5
|
-
import { validateAndTrackApiKey } from '../utils/inputValidation/apiKey';
|
|
6
5
|
import { createLoggerAPI } from '../logger/sdkLogger';
|
|
7
6
|
import { NEW_FACTORY, RETRIEVE_MANAGER } from '../logger/constants';
|
|
8
7
|
import { SDK_SPLITS_ARRIVED, SDK_SEGMENTS_ARRIVED, SDK_SPLITS_CACHE_LOADED } from '../readiness/constants';
|
|
9
8
|
import { objectAssign } from '../utils/lang/objectAssign';
|
|
10
|
-
import { strategyDebugFactory } from '../trackers/strategy/strategyDebug';
|
|
11
|
-
import { strategyOptimizedFactory } from '../trackers/strategy/strategyOptimized';
|
|
12
|
-
import { strategyNoneFactory } from '../trackers/strategy/strategyNone';
|
|
13
|
-
import { uniqueKeysTrackerFactory } from '../trackers/uniqueKeysTracker';
|
|
14
|
-
import { DEBUG, OPTIMIZED } from '../utils/constants';
|
|
15
9
|
import { setRolloutPlan } from '../storages/setRolloutPlan';
|
|
16
10
|
import { getMatching } from '../utils/key';
|
|
17
11
|
import { FallbackTreatmentsCalculator } from '../evaluator/fallbackTreatmentsCalculator';
|
|
@@ -19,19 +13,10 @@ import { FallbackTreatmentsCalculator } from '../evaluator/fallbackTreatmentsCal
|
|
|
19
13
|
* Modular SDK factory
|
|
20
14
|
*/
|
|
21
15
|
export function sdkFactory(params) {
|
|
22
|
-
var settings = params.settings, platform = params.platform, storageFactory = params.storageFactory, splitApiFactory = params.splitApiFactory, extraProps = params.extraProps, syncManagerFactory = params.syncManagerFactory,
|
|
23
|
-
var log = settings.log,
|
|
16
|
+
var settings = params.settings, platform = params.platform, storageFactory = params.storageFactory, splitApiFactory = params.splitApiFactory, extraProps = params.extraProps, syncManagerFactory = params.syncManagerFactory, integrationsManagerFactory = params.integrationsManagerFactory, sdkManagerFactory = params.sdkManagerFactory, sdkClientMethodFactory = params.sdkClientMethodFactory, lazyInit = params.lazyInit;
|
|
17
|
+
var log = settings.log, initialRolloutPlan = settings.initialRolloutPlan, key = settings.core.key;
|
|
24
18
|
// @TODO handle non-recoverable errors, such as, global `fetch` not available, invalid SDK Key, etc.
|
|
25
19
|
// On non-recoverable errors, we should mark the SDK as destroyed and not start synchronization.
|
|
26
|
-
// initialization
|
|
27
|
-
var hasInit = false;
|
|
28
|
-
var initCallbacks = [];
|
|
29
|
-
function whenInit(cb) {
|
|
30
|
-
if (hasInit)
|
|
31
|
-
cb();
|
|
32
|
-
else
|
|
33
|
-
initCallbacks.push(cb);
|
|
34
|
-
}
|
|
35
20
|
var sdkReadinessManager = sdkReadinessManagerFactory(platform.EventEmitter, settings);
|
|
36
21
|
var readiness = sdkReadinessManager.readinessManager;
|
|
37
22
|
var storage = storageFactory({
|
|
@@ -49,7 +34,7 @@ export function sdkFactory(params) {
|
|
|
49
34
|
readiness.splits.emit(SDK_SPLITS_CACHE_LOADED);
|
|
50
35
|
}
|
|
51
36
|
});
|
|
52
|
-
var
|
|
37
|
+
var fallbackCalculator = FallbackTreatmentsCalculator(settings.fallbackTreatments);
|
|
53
38
|
if (initialRolloutPlan) {
|
|
54
39
|
setRolloutPlan(log, initialRolloutPlan, storage, key && getMatching(key));
|
|
55
40
|
if (storage.splits.getChangeNumber() > -1)
|
|
@@ -58,38 +43,17 @@ export function sdkFactory(params) {
|
|
|
58
43
|
var clients = {};
|
|
59
44
|
var telemetryTracker = telemetryTrackerFactory(storage.telemetry, platform.now);
|
|
60
45
|
var integrationsManager = integrationsManagerFactory && integrationsManagerFactory({ settings: settings, storage: storage, telemetryTracker: telemetryTracker });
|
|
61
|
-
var
|
|
62
|
-
var
|
|
63
|
-
var noneStrategy = strategyNoneFactory(storage.impressionCounts, uniqueKeysTracker);
|
|
64
|
-
var strategy = impressionsMode === OPTIMIZED ?
|
|
65
|
-
strategyOptimizedFactory(observer, storage.impressionCounts) :
|
|
66
|
-
impressionsMode === DEBUG ?
|
|
67
|
-
strategyDebugFactory(observer) :
|
|
68
|
-
noneStrategy;
|
|
69
|
-
var impressionsTracker = impressionsTrackerFactory(settings, storage.impressions, noneStrategy, strategy, whenInit, integrationsManager, storage.telemetry);
|
|
70
|
-
var eventTracker = eventTrackerFactory(settings, storage.events, whenInit, integrationsManager, storage.telemetry);
|
|
46
|
+
var impressionsTracker = impressionsTrackerFactory(params, storage, integrationsManager);
|
|
47
|
+
var eventTracker = eventTrackerFactory(settings, storage.events, integrationsManager, storage.telemetry);
|
|
71
48
|
// splitApi is used by SyncManager and Browser signal listener
|
|
72
49
|
var splitApi = splitApiFactory && splitApiFactory(settings, platform, telemetryTracker);
|
|
73
|
-
var ctx = { clients: clients, splitApi: splitApi, eventTracker: eventTracker, impressionsTracker: impressionsTracker, telemetryTracker: telemetryTracker,
|
|
74
|
-
|
|
75
|
-
ctx.syncManager = syncManager;
|
|
76
|
-
var signalListener = SignalListener && new SignalListener(syncManager, settings, storage, splitApi);
|
|
77
|
-
ctx.signalListener = signalListener;
|
|
50
|
+
var ctx = { clients: clients, splitApi: splitApi, eventTracker: eventTracker, impressionsTracker: impressionsTracker, telemetryTracker: telemetryTracker, sdkReadinessManager: sdkReadinessManager, readiness: readiness, settings: settings, storage: storage, platform: platform, fallbackCalculator: fallbackCalculator };
|
|
51
|
+
ctx.syncManager = syncManagerFactory && syncManagerFactory(ctx);
|
|
78
52
|
// SDK client and manager
|
|
79
53
|
var clientMethod = sdkClientMethodFactory(ctx);
|
|
80
54
|
var managerInstance = sdkManagerFactory(settings, storage.splits, sdkReadinessManager);
|
|
81
55
|
function init() {
|
|
82
|
-
|
|
83
|
-
return;
|
|
84
|
-
hasInit = true;
|
|
85
|
-
// We will just log and allow for the SDK to end up throwing an SDK_TIMEOUT event for devs to handle.
|
|
86
|
-
validateAndTrackApiKey(log, settings.core.authorizationKey);
|
|
87
|
-
readiness.init();
|
|
88
|
-
uniqueKeysTracker.start();
|
|
89
|
-
syncManager && syncManager.start();
|
|
90
|
-
signalListener && signalListener.start();
|
|
91
|
-
initCallbacks.forEach(function (cb) { return cb(); });
|
|
92
|
-
initCallbacks.length = 0;
|
|
56
|
+
Object.keys(clients).map(function (key) { return clients[key].init(); });
|
|
93
57
|
}
|
|
94
58
|
log.info(NEW_FACTORY, [settings.version]);
|
|
95
59
|
// @ts-ignore
|
|
@@ -105,7 +69,6 @@ export function sdkFactory(params) {
|
|
|
105
69
|
Logger: createLoggerAPI(log),
|
|
106
70
|
settings: settings,
|
|
107
71
|
destroy: function () {
|
|
108
|
-
hasInit = false;
|
|
109
72
|
return Promise.all(Object.keys(clients).map(function (key) { return clients[key].destroy(); })).then(function () { });
|
|
110
73
|
}
|
|
111
74
|
}, extraProps && extraProps(ctx), lazyInit ? { init: init } : init());
|
package/esm/sdkManager/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { objectAssign } from '../utils/lang/objectAssign';
|
|
2
2
|
import { thenable } from '../utils/promise/thenable';
|
|
3
3
|
import { find } from '../utils/lang';
|
|
4
|
-
import {
|
|
4
|
+
import { validateDefinition, validateDefinitionExistence, validateIfOperational } from '../utils/inputValidation';
|
|
5
5
|
import { isConsumerMode } from '../utils/settingsValidation/mode';
|
|
6
6
|
import { SPLIT_FN_LABEL, SPLITS_FN_LABEL, NAMES_FN_LABEL } from '../utils/constants';
|
|
7
7
|
function collectTreatments(splitObject) {
|
|
@@ -50,18 +50,18 @@ export function sdkManagerFactory(settings, splits, _a) {
|
|
|
50
50
|
* Get the feature flag object corresponding to the given feature flag name if valid
|
|
51
51
|
*/
|
|
52
52
|
split: function (featureFlagName) {
|
|
53
|
-
var splitName =
|
|
53
|
+
var splitName = validateDefinition(log, featureFlagName, SPLIT_FN_LABEL);
|
|
54
54
|
if (!validateIfOperational(log, readinessManager, SPLIT_FN_LABEL) || !splitName) {
|
|
55
55
|
return isAsync ? Promise.resolve(null) : null;
|
|
56
56
|
}
|
|
57
57
|
var split = splits.getSplit(splitName);
|
|
58
58
|
if (thenable(split)) {
|
|
59
59
|
return split.catch(function () { return null; }).then(function (result) {
|
|
60
|
-
|
|
60
|
+
validateDefinitionExistence(log, readinessManager, splitName, result, SPLIT_FN_LABEL);
|
|
61
61
|
return objectToView(result);
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
|
-
|
|
64
|
+
validateDefinitionExistence(log, readinessManager, splitName, split, SPLIT_FN_LABEL);
|
|
65
65
|
return objectToView(split);
|
|
66
66
|
},
|
|
67
67
|
/**
|