@flopflip/http-adapter 0.0.25 → 0.0.27

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.
@@ -51,31 +51,19 @@ var intialAdapterState = {
51
51
  user: {},
52
52
  emitter: mitt__default["default"]()
53
53
  };
54
-
55
54
  var _internalConfiguredStatusChange__ = /*#__PURE__*/_classPrivateFieldLooseKey("__internalConfiguredStatusChange__");
56
-
57
55
  var _adapterState = /*#__PURE__*/_classPrivateFieldLooseKey("adapterState");
58
-
59
56
  var _defaultPollingInteralMs = /*#__PURE__*/_classPrivateFieldLooseKey("defaultPollingInteralMs");
60
-
61
57
  var _getIsAdapterUnsubscribed = /*#__PURE__*/_classPrivateFieldLooseKey("getIsAdapterUnsubscribed");
62
-
63
58
  var _getIsFlagLocked = /*#__PURE__*/_classPrivateFieldLooseKey("getIsFlagLocked");
64
-
65
59
  var _getCache = /*#__PURE__*/_classPrivateFieldLooseKey("getCache");
66
-
67
60
  var _didFlagsChange = /*#__PURE__*/_classPrivateFieldLooseKey("didFlagsChange");
68
-
69
61
  var _fetchFlags = /*#__PURE__*/_classPrivateFieldLooseKey("fetchFlags");
70
-
71
62
  var _subscribeToFlagsChanges = /*#__PURE__*/_classPrivateFieldLooseKey("subscribeToFlagsChanges");
72
-
73
63
  var HttpAdapter = /*#__PURE__*/function () {
74
64
  function HttpAdapter() {
75
65
  var _this = this;
76
-
77
66
  _classCallCheck(this, HttpAdapter);
78
-
79
67
  Object.defineProperty(this, _internalConfiguredStatusChange__, {
80
68
  writable: true,
81
69
  value: '__internalConfiguredStatusChange__'
@@ -113,26 +101,20 @@ var HttpAdapter = /*#__PURE__*/function () {
113
101
  _context.t0 = cacheIdentifier;
114
102
  _context.next = _context.t0 === types.cacheIdentifiers.local ? 3 : _context.t0 === types.cacheIdentifiers.session ? 7 : 11;
115
103
  break;
116
-
117
104
  case 3:
118
105
  _context.next = 5;
119
106
  return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@flopflip/localstorage-cache')); });
120
-
121
107
  case 5:
122
108
  cacheModule = _context.sent;
123
109
  return _context.abrupt("break", 12);
124
-
125
110
  case 7:
126
111
  _context.next = 9;
127
112
  return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@flopflip/sessionstorage-cache')); });
128
-
129
113
  case 9:
130
114
  cacheModule = _context.sent;
131
115
  return _context.abrupt("break", 12);
132
-
133
116
  case 11:
134
117
  return _context.abrupt("break", 12);
135
-
136
118
  case 12:
137
119
  createCache = cacheModule.default;
138
120
  cache = createCache({
@@ -149,7 +131,6 @@ var HttpAdapter = /*#__PURE__*/function () {
149
131
  return cache.unset('flags');
150
132
  }
151
133
  });
152
-
153
134
  case 15:
154
135
  case "end":
155
136
  return _context.stop();
@@ -157,11 +138,9 @@ var HttpAdapter = /*#__PURE__*/function () {
157
138
  }
158
139
  }, _callee);
159
140
  }));
160
-
161
141
  function value(_x) {
162
142
  return _value.apply(this, arguments);
163
143
  }
164
-
165
144
  return value;
166
145
  }()
167
146
  });
@@ -169,7 +148,6 @@ var HttpAdapter = /*#__PURE__*/function () {
169
148
  writable: true,
170
149
  value: function value(nextFlags) {
171
150
  var previousFlags = _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState].flags;
172
-
173
151
  if (previousFlags === undefined) return true;
174
152
  return !isEqual__default["default"](nextFlags, previousFlags);
175
153
  }
@@ -185,11 +163,9 @@ var HttpAdapter = /*#__PURE__*/function () {
185
163
  case 0:
186
164
  _context2.next = 2;
187
165
  return adapterArgs.execute();
188
-
189
166
  case 2:
190
167
  flags = _context2.sent;
191
168
  return _context2.abrupt("return", flags);
192
-
193
169
  case 4:
194
170
  case "end":
195
171
  return _context2.stop();
@@ -197,11 +173,9 @@ var HttpAdapter = /*#__PURE__*/function () {
197
173
  }
198
174
  }, _callee2);
199
175
  }));
200
-
201
176
  function value(_x2) {
202
177
  return _value2.apply(this, arguments);
203
178
  }
204
-
205
179
  return value;
206
180
  }()
207
181
  });
@@ -209,7 +183,6 @@ var HttpAdapter = /*#__PURE__*/function () {
209
183
  writable: true,
210
184
  value: function value(adapterArgs) {
211
185
  var _adapterArgs$pollingI;
212
-
213
186
  var pollingInteralMs = (_adapterArgs$pollingI = adapterArgs.pollingInteralMs) !== null && _adapterArgs$pollingI !== void 0 ? _adapterArgs$pollingI : _classPrivateFieldLooseBase(_this, _defaultPollingInteralMs)[_defaultPollingInteralMs];
214
187
  setInterval( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee3() {
215
188
  var nextFlags, cache;
@@ -221,37 +194,28 @@ var HttpAdapter = /*#__PURE__*/function () {
221
194
  _context3.next = 14;
222
195
  break;
223
196
  }
224
-
225
197
  _context3.t0 = adapterUtilities.normalizeFlags;
226
198
  _context3.next = 4;
227
199
  return _classPrivateFieldLooseBase(_this, _fetchFlags)[_fetchFlags](adapterArgs);
228
-
229
200
  case 4:
230
201
  _context3.t1 = _context3.sent;
231
202
  nextFlags = (0, _context3.t0)(_context3.t1);
232
-
233
203
  if (!_classPrivateFieldLooseBase(_this, _didFlagsChange)[_didFlagsChange](nextFlags)) {
234
204
  _context3.next = 14;
235
205
  break;
236
206
  }
237
-
238
207
  if (!adapterArgs.cacheIdentifier) {
239
208
  _context3.next = 12;
240
209
  break;
241
210
  }
242
-
243
211
  _context3.next = 10;
244
212
  return _classPrivateFieldLooseBase(_this, _getCache)[_getCache](adapterArgs.cacheIdentifier);
245
-
246
213
  case 10:
247
214
  cache = _context3.sent;
248
215
  cache.set(nextFlags);
249
-
250
216
  case 12:
251
217
  _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState].flags = nextFlags;
252
-
253
218
  _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState].emitter.emit('flagsStateChange', nextFlags);
254
-
255
219
  case 14:
256
220
  case "end":
257
221
  return _context3.stop();
@@ -261,68 +225,50 @@ var HttpAdapter = /*#__PURE__*/function () {
261
225
  })), pollingInteralMs);
262
226
  }
263
227
  });
264
-
265
228
  this.getUser = function () {
266
229
  return _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState].user;
267
230
  };
268
-
269
231
  this.updateFlags = function (flags, options) {
270
232
  var isAdapterConfigured = _this.getIsConfigurationStatus(types.AdapterConfigurationStatus.Configured);
271
-
272
233
  warning__default["default"](isAdapterConfigured, '@flopflip/http-adapter: adapter not configured. Flags can not be updated before.');
273
234
  if (!isAdapterConfigured) return;
274
-
275
235
  var previousFlags = _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState].flags;
