@flopflip/http-adapter 12.5.6 → 13.0.1
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/dist/flopflip-http-adapter.cjs.dev.js +152 -322
- package/dist/flopflip-http-adapter.cjs.prod.js +152 -322
- package/dist/flopflip-http-adapter.esm.js +153 -322
- package/package.json +6 -6
|
@@ -1,20 +1,15 @@
|
|
|
1
|
-
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
2
1
|
import _objectSpread from '@babel/runtime/helpers/esm/objectSpread2';
|
|
3
2
|
import _slicedToArray from '@babel/runtime/helpers/esm/slicedToArray';
|
|
4
|
-
import _asyncToGenerator from '@babel/runtime/helpers/esm/asyncToGenerator';
|
|
5
|
-
import _classCallCheck from '@babel/runtime/helpers/esm/classCallCheck';
|
|
6
|
-
import _createClass from '@babel/runtime/helpers/esm/createClass';
|
|
7
3
|
import _classPrivateFieldLooseBase from '@babel/runtime/helpers/esm/classPrivateFieldLooseBase';
|
|
8
4
|
import _classPrivateFieldLooseKey from '@babel/runtime/helpers/esm/classPrivateFieldLooseKey';
|
|
9
|
-
import _regeneratorRuntime from '@babel/runtime/regenerator';
|
|
10
5
|
import { exposeGlobally, normalizeFlags, normalizeFlag } from '@flopflip/adapter-utilities';
|
|
11
|
-
import { AdapterSubscriptionStatus, AdapterConfigurationStatus,
|
|
6
|
+
import { AdapterSubscriptionStatus, AdapterConfigurationStatus, cacheIdentifiers, adapterIdentifiers, AdapterInitializationStatus } from '@flopflip/types';
|
|
12
7
|
import isEqual from 'lodash/isEqual';
|
|
13
8
|
import mitt from 'mitt';
|
|
14
9
|
import warning from 'tiny-warning';
|
|
15
10
|
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
const STORAGE_SLICE = '@flopflip';
|
|
12
|
+
const intialAdapterState = {
|
|
18
13
|
subscriptionStatus: AdapterSubscriptionStatus.Subscribed,
|
|
19
14
|
configurationStatus: AdapterConfigurationStatus.Unconfigured,
|
|
20
15
|
flags: {},
|
|
@@ -31,10 +26,8 @@ var _getCache = /*#__PURE__*/_classPrivateFieldLooseKey("getCache");
|
|
|
31
26
|
var _didFlagsChange = /*#__PURE__*/_classPrivateFieldLooseKey("didFlagsChange");
|
|
32
27
|
var _fetchFlags = /*#__PURE__*/_classPrivateFieldLooseKey("fetchFlags");
|
|
33
28
|
var _subscribeToFlagsChanges = /*#__PURE__*/_classPrivateFieldLooseKey("subscribeToFlagsChanges");
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
var _this = this;
|
|
37
|
-
_classCallCheck(this, HttpAdapter);
|
|
29
|
+
class HttpAdapter {
|
|
30
|
+
constructor() {
|
|
38
31
|
this.id = void 0;
|
|
39
32
|
Object.defineProperty(this, _internalConfiguredStatusChange__, {
|
|
40
33
|
writable: true,
|
|
@@ -50,361 +43,199 @@ var HttpAdapter = /*#__PURE__*/function () {
|
|
|
50
43
|
});
|
|
51
44
|
Object.defineProperty(this, _getIsAdapterUnsubscribed, {
|
|
52
45
|
writable: true,
|
|
53
|
-
value:
|
|
54
|
-
return _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState].subscriptionStatus === AdapterSubscriptionStatus.Unsubscribed;
|
|
55
|
-
}
|
|
46
|
+
value: () => _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].subscriptionStatus === AdapterSubscriptionStatus.Unsubscribed
|
|
56
47
|
});
|
|
57
48
|
Object.defineProperty(this, _getIsFlagLocked, {
|
|
58
49
|
writable: true,
|
|
59
|
-
value:
|
|
60
|
-
return _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState].lockedFlags.has(flagName);
|
|
61
|
-
}
|
|
50
|
+
value: flagName => _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].lockedFlags.has(flagName)
|
|
62
51
|
});
|
|
63
52
|
Object.defineProperty(this, _getCache, {
|
|
64
53
|
writable: true,
|
|
65
|
-
value:
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
case 5:
|
|
78
|
-
cacheModule = _context.sent;
|
|
79
|
-
return _context.abrupt("break", 12);
|
|
80
|
-
case 7:
|
|
81
|
-
_context.next = 9;
|
|
82
|
-
return import('@flopflip/sessionstorage-cache');
|
|
83
|
-
case 9:
|
|
84
|
-
cacheModule = _context.sent;
|
|
85
|
-
return _context.abrupt("break", 12);
|
|
86
|
-
case 11:
|
|
87
|
-
return _context.abrupt("break", 12);
|
|
88
|
-
case 12:
|
|
89
|
-
createCache = cacheModule.default;
|
|
90
|
-
cache = createCache({
|
|
91
|
-
prefix: STORAGE_SLICE
|
|
92
|
-
});
|
|
93
|
-
return _context.abrupt("return", {
|
|
94
|
-
set: function set(flags) {
|
|
95
|
-
return cache.set('flags', flags);
|
|
96
|
-
},
|
|
97
|
-
get: function get() {
|
|
98
|
-
return cache.get('flags');
|
|
99
|
-
},
|
|
100
|
-
unset: function unset() {
|
|
101
|
-
return cache.unset('flags');
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
case 15:
|
|
105
|
-
case "end":
|
|
106
|
-
return _context.stop();
|
|
54
|
+
value: async cacheIdentifier => {
|
|
55
|
+
let cacheModule;
|
|
56
|
+
switch (cacheIdentifier) {
|
|
57
|
+
case cacheIdentifiers.local:
|
|
58
|
+
{
|
|
59
|
+
cacheModule = await import('@flopflip/localstorage-cache');
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
case cacheIdentifiers.session:
|
|
63
|
+
{
|
|
64
|
+
cacheModule = await import('@flopflip/sessionstorage-cache');
|
|
65
|
+
break;
|
|
107
66
|
}
|
|
108
|
-
}, _callee);
|
|
109
|
-
}));
|
|
110
|
-
function value(_x) {
|
|
111
|
-
return _value.apply(this, arguments);
|
|
112
67
|
}
|
|
113
|
-
|
|
114
|
-
|
|
68
|
+
const createCache = cacheModule.default;
|
|
69
|
+
const cache = createCache({
|
|
70
|
+
prefix: STORAGE_SLICE
|
|
71
|
+
});
|
|
72
|
+
return {
|
|
73
|
+
set(flags) {
|
|
74
|
+
return cache.set('flags', flags);
|
|
75
|
+
},
|
|
76
|
+
get() {
|
|
77
|
+
return cache.get('flags');
|
|
78
|
+
},
|
|
79
|
+
unset() {
|
|
80
|
+
return cache.unset('flags');
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
115
84
|
});
|
|
116
85
|
Object.defineProperty(this, _didFlagsChange, {
|
|
117
86
|
writable: true,
|
|
118
|
-
value:
|
|
119
|
-
|
|
87
|
+
value: nextFlags => {
|
|
88
|
+
const previousFlags = _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].flags;
|
|
120
89
|
if (previousFlags === undefined) return true;
|
|
121
90
|
return !isEqual(nextFlags, previousFlags);
|
|
122
91
|
}
|
|
123
92
|
});
|
|
124
93
|
Object.defineProperty(this, _fetchFlags, {
|
|
125
94
|
writable: true,
|
|
126
|
-
value:
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
131
|
-
case 0:
|
|
132
|
-
_context2.next = 2;
|
|
133
|
-
return adapterArgs.execute();
|
|
134
|
-
case 2:
|
|
135
|
-
flags = _context2.sent;
|
|
136
|
-
return _context2.abrupt("return", flags);
|
|
137
|
-
case 4:
|
|
138
|
-
case "end":
|
|
139
|
-
return _context2.stop();
|
|
140
|
-
}
|
|
141
|
-
}, _callee2);
|
|
142
|
-
}));
|
|
143
|
-
function value(_x2) {
|
|
144
|
-
return _value2.apply(this, arguments);
|
|
145
|
-
}
|
|
146
|
-
return value;
|
|
147
|
-
}()
|
|
95
|
+
value: async adapterArgs => {
|
|
96
|
+
const flags = await adapterArgs.execute();
|
|
97
|
+
return flags;
|
|
98
|
+
}
|
|
148
99
|
});
|
|
149
100
|
Object.defineProperty(this, _subscribeToFlagsChanges, {
|
|
150
101
|
writable: true,
|
|
151
|
-
value:
|
|
102
|
+
value: adapterArgs => {
|
|
152
103
|
var _adapterArgs$pollingI;
|
|
153
|
-
|
|
154
|
-
setInterval(
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
_context3.next = 14;
|
|
161
|
-
break;
|
|
162
|
-
}
|
|
163
|
-
_context3.t0 = normalizeFlags;
|
|
164
|
-
_context3.next = 4;
|
|
165
|
-
return _classPrivateFieldLooseBase(_this, _fetchFlags)[_fetchFlags](adapterArgs);
|
|
166
|
-
case 4:
|
|
167
|
-
_context3.t1 = _context3.sent;
|
|
168
|
-
nextFlags = (0, _context3.t0)(_context3.t1);
|
|
169
|
-
if (!_classPrivateFieldLooseBase(_this, _didFlagsChange)[_didFlagsChange](nextFlags)) {
|
|
170
|
-
_context3.next = 14;
|
|
171
|
-
break;
|
|
172
|
-
}
|
|
173
|
-
if (!adapterArgs.cacheIdentifier) {
|
|
174
|
-
_context3.next = 12;
|
|
175
|
-
break;
|
|
176
|
-
}
|
|
177
|
-
_context3.next = 10;
|
|
178
|
-
return _classPrivateFieldLooseBase(_this, _getCache)[_getCache](adapterArgs.cacheIdentifier);
|
|
179
|
-
case 10:
|
|
180
|
-
cache = _context3.sent;
|
|
104
|
+
const pollingInteralMs = (_adapterArgs$pollingI = adapterArgs.pollingInteralMs) !== null && _adapterArgs$pollingI !== void 0 ? _adapterArgs$pollingI : _classPrivateFieldLooseBase(this, _defaultPollingInteralMs)[_defaultPollingInteralMs];
|
|
105
|
+
setInterval(async () => {
|
|
106
|
+
if (!_classPrivateFieldLooseBase(this, _getIsAdapterUnsubscribed)[_getIsAdapterUnsubscribed]()) {
|
|
107
|
+
const nextFlags = normalizeFlags(await _classPrivateFieldLooseBase(this, _fetchFlags)[_fetchFlags](adapterArgs));
|
|
108
|
+
if (_classPrivateFieldLooseBase(this, _didFlagsChange)[_didFlagsChange](nextFlags)) {
|
|
109
|
+
if (adapterArgs.cacheIdentifier) {
|
|
110
|
+
const cache = await _classPrivateFieldLooseBase(this, _getCache)[_getCache](adapterArgs.cacheIdentifier);
|
|
181
111
|
cache.set(nextFlags);
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
case 14:
|
|
186
|
-
case "end":
|
|
187
|
-
return _context3.stop();
|
|
112
|
+
}
|
|
113
|
+
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].flags = nextFlags;
|
|
114
|
+
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].emitter.emit('flagsStateChange', nextFlags);
|
|
188
115
|
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
116
|
+
}
|
|
117
|
+
}, pollingInteralMs);
|
|
191
118
|
}
|
|
192
119
|
});
|
|
193
|
-
this.getUser =
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
this.updateFlags = function (flags, options) {
|
|
197
|
-
var isAdapterConfigured = _this.getIsConfigurationStatus(AdapterConfigurationStatus.Configured);
|
|
120
|
+
this.getUser = () => _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].user;
|
|
121
|
+
this.updateFlags = (flags, options) => {
|
|
122
|
+
const isAdapterConfigured = this.getIsConfigurationStatus(AdapterConfigurationStatus.Configured);
|
|
198
123
|
warning(isAdapterConfigured, '@flopflip/http-adapter: adapter not configured. Flags can not be updated before.');
|
|
199
124
|
if (!isAdapterConfigured) return;
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
flagName =
|
|
204
|
-
flagValue =
|
|
205
|
-
|
|
125
|
+
const previousFlags = _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].flags;
|
|
126
|
+
const updatedFlags = Object.entries(flags).reduce((updatedFlags, _ref) => {
|
|
127
|
+
let _ref2 = _slicedToArray(_ref, 2),
|
|
128
|
+
flagName = _ref2[0],
|
|
129
|
+
flagValue = _ref2[1];
|
|
130
|
+
const _normalizeFlag = normalizeFlag(flagName, flagValue),
|
|
206
131
|
_normalizeFlag2 = _slicedToArray(_normalizeFlag, 2),
|
|
207
132
|
normalizedFlagName = _normalizeFlag2[0],
|
|
208
133
|
normalizedFlagValue = _normalizeFlag2[1];
|
|
209
|
-
if (_classPrivateFieldLooseBase(
|
|
134
|
+
if (_classPrivateFieldLooseBase(this, _getIsFlagLocked)[_getIsFlagLocked](normalizedFlagName)) return updatedFlags;
|
|
210
135
|
if (options !== null && options !== void 0 && options.lockFlags) {
|
|
211
|
-
_classPrivateFieldLooseBase(
|
|
136
|
+
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].lockedFlags.add(normalizedFlagName);
|
|
212
137
|
}
|
|
213
|
-
updatedFlags = _objectSpread(_objectSpread({}, updatedFlags), {},
|
|
138
|
+
updatedFlags = _objectSpread(_objectSpread({}, updatedFlags), {}, {
|
|
139
|
+
[normalizedFlagName]: normalizedFlagValue
|
|
140
|
+
});
|
|
214
141
|
return updatedFlags;
|
|
215
142
|
}, {});
|
|
216
|
-
|
|
217
|
-
_classPrivateFieldLooseBase(
|
|
218
|
-
_classPrivateFieldLooseBase(
|
|
143
|
+
const nextFlags = _objectSpread(_objectSpread({}, previousFlags), updatedFlags);
|
|
144
|
+
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].flags = nextFlags;
|
|
145
|
+
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].emitter.emit('flagsStateChange', nextFlags);
|
|
219
146
|
};
|
|
220
|
-
this.reset =
|
|
221
|
-
_classPrivateFieldLooseBase(
|
|
147
|
+
this.reset = () => {
|
|
148
|
+
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState] = _objectSpread({}, intialAdapterState);
|
|
222
149
|
};
|
|
223
|
-
this.unsubscribe =
|
|
224
|
-
_classPrivateFieldLooseBase(
|
|
150
|
+
this.unsubscribe = () => {
|
|
151
|
+
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].subscriptionStatus = AdapterSubscriptionStatus.Unsubscribed;
|
|
225
152
|
};
|
|
226
|
-
this.subscribe =
|
|
227
|
-
_classPrivateFieldLooseBase(
|
|
153
|
+
this.subscribe = () => {
|
|
154
|
+
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].subscriptionStatus = AdapterSubscriptionStatus.Subscribed;
|
|
228
155
|
};
|
|
229
156
|
this.id = adapterIdentifiers.http;
|
|
230
157
|
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState] = _objectSpread({}, intialAdapterState);
|
|
231
158
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
var cachedFlags, cache, flags, _cache;
|
|
261
|
-
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
262
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
263
|
-
case 0:
|
|
264
|
-
if (!adapterArgs.cacheIdentifier) {
|
|
265
|
-
_context4.next = 6;
|
|
266
|
-
break;
|
|
267
|
-
}
|
|
268
|
-
_context4.next = 3;
|
|
269
|
-
return _classPrivateFieldLooseBase(_this2, _getCache)[_getCache](adapterArgs.cacheIdentifier);
|
|
270
|
-
case 3:
|
|
271
|
-
cache = _context4.sent;
|
|
272
|
-
cachedFlags = cache.get();
|
|
273
|
-
if (cachedFlags) {
|
|
274
|
-
_classPrivateFieldLooseBase(_this2, _adapterState)[_adapterState].flags = cachedFlags;
|
|
275
|
-
_classPrivateFieldLooseBase(_this2, _adapterState)[_adapterState].emitter.emit('flagsStateChange', cachedFlags);
|
|
276
|
-
}
|
|
277
|
-
case 6:
|
|
278
|
-
_this2.setConfigurationStatus(AdapterConfigurationStatus.Configured);
|
|
279
|
-
_context4.t0 = normalizeFlags;
|
|
280
|
-
_context4.next = 10;
|
|
281
|
-
return _classPrivateFieldLooseBase(_this2, _fetchFlags)[_fetchFlags](adapterArgs);
|
|
282
|
-
case 10:
|
|
283
|
-
_context4.t1 = _context4.sent;
|
|
284
|
-
flags = (0, _context4.t0)(_context4.t1);
|
|
285
|
-
_classPrivateFieldLooseBase(_this2, _adapterState)[_adapterState].flags = flags;
|
|
286
|
-
if (!adapterArgs.cacheIdentifier) {
|
|
287
|
-
_context4.next = 18;
|
|
288
|
-
break;
|
|
289
|
-
}
|
|
290
|
-
_context4.next = 16;
|
|
291
|
-
return _classPrivateFieldLooseBase(_this2, _getCache)[_getCache](adapterArgs.cacheIdentifier);
|
|
292
|
-
case 16:
|
|
293
|
-
_cache = _context4.sent;
|
|
294
|
-
_cache.set(flags);
|
|
295
|
-
case 18:
|
|
296
|
-
_classPrivateFieldLooseBase(_this2, _adapterState)[_adapterState].emitter.emit('flagsStateChange', flags);
|
|
297
|
-
_classPrivateFieldLooseBase(_this2, _adapterState)[_adapterState].emitter.emit(_classPrivateFieldLooseBase(_this2, _internalConfiguredStatusChange__)[_internalConfiguredStatusChange__]);
|
|
298
|
-
_classPrivateFieldLooseBase(_this2, _subscribeToFlagsChanges)[_subscribeToFlagsChanges](adapterArgs);
|
|
299
|
-
return _context4.abrupt("return", {
|
|
300
|
-
initializationStatus: AdapterInitializationStatus.Succeeded
|
|
301
|
-
});
|
|
302
|
-
case 22:
|
|
303
|
-
case "end":
|
|
304
|
-
return _context4.stop();
|
|
305
|
-
}
|
|
306
|
-
}, _callee4);
|
|
307
|
-
}))));
|
|
308
|
-
case 7:
|
|
309
|
-
case "end":
|
|
310
|
-
return _context5.stop();
|
|
311
|
-
}
|
|
312
|
-
}, _callee5, this);
|
|
313
|
-
}));
|
|
314
|
-
function configure(_x3, _x4) {
|
|
315
|
-
return _configure.apply(this, arguments);
|
|
316
|
-
}
|
|
317
|
-
return configure;
|
|
318
|
-
}()
|
|
319
|
-
}, {
|
|
320
|
-
key: "reconfigure",
|
|
321
|
-
value: function () {
|
|
322
|
-
var _reconfigure = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(adapterArgs, _adapterEventHandlers) {
|
|
323
|
-
var cache, nextUser;
|
|
324
|
-
return _regeneratorRuntime.wrap(function _callee6$(_context6) {
|
|
325
|
-
while (1) switch (_context6.prev = _context6.next) {
|
|
326
|
-
case 0:
|
|
327
|
-
if (this.getIsConfigurationStatus(AdapterConfigurationStatus.Configured)) {
|
|
328
|
-
_context6.next = 2;
|
|
329
|
-
break;
|
|
330
|
-
}
|
|
331
|
-
return _context6.abrupt("return", Promise.reject(new Error('@flopflip/http-adapter: please configure adapter before reconfiguring.')));
|
|
332
|
-
case 2:
|
|
333
|
-
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].flags = {};
|
|
334
|
-
if (!adapterArgs.cacheIdentifier) {
|
|
335
|
-
_context6.next = 8;
|
|
336
|
-
break;
|
|
337
|
-
}
|
|
338
|
-
_context6.next = 6;
|
|
339
|
-
return _classPrivateFieldLooseBase(this, _getCache)[_getCache](adapterArgs.cacheIdentifier);
|
|
340
|
-
case 6:
|
|
341
|
-
cache = _context6.sent;
|
|
342
|
-
cache.unset();
|
|
343
|
-
case 8:
|
|
344
|
-
nextUser = adapterArgs.user;
|
|
345
|
-
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].user = nextUser;
|
|
346
|
-
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].emitter.emit('flagsStateChange', {});
|
|
347
|
-
return _context6.abrupt("return", Promise.resolve({
|
|
348
|
-
initializationStatus: AdapterInitializationStatus.Succeeded
|
|
349
|
-
}));
|
|
350
|
-
case 12:
|
|
351
|
-
case "end":
|
|
352
|
-
return _context6.stop();
|
|
353
|
-
}
|
|
354
|
-
}, _callee6, this);
|
|
355
|
-
}));
|
|
356
|
-
function reconfigure(_x5, _x6) {
|
|
357
|
-
return _reconfigure.apply(this, arguments);
|
|
159
|
+
async configure(adapterArgs, adapterEventHandlers) {
|
|
160
|
+
const handleFlagsChange = nextFlags => {
|
|
161
|
+
if (_classPrivateFieldLooseBase(this, _getIsAdapterUnsubscribed)[_getIsAdapterUnsubscribed]()) return;
|
|
162
|
+
adapterEventHandlers.onFlagsStateChange({
|
|
163
|
+
flags: nextFlags,
|
|
164
|
+
id: this.id
|
|
165
|
+
});
|
|
166
|
+
};
|
|
167
|
+
const handleStatusChange = nextStatus => {
|
|
168
|
+
if (_classPrivateFieldLooseBase(this, _getIsAdapterUnsubscribed)[_getIsAdapterUnsubscribed]()) return;
|
|
169
|
+
adapterEventHandlers.onStatusStateChange({
|
|
170
|
+
status: nextStatus,
|
|
171
|
+
id: this.id
|
|
172
|
+
});
|
|
173
|
+
};
|
|
174
|
+
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].emitter.on('flagsStateChange', handleFlagsChange);
|
|
175
|
+
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].emitter.on('statusStateChange', handleStatusChange);
|
|
176
|
+
this.setConfigurationStatus(AdapterConfigurationStatus.Configuring);
|
|
177
|
+
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].user = adapterArgs.user;
|
|
178
|
+
return Promise.resolve().then(async () => {
|
|
179
|
+
let cachedFlags;
|
|
180
|
+
if (adapterArgs.cacheIdentifier) {
|
|
181
|
+
const cache = await _classPrivateFieldLooseBase(this, _getCache)[_getCache](adapterArgs.cacheIdentifier);
|
|
182
|
+
cachedFlags = cache.get();
|
|
183
|
+
if (cachedFlags) {
|
|
184
|
+
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].flags = cachedFlags;
|
|
185
|
+
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].emitter.emit('flagsStateChange', cachedFlags);
|
|
186
|
+
}
|
|
358
187
|
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
var _this3 = this;
|
|
366
|
-
return _regeneratorRuntime.wrap(function _callee7$(_context7) {
|
|
367
|
-
while (1) switch (_context7.prev = _context7.next) {
|
|
368
|
-
case 0:
|
|
369
|
-
return _context7.abrupt("return", new Promise(function (resolve) {
|
|
370
|
-
if (_this3.getIsConfigurationStatus(AdapterConfigurationStatus.Configured)) resolve();else _classPrivateFieldLooseBase(_this3, _adapterState)[_adapterState].emitter.on(_classPrivateFieldLooseBase(_this3, _internalConfiguredStatusChange__)[_internalConfiguredStatusChange__], resolve);
|
|
371
|
-
}));
|
|
372
|
-
case 1:
|
|
373
|
-
case "end":
|
|
374
|
-
return _context7.stop();
|
|
375
|
-
}
|
|
376
|
-
}, _callee7);
|
|
377
|
-
}));
|
|
378
|
-
function waitUntilConfigured() {
|
|
379
|
-
return _waitUntilConfigured.apply(this, arguments);
|
|
188
|
+
this.setConfigurationStatus(AdapterConfigurationStatus.Configured);
|
|
189
|
+
const flags = normalizeFlags(await _classPrivateFieldLooseBase(this, _fetchFlags)[_fetchFlags](adapterArgs));
|
|
190
|
+
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].flags = flags;
|
|
191
|
+
if (adapterArgs.cacheIdentifier) {
|
|
192
|
+
const cache = await _classPrivateFieldLooseBase(this, _getCache)[_getCache](adapterArgs.cacheIdentifier);
|
|
193
|
+
cache.set(flags);
|
|
380
194
|
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
key: "setConfigurationStatus",
|
|
396
|
-
value: function setConfigurationStatus(nextConfigurationStatus) {
|
|
397
|
-
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].configurationStatus = nextConfigurationStatus;
|
|
398
|
-
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].emitter.emit('statusStateChange', {
|
|
399
|
-
configurationStatus: _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].configurationStatus
|
|
400
|
-
});
|
|
195
|
+
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].emitter.emit('flagsStateChange', flags);
|
|
196
|
+
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].emitter.emit(_classPrivateFieldLooseBase(this, _internalConfiguredStatusChange__)[_internalConfiguredStatusChange__]);
|
|
197
|
+
_classPrivateFieldLooseBase(this, _subscribeToFlagsChanges)[_subscribeToFlagsChanges](adapterArgs);
|
|
198
|
+
return {
|
|
199
|
+
initializationStatus: AdapterInitializationStatus.Succeeded
|
|
200
|
+
};
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
async reconfigure(adapterArgs, _adapterEventHandlers) {
|
|
204
|
+
if (!this.getIsConfigurationStatus(AdapterConfigurationStatus.Configured)) return Promise.reject(new Error('@flopflip/http-adapter: please configure adapter before reconfiguring.'));
|
|
205
|
+
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].flags = {};
|
|
206
|
+
if (adapterArgs.cacheIdentifier) {
|
|
207
|
+
const cache = await _classPrivateFieldLooseBase(this, _getCache)[_getCache](adapterArgs.cacheIdentifier);
|
|
208
|
+
cache.unset();
|
|
401
209
|
}
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
210
|
+
const nextUser = adapterArgs.user;
|
|
211
|
+
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].user = nextUser;
|
|
212
|
+
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].emitter.emit('flagsStateChange', {});
|
|
213
|
+
return Promise.resolve({
|
|
214
|
+
initializationStatus: AdapterInitializationStatus.Succeeded
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
async waitUntilConfigured() {
|
|
218
|
+
return new Promise(resolve => {
|
|
219
|
+
if (this.getIsConfigurationStatus(AdapterConfigurationStatus.Configured)) resolve();else _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].emitter.on(_classPrivateFieldLooseBase(this, _internalConfiguredStatusChange__)[_internalConfiguredStatusChange__], resolve);
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
getIsConfigurationStatus(configurationStatus) {
|
|
223
|
+
return _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].configurationStatus === configurationStatus;
|
|
224
|
+
}
|
|
225
|
+
getFlag(flagName) {
|
|
226
|
+
var _classPrivateFieldLoo;
|
|
227
|
+
return (_classPrivateFieldLoo = _classPrivateFieldLooseBase(this, _adapterState)[_adapterState]) === null || _classPrivateFieldLoo === void 0 ? void 0 : _classPrivateFieldLoo.flags[flagName];
|
|
228
|
+
}
|
|
229
|
+
setConfigurationStatus(nextConfigurationStatus) {
|
|
230
|
+
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].configurationStatus = nextConfigurationStatus;
|
|
231
|
+
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].emitter.emit('statusStateChange', {
|
|
232
|
+
configurationStatus: _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].configurationStatus
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
const adapter = new HttpAdapter();
|
|
406
237
|
exposeGlobally(adapter);
|
|
407
238
|
|
|
408
|
-
|
|
239
|
+
const version = "13.0.1";
|
|
409
240
|
|
|
410
241
|
export { adapter as default, version };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flopflip/http-adapter",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "13.0.1",
|
|
4
4
|
"description": "An HTTP adapter for flipflop",
|
|
5
5
|
"main": "dist/flopflip-http-adapter.cjs.js",
|
|
6
6
|
"module": "dist/flopflip-http-adapter.esm.js",
|
|
@@ -29,11 +29,11 @@
|
|
|
29
29
|
"client"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@babel/runtime": "7.
|
|
33
|
-
"@flopflip/adapter-utilities": "
|
|
34
|
-
"@flopflip/localstorage-cache": "
|
|
35
|
-
"@flopflip/sessionstorage-cache": "
|
|
36
|
-
"@flopflip/types": "
|
|
32
|
+
"@babel/runtime": "7.21.0",
|
|
33
|
+
"@flopflip/adapter-utilities": "13.0.1",
|
|
34
|
+
"@flopflip/localstorage-cache": "13.0.1",
|
|
35
|
+
"@flopflip/sessionstorage-cache": "13.0.1",
|
|
36
|
+
"@flopflip/types": "13.0.1",
|
|
37
37
|
"lodash": "4.17.21",
|
|
38
38
|
"mitt": "3.0.0",
|
|
39
39
|
"tiny-warning": "1.0.3"
|