@splitsoftware/splitio-commons 0.1.1-rc.20 → 1.0.1-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 (97) hide show
  1. package/CHANGES.txt +9 -0
  2. package/README.md +3 -2
  3. package/cjs/listeners/browser.js +3 -1
  4. package/cjs/logger/constants.js +4 -4
  5. package/cjs/logger/messages/error.js +2 -1
  6. package/cjs/logger/messages/warn.js +0 -1
  7. package/cjs/sdkClient/sdkClient.js +4 -4
  8. package/cjs/sdkClient/sdkClientMethodCS.js +16 -5
  9. package/cjs/sdkClient/sdkClientMethodCSWithTT.js +17 -6
  10. package/cjs/sdkFactory/index.js +6 -3
  11. package/cjs/storages/inMemory/InMemoryStorage.js +0 -3
  12. package/cjs/storages/inRedis/index.js +1 -2
  13. package/cjs/storages/pluggable/SplitsCachePluggable.js +1 -1
  14. package/cjs/storages/pluggable/inMemoryWrapper.js +19 -5
  15. package/cjs/storages/pluggable/index.js +38 -15
  16. package/cjs/storages/pluggable/wrapperAdapter.js +3 -3
  17. package/cjs/sync/polling/updaters/mySegmentsUpdater.js +1 -1
  18. package/cjs/sync/streaming/UpdateWorkers/SplitsUpdateWorker.js +0 -1
  19. package/cjs/sync/submitters/submitterManager.js +19 -0
  20. package/cjs/sync/syncManagerOnline.js +20 -26
  21. package/cjs/trackers/impressionObserver/utils.js +1 -1
  22. package/cjs/utils/constants/index.js +3 -2
  23. package/cjs/utils/settingsValidation/mode.js +1 -1
  24. package/cjs/utils/settingsValidation/storage/storageCS.js +17 -3
  25. package/esm/listeners/browser.js +3 -1
  26. package/esm/logger/constants.js +3 -3
  27. package/esm/logger/messages/error.js +2 -1
  28. package/esm/logger/messages/warn.js +0 -1
  29. package/esm/sdkClient/sdkClient.js +5 -5
  30. package/esm/sdkClient/sdkClientMethodCS.js +16 -5
  31. package/esm/sdkClient/sdkClientMethodCSWithTT.js +17 -6
  32. package/esm/sdkFactory/index.js +6 -3
  33. package/esm/storages/inMemory/InMemoryStorage.js +0 -3
  34. package/esm/storages/inRedis/index.js +1 -2
  35. package/esm/storages/pluggable/SplitsCachePluggable.js +1 -1
  36. package/esm/storages/pluggable/inMemoryWrapper.js +19 -5
  37. package/esm/storages/pluggable/index.js +40 -16
  38. package/esm/storages/pluggable/wrapperAdapter.js +3 -3
  39. package/esm/sync/polling/updaters/mySegmentsUpdater.js +1 -1
  40. package/esm/sync/streaming/UpdateWorkers/SplitsUpdateWorker.js +0 -1
  41. package/esm/sync/submitters/submitterManager.js +15 -0
  42. package/esm/sync/syncManagerOnline.js +20 -26
  43. package/esm/trackers/impressionObserver/utils.js +2 -2
  44. package/esm/utils/constants/index.js +2 -1
  45. package/esm/utils/settingsValidation/mode.js +2 -2
  46. package/esm/utils/settingsValidation/storage/storageCS.js +19 -5
  47. package/package.json +1 -1
  48. package/src/listeners/browser.ts +3 -1
  49. package/src/logger/constants.ts +3 -3
  50. package/src/logger/messages/error.ts +2 -1
  51. package/src/logger/messages/warn.ts +0 -1
  52. package/src/sdkClient/sdkClient.ts +6 -6
  53. package/src/sdkClient/sdkClientMethodCS.ts +14 -4
  54. package/src/sdkClient/sdkClientMethodCSWithTT.ts +15 -5
  55. package/src/sdkFactory/index.ts +7 -3
  56. package/src/services/splitApi.ts +4 -1
  57. package/src/storages/inLocalStorage/index.ts +2 -2
  58. package/src/storages/inMemory/InMemoryStorage.ts +0 -3
  59. package/src/storages/inMemory/InMemoryStorageCS.ts +2 -2
  60. package/src/storages/inRedis/index.ts +1 -1
  61. package/src/storages/pluggable/EventsCachePluggable.ts +3 -3
  62. package/src/storages/pluggable/ImpressionsCachePluggable.ts +3 -3
  63. package/src/storages/pluggable/SegmentsCachePluggable.ts +3 -3
  64. package/src/storages/pluggable/SplitsCachePluggable.ts +4 -4
  65. package/src/storages/pluggable/inMemoryWrapper.ts +20 -6
  66. package/src/storages/pluggable/index.ts +46 -16
  67. package/src/storages/pluggable/wrapperAdapter.ts +5 -5
  68. package/src/storages/types.ts +24 -24
  69. package/src/sync/polling/updaters/mySegmentsUpdater.ts +1 -1
  70. package/src/sync/streaming/UpdateWorkers/SplitsUpdateWorker.ts +0 -1
  71. package/src/sync/submitters/submitterManager.ts +22 -0
  72. package/src/sync/syncManagerOnline.ts +26 -32
  73. package/src/sync/types.ts +1 -1
  74. package/src/trackers/impressionObserver/ImpressionObserver.ts +1 -1
  75. package/src/trackers/impressionObserver/utils.ts +2 -2
  76. package/src/types.ts +5 -5
  77. package/src/utils/constants/index.ts +6 -4
  78. package/src/utils/settingsValidation/mode.ts +2 -2
  79. package/src/utils/settingsValidation/storage/storageCS.ts +21 -8
  80. package/types/logger/constants.d.ts +3 -3
  81. package/types/services/splitApi.d.ts +1 -1
  82. package/types/storages/inMemory/InMemoryStorageCS.d.ts +2 -2
  83. package/types/storages/pluggable/EventsCachePluggable.d.ts +2 -2
  84. package/types/storages/pluggable/ImpressionsCachePluggable.d.ts +2 -2
  85. package/types/storages/pluggable/SegmentsCachePluggable.d.ts +5 -5
  86. package/types/storages/pluggable/SplitsCachePluggable.d.ts +3 -3
  87. package/types/storages/pluggable/inMemoryWrapper.d.ts +6 -3
  88. package/types/storages/pluggable/index.d.ts +2 -2
  89. package/types/storages/pluggable/wrapperAdapter.d.ts +4 -4
  90. package/types/storages/types.d.ts +21 -22
  91. package/types/sync/submitters/submitterManager.d.ts +4 -0
  92. package/types/sync/syncManagerOnline.d.ts +1 -1
  93. package/types/sync/types.d.ts +1 -1
  94. package/types/trackers/impressionObserver/ImpressionObserver.d.ts +1 -1
  95. package/types/types.d.ts +5 -5
  96. package/types/utils/constants/index.d.ts +6 -4
  97. package/types/utils/settingsValidation/storage/storageCS.d.ts +6 -4
