@splitsoftware/splitio-commons 1.0.1-rc.1 → 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.
- package/cjs/logger/constants.js +4 -4
- package/cjs/logger/messages/error.js +2 -1
- package/cjs/logger/messages/warn.js +0 -1
- package/cjs/sdkFactory/index.js +1 -1
- package/cjs/storages/inRedis/index.js +1 -2
- package/cjs/storages/pluggable/SplitsCachePluggable.js +1 -1
- package/cjs/storages/pluggable/inMemoryWrapper.js +3 -3
- package/cjs/storages/pluggable/index.js +6 -6
- package/cjs/storages/pluggable/wrapperAdapter.js +3 -3
- package/cjs/sync/polling/updaters/mySegmentsUpdater.js +1 -1
- package/cjs/sync/streaming/UpdateWorkers/SplitsUpdateWorker.js +0 -1
- package/cjs/utils/constants/index.js +2 -2
- package/cjs/utils/settingsValidation/storage/storageCS.js +11 -8
- package/esm/logger/constants.js +3 -3
- package/esm/logger/messages/error.js +2 -1
- package/esm/logger/messages/warn.js +0 -1
- package/esm/sdkFactory/index.js +1 -1
- package/esm/storages/inRedis/index.js +1 -2
- package/esm/storages/pluggable/SplitsCachePluggable.js +1 -1
- package/esm/storages/pluggable/inMemoryWrapper.js +3 -3
- package/esm/storages/pluggable/index.js +7 -7
- package/esm/storages/pluggable/wrapperAdapter.js +3 -3
- package/esm/sync/polling/updaters/mySegmentsUpdater.js +1 -1
- package/esm/sync/streaming/UpdateWorkers/SplitsUpdateWorker.js +0 -1
- package/esm/utils/constants/index.js +1 -1
- package/esm/utils/settingsValidation/storage/storageCS.js +13 -10
- package/package.json +1 -1
- package/src/logger/constants.ts +3 -3
- package/src/logger/messages/error.ts +2 -1
- package/src/logger/messages/warn.ts +0 -1
- package/src/sdkFactory/index.ts +1 -1
- package/src/services/splitApi.ts +4 -1
- package/src/storages/inRedis/index.ts +1 -1
- package/src/storages/pluggable/EventsCachePluggable.ts +3 -3
- package/src/storages/pluggable/ImpressionsCachePluggable.ts +3 -3
- package/src/storages/pluggable/SegmentsCachePluggable.ts +3 -3
- package/src/storages/pluggable/SplitsCachePluggable.ts +4 -4
- package/src/storages/pluggable/inMemoryWrapper.ts +5 -5
- package/src/storages/pluggable/index.ts +10 -10
- package/src/storages/pluggable/wrapperAdapter.ts +5 -5
- package/src/storages/types.ts +7 -7
- package/src/sync/polling/updaters/mySegmentsUpdater.ts +1 -1
- package/src/sync/streaming/UpdateWorkers/SplitsUpdateWorker.ts +0 -1
- package/src/trackers/impressionObserver/ImpressionObserver.ts +1 -1
- package/src/types.ts +1 -1
- package/src/utils/constants/index.ts +1 -1
- package/src/utils/settingsValidation/storage/storageCS.ts +12 -8
- package/types/logger/constants.d.ts +3 -3
- package/types/services/splitApi.d.ts +1 -1
- package/types/storages/pluggable/EventsCachePluggable.d.ts +2 -2
- package/types/storages/pluggable/ImpressionsCachePluggable.d.ts +2 -2
- package/types/storages/pluggable/SegmentsCachePluggable.d.ts +2 -2
- package/types/storages/pluggable/SplitsCachePluggable.d.ts +3 -3
- package/types/storages/pluggable/inMemoryWrapper.d.ts +3 -3
- package/types/storages/pluggable/index.d.ts +2 -2
- package/types/storages/pluggable/wrapperAdapter.d.ts +4 -4
- package/types/storages/types.d.ts +6 -6
- package/types/trackers/impressionObserver/ImpressionObserver.d.ts +1 -1
- package/types/types.d.ts +1 -1
- package/types/utils/constants/index.d.ts +1 -1
- package/types/utils/settingsValidation/storage/storageCS.d.ts +3 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IPluggableStorageWrapper, IImpressionsCacheAsync } from '../types';
|
|
2
2
|
import { IMetadata } from '../../dtos/types';
|
|
3
3
|
import { ImpressionDTO } from '../../types';
|
|
4
4
|
import { ILogger } from '../../logger/types';
|
|
@@ -8,10 +8,10 @@ export class ImpressionsCachePluggable implements IImpressionsCacheAsync {
|
|
|
8
8
|
|
|
9
9
|
private readonly log: ILogger;
|
|
10
10
|
private readonly key: string;
|
|
11
|
-
private readonly wrapper:
|
|
11
|
+
private readonly wrapper: IPluggableStorageWrapper;
|
|
12
12
|
private readonly metadata: IMetadata;
|
|
13
13
|
|
|
14
|
-
constructor(log: ILogger, key: string, wrapper:
|
|
14
|
+
constructor(log: ILogger, key: string, wrapper: IPluggableStorageWrapper, metadata: IMetadata) {
|
|
15
15
|
this.log = log;
|
|
16
16
|
this.key = key;
|
|
17
17
|
this.wrapper = wrapper;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/* eslint-disable no-unused-vars */
|
|
3
3
|
import { isNaNNumber } from '../../utils/lang';
|
|
4
4
|
import KeyBuilderSS from '../KeyBuilderSS';
|
|
5
|
-
import {
|
|
5
|
+
import { IPluggableStorageWrapper, ISegmentsCacheAsync } from '../types';
|
|
6
6
|
import { ILogger } from '../../logger/types';
|
|
7
7
|
import { LOG_PREFIX } from './constants';
|
|
8
8
|
import { _Set } from '../../utils/lang/sets';
|
|
@@ -14,9 +14,9 @@ export class SegmentsCachePluggable implements ISegmentsCacheAsync {
|
|
|
14
14
|
|
|
15
15
|
private readonly log: ILogger;
|
|
16
16
|
private readonly keys: KeyBuilderSS;
|
|
17
|
-
private readonly wrapper:
|
|
17
|
+
private readonly wrapper: IPluggableStorageWrapper;
|
|
18
18
|
|
|
19
|
-
constructor(log: ILogger, keys: KeyBuilderSS, wrapper:
|
|
19
|
+
constructor(log: ILogger, keys: KeyBuilderSS, wrapper: IPluggableStorageWrapper) {
|
|
20
20
|
this.log = log;
|
|
21
21
|
this.keys = keys;
|
|
22
22
|
this.wrapper = wrapper;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isFiniteNumber, isNaNNumber } from '../../utils/lang';
|
|
2
2
|
import KeyBuilder from '../KeyBuilder';
|
|
3
|
-
import {
|
|
3
|
+
import { IPluggableStorageWrapper } from '../types';
|
|
4
4
|
import { ILogger } from '../../logger/types';
|
|
5
5
|
import { ISplit } from '../../dtos/types';
|
|
6
6
|
import { LOG_PREFIX } from './constants';
|
|
@@ -13,15 +13,15 @@ export class SplitsCachePluggable extends AbstractSplitsCacheAsync {
|
|
|
13
13
|
|
|
14
14
|
private readonly log: ILogger;
|
|
15
15
|
private readonly keys: KeyBuilder;
|
|
16
|
-
private readonly wrapper:
|
|
16
|
+
private readonly wrapper: IPluggableStorageWrapper;
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
* Create a SplitsCache that uses a
|
|
19
|
+
* Create a SplitsCache that uses a storage wrapper.
|
|
20
20
|
* @param log Logger instance.
|
|
21
21
|
* @param keys Key builder.
|
|
22
22
|
* @param wrapper Adapted wrapper storage.
|
|
23
23
|
*/
|
|
24
|
-
constructor(log: ILogger, keys: KeyBuilder, wrapper:
|
|
24
|
+
constructor(log: ILogger, keys: KeyBuilder, wrapper: IPluggableStorageWrapper) {
|
|
25
25
|
super();
|
|
26
26
|
this.log = log;
|
|
27
27
|
this.keys = keys;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IPluggableStorageWrapper } from '../types';
|
|
2
2
|
import { startsWith, toNumber } from '../../utils/lang';
|
|
3
3
|
import { ISet, setToArray, _Set } from '../../utils/lang/sets';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Creates a
|
|
6
|
+
* Creates a IPluggableStorageWrapper implementation that stores items in memory.
|
|
7
7
|
* The `_cache` property is the object were items are stored.
|
|
8
8
|
* Intended for testing purposes.
|
|
9
9
|
*
|
|
10
10
|
* @param connDelay delay in millis for `connect` resolve. If not provided, `connect` resolves inmediatelly.
|
|
11
11
|
*/
|
|
12
|
-
export function inMemoryWrapperFactory(connDelay?: number):
|
|
12
|
+
export function inMemoryWrapperFactory(connDelay?: number): IPluggableStorageWrapper & { _cache: Record<string, string | string[] | ISet<string>>, _setConnDelay(connDelay: number): void } {
|
|
13
13
|
|
|
14
14
|
let _cache: Record<string, string | string[] | ISet<string>> = {};
|
|
15
15
|
let _connDelay = connDelay;
|
|
@@ -112,7 +112,7 @@ export function inMemoryWrapperFactory(connDelay?: number): ICustomStorageWrappe
|
|
|
112
112
|
return Promise.reject('key is not a set');
|
|
113
113
|
},
|
|
114
114
|
|
|
115
|
-
// always connects and
|
|
115
|
+
// always connects and disconnects
|
|
116
116
|
connect() {
|
|
117
117
|
if (typeof _connDelay === 'number') {
|
|
118
118
|
return new Promise(res => setTimeout(res, _connDelay));
|
|
@@ -120,7 +120,7 @@ export function inMemoryWrapperFactory(connDelay?: number): ICustomStorageWrappe
|
|
|
120
120
|
return Promise.resolve();
|
|
121
121
|
}
|
|
122
122
|
},
|
|
123
|
-
|
|
123
|
+
disconnect() { return Promise.resolve(); },
|
|
124
124
|
|
|
125
125
|
// for testing
|
|
126
126
|
_setConnDelay(connDelay: number) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IPluggableStorageWrapper, IStorageAsync, IStorageAsyncFactory, IStorageFactoryParams } from '../types';
|
|
2
2
|
|
|
3
3
|
import KeyBuilderSS from '../KeyBuilderSS';
|
|
4
4
|
import { SplitsCachePluggable } from './SplitsCachePluggable';
|
|
@@ -8,17 +8,17 @@ import { EventsCachePluggable } from './EventsCachePluggable';
|
|
|
8
8
|
import { wrapperAdapter, METHODS_TO_PROMISE_WRAP } from './wrapperAdapter';
|
|
9
9
|
import { isObject } from '../../utils/lang';
|
|
10
10
|
import { validatePrefix } from '../KeyBuilder';
|
|
11
|
-
import { CONSUMER_PARTIAL_MODE,
|
|
11
|
+
import { CONSUMER_PARTIAL_MODE, STORAGE_PLUGGABLE } from '../../utils/constants';
|
|
12
12
|
import ImpressionsCacheInMemory from '../inMemory/ImpressionsCacheInMemory';
|
|
13
13
|
import EventsCacheInMemory from '../inMemory/EventsCacheInMemory';
|
|
14
14
|
import ImpressionCountsCacheInMemory from '../inMemory/ImpressionCountsCacheInMemory';
|
|
15
15
|
|
|
16
|
-
const NO_VALID_WRAPPER = 'Expecting
|
|
16
|
+
const NO_VALID_WRAPPER = 'Expecting pluggable storage `wrapper` in options, but no valid wrapper instance was provided.';
|
|
17
17
|
const NO_VALID_WRAPPER_INTERFACE = 'The provided wrapper instance doesn’t follow the expected interface. Check our docs.';
|
|
18
18
|
|
|
19
19
|
export interface PluggableStorageOptions {
|
|
20
20
|
prefix?: string
|
|
21
|
-
wrapper:
|
|
21
|
+
wrapper: IPluggableStorageWrapper
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
/**
|
|
@@ -36,7 +36,7 @@ function validatePluggableStorageOptions(options: any) {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
// subscription to wrapper connect event in order to emit SDK_READY event
|
|
39
|
-
function wrapperConnect(wrapper:
|
|
39
|
+
function wrapperConnect(wrapper: IPluggableStorageWrapper, onReadyCb: (error?: any) => void) {
|
|
40
40
|
wrapper.connect().then(() => {
|
|
41
41
|
onReadyCb();
|
|
42
42
|
}).catch((e) => {
|
|
@@ -68,7 +68,7 @@ export function PluggableStorage(options: PluggableStorageOptions): IStorageAsyn
|
|
|
68
68
|
const wrapper = wrapperAdapter(log, options.wrapper);
|
|
69
69
|
const isPartialConsumer = mode === CONSUMER_PARTIAL_MODE;
|
|
70
70
|
|
|
71
|
-
//
|
|
71
|
+
// Connects to wrapper and emits SDK_READY event on main client
|
|
72
72
|
wrapperConnect(wrapper, onReadyCb);
|
|
73
73
|
|
|
74
74
|
return {
|
|
@@ -79,9 +79,9 @@ export function PluggableStorage(options: PluggableStorageOptions): IStorageAsyn
|
|
|
79
79
|
events: isPartialConsumer ? promisifyEventsTrack(new EventsCacheInMemory(eventsQueueSize)) : new EventsCachePluggable(log, keys.buildEventsKey(), wrapper, metadata),
|
|
80
80
|
// @TODO add telemetry cache when required
|
|
81
81
|
|
|
82
|
-
// Disconnect the underlying storage
|
|
82
|
+
// Disconnect the underlying storage
|
|
83
83
|
destroy() {
|
|
84
|
-
return wrapper.
|
|
84
|
+
return wrapper.disconnect();
|
|
85
85
|
},
|
|
86
86
|
|
|
87
87
|
// emits SDK_READY event on shared clients and returns a reference to the storage
|
|
@@ -89,13 +89,13 @@ export function PluggableStorage(options: PluggableStorageOptions): IStorageAsyn
|
|
|
89
89
|
wrapperConnect(wrapper, onReadyCb);
|
|
90
90
|
return {
|
|
91
91
|
...this,
|
|
92
|
-
// no-op destroy, to
|
|
92
|
+
// no-op destroy, to disconnect the wrapper only when the main client is destroyed
|
|
93
93
|
destroy() { }
|
|
94
94
|
};
|
|
95
95
|
}
|
|
96
96
|
};
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
PluggableStorageFactory.type =
|
|
99
|
+
PluggableStorageFactory.type = STORAGE_PLUGGABLE;
|
|
100
100
|
return PluggableStorageFactory;
|
|
101
101
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ILogger } from '../../logger/types';
|
|
2
|
-
import {
|
|
2
|
+
import { IPluggableStorageWrapper } from '../types';
|
|
3
3
|
import { LOG_PREFIX } from './constants';
|
|
4
4
|
|
|
5
5
|
export const METHODS_TO_PROMISE_WRAP: string[] = [
|
|
@@ -19,18 +19,18 @@ export const METHODS_TO_PROMISE_WRAP: string[] = [
|
|
|
19
19
|
'removeItems',
|
|
20
20
|
'getItems',
|
|
21
21
|
'connect',
|
|
22
|
-
'
|
|
22
|
+
'disconnect'
|
|
23
23
|
];
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
|
-
* Adapter of the
|
|
26
|
+
* Adapter of the Pluggable Storage Wrapper.
|
|
27
27
|
* Used to handle exceptions as rejected promises, in order to simplify the error handling on storages.
|
|
28
28
|
*
|
|
29
29
|
* @param log logger instance
|
|
30
|
-
* @param wrapper
|
|
30
|
+
* @param wrapper storage wrapper to adapt
|
|
31
31
|
* @returns an adapted version of the given storage wrapper
|
|
32
32
|
*/
|
|
33
|
-
export function wrapperAdapter(log: ILogger, wrapper:
|
|
33
|
+
export function wrapperAdapter(log: ILogger, wrapper: IPluggableStorageWrapper): IPluggableStorageWrapper {
|
|
34
34
|
|
|
35
35
|
const wrapperAdapter: Record<string, Function> = {};
|
|
36
36
|
|
package/src/storages/types.ts
CHANGED
|
@@ -4,9 +4,9 @@ import { StoredEventWithMetadata, StoredImpressionWithMetadata } from '../sync/s
|
|
|
4
4
|
import { SplitIO, ImpressionDTO, SDKMode } from '../types';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Interface of a
|
|
7
|
+
* Interface of a pluggable storage wrapper.
|
|
8
8
|
*/
|
|
9
|
-
export interface
|
|
9
|
+
export interface IPluggableStorageWrapper {
|
|
10
10
|
|
|
11
11
|
/** Key-Value operations */
|
|
12
12
|
|
|
@@ -177,15 +177,15 @@ export interface ICustomStorageWrapper {
|
|
|
177
177
|
*/
|
|
178
178
|
connect: () => Promise<void>
|
|
179
179
|
/**
|
|
180
|
-
* Disconnects the underlying storage.
|
|
180
|
+
* Disconnects from the underlying storage.
|
|
181
181
|
* It is meant for storages that requires to be closed, in order to release resources. Otherwise it can just return a resolved promise.
|
|
182
182
|
* Note: will be called once on SplitFactory main client destroy.
|
|
183
183
|
*
|
|
184
|
-
* @function
|
|
184
|
+
* @function disconnect
|
|
185
185
|
* @returns {Promise<void>} A promise that resolves when the operation ends.
|
|
186
186
|
* The promise never rejects.
|
|
187
187
|
*/
|
|
188
|
-
|
|
188
|
+
disconnect: () => Promise<void>
|
|
189
189
|
}
|
|
190
190
|
|
|
191
191
|
/** Splits cache */
|
|
@@ -430,7 +430,7 @@ export interface IStorageFactoryParams {
|
|
|
430
430
|
matchingKey?: string, /* undefined on server-side SDKs */
|
|
431
431
|
splitFiltersValidation?: ISplitFiltersValidation,
|
|
432
432
|
|
|
433
|
-
// ATM, only used by
|
|
433
|
+
// ATM, only used by PluggableStorage
|
|
434
434
|
mode?: SDKMode,
|
|
435
435
|
|
|
436
436
|
// This callback is invoked when the storage is ready to be used. Error-first callback style: if an error is passed,
|
|
@@ -440,7 +440,7 @@ export interface IStorageFactoryParams {
|
|
|
440
440
|
metadata: IMetadata,
|
|
441
441
|
}
|
|
442
442
|
|
|
443
|
-
export type StorageType = 'MEMORY' | 'LOCALSTORAGE' | 'REDIS' | '
|
|
443
|
+
export type StorageType = 'MEMORY' | 'LOCALSTORAGE' | 'REDIS' | 'PLUGGABLE';
|
|
444
444
|
|
|
445
445
|
export type IStorageSyncFactory = {
|
|
446
446
|
type: StorageType,
|
|
@@ -38,7 +38,7 @@ export function mySegmentsUpdaterFactory(
|
|
|
38
38
|
// mySegmentsPromise = tracker.start(tracker.TaskNames.MY_SEGMENTS_FETCH, startingUp ? metricCollectors : false, mySegmentsPromise);
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
// @TODO if allowing
|
|
41
|
+
// @TODO if allowing pluggable storages, handle async execution
|
|
42
42
|
function updateSegments(segmentsData: SegmentsData) {
|
|
43
43
|
|
|
44
44
|
let shouldNotifyUpdate;
|
|
@@ -83,7 +83,6 @@ export default class SplitsUpdateWorker implements IUpdateWorker {
|
|
|
83
83
|
* @param {string} defaultTreatment default treatment value
|
|
84
84
|
*/
|
|
85
85
|
killSplit({ changeNumber, splitName, defaultTreatment }: ISplitKillData) {
|
|
86
|
-
// @TODO handle retry due to errors in storage, once we allow the definition of custom async storages
|
|
87
86
|
if (this.splitsCache.killLocally(splitName, defaultTreatment, changeNumber)) {
|
|
88
87
|
// trigger an SDK_UPDATE if Split was killed locally
|
|
89
88
|
this.splitsEventEmitter.emit(SDK_SPLITS_ARRIVED, true);
|
|
@@ -2,7 +2,7 @@ import { ImpressionDTO } from '../../types';
|
|
|
2
2
|
import LRUCache from '../../utils/LRUCache';
|
|
3
3
|
import { IImpressionObserver } from './types';
|
|
4
4
|
|
|
5
|
-
export default class ImpressionObserver<K extends string | number> implements IImpressionObserver {
|
|
5
|
+
export default class ImpressionObserver<K extends string | number = string> implements IImpressionObserver {
|
|
6
6
|
private cache: LRUCache<K, number>;
|
|
7
7
|
private hasher: (impression: ImpressionDTO) => K;
|
|
8
8
|
|
package/src/types.ts
CHANGED
|
@@ -93,7 +93,7 @@ export interface ISettings {
|
|
|
93
93
|
auth: string,
|
|
94
94
|
streaming: string
|
|
95
95
|
},
|
|
96
|
-
readonly debug: boolean | LogLevel,
|
|
96
|
+
readonly debug: boolean | LogLevel | ILogger,
|
|
97
97
|
readonly version: string,
|
|
98
98
|
features: SplitIO.MockedFeaturesFilePath | SplitIO.MockedFeaturesMap,
|
|
99
99
|
readonly streamingEnabled: boolean,
|
|
@@ -31,4 +31,4 @@ export const CONSUMER_PARTIAL_MODE: SDKMode = 'consumer_partial';
|
|
|
31
31
|
export const STORAGE_MEMORY: StorageType = 'MEMORY';
|
|
32
32
|
export const STORAGE_LOCALSTORAGE: StorageType = 'LOCALSTORAGE';
|
|
33
33
|
export const STORAGE_REDIS: StorageType = 'REDIS';
|
|
34
|
-
export const
|
|
34
|
+
export const STORAGE_PLUGGABLE: StorageType = 'PLUGGABLE';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { InMemoryStorageCSFactory } from '../../../storages/inMemory/InMemoryStorageCS';
|
|
2
2
|
import { ISettings, SDKMode } from '../../../types';
|
|
3
3
|
import { ILogger } from '../../../logger/types';
|
|
4
|
-
import {
|
|
5
|
-
import { LOCALHOST_MODE, STANDALONE_MODE,
|
|
4
|
+
import { ERROR_STORAGE_INVALID } from '../../../logger/constants';
|
|
5
|
+
import { LOCALHOST_MODE, STANDALONE_MODE, STORAGE_PLUGGABLE, STORAGE_LOCALSTORAGE, STORAGE_MEMORY } from '../../../utils/constants';
|
|
6
6
|
import { IStorageFactoryParams, IStorageSync } from '../../../storages/types';
|
|
7
7
|
|
|
8
8
|
export function __InLocalStorageMockFactory(params: IStorageFactoryParams): IStorageSync {
|
|
@@ -17,15 +17,17 @@ __InLocalStorageMockFactory.type = STORAGE_MEMORY;
|
|
|
17
17
|
*
|
|
18
18
|
* @param {any} settings config object provided by the user to initialize the sdk
|
|
19
19
|
*
|
|
20
|
-
* @returns {Object} valid storage factory.
|
|
20
|
+
* @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
|
|
21
|
+
*
|
|
22
|
+
* @throws error if mode is consumer and the provided storage is not compatible
|
|
21
23
|
*/
|
|
22
24
|
export function validateStorageCS(settings: { log: ILogger, storage?: any, mode: SDKMode }): ISettings['storage'] {
|
|
23
25
|
let { storage = InMemoryStorageCSFactory, log, mode } = settings;
|
|
24
26
|
|
|
25
27
|
// If an invalid storage is provided, fallback into MEMORY
|
|
26
|
-
if (typeof storage !== 'function' || [STORAGE_MEMORY, STORAGE_LOCALSTORAGE,
|
|
28
|
+
if (typeof storage !== 'function' || [STORAGE_MEMORY, STORAGE_LOCALSTORAGE, STORAGE_PLUGGABLE].indexOf(storage.type) === -1) {
|
|
27
29
|
storage = InMemoryStorageCSFactory;
|
|
28
|
-
log.
|
|
30
|
+
log.error(ERROR_STORAGE_INVALID);
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
// In localhost mode with InLocalStorage, fallback to a mock InLocalStorage to emit SDK_READY_FROM_CACHE
|
|
@@ -33,13 +35,15 @@ export function validateStorageCS(settings: { log: ILogger, storage?: any, mode:
|
|
|
33
35
|
return __InLocalStorageMockFactory;
|
|
34
36
|
}
|
|
35
37
|
|
|
36
|
-
// @TODO check behaviour
|
|
37
38
|
if ([LOCALHOST_MODE, STANDALONE_MODE].indexOf(mode) === -1) {
|
|
38
39
|
// Consumer modes require an async storage
|
|
39
|
-
if (storage.type !==
|
|
40
|
+
if (storage.type !== STORAGE_PLUGGABLE) throw new Error('A PluggableStorage instance is required on consumer mode');
|
|
40
41
|
} else {
|
|
41
42
|
// Standalone and localhost modes require a sync storage
|
|
42
|
-
if (storage.type ===
|
|
43
|
+
if (storage.type === STORAGE_PLUGGABLE) {
|
|
44
|
+
storage = InMemoryStorageCSFactory;
|
|
45
|
+
log.error(ERROR_STORAGE_INVALID, [' It requires consumer mode.']);
|
|
46
|
+
}
|
|
43
47
|
}
|
|
44
48
|
|
|
45
49
|
// return default InMemory storage if provided one is not valid
|
|
@@ -89,9 +89,8 @@ export declare const WARN_INTEGRATION_INVALID = 218;
|
|
|
89
89
|
export declare const WARN_SPLITS_FILTER_IGNORED = 219;
|
|
90
90
|
export declare const WARN_SPLITS_FILTER_INVALID = 220;
|
|
91
91
|
export declare const WARN_SPLITS_FILTER_EMPTY = 221;
|
|
92
|
-
export declare const
|
|
93
|
-
export declare const
|
|
94
|
-
export declare const STREAMING_PARSING_MY_SEGMENTS_UPDATE_V2 = 224;
|
|
92
|
+
export declare const WARN_API_KEY = 222;
|
|
93
|
+
export declare const STREAMING_PARSING_MY_SEGMENTS_UPDATE_V2 = 223;
|
|
95
94
|
export declare const ERROR_ENGINE_COMBINER_IFELSEIF = 300;
|
|
96
95
|
export declare const ERROR_LOGLEVEL_INVALID = 301;
|
|
97
96
|
export declare const ERROR_CLIENT_LISTENER = 302;
|
|
@@ -116,6 +115,7 @@ export declare const ERROR_EMPTY_ARRAY = 320;
|
|
|
116
115
|
export declare const ERROR_INVALID_IMPRESSIONS_MODE = 321;
|
|
117
116
|
export declare const ERROR_HTTP = 322;
|
|
118
117
|
export declare const ERROR_LOCALHOST_MODULE_REQUIRED = 323;
|
|
118
|
+
export declare const ERROR_STORAGE_INVALID = 324;
|
|
119
119
|
export declare const LOG_PREFIX_SETTINGS = "settings";
|
|
120
120
|
export declare const LOG_PREFIX_INSTANTIATION = "Factory instantiation";
|
|
121
121
|
export declare const LOG_PREFIX_ENGINE = "engine";
|
|
@@ -7,4 +7,4 @@ import { ISplitApi } from './types';
|
|
|
7
7
|
* @param settings validated settings object
|
|
8
8
|
* @param platform object containing environment-specific `getFetch` and `getOptions` dependencies
|
|
9
9
|
*/
|
|
10
|
-
export declare function splitApiFactory(settings: ISettings, platform: Pick<IPlatform, 'getFetch' | 'getOptions'>): ISplitApi;
|
|
10
|
+
export declare function splitApiFactory(settings: Pick<ISettings, 'urls' | 'sync' | 'log' | 'version' | 'runtime' | 'core'>, platform: Pick<IPlatform, 'getFetch' | 'getOptions'>): ISplitApi;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IPluggableStorageWrapper, IEventsCacheAsync } from '../types';
|
|
2
2
|
import { IMetadata } from '../../dtos/types';
|
|
3
3
|
import { SplitIO } from '../../types';
|
|
4
4
|
import { ILogger } from '../../logger/types';
|
|
@@ -8,7 +8,7 @@ export declare class EventsCachePluggable implements IEventsCacheAsync {
|
|
|
8
8
|
private readonly wrapper;
|
|
9
9
|
private readonly key;
|
|
10
10
|
private readonly metadata;
|
|
11
|
-
constructor(log: ILogger, key: string, wrapper:
|
|
11
|
+
constructor(log: ILogger, key: string, wrapper: IPluggableStorageWrapper, metadata: IMetadata);
|
|
12
12
|
/**
|
|
13
13
|
* Push given event to the storage.
|
|
14
14
|
* @param eventData Event item to push.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IPluggableStorageWrapper, IImpressionsCacheAsync } from '../types';
|
|
2
2
|
import { IMetadata } from '../../dtos/types';
|
|
3
3
|
import { ImpressionDTO } from '../../types';
|
|
4
4
|
import { ILogger } from '../../logger/types';
|
|
@@ -8,7 +8,7 @@ export declare class ImpressionsCachePluggable implements IImpressionsCacheAsync
|
|
|
8
8
|
private readonly key;
|
|
9
9
|
private readonly wrapper;
|
|
10
10
|
private readonly metadata;
|
|
11
|
-
constructor(log: ILogger, key: string, wrapper:
|
|
11
|
+
constructor(log: ILogger, key: string, wrapper: IPluggableStorageWrapper, metadata: IMetadata);
|
|
12
12
|
/**
|
|
13
13
|
* Push given impressions to the storage.
|
|
14
14
|
* @param impressions List of impresions to push.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import KeyBuilderSS from '../KeyBuilderSS';
|
|
2
|
-
import {
|
|
2
|
+
import { IPluggableStorageWrapper, ISegmentsCacheAsync } from '../types';
|
|
3
3
|
import { ILogger } from '../../logger/types';
|
|
4
4
|
/**
|
|
5
5
|
* ISegmentsCacheAsync implementation for pluggable storages.
|
|
@@ -8,7 +8,7 @@ export declare class SegmentsCachePluggable implements ISegmentsCacheAsync {
|
|
|
8
8
|
private readonly log;
|
|
9
9
|
private readonly keys;
|
|
10
10
|
private readonly wrapper;
|
|
11
|
-
constructor(log: ILogger, keys: KeyBuilderSS, wrapper:
|
|
11
|
+
constructor(log: ILogger, keys: KeyBuilderSS, wrapper: IPluggableStorageWrapper);
|
|
12
12
|
/**
|
|
13
13
|
* Add a list of `segmentKeys` to the given segment `name`.
|
|
14
14
|
* The returned promise is resolved when the operation success
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import KeyBuilder from '../KeyBuilder';
|
|
2
|
-
import {
|
|
2
|
+
import { IPluggableStorageWrapper } from '../types';
|
|
3
3
|
import { ILogger } from '../../logger/types';
|
|
4
4
|
import AbstractSplitsCacheAsync from '../AbstractSplitsCacheAsync';
|
|
5
5
|
/**
|
|
@@ -10,12 +10,12 @@ export declare class SplitsCachePluggable extends AbstractSplitsCacheAsync {
|
|
|
10
10
|
private readonly keys;
|
|
11
11
|
private readonly wrapper;
|
|
12
12
|
/**
|
|
13
|
-
* Create a SplitsCache that uses a
|
|
13
|
+
* Create a SplitsCache that uses a storage wrapper.
|
|
14
14
|
* @param log Logger instance.
|
|
15
15
|
* @param keys Key builder.
|
|
16
16
|
* @param wrapper Adapted wrapper storage.
|
|
17
17
|
*/
|
|
18
|
-
constructor(log: ILogger, keys: KeyBuilder, wrapper:
|
|
18
|
+
constructor(log: ILogger, keys: KeyBuilder, wrapper: IPluggableStorageWrapper);
|
|
19
19
|
private _decrementCounts;
|
|
20
20
|
private _incrementCounts;
|
|
21
21
|
/**
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IPluggableStorageWrapper } from '../types';
|
|
2
2
|
import { ISet } from '../../utils/lang/sets';
|
|
3
3
|
/**
|
|
4
|
-
* Creates a
|
|
4
|
+
* Creates a IPluggableStorageWrapper implementation that stores items in memory.
|
|
5
5
|
* The `_cache` property is the object were items are stored.
|
|
6
6
|
* Intended for testing purposes.
|
|
7
7
|
*
|
|
8
8
|
* @param connDelay delay in millis for `connect` resolve. If not provided, `connect` resolves inmediatelly.
|
|
9
9
|
*/
|
|
10
|
-
export declare function inMemoryWrapperFactory(connDelay?: number):
|
|
10
|
+
export declare function inMemoryWrapperFactory(connDelay?: number): IPluggableStorageWrapper & {
|
|
11
11
|
_cache: Record<string, string | string[] | ISet<string>>;
|
|
12
12
|
_setConnDelay(connDelay: number): void;
|
|
13
13
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IPluggableStorageWrapper, IStorageAsyncFactory } from '../types';
|
|
2
2
|
export interface PluggableStorageOptions {
|
|
3
3
|
prefix?: string;
|
|
4
|
-
wrapper:
|
|
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 {
|
|
2
|
+
import { IPluggableStorageWrapper } from '../types';
|
|
3
3
|
export declare const METHODS_TO_PROMISE_WRAP: string[];
|
|
4
4
|
/**
|
|
5
|
-
* Adapter of the
|
|
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
|
|
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:
|
|
12
|
+
export declare function wrapperAdapter(log: ILogger, wrapper: IPluggableStorageWrapper): IPluggableStorageWrapper;
|
|
@@ -3,9 +3,9 @@ import { ILogger } from '../logger/types';
|
|
|
3
3
|
import { StoredEventWithMetadata, StoredImpressionWithMetadata } from '../sync/submitters/types';
|
|
4
4
|
import { SplitIO, ImpressionDTO, SDKMode } from '../types';
|
|
5
5
|
/**
|
|
6
|
-
* Interface of a
|
|
6
|
+
* Interface of a pluggable storage wrapper.
|
|
7
7
|
*/
|
|
8
|
-
export interface
|
|
8
|
+
export interface IPluggableStorageWrapper {
|
|
9
9
|
/** Key-Value operations */
|
|
10
10
|
/**
|
|
11
11
|
* Get the value of given `key`.
|
|
@@ -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
171
|
* Note: will be called once on SplitFactory main client destroy.
|
|
172
172
|
*
|
|
173
|
-
* @function
|
|
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
|
-
|
|
177
|
+
disconnect: () => Promise<void>;
|
|
178
178
|
}
|
|
179
179
|
/** Splits cache */
|
|
180
180
|
export interface ISplitsCacheBase {
|
|
@@ -343,7 +343,7 @@ export interface IStorageFactoryParams {
|
|
|
343
343
|
onReadyCb: (error?: any) => void;
|
|
344
344
|
metadata: IMetadata;
|
|
345
345
|
}
|
|
346
|
-
export declare type StorageType = 'MEMORY' | 'LOCALSTORAGE' | 'REDIS' | '
|
|
346
|
+
export declare type StorageType = 'MEMORY' | 'LOCALSTORAGE' | 'REDIS' | 'PLUGGABLE';
|
|
347
347
|
export declare type IStorageSyncFactory = {
|
|
348
348
|
type: StorageType;
|
|
349
349
|
(params: IStorageFactoryParams): IStorageSync;
|
|
@@ -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
|
@@ -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;
|
|
@@ -19,4 +19,4 @@ export declare const CONSUMER_PARTIAL_MODE: SDKMode;
|
|
|
19
19
|
export declare const STORAGE_MEMORY: StorageType;
|
|
20
20
|
export declare const STORAGE_LOCALSTORAGE: StorageType;
|
|
21
21
|
export declare const STORAGE_REDIS: StorageType;
|
|
22
|
-
export declare const
|
|
22
|
+
export declare const STORAGE_PLUGGABLE: StorageType;
|
|
@@ -10,7 +10,9 @@ 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.
|
|
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;
|