276
-
277
236
  var updatedFlags = Object.entries(flags).reduce(function (updatedFlags, _ref2) {
278
237
  var _ref3 = _slicedToArray(_ref2, 2),
279
- flagName = _ref3[0],
280
- flagValue = _ref3[1];
281
-
238
+ flagName = _ref3[0],
239
+ flagValue = _ref3[1];
282
240
  var _normalizeFlag = adapterUtilities.normalizeFlag(flagName, flagValue),
283
- _normalizeFlag2 = _slicedToArray(_normalizeFlag, 2),
284
- normalizedFlagName = _normalizeFlag2[0],
285
- normalizedFlagValue = _normalizeFlag2[1];
286
-
241
+ _normalizeFlag2 = _slicedToArray(_normalizeFlag, 2),
242
+ normalizedFlagName = _normalizeFlag2[0],
243
+ normalizedFlagValue = _normalizeFlag2[1];
287
244
  if (_classPrivateFieldLooseBase(_this, _getIsFlagLocked)[_getIsFlagLocked](normalizedFlagName)) return updatedFlags;
288
-
289
245
  if (options !== null && options !== void 0 && options.lockFlags) {
290
246
  _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState].lockedFlags.add(normalizedFlagName);
291
247
  }
292
-
293
248
  updatedFlags = _objectSpread(_objectSpread({}, updatedFlags), {}, _defineProperty({}, normalizedFlagName, normalizedFlagValue));
294
249
  return updatedFlags;
295
250
  }, {});
296
-
297
251
  var nextFlags = _objectSpread(_objectSpread({}, previousFlags), updatedFlags);
298
-
299
252
  _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState].flags = nextFlags;
300
-
301
253
  _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState].emitter.emit('flagsStateChange', nextFlags);
302
254
  };
303
-
304
255
  this.reset = function () {
305
256
  _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState] = _objectSpread({}, intialAdapterState);
306
257
  };
307
-
308
258
  this.unsubscribe = function () {
309
259
  _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState].subscriptionStatus = types.AdapterSubscriptionStatus.Unsubscribed;
310
260
  };
311
-
312
261
  this.subscribe = function () {
313
262
  _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState].subscriptionStatus = types.AdapterSubscriptionStatus.Subscribed;
314
263
  };
315
-
316
264
  this.id = types.adapterIdentifiers.http;
317
265
  _classPrivateFieldLooseBase(this, _adapterState)[_adapterState] = _objectSpread({}, intialAdapterState);
318
266
  }
319
-
320
267
  _createClass(HttpAdapter, [{
321
268
  key: "configure",
322
269
  value: function () {
323
270
  var _configure = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee5(adapterArgs, adapterEventHandlers) {
324
271
  var _this2 = this;
325
-
326
272
  var handleFlagsChange, handleStatusChange;
327
273
  return _regeneratorRuntime__default["default"].wrap(function _callee5$(_context5) {
328
274
  while (1) {
@@ -335,7 +281,6 @@ var HttpAdapter = /*#__PURE__*/function () {
335
281
  id: _this2.id
336
282
  });
337
283
  };
338
-
339
284
  handleStatusChange = function handleStatusChange(nextStatus) {
340
285
  if (_classPrivateFieldLooseBase(_this2, _getIsAdapterUnsubscribed)[_getIsAdapterUnsubscribed]()) return;
341
286
  adapterEventHandlers.onStatusStateChange({
@@ -343,16 +288,12 @@ var HttpAdapter = /*#__PURE__*/function () {
343
288
  id: _this2.id
344
289
  });
345
290
  };
346
-
347
291
  _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].emitter.on('flagsStateChange', handleFlagsChange);
348
-
349
292
  _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].emitter.on('statusStateChange', handleStatusChange);
350
-
351
293
  this.setConfigurationStatus(types.AdapterConfigurationStatus.Configuring);
352
294
  _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].user = adapterArgs.user;
353
295
  return _context5.abrupt("return", Promise.resolve().then( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee4() {
354
296
  var cachedFlags, cache, flags, _cache;
355
-
356
297
  return _regeneratorRuntime__default["default"].wrap(function _callee4$(_context4) {
357
298
  while (1) {
358
299
  switch (_context4.prev = _context4.next) {
@@ -361,56 +302,40 @@ var HttpAdapter = /*#__PURE__*/function () {
361
302
  _context4.next = 6;
362
303
  break;
363
304
  }
364
-
365
305
  _context4.next = 3;
366
306
  return _classPrivateFieldLooseBase(_this2, _getCache)[_getCache](adapterArgs.cacheIdentifier);
367
-
368
307
  case 3:
369
308
  cache = _context4.sent;
370
309
  cachedFlags = cache.get();
371
-
372
310
  if (cachedFlags) {
373
311
  _classPrivateFieldLooseBase(_this2, _adapterState)[_adapterState].flags = cachedFlags;
374
-
375
312
  _classPrivateFieldLooseBase(_this2, _adapterState)[_adapterState].emitter.emit('flagsStateChange', cachedFlags);
376
313
  }
377
-
378
314
  case 6:
379
315
  _this2.setConfigurationStatus(types.AdapterConfigurationStatus.Configured);
380
-
381
316
  _context4.t0 = adapterUtilities.normalizeFlags;
382
317
  _context4.next = 10;
383
318
  return _classPrivateFieldLooseBase(_this2, _fetchFlags)[_fetchFlags](adapterArgs);
384
-
385
319
  case 10:
386
320
  _context4.t1 = _context4.sent;
387
321
  flags = (0, _context4.t0)(_context4.t1);
388
322
  _classPrivateFieldLooseBase(_this2, _adapterState)[_adapterState].flags = flags;
389
-
390
323
  if (!adapterArgs.cacheIdentifier) {
391
324
  _context4.next = 18;
392
325
  break;
393
326
  }
394
-
395
327
  _context4.next = 16;
396
328
  return _classPrivateFieldLooseBase(_this2, _getCache)[_getCache](adapterArgs.cacheIdentifier);
397
-
398
329
  case 16:
399
330
  _cache = _context4.sent;
400
-
401
331
  _cache.set(flags);
402
-
403
332
  case 18:
404
333
  _classPrivateFieldLooseBase(_this2, _adapterState)[_adapterState].emitter.emit('flagsStateChange', flags);
405
-
406
334
  _classPrivateFieldLooseBase(_this2, _adapterState)[_adapterState].emitter.emit(_classPrivateFieldLooseBase(_this2, _internalConfiguredStatusChange__)[_internalConfiguredStatusChange__]);
407
-
408
335
  _classPrivateFieldLooseBase(_this2, _subscribeToFlagsChanges)[_subscribeToFlagsChanges](adapterArgs);
409
-
410
336
  return _context4.abrupt("return", {
411
337
  initializationStatus: types.AdapterInitializationStatus.Succeeded
412
338
  });
413
-
414
339
  case 22:
415
340
  case "end":
416
341
  return _context4.stop();
@@ -418,7 +343,6 @@ var HttpAdapter = /*#__PURE__*/function () {
418
343
  }
419
344
  }, _callee4);
420
345
  }))));
421
-
422
346
  case 7:
423
347
  case "end":
424
348
  return _context5.stop();
@@ -426,11 +350,9 @@ var HttpAdapter = /*#__PURE__*/function () {
426
350
  }
427
351
  }, _callee5, this);
428
352
  }));
