@splitsoftware/splitio-commons 1.9.1-rc.0 → 1.9.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.
package/CHANGES.txt CHANGED
@@ -1,10 +1,13 @@
1
+ 1.9.1 (September 21, 2023)
2
+ - 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
+
1
4
  1.9.0 (July 18, 2023)
2
5
  - Updated streaming architecture implementation to apply feature flag updates from the notification received which is now enhanced, improving efficiency and reliability of the whole update system.
3
6
 
4
7
  1.8.3 (June 29, 2023)
5
8
  - Updated some transitive dependencies for vulnerability fixes.
6
9
  - Updated SDK_READY_TIMED_OUT event to be emitted immediately when a connection error occurs using pluggable storage (i.e., when the wrapper `connect` promise is rejected) in consumer and partial consumer modes.
7
- - Bugfix - The `destroy` method has been updated to immediately flag the SDK client as destroyed, to prevent unexpected behaviours when `getTreatment` and `track` methods are called synchronously after `destroy` method is called.
10
+ - Bugfixing - The `destroy` method has been updated to immediately flag the SDK client as destroyed, to prevent unexpected behaviours when `getTreatment` and `track` methods are called synchronously after `destroy` method is called.
8
11
 
9
12
  1.8.2 (May 15, 2023)
10
13
  - Updated terminology on the SDKs codebase to be more aligned with current standard without causing a breaking change. The core change is the term split for feature flag on things like logs and IntelliSense comments.
@@ -90,7 +93,7 @@
90
93
  - Integration with Auth service V2, connecting to the new channels and applying the received connection delay.
91
94
  - Implemented handling of the new MySegmentsV2 notification types (SegmentRemoval, KeyList, Bounded and Unbounded)
92
95
  - New control notification for environment scoped streaming reset.
93
- - Updated localhost mode to emit SDK_READY_FROM_CACHE event in Browser when using localStorage (Related to issue https://github.com/splitio/react-client/issues/34).
96
+ - Updated localhost mode to emit SDK_READY_FROM_CACHE event in browser when using localStorage (Related to issue https://github.com/splitio/react-client/issues/34).
94
97
  - Updated dependencies for vulnerability fixes.
95
98
 
96
99
  0.1.0 (March 30, 2021)
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GaToSplit = exports.fixEventTypeId = exports.validateEventData = exports.validateIdentities = exports.defaultPrefix = exports.defaultMapper = void 0;
4
- /* eslint-disable no-undef */
5
4
  var objectAssign_1 = require("../../utils/lang/objectAssign");
6
5
  var lang_1 = require("../../utils/lang");
7
6
  var inputValidation_1 = require("../../utils/inputValidation");
@@ -252,6 +251,7 @@ function GaToSplit(sdkOptions, params) {
252
251
  return SplitTracker;
253
252
  }());
254
253
  // Register the plugin, even if config is invalid, since, if not provided, it will block `ga` command queue.
254
+ // eslint-disable-next-line no-undef
255
255
  providePlugin(window, 'splitTracker', SplitTracker, log, sdkOptions.autoRequire === true, telemetryTracker);
256
256
  }
257
257
  exports.GaToSplit = GaToSplit;
@@ -9,8 +9,7 @@ var constants_2 = require("../logger/constants");
9
9
  var consent_1 = require("../consent");
10
10
  var VISIBILITYCHANGE_EVENT = 'visibilitychange';
11
11
  var PAGEHIDE_EVENT = 'pagehide';
12
- var UNLOAD_EVENT = 'unload';
13
- var EVENT_NAME = 'for unload page event.';
12
+ var EVENT_NAME = 'for visibilitychange and pagehide events.';
14
13
  /**
15
14
  * We'll listen for events over the window object.
16
15
  */
