@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.
Files changed (94) hide show
  1. package/CHANGES.txt +24 -22
  2. package/README.md +1 -1
  3. package/cjs/logger/constants.js +3 -3
  4. package/cjs/logger/messages/debug.js +7 -7
  5. package/cjs/logger/messages/error.js +2 -2
  6. package/cjs/logger/messages/info.js +3 -3
  7. package/cjs/logger/messages/warn.js +7 -7
  8. package/cjs/sdkClient/client.js +20 -20
  9. package/cjs/sdkClient/clientAttributesDecoration.js +8 -8
  10. package/cjs/sdkClient/clientInputValidation.js +10 -10
  11. package/cjs/sdkClient/sdkClient.js +1 -1
  12. package/cjs/sdkFactory/index.js +1 -1
  13. package/cjs/sdkManager/index.js +10 -8
  14. package/cjs/services/splitApi.js +1 -0
  15. package/cjs/services/splitHttpClient.js +1 -1
  16. package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +6 -10
  17. package/cjs/storages/inMemory/SplitsCacheInMemory.js +8 -16
  18. package/cjs/storages/inRedis/SplitsCacheInRedis.js +20 -23
  19. package/cjs/storages/pluggable/SplitsCachePluggable.js +18 -18
  20. package/cjs/sync/polling/updaters/segmentChangesUpdater.js +1 -1
  21. package/cjs/sync/polling/updaters/splitChangesUpdater.js +5 -12
  22. package/cjs/sync/streaming/pushManager.js +1 -1
  23. package/cjs/sync/submitters/telemetrySubmitter.js +2 -2
  24. package/cjs/utils/inputValidation/apiKey.js +26 -25
  25. package/cjs/utils/inputValidation/preloadedData.js +3 -3
  26. package/cjs/utils/inputValidation/split.js +1 -1
  27. package/cjs/utils/inputValidation/splits.js +2 -2
  28. package/cjs/utils/settingsValidation/index.js +1 -1
  29. package/esm/logger/constants.js +2 -2
  30. package/esm/logger/messages/debug.js +7 -7
  31. package/esm/logger/messages/error.js +2 -2
  32. package/esm/logger/messages/info.js +3 -3
  33. package/esm/logger/messages/warn.js +7 -7
  34. package/esm/sdkClient/client.js +20 -20
  35. package/esm/sdkClient/clientAttributesDecoration.js +8 -8
  36. package/esm/sdkClient/clientInputValidation.js +10 -10
  37. package/esm/sdkClient/sdkClient.js +1 -1
  38. package/esm/sdkFactory/index.js +1 -1
  39. package/esm/sdkManager/index.js +10 -8
  40. package/esm/services/splitApi.js +1 -0
  41. package/esm/services/splitHttpClient.js +1 -1
  42. package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +6 -10
  43. package/esm/storages/inMemory/SplitsCacheInMemory.js +8 -16
  44. package/esm/storages/inRedis/SplitsCacheInRedis.js +20 -23
  45. package/esm/storages/pluggable/SplitsCachePluggable.js +18 -18
  46. package/esm/sync/polling/updaters/segmentChangesUpdater.js +1 -1
  47. package/esm/sync/polling/updaters/splitChangesUpdater.js +5 -12
  48. package/esm/sync/streaming/pushManager.js +1 -1
  49. package/esm/sync/submitters/telemetrySubmitter.js +2 -2
  50. package/esm/utils/inputValidation/apiKey.js +27 -26
  51. package/esm/utils/inputValidation/preloadedData.js +3 -3
  52. package/esm/utils/inputValidation/split.js +1 -1
  53. package/esm/utils/inputValidation/splits.js +2 -2
  54. package/esm/utils/settingsValidation/index.js +1 -1
  55. package/package.json +1 -1
  56. package/src/logger/constants.ts +2 -2
  57. package/src/logger/messages/debug.ts +7 -7
  58. package/src/logger/messages/error.ts +2 -2
  59. package/src/logger/messages/info.ts +3 -3
  60. package/src/logger/messages/warn.ts +7 -7
  61. package/src/sdkClient/client.ts +20 -20
  62. package/src/sdkClient/clientAttributesDecoration.ts +10 -10
  63. package/src/sdkClient/clientInputValidation.ts +10 -10
  64. package/src/sdkClient/sdkClient.ts +3 -3
  65. package/src/sdkFactory/index.ts +1 -1
  66. package/src/sdkManager/index.ts +11 -8
  67. package/src/services/splitApi.ts +1 -0
  68. package/src/services/splitHttpClient.ts +1 -1
  69. package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +6 -10
  70. package/src/storages/inMemory/AttributesCacheInMemory.ts +7 -6
  71. package/src/storages/inMemory/SplitsCacheInMemory.ts +6 -14
  72. package/src/storages/inRedis/SplitsCacheInRedis.ts +19 -20
  73. package/src/storages/pluggable/SplitsCachePluggable.ts +17 -18
  74. package/src/sync/polling/updaters/segmentChangesUpdater.ts +1 -1
  75. package/src/sync/polling/updaters/splitChangesUpdater.ts +6 -12
  76. package/src/sync/streaming/pushManager.ts +1 -1
  77. package/src/sync/submitters/telemetrySubmitter.ts +2 -2
  78. package/src/types.ts +147 -140
  79. package/src/utils/inputValidation/apiKey.ts +25 -24
  80. package/src/utils/inputValidation/preloadedData.ts +3 -3
  81. package/src/utils/inputValidation/split.ts +1 -1
  82. package/src/utils/inputValidation/splits.ts +1 -1
  83. package/src/utils/settingsValidation/index.ts +1 -1
  84. package/types/logger/constants.d.ts +1 -1
  85. package/types/sdkClient/clientAttributesDecoration.d.ts +7 -7
  86. package/types/storages/inMemory/AttributesCacheInMemory.d.ts +4 -3
  87. package/types/types.d.ts +142 -135
  88. package/types/utils/inputValidation/apiKey.d.ts +5 -5
  89. package/types/utils/inputValidation/sdkKey.d.ts +7 -0
  90. package/types/utils/settingsValidation/index.d.ts +1 -1
  91. package/types/storages/metadataBuilder.d.ts +0 -3
  92. /package/types/storages/inMemory/{uniqueKeysCacheInMemory.d.ts → UniqueKeysCacheInMemory.d.ts} +0 -0
  93. /package/types/storages/inMemory/{uniqueKeysCacheInMemoryCS.d.ts → UniqueKeysCacheInMemoryCS.d.ts} +0 -0
  94. /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