429
-
430
353
  function configure(_x3, _x4) {
431
354
  return _configure.apply(this, arguments);
432
355
  }
433
-
434
356
  return configure;
435
357
  }()
436
358
  }, {
@@ -446,34 +368,25 @@ var HttpAdapter = /*#__PURE__*/function () {
446
368
  _context6.next = 2;
447
369
  break;
448
370
  }
449
-
450
371
  return _context6.abrupt("return", Promise.reject(new Error('@flopflip/http-adapter: please configure adapter before reconfiguring.')));
451
-
452
372
  case 2:
453
373
  _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].flags = {};
454
-
455
374
  if (!adapterArgs.cacheIdentifier) {
456
375
  _context6.next = 8;
457
376
  break;
458
377
  }
459
-
460
378
  _context6.next = 6;
461
379
  return _classPrivateFieldLooseBase(this, _getCache)[_getCache](adapterArgs.cacheIdentifier);
462
-
463
380
  case 6:
464
381
  cache = _context6.sent;
465
382
  cache.unset();
466
-
467
383
  case 8:
468
384
  nextUser = adapterArgs.user;
469
385
  _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].user = nextUser;
470
-
471
386
  _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].emitter.emit('flagsStateChange', {});
472
-
473
387
  return _context6.abrupt("return", Promise.resolve({
474
388
  initializationStatus: types.AdapterInitializationStatus.Succeeded
475
389
  }));
476
-
477
390
  case 12:
478
391
  case "end":
479
392
  return _context6.stop();
@@ -481,11 +394,9 @@ var HttpAdapter = /*#__PURE__*/function () {
481
394
  }
482
395
  }, _callee6, this);
483
396
  }));
484
-
485
397
  function reconfigure(_x5, _x6) {
486
398
  return _reconfigure.apply(this, arguments);
487
399
  }
488
-
489
400
  return reconfigure;
490
401
  }()
491
402
  }, {
@@ -493,7 +404,6 @@ var HttpAdapter = /*#__PURE__*/function () {
493
404
  value: function () {
494
405
  var _waitUntilConfigured = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee7() {
495
406
  var _this3 = this;
496
-
497
407
  return _regeneratorRuntime__default["default"].wrap(function _callee7$(_context7) {
498
408
  while (1) {
499
409
  switch (_context7.prev = _context7.next) {
@@ -501,7 +411,6 @@ var HttpAdapter = /*#__PURE__*/function () {
501
411
  return _context7.abrupt("return", new Promise(function (resolve) {
502
412
  if (_this3.getIsConfigurationStatus(types.AdapterConfigurationStatus.Configured)) resolve();else _classPrivateFieldLooseBase(_this3, _adapterState)[_adapterState].emitter.on(_classPrivateFieldLooseBase(_this3, _internalConfiguredStatusChange__)[_internalConfiguredStatusChange__], resolve);
503
413
  }));
504
-
505
414
  case 1:
506
415
  case "end":
507
416
  return _context7.stop();
@@ -509,11 +418,9 @@ var HttpAdapter = /*#__PURE__*/function () {
509
418
  }
510
419
  }, _callee7);
511
420
  }));
512
-
513
421
  function waitUntilConfigured() {
514
422
  return _waitUntilConfigured.apply(this, arguments);
515
423
  }
516
-
517
424
  return waitUntilConfigured;
518
425
  }()
519
426
  }, {
@@ -525,27 +432,23 @@ var HttpAdapter = /*#__PURE__*/function () {
525
432
  key: "getFlag",
526
433
  value: function getFlag(flagName) {
527
434
  var _classPrivateFieldLoo;
528
-
529
435
  return (_classPrivateFieldLoo = _classPrivateFieldLooseBase(this, _adapterState)[_adapterState]) === null || _classPrivateFieldLoo === void 0 ? void 0 : _classPrivateFieldLoo.flags[flagName];
530
436
  }
531
437
  }, {
532
438
  key: "setConfigurationStatus",
533
439
  value: function setConfigurationStatus(nextConfigurationStatus) {
534
440
  _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].configurationStatus = nextConfigurationStatus;
535
-
536
441
  _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].emitter.emit('statusStateChange', {
537
442
  configurationStatus: _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].configurationStatus
538
443
  });
539
444
  }
540
445
  }]);
541
-
542
446
  return HttpAdapter;
543
447
  }();
544
-
545
448
  var adapter = new HttpAdapter();
546
449
  adapterUtilities.exposeGlobally(adapter);
547
450
 
548
- var version = "0.0.25";
451
+ var version = "0.0.27";
549
452
 
550
453
  exports["default"] = adapter;
551
454
  exports.version = version;
@@ -51,31 +51,19 @@ var intialAdapterState = {
51
51
  user: {},
52
52
  emitter: mitt__default["default"]()
53
53
  };
54
-
55
54
  var _internalConfiguredStatusChange__ = /*#__PURE__*/_classPrivateFieldLooseKey("__internalConfiguredStatusChange__");
56
-
57
55
  var _adapterState = /*#__PURE__*/_classPrivateFieldLooseKey("adapterState");
58
-
59
56
  var _defaultPollingInteralMs = /*#__PURE__*/_classPrivateFieldLooseKey("defaultPollingInteralMs");
60
-
61
57
  var _getIsAdapterUnsubscribed = /*#__PURE__*/_classPrivateFieldLooseKey("getIsAdapterUnsubscribed");
62
-
63
58
  var _getIsFlagLocked = /*#__PURE__*/_classPrivateFieldLooseKey("getIsFlagLocked");
64
-
65
59
  var _getCache = /*#__PURE__*/_classPrivateFieldLooseKey("getCache");
66
-
67
60
  var _didFlagsChange = /*#__PURE__*/_classPrivateFieldLooseKey("didFlagsChange");
68
-
69
61
  var _fetchFlags = /*#__PURE__*/_classPrivateFieldLooseKey("fetchFlags");
70
-
71
62
  var _subscribeToFlagsChanges = /*#__PURE__*/_classPrivateFieldLooseKey("subscribeToFlagsChanges");
72
-
73
63
  var HttpAdapter = /*#__PURE__*/function () {
74
64
  function HttpAdapter() {
75
65
  var _this = this;
76
-
77
66
  _classCallCheck(this, HttpAdapter);
78
-
79
67
  Object.defineProperty(this, _internalConfiguredStatusChange__, {
80
68
  writable: true,
81
69
  value: '__internalConfiguredStatusChange__'
@@ -113,26 +101,20 @@ var HttpAdapter = /*#__PURE__*/function () {
113
101
  _context.t0 = cacheIdentifier;
114
102
  _context.next = _context.t0 === types.cacheIdentifiers.local ? 3 : _context.t0 === types.cacheIdentifiers.session ? 7 : 11;
115
103
  break;
116
-
117
104
  case 3:
118
105
  _context.next = 5;
119
106
  return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@flopflip/localstorage-cache')); });
120
-
121
107
  case 5:
122
108
  cacheModule = _context.sent;
123
109
  return _context.abrupt("break", 12);
124
-
125
110
  case 7:
126
111
  _context.next = 9;
127
112
  return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@flopflip/sessionstorage-cache')); });
128
-
129
113
  case 9:
130
114
  cacheModule = _context.sent;
131
115
  return _context.abrupt("break", 12);
132
-
133
116
  case 11:
134
117
  return _context.abrupt("break", 12);
135
-
136
118
  case 12:
137
119
  createCache = cacheModule.default;
138
120
  cache = createCache({
@@ -149,7 +131,6 @@ var HttpAdapter = /*#__PURE__*/function () {
149
131
  return cache.unset('flags');
150
132
  }
151
133
  });
152
-
153
134
  case 15:
154
135
  case "end":
155
136
  return _context.stop();
@@ -157,11 +138,9 @@ var HttpAdapter = /*#__PURE__*/function () {
157
138
  }
158
139
  }, _callee);
159
140
  }));
