@splitsoftware/splitio-commons 2.1.1-rc.0 → 2.1.1-rc.1
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 +3 -0
- package/README.md +0 -1
- package/cjs/evaluator/combiners/and.js +6 -2
- package/cjs/evaluator/combiners/ifelseif.js +6 -6
- package/cjs/evaluator/condition/index.js +5 -6
- package/cjs/evaluator/index.js +7 -7
- package/cjs/evaluator/matchers/index.js +1 -3
- package/cjs/evaluator/matchers/matcherTypes.js +0 -1
- package/cjs/evaluator/matchersTransform/index.js +0 -4
- package/cjs/evaluator/parser/index.js +2 -2
- package/cjs/evaluator/value/sanitize.js +0 -1
- package/cjs/logger/constants.js +3 -4
- package/cjs/logger/messages/debug.js +2 -3
- package/cjs/logger/messages/error.js +1 -1
- package/cjs/logger/messages/warn.js +2 -2
- package/cjs/sdkClient/client.js +29 -19
- package/cjs/sdkClient/clientAttributesDecoration.js +19 -25
- package/cjs/sdkClient/clientInputValidation.js +28 -26
- package/cjs/services/splitApi.js +2 -2
- package/cjs/storages/AbstractSplitsCacheSync.js +2 -5
- package/cjs/storages/KeyBuilder.js +0 -9
- package/cjs/storages/KeyBuilderCS.js +1 -4
- package/cjs/storages/KeyBuilderSS.js +0 -3
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +14 -9
- package/cjs/storages/inLocalStorage/index.js +0 -4
- package/cjs/storages/inMemory/InMemoryStorage.js +0 -3
- package/cjs/storages/inMemory/InMemoryStorageCS.js +0 -4
- package/cjs/storages/inRedis/index.js +0 -2
- package/cjs/storages/pluggable/index.js +0 -2
- package/cjs/storages/utils.js +1 -0
- package/cjs/sync/polling/fetchers/splitChangesFetcher.js +2 -2
- package/cjs/sync/polling/pollingManagerCS.js +7 -7
- package/cjs/sync/polling/updaters/mySegmentsUpdater.js +2 -2
- package/cjs/sync/polling/updaters/segmentChangesUpdater.js +1 -1
- package/cjs/sync/polling/updaters/splitChangesUpdater.js +35 -51
- package/cjs/sync/streaming/SSEHandler/index.js +0 -1
- package/cjs/sync/streaming/UpdateWorkers/SplitsUpdateWorker.js +77 -106
- package/cjs/sync/streaming/constants.js +1 -2
- package/cjs/sync/streaming/pushManager.js +16 -3
- package/cjs/sync/submitters/impressionsSubmitter.js +3 -2
- package/cjs/sync/syncManagerOnline.js +2 -2
- package/cjs/trackers/strategy/strategyOptimized.js +3 -0
- package/cjs/utils/constants/index.js +2 -3
- package/cjs/utils/inputValidation/eventProperties.js +12 -1
- package/cjs/utils/inputValidation/index.js +3 -1
- package/esm/evaluator/combiners/and.js +6 -2
- package/esm/evaluator/combiners/ifelseif.js +7 -7
- package/esm/evaluator/condition/index.js +5 -6
- package/esm/evaluator/index.js +7 -7
- package/esm/evaluator/matchers/index.js +1 -3
- package/esm/evaluator/matchers/matcherTypes.js +0 -1
- package/esm/evaluator/matchersTransform/index.js +0 -4
- package/esm/evaluator/parser/index.js +2 -2
- package/esm/evaluator/value/sanitize.js +0 -1
- package/esm/logger/constants.js +0 -1
- package/esm/logger/messages/debug.js +2 -3
- package/esm/logger/messages/error.js +1 -1
- package/esm/logger/messages/warn.js +2 -2
- package/esm/sdkClient/client.js +29 -19
- package/esm/sdkClient/clientAttributesDecoration.js +19 -25
- package/esm/sdkClient/clientInputValidation.js +29 -27
- package/esm/services/splitApi.js +2 -2
- package/esm/storages/AbstractSplitsCacheSync.js +2 -5
- package/esm/storages/KeyBuilder.js +0 -9
- package/esm/storages/KeyBuilderCS.js +1 -4
- package/esm/storages/KeyBuilderSS.js +0 -3
- package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +14 -9
- package/esm/storages/inLocalStorage/index.js +0 -4
- package/esm/storages/inMemory/InMemoryStorage.js +0 -3
- package/esm/storages/inMemory/InMemoryStorageCS.js +0 -4
- package/esm/storages/inRedis/index.js +0 -2
- package/esm/storages/pluggable/index.js +0 -2
- package/esm/storages/utils.js +1 -0
- package/esm/sync/polling/fetchers/splitChangesFetcher.js +2 -2
- package/esm/sync/polling/pollingManagerCS.js +7 -7
- package/esm/sync/polling/updaters/mySegmentsUpdater.js +2 -2
- package/esm/sync/polling/updaters/segmentChangesUpdater.js +1 -1
- package/esm/sync/polling/updaters/splitChangesUpdater.js +35 -51
- package/esm/sync/streaming/SSEHandler/index.js +1 -2
- package/esm/sync/streaming/UpdateWorkers/SplitsUpdateWorker.js +73 -102
- package/esm/sync/streaming/constants.js +0 -1
- package/esm/sync/streaming/pushManager.js +19 -6
- package/esm/sync/submitters/impressionsSubmitter.js +3 -2
- package/esm/sync/syncManagerOnline.js +2 -2
- package/esm/trackers/strategy/strategyOptimized.js +3 -0
- package/esm/utils/constants/index.js +1 -2
- package/esm/utils/inputValidation/eventProperties.js +10 -0
- package/esm/utils/inputValidation/index.js +1 -0
- package/package.json +1 -1
- package/src/dtos/types.ts +8 -32
- package/src/evaluator/Engine.ts +1 -1
- package/src/evaluator/combiners/and.ts +4 -5
- package/src/evaluator/combiners/ifelseif.ts +9 -7
- package/src/evaluator/condition/engineUtils.ts +1 -1
- package/src/evaluator/condition/index.ts +12 -12
- package/src/evaluator/index.ts +7 -7
- package/src/evaluator/matchers/index.ts +1 -3
- package/src/evaluator/matchers/matcherTypes.ts +0 -1
- package/src/evaluator/matchersTransform/index.ts +0 -3
- package/src/evaluator/parser/index.ts +3 -3
- package/src/evaluator/types.ts +2 -2
- package/src/evaluator/value/index.ts +2 -2
- package/src/evaluator/value/sanitize.ts +4 -5
- package/src/logger/constants.ts +0 -1
- package/src/logger/messages/debug.ts +2 -3
- package/src/logger/messages/error.ts +1 -1
- package/src/logger/messages/warn.ts +2 -2
- package/src/sdkClient/client.ts +31 -21
- package/src/sdkClient/clientAttributesDecoration.ts +20 -27
- package/src/sdkClient/clientInputValidation.ts +30 -27
- package/src/sdkManager/index.ts +1 -1
- package/src/services/splitApi.ts +2 -2
- package/src/services/types.ts +1 -1
- package/src/storages/AbstractSplitsCacheSync.ts +3 -6
- package/src/storages/KeyBuilder.ts +0 -12
- package/src/storages/KeyBuilderCS.ts +1 -5
- package/src/storages/KeyBuilderSS.ts +0 -4
- package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +14 -10
- package/src/storages/inLocalStorage/index.ts +0 -4
- package/src/storages/inMemory/InMemoryStorage.ts +0 -3
- package/src/storages/inMemory/InMemoryStorageCS.ts +0 -4
- package/src/storages/inRedis/index.ts +0 -2
- package/src/storages/pluggable/index.ts +0 -2
- package/src/storages/types.ts +1 -33
- package/src/storages/utils.ts +1 -0
- package/src/sync/polling/fetchers/splitChangesFetcher.ts +1 -2
- package/src/sync/polling/fetchers/types.ts +0 -1
- package/src/sync/polling/pollingManagerCS.ts +7 -7
- package/src/sync/polling/types.ts +2 -2
- package/src/sync/polling/updaters/mySegmentsUpdater.ts +2 -2
- package/src/sync/polling/updaters/segmentChangesUpdater.ts +1 -1
- package/src/sync/polling/updaters/splitChangesUpdater.ts +44 -61
- package/src/sync/streaming/SSEHandler/index.ts +1 -2
- package/src/sync/streaming/SSEHandler/types.ts +2 -2
- package/src/sync/streaming/UpdateWorkers/SplitsUpdateWorker.ts +68 -98
- package/src/sync/streaming/constants.ts +0 -1
- package/src/sync/streaming/parseUtils.ts +2 -2
- package/src/sync/streaming/pushManager.ts +18 -6
- package/src/sync/streaming/types.ts +2 -3
- package/src/sync/submitters/impressionsSubmitter.ts +3 -2
- package/src/sync/submitters/types.ts +23 -33
- package/src/sync/syncManagerOnline.ts +2 -2
- package/src/trackers/strategy/strategyOptimized.ts +3 -0
- package/src/utils/constants/index.ts +1 -2
- package/src/utils/inputValidation/eventProperties.ts +10 -0
- package/src/utils/inputValidation/index.ts +1 -0
- package/src/utils/lang/index.ts +1 -1
- package/types/splitio.d.ts +100 -35
- package/cjs/evaluator/matchers/rbsegment.js +0 -43
- package/cjs/storages/inLocalStorage/RBSegmentsCacheInLocal.js +0 -117
- package/cjs/storages/inMemory/RBSegmentsCacheInMemory.js +0 -61
- package/cjs/storages/inRedis/RBSegmentsCacheInRedis.js +0 -64
- package/cjs/storages/pluggable/RBSegmentsCachePluggable.js +0 -64
- package/esm/evaluator/matchers/rbsegment.js +0 -39
- package/esm/storages/inLocalStorage/RBSegmentsCacheInLocal.js +0 -114
- package/esm/storages/inMemory/RBSegmentsCacheInMemory.js +0 -58
- package/esm/storages/inRedis/RBSegmentsCacheInRedis.js +0 -61
- package/esm/storages/pluggable/RBSegmentsCachePluggable.js +0 -61
- package/src/evaluator/matchers/rbsegment.ts +0 -61
- package/src/storages/inLocalStorage/RBSegmentsCacheInLocal.ts +0 -136
- package/src/storages/inMemory/RBSegmentsCacheInMemory.ts +0 -68
- package/src/storages/inRedis/RBSegmentsCacheInRedis.ts +0 -79
- package/src/storages/pluggable/RBSegmentsCachePluggable.ts +0 -76
|
@@ -9,7 +9,8 @@ import {
|
|
|
9
9
|
validateSplits,
|
|
10
10
|
validateTrafficType,
|
|
11
11
|
validateIfNotDestroyed,
|
|
12
|
-
validateIfOperational
|
|
12
|
+
validateIfOperational,
|
|
13
|
+
validateEvaluationOptions
|
|
13
14
|
} from '../utils/inputValidation';
|
|
14
15
|
import { startsWith } from '../utils/lang';
|
|
15
16
|
import { CONTROL, CONTROL_WITH_CONFIG, 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, TRACK_FN_LABEL } from '../utils/constants';
|
|
@@ -32,7 +33,7 @@ export function clientInputValidationDecorator<TClient extends SplitIO.IClient |
|
|
|
32
33
|
/**
|
|
33
34
|
* Avoid repeating this validations code
|
|
34
35
|
*/
|
|
35
|
-
function validateEvaluationParams(maybeKey: SplitIO.SplitKey, maybeNameOrNames: string | string[], maybeAttributes
|
|
36
|
+
function validateEvaluationParams(methodName: string, maybeKey: SplitIO.SplitKey, maybeNameOrNames: string | string[], maybeAttributes?: SplitIO.Attributes, maybeOptions?: SplitIO.EvaluationOptions) {
|
|
36
37
|
const key = validateKey(log, maybeKey, methodName);
|
|
37
38
|
|
|
38
39
|
const nameOrNames = methodName.indexOf('ByFlagSet') > -1 ?
|
|
@@ -43,6 +44,7 @@ export function clientInputValidationDecorator<TClient extends SplitIO.IClient |
|
|
|
43
44
|
|
|
44
45
|
const attributes = validateAttributes(log, maybeAttributes, methodName);
|
|
45
46
|
const isNotDestroyed = validateIfNotDestroyed(log, readinessManager, methodName);
|
|
47
|
+
const options = validateEvaluationOptions(log, maybeOptions, methodName);
|
|
46
48
|
|
|
47
49
|
validateIfOperational(log, readinessManager, methodName, nameOrNames);
|
|
48
50
|
|
|
@@ -52,7 +54,8 @@ export function clientInputValidationDecorator<TClient extends SplitIO.IClient |
|
|
|
52
54
|
valid,
|
|
53
55
|
key,
|
|
54
56
|
nameOrNames,
|
|
55
|
-
attributes
|
|
57
|
+
attributes,
|
|
58
|
+
options
|
|
56
59
|
};
|
|
57
60
|
}
|
|
58
61
|
|
|
@@ -60,31 +63,31 @@ export function clientInputValidationDecorator<TClient extends SplitIO.IClient |
|
|
|
60
63
|
return isAsync ? Promise.resolve(value) : value;
|
|
61
64
|
}
|
|
62
65
|
|
|
63
|
-
function getTreatment(maybeKey: SplitIO.SplitKey, maybeFeatureFlagName: string, maybeAttributes?: SplitIO.Attributes) {
|
|
64
|
-
const params = validateEvaluationParams(maybeKey, maybeFeatureFlagName, maybeAttributes,
|
|
66
|
+
function getTreatment(maybeKey: SplitIO.SplitKey, maybeFeatureFlagName: string, maybeAttributes?: SplitIO.Attributes, maybeOptions?: SplitIO.EvaluationOptions) {
|
|
67
|
+
const params = validateEvaluationParams(GET_TREATMENT, maybeKey, maybeFeatureFlagName, maybeAttributes, maybeOptions);
|
|
65
68
|
|
|
66
69
|
if (params.valid) {
|
|
67
|
-
return client.getTreatment(params.key as SplitIO.SplitKey, params.nameOrNames as string, params.attributes as SplitIO.Attributes | undefined);
|
|
70
|
+
return client.getTreatment(params.key as SplitIO.SplitKey, params.nameOrNames as string, params.attributes as SplitIO.Attributes | undefined, params.options);
|
|
68
71
|
} else {
|
|
69
72
|
return wrapResult(CONTROL);
|
|
70
73
|
}
|
|
71
74
|
}
|
|
72
75
|
|
|
73
|
-
function getTreatmentWithConfig(maybeKey: SplitIO.SplitKey, maybeFeatureFlagName: string, maybeAttributes?: SplitIO.Attributes) {
|
|
74
|
-
const params = validateEvaluationParams(maybeKey, maybeFeatureFlagName, maybeAttributes,
|
|
76
|
+
function getTreatmentWithConfig(maybeKey: SplitIO.SplitKey, maybeFeatureFlagName: string, maybeAttributes?: SplitIO.Attributes, maybeOptions?: SplitIO.EvaluationOptions) {
|
|
77
|
+
const params = validateEvaluationParams(GET_TREATMENT_WITH_CONFIG, maybeKey, maybeFeatureFlagName, maybeAttributes, maybeOptions);
|
|
75
78
|
|
|
76
79
|
if (params.valid) {
|
|
77
|
-
return client.getTreatmentWithConfig(params.key as SplitIO.SplitKey, params.nameOrNames as string, params.attributes as SplitIO.Attributes | undefined);
|
|
80
|
+
return client.getTreatmentWithConfig(params.key as SplitIO.SplitKey, params.nameOrNames as string, params.attributes as SplitIO.Attributes | undefined, params.options);
|
|
78
81
|
} else {
|
|
79
82
|
return wrapResult(objectAssign({}, CONTROL_WITH_CONFIG));
|
|
80
83
|
}
|
|
81
84
|
}
|
|
82
85
|
|
|
83
|
-
function getTreatments(maybeKey: SplitIO.SplitKey, maybeFeatureFlagNames: string[], maybeAttributes?: SplitIO.Attributes) {
|
|
84
|
-
const params = validateEvaluationParams(maybeKey, maybeFeatureFlagNames, maybeAttributes,
|
|
86
|
+
function getTreatments(maybeKey: SplitIO.SplitKey, maybeFeatureFlagNames: string[], maybeAttributes?: SplitIO.Attributes, maybeOptions?: SplitIO.EvaluationOptions) {
|
|
87
|
+
const params = validateEvaluationParams(GET_TREATMENTS, maybeKey, maybeFeatureFlagNames, maybeAttributes, maybeOptions);
|
|
85
88
|
|
|
86
89
|
if (params.valid) {
|
|
87
|
-
return client.getTreatments(params.key as SplitIO.SplitKey, params.nameOrNames as string[], params.attributes as SplitIO.Attributes | undefined);
|
|
90
|
+
return client.getTreatments(params.key as SplitIO.SplitKey, params.nameOrNames as string[], params.attributes as SplitIO.Attributes | undefined, params.options);
|
|
88
91
|
} else {
|
|
89
92
|
const res: SplitIO.Treatments = {};
|
|
90
93
|
if (params.nameOrNames) (params.nameOrNames as string[]).forEach((split: string) => res[split] = CONTROL);
|
|
@@ -93,11 +96,11 @@ export function clientInputValidationDecorator<TClient extends SplitIO.IClient |
|
|
|
93
96
|
}
|
|
94
97
|
}
|
|
95
98
|
|
|
96
|
-
function getTreatmentsWithConfig(maybeKey: SplitIO.SplitKey, maybeFeatureFlagNames: string[], maybeAttributes?: SplitIO.Attributes) {
|
|
97
|
-
const params = validateEvaluationParams(maybeKey, maybeFeatureFlagNames, maybeAttributes,
|
|
99
|
+
function getTreatmentsWithConfig(maybeKey: SplitIO.SplitKey, maybeFeatureFlagNames: string[], maybeAttributes?: SplitIO.Attributes, maybeOptions?: SplitIO.EvaluationOptions) {
|
|
100
|
+
const params = validateEvaluationParams(GET_TREATMENTS_WITH_CONFIG, maybeKey, maybeFeatureFlagNames, maybeAttributes, maybeOptions);
|
|
98
101
|
|
|
99
102
|
if (params.valid) {
|
|
100
|
-
return client.getTreatmentsWithConfig(params.key as SplitIO.SplitKey, params.nameOrNames as string[], params.attributes as SplitIO.Attributes | undefined);
|
|
103
|
+
return client.getTreatmentsWithConfig(params.key as SplitIO.SplitKey, params.nameOrNames as string[], params.attributes as SplitIO.Attributes | undefined, params.options);
|
|
101
104
|
} else {
|
|
102
105
|
const res: SplitIO.TreatmentsWithConfig = {};
|
|
103
106
|
if (params.nameOrNames) (params.nameOrNames as string[]).forEach(split => res[split] = objectAssign({}, CONTROL_WITH_CONFIG));
|
|
@@ -106,41 +109,41 @@ export function clientInputValidationDecorator<TClient extends SplitIO.IClient |
|
|
|
106
109
|
}
|
|
107
110
|
}
|
|
108
111
|
|
|
109
|
-
function getTreatmentsByFlagSets(maybeKey: SplitIO.SplitKey, maybeFlagSets: string[], maybeAttributes?: SplitIO.Attributes) {
|
|
110
|
-
const params = validateEvaluationParams(maybeKey, maybeFlagSets, maybeAttributes,
|
|
112
|
+
function getTreatmentsByFlagSets(maybeKey: SplitIO.SplitKey, maybeFlagSets: string[], maybeAttributes?: SplitIO.Attributes, maybeOptions?: SplitIO.EvaluationOptions) {
|
|
113
|
+
const params = validateEvaluationParams(GET_TREATMENTS_BY_FLAG_SETS, maybeKey, maybeFlagSets, maybeAttributes, maybeOptions);
|
|
111
114
|
|
|
112
115
|
if (params.valid) {
|
|
113
|
-
return client.getTreatmentsByFlagSets(params.key as SplitIO.SplitKey, params.nameOrNames as string[], params.attributes as SplitIO.Attributes | undefined);
|
|
116
|
+
return client.getTreatmentsByFlagSets(params.key as SplitIO.SplitKey, params.nameOrNames as string[], params.attributes as SplitIO.Attributes | undefined, params.options);
|
|
114
117
|
} else {
|
|
115
118
|
return wrapResult({});
|
|
116
119
|
}
|
|
117
120
|
}
|
|
118
121
|
|
|
119
|
-
function getTreatmentsWithConfigByFlagSets(maybeKey: SplitIO.SplitKey, maybeFlagSets: string[], maybeAttributes?: SplitIO.Attributes) {
|
|
120
|
-
const params = validateEvaluationParams(maybeKey, maybeFlagSets, maybeAttributes,
|
|
122
|
+
function getTreatmentsWithConfigByFlagSets(maybeKey: SplitIO.SplitKey, maybeFlagSets: string[], maybeAttributes?: SplitIO.Attributes, maybeOptions?: SplitIO.EvaluationOptions) {
|
|
123
|
+
const params = validateEvaluationParams(GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, maybeKey, maybeFlagSets, maybeAttributes, maybeOptions);
|
|
121
124
|
|
|
122
125
|
if (params.valid) {
|
|
123
|
-
return client.getTreatmentsWithConfigByFlagSets(params.key as SplitIO.SplitKey, params.nameOrNames as string[], params.attributes as SplitIO.Attributes | undefined);
|
|
126
|
+
return client.getTreatmentsWithConfigByFlagSets(params.key as SplitIO.SplitKey, params.nameOrNames as string[], params.attributes as SplitIO.Attributes | undefined, params.options);
|
|
124
127
|
} else {
|
|
125
128
|
return wrapResult({});
|
|
126
129
|
}
|
|
127
130
|
}
|
|
128
131
|
|
|
129
|
-
function getTreatmentsByFlagSet(maybeKey: SplitIO.SplitKey, maybeFlagSet: string, maybeAttributes?: SplitIO.Attributes) {
|
|
130
|
-
const params = validateEvaluationParams(maybeKey, [maybeFlagSet], maybeAttributes,
|
|
132
|
+
function getTreatmentsByFlagSet(maybeKey: SplitIO.SplitKey, maybeFlagSet: string, maybeAttributes?: SplitIO.Attributes, maybeOptions?: SplitIO.EvaluationOptions) {
|
|
133
|
+
const params = validateEvaluationParams(GET_TREATMENTS_BY_FLAG_SET, maybeKey, [maybeFlagSet], maybeAttributes, maybeOptions);
|
|
131
134
|
|
|
132
135
|
if (params.valid) {
|
|
133
|
-
return client.getTreatmentsByFlagSet(params.key as SplitIO.SplitKey, (params.nameOrNames as string[])[0], params.attributes as SplitIO.Attributes | undefined);
|
|
136
|
+
return client.getTreatmentsByFlagSet(params.key as SplitIO.SplitKey, (params.nameOrNames as string[])[0], params.attributes as SplitIO.Attributes | undefined, params.options);
|
|
134
137
|
} else {
|
|
135
138
|
return wrapResult({});
|
|
136
139
|
}
|
|
137
140
|
}
|
|
138
141
|
|
|
139
|
-
function getTreatmentsWithConfigByFlagSet(maybeKey: SplitIO.SplitKey, maybeFlagSet: string, maybeAttributes?: SplitIO.Attributes) {
|
|
140
|
-
const params = validateEvaluationParams(maybeKey, [maybeFlagSet], maybeAttributes,
|
|
142
|
+
function getTreatmentsWithConfigByFlagSet(maybeKey: SplitIO.SplitKey, maybeFlagSet: string, maybeAttributes?: SplitIO.Attributes, maybeOptions?: SplitIO.EvaluationOptions) {
|
|
143
|
+
const params = validateEvaluationParams(GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET, maybeKey, [maybeFlagSet], maybeAttributes, maybeOptions);
|
|
141
144
|
|
|
142
145
|
if (params.valid) {
|
|
143
|
-
return client.getTreatmentsWithConfigByFlagSet(params.key as SplitIO.SplitKey, (params.nameOrNames as string[])[0], params.attributes as SplitIO.Attributes | undefined);
|
|
146
|
+
return client.getTreatmentsWithConfigByFlagSet(params.key as SplitIO.SplitKey, (params.nameOrNames as string[])[0], params.attributes as SplitIO.Attributes | undefined, params.options);
|
|
144
147
|
} else {
|
|
145
148
|
return wrapResult({});
|
|
146
149
|
}
|
package/src/sdkManager/index.ts
CHANGED
|
@@ -17,7 +17,7 @@ function collectTreatments(splitObject: ISplit) {
|
|
|
17
17
|
// Localstorage mode could fall into a no rollout conditions state. Take the first condition in that case.
|
|
18
18
|
if (!allTreatmentsCondition) allTreatmentsCondition = conditions[0];
|
|
19
19
|
// Then extract the treatments from the partitions
|
|
20
|
-
return allTreatmentsCondition ? allTreatmentsCondition.partitions
|
|
20
|
+
return allTreatmentsCondition ? allTreatmentsCondition.partitions.map(v => v.treatment) : [];
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
function objectToView(splitObject: ISplit | null): SplitIO.SplitView | null {
|
package/src/services/splitApi.ts
CHANGED
|
@@ -53,8 +53,8 @@ export function splitApiFactory(
|
|
|
53
53
|
return splitHttpClient(url, undefined, telemetryTracker.trackHttp(TOKEN));
|
|
54
54
|
},
|
|
55
55
|
|
|
56
|
-
fetchSplitChanges(since: number, noCache?: boolean, till?: number
|
|
57
|
-
const url = `${urls.sdk}/splitChanges?s=${flagSpecVersion}&since=${since}${
|
|
56
|
+
fetchSplitChanges(since: number, noCache?: boolean, till?: number) {
|
|
57
|
+
const url = `${urls.sdk}/splitChanges?s=${flagSpecVersion}&since=${since}${filterQueryString || ''}${till ? '&till=' + till : ''}`;
|
|
58
58
|
return splitHttpClient(url, noCache ? noCacheHeaderOptions : undefined, telemetryTracker.trackHttp(SPLITS))
|
|
59
59
|
.catch((err) => {
|
|
60
60
|
if (err.statusCode === 414) settings.log.error(ERROR_TOO_MANY_SETS);
|
package/src/services/types.ts
CHANGED
|
@@ -35,7 +35,7 @@ export type ISplitHttpClient = (url: string, options?: IRequestOptions, latencyT
|
|
|
35
35
|
|
|
36
36
|
export type IFetchAuth = (userKeys?: string[]) => Promise<IResponse>
|
|
37
37
|
|
|
38
|
-
export type IFetchSplitChanges = (since: number, noCache?: boolean, till?: number
|
|
38
|
+
export type IFetchSplitChanges = (since: number, noCache?: boolean, till?: number) => Promise<IResponse>
|
|
39
39
|
|
|
40
40
|
export type IFetchSegmentChanges = (since: number, segmentName: string, noCache?: boolean, till?: number) => Promise<IResponse>
|
|
41
41
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ISplitsCacheSync } from './types';
|
|
2
|
-
import {
|
|
2
|
+
import { ISplit } from '../dtos/types';
|
|
3
3
|
import { objectAssign } from '../utils/lang/objectAssign';
|
|
4
4
|
import { IN_SEGMENT, IN_LARGE_SEGMENT } from '../utils/constants';
|
|
5
5
|
|
|
@@ -80,8 +80,8 @@ export abstract class AbstractSplitsCacheSync implements ISplitsCacheSync {
|
|
|
80
80
|
* Given a parsed split, it returns a boolean flagging if its conditions use segments matchers (rules & whitelists).
|
|
81
81
|
* This util is intended to simplify the implementation of `splitsCache::usesSegments` method
|
|
82
82
|
*/
|
|
83
|
-
export function usesSegments(
|
|
84
|
-
const conditions =
|
|
83
|
+
export function usesSegments(split: ISplit) {
|
|
84
|
+
const conditions = split.conditions || [];
|
|
85
85
|
for (let i = 0; i < conditions.length; i++) {
|
|
86
86
|
const matchers = conditions[i].matcherGroup.matchers;
|
|
87
87
|
|
|
@@ -91,8 +91,5 @@ export function usesSegments(ruleEntity: ISplit | IRBSegment) {
|
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
const excluded = (ruleEntity as IRBSegment).excluded;
|
|
95
|
-
if (excluded && excluded.segments && excluded.segments.length > 0) return true;
|
|
96
|
-
|
|
97
94
|
return false;
|
|
98
95
|
}
|
|
@@ -37,18 +37,6 @@ export class KeyBuilder {
|
|
|
37
37
|
return `${this.prefix}.split.`;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
buildRBSegmentKey(rbsegmentName: string) {
|
|
41
|
-
return `${this.prefix}.rbsegment.${rbsegmentName}`;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
buildRBSegmentsTillKey() {
|
|
45
|
-
return `${this.prefix}.rbsegments.till`;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
buildRBSegmentKeyPrefix() {
|
|
49
|
-
return `${this.prefix}.rbsegment.`;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
40
|
buildSegmentNameKey(segmentName: string) {
|
|
53
41
|
return `${this.prefix}.segment.${segmentName}`;
|
|
54
42
|
}
|
|
@@ -15,7 +15,7 @@ export class KeyBuilderCS extends KeyBuilder implements MySegmentsKeyBuilder {
|
|
|
15
15
|
constructor(prefix: string, matchingKey: string) {
|
|
16
16
|
super(prefix);
|
|
17
17
|
this.matchingKey = matchingKey;
|
|
18
|
-
this.regexSplitsCacheKey = new RegExp(`^${prefix}\\.(splits?|trafficType|flagSet
|
|
18
|
+
this.regexSplitsCacheKey = new RegExp(`^${prefix}\\.(splits?|trafficType|flagSet)\\.`);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/**
|
|
@@ -47,10 +47,6 @@ export class KeyBuilderCS extends KeyBuilder implements MySegmentsKeyBuilder {
|
|
|
47
47
|
return startsWith(key, `${this.prefix}.split.`);
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
isRBSegmentKey(key: string) {
|
|
51
|
-
return startsWith(key, `${this.prefix}.rbsegment.`);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
50
|
buildSplitsWithSegmentCountKey() {
|
|
55
51
|
return `${this.prefix}.splits.usingSegments`;
|
|
56
52
|
}
|
|
@@ -53,10 +53,6 @@ export class KeyBuilderSS extends KeyBuilder {
|
|
|
53
53
|
return `${this.buildSplitKeyPrefix()}*`;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
searchPatternForRBSegmentKeys() {
|
|
57
|
-
return `${this.buildRBSegmentKeyPrefix()}*`;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
56
|
/* Telemetry keys */
|
|
61
57
|
|
|
62
58
|
buildLatencyKey(method: Method, bucket: number) {
|
|
@@ -57,14 +57,16 @@ export class SplitsCacheInLocal extends AbstractSplitsCacheSync {
|
|
|
57
57
|
|
|
58
58
|
private _incrementCounts(split: ISplit) {
|
|
59
59
|
try {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
localStorage.setItem(ttKey, toNumber(localStorage.getItem(ttKey)) + 1);
|
|
63
|
-
|
|
64
|
-
if (usesSegments(split)) {
|
|
65
|
-
const segmentsCountKey = this.keys.buildSplitsWithSegmentCountKey();
|
|
60
|
+
if (split) {
|
|
61
|
+
const ttKey = this.keys.buildTrafficTypeKey(split.trafficTypeName);
|
|
66
62
|
// @ts-expect-error
|
|
67
|
-
localStorage.setItem(
|
|
63
|
+
localStorage.setItem(ttKey, toNumber(localStorage.getItem(ttKey)) + 1);
|
|
64
|
+
|
|
65
|
+
if (usesSegments(split)) {
|
|
66
|
+
const segmentsCountKey = this.keys.buildSplitsWithSegmentCountKey();
|
|
67
|
+
// @ts-expect-error
|
|
68
|
+
localStorage.setItem(segmentsCountKey, toNumber(localStorage.getItem(segmentsCountKey)) + 1);
|
|
69
|
+
}
|
|
68
70
|
}
|
|
69
71
|
} catch (e) {
|
|
70
72
|
this.log.error(LOG_PREFIX + e);
|
|
@@ -206,9 +208,11 @@ export class SplitsCacheInLocal extends AbstractSplitsCacheSync {
|
|
|
206
208
|
const storedCount = localStorage.getItem(this.keys.buildSplitsWithSegmentCountKey());
|
|
207
209
|
const splitsWithSegmentsCount = storedCount === null ? 0 : toNumber(storedCount);
|
|
208
210
|
|
|
209
|
-
|
|
210
|
-
splitsWithSegmentsCount > 0
|
|
211
|
-
|
|
211
|
+
if (isFiniteNumber(splitsWithSegmentsCount)) {
|
|
212
|
+
return splitsWithSegmentsCount > 0;
|
|
213
|
+
} else {
|
|
214
|
+
return true;
|
|
215
|
+
}
|
|
212
216
|
}
|
|
213
217
|
|
|
214
218
|
/**
|
|
@@ -14,7 +14,6 @@ import { STORAGE_LOCALSTORAGE } from '../../utils/constants';
|
|
|
14
14
|
import { shouldRecordTelemetry, TelemetryCacheInMemory } from '../inMemory/TelemetryCacheInMemory';
|
|
15
15
|
import { UniqueKeysCacheInMemoryCS } from '../inMemory/UniqueKeysCacheInMemoryCS';
|
|
16
16
|
import { getMatching } from '../../utils/key';
|
|
17
|
-
import { RBSegmentsCacheInLocal } from './RBSegmentsCacheInLocal';
|
|
18
17
|
|
|
19
18
|
export interface InLocalStorageOptions {
|
|
20
19
|
prefix?: string
|
|
@@ -41,13 +40,11 @@ export function InLocalStorage(options: InLocalStorageOptions = {}): IStorageSyn
|
|
|
41
40
|
const expirationTimestamp = Date.now() - DEFAULT_CACHE_EXPIRATION_IN_MILLIS;
|
|
42
41
|
|
|
43
42
|
const splits = new SplitsCacheInLocal(settings, keys, expirationTimestamp);
|
|
44
|
-
const rbSegments = new RBSegmentsCacheInLocal(settings, keys);
|
|
45
43
|
const segments = new MySegmentsCacheInLocal(log, keys);
|
|
46
44
|
const largeSegments = new MySegmentsCacheInLocal(log, myLargeSegmentsKeyBuilder(prefix, matchingKey));
|
|
47
45
|
|
|
48
46
|
return {
|
|
49
47
|
splits,
|
|
50
|
-
rbSegments,
|
|
51
48
|
segments,
|
|
52
49
|
largeSegments,
|
|
53
50
|
impressions: new ImpressionsCacheInMemory(impressionsQueueSize),
|
|
@@ -63,7 +60,6 @@ export function InLocalStorage(options: InLocalStorageOptions = {}): IStorageSyn
|
|
|
63
60
|
|
|
64
61
|
return {
|
|
65
62
|
splits: this.splits,
|
|
66
|
-
rbSegments: this.rbSegments,
|
|
67
63
|
segments: new MySegmentsCacheInLocal(log, new KeyBuilderCS(prefix, matchingKey)),
|
|
68
64
|
largeSegments: new MySegmentsCacheInLocal(log, myLargeSegmentsKeyBuilder(prefix, matchingKey)),
|
|
69
65
|
impressions: this.impressions,
|
|
@@ -7,7 +7,6 @@ import { ImpressionCountsCacheInMemory } from './ImpressionCountsCacheInMemory';
|
|
|
7
7
|
import { LOCALHOST_MODE, STORAGE_MEMORY } from '../../utils/constants';
|
|
8
8
|
import { shouldRecordTelemetry, TelemetryCacheInMemory } from './TelemetryCacheInMemory';
|
|
9
9
|
import { UniqueKeysCacheInMemory } from './UniqueKeysCacheInMemory';
|
|
10
|
-
import { RBSegmentsCacheInMemory } from './RBSegmentsCacheInMemory';
|
|
11
10
|
|
|
12
11
|
/**
|
|
13
12
|
* InMemory storage factory for standalone server-side SplitFactory
|
|
@@ -18,12 +17,10 @@ export function InMemoryStorageFactory(params: IStorageFactoryParams): IStorageS
|
|
|
18
17
|
const { settings: { scheduler: { impressionsQueueSize, eventsQueueSize, }, sync: { __splitFiltersValidation } } } = params;
|
|
19
18
|
|
|
20
19
|
const splits = new SplitsCacheInMemory(__splitFiltersValidation);
|
|
21
|
-
const rbSegments = new RBSegmentsCacheInMemory();
|
|
22
20
|
const segments = new SegmentsCacheInMemory();
|
|
23
21
|
|
|
24
22
|
const storage = {
|
|
25
23
|
splits,
|
|
26
|
-
rbSegments,
|
|
27
24
|
segments,
|
|
28
25
|
impressions: new ImpressionsCacheInMemory(impressionsQueueSize),
|
|
29
26
|
impressionCounts: new ImpressionCountsCacheInMemory(),
|
|
@@ -7,7 +7,6 @@ import { ImpressionCountsCacheInMemory } from './ImpressionCountsCacheInMemory';
|
|
|
7
7
|
import { LOCALHOST_MODE, STORAGE_MEMORY } from '../../utils/constants';
|
|
8
8
|
import { shouldRecordTelemetry, TelemetryCacheInMemory } from './TelemetryCacheInMemory';
|
|
9
9
|
import { UniqueKeysCacheInMemoryCS } from './UniqueKeysCacheInMemoryCS';
|
|
10
|
-
import { RBSegmentsCacheInMemory } from './RBSegmentsCacheInMemory';
|
|
11
10
|
|
|
12
11
|
/**
|
|
13
12
|
* InMemory storage factory for standalone client-side SplitFactory
|
|
@@ -18,13 +17,11 @@ export function InMemoryStorageCSFactory(params: IStorageFactoryParams): IStorag
|
|
|
18
17
|
const { settings: { scheduler: { impressionsQueueSize, eventsQueueSize }, sync: { __splitFiltersValidation } } } = params;
|
|
19
18
|
|
|
20
19
|
const splits = new SplitsCacheInMemory(__splitFiltersValidation);
|
|
21
|
-
const rbSegments = new RBSegmentsCacheInMemory();
|
|
22
20
|
const segments = new MySegmentsCacheInMemory();
|
|
23
21
|
const largeSegments = new MySegmentsCacheInMemory();
|
|
24
22
|
|
|
25
23
|
const storage = {
|
|
26
24
|
splits,
|
|
27
|
-
rbSegments,
|
|
28
25
|
segments,
|
|
29
26
|
largeSegments,
|
|
30
27
|
impressions: new ImpressionsCacheInMemory(impressionsQueueSize),
|
|
@@ -39,7 +36,6 @@ export function InMemoryStorageCSFactory(params: IStorageFactoryParams): IStorag
|
|
|
39
36
|
shared() {
|
|
40
37
|
return {
|
|
41
38
|
splits: this.splits,
|
|
42
|
-
rbSegments: this.rbSegments,
|
|
43
39
|
segments: new MySegmentsCacheInMemory(),
|
|
44
40
|
largeSegments: new MySegmentsCacheInMemory(),
|
|
45
41
|
impressions: this.impressions,
|
|
@@ -11,7 +11,6 @@ import { TelemetryCacheInRedis } from './TelemetryCacheInRedis';
|
|
|
11
11
|
import { UniqueKeysCacheInRedis } from './UniqueKeysCacheInRedis';
|
|
12
12
|
import { ImpressionCountsCacheInRedis } from './ImpressionCountsCacheInRedis';
|
|
13
13
|
import { metadataBuilder } from '../utils';
|
|
14
|
-
import { RBSegmentsCacheInRedis } from './RBSegmentsCacheInRedis';
|
|
15
14
|
|
|
16
15
|
export interface InRedisStorageOptions {
|
|
17
16
|
prefix?: string
|
|
@@ -51,7 +50,6 @@ export function InRedisStorage(options: InRedisStorageOptions = {}): IStorageAsy
|
|
|
51
50
|
|
|
52
51
|
return {
|
|
53
52
|
splits: new SplitsCacheInRedis(log, keys, redisClient, settings.sync.__splitFiltersValidation),
|
|
54
|
-
rbSegments: new RBSegmentsCacheInRedis(log, keys, redisClient),
|
|
55
53
|
segments: new SegmentsCacheInRedis(log, keys, redisClient),
|
|
56
54
|
impressions: new ImpressionsCacheInRedis(log, keys.buildImpressionsKey(), redisClient, metadata),
|
|
57
55
|
impressionCounts: impressionCountsCache,
|
|
@@ -20,7 +20,6 @@ import { UniqueKeysCacheInMemory } from '../inMemory/UniqueKeysCacheInMemory';
|
|
|
20
20
|
import { UniqueKeysCacheInMemoryCS } from '../inMemory/UniqueKeysCacheInMemoryCS';
|
|
21
21
|
import { metadataBuilder } from '../utils';
|
|
22
22
|
import { LOG_PREFIX } from '../pluggable/constants';
|
|
23
|
-
import { RBSegmentsCachePluggable } from './RBSegmentsCachePluggable';
|
|
24
23
|
|
|
25
24
|
const NO_VALID_WRAPPER = 'Expecting pluggable storage `wrapper` in options, but no valid wrapper instance was provided.';
|
|
26
25
|
const NO_VALID_WRAPPER_INTERFACE = 'The provided wrapper instance doesn’t follow the expected interface. Check our docs.';
|
|
@@ -117,7 +116,6 @@ export function PluggableStorage(options: PluggableStorageOptions): IStorageAsyn
|
|
|
117
116
|
|
|
118
117
|
return {
|
|
119
118
|
splits: new SplitsCachePluggable(log, keys, wrapper, settings.sync.__splitFiltersValidation),
|
|
120
|
-
rbSegments: new RBSegmentsCachePluggable(log, keys, wrapper),
|
|
121
119
|
segments: new SegmentsCachePluggable(log, keys, wrapper),
|
|
122
120
|
impressions: isPartialConsumer ? new ImpressionsCacheInMemory(impressionsQueueSize) : new ImpressionsCachePluggable(log, keys.buildImpressionsKey(), wrapper, metadata),
|
|
123
121
|
impressionCounts: impressionCountsCache,
|
package/src/storages/types.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import SplitIO from '../../types/splitio';
|
|
2
|
-
import { MaybeThenable, ISplit,
|
|
2
|
+
import { MaybeThenable, ISplit, IMySegmentsResponse } from '../dtos/types';
|
|
3
3
|
import { MySegmentsData } from '../sync/polling/types';
|
|
4
4
|
import { EventDataType, HttpErrors, HttpLatencies, ImpressionDataType, LastSync, Method, MethodExceptions, MethodLatencies, MultiMethodExceptions, MultiMethodLatencies, MultiConfigs, OperationType, StoredEventWithMetadata, StoredImpressionWithMetadata, StreamingEvent, UniqueKeysPayloadCs, UniqueKeysPayloadSs, TelemetryUsageStatsPayload, UpdatesFromSSEEnum } from '../sync/submitters/types';
|
|
5
5
|
import { ISettings } from '../types';
|
|
@@ -225,34 +225,6 @@ export interface ISplitsCacheAsync extends ISplitsCacheBase {
|
|
|
225
225
|
getNamesByFlagSets(flagSets: string[]): Promise<Set<string>[]>
|
|
226
226
|
}
|
|
227
227
|
|
|
228
|
-
/** Rule-Based Segments cache */
|
|
229
|
-
|
|
230
|
-
export interface IRBSegmentsCacheBase {
|
|
231
|
-
update(toAdd: IRBSegment[], toRemove: IRBSegment[], changeNumber: number): MaybeThenable<boolean>,
|
|
232
|
-
get(name: string): MaybeThenable<IRBSegment | null>,
|
|
233
|
-
getChangeNumber(): MaybeThenable<number>,
|
|
234
|
-
clear(): MaybeThenable<boolean | void>,
|
|
235
|
-
contains(names: Set<string>): MaybeThenable<boolean>,
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
export interface IRBSegmentsCacheSync extends IRBSegmentsCacheBase {
|
|
239
|
-
update(toAdd: IRBSegment[], toRemove: IRBSegment[], changeNumber: number): boolean,
|
|
240
|
-
get(name: string): IRBSegment | null,
|
|
241
|
-
getChangeNumber(): number,
|
|
242
|
-
clear(): void,
|
|
243
|
-
contains(names: Set<string>): boolean,
|
|
244
|
-
// Used only for smart pausing in client-side standalone. Returns true if the storage contains a RBSegment using segments or large segments matchers
|
|
245
|
-
usesSegments(): boolean,
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
export interface IRBSegmentsCacheAsync extends IRBSegmentsCacheBase {
|
|
249
|
-
update(toAdd: IRBSegment[], toRemove: IRBSegment[], changeNumber: number): Promise<boolean>,
|
|
250
|
-
get(name: string): Promise<IRBSegment | null>,
|
|
251
|
-
getChangeNumber(): Promise<number>,
|
|
252
|
-
clear(): Promise<boolean | void>,
|
|
253
|
-
contains(names: Set<string>): Promise<boolean>,
|
|
254
|
-
}
|
|
255
|
-
|
|
256
228
|
/** Segments cache */
|
|
257
229
|
|
|
258
230
|
export interface ISegmentsCacheBase {
|
|
@@ -451,7 +423,6 @@ export interface ITelemetryCacheAsync extends ITelemetryEvaluationProducerAsync,
|
|
|
451
423
|
|
|
452
424
|
export interface IStorageBase<
|
|
453
425
|
TSplitsCache extends ISplitsCacheBase = ISplitsCacheBase,
|
|
454
|
-
TRBSegmentsCache extends IRBSegmentsCacheBase = IRBSegmentsCacheBase,
|
|
455
426
|
TSegmentsCache extends ISegmentsCacheBase = ISegmentsCacheBase,
|
|
456
427
|
TImpressionsCache extends IImpressionsCacheBase = IImpressionsCacheBase,
|
|
457
428
|
TImpressionsCountCache extends IImpressionCountsCacheBase = IImpressionCountsCacheBase,
|
|
@@ -460,7 +431,6 @@ export interface IStorageBase<
|
|
|
460
431
|
TUniqueKeysCache extends IUniqueKeysCacheBase = IUniqueKeysCacheBase
|
|
461
432
|
> {
|
|
462
433
|
splits: TSplitsCache,
|
|
463
|
-
rbSegments: TRBSegmentsCache,
|
|
464
434
|
segments: TSegmentsCache,
|
|
465
435
|
impressions: TImpressionsCache,
|
|
466
436
|
impressionCounts: TImpressionsCountCache,
|
|
@@ -473,7 +443,6 @@ export interface IStorageBase<
|
|
|
473
443
|
|
|
474
444
|
export interface IStorageSync extends IStorageBase<
|
|
475
445
|
ISplitsCacheSync,
|
|
476
|
-
IRBSegmentsCacheSync,
|
|
477
446
|
ISegmentsCacheSync,
|
|
478
447
|
IImpressionsCacheSync,
|
|
479
448
|
IImpressionCountsCacheSync,
|
|
@@ -487,7 +456,6 @@ export interface IStorageSync extends IStorageBase<
|
|
|
487
456
|
|
|
488
457
|
export interface IStorageAsync extends IStorageBase<
|
|
489
458
|
ISplitsCacheAsync,
|
|
490
|
-
IRBSegmentsCacheAsync,
|
|
491
459
|
ISegmentsCacheAsync,
|
|
492
460
|
IImpressionsCacheAsync | IImpressionsCacheSync,
|
|
493
461
|
IImpressionCountsCacheBase,
|
package/src/storages/utils.ts
CHANGED
|
@@ -11,12 +11,11 @@ export function splitChangesFetcherFactory(fetchSplitChanges: IFetchSplitChanges
|
|
|
11
11
|
since: number,
|
|
12
12
|
noCache?: boolean,
|
|
13
13
|
till?: number,
|
|
14
|
-
rbSince?: number,
|
|
15
14
|
// Optional decorator for `fetchSplitChanges` promise, such as timeout or time tracker
|
|
16
15
|
decorator?: (promise: Promise<IResponse>) => Promise<IResponse>
|
|
17
16
|
) {
|
|
18
17
|
|
|
19
|
-
let splitsPromise = fetchSplitChanges(since, noCache, till
|
|
18
|
+
let splitsPromise = fetchSplitChanges(since, noCache, till);
|
|
20
19
|
if (decorator) splitsPromise = decorator(splitsPromise);
|
|
21
20
|
|
|
22
21
|
return splitsPromise.then(resp => resp.json());
|
|
@@ -43,10 +43,10 @@ export function pollingManagerCSFactory(
|
|
|
43
43
|
// smart pausing
|
|
44
44
|
readiness.splits.on(SDK_SPLITS_ARRIVED, () => {
|
|
45
45
|
if (!splitsSyncTask.isRunning()) return; // noop if not doing polling
|
|
46
|
-
const
|
|
47
|
-
if (
|
|
48
|
-
log.info(POLLING_SMART_PAUSING, [
|
|
49
|
-
if (
|
|
46
|
+
const splitsHaveSegments = storage.splits.usesSegments();
|
|
47
|
+
if (splitsHaveSegments !== mySegmentsSyncTask.isRunning()) {
|
|
48
|
+
log.info(POLLING_SMART_PAUSING, [splitsHaveSegments ? 'ON' : 'OFF']);
|
|
49
|
+
if (splitsHaveSegments) {
|
|
50
50
|
startMySegmentsSyncTasks();
|
|
51
51
|
} else {
|
|
52
52
|
stopMySegmentsSyncTasks();
|
|
@@ -59,9 +59,9 @@ export function pollingManagerCSFactory(
|
|
|
59
59
|
|
|
60
60
|
// smart ready
|
|
61
61
|
function smartReady() {
|
|
62
|
-
if (!readiness.isReady() && !storage.splits.usesSegments()
|
|
62
|
+
if (!readiness.isReady() && !storage.splits.usesSegments()) readiness.segments.emit(SDK_SEGMENTS_ARRIVED);
|
|
63
63
|
}
|
|
64
|
-
if (!storage.splits.usesSegments()
|
|
64
|
+
if (!storage.splits.usesSegments()) setTimeout(smartReady, 0);
|
|
65
65
|
else readiness.splits.once(SDK_SPLITS_ARRIVED, smartReady);
|
|
66
66
|
|
|
67
67
|
mySegmentsSyncTasks[matchingKey] = mySegmentsSyncTask;
|
|
@@ -77,7 +77,7 @@ export function pollingManagerCSFactory(
|
|
|
77
77
|
log.info(POLLING_START);
|
|
78
78
|
|
|
79
79
|
splitsSyncTask.start();
|
|
80
|
-
if (storage.splits.usesSegments()
|
|
80
|
+
if (storage.splits.usesSegments()) startMySegmentsSyncTasks();
|
|
81
81
|
},
|
|
82
82
|
|
|
83
83
|
// Stop periodic fetching (polling)
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ISplit } from '../../dtos/types';
|
|
2
2
|
import { IReadinessManager } from '../../readiness/types';
|
|
3
3
|
import { IStorageSync } from '../../storages/types';
|
|
4
4
|
import { MEMBERSHIPS_LS_UPDATE, MEMBERSHIPS_MS_UPDATE } from '../streaming/types';
|
|
5
5
|
import { ITask, ISyncTask } from '../types';
|
|
6
6
|
|
|
7
|
-
export interface ISplitsSyncTask extends ISyncTask<[noCache?: boolean, till?: number, splitUpdateNotification?: { payload: ISplit
|
|
7
|
+
export interface ISplitsSyncTask extends ISyncTask<[noCache?: boolean, till?: number, splitUpdateNotification?: { payload: ISplit, changeNumber: number }], boolean> { }
|
|
8
8
|
|
|
9
9
|
export interface ISegmentsSyncTask extends ISyncTask<[fetchOnlyNew?: boolean, segmentName?: string, noCache?: boolean, till?: number], boolean> { }
|
|
10
10
|
|
|
@@ -27,7 +27,7 @@ export function mySegmentsUpdaterFactory(
|
|
|
27
27
|
matchingKey: string
|
|
28
28
|
): IMySegmentsUpdater {
|
|
29
29
|
|
|
30
|
-
const { splits,
|
|
30
|
+
const { splits, segments, largeSegments } = storage;
|
|
31
31
|
let readyOnAlreadyExistentState = true;
|
|
32
32
|
let startingUp = true;
|
|
33
33
|
|
|
@@ -51,7 +51,7 @@ export function mySegmentsUpdaterFactory(
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
// Notify update if required
|
|
54
|
-
if (
|
|
54
|
+
if (splits.usesSegments() && (shouldNotifyUpdate || readyOnAlreadyExistentState)) {
|
|
55
55
|
readyOnAlreadyExistentState = false;
|
|
56
56
|
segmentsEventEmitter.emit(SDK_SEGMENTS_ARRIVED);
|
|
57
57
|
}
|
|
@@ -51,7 +51,7 @@ export function segmentChangesUpdaterFactory(
|
|
|
51
51
|
* Returned promise will not be rejected.
|
|
52
52
|
*
|
|
53
53
|
* @param fetchOnlyNew - if true, only fetch the segments that not exists, i.e., which `changeNumber` is equal to -1.
|
|
54
|
-
* This param is used by SplitUpdateWorker on server-side SDK, to fetch new registered segments on SPLIT_UPDATE
|
|
54
|
+
* This param is used by SplitUpdateWorker on server-side SDK, to fetch new registered segments on SPLIT_UPDATE notifications.
|
|
55
55
|
* @param segmentName - segment name to fetch. By passing `undefined` it fetches the list of segments registered at the storage
|
|
56
56
|
* @param noCache - true to revalidate data to fetch on a SEGMENT_UPDATE notifications.
|
|
57
57
|
* @param till - till target for the provided segmentName, for CDN bypass.
|