@@ -1,7 +1,7 @@
1
- import { ICustomStorageWrapper, IStorageAsyncFactory } from '../types';
1
+ import { IPluggableStorageWrapper, IStorageAsyncFactory } from '../types';
2
2
  export interface PluggableStorageOptions {
3
3
  prefix?: string;
4
- wrapper: ICustomStorageWrapper;
4
+ wrapper: IPluggableStorageWrapper;
5
5
  }
6
6
  /**
7
7
  * Pluggable storage factory for consumer server-side & client-side SplitFactory.
@@ -1,12 +1,12 @@
1
1
  import { ILogger } from '../../logger/types';
2
- import { ICustomStorageWrapper } from '../types';
2
+ import { IPluggableStorageWrapper } from '../types';
3
3
  export declare const METHODS_TO_PROMISE_WRAP: string[];
4
4
  /**
5
- * Adapter of the Custom Storage Wrapper.
5
+ * Adapter of the Pluggable Storage Wrapper.
6
6
  * Used to handle exceptions as rejected promises, in order to simplify the error handling on storages.
7
7
  *
8
8
  * @param log logger instance
9
- * @param wrapper custom storage wrapper to adapt
9
+ * @param wrapper storage wrapper to adapt
10
10
  * @returns an adapted version of the given storage wrapper
11
11
  */
