@splitsoftware/splitio-commons 1.8.2-rc.0 → 1.8.2-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.
Files changed (85) hide show
  1. package/CHANGES.txt +5 -5
  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/splitHttpClient.js +1 -1
  15. package/cjs/storages/inRedis/SplitsCacheInRedis.js +2 -2
  16. package/cjs/storages/pluggable/SplitsCachePluggable.js +1 -1
  17. package/cjs/sync/polling/updaters/segmentChangesUpdater.js +1 -1
  18. package/cjs/sync/polling/updaters/splitChangesUpdater.js +5 -12
  19. package/cjs/sync/streaming/pushManager.js +1 -1
  20. package/cjs/sync/submitters/telemetrySubmitter.js +2 -2
  21. package/cjs/utils/inputValidation/apiKey.js +26 -25
  22. package/cjs/utils/inputValidation/preloadedData.js +3 -3
  23. package/cjs/utils/inputValidation/split.js +1 -1
  24. package/cjs/utils/inputValidation/splits.js +2 -2
  25. package/cjs/utils/settingsValidation/index.js +1 -1
  26. package/esm/logger/constants.js +2 -2
  27. package/esm/logger/messages/debug.js +7 -7
  28. package/esm/logger/messages/error.js +2 -2
  29. package/esm/logger/messages/info.js +3 -3
  30. package/esm/logger/messages/warn.js +7 -7
  31. package/esm/sdkClient/client.js +20 -20
  32. package/esm/sdkClient/clientAttributesDecoration.js +8 -8
  33. package/esm/sdkClient/clientInputValidation.js +10 -10
  34. package/esm/sdkClient/sdkClient.js +1 -1
  35. package/esm/sdkFactory/index.js +1 -1
  36. package/esm/sdkManager/index.js +10 -8
  37. package/esm/services/splitHttpClient.js +1 -1
  38. package/esm/storages/inRedis/SplitsCacheInRedis.js +2 -2
  39. package/esm/storages/pluggable/SplitsCachePluggable.js +1 -1
  40. package/esm/sync/polling/updaters/segmentChangesUpdater.js +1 -1
  41. package/esm/sync/polling/updaters/splitChangesUpdater.js +5 -12
  42. package/esm/sync/streaming/pushManager.js +1 -1
  43. package/esm/sync/submitters/telemetrySubmitter.js +2 -2
  44. package/esm/utils/inputValidation/apiKey.js +27 -26
  45. package/esm/utils/inputValidation/preloadedData.js +3 -3
  46. package/esm/utils/inputValidation/split.js +1 -1
  47. package/esm/utils/inputValidation/splits.js +2 -2
  48. package/esm/utils/settingsValidation/index.js +1 -1
  49. package/package.json +1 -1
  50. package/src/logger/constants.ts +2 -2
  51. package/src/logger/messages/debug.ts +7 -7
  52. package/src/logger/messages/error.ts +2 -2
  53. package/src/logger/messages/info.ts +3 -3
  54. package/src/logger/messages/warn.ts +7 -7
  55. package/src/sdkClient/client.ts +20 -20
  56. package/src/sdkClient/clientAttributesDecoration.ts +10 -10
  57. package/src/sdkClient/clientInputValidation.ts +10 -10
  58. package/src/sdkClient/sdkClient.ts +3 -3
  59. package/src/sdkFactory/index.ts +1 -1
  60. package/src/sdkManager/index.ts +11 -8
  61. package/src/services/splitHttpClient.ts +1 -1
  62. package/src/storages/inMemory/AttributesCacheInMemory.ts +7 -6
  63. package/src/storages/inRedis/SplitsCacheInRedis.ts +2 -2
  64. package/src/storages/pluggable/SplitsCachePluggable.ts +1 -1
  65. package/src/sync/polling/updaters/segmentChangesUpdater.ts +1 -1
  66. package/src/sync/polling/updaters/splitChangesUpdater.ts +6 -12
  67. package/src/sync/streaming/pushManager.ts +1 -1
  68. package/src/sync/submitters/telemetrySubmitter.ts +2 -2
  69. package/src/types.ts +147 -140
  70. package/src/utils/inputValidation/apiKey.ts +25 -24
  71. package/src/utils/inputValidation/preloadedData.ts +3 -3
  72. package/src/utils/inputValidation/split.ts +1 -1
  73. package/src/utils/inputValidation/splits.ts +1 -1
  74. package/src/utils/settingsValidation/index.ts +1 -1
  75. package/types/logger/constants.d.ts +1 -1
  76. package/types/sdkClient/clientAttributesDecoration.d.ts +7 -7
  77. package/types/storages/inMemory/AttributesCacheInMemory.d.ts +4 -3
  78. package/types/types.d.ts +142 -135
  79. package/types/utils/inputValidation/apiKey.d.ts +5 -5
  80. package/types/utils/inputValidation/sdkKey.d.ts +7 -0
  81. package/types/utils/settingsValidation/index.d.ts +1 -1
  82. package/types/storages/metadataBuilder.d.ts +0 -3
  83. /package/types/storages/inMemory/{uniqueKeysCacheInMemory.d.ts → UniqueKeysCacheInMemory.d.ts} +0 -0
  84. /package/types/storages/inMemory/{uniqueKeysCacheInMemoryCS.d.ts → UniqueKeysCacheInMemoryCS.d.ts} +0 -0
  85. /package/types/storages/inRedis/{uniqueKeysCacheInRedis.d.ts → UniqueKeysCacheInRedis.d.ts} +0 -0
