@splitsoftware/splitio-commons 3.1.1-rc.0 → 3.1.1-rc.10

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 (241) hide show
  1. package/CHANGES.txt +10 -1
  2. package/cjs/evaluator/condition/index.js +1 -1
  3. package/cjs/evaluator/fallbackTreatmentsCalculator/fallbackSanitizer/index.js +8 -5
  4. package/cjs/evaluator/index.js +69 -81
  5. package/cjs/listeners/browser.js +1 -2
  6. package/cjs/listeners/node.js +4 -4
  7. package/cjs/logger/constants.js +20 -15
  8. package/cjs/logger/messages/debug.js +6 -5
  9. package/cjs/logger/messages/error.js +3 -3
  10. package/cjs/logger/messages/info.js +4 -3
  11. package/cjs/logger/messages/warn.js +7 -6
  12. package/cjs/presets/serverSide.js +2 -2
  13. package/cjs/readiness/constants.js +4 -5
  14. package/cjs/readiness/readinessManager.js +23 -23
  15. package/cjs/readiness/sdkReadinessManager.js +17 -1
  16. package/cjs/sdkClient/client.js +34 -9
  17. package/cjs/sdkClient/clientInputValidation.js +17 -6
  18. package/cjs/sdkClient/sdkClient.js +60 -3
  19. package/cjs/sdkFactory/index.js +15 -11
  20. package/cjs/sdkManager/index.js +5 -5
  21. package/cjs/services/decorateHeaders.js +1 -2
  22. package/cjs/services/splitApi.js +1 -14
  23. package/cjs/services/splitHttpClient.js +5 -3
  24. package/cjs/storages/AbstractSplitsCacheAsync.js +51 -0
  25. package/cjs/storages/AbstractSplitsCacheSync.js +76 -0
  26. package/cjs/storages/KeyBuilder.js +6 -6
  27. package/cjs/storages/KeyBuilderCS.js +5 -5
  28. package/cjs/storages/KeyBuilderSS.js +2 -2
  29. package/cjs/storages/getRolloutPlan.js +3 -3
  30. package/cjs/storages/inLocalStorage/MySegmentsCacheInLocal.js +2 -1
  31. package/cjs/storages/inLocalStorage/RBSegmentsCacheInLocal.js +10 -10
  32. package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +194 -0
  33. package/cjs/storages/inLocalStorage/index.js +6 -6
  34. package/cjs/storages/inLocalStorage/validateCache.js +3 -3
  35. package/cjs/storages/inMemory/InMemoryStorage.js +4 -4
  36. package/cjs/storages/inMemory/InMemoryStorageCS.js +5 -5
  37. package/cjs/storages/inMemory/RBSegmentsCacheInMemory.js +5 -5
  38. package/cjs/storages/inMemory/SegmentsCacheInMemory.js +1 -1
  39. package/cjs/storages/inMemory/SplitsCacheInMemory.js +121 -0
  40. package/cjs/storages/inMemory/TelemetryCacheInMemory.js +5 -5
  41. package/cjs/storages/inRedis/RBSegmentsCacheInRedis.js +1 -1
  42. package/cjs/storages/inRedis/RedisAdapter.js +8 -5
  43. package/cjs/storages/inRedis/{DefinitionsCacheInRedis.js → SplitsCacheInRedis.js} +77 -77
  44. package/cjs/storages/inRedis/index.js +2 -2
  45. package/cjs/storages/pluggable/RBSegmentsCachePluggable.js +1 -1
  46. package/cjs/storages/pluggable/SplitsCachePluggable.js +212 -0
  47. package/cjs/storages/pluggable/index.js +2 -2
  48. package/cjs/storages/setRolloutPlan.js +4 -4
  49. package/cjs/storages/utils.js +0 -1
  50. package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +5 -5
  51. package/cjs/sync/polling/fetchers/splitChangesFetcher.js +15 -24
  52. package/cjs/sync/polling/pollingManagerCS.js +20 -20
  53. package/cjs/sync/polling/pollingManagerSS.js +15 -15
  54. package/cjs/sync/polling/syncTasks/segmentsSyncTask.js +3 -2
  55. package/cjs/sync/polling/syncTasks/splitsSyncTask.js +13 -0
  56. package/cjs/sync/polling/updaters/mySegmentsUpdater.js +3 -3
  57. package/cjs/sync/polling/updaters/segmentChangesUpdater.js +6 -6
  58. package/cjs/sync/polling/updaters/{definitionChangesUpdater.js → splitChangesUpdater.js} +68 -65
  59. package/cjs/sync/streaming/AuthClient/index.js +1 -1
  60. package/cjs/sync/streaming/SSEHandler/NotificationKeeper.js +1 -1
  61. package/cjs/sync/streaming/SSEHandler/index.js +1 -1
  62. package/cjs/sync/streaming/UpdateWorkers/{DefinitionsUpdateWorker.js → SplitsUpdateWorker.js} +19 -16
  63. package/cjs/sync/streaming/constants.js +3 -3
  64. package/cjs/sync/streaming/parseUtils.js +11 -11
  65. package/cjs/sync/streaming/pushManager.js +16 -16
  66. package/cjs/sync/submitters/eventsSubmitter.js +1 -1
  67. package/cjs/sync/submitters/impressionCountsSubmitter.js +1 -1
  68. package/cjs/sync/submitters/impressionsSubmitter.js +4 -5
  69. package/cjs/sync/submitters/telemetrySubmitter.js +4 -3
  70. package/cjs/sync/submitters/uniqueKeysSubmitter.js +1 -1
  71. package/cjs/sync/syncManagerOnline.js +7 -12
  72. package/cjs/utils/Backoff.js +0 -20
  73. package/cjs/utils/inputValidation/index.js +7 -7
  74. package/cjs/utils/inputValidation/isOperational.js +4 -4
  75. package/cjs/utils/inputValidation/{definition.js → split.js} +10 -10
  76. package/cjs/utils/inputValidation/{definitionExistence.js → splitExistence.js} +6 -6
  77. package/cjs/utils/inputValidation/splits.js +25 -0
  78. package/cjs/utils/labels/index.js +3 -3
  79. package/cjs/utils/settingsValidation/index.js +0 -2
  80. package/cjs/utils/settingsValidation/splitFilters.js +3 -3
  81. package/cjs/utils/settingsValidation/url.js +2 -6
  82. package/esm/evaluator/condition/index.js +1 -1
  83. package/esm/evaluator/fallbackTreatmentsCalculator/fallbackSanitizer/index.js +8 -5
  84. package/esm/evaluator/index.js +69 -80
  85. package/esm/listeners/browser.js +1 -2
  86. package/esm/listeners/node.js +4 -4
  87. package/esm/logger/constants.js +17 -12
  88. package/esm/logger/messages/debug.js +6 -5
  89. package/esm/logger/messages/error.js +3 -3
  90. package/esm/logger/messages/info.js +4 -3
  91. package/esm/logger/messages/warn.js +7 -6
  92. package/esm/presets/serverSide.js +2 -2
  93. package/esm/readiness/constants.js +3 -4
  94. package/esm/readiness/readinessManager.js +24 -24
  95. package/esm/readiness/sdkReadinessManager.js +18 -2
  96. package/esm/sdkClient/client.js +35 -9
  97. package/esm/sdkClient/clientInputValidation.js +19 -8
  98. package/esm/sdkClient/sdkClient.js +60 -3
  99. package/esm/sdkFactory/index.js +16 -12
  100. package/esm/sdkManager/index.js +6 -6
  101. package/esm/services/decorateHeaders.js +1 -2
  102. package/esm/services/splitApi.js +1 -14
  103. package/esm/services/splitHttpClient.js +5 -3
  104. package/esm/storages/AbstractSplitsCacheAsync.js +48 -0
  105. package/esm/storages/AbstractSplitsCacheSync.js +71 -0
  106. package/esm/storages/KeyBuilder.js +6 -6
  107. package/esm/storages/KeyBuilderCS.js +5 -5
  108. package/esm/storages/KeyBuilderSS.js +2 -2
  109. package/esm/storages/getRolloutPlan.js +3 -3
  110. package/esm/storages/inLocalStorage/MySegmentsCacheInLocal.js +2 -1
  111. package/esm/storages/inLocalStorage/RBSegmentsCacheInLocal.js +7 -7
  112. package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +191 -0
  113. package/esm/storages/inLocalStorage/index.js +6 -6
  114. package/esm/storages/inLocalStorage/validateCache.js +3 -3
  115. package/esm/storages/inMemory/InMemoryStorage.js +4 -4
  116. package/esm/storages/inMemory/InMemoryStorageCS.js +5 -5
  117. package/esm/storages/inMemory/RBSegmentsCacheInMemory.js +2 -2
  118. package/esm/storages/inMemory/SegmentsCacheInMemory.js +1 -1
  119. package/esm/storages/inMemory/SplitsCacheInMemory.js +118 -0
  120. package/esm/storages/inMemory/TelemetryCacheInMemory.js +5 -5
  121. package/esm/storages/inRedis/RBSegmentsCacheInRedis.js +1 -1
  122. package/esm/storages/inRedis/RedisAdapter.js +8 -5
  123. package/esm/storages/inRedis/{DefinitionsCacheInRedis.js → SplitsCacheInRedis.js} +76 -76
  124. package/esm/storages/inRedis/index.js +2 -2
  125. package/esm/storages/pluggable/RBSegmentsCachePluggable.js +1 -1
  126. package/esm/storages/pluggable/SplitsCachePluggable.js +209 -0
  127. package/esm/storages/pluggable/index.js +2 -2
  128. package/esm/storages/setRolloutPlan.js +4 -4
  129. package/esm/storages/utils.js +0 -1
  130. package/esm/sync/offline/syncTasks/fromObjectSyncTask.js +6 -6
  131. package/esm/sync/polling/fetchers/splitChangesFetcher.js +16 -25
  132. package/esm/sync/polling/pollingManagerCS.js +17 -17
  133. package/esm/sync/polling/pollingManagerSS.js +15 -15
  134. package/esm/sync/polling/syncTasks/segmentsSyncTask.js +3 -2
  135. package/esm/sync/polling/syncTasks/splitsSyncTask.js +9 -0
  136. package/esm/sync/polling/updaters/mySegmentsUpdater.js +3 -3
  137. package/esm/sync/polling/updaters/segmentChangesUpdater.js +7 -7
  138. package/esm/sync/polling/updaters/{definitionChangesUpdater.js → splitChangesUpdater.js} +68 -65
  139. package/esm/sync/streaming/AuthClient/index.js +1 -1
  140. package/esm/sync/streaming/SSEHandler/NotificationKeeper.js +2 -2
  141. package/esm/sync/streaming/SSEHandler/index.js +2 -2
  142. package/esm/sync/streaming/UpdateWorkers/{DefinitionsUpdateWorker.js → SplitsUpdateWorker.js} +18 -15
  143. package/esm/sync/streaming/constants.js +2 -2
  144. package/esm/sync/streaming/parseUtils.js +9 -9
  145. package/esm/sync/streaming/pushManager.js +18 -18
  146. package/esm/sync/submitters/eventsSubmitter.js +1 -1
  147. package/esm/sync/submitters/impressionCountsSubmitter.js +1 -1
  148. package/esm/sync/submitters/impressionsSubmitter.js +4 -5
  149. package/esm/sync/submitters/telemetrySubmitter.js +4 -3
  150. package/esm/sync/submitters/uniqueKeysSubmitter.js +1 -1
  151. package/esm/sync/syncManagerOnline.js +6 -11
  152. package/esm/utils/Backoff.js +0 -20
  153. package/esm/utils/inputValidation/index.js +3 -3
  154. package/esm/utils/inputValidation/isOperational.js +4 -4
  155. package/esm/utils/inputValidation/{definition.js → split.js} +8 -8
  156. package/esm/utils/inputValidation/splitExistence.js +15 -0
  157. package/esm/utils/inputValidation/splits.js +21 -0
  158. package/esm/utils/labels/index.js +2 -2
  159. package/esm/utils/settingsValidation/index.js +0 -2
  160. package/esm/utils/settingsValidation/splitFilters.js +3 -3
  161. package/esm/utils/settingsValidation/url.js +2 -6
  162. package/package.json +6 -7
  163. package/src/dtos/types.ts +1 -1
  164. package/src/evaluator/Engine.ts +3 -3
  165. package/src/evaluator/condition/index.ts +2 -2
  166. package/src/evaluator/index.ts +27 -35
  167. package/src/evaluator/types.ts +2 -6
  168. package/src/presets/serverSide.ts +3 -3
  169. package/src/sdkClient/client.ts +22 -24
  170. package/src/sdkClient/sdkLifecycle.ts +3 -0
  171. package/src/services/authProvider.ts +41 -19
  172. package/src/services/secureSplitHttpClient.ts +10 -18
  173. package/src/services/serviceApi.ts +27 -24
  174. package/src/services/splitApi.ts +10 -9
  175. package/src/services/types.ts +5 -4
  176. package/src/storages/inRedis/RedisAdapter.ts +8 -5
  177. package/src/sync/polling/pollingManagerCS.ts +80 -78
  178. package/src/sync/polling/pollingManagerSS.ts +49 -45
  179. package/src/sync/polling/updaters/definitionChangesUpdater.ts +3 -3
  180. package/src/sync/polling/updaters/segmentChangesUpdater.ts +1 -1
  181. package/src/sync/streaming/AuthClient/index.ts +14 -15
  182. package/src/sync/streaming/AuthClient/types.ts +9 -13
  183. package/src/sync/streaming/SSEClient/index.ts +2 -2
  184. package/src/sync/streaming/SSEClient/types.ts +2 -2
  185. package/src/sync/streaming/SSEHandler/index.ts +2 -1
  186. package/src/sync/streaming/SSEHandler/types.ts +2 -2
  187. package/src/sync/streaming/constants.ts +1 -0
  188. package/src/sync/streaming/pushManager.ts +32 -42
  189. package/src/sync/streaming/types.ts +3 -2
  190. package/src/sync/submitters/impressionsSubmitter.ts +3 -3
  191. package/src/sync/submitters/types.ts +2 -2
  192. package/src/sync/syncManagerOnline.ts +2 -8
  193. package/src/utils/Backoff.ts +16 -4
  194. package/types/splitio.d.ts +5 -4
  195. package/cjs/platform/browser.js +0 -15
  196. package/cjs/platform/getEventSource/browser.js +0 -8
  197. package/cjs/platform/getEventSource/eventsource.js +0 -480
  198. package/cjs/platform/getEventSource/node.js +0 -26
  199. package/cjs/platform/getFetch/browser.js +0 -9
  200. package/cjs/platform/getFetch/node.js +0 -27
  201. package/cjs/platform/getOptions/node.js +0 -25
  202. package/cjs/platform/node.js +0 -17
  203. package/cjs/sdkClient/sdkLifecycle.js +0 -72
  204. package/cjs/sdkClient/trackMethod.js +0 -56
  205. package/cjs/services/authProvider.js +0 -67
  206. package/cjs/services/secureSplitHttpClient.js +0 -39
  207. package/cjs/services/serviceApi.js +0 -145
  208. package/cjs/storages/AbstractDefinitionsCacheAsync.js +0 -51
  209. package/cjs/storages/AbstractDefinitionsCacheSync.js +0 -76
  210. package/cjs/storages/inLocalStorage/DefinitionsCacheInLocal.js +0 -194
  211. package/cjs/storages/inMemory/DefinitionsCacheInMemory.js +0 -121
  212. package/cjs/storages/pluggable/DefinitionsCachePluggable.js +0 -212
  213. package/cjs/sync/polling/syncTasks/definitionsSyncTask.js +0 -13
  214. package/cjs/utils/EventEmitter.js +0 -391
  215. package/cjs/utils/filter/bloomFilter.js +0 -37
  216. package/cjs/utils/inputValidation/definitions.js +0 -25
  217. package/cjs/utils/inputValidation/target.js +0 -22
  218. package/esm/platform/browser.js +0 -12
  219. package/esm/platform/getEventSource/browser.js +0 -4
  220. package/esm/platform/getEventSource/eventsource.js +0 -480
  221. package/esm/platform/getEventSource/node.js +0 -20
  222. package/esm/platform/getFetch/browser.js +0 -5
  223. package/esm/platform/getFetch/node.js +0 -22
  224. package/esm/platform/getOptions/node.js +0 -20
  225. package/esm/platform/node.js +0 -14
  226. package/esm/sdkClient/sdkLifecycle.js +0 -68
  227. package/esm/sdkClient/trackMethod.js +0 -52
  228. package/esm/services/authProvider.js +0 -63
  229. package/esm/services/secureSplitHttpClient.js +0 -35
  230. package/esm/services/serviceApi.js +0 -141
  231. package/esm/storages/AbstractDefinitionsCacheAsync.js +0 -48
  232. package/esm/storages/AbstractDefinitionsCacheSync.js +0 -71
  233. package/esm/storages/inLocalStorage/DefinitionsCacheInLocal.js +0 -191
  234. package/esm/storages/inMemory/DefinitionsCacheInMemory.js +0 -118
  235. package/esm/storages/pluggable/DefinitionsCachePluggable.js +0 -209
  236. package/esm/sync/polling/syncTasks/definitionsSyncTask.js +0 -9
  237. package/esm/utils/EventEmitter.js +0 -387
  238. package/esm/utils/filter/bloomFilter.js +0 -33
  239. package/esm/utils/inputValidation/definitionExistence.js +0 -15
  240. package/esm/utils/inputValidation/definitions.js +0 -21
  241. package/esm/utils/inputValidation/target.js +0 -18