160
-
161
141
  function value(_x) {
162
142
  return _value.apply(this, arguments);
163
143
  }
164
-
165
144
  return value;
166
145
  }()
167
146
  });
@@ -169,7 +148,6 @@ var HttpAdapter = /*#__PURE__*/function () {
169
148
  writable: true,
170
149
  value: function value(nextFlags) {
171
150
  var previousFlags = _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState].flags;
172
-
173
151
  if (previousFlags === undefined) return true;
174
152
  return !isEqual__default["default"](nextFlags, previousFlags);
175
153
  }
@@ -185,11 +163,9 @@ var HttpAdapter = /*#__PURE__*/function () {
185
163
  case 0:
186
164
  _context2.next = 2;
187
165
  return adapterArgs.execute();
188
-
189
166
  case 2:
190
167
  flags = _context2.sent;
191
168
  return _context2.abrupt("return", flags);
192
-
193
169
  case 4:
194
170
  case "end":
195
171
  return _context2.stop();
@@ -197,11 +173,9 @@ var HttpAdapter = /*#__PURE__*/function () {
197
173
  }
198
174
  }, _callee2);
199
175
  }));
200
-
201
176
  function value(_x2) {
202
177
  return _value2.apply(this, arguments);
203
178
  }
204
-
205
179
  return value;
206
180
  }()
207
181
  });
@@ -209,7 +183,6 @@ var HttpAdapter = /*#__PURE__*/function () {
209
183
  writable: true,
210
184
  value: function value(adapterArgs) {
211
185
  var _adapterArgs$pollingI;
212
-
213
186
  var pollingInteralMs = (_adapterArgs$pollingI = adapterArgs.pollingInteralMs) !== null && _adapterArgs$pollingI !== void 0 ? _adapterArgs$pollingI : _classPrivateFieldLooseBase(_this, _defaultPollingInteralMs)[_defaultPollingInteralMs];
214
187
  setInterval( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee3() {
215
188
  var nextFlags, cache;
@@ -221,37 +194,28 @@ var HttpAdapter = /*#__PURE__*/function () {
221
194
  _context3.next = 14;
222
195
  break;
223
196
  }
224
-
225
197
  _context3.t0 = adapterUtilities.normalizeFlags;
226
198
  _context3.next = 4;
227
199
  return _classPrivateFieldLooseBase(_this, _fetchFlags)[_fetchFlags](adapterArgs);
228
-
229
200
  case 4:
230
201
  _context3.t1 = _context3.sent;
231
202
  nextFlags = (0, _context3.t0)(_context3.t1);
232
-
233
203
  if (!_classPrivateFieldLooseBase(_this, _didFlagsChange)[_didFlagsChange](nextFlags)) {
234
204
  _context3.next = 14;
235
205
  break;
236
206
  }
237
-
238
207
  if (!adapterArgs.cacheIdentifier) {
239
208
  _context3.next = 12;
240
209
  break;
241
210
  }
242
-
243
211
  _context3.next = 10;
244
212
  return _classPrivateFieldLooseBase(_this, _getCache)[_getCache](adapterArgs.cacheIdentifier);
245
-
246
213
  case 10:
247
214
  cache = _context3.sent;
248
215
  cache.set(nextFlags);
249
-
250
216
  case 12:
251
217
  _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState].flags = nextFlags;
252
-
253
218
  _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState].emitter.emit('flagsStateChange', nextFlags);
254
-
255
219
  case 14:
256
220
  case "end":
257
221
  return _context3.stop();
@@ -261,68 +225,50 @@ var HttpAdapter = /*#__PURE__*/function () {
261
225
  })), pollingInteralMs);
262
226
  }
263
227
  });
264
-
265
228
  this.getUser = function () {
266
229
  return _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState].user;
267
230
  };
268
-
269
231
  this.updateFlags = function (flags, options) {
270
232
  var isAdapterConfigured = _this.getIsConfigurationStatus(types.AdapterConfigurationStatus.Configured);
271
-
272
233
  warning__default["default"](isAdapterConfigured, '@flopflip/http-adapter: adapter not configured. Flags can not be updated before.');
273
234
  if (!isAdapterConfigured) return;
274
-
275
235
  var previousFlags = _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState].flags;
276
-
277
236
  var updatedFlags = Object.entries(flags).reduce(function (updatedFlags, _ref2) {
278
237
  var _ref3 = _slicedToArray(_ref2, 2),
279
- flagName = _ref3[0],
280
- flagValue = _ref3[1];
281
-
238
+ flagName = _ref3[0],
239
+ flagValue = _ref3[1];
282
240
  var _normalizeFlag = adapterUtilities.normalizeFlag(flagName, flagValue),
283
- _normalizeFlag2 = _slicedToArray(_normalizeFlag, 2),
284
- normalizedFlagName = _normalizeFlag2[0],
285
- normalizedFlagValue = _normalizeFlag2[1];
286
-
241
+ _normalizeFlag2 = _slicedToArray(_normalizeFlag, 2),
242
+ normalizedFlagName = _normalizeFlag2[0],
243
+ normalizedFlagValue = _normalizeFlag2[1];
287
244
  if (_classPrivateFieldLooseBase(_this, _getIsFlagLocked)[_getIsFlagLocked](normalizedFlagName)) return updatedFlags;
288
-
289
245
  if (options !== null && options !== void 0 && options.lockFlags) {
290
246
  _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState].lockedFlags.add(normalizedFlagName);
291
247
  }
292
-
293
248
  updatedFlags = _objectSpread(_objectSpread({}, updatedFlags), {}, _defineProperty({}, normalizedFlagName, normalizedFlagValue));
294
249
  return updatedFlags;
295
250
  }, {});
296
-
297
251
  var nextFlags = _objectSpread(_objectSpread({}, previousFlags), updatedFlags);
298
-
299
252
  _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState].flags = nextFlags;
300
-
301
253
  _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState].emitter.emit('flagsStateChange', nextFlags);
302
254
  };
303
-
304
255
  this.reset = function () {
305
256
  _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState] = _objectSpread({}, intialAdapterState);
306
257
  };
307
-
308
258
  this.unsubscribe = function () {
309
259
  _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState].subscriptionStatus = types.AdapterSubscriptionStatus.Unsubscribed;
310
260
  };
311
-
312
261
  this.subscribe = function () {
313
262
  _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState].subscriptionStatus = types.AdapterSubscriptionStatus.Subscribed;
314
263
  };
315
-
316
264
  this.id = types.adapterIdentifiers.http;
317
265
  _classPrivateFieldLooseBase(this, _adapterState)[_adapterState] = _objectSpread({}, intialAdapterState);
318
266
  }
