@splitsoftware/splitio-commons 2.0.0-rc.5 → 2.0.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,11 +1,11 @@
1
- 2.0.0 (October XX, 2024)
1
+ 2.0.0 (November 1, 2024)
2
2
  - Added support for targeting rules based on large segments.
3
3
  - Added `factory.destroy()` method, which invokes the `destroy` method on all SDK clients created by the factory.
4
- - Added `SplitIO` namespace with the public TypeScript definitions to be reused by the SDKs, rather than having each SDK define its own types.
4
+ - Added `SplitIO` namespace with the public TypeScript definitions to be reused by the SDKs.
5
5
  - Updated the handling of timers and async operations inside an `init` factory method to enable lazy initialization of the SDK in standalone mode. This update is intended for the React SDK.
6
6
  - Bugfixing - Fixed an issue with the server-side polling manager that caused dangling timers when the SDK was destroyed before it was ready.
7
7
  - BREAKING CHANGES:
8
- - Updated default flag spec version to 1.2.
8
+ - Updated default flag spec version to 1.2, which requires Split Proxy v5.9.0 or higher.
9
9
  - Removed `/mySegments` endpoint from SplitAPI module, as it is replaced by `/memberships` endpoint.
10
10
  - Removed support for MY_SEGMENTS_UPDATE and MY_SEGMENTS_UPDATE_V2 notification types, as they are replaced by MEMBERSHIPS_MS_UPDATE and MEMBERSHIPS_LS_UPDATE notification types.
11
11
  - Removed the deprecated `GOOGLE_ANALYTICS_TO_SPLIT` and `SPLIT_TO_GOOGLE_ANALYTICS` integrations.