@@ -1,56 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.trackMethodFactory = void 0;
4
- var thenable_1 = require("../utils/promise/thenable");
5
- var key_1 = require("../utils/key");
6
- var trafficTypeExistence_1 = require("../utils/inputValidation/trafficTypeExistence");
7
- var inputValidation_1 = require("../utils/inputValidation");
8
- var constants_1 = require("../utils/constants");
9
- var mode_1 = require("../utils/settingsValidation/mode");
10
- /**
11
- * Creates a standalone `track` function with input validation.
12
- * Reusable by FF SDK client, Configs SDK, and thin-client SDK.
13
- */
14
- function trackMethodFactory(params, warnTTExistence) {
15
- if (warnTTExistence === void 0) { warnTTExistence = true; }
16
- var settings = params.settings, definitions = params.storage.definitions, telemetryTracker = params.telemetryTracker, eventTracker = params.eventTracker, readinessManager = params.sdkReadinessManager.readinessManager;
17
- var log = settings.log, mode = settings.mode;
18
- var isAsync = (0, mode_1.isConsumerMode)(mode);
19
- return function track(maybeKey, maybeTT, maybeEvent, maybeEventValue, maybeProperties) {
20
- // Input validation
21
- var key = (0, inputValidation_1.validateKey)(log, maybeKey, constants_1.TRACK_FN_LABEL);
22
- var trafficTypeName = (0, inputValidation_1.validateTrafficType)(log, maybeTT, constants_1.TRACK_FN_LABEL);
23
- var eventTypeId = (0, inputValidation_1.validateEvent)(log, maybeEvent, constants_1.TRACK_FN_LABEL);
24
- var value = (0, inputValidation_1.validateEventValue)(log, maybeEventValue, constants_1.TRACK_FN_LABEL);
25
- var _a = (0, inputValidation_1.validateEventProperties)(log, maybeProperties, constants_1.TRACK_FN_LABEL), properties = _a.properties, size = _a.size;
26
- var isNotDestroyed = (0, inputValidation_1.validateIfNotDestroyed)(log, readinessManager, constants_1.TRACK_FN_LABEL);
27
- if (!(isNotDestroyed && key && trafficTypeName && eventTypeId && value !== false && properties !== false)) {
28
- return isAsync ? Promise.resolve(false) : false;
29
- }
30
- // Core logic
31
- var stopTelemetryTracker = telemetryTracker.trackEval(constants_1.TRACK);
32
- var eventData = {
33
- eventTypeId: eventTypeId,
34
- trafficTypeName: trafficTypeName,
35
- value: value,
36
- timestamp: Date.now(),
37
- key: (0, key_1.getMatching)(key),
38
- properties: properties
39
- };
40
- // This may be async but we only warn, we don't actually care if it is valid or not in terms of queueing the event.
41
- if (warnTTExistence)
42
- (0, trafficTypeExistence_1.validateTrafficTypeExistence)(log, readinessManager, definitions, mode, trafficTypeName, constants_1.TRACK_FN_LABEL);
43
- var result = eventTracker.track(eventData, size);
44
- if ((0, thenable_1.thenable)(result)) {
45
- return result.then(function (result) {
46
- stopTelemetryTracker();
47
- return result;
48
- });
49
- }
50
- else {
51
- stopTelemetryTracker();
52
- return result;
53
- }
54
- };
55
- }
56
- exports.trackMethodFactory = trackMethodFactory;
@@ -1,67 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.authProviderFactory = void 0;
4
- var AuthClient_1 = require("../sync/streaming/AuthClient");
5
- var Backoff_1 = require("../utils/Backoff");
6
- var constants_1 = require("../logger/constants");
7
- var constants_2 = require("../utils/constants");
8
- var SKEW_SECONDS = 30;
9
- function isExpired(credential) {
10
- return Date.now() / 1000 + SKEW_SECONDS >= credential.decodedToken.exp;
11
- }
12
- /**
13
- * Factory of AuthProvider, which provides JWT credentials for authenticated HTTP requests.
14
- * Credentials are fetched lazily on demand, cached in memory, and retried with backoff on failure.
15
- */
16
- function authProviderFactory(settings, splitHttpClient, telemetryTracker) {
17
- var urls = settings.urls, log = settings.log;
18
- function fetchAuth() {
19
- var url = "".concat(urls.auth, "/api/v3/auth?capabilities=config,aiconfig");
20
- return splitHttpClient(url, undefined, telemetryTracker.trackHttp(constants_2.TOKEN), false, true);
21
- }
22
- var authenticate = (0, AuthClient_1.authenticateFactory)(fetchAuth);
23
- var backoff = new Backoff_1.Backoff(fetchCredential);
24
- var cachedCredential;
25
- var inFlightPromise;
26
- var stopped = false;
27
- function fetchCredential() {
28
- return authenticate().then(function (credential) {
29
- log.info(constants_1.LOG_PREFIX_SYNC_AUTH + 'credential fetched successfully');
30
- cachedCredential = credential;
31
- inFlightPromise = undefined;
32
- backoff.reset();
33
- return credential;
34
- }).catch(function (error) {
35
- // Avoid rejected promises and unnecessary retries after stop()
36
- if (stopped)
37
- return cachedCredential;
38
- if (error.statusCode && error.statusCode >= 400 && error.statusCode < 500) {
39
- log.error(constants_1.LOG_PREFIX_SYNC_AUTH + 'non-retryable error fetching credential (status ' + error.statusCode + '): ' + error.message);
40
- inFlightPromise = undefined;
41
- throw error;
42
- }
43
- log.warn(constants_1.LOG_PREFIX_SYNC_AUTH + 'credential fetch failed (attempt ' + (backoff.attempts + 1) + '). Error: ' + error.message);
44
- return backoff.scheduleCallAsync();
45
- });
46
- }
47
- return {
48
- credential: function () {
49
- if (cachedCredential && !isExpired(cachedCredential)) {
50
- return Promise.resolve(cachedCredential);
51
- }
52
- if (cachedCredential)
53
- log.debug(constants_1.LOG_PREFIX_SYNC_AUTH + 'cached credential expired');
54
- return inFlightPromise || (inFlightPromise = fetchCredential());
55
- },
56
- invalidate: function () {
57
- cachedCredential = undefined;
58
- },
59
- stop: function () {
60
- stopped = true;
61
- cachedCredential = undefined;
62
- inFlightPromise = undefined;
63
- backoff.reset();
64
- }
65
- };
66
- }
67
- exports.authProviderFactory = authProviderFactory;
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.secureSplitHttpClientFactory = void 0;
4
- var tslib_1 = require("tslib");
5
- var splitHttpClient_1 = require("./splitHttpClient");
6
- var authProvider_1 = require("./authProvider");
7
- /**
8
- * Factory of Secure HTTP client, which authenticates requests using a JWT token.
9
- * On 401 responses, invalidates the cached credential and retries once with a fresh token.
10
- *
11
- * @param settings - SDK settings
12
- * @param platform - object containing environment-specific dependencies
13
- * @param fetchAuth - function to fetch auth credentials from the /v2/auth endpoint
14
- */
15
- function secureSplitHttpClientFactory(settings, platform, telemetryTracker) {
16
- var splitHttpClient = (0, splitHttpClient_1.splitHttpClientFactory)(settings, platform);
17
- var authProvider = (0, authProvider_1.authProviderFactory)(settings, splitHttpClient, telemetryTracker);
18
- function makeRequest(url, options, latencyTracker, logErrorsAsInfo, token) {
19
- return splitHttpClient(url, tslib_1.__assign(tslib_1.__assign({}, options), { headers: tslib_1.__assign(tslib_1.__assign({}, options === null || options === void 0 ? void 0 : options.headers), { Authorization: "Bearer ".concat(token) }) }), latencyTracker, logErrorsAsInfo, true);
20
- }
21
- var httpClient = function (url, options, latencyTracker, logErrorsAsInfo) {
22
- return authProvider.credential().then(function (credential) {
23
- return makeRequest(url, options, latencyTracker, logErrorsAsInfo, credential.token)
24
- .catch(function (error) {
25
- if (error.statusCode === 401) {
26
- // retry once for 401, in case the token has just expired
27
- authProvider.invalidate();
28
- return authProvider.credential().then(function (newCredential) {
29
- return makeRequest(url, options, latencyTracker, logErrorsAsInfo, newCredential.token);
30
- });
31
- }
32
- throw error;
33
- });
34
- });
35
- };
36
- httpClient.stop = function () { return authProvider.stop(); };
37
- return httpClient;
38
- }
39
- exports.secureSplitHttpClientFactory = secureSplitHttpClientFactory;
@@ -1,145 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.serviceApiFactory = void 0;
4
- var splitHttpClient_1 = require("./splitHttpClient");
5
- var objectAssign_1 = require("../utils/lang/objectAssign");
6
- var constants_1 = require("../utils/constants");
7
- var constants_2 = require("../logger/constants");
8
- var noCacheHeaderOptions = { headers: { 'Cache-Control': 'no-cache' } };
9
- function userKeyToQueryParam(userKey) {
10
- return 'users=' + encodeURIComponent(userKey); // no need to check availability of `encodeURIComponent`, since it is a global highly supported.
11
- }
12
- /**
13
- * Factory of ServiceApi objects, which group the collection of HTTP endpoints used by the SDKs
14
- *
15
- * @param settings - validated settings object
16
- * @param platform - object containing environment-specific dependencies
17
- * @param telemetryTracker - telemetry tracker
18
- * @param secureSplitHttpClientFactory - factory of SecureSplitHttpClient objects
19
- */
20
- function serviceApiFactory(settings, platform, telemetryTracker, secureSplitHttpClientFactory) {
21
- var urls = settings.urls;
22
- var filterQueryString = settings.sync.__splitFiltersValidation && settings.sync.__splitFiltersValidation.queryString;
23
- var SplitSDKImpressionsMode = settings.sync.impressionsMode;
24
- var splitHttpClient = (0, splitHttpClient_1.splitHttpClientFactory)(settings, platform);
25
- var secureSplitHttpClient = secureSplitHttpClientFactory(settings, platform, telemetryTracker);
26
- return {
27
- // @TODO throw errors if health check requests fail, to log them in the Synchronizer
28
- getSdkAPIHealthCheck: function () {
29
- var url = "".concat(urls.sdk, "/api/version");
30
- return splitHttpClient(url).then(function () { return true; }).catch(function () { return false; });
31
- },
32
- getEventsAPIHealthCheck: function () {
33
- var url = "".concat(urls.events, "/api/version");
34
- return splitHttpClient(url).then(function () { return true; }).catch(function () { return false; });
35
- },
36
- fetchAuth: function (userMatchingKeys) {
37
- var url = "".concat(urls.auth, "/api/v2/auth?s=").concat(settings.sync.flagSpecVersion);
38
- if (userMatchingKeys) { // `userMatchingKeys` is undefined in server-side
39
- var queryParams = userMatchingKeys.map(userKeyToQueryParam).join('&');
40
- if (queryParams)
41
- url += '&' + queryParams;
42
- }
43
- return splitHttpClient(url, undefined, telemetryTracker.trackHttp(constants_1.TOKEN));
44
- },
45
- fetchSplitChanges: function (since, noCache, till, rbSince) {
46
- var url = "".concat(urls.sdk, "/api/splitChanges?s=").concat(settings.sync.flagSpecVersion, "&since=").concat(since).concat(rbSince ? '&rbSince=' + rbSince : '').concat(filterQueryString || '').concat(till ? '&till=' + till : '');
47
- return splitHttpClient(url, noCache ? noCacheHeaderOptions : undefined, telemetryTracker.trackHttp(constants_1.SPLITS))
48
- .catch(function (err) {
49
- if (err.statusCode === 414)
50
- settings.log.error(constants_2.ERROR_TOO_MANY_SETS);
51
- throw err;
52
- });
53
- },
54
- fetchSegmentChanges: function (since, segmentName, noCache, till) {
55
- var url = "".concat(urls.sdk, "/api/segmentChanges/").concat(segmentName, "?since=").concat(since).concat(till ? '&till=' + till : '');
56
- return splitHttpClient(url, noCache ? noCacheHeaderOptions : undefined, telemetryTracker.trackHttp(constants_1.SEGMENT));
57
- },
58
- // @TODO support filterQueryString and handle ERROR_TOO_MANY_SETS error
59
- fetchConfigs: function (since, noCache, till, rbSince) {
60
- var url = "".concat(urls.configs, "/api/v1/configs?since=").concat(since).concat(rbSince ? '&rbSince=' + rbSince : '').concat(filterQueryString || '').concat(till ? '&till=' + till : '');
61
- return secureSplitHttpClient(url, noCache ? noCacheHeaderOptions : undefined);
62
- },
63
- fetchConfigsSegmentChanges: function (since, segmentName, noCache, till) {
64
- var url = "".concat(urls.configs, "/api/v1/segmentChanges/").concat(segmentName, "?since=").concat(since).concat(till ? '&till=' + till : '');
65
- return secureSplitHttpClient(url, noCache ? noCacheHeaderOptions : undefined);
66
- },
67
- fetchMemberships: function (userMatchingKey, noCache, till) {
68
- /**
69
- * URI encoding of user keys in order to:
70
- * - avoid 400 responses (due to URI malformed). E.g.: '/api/memberships/%'
71
- * - avoid 404 responses. E.g.: '/api/memberships/foo/bar'
72
- * - match user keys with special characters. E.g.: 'foo%bar', 'foo/bar'
73
- */
74
- var url = "".concat(urls.sdk, "/api/memberships/").concat(encodeURIComponent(userMatchingKey)).concat(till ? '?till=' + till : '');
75
- return splitHttpClient(url, noCache ? noCacheHeaderOptions : undefined, telemetryTracker.trackHttp(constants_1.MEMBERSHIPS));
76
- },
77
- /**
78
- * Post events.
79
- *
80
- * @param body - Events bulk payload
81
- * @param headers - Optionals headers to overwrite default ones. For example, it is used in producer mode to overwrite metadata headers.
82
- */
83
- postEventsBulk: function (body, headers) {
84
- var url = "".concat(urls.events, "/api/events/bulk");
85
- return splitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(constants_1.EVENTS));
86
- },
87
- /**
88
- * Post impressions.
89
- *
90
- * @param body - Impressions bulk payload
91
- * @param headers - Optionals headers to overwrite default ones. For example, it is used in producer mode to overwrite metadata headers.
92
- */
93
- postTestImpressionsBulk: function (body, headers) {
94
- var url = "".concat(urls.events, "/api/testImpressions/bulk");
95
- return splitHttpClient(url, {
96
- // Adding extra headers to send impressions in OPTIMIZED or DEBUG modes.
97
- method: 'POST',
98
- body: body,
99
- headers: (0, objectAssign_1.objectAssign)({ SplitSDKImpressionsMode: SplitSDKImpressionsMode }, headers)
100
- }, telemetryTracker.trackHttp(constants_1.IMPRESSIONS));
101
- },
102
- /**
103
- * Post impressions counts.
104
- *
105
- * @param body - Impressions counts payload
106
- * @param headers - Optionals headers to overwrite default ones. For example, it is used in producer mode to overwrite metadata headers.
107
- */
108
- postTestImpressionsCount: function (body, headers) {
109
- var url = "".concat(urls.events, "/api/testImpressions/count");
110
- return splitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(constants_1.IMPRESSIONS_COUNT));
111
- },
112
- /**
113
- * Post unique keys for client side.
114
- *
115
- * @param body - unique keys payload
116
- * @param headers - Optionals headers to overwrite default ones. For example, it is used in producer mode to overwrite metadata headers.
117
- */
118
- postUniqueKeysBulkCs: function (body, headers) {
119
- var url = "".concat(urls.telemetry, "/api/v1/keys/cs");
120
- return splitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(constants_1.TELEMETRY));
121
- },
122
- /**
123
- * Post unique keys for server side.
124
- *
125
- * @param body - unique keys payload
126
- * @param headers - Optionals headers to overwrite default ones. For example, it is used in producer mode to overwrite metadata headers.
127
- */
128
- postUniqueKeysBulkSs: function (body, headers) {
129
- var url = "".concat(urls.telemetry, "/api/v1/keys/ss");
130
- return splitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(constants_1.TELEMETRY));
131
- },
132
- postMetricsConfig: function (body, headers) {
133
- var url = "".concat(urls.telemetry, "/api/v1/metrics/config");
134
- return splitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(constants_1.TELEMETRY), true);
135
- },
136
- postMetricsUsage: function (body, headers) {
137
- var url = "".concat(urls.telemetry, "/api/v1/metrics/usage");
138
- return splitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(constants_1.TELEMETRY), true);
139
- },
140
- stop: function () {
141
- secureSplitHttpClient.stop();
142
- }
143
- };
144
- }
145
- exports.serviceApiFactory = serviceApiFactory;
@@ -1,51 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AbstractDefinitionsCacheAsync = void 0;
4
- var objectAssign_1 = require("../utils/lang/objectAssign");
5
- /**
6
- * This class provides a skeletal implementation of the IDefinitionsCacheAsync interface
7
- * to minimize the effort required to implement this interface.
8
- */
9
- var AbstractDefinitionsCacheAsync = /** @class */ (function () {
10
- function AbstractDefinitionsCacheAsync() {
11
- }
12
- AbstractDefinitionsCacheAsync.prototype.update = function (toAdd, toRemove, changeNumber) {
13
- var _this = this;
14
- return Promise.all([
15
- this.setChangeNumber(changeNumber),
16
- Promise.all(toAdd.map(function (addedFF) { return _this.add(addedFF); })),
17
- Promise.all(toRemove.map(function (removedFF) { return _this.remove(removedFF); }))
18
- ]).then(function (_a) {
19
- var added = _a[1], removed = _a[2];
20
- return added.some(function (result) { return result; }) || removed.some(function (result) { return result; });
21
- });
22
- };
23
- // @TODO revisit segment-related methods ('usesSegments', 'getRegisteredSegments', 'registerSegments')
24
- // noop, just keeping the interface. This is used by standalone client-side API only, and so only implemented by InMemory and InLocalStorage.
25
- AbstractDefinitionsCacheAsync.prototype.usesSegments = function () {
26
- return Promise.resolve(true);
27
- };
28
- /**
29
- * Kill `name` definition and set `defaultTreatment` and `changeNumber`.
30
- * Used for SPLIT_KILL push notifications.
31
- *
32
- * @returns a promise that is resolved once the definition kill operation is performed. The fulfillment value is a boolean: `true` if the operation succeeded updating the definition or `false` if no definition is updated,
33
- * for instance, if the `changeNumber` is old, or if the definition is not found (e.g., `/splitchanges` hasn't been fetched yet), or if the storage fails to apply the update.
34
- * The promise will never be rejected.
35
- */
36
- AbstractDefinitionsCacheAsync.prototype.killLocally = function (name, defaultTreatment, changeNumber) {
37
- var _this = this;
38
- return this.get(name).then(function (definition) {
39
- if (definition && (!definition.changeNumber || definition.changeNumber < changeNumber)) {
40
- var newDefinition = (0, objectAssign_1.objectAssign)({}, definition);
41
- newDefinition.killed = true;
42
- newDefinition.defaultTreatment = defaultTreatment;
43
- newDefinition.changeNumber = changeNumber;
44
- return _this.add(newDefinition);
45
- }
46
- return false;
47
- }).catch(function () { return false; });
48
- };
49
- return AbstractDefinitionsCacheAsync;
50
- }());
51
- exports.AbstractDefinitionsCacheAsync = AbstractDefinitionsCacheAsync;
@@ -1,76 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.usesSegmentsSync = exports.usesSegments = exports.AbstractDefinitionsCacheSync = void 0;
4
- var objectAssign_1 = require("../utils/lang/objectAssign");
5
- var constants_1 = require("../utils/constants");
6
- /**
7
- * This class provides a skeletal implementation of the IDefinitionsCacheSync interface
8
- * to minimize the effort required to implement this interface.
9
- */
10
- var AbstractDefinitionsCacheSync = /** @class */ (function () {
11
- function AbstractDefinitionsCacheSync() {
12
- }
13
- AbstractDefinitionsCacheSync.prototype.update = function (toAdd, toRemove, changeNumber) {
14
- var _this = this;
15
- var updated = toAdd.map(function (addedFF) { return _this.add(addedFF); }).some(function (result) { return result; });
16
- updated = toRemove.map(function (removedFF) { return _this.remove(removedFF); }).some(function (result) { return result; }) || updated;
17
- this.setChangeNumber(changeNumber);
18
- return updated;
19
- };
20
- AbstractDefinitionsCacheSync.prototype.getMany = function (names) {
21
- var _this = this;
22
- var definitions = {};
23
- names.forEach(function (name) {
24
- definitions[name] = _this.get(name);
25
- });
26
- return definitions;
27
- };
28
- AbstractDefinitionsCacheSync.prototype.getAll = function () {
29
- var _this = this;
30
- return this.getNames().map(function (key) { return _this.get(key); });
31
- };
32
- /**
33
- * Kill `name` definition and set `defaultTreatment` and `changeNumber`.
34
- * Used for SPLIT_KILL push notifications.
35
- *
36
- * @returns `true` if the operation successed updating the definition, or `false` if no definition is updated,
37
- * for instance, if the `changeNumber` is old, or if the definition is not found (e.g., `/splitchanges` hasn't been fetched yet), or if the storage fails to apply the update.
38
- */
39
- AbstractDefinitionsCacheSync.prototype.killLocally = function (name, defaultTreatment, changeNumber) {
40
- var definition = this.get(name);
41
- if (definition && (!definition.changeNumber || definition.changeNumber < changeNumber)) {
42
- var newDefinition = (0, objectAssign_1.objectAssign)({}, definition);
43
- newDefinition.killed = true;
44
- newDefinition.defaultTreatment = defaultTreatment;
45
- newDefinition.changeNumber = changeNumber;
46
- return this.add(newDefinition);
47
- }
48
- return false;
49
- };
50
- return AbstractDefinitionsCacheSync;
51
- }());
52
- exports.AbstractDefinitionsCacheSync = AbstractDefinitionsCacheSync;
53
- /**
54
- * Given a parsed definition, it returns a boolean flagging if its conditions use segments matchers (rules & whitelists).
55
- * This util is intended to simplify the implementation of `definitionsCache::usesSegments` method
56
- */
57
- function usesSegments(ruleEntity) {
58
- var conditions = ruleEntity.conditions || [];
59
- for (var i = 0; i < conditions.length; i++) {
60
- var matchers = conditions[i].matcherGroup.matchers;
61
- for (var j = 0; j < matchers.length; j++) {
62
- var matcher = matchers[j].matcherType;
63
- if (matcher === constants_1.IN_SEGMENT || matcher === constants_1.IN_LARGE_SEGMENT)
64
- return true;
65
- }
66
- }
67
- var excluded = ruleEntity.excluded;
68
- if (excluded && excluded.segments && excluded.segments.length > 0)
69
- return true;
70
- return false;
71
- }
72
- exports.usesSegments = usesSegments;
73
- function usesSegmentsSync(storage) {
74
- return storage.definitions.usesSegments() || storage.rbSegments.usesSegments();
75
- }
76
- exports.usesSegmentsSync = usesSegmentsSync;
@@ -1,194 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DefinitionsCacheInLocal = void 0;
4
- var tslib_1 = require("tslib");
5
- var AbstractDefinitionsCacheSync_1 = require("../AbstractDefinitionsCacheSync");
6
- var lang_1 = require("../../utils/lang");
7
- var constants_1 = require("./constants");
8
- var sets_1 = require("../../utils/lang/sets");
9
- var DefinitionsCacheInLocal = /** @class */ (function (_super) {
10
- tslib_1.__extends(DefinitionsCacheInLocal, _super);
11
- function DefinitionsCacheInLocal(settings, keys, storage) {
12
- var _this = _super.call(this) || this;
13
- _this.keys = keys;
14
- _this.log = settings.log;
15
- _this.setsFilter = settings.sync.__splitFiltersValidation.groupedFilters.bySet;
16
- _this.storage = storage;
17
- return _this;
18
- }
19
- DefinitionsCacheInLocal.prototype._decrementCount = function (key) {
20
- var count = (0, lang_1.toNumber)(this.storage.getItem(key)) - 1;
21
- if (count > 0)
22
- this.storage.setItem(key, count + '');
23
- else
24
- this.storage.removeItem(key);
25
- };
26
- DefinitionsCacheInLocal.prototype._decrementCounts = function (definition) {
27
- try {
28
- var ttKey = this.keys.buildTrafficTypeKey(definition.trafficTypeName);
29
- this._decrementCount(ttKey);
30
- if ((0, AbstractDefinitionsCacheSync_1.usesSegments)(definition)) {
31
- var segmentsCountKey = this.keys.buildDefinitionsWithSegmentCountKey();
32
- this._decrementCount(segmentsCountKey);
33
- }
34
- }
35
- catch (e) {
36
- this.log.error(constants_1.LOG_PREFIX + e);
37
- }
38
- };
39
- DefinitionsCacheInLocal.prototype._incrementCounts = function (definition) {
40
- try {
41
- var ttKey = this.keys.buildTrafficTypeKey(definition.trafficTypeName);
42
- this.storage.setItem(ttKey, ((0, lang_1.toNumber)(this.storage.getItem(ttKey)) + 1) + '');
43
- if ((0, AbstractDefinitionsCacheSync_1.usesSegments)(definition)) {
44
- var segmentsCountKey = this.keys.buildDefinitionsWithSegmentCountKey();
45
- this.storage.setItem(segmentsCountKey, ((0, lang_1.toNumber)(this.storage.getItem(segmentsCountKey)) + 1) + '');
46
- }
47
- }
48
- catch (e) {
49
- this.log.error(constants_1.LOG_PREFIX + e);
50
- }
51
- };
52
- /**
53
- * Removes all definitions related data from localStorage (splits, counters, changeNumber and lastUpdated).
54
- * We cannot simply call `localStorage.clear()` since that implies removing user items from the storage.
55
- */
56
- DefinitionsCacheInLocal.prototype.clear = function () {
57
- var _this = this;
58
- // collect item keys
59
- var len = this.storage.length;
60
- var accum = [];
61
- for (var cur = 0; cur < len; cur++) {
62
- var key = this.storage.key(cur);
63
- if (key != null && this.keys.isDefinitionsCacheKey(key))
64
- accum.push(key);
65
- }
66
- // remove items
67
- accum.forEach(function (key) {
68
- _this.storage.removeItem(key);
69
- });
70
- this.hasSync = false;
71
- };
72
- DefinitionsCacheInLocal.prototype.add = function (definition) {
73
- var name = definition.name;
74
- var definitionKey = this.keys.buildDefinitionKey(name);
75
- var definitionFromStorage = this.storage.getItem(definitionKey);
76
- var previousDefinition = definitionFromStorage ? JSON.parse(definitionFromStorage) : null;
77
- if (previousDefinition) {
78
- this._decrementCounts(previousDefinition);
79
- this.removeFromSets(previousDefinition.name, previousDefinition.sets);
80
- }
81
- this.storage.setItem(definitionKey, JSON.stringify(definition));
82
- this._incrementCounts(definition);
83
- this.addToSets(definition);
84
- return true;
85
- };
86
- DefinitionsCacheInLocal.prototype.remove = function (name) {
87
- var definition = this.get(name);
88
- if (!definition)
89
- return false;
90
- this.storage.removeItem(this.keys.buildDefinitionKey(name));
91
- this._decrementCounts(definition);
92
- this.removeFromSets(definition.name, definition.sets);
93
- return true;
94
- };
95
- DefinitionsCacheInLocal.prototype.get = function (name) {
96
- var item = this.storage.getItem(this.keys.buildDefinitionKey(name));
97
- return item && JSON.parse(item);
98
- };
99
- DefinitionsCacheInLocal.prototype.setChangeNumber = function (changeNumber) {
100
- try {
101
- this.storage.setItem(this.keys.buildDefinitionsTillKey(), changeNumber + '');
102
- // update "last updated" timestamp with current time
103
- this.storage.setItem(this.keys.buildLastUpdatedKey(), Date.now() + '');
104
- this.hasSync = true;
105
- return true;
106
- }
107
- catch (e) {
108
- this.log.error(constants_1.LOG_PREFIX + e);
109
- return false;
110
- }
111
- };
112
- DefinitionsCacheInLocal.prototype.getChangeNumber = function () {
113
- var n = -1;
114
- var value = this.storage.getItem(this.keys.buildDefinitionsTillKey());
115
- if (value !== null) {
116
- value = parseInt(value, 10);
117
- return (0, lang_1.isNaNNumber)(value) ? n : value;
118
- }
119
- return n;
120
- };
121
- DefinitionsCacheInLocal.prototype.getNames = function () {
122
- var len = this.storage.length;
123
- var accum = [];
124
- var cur = 0;
125
- while (cur < len) {
126
- var key = this.storage.key(cur);
127
- if (key != null && this.keys.isDefinitionKey(key))
128
- accum.push(this.keys.extractKey(key));
129
- cur++;
130
- }
131
- return accum;
132
- };
133
- DefinitionsCacheInLocal.prototype.trafficTypeExists = function (trafficType) {
134
- var ttCount = (0, lang_1.toNumber)(this.storage.getItem(this.keys.buildTrafficTypeKey(trafficType)));
135
- return (0, lang_1.isFiniteNumber)(ttCount) && ttCount > 0;
136
- };
137
- DefinitionsCacheInLocal.prototype.usesSegments = function () {
138
- // If cache hasn't been synchronized with the cloud, assume we need them.
139
- if (!this.hasSync)
140
- return true;
141
- var storedCount = this.storage.getItem(this.keys.buildDefinitionsWithSegmentCountKey());
142
- var definitionsWithSegmentsCount = storedCount === null ? 0 : (0, lang_1.toNumber)(storedCount);
143
- return (0, lang_1.isFiniteNumber)(definitionsWithSegmentsCount) ?
144
- definitionsWithSegmentsCount > 0 :
145
- true;
146
- };
147
- DefinitionsCacheInLocal.prototype.getNamesBySets = function (sets) {
148
- var _this = this;
149
- return sets.map(function (set) {
150
- var setKey = _this.keys.buildSetKey(set);
151
- var setFromStorage = _this.storage.getItem(setKey);
152
- return new Set(setFromStorage ? JSON.parse(setFromStorage) : []);
153
- });
154
- };
155
- DefinitionsCacheInLocal.prototype.addToSets = function (definition) {
156
- var _this = this;
157
- if (!definition.sets)
158
- return;
159
- definition.sets.forEach(function (set) {
160
- if (_this.setsFilter.length > 0 && !_this.setsFilter.some(function (filterSet) { return filterSet === set; }))
161
- return;
162
- var setKey = _this.keys.buildSetKey(set);
163
- var setFromStorage = _this.storage.getItem(setKey);
164
- var setCache = new Set(setFromStorage ? JSON.parse(setFromStorage) : []);
165
- if (setCache.has(definition.name))
166
- return;
167
- setCache.add(definition.name);
168
- _this.storage.setItem(setKey, JSON.stringify((0, sets_1.setToArray)(setCache)));
169
- });
170
- };
171
- DefinitionsCacheInLocal.prototype.removeFromSets = function (definitionName, sets) {
172
- var _this = this;
173
- if (!sets)
174
- return;
175
- sets.forEach(function (set) {
176
- _this.removeNames(set, definitionName);
177
- });
178
- };
179
- DefinitionsCacheInLocal.prototype.removeNames = function (setName, definitionName) {
180
- var setKey = this.keys.buildSetKey(setName);
181
- var setFromStorage = this.storage.getItem(setKey);
182
- if (!setFromStorage)
183
- return;
184
- var setCache = new Set(JSON.parse(setFromStorage));
185
- setCache.delete(definitionName);
186
- if (setCache.size === 0) {
187
- this.storage.removeItem(setKey);
188
- return;
189
- }
190
- this.storage.setItem(setKey, JSON.stringify((0, sets_1.setToArray)(setCache)));
191
- };
192
- return DefinitionsCacheInLocal;
193
- }(AbstractDefinitionsCacheSync_1.AbstractDefinitionsCacheSync));
194
- exports.DefinitionsCacheInLocal = DefinitionsCacheInLocal;