@@ -22,7 +21,6 @@ var BrowserSignalListener = /** @class */ (function () {
22
21
  this.serviceApi = serviceApi;
23
22
  this.flushData = this.flushData.bind(this);
24
23
  this.flushDataIfHidden = this.flushDataIfHidden.bind(this);
25
- this.stopSync = this.stopSync.bind(this);
26
24
  this.fromImpressionsCollector = impressionsSubmitter_1.fromImpressionsCollector.bind(undefined, settings.core.labelsEnabled);
27
25
  }
28
26
  /**
@@ -36,11 +34,9 @@ var BrowserSignalListener = /** @class */ (function () {
36
34
  document.addEventListener(VISIBILITYCHANGE_EVENT, this.flushDataIfHidden);
37
35
  }
38
36
  if (typeof window !== 'undefined' && window.addEventListener) {
39
- // Some browsers like Safari does not fire the `visibilitychange` event when the page is being unloaded. So we also flush data in the `pagehide` event.
40
- // If both events are triggered, the last one will find the storage empty, so no duplicated data will be submitted.
37
+ // Some browsers, like Safari, does not fire the `visibilitychange` event when the page is being unloaded. Therefore, we also flush data in the `pagehide` event.
38
+ // If both events are triggered, the latter will find the storage empty, so no duplicate data will be submitted.
41
39
  window.addEventListener(PAGEHIDE_EVENT, this.flushData);
42
- // Stop streaming on 'unload' event. Used instead of 'beforeunload', because 'unload' is not a cancelable event, so no other listeners can stop the event from occurring.
43
- window.addEventListener(UNLOAD_EVENT, this.stopSync);
44
40
  }
45
41
  };
46
42
  /**
@@ -54,14 +50,8 @@ var BrowserSignalListener = /** @class */ (function () {
54
50
  }
55
51
  if (typeof window !== 'undefined' && window.removeEventListener) {
56
52
  window.removeEventListener(PAGEHIDE_EVENT, this.flushData);
57
- window.removeEventListener(UNLOAD_EVENT, this.stopSync);
58
53
  }
59
54
  };
60
- BrowserSignalListener.prototype.stopSync = function () {
61
- // Close streaming connection
62
- if (this.syncManager && this.syncManager.pushManager)
63
- this.syncManager.pushManager.stop();
64
- };
65
55
  /**
66
56
  * flushData method.
67
57
  * Called when pagehide event is triggered. It flushed remaining impressions and events to the backend,
@@ -20,10 +20,7 @@ function clientCSDecorator(log, client, key, trafficType) {
20
20
  getTreatmentsWithConfig: clientCS.getTreatmentsWithConfig.bind(clientCS, key),
21
21
  // Key is bound to the `track` method. Same thing happens with trafficType but only if provided
22
22
  track: trafficType ? clientCS.track.bind(clientCS, key, trafficType) : clientCS.track.bind(clientCS, key),
23
- // Not part of the public API. These properties are used to support other modules (e.g., Split Suite)
24
- isClientSide: true,
25
- key: key,
26
- trafficType: trafficType
23
+ isClientSide: true
27
24
  });
28
25
  }
29
26
  exports.clientCSDecorator = clientCSDecorator;
@@ -10,6 +10,7 @@ function Uint8ArrayToString(myUint8Arr) {
10
10
  }
11
11
  function StringToUint8Array(myString) {
12
12
  var charCodes = myString.split('').map(function (e) { return e.charCodeAt(0); });
13
+ // eslint-disable-next-line compat/compat
13
14
  return new Uint8Array(charCodes);
14
15
  }
15
16
  /**
@@ -1,4 +1,3 @@
1
- /* eslint-disable no-undef */
2
1
  import { objectAssign } from '../../utils/lang/objectAssign';
3
2
  import { isString, isFiniteNumber, uniqAsStrings } from '../../utils/lang';
4
3
  import { validateEvent, validateEventValue, validateEventProperties, validateKey, validateTrafficType } from '../../utils/inputValidation';
@@ -246,5 +245,6 @@ export function GaToSplit(sdkOptions, params) {
246
245
  return SplitTracker;
247
246
  }());
248
247
  // Register the plugin, even if config is invalid, since, if not provided, it will block `ga` command queue.
