@splitsoftware/splitio-commons 1.9.2 → 1.10.0

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 CHANGED
@@ -1,3 +1,7 @@
1
+ 1.10.0 (October 20, 2023)
2
+ - Added `defaultTreatment` property to the `SplitView` object returned by the `split` and `splits` methods of the SDK manager (Related to issue https://github.com/splitio/javascript-commons/issues/225).
3
+ - Updated log warning message to include the feature flag name when `getTreatment` method is called and the SDK client is not ready.
4
+
1
5
  1.9.2 (October 19, 2023)
2
6
  - Updated client module to support the Split Suite.
3
7
  - Updated some transitive dependencies for vulnerability fixes.
@@ -17,7 +17,7 @@ exports.codesWarn = error_1.codesError.concat([
17
17
  [c.SUBMITTERS_PUSH_FAILS, c.LOG_PREFIX_SYNC_SUBMITTERS + 'Dropping %s after retry. Reason: %s.'],
18
18
  [c.SUBMITTERS_PUSH_RETRY, c.LOG_PREFIX_SYNC_SUBMITTERS + 'Failed to push %s, keeping data to retry on next iteration. Reason: %s.'],
19
19
  // client status
20
- [c.CLIENT_NOT_READY, '%s: the SDK is not ready, results may be incorrect. Make sure to wait for SDK readiness before using this method.'],
20
+ [c.CLIENT_NOT_READY, '%s: the SDK is not ready, results may be incorrect%s. Make sure to wait for SDK readiness before using this method.'],
21
21
  [c.CLIENT_NO_LISTENER, 'No listeners for SDK Readiness detected. Incorrect control treatments could have been logged if you called getTreatment/s while the SDK was not yet ready.'],
22
22
  // input validation
23
23
  [c.WARN_SETTING_NULL, '%s: Property "%s" is of invalid type. Setting value to null.'],
@@ -22,7 +22,7 @@ function clientInputValidationDecorator(settings, client, readinessManager) {
22
22
  var splitOrSplits = multi ? (0, inputValidation_1.validateSplits)(log, maybeFeatureFlagNameOrNames, methodName) : (0, inputValidation_1.validateSplit)(log, maybeFeatureFlagNameOrNames, methodName);
23
23
  var attributes = (0, inputValidation_1.validateAttributes)(log, maybeAttributes, methodName);
24
24
  var isNotDestroyed = (0, inputValidation_1.validateIfNotDestroyed)(log, readinessManager, methodName);
25
- (0, inputValidation_1.validateIfOperational)(log, readinessManager, methodName);
25
+ (0, inputValidation_1.validateIfOperational)(log, readinessManager, methodName, splitOrSplits);
26
26
  var valid = isNotDestroyed && key && splitOrSplits && attributes !== false;
27
27
  return {
28
28
  valid: valid,
@@ -27,7 +27,8 @@ function objectToView(splitObject) {
27
27
  killed: splitObject.killed,
28
28
  changeNumber: splitObject.changeNumber || 0,
29
29
  treatments: collectTreatments(splitObject),
30
- configs: splitObject.configurations || {}
30
+ configs: splitObject.configurations || {},
31
+ defaultTreatment: splitObject.defaultTreatment
31
32
  };
32
33
  }
33
34
  function objectsToViews(splitObjects) {
@@ -9,10 +9,10 @@ function validateIfNotDestroyed(log, readinessManager, method) {
9
9
  return false;
10
10
  }
11
11
  exports.validateIfNotDestroyed = validateIfNotDestroyed;
12
- function validateIfOperational(log, readinessManager, method) {
12
+ function validateIfOperational(log, readinessManager, method, featureFlagNameOrNames) {
13
13
  if (readinessManager.isReady() || readinessManager.isReadyFromCache())
14
14
  return true;
15
- log.warn(constants_1.CLIENT_NOT_READY, [method]);
15
+ log.warn(constants_1.CLIENT_NOT_READY, [method, featureFlagNameOrNames ? " for feature flag " + featureFlagNameOrNames.toString() : '']);
16
16
  return false;
17
17
  }
18
18
  exports.validateIfOperational = validateIfOperational;
@@ -13,7 +13,7 @@ export var codesWarn = codesError.concat([
13
13
  [c.SUBMITTERS_PUSH_FAILS, c.LOG_PREFIX_SYNC_SUBMITTERS + 'Dropping %s after retry. Reason: %s.'],
14
14
  [c.SUBMITTERS_PUSH_RETRY, c.LOG_PREFIX_SYNC_SUBMITTERS + 'Failed to push %s, keeping data to retry on next iteration. Reason: %s.'],
15
15
  // client status
16
- [c.CLIENT_NOT_READY, '%s: the SDK is not ready, results may be incorrect. Make sure to wait for SDK readiness before using this method.'],
16
+ [c.CLIENT_NOT_READY, '%s: the SDK is not ready, results may be incorrect%s. Make sure to wait for SDK readiness before using this method.'],
17
17
  [c.CLIENT_NO_LISTENER, 'No listeners for SDK Readiness detected. Incorrect control treatments could have been logged if you called getTreatment/s while the SDK was not yet ready.'],
18
18
  // input validation
19
19
  [c.WARN_SETTING_NULL, '%s: Property "%s" is of invalid type. Setting value to null.'],
@@ -19,7 +19,7 @@ export function clientInputValidationDecorator(settings, client, readinessManage
19
19
  var splitOrSplits = multi ? validateSplits(log, maybeFeatureFlagNameOrNames, methodName) : validateSplit(log, maybeFeatureFlagNameOrNames, methodName);
20
20
  var attributes = validateAttributes(log, maybeAttributes, methodName);
21
21
  var isNotDestroyed = validateIfNotDestroyed(log, readinessManager, methodName);
22
- validateIfOperational(log, readinessManager, methodName);
22
+ validateIfOperational(log, readinessManager, methodName, splitOrSplits);
23
23
  var valid = isNotDestroyed && key && splitOrSplits && attributes !== false;
24
24
  return {
25
25
  valid: valid,
@@ -24,7 +24,8 @@ function objectToView(splitObject) {
24
24
  killed: splitObject.killed,
25
25
  changeNumber: splitObject.changeNumber || 0,
26
26
  treatments: collectTreatments(splitObject),
27
- configs: splitObject.configurations || {}
27
+ configs: splitObject.configurations || {},
28
+ defaultTreatment: splitObject.defaultTreatment
28
29
  };
29
30
  }
30
31
  function objectsToViews(splitObjects) {
@@ -5,9 +5,9 @@ export function validateIfNotDestroyed(log, readinessManager, method) {
5
5
  log.error(ERROR_CLIENT_DESTROYED, [method]);
6
6
  return false;
7
7
  }
8
- export function validateIfOperational(log, readinessManager, method) {
8
+ export function validateIfOperational(log, readinessManager, method, featureFlagNameOrNames) {
9
9
  if (readinessManager.isReady() || readinessManager.isReadyFromCache())
10
10
  return true;
11
- log.warn(CLIENT_NOT_READY, [method]);
11
+ log.warn(CLIENT_NOT_READY, [method, featureFlagNameOrNames ? " for feature flag " + featureFlagNameOrNames.toString() : '']);
12
12
  return false;
13
13
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@splitsoftware/splitio-commons",
3
- "version": "1.9.2",
3
+ "version": "1.10.0",
4
4
  "description": "Split Javascript SDK common components",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",
@@ -22,7 +22,7 @@
22
22
  "build": "npm run build:cjs && npm run build:esm",
23
23
  "build:esm": "rimraf esm && tsc -m es2015 --outDir esm -d true --declarationDir types",
24
24
  "build:cjs": "rimraf cjs && tsc -m CommonJS --outDir cjs",
25
- "test": "jest",
25
+ "test": "jest --runInBand",
26
26
  "test:coverage": "jest --coverage",
27
27
  "all": "npm run check && npm run build && npm run test",
28
28
  "publish:rc": "npm run check && npm run test && npm run build && npm publish --tag rc",
@@ -14,7 +14,7 @@ export const codesWarn: [number, string][] = codesError.concat([
14
14
  [c.SUBMITTERS_PUSH_FAILS, c.LOG_PREFIX_SYNC_SUBMITTERS + 'Dropping %s after retry. Reason: %s.'],
15
15
  [c.SUBMITTERS_PUSH_RETRY, c.LOG_PREFIX_SYNC_SUBMITTERS + 'Failed to push %s, keeping data to retry on next iteration. Reason: %s.'],
16
16
  // client status
17
- [c.CLIENT_NOT_READY, '%s: the SDK is not ready, results may be incorrect. Make sure to wait for SDK readiness before using this method.'],
17
+ [c.CLIENT_NOT_READY, '%s: the SDK is not ready, results may be incorrect%s. Make sure to wait for SDK readiness before using this method.'],
18
18
  [c.CLIENT_NO_LISTENER, 'No listeners for SDK Readiness detected. Incorrect control treatments could have been logged if you called getTreatment/s while the SDK was not yet ready.'],
19
19
  // input validation
20
20
  [c.WARN_SETTING_NULL, '%s: Property "%s" is of invalid type. Setting value to null.'],
@@ -37,7 +37,7 @@ export function clientInputValidationDecorator<TClient extends SplitIO.IClient |
37
37
  const attributes = validateAttributes(log, maybeAttributes, methodName);
38
38
  const isNotDestroyed = validateIfNotDestroyed(log, readinessManager, methodName);
39
39
 
40
- validateIfOperational(log, readinessManager, methodName);
40
+ validateIfOperational(log, readinessManager, methodName, splitOrSplits);
41
41
 
42
42
  const valid = isNotDestroyed && key && splitOrSplits && attributes !== false;
43
43
 
@@ -31,7 +31,8 @@ function objectToView(splitObject: ISplit | null): SplitIO.SplitView | null {
31
31
  killed: splitObject.killed,
32
32
  changeNumber: splitObject.changeNumber || 0,
33
33
  treatments: collectTreatments(splitObject),
34
- configs: splitObject.configurations || {}
34
+ configs: splitObject.configurations || {},
35
+ defaultTreatment: splitObject.defaultTreatment
35
36
  };
36
37
  }
37
38
 
package/src/types.ts CHANGED
@@ -610,6 +610,11 @@ export namespace SplitIO {
610
610
  configs: {
611
611
  [treatmentName: string]: string
612
612
  }
613
+ /**
614
+ * The default treatment of the feature flag.
615
+ * @property {string} defaultTreatment
616
+ */
617
+ defaultTreatment: string,
613
618
  };
614
619
  /**
615
620
  * A promise that resolves to a feature flag view.
@@ -9,9 +9,9 @@ export function validateIfNotDestroyed(log: ILogger, readinessManager: IReadines
9
9
  return false;
10
10
  }
11
11
 
12
- export function validateIfOperational(log: ILogger, readinessManager: IReadinessManager, method: string) {
12
+ export function validateIfOperational(log: ILogger, readinessManager: IReadinessManager, method: string, featureFlagNameOrNames?: string | string[] | false) {
13
13
  if (readinessManager.isReady() || readinessManager.isReadyFromCache()) return true;
14
14
 
15
- log.warn(CLIENT_NOT_READY, [method]);
15
+ log.warn(CLIENT_NOT_READY, [method, featureFlagNameOrNames ? ` for feature flag ${featureFlagNameOrNames.toString()}` : '']);
16
16
  return false;
17
17
  }
package/types/types.d.ts CHANGED
@@ -601,6 +601,11 @@ export declare namespace SplitIO {
601
601
  configs: {
602
602
  [treatmentName: string]: string;
603
603
  };
604
+ /**
605
+ * The default treatment of the feature flag.
606
+ * @property {string} defaultTreatment
607
+ */
608
+ defaultTreatment: string;
604
609
  };
605
610
  /**
606
611
  * A promise that resolves to a feature flag view.
@@ -1,4 +1,4 @@
1
1
  import { ILogger } from '../../logger/types';
2
2
  import { IReadinessManager } from '../../readiness/types';
3
3
  export declare function validateIfNotDestroyed(log: ILogger, readinessManager: IReadinessManager, method: string): boolean;
4
- export declare function validateIfOperational(log: ILogger, readinessManager: IReadinessManager, method: string): boolean;
4
+ export declare function validateIfOperational(log: ILogger, readinessManager: IReadinessManager, method: string, featureFlagNameOrNames?: string | string[] | false): boolean;