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

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 (208) hide show
  1. package/CHANGES.txt +2 -0
  2. package/cjs/evaluator/condition/index.js +2 -2
  3. package/cjs/evaluator/fallbackTreatmentsCalculator/fallbackSanitizer/index.js +5 -8
  4. package/cjs/evaluator/index.js +81 -71
  5. package/cjs/listeners/browser.js +2 -1
  6. package/cjs/listeners/node.js +4 -4
  7. package/cjs/logger/constants.js +15 -20
  8. package/cjs/logger/messages/debug.js +5 -6
  9. package/cjs/logger/messages/error.js +3 -3
  10. package/cjs/logger/messages/info.js +3 -4
  11. package/cjs/logger/messages/warn.js +6 -7
  12. package/cjs/platform/browser.js +15 -0
  13. package/cjs/platform/getEventSource/browser.js +8 -0
  14. package/cjs/platform/getEventSource/eventsource.js +480 -0
  15. package/cjs/platform/getEventSource/node.js +26 -0
  16. package/cjs/platform/getFetch/browser.js +9 -0
  17. package/cjs/platform/getFetch/node.js +27 -0
  18. package/cjs/platform/getOptions/node.js +25 -0
  19. package/cjs/platform/node.js +17 -0
  20. package/cjs/presets/serverSide.js +2 -2
  21. package/cjs/readiness/constants.js +5 -4
  22. package/cjs/readiness/readinessManager.js +23 -23
  23. package/cjs/readiness/sdkReadinessManager.js +1 -17
  24. package/cjs/sdkClient/client.js +24 -50
  25. package/cjs/sdkClient/clientInputValidation.js +6 -17
  26. package/cjs/sdkClient/sdkClient.js +3 -60
  27. package/cjs/sdkClient/sdkLifecycle.js +74 -0
  28. package/cjs/sdkClient/trackMethod.js +56 -0
  29. package/cjs/sdkFactory/index.js +11 -15
  30. package/cjs/sdkManager/index.js +5 -5
  31. package/cjs/services/authProvider.js +80 -0
  32. package/cjs/services/decorateHeaders.js +2 -1
  33. package/cjs/services/secureSplitHttpClient.js +36 -0
  34. package/cjs/services/serviceApi.js +147 -0
  35. package/cjs/services/splitApi.js +24 -10
  36. package/cjs/services/splitHttpClient.js +3 -5
  37. package/cjs/storages/AbstractDefinitionsCacheAsync.js +51 -0
  38. package/cjs/storages/AbstractDefinitionsCacheSync.js +76 -0
  39. package/cjs/storages/KeyBuilder.js +6 -6
  40. package/cjs/storages/KeyBuilderCS.js +5 -5
  41. package/cjs/storages/KeyBuilderSS.js +2 -2
  42. package/cjs/storages/getRolloutPlan.js +3 -3
  43. package/cjs/storages/inLocalStorage/DefinitionsCacheInLocal.js +194 -0
  44. package/cjs/storages/inLocalStorage/MySegmentsCacheInLocal.js +1 -2
  45. package/cjs/storages/inLocalStorage/RBSegmentsCacheInLocal.js +10 -10
  46. package/cjs/storages/inLocalStorage/index.js +6 -6
  47. package/cjs/storages/inLocalStorage/validateCache.js +3 -3
  48. package/cjs/storages/inMemory/DefinitionsCacheInMemory.js +121 -0
  49. package/cjs/storages/inMemory/InMemoryStorage.js +4 -4
  50. package/cjs/storages/inMemory/InMemoryStorageCS.js +5 -5
  51. package/cjs/storages/inMemory/RBSegmentsCacheInMemory.js +5 -5
  52. package/cjs/storages/inMemory/SegmentsCacheInMemory.js +1 -1
  53. package/cjs/storages/inMemory/TelemetryCacheInMemory.js +5 -5
  54. package/cjs/storages/inRedis/{SplitsCacheInRedis.js → DefinitionsCacheInRedis.js} +77 -77
  55. package/cjs/storages/inRedis/RBSegmentsCacheInRedis.js +1 -1
  56. package/cjs/storages/inRedis/index.js +2 -2
  57. package/cjs/storages/pluggable/DefinitionsCachePluggable.js +212 -0
  58. package/cjs/storages/pluggable/RBSegmentsCachePluggable.js +1 -1
  59. package/cjs/storages/pluggable/index.js +2 -2
  60. package/cjs/storages/setRolloutPlan.js +4 -4
  61. package/cjs/storages/utils.js +1 -0
  62. package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +5 -5
  63. package/cjs/sync/polling/fetchers/splitChangesFetcher.js +24 -15
  64. package/cjs/sync/polling/pollingManagerCS.js +86 -81
  65. package/cjs/sync/polling/pollingManagerSS.js +44 -36
  66. package/cjs/sync/polling/syncTasks/definitionsSyncTask.js +13 -0
  67. package/cjs/sync/polling/syncTasks/segmentsSyncTask.js +2 -3
  68. package/cjs/sync/polling/updaters/{splitChangesUpdater.js → definitionChangesUpdater.js} +66 -69
  69. package/cjs/sync/polling/updaters/mySegmentsUpdater.js +3 -3
  70. package/cjs/sync/polling/updaters/segmentChangesUpdater.js +6 -6
  71. package/cjs/sync/streaming/AuthClient/index.js +13 -14
  72. package/cjs/sync/streaming/SSEHandler/NotificationKeeper.js +1 -1
  73. package/cjs/sync/streaming/SSEHandler/index.js +2 -1
  74. package/cjs/sync/streaming/UpdateWorkers/{SplitsUpdateWorker.js → DefinitionsUpdateWorker.js} +16 -19
  75. package/cjs/sync/streaming/constants.js +4 -3
  76. package/cjs/sync/streaming/parseUtils.js +11 -11
  77. package/cjs/sync/streaming/pushManager.js +20 -25
  78. package/cjs/sync/submitters/eventsSubmitter.js +1 -1
  79. package/cjs/sync/submitters/impressionCountsSubmitter.js +1 -1
  80. package/cjs/sync/submitters/impressionsSubmitter.js +5 -4
  81. package/cjs/sync/submitters/telemetrySubmitter.js +3 -4
  82. package/cjs/sync/submitters/uniqueKeysSubmitter.js +1 -1
  83. package/cjs/sync/syncManagerOnline.js +5 -5
  84. package/cjs/utils/Backoff.js +35 -3
  85. package/cjs/utils/EventEmitter.js +391 -0
  86. package/cjs/utils/filter/bloomFilter.js +37 -0
  87. package/cjs/utils/inputValidation/{split.js → definition.js} +10 -10
  88. package/cjs/utils/inputValidation/{splitExistence.js → definitionExistence.js} +6 -6
  89. package/cjs/utils/inputValidation/definitions.js +25 -0
  90. package/cjs/utils/inputValidation/index.js +7 -7
  91. package/cjs/utils/inputValidation/isOperational.js +4 -4
  92. package/cjs/utils/inputValidation/target.js +22 -0
  93. package/cjs/utils/labels/index.js +3 -3
  94. package/cjs/utils/settingsValidation/index.js +2 -0
  95. package/cjs/utils/settingsValidation/splitFilters.js +3 -3
  96. package/cjs/utils/settingsValidation/url.js +6 -2
  97. package/esm/evaluator/condition/index.js +2 -2
  98. package/esm/evaluator/fallbackTreatmentsCalculator/fallbackSanitizer/index.js +5 -8
  99. package/esm/evaluator/index.js +80 -71
  100. package/esm/listeners/browser.js +2 -1
  101. package/esm/listeners/node.js +4 -4
  102. package/esm/logger/constants.js +12 -17
  103. package/esm/logger/messages/debug.js +5 -6
  104. package/esm/logger/messages/error.js +3 -3
  105. package/esm/logger/messages/info.js +3 -4
  106. package/esm/logger/messages/warn.js +6 -7
  107. package/esm/platform/browser.js +12 -0
  108. package/esm/platform/getEventSource/browser.js +4 -0
  109. package/esm/platform/getEventSource/eventsource.js +480 -0
  110. package/esm/platform/getEventSource/node.js +20 -0
  111. package/esm/platform/getFetch/browser.js +5 -0
  112. package/esm/platform/getFetch/node.js +22 -0
  113. package/esm/platform/getOptions/node.js +20 -0
  114. package/esm/platform/node.js +14 -0
  115. package/esm/presets/serverSide.js +2 -2
  116. package/esm/readiness/constants.js +4 -3
  117. package/esm/readiness/readinessManager.js +24 -24
  118. package/esm/readiness/sdkReadinessManager.js +2 -18
  119. package/esm/sdkClient/client.js +23 -50
  120. package/esm/sdkClient/clientInputValidation.js +8 -19
  121. package/esm/sdkClient/sdkClient.js +3 -60
  122. package/esm/sdkClient/sdkLifecycle.js +70 -0
  123. package/esm/sdkClient/trackMethod.js +52 -0
  124. package/esm/sdkFactory/index.js +12 -16
  125. package/esm/sdkManager/index.js +6 -6
  126. package/esm/services/authProvider.js +76 -0
  127. package/esm/services/decorateHeaders.js +2 -1
  128. package/esm/services/secureSplitHttpClient.js +32 -0
  129. package/esm/services/serviceApi.js +143 -0
  130. package/esm/services/splitApi.js +24 -10
  131. package/esm/services/splitHttpClient.js +3 -5
  132. package/esm/storages/AbstractDefinitionsCacheAsync.js +48 -0
  133. package/esm/storages/AbstractDefinitionsCacheSync.js +71 -0
  134. package/esm/storages/KeyBuilder.js +6 -6
  135. package/esm/storages/KeyBuilderCS.js +5 -5
  136. package/esm/storages/KeyBuilderSS.js +2 -2
  137. package/esm/storages/getRolloutPlan.js +3 -3
  138. package/esm/storages/inLocalStorage/DefinitionsCacheInLocal.js +191 -0
  139. package/esm/storages/inLocalStorage/MySegmentsCacheInLocal.js +1 -2
  140. package/esm/storages/inLocalStorage/RBSegmentsCacheInLocal.js +7 -7
  141. package/esm/storages/inLocalStorage/index.js +6 -6
  142. package/esm/storages/inLocalStorage/validateCache.js +3 -3
  143. package/esm/storages/inMemory/DefinitionsCacheInMemory.js +118 -0
  144. package/esm/storages/inMemory/InMemoryStorage.js +4 -4
  145. package/esm/storages/inMemory/InMemoryStorageCS.js +5 -5
  146. package/esm/storages/inMemory/RBSegmentsCacheInMemory.js +2 -2
  147. package/esm/storages/inMemory/SegmentsCacheInMemory.js +1 -1
  148. package/esm/storages/inMemory/TelemetryCacheInMemory.js +5 -5
  149. package/esm/storages/inRedis/{SplitsCacheInRedis.js → DefinitionsCacheInRedis.js} +76 -76
  150. package/esm/storages/inRedis/RBSegmentsCacheInRedis.js +1 -1
  151. package/esm/storages/inRedis/index.js +2 -2
  152. package/esm/storages/pluggable/DefinitionsCachePluggable.js +209 -0
  153. package/esm/storages/pluggable/RBSegmentsCachePluggable.js +1 -1
  154. package/esm/storages/pluggable/index.js +2 -2
  155. package/esm/storages/setRolloutPlan.js +4 -4
  156. package/esm/storages/utils.js +1 -0
  157. package/esm/sync/offline/syncTasks/fromObjectSyncTask.js +6 -6
  158. package/esm/sync/polling/fetchers/splitChangesFetcher.js +25 -16
  159. package/esm/sync/polling/pollingManagerCS.js +87 -82
  160. package/esm/sync/polling/pollingManagerSS.js +44 -36
  161. package/esm/sync/polling/syncTasks/definitionsSyncTask.js +9 -0
  162. package/esm/sync/polling/syncTasks/segmentsSyncTask.js +2 -3
  163. package/esm/sync/polling/updaters/definitionChangesUpdater.js +191 -0
  164. package/esm/sync/polling/updaters/mySegmentsUpdater.js +3 -3
  165. package/esm/sync/polling/updaters/segmentChangesUpdater.js +7 -7
  166. package/esm/sync/streaming/AuthClient/index.js +11 -11
  167. package/esm/sync/streaming/SSEHandler/NotificationKeeper.js +2 -2
  168. package/esm/sync/streaming/SSEHandler/index.js +3 -2
  169. package/esm/sync/streaming/UpdateWorkers/{SplitsUpdateWorker.js → DefinitionsUpdateWorker.js} +15 -18
  170. package/esm/sync/streaming/constants.js +3 -2
  171. package/esm/sync/streaming/parseUtils.js +9 -9
  172. package/esm/sync/streaming/pushManager.js +22 -27
  173. package/esm/sync/submitters/eventsSubmitter.js +1 -1
  174. package/esm/sync/submitters/impressionCountsSubmitter.js +1 -1
  175. package/esm/sync/submitters/impressionsSubmitter.js +5 -4
  176. package/esm/sync/submitters/telemetrySubmitter.js +3 -4
  177. package/esm/sync/submitters/uniqueKeysSubmitter.js +1 -1
  178. package/esm/sync/syncManagerOnline.js +4 -4
  179. package/esm/utils/Backoff.js +35 -3
  180. package/esm/utils/EventEmitter.js +387 -0
  181. package/esm/utils/filter/bloomFilter.js +33 -0
  182. package/esm/utils/inputValidation/{split.js → definition.js} +8 -8
  183. package/esm/utils/inputValidation/definitionExistence.js +15 -0
  184. package/esm/utils/inputValidation/definitions.js +21 -0
  185. package/esm/utils/inputValidation/index.js +3 -3
  186. package/esm/utils/inputValidation/isOperational.js +4 -4
  187. package/esm/utils/inputValidation/target.js +18 -0
  188. package/esm/utils/labels/index.js +2 -2
  189. package/esm/utils/settingsValidation/index.js +2 -0
  190. package/esm/utils/settingsValidation/splitFilters.js +3 -3
  191. package/esm/utils/settingsValidation/url.js +6 -2
  192. package/package.json +1 -1
  193. package/cjs/storages/AbstractSplitsCacheAsync.js +0 -51
  194. package/cjs/storages/AbstractSplitsCacheSync.js +0 -76
  195. package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +0 -194
  196. package/cjs/storages/inMemory/SplitsCacheInMemory.js +0 -121
  197. package/cjs/storages/pluggable/SplitsCachePluggable.js +0 -212
  198. package/cjs/sync/polling/syncTasks/splitsSyncTask.js +0 -13
  199. package/cjs/utils/inputValidation/splits.js +0 -25
  200. package/esm/storages/AbstractSplitsCacheAsync.js +0 -48
  201. package/esm/storages/AbstractSplitsCacheSync.js +0 -71
  202. package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +0 -191
  203. package/esm/storages/inMemory/SplitsCacheInMemory.js +0 -118
  204. package/esm/storages/pluggable/SplitsCachePluggable.js +0 -209
  205. package/esm/sync/polling/syncTasks/splitsSyncTask.js +0 -9
  206. package/esm/sync/polling/updaters/splitChangesUpdater.js +0 -194
  207. package/esm/utils/inputValidation/splitExistence.js +0 -15
  208. package/esm/utils/inputValidation/splits.js +0 -21