@@ -1,8 +1,9 @@
1
+ import { SplitIO } from '../../types';
1
2
  import { objectAssign } from '../../utils/lang/objectAssign';
2
3
 
3
4
  export class AttributesCacheInMemory {
4
5
 
5
- private attributesCache: Record<string, Object> = {};
6
+ private attributesCache: Record<string, SplitIO.AttributeType> = {};
6
7
 
7
8
 
8
9
  /**
@@ -12,7 +13,7 @@ export class AttributesCacheInMemory {
12
13
  * @param {Object} attributeValue attribute value
13
14
  * @returns {boolean} the attribute was stored
14
15
  */
15
- setAttribute(attributeName: string, attributeValue: Object): boolean {
16
+ setAttribute(attributeName: string, attributeValue: SplitIO.AttributeType) {
16
17
  this.attributesCache[attributeName] = attributeValue;
17
18
  return true;
18
19
  }
@@ -23,7 +24,7 @@ export class AttributesCacheInMemory {
23
24
  * @param {string} attributeName attribute name
24
25
  * @returns {Object?} stored attribute value
25
26
  */
26
- getAttribute(attributeName: string): Object {
27
+ getAttribute(attributeName: string) {
27
28
  return this.attributesCache[attributeName];
28
29
  }
29
30
 
@@ -33,7 +34,7 @@ export class AttributesCacheInMemory {
33
34
  * @param {[string, Object]} attributes attributes to create or update
34
35
  * @returns {boolean} attributes were stored
35
36
  */
36
- setAttributes(attributes: Record<string, Object>): boolean {
37
+ setAttributes(attributes: Record<string, Object>) {
37
38
  this.attributesCache = objectAssign(this.attributesCache, attributes);
38
39
  return true;
39
40
  }
@@ -43,7 +44,7 @@ export class AttributesCacheInMemory {
43
44
  *
44
45
  * @returns {Map<string, Object>} stored attributes
45
46
  */
46
- getAll(): Record<string, Object> {
47
+ getAll() {
47
48
  return this.attributesCache;
48
49
  }
49
50
 
@@ -53,7 +54,7 @@ export class AttributesCacheInMemory {
53
54
  * @param {string} attributeName attribute to remove
54
55
  * @returns {boolean} attribute removed
55
56
  */
56
- removeAttribute(attributeName: string): boolean {
57
+ removeAttribute(attributeName: string) {
57
58
  if (Object.keys(this.attributesCache).indexOf(attributeName) >= 0) {
58
59
  delete this.attributesCache[attributeName];
59
60
  return true;
@@ -75,7 +75,7 @@ export class SplitsCacheInRedis extends AbstractSplitsCacheAsync {
75
75
  parsedPreviousSplit = splitFromStorage ? JSON.parse(splitFromStorage) : undefined;
76
76
  newStringifiedSplit = JSON.stringify(split);
77
77
  } catch (e) {
78
- throw new Error('Error parsing split definition: ' + e);
78
+ throw new Error('Error parsing feature flag definition: ' + e);
79
79
  }
80
80
 
81
81
  return Promise.all([
@@ -247,7 +247,7 @@ export class SplitsCacheInRedis extends AbstractSplitsCacheAsync {
247
247
  return Promise.resolve(splits);
248
248
  })
249
249
  .catch(e => {
250
- this.log.error(LOG_PREFIX + `Could not grab splits due to an error: ${e}.`);
250
+ this.log.error(LOG_PREFIX + `Could not grab feature flags due to an error: ${e}.`);
251
251
  return Promise.reject(e);
252
252
  });
253
253
  }
@@ -59,7 +59,7 @@ export class SplitsCachePluggable extends AbstractSplitsCacheAsync {
59
59
  parsedPreviousSplit = splitFromStorage ? JSON.parse(splitFromStorage) : undefined;
60
60
  stringifiedNewSplit = JSON.stringify(split);
61
61
  } catch (e) {
62
- throw new Error('Error parsing split definition: ' + e);
62
+ throw new Error('Error parsing feature flag definition: ' + e);
63
63
  }
64
64
 
65
65
  return Promise.all([
@@ -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