12
- export declare function wrapperAdapter(log: ILogger, wrapper: ICustomStorageWrapper): ICustomStorageWrapper;
12
+ export declare function wrapperAdapter(log: ILogger, wrapper: IPluggableStorageWrapper): IPluggableStorageWrapper;
@@ -1,11 +1,11 @@
1
1
  import { MaybeThenable, IMetadata, ISplitFiltersValidation } from '../dtos/types';
2
2
  import { ILogger } from '../logger/types';
3
3
  import { StoredEventWithMetadata, StoredImpressionWithMetadata } from '../sync/submitters/types';
4
- import { SplitIO, ImpressionDTO } from '../types';
4
+ import { SplitIO, ImpressionDTO, SDKMode } from '../types';
5
5
  /**
6
- * Interface of a custom wrapper storage.
6
+ * Interface of a pluggable storage wrapper.
7
7
  */
8
- export interface ICustomStorageWrapper {
8
+ export interface IPluggableStorageWrapper {
9
9
  /** Key-Value operations */
10
10
  /**
11
11
  * Get the value of given `key`.
@@ -25,7 +25,7 @@ export interface ICustomStorageWrapper {
25
25
  * @returns {Promise<void>} A promise that resolves if the operation success, whether the key was added or updated.
26
26
  * The promise rejects if the operation fails.
27
27
  */
28
- set: (key: string, value: string) => Promise<void | boolean>;
28
+ set: (key: string, value: string) => Promise<boolean | void>;
29
29
  /**
30
30
  * Add or update an item with a specified `key` and `value`.
31
31
  *
@@ -44,7 +44,7 @@ export interface ICustomStorageWrapper {
44
44
  * @returns {Promise<void>} A promise that resolves if the operation success, whether the key existed and was removed or it didn't exist.
45
45
  * The promise rejects if the operation fails, for example, if there is a connection error.
46
46
  */
47
- del: (key: string) => Promise<void | boolean>;
47
+ del: (key: string) => Promise<boolean | void>;
48
48
  /**
49
49
  * Returns all keys matching the given prefix.
50
50
  *
@@ -131,20 +131,20 @@ export interface ICustomStorageWrapper {
131
131
  * @function addItems
132
132
  * @param {string} key Set key
133
133
  * @param {string} items Items to add
134
- * @returns {Promise<void>} A promise that resolves if the operation success.
134
+ * @returns {Promise<boolean | void>} A promise that resolves if the operation success.
135
135
  * The promise rejects if the operation fails, for example, if there is a connection error or the key holds a value that is not a set.
136
136
  */
137
- addItems: (key: string, items: string[]) => Promise<void>;
137
+ addItems: (key: string, items: string[]) => Promise<boolean | void>;
138
138
  /**
139
139
  * Remove the specified `items` from the set stored at `key`. Those items that are not part of the set are ignored.
140
140
  *
141
141
  * @function removeItems
142
142
  * @param {string} key Set key
143
143
  * @param {string} items Items to remove
144
- * @returns {Promise<void>} A promise that resolves if the operation success. If key does not exist, the promise also resolves.
144
+ * @returns {Promise<boolean | void>} A promise that resolves if the operation success. If key does not exist, the promise also resolves.
145
145
  * The promise rejects if the operation fails, for example, if there is a connection error or the key holds a value that is not a set.
146
146
  */
147
- removeItems: (key: string, items: string[]) => Promise<void>;
147
+ removeItems: (key: string, items: string[]) => Promise<boolean | void>;
148
148
  /**
149
149
  * Returns all the items of the `key` set.
150
150
  *
@@ -158,7 +158,7 @@ export interface ICustomStorageWrapper {
158
158
  /**
159
159
  * Connects to the underlying storage.
160
160
  * It is meant for storages that requires to be connected to some database or server. Otherwise it can just return a resolved promise.
161
- * Note: will be called once on SplitFactory instantiation.
161
+ * Note: will be called once on SplitFactory instantiation and once per each shared client instantiation.
162
162
  *
163
163
  * @function connect
164
164
  * @returns {Promise<void>} A promise that resolves when the wrapper successfully connect to the underlying storage.
@@ -166,15 +166,15 @@ export interface ICustomStorageWrapper {
166
166
  */
167
167
  connect: () => Promise<void>;
168
168
  /**
169
- * Disconnects the underlying storage.
169
+ * Disconnects from the underlying storage.
170
170
  * It is meant for storages that requires to be closed, in order to release resources. Otherwise it can just return a resolved promise.
171
- * Note: will be called once on SplitFactory client destroy.
171
+ * Note: will be called once on SplitFactory main client destroy.
172
172
  *
173
- * @function close
173
+ * @function disconnect
174
174
  * @returns {Promise<void>} A promise that resolves when the operation ends.
175
175
  * The promise never rejects.
176
176
  */
177
- close: () => Promise<void>;
177
+ disconnect: () => Promise<void>;
178
178
  }
179
179
  /** Splits cache */
180
180
  export interface ISplitsCacheBase {
@@ -247,7 +247,7 @@ export interface ISegmentsCacheSync extends ISegmentsCacheBase {
247
247
  export interface ISegmentsCacheAsync extends ISegmentsCacheBase {
248
248
  addToSegment(name: string, segmentKeys: string[]): Promise<boolean | void>;
249
249
  removeFromSegment(name: string, segmentKeys: string[]): Promise<boolean | void>;
250
- isInSegment(name: string, key?: string): Promise<boolean>;
250
+ isInSegment(name: string, key: string): Promise<boolean>;
251
251
  registerSegments(names: string[]): Promise<boolean | void>;
252
252
  getRegisteredSegments(): Promise<string[]>;
253
253
  setChangeNumber(name: string, changeNumber: number): Promise<boolean | void>;
@@ -326,13 +326,11 @@ export interface IStorageBase<TSplitsCache extends ISplitsCacheBase, TSegmentsCa
326
326
  events: TEventsCache;
327
327
  latencies?: TLatenciesCache;
328
328
  counts?: TCountsCache;
329
- destroy(): void;
329
+ destroy(): void | Promise<void>;
330
+ shared?: (matchingKey: string, onReadyCb: (error?: any) => void) => this;
330
331
  }
331
332
  export declare type IStorageSync = IStorageBase<ISplitsCacheSync, ISegmentsCacheSync, IImpressionsCacheSync, IEventsCacheSync, ILatenciesCacheSync, ICountsCacheSync>;
332
- export interface IStorageSyncCS extends IStorageSync {
333
- shared(matchingKey: string): IStorageSync;
334
- }
335
- export declare type IStorageAsync = IStorageBase<ISplitsCacheAsync, ISegmentsCacheAsync, IImpressionsCacheAsync, IEventsCacheAsync, ILatenciesCacheAsync, ICountsCacheAsync>;
333
+ export declare type IStorageAsync = IStorageBase<ISplitsCacheAsync, ISegmentsCacheAsync, IImpressionsCacheAsync | IImpressionsCacheSync, IEventsCacheAsync | IEventsCacheSync, ILatenciesCacheAsync, ICountsCacheAsync>;
336
334
  /** StorageFactory */
337
335
  export declare type DataLoader = (storage: IStorageSync, matchingKey: string) => void;
338
336
  export interface IStorageFactoryParams {
@@ -341,10 +339,11 @@ export interface IStorageFactoryParams {
341
339
  optimize?: boolean;
342
340
  matchingKey?: string;
343
341
  splitFiltersValidation?: ISplitFiltersValidation;
344
- onReadyCb?: (error?: any) => void;
342
+ mode?: SDKMode;
343
+ onReadyCb: (error?: any) => void;
345
344
  metadata: IMetadata;
346
345
  }
347
- export declare type StorageType = 'MEMORY' | 'LOCALSTORAGE' | 'REDIS' | 'CUSTOM';
346
+ export declare type StorageType = 'MEMORY' | 'LOCALSTORAGE' | 'REDIS' | 'PLUGGABLE';
348
347
  export declare type IStorageSyncFactory = {
349
348
  type: StorageType;
350
349
  (params: IStorageFactoryParams): IStorageSync;
@@ -0,0 +1,4 @@
1
+ import { ISplitApi } from '../../services/types';
2
+ import { IStorageSync } from '../../storages/types';
3
+ import { ISettings } from '../../types';
4
+ export declare function submitterManagerFactory(settings: ISettings, storage: IStorageSync, splitApi: ISplitApi): import("../types").ISyncTask<[], any>;
@@ -9,4 +9,4 @@ import { IPollingManager, IPollingManagerFactoryParams } from './polling/types';
9
9
  * `pollingManagerSSFactory` or `pollingManagerCSFactory` respectively.
10
10
  * @param pushManagerFactory optional to build a SyncManager with or without streaming support
11
11
  */
12
- export declare function syncManagerOnlineFactory(pollingManagerFactory: (...args: IPollingManagerFactoryParams) => IPollingManager, pushManagerFactory?: (...args: IPushManagerFactoryParams) => IPushManager | undefined): (params: ISyncManagerFactoryParams) => ISyncManagerCS;
12
+ export declare function syncManagerOnlineFactory(pollingManagerFactory?: (...args: IPollingManagerFactoryParams) => IPollingManager, pushManagerFactory?: (...args: IPushManagerFactoryParams) => IPushManager | undefined): (params: ISyncManagerFactoryParams) => ISyncManagerCS;
@@ -41,7 +41,7 @@ export interface ISyncManager extends ITask {
41
41
  pushManager?: IPushManager;
42
42
  }
43
43
  export interface ISyncManagerCS extends ISyncManager {
44
- shared(matchingKey: string, readinessManager: IReadinessManager, storage: IStorageSync): ISyncManager;
44
+ shared(matchingKey: string, readinessManager: IReadinessManager, storage: IStorageSync): ISyncManager | undefined;
45
45
  }
46
46
  export interface ISyncManagerFactoryParams {
47
47
  settings: ISettings;
@@ -1,6 +1,6 @@
1
1
  import { ImpressionDTO } from '../../types';
2
2
  import { IImpressionObserver } from './types';
3
- export default class ImpressionObserver<K extends string | number> implements IImpressionObserver {
3
+ export default class ImpressionObserver<K extends string | number = string> implements IImpressionObserver {
4
4
  private cache;
5
5
  private hasher;
6
6
  constructor(size: number, hasher: (impression: ImpressionDTO) => K);
package/types/types.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  import { ISplitFiltersValidation } from './dtos/types';
3
3
  import { IIntegration, IIntegrationFactoryParams } from './integrations/types';
4
4
  import { ILogger } from './logger/types';
5
- import { IStorageFactoryParams, IStorageSyncCS, IStorageSync, IStorageAsync, IStorageSyncFactory } from './storages/types';
5
+ import { IStorageFactoryParams, IStorageSync, IStorageAsync, IStorageSyncFactory, IStorageAsyncFactory } from './storages/types';
6
6
  import { ISyncManagerFactoryParams, ISyncManagerCS } from './sync/types';
7
7
  /**
8
8
  * EventEmitter interface with the minimal methods used by the SDK
@@ -47,7 +47,7 @@ declare type EventConsts = {
47
47
  * SDK Modes.
48
48
  * @typedef {string} SDKMode
49
49
  */
50
- export declare type SDKMode = 'standalone' | 'consumer' | 'localhost';
50
+ export declare type SDKMode = 'standalone' | 'consumer' | 'localhost' | 'consumer_partial';
51
51
  /**
52
52
  * Settings interface. This is a representation of the settings the SDK expose, that's why
53
53
  * most of it's props are readonly. Only features should be rewritten when localhost mode is active.
@@ -80,7 +80,7 @@ export interface ISettings {
80
80
  retriesOnFailureBeforeReady: number;
81
81
  eventsFirstPushWindow: number;
82
82
  };
83
- readonly storage: IStorageSyncFactory;
83
+ readonly storage: IStorageSyncFactory | IStorageAsyncFactory;
84
84
  readonly integrations?: Array<(params: IIntegrationFactoryParams) => IIntegration | void>;
85
85
  readonly urls: {
86
86
  events: string;
@@ -88,7 +88,7 @@ export interface ISettings {
88
88
  auth: string;
89
89
  streaming: string;
90
90
  };
91
- readonly debug: boolean | LogLevel;
91
+ readonly debug: boolean | LogLevel | ILogger;
92
92
  readonly version: string;
93
93
  features: SplitIO.MockedFeaturesFilePath | SplitIO.MockedFeaturesMap;
94
94
  readonly streamingEnabled: boolean;
@@ -842,7 +842,7 @@ export declare namespace SplitIO {
842
842
  * Defines which kind of storage we should instanciate.
843
843
  * @property {Object} storage
844
844
  */
845
- storage?: (params: IStorageFactoryParams) => IStorageSyncCS;
845
+ storage?: (params: IStorageFactoryParams) => IStorageSync | IStorageAsync;
846
846
  /**
847
847
  * List of URLs that the SDK will use as base for it's synchronization functionalities, applicable only when running as standalone.
848
848
  * Do not change these settings unless you're working an advanced use case, like connecting to the Split proxy.
@@ -1,4 +1,5 @@
1
1
  import { StorageType } from '../../storages/types';
2
+ import { SDKMode } from '../../types';
2
3
  export declare const CONTROL = "control";
3
4
  export declare const CONTROL_WITH_CONFIG: {
4
5
  treatment: string;
@@ -10,11 +11,12 @@ export declare const SPLIT_IMPRESSION = "IMPRESSION";
10
11
  export declare const SPLIT_EVENT = "EVENT";
11
12
  export declare const DEBUG = "DEBUG";
12
13
  export declare const OPTIMIZED = "OPTIMIZED";
13
- export declare const LOCALHOST_MODE = "localhost";
14
- export declare const STANDALONE_MODE = "standalone";
14
+ export declare const LOCALHOST_MODE: SDKMode;
15
+ export declare const STANDALONE_MODE: SDKMode;
15
16
  export declare const PRODUCER_MODE = "producer";
16
- export declare const CONSUMER_MODE = "consumer";
17
+ export declare const CONSUMER_MODE: SDKMode;
18
+ export declare const CONSUMER_PARTIAL_MODE: SDKMode;
17
19
  export declare const STORAGE_MEMORY: StorageType;
18
20
  export declare const STORAGE_LOCALSTORAGE: StorageType;
19
21
  export declare const STORAGE_REDIS: StorageType;
20
- export declare const STORAGE_CUSTOM: StorageType;
22
+ export declare const STORAGE_PLUGGABLE: StorageType;
@@ -1,7 +1,7 @@
1
1
  import { ISettings, SDKMode } from '../../../types';
2
2
  import { ILogger } from '../../../logger/types';
3
- import { IStorageFactoryParams, IStorageSyncCS } from '../../../storages/types';
4
- export declare function __InLocalStorageMockFactory(params: IStorageFactoryParams): IStorageSyncCS;
3
+ import { IStorageFactoryParams, IStorageSync } from '../../../storages/types';
4
+ export declare function __InLocalStorageMockFactory(params: IStorageFactoryParams): IStorageSync;
5
5
  export declare namespace __InLocalStorageMockFactory {
6
6
  var type: import("../../../storages/types").StorageType;
7
7
  }
@@ -10,10 +10,12 @@ export declare namespace __InLocalStorageMockFactory {
10
10
  *
11
11
  * @param {any} settings config object provided by the user to initialize the sdk
12
12
  *
13
- * @returns {Object} valid storage factory. It might be the default `InMemoryStorageCSFactory` if the provided storage is invalid.
13
+ * @returns {Object} valid storage factory. Default to `InMemoryStorageCSFactory` if the provided storage is invalid or not compatible with the sdk mode if mode is standalone or localhost
14
+ *
15
+ * @throws error if mode is consumer and the provided storage is not compatible
14
16
  */
15
17
  export declare function validateStorageCS(settings: {
16
18
  log: ILogger;
17
19
  storage?: any;
18
- mode?: SDKMode;
20
+ mode: SDKMode;
19
21
  }): ISettings['storage'];