@flopflip/launchdarkly-adapter 13.2.1 → 13.2.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.
|
@@ -17,17 +17,37 @@ var tsDeepmerge = require('ts-deepmerge');
|
|
|
17
17
|
|
|
18
18
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
19
19
|
|
|
20
|
+
function _interopNamespace(e) {
|
|
21
|
+
if (e && e.__esModule) return e;
|
|
22
|
+
var n = Object.create(null);
|
|
23
|
+
if (e) {
|
|
24
|
+
Object.keys(e).forEach(function (k) {
|
|
25
|
+
if (k !== 'default') {
|
|
26
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
27
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
get: function () { return e[k]; }
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
n["default"] = e;
|
|
35
|
+
return Object.freeze(n);
|
|
36
|
+
}
|
|
37
|
+
|
|
20
38
|
var debounce__default = /*#__PURE__*/_interopDefault(debounce);
|
|
21
39
|
var isEqual__default = /*#__PURE__*/_interopDefault(isEqual);
|
|
22
40
|
var mitt__default = /*#__PURE__*/_interopDefault(mitt);
|
|
23
41
|
var warning__default = /*#__PURE__*/_interopDefault(warning);
|
|
24
42
|
|
|
43
|
+
const STORAGE_SLICE = '@flopflip';
|
|
25
44
|
var _adapterState = /*#__PURE__*/_classPrivateFieldLooseKey("adapterState");
|
|
26
45
|
var _updateFlagsInAdapterState = /*#__PURE__*/_classPrivateFieldLooseKey("updateFlagsInAdapterState");
|
|
27
46
|
var _getIsAdapterUnsubscribed = /*#__PURE__*/_classPrivateFieldLooseKey("getIsAdapterUnsubscribed");
|
|
28
47
|
var _getIsFlagUnsubcribed = /*#__PURE__*/_classPrivateFieldLooseKey("getIsFlagUnsubcribed");
|
|
29
48
|
var _getIsFlagLocked = /*#__PURE__*/_classPrivateFieldLooseKey("getIsFlagLocked");
|
|
30
49
|
var _withoutUnsubscribedOrLockedFlags = /*#__PURE__*/_classPrivateFieldLooseKey("withoutUnsubscribedOrLockedFlags");
|
|
50
|
+
var _getCache = /*#__PURE__*/_classPrivateFieldLooseKey("getCache");
|
|
31
51
|
var _getIsAnonymousContext = /*#__PURE__*/_classPrivateFieldLooseKey("getIsAnonymousContext");
|
|
32
52
|
var _ensureContext = /*#__PURE__*/_classPrivateFieldLooseKey("ensureContext");
|
|
33
53
|
var _initializeClient = /*#__PURE__*/_classPrivateFieldLooseKey("initializeClient");
|
|
@@ -84,6 +104,42 @@ class LaunchDarklyAdapter {
|
|
|
84
104
|
return !_classPrivateFieldLooseBase(this, _getIsFlagUnsubcribed)[_getIsFlagUnsubcribed](flagName) && !_classPrivateFieldLooseBase(this, _getIsFlagLocked)[_getIsFlagLocked](flagName);
|
|
85
105
|
}))
|
|
86
106
|
});
|
|
107
|
+
Object.defineProperty(this, _getCache, {
|
|
108
|
+
writable: true,
|
|
109
|
+
value: async (cacheIdentifier, cacheKey) => {
|
|
110
|
+
let cacheModule;
|
|
111
|
+
|
|
112
|
+
// eslint-disable-next-line default-case, @typescript-eslint/switch-exhaustiveness-check
|
|
113
|
+
switch (cacheIdentifier) {
|
|
114
|
+
case types.cacheIdentifiers.local:
|
|
115
|
+
{
|
|
116
|
+
cacheModule = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@flopflip/localstorage-cache')); });
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
case types.cacheIdentifiers.session:
|
|
120
|
+
{
|
|
121
|
+
cacheModule = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@flopflip/sessionstorage-cache')); });
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
const createCache = cacheModule.default;
|
|
126
|
+
const cachePrefix = [STORAGE_SLICE, cacheKey].filter(Boolean).join('/');
|
|
127
|
+
const cache = createCache({
|
|
128
|
+
prefix: cachePrefix
|
|
129
|
+
});
|
|
130
|
+
return {
|
|
131
|
+
set(flags) {
|
|
132
|
+
return cache.set('flags', flags);
|
|
133
|
+
},
|
|
134
|
+
get() {
|
|
135
|
+
return cache.get('flags');
|
|
136
|
+
},
|
|
137
|
+
unset() {
|
|
138
|
+
return cache.unset('flags');
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
});
|
|
87
143
|
Object.defineProperty(this, _getIsAnonymousContext, {
|
|
88
144
|
writable: true,
|
|
89
145
|
value: context => !(context !== null && context !== void 0 && context.key)
|
|
@@ -261,18 +317,32 @@ class LaunchDarklyAdapter {
|
|
|
261
317
|
_adapterArgs$throwOnI = adapterArgs.throwOnInitializationFailure,
|
|
262
318
|
throwOnInitializationFailure = _adapterArgs$throwOnI === void 0 ? false : _adapterArgs$throwOnI,
|
|
263
319
|
flagsUpdateDelayMs = adapterArgs.flagsUpdateDelayMs;
|
|
320
|
+
let cachedFlags;
|
|
264
321
|
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].context = _classPrivateFieldLooseBase(this, _ensureContext)[_ensureContext](context);
|
|
322
|
+
if (adapterArgs.cacheIdentifier) {
|
|
323
|
+
const cache = await _classPrivateFieldLooseBase(this, _getCache)[_getCache](adapterArgs.cacheIdentifier, context.key);
|
|
324
|
+
cachedFlags = cache.get();
|
|
325
|
+
if (cachedFlags) {
|
|
326
|
+
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].flags = cachedFlags;
|
|
327
|
+
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].emitter.emit('flagsStateChange', cachedFlags);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
265
330
|
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].client = _classPrivateFieldLooseBase(this, _initializeClient)[_initializeClient](sdk.clientSideId, _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].context, (_sdk$clientOptions = sdk.clientOptions) !== null && _sdk$clientOptions !== void 0 ? _sdk$clientOptions : {});
|
|
266
331
|
return _classPrivateFieldLooseBase(this, _getInitialFlags)[_getInitialFlags]({
|
|
267
332
|
flags,
|
|
268
333
|
throwOnInitializationFailure
|
|
269
|
-
}).then(_ref9 => {
|
|
334
|
+
}).then(async _ref9 => {
|
|
270
335
|
let flagsFromSdk = _ref9.flagsFromSdk,
|
|
271
336
|
initializationStatus = _ref9.initializationStatus;
|
|
272
337
|
if (subscribeToFlagChanges && flagsFromSdk) _classPrivateFieldLooseBase(this, _setupFlagSubcription)[_setupFlagSubcription]({
|
|
273
338
|
flagsFromSdk,
|
|
274
339
|
flagsUpdateDelayMs
|
|
275
340
|
});
|
|
341
|
+
if (adapterArgs.cacheIdentifier) {
|
|
342
|
+
var _classPrivateFieldLoo2;
|
|
343
|
+
const cache = await _classPrivateFieldLooseBase(this, _getCache)[_getCache](adapterArgs.cacheIdentifier, (_classPrivateFieldLoo2 = _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].context) === null || _classPrivateFieldLoo2 === void 0 ? void 0 : _classPrivateFieldLoo2.key);
|
|
344
|
+
cache.set(flagsFromSdk !== null && flagsFromSdk !== void 0 ? flagsFromSdk : {});
|
|
345
|
+
}
|
|
276
346
|
return {
|
|
277
347
|
initializationStatus
|
|
278
348
|
};
|
|
@@ -282,6 +352,11 @@ class LaunchDarklyAdapter {
|
|
|
282
352
|
if (!this.getIsConfigurationStatus(types.AdapterConfigurationStatus.Configured)) return Promise.reject(new Error('@flopflip/launchdarkly-adapter: please configure adapter before reconfiguring.'));
|
|
283
353
|
const nextContext = adapterArgs.context;
|
|
284
354
|
if (!isEqual__default["default"](_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].context, nextContext)) {
|
|
355
|
+
if (adapterArgs.cacheIdentifier) {
|
|
356
|
+
var _classPrivateFieldLoo3;
|
|
357
|
+
const cache = await _classPrivateFieldLooseBase(this, _getCache)[_getCache](adapterArgs.cacheIdentifier, (_classPrivateFieldLoo3 = _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].context) === null || _classPrivateFieldLoo3 === void 0 ? void 0 : _classPrivateFieldLoo3.key);
|
|
358
|
+
cache.unset();
|
|
359
|
+
}
|
|
285
360
|
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].context = _classPrivateFieldLooseBase(this, _ensureContext)[_ensureContext](nextContext);
|
|
286
361
|
await _classPrivateFieldLooseBase(this, _changeClientContext)[_changeClientContext](_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].context);
|
|
287
362
|
return Promise.resolve({
|
|
@@ -317,7 +392,7 @@ class LaunchDarklyAdapter {
|
|
|
317
392
|
const adapter = new LaunchDarklyAdapter();
|
|
318
393
|
adapterUtilities.exposeGlobally(adapter);
|
|
319
394
|
|
|
320
|
-
const version = "13.2.
|
|
395
|
+
const version = "13.2.2";
|
|
321
396
|
|
|
322
397
|
exports["default"] = adapter;
|
|
323
398
|
exports.version = version;
|
|
@@ -17,17 +17,37 @@ var tsDeepmerge = require('ts-deepmerge');
|
|
|
17
17
|
|
|
18
18
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
19
19
|
|
|
20
|
+
function _interopNamespace(e) {
|
|
21
|
+
if (e && e.__esModule) return e;
|
|
22
|
+
var n = Object.create(null);
|
|
23
|
+
if (e) {
|
|
24
|
+
Object.keys(e).forEach(function (k) {
|
|
25
|
+
if (k !== 'default') {
|
|
26
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
27
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
get: function () { return e[k]; }
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
n["default"] = e;
|
|
35
|
+
return Object.freeze(n);
|
|
36
|
+
}
|
|
37
|
+
|
|
20
38
|
var debounce__default = /*#__PURE__*/_interopDefault(debounce);
|
|
21
39
|
var isEqual__default = /*#__PURE__*/_interopDefault(isEqual);
|
|
22
40
|
var mitt__default = /*#__PURE__*/_interopDefault(mitt);
|
|
23
41
|
var warning__default = /*#__PURE__*/_interopDefault(warning);
|
|
24
42
|
|
|
43
|
+
const STORAGE_SLICE = '@flopflip';
|
|
25
44
|
var _adapterState = /*#__PURE__*/_classPrivateFieldLooseKey("adapterState");
|
|
26
45
|
var _updateFlagsInAdapterState = /*#__PURE__*/_classPrivateFieldLooseKey("updateFlagsInAdapterState");
|
|
27
46
|
var _getIsAdapterUnsubscribed = /*#__PURE__*/_classPrivateFieldLooseKey("getIsAdapterUnsubscribed");
|
|
28
47
|
var _getIsFlagUnsubcribed = /*#__PURE__*/_classPrivateFieldLooseKey("getIsFlagUnsubcribed");
|
|
29
48
|
var _getIsFlagLocked = /*#__PURE__*/_classPrivateFieldLooseKey("getIsFlagLocked");
|
|
30
49
|
var _withoutUnsubscribedOrLockedFlags = /*#__PURE__*/_classPrivateFieldLooseKey("withoutUnsubscribedOrLockedFlags");
|
|
50
|
+
var _getCache = /*#__PURE__*/_classPrivateFieldLooseKey("getCache");
|
|
31
51
|
var _getIsAnonymousContext = /*#__PURE__*/_classPrivateFieldLooseKey("getIsAnonymousContext");
|
|
32
52
|
var _ensureContext = /*#__PURE__*/_classPrivateFieldLooseKey("ensureContext");
|
|
33
53
|
var _initializeClient = /*#__PURE__*/_classPrivateFieldLooseKey("initializeClient");
|
|
@@ -84,6 +104,42 @@ class LaunchDarklyAdapter {
|
|
|
84
104
|
return !_classPrivateFieldLooseBase(this, _getIsFlagUnsubcribed)[_getIsFlagUnsubcribed](flagName) && !_classPrivateFieldLooseBase(this, _getIsFlagLocked)[_getIsFlagLocked](flagName);
|
|
85
105
|
}))
|
|
86
106
|
});
|
|
107
|
+
Object.defineProperty(this, _getCache, {
|
|
108
|
+
writable: true,
|
|
109
|
+
value: async (cacheIdentifier, cacheKey) => {
|
|
110
|
+
let cacheModule;
|
|
111
|
+
|
|
112
|
+
// eslint-disable-next-line default-case, @typescript-eslint/switch-exhaustiveness-check
|
|
113
|
+
switch (cacheIdentifier) {
|
|
114
|
+
case types.cacheIdentifiers.local:
|
|
115
|
+
{
|
|
116
|
+
cacheModule = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@flopflip/localstorage-cache')); });
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
case types.cacheIdentifiers.session:
|
|
120
|
+
{
|
|
121
|
+
cacheModule = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@flopflip/sessionstorage-cache')); });
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
const createCache = cacheModule.default;
|
|
126
|
+
const cachePrefix = [STORAGE_SLICE, cacheKey].filter(Boolean).join('/');
|
|
127
|
+
const cache = createCache({
|
|
128
|
+
prefix: cachePrefix
|
|
129
|
+
});
|
|
130
|
+
return {
|
|
131
|
+
set(flags) {
|
|
132
|
+
return cache.set('flags', flags);
|
|
133
|
+
},
|
|
134
|
+
get() {
|
|
135
|
+
return cache.get('flags');
|
|
136
|
+
},
|
|
137
|
+
unset() {
|
|
138
|
+
return cache.unset('flags');
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
});
|
|
87
143
|
Object.defineProperty(this, _getIsAnonymousContext, {
|
|
88
144
|
writable: true,
|
|
89
145
|
value: context => !(context !== null && context !== void 0 && context.key)
|
|
@@ -261,18 +317,32 @@ class LaunchDarklyAdapter {
|
|
|
261
317
|
_adapterArgs$throwOnI = adapterArgs.throwOnInitializationFailure,
|
|
262
318
|
throwOnInitializationFailure = _adapterArgs$throwOnI === void 0 ? false : _adapterArgs$throwOnI,
|
|
263
319
|
flagsUpdateDelayMs = adapterArgs.flagsUpdateDelayMs;
|
|
320
|
+
let cachedFlags;
|
|
264
321
|
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].context = _classPrivateFieldLooseBase(this, _ensureContext)[_ensureContext](context);
|
|
322
|
+
if (adapterArgs.cacheIdentifier) {
|
|
323
|
+
const cache = await _classPrivateFieldLooseBase(this, _getCache)[_getCache](adapterArgs.cacheIdentifier, context.key);
|
|
324
|
+
cachedFlags = cache.get();
|
|
325
|
+
if (cachedFlags) {
|
|
326
|
+
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].flags = cachedFlags;
|
|
327
|
+
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].emitter.emit('flagsStateChange', cachedFlags);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
265
330
|
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].client = _classPrivateFieldLooseBase(this, _initializeClient)[_initializeClient](sdk.clientSideId, _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].context, (_sdk$clientOptions = sdk.clientOptions) !== null && _sdk$clientOptions !== void 0 ? _sdk$clientOptions : {});
|
|
266
331
|
return _classPrivateFieldLooseBase(this, _getInitialFlags)[_getInitialFlags]({
|
|
267
332
|
flags,
|
|
268
333
|
throwOnInitializationFailure
|
|
269
|
-
}).then(_ref9 => {
|
|
334
|
+
}).then(async _ref9 => {
|
|
270
335
|
let flagsFromSdk = _ref9.flagsFromSdk,
|
|
271
336
|
initializationStatus = _ref9.initializationStatus;
|
|
272
337
|
if (subscribeToFlagChanges && flagsFromSdk) _classPrivateFieldLooseBase(this, _setupFlagSubcription)[_setupFlagSubcription]({
|
|
273
338
|
flagsFromSdk,
|
|
274
339
|
flagsUpdateDelayMs
|
|
275
340
|
});
|
|
341
|
+
if (adapterArgs.cacheIdentifier) {
|
|
342
|
+
var _classPrivateFieldLoo2;
|
|
343
|
+
const cache = await _classPrivateFieldLooseBase(this, _getCache)[_getCache](adapterArgs.cacheIdentifier, (_classPrivateFieldLoo2 = _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].context) === null || _classPrivateFieldLoo2 === void 0 ? void 0 : _classPrivateFieldLoo2.key);
|
|
344
|
+
cache.set(flagsFromSdk !== null && flagsFromSdk !== void 0 ? flagsFromSdk : {});
|
|
345
|
+
}
|
|
276
346
|
return {
|
|
277
347
|
initializationStatus
|
|
278
348
|
};
|
|
@@ -282,6 +352,11 @@ class LaunchDarklyAdapter {
|
|
|
282
352
|
if (!this.getIsConfigurationStatus(types.AdapterConfigurationStatus.Configured)) return Promise.reject(new Error('@flopflip/launchdarkly-adapter: please configure adapter before reconfiguring.'));
|
|
283
353
|
const nextContext = adapterArgs.context;
|
|
284
354
|
if (!isEqual__default["default"](_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].context, nextContext)) {
|
|
355
|
+
if (adapterArgs.cacheIdentifier) {
|
|
356
|
+
var _classPrivateFieldLoo3;
|
|
357
|
+
const cache = await _classPrivateFieldLooseBase(this, _getCache)[_getCache](adapterArgs.cacheIdentifier, (_classPrivateFieldLoo3 = _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].context) === null || _classPrivateFieldLoo3 === void 0 ? void 0 : _classPrivateFieldLoo3.key);
|
|
358
|
+
cache.unset();
|
|
359
|
+
}
|
|
285
360
|
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].context = _classPrivateFieldLooseBase(this, _ensureContext)[_ensureContext](nextContext);
|
|
286
361
|
await _classPrivateFieldLooseBase(this, _changeClientContext)[_changeClientContext](_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].context);
|
|
287
362
|
return Promise.resolve({
|
|
@@ -317,7 +392,7 @@ class LaunchDarklyAdapter {
|
|
|
317
392
|
const adapter = new LaunchDarklyAdapter();
|
|
318
393
|
adapterUtilities.exposeGlobally(adapter);
|
|
319
394
|
|
|
320
|
-
const version = "13.2.
|
|
395
|
+
const version = "13.2.2";
|
|
321
396
|
|
|
322
397
|
exports["default"] = adapter;
|
|
323
398
|
exports.version = version;
|
|
@@ -3,7 +3,7 @@ import _slicedToArray from '@babel/runtime/helpers/esm/slicedToArray';
|
|
|
3
3
|
import _classPrivateFieldLooseBase from '@babel/runtime/helpers/esm/classPrivateFieldLooseBase';
|
|
4
4
|
import _classPrivateFieldLooseKey from '@babel/runtime/helpers/esm/classPrivateFieldLooseKey';
|
|
5
5
|
import { exposeGlobally, denormalizeFlagName, normalizeFlags, normalizeFlag } from '@flopflip/adapter-utilities';
|
|
6
|
-
import { AdapterSubscriptionStatus, AdapterConfigurationStatus, AdapterInitializationStatus, adapterIdentifiers } from '@flopflip/types';
|
|
6
|
+
import { AdapterSubscriptionStatus, cacheIdentifiers, AdapterConfigurationStatus, AdapterInitializationStatus, adapterIdentifiers } from '@flopflip/types';
|
|
7
7
|
import debounce from 'debounce-fn';
|
|
8
8
|
import { initialize } from 'launchdarkly-js-client-sdk';
|
|
9
9
|
import isEqual from 'lodash/isEqual';
|
|
@@ -11,12 +11,14 @@ import mitt from 'mitt';
|
|
|
11
11
|
import warning from 'tiny-warning';
|
|
12
12
|
import { merge } from 'ts-deepmerge';
|
|
13
13
|
|
|
14
|
+
const STORAGE_SLICE = '@flopflip';
|
|
14
15
|
var _adapterState = /*#__PURE__*/_classPrivateFieldLooseKey("adapterState");
|
|
15
16
|
var _updateFlagsInAdapterState = /*#__PURE__*/_classPrivateFieldLooseKey("updateFlagsInAdapterState");
|
|
16
17
|
var _getIsAdapterUnsubscribed = /*#__PURE__*/_classPrivateFieldLooseKey("getIsAdapterUnsubscribed");
|
|
17
18
|
var _getIsFlagUnsubcribed = /*#__PURE__*/_classPrivateFieldLooseKey("getIsFlagUnsubcribed");
|
|
18
19
|
var _getIsFlagLocked = /*#__PURE__*/_classPrivateFieldLooseKey("getIsFlagLocked");
|
|
19
20
|
var _withoutUnsubscribedOrLockedFlags = /*#__PURE__*/_classPrivateFieldLooseKey("withoutUnsubscribedOrLockedFlags");
|
|
21
|
+
var _getCache = /*#__PURE__*/_classPrivateFieldLooseKey("getCache");
|
|
20
22
|
var _getIsAnonymousContext = /*#__PURE__*/_classPrivateFieldLooseKey("getIsAnonymousContext");
|
|
21
23
|
var _ensureContext = /*#__PURE__*/_classPrivateFieldLooseKey("ensureContext");
|
|
22
24
|
var _initializeClient = /*#__PURE__*/_classPrivateFieldLooseKey("initializeClient");
|
|
@@ -73,6 +75,42 @@ class LaunchDarklyAdapter {
|
|
|
73
75
|
return !_classPrivateFieldLooseBase(this, _getIsFlagUnsubcribed)[_getIsFlagUnsubcribed](flagName) && !_classPrivateFieldLooseBase(this, _getIsFlagLocked)[_getIsFlagLocked](flagName);
|
|
74
76
|
}))
|
|
75
77
|
});
|
|
78
|
+
Object.defineProperty(this, _getCache, {
|
|
79
|
+
writable: true,
|
|
80
|
+
value: async (cacheIdentifier, cacheKey) => {
|
|
81
|
+
let cacheModule;
|
|
82
|
+
|
|
83
|
+
// eslint-disable-next-line default-case, @typescript-eslint/switch-exhaustiveness-check
|
|
84
|
+
switch (cacheIdentifier) {
|
|
85
|
+
case cacheIdentifiers.local:
|
|
86
|
+
{
|
|
87
|
+
cacheModule = await import('@flopflip/localstorage-cache');
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
case cacheIdentifiers.session:
|
|
91
|
+
{
|
|
92
|
+
cacheModule = await import('@flopflip/sessionstorage-cache');
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const createCache = cacheModule.default;
|
|
97
|
+
const cachePrefix = [STORAGE_SLICE, cacheKey].filter(Boolean).join('/');
|
|
98
|
+
const cache = createCache({
|
|
99
|
+
prefix: cachePrefix
|
|
100
|
+
});
|
|
101
|
+
return {
|
|
102
|
+
set(flags) {
|
|
103
|
+
return cache.set('flags', flags);
|
|
104
|
+
},
|
|
105
|
+
get() {
|
|
106
|
+
return cache.get('flags');
|
|
107
|
+
},
|
|
108
|
+
unset() {
|
|
109
|
+
return cache.unset('flags');
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
});
|
|
76
114
|
Object.defineProperty(this, _getIsAnonymousContext, {
|
|
77
115
|
writable: true,
|
|
78
116
|
value: context => !(context !== null && context !== void 0 && context.key)
|
|
@@ -250,18 +288,32 @@ class LaunchDarklyAdapter {
|
|
|
250
288
|
_adapterArgs$throwOnI = adapterArgs.throwOnInitializationFailure,
|
|
251
289
|
throwOnInitializationFailure = _adapterArgs$throwOnI === void 0 ? false : _adapterArgs$throwOnI,
|
|
252
290
|
flagsUpdateDelayMs = adapterArgs.flagsUpdateDelayMs;
|
|
291
|
+
let cachedFlags;
|
|
253
292
|
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].context = _classPrivateFieldLooseBase(this, _ensureContext)[_ensureContext](context);
|
|
293
|
+
if (adapterArgs.cacheIdentifier) {
|
|
294
|
+
const cache = await _classPrivateFieldLooseBase(this, _getCache)[_getCache](adapterArgs.cacheIdentifier, context.key);
|
|
295
|
+
cachedFlags = cache.get();
|
|
296
|
+
if (cachedFlags) {
|
|
297
|
+
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].flags = cachedFlags;
|
|
298
|
+
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].emitter.emit('flagsStateChange', cachedFlags);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
254
301
|
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].client = _classPrivateFieldLooseBase(this, _initializeClient)[_initializeClient](sdk.clientSideId, _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].context, (_sdk$clientOptions = sdk.clientOptions) !== null && _sdk$clientOptions !== void 0 ? _sdk$clientOptions : {});
|
|
255
302
|
return _classPrivateFieldLooseBase(this, _getInitialFlags)[_getInitialFlags]({
|
|
256
303
|
flags,
|
|
257
304
|
throwOnInitializationFailure
|
|
258
|
-
}).then(_ref9 => {
|
|
305
|
+
}).then(async _ref9 => {
|
|
259
306
|
let flagsFromSdk = _ref9.flagsFromSdk,
|
|
260
307
|
initializationStatus = _ref9.initializationStatus;
|
|
261
308
|
if (subscribeToFlagChanges && flagsFromSdk) _classPrivateFieldLooseBase(this, _setupFlagSubcription)[_setupFlagSubcription]({
|
|
262
309
|
flagsFromSdk,
|
|
263
310
|
flagsUpdateDelayMs
|
|
264
311
|
});
|
|
312
|
+
if (adapterArgs.cacheIdentifier) {
|
|
313
|
+
var _classPrivateFieldLoo2;
|
|
314
|
+
const cache = await _classPrivateFieldLooseBase(this, _getCache)[_getCache](adapterArgs.cacheIdentifier, (_classPrivateFieldLoo2 = _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].context) === null || _classPrivateFieldLoo2 === void 0 ? void 0 : _classPrivateFieldLoo2.key);
|
|
315
|
+
cache.set(flagsFromSdk !== null && flagsFromSdk !== void 0 ? flagsFromSdk : {});
|
|
316
|
+
}
|
|
265
317
|
return {
|
|
266
318
|
initializationStatus
|
|
267
319
|
};
|
|
@@ -271,6 +323,11 @@ class LaunchDarklyAdapter {
|
|
|
271
323
|
if (!this.getIsConfigurationStatus(AdapterConfigurationStatus.Configured)) return Promise.reject(new Error('@flopflip/launchdarkly-adapter: please configure adapter before reconfiguring.'));
|
|
272
324
|
const nextContext = adapterArgs.context;
|
|
273
325
|
if (!isEqual(_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].context, nextContext)) {
|
|
326
|
+
if (adapterArgs.cacheIdentifier) {
|
|
327
|
+
var _classPrivateFieldLoo3;
|
|
328
|
+
const cache = await _classPrivateFieldLooseBase(this, _getCache)[_getCache](adapterArgs.cacheIdentifier, (_classPrivateFieldLoo3 = _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].context) === null || _classPrivateFieldLoo3 === void 0 ? void 0 : _classPrivateFieldLoo3.key);
|
|
329
|
+
cache.unset();
|
|
330
|
+
}
|
|
274
331
|
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].context = _classPrivateFieldLooseBase(this, _ensureContext)[_ensureContext](nextContext);
|
|
275
332
|
await _classPrivateFieldLooseBase(this, _changeClientContext)[_changeClientContext](_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].context);
|
|
276
333
|
return Promise.resolve({
|
|
@@ -306,6 +363,6 @@ class LaunchDarklyAdapter {
|
|
|
306
363
|
const adapter = new LaunchDarklyAdapter();
|
|
307
364
|
exposeGlobally(adapter);
|
|
308
365
|
|
|
309
|
-
const version = "13.2.
|
|
366
|
+
const version = "13.2.2";
|
|
310
367
|
|
|
311
368
|
export { adapter as default, version };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flopflip/launchdarkly-adapter",
|
|
3
|
-
"version": "13.2.
|
|
3
|
+
"version": "13.2.2",
|
|
4
4
|
"description": "A adapter around the LaunchDarkly client for flipflop",
|
|
5
5
|
"main": "dist/flopflip-launchdarkly-adapter.cjs.js",
|
|
6
6
|
"module": "dist/flopflip-launchdarkly-adapter.esm.js",
|
|
@@ -26,9 +26,11 @@
|
|
|
26
26
|
"globalthis": "1.0.3"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@babel/runtime": "7.
|
|
30
|
-
"@flopflip/adapter-utilities": "13.2.
|
|
31
|
-
"@flopflip/
|
|
29
|
+
"@babel/runtime": "7.24.0",
|
|
30
|
+
"@flopflip/adapter-utilities": "13.2.2",
|
|
31
|
+
"@flopflip/localstorage-cache": "13.2.2",
|
|
32
|
+
"@flopflip/sessionstorage-cache": "13.2.2",
|
|
33
|
+
"@flopflip/types": "13.2.2",
|
|
32
34
|
"debounce-fn": "4.0.0",
|
|
33
35
|
"launchdarkly-js-client-sdk": "3.1.4",
|
|
34
36
|
"lodash": "4.17.21",
|