@@ -7,7 +7,7 @@ function splitsEventEmitterFactory(EventEmitter) {
7
7
  var splitsEventEmitter = (0, objectAssign_1.objectAssign)(new EventEmitter(), {
8
8
  splitsArrived: false,
9
9
  splitsCacheLoaded: false,
10
- initialized: false,
10
+ hasInit: false,
11
11
  initCallbacks: []
12
12
  });
13
13
  // `isSplitKill` condition avoids an edge-case of wrongly emitting SDK_READY if:
@@ -56,7 +56,7 @@ function readinessManagerFactory(EventEmitter, settings, splits) {
56
56
  }
57
57
  var readyTimeoutId;
58
58
  if (readyTimeout > 0) {
59
- if (splits.initialized)
59
+ if (splits.hasInit)
60
60
  readyTimeoutId = setTimeout(timeout, readyTimeout);
61
61
  else
62
62
  splits.initCallbacks.push(function () { readyTimeoutId = setTimeout(timeout, readyTimeout); });
@@ -122,9 +122,9 @@ function readinessManagerFactory(EventEmitter, settings, splits) {
122
122
  // tracking and evaluations, while keeping event listeners to emit SDK_READY_TIMED_OUT event
123
123
  setDestroyed: function () { isDestroyed = true; },
124
124
  init: function () {
125
- if (splits.initialized)
125
+ if (splits.hasInit)
126
126
  return;
127
- splits.initialized = true;
127
+ splits.hasInit = true;
128
128
  splits.initCallbacks.forEach(function (cb) { return cb(); });
129
129
  },
130
130
  destroy: function () {
@@ -4,11 +4,6 @@ exports.UniqueKeysCacheInMemoryCS = void 0;
4
4
  var constants_1 = require("../inRedis/constants");
5
5
  var sets_1 = require("../../utils/lang/sets");
6
6
  var UniqueKeysCacheInMemoryCS = /** @class */ (function () {
7
- /**
8
- *
9
- * @param impressionsQueueSize - number of queued impressions to call onFullQueueCb.
10
- * Default value is 0, that means no maximum value, in case we want to avoid this being triggered.
11
- */
12
7
  function UniqueKeysCacheInMemoryCS(uniqueKeysQueueSize) {
13
8
  if (uniqueKeysQueueSize === void 0) { uniqueKeysQueueSize = constants_1.DEFAULT_CACHE_SIZE; }
14
9
  this.uniqueTrackerSize = 0;
@@ -4,7 +4,7 @@ function splitsEventEmitterFactory(EventEmitter) {
4
4
  var splitsEventEmitter = objectAssign(new EventEmitter(), {
5
5
  splitsArrived: false,
6
6
  splitsCacheLoaded: false,
7
- initialized: false,
7
+ hasInit: false,
8
8
  initCallbacks: []
9
9
  });
10
10
  // `isSplitKill` condition avoids an edge-case of wrongly emitting SDK_READY if:
@@ -53,7 +53,7 @@ export function readinessManagerFactory(EventEmitter, settings, splits) {
53
53
  }
54
54
  var readyTimeoutId;
55
55
  if (readyTimeout > 0) {
56
- if (splits.initialized)
56
+ if (splits.hasInit)
57
57
  readyTimeoutId = setTimeout(timeout, readyTimeout);
58
58
  else
59
59
  splits.initCallbacks.push(function () { readyTimeoutId = setTimeout(timeout, readyTimeout); });
@@ -119,9 +119,9 @@ export function readinessManagerFactory(EventEmitter, settings, splits) {
119
119
  // tracking and evaluations, while keeping event listeners to emit SDK_READY_TIMED_OUT event
120
120
  setDestroyed: function () { isDestroyed = true; },
121
121
  init: function () {
122
- if (splits.initialized)
122
+ if (splits.hasInit)
123
123
  return;
124
- splits.initialized = true;
124
+ splits.hasInit = true;
125
125
  splits.initCallbacks.forEach(function (cb) { return cb(); });
126
126
  },
127
127
  destroy: function () {
@@ -1,11 +1,6 @@
1
1
  import { DEFAULT_CACHE_SIZE } from '../inRedis/constants';
2
2
  import { setToArray } from '../../utils/lang/sets';
3
3
  var UniqueKeysCacheInMemoryCS = /** @class */ (function () {
4
- /**
5
- *
6
- * @param impressionsQueueSize - number of queued impressions to call onFullQueueCb.
7
- * Default value is 0, that means no maximum value, in case we want to avoid this being triggered.
8
- */
9
4
  function UniqueKeysCacheInMemoryCS(uniqueKeysQueueSize) {
10
5
  if (uniqueKeysQueueSize === void 0) { uniqueKeysQueueSize = DEFAULT_CACHE_SIZE; }
11
6
  this.uniqueTrackerSize = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@splitsoftware/splitio-commons",
3
- "version": "2.0.0-rc.5",
3
+ "version": "2.0.0",
4
4
  "description": "Split JavaScript SDK common components",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",
@@ -8,7 +8,7 @@ function splitsEventEmitterFactory(EventEmitter: new () => SplitIO.IEventEmitter
8
8
  const splitsEventEmitter = objectAssign(new EventEmitter(), {
9
9
  splitsArrived: false,
10
10
  splitsCacheLoaded: false,
11
- initialized: false,
11
+ hasInit: false,
12
12
  initCallbacks: []
13
13
  });
14
14
 
@@ -68,7 +68,7 @@ export function readinessManagerFactory(
68
68
 
69
69
  let readyTimeoutId: ReturnType<typeof setTimeout>;
70
70
  if (readyTimeout > 0) {
71
- if (splits.initialized) readyTimeoutId = setTimeout(timeout, readyTimeout);
71
+ if (splits.hasInit) readyTimeoutId = setTimeout(timeout, readyTimeout);
72
72
  else splits.initCallbacks.push(() => { readyTimeoutId = setTimeout(timeout, readyTimeout); });
73
73
  }
74
74
 
@@ -137,8 +137,8 @@ export function readinessManagerFactory(
137
137
  setDestroyed() { isDestroyed = true; },
138
138
 
139
139
  init() {
140
- if (splits.initialized) return;
141
- splits.initialized = true;
140
+ if (splits.hasInit) return;
141
+ splits.hasInit = true;
142
142
  splits.initCallbacks.forEach(cb => cb());
143
143
  },
144
144
 
@@ -13,7 +13,7 @@ export interface ISplitsEventEmitter extends SplitIO.IEventEmitter {
13
13
  once(event: ISplitsEvent, listener: (...args: any[]) => void): this;
14
14
  splitsArrived: boolean
15
15
  splitsCacheLoaded: boolean
16
- initialized: boolean,
16
+ hasInit: boolean,
17
17
  initCallbacks: (() => void)[]
18
18
  }
19
19
 
@@ -25,7 +25,7 @@ function treatmentsNotReady(featureFlagNames: string[]) {
25
25
  /**
26
26
  * Creator of base client with getTreatments and track methods.
27
27
  */
28
- export function clientFactory(params: ISdkFactoryContext): SplitIO.INodeClient | SplitIO.INodeAsyncClient {
28
+ export function clientFactory(params: ISdkFactoryContext): SplitIO.IClient | SplitIO.IAsyncClient {
29
29
  const { sdkReadinessManager: { readinessManager }, storage, settings, impressionsTracker, eventTracker, telemetryTracker } = params;
30
30
  const { log, mode } = settings;
31
31
  const isAsync = isConsumerMode(mode);
@@ -199,5 +199,5 @@ export function clientFactory(params: ISdkFactoryContext): SplitIO.INodeClient |
199
199
  getTreatmentsByFlagSet,
200
200
  getTreatmentsWithConfigByFlagSet,
201
201
  track,
202
- } as SplitIO.INodeClient | SplitIO.INodeAsyncClient;
202
+ } as SplitIO.IClient | SplitIO.IAsyncClient;
203
203
  }
@@ -7,7 +7,7 @@ import { objectAssign } from '../utils/lang/objectAssign';
7
7
  /**
8
8
  * Add in memory attributes storage methods and combine them with any attribute received from the getTreatment/s call
9
9
  */
10
- export function clientAttributesDecoration<TClient extends SplitIO.INodeClient | SplitIO.INodeAsyncClient>(log: ILogger, client: TClient) {
10
+ export function clientAttributesDecoration<TClient extends SplitIO.IClient | SplitIO.IAsyncClient>(log: ILogger, client: TClient) {
11
11
 
12
12
  const attributeStorage = new AttributesCacheInMemory();
13
13
 
@@ -10,7 +10,7 @@ import { clientAttributesDecoration } from './clientAttributesDecoration';
10
10
  * @param client - sync client instance
11
11
  * @param key - validated split key
12
12
  */
13
- export function clientCSDecorator(log: ILogger, client: SplitIO.INodeClient, key: SplitIO.SplitKey): SplitIO.IClient {
13
+ export function clientCSDecorator(log: ILogger, client: SplitIO.IClient, key: SplitIO.SplitKey): SplitIO.IBrowserClient {
14
14
 
15
15
  let clientCS = clientAttributesDecoration(log, client);
16
16
 
@@ -30,5 +30,5 @@ export function clientCSDecorator(log: ILogger, client: SplitIO.INodeClient, key
30
30
  // Not part of the public API. These properties are used to support other modules (e.g., Split Suite)
31
31
  isClientSide: true,
32
32
  key
33
- }) as SplitIO.IClient;
33
+ }) as SplitIO.IBrowserClient;
34
34
  }
@@ -24,7 +24,7 @@ import { validateFlagSets } from '../utils/settingsValidation/splitFilters';
24
24
  * Decorator that validates the input before actually executing the client methods.
25
25
  * We should "guard" the client here, while not polluting the "real" implementation of those methods.
26
26
  */
27
- export function clientInputValidationDecorator<TClient extends SplitIO.INodeClient | SplitIO.INodeAsyncClient>(settings: ISettings, client: TClient, readinessManager: IReadinessManager): TClient {
27
+ export function clientInputValidationDecorator<TClient extends SplitIO.IClient | SplitIO.IAsyncClient>(settings: ISettings, client: TClient, readinessManager: IReadinessManager): TClient {
28
28
 
29
29
  const { log, mode } = settings;
30
30
  const isAsync = isConsumerMode(mode);
@@ -10,7 +10,7 @@ const COOLDOWN_TIME_IN_MILLIS = 1000;
10
10
  /**
11
11
  * Creates an Sdk client, i.e., a base client with status and destroy interface
12
12
  */
13
- export function sdkClientFactory(params: ISdkFactoryContext, isSharedClient?: boolean): SplitIO.INodeClient | SplitIO.INodeAsyncClient {
13
+ export function sdkClientFactory(params: ISdkFactoryContext, isSharedClient?: boolean): SplitIO.IClient | SplitIO.IAsyncClient {
14
14
  const { sdkReadinessManager, syncManager, storage, signalListener, settings, telemetryTracker, uniqueKeysTracker } = params;
15
15
 
16
16
  let lastActionTime = 0;
@@ -6,7 +6,7 @@ import { ISdkFactoryContext } from '../sdkFactory/types';
6
6
  /**
7
7
  * Factory of client method for server-side SDKs
8
8
  */
9
- export function sdkClientMethodFactory(params: ISdkFactoryContext): () => SplitIO.INodeClient | SplitIO.INodeAsyncClient {
9
+ export function sdkClientMethodFactory(params: ISdkFactoryContext): () => SplitIO.IClient | SplitIO.IAsyncClient {
10
10
  const log = params.settings.log;
11
11
  const clientInstance = sdkClientFactory(params);
12
12
 
@@ -14,12 +14,12 @@ import { buildInstanceId } from './identity';
14
14
  * Factory of client method for the client-side API variant where TT is ignored.
15
15
  * Therefore, clients don't have a bound TT for the track method.
16
16
  */
17
- export function sdkClientMethodCSFactory(params: ISdkFactoryContext): (key?: SplitIO.SplitKey) => SplitIO.IClient {
17
+ export function sdkClientMethodCSFactory(params: ISdkFactoryContext): (key?: SplitIO.SplitKey) => SplitIO.IBrowserClient {
18
18
  const { clients, storage, syncManager, sdkReadinessManager, settings: { core: { key }, log } } = params;
19
19
 
20
20
  const mainClientInstance = clientCSDecorator(
21
21
  log,
22
- sdkClientFactory(params) as SplitIO.INodeClient,
22
+ sdkClientFactory(params) as SplitIO.IClient,
23
23
  key
24
24
  );
25
25
 
@@ -71,7 +71,7 @@ export function sdkClientMethodCSFactory(params: ISdkFactoryContext): (key?: Spl
71
71
  sdkReadinessManager: sharedSdkReadiness,
72
72
  storage: sharedStorage || storage,
73
73
  syncManager: sharedSyncManager,
74
- }), true) as SplitIO.INodeClient,
74
+ }), true) as SplitIO.IClient,
75
75
  validKey
76
76
  );
77
77
 
@@ -80,6 +80,6 @@ export function sdkClientMethodCSFactory(params: ISdkFactoryContext): (key?: Spl
80
80
  log.debug(RETRIEVE_CLIENT_EXISTING);
81
81
  }
82
82
 
83
- return clients[instanceId] as SplitIO.IClient;
83
+ return clients[instanceId] as SplitIO.IBrowserClient;
84
84
  };
85
85
  }
@@ -18,7 +18,7 @@ import { NONE, OPTIMIZED } from '../utils/constants';
18
18
  /**
19
19
  * Modular SDK factory
20
20
  */
21
- export function sdkFactory(params: ISdkFactoryParams): SplitIO.INodeSDK | SplitIO.INodeAsyncSDK | SplitIO.ISDK | SplitIO.IAsyncSDK {
21
+ export function sdkFactory(params: ISdkFactoryParams): SplitIO.ISDK | SplitIO.IAsyncSDK | SplitIO.IBrowserSDK | SplitIO.IBrowserAsyncSDK {
22
22
 
23
23
  const { settings, platform, storageFactory, splitApiFactory, extraProps,
24
24
  syncManagerFactory, SignalListener, impressionsObserverFactory,
@@ -79,7 +79,7 @@ export interface ISdkFactoryParams {
79
79
  platform: IPlatform,
80
80
 
81
81
  // Storage factory. The result storage type implies the type of the SDK:
82
- // sync SDK (`ISDK` and `INodeSDK`) with `IStorageSync`, and async SDK (`IAsyncSDK` and `INodeAsyncSDK`) with `IStorageAsync`
82
+ // sync SDK (`IBrowserSDK` and `ISDK`) with `IStorageSync`, and async SDK (`IBrowserAsyncSDK` and `IAsyncSDK`) with `IStorageAsync`
83
83
  storageFactory: (params: IStorageFactoryParams) => IStorageSync | IStorageAsync,
84
84
 
85
85
  // Factory of Split Api (HTTP Client Service).
@@ -94,9 +94,9 @@ export interface ISdkFactoryParams {
94
94
  // Sdk manager factory
95
95
  sdkManagerFactory: typeof sdkManagerFactory,
96
96
 
97
- // Sdk client method factory (ISDK::client method).
98
- // It Allows to distinguish SDK clients with the client-side API (`ISDK` and `IAsyncSDK`) or server-side API (`INodeSDK` and `INodeAsyncSDK`).
99
- sdkClientMethodFactory: (params: ISdkFactoryContext) => ({ (): SplitIO.IClient; (key: SplitIO.SplitKey): SplitIO.IClient; } | (() => SplitIO.INodeClient) | (() => SplitIO.INodeAsyncClient))
97
+ // Sdk client method factory.
98
+ // It Allows to distinguish SDK clients with the client-side API (`IBrowserSDK` and `IBrowserAsyncSDK`) or server-side API (`ISDK` and `IAsyncSDK`).
99
+ sdkClientMethodFactory: (params: ISdkFactoryContext) => ({ (): SplitIO.IBrowserClient; (key: SplitIO.SplitKey): SplitIO.IBrowserClient; } | (() => SplitIO.IClient) | (() => SplitIO.IAsyncClient))
100
100
 
101
101
  // Impression observer factory.
102
102
  impressionsObserverFactory: () => IImpressionObserver
@@ -10,11 +10,6 @@ export class UniqueKeysCacheInMemoryCS implements IUniqueKeysCacheBase {
10
10
  private uniqueTrackerSize = 0;
11
11
  private uniqueKeysTracker: { [userKey: string]: Set<string> } = {};
12
12
 
13
- /**
14
- *
15
- * @param impressionsQueueSize - number of queued impressions to call onFullQueueCb.
16
- * Default value is 0, that means no maximum value, in case we want to avoid this being triggered.
17
- */
18
13
  constructor(uniqueKeysQueueSize = DEFAULT_CACHE_SIZE) {
19
14
  this.maxStorage = uniqueKeysQueueSize;
20
15
  }