@splitsoftware/splitio-commons 1.8.2-rc.0 → 1.8.2-rc.2
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 +24 -22
- package/README.md +1 -1
- package/cjs/logger/constants.js +3 -3
- package/cjs/logger/messages/debug.js +7 -7
- package/cjs/logger/messages/error.js +2 -2
- package/cjs/logger/messages/info.js +3 -3
- package/cjs/logger/messages/warn.js +7 -7
- package/cjs/sdkClient/client.js +20 -20
- package/cjs/sdkClient/clientAttributesDecoration.js +8 -8
- package/cjs/sdkClient/clientInputValidation.js +10 -10
- package/cjs/sdkClient/sdkClient.js +1 -1
- package/cjs/sdkFactory/index.js +1 -1
- package/cjs/sdkManager/index.js +10 -8
- package/cjs/services/splitApi.js +1 -0
- package/cjs/services/splitHttpClient.js +1 -1
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +6 -10
- package/cjs/storages/inMemory/SplitsCacheInMemory.js +8 -16
- package/cjs/storages/inRedis/SplitsCacheInRedis.js +20 -23
- package/cjs/storages/pluggable/SplitsCachePluggable.js +18 -18
- package/cjs/sync/polling/updaters/segmentChangesUpdater.js +1 -1
- package/cjs/sync/polling/updaters/splitChangesUpdater.js +5 -12
- package/cjs/sync/streaming/pushManager.js +1 -1
- package/cjs/sync/submitters/telemetrySubmitter.js +2 -2
- package/cjs/utils/inputValidation/apiKey.js +26 -25
- package/cjs/utils/inputValidation/preloadedData.js +3 -3
- package/cjs/utils/inputValidation/split.js +1 -1
- package/cjs/utils/inputValidation/splits.js +2 -2
- package/cjs/utils/settingsValidation/index.js +1 -1
- package/esm/logger/constants.js +2 -2
- package/esm/logger/messages/debug.js +7 -7
- package/esm/logger/messages/error.js +2 -2
- package/esm/logger/messages/info.js +3 -3
- package/esm/logger/messages/warn.js +7 -7
- package/esm/sdkClient/client.js +20 -20
- package/esm/sdkClient/clientAttributesDecoration.js +8 -8
- package/esm/sdkClient/clientInputValidation.js +10 -10
- package/esm/sdkClient/sdkClient.js +1 -1
- package/esm/sdkFactory/index.js +1 -1
- package/esm/sdkManager/index.js +10 -8
- package/esm/services/splitApi.js +1 -0
- package/esm/services/splitHttpClient.js +1 -1
- package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +6 -10
- package/esm/storages/inMemory/SplitsCacheInMemory.js +8 -16
- package/esm/storages/inRedis/SplitsCacheInRedis.js +20 -23
- package/esm/storages/pluggable/SplitsCachePluggable.js +18 -18
- package/esm/sync/polling/updaters/segmentChangesUpdater.js +1 -1
- package/esm/sync/polling/updaters/splitChangesUpdater.js +5 -12
- package/esm/sync/streaming/pushManager.js +1 -1
- package/esm/sync/submitters/telemetrySubmitter.js +2 -2
- package/esm/utils/inputValidation/apiKey.js +27 -26
- package/esm/utils/inputValidation/preloadedData.js +3 -3
- package/esm/utils/inputValidation/split.js +1 -1
- package/esm/utils/inputValidation/splits.js +2 -2
- package/esm/utils/settingsValidation/index.js +1 -1
- package/package.json +1 -1
- package/src/logger/constants.ts +2 -2
- package/src/logger/messages/debug.ts +7 -7
- package/src/logger/messages/error.ts +2 -2
- package/src/logger/messages/info.ts +3 -3
- package/src/logger/messages/warn.ts +7 -7
- package/src/sdkClient/client.ts +20 -20
- package/src/sdkClient/clientAttributesDecoration.ts +10 -10
- package/src/sdkClient/clientInputValidation.ts +10 -10
- package/src/sdkClient/sdkClient.ts +3 -3
- package/src/sdkFactory/index.ts +1 -1
- package/src/sdkManager/index.ts +11 -8
- package/src/services/splitApi.ts +1 -0
- package/src/services/splitHttpClient.ts +1 -1
- package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +6 -10
- package/src/storages/inMemory/AttributesCacheInMemory.ts +7 -6
- package/src/storages/inMemory/SplitsCacheInMemory.ts +6 -14
- package/src/storages/inRedis/SplitsCacheInRedis.ts +19 -20
- package/src/storages/pluggable/SplitsCachePluggable.ts +17 -18
- package/src/sync/polling/updaters/segmentChangesUpdater.ts +1 -1
- package/src/sync/polling/updaters/splitChangesUpdater.ts +6 -12
- package/src/sync/streaming/pushManager.ts +1 -1
- package/src/sync/submitters/telemetrySubmitter.ts +2 -2
- package/src/types.ts +147 -140
- package/src/utils/inputValidation/apiKey.ts +25 -24
- package/src/utils/inputValidation/preloadedData.ts +3 -3
- package/src/utils/inputValidation/split.ts +1 -1
- package/src/utils/inputValidation/splits.ts +1 -1
- package/src/utils/settingsValidation/index.ts +1 -1
- package/types/logger/constants.d.ts +1 -1
- package/types/sdkClient/clientAttributesDecoration.d.ts +7 -7
- package/types/storages/inMemory/AttributesCacheInMemory.d.ts +4 -3
- package/types/types.d.ts +142 -135
- package/types/utils/inputValidation/apiKey.d.ts +5 -5
- package/types/utils/inputValidation/sdkKey.d.ts +7 -0
- package/types/utils/settingsValidation/index.d.ts +1 -1
- package/types/storages/metadataBuilder.d.ts +0 -3
- /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
|
@@ -29,19 +29,15 @@ export class SplitsCachePluggable extends AbstractSplitsCacheAsync {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
private _decrementCounts(split: ISplit) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return this.wrapper.
|
|
35
|
-
|
|
36
|
-
});
|
|
37
|
-
}
|
|
32
|
+
const ttKey = this.keys.buildTrafficTypeKey(split.trafficTypeName);
|
|
33
|
+
return this.wrapper.decr(ttKey).then(count => {
|
|
34
|
+
if (count === 0) return this.wrapper.del(ttKey);
|
|
35
|
+
});
|
|
38
36
|
}
|
|
39
37
|
|
|
40
38
|
private _incrementCounts(split: ISplit) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return this.wrapper.incr(ttKey);
|
|
44
|
-
}
|
|
39
|
+
const ttKey = this.keys.buildTrafficTypeKey(split.trafficTypeName);
|
|
40
|
+
return this.wrapper.incr(ttKey);
|
|
45
41
|
}
|
|
46
42
|
|
|
47
43
|
/**
|
|
@@ -54,20 +50,23 @@ export class SplitsCachePluggable extends AbstractSplitsCacheAsync {
|
|
|
54
50
|
return this.wrapper.get(splitKey).then(splitFromStorage => {
|
|
55
51
|
|
|
56
52
|
// handling parsing error
|
|
57
|
-
let parsedPreviousSplit, stringifiedNewSplit;
|
|
53
|
+
let parsedPreviousSplit: ISplit, stringifiedNewSplit;
|
|
58
54
|
try {
|
|
59
55
|
parsedPreviousSplit = splitFromStorage ? JSON.parse(splitFromStorage) : undefined;
|
|
60
56
|
stringifiedNewSplit = JSON.stringify(split);
|
|
61
57
|
} catch (e) {
|
|
62
|
-
throw new Error('Error parsing
|
|
58
|
+
throw new Error('Error parsing feature flag definition: ' + e);
|
|
63
59
|
}
|
|
64
60
|
|
|
65
|
-
return
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
61
|
+
return this.wrapper.set(splitKey, stringifiedNewSplit).then(() => {
|
|
62
|
+
// avoid unnecessary increment/decrement operations
|
|
63
|
+
if (parsedPreviousSplit && parsedPreviousSplit.trafficTypeName === split.trafficTypeName) return;
|
|
64
|
+
|
|
65
|
+
// update traffic type counts
|
|
66
|
+
return this._incrementCounts(split).then(() => {
|
|
67
|
+
if (parsedPreviousSplit) return this._decrementCounts(parsedPreviousSplit);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
71
70
|
}).then(() => true);
|
|
72
71
|
}
|
|
73
72
|
|
|
@@ -98,7 +98,7 @@ export function segmentChangesUpdaterFactory(
|
|
|
98
98
|
// If the operation is forbidden, it may be due to permissions. Destroy the SDK instance.
|
|
99
99
|
// @TODO although factory status is destroyed, synchronization is not stopped
|
|
100
100
|
if (readiness) readiness.destroy();
|
|
101
|
-
log.error(`${LOG_PREFIX_INSTANTIATION}: you passed a client-side type authorizationKey, please grab an
|
|
101
|
+
log.error(`${LOG_PREFIX_INSTANTIATION}: you passed a client-side type authorizationKey, please grab an SDK Key from the Split user interface that is of type server-side.`);
|
|
102
102
|
} else {
|
|
103
103
|
log.warn(`${LOG_PREFIX_SYNC_SEGMENTS}Error while doing fetch of segments. ${error}`);
|
|
104
104
|
}
|
|
@@ -7,7 +7,6 @@ import { timeout } from '../../../utils/promise/timeout';
|
|
|
7
7
|
import { SDK_SPLITS_ARRIVED, SDK_SPLITS_CACHE_LOADED } from '../../../readiness/constants';
|
|
8
8
|
import { ILogger } from '../../../logger/types';
|
|
9
9
|
import { SYNC_SPLITS_FETCH, SYNC_SPLITS_NEW, SYNC_SPLITS_REMOVED, SYNC_SPLITS_SEGMENTS, SYNC_SPLITS_FETCH_FAILS, SYNC_SPLITS_FETCH_RETRY } from '../../../logger/constants';
|
|
10
|
-
import { _Map } from '../../../utils/lang/maps';
|
|
11
10
|
|
|
12
11
|
type ISplitChangesUpdater = (noCache?: boolean, till?: number) => Promise<boolean>
|
|
13
12
|
|
|
@@ -52,25 +51,20 @@ interface ISplitMutations {
|
|
|
52
51
|
* Exported for testing purposes.
|
|
53
52
|
*/
|
|
54
53
|
export function computeSplitsMutation(entries: ISplit[]): ISplitMutations {
|
|
55
|
-
const uniqueEntries = new _Map();
|
|
56
|
-
entries.forEach(split => {
|
|
57
|
-
const prevSplit = uniqueEntries.get(split.name);
|
|
58
|
-
if (!prevSplit || prevSplit.changeNumber < split.changeNumber) uniqueEntries.set(split.name, split);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
54
|
const segments = new _Set<string>();
|
|
62
|
-
const computed =
|
|
63
|
-
uniqueEntries.forEach((split) => {
|
|
55
|
+
const computed = entries.reduce((accum, split) => {
|
|
64
56
|
if (split.status === 'ACTIVE') {
|
|
65
|
-
|
|
57
|
+
accum.added.push([split.name, split]);
|
|
66
58
|
|
|
67
59
|
parseSegments(split).forEach((segmentName: string) => {
|
|
68
60
|
segments.add(segmentName);
|
|
69
61
|
});
|
|
70
62
|
} else {
|
|
71
|
-
|
|
63
|
+
accum.removed.push(split.name);
|
|
72
64
|
}
|
|
73
|
-
|
|
65
|
+
|
|
66
|
+
return accum;
|
|
67
|
+
}, { added: [], removed: [], segments: [] } as ISplitMutations);
|
|
74
68
|
|
|
75
69
|
computed.segments = setToArray(segments);
|
|
76
70
|
|
|
@@ -139,7 +139,7 @@ export function pushManagerFactory(
|
|
|
139
139
|
|
|
140
140
|
log.error(ERROR_STREAMING_AUTH, [error.message]);
|
|
141
141
|
|
|
142
|
-
// Handle 4XX HTTP errors: 401 (invalid
|
|
142
|
+
// Handle 4XX HTTP errors: 401 (invalid SDK Key) or 400 (using incorrect SDK Key, i.e., client-side SDK Key on server-side)
|
|
143
143
|
if (error.statusCode >= 400 && error.statusCode < 500) {
|
|
144
144
|
telemetryTracker.streamingEvent(AUTH_REJECTION);
|
|
145
145
|
pushEmitter.emit(PUSH_NONRETRYABLE_ERROR);
|
|
@@ -33,8 +33,8 @@ function getActiveFactories() {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
function getRedundantActiveFactories() {
|
|
36
|
-
return Object.keys(usedKeysMap).reduce((acum,
|
|
37
|
-
return acum + usedKeysMap[
|
|
36
|
+
return Object.keys(usedKeysMap).reduce((acum, sdkKey) => {
|
|
37
|
+
return acum + usedKeysMap[sdkKey] - 1;
|
|
38
38
|
}, 0);
|
|
39
39
|
}
|
|
40
40
|
|