@splitsoftware/splitio-commons 1.17.2-rc.0 → 1.17.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.
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +16 -40
- package/cjs/sync/polling/updaters/splitChangesUpdater.js +3 -5
- package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +16 -40
- package/esm/sync/polling/updaters/splitChangesUpdater.js +3 -5
- package/package.json +1 -1
- package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +17 -41
- package/src/sync/polling/updaters/splitChangesUpdater.ts +5 -7
- package/types/storages/inLocalStorage/SplitsCacheInLocal.d.ts +0 -1
|
@@ -88,52 +88,28 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
88
88
|
this.hasSync = false;
|
|
89
89
|
};
|
|
90
90
|
SplitsCacheInLocal.prototype.addSplit = function (name, split) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return true;
|
|
101
|
-
}
|
|
102
|
-
catch (e) {
|
|
103
|
-
this.log.error(constants_1.LOG_PREFIX + e);
|
|
104
|
-
return false;
|
|
105
|
-
}
|
|
91
|
+
var splitKey = this.keys.buildSplitKey(name);
|
|
92
|
+
var splitFromLocalStorage = localStorage.getItem(splitKey);
|
|
93
|
+
var previousSplit = splitFromLocalStorage ? JSON.parse(splitFromLocalStorage) : null;
|
|
94
|
+
localStorage.setItem(splitKey, JSON.stringify(split));
|
|
95
|
+
this._incrementCounts(split);
|
|
96
|
+
this._decrementCounts(previousSplit);
|
|
97
|
+
// if (previousSplit) this.removeFromFlagSets(previousSplit.name, previousSplit.sets);
|
|
98
|
+
// this.addToFlagSets(split);
|
|
99
|
+
return true;
|
|
106
100
|
};
|
|
107
101
|
SplitsCacheInLocal.prototype.removeSplit = function (name) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
return true;
|
|
114
|
-
}
|
|
115
|
-
catch (e) {
|
|
116
|
-
this.log.error(constants_1.LOG_PREFIX + e);
|
|
117
|
-
return false;
|
|
118
|
-
}
|
|
102
|
+
var split = this.getSplit(name);
|
|
103
|
+
localStorage.removeItem(this.keys.buildSplitKey(name));
|
|
104
|
+
this._decrementCounts(split);
|
|
105
|
+
// if (split) this.removeFromFlagSets(split.name, split.sets);
|
|
106
|
+
return true;
|
|
119
107
|
};
|
|
120
108
|
SplitsCacheInLocal.prototype.getSplit = function (name) {
|
|
121
109
|
var item = localStorage.getItem(this.keys.buildSplitKey(name));
|
|
122
110
|
return item && JSON.parse(item);
|
|
123
111
|
};
|
|
124
112
|
SplitsCacheInLocal.prototype.setChangeNumber = function (changeNumber) {
|
|
125
|
-
// when using a new split query, we must update it at the store
|
|
126
|
-
if (this.updateNewFilter) {
|
|
127
|
-
this.log.info(constants_1.LOG_PREFIX + 'SDK key, flags filter criteria or flags spec version was modified. Updating cache');
|
|
128
|
-
var storageHashKey = this.keys.buildHashKey();
|
|
129
|
-
try {
|
|
130
|
-
localStorage.setItem(storageHashKey, this.storageHash);
|
|
131
|
-
}
|
|
132
|
-
catch (e) {
|
|
133
|
-
this.log.error(constants_1.LOG_PREFIX + e);
|
|
134
|
-
}
|
|
135
|
-
this.updateNewFilter = false;
|
|
136
|
-
}
|
|
137
113
|
try {
|
|
138
114
|
localStorage.setItem(this.keys.buildSplitsTillKey(), changeNumber + '');
|
|
139
115
|
// update "last updated" timestamp with current time
|
|
@@ -211,11 +187,11 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
211
187
|
var storageHash = localStorage.getItem(storageHashKey);
|
|
212
188
|
if (storageHash !== this.storageHash) {
|
|
213
189
|
try {
|
|
214
|
-
// mark cache to update the new query filter on first successful splits fetch
|
|
215
|
-
this.updateNewFilter = true;
|
|
216
190
|
// if there is cache, clear it
|
|
217
191
|
if (this.checkCache())
|
|
218
192
|
this.clear();
|
|
193
|
+
this.log.info(constants_1.LOG_PREFIX + 'SDK key, flags filter criteria or flags spec version was modified. Updating cache');
|
|
194
|
+
localStorage.setItem(storageHashKey, this.storageHash);
|
|
219
195
|
}
|
|
220
196
|
catch (e) {
|
|
221
197
|
this.log.error(constants_1.LOG_PREFIX + e);
|
|
@@ -102,7 +102,7 @@ function splitChangesUpdaterFactory(log, splitChangesFetcher, splits, segments,
|
|
|
102
102
|
}
|
|
103
103
|
/** Returns true if at least one split was updated */
|
|
104
104
|
function isThereUpdate(flagsChange) {
|
|
105
|
-
var added = flagsChange[
|
|
105
|
+
var added = flagsChange[0], removed = flagsChange[1];
|
|
106
106
|
// There is at least one added or modified feature flag
|
|
107
107
|
if (added && added.some(function (update) { return update; }))
|
|
108
108
|
return true;
|
|
@@ -130,20 +130,18 @@ function splitChangesUpdaterFactory(log, splitChangesFetcher, splits, segments,
|
|
|
130
130
|
{ splits: [splitUpdateNotification.payload], till: splitUpdateNotification.changeNumber } :
|
|
131
131
|
splitChangesFetcher(since, noCache, till, _promiseDecorator))
|
|
132
132
|
.then(function (splitChanges) {
|
|
133
|
-
startingUp = false;
|
|
134
133
|
var mutation = computeSplitsMutation(splitChanges.splits, splitFiltersValidation);
|
|
135
134
|
log.debug(constants_2.SYNC_SPLITS_NEW, [mutation.added.length]);
|
|
136
135
|
log.debug(constants_2.SYNC_SPLITS_REMOVED, [mutation.removed.length]);
|
|
137
136
|
log.debug(constants_2.SYNC_SPLITS_SEGMENTS, [mutation.segments.length]);
|
|
138
137
|
// Write into storage
|
|
139
|
-
// @TODO call `setChangeNumber` only if the other storage operations have succeeded, in order to keep storage consistency
|
|
140
138
|
return Promise.all([
|
|
141
|
-
// calling first `setChangenumber` method, to perform cache flush if split filter queryString changed
|
|
142
|
-
splits.setChangeNumber(splitChanges.till),
|
|
143
139
|
splits.addSplits(mutation.added),
|
|
144
140
|
splits.removeSplits(mutation.removed),
|
|
145
141
|
segments.registerSegments(mutation.segments)
|
|
146
142
|
]).then(function (flagsChange) {
|
|
143
|
+
splits.setChangeNumber(splitChanges.till);
|
|
144
|
+
startingUp = false;
|
|
147
145
|
if (splitsEventEmitter) {
|
|
148
146
|
// To emit SDK_SPLITS_ARRIVED for server-side SDK, we must check that all registered segments have been fetched
|
|
149
147
|
return Promise.resolve(!splitsEventEmitter.splitsArrived || (since !== splitChanges.till && isThereUpdate(flagsChange) && (isClientSide || checkAllSegmentsExist(segments))))
|
|
@@ -85,52 +85,28 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
85
85
|
this.hasSync = false;
|
|
86
86
|
};
|
|
87
87
|
SplitsCacheInLocal.prototype.addSplit = function (name, split) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
return true;
|
|
98
|
-
}
|
|
99
|
-
catch (e) {
|
|
100
|
-
this.log.error(LOG_PREFIX + e);
|
|
101
|
-
return false;
|
|
102
|
-
}
|
|
88
|
+
var splitKey = this.keys.buildSplitKey(name);
|
|
89
|
+
var splitFromLocalStorage = localStorage.getItem(splitKey);
|
|
90
|
+
var previousSplit = splitFromLocalStorage ? JSON.parse(splitFromLocalStorage) : null;
|
|
91
|
+
localStorage.setItem(splitKey, JSON.stringify(split));
|
|
92
|
+
this._incrementCounts(split);
|
|
93
|
+
this._decrementCounts(previousSplit);
|
|
94
|
+
// if (previousSplit) this.removeFromFlagSets(previousSplit.name, previousSplit.sets);
|
|
95
|
+
// this.addToFlagSets(split);
|
|
96
|
+
return true;
|
|
103
97
|
};
|
|
104
98
|
SplitsCacheInLocal.prototype.removeSplit = function (name) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
return true;
|
|
111
|
-
}
|
|
112
|
-
catch (e) {
|
|
113
|
-
this.log.error(LOG_PREFIX + e);
|
|
114
|
-
return false;
|
|
115
|
-
}
|
|
99
|
+
var split = this.getSplit(name);
|
|
100
|
+
localStorage.removeItem(this.keys.buildSplitKey(name));
|
|
101
|
+
this._decrementCounts(split);
|
|
102
|
+
// if (split) this.removeFromFlagSets(split.name, split.sets);
|
|
103
|
+
return true;
|
|
116
104
|
};
|
|
117
105
|
SplitsCacheInLocal.prototype.getSplit = function (name) {
|
|
118
106
|
var item = localStorage.getItem(this.keys.buildSplitKey(name));
|
|
119
107
|
return item && JSON.parse(item);
|
|
120
108
|
};
|
|
121
109
|
SplitsCacheInLocal.prototype.setChangeNumber = function (changeNumber) {
|
|
122
|
-
// when using a new split query, we must update it at the store
|
|
123
|
-
if (this.updateNewFilter) {
|
|
124
|
-
this.log.info(LOG_PREFIX + 'SDK key, flags filter criteria or flags spec version was modified. Updating cache');
|
|
125
|
-
var storageHashKey = this.keys.buildHashKey();
|
|
126
|
-
try {
|
|
127
|
-
localStorage.setItem(storageHashKey, this.storageHash);
|
|
128
|
-
}
|
|
129
|
-
catch (e) {
|
|
130
|
-
this.log.error(LOG_PREFIX + e);
|
|
131
|
-
}
|
|
132
|
-
this.updateNewFilter = false;
|
|
133
|
-
}
|
|
134
110
|
try {
|
|
135
111
|
localStorage.setItem(this.keys.buildSplitsTillKey(), changeNumber + '');
|
|
136
112
|
// update "last updated" timestamp with current time
|
|
@@ -208,11 +184,11 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
208
184
|
var storageHash = localStorage.getItem(storageHashKey);
|
|
209
185
|
if (storageHash !== this.storageHash) {
|
|
210
186
|
try {
|
|
211
|
-
// mark cache to update the new query filter on first successful splits fetch
|
|
212
|
-
this.updateNewFilter = true;
|
|
213
187
|
// if there is cache, clear it
|
|
214
188
|
if (this.checkCache())
|
|
215
189
|
this.clear();
|
|
190
|
+
this.log.info(LOG_PREFIX + 'SDK key, flags filter criteria or flags spec version was modified. Updating cache');
|
|
191
|
+
localStorage.setItem(storageHashKey, this.storageHash);
|
|
216
192
|
}
|
|
217
193
|
catch (e) {
|
|
218
194
|
this.log.error(LOG_PREFIX + e);
|
|
@@ -97,7 +97,7 @@ export function splitChangesUpdaterFactory(log, splitChangesFetcher, splits, seg
|
|
|
97
97
|
}
|
|
98
98
|
/** Returns true if at least one split was updated */
|
|
99
99
|
function isThereUpdate(flagsChange) {
|
|
100
|
-
var added = flagsChange[
|
|
100
|
+
var added = flagsChange[0], removed = flagsChange[1];
|
|
101
101
|
// There is at least one added or modified feature flag
|
|
102
102
|
if (added && added.some(function (update) { return update; }))
|
|
103
103
|
return true;
|
|
@@ -125,20 +125,18 @@ export function splitChangesUpdaterFactory(log, splitChangesFetcher, splits, seg
|
|
|
125
125
|
{ splits: [splitUpdateNotification.payload], till: splitUpdateNotification.changeNumber } :
|
|
126
126
|
splitChangesFetcher(since, noCache, till, _promiseDecorator))
|
|
127
127
|
.then(function (splitChanges) {
|
|
128
|
-
startingUp = false;
|
|
129
128
|
var mutation = computeSplitsMutation(splitChanges.splits, splitFiltersValidation);
|
|
130
129
|
log.debug(SYNC_SPLITS_NEW, [mutation.added.length]);
|
|
131
130
|
log.debug(SYNC_SPLITS_REMOVED, [mutation.removed.length]);
|
|
132
131
|
log.debug(SYNC_SPLITS_SEGMENTS, [mutation.segments.length]);
|
|
133
132
|
// Write into storage
|
|
134
|
-
// @TODO call `setChangeNumber` only if the other storage operations have succeeded, in order to keep storage consistency
|
|
135
133
|
return Promise.all([
|
|
136
|
-
// calling first `setChangenumber` method, to perform cache flush if split filter queryString changed
|
|
137
|
-
splits.setChangeNumber(splitChanges.till),
|
|
138
134
|
splits.addSplits(mutation.added),
|
|
139
135
|
splits.removeSplits(mutation.removed),
|
|
140
136
|
segments.registerSegments(mutation.segments)
|
|
141
137
|
]).then(function (flagsChange) {
|
|
138
|
+
splits.setChangeNumber(splitChanges.till);
|
|
139
|
+
startingUp = false;
|
|
142
140
|
if (splitsEventEmitter) {
|
|
143
141
|
// To emit SDK_SPLITS_ARRIVED for server-side SDK, we must check that all registered segments have been fetched
|
|
144
142
|
return Promise.resolve(!splitsEventEmitter.splitsArrived || (since !== splitChanges.till && isThereUpdate(flagsChange) && (isClientSide || checkAllSegmentsExist(segments))))
|
package/package.json
CHANGED
|
@@ -18,7 +18,6 @@ export class SplitsCacheInLocal extends AbstractSplitsCacheSync {
|
|
|
18
18
|
private readonly storageHash: string;
|
|
19
19
|
private readonly flagSetsFilter: string[];
|
|
20
20
|
private hasSync?: boolean;
|
|
21
|
-
private updateNewFilter?: boolean;
|
|
22
21
|
|
|
23
22
|
/**
|
|
24
23
|
* @param {KeyBuilderCS} keys
|
|
@@ -102,39 +101,29 @@ export class SplitsCacheInLocal extends AbstractSplitsCacheSync {
|
|
|
102
101
|
}
|
|
103
102
|
|
|
104
103
|
addSplit(name: string, split: ISplit) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const previousSplit = splitFromLocalStorage ? JSON.parse(splitFromLocalStorage) : null;
|
|
104
|
+
const splitKey = this.keys.buildSplitKey(name);
|
|
105
|
+
const splitFromLocalStorage = localStorage.getItem(splitKey);
|
|
106
|
+
const previousSplit = splitFromLocalStorage ? JSON.parse(splitFromLocalStorage) : null;
|
|
109
107
|
|
|
110
|
-
|
|
108
|
+
localStorage.setItem(splitKey, JSON.stringify(split));
|
|
111
109
|
|
|
112
|
-
|
|
113
|
-
|
|
110
|
+
this._incrementCounts(split);
|
|
111
|
+
this._decrementCounts(previousSplit);
|
|
114
112
|
|
|
115
|
-
|
|
116
|
-
|
|
113
|
+
// if (previousSplit) this.removeFromFlagSets(previousSplit.name, previousSplit.sets);
|
|
114
|
+
// this.addToFlagSets(split);
|
|
117
115
|
|
|
118
|
-
|
|
119
|
-
} catch (e) {
|
|
120
|
-
this.log.error(LOG_PREFIX + e);
|
|
121
|
-
return false;
|
|
122
|
-
}
|
|
116
|
+
return true;
|
|
123
117
|
}
|
|
124
118
|
|
|
125
119
|
removeSplit(name: string): boolean {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
localStorage.removeItem(this.keys.buildSplitKey(name));
|
|
120
|
+
const split = this.getSplit(name);
|
|
121
|
+
localStorage.removeItem(this.keys.buildSplitKey(name));
|
|
129
122
|
|
|
130
|
-
|
|
131
|
-
|
|
123
|
+
this._decrementCounts(split);
|
|
124
|
+
// if (split) this.removeFromFlagSets(split.name, split.sets);
|
|
132
125
|
|
|
133
|
-
|
|
134
|
-
} catch (e) {
|
|
135
|
-
this.log.error(LOG_PREFIX + e);
|
|
136
|
-
return false;
|
|
137
|
-
}
|
|
126
|
+
return true;
|
|
138
127
|
}
|
|
139
128
|
|
|
140
129
|
getSplit(name: string) {
|
|
@@ -143,19 +132,6 @@ export class SplitsCacheInLocal extends AbstractSplitsCacheSync {
|
|
|
143
132
|
}
|
|
144
133
|
|
|
145
134
|
setChangeNumber(changeNumber: number): boolean {
|
|
146
|
-
|
|
147
|
-
// when using a new split query, we must update it at the store
|
|
148
|
-
if (this.updateNewFilter) {
|
|
149
|
-
this.log.info(LOG_PREFIX + 'SDK key, flags filter criteria or flags spec version was modified. Updating cache');
|
|
150
|
-
const storageHashKey = this.keys.buildHashKey();
|
|
151
|
-
try {
|
|
152
|
-
localStorage.setItem(storageHashKey, this.storageHash);
|
|
153
|
-
} catch (e) {
|
|
154
|
-
this.log.error(LOG_PREFIX + e);
|
|
155
|
-
}
|
|
156
|
-
this.updateNewFilter = false;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
135
|
try {
|
|
160
136
|
localStorage.setItem(this.keys.buildSplitsTillKey(), changeNumber + '');
|
|
161
137
|
// update "last updated" timestamp with current time
|
|
@@ -246,12 +222,12 @@ export class SplitsCacheInLocal extends AbstractSplitsCacheSync {
|
|
|
246
222
|
|
|
247
223
|
if (storageHash !== this.storageHash) {
|
|
248
224
|
try {
|
|
249
|
-
// mark cache to update the new query filter on first successful splits fetch
|
|
250
|
-
this.updateNewFilter = true;
|
|
251
|
-
|
|
252
225
|
// if there is cache, clear it
|
|
253
226
|
if (this.checkCache()) this.clear();
|
|
254
227
|
|
|
228
|
+
this.log.info(LOG_PREFIX + 'SDK key, flags filter criteria or flags spec version was modified. Updating cache');
|
|
229
|
+
localStorage.setItem(storageHashKey, this.storageHash);
|
|
230
|
+
|
|
255
231
|
} catch (e) {
|
|
256
232
|
this.log.error(LOG_PREFIX + e);
|
|
257
233
|
}
|
|
@@ -129,8 +129,8 @@ export function splitChangesUpdaterFactory(
|
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
/** Returns true if at least one split was updated */
|
|
132
|
-
function isThereUpdate(flagsChange: [
|
|
133
|
-
const [
|
|
132
|
+
function isThereUpdate(flagsChange: [void | boolean[], void | boolean[], boolean | void] | [any, any, any]) {
|
|
133
|
+
const [added, removed] = flagsChange;
|
|
134
134
|
// There is at least one added or modified feature flag
|
|
135
135
|
if (added && added.some((update: boolean) => update)) return true;
|
|
136
136
|
// There is at least one removed feature flag
|
|
@@ -158,8 +158,6 @@ export function splitChangesUpdaterFactory(
|
|
|
158
158
|
splitChangesFetcher(since, noCache, till, _promiseDecorator)
|
|
159
159
|
)
|
|
160
160
|
.then((splitChanges: ISplitChangesResponse) => {
|
|
161
|
-
startingUp = false;
|
|
162
|
-
|
|
163
161
|
const mutation = computeSplitsMutation(splitChanges.splits, splitFiltersValidation);
|
|
164
162
|
|
|
165
163
|
log.debug(SYNC_SPLITS_NEW, [mutation.added.length]);
|
|
@@ -167,14 +165,14 @@ export function splitChangesUpdaterFactory(
|
|
|
167
165
|
log.debug(SYNC_SPLITS_SEGMENTS, [mutation.segments.length]);
|
|
168
166
|
|
|
169
167
|
// Write into storage
|
|
170
|
-
// @TODO call `setChangeNumber` only if the other storage operations have succeeded, in order to keep storage consistency
|
|
171
168
|
return Promise.all([
|
|
172
|
-
// calling first `setChangenumber` method, to perform cache flush if split filter queryString changed
|
|
173
|
-
splits.setChangeNumber(splitChanges.till),
|
|
174
169
|
splits.addSplits(mutation.added),
|
|
175
170
|
splits.removeSplits(mutation.removed),
|
|
176
171
|
segments.registerSegments(mutation.segments)
|
|
177
172
|
]).then((flagsChange) => {
|
|
173
|
+
splits.setChangeNumber(splitChanges.till);
|
|
174
|
+
startingUp = false;
|
|
175
|
+
|
|
178
176
|
if (splitsEventEmitter) {
|
|
179
177
|
// To emit SDK_SPLITS_ARRIVED for server-side SDK, we must check that all registered segments have been fetched
|
|
180
178
|
return Promise.resolve(!splitsEventEmitter.splitsArrived || (since !== splitChanges.till && isThereUpdate(flagsChange) && (isClientSide || checkAllSegmentsExist(segments))))
|
|
@@ -12,7 +12,6 @@ export declare class SplitsCacheInLocal extends AbstractSplitsCacheSync {
|
|
|
12
12
|
private readonly storageHash;
|
|
13
13
|
private readonly flagSetsFilter;
|
|
14
14
|
private hasSync?;
|
|
15
|
-
private updateNewFilter?;
|
|
16
15
|
/**
|
|
17
16
|
* @param {KeyBuilderCS} keys
|
|
18
17
|
* @param {number | undefined} expirationTimestamp
|