319
-
320
267
  _createClass(HttpAdapter, [{
321
268
  key: "configure",
322
269
  value: function () {
323
270
  var _configure = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee5(adapterArgs, adapterEventHandlers) {
324
271
  var _this2 = this;
325
-
326
272
  var handleFlagsChange, handleStatusChange;
327
273
  return _regeneratorRuntime__default["default"].wrap(function _callee5$(_context5) {
328
274
  while (1) {
@@ -335,7 +281,6 @@ var HttpAdapter = /*#__PURE__*/function () {
335
281
  id: _this2.id
336
282
  });
337
283
  };
338
-
339
284
  handleStatusChange = function handleStatusChange(nextStatus) {
340
285
  if (_classPrivateFieldLooseBase(_this2, _getIsAdapterUnsubscribed)[_getIsAdapterUnsubscribed]()) return;
341
286
  adapterEventHandlers.onStatusStateChange({
@@ -343,16 +288,12 @@ var HttpAdapter = /*#__PURE__*/function () {
343
288
  id: _this2.id
344
289
  });
345
290
  };
346
-
347
291
  _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].emitter.on('flagsStateChange', handleFlagsChange);
348
-
349
292
  _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].emitter.on('statusStateChange', handleStatusChange);
350
-
351
293
  this.setConfigurationStatus(types.AdapterConfigurationStatus.Configuring);
352
294
  _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].user = adapterArgs.user;
353
295
  return _context5.abrupt("return", Promise.resolve().then( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee4() {
354
296
  var cachedFlags, cache, flags, _cache;
355
-
356
297
  return _regeneratorRuntime__default["default"].wrap(function _callee4$(_context4) {
357
298
  while (1) {
358
299
  switch (_context4.prev = _context4.next) {
@@ -361,56 +302,40 @@ var HttpAdapter = /*#__PURE__*/function () {
361
302
  _context4.next = 6;
362
303
  break;
363
304
  }
364
-
365
305
  _context4.next = 3;
366
306
  return _classPrivateFieldLooseBase(_this2, _getCache)[_getCache](adapterArgs.cacheIdentifier);
367
-
368
307
  case 3:
369
308
  cache = _context4.sent;
370
309
  cachedFlags = cache.get();
371
-
372
310
  if (cachedFlags) {
373
311
  _classPrivateFieldLooseBase(_this2, _adapterState)[_adapterState].flags = cachedFlags;
374
-
375
312
  _classPrivateFieldLooseBase(_this2, _adapterState)[_adapterState].emitter.emit('flagsStateChange', cachedFlags);
376
313
  }
377
-
378
314
  case 6:
379
315
  _this2.setConfigurationStatus(types.AdapterConfigurationStatus.Configured);
380
-
381
316
  _context4.t0 = adapterUtilities.normalizeFlags;
382
317
  _context4.next = 10;
383
318
  return _classPrivateFieldLooseBase(_this2, _fetchFlags)[_fetchFlags](adapterArgs);
384
-
385
319
  case 10:
386
320
  _context4.t1 = _context4.sent;
387
321
  flags = (0, _context4.t0)(_context4.t1);
388
322
  _classPrivateFieldLooseBase(_this2, _adapterState)[_adapterState].flags = flags;
389
-
390
323
  if (!adapterArgs.cacheIdentifier) {
391
324
  _context4.next = 18;
392
325
  break;
393
326
  }
394
-
395
327
  _context4.next = 16;
396
328
  return _classPrivateFieldLooseBase(_this2, _getCache)[_getCache](adapterArgs.cacheIdentifier);
397
-
398
329
  case 16:
399
330
  _cache = _context4.sent;
400
-
401
331
  _cache.set(flags);
402
-
403
332
  case 18:
404
333
  _classPrivateFieldLooseBase(_this2, _adapterState)[_adapterState].emitter.emit('flagsStateChange', flags);
405
-
406
334
  _classPrivateFieldLooseBase(_this2, _adapterState)[_adapterState].emitter.emit(_classPrivateFieldLooseBase(_this2, _internalConfiguredStatusChange__)[_internalConfiguredStatusChange__]);
407
-
408
335
  _classPrivateFieldLooseBase(_this2, _subscribeToFlagsChanges)[_subscribeToFlagsChanges](adapterArgs);
409
-
410
336
  return _context4.abrupt("return", {
411
337
  initializationStatus: types.AdapterInitializationStatus.Succeeded
412
338
  });
413
-
414
339
  case 22:
415
340
  case "end":
416
341
  return _context4.stop();
@@ -418,7 +343,6 @@ var HttpAdapter = /*#__PURE__*/function () {
418
343
  }
419
344
  }, _callee4);
420
345
  }))));
421
-
422
346
  case 7:
423
347
  case "end":
424
348
  return _context5.stop();
@@ -426,11 +350,9 @@ var HttpAdapter = /*#__PURE__*/function () {
426
350
  }
427
351
  }, _callee5, this);
428
352
  }));
429
-
430
353
  function configure(_x3, _x4) {
431
354
  return _configure.apply(this, arguments);
432
355
  }
433
-
434
356
  return configure;
435
357
  }()
436
358
  }, {
@@ -446,34 +368,25 @@ var HttpAdapter = /*#__PURE__*/function () {
446
368
  _context6.next = 2;
447
369
  break;
448
370
  }
449
-
450
371
  return _context6.abrupt("return", Promise.reject(new Error('@flopflip/http-adapter: please configure adapter before reconfiguring.')));
451
-
452
372
  case 2:
453
373
  _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].flags = {};
454
-
455
374
  if (!adapterArgs.cacheIdentifier) {
456
375
  _context6.next = 8;
457
376
  break;
458
377
  }
459
-
460
378
  _context6.next = 6;
461
379
  return _classPrivateFieldLooseBase(this, _getCache)[_getCache](adapterArgs.cacheIdentifier);
462
-
463
380
  case 6:
464
381
  cache = _context6.sent;
465
382
  cache.unset();
466
-
467
383
  case 8:
468
384
  nextUser = adapterArgs.user;
469
385
  _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].user = nextUser;
470
-
471
386
  _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].emitter.emit('flagsStateChange', {});
472
-
473
387
  return _context6.abrupt("return", Promise.resolve({
474
388
  initializationStatus: types.AdapterInitializationStatus.Succeeded
475
389
  }));
476
-
477
390
  case 12:
478
391
  case "end":
479
392
  return _context6.stop();
@@ -481,11 +394,9 @@ var HttpAdapter = /*#__PURE__*/function () {
481
394
  }
482
395
  }, _callee6, this);
483
396
  }));
484
-
485
397
  function reconfigure(_x5, _x6) {
486
398
  return _reconfigure.apply(this, arguments);
487
399
  }
488
-
489
400
  return reconfigure;
490
401
  }()
