@splitsoftware/splitio-commons 1.17.0-rc.2 → 1.17.0-rc.4

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,5 +1,6 @@
1
- 1.17.0 (August XXX, 2024)
1
+ 1.17.0 (September 6, 2024)
2
2
  - Added `sync.requestOptions.getHeaderOverrides` configuration option to enhance SDK HTTP request Headers for Authorization Frameworks.
3
+ - Added `isTimedout` and `lastUpdate` properties to IStatusInterface to keep track of the timestamp of the last SDK event, used on React and Redux SDKs.
3
4
  - Updated some transitive dependencies for vulnerability fixes.
4
5
 
5
6
  1.16.0 (June 13, 2024)
@@ -31,6 +31,12 @@ function readinessManagerFactory(EventEmitter, readyTimeout, splits) {
31
31
  if (splits === void 0) { splits = splitsEventEmitterFactory(EventEmitter); }
32
32
  var segments = segmentsEventEmitterFactory(EventEmitter);
33
33
  var gate = new EventEmitter();
34
+ var lastUpdate = 0;
35
+ function syncLastUpdate() {
36
+ var dateNow = Date.now();
37
+ // ensure lastUpdate is always increasing per event, is case Date.now() is mocked or its value is the same
38
+ lastUpdate = dateNow > lastUpdate ? dateNow : lastUpdate + 1;
39
+ }
34
40
  // emit SDK_READY_FROM_CACHE
35
41
  var isReadyFromCache = false;
36
42
  if (splits.splitsCacheLoaded)
@@ -43,6 +49,7 @@ function readinessManagerFactory(EventEmitter, readyTimeout, splits) {
43
49
  if (hasTimedout)
44
50
  return;
45
51
  hasTimedout = true;
52
+ syncLastUpdate();
46
53
  gate.emit(constants_1.SDK_READY_TIMED_OUT, 'Split SDK emitted SDK_READY_TIMED_OUT event.');
47
54
  }
48
55
  var readyTimeoutId;
@@ -59,6 +66,7 @@ function readinessManagerFactory(EventEmitter, readyTimeout, splits) {
59
66
  // Don't emit SDK_READY_FROM_CACHE if SDK_READY has been emitted
60
67
  if (!isReady) {
61
68
  try {
69
+ syncLastUpdate();
62
70
  gate.emit(constants_1.SDK_READY_FROM_CACHE);
63
71
  }
64
72
  catch (e) {
@@ -70,6 +78,7 @@ function readinessManagerFactory(EventEmitter, readyTimeout, splits) {
70
78
  function checkIsReadyOrUpdate(diff) {
71
79
  if (isReady) {
72
80
  try {
81
+ syncLastUpdate();
73
82
  gate.emit(constants_1.SDK_UPDATE, diff);
74
83
  }
75
84
  catch (e) {
@@ -82,6 +91,7 @@ function readinessManagerFactory(EventEmitter, readyTimeout, splits) {
82
91
  clearTimeout(readyTimeoutId);
83
92
  isReady = true;
84
93
  try {
94
+ syncLastUpdate();
85
95
  gate.emit(constants_1.SDK_READY);
86
96
  }
87
97
  catch (e) {
@@ -109,6 +119,7 @@ function readinessManagerFactory(EventEmitter, readyTimeout, splits) {
109
119
  setDestroyed: function () { isDestroyed = true; },
110
120
  destroy: function () {
111
121
  isDestroyed = true;
122
+ syncLastUpdate();
112
123
  segments.removeAllListeners();
113
124
  gate.removeAllListeners();
114
125
  clearTimeout(readyTimeoutId);
@@ -118,10 +129,12 @@ function readinessManagerFactory(EventEmitter, readyTimeout, splits) {
118
129
  splits.removeAllListeners();
119
130
  },
120
131
  isReady: function () { return isReady; },
121
- hasTimedout: function () { return hasTimedout; },
122
132
  isReadyFromCache: function () { return isReadyFromCache; },
133
+ isTimedout: function () { return hasTimedout && !isReady; },
134
+ hasTimedout: function () { return hasTimedout; },
123
135
  isDestroyed: function () { return isDestroyed; },
124
- isOperational: function () { return (isReady || isReadyFromCache) && !isDestroyed; }
136
+ isOperational: function () { return (isReady || isReadyFromCache) && !isDestroyed; },
137
+ lastUpdate: function () { return lastUpdate; }
125
138
  };
126
139
  }
127
140
  exports.readinessManagerFactory = readinessManagerFactory;
@@ -107,14 +107,15 @@ function sdkReadinessManagerFactory(log, EventEmitter, readyTimeout, readinessMa
107
107
  }
108
108
  return readyPromise;
109
109
  },
110
- // Expose status for internal purposes only. Not considered part of the public API, and might be updated eventually.
111
110
  __getStatus: function () {
112
111
  return {
113
112
  isReady: readinessManager.isReady(),
114
113
  isReadyFromCache: readinessManager.isReadyFromCache(),
115
- isOperational: readinessManager.isOperational(),
114
+ isTimedout: readinessManager.isTimedout(),
116
115
  hasTimedout: readinessManager.hasTimedout(),
117
116
  isDestroyed: readinessManager.isDestroyed(),
117
+ isOperational: readinessManager.isOperational(),
118
+ lastUpdate: readinessManager.lastUpdate(),
118
119
  };
119
120
  },
120
121
  })
@@ -28,6 +28,12 @@ export function readinessManagerFactory(EventEmitter, readyTimeout, splits) {
28
28
  if (splits === void 0) { splits = splitsEventEmitterFactory(EventEmitter); }
29
29
  var segments = segmentsEventEmitterFactory(EventEmitter);
30
30
  var gate = new EventEmitter();
31
+ var lastUpdate = 0;
32
+ function syncLastUpdate() {
33
+ var dateNow = Date.now();
34
+ // ensure lastUpdate is always increasing per event, is case Date.now() is mocked or its value is the same
35
+ lastUpdate = dateNow > lastUpdate ? dateNow : lastUpdate + 1;
36
+ }
31
37
  // emit SDK_READY_FROM_CACHE
32
38
  var isReadyFromCache = false;
33
39
  if (splits.splitsCacheLoaded)
@@ -40,6 +46,7 @@ export function readinessManagerFactory(EventEmitter, readyTimeout, splits) {
40
46
  if (hasTimedout)
41
47
  return;
42
48
  hasTimedout = true;
49
+ syncLastUpdate();
43
50
  gate.emit(SDK_READY_TIMED_OUT, 'Split SDK emitted SDK_READY_TIMED_OUT event.');
44
51
  }
45
52
  var readyTimeoutId;
@@ -56,6 +63,7 @@ export function readinessManagerFactory(EventEmitter, readyTimeout, splits) {
56
63
  // Don't emit SDK_READY_FROM_CACHE if SDK_READY has been emitted
57
64
  if (!isReady) {
58
65
  try {
66
+ syncLastUpdate();
59
67
  gate.emit(SDK_READY_FROM_CACHE);
60
68
  }
61
69
  catch (e) {
@@ -67,6 +75,7 @@ export function readinessManagerFactory(EventEmitter, readyTimeout, splits) {
67
75
  function checkIsReadyOrUpdate(diff) {
68
76
  if (isReady) {
69
77
  try {
78
+ syncLastUpdate();
70
79
  gate.emit(SDK_UPDATE, diff);
71
80
  }
72
81
  catch (e) {
@@ -79,6 +88,7 @@ export function readinessManagerFactory(EventEmitter, readyTimeout, splits) {
79
88
  clearTimeout(readyTimeoutId);
80
89
  isReady = true;
81
90
  try {
91
+ syncLastUpdate();
82
92
  gate.emit(SDK_READY);
83
93
  }
84
94
  catch (e) {
@@ -106,6 +116,7 @@ export function readinessManagerFactory(EventEmitter, readyTimeout, splits) {
106
116
  setDestroyed: function () { isDestroyed = true; },
107
117
  destroy: function () {
108
118
  isDestroyed = true;
119
+ syncLastUpdate();
109
120
  segments.removeAllListeners();
110
121
  gate.removeAllListeners();
111
122
  clearTimeout(readyTimeoutId);
@@ -115,9 +126,11 @@ export function readinessManagerFactory(EventEmitter, readyTimeout, splits) {
115
126
  splits.removeAllListeners();
116
127
  },
117
128
  isReady: function () { return isReady; },
118
- hasTimedout: function () { return hasTimedout; },
119
129
  isReadyFromCache: function () { return isReadyFromCache; },
130
+ isTimedout: function () { return hasTimedout && !isReady; },
131
+ hasTimedout: function () { return hasTimedout; },
120
132
  isDestroyed: function () { return isDestroyed; },
121
- isOperational: function () { return (isReady || isReadyFromCache) && !isDestroyed; }
133
+ isOperational: function () { return (isReady || isReadyFromCache) && !isDestroyed; },
134
+ lastUpdate: function () { return lastUpdate; }
122
135
  };
123
136
  }
@@ -104,14 +104,15 @@ export function sdkReadinessManagerFactory(log, EventEmitter, readyTimeout, read
104
104
  }
105
105
  return readyPromise;
106
106
  },
107
- // Expose status for internal purposes only. Not considered part of the public API, and might be updated eventually.
108
107
  __getStatus: function () {
109
108
  return {
110
109
  isReady: readinessManager.isReady(),
111
110
  isReadyFromCache: readinessManager.isReadyFromCache(),
112
- isOperational: readinessManager.isOperational(),
111
+ isTimedout: readinessManager.isTimedout(),
113
112
  hasTimedout: readinessManager.hasTimedout(),
114
113
  isDestroyed: readinessManager.isDestroyed(),
114
+ isOperational: readinessManager.isOperational(),
115
+ lastUpdate: readinessManager.lastUpdate(),
115
116
  };
116
117
  },
117
118
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@splitsoftware/splitio-commons",
3
- "version": "1.17.0-rc.2",
3
+ "version": "1.17.0-rc.4",
4
4
  "description": "Split JavaScript SDK common components",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",
@@ -39,6 +39,13 @@ export function readinessManagerFactory(
39
39
  const segments: ISegmentsEventEmitter = segmentsEventEmitterFactory(EventEmitter);
40
40
  const gate: IReadinessEventEmitter = new EventEmitter();
41
41
 
42
+ let lastUpdate = 0;
43
+ function syncLastUpdate() {
44
+ const dateNow = Date.now();
45
+ // ensure lastUpdate is always increasing per event, is case Date.now() is mocked or its value is the same
46
+ lastUpdate = dateNow > lastUpdate ? dateNow : lastUpdate + 1;
47
+ }
48
+
42
49
  // emit SDK_READY_FROM_CACHE
43
50
  let isReadyFromCache = false;
44
51
  if (splits.splitsCacheLoaded) isReadyFromCache = true; // ready from cache, but doesn't emit SDK_READY_FROM_CACHE
@@ -50,6 +57,7 @@ export function readinessManagerFactory(
50
57
  function timeout() {
51
58
  if (hasTimedout) return;
52
59
  hasTimedout = true;
60
+ syncLastUpdate();
53
61
  gate.emit(SDK_READY_TIMED_OUT, 'Split SDK emitted SDK_READY_TIMED_OUT event.');
54
62
  }
55
63
 
@@ -70,6 +78,7 @@ export function readinessManagerFactory(
70
78
  // Don't emit SDK_READY_FROM_CACHE if SDK_READY has been emitted
71
79
  if (!isReady) {
72
80
  try {
81
+ syncLastUpdate();
73
82
  gate.emit(SDK_READY_FROM_CACHE);
74
83
  } catch (e) {
75
84
  // throws user callback exceptions in next tick
@@ -81,6 +90,7 @@ export function readinessManagerFactory(
81
90
  function checkIsReadyOrUpdate(diff: any) {
82
91
  if (isReady) {
83
92
  try {
93
+ syncLastUpdate();
84
94
  gate.emit(SDK_UPDATE, diff);
85
95
  } catch (e) {
86
96
  // throws user callback exceptions in next tick
@@ -91,6 +101,7 @@ export function readinessManagerFactory(
91
101
  clearTimeout(readyTimeoutId);
92
102
  isReady = true;
93
103
  try {
104
+ syncLastUpdate();
94
105
  gate.emit(SDK_READY);
95
106
  } catch (e) {
96
107
  // throws user callback exceptions in next tick
@@ -121,6 +132,7 @@ export function readinessManagerFactory(
121
132
 
122
133
  destroy() {
123
134
  isDestroyed = true;
135
+ syncLastUpdate();
124
136
 
125
137
  segments.removeAllListeners();
126
138
  gate.removeAllListeners();
@@ -131,10 +143,12 @@ export function readinessManagerFactory(
131
143
  },
132
144
 
133
145
  isReady() { return isReady; },
134
- hasTimedout() { return hasTimedout; },
135
146
  isReadyFromCache() { return isReadyFromCache; },
147
+ isTimedout() { return hasTimedout && !isReady; },
148
+ hasTimedout() { return hasTimedout; },
136
149
  isDestroyed() { return isDestroyed; },
137
- isOperational() { return (isReady || isReadyFromCache) && !isDestroyed; }
150
+ isOperational() { return (isReady || isReadyFromCache) && !isDestroyed; },
151
+ lastUpdate() { return lastUpdate; }
138
152
  };
139
153
 
140
154
  }
@@ -121,14 +121,15 @@ export function sdkReadinessManagerFactory(
121
121
  return readyPromise;
122
122
  },
123
123
 
124
- // Expose status for internal purposes only. Not considered part of the public API, and might be updated eventually.
125
124
  __getStatus() {
126
125
  return {
127
126
  isReady: readinessManager.isReady(),
128
127
  isReadyFromCache: readinessManager.isReadyFromCache(),
129
- isOperational: readinessManager.isOperational(),
128
+ isTimedout: readinessManager.isTimedout(),
130
129
  hasTimedout: readinessManager.hasTimedout(),
131
130
  isDestroyed: readinessManager.isDestroyed(),
131
+ isOperational: readinessManager.isOperational(),
132
+ lastUpdate: readinessManager.lastUpdate(),
132
133
  };
133
134
  },
134
135
  }
@@ -50,9 +50,11 @@ export interface IReadinessManager {
50
50
  /** Readiness status */
51
51
  isReady(): boolean,
52
52
  isReadyFromCache(): boolean,
53
+ isTimedout(): boolean,
53
54
  hasTimedout(): boolean,
54
55
  isDestroyed(): boolean,
55
56
  isOperational(): boolean,
57
+ lastUpdate(): number,
56
58
 
57
59
  timeout(): void,
58
60
  setDestroyed(): void,
package/src/types.ts CHANGED
@@ -409,6 +409,17 @@ export interface IStatusInterface extends IEventEmitter {
409
409
  * @returns {Promise<void>}
410
410
  */
411
411
  ready(): Promise<void>
412
+
413
+ // Expose status for internal purposes only. Not considered part of the public API, and might be updated eventually.
414
+ __getStatus(): {
415
+ isReady: boolean;
416
+ isReadyFromCache: boolean;
417
+ isTimedout: boolean;
418
+ hasTimedout: boolean;
419
+ isDestroyed: boolean;
420
+ isOperational: boolean;
421
+ lastUpdate: number;
422
+ }
412
423
  }
413
424
  /**
414
425
  * Common definitions between clients for different environments interface.
@@ -38,9 +38,11 @@ export interface IReadinessManager {
38
38
  /** Readiness status */
39
39
  isReady(): boolean;
40
40
  isReadyFromCache(): boolean;
41
+ isTimedout(): boolean;
41
42
  hasTimedout(): boolean;
42
43
  isDestroyed(): boolean;
43
44
  isOperational(): boolean;
45
+ lastUpdate(): number;
44
46
  timeout(): void;
45
47
  setDestroyed(): void;
46
48
  destroy(): void;
@@ -0,0 +1,9 @@
1
+ import { IPushManager } from './types';
2
+ import { IPollingManager } from '../polling/types';
3
+ import { ISdkFactoryContextSync } from '../../sdkFactory/types';
4
+ /**
5
+ * PushManager factory:
6
+ * - for server-side if key is not provided in settings.
7
+ * - for client-side, with support for multiple clients, if key is provided in settings
8
+ */
9
+ export declare function pushManagerFactory(params: ISdkFactoryContextSync, pollingManager: IPollingManager): IPushManager | undefined;
@@ -0,0 +1,9 @@
1
+ import { IPushManager } from './types';
2
+ import { IPollingManager } from '../polling/types';
3
+ import { ISdkFactoryContextSync } from '../../sdkFactory/types';
4
+ /**
5
+ * PushManager factory:
6
+ * - for server-side if key is not provided in settings.
7
+ * - for client-side, with support for multiple clients, if key is provided in settings
8
+ */
9
+ export declare function pushManagerFactory(params: ISdkFactoryContextSync, pollingManager: IPollingManager): IPushManager | undefined;
package/types/types.d.ts CHANGED
@@ -407,6 +407,15 @@ export interface IStatusInterface extends IEventEmitter {
407
407
  * @returns {Promise<void>}
408
408
  */
409
409
  ready(): Promise<void>;
410
+ __getStatus(): {
411
+ isReady: boolean;
412
+ isReadyFromCache: boolean;
413
+ isTimedout: boolean;
414
+ hasTimedout: boolean;
415
+ isDestroyed: boolean;
416
+ isOperational: boolean;
417
+ lastUpdate: number;
418
+ };
410
419
  }
411
420
  /**
412
421
  * Common definitions between clients for different environments interface.