@splitsoftware/splitio-commons 1.2.1-rc.2 → 1.2.1-rc.3

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.
@@ -4,8 +4,10 @@ exports.GoogleAnalyticsToSplit = void 0;
4
4
  var GaToSplit_1 = require("./GaToSplit");
5
5
  function GoogleAnalyticsToSplit(options) {
6
6
  // GaToSplit integration factory
7
- return function (params) {
7
+ function GoogleAnalyticsToSplitFactory(params) {
8
8
  return (0, GaToSplit_1.GaToSplit)(options, params);
9
- };
9
+ }
10
+ GoogleAnalyticsToSplitFactory.type = 'GOOGLE_ANALYTICS_TO_SPLIT';
11
+ return GoogleAnalyticsToSplitFactory;
10
12
  }
11
13
  exports.GoogleAnalyticsToSplit = GoogleAnalyticsToSplit;
@@ -5,8 +5,10 @@ var SplitToGa_1 = require("./SplitToGa");
5
5
  function SplitToGoogleAnalytics(options) {
6
6
  if (options === void 0) { options = {}; }
7
7
  // SplitToGa integration factory
8
- return function (params) {
8
+ function SplitToGoogleAnalyticsFactory(params) {
9
9
  return new SplitToGa_1.SplitToGa(params.settings.log, options);
10
- };
10
+ }
11
+ SplitToGoogleAnalyticsFactory.type = 'SPLIT_TO_GOOGLE_ANALYTICS';
12
+ return SplitToGoogleAnalyticsFactory;
11
13
  }
12
14
  exports.SplitToGoogleAnalytics = SplitToGoogleAnalytics;