@@ -1,194 +0,0 @@
1
- import { timeout } from '../../../utils/promise/timeout';
2
- import { SDK_SPLITS_ARRIVED, FLAGS_UPDATE, SEGMENTS_UPDATE } from '../../../readiness/constants';
3
- import { SYNC_SPLITS_FETCH, SYNC_SPLITS_UPDATE, SYNC_RBS_UPDATE, SYNC_SPLITS_FETCH_FAILS, SYNC_SPLITS_FETCH_RETRY } from '../../../logger/constants';
4
- import { startsWith } from '../../../utils/lang';
5
- import { IN_RULE_BASED_SEGMENT, IN_SEGMENT, RULE_BASED_SEGMENT, STANDARD_SEGMENT } from '../../../utils/constants';
6
- import { setToArray } from '../../../utils/lang/sets';
7
- import { SPLIT_UPDATE } from '../../streaming/constants';
8
- // Checks that all registered segments have been fetched (changeNumber !== -1 for every segment).
9
- // Returns a promise that could be rejected.
10
- // @TODO review together with Segments and MySegments storage APIs
11
- function checkAllSegmentsExist(segments) {
12
- var registeredSegments = Promise.resolve(segments.getRegisteredSegments());
13
- return registeredSegments.then(function (segmentNames) {
14
- return Promise.all(segmentNames.map(function (segmentName) { return segments.getChangeNumber(segmentName); }))
15
- .then(function (changeNumbers) { return changeNumbers.every(function (changeNumber) { return changeNumber !== undefined; }); });
16
- });
17
- }
18
- /**
19
- * Collect segments from a raw FF or RBS definition.
20
- * Exported for testing purposes.
21
- */
22
- export function parseSegments(ruleEntity, matcherType) {
23
- if (matcherType === void 0) { matcherType = IN_SEGMENT; }
24
- var _a = ruleEntity, conditions = _a.conditions, excluded = _a.excluded;
25
- var segments = new Set();
26
- if (excluded && excluded.segments) {
27
- excluded.segments.forEach(function (_a) {
28
- var type = _a.type, name = _a.name;
29
- if ((type === STANDARD_SEGMENT && matcherType === IN_SEGMENT) || (type === RULE_BASED_SEGMENT && matcherType === IN_RULE_BASED_SEGMENT)) {
30
- segments.add(name);
31
- }
32
- });
33
- }
34
- if (conditions) {
35
- for (var i = 0; i < conditions.length; i++) {
36
- var matchers = conditions[i].matcherGroup.matchers;
37
- matchers.forEach(function (matcher) {
38
- if (matcher.matcherType === matcherType)
39
- segments.add(matcher.userDefinedSegmentMatcherData.segmentName);
40
- });
41
- }
42
- }
43
- return segments;
44
- }
45
- /**
46
- * If there are defined filters and one feature flag doesn't match with them, its status is changed to 'ARCHIVE' to avoid storing it
47
- * If there is `bySet` filter, `byName` and `byPrefix` filters are ignored
48
- *
49
- * @param featureFlag - feature flag to be evaluated
50
- * @param filters - splitFiltersValidation bySet | byName
51
- */
52
- function matchFilters(featureFlag, filters) {
53
- var _a = filters.groupedFilters, setsFilter = _a.bySet, namesFilter = _a.byName, prefixFilter = _a.byPrefix;
54
- if (setsFilter.length > 0)
55
- return featureFlag.sets && featureFlag.sets.some(function (featureFlagSet) { return setsFilter.indexOf(featureFlagSet) > -1; });
56
- var namesFilterConfigured = namesFilter.length > 0;
57
- var prefixFilterConfigured = prefixFilter.length > 0;
58
- if (!namesFilterConfigured && !prefixFilterConfigured)
59
- return true;
60
- var matchNames = namesFilterConfigured && namesFilter.indexOf(featureFlag.name) > -1;
61
- var matchPrefix = prefixFilterConfigured && prefixFilter.some(function (prefix) { return startsWith(featureFlag.name, prefix); });
62
- return matchNames || matchPrefix;
63
- }
64
- /**
65
- * Given the list of splits from /splitChanges endpoint, it returns the mutations,
66
- * i.e., an object with added splits, removed splits and used segments.
67
- * Exported for testing purposes.
68
- */
69
- export function computeMutation(rules, segments, filters) {
70
- return rules.reduce(function (accum, ruleEntity) {
71
- if (ruleEntity.status !== 'ARCHIVED' && (!filters || matchFilters(ruleEntity, filters))) {
72
- accum.added.push(ruleEntity);
73
- parseSegments(ruleEntity).forEach(function (segmentName) {
74
- segments.add(segmentName);
75
- });
76
- }
77
- else {
78
- accum.removed.push(ruleEntity);
79
- }
80
- accum.names.push(ruleEntity.name);
81
- return accum;
82
- }, { added: [], removed: [], names: [] });
83
- }
84
- /**
85
- * factory of SplitChanges updater, a task that:
86
- * - fetches split changes using `splitChangesFetcher`
87
- * - updates `splitsCache`
88
- * - uses `splitsEventEmitter` to emit events related to split data updates
89
- *
90
- * @param log - Logger instance
91
- * @param splitChangesFetcher - Fetcher of `/splitChanges`
92
- * @param splits - Splits storage, with sync or async methods
93
- * @param segments - Segments storage, with sync or async methods
94
- * @param splitsEventEmitter - Optional readiness manager. Not required for synchronizer or producer mode.
95
- * @param requestTimeoutBeforeReady - How long the updater will wait for the request to timeout. Default 0, i.e., never timeout.
96
- * @param retriesOnFailureBeforeReady - How many retries on `/splitChanges` we the updater do in case of failure or timeout. Default 0, i.e., no retries.
97
- */
98
- export function splitChangesUpdaterFactory(log, splitChangesFetcher, storage, splitFiltersValidation, splitsEventEmitter, requestTimeoutBeforeReady, retriesOnFailureBeforeReady, isClientSide) {
99
- if (requestTimeoutBeforeReady === void 0) { requestTimeoutBeforeReady = 0; }
100
- if (retriesOnFailureBeforeReady === void 0) { retriesOnFailureBeforeReady = 0; }
101
- var splits = storage.splits, rbSegments = storage.rbSegments, segments = storage.segments;
102
- var startingUp = true;
103
- /** timeout decorator for `splitChangesFetcher` promise */
104
- function _promiseDecorator(promise) {
105
- if (startingUp && requestTimeoutBeforeReady)
106
- promise = timeout(requestTimeoutBeforeReady, promise);
107
- return promise;
108
- }
109
- /**
110
- * SplitChanges updater returns a promise that resolves with a `false` boolean value if it fails to fetch splits or synchronize them with the storage.
111
- * Returned promise will not be rejected.
112
- *
113
- * @param noCache - true to revalidate data to fetch
114
- * @param till - query param to bypass CDN requests
115
- */
116
- return function splitChangesUpdater(noCache, till, instantUpdate) {
117
- /**
118
- * @param since - current changeNumber at splitsCache
119
- * @param retry - current number of retry attempts
120
- */
121
- function _splitChangesUpdater(sinces, retry) {
122
- if (retry === void 0) { retry = 0; }
123
- var since = sinces[0], rbSince = sinces[1];
124
- log.debug(SYNC_SPLITS_FETCH, sinces);
125
- return Promise.resolve(instantUpdate ?
126
- instantUpdate.type === SPLIT_UPDATE ?
127
- // IFFU edge case: a change to a flag that adds an IN_RULE_BASED_SEGMENT matcher that is not present yet
128
- Promise.resolve(rbSegments.contains(parseSegments(instantUpdate.payload, IN_RULE_BASED_SEGMENT))).then(function (contains) {
129
- return contains ?
130
- { ff: { d: [instantUpdate.payload], t: instantUpdate.changeNumber } } :
131
- splitChangesFetcher(since, noCache, till, rbSince, _promiseDecorator);
132
- }) :
133
- { rbs: { d: [instantUpdate.payload], t: instantUpdate.changeNumber } } :
134
- splitChangesFetcher(since, noCache, till, rbSince, _promiseDecorator))
135
- .then(function (splitChanges) {
136
- var usedSegments = new Set();
137
- var updatedFlags = [];
138
- var ffUpdate = false;
139
- if (splitChanges.ff) {
140
- var _a = computeMutation(splitChanges.ff.d || [], usedSegments, splitFiltersValidation), added = _a.added, removed = _a.removed, names = _a.names;
141
- updatedFlags = names;
142
- log.debug(SYNC_SPLITS_UPDATE, [added.length, removed.length]);
143
- ffUpdate = splits.update(added, removed, splitChanges.ff.t);
144
- }
145
- var rbsUpdate = false;
146
- if (splitChanges.rbs) {
147
- var _b = computeMutation(splitChanges.rbs.d || [], usedSegments), added = _b.added, removed = _b.removed;
148
- log.debug(SYNC_RBS_UPDATE, [added.length, removed.length]);
149
- rbsUpdate = rbSegments.update(added, removed, splitChanges.rbs.t);
150
- }
151
- return Promise.all([ffUpdate, rbsUpdate,
152
- // @TODO if at least 1 segment fetch fails due to 404 and other segments are updated in the storage, SDK_UPDATE is not emitted
153
- segments.registerSegments(setToArray(usedSegments))
154
- ]).then(function (_a) {
155
- var ffChanged = _a[0], rbsChanged = _a[1];
156
- if (storage.save)
157
- storage.save();
158
- startingUp = false;
159
- if (splitsEventEmitter) {
160
- // To emit SDK_SPLITS_ARRIVED for server-side SDK, we must check that all registered segments have been fetched
161
- return Promise.resolve(!splitsEventEmitter.splitsArrived || ((ffChanged || rbsChanged) && (isClientSide || checkAllSegmentsExist(segments))))
162
- .catch(function () { return false; } /** noop. just to handle a possible `checkAllSegmentsExist` rejection, before emitting SDK event */)
163
- .then(function (emitSplitsArrivedEvent) {
164
- // emit SDK events
165
- if (emitSplitsArrivedEvent) {
166
- var metadata = {
167
- type: updatedFlags.length > 0 ? FLAGS_UPDATE : SEGMENTS_UPDATE,
168
- names: updatedFlags.length > 0 ? updatedFlags : []
169
- };
170
- splitsEventEmitter.emit(SDK_SPLITS_ARRIVED, metadata);
171
- }
172
- return true;
173
- });
174
- }
175
- return true;
176
- });
177
- })
178
- .catch(function (error) {
179
- if (startingUp && retriesOnFailureBeforeReady > retry) {
180
- retry += 1;
181
- log.warn(SYNC_SPLITS_FETCH_RETRY, [retry, error]);
182
- return _splitChangesUpdater(sinces, retry);
183
- }
184
- else {
185
- startingUp = false;
186
- log.warn(SYNC_SPLITS_FETCH_FAILS, [error]);
187
- }
188
- return false;
189
- });
190
- }
191
- // `getChangeNumber` never rejects or throws error
192
- return Promise.all([splits.getChangeNumber(), rbSegments.getChangeNumber()]).then(_splitChangesUpdater);
193
- };
194
- }
@@ -1,15 +0,0 @@
1
- import { FALLBACK_SPLIT_NOT_FOUND, SPLIT_NOT_FOUND } from '../labels';
2
- import { WARN_NOT_EXISTENT_SPLIT } from '../../logger/constants';
3
- /**
4
- * This is defined here and in this format mostly because of the logger and the fact that it's considered a validation at product level.
5
- * But it's not going to run on the input validation layer. In any case, the most compelling reason to use it as we do is to avoid going to Redis and get a split twice.
6
- */
7
- export function validateSplitExistence(log, readinessManager, splitName, labelOrSplitObj, method) {
8
- if (readinessManager.isReady()) { // Only if it's ready (synced with BE) we validate this, otherwise it may just be that the SDK is still syncing
9
- if (labelOrSplitObj === SPLIT_NOT_FOUND || labelOrSplitObj === FALLBACK_SPLIT_NOT_FOUND || labelOrSplitObj == null) {
10
- log.warn(WARN_NOT_EXISTENT_SPLIT, [method, splitName]);
11
- return false;
12
- }
13
- }
14
- return true;
15
- }
@@ -1,21 +0,0 @@
1
- import { ERROR_EMPTY_ARRAY } from '../../logger/constants';
2
- import { uniq } from '../lang';
3
- import { validateSplit } from './split';
4
- export function validateSplits(log, maybeSplits, method, listName, item) {
5
- if (listName === void 0) { listName = 'feature flag names'; }
6
- if (item === void 0) { item = 'feature flag name'; }
7
- if (Array.isArray(maybeSplits) && maybeSplits.length > 0) {
8
- var validatedArray_1 = [];
9
- // Remove invalid values
10
- maybeSplits.forEach(function (maybeSplit) {
11
- var splitName = validateSplit(log, maybeSplit, method, item);
12
- if (splitName)
13
- validatedArray_1.push(splitName);
14
- });
15
- // Strip off duplicated values if we have valid split names then return
16
- if (validatedArray_1.length)
17
- return uniq(validatedArray_1);
18
- }
19
- log.error(ERROR_EMPTY_ARRAY, [method, listName]);
20
- return false;
21
- }