- if (split.trafficTypeName) {
33
- const ttKey = this.keys.buildTrafficTypeKey(split.trafficTypeName);
34
- return this.wrapper.decr(ttKey).then(count => {
35
- if (count === 0) return this.wrapper.del(ttKey);
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
- if (split.trafficTypeName) {
42
- const ttKey = this.keys.buildTrafficTypeKey(split.trafficTypeName);
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 split definition: ' + e);
58
+ throw new Error('Error parsing feature flag definition: ' + e);
63
59
  }
64
60
 
65
- return Promise.all([
66
- this.wrapper.set(splitKey, stringifiedNewSplit),
67
- this._incrementCounts(split),
68
- // If it's an update, we decrement the traffic type and segment count of the existing split,
69
- parsedPreviousSplit && this._decrementCounts(parsedPreviousSplit)
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 Api Key from the Split web console that is of type Server-side.`);
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 = { added: [], removed: [], segments: [] } as ISplitMutations;
63
- uniqueEntries.forEach((split) => {
55
+ const computed = entries.reduce((accum, split) => {
64
56
  if (split.status === 'ACTIVE') {
65
- computed.added.push([split.name, split]);
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
- computed.removed.push(split.name);
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 API Key) or 400 (using incorrect API Key, i.e., client-side API Key on server-side)
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, apiKey) => {
37
- return acum + usedKeysMap[apiKey] - 1;
36
+ return Object.keys(usedKeysMap).reduce((acum, sdkKey) => {
37
+ return acum + usedKeysMap[sdkKey] - 1;
38
38
  }, 0);
39
39
  }
40
40