@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
@@ -1,51 +1,52 @@
1
- import { ERROR_NULL, ERROR_EMPTY, ERROR_INVALID, WARN_API_KEY, LOG_PREFIX_INSTANTIATION } from '../../logger/constants';
1
+ import { ERROR_NULL, ERROR_EMPTY, ERROR_INVALID, WARN_SDK_KEY, LOG_PREFIX_INSTANTIATION } from '../../logger/constants';
2
2
  import { ILogger } from '../../logger/types';
3
3
  import { isString } from '../lang';
4
4
 
5
- const item = 'api_key';
5
+ const item = 'sdk_key';
6
6
 
7
- /** validates the given api key */
8
- export function validateApiKey(log: ILogger, maybeApiKey: any): string | false {
9
- let apiKey: string | false = false;
10
- if (maybeApiKey == undefined) { // eslint-disable-line eqeqeq
7
+ // @TODO replace ApiKey with SdkKey in function names
8
+ /** validates the given SDK key */
9
+ export function validateApiKey(log: ILogger, maybeSdkKey: any): string | false {
10
+ let sdkKey: string | false = false;
11
+ if (maybeSdkKey == undefined) { // eslint-disable-line eqeqeq
11
12
  log.error(ERROR_NULL, [LOG_PREFIX_INSTANTIATION, item]);
12
- } else if (isString(maybeApiKey)) {
13
- if (maybeApiKey.length > 0)
14
- apiKey = maybeApiKey;
13
+ } else if (isString(maybeSdkKey)) {
14
+ if (maybeSdkKey.length > 0)
15
+ sdkKey = maybeSdkKey;
15
16
  else
16
17
  log.error(ERROR_EMPTY, [LOG_PREFIX_INSTANTIATION, item]);
17
18
  } else {
18
19
  log.error(ERROR_INVALID, [LOG_PREFIX_INSTANTIATION, item]);
19
20
  }
20
21
 
21
- return apiKey;
22
+ return sdkKey;
22
23
  }
23
24
 
24
25
  // Exported for telemetry
25
26
  export const usedKeysMap: Record<string, number> = {};
26
27
 
27
- /** validates the given api key and also warns if it is in use */
28
- export function validateAndTrackApiKey(log: ILogger, maybeApiKey: any): string | false {
29
- const apiKey = validateApiKey(log, maybeApiKey);
28
+ /** validates the given SDK key and also warns if it is in use */
29
+ export function validateAndTrackApiKey(log: ILogger, maybeSdkKey: any): string | false {
30
+ const sdkKey = validateApiKey(log, maybeSdkKey);
30
31
 
31
- // If the apiKey is correct, we'll save it as the instance creation should work.
32
- if (apiKey) {
33
- if (!usedKeysMap[apiKey]) {
32
+ // If sdkKey is correct, we'll save it as the instance creation should work.
33
+ if (sdkKey) {
34
+ if (!usedKeysMap[sdkKey]) {
34
35
  // If this key is not present, only warning scenarios is that we have factories for other keys.
35
- usedKeysMap[apiKey] = 1;
36
+ usedKeysMap[sdkKey] = 1;
36
37
  if (Object.keys(usedKeysMap).length > 1) {
37
- log.warn(WARN_API_KEY, ['an instance of the Split factory']);
38
+ log.warn(WARN_SDK_KEY, ['an instance of the Split factory']);
38
39
  }
39
40
  } else {
40
- log.warn(WARN_API_KEY, [`${usedKeysMap[apiKey]} factory/ies with this API Key`]);
41
- usedKeysMap[apiKey]++;
41
+ log.warn(WARN_SDK_KEY, [`${usedKeysMap[sdkKey]} factory/ies with this SDK Key`]);
42
+ usedKeysMap[sdkKey]++;
42
43
  }
43
44
  }
44
45
 
45
- return apiKey;
46
+ return sdkKey;
46
47
  }
47
48
 
48
- export function releaseApiKey(apiKey: string) {
49
- if (usedKeysMap[apiKey]) usedKeysMap[apiKey]--;
50
- if (usedKeysMap[apiKey] === 0) delete usedKeysMap[apiKey];
49
+ export function releaseApiKey(sdkKey: string) {
50
+ if (usedKeysMap[sdkKey]) usedKeysMap[sdkKey]--;
51
+ if (usedKeysMap[sdkKey] === 0) delete usedKeysMap[sdkKey];
51
52
  }
@@ -12,11 +12,11 @@ function validateTimestampData(log: ILogger, maybeTimestamp: any, method: string
12
12
  function validateSplitsData(log: ILogger, maybeSplitsData: any, method: string) {
13
13
  if (isObject(maybeSplitsData)) {
14
14
  const splitNames = Object.keys(maybeSplitsData);
15
- if (splitNames.length === 0) log.warn(`${method}: preloadedData.splitsData doesn't contain split definitions.`);
15
+ if (splitNames.length === 0) log.warn(`${method}: preloadedData.splitsData doesn't contain feature flag definitions.`);
16
16
  // @TODO in the future, consider handling the possibility of having parsed definitions of splits
17
17
  if (splitNames.every(splitName => validateSplit(log, splitName, method) && isString(maybeSplitsData[splitName]))) return true;
18
18
  }
19
- log.error(`${method}: preloadedData.splitsData must be a map of split names to their serialized definitions.`);
19
+ log.error(`${method}: preloadedData.splitsData must be a map of feature flag names to their stringified definitions.`);
20
20
  return false;
21
21
  }
22
22
 
@@ -38,7 +38,7 @@ function validateSegmentsData(log: ILogger, maybeSegmentsData: any, method: stri
38
38
  const segmentNames = Object.keys(maybeSegmentsData);
39
39
  if (segmentNames.every(segmentName => isString(maybeSegmentsData[segmentName]))) return true;
40
40
  }
41
- log.error(`${method}: preloadedData.segmentsData must be a map of segment names to their serialized definitions.`);
41
+ log.error(`${method}: preloadedData.segmentsData must be a map of segment names to their stringified definitions.`);
42
42
  return false;
43
43
  }
44
44
 
@@ -5,7 +5,7 @@ import { isString } from '../lang';
5
5
  // include BOM and nbsp
6
6
  const TRIMMABLE_SPACES_REGEX = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/;
7
7
 
8
- export function validateSplit(log: ILogger, maybeSplit: any, method: string, item = 'split name'): string | false {
8
+ export function validateSplit(log: ILogger, maybeSplit: any, method: string, item = 'feature flag name'): string | false {
9
9
  if (maybeSplit == undefined) { // eslint-disable-line eqeqeq
10
10
  log.error(ERROR_NULL, [method, item]);
11
11
  } else if (!isString(maybeSplit)) {
@@ -3,7 +3,7 @@ import { ILogger } from '../../logger/types';
3
3
  import { uniq } from '../lang';
4
4
  import { validateSplit } from './split';
5
5
 
6
- export function validateSplits(log: ILogger, maybeSplits: any, method: string, listName = 'split_names', item = 'split name'): string[] | false {
6
+ export function validateSplits(log: ILogger, maybeSplits: any, method: string, listName = 'feature flag names', item = 'feature flag name'): string[] | false {
7
7
  if (Array.isArray(maybeSplits) && maybeSplits.length > 0) {
8
8
  let validatedArray: string[] = [];
9
9
  // Remove invalid values
@@ -97,7 +97,7 @@ function fromSecondsToMillis(n: number) {
97
97
 
98
98
  /**
99
99
  * Validates the given config and use it to build a settings object.
100
- * NOTE: it doesn't validate the Api Key. Call `validateApikey` or `validateAndTrackApiKey` for that after settings validation.
100
+ * NOTE: it doesn't validate the SDK Key. Call `validateApiKey` or `validateAndTrackApiKey` for that after settings validation.
101
101
  *
102
102
  * @param config user defined configuration
103
103
  * @param validationParams defaults and fields validators used to validate and creates a settings object from a given config
@@ -92,7 +92,7 @@ export declare const WARN_INTEGRATION_INVALID = 218;
92
92
  export declare const WARN_SPLITS_FILTER_IGNORED = 219;
93
93
  export declare const WARN_SPLITS_FILTER_INVALID = 220;
94
94
  export declare const WARN_SPLITS_FILTER_EMPTY = 221;
95
- export declare const WARN_API_KEY = 222;
95
+ export declare const WARN_SDK_KEY = 222;
96
96
  export declare const STREAMING_PARSING_MY_SEGMENTS_UPDATE_V2 = 223;
97
97
  export declare const ERROR_ENGINE_COMBINER_IFELSEIF = 300;
98
98
  export declare const ERROR_LOGLEVEL_INVALID = 301;
@@ -4,10 +4,10 @@ import { ILogger } from '../logger/types';
4
4
  * Add in memory attributes storage methods and combine them with any attribute received from the getTreatment/s call
5
5
  */
6
6
  export declare function clientAttributesDecoration<TClient extends SplitIO.IClient | SplitIO.IAsyncClient>(log: ILogger, client: TClient): TClient & {
7
- getTreatment: (maybeKey: SplitIO.SplitKey, maybeSplit: string, maybeAttributes?: SplitIO.Attributes | undefined) => string | SplitIO.AsyncTreatment;
8
- getTreatmentWithConfig: (maybeKey: SplitIO.SplitKey, maybeSplit: string, maybeAttributes?: SplitIO.Attributes | undefined) => SplitIO.TreatmentWithConfig | SplitIO.AsyncTreatmentWithConfig;
9
- getTreatments: (maybeKey: SplitIO.SplitKey, maybeSplits: string[], maybeAttributes?: SplitIO.Attributes | undefined) => SplitIO.Treatments | SplitIO.AsyncTreatments;
10
- getTreatmentsWithConfig: (maybeKey: SplitIO.SplitKey, maybeSplits: string[], maybeAttributes?: SplitIO.Attributes | undefined) => SplitIO.TreatmentsWithConfig | SplitIO.AsyncTreatmentsWithConfig;
7
+ getTreatment: (maybeKey: SplitIO.SplitKey, maybeFeatureFlagName: string, maybeAttributes?: SplitIO.Attributes | undefined) => string | SplitIO.AsyncTreatment;
8
+ getTreatmentWithConfig: (maybeKey: SplitIO.SplitKey, maybeFeatureFlagName: string, maybeAttributes?: SplitIO.Attributes | undefined) => SplitIO.TreatmentWithConfig | SplitIO.AsyncTreatmentWithConfig;
9
+ getTreatments: (maybeKey: SplitIO.SplitKey, maybeFeatureFlagNames: string[], maybeAttributes?: SplitIO.Attributes | undefined) => SplitIO.Treatments | SplitIO.AsyncTreatments;
10
+ getTreatmentsWithConfig: (maybeKey: SplitIO.SplitKey, maybeFeatureFlagNames: string[], maybeAttributes?: SplitIO.Attributes | undefined) => SplitIO.TreatmentsWithConfig | SplitIO.AsyncTreatmentsWithConfig;
11
11
  track: (maybeKey: SplitIO.SplitKey, maybeTT: string, maybeEvent: string, maybeEventValue?: number | undefined, maybeProperties?: SplitIO.Properties | undefined) => boolean | Promise<boolean>;
12
12
  /**
13
13
  * Add an attribute to client's in memory attributes storage
@@ -16,14 +16,14 @@ export declare function clientAttributesDecoration<TClient extends SplitIO.IClie
16
16
  * @param {string, number, boolean, list} attributeValue Attribute value
17
17
  * @returns {boolean} true if the attribute was stored and false otherways
18
18
  */
19
- setAttribute(attributeName: string, attributeValue: Object): boolean;
19
+ setAttribute(attributeName: string, attributeValue: SplitIO.AttributeType): boolean;
20
20
  /**
21
21
  * Returns the attribute with the given key
22
22
  *
23
23
  * @param {string} attributeName Attribute name
24
24
  * @returns {Object} Attribute with the given key
25
25
  */
26
- getAttribute(attributeName: string): Object;
26
+ getAttribute(attributeName: string): SplitIO.AttributeType;
27
27
  /**
28
28
  * Add to client's in memory attributes storage the attributes in 'attributes'
29
29
  *
@@ -36,7 +36,7 @@ export declare function clientAttributesDecoration<TClient extends SplitIO.IClie
36
36
  *
37
37
  * @returns {Object} returns all the stored attributes
38
38
  */
39
- getAttributes(): Record<string, Object>;
39
+ getAttributes(): Record<string, SplitIO.AttributeType>;
40
40
  /**
41
41
  * Removes from client's in memory attributes storage the attribute with the given key
42
42
  *
@@ -1,3 +1,4 @@
1
+ import { SplitIO } from '../../types';
1
2
  export declare class AttributesCacheInMemory {
2
3
  private attributesCache;
3
4
  /**
@@ -7,14 +8,14 @@ export declare class AttributesCacheInMemory {
7
8
  * @param {Object} attributeValue attribute value
8
9
  * @returns {boolean} the attribute was stored
9
10
  */
10
- setAttribute(attributeName: string, attributeValue: Object): boolean;
11
+ setAttribute(attributeName: string, attributeValue: SplitIO.AttributeType): boolean;
11
12
  /**
12
13
  * Retrieves the value of a given attribute
13
14
  *
14
15
  * @param {string} attributeName attribute name
15
16
  * @returns {Object?} stored attribute value
16
17
  */
17
- getAttribute(attributeName: string): Object;
18
+ getAttribute(attributeName: string): SplitIO.AttributeType;
18
19
  /**
19
20
  * Create or update all the given attributes
20
21
  *
@@ -27,7 +28,7 @@ export declare class AttributesCacheInMemory {
27
28
  *
28
29
  * @returns {Map<string, Object>} stored attributes
29
30
  */
30
- getAll(): Record<string, Object>;
31
+ getAll(): Record<string, SplitIO.AttributeType>;
31
32
  /**
32
33
  * Removes a given attribute from the map
33
34
  *