491
402
  }, {
@@ -493,7 +404,6 @@ var HttpAdapter = /*#__PURE__*/function () {
493
404
  value: function () {
494
405
  var _waitUntilConfigured = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee7() {
495
406
  var _this3 = this;
496
-
497
407
  return _regeneratorRuntime__default["default"].wrap(function _callee7$(_context7) {
498
408
  while (1) {
499
409
  switch (_context7.prev = _context7.next) {
@@ -501,7 +411,6 @@ var HttpAdapter = /*#__PURE__*/function () {
501
411
  return _context7.abrupt("return", new Promise(function (resolve) {
502
412
  if (_this3.getIsConfigurationStatus(types.AdapterConfigurationStatus.Configured)) resolve();else _classPrivateFieldLooseBase(_this3, _adapterState)[_adapterState].emitter.on(_classPrivateFieldLooseBase(_this3, _internalConfiguredStatusChange__)[_internalConfiguredStatusChange__], resolve);
503
413
  }));
504
-
505
414
  case 1:
506
415
  case "end":
507
416
  return _context7.stop();
@@ -509,11 +418,9 @@ var HttpAdapter = /*#__PURE__*/function () {
509
418
  }
510
419
  }, _callee7);
511
420
  }));
512
-
513
421
  function waitUntilConfigured() {
514
422
  return _waitUntilConfigured.apply(this, arguments);
515
423
  }
516
-
517
424
  return waitUntilConfigured;
518
425
  }()
519
426
  }, {
@@ -525,27 +432,23 @@ var HttpAdapter = /*#__PURE__*/function () {
525
432
  key: "getFlag",
526
433
  value: function getFlag(flagName) {
527
434
  var _classPrivateFieldLoo;
528
-
529
435
  return (_classPrivateFieldLoo = _classPrivateFieldLooseBase(this, _adapterState)[_adapterState]) === null || _classPrivateFieldLoo === void 0 ? void 0 : _classPrivateFieldLoo.flags[flagName];
530
436
  }
531
437
  }, {
532
438
  key: "setConfigurationStatus",
533
439
  value: function setConfigurationStatus(nextConfigurationStatus) {
534
440
  _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].configurationStatus = nextConfigurationStatus;
535
-
536
441
  _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].emitter.emit('statusStateChange', {
537
442
  configurationStatus: _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].configurationStatus
538
443
  });
539
444
  }
540
445
  }]);
541
-
542
446
  return HttpAdapter;
543
447
  }();
544
-
545
448
  var adapter = new HttpAdapter();
546
449
  adapterUtilities.exposeGlobally(adapter);
547
450
 
548
- var version = "0.0.25";
451
+ var version = "0.0.27";
549
452
 
550
453
  exports["default"] = adapter;
551
454
  exports.version = version;
@@ -22,31 +22,19 @@ var intialAdapterState = {
22
22
  user: {},
23
23
  emitter: mitt()
24
24
  };
25
-
26
25
  var _internalConfiguredStatusChange__ = /*#__PURE__*/_classPrivateFieldLooseKey("__internalConfiguredStatusChange__");
27
-
28
26
  var _adapterState = /*#__PURE__*/_classPrivateFieldLooseKey("adapterState");
29
-
30
27
  var _defaultPollingInteralMs = /*#__PURE__*/_classPrivateFieldLooseKey("defaultPollingInteralMs");
31
-
32
28
  var _getIsAdapterUnsubscribed = /*#__PURE__*/_classPrivateFieldLooseKey("getIsAdapterUnsubscribed");
33
-
34
29
  var _getIsFlagLocked = /*#__PURE__*/_classPrivateFieldLooseKey("getIsFlagLocked");
35
-
36
30
  var _getCache = /*#__PURE__*/_classPrivateFieldLooseKey("getCache");
37
-
38
31
  var _didFlagsChange = /*#__PURE__*/_classPrivateFieldLooseKey("didFlagsChange");
39
-
40
32
  var _fetchFlags = /*#__PURE__*/_classPrivateFieldLooseKey("fetchFlags");
41
-
42
33
  var _subscribeToFlagsChanges = /*#__PURE__*/_classPrivateFieldLooseKey("subscribeToFlagsChanges");
43
-
44
34
  var HttpAdapter = /*#__PURE__*/function () {
45
35
  function HttpAdapter() {
46
36
  var _this = this;
47
-
48
37
  _classCallCheck(this, HttpAdapter);
49
-
50
38
  Object.defineProperty(this, _internalConfiguredStatusChange__, {
51
39
  writable: true,
52
40
  value: '__internalConfiguredStatusChange__'
@@ -84,26 +72,20 @@ var HttpAdapter = /*#__PURE__*/function () {
84
72
  _context.t0 = cacheIdentifier;
85
73
  _context.next = _context.t0 === cacheIdentifiers.local ? 3 : _context.t0 === cacheIdentifiers.session ? 7 : 11;
86
74
  break;
87
-
88
75
  case 3:
89
76
  _context.next = 5;
90
77
  return import('@flopflip/localstorage-cache');
91
-
92
78
  case 5:
93
79
  cacheModule = _context.sent;
94
80
  return _context.abrupt("break", 12);
95
-
96
81
  case 7:
97
82
  _context.next = 9;
98
83
  return import('@flopflip/sessionstorage-cache');
99
-
100
84
  case 9:
101
85
  cacheModule = _context.sent;
102
86
  return _context.abrupt("break", 12);
103
-
104
87
  case 11:
105
88
  return _context.abrupt("break", 12);
106
-
107
89
  case 12:
108
90
  createCache = cacheModule.default;
109
91
  cache = createCache({
@@ -120,7 +102,6 @@ var HttpAdapter = /*#__PURE__*/function () {
120
102
  return cache.unset('flags');
121
103
  }
122
104
  });
123
-
124
105
  case 15:
125
106
  case "end":
126
107
  return _context.stop();
@@ -128,11 +109,9 @@ var HttpAdapter = /*#__PURE__*/function () {
128
109
  }
129
110
  }, _callee);
130
111
  }));
131
-
132
112
  function value(_x) {
133
113
  return _value.apply(this, arguments);
134
114
  }
135
-
136
115
  return value;
137
116
  }()
138
117
  });
@@ -140,7 +119,6 @@ var HttpAdapter = /*#__PURE__*/function () {
140
119
  writable: true,
141
120
  value: function value(nextFlags) {
142
121
  var previousFlags = _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState].flags;
143
-
144
122
  if (previousFlags === undefined) return true;
145
123
  return !isEqual(nextFlags, previousFlags);
146
124
  }
@@ -156,11 +134,9 @@ var HttpAdapter = /*#__PURE__*/function () {
156
134
  case 0:
157
135
  _context2.next = 2;
158
136
  return adapterArgs.execute();
159
-
160
137
  case 2:
161
138
  flags = _context2.sent;
162
139
  return _context2.abrupt("return", flags);
163
-
164
140
  case 4:
165
141
  case "end":
166
142
  return _context2.stop();
@@ -168,11 +144,9 @@ var HttpAdapter = /*#__PURE__*/function () {
168
144
  }
169
145
  }, _callee2);
170
146
  }));
171
-
172
147
  function value(_x2) {
173
148
  return _value2.apply(this, arguments);
174
149
  }
175
-
176
150
  return value;
177
151
  }()
178
152
  });
