@splitsoftware/splitio-commons 1.4.2-rc.5 → 1.5.1-rc.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.
Files changed (72) hide show
  1. package/CHANGES.txt +3 -3
  2. package/cjs/integrations/ga/GaToSplit.js +11 -12
  3. package/cjs/listeners/browser.js +35 -15
  4. package/cjs/services/splitApi.js +4 -4
  5. package/cjs/sync/polling/fetchers/segmentChangesFetcher.js +5 -5
  6. package/cjs/sync/polling/fetchers/splitChangesFetcher.js +2 -2
  7. package/cjs/sync/polling/updaters/segmentChangesUpdater.js +34 -34
  8. package/cjs/sync/polling/updaters/splitChangesUpdater.js +4 -3
  9. package/cjs/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.js +46 -46
  10. package/cjs/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.js +82 -64
  11. package/cjs/sync/streaming/UpdateWorkers/SplitsUpdateWorker.js +74 -58
  12. package/cjs/sync/streaming/UpdateWorkers/constants.js +6 -0
  13. package/cjs/sync/streaming/pushManager.js +6 -7
  14. package/cjs/sync/syncTask.js +13 -16
  15. package/cjs/utils/Backoff.js +3 -2
  16. package/esm/integrations/ga/GaToSplit.js +11 -12
  17. package/esm/listeners/browser.js +35 -15
  18. package/esm/services/splitApi.js +4 -4
  19. package/esm/sync/polling/fetchers/segmentChangesFetcher.js +5 -5
  20. package/esm/sync/polling/fetchers/splitChangesFetcher.js +2 -2
  21. package/esm/sync/polling/updaters/segmentChangesUpdater.js +34 -34
  22. package/esm/sync/polling/updaters/splitChangesUpdater.js +4 -3
  23. package/esm/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.js +46 -47
  24. package/esm/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.js +82 -65
  25. package/esm/sync/streaming/UpdateWorkers/SplitsUpdateWorker.js +74 -59
  26. package/esm/sync/streaming/UpdateWorkers/constants.js +3 -0
  27. package/esm/sync/streaming/pushManager.js +6 -7
  28. package/esm/sync/syncTask.js +13 -16
  29. package/esm/utils/Backoff.js +3 -2
  30. package/package.json +1 -1
  31. package/src/integrations/ga/GaToSplit.ts +8 -14
  32. package/src/integrations/ga/types.ts +2 -13
  33. package/src/listeners/browser.ts +34 -14
  34. package/src/services/splitApi.ts +4 -4
  35. package/src/services/types.ts +2 -2
  36. package/src/sync/polling/fetchers/segmentChangesFetcher.ts +5 -4
  37. package/src/sync/polling/fetchers/splitChangesFetcher.ts +2 -1
  38. package/src/sync/polling/fetchers/types.ts +2 -0
  39. package/src/sync/polling/pollingManagerCS.ts +5 -5
  40. package/src/sync/polling/syncTasks/mySegmentsSyncTask.ts +2 -2
  41. package/src/sync/polling/types.ts +14 -6
  42. package/src/sync/polling/updaters/mySegmentsUpdater.ts +4 -4
  43. package/src/sync/polling/updaters/segmentChangesUpdater.ts +34 -32
  44. package/src/sync/polling/updaters/splitChangesUpdater.ts +5 -4
  45. package/src/sync/streaming/SSEHandler/types.ts +0 -7
  46. package/src/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.ts +45 -54
  47. package/src/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.ts +78 -63
  48. package/src/sync/streaming/UpdateWorkers/SplitsUpdateWorker.ts +73 -61
  49. package/src/sync/streaming/UpdateWorkers/constants.ts +3 -0
  50. package/src/sync/streaming/UpdateWorkers/types.ts +2 -4
  51. package/src/sync/streaming/pushManager.ts +12 -12
  52. package/src/sync/streaming/types.ts +2 -2
  53. package/src/sync/syncTask.ts +16 -18
  54. package/src/utils/Backoff.ts +7 -2
  55. package/types/integrations/ga/types.d.ts +2 -13
  56. package/types/listeners/browser.d.ts +6 -6
  57. package/types/services/types.d.ts +2 -2
  58. package/types/sync/polling/fetchers/types.d.ts +2 -2
  59. package/types/sync/polling/syncTasks/mySegmentsSyncTask.d.ts +2 -2
  60. package/types/sync/polling/types.d.ts +11 -6
  61. package/types/sync/polling/updaters/segmentChangesUpdater.d.ts +1 -1
  62. package/types/sync/polling/updaters/splitChangesUpdater.d.ts +1 -1
  63. package/types/sync/streaming/SSEHandler/types.d.ts +0 -4
  64. package/types/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.d.ts +3 -24
  65. package/types/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.d.ts +3 -23
  66. package/types/sync/streaming/UpdateWorkers/SplitsUpdateWorker.d.ts +6 -33
  67. package/types/sync/streaming/UpdateWorkers/constants.d.ts +3 -0
  68. package/types/sync/streaming/UpdateWorkers/types.d.ts +1 -2
  69. package/types/sync/streaming/types.d.ts +2 -2
  70. package/types/sync/syncTask.d.ts +2 -3
  71. package/types/utils/Backoff.d.ts +2 -0
  72. package/src/integrations/ga/autoRequire.js +0 -33
