@splitsoftware/splitio-commons 2.4.2-rc.0 → 2.4.2-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 (64) hide show
  1. package/CHANGES.txt +13 -1
  2. package/cjs/logger/messages/error.js +1 -1
  3. package/cjs/sdkClient/sdkClient.js +0 -1
  4. package/cjs/sdkFactory/index.js +3 -10
  5. package/cjs/services/splitHttpClient.js +1 -1
  6. package/cjs/storages/AbstractMySegmentsCacheSync.js +31 -23
  7. package/cjs/storages/AbstractSplitsCacheSync.js +8 -3
  8. package/cjs/storages/inLocalStorage/MySegmentsCacheInLocal.js +16 -16
  9. package/cjs/storages/inLocalStorage/RBSegmentsCacheInLocal.js +20 -19
  10. package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +33 -37
  11. package/cjs/storages/inLocalStorage/index.js +28 -13
  12. package/cjs/storages/inLocalStorage/storageAdapter.js +48 -0
  13. package/cjs/storages/inLocalStorage/validateCache.js +25 -23
  14. package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +2 -3
  15. package/cjs/sync/polling/pollingManagerCS.js +5 -4
  16. package/cjs/sync/polling/updaters/mySegmentsUpdater.js +3 -2
  17. package/cjs/sync/polling/updaters/splitChangesUpdater.js +1 -1
  18. package/cjs/sync/syncManagerOnline.js +31 -26
  19. package/cjs/utils/env/isLocalStorageAvailable.js +28 -5
  20. package/cjs/utils/settingsValidation/splitFilters.js +0 -6
  21. package/cjs/utils/settingsValidation/storage/storageCS.js +1 -1
  22. package/esm/logger/messages/error.js +1 -1
  23. package/esm/sdkClient/sdkClient.js +0 -1
  24. package/esm/sdkFactory/index.js +3 -10
  25. package/esm/services/splitHttpClient.js +1 -1
  26. package/esm/storages/AbstractMySegmentsCacheSync.js +31 -23
  27. package/esm/storages/AbstractSplitsCacheSync.js +6 -2
  28. package/esm/storages/inLocalStorage/MySegmentsCacheInLocal.js +16 -16
  29. package/esm/storages/inLocalStorage/RBSegmentsCacheInLocal.js +20 -19
  30. package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +33 -37
  31. package/esm/storages/inLocalStorage/index.js +29 -14
  32. package/esm/storages/inLocalStorage/storageAdapter.js +44 -0
  33. package/esm/storages/inLocalStorage/validateCache.js +25 -23
  34. package/esm/sync/offline/syncTasks/fromObjectSyncTask.js +2 -3
  35. package/esm/sync/polling/pollingManagerCS.js +5 -4
  36. package/esm/sync/polling/updaters/mySegmentsUpdater.js +3 -2
  37. package/esm/sync/polling/updaters/splitChangesUpdater.js +1 -1
  38. package/esm/sync/syncManagerOnline.js +31 -26
  39. package/esm/utils/env/isLocalStorageAvailable.js +24 -3
  40. package/esm/utils/settingsValidation/splitFilters.js +0 -6
  41. package/esm/utils/settingsValidation/storage/storageCS.js +1 -1
  42. package/package.json +1 -1
  43. package/src/logger/messages/error.ts +1 -1
  44. package/src/sdkClient/sdkClient.ts +0 -1
  45. package/src/sdkFactory/index.ts +3 -13
  46. package/src/services/splitHttpClient.ts +1 -1
  47. package/src/storages/AbstractMySegmentsCacheSync.ts +26 -20
  48. package/src/storages/AbstractSplitsCacheSync.ts +8 -3
  49. package/src/storages/inLocalStorage/MySegmentsCacheInLocal.ts +18 -17
  50. package/src/storages/inLocalStorage/RBSegmentsCacheInLocal.ts +22 -20
  51. package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +34 -37
  52. package/src/storages/inLocalStorage/index.ts +33 -16
  53. package/src/storages/inLocalStorage/storageAdapter.ts +50 -0
  54. package/src/storages/inLocalStorage/validateCache.ts +26 -23
  55. package/src/storages/types.ts +17 -1
  56. package/src/sync/offline/syncTasks/fromObjectSyncTask.ts +1 -2
  57. package/src/sync/polling/pollingManagerCS.ts +5 -4
  58. package/src/sync/polling/updaters/mySegmentsUpdater.ts +3 -2
  59. package/src/sync/polling/updaters/splitChangesUpdater.ts +1 -1
  60. package/src/sync/syncManagerOnline.ts +30 -24
  61. package/src/utils/env/isLocalStorageAvailable.ts +24 -3
  62. package/src/utils/settingsValidation/splitFilters.ts +0 -6
  63. package/src/utils/settingsValidation/storage/storageCS.ts +1 -1
  64. package/types/splitio.d.ts +57 -16