@@ -16,7 +16,7 @@ exports.codesError = [
16
16
  [c.ERROR_SYNC_OFFLINE_LOADING, c.LOG_PREFIX_SYNC_OFFLINE + 'There was an issue loading the mock Splits data, no changes will be applied to the current cache. %s'],
17
17
  [c.ERROR_STREAMING_SSE, c.LOG_PREFIX_SYNC_STREAMING + 'Failed to connect or error on streaming connection, with error message: %s'],
18
18
  [c.ERROR_STREAMING_AUTH, c.LOG_PREFIX_SYNC_STREAMING + 'Failed to authenticate for streaming. Error: %s.'],
19
- [c.ERROR_HTTP, ' Response status is not OK. Status: %s. URL: %s. Message: %s'],
19
+ [c.ERROR_HTTP, 'Response status is not OK. Status: %s. URL: %s. Message: %s'],
20
20
  // client status
21
21
  [c.ERROR_CLIENT_LISTENER, 'A listener was added for %s on the SDK, which has already fired and won\'t be emitted again. The callback won\'t be executed.'],
22
22
  [c.ERROR_CLIENT_DESTROYED, '%s: Client has already been destroyed - no calls possible.'],
@@ -30,5 +30,5 @@ exports.codesInfo = warn_1.codesWarn.concat([
30
30
  [c.STREAMING_DISCONNECTING, c.LOG_PREFIX_SYNC_STREAMING + 'Disconnecting streaming.'],
31
31
  [c.SYNC_START_POLLING, c.LOG_PREFIX_SYNC_MANAGER + 'Streaming not available. Starting polling.'],
32
32
  [c.SYNC_CONTINUE_POLLING, c.LOG_PREFIX_SYNC_MANAGER + 'Streaming couldn\'t connect. Continue polling.'],
33
- [c.SYNC_STOP_POLLING, c.LOG_PREFIX_SYNC_MANAGER + 'Streaming (re)connected. Syncing and stopping polling.'],
33
+ [c.SYNC_STOP_POLLING, c.LOG_PREFIX_SYNC_MANAGER + 'Streaming connected. Syncing and stopping polling.'],
34
34
  ]);
@@ -58,6 +58,7 @@ function pushManagerFactory(params, pollingManager) {
58
58
  // It is used to halt the `connectPush` process if it was in progress.
59
59
  var disconnected;
60
60
  // flag that indicates a PUSH_NONRETRYABLE_ERROR, condition with which starting pushManager again is ignored.
61
+ // true if STREAMING_DISABLED control event, or 'pushEnabled: false', or non-recoverable SSE or Auth errors.
61
62
  var disabled; // `disabled` implies `disconnected === true`
62
63
  /** PushManager functions related to initialization */
63
64
  var connectPushRetryBackoff = new Backoff_1.Backoff(connectPush, settings.scheduler.pushRetryBackoffBase);
@@ -258,13 +259,15 @@ function pushManagerFactory(params, pollingManager) {
258
259
  return (0, objectAssign_1.objectAssign)(
259
260
  // Expose Event Emitter functionality and Event constants
260
261
  Object.create(pushEmitter), {
261
- // Stop/pause push mode
262
+ // Stop/pause push mode.
263
+ // It doesn't emit events. Neither PUSH_SUBSYSTEM_DOWN to start polling.
262
264
  stop: function () {
263
265
  disconnectPush(); // `handleNonRetryableError` cannot be used as `stop`, because it emits PUSH_SUBSYSTEM_DOWN event, which starts polling.
264
266
  if (userKey)
265
267
  this.remove(userKey); // Necessary to properly resume streaming in client-side (e.g., RN SDK transition to foreground).
266
268
  },
267
- // Start/resume push mode
269
+ // Start/resume push mode.
270
+ // It eventually emits PUSH_SUBSYSTEM_DOWN, that starts polling, or PUSH_SUBSYSTEM_UP, that executes a syncAll
268
271
  start: function () {
269
272
  // Guard condition to avoid calling `connectPush` again if the `start` method is called multiple times or if push has been disabled.
270
273
  if (disabled || disconnected === false)
@@ -275,6 +278,10 @@ function pushManagerFactory(params, pollingManager) {
275
278
  else
276
279
  setTimeout(connectPush); // server-side runs in next cycle as in client-side, for consistency with client-side
277
280
  },
281
+ // true/false if start or stop was called last respectively
282
+ isRunning: function () {
283
+ return disconnected === false;
284
+ },
278
285
  // [Only for client-side]
279
286
  add: function (userKey, mySegmentsSyncTask) {
280
287
  var hash = (0, AuthClient_1.hashUserKey)(userKey);
@@ -1,7 +1,9 @@
1
1
  import { GaToSplit } from './GaToSplit';
2
2
  export function GoogleAnalyticsToSplit(options) {
3
3
  // GaToSplit integration factory
4
- return function (params) {
4
+ function GoogleAnalyticsToSplitFactory(params) {
5
5
  return GaToSplit(options, params);
6
- };
6
+ }
7
+ GoogleAnalyticsToSplitFactory.type = 'GOOGLE_ANALYTICS_TO_SPLIT';
8
+ return GoogleAnalyticsToSplitFactory;
7
9
  }
@@ -2,7 +2,9 @@ import { SplitToGa } from './SplitToGa';
2
2
  export function SplitToGoogleAnalytics(options) {
3
3
  if (options === void 0) { options = {}; }
4
4
  // SplitToGa integration factory
5
- return function (params) {
5
+ function SplitToGoogleAnalyticsFactory(params) {
6
6
  return new SplitToGa(params.settings.log, options);
7
- };
7
+ }
8
+ SplitToGoogleAnalyticsFactory.type = 'SPLIT_TO_GOOGLE_ANALYTICS';
9
+ return SplitToGoogleAnalyticsFactory;
8
10
  }
@@ -12,7 +12,7 @@ export var codesError = [
12
12
  [c.ERROR_SYNC_OFFLINE_LOADING, c.LOG_PREFIX_SYNC_OFFLINE + 'There was an issue loading the mock Splits data, no changes will be applied to the current cache. %s'],
13
13
  [c.ERROR_STREAMING_SSE, c.LOG_PREFIX_SYNC_STREAMING + 'Failed to connect or error on streaming connection, with error message: %s'],
14
14
  [c.ERROR_STREAMING_AUTH, c.LOG_PREFIX_SYNC_STREAMING + 'Failed to authenticate for streaming. Error: %s.'],
15
- [c.ERROR_HTTP, ' Response status is not OK. Status: %s. URL: %s. Message: %s'],
15
+ [c.ERROR_HTTP, 'Response status is not OK. Status: %s. URL: %s. Message: %s'],
16
16
  // client status
17
17
  [c.ERROR_CLIENT_LISTENER, 'A listener was added for %s on the SDK, which has already fired and won\'t be emitted again. The callback won\'t be executed.'],
18
18
  [c.ERROR_CLIENT_DESTROYED, '%s: Client has already been destroyed - no calls possible.'],
@@ -26,5 +26,5 @@ export var codesInfo = codesWarn.concat([
26
26
  [c.STREAMING_DISCONNECTING, c.LOG_PREFIX_SYNC_STREAMING + 'Disconnecting streaming.'],
27
27
  [c.SYNC_START_POLLING, c.LOG_PREFIX_SYNC_MANAGER + 'Streaming not available. Starting polling.'],
28
28
  [c.SYNC_CONTINUE_POLLING, c.LOG_PREFIX_SYNC_MANAGER + 'Streaming couldn\'t connect. Continue polling.'],
29
- [c.SYNC_STOP_POLLING, c.LOG_PREFIX_SYNC_MANAGER + 'Streaming (re)connected. Syncing and stopping polling.'],
29
+ [c.SYNC_STOP_POLLING, c.LOG_PREFIX_SYNC_MANAGER + 'Streaming connected. Syncing and stopping polling.'],
30
30
  ]);
@@ -55,6 +55,7 @@ export function pushManagerFactory(params, pollingManager) {
55
55
  // It is used to halt the `connectPush` process if it was in progress.
56
56
  var disconnected;
57
57
  // flag that indicates a PUSH_NONRETRYABLE_ERROR, condition with which starting pushManager again is ignored.
58
+ // true if STREAMING_DISABLED control event, or 'pushEnabled: false', or non-recoverable SSE or Auth errors.
58
59
  var disabled; // `disabled` implies `disconnected === true`
59
60
  /** PushManager functions related to initialization */
60
61
  var connectPushRetryBackoff = new Backoff(connectPush, settings.scheduler.pushRetryBackoffBase);
@@ -255,13 +256,15 @@ export function pushManagerFactory(params, pollingManager) {
255
256
  return objectAssign(
256
257
  // Expose Event Emitter functionality and Event constants
257
258
  Object.create(pushEmitter), {
258
- // Stop/pause push mode
259
+ // Stop/pause push mode.
260
+ // It doesn't emit events. Neither PUSH_SUBSYSTEM_DOWN to start polling.
259
261
  stop: function () {
260
262
  disconnectPush(); // `handleNonRetryableError` cannot be used as `stop`, because it emits PUSH_SUBSYSTEM_DOWN event, which starts polling.
261
263
  if (userKey)
262
264
  this.remove(userKey); // Necessary to properly resume streaming in client-side (e.g., RN SDK transition to foreground).
263
265
  },
264
- // Start/resume push mode
266
+ // Start/resume push mode.
267
+ // It eventually emits PUSH_SUBSYSTEM_DOWN, that starts polling, or PUSH_SUBSYSTEM_UP, that executes a syncAll
265
268
  start: function () {
266
269
  // Guard condition to avoid calling `connectPush` again if the `start` method is called multiple times or if push has been disabled.
267
270
  if (disabled || disconnected === false)
@@ -272,6 +275,10 @@ export function pushManagerFactory(params, pollingManager) {
272
275
  else
273
276
  setTimeout(connectPush); // server-side runs in next cycle as in client-side, for consistency with client-side
274
277
  },
278
+ // true/false if start or stop was called last respectively
279
+ isRunning: function () {
280
+ return disconnected === false;
281
+ },
275
282
  // [Only for client-side]
276
283
  add: function (userKey, mySegmentsSyncTask) {
277
284
  var hash = hashUserKey(userKey);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@splitsoftware/splitio-commons",
3
- "version": "1.2.1-rc.2",
3
+ "version": "1.2.1-rc.3",
4
4
  "description": "Split Javascript SDK common components",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",
@@ -1,11 +1,14 @@
1
- import { IIntegrationFactoryParams } from '../types';
1
+ import { IIntegrationFactoryParams, IntegrationFactory } from '../types';
2
2
  import { GaToSplit } from './GaToSplit';
3
3
  import { GoogleAnalyticsToSplitOptions } from './types';
4
4
 
5
- export function GoogleAnalyticsToSplit(options: GoogleAnalyticsToSplitOptions) {
5
+ export function GoogleAnalyticsToSplit(options: GoogleAnalyticsToSplitOptions): IntegrationFactory {
6
6
 
7
7
  // GaToSplit integration factory
8
- return (params: IIntegrationFactoryParams) => {
8
+ function GoogleAnalyticsToSplitFactory(params: IIntegrationFactoryParams) {
9
9
  return GaToSplit(options, params);
10
- };
10
+ }
11
+
12
+ GoogleAnalyticsToSplitFactory.type = 'GOOGLE_ANALYTICS_TO_SPLIT';
13
+ return GoogleAnalyticsToSplitFactory;
11
14
  }
@@ -1,11 +1,14 @@
1
- import { IIntegrationFactoryParams } from '../types';
1
+ import { IIntegrationFactoryParams, IntegrationFactory } from '../types';
2
2
  import { SplitToGa } from './SplitToGa';
3
3
  import { SplitToGoogleAnalyticsOptions } from './types';
4
4
 
5
- export function SplitToGoogleAnalytics(options: SplitToGoogleAnalyticsOptions = {}) {
5
+ export function SplitToGoogleAnalytics(options: SplitToGoogleAnalyticsOptions = {}): IntegrationFactory {
6
6
 
7
7
  // SplitToGa integration factory
8
- return (params: IIntegrationFactoryParams) => {
8
+ function SplitToGoogleAnalyticsFactory(params: IIntegrationFactoryParams) {
9
9
  return new SplitToGa(params.settings.log, options);
10
- };
10
+ }
11
+
12
+ SplitToGoogleAnalyticsFactory.type = 'SPLIT_TO_GOOGLE_ANALYTICS';
13
+ return SplitToGoogleAnalyticsFactory;
11
14
  }
@@ -12,3 +12,8 @@ export interface IIntegrationFactoryParams {
12
12
  storage: { events: IEventsCacheBase }
13
13
  settings: ISettings
14
14
  }
15
+
16
+ export type IntegrationFactory = {
17
+ readonly type: string
18
+ (params: IIntegrationFactoryParams): IIntegration | void
19
+ }
@@ -13,7 +13,7 @@ export const codesError: [number, string][] = [
13
13
  [c.ERROR_SYNC_OFFLINE_LOADING, c.LOG_PREFIX_SYNC_OFFLINE + 'There was an issue loading the mock Splits data, no changes will be applied to the current cache. %s'],
14
14
  [c.ERROR_STREAMING_SSE, c.LOG_PREFIX_SYNC_STREAMING + 'Failed to connect or error on streaming connection, with error message: %s'],
15
15
  [c.ERROR_STREAMING_AUTH, c.LOG_PREFIX_SYNC_STREAMING + 'Failed to authenticate for streaming. Error: %s.'],
16
- [c.ERROR_HTTP, ' Response status is not OK. Status: %s. URL: %s. Message: %s'],
16
+ [c.ERROR_HTTP, 'Response status is not OK. Status: %s. URL: %s. Message: %s'],
17
17
  // client status
18
18
  [c.ERROR_CLIENT_LISTENER, 'A listener was added for %s on the SDK, which has already fired and won\'t be emitted again. The callback won\'t be executed.'],
19
19
  [c.ERROR_CLIENT_DESTROYED, '%s: Client has already been destroyed - no calls possible.'],
@@ -29,5 +29,5 @@ export const codesInfo: [number, string][] = codesWarn.concat([
29
29
  [c.STREAMING_DISCONNECTING, c.LOG_PREFIX_SYNC_STREAMING + 'Disconnecting streaming.'],
30
30
  [c.SYNC_START_POLLING, c.LOG_PREFIX_SYNC_MANAGER + 'Streaming not available. Starting polling.'],
31
31
  [c.SYNC_CONTINUE_POLLING, c.LOG_PREFIX_SYNC_MANAGER + 'Streaming couldn\'t connect. Continue polling.'],
32
- [c.SYNC_STOP_POLLING, c.LOG_PREFIX_SYNC_MANAGER + 'Streaming (re)connected. Syncing and stopping polling.'],
32
+ [c.SYNC_STOP_POLLING, c.LOG_PREFIX_SYNC_MANAGER + 'Streaming connected. Syncing and stopping polling.'],
33
33
  ]);
@@ -9,15 +9,15 @@ export interface ILoggerOptions {
9
9
  export interface ILogger {
10
10
  setLogLevel(logLevel: LogLevel): void
11
11
 
12
- debug(msg: unknown): void
12
+ debug(msg: any): void
13
13
  debug(msg: string | number, args?: any[]): void
14
14
 
15
- info(msg: unknown): void
15
+ info(msg: any): void
16
16
  info(msg: string | number, args?: any[]): void
17
17
 
18
- warn(msg: unknown): void
18
+ warn(msg: any): void
19
19
  warn(msg: string | number, args?: any[]): void
20
20
 
21
- error(msg: unknown): void
21
+ error(msg: any): void
22
22
  error(msg: string | number, args?: any[]): void
23
23
  }
@@ -443,7 +443,7 @@ export interface IStorageFactoryParams {
443
443
  export type StorageType = 'MEMORY' | 'LOCALSTORAGE' | 'REDIS' | 'PLUGGABLE';
444
444
 
445
445
  export type IStorageSyncFactory = {
446
- type: StorageType,
446
+ readonly type: StorageType,
447
447
  (params: IStorageFactoryParams): IStorageSync
448
448
  }
449
449
 
@@ -71,6 +71,7 @@ export function pushManagerFactory(
71
71
  // It is used to halt the `connectPush` process if it was in progress.
72
72
  let disconnected: boolean | undefined;
73
73
  // flag that indicates a PUSH_NONRETRYABLE_ERROR, condition with which starting pushManager again is ignored.
74
+ // true if STREAMING_DISABLED control event, or 'pushEnabled: false', or non-recoverable SSE or Auth errors.
74
75
  let disabled: boolean | undefined; // `disabled` implies `disconnected === true`
75
76
 
76
77
  /** PushManager functions related to initialization */
@@ -296,12 +297,15 @@ export function pushManagerFactory(
296
297
  // Expose Event Emitter functionality and Event constants
297
298
  Object.create(pushEmitter),
298
299
  {
299
- // Stop/pause push mode
300
+ // Stop/pause push mode.
301
+ // It doesn't emit events. Neither PUSH_SUBSYSTEM_DOWN to start polling.
300
302
  stop() {
301
303
  disconnectPush(); // `handleNonRetryableError` cannot be used as `stop`, because it emits PUSH_SUBSYSTEM_DOWN event, which starts polling.
302
304
  if (userKey) this.remove(userKey); // Necessary to properly resume streaming in client-side (e.g., RN SDK transition to foreground).
303
305
  },
304
- // Start/resume push mode
306
+
307
+ // Start/resume push mode.
308
+ // It eventually emits PUSH_SUBSYSTEM_DOWN, that starts polling, or PUSH_SUBSYSTEM_UP, that executes a syncAll
305
309
  start() {
306
310
  // Guard condition to avoid calling `connectPush` again if the `start` method is called multiple times or if push has been disabled.
307
311
  if (disabled || disconnected === false) return;
@@ -311,6 +315,11 @@ export function pushManagerFactory(
311
315
  else setTimeout(connectPush); // server-side runs in next cycle as in client-side, for consistency with client-side
312
316
  },
313
317
 
318
+ // true/false if start or stop was called last respectively
319
+ isRunning(){
320
+ return disconnected === false;
321
+ },
322
+
314
323
  // [Only for client-side]
315
324
  add(userKey: string, mySegmentsSyncTask: ISegmentsSyncTask) {
316
325
  const hash = hashUserKey(userKey);
@@ -1,4 +1,6 @@
1
- export function validateRuntime() {
1
+ import { ISettings } from '../../../types';
2
+
3
+ export function validateRuntime(): ISettings['runtime'] {
2
4
  return {
3
5
  ip: false,
4
6
  hostname: false
@@ -4,7 +4,7 @@ import ipFunction from 'ip';
4
4
  import { UNKNOWN, NA, CONSUMER_MODE } from '../../constants';
5
5
  import { ISettings } from '../../../types';
6
6
 
7
- export function validateRuntime(settings: ISettings) {
7
+ export function validateRuntime(settings: ISettings): ISettings['runtime'] {
8
8
  const isIPAddressesEnabled = settings.core.IPAddressesEnabled === true;
9
9
  const isConsumerMode = settings.mode === CONSUMER_MODE;
10
10
 
@@ -1,3 +1,3 @@
1
- import { IIntegrationFactoryParams } from '../types';
1
+ import { IntegrationFactory } from '../types';
2
2
  import { GoogleAnalyticsToSplitOptions } from './types';
3
- export declare function GoogleAnalyticsToSplit(options: GoogleAnalyticsToSplitOptions): (params: IIntegrationFactoryParams) => void;
3
+ export declare function GoogleAnalyticsToSplit(options: GoogleAnalyticsToSplitOptions): IntegrationFactory;
@@ -1,4 +1,3 @@
1
- import { IIntegrationFactoryParams } from '../types';
2
- import { SplitToGa } from './SplitToGa';
1
+ import { IntegrationFactory } from '../types';
3
2
  import { SplitToGoogleAnalyticsOptions } from './types';
4
- export declare function SplitToGoogleAnalytics(options?: SplitToGoogleAnalyticsOptions): (params: IIntegrationFactoryParams) => SplitToGa;
3
+ export declare function SplitToGoogleAnalytics(options?: SplitToGoogleAnalyticsOptions): IntegrationFactory;
@@ -11,3 +11,7 @@ export interface IIntegrationFactoryParams {
11
11
  };
12
12
  settings: ISettings;
13
13
  }
14
+ export declare type IntegrationFactory = {
15
+ readonly type: string;
16
+ (params: IIntegrationFactoryParams): IIntegration | void;
17
+ };
@@ -6,12 +6,12 @@ export interface ILoggerOptions {
6
6
  }
7
7
  export interface ILogger {
8
8
  setLogLevel(logLevel: LogLevel): void;
9
- debug(msg: unknown): void;
9
+ debug(msg: any): void;
10
10
  debug(msg: string | number, args?: any[]): void;
11
- info(msg: unknown): void;
11
+ info(msg: any): void;
12
12
  info(msg: string | number, args?: any[]): void;
13
- warn(msg: unknown): void;
13
+ warn(msg: any): void;
14
14
  warn(msg: string | number, args?: any[]): void;
15
- error(msg: unknown): void;
15
+ error(msg: any): void;
16
16
  error(msg: string | number, args?: any[]): void;
17
17
  }
@@ -345,7 +345,7 @@ export interface IStorageFactoryParams {
345
345
  }
346
346
  export declare type StorageType = 'MEMORY' | 'LOCALSTORAGE' | 'REDIS' | 'PLUGGABLE';
347
347
  export declare type IStorageSyncFactory = {
348
- type: StorageType;
348
+ readonly type: StorageType;
349
349
  (params: IStorageFactoryParams): IStorageSync;
350
350
  };
351
351
  export declare type IStorageAsyncFactory = {
@@ -1,4 +1,2 @@
1
- export declare function validateRuntime(): {
2
- ip: boolean;
3
- hostname: boolean;
4
- };
1
+ import { ISettings } from '../../../types';
2
+ export declare function validateRuntime(): ISettings['runtime'];
@@ -1,5 +1,2 @@
1
1
  import { ISettings } from '../../../types';
2
- export declare function validateRuntime(settings: ISettings): {
3
- ip: string | false;
4
- hostname: string | false;
5
- };
2
+ export declare function validateRuntime(settings: ISettings): ISettings['runtime'];