@@ -180,7 +154,6 @@ var HttpAdapter = /*#__PURE__*/function () {
180
154
  writable: true,
181
155
  value: function value(adapterArgs) {
182
156
  var _adapterArgs$pollingI;
183
-
184
157
  var pollingInteralMs = (_adapterArgs$pollingI = adapterArgs.pollingInteralMs) !== null && _adapterArgs$pollingI !== void 0 ? _adapterArgs$pollingI : _classPrivateFieldLooseBase(_this, _defaultPollingInteralMs)[_defaultPollingInteralMs];
185
158
  setInterval( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
186
159
  var nextFlags, cache;
@@ -192,37 +165,28 @@ var HttpAdapter = /*#__PURE__*/function () {
192
165
  _context3.next = 14;
193
166
  break;
194
167
  }
195
-
196
168
  _context3.t0 = normalizeFlags;
197
169
  _context3.next = 4;
198
170
  return _classPrivateFieldLooseBase(_this, _fetchFlags)[_fetchFlags](adapterArgs);
199
-
200
171
  case 4:
201
172
  _context3.t1 = _context3.sent;
202
173
  nextFlags = (0, _context3.t0)(_context3.t1);
203
-
204
174
  if (!_classPrivateFieldLooseBase(_this, _didFlagsChange)[_didFlagsChange](nextFlags)) {
205
175
  _context3.next = 14;
206
176
  break;
207
177
  }
208
-
209
178
  if (!adapterArgs.cacheIdentifier) {
210
179
  _context3.next = 12;
211
180
  break;
212
181
  }
213
-
214
182
  _context3.next = 10;
215
183
  return _classPrivateFieldLooseBase(_this, _getCache)[_getCache](adapterArgs.cacheIdentifier);
216
-
217
184
  case 10:
218
185
  cache = _context3.sent;
219
186
  cache.set(nextFlags);
220
-
221
187
  case 12:
222
188
  _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState].flags = nextFlags;
223
-
224
189
  _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState].emitter.emit('flagsStateChange', nextFlags);
225
-
226
190
  case 14:
227
191
  case "end":
228
192
  return _context3.stop();
@@ -232,68 +196,50 @@ var HttpAdapter = /*#__PURE__*/function () {
232
196
  })), pollingInteralMs);
233
197
  }
234
198
  });
235
-
236
199
  this.getUser = function () {
237
200
  return _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState].user;
238
201
  };
239
-
240
202
  this.updateFlags = function (flags, options) {
241
203
  var isAdapterConfigured = _this.getIsConfigurationStatus(AdapterConfigurationStatus.Configured);
242
-
243
204
  warning(isAdapterConfigured, '@flopflip/http-adapter: adapter not configured. Flags can not be updated before.');
244
205
  if (!isAdapterConfigured) return;
245
-
246
206
  var previousFlags = _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState].flags;
247
-
248
207
  var updatedFlags = Object.entries(flags).reduce(function (updatedFlags, _ref2) {
249
208
  var _ref3 = _slicedToArray(_ref2, 2),
250
- flagName = _ref3[0],
251
- flagValue = _ref3[1];
252
-
209
+ flagName = _ref3[0],
210
+ flagValue = _ref3[1];
253
211
  var _normalizeFlag = normalizeFlag(flagName, flagValue),
254
- _normalizeFlag2 = _slicedToArray(_normalizeFlag, 2),
255
- normalizedFlagName = _normalizeFlag2[0],
256
- normalizedFlagValue = _normalizeFlag2[1];
257
-
212
+ _normalizeFlag2 = _slicedToArray(_normalizeFlag, 2),
213
+ normalizedFlagName = _normalizeFlag2[0],
214
+ normalizedFlagValue = _normalizeFlag2[1];
258
215
  if (_classPrivateFieldLooseBase(_this, _getIsFlagLocked)[_getIsFlagLocked](normalizedFlagName)) return updatedFlags;
259
-
260
216
  if (options !== null && options !== void 0 && options.lockFlags) {
261
217
  _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState].lockedFlags.add(normalizedFlagName);
262
218
  }
263
-
264
219
  updatedFlags = _objectSpread(_objectSpread({}, updatedFlags), {}, _defineProperty({}, normalizedFlagName, normalizedFlagValue));
265
220
  return updatedFlags;
266
221
  }, {});
267
-
268
222
  var nextFlags = _objectSpread(_objectSpread({}, previousFlags), updatedFlags);
269
-
270
223
  _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState].flags = nextFlags;
271
-
272
224
  _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState].emitter.emit('flagsStateChange', nextFlags);
273
225
  };
274
-
275
226
  this.reset = function () {
276
227
  _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState] = _objectSpread({}, intialAdapterState);
277
228
  };
278
-
279
229
  this.unsubscribe = function () {
280
230
  _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState].subscriptionStatus = AdapterSubscriptionStatus.Unsubscribed;
281
231
  };
282
-
283
232
  this.subscribe = function () {
284
233
  _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState].subscriptionStatus = AdapterSubscriptionStatus.Subscribed;
285
234
  };
286
-
287
235
  this.id = adapterIdentifiers.http;
288
236
  _classPrivateFieldLooseBase(this, _adapterState)[_adapterState] = _objectSpread({}, intialAdapterState);
289
237
  }
290
-
291
238
  _createClass(HttpAdapter, [{
292
239
  key: "configure",
293
240
  value: function () {
294
241
  var _configure = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(adapterArgs, adapterEventHandlers) {
295
242
  var _this2 = this;
296
-
297
243
  var handleFlagsChange, handleStatusChange;
298
244
  return _regeneratorRuntime.wrap(function _callee5$(_context5) {
299
245
  while (1) {
@@ -306,7 +252,6 @@ var HttpAdapter = /*#__PURE__*/function () {
306
252
  id: _this2.id
307
253
  });
308
254
  };
309
-
310
255
  handleStatusChange = function handleStatusChange(nextStatus) {
311
256
  if (_classPrivateFieldLooseBase(_this2, _getIsAdapterUnsubscribed)[_getIsAdapterUnsubscribed]()) return;
312
257
  adapterEventHandlers.onStatusStateChange({
@@ -314,16 +259,12 @@ var HttpAdapter = /*#__PURE__*/function () {
314
259
  id: _this2.id
315
260
  });
316
261
  };
317
-
318
262
  _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].emitter.on('flagsStateChange', handleFlagsChange);
319
-
320
263
  _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].emitter.on('statusStateChange', handleStatusChange);
321
-
322
264
  this.setConfigurationStatus(AdapterConfigurationStatus.Configuring);
323
265
  _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].user = adapterArgs.user;
324
266
  return _context5.abrupt("return", Promise.resolve().then( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
325
267
  var cachedFlags, cache, flags, _cache;
326
-
327
268
  return _regeneratorRuntime.wrap(function _callee4$(_context4) {
328
269
  while (1) {
329
270
  switch (_context4.prev = _context4.next) {
@@ -332,56 +273,40 @@ var HttpAdapter = /*#__PURE__*/function () {
332
273
  _context4.next = 6;
333
274
  break;
334
275
  }
335
-
336
276
  _context4.next = 3;
337
277
  return _classPrivateFieldLooseBase(_this2, _getCache)[_getCache](adapterArgs.cacheIdentifier);
338
-
339
278
  case 3:
340
279
  cache = _context4.sent;
341
280
  cachedFlags = cache.get();
342
-
343
281
  if (cachedFlags) {
344
282
  _classPrivateFieldLooseBase(_this2, _adapterState)[_adapterState].flags = cachedFlags;
345
-
346
283
  _classPrivateFieldLooseBase(_this2, _adapterState)[_adapterState].emitter.emit('flagsStateChange', cachedFlags);
347
284
  }
348
-
349
285
  case 6:
350
286
  _this2.setConfigurationStatus(AdapterConfigurationStatus.Configured);
351
-
352
287
  _context4.t0 = normalizeFlags;
353
288
  _context4.next = 10;
354
289
  return _classPrivateFieldLooseBase(_this2, _fetchFlags)[_fetchFlags](adapterArgs);
355
-
356
290
  case 10:
357
291
  _context4.t1 = _context4.sent;
358
292
  flags = (0, _context4.t0)(_context4.t1);
359
293
  _classPrivateFieldLooseBase(_this2, _adapterState)[_adapterState].flags = flags;
360
-
361
294
  if (!adapterArgs.cacheIdentifier) {
362
295
  _context4.next = 18;
363
296
  break;
364
297
  }
365
-
366
298
  _context4.next = 16;
367
299
  return _classPrivateFieldLooseBase(_this2, _getCache)[_getCache](adapterArgs.cacheIdentifier);
368
-
369
300
  case 16:
370
301
  _cache = _context4.sent;
371
-
372
302
  _cache.set(flags);
373
-
374
303
  case 18:
375
304
  _classPrivateFieldLooseBase(_this2, _adapterState)[_adapterState].emitter.emit('flagsStateChange', flags);
376
-
377
305
  _classPrivateFieldLooseBase(_this2, _adapterState)[_adapterState].emitter.emit(_classPrivateFieldLooseBase(_this2, _internalConfiguredStatusChange__)[_internalConfiguredStatusChange__]);
378
-
379
306
  _classPrivateFieldLooseBase(_this2, _subscribeToFlagsChanges)[_subscribeToFlagsChanges](adapterArgs);
380
-
381
307
  return _context4.abrupt("return", {
382
308
  initializationStatus: AdapterInitializationStatus.Succeeded
383
309
  });
384
-
385
310
  case 22:
386
311
  case "end":
387
312
  return _context4.stop();
@@ -389,7 +314,6 @@ var HttpAdapter = /*#__PURE__*/function () {
389
314
  }
390
315
  }, _callee4);
391
316
  }))));
392
-
393
317
  case 7:
394
318
  case "end":
395
319
  return _context5.stop();
@@ -397,11 +321,9 @@ var HttpAdapter = /*#__PURE__*/function () {
397
321
  }
398
322
  }, _callee5, this);
399
323
  }));
