@splitsoftware/splitio-commons 2.0.0-rc.0 → 2.0.0-rc.2

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 (114) hide show
  1. package/CHANGES.txt +5 -1
  2. package/cjs/evaluator/Engine.js +1 -1
  3. package/cjs/evaluator/index.js +1 -1
  4. package/cjs/readiness/readinessManager.js +13 -2
  5. package/cjs/sdkClient/sdkClientMethodCS.js +0 -1
  6. package/cjs/sdkFactory/index.js +29 -9
  7. package/cjs/storages/{AbstractSegmentsCacheSync.js → AbstractMySegmentsCacheSync.js} +15 -17
  8. package/cjs/storages/dataLoader.js +99 -37
  9. package/cjs/storages/inLocalStorage/MySegmentsCacheInLocal.js +5 -5
  10. package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +3 -2
  11. package/cjs/storages/inLocalStorage/index.js +1 -1
  12. package/cjs/storages/inMemory/InMemoryStorageCS.js +18 -6
  13. package/cjs/storages/inMemory/MySegmentsCacheInMemory.js +5 -5
  14. package/cjs/storages/inMemory/SegmentsCacheInMemory.js +13 -27
  15. package/cjs/storages/inMemory/SplitsCacheInMemory.js +0 -1
  16. package/cjs/storages/inMemory/UniqueKeysCacheInMemory.js +2 -1
  17. package/cjs/storages/inMemory/UniqueKeysCacheInMemoryCS.js +2 -1
  18. package/cjs/storages/inRedis/RedisAdapter.js +2 -1
  19. package/cjs/storages/inRedis/SegmentsCacheInRedis.js +13 -19
  20. package/cjs/storages/inRedis/UniqueKeysCacheInRedis.js +2 -1
  21. package/cjs/storages/pluggable/SegmentsCachePluggable.js +11 -32
  22. package/cjs/storages/pluggable/UniqueKeysCachePluggable.js +2 -1
  23. package/cjs/storages/pluggable/inMemoryWrapper.js +2 -1
  24. package/cjs/sync/offline/syncManagerOffline.js +18 -11
  25. package/cjs/sync/polling/updaters/segmentChangesUpdater.js +12 -28
  26. package/cjs/sync/polling/updaters/splitChangesUpdater.js +2 -1
  27. package/cjs/sync/syncManagerOnline.js +20 -21
  28. package/cjs/trackers/eventTracker.js +12 -10
  29. package/cjs/trackers/impressionsTracker.js +16 -14
  30. package/cjs/trackers/uniqueKeysTracker.js +5 -3
  31. package/cjs/utils/lang/sets.js +12 -2
  32. package/esm/evaluator/Engine.js +1 -1
  33. package/esm/evaluator/index.js +2 -2
  34. package/esm/readiness/readinessManager.js +13 -2
  35. package/esm/sdkClient/sdkClientMethodCS.js +0 -1
  36. package/esm/sdkFactory/index.js +30 -10
  37. package/esm/storages/{AbstractSegmentsCacheSync.js → AbstractMySegmentsCacheSync.js} +14 -16
  38. package/esm/storages/dataLoader.js +96 -35
  39. package/esm/storages/inLocalStorage/MySegmentsCacheInLocal.js +5 -5
  40. package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +3 -2
  41. package/esm/storages/inLocalStorage/index.js +1 -1
  42. package/esm/storages/inMemory/InMemoryStorageCS.js +18 -6
  43. package/esm/storages/inMemory/MySegmentsCacheInMemory.js +5 -5
  44. package/esm/storages/inMemory/SegmentsCacheInMemory.js +13 -27
  45. package/esm/storages/inMemory/SplitsCacheInMemory.js +0 -1
  46. package/esm/storages/inMemory/UniqueKeysCacheInMemory.js +2 -1
  47. package/esm/storages/inMemory/UniqueKeysCacheInMemoryCS.js +2 -1
  48. package/esm/storages/inRedis/RedisAdapter.js +2 -1
  49. package/esm/storages/inRedis/SegmentsCacheInRedis.js +13 -19
  50. package/esm/storages/inRedis/UniqueKeysCacheInRedis.js +2 -1
  51. package/esm/storages/pluggable/SegmentsCachePluggable.js +11 -32
  52. package/esm/storages/pluggable/UniqueKeysCachePluggable.js +2 -1
  53. package/esm/storages/pluggable/inMemoryWrapper.js +2 -1
  54. package/esm/sync/offline/syncManagerOffline.js +18 -11
  55. package/esm/sync/polling/updaters/segmentChangesUpdater.js +12 -28
  56. package/esm/sync/polling/updaters/splitChangesUpdater.js +2 -1
  57. package/esm/sync/syncManagerOnline.js +20 -21
  58. package/esm/trackers/eventTracker.js +12 -10
  59. package/esm/trackers/impressionsTracker.js +16 -14
  60. package/esm/trackers/uniqueKeysTracker.js +5 -3
  61. package/esm/utils/lang/sets.js +10 -1
  62. package/package.json +1 -1
  63. package/src/evaluator/Engine.ts +1 -1
  64. package/src/evaluator/index.ts +2 -2
  65. package/src/readiness/readinessManager.ts +12 -3
  66. package/src/readiness/types.ts +3 -0
  67. package/src/sdkClient/sdkClientMethodCS.ts +0 -2
  68. package/src/sdkFactory/index.ts +34 -12
  69. package/src/sdkFactory/types.ts +2 -0
  70. package/src/storages/{AbstractSegmentsCacheSync.ts → AbstractMySegmentsCacheSync.ts} +13 -28
  71. package/src/storages/dataLoader.ts +97 -38
  72. package/src/storages/inLocalStorage/MySegmentsCacheInLocal.ts +5 -5
  73. package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +3 -2
  74. package/src/storages/inLocalStorage/index.ts +1 -1
  75. package/src/storages/inMemory/InMemoryStorageCS.ts +21 -6
  76. package/src/storages/inMemory/MySegmentsCacheInMemory.ts +5 -5
  77. package/src/storages/inMemory/SegmentsCacheInMemory.ts +12 -26
  78. package/src/storages/inMemory/SplitsCacheInMemory.ts +0 -1
  79. package/src/storages/inMemory/UniqueKeysCacheInMemory.ts +2 -1
  80. package/src/storages/inMemory/UniqueKeysCacheInMemoryCS.ts +2 -1
  81. package/src/storages/inRedis/RedisAdapter.ts +2 -1
  82. package/src/storages/inRedis/SegmentsCacheInRedis.ts +13 -22
  83. package/src/storages/inRedis/UniqueKeysCacheInRedis.ts +2 -1
  84. package/src/storages/pluggable/SegmentsCachePluggable.ts +11 -35
  85. package/src/storages/pluggable/UniqueKeysCachePluggable.ts +2 -1
  86. package/src/storages/pluggable/inMemoryWrapper.ts +2 -1
  87. package/src/storages/types.ts +7 -11
  88. package/src/sync/offline/syncManagerOffline.ts +21 -13
  89. package/src/sync/polling/updaters/segmentChangesUpdater.ts +13 -29
  90. package/src/sync/polling/updaters/splitChangesUpdater.ts +2 -1
  91. package/src/sync/syncManagerOnline.ts +17 -17
  92. package/src/sync/types.ts +1 -1
  93. package/src/trackers/eventTracker.ts +11 -8
  94. package/src/trackers/impressionsTracker.ts +13 -10
  95. package/src/trackers/types.ts +1 -0
  96. package/src/trackers/uniqueKeysTracker.ts +6 -4
  97. package/src/types.ts +14 -13
  98. package/src/utils/lang/sets.ts +11 -1
  99. package/types/readiness/types.d.ts +3 -0
  100. package/types/sdkFactory/types.d.ts +1 -0
  101. package/types/storages/dataLoader.d.ts +17 -6
  102. package/types/storages/inLocalStorage/MySegmentsCacheInLocal.d.ts +5 -5
  103. package/types/storages/inMemory/MySegmentsCacheInMemory.d.ts +5 -5
  104. package/types/storages/inMemory/SegmentsCacheInMemory.d.ts +5 -7
  105. package/types/storages/inMemory/SplitsCacheInMemory.d.ts +0 -1
  106. package/types/storages/inRedis/SegmentsCacheInRedis.d.ts +6 -3
  107. package/types/storages/pluggable/SegmentsCachePluggable.d.ts +4 -16
  108. package/types/storages/types.d.ts +7 -10
  109. package/types/sync/types.d.ts +1 -1
  110. package/types/trackers/eventTracker.d.ts +1 -1
  111. package/types/trackers/impressionsTracker.d.ts +1 -1
  112. package/types/trackers/types.d.ts +1 -0
  113. package/types/types.d.ts +13 -13
  114. package/types/utils/lang/sets.d.ts +1 -0