@@ -1,11 +1,32 @@
1
- /* eslint-disable no-undef */
2
1
  export function isLocalStorageAvailable(): boolean {
2
+ try {
3
+ // eslint-disable-next-line no-undef
4
+ return isValidStorageWrapper(localStorage);
5
+ } catch (e) {
6
+ return false;
7
+ }
8
+ }
9
+
10
+ export function isValidStorageWrapper(wrapper: any): boolean {
3
11
  var mod = '__SPLITSOFTWARE__';
4
12
  try {
5
- localStorage.setItem(mod, mod);
6
- localStorage.removeItem(mod);
13
+ wrapper.setItem(mod, mod);
14
+ wrapper.getItem(mod);
15
+ wrapper.removeItem(mod);
7
16
  return true;
8
17
  } catch (e) {
9
18
  return false;
10
19
  }
11
20
  }
21
+
22
+ export function isWebStorage(wrapper: any): boolean {
23
+ if (typeof wrapper.length === 'number') {
24
+ try {
25
+ wrapper.key(0);
26
+ return true;
27
+ } catch (e) {
28
+ return false;
29
+ }
30
+ }
31
+ return false;
32
+ }
@@ -69,12 +69,6 @@ function validateSplitFilter(log: ILogger, type: SplitIO.SplitFilterType, values
69
69
  /**
70
70
  * Returns a string representing the URL encoded query component of /splitChanges URL.
71
71
  *
72
- * The possible formats of the query string are:
73
- * - null: if all filters are empty
74
- * - '&names=<comma-separated-values>': if only `byPrefix` filter is undefined
75
- * - '&prefixes=<comma-separated-values>': if only `byName` filter is undefined
76
- * - '&names=<comma-separated-values>&prefixes=<comma-separated-values>': if no one is undefined
77
- *
78
72
  * @param groupedFilters - object of filters. Each filter must be a list of valid, unique and ordered string values.
79
73
  * @returns null or string with the `split filter query` component of the URL.
80
74
  */
@@ -8,7 +8,7 @@ import { IStorageFactoryParams, IStorageSync } from '../../../storages/types';
8
8
 
9
9
  export function __InLocalStorageMockFactory(params: IStorageFactoryParams): IStorageSync {
10
10
  const result = InMemoryStorageCSFactory(params);
11
- result.validateCache = () => true; // to emit SDK_READY_FROM_CACHE
11
+ result.validateCache = () => Promise.resolve(true); // to emit SDK_READY_FROM_CACHE
12
12
  return result;
13
13
  }
14
14
  __InLocalStorageMockFactory.type = STORAGE_MEMORY;
@@ -24,7 +24,11 @@ interface ISharedSettings {
24
24
  sync?: {
25
25
  /**
26
26
  * List of feature flag filters. These filters are used to fetch a subset of the feature flag definitions in your environment, in order to reduce the delay of the SDK to be ready.
27
- * This configuration is only meaningful when the SDK is working in "standalone" mode.
27
+ *
28
+ * NOTES:
29
+ * - This configuration is only meaningful when the SDK is working in `"standalone"` mode.
30
+ * - If `bySet` filter is provided, `byName` and `byPrefix` filters are ignored.
31
+ * - If both `byName` and `byPrefix` filters are provided, the intersection of the two groups of feature flags is fetched.
28
32
  *
29
33
  * Example:
30
34
  * ```
@@ -66,12 +70,17 @@ interface ISharedSettings {
66
70
  *
67
71
  * @example
68
72
  * ```
69
- * const getHeaderOverrides = (context) => {
70
- * return {
71
- * 'Authorization': context.headers['Authorization'] + ', other-value',
72
- * 'custom-header': 'custom-value'
73
- * };
74
- * };
73
+ * const factory = SplitFactory({
74
+ * ...
75
+ * sync: {
76
+ * getHeaderOverrides: (context) => {
77
+ * return {
78
+ * 'Authorization': context.headers['Authorization'] + ', other-value',
79
+ * 'custom-header': 'custom-value'
80
+ * };
81
+ * }
82
+ * }
83
+ * });
75
84
  * ```
76
85
  */
77
86
  getHeaderOverrides?: (context: { headers: Record<string, string> }) => Record<string, string>;
@@ -449,6 +458,21 @@ interface IClientSideSyncSharedSettings extends IClientSideSharedSettings, ISync
449
458
  */
450
459
  declare namespace SplitIO {
451
460
 
461
+ interface StorageWrapper {
462
+ /**
463
+ * Returns a promise that resolves to the current value associated with the given key, or null if the given key does not exist.
464
+ */
465
+ getItem(key: string): Promise<string | null> | string | null;
466
+ /**
467
+ * Returns a promise that resolves when the value of the pair identified by key is set to value, creating a new key/value pair if none existed for key previously.
468
+ */
469
+ setItem(key: string, value: string): Promise<void> | void;
470
+ /**
471
+ * Returns a promise that resolves when the key/value pair with the given key is removed, if a key/value pair with the given key exists.
472
+ */
473
+ removeItem(key: string): Promise<void> | void;
474
+ }
475
+
452
476
  /**
453
477
  * EventEmitter interface based on a subset of the Node.js EventEmitter methods.
454
478
  */
@@ -952,7 +976,7 @@ declare namespace SplitIO {
952
976
  */
953
977
  prefix?: string;
954
978
  /**
955
- * Number of days before cached data expires if it was not updated. If cache expires, it is cleared on initialization.
979
+ * Number of days before cached data expires if it was not successfully synchronized (i.e., last SDK_READY or SDK_UPDATE event emitted). If cache expires, it is cleared on initialization.
956
980
  *
957
981
  * @defaultValue `10`
958
982
  */
@@ -963,6 +987,12 @@ declare namespace SplitIO {
963
987
  * @defaultValue `false`
964
988
  */
965
989
  clearOnInit?: boolean;
990
+ /**
991
+ * Optional storage wrapper to persist rollout plan related data. If not provided, the SDK will use the default localStorage Web API.
992
+ *
993
+ * @defaultValue `window.localStorage`
994
+ */
995
+ wrapper?: StorageWrapper;
966
996
  }
967
997
  /**
968
998
  * Storage for asynchronous (consumer) SDK.
@@ -1130,7 +1160,7 @@ declare namespace SplitIO {
1130
1160
  */
1131
1161
  type: SplitFilterType;
1132
1162
  /**
1133
- * List of values: feature flag names for 'byName' filter type, and feature flag name prefixes for 'byPrefix' type.
1163
+ * List of values: flag set names for 'bySet' filter type, feature flag names for 'byName' filter type, and feature flag name prefixes for 'byPrefix' type.
1134
1164
  */
1135
1165
  values: string[];
1136
1166
  }
@@ -1292,7 +1322,7 @@ declare namespace SplitIO {
1292
1322
  */
1293
1323
  prefix?: string;
1294
1324
  /**
1295
- * Optional settings for the 'LOCALSTORAGE' storage type. It specifies the number of days before cached data expires if it was not updated. If cache expires, it is cleared on initialization.
1325
+ * Optional settings for the 'LOCALSTORAGE' storage type. It specifies the number of days before cached data expires if it was not successfully synchronized (i.e., last SDK_READY or SDK_UPDATE event emitted). If cache expires, it is cleared on initialization.
1296
1326
  *
1297
1327
  * @defaultValue `10`
1298
1328
  */
@@ -1303,6 +1333,12 @@ declare namespace SplitIO {
1303
1333
  * @defaultValue `false`
1304
1334
  */
1305
1335
  clearOnInit?: boolean;
1336
+ /**
1337
+ * Optional storage wrapper to persist rollout plan related data. If not provided, the SDK will use the default localStorage Web API.
1338
+ *
1339
+ * @defaultValue `window.localStorage`
1340
+ */
1341
+ wrapper?: StorageWrapper;
1306
1342
  };
1307
1343
  }
1308
1344
  /**
@@ -1350,12 +1386,17 @@ declare namespace SplitIO {
1350
1386
  *
1351
1387
  * @example
1352
1388
  * ```
1353
- * const getHeaderOverrides = (context) => {
1354
- * return {
1355
- * 'Authorization': context.headers['Authorization'] + ', other-value',
1356
- * 'custom-header': 'custom-value'
1357
- * };
1358
- * };
1389
+ * const factory = SplitFactory({
1390
+ * ...
1391
+ * sync: {
1392
+ * getHeaderOverrides: (context) => {
1393
+ * return {
1394
+ * 'Authorization': context.headers['Authorization'] + ', other-value',
1395
+ * 'custom-header': 'custom-value'
1396
+ * };
1397
+ * }
1398
+ * }
1399
+ * });
1359
1400
  * ```
1360
1401
  */
1361
1402
  getHeaderOverrides?: (context: { headers: Record<string, string> }) => Record<string, string>;