400
-
401
324
  function configure(_x3, _x4) {
402
325
  return _configure.apply(this, arguments);
403
326
  }
404
-
405
327
  return configure;
406
328
  }()
407
329
  }, {
@@ -417,34 +339,25 @@ var HttpAdapter = /*#__PURE__*/function () {
417
339
  _context6.next = 2;
418
340
  break;
419
341
  }
420
-
421
342
  return _context6.abrupt("return", Promise.reject(new Error('@flopflip/http-adapter: please configure adapter before reconfiguring.')));
422
-
423
343
  case 2:
424
344
  _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].flags = {};
425
-
426
345
  if (!adapterArgs.cacheIdentifier) {
427
346
  _context6.next = 8;
428
347
  break;
429
348
  }
430
-
431
349
  _context6.next = 6;
432
350
  return _classPrivateFieldLooseBase(this, _getCache)[_getCache](adapterArgs.cacheIdentifier);
433
-
434
351
  case 6:
435
352
  cache = _context6.sent;
436
353
  cache.unset();
437
-
438
354
  case 8:
439
355
  nextUser = adapterArgs.user;
440
356
  _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].user = nextUser;
441
-
442
357
  _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].emitter.emit('flagsStateChange', {});
443
-
444
358
  return _context6.abrupt("return", Promise.resolve({
445
359
  initializationStatus: AdapterInitializationStatus.Succeeded
446
360
  }));
447
-
448
361
  case 12:
449
362
  case "end":
450
363
  return _context6.stop();
@@ -452,11 +365,9 @@ var HttpAdapter = /*#__PURE__*/function () {
452
365
  }
453
366
  }, _callee6, this);
454
367
  }));
455
-
456
368
  function reconfigure(_x5, _x6) {
457
369
  return _reconfigure.apply(this, arguments);
458
370
  }
459
-
460
371
  return reconfigure;
461
372
  }()
462
373
  }, {
@@ -464,7 +375,6 @@ var HttpAdapter = /*#__PURE__*/function () {
464
375
  value: function () {
465
376
  var _waitUntilConfigured = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7() {
466
377
  var _this3 = this;
467
-
468
378
  return _regeneratorRuntime.wrap(function _callee7$(_context7) {
469
379
  while (1) {
470
380
  switch (_context7.prev = _context7.next) {
@@ -472,7 +382,6 @@ var HttpAdapter = /*#__PURE__*/function () {
472
382
  return _context7.abrupt("return", new Promise(function (resolve) {
473
383
  if (_this3.getIsConfigurationStatus(AdapterConfigurationStatus.Configured)) resolve();else _classPrivateFieldLooseBase(_this3, _adapterState)[_adapterState].emitter.on(_classPrivateFieldLooseBase(_this3, _internalConfiguredStatusChange__)[_internalConfiguredStatusChange__], resolve);
474
384
  }));
475
-
476
385
  case 1:
477
386
  case "end":
478
387
  return _context7.stop();
@@ -480,11 +389,9 @@ var HttpAdapter = /*#__PURE__*/function () {
480
389
  }
481
390
  }, _callee7);
482
391
  }));
483
-
484
392
  function waitUntilConfigured() {
485
393
  return _waitUntilConfigured.apply(this, arguments);
486
394
  }
487
-
488
395
  return waitUntilConfigured;
489
396
  }()
490
397
  }, {
@@ -496,26 +403,22 @@ var HttpAdapter = /*#__PURE__*/function () {
496
403
  key: "getFlag",
497
404
  value: function getFlag(flagName) {
498
405
  var _classPrivateFieldLoo;
499
-
500
406
  return (_classPrivateFieldLoo = _classPrivateFieldLooseBase(this, _adapterState)[_adapterState]) === null || _classPrivateFieldLoo === void 0 ? void 0 : _classPrivateFieldLoo.flags[flagName];
501
407
  }
502
408
  }, {
503
409
  key: "setConfigurationStatus",
504
410
  value: function setConfigurationStatus(nextConfigurationStatus) {
505
411
  _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].configurationStatus = nextConfigurationStatus;
506
-
507
412
  _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].emitter.emit('statusStateChange', {
508
413
  configurationStatus: _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].configurationStatus
509
414
  });
510
415
  }
511
416
  }]);
512
-
513
417
  return HttpAdapter;
514
418
  }();
515
-
516
419
  var adapter = new HttpAdapter();
517
420
  exposeGlobally(adapter);
518
421
 
519
- var version = "0.0.25";
422
+ var version = "0.0.27";
520
423
 
521
424
  export { adapter as default, version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flopflip/http-adapter",
3
- "version": "0.0.25",
3
+ "version": "0.0.27",
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.18.9",
33
- "@flopflip/adapter-utilities": "1.0.31",
34
- "@flopflip/localstorage-cache": "1.0.30",
35
- "@flopflip/sessionstorage-cache": "1.0.30",
36
- "@flopflip/types": "4.1.26",
32
+ "@babel/runtime": "7.19.4",
33
+ "@flopflip/adapter-utilities": "1.0.33",
34
+ "@flopflip/localstorage-cache": "1.0.32",
35
+ "@flopflip/sessionstorage-cache": "1.0.32",
36
+ "@flopflip/types": "4.1.28",
37
37
  "lodash": "4.17.21",
38
38
  "mitt": "3.0.0",
39
39
  "tiny-warning": "1.0.3"