@splitsoftware/splitio-commons 1.9.1 → 1.9.2-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/cjs/evaluator/index.js +18 -1
- package/cjs/logger/constants.js +7 -2
- package/cjs/logger/messages/error.js +2 -0
- package/cjs/logger/messages/warn.js +3 -1
- package/cjs/myLogger.js +34 -0
- package/cjs/sdkClient/client.js +33 -0
- package/cjs/sdkClient/clientAttributesDecoration.js +20 -0
- package/cjs/sdkClient/clientCS.js +4 -0
- package/cjs/sdkClient/clientInputValidation.js +52 -3
- package/cjs/sdkManager/index.js +2 -1
- package/cjs/services/splitApi.js +7 -1
- package/cjs/storages/KeyBuilder.js +3 -0
- package/cjs/storages/KeyBuilderSS.js +4 -0
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +63 -27
- package/cjs/storages/inLocalStorage/index.js +2 -2
- package/cjs/storages/inMemory/InMemoryStorage.js +2 -2
- package/cjs/storages/inMemory/InMemoryStorageCS.js +3 -3
- package/cjs/storages/inMemory/SplitsCacheInMemory.js +47 -2
- package/cjs/storages/inRedis/SplitsCacheInRedis.js +11 -0
- package/cjs/storages/pluggable/SplitsCachePluggable.js +11 -0
- package/cjs/sync/polling/syncTasks/splitsSyncTask.js +1 -1
- package/cjs/sync/polling/updaters/splitChangesUpdater.js +24 -4
- package/cjs/sync/submitters/telemetrySubmitter.js +15 -1
- package/cjs/utils/constants/index.js +6 -2
- package/cjs/utils/lang/sets.js +9 -1
- package/cjs/utils/settingsValidation/splitFilters.js +77 -2
- package/esm/evaluator/index.js +16 -0
- package/esm/logger/constants.js +5 -0
- package/esm/logger/messages/error.js +2 -0
- package/esm/logger/messages/warn.js +3 -1
- package/esm/myLogger.js +31 -0
- package/esm/sdkClient/client.js +35 -2
- package/esm/sdkClient/clientAttributesDecoration.js +20 -0
- package/esm/sdkClient/clientCS.js +4 -0
- package/esm/sdkClient/clientInputValidation.js +52 -3
- package/esm/sdkManager/index.js +2 -1
- package/esm/services/splitApi.js +7 -1
- package/esm/storages/KeyBuilder.js +3 -0
- package/esm/storages/KeyBuilderSS.js +4 -0
- package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +63 -27
- package/esm/storages/inLocalStorage/index.js +2 -2
- package/esm/storages/inMemory/InMemoryStorage.js +2 -2
- package/esm/storages/inMemory/InMemoryStorageCS.js +3 -3
- package/esm/storages/inMemory/SplitsCacheInMemory.js +47 -2
- package/esm/storages/inRedis/SplitsCacheInRedis.js +11 -0
- package/esm/storages/pluggable/SplitsCachePluggable.js +11 -0
- package/esm/sync/polling/syncTasks/splitsSyncTask.js +1 -1
- package/esm/sync/polling/updaters/splitChangesUpdater.js +24 -4
- package/esm/sync/submitters/telemetrySubmitter.js +15 -1
- package/esm/utils/constants/index.js +4 -0
- package/esm/utils/lang/sets.js +7 -0
- package/esm/utils/settingsValidation/splitFilters.js +76 -2
- package/package.json +2 -2
- package/src/dtos/types.ts +3 -2
- package/src/evaluator/index.ts +24 -0
- package/src/logger/constants.ts +5 -0
- package/src/logger/messages/error.ts +2 -0
- package/src/logger/messages/warn.ts +3 -1
- package/src/myLogger.ts +36 -0
- package/src/sdkClient/client.ts +42 -2
- package/src/sdkClient/clientAttributesDecoration.ts +24 -0
- package/src/sdkClient/clientCS.ts +4 -0
- package/src/sdkClient/clientInputValidation.ts +56 -4
- package/src/sdkManager/index.ts +2 -1
- package/src/services/splitApi.ts +6 -1
- package/src/storages/AbstractSplitsCacheAsync.ts +2 -0
- package/src/storages/AbstractSplitsCacheSync.ts +3 -0
- package/src/storages/KeyBuilder.ts +4 -0
- package/src/storages/KeyBuilderSS.ts +4 -0
- package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +74 -28
- package/src/storages/inLocalStorage/index.ts +2 -2
- package/src/storages/inMemory/InMemoryStorage.ts +2 -2
- package/src/storages/inMemory/InMemoryStorageCS.ts +3 -3
- package/src/storages/inMemory/SplitsCacheInMemory.ts +50 -1
- package/src/storages/inRedis/SplitsCacheInRedis.ts +12 -0
- package/src/storages/pluggable/SplitsCachePluggable.ts +12 -0
- package/src/storages/types.ts +7 -3
- package/src/sync/polling/syncTasks/splitsSyncTask.ts +1 -0
- package/src/sync/polling/updaters/splitChangesUpdater.ts +27 -4
- package/src/sync/submitters/telemetrySubmitter.ts +19 -2
- package/src/sync/submitters/types.ts +7 -1
- package/src/types.ts +118 -1
- package/src/utils/constants/index.ts +4 -0
- package/src/utils/lang/sets.ts +8 -0
- package/src/utils/settingsValidation/splitFilters.ts +82 -2
- package/types/dtos/types.d.ts +1 -0
- package/types/evaluator/index.d.ts +1 -0
- package/types/logger/constants.d.ts +5 -0
- package/types/myLogger.d.ts +5 -0
- package/types/sdkClient/clientAttributesDecoration.d.ts +4 -0
- package/types/sdkClient/types.d.ts +18 -0
- package/types/storages/AbstractSplitsCacheAsync.d.ts +2 -0
- package/types/storages/AbstractSplitsCacheSync.d.ts +2 -0
- package/types/storages/KeyBuilder.d.ts +1 -0
- package/types/storages/inLocalStorage/SplitsCacheInLocal.d.ts +6 -1
- package/types/storages/inMemory/CountsCacheInMemory.d.ts +20 -0
- package/types/storages/inMemory/LatenciesCacheInMemory.d.ts +20 -0
- package/types/storages/inMemory/SplitsCacheInMemory.d.ts +9 -1
- package/types/storages/inRedis/CountsCacheInRedis.d.ts +9 -0
- package/types/storages/inRedis/LatenciesCacheInRedis.d.ts +9 -0
- package/types/storages/inRedis/SplitsCacheInRedis.d.ts +8 -0
- package/types/storages/metadataBuilder.d.ts +3 -0
- package/types/storages/pluggable/SplitsCachePluggable.d.ts +8 -0
- package/types/storages/types.d.ts +4 -0
- package/types/sync/offline/LocalhostFromFile.d.ts +2 -0
- package/types/sync/offline/splitsParser/splitsParserFromFile.d.ts +2 -0
- package/types/sync/offline/updaters/splitChangesUpdater.d.ts +0 -0
- package/types/sync/polling/updaters/splitChangesUpdater.d.ts +3 -3
- package/types/sync/submitters/eventsSyncTask.d.ts +8 -0
- package/types/sync/submitters/impressionCountsSubmitterInRedis.d.ts +5 -0
- package/types/sync/submitters/impressionCountsSyncTask.d.ts +13 -0
- package/types/sync/submitters/impressionsSyncTask.d.ts +14 -0
- package/types/sync/submitters/metricsSyncTask.d.ts +12 -0
- package/types/sync/submitters/submitterSyncTask.d.ts +10 -0
- package/types/sync/submitters/types.d.ts +7 -1
- package/types/sync/submitters/uniqueKeysSubmitterInRedis.d.ts +5 -0
- package/types/sync/syncTaskComposite.d.ts +5 -0
- package/types/trackers/filter/bloomFilter.d.ts +10 -0
- package/types/trackers/filter/dictionaryFilter.d.ts +8 -0
- package/types/trackers/filter/types.d.ts +5 -0
- package/types/types.d.ts +118 -1
- package/types/utils/constants/index.d.ts +4 -0
- package/types/utils/lang/sets.d.ts +1 -0
- package/types/utils/settingsValidation/splitFilters.d.ts +1 -0
- package/types/utils/timeTracker/index.d.ts +70 -0
- package/types/sdkClient/identity.d.ts +0 -6
- package/types/utils/inputValidation/sdkKey.d.ts +0 -7
- /package/types/storages/inMemory/{UniqueKeysCacheInMemory.d.ts → uniqueKeysCacheInMemory.d.ts} +0 -0
- /package/types/storages/inMemory/{UniqueKeysCacheInMemoryCS.d.ts → uniqueKeysCacheInMemoryCS.d.ts} +0 -0
- /package/types/storages/inRedis/{UniqueKeysCacheInRedis.d.ts → uniqueKeysCacheInRedis.d.ts} +0 -0
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { STANDALONE_MODE } from '../constants';
|
|
2
2
|
import { validateSplits } from '../inputValidation/splits';
|
|
3
|
-
import { WARN_SPLITS_FILTER_IGNORED, WARN_SPLITS_FILTER_EMPTY, WARN_SPLITS_FILTER_INVALID, SETTINGS_SPLITS_FILTER, LOG_PREFIX_SETTINGS } from '../../logger/constants';
|
|
3
|
+
import { WARN_SPLITS_FILTER_IGNORED, WARN_SPLITS_FILTER_EMPTY, WARN_SPLITS_FILTER_INVALID, SETTINGS_SPLITS_FILTER, LOG_PREFIX_SETTINGS, ERROR_SETS_FILTER_EXCLUSIVE, WARN_SPLITS_FILTER_LOWERCASE_SET, WARN_SPLITS_FILTER_INVALID_SET, ERROR_EMPTY_ARRAY, WARN_FLAGSET_NOT_CONFIGURED } from '../../logger/constants';
|
|
4
|
+
import { objectAssign } from '../lang/objectAssign';
|
|
5
|
+
import { find, uniq } from '../lang';
|
|
4
6
|
// Split filters metadata.
|
|
5
7
|
// Ordered according to their precedency when forming the filter query string: `&names=<values>&prefixes=<values>`
|
|
6
8
|
var FILTERS_METADATA = [
|
|
9
|
+
{
|
|
10
|
+
type: 'bySet',
|
|
11
|
+
maxLength: 50,
|
|
12
|
+
queryParam: 'sets='
|
|
13
|
+
},
|
|
7
14
|
{
|
|
8
15
|
type: 'byName',
|
|
9
16
|
maxLength: 400,
|
|
@@ -15,6 +22,8 @@ var FILTERS_METADATA = [
|
|
|
15
22
|
queryParam: 'prefixes='
|
|
16
23
|
}
|
|
17
24
|
];
|
|
25
|
+
var VALID_FLAGSET_REGEX = /^[a-z0-9][_a-z0-9]{0,49}$/;
|
|
26
|
+
var CAPITAL_LETTERS_REGEX = /[A-Z]/;
|
|
18
27
|
/**
|
|
19
28
|
* Validates that the given value is a valid filter type
|
|
20
29
|
*/
|
|
@@ -35,6 +44,9 @@ function validateSplitFilter(log, type, values, maxLength) {
|
|
|
35
44
|
// validate and remove invalid and duplicated values
|
|
36
45
|
var result = validateSplits(log, values, LOG_PREFIX_SETTINGS, type + " filter", type + " filter value");
|
|
37
46
|
if (result) {
|
|
47
|
+
if (type === 'bySet') {
|
|
48
|
+
result = sanitizeFlagSets(log, result);
|
|
49
|
+
}
|
|
38
50
|
// check max length
|
|
39
51
|
if (result.length > maxLength)
|
|
40
52
|
throw new Error(maxLength + " unique values can be specified at most for '" + type + "' filter. You passed " + result.length + ". Please consider reducing the amount or using other filter.");
|
|
@@ -65,6 +77,42 @@ function queryStringBuilder(groupedFilters) {
|
|
|
65
77
|
});
|
|
66
78
|
return queryParams.length > 0 ? '&' + queryParams.join('&') : null;
|
|
67
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* Sanitizes set names list taking in account:
|
|
82
|
+
* - It should be lowercase
|
|
83
|
+
* - Must adhere the following regular expression /^[a-z0-9][_a-z0-9]{0,49}$/ that means
|
|
84
|
+
* - must start with a letter or number
|
|
85
|
+
* - Be in lowercase
|
|
86
|
+
* - Be alphanumeric
|
|
87
|
+
* - have a max length of 50 characters
|
|
88
|
+
*
|
|
89
|
+
* @param {ILogger} log
|
|
90
|
+
* @param {string[]} flagSets
|
|
91
|
+
* @returns sanitized list of set names
|
|
92
|
+
*/
|
|
93
|
+
function sanitizeFlagSets(log, flagSets) {
|
|
94
|
+
var sanitizedSets = flagSets
|
|
95
|
+
.map(function (flagSet) {
|
|
96
|
+
if (CAPITAL_LETTERS_REGEX.test(flagSet)) {
|
|
97
|
+
log.warn(WARN_SPLITS_FILTER_LOWERCASE_SET, [flagSet]);
|
|
98
|
+
flagSet = flagSet.toLowerCase();
|
|
99
|
+
}
|
|
100
|
+
return flagSet;
|
|
101
|
+
})
|
|
102
|
+
.filter(function (flagSet) {
|
|
103
|
+
if (!VALID_FLAGSET_REGEX.test(flagSet)) {
|
|
104
|
+
log.warn(WARN_SPLITS_FILTER_INVALID_SET, [flagSet, VALID_FLAGSET_REGEX, flagSet]);
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
if (typeof flagSet !== 'string')
|
|
108
|
+
return false;
|
|
109
|
+
return true;
|
|
110
|
+
});
|
|
111
|
+
return uniq(sanitizedSets);
|
|
112
|
+
}
|
|
113
|
+
function configuredFilter(validFilters, filterType) {
|
|
114
|
+
return find(validFilters, function (filter) { return filter.type === filterType && filter.values.length > 0; });
|
|
115
|
+
}
|
|
68
116
|
/**
|
|
69
117
|
* Validates `splitFilters` configuration object and parses it into a query string for filtering splits on `/splitChanges` fetch.
|
|
70
118
|
*
|
|
@@ -83,7 +131,7 @@ export function validateSplitFilters(log, maybeSplitFilters, mode) {
|
|
|
83
131
|
var res = {
|
|
84
132
|
validFilters: [],
|
|
85
133
|
queryString: null,
|
|
86
|
-
groupedFilters: { byName: [], byPrefix: [] }
|
|
134
|
+
groupedFilters: { bySet: [], byName: [], byPrefix: [] },
|
|
87
135
|
};
|
|
88
136
|
// do nothing if `splitFilters` param is not a non-empty array or mode is not STANDALONE
|
|
89
137
|
if (!maybeSplitFilters)
|
|
@@ -115,8 +163,34 @@ export function validateSplitFilters(log, maybeSplitFilters, mode) {
|
|
|
115
163
|
if (res.groupedFilters[type].length > 0)
|
|
116
164
|
res.groupedFilters[type] = validateSplitFilter(log, type, res.groupedFilters[type], maxLength);
|
|
117
165
|
});
|
|
166
|
+
var setFilter = configuredFilter(res.validFilters, 'bySet');
|
|
167
|
+
// Clean all filters if set filter is present
|
|
168
|
+
if (setFilter) {
|
|
169
|
+
if (configuredFilter(res.validFilters, 'byName') || configuredFilter(res.validFilters, 'byPrefix'))
|
|
170
|
+
log.error(ERROR_SETS_FILTER_EXCLUSIVE);
|
|
171
|
+
objectAssign(res.groupedFilters, { byName: [], byPrefix: [] });
|
|
172
|
+
}
|
|
118
173
|
// build query string
|
|
119
174
|
res.queryString = queryStringBuilder(res.groupedFilters);
|
|
120
175
|
log.debug(SETTINGS_SPLITS_FILTER, [res.queryString]);
|
|
121
176
|
return res;
|
|
122
177
|
}
|
|
178
|
+
export function flagSetsAreValid(log, method, flagSets, flagSetsInConfig) {
|
|
179
|
+
var toReturn = [];
|
|
180
|
+
if (flagSets.length === 0) {
|
|
181
|
+
log.error(ERROR_EMPTY_ARRAY, [method, 'flagSets']);
|
|
182
|
+
return toReturn;
|
|
183
|
+
}
|
|
184
|
+
var sets = validateSplits(log, flagSets, method, 'flag sets', 'flag set');
|
|
185
|
+
toReturn = sets ? sanitizeFlagSets(log, sets) : [];
|
|
186
|
+
if (flagSetsInConfig.length > 0) {
|
|
187
|
+
toReturn = toReturn.filter(function (flagSet) {
|
|
188
|
+
if (flagSetsInConfig.indexOf(flagSet) > -1) {
|
|
189
|
+
return true;
|
|
190
|
+
}
|
|
191
|
+
log.warn(WARN_FLAGSET_NOT_CONFIGURED, [flagSet]);
|
|
192
|
+
return false;
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
return toReturn;
|
|
196
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@splitsoftware/splitio-commons",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.2-rc.0",
|
|
4
4
|
"description": "Split Javascript SDK common components",
|
|
5
5
|
"main": "cjs/index.js",
|
|
6
6
|
"module": "esm/index.js",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"build": "npm run build:cjs && npm run build:esm",
|
|
23
23
|
"build:esm": "rimraf esm && tsc -m es2015 --outDir esm -d true --declarationDir types",
|
|
24
24
|
"build:cjs": "rimraf cjs && tsc -m CommonJS --outDir cjs",
|
|
25
|
-
"test": "jest
|
|
25
|
+
"test": "jest",
|
|
26
26
|
"test:coverage": "jest --coverage",
|
|
27
27
|
"all": "npm run check && npm run build && npm run test",
|
|
28
28
|
"publish:rc": "npm run check && npm run test && npm run build && npm publish --tag rc",
|
package/src/dtos/types.ts
CHANGED
|
@@ -163,7 +163,8 @@ export interface ISplit {
|
|
|
163
163
|
trafficAllocationSeed?: number
|
|
164
164
|
configurations?: {
|
|
165
165
|
[treatmentName: string]: string
|
|
166
|
-
}
|
|
166
|
+
},
|
|
167
|
+
sets?: string[]
|
|
167
168
|
}
|
|
168
169
|
|
|
169
170
|
// Split definition used in offline mode
|
|
@@ -208,5 +209,5 @@ export interface IMetadata {
|
|
|
208
209
|
export type ISplitFiltersValidation = {
|
|
209
210
|
queryString: string | null,
|
|
210
211
|
groupedFilters: Record<SplitIO.SplitFilterType, string[]>,
|
|
211
|
-
validFilters: SplitIO.SplitFilter[]
|
|
212
|
+
validFilters: SplitIO.SplitFilter[],
|
|
212
213
|
};
|
package/src/evaluator/index.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { IStorageAsync, IStorageSync } from '../storages/types';
|
|
|
7
7
|
import { IEvaluationResult } from './types';
|
|
8
8
|
import { SplitIO } from '../types';
|
|
9
9
|
import { ILogger } from '../logger/types';
|
|
10
|
+
import { ISet, setToArray } from '../utils/lang/sets';
|
|
10
11
|
|
|
11
12
|
const treatmentException = {
|
|
12
13
|
treatment: CONTROL,
|
|
@@ -87,6 +88,29 @@ export function evaluateFeatures(
|
|
|
87
88
|
getEvaluations(log, splitNames, parsedSplits, key, attributes, storage);
|
|
88
89
|
}
|
|
89
90
|
|
|
91
|
+
export function evaluateFeaturesByFlagSets(
|
|
92
|
+
log: ILogger,
|
|
93
|
+
key: SplitIO.SplitKey,
|
|
94
|
+
flagSets: string[],
|
|
95
|
+
attributes: SplitIO.Attributes | undefined,
|
|
96
|
+
storage: IStorageSync | IStorageAsync,
|
|
97
|
+
): MaybeThenable<Record<string,IEvaluationResult>> {
|
|
98
|
+
let storedFlagNames: MaybeThenable<ISet<string>>;
|
|
99
|
+
|
|
100
|
+
// get features by flag sets
|
|
101
|
+
try {
|
|
102
|
+
storedFlagNames = storage.splits.getNamesByFlagSets(flagSets);
|
|
103
|
+
} catch (e) {
|
|
104
|
+
// return empty evaluations
|
|
105
|
+
return {};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// evaluate related features
|
|
109
|
+
return thenable(storedFlagNames) ?
|
|
110
|
+
storedFlagNames.then((splitNames) => evaluateFeatures(log, key, setToArray(splitNames), attributes, storage)) :
|
|
111
|
+
evaluateFeatures(log, key, setToArray(storedFlagNames), attributes, storage);
|
|
112
|
+
}
|
|
113
|
+
|
|
90
114
|
function getEvaluation(
|
|
91
115
|
log: ILogger,
|
|
92
116
|
splitJSON: ISplit | null,
|
package/src/logger/constants.ts
CHANGED
|
@@ -97,6 +97,9 @@ export const WARN_SPLITS_FILTER_EMPTY = 221;
|
|
|
97
97
|
export const WARN_SDK_KEY = 222;
|
|
98
98
|
export const STREAMING_PARSING_MY_SEGMENTS_UPDATE_V2 = 223;
|
|
99
99
|
export const STREAMING_PARSING_SPLIT_UPDATE = 224;
|
|
100
|
+
export const WARN_SPLITS_FILTER_INVALID_SET = 225;
|
|
101
|
+
export const WARN_SPLITS_FILTER_LOWERCASE_SET = 226;
|
|
102
|
+
export const WARN_FLAGSET_NOT_CONFIGURED = 227;
|
|
100
103
|
|
|
101
104
|
export const ERROR_ENGINE_COMBINER_IFELSEIF = 300;
|
|
102
105
|
export const ERROR_LOGLEVEL_INVALID = 301;
|
|
@@ -125,6 +128,8 @@ export const ERROR_LOCALHOST_MODULE_REQUIRED = 323;
|
|
|
125
128
|
export const ERROR_STORAGE_INVALID = 324;
|
|
126
129
|
export const ERROR_NOT_BOOLEAN = 325;
|
|
127
130
|
export const ERROR_MIN_CONFIG_PARAM = 326;
|
|
131
|
+
export const ERROR_TOO_MANY_SETS = 327;
|
|
132
|
+
export const ERROR_SETS_FILTER_EXCLUSIVE = 328;
|
|
128
133
|
|
|
129
134
|
// Log prefixes (a.k.a. tags or categories)
|
|
130
135
|
export const LOG_PREFIX_SETTINGS = 'settings';
|
|
@@ -34,4 +34,6 @@ export const codesError: [number, string][] = [
|
|
|
34
34
|
[c.ERROR_LOCALHOST_MODULE_REQUIRED, c.LOG_PREFIX_SETTINGS + ': an invalid value was received for "sync.localhostMode" config. A valid entity should be provided for localhost mode.'],
|
|
35
35
|
[c.ERROR_STORAGE_INVALID, c.LOG_PREFIX_SETTINGS+': the provided storage is invalid.%s Falling back into default MEMORY storage'],
|
|
36
36
|
[c.ERROR_MIN_CONFIG_PARAM, c.LOG_PREFIX_SETTINGS + ': the provided "%s" config param is lower than allowed. Setting to the minimum value %s seconds'],
|
|
37
|
+
[c.ERROR_TOO_MANY_SETS, c.LOG_PREFIX_SETTINGS + ': the amount of flag sets provided are big causing uri length error.'],
|
|
38
|
+
[c.ERROR_SETS_FILTER_EXCLUSIVE, c.LOG_PREFIX_SETTINGS+': the Set filter is exclusive and cannot be used simultaneously with names or prefix filters. Ignoring names and prefixes.'],
|
|
37
39
|
];
|
|
@@ -27,10 +27,12 @@ export const codesWarn: [number, string][] = codesError.concat([
|
|
|
27
27
|
// initialization / settings validation
|
|
28
28
|
[c.WARN_INTEGRATION_INVALID, c.LOG_PREFIX_SETTINGS+': %s integration item(s) at settings is invalid. %s'],
|
|
29
29
|
[c.WARN_SPLITS_FILTER_IGNORED, c.LOG_PREFIX_SETTINGS+': feature flag filters have been configured but will have no effect if mode is not "%s", since synchronization is being deferred to an external tool.'],
|
|
30
|
-
[c.WARN_SPLITS_FILTER_INVALID, c.LOG_PREFIX_SETTINGS+': feature flag filter at position %s is invalid. It must be an object with a valid filter type ("byName" or "byPrefix") and a list of "values".'],
|
|
30
|
+
[c.WARN_SPLITS_FILTER_INVALID, c.LOG_PREFIX_SETTINGS+': feature flag filter at position %s is invalid. It must be an object with a valid filter type ("bySet", "byName" or "byPrefix") and a list of "values".'],
|
|
31
31
|
[c.WARN_SPLITS_FILTER_EMPTY, c.LOG_PREFIX_SETTINGS+': feature flag filter configuration must be a non-empty array of filter objects.'],
|
|
32
32
|
[c.WARN_SDK_KEY, c.LOG_PREFIX_SETTINGS+': You already have %s. We recommend keeping only one instance of the factory at all times (Singleton pattern) and reusing it throughout your application'],
|
|
33
33
|
|
|
34
34
|
[c.STREAMING_PARSING_MY_SEGMENTS_UPDATE_V2, c.LOG_PREFIX_SYNC_STREAMING + 'Fetching MySegments due to an error processing %s notification: %s'],
|
|
35
35
|
[c.STREAMING_PARSING_SPLIT_UPDATE, c.LOG_PREFIX_SYNC_STREAMING + 'Fetching SplitChanges due to an error processing SPLIT_UPDATE notification: %s'],
|
|
36
|
+
[c.WARN_SPLITS_FILTER_INVALID_SET, c.LOG_PREFIX_SETTINGS+': you passed %s, flag set must adhere to the regular expressions %s. This means a flag set must start with a letter or number, be in lowercase, alphanumeric and have a max length of 50 characters. %s was discarded.'],
|
|
37
|
+
[c.WARN_SPLITS_FILTER_LOWERCASE_SET, c.LOG_PREFIX_SETTINGS+': flag set %s should be all lowercase - converting string to lowercase.'],
|
|
36
38
|
]);
|
package/src/myLogger.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// get the Console class
|
|
2
|
+
// const { Console } = require('console');
|
|
3
|
+
// get fs module for creating write streams
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
var pjson = require('../package.json');
|
|
6
|
+
|
|
7
|
+
//@ts-ignore
|
|
8
|
+
const pad = (value) => ('00'+value).slice(-2);
|
|
9
|
+
const getDate = () => {
|
|
10
|
+
const date = new Date();
|
|
11
|
+
return `${date.getFullYear()}-${pad(date.getMonth()+1)}-${pad(date.getDate())}_${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
//@ts-ignore
|
|
15
|
+
|
|
16
|
+
const logToFile = (file, msg) => {
|
|
17
|
+
//@ts-ignore
|
|
18
|
+
fs.appendFileSync(file, `${msg}\n`, (err) => {
|
|
19
|
+
if (err) {
|
|
20
|
+
return console.log(err);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// make a new logger
|
|
26
|
+
const version = pjson.version.replace('.','').replace('.','');
|
|
27
|
+
const filePath = `logs/${version}_${getDate()}`;
|
|
28
|
+
export const myLogger = {
|
|
29
|
+
//@ts-ignore
|
|
30
|
+
log: (msg) => logToFile(filePath, msg),
|
|
31
|
+
//@ts-ignore
|
|
32
|
+
logCsv: (msg) => logToFile(`${filePath}.csv`, msg),
|
|
33
|
+
//@ts-ignore
|
|
34
|
+
logToFile: (file, msg) => logToFile(`logs/${file}`, msg),
|
|
35
|
+
};
|
|
36
|
+
|
package/src/sdkClient/client.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { evaluateFeature, evaluateFeatures } from '../evaluator';
|
|
1
|
+
import { evaluateFeature, evaluateFeatures, evaluateFeaturesByFlagSets } from '../evaluator';
|
|
2
2
|
import { thenable } from '../utils/promise/thenable';
|
|
3
3
|
import { getMatching, getBucketing } from '../utils/key';
|
|
4
4
|
import { validateSplitExistance } from '../utils/inputValidation/splitExistance';
|
|
5
5
|
import { validateTrafficTypeExistance } from '../utils/inputValidation/trafficTypeExistance';
|
|
6
6
|
import { SDK_NOT_READY } from '../utils/labels';
|
|
7
|
-
import { CONTROL, TREATMENT, TREATMENTS, TREATMENT_WITH_CONFIG, TREATMENTS_WITH_CONFIG, TRACK } from '../utils/constants';
|
|
7
|
+
import { CONTROL, TREATMENT, TREATMENTS, TREATMENT_WITH_CONFIG, TREATMENTS_WITH_CONFIG, TRACK, TREATMENTS_WITH_CONFIG_BY_FLAGSETS, TREATMENTS_BY_FLAGSETS, TREATMENTS_BY_FLAGSET, TREATMENTS_WITH_CONFIG_BY_FLAGSET } from '../utils/constants';
|
|
8
8
|
import { IEvaluationResult } from '../evaluator/types';
|
|
9
9
|
import { SplitIO, ImpressionDTO } from '../types';
|
|
10
10
|
import { IMPRESSION, IMPRESSION_QUEUEING } from '../logger/constants';
|
|
11
11
|
import { ISdkFactoryContext } from '../sdkFactory/types';
|
|
12
12
|
import { isStorageSync } from '../trackers/impressionObserver/utils';
|
|
13
|
+
import { Method } from '../sync/submitters/types';
|
|
13
14
|
|
|
14
15
|
const treatmentNotReady = { treatment: CONTROL, label: SDK_NOT_READY };
|
|
15
16
|
|
|
@@ -81,6 +82,41 @@ export function clientFactory(params: ISdkFactoryContext): SplitIO.IClient | Spl
|
|
|
81
82
|
return getTreatments(key, featureFlagNames, attributes, true);
|
|
82
83
|
}
|
|
83
84
|
|
|
85
|
+
function getTreatmentsByFlagSets(key: SplitIO.SplitKey, flagSetNames: string[], attributes: SplitIO.Attributes | undefined, withConfig = false, method: Method = TREATMENTS_BY_FLAGSETS) {
|
|
86
|
+
const stopTelemetryTracker = telemetryTracker.trackEval(method);
|
|
87
|
+
|
|
88
|
+
const wrapUp = (evaluationResults: Record<string,IEvaluationResult>) => {
|
|
89
|
+
const queue: ImpressionDTO[] = [];
|
|
90
|
+
const treatments: Record<string, SplitIO.Treatment | SplitIO.TreatmentWithConfig> = {};
|
|
91
|
+
const evaluations = evaluationResults;
|
|
92
|
+
Object.keys(evaluations).forEach(featureFlagName => {
|
|
93
|
+
treatments[featureFlagName] = processEvaluation(evaluations[featureFlagName], featureFlagName, key, attributes, withConfig, `getTreatmentsByFlagSets${withConfig ? 'WithConfig' : ''}`, queue);
|
|
94
|
+
});
|
|
95
|
+
impressionsTracker.track(queue, attributes);
|
|
96
|
+
|
|
97
|
+
stopTelemetryTracker(queue[0] && queue[0].label);
|
|
98
|
+
return treatments;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const evaluations = readinessManager.isReady() || readinessManager.isReadyFromCache() ?
|
|
102
|
+
evaluateFeaturesByFlagSets(log, key, flagSetNames, attributes, storage) :
|
|
103
|
+
isStorageSync(settings) ? {} : Promise.resolve({}); // Promisify if async
|
|
104
|
+
|
|
105
|
+
return thenable(evaluations) ? evaluations.then((res) => wrapUp(res)) : wrapUp(evaluations);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function getTreatmentsWithConfigByFlagSets(key: SplitIO.SplitKey, flagSetNames: string[], attributes: SplitIO.Attributes | undefined) {
|
|
109
|
+
return getTreatmentsByFlagSets(key, flagSetNames, attributes, true, TREATMENTS_WITH_CONFIG_BY_FLAGSETS);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function getTreatmentsByFlagSet(key: SplitIO.SplitKey, flagSetName: string, attributes: SplitIO.Attributes | undefined) {
|
|
113
|
+
return getTreatmentsByFlagSets(key, [flagSetName], attributes, false, TREATMENTS_BY_FLAGSET);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function getTreatmentsWithConfigByFlagSet(key: SplitIO.SplitKey, flagSetName: string, attributes: SplitIO.Attributes | undefined) {
|
|
117
|
+
return getTreatmentsByFlagSets(key, [flagSetName], attributes, true, TREATMENTS_WITH_CONFIG_BY_FLAGSET);
|
|
118
|
+
}
|
|
119
|
+
|
|
84
120
|
// Internal function
|
|
85
121
|
function processEvaluation(
|
|
86
122
|
evaluation: IEvaluationResult,
|
|
@@ -155,6 +191,10 @@ export function clientFactory(params: ISdkFactoryContext): SplitIO.IClient | Spl
|
|
|
155
191
|
getTreatmentWithConfig,
|
|
156
192
|
getTreatments,
|
|
157
193
|
getTreatmentsWithConfig,
|
|
194
|
+
getTreatmentsByFlagSets,
|
|
195
|
+
getTreatmentsWithConfigByFlagSets,
|
|
196
|
+
getTreatmentsByFlagSet,
|
|
197
|
+
getTreatmentsWithConfigByFlagSet,
|
|
158
198
|
track,
|
|
159
199
|
isClientSide: false
|
|
160
200
|
} as SplitIO.IClient | SplitIO.IAsyncClient;
|
|
@@ -16,6 +16,10 @@ export function clientAttributesDecoration<TClient extends SplitIO.IClient | Spl
|
|
|
16
16
|
const clientGetTreatmentWithConfig = client.getTreatmentWithConfig;
|
|
17
17
|
const clientGetTreatments = client.getTreatments;
|
|
18
18
|
const clientGetTreatmentsWithConfig = client.getTreatmentsWithConfig;
|
|
19
|
+
const clientGetTreatmentsByFlagSets = client.getTreatmentsByFlagSets;
|
|
20
|
+
const clientGetTreatmentsWithConfigByFlagSets = client.getTreatmentsWithConfigByFlagSets;
|
|
21
|
+
const clientGetTreatmentsByFlagSet = client.getTreatmentsByFlagSet;
|
|
22
|
+
const clientGetTreatmentsWithConfigByFlagSet = client.getTreatmentsWithConfigByFlagSet;
|
|
19
23
|
const clientTrack = client.track;
|
|
20
24
|
|
|
21
25
|
function getTreatment(maybeKey: SplitIO.SplitKey, maybeFeatureFlagName: string, maybeAttributes?: SplitIO.Attributes) {
|
|
@@ -34,6 +38,22 @@ export function clientAttributesDecoration<TClient extends SplitIO.IClient | Spl
|
|
|
34
38
|
return clientGetTreatmentsWithConfig(maybeKey, maybeFeatureFlagNames, combineAttributes(maybeAttributes));
|
|
35
39
|
}
|
|
36
40
|
|
|
41
|
+
function getTreatmentsByFlagSets(maybeKey: SplitIO.SplitKey, maybeFlagSets: string[], maybeAttributes?: SplitIO.Attributes) {
|
|
42
|
+
return clientGetTreatmentsByFlagSets(maybeKey, maybeFlagSets, combineAttributes(maybeAttributes));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function getTreatmentsWithConfigByFlagSets(maybeKey: SplitIO.SplitKey, maybeFlagSets: string[], maybeAttributes?: SplitIO.Attributes) {
|
|
46
|
+
return clientGetTreatmentsWithConfigByFlagSets(maybeKey, maybeFlagSets, combineAttributes(maybeAttributes));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function getTreatmentsByFlagSet(maybeKey: SplitIO.SplitKey, maybeFlagSet: string, maybeAttributes?: SplitIO.Attributes) {
|
|
50
|
+
return clientGetTreatmentsByFlagSet(maybeKey, maybeFlagSet, combineAttributes(maybeAttributes));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function getTreatmentsWithConfigByFlagSet(maybeKey: SplitIO.SplitKey, maybeFlagSet: string, maybeAttributes?: SplitIO.Attributes) {
|
|
54
|
+
return clientGetTreatmentsWithConfigByFlagSet(maybeKey, maybeFlagSet, combineAttributes(maybeAttributes));
|
|
55
|
+
}
|
|
56
|
+
|
|
37
57
|
function track(maybeKey: SplitIO.SplitKey, maybeTT: string, maybeEvent: string, maybeEventValue?: number, maybeProperties?: SplitIO.Properties) {
|
|
38
58
|
return clientTrack(maybeKey, maybeTT, maybeEvent, maybeEventValue, maybeProperties);
|
|
39
59
|
}
|
|
@@ -51,6 +71,10 @@ export function clientAttributesDecoration<TClient extends SplitIO.IClient | Spl
|
|
|
51
71
|
getTreatmentWithConfig: getTreatmentWithConfig,
|
|
52
72
|
getTreatments: getTreatments,
|
|
53
73
|
getTreatmentsWithConfig: getTreatmentsWithConfig,
|
|
74
|
+
getTreatmentsByFlagSets: getTreatmentsByFlagSets,
|
|
75
|
+
getTreatmentsWithConfigByFlagSets: getTreatmentsWithConfigByFlagSets,
|
|
76
|
+
getTreatmentsByFlagSet: getTreatmentsByFlagSet,
|
|
77
|
+
getTreatmentsWithConfigByFlagSet: getTreatmentsWithConfigByFlagSet,
|
|
54
78
|
track: track,
|
|
55
79
|
|
|
56
80
|
/**
|
|
@@ -21,6 +21,10 @@ export function clientCSDecorator(log: ILogger, client: SplitIO.IClient, key: Sp
|
|
|
21
21
|
getTreatmentWithConfig: clientCS.getTreatmentWithConfig.bind(clientCS, key),
|
|
22
22
|
getTreatments: clientCS.getTreatments.bind(clientCS, key),
|
|
23
23
|
getTreatmentsWithConfig: clientCS.getTreatmentsWithConfig.bind(clientCS, key),
|
|
24
|
+
getTreatmentsByFlagSets: clientCS.getTreatmentsByFlagSets.bind(clientCS, key),
|
|
25
|
+
getTreatmentsWithConfigByFlagSets: clientCS.getTreatmentsWithConfigByFlagSets.bind(clientCS, key),
|
|
26
|
+
getTreatmentsByFlagSet: clientCS.getTreatmentsByFlagSet.bind(clientCS, key),
|
|
27
|
+
getTreatmentsWithConfigByFlagSet: clientCS.getTreatmentsWithConfigByFlagSet.bind(clientCS, key),
|
|
24
28
|
|
|
25
29
|
// Key is bound to the `track` method. Same thing happens with trafficType but only if provided
|
|
26
30
|
track: trafficType ? clientCS.track.bind(clientCS, key, trafficType) : clientCS.track.bind(clientCS, key),
|
|
@@ -17,6 +17,7 @@ import { IReadinessManager } from '../readiness/types';
|
|
|
17
17
|
import { MaybeThenable } from '../dtos/types';
|
|
18
18
|
import { ISettings, SplitIO } from '../types';
|
|
19
19
|
import { isStorageSync } from '../trackers/impressionObserver/utils';
|
|
20
|
+
import { flagSetsAreValid } from '../utils/settingsValidation/splitFilters';
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* Decorator that validates the input before actually executing the client methods.
|
|
@@ -30,21 +31,28 @@ export function clientInputValidationDecorator<TClient extends SplitIO.IClient |
|
|
|
30
31
|
/**
|
|
31
32
|
* Avoid repeating this validations code
|
|
32
33
|
*/
|
|
33
|
-
function validateEvaluationParams(maybeKey: SplitIO.SplitKey, maybeFeatureFlagNameOrNames: string | string[], maybeAttributes: SplitIO.Attributes | undefined, methodName: string) {
|
|
34
|
+
function validateEvaluationParams(maybeKey: SplitIO.SplitKey, maybeFeatureFlagNameOrNames: string | string[] | undefined, maybeAttributes: SplitIO.Attributes | undefined, methodName: string, maybeFlagSetNameOrNames?: string[] | undefined) {
|
|
34
35
|
const multi = startsWith(methodName, 'getTreatments');
|
|
35
36
|
const key = validateKey(log, maybeKey, methodName);
|
|
36
|
-
|
|
37
|
+
let splitOrSplits: string | string[] | false = false;
|
|
38
|
+
let flagSetOrFlagSets: string[] = [];
|
|
39
|
+
if (maybeFeatureFlagNameOrNames) {
|
|
40
|
+
splitOrSplits = multi ? validateSplits(log, maybeFeatureFlagNameOrNames, methodName) : validateSplit(log, maybeFeatureFlagNameOrNames, methodName);
|
|
41
|
+
}
|
|
37
42
|
const attributes = validateAttributes(log, maybeAttributes, methodName);
|
|
38
43
|
const isNotDestroyed = validateIfNotDestroyed(log, readinessManager, methodName);
|
|
39
|
-
|
|
44
|
+
if (maybeFlagSetNameOrNames) {
|
|
45
|
+
flagSetOrFlagSets = flagSetsAreValid(log, methodName, maybeFlagSetNameOrNames, settings.sync.__splitFiltersValidation.groupedFilters.bySet);
|
|
46
|
+
}
|
|
40
47
|
validateIfOperational(log, readinessManager, methodName);
|
|
41
48
|
|
|
42
|
-
const valid = isNotDestroyed && key && splitOrSplits && attributes !== false;
|
|
49
|
+
const valid = isNotDestroyed && key && (splitOrSplits || flagSetOrFlagSets.length > 0) && attributes !== false;
|
|
43
50
|
|
|
44
51
|
return {
|
|
45
52
|
valid,
|
|
46
53
|
key,
|
|
47
54
|
splitOrSplits,
|
|
55
|
+
flagSetOrFlagSets,
|
|
48
56
|
attributes
|
|
49
57
|
};
|
|
50
58
|
}
|
|
@@ -99,6 +107,46 @@ export function clientInputValidationDecorator<TClient extends SplitIO.IClient |
|
|
|
99
107
|
}
|
|
100
108
|
}
|
|
101
109
|
|
|
110
|
+
function getTreatmentsByFlagSets(maybeKey: SplitIO.SplitKey, maybeFlagSets: string[], maybeAttributes?: SplitIO.Attributes) {
|
|
111
|
+
const params = validateEvaluationParams(maybeKey, undefined, maybeAttributes, 'getTreatmentsByFlagSets', maybeFlagSets);
|
|
112
|
+
|
|
113
|
+
if (params.valid) {
|
|
114
|
+
return client.getTreatmentsByFlagSets(params.key as SplitIO.SplitKey, params.flagSetOrFlagSets as string[], params.attributes as SplitIO.Attributes | undefined);
|
|
115
|
+
} else {
|
|
116
|
+
return wrapResult({});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function getTreatmentsWithConfigByFlagSets(maybeKey: SplitIO.SplitKey, maybeFlagSets: string[], maybeAttributes?: SplitIO.Attributes) {
|
|
121
|
+
const params = validateEvaluationParams(maybeKey, undefined, maybeAttributes, 'getTreatmentsWithConfigByFlagSets', maybeFlagSets);
|
|
122
|
+
|
|
123
|
+
if (params.valid) {
|
|
124
|
+
return client.getTreatmentsWithConfigByFlagSets(params.key as SplitIO.SplitKey, params.flagSetOrFlagSets as string[], params.attributes as SplitIO.Attributes | undefined);
|
|
125
|
+
} else {
|
|
126
|
+
return wrapResult({});
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function getTreatmentsByFlagSet(maybeKey: SplitIO.SplitKey, maybeFlagSet: string, maybeAttributes?: SplitIO.Attributes) {
|
|
131
|
+
const params = validateEvaluationParams(maybeKey, undefined, maybeAttributes, 'getTreatmentsByFlagSet', [maybeFlagSet]);
|
|
132
|
+
|
|
133
|
+
if (params.valid) {
|
|
134
|
+
return client.getTreatmentsByFlagSet(params.key as SplitIO.SplitKey, params.flagSetOrFlagSets[0] as string, params.attributes as SplitIO.Attributes | undefined);
|
|
135
|
+
} else {
|
|
136
|
+
return wrapResult({});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function getTreatmentsWithConfigByFlagSet(maybeKey: SplitIO.SplitKey, maybeFlagSet: string, maybeAttributes?: SplitIO.Attributes) {
|
|
141
|
+
const params = validateEvaluationParams(maybeKey, undefined, maybeAttributes, 'getTreatmentsWithConfigByFlagSet', [maybeFlagSet]);
|
|
142
|
+
|
|
143
|
+
if (params.valid) {
|
|
144
|
+
return client.getTreatmentsWithConfigByFlagSet(params.key as SplitIO.SplitKey, params.flagSetOrFlagSets[0] as string, params.attributes as SplitIO.Attributes | undefined);
|
|
145
|
+
} else {
|
|
146
|
+
return wrapResult({});
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
102
150
|
function track(maybeKey: SplitIO.SplitKey, maybeTT: string, maybeEvent: string, maybeEventValue?: number, maybeProperties?: SplitIO.Properties) {
|
|
103
151
|
const key = validateKey(log, maybeKey, 'track');
|
|
104
152
|
const tt = validateTrafficType(log, maybeTT, 'track');
|
|
@@ -119,6 +167,10 @@ export function clientInputValidationDecorator<TClient extends SplitIO.IClient |
|
|
|
119
167
|
getTreatmentWithConfig,
|
|
120
168
|
getTreatments,
|
|
121
169
|
getTreatmentsWithConfig,
|
|
170
|
+
getTreatmentsByFlagSets,
|
|
171
|
+
getTreatmentsWithConfigByFlagSets,
|
|
172
|
+
getTreatmentsByFlagSet,
|
|
173
|
+
getTreatmentsWithConfigByFlagSet,
|
|
122
174
|
track
|
|
123
175
|
} as TClient;
|
|
124
176
|
}
|
package/src/sdkManager/index.ts
CHANGED
|
@@ -31,7 +31,8 @@ function objectToView(splitObject: ISplit | null): SplitIO.SplitView | null {
|
|
|
31
31
|
killed: splitObject.killed,
|
|
32
32
|
changeNumber: splitObject.changeNumber || 0,
|
|
33
33
|
treatments: collectTreatments(splitObject),
|
|
34
|
-
configs: splitObject.configurations || {}
|
|
34
|
+
configs: splitObject.configurations || {},
|
|
35
|
+
sets: splitObject.sets || []
|
|
35
36
|
};
|
|
36
37
|
}
|
|
37
38
|
|
package/src/services/splitApi.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { ISplitApi } from './types';
|
|
|
5
5
|
import { objectAssign } from '../utils/lang/objectAssign';
|
|
6
6
|
import { ITelemetryTracker } from '../trackers/types';
|
|
7
7
|
import { SPLITS, IMPRESSIONS, IMPRESSIONS_COUNT, EVENTS, TELEMETRY, TOKEN, SEGMENT, MY_SEGMENT } from '../utils/constants';
|
|
8
|
+
import { ERROR_TOO_MANY_SETS } from '../logger/constants';
|
|
8
9
|
|
|
9
10
|
const noCacheHeaderOptions = { headers: { 'Cache-Control': 'no-cache' } };
|
|
10
11
|
|
|
@@ -53,7 +54,11 @@ export function splitApiFactory(
|
|
|
53
54
|
|
|
54
55
|
fetchSplitChanges(since: number, noCache?: boolean, till?: number) {
|
|
55
56
|
const url = `${urls.sdk}/splitChanges?since=${since}${till ? '&till=' + till : ''}${filterQueryString || ''}`;
|
|
56
|
-
return splitHttpClient(url, noCache ? noCacheHeaderOptions : undefined, telemetryTracker.trackHttp(SPLITS))
|
|
57
|
+
return splitHttpClient(url, noCache ? noCacheHeaderOptions : undefined, telemetryTracker.trackHttp(SPLITS))
|
|
58
|
+
.catch((err) => {
|
|
59
|
+
if (err.statusCode === 414) settings.log.error(ERROR_TOO_MANY_SETS);
|
|
60
|
+
throw err;
|
|
61
|
+
});
|
|
57
62
|
},
|
|
58
63
|
|
|
59
64
|
fetchSegmentChanges(since: number, segmentName: string, noCache?: boolean, till?: number) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ISplitsCacheAsync } from './types';
|
|
2
2
|
import { ISplit } from '../dtos/types';
|
|
3
3
|
import { objectAssign } from '../utils/lang/objectAssign';
|
|
4
|
+
import { ISet } from '../utils/lang/sets';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* This class provides a skeletal implementation of the ISplitsCacheAsync interface
|
|
@@ -17,6 +18,7 @@ export abstract class AbstractSplitsCacheAsync implements ISplitsCacheAsync {
|
|
|
17
18
|
abstract getChangeNumber(): Promise<number>
|
|
18
19
|
abstract getAll(): Promise<ISplit[]>
|
|
19
20
|
abstract getSplitNames(): Promise<string[]>
|
|
21
|
+
abstract getNamesByFlagSets(flagSets: string[]): Promise<ISet<string>>
|
|
20
22
|
abstract trafficTypeExists(trafficType: string): Promise<boolean>
|
|
21
23
|
abstract clear(): Promise<boolean | void>
|
|
22
24
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ISplitsCacheSync } from './types';
|
|
2
2
|
import { ISplit } from '../dtos/types';
|
|
3
3
|
import { objectAssign } from '../utils/lang/objectAssign';
|
|
4
|
+
import { ISet } from '../utils/lang/sets';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* This class provides a skeletal implementation of the ISplitsCacheSync interface
|
|
@@ -78,6 +79,8 @@ export abstract class AbstractSplitsCacheSync implements ISplitsCacheSync {
|
|
|
78
79
|
return false;
|
|
79
80
|
}
|
|
80
81
|
|
|
82
|
+
abstract getNamesByFlagSets(flagSets: string[]): ISet<string>
|
|
83
|
+
|
|
81
84
|
}
|
|
82
85
|
|
|
83
86
|
/**
|
|
@@ -20,6 +20,10 @@ export class KeyBuilder {
|
|
|
20
20
|
return `${this.prefix}.trafficType.${trafficType}`;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
buildFlagSetKey(flagSet: string) {
|
|
24
|
+
return `${this.prefix}.flagset.${flagSet}`;
|
|
25
|
+
}
|
|
26
|
+
|
|
23
27
|
buildSplitKey(splitName: string) {
|
|
24
28
|
return `${this.prefix}.split.${splitName}`;
|
|
25
29
|
}
|
|
@@ -7,6 +7,10 @@ export const METHOD_NAMES: Record<Method, string> = {
|
|
|
7
7
|
ts: 'treatments',
|
|
8
8
|
tc: 'treatmentWithConfig',
|
|
9
9
|
tcs: 'treatmentsWithConfig',
|
|
10
|
+
tf: 'treatmentsByFlagSet',
|
|
11
|
+
tfs: 'treatmentsByFlagSets',
|
|
12
|
+
tcf: 'treatmentsWithConfigByFlagSet',
|
|
13
|
+
tcfs: 'treatmentsWithConfigByFlagSets',
|
|
10
14
|
tr: 'track'
|
|
11
15
|
};
|
|
12
16
|
|