@@ -1,19 +1,17 @@
1
- import { AbstractSegmentsCacheSync } from '../AbstractSegmentsCacheSync';
1
+ import { ISegmentsCacheSync } from '../types';
2
2
  /**
3
- * Default ISplitsCacheSync implementation that stores split definitions in memory.
4
- * Supported by all JS runtimes.
3
+ * Default ISplitsCacheSync implementation for server-side that stores segments definitions in memory.
5
4
  */
6
- export declare class SegmentsCacheInMemory extends AbstractSegmentsCacheSync {
5
+ export declare class SegmentsCacheInMemory implements ISegmentsCacheSync {
7
6
  private segmentCache;
8
7
  private segmentChangeNumber;
9
- addToSegment(name: string, segmentKeys: string[]): boolean;
10
- removeFromSegment(name: string, segmentKeys: string[]): boolean;
8
+ update(name: string, addedKeys: string[], removedKeys: string[], changeNumber: number): boolean;
11
9
  isInSegment(name: string, key: string): boolean;
12
10
  clear(): void;
13
11
  private _registerSegment;
14
12
  registerSegments(names: string[]): boolean;
15
13
  getRegisteredSegments(): string[];
16
14
  getKeysCount(): number;
17
- setChangeNumber(name: string, changeNumber: number): boolean;
18
15
  getChangeNumber(name: string): number;
16
+ resetSegments(): boolean;
19
17
  }
@@ -2,7 +2,6 @@ import { ISplit, ISplitFiltersValidation } from '../../dtos/types';
2
2
  import { AbstractSplitsCacheSync } from '../AbstractSplitsCacheSync';
3
3
  /**
4
4
  * Default ISplitsCacheSync implementation that stores split definitions in memory.
5
- * Supported by all JS runtimes.
6
5
  */
7
6
  export declare class SplitsCacheInMemory extends AbstractSplitsCacheSync {
8
7
  private flagSetsFilter;
@@ -7,10 +7,13 @@ export declare class SegmentsCacheInRedis implements ISegmentsCacheAsync {
7
7
  private readonly redis;
8
8
  private readonly keys;
9
9
  constructor(log: ILogger, keys: KeyBuilderSS, redis: RedisAdapter);
10
- addToSegment(name: string, segmentKeys: string[]): Promise<boolean>;
11
- removeFromSegment(name: string, segmentKeys: string[]): Promise<boolean>;
10
+ /**
11
+ * Update the given segment `name` with the lists of `addedKeys`, `removedKeys` and `changeNumber`.
12
+ * The returned promise is resolved if the operation success, with `true` if the segment was updated (i.e., some key was added or removed),
13
+ * or rejected if it fails (e.g., Redis operation fails).
14
+ */
15
+ update(name: string, addedKeys: string[], removedKeys: string[], changeNumber: number): Promise<boolean>;
12
16
  isInSegment(name: string, key: string): Promise<boolean>;
13
- setChangeNumber(name: string, changeNumber: number): Promise<boolean>;
14
17
  getChangeNumber(name: string): Promise<number>;
15
18
  registerSegments(segments: string[]): Promise<boolean>;
16
19
  getRegisteredSegments(): Promise<string[]>;
@@ -10,28 +10,16 @@ export declare class SegmentsCachePluggable implements ISegmentsCacheAsync {
10
10
  private readonly wrapper;
11
11
  constructor(log: ILogger, keys: KeyBuilderSS, wrapper: IPluggableStorageWrapper);
12
12
  /**
13
- * Add a list of `segmentKeys` to the given segment `name`.
14
- * The returned promise is resolved when the operation success
15
- * or rejected if wrapper operation fails.
16
- */
17
- addToSegment(name: string, segmentKeys: string[]): Promise<boolean | void>;
18
- /**
19
- * Remove a list of `segmentKeys` from the given segment `name`.
20
- * The returned promise is resolved when the operation success
21
- * or rejected if wrapper operation fails.
13
+ * Update the given segment `name` with the lists of `addedKeys`, `removedKeys` and `changeNumber`.
14
+ * The returned promise is resolved if the operation success, with `true` if the segment was updated (i.e., some key was added or removed),
15
+ * or rejected if it fails (e.g., wrapper operation fails).
22
16
  */
23
- removeFromSegment(name: string, segmentKeys: string[]): Promise<boolean | void>;
17
+ update(name: string, addedKeys: string[], removedKeys: string[], changeNumber: number): Promise<boolean>;
24
18
  /**
25
19
  * Returns a promise that resolves with a boolean value indicating if `key` is part of `name` segment.
26
20
  * Promise can be rejected if wrapper operation fails.
27
21
  */
28
22
  isInSegment(name: string, key: string): Promise<boolean>;
29
- /**
30
- * Set till number for the given segment `name`.
31
- * The returned promise is resolved when the operation success,
32
- * or rejected if it fails (e.g., wrapper operation fails).
33
- */
34
- setChangeNumber(name: string, changeNumber: number): Promise<boolean | void>;
35
23
  /**
36
24
  * Get till number or -1 if it's not defined.
37
25
  * The returned promise is resolved with the changeNumber or -1 if it doesn't exist or a wrapper operation fails.
@@ -229,35 +229,29 @@ export interface ISplitsCacheAsync extends ISplitsCacheBase {
229
229
  }
230
230
  /** Segments cache */
231
231
  export interface ISegmentsCacheBase {
232
- addToSegment(name: string, segmentKeys: string[]): MaybeThenable<boolean | void>;
233
- removeFromSegment(name: string, segmentKeys: string[]): MaybeThenable<boolean | void>;
234
232
  isInSegment(name: string, key?: string): MaybeThenable<boolean>;
235
233
  registerSegments(names: string[]): MaybeThenable<boolean | void>;
236
234
  getRegisteredSegments(): MaybeThenable<string[]>;
237
- setChangeNumber(name: string, changeNumber: number): MaybeThenable<boolean | void>;
238
235
  getChangeNumber(name: string): MaybeThenable<number>;
236
+ update(name: string, addedKeys: string[], removedKeys: string[], changeNumber: number): MaybeThenable<boolean>;
239
237
  clear(): MaybeThenable<boolean | void>;
240
238
  }
241
239
  export interface ISegmentsCacheSync extends ISegmentsCacheBase {
242
- addToSegment(name: string, segmentKeys?: string[]): boolean;
243
- removeFromSegment(name: string, segmentKeys?: string[]): boolean;
244
240
  isInSegment(name: string, key?: string): boolean;
245
241
  registerSegments(names: string[]): boolean;
246
242
  getRegisteredSegments(): string[];
247
243
  getKeysCount(): number;
248
- setChangeNumber(name: string, changeNumber: number): boolean | void;
249
244
  getChangeNumber(name?: string): number;
245
+ update(name: string, addedKeys: string[], removedKeys: string[], changeNumber: number): boolean;
250
246
  resetSegments(segmentsData: MySegmentsData | IMySegmentsResponse): boolean;
251
247
  clear(): void;
252
248
  }
253
249
  export interface ISegmentsCacheAsync extends ISegmentsCacheBase {
254
- addToSegment(name: string, segmentKeys: string[]): Promise<boolean | void>;
255
- removeFromSegment(name: string, segmentKeys: string[]): Promise<boolean | void>;
256
250
  isInSegment(name: string, key: string): Promise<boolean>;
257
251
  registerSegments(names: string[]): Promise<boolean | void>;
258
252
  getRegisteredSegments(): Promise<string[]>;
259
- setChangeNumber(name: string, changeNumber: number): Promise<boolean | void>;
260
253
  getChangeNumber(name: string): Promise<number>;
254
+ update(name: string, addedKeys: string[], removedKeys: string[], changeNumber: number): Promise<boolean>;
261
255
  clear(): Promise<boolean | void>;
262
256
  }
263
257
  /** Recorder storages (impressions, events and telemetry) */
@@ -393,7 +387,6 @@ export interface IStorageSync extends IStorageBase<ISplitsCacheSync, ISegmentsCa
393
387
  export interface IStorageAsync extends IStorageBase<ISplitsCacheAsync, ISegmentsCacheAsync, IImpressionsCacheAsync | IImpressionsCacheSync, IImpressionCountsCacheBase, IEventsCacheAsync | IEventsCacheSync, ITelemetryCacheAsync | ITelemetryCacheSync, IUniqueKeysCacheBase> {
394
388
  }
395
389
  /** StorageFactory */
396
- export declare type DataLoader = (storage: IStorageSync, matchingKey: string) => void;
397
390
  export interface IStorageFactoryParams {
398
391
  settings: ISettings;
399
392
  /**
@@ -401,6 +394,10 @@ export interface IStorageFactoryParams {
401
394
  * It is meant for emitting SDK_READY event in consumer mode, and waiting before using the storage in the synchronizer.
402
395
  */
403
396
  onReadyCb: (error?: any) => void;
397
+ /**
398
+ * It is meant for emitting SDK_READY_FROM_CACHE event in standalone mode with preloaded data
399
+ */
400
+ onReadyFromCacheCb: () => void;
404
401
  }
405
402
  export declare type StorageType = 'MEMORY' | 'LOCALSTORAGE' | 'REDIS' | 'PLUGGABLE';
406
403
  export declare type IStorageSyncFactory = {
@@ -39,5 +39,5 @@ export interface ISyncManager extends ITask {
39
39
  submitterManager?: ISubmitterManager;
40
40
  }
41
41
  export interface ISyncManagerCS extends ISyncManager {
42
- shared(matchingKey: string, readinessManager: IReadinessManager, storage: IStorageSync): ISyncManager | undefined;
42
+ shared(matchingKey: string, readinessManager: IReadinessManager, storage: IStorageSync): Pick<ISyncManager, 'stop' | 'flush'> | undefined;
43
43
  }
@@ -7,4 +7,4 @@ import { ISettings } from '../types';
7
7
  * @param eventsCache cache to save events
8
8
  * @param integrationsManager optional event handler used for integrations
9
9
  */
10
- export declare function eventTrackerFactory(settings: ISettings, eventsCache: IEventsCacheBase, integrationsManager?: IEventsHandler, telemetryCache?: ITelemetryCacheSync | ITelemetryCacheAsync): IEventTracker;
10
+ export declare function eventTrackerFactory(settings: ISettings, eventsCache: IEventsCacheBase, whenInit: (cb: () => void) => void, integrationsManager?: IEventsHandler, telemetryCache?: ITelemetryCacheSync | ITelemetryCacheAsync): IEventTracker;
@@ -10,4 +10,4 @@ import { ISettings } from '../types';
10
10
  * @param integrationsManager optional integrations manager
11
11
  * @param strategy strategy for impressions tracking.
12
12
  */
13
- export declare function impressionsTrackerFactory(settings: ISettings, impressionsCache: IImpressionsCacheBase, strategy: IStrategy, integrationsManager?: IImpressionsHandler, telemetryCache?: ITelemetryCacheSync | ITelemetryCacheAsync): IImpressionsTracker;
13
+ export declare function impressionsTrackerFactory(settings: ISettings, impressionsCache: IImpressionsCacheBase, strategy: IStrategy, whenInit: (cb: () => void) => void, integrationsManager?: IImpressionsHandler, telemetryCache?: ITelemetryCacheSync | ITelemetryCacheAsync): IImpressionsTracker;
@@ -54,6 +54,7 @@ export interface IImpressionSenderAdapter {
54
54
  }
55
55
  /** Unique keys tracker */
56
56
  export interface IUniqueKeysTracker {
57
+ start(): void;
57
58
  stop(): void;
58
59
  track(key: string, featureName: string): void;
59
60
  }
package/types/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ISplitFiltersValidation } from './dtos/types';
1
+ import { IMembershipsResponse, ISplit, ISplitFiltersValidation } from './dtos/types';
2
2
  import { IIntegration, IIntegrationFactoryParams } from './integrations/types';
3
3
  import { ILogger } from './logger/types';
4
4
  import { ISdkFactoryContext } from './sdkFactory/types';
@@ -91,6 +91,7 @@ export interface ISettings {
91
91
  eventsFirstPushWindow: number;
92
92
  };
93
93
  readonly storage: IStorageSyncFactory | IStorageAsyncFactory;
94
+ readonly preloadedData?: SplitIO.PreloadedData;
94
95
  readonly integrations: Array<{
95
96
  readonly type: string;
96
97
  (params: IIntegrationFactoryParams): IIntegration | void;
@@ -769,31 +770,30 @@ export declare namespace SplitIO {
769
770
  * If this value is older than 10 days ago (expiration time policy), the data is not used to update the storage content.
770
771
  * @TODO configurable expiration time policy?
771
772
  */
772
- lastUpdated: number;
773
773
  /**
774
774
  * Change number of the preloaded data.
775
775
  * If this value is older than the current changeNumber at the storage, the data is not used to update the storage content.
776
776
  */
777
777
  since: number;
778
778
  /**
779
- * Map of feature flags to their stringified definitions.
779
+ * List of feature flag definitions.
780
+ * @TODO rename to flags
780
781
  */
781
- splitsData: {
782
- [splitName: string]: string;
783
- };
782
+ splitsData: ISplit[];
784
783
  /**
785
- * Optional map of user keys to their list of segments.
786
- * @TODO remove when releasing first version
784
+ * Optional map of user keys to their memberships.
785
+ * @TODO rename to memberships
787
786
  */
788
- mySegmentsData?: {
789
- [key: string]: string[];
787
+ membershipsData?: {
788
+ [key: string]: IMembershipsResponse;
790
789
  };
791
790
  /**
792
- * Optional map of segments to their stringified definitions.
793
- * This property is ignored if `mySegmentsData` was provided.
791
+ * Optional map of segments to their list of keys.
792
+ * This property is ignored if `membershipsData` was provided.
793
+ * @TODO rename to segments
794
794
  */
795
795
  segmentsData?: {
796
- [segmentName: string]: string;
796
+ [segmentName: string]: string[];
797
797
  };
798
798
  }
799
799
  /**
@@ -1,2 +1,3 @@
1
+ export declare function setToArray<T>(set: Set<T>): T[];
1
2
  export declare function returnSetsUnion<T>(set: Set<T>, set2: Set<T>): Set<T>;
2
3
  export declare function returnDifference<T>(list?: T[], list2?: T[]): T[];