248
+ // eslint-disable-next-line no-undef
249
249
  providePlugin(window, 'splitTracker', SplitTracker, log, sdkOptions.autoRequire === true, telemetryTracker);
250
250
  }
@@ -6,8 +6,7 @@ import { CLEANUP_REGISTERING, CLEANUP_DEREGISTERING } from '../logger/constants'
6
6
  import { isConsentGranted } from '../consent';
7
7
  var VISIBILITYCHANGE_EVENT = 'visibilitychange';
8
8
  var PAGEHIDE_EVENT = 'pagehide';
9
- var UNLOAD_EVENT = 'unload';
10
- var EVENT_NAME = 'for unload page event.';
9
+ var EVENT_NAME = 'for visibilitychange and pagehide events.';
11
10
  /**
12
11
  * We'll listen for events over the window object.
13
12
  */
@@ -19,7 +18,6 @@ var BrowserSignalListener = /** @class */ (function () {
19
18
  this.serviceApi = serviceApi;
20
19
  this.flushData = this.flushData.bind(this);
21
20
  this.flushDataIfHidden = this.flushDataIfHidden.bind(this);
22
- this.stopSync = this.stopSync.bind(this);
23
21
  this.fromImpressionsCollector = fromImpressionsCollector.bind(undefined, settings.core.labelsEnabled);
24
22
  }
25
23
  /**
@@ -33,11 +31,9 @@ var BrowserSignalListener = /** @class */ (function () {
33
31
  document.addEventListener(VISIBILITYCHANGE_EVENT, this.flushDataIfHidden);
34
32
  }
35
33
  if (typeof window !== 'undefined' && window.addEventListener) {
36
- // Some browsers like Safari does not fire the `visibilitychange` event when the page is being unloaded. So we also flush data in the `pagehide` event.
37
- // If both events are triggered, the last one will find the storage empty, so no duplicated data will be submitted.
34
+ // Some browsers, like Safari, does not fire the `visibilitychange` event when the page is being unloaded. Therefore, we also flush data in the `pagehide` event.
35
+ // If both events are triggered, the latter will find the storage empty, so no duplicate data will be submitted.
38
36
  window.addEventListener(PAGEHIDE_EVENT, this.flushData);
39
- // Stop streaming on 'unload' event. Used instead of 'beforeunload', because 'unload' is not a cancelable event, so no other listeners can stop the event from occurring.
40
- window.addEventListener(UNLOAD_EVENT, this.stopSync);
41
37
  }
42
38
  };
43
39
  /**
@@ -51,14 +47,8 @@ var BrowserSignalListener = /** @class */ (function () {
51
47
  }
52
48
  if (typeof window !== 'undefined' && window.removeEventListener) {
53
49
  window.removeEventListener(PAGEHIDE_EVENT, this.flushData);
54
- window.removeEventListener(UNLOAD_EVENT, this.stopSync);
55
50
  }
56
51
  };
57
- BrowserSignalListener.prototype.stopSync = function () {
58
- // Close streaming connection
59
- if (this.syncManager && this.syncManager.pushManager)
60
- this.syncManager.pushManager.stop();
61
- };
62
52
  /**
63
53
  * flushData method.
64
54
  * Called when pagehide event is triggered. It flushed remaining impressions and events to the backend,
@@ -17,9 +17,6 @@ export function clientCSDecorator(log, client, key, trafficType) {
17
17
  getTreatmentsWithConfig: clientCS.getTreatmentsWithConfig.bind(clientCS, key),
18
18
  // Key is bound to the `track` method. Same thing happens with trafficType but only if provided
19
19
  track: trafficType ? clientCS.track.bind(clientCS, key, trafficType) : clientCS.track.bind(clientCS, key),
20
- // Not part of the public API. These properties are used to support other modules (e.g., Split Suite)
21
- isClientSide: true,
22
- key: key,
23
- trafficType: trafficType
20
+ isClientSide: true
24
21
  });
25
22
  }
@@ -7,6 +7,7 @@ function Uint8ArrayToString(myUint8Arr) {
7
7
  }
8
8
  function StringToUint8Array(myString) {
9
9
  var charCodes = myString.split('').map(function (e) { return e.charCodeAt(0); });
10
+ // eslint-disable-next-line compat/compat
10
11
  return new Uint8Array(charCodes);
11
12
  }
12
13
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@splitsoftware/splitio-commons",
3
- "version": "1.9.1-rc.0",
3
+ "version": "1.9.1",
4
4
  "description": "Split Javascript SDK common components",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",
@@ -60,12 +60,12 @@
60
60
  "@types/ioredis": "^4.28.0",
61
61
  "@types/jest": "^27.0.0",
62
62
  "@types/lodash": "^4.14.162",
63
- "@typescript-eslint/eslint-plugin": "^4.2.0",
64
- "@typescript-eslint/parser": "^4.2.0",
63
+ "@typescript-eslint/eslint-plugin": "^6.6.0",
64
+ "@typescript-eslint/parser": "^6.6.0",
65
65
  "cross-env": "^7.0.2",
66
66
  "csv-streamify": "^4.0.0",
67
- "eslint": "^7.32.0",
68
- "eslint-plugin-compat": "3.7.0",
67
+ "eslint": "^8.48.0",
68
+ "eslint-plugin-compat": "^4.2.0",
69
69
  "eslint-plugin-import": "^2.25.3",
70
70
  "fetch-mock": "^9.11.0",
71
71
  "ioredis": "^4.28.0",
@@ -1,4 +1,3 @@
1
- /* eslint-disable no-undef */
2
1
  import { objectAssign } from '../../utils/lang/objectAssign';
3
2
  import { isString, isFiniteNumber, uniqAsStrings } from '../../utils/lang';
4
3
  import {
@@ -295,5 +294,6 @@ export function GaToSplit(sdkOptions: GoogleAnalyticsToSplitOptions, params: IIn
295
294
  }
296
295
 
297
296
  // Register the plugin, even if config is invalid, since, if not provided, it will block `ga` command queue.
297
+ // eslint-disable-next-line no-undef
298
298
  providePlugin(window, 'splitTracker', SplitTracker, log, sdkOptions.autoRequire === true, telemetryTracker);
299
299
  }
@@ -15,8 +15,7 @@ import { isConsentGranted } from '../consent';
15
15
 
16
16
  const VISIBILITYCHANGE_EVENT = 'visibilitychange';
17
17
  const PAGEHIDE_EVENT = 'pagehide';
18
- const UNLOAD_EVENT = 'unload';
19
- const EVENT_NAME = 'for unload page event.';
18
+ const EVENT_NAME = 'for visibilitychange and pagehide events.';
20
19
 
21
20
  /**
22
21
  * We'll listen for events over the window object.
@@ -33,7 +32,6 @@ export class BrowserSignalListener implements ISignalListener {
33
32
  ) {
34
33
  this.flushData = this.flushData.bind(this);
35
34
  this.flushDataIfHidden = this.flushDataIfHidden.bind(this);
36
- this.stopSync = this.stopSync.bind(this);
37
35
  this.fromImpressionsCollector = fromImpressionsCollector.bind(undefined, settings.core.labelsEnabled);
38
36
  }
39
37
 
@@ -48,11 +46,9 @@ export class BrowserSignalListener implements ISignalListener {
48
46
  document.addEventListener(VISIBILITYCHANGE_EVENT, this.flushDataIfHidden);
49
47
  }
50
48
  if (typeof window !== 'undefined' && window.addEventListener) {
51
- // Some browsers like Safari does not fire the `visibilitychange` event when the page is being unloaded. So we also flush data in the `pagehide` event.
52
- // If both events are triggered, the last one will find the storage empty, so no duplicated data will be submitted.
49
+ // Some browsers, like Safari, does not fire the `visibilitychange` event when the page is being unloaded. Therefore, we also flush data in the `pagehide` event.
50
+ // If both events are triggered, the latter will find the storage empty, so no duplicate data will be submitted.
53
51
  window.addEventListener(PAGEHIDE_EVENT, this.flushData);
54
- // Stop streaming on 'unload' event. Used instead of 'beforeunload', because 'unload' is not a cancelable event, so no other listeners can stop the event from occurring.
55
- window.addEventListener(UNLOAD_EVENT, this.stopSync);
56
52
  }
57
53
  }
58
54
 
@@ -67,15 +63,9 @@ export class BrowserSignalListener implements ISignalListener {
67
63
  }
68
64
  if (typeof window !== 'undefined' && window.removeEventListener) {
69
65
  window.removeEventListener(PAGEHIDE_EVENT, this.flushData);
70
- window.removeEventListener(UNLOAD_EVENT, this.stopSync);
71
66
  }
72
67
  }
73
68
 
74
- stopSync() {
75
- // Close streaming connection
76
- if (this.syncManager && this.syncManager.pushManager) this.syncManager.pushManager.stop();
77
- }
78
-
79
69
  /**
80
70
  * flushData method.
81
71
  * Called when pagehide event is triggered. It flushed remaining impressions and events to the backend,
@@ -25,9 +25,6 @@ export function clientCSDecorator(log: ILogger, client: SplitIO.IClient, key: Sp
25
25
  // Key is bound to the `track` method. Same thing happens with trafficType but only if provided
26
26
  track: trafficType ? clientCS.track.bind(clientCS, key, trafficType) : clientCS.track.bind(clientCS, key),
27
27
 
28
- // Not part of the public API. These properties are used to support other modules (e.g., Split Suite)
29
- isClientSide: true,
30
- key,
31
- trafficType
28
+ isClientSide: true
32
29
  }) as SplitIO.ICsClient;
33
30
  }
@@ -181,7 +181,7 @@ export class TelemetryCacheInMemory implements ITelemetryCacheSync {
181
181
  this.e = false;
182
182
  }
183
183
 
184
- private streamingEvents: StreamingEvent[] = []
184
+ private streamingEvents: StreamingEvent[] = [];
185
185
 
186
186
  popStreamingEvents() {
187
187
  return this.streamingEvents.splice(0);
@@ -33,7 +33,7 @@ interface IRedisCommand {
33
33
  * Redis adapter on top of the library of choice (written with ioredis) for some extra control.
34
34
  */
35
35
  export class RedisAdapter extends ioredis {
36
- private readonly log: ILogger
36
+ private readonly log: ILogger;
37
37
  private _options: object;
38
38
  private _notReadyCommandsQueue?: IRedisCommand[];
39
39
  private _runningCommands: ISet<Promise<any>>;
@@ -11,6 +11,7 @@ function Uint8ArrayToString(myUint8Arr: Uint8Array) { // @ts-ignore
11
11
 
12
12
  function StringToUint8Array(myString: string) {
13
13
  const charCodes = myString.split('').map((e) => e.charCodeAt(0));
14
+ // eslint-disable-next-line compat/compat
14
15
  return new Uint8Array(charCodes);
15
16
  }
16
17
 
@@ -13,7 +13,7 @@ const PIPELINE_METHODS = ['rpush', 'hincrby'];
13
13
 
14
14
  export class RedisMock {
15
15
 
16
- private pipelineMethods: any = { exec: jest.fn(asyncFunction) }
16
+ private pipelineMethods: any = { exec: jest.fn(asyncFunction) };
17
17
 
18
18
  constructor() {
19
19
  IDENTITY_METHODS.forEach(method => {
@@ -23,7 +23,6 @@ export declare class BrowserSignalListener implements ISignalListener {
23
23
  * Called when client is destroyed, it removes event listeners.
24
24
  */
25
25
  stop(): void;
26
- stopSync(): void;
27
26
  /**
28
27
  * flushData method.
29
28
  * Called when pagehide event is triggered. It flushed remaining impressions and events to the backend,