@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
|
@@ -4,7 +4,7 @@ exports.validateAttribute = void 0;
|
|
|
4
4
|
var lang_1 = require("../../utils/lang");
|
|
5
5
|
function validateAttribute(log, attributeKey, attributeValue, method) {
|
|
6
6
|
if (!(0, lang_1.isString)(attributeKey) || attributeKey.length === 0) {
|
|
7
|
-
log.warn(method
|
|
7
|
+
log.warn("".concat(method, ": you passed an invalid attribute name, attribute name must be a non-empty string."));
|
|
8
8
|
return false;
|
|
9
9
|
}
|
|
10
10
|
var isStringVal = (0, lang_1.isString)(attributeValue);
|
|
@@ -12,7 +12,7 @@ function validateAttribute(log, attributeKey, attributeValue, method) {
|
|
|
12
12
|
var isBoolVal = (0, lang_1.isBoolean)(attributeValue);
|
|
13
13
|
var isArrayVal = Array.isArray(attributeValue);
|
|
14
14
|
if (!(isStringVal || isFiniteVal || isBoolVal || isArrayVal)) { // If it's not of valid type.
|
|
15
|
-
log.warn(method
|
|
15
|
+
log.warn("".concat(method, ": you passed an invalid attribute value for ").concat(attributeKey, ". Acceptable types are: string, number, boolean and array of strings."));
|
|
16
16
|
return false;
|
|
17
17
|
}
|
|
18
18
|
return true;
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.validateDefinition = void 0;
|
|
4
4
|
var constants_1 = require("../../logger/constants");
|
|
5
5
|
var lang_1 = require("../lang");
|
|
6
6
|
// include BOM and nbsp
|
|
7
7
|
var TRIMMABLE_SPACES_REGEX = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/;
|
|
8
|
-
function
|
|
8
|
+
function validateDefinition(log, maybeDefinition, method, item) {
|
|
9
9
|
if (item === void 0) { item = 'feature flag name'; }
|
|
10
|
-
if (
|
|
10
|
+
if (maybeDefinition == undefined) { // eslint-disable-line eqeqeq
|
|
11
11
|
log.error(constants_1.ERROR_NULL, [method, item]);
|
|
12
12
|
}
|
|
13
|
-
else if (!(0, lang_1.isString)(
|
|
13
|
+
else if (!(0, lang_1.isString)(maybeDefinition)) {
|
|
14
14
|
log.error(constants_1.ERROR_INVALID, [method, item]);
|
|
15
15
|
}
|
|
16
16
|
else {
|
|
17
|
-
if (TRIMMABLE_SPACES_REGEX.test(
|
|
18
|
-
log.warn(constants_1.WARN_TRIMMING, [method, item,
|
|
19
|
-
|
|
17
|
+
if (TRIMMABLE_SPACES_REGEX.test(maybeDefinition)) {
|
|
18
|
+
log.warn(constants_1.WARN_TRIMMING, [method, item, maybeDefinition]);
|
|
19
|
+
maybeDefinition = maybeDefinition.trim();
|
|
20
20
|
}
|
|
21
|
-
if (
|
|
22
|
-
return
|
|
21
|
+
if (maybeDefinition.length > 0) {
|
|
22
|
+
return maybeDefinition;
|
|
23
23
|
}
|
|
24
24
|
else {
|
|
25
25
|
log.error(constants_1.ERROR_EMPTY, [method, item]);
|
|
@@ -27,4 +27,4 @@ function validateSplit(log, maybeSplit, method, item) {
|
|
|
27
27
|
}
|
|
28
28
|
return false;
|
|
29
29
|
}
|
|
30
|
-
exports.
|
|
30
|
+
exports.validateDefinition = validateDefinition;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.validateDefinitionExistence = void 0;
|
|
4
4
|
var labels_1 = require("../labels");
|
|
5
5
|
var constants_1 = require("../../logger/constants");
|
|
6
6
|
/**
|
|
7
7
|
* This is defined here and in this format mostly because of the logger and the fact that it's considered a validation at product level.
|
|
8
|
-
* But it's not going to run on the input validation layer. In any case, the most compelling reason to use it as we do is to avoid going to Redis and get a
|
|
8
|
+
* But it's not going to run on the input validation layer. In any case, the most compelling reason to use it as we do is to avoid going to Redis and get a definition twice.
|
|
9
9
|
*/
|
|
10
|
-
function
|
|
10
|
+
function validateDefinitionExistence(log, readinessManager, definitionName, labelOrDefinitionObj, method) {
|
|
11
11
|
if (readinessManager.isReady()) { // Only if it's ready (synced with BE) we validate this, otherwise it may just be that the SDK is still syncing
|
|
12
|
-
if (
|
|
13
|
-
log.warn(constants_1.
|
|
12
|
+
if (labelOrDefinitionObj === labels_1.DEFINITION_NOT_FOUND || labelOrDefinitionObj === labels_1.FALLBACK_DEFINITION_NOT_FOUND || labelOrDefinitionObj == null) {
|
|
13
|
+
log.warn(constants_1.WARN_NOT_EXISTENT_DEFINITION, [method, definitionName]);
|
|
14
14
|
return false;
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
return true;
|
|
18
18
|
}
|
|
19
|
-
exports.
|
|
19
|
+
exports.validateDefinitionExistence = validateDefinitionExistence;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateDefinitions = void 0;
|
|
4
|
+
var constants_1 = require("../../logger/constants");
|
|
5
|
+
var lang_1 = require("../lang");
|
|
6
|
+
var definition_1 = require("./definition");
|
|
7
|
+
function validateDefinitions(log, maybeDefinitions, method, listName, item) {
|
|
8
|
+
if (listName === void 0) { listName = 'feature flag names'; }
|
|
9
|
+
if (item === void 0) { item = 'feature flag name'; }
|
|
10
|
+
if (Array.isArray(maybeDefinitions) && maybeDefinitions.length > 0) {
|
|
11
|
+
var validatedArray_1 = [];
|
|
12
|
+
// Remove invalid values
|
|
13
|
+
maybeDefinitions.forEach(function (maybeDefinition) {
|
|
14
|
+
var definitionName = (0, definition_1.validateDefinition)(log, maybeDefinition, method, item);
|
|
15
|
+
if (definitionName)
|
|
16
|
+
validatedArray_1.push(definitionName);
|
|
17
|
+
});
|
|
18
|
+
// Strip off duplicated values if we have valid definition names then return
|
|
19
|
+
if (validatedArray_1.length)
|
|
20
|
+
return (0, lang_1.uniq)(validatedArray_1);
|
|
21
|
+
}
|
|
22
|
+
log.error(constants_1.ERROR_EMPTY_ARRAY, [method, listName]);
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
exports.validateDefinitions = validateDefinitions;
|
|
@@ -70,7 +70,7 @@ function validateEvaluationOptions(log, maybeOptions, method) {
|
|
|
70
70
|
if (!impressionsDisabled)
|
|
71
71
|
return options;
|
|
72
72
|
// @ts-expect-error impressionsDisabled is not exposed in the public typings yet.
|
|
73
|
-
return options ?
|
|
73
|
+
return options ? tslib_1.__assign(tslib_1.__assign({}, options), { impressionsDisabled: impressionsDisabled }) : { impressionsDisabled: impressionsDisabled };
|
|
74
74
|
}
|
|
75
75
|
else if (maybeOptions) {
|
|
76
76
|
log.error(constants_1.ERROR_NOT_PLAIN_OBJECT, [method, 'evaluation options']);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateEvaluationOptions = exports.validateTrafficTypeExistence = exports.
|
|
3
|
+
exports.validateEvaluationOptions = exports.validateTrafficTypeExistence = exports.validateDefinitionExistence = exports.validateIfOperational = exports.validateIfReadyFromCache = exports.validateIfNotDestroyed = exports.validateTrafficType = exports.validateDefinitions = exports.validateDefinition = exports.validateKey = exports.validateEventProperties = exports.validateEventValue = exports.validateEvent = exports.validateAttributes = exports.releaseApiKey = exports.validateAndTrackApiKey = exports.validateApiKey = void 0;
|
|
4
4
|
var apiKey_1 = require("./apiKey");
|
|
5
5
|
Object.defineProperty(exports, "validateApiKey", { enumerable: true, get: function () { return apiKey_1.validateApiKey; } });
|
|
6
6
|
Object.defineProperty(exports, "validateAndTrackApiKey", { enumerable: true, get: function () { return apiKey_1.validateAndTrackApiKey; } });
|
|
@@ -15,18 +15,18 @@ var eventProperties_1 = require("./eventProperties");
|
|
|
15
15
|
Object.defineProperty(exports, "validateEventProperties", { enumerable: true, get: function () { return eventProperties_1.validateEventProperties; } });
|
|
16
16
|
var key_1 = require("./key");
|
|
17
17
|
Object.defineProperty(exports, "validateKey", { enumerable: true, get: function () { return key_1.validateKey; } });
|
|
18
|
-
var
|
|
19
|
-
Object.defineProperty(exports, "
|
|
20
|
-
var
|
|
21
|
-
Object.defineProperty(exports, "
|
|
18
|
+
var definition_1 = require("./definition");
|
|
19
|
+
Object.defineProperty(exports, "validateDefinition", { enumerable: true, get: function () { return definition_1.validateDefinition; } });
|
|
20
|
+
var definitions_1 = require("./definitions");
|
|
21
|
+
Object.defineProperty(exports, "validateDefinitions", { enumerable: true, get: function () { return definitions_1.validateDefinitions; } });
|
|
22
22
|
var trafficType_1 = require("./trafficType");
|
|
23
23
|
Object.defineProperty(exports, "validateTrafficType", { enumerable: true, get: function () { return trafficType_1.validateTrafficType; } });
|
|
24
24
|
var isOperational_1 = require("./isOperational");
|
|
25
25
|
Object.defineProperty(exports, "validateIfNotDestroyed", { enumerable: true, get: function () { return isOperational_1.validateIfNotDestroyed; } });
|
|
26
26
|
Object.defineProperty(exports, "validateIfReadyFromCache", { enumerable: true, get: function () { return isOperational_1.validateIfReadyFromCache; } });
|
|
27
27
|
Object.defineProperty(exports, "validateIfOperational", { enumerable: true, get: function () { return isOperational_1.validateIfOperational; } });
|
|
28
|
-
var
|
|
29
|
-
Object.defineProperty(exports, "
|
|
28
|
+
var definitionExistence_1 = require("./definitionExistence");
|
|
29
|
+
Object.defineProperty(exports, "validateDefinitionExistence", { enumerable: true, get: function () { return definitionExistence_1.validateDefinitionExistence; } });
|
|
30
30
|
var trafficTypeExistence_1 = require("./trafficTypeExistence");
|
|
31
31
|
Object.defineProperty(exports, "validateTrafficTypeExistence", { enumerable: true, get: function () { return trafficTypeExistence_1.validateTrafficTypeExistence; } });
|
|
32
32
|
var eventProperties_2 = require("./eventProperties");
|
|
@@ -9,15 +9,15 @@ function validateIfNotDestroyed(log, readinessManager, method) {
|
|
|
9
9
|
return false;
|
|
10
10
|
}
|
|
11
11
|
exports.validateIfNotDestroyed = validateIfNotDestroyed;
|
|
12
|
-
function validateIfReadyFromCache(log, readinessManager, method
|
|
12
|
+
function validateIfReadyFromCache(log, readinessManager, method) {
|
|
13
13
|
if (readinessManager.isReadyFromCache())
|
|
14
14
|
return true;
|
|
15
|
-
log.warn(constants_1.CLIENT_NOT_READY_FROM_CACHE, [method
|
|
15
|
+
log.warn(constants_1.CLIENT_NOT_READY_FROM_CACHE, [method]);
|
|
16
16
|
return false;
|
|
17
17
|
}
|
|
18
18
|
exports.validateIfReadyFromCache = validateIfReadyFromCache;
|
|
19
19
|
// Operational means that the SDK is ready to evaluate (not destroyed and ready from cache)
|
|
20
|
-
function validateIfOperational(log, readinessManager, method
|
|
21
|
-
return validateIfNotDestroyed(log, readinessManager, method) && validateIfReadyFromCache(log, readinessManager, method
|
|
20
|
+
function validateIfOperational(log, readinessManager, method) {
|
|
21
|
+
return validateIfNotDestroyed(log, readinessManager, method) && validateIfReadyFromCache(log, readinessManager, method);
|
|
22
22
|
}
|
|
23
23
|
exports.validateIfOperational = validateIfOperational;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateTarget = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var lang_1 = require("../lang");
|
|
6
|
+
var key_1 = require("./key");
|
|
7
|
+
var attributes_1 = require("./attributes");
|
|
8
|
+
var constants_1 = require("../../logger/constants");
|
|
9
|
+
function validateTarget(log, maybeTarget, method) {
|
|
10
|
+
if (!(0, lang_1.isObject)(maybeTarget)) {
|
|
11
|
+
log.error(constants_1.ERROR_NOT_PLAIN_OBJECT, [method, 'target']);
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
var key = (0, key_1.validateKey)(log, maybeTarget.key, method);
|
|
15
|
+
if (key === false)
|
|
16
|
+
return false;
|
|
17
|
+
var attributes = (0, attributes_1.validateAttributes)(log, maybeTarget.attributes, method);
|
|
18
|
+
if (attributes === false)
|
|
19
|
+
return false;
|
|
20
|
+
return tslib_1.__assign(tslib_1.__assign({}, maybeTarget), { key: key, attributes: attributes });
|
|
21
|
+
}
|
|
22
|
+
exports.validateTarget = validateTarget;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.FALLBACK_DEFINITION_NOT_FOUND = exports.PREREQUISITES_NOT_MET = exports.UNSUPPORTED_MATCHER_TYPE = exports.NOT_IN_SPLIT = exports.SPLIT_ARCHIVED = exports.EXCEPTION = exports.SDK_NOT_READY = exports.DEFINITION_NOT_FOUND = exports.NO_CONDITION_MATCH = exports.SPLIT_KILLED = void 0;
|
|
4
4
|
var fallbackTreatmentsCalculator_1 = require("../../evaluator/fallbackTreatmentsCalculator");
|
|
5
5
|
exports.SPLIT_KILLED = 'killed';
|
|
6
6
|
exports.NO_CONDITION_MATCH = 'default rule';
|
|
7
|
-
exports.
|
|
7
|
+
exports.DEFINITION_NOT_FOUND = 'definition not found';
|
|
8
8
|
exports.SDK_NOT_READY = 'not ready';
|
|
9
9
|
exports.EXCEPTION = 'exception';
|
|
10
10
|
exports.SPLIT_ARCHIVED = 'archived';
|
|
11
11
|
exports.NOT_IN_SPLIT = 'not in split';
|
|
12
12
|
exports.UNSUPPORTED_MATCHER_TYPE = 'targeting rule type unsupported by sdk';
|
|
13
13
|
exports.PREREQUISITES_NOT_MET = 'prerequisites not met';
|
|
14
|
-
exports.
|
|
14
|
+
exports.FALLBACK_DEFINITION_NOT_FOUND = fallbackTreatmentsCalculator_1.FALLBACK_PREFIX + exports.DEFINITION_NOT_FOUND;
|
package/cjs/utils/lang/index.js
CHANGED
|
@@ -200,7 +200,7 @@ function merge(target, source) {
|
|
|
200
200
|
});
|
|
201
201
|
if (rest && rest.length) {
|
|
202
202
|
var nextSource = rest.splice(0, 1)[0];
|
|
203
|
-
res = merge.apply(void 0,
|
|
203
|
+
res = merge.apply(void 0, tslib_1.__spreadArray([res, nextSource], rest, false));
|
|
204
204
|
}
|
|
205
205
|
return res;
|
|
206
206
|
}
|
|
@@ -6,7 +6,7 @@ function timeout(ms, promise) {
|
|
|
6
6
|
return promise;
|
|
7
7
|
return new Promise(function (resolve, reject) {
|
|
8
8
|
var tid = setTimeout(function () {
|
|
9
|
-
reject(new Error("Operation timed out because it exceeded the configured time limit of "
|
|
9
|
+
reject(new Error("Operation timed out because it exceeded the configured time limit of ".concat(ms, " ms.")));
|
|
10
10
|
}, ms);
|
|
11
11
|
promise.then(function (res) {
|
|
12
12
|
clearTimeout(tid);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.validateFlagSets = exports.validateSplitFilters = void 0;
|
|
4
|
-
var
|
|
4
|
+
var definitions_1 = require("../inputValidation/definitions");
|
|
5
5
|
var constants_1 = require("../../logger/constants");
|
|
6
6
|
var objectAssign_1 = require("../lang/objectAssign");
|
|
7
7
|
var lang_1 = require("../lang");
|
|
@@ -45,14 +45,14 @@ function validateFilterType(maybeFilterType) {
|
|
|
45
45
|
*/
|
|
46
46
|
function validateSplitFilter(log, type, values, maxLength) {
|
|
47
47
|
// validate and remove invalid and duplicated values
|
|
48
|
-
var result = (0,
|
|
48
|
+
var result = (0, definitions_1.validateDefinitions)(log, values, constants_1.LOG_PREFIX_SETTINGS, "".concat(type, " filter"), "".concat(type, " filter value"));
|
|
49
49
|
if (result) {
|
|
50
50
|
if (type === 'bySet') {
|
|
51
51
|
result = sanitizeFlagSets(log, result, constants_1.LOG_PREFIX_SETTINGS);
|
|
52
52
|
}
|
|
53
53
|
// check max length
|
|
54
54
|
if (result.length > maxLength)
|
|
55
|
-
throw new Error(maxLength
|
|
55
|
+
throw new Error("".concat(maxLength, " unique values can be specified at most for '").concat(type, "' filter. You passed ").concat(result.length, ". Please consider reducing the amount or using other filter."));
|
|
56
56
|
// sort values
|
|
57
57
|
result.sort();
|
|
58
58
|
}
|
|
@@ -172,7 +172,7 @@ function validateSplitFilters(log, maybeSplitFilters, mode) {
|
|
|
172
172
|
}
|
|
173
173
|
exports.validateSplitFilters = validateSplitFilters;
|
|
174
174
|
function validateFlagSets(log, method, flagSets, flagSetsInConfig) {
|
|
175
|
-
var sets = (0,
|
|
175
|
+
var sets = (0, definitions_1.validateDefinitions)(log, flagSets, method, 'flag sets', 'flag set');
|
|
176
176
|
var toReturn = sets ? sanitizeFlagSets(log, sets, method) : [];
|
|
177
177
|
if (flagSetsInConfig.length > 0) {
|
|
178
178
|
toReturn = toReturn.filter(function (flagSet) {
|
|
@@ -15,17 +15,17 @@ var streamingEndpointMatcher = /^\/(sse|event-stream)/;
|
|
|
15
15
|
*/
|
|
16
16
|
function url(settings, target) {
|
|
17
17
|
if (telemetryEndpointMatcher.test(target)) {
|
|
18
|
-
return ""
|
|
18
|
+
return "".concat(settings.urls.telemetry).concat(target);
|
|
19
19
|
}
|
|
20
20
|
if (eventsEndpointMatcher.test(target)) {
|
|
21
|
-
return ""
|
|
21
|
+
return "".concat(settings.urls.events).concat(target);
|
|
22
22
|
}
|
|
23
23
|
if (authEndpointMatcher.test(target)) {
|
|
24
|
-
return ""
|
|
24
|
+
return "".concat(settings.urls.auth).concat(target);
|
|
25
25
|
}
|
|
26
26
|
if (streamingEndpointMatcher.test(target)) {
|
|
27
|
-
return ""
|
|
27
|
+
return "".concat(settings.urls.streaming).concat(target);
|
|
28
28
|
}
|
|
29
|
-
return ""
|
|
29
|
+
return "".concat(settings.urls.sdk).concat(target);
|
|
30
30
|
}
|
|
31
31
|
exports.url = url;
|
|
@@ -12,10 +12,10 @@ export function getTreatment(log, key, seed, treatments) {
|
|
|
12
12
|
/**
|
|
13
13
|
* Evaluates the traffic allocation to see if we should apply rollout conditions or not.
|
|
14
14
|
*/
|
|
15
|
-
export function shouldApplyRollout(trafficAllocation,
|
|
15
|
+
export function shouldApplyRollout(trafficAllocation, bucketingKey, trafficAllocationSeed) {
|
|
16
16
|
// For rollout, if traffic allocation for splits is 100%, we don't need to filter it because everything should evaluate the rollout.
|
|
17
17
|
if (trafficAllocation < 100) {
|
|
18
|
-
var _bucket = bucket(
|
|
18
|
+
var _bucket = bucket(bucketingKey, trafficAllocationSeed);
|
|
19
19
|
if (_bucket > trafficAllocation) {
|
|
20
20
|
return false;
|
|
21
21
|
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { isObject, isString } from '../../../utils/lang';
|
|
2
|
+
var CONFIG_NAME_DISCARD_REASON = 'Invalid config name (max 100 chars, no spaces)';
|
|
3
|
+
var VARIANT_DISCARD_REASON = 'Invalid variant (max 100 chars and must match pattern)';
|
|
4
|
+
var VALUE_DISCARD_REASON = 'Invalid value (must be an object)';
|
|
5
|
+
var VARIANT_PATTERN = /^[0-9]+[.a-zA-Z0-9_-]*$|^[a-zA-Z]+[a-zA-Z0-9_-]*$/;
|
|
6
|
+
export function isValidConfigName(name) {
|
|
7
|
+
return name.length <= 100 && !name.includes(' ');
|
|
8
|
+
}
|
|
9
|
+
export function isValidConfig(config) {
|
|
10
|
+
if (!isObject(config))
|
|
11
|
+
return false;
|
|
12
|
+
if (!isString(config.variant) || config.variant.length > 100 || !VARIANT_PATTERN.test(config.variant))
|
|
13
|
+
return false;
|
|
14
|
+
if (!isObject(config.value))
|
|
15
|
+
return false;
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
function sanitizeGlobal(logger, config) {
|
|
19
|
+
if (config === undefined)
|
|
20
|
+
return undefined;
|
|
21
|
+
if (!isValidConfig(config)) {
|
|
22
|
+
if (!isObject(config) || !isString(config.variant) || config.variant.length > 100 || !VARIANT_PATTERN.test(config.variant)) {
|
|
23
|
+
logger.error("Fallback configs - Discarded fallback: ".concat(VARIANT_DISCARD_REASON));
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
logger.error("Fallback configs - Discarded fallback: ".concat(VALUE_DISCARD_REASON));
|
|
27
|
+
}
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
return config;
|
|
31
|
+
}
|
|
32
|
+
function sanitizeByName(logger, byNameFallbacks) {
|
|
33
|
+
var sanitizedByName = {};
|
|
34
|
+
if (!isObject(byNameFallbacks))
|
|
35
|
+
return sanitizedByName;
|
|
36
|
+
Object.keys(byNameFallbacks).forEach(function (configName) {
|
|
37
|
+
var config = byNameFallbacks[configName];
|
|
38
|
+
if (!isValidConfigName(configName)) {
|
|
39
|
+
logger.error("Fallback configs - Discarded config '".concat(configName, "': ").concat(CONFIG_NAME_DISCARD_REASON));
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (!isValidConfig(config)) {
|
|
43
|
+
if (!isObject(config) || !isString(config.variant) || config.variant.length > 100 || !VARIANT_PATTERN.test(config.variant)) {
|
|
44
|
+
logger.error("Fallback configs - Discarded config '".concat(configName, "': ").concat(VARIANT_DISCARD_REASON));
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
logger.error("Fallback configs - Discarded config '".concat(configName, "': ").concat(VALUE_DISCARD_REASON));
|
|
48
|
+
}
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
sanitizedByName[configName] = config;
|
|
52
|
+
});
|
|
53
|
+
return sanitizedByName;
|
|
54
|
+
}
|
|
55
|
+
export function sanitizeFallbacks(logger, fallbacks) {
|
|
56
|
+
if (!isObject(fallbacks)) {
|
|
57
|
+
logger.error('Fallback configs - Discarded configuration: it must be an object with optional `global` and `byName` properties');
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
global: sanitizeGlobal(logger, fallbacks.global),
|
|
62
|
+
byName: sanitizeByName(logger, fallbacks.byName)
|
|
63
|
+
};
|
|
64
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CONTROL } from '../../utils/constants';
|
|
2
|
+
export var FALLBACK_PREFIX = 'fallback - ';
|
|
3
|
+
export function FallbackConfigsCalculator(fallbacks) {
|
|
4
|
+
if (fallbacks === void 0) { fallbacks = {}; }
|
|
5
|
+
return function (configName, label) {
|
|
6
|
+
var _a;
|
|
7
|
+
if (label === void 0) { label = ''; }
|
|
8
|
+
var fallback = ((_a = fallbacks.byName) === null || _a === void 0 ? void 0 : _a[configName]) || fallbacks.global;
|
|
9
|
+
return fallback ?
|
|
10
|
+
{
|
|
11
|
+
treatment: fallback.variant,
|
|
12
|
+
config: fallback.value,
|
|
13
|
+
label: "".concat(FALLBACK_PREFIX).concat(label),
|
|
14
|
+
} :
|
|
15
|
+
{
|
|
16
|
+
treatment: CONTROL,
|
|
17
|
+
config: null,
|
|
18
|
+
label: label,
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { isObject, isString } from '../../../utils/lang';
|
|
2
|
-
var
|
|
3
|
-
(
|
|
4
|
-
FallbackDiscardReason["FlagName"] = "Invalid flag name (max 100 chars, no spaces)";
|
|
5
|
-
FallbackDiscardReason["Treatment"] = "Invalid treatment (max 100 chars and must match pattern)";
|
|
6
|
-
})(FallbackDiscardReason || (FallbackDiscardReason = {}));
|
|
2
|
+
var FLAG_NAME_DISCARD_REASON = 'Invalid flag name (max 100 chars, no spaces)';
|
|
3
|
+
var TREATMENT_DISCARD_REASON = 'Invalid treatment (max 100 chars and must match pattern)';
|
|
7
4
|
var TREATMENT_PATTERN = /^[0-9]+[.a-zA-Z0-9_-]*$|^[a-zA-Z]+[a-zA-Z0-9_-]*$/;
|
|
8
5
|
export function isValidFlagName(name) {
|
|
9
6
|
return name.length <= 100 && !name.includes(' ');
|
|
@@ -19,7 +16,7 @@ function sanitizeGlobal(logger, treatment) {
|
|
|
19
16
|
if (treatment === undefined)
|
|
20
17
|
return undefined;
|
|
21
18
|
if (!isValidTreatment(treatment)) {
|
|
22
|
-
logger.error("Fallback treatments - Discarded fallback: "
|
|
19
|
+
logger.error("Fallback treatments - Discarded fallback: ".concat(TREATMENT_DISCARD_REASON));
|
|
23
20
|
return undefined;
|
|
24
21
|
}
|
|
25
22
|
return treatment;
|
|
@@ -31,11 +28,11 @@ function sanitizeByFlag(logger, byFlagFallbacks) {
|
|
|
31
28
|
Object.keys(byFlagFallbacks).forEach(function (flag) {
|
|
32
29
|
var t = byFlagFallbacks[flag];
|
|
33
30
|
if (!isValidFlagName(flag)) {
|
|
34
|
-
logger.error("Fallback treatments - Discarded flag '"
|
|
31
|
+
logger.error("Fallback treatments - Discarded flag '".concat(flag, "': ").concat(FLAG_NAME_DISCARD_REASON));
|
|
35
32
|
return;
|
|
36
33
|
}
|
|
37
34
|
if (!isValidTreatment(t)) {
|
|
38
|
-
logger.error("Fallback treatments - Discarded treatment for flag '"
|
|
35
|
+
logger.error("Fallback treatments - Discarded treatment for flag '".concat(flag, "': ").concat(TREATMENT_DISCARD_REASON));
|
|
39
36
|
return;
|
|
40
37
|
}
|
|
41
38
|
sanitizedByFlag[flag] = t;
|
|
@@ -1,40 +1,28 @@
|
|
|
1
1
|
import { CONTROL } from '../../utils/constants';
|
|
2
2
|
import { isString } from '../../utils/lang';
|
|
3
3
|
export var FALLBACK_PREFIX = 'fallback - ';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
this.fallbacks = fallbacks;
|
|
8
|
-
}
|
|
9
|
-
FallbackTreatmentsCalculator.prototype.resolve = function (flagName, label) {
|
|
4
|
+
export function FallbackTreatmentsCalculator(fallbacks) {
|
|
5
|
+
if (fallbacks === void 0) { fallbacks = {}; }
|
|
6
|
+
return function (flagName, label) {
|
|
10
7
|
var _a;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
treatment: fallback,
|
|
8
|
+
if (label === void 0) { label = ''; }
|
|
9
|
+
var fallback = ((_a = fallbacks.byFlag) === null || _a === void 0 ? void 0 : _a[flagName]) || fallbacks.global;
|
|
10
|
+
return fallback ?
|
|
11
|
+
isString(fallback) ?
|
|
12
|
+
{
|
|
13
|
+
treatment: fallback,
|
|
14
|
+
config: null,
|
|
15
|
+
label: "".concat(FALLBACK_PREFIX).concat(label),
|
|
16
|
+
} :
|
|
17
|
+
{
|
|
18
|
+
treatment: fallback.treatment,
|
|
19
|
+
config: fallback.config,
|
|
20
|
+
label: "".concat(FALLBACK_PREFIX).concat(label),
|
|
21
|
+
} :
|
|
22
|
+
{
|
|
23
|
+
treatment: CONTROL,
|
|
28
24
|
config: null,
|
|
29
|
-
label:
|
|
25
|
+
label: label,
|
|
30
26
|
};
|
|
31
|
-
}
|
|
32
|
-
return {
|
|
33
|
-
treatment: fallback.treatment,
|
|
34
|
-
config: fallback.config,
|
|
35
|
-
label: "" + FALLBACK_PREFIX + label,
|
|
36
|
-
};
|
|
37
27
|
};
|
|
38
|
-
|
|
39
|
-
}());
|
|
40
|
-
export { FallbackTreatmentsCalculator };
|
|
28
|
+
}
|