@splitsoftware/splitio-commons 1.9.2-rc.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,11 @@
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
+
5
+ 1.9.2 (October 19, 2023)
6
+ - Updated client module to support the Split Suite.
7
+ - Updated some transitive dependencies for vulnerability fixes.
8
+
1
9
  1.9.1 (September 21, 2023)
2
10
  - Updated browser listener to avoid registering a handler for 'unload' DOM events, that can prevent browsers from being able to put pages in the back/forward cache for faster back and forward loads (Related to issue https://github.com/splitio/javascript-client/issues/759).
3
11
 
@@ -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,
@@ -14,8 +14,8 @@ function buildInstanceId(key) {
14
14
  }
15
15
  var method = 'Client instantiation';
16
16
  /**
17
- * Factory of client method for the client-side API variant where TT is ignored and thus
18
- * clients don't have a binded TT for the track method.
17
+ * Factory of client method for the client-side API variant where TT is ignored.
18
+ * Therefore, clients don't have a bound TT for the track method.
19
19
  */
20
20
  function sdkClientMethodCSFactory(params) {
21
21
  var storage = params.storage, syncManager = params.syncManager, sdkReadinessManager = params.sdkReadinessManager, _a = params.settings, key = _a.core.key, readyTimeout = _a.startup.readyTimeout, log = _a.log;
@@ -16,7 +16,7 @@ function buildInstanceId(key, trafficType) {
16
16
  var method = 'Client instantiation';
17
17
  /**
18
18
  * Factory of client method for the client-side (browser) variant of the Isomorphic JS SDK,
19
- * where clients can have a binded TT for the track method, which is provided via the settings
19
+ * where clients can have a bound TT for the track method, which is provided via the settings
20
20
  * (default client) or the client method (shared clients).
21
21
  */
22
22
  function sdkClientMethodCSFactory(params) {
@@ -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;
@@ -140,7 +140,7 @@ function settingsValidation(config, validationParams) {
140
140
  }
141
141
  else {
142
142
  // Keeping same behaviour than JS SDK: if settings key or TT are invalid,
143
- // `false` value is used as binded key/TT of the default client, which leads to some issues.
143
+ // `false` value is used as bound key/TT of the default client, which leads to some issues.
144
144
  // @ts-ignore, @TODO handle invalid keys as a non-recoverable error?
145
145
  withDefaults.core.key = (0, key_1.validateKey)(log, maybeKey, 'Client instantiation');
146
146
  }
@@ -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,
@@ -11,8 +11,8 @@ function buildInstanceId(key) {
11
11
  }
12
12
  var method = 'Client instantiation';
13
13
  /**
14
- * Factory of client method for the client-side API variant where TT is ignored and thus
15
- * clients don't have a binded TT for the track method.
14
+ * Factory of client method for the client-side API variant where TT is ignored.
15
+ * Therefore, clients don't have a bound TT for the track method.
16
16
  */
17
17
  export function sdkClientMethodCSFactory(params) {
18
18
  var storage = params.storage, syncManager = params.syncManager, sdkReadinessManager = params.sdkReadinessManager, _a = params.settings, key = _a.core.key, readyTimeout = _a.startup.readyTimeout, log = _a.log;
@@ -13,7 +13,7 @@ function buildInstanceId(key, trafficType) {
13
13
  var method = 'Client instantiation';
14
14
  /**
15
15
  * Factory of client method for the client-side (browser) variant of the Isomorphic JS SDK,
16
- * where clients can have a binded TT for the track method, which is provided via the settings
16
+ * where clients can have a bound TT for the track method, which is provided via the settings
17
17
  * (default client) or the client method (shared clients).
18
18
  */
19
19
  export function sdkClientMethodCSFactory(params) {
@@ -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
  }
@@ -137,7 +137,7 @@ export function settingsValidation(config, validationParams) {
137
137
  }
138
138
  else {
139
139
  // Keeping same behaviour than JS SDK: if settings key or TT are invalid,
140
- // `false` value is used as binded key/TT of the default client, which leads to some issues.
140
+ // `false` value is used as bound key/TT of the default client, which leads to some issues.
141
141
  // @ts-ignore, @TODO handle invalid keys as a non-recoverable error?
142
142
  withDefaults.core.key = validateKey(log, maybeKey, 'Client instantiation');
143
143
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@splitsoftware/splitio-commons",
3
- "version": "1.9.2-rc.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
 
@@ -17,8 +17,8 @@ function buildInstanceId(key: SplitIO.SplitKey) {
17
17
  const method = 'Client instantiation';
18
18
 
19
19
  /**
20
- * Factory of client method for the client-side API variant where TT is ignored and thus
21
- * clients don't have a binded TT for the track method.
20
+ * Factory of client method for the client-side API variant where TT is ignored.
21
+ * Therefore, clients don't have a bound TT for the track method.
22
22
  */
23
23
  export function sdkClientMethodCSFactory(params: ISdkFactoryContext): (key?: SplitIO.SplitKey) => SplitIO.ICsClient {
24
24
  const { storage, syncManager, sdkReadinessManager, settings: { core: { key }, startup: { readyTimeout }, log } } = params;
@@ -19,7 +19,7 @@ const method = 'Client instantiation';
19
19
 
20
20
  /**
21
21
  * Factory of client method for the client-side (browser) variant of the Isomorphic JS SDK,
22
- * where clients can have a binded TT for the track method, which is provided via the settings
22
+ * where clients can have a bound TT for the track method, which is provided via the settings
23
23
  * (default client) or the client method (shared clients).
24
24
  */
25
25
  export function sdkClientMethodCSFactory(params: ISdkFactoryContext): (key?: SplitIO.SplitKey, trafficType?: string) => SplitIO.ICsClient {
@@ -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
  }
@@ -160,7 +160,7 @@ export function settingsValidation(config: unknown, validationParams: ISettingsV
160
160
  withDefaults.core.key = 'localhost_key';
161
161
  } else {
162
162
  // Keeping same behaviour than JS SDK: if settings key or TT are invalid,
163
- // `false` value is used as binded key/TT of the default client, which leads to some issues.
163
+ // `false` value is used as bound key/TT of the default client, which leads to some issues.
164
164
  // @ts-ignore, @TODO handle invalid keys as a non-recoverable error?
165
165
  withDefaults.core.key = validateKey(log, maybeKey, 'Client instantiation');
166
166
  }
@@ -1,7 +1,7 @@
1
1
  import { SplitIO } from '../types';
2
2
  import { ISdkFactoryContext } from '../sdkFactory/types';
3
3
  /**
4
- * Factory of client method for the client-side API variant where TT is ignored and thus
5
- * clients don't have a binded TT for the track method.
4
+ * Factory of client method for the client-side API variant where TT is ignored.
5
+ * Therefore, clients don't have a bound TT for the track method.
6
6
  */
7
7
  export declare function sdkClientMethodCSFactory(params: ISdkFactoryContext): (key?: SplitIO.SplitKey) => SplitIO.ICsClient;
@@ -2,7 +2,7 @@ import { SplitIO } from '../types';
2
2
  import { ISdkFactoryContext } from '../sdkFactory/types';
3
3
  /**
4
4
  * Factory of client method for the client-side (browser) variant of the Isomorphic JS SDK,
5
- * where clients can have a binded TT for the track method, which is provided via the settings
5
+ * where clients can have a bound TT for the track method, which is provided via the settings
6
6
  * (default client) or the client method (shared clients).
7
7
  */
8
8
  export declare function sdkClientMethodCSFactory(params: ISdkFactoryContext): (key?: SplitIO.SplitKey, trafficType?: string) => SplitIO.ICsClient;
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;