@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
|
@@ -1,51 +1,52 @@
|
|
|
1
|
-
import { ERROR_NULL, ERROR_EMPTY, ERROR_INVALID,
|
|
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 = '
|
|
5
|
+
const item = 'sdk_key';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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(
|
|
13
|
-
if (
|
|
14
|
-
|
|
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
|
|
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
|
|
28
|
-
export function validateAndTrackApiKey(log: ILogger,
|
|
29
|
-
const
|
|
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
|
|
32
|
-
if (
|
|
33
|
-
if (!usedKeysMap[
|
|
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[
|
|
36
|
+
usedKeysMap[sdkKey] = 1;
|
|
36
37
|
if (Object.keys(usedKeysMap).length > 1) {
|
|
37
|
-
log.warn(
|
|
38
|
+
log.warn(WARN_SDK_KEY, ['an instance of the Split factory']);
|
|
38
39
|
}
|
|
39
40
|
} else {
|
|
40
|
-
log.warn(
|
|
41
|
-
usedKeysMap[
|
|
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
|
|
46
|
+
return sdkKey;
|
|
46
47
|
}
|
|
47
48
|
|
|
48
|
-
export function releaseApiKey(
|
|
49
|
-
if (usedKeysMap[
|
|
50
|
-
if (usedKeysMap[
|
|
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
|
|
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
|
|
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
|
|
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 = '
|
|
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 = '
|
|
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
|
|
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
|
|
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,
|
|
8
|
-
getTreatmentWithConfig: (maybeKey: SplitIO.SplitKey,
|
|
9
|
-
getTreatments: (maybeKey: SplitIO.SplitKey,
|
|
10
|
-
getTreatmentsWithConfig: (maybeKey: SplitIO.SplitKey,
|
|
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:
|
|
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):
|
|
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,
|
|
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:
|
|
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):
|
|
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,
|
|
31
|
+
getAll(): Record<string, SplitIO.AttributeType>;
|
|
31
32
|
/**
|
|
32
33
|
* Removes a given attribute from the map
|
|
33
34
|
*
|