@@ -1,21 +1,26 @@
1
1
  import { IReadinessManager } from '../../readiness/types';
2
2
  import { IStorageSync } from '../../storages/types';
3
- import { SegmentsData } from '../streaming/SSEHandler/types';
4
3
  import { ITask, ISyncTask } from '../types';
5
- export interface ISplitsSyncTask extends ISyncTask<[noCache?: boolean], boolean> {
4
+ export interface ISplitsSyncTask extends ISyncTask<[noCache?: boolean, till?: number], boolean> {
6
5
  }
7
- export interface ISegmentsSyncTask extends ISyncTask<[segmentNames?: SegmentsData, noCache?: boolean, fetchOnlyNew?: boolean], boolean> {
6
+ export interface ISegmentsSyncTask extends ISyncTask<[fetchOnlyNew?: boolean, segmentName?: string, noCache?: boolean, till?: number], boolean> {
7
+ }
8
+ export declare type MySegmentsData = string[] | {
9
+ name: string;
10
+ add: boolean;
11
+ };
12
+ export interface IMySegmentsSyncTask extends ISyncTask<[segmentsData?: MySegmentsData, noCache?: boolean], boolean> {
8
13
  }
9
14
  export interface IPollingManager extends ITask {
10
15
  syncAll(): Promise<any>;
11
16
  splitsSyncTask: ISplitsSyncTask;
12
- segmentsSyncTask: ISegmentsSyncTask;
17
+ segmentsSyncTask: ISyncTask;
13
18
  }
14
19
  /**
15
20
  * PollingManager for client-side with support for multiple clients
16
21
  */
17
22
  export interface IPollingManagerCS extends IPollingManager {
18
- add(matchingKey: string, readiness: IReadinessManager, storage: IStorageSync): ISegmentsSyncTask;
23
+ add(matchingKey: string, readiness: IReadinessManager, storage: IStorageSync): IMySegmentsSyncTask;
19
24
  remove(matchingKey: string): void;
20
- get(matchingKey: string): ISegmentsSyncTask | undefined;
25
+ get(matchingKey: string): IMySegmentsSyncTask | undefined;
21
26
  }
@@ -2,7 +2,7 @@ import { ISegmentChangesFetcher } from '../fetchers/types';
2
2
  import { ISegmentsCacheBase } from '../../../storages/types';
3
3
  import { IReadinessManager } from '../../../readiness/types';
4
4
  import { ILogger } from '../../../logger/types';
5
- declare type ISegmentChangesUpdater = (segmentNames?: string[], noCache?: boolean, fetchOnlyNew?: boolean) => Promise<boolean>;
5
+ declare type ISegmentChangesUpdater = (fetchOnlyNew?: boolean, segmentName?: string, noCache?: boolean, till?: number) => Promise<boolean>;
6
6
  /**
7
7
  * Factory of SegmentChanges updater, a task that:
8
8
  * - fetches segment changes using `segmentChangesFetcher`
@@ -4,7 +4,7 @@ import { ISplitChangesFetcher } from '../fetchers/types';
4
4
  import { ISplit } from '../../../dtos/types';
5
5
  import { ISplitsEventEmitter } from '../../../readiness/types';
6
6
  import { ILogger } from '../../../logger/types';
7
- declare type ISplitChangesUpdater = (noCache?: boolean) => Promise<boolean>;
7
+ declare type ISplitChangesUpdater = (noCache?: boolean, till?: number) => Promise<boolean>;
8
8
  /**
9
9
  * Collect segments from a raw split definition.
10
10
  * Exported for testing purposes.
@@ -65,7 +65,3 @@ export declare type INotificationError = Event & {
65
65
  parsedData?: any;
66
66
  message?: string;
67
67
  };
68
- export declare type SegmentsData = string[] | {
69
- name: string;
70
- add: boolean;
71
- };
@@ -1,27 +1,6 @@
1
- import { ISegmentsSyncTask } from '../../polling/types';
2
- import { Backoff } from '../../../utils/Backoff';
1
+ import { IMySegmentsSyncTask } from '../../polling/types';
3
2
  import { IUpdateWorker } from './types';
4
- import { SegmentsData } from '../SSEHandler/types';
5
3
  /**
6
- * MySegmentsUpdateWorker class
4
+ * MySegmentsUpdateWorker factory
7
5
  */
8
- export declare class MySegmentsUpdateWorker implements IUpdateWorker {
9
- private readonly mySegmentsSyncTask;
10
- private maxChangeNumber;
11
- private handleNewEvent;
12
- private segmentsData?;
13
- private currentChangeNumber;
14
- readonly backoff: Backoff;
15
- /**
16
- * @param {Object} mySegmentsSyncTask task for syncing mySegments data
17
- */
18
- constructor(mySegmentsSyncTask: ISegmentsSyncTask);
19
- __handleMySegmentsUpdateCall(): void;
20
- /**
21
- * Invoked by NotificationProcessor on MY_SEGMENTS_UPDATE event
22
- *
23
- * @param {number} changeNumber change number of the MY_SEGMENTS_UPDATE notification
24
- * @param {SegmentsData | undefined} segmentsData might be undefined
25
- */
26
- put(changeNumber: number, segmentsData?: SegmentsData): void;
27
- }
6
+ export declare function MySegmentsUpdateWorker(mySegmentsSyncTask: IMySegmentsSyncTask): IUpdateWorker;
@@ -1,28 +1,8 @@
1
+ import { ILogger } from '../../../logger/types';
1
2
  import { ISegmentsCacheSync } from '../../../storages/types';
2
- import { Backoff } from '../../../utils/Backoff';
3
3
  import { ISegmentsSyncTask } from '../../polling/types';
4
- import { ISegmentUpdateData } from '../SSEHandler/types';
5
4
  import { IUpdateWorker } from './types';
6
5
  /**
7
- * SegmentUpdateWorker class
6
+ * SegmentsUpdateWorker factory
8
7
  */
9
- export declare class SegmentsUpdateWorker implements IUpdateWorker {
10
- private readonly segmentsCache;
11
- private readonly segmentsSyncTask;
12
- private readonly maxChangeNumbers;
13
- private handleNewEvent;
14
- readonly backoff: Backoff;
15
- /**
16
- * @param {Object} segmentsCache segments data cache
17
- * @param {Object} segmentsSyncTask task for syncing segments data
18
- */
19
- constructor(segmentsSyncTask: ISegmentsSyncTask, segmentsCache: ISegmentsCacheSync);
20
- __handleSegmentUpdateCall(): void;
21
- /**
22
- * Invoked by NotificationProcessor on SEGMENT_UPDATE event
23
- *
24
- * @param {number} changeNumber change number of the SEGMENT_UPDATE notification
25
- * @param {string} segmentName segment name of the SEGMENT_UPDATE notification
26
- */
27
- put({ changeNumber, segmentName }: ISegmentUpdateData): void;
28
- }
8
+ export declare function SegmentsUpdateWorker(log: ILogger, segmentsSyncTask: ISegmentsSyncTask, segmentsCache: ISegmentsCacheSync): IUpdateWorker;
@@ -1,39 +1,12 @@
1
+ import { ILogger } from '../../../logger/types';
1
2
  import { ISplitsEventEmitter } from '../../../readiness/types';
2
3
  import { ISplitsCacheSync } from '../../../storages/types';
3
- import { Backoff } from '../../../utils/Backoff';
4
4
  import { ISegmentsSyncTask, ISplitsSyncTask } from '../../polling/types';
5
- import { ISplitKillData, ISplitUpdateData } from '../SSEHandler/types';
5
+ import { ISplitKillData } from '../SSEHandler/types';
6
6
  import { IUpdateWorker } from './types';
7
7
  /**
8
- * SplitsUpdateWorker class
8
+ * SplitsUpdateWorker factory
9
9
  */
10
- export declare class SplitsUpdateWorker implements IUpdateWorker {
11
- private readonly splitsCache;
12
- private readonly splitsSyncTask;
13
- private readonly splitsEventEmitter;
14
- private readonly segmentsSyncTask?;
15
- private maxChangeNumber;
16
- private handleNewEvent;
17
- readonly backoff: Backoff;
18
- /**
19
- * @param {Object} splitsCache splits data cache
20
- * @param {Object} splitsSyncTask task for syncing splits data
21
- * @param {Object} splitsEventEmitter emitter for splits data events
22
- */
23
- constructor(splitsCache: ISplitsCacheSync, splitsSyncTask: ISplitsSyncTask, splitsEventEmitter: ISplitsEventEmitter, segmentsSyncTask?: ISegmentsSyncTask);
24
- __handleSplitUpdateCall(): void;
25
- /**
26
- * Invoked by NotificationProcessor on SPLIT_UPDATE event
27
- *
28
- * @param {number} changeNumber change number of the SPLIT_UPDATE notification
29
- */
30
- put({ changeNumber }: Pick<ISplitUpdateData, 'changeNumber'>): void;
31
- /**
32
- * Invoked by NotificationProcessor on SPLIT_KILL event
33
- *
34
- * @param {number} changeNumber change number of the SPLIT_UPDATE notification
35
- * @param {string} splitName name of split to kill
36
- * @param {string} defaultTreatment default treatment value
37
- */
38
- killSplit({ changeNumber, splitName, defaultTreatment }: ISplitKillData): void;
39
- }
10
+ export declare function SplitsUpdateWorker(log: ILogger, splitsCache: ISplitsCacheSync, splitsSyncTask: ISplitsSyncTask, splitsEventEmitter: ISplitsEventEmitter, segmentsSyncTask?: ISegmentsSyncTask): IUpdateWorker & {
11
+ killSplit(event: ISplitKillData): void;
12
+ };
@@ -0,0 +1,3 @@
1
+ export declare const FETCH_BACKOFF_BASE = 10000;
2
+ export declare const FETCH_BACKOFF_MAX_WAIT = 60000;
3
+ export declare const FETCH_BACKOFF_MAX_RETRIES = 10;
@@ -1,5 +1,4 @@
1
- import { Backoff } from '../../../utils/Backoff';
2
1
  export interface IUpdateWorker {
3
- readonly backoff: Backoff;
2
+ stop(): void;
4
3
  put(...args: any[]): void;
5
4
  }
@@ -1,6 +1,6 @@
1
1
  import { IMySegmentsUpdateData, IMySegmentsUpdateV2Data, ISegmentUpdateData, ISplitUpdateData, ISplitKillData } from './SSEHandler/types';
2
2
  import { ITask } from '../types';
3
- import { ISegmentsSyncTask } from '../polling/types';
3
+ import { IMySegmentsSyncTask } from '../polling/types';
4
4
  import { IEventEmitter } from '../../types';
5
5
  import { ControlType } from './constants';
6
6
  export declare type PUSH_SUBSYSTEM_UP = 'PUSH_SUBSYSTEM_UP';
@@ -29,7 +29,7 @@ export interface IPushEventEmitter extends IEventEmitter {
29
29
  * PushManager
30
30
  */
31
31
  export interface IPushManager extends ITask, IPushEventEmitter {
32
- add(userKey: string, mySegmentsSyncTask: ISegmentsSyncTask): void;
32
+ add(userKey: string, mySegmentsSyncTask: IMySegmentsSyncTask): void;
33
33
  remove(userKey: string): void;
34
34
  }
35
35
  export {};
@@ -1,9 +1,8 @@
1
1
  import { ILogger } from '../logger/types';
2
2
  import { ISyncTask } from './types';
3
3
  /**
4
- * Creates a syncTask that handles the periodic execution of a given task ("start" and "stop" methods).
5
- * The task can be also executed by calling the "execute" method. Multiple execute calls are chained to run secuentially and avoid race conditions.
6
- * For example, submitters executed on SDK destroy or full queue, while periodic execution is pending.
4
+ * Creates an object that handles the periodic execution of a given task via "start" and "stop" methods.
5
+ * The task can be also executed by calling the "execute" method. Multiple calls run sequentially to avoid race conditions (e.g., submitters executed on SDK destroy or full queue, while periodic execution is pending).
7
6
  *
8
7
  * @param log Logger instance.
9
8
  * @param task Task to execute that returns a promise that NEVER REJECTS. Otherwise, periodic execution can result in Unhandled Promise Rejections.
@@ -1,4 +1,6 @@
1
1
  export declare class Backoff {
2
+ static __TEST__BASE_MILLIS?: number;
3
+ static __TEST__MAX_MILLIS?: number;
2
4
  static DEFAULT_BASE_MILLIS: number;
3
5
  static DEFAULT_MAX_MILLIS: number;
4
6
  baseMillis: number;
@@ -1,33 +0,0 @@
1
- /* eslint-disable no-undef */
2
- /**
3
- * Auto-require script to use with GoogleAnalyticsToSplit integration
4
- */
5
- (function (i, r, s) {
6
- i[s] = i[s] || r;
7
- i[r] = i[r] || function () { i[r].q.push(arguments); };
8
- i[r].q = i[r].q || [];
9
-
10
- var ts = {}; // Tracker names
11
- function n(arg) { return typeof arg === 'object' && typeof arg.name === 'string' && arg.name; }
12
-
13
- function p(v) { // Queue a `require` command if v is a `create` command
14
- if (v && v[0] === 'create') {
15
- var t = n(v[1]) || n(v[2]) || n(v[3]) || (typeof v[3] === 'string' ? v[3] : undefined); // Get tracker name
16
-
17
- if (!ts[t]) {
18
- ts[t] = true;
19
- i[r]((t ? t + '.' : '') + 'require', 'splitTracker'); // Auto-require
20
- }
21
- }
22
- }
23
-
24
- i[r].q.forEach(function (v) { p(v); }); // Process already queued commands
25
-
26
- var o = i[r].q.push;
27
- i[r].q.push = function (v) { // Spy new queued commands
28
- var result = o.apply(this, arguments);
29
- p(v);
30
- return result;
31
- };
32
-
33
- })(window, 'ga', 'GoogleAnalyticsObject');