@flopflip/launchdarkly-adapter 12.5.6 → 13.0.0
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.
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/// <reference types="launchdarkly-js-sdk-common" />
|
|
2
|
-
import { AdapterConfigurationStatus, adapterIdentifiers, AdapterInitializationStatus, type TAdapterEventHandlers, type TFlagName, type TFlags, type TFlagVariation, type TLaunchDarklyAdapterArgs, type TLaunchDarklyAdapterInterface, type TUpdateFlagsOptions
|
|
3
|
-
import { type LDClient
|
|
4
|
-
type TLaunchDarklyUser = TUser<LDUser>;
|
|
2
|
+
import { AdapterConfigurationStatus, adapterIdentifiers, AdapterInitializationStatus, type TAdapterEventHandlers, type TFlagName, type TFlags, type TFlagVariation, type TLaunchDarklyAdapterArgs, type TLaunchDarklyAdapterInterface, type TUpdateFlagsOptions } from '@flopflip/types';
|
|
3
|
+
import { type LDClient } from 'launchdarkly-js-client-sdk';
|
|
5
4
|
declare class LaunchDarklyAdapter implements TLaunchDarklyAdapterInterface {
|
|
6
5
|
#private;
|
|
7
6
|
id: typeof adapterIdentifiers.launchdarkly;
|
|
@@ -17,7 +16,7 @@ declare class LaunchDarklyAdapter implements TLaunchDarklyAdapterInterface {
|
|
|
17
16
|
setConfigurationStatus(nextConfigurationStatus: AdapterConfigurationStatus): void;
|
|
18
17
|
getClient(): LDClient | undefined;
|
|
19
18
|
getFlag(flagName: TFlagName): TFlagVariation;
|
|
20
|
-
|
|
19
|
+
updateClientContext(updatedContextProps: TLaunchDarklyAdapterArgs['context']): Promise<import("launchdarkly-js-sdk-common").LDFlagSet>;
|
|
21
20
|
unsubscribe: () => void;
|
|
22
21
|
subscribe: () => void;
|
|
23
22
|
}
|
|
@@ -35,10 +35,10 @@ var _getIsAdapterUnsubscribed = /*#__PURE__*/_classPrivateFieldLooseKey("getIsAd
|
|
|
35
35
|
var _getIsFlagUnsubcribed = /*#__PURE__*/_classPrivateFieldLooseKey("getIsFlagUnsubcribed");
|
|
36
36
|
var _getIsFlagLocked = /*#__PURE__*/_classPrivateFieldLooseKey("getIsFlagLocked");
|
|
37
37
|
var _withoutUnsubscribedOrLockedFlags = /*#__PURE__*/_classPrivateFieldLooseKey("withoutUnsubscribedOrLockedFlags");
|
|
38
|
-
var
|
|
39
|
-
var
|
|
38
|
+
var _getIsAnonymousContext = /*#__PURE__*/_classPrivateFieldLooseKey("getIsAnonymousContext");
|
|
39
|
+
var _ensureContext = /*#__PURE__*/_classPrivateFieldLooseKey("ensureContext");
|
|
40
40
|
var _initializeClient = /*#__PURE__*/_classPrivateFieldLooseKey("initializeClient");
|
|
41
|
-
var
|
|
41
|
+
var _changeClientContext = /*#__PURE__*/_classPrivateFieldLooseKey("changeClientContext");
|
|
42
42
|
var _getInitialFlags = /*#__PURE__*/_classPrivateFieldLooseKey("getInitialFlags");
|
|
43
43
|
var _didFlagChange = /*#__PURE__*/_classPrivateFieldLooseKey("didFlagChange");
|
|
44
44
|
var _setupFlagSubcription = /*#__PURE__*/_classPrivateFieldLooseKey("setupFlagSubcription");
|
|
@@ -99,39 +99,39 @@ var LaunchDarklyAdapter = /*#__PURE__*/function () {
|
|
|
99
99
|
}));
|
|
100
100
|
}
|
|
101
101
|
});
|
|
102
|
-
Object.defineProperty(this,
|
|
102
|
+
Object.defineProperty(this, _getIsAnonymousContext, {
|
|
103
103
|
writable: true,
|
|
104
|
-
value: function value(
|
|
105
|
-
return !(
|
|
104
|
+
value: function value(context) {
|
|
105
|
+
return !(context !== null && context !== void 0 && context.key);
|
|
106
106
|
}
|
|
107
107
|
});
|
|
108
|
-
Object.defineProperty(this,
|
|
108
|
+
Object.defineProperty(this, _ensureContext, {
|
|
109
109
|
writable: true,
|
|
110
|
-
value: function value(
|
|
111
|
-
var
|
|
110
|
+
value: function value(context) {
|
|
111
|
+
var isAnonymousContext = _classPrivateFieldLooseBase(_this, _getIsAnonymousContext)[_getIsAnonymousContext](context);
|
|
112
112
|
|
|
113
113
|
// NOTE: When marked `anonymous` the SDK will generate a unique key and cache it in local storage
|
|
114
|
-
return merge__default["default"](
|
|
115
|
-
key:
|
|
116
|
-
anonymous:
|
|
114
|
+
return merge__default["default"](context, {
|
|
115
|
+
key: isAnonymousContext ? undefined : context.key,
|
|
116
|
+
anonymous: isAnonymousContext
|
|
117
117
|
});
|
|
118
118
|
}
|
|
119
119
|
});
|
|
120
120
|
Object.defineProperty(this, _initializeClient, {
|
|
121
121
|
writable: true,
|
|
122
|
-
value: function value(clientSideId,
|
|
123
|
-
return launchdarklyJsClientSdk.initialize(clientSideId,
|
|
122
|
+
value: function value(clientSideId, context, options) {
|
|
123
|
+
return launchdarklyJsClientSdk.initialize(clientSideId, context, options);
|
|
124
124
|
}
|
|
125
125
|
});
|
|
126
|
-
Object.defineProperty(this,
|
|
126
|
+
Object.defineProperty(this, _changeClientContext, {
|
|
127
127
|
writable: true,
|
|
128
128
|
value: function () {
|
|
129
|
-
var _value = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee(
|
|
129
|
+
var _value = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee(nextContext) {
|
|
130
130
|
var _classPrivateFieldLoo;
|
|
131
131
|
return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
|
|
132
132
|
while (1) switch (_context.prev = _context.next) {
|
|
133
133
|
case 0:
|
|
134
|
-
return _context.abrupt("return", (_classPrivateFieldLoo = _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState].client) !== null && _classPrivateFieldLoo !== void 0 && _classPrivateFieldLoo.identify ? _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState].client.identify(
|
|
134
|
+
return _context.abrupt("return", (_classPrivateFieldLoo = _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState].client) !== null && _classPrivateFieldLoo !== void 0 && _classPrivateFieldLoo.identify ? _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState].client.identify(nextContext) : Promise.reject(new Error('Can not change user context: client not yet initialized.')));
|
|
135
135
|
case 1:
|
|
136
136
|
case "end":
|
|
137
137
|
return _context.stop();
|
|
@@ -277,6 +277,7 @@ var LaunchDarklyAdapter = /*#__PURE__*/function () {
|
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
279
|
});
|
|
280
|
+
// External. Flags are autolocked when updated.
|
|
280
281
|
this.updateFlags = function (flags, options) {
|
|
281
282
|
_classPrivateFieldLooseBase(_this, _updateFlagsInAdapterState)[_updateFlagsInAdapterState](flags, options);
|
|
282
283
|
|
|
@@ -292,7 +293,7 @@ var LaunchDarklyAdapter = /*#__PURE__*/function () {
|
|
|
292
293
|
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState] = {
|
|
293
294
|
subscriptionStatus: types.AdapterSubscriptionStatus.Subscribed,
|
|
294
295
|
configurationStatus: types.AdapterConfigurationStatus.Unconfigured,
|
|
295
|
-
|
|
296
|
+
context: undefined,
|
|
296
297
|
client: undefined,
|
|
297
298
|
flags: {},
|
|
298
299
|
// Typings are incorrect and state that mitt is not callable.
|
|
@@ -309,7 +310,7 @@ var LaunchDarklyAdapter = /*#__PURE__*/function () {
|
|
|
309
310
|
var _configure = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee5(adapterArgs, adapterEventHandlers) {
|
|
310
311
|
var _this2 = this,
|
|
311
312
|
_sdk$clientOptions;
|
|
312
|
-
var handleFlagsChange, handleStatusChange, sdk,
|
|
313
|
+
var handleFlagsChange, handleStatusChange, sdk, context, flags, _adapterArgs$subscrib, subscribeToFlagChanges, _adapterArgs$throwOnI, throwOnInitializationFailure, flagsUpdateDelayMs;
|
|
313
314
|
return _regeneratorRuntime__default["default"].wrap(function _callee5$(_context5) {
|
|
314
315
|
while (1) switch (_context5.prev = _context5.next) {
|
|
315
316
|
case 0:
|
|
@@ -333,9 +334,9 @@ var LaunchDarklyAdapter = /*#__PURE__*/function () {
|
|
|
333
334
|
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].emitter.emit('statusStateChange', {
|
|
334
335
|
configurationStatus: _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].configurationStatus
|
|
335
336
|
});
|
|
336
|
-
sdk = adapterArgs.sdk,
|
|
337
|
-
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].
|
|
338
|
-
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].client = _classPrivateFieldLooseBase(this, _initializeClient)[_initializeClient](sdk.clientSideId, _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].
|
|
337
|
+
sdk = adapterArgs.sdk, context = adapterArgs.context, flags = adapterArgs.flags, _adapterArgs$subscrib = adapterArgs.subscribeToFlagChanges, subscribeToFlagChanges = _adapterArgs$subscrib === void 0 ? true : _adapterArgs$subscrib, _adapterArgs$throwOnI = adapterArgs.throwOnInitializationFailure, throwOnInitializationFailure = _adapterArgs$throwOnI === void 0 ? false : _adapterArgs$throwOnI, flagsUpdateDelayMs = adapterArgs.flagsUpdateDelayMs;
|
|
338
|
+
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].context = _classPrivateFieldLooseBase(this, _ensureContext)[_ensureContext](context);
|
|
339
|
+
_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 : {});
|
|
339
340
|
return _context5.abrupt("return", _classPrivateFieldLooseBase(this, _getInitialFlags)[_getInitialFlags]({
|
|
340
341
|
flags: flags,
|
|
341
342
|
throwOnInitializationFailure: throwOnInitializationFailure
|
|
@@ -365,7 +366,7 @@ var LaunchDarklyAdapter = /*#__PURE__*/function () {
|
|
|
365
366
|
key: "reconfigure",
|
|
366
367
|
value: function () {
|
|
367
368
|
var _reconfigure = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee6(adapterArgs, _adapterEventHandlers) {
|
|
368
|
-
var
|
|
369
|
+
var nextContext;
|
|
369
370
|
return _regeneratorRuntime__default["default"].wrap(function _callee6$(_context6) {
|
|
370
371
|
while (1) switch (_context6.prev = _context6.next) {
|
|
371
372
|
case 0:
|
|
@@ -375,14 +376,14 @@ var LaunchDarklyAdapter = /*#__PURE__*/function () {
|
|
|
375
376
|
}
|
|
376
377
|
return _context6.abrupt("return", Promise.reject(new Error('@flopflip/launchdarkly-adapter: please configure adapter before reconfiguring.')));
|
|
377
378
|
case 2:
|
|
378
|
-
|
|
379
|
-
if (isEqual__default["default"](_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].
|
|
379
|
+
nextContext = adapterArgs.context;
|
|
380
|
+
if (isEqual__default["default"](_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].context, nextContext)) {
|
|
380
381
|
_context6.next = 8;
|
|
381
382
|
break;
|
|
382
383
|
}
|
|
383
|
-
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].
|
|
384
|
+
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].context = _classPrivateFieldLooseBase(this, _ensureContext)[_ensureContext](nextContext);
|
|
384
385
|
_context6.next = 7;
|
|
385
|
-
return _classPrivateFieldLooseBase(this,
|
|
386
|
+
return _classPrivateFieldLooseBase(this, _changeClientContext)[_changeClientContext](_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].context);
|
|
386
387
|
case 7:
|
|
387
388
|
return _context6.abrupt("return", Promise.resolve({
|
|
388
389
|
initializationStatus: types.AdapterInitializationStatus.Succeeded
|
|
@@ -426,32 +427,32 @@ var LaunchDarklyAdapter = /*#__PURE__*/function () {
|
|
|
426
427
|
return _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].flags[flagName];
|
|
427
428
|
}
|
|
428
429
|
}, {
|
|
429
|
-
key: "
|
|
430
|
+
key: "updateClientContext",
|
|
430
431
|
value: function () {
|
|
431
|
-
var
|
|
432
|
+
var _updateClientContext = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee7(updatedContextProps) {
|
|
432
433
|
var isAdapterConfigured;
|
|
433
434
|
return _regeneratorRuntime__default["default"].wrap(function _callee7$(_context7) {
|
|
434
435
|
while (1) switch (_context7.prev = _context7.next) {
|
|
435
436
|
case 0:
|
|
436
437
|
isAdapterConfigured = this.getIsConfigurationStatus(types.AdapterConfigurationStatus.Configured);
|
|
437
|
-
warning__default["default"](isAdapterConfigured, '@flopflip/launchdarkly-adapter: adapter not configured.
|
|
438
|
+
warning__default["default"](isAdapterConfigured, '@flopflip/launchdarkly-adapter: adapter not configured. Client context can not be updated before.');
|
|
438
439
|
if (isAdapterConfigured) {
|
|
439
440
|
_context7.next = 4;
|
|
440
441
|
break;
|
|
441
442
|
}
|
|
442
|
-
return _context7.abrupt("return", Promise.reject(new Error('Can not update
|
|
443
|
+
return _context7.abrupt("return", Promise.reject(new Error('Can not update client context: adapter not yet configured.')));
|
|
443
444
|
case 4:
|
|
444
|
-
return _context7.abrupt("return", _classPrivateFieldLooseBase(this,
|
|
445
|
+
return _context7.abrupt("return", _classPrivateFieldLooseBase(this, _changeClientContext)[_changeClientContext](_objectSpread(_objectSpread({}, _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].context), updatedContextProps)));
|
|
445
446
|
case 5:
|
|
446
447
|
case "end":
|
|
447
448
|
return _context7.stop();
|
|
448
449
|
}
|
|
449
450
|
}, _callee7, this);
|
|
450
451
|
}));
|
|
451
|
-
function
|
|
452
|
-
return
|
|
452
|
+
function updateClientContext(_x7) {
|
|
453
|
+
return _updateClientContext.apply(this, arguments);
|
|
453
454
|
}
|
|
454
|
-
return
|
|
455
|
+
return updateClientContext;
|
|
455
456
|
}()
|
|
456
457
|
}]);
|
|
457
458
|
return LaunchDarklyAdapter;
|
|
@@ -459,7 +460,7 @@ var LaunchDarklyAdapter = /*#__PURE__*/function () {
|
|
|
459
460
|
var adapter = new LaunchDarklyAdapter();
|
|
460
461
|
adapterUtilities.exposeGlobally(adapter);
|
|
461
462
|
|
|
462
|
-
var version = "
|
|
463
|
+
var version = "13.0.0";
|
|
463
464
|
|
|
464
465
|
exports["default"] = adapter;
|
|
465
466
|
exports.version = version;
|
|
@@ -35,10 +35,10 @@ var _getIsAdapterUnsubscribed = /*#__PURE__*/_classPrivateFieldLooseKey("getIsAd
|
|
|
35
35
|
var _getIsFlagUnsubcribed = /*#__PURE__*/_classPrivateFieldLooseKey("getIsFlagUnsubcribed");
|
|
36
36
|
var _getIsFlagLocked = /*#__PURE__*/_classPrivateFieldLooseKey("getIsFlagLocked");
|
|
37
37
|
var _withoutUnsubscribedOrLockedFlags = /*#__PURE__*/_classPrivateFieldLooseKey("withoutUnsubscribedOrLockedFlags");
|
|
38
|
-
var
|
|
39
|
-
var
|
|
38
|
+
var _getIsAnonymousContext = /*#__PURE__*/_classPrivateFieldLooseKey("getIsAnonymousContext");
|
|
39
|
+
var _ensureContext = /*#__PURE__*/_classPrivateFieldLooseKey("ensureContext");
|
|
40
40
|
var _initializeClient = /*#__PURE__*/_classPrivateFieldLooseKey("initializeClient");
|
|
41
|
-
var
|
|
41
|
+
var _changeClientContext = /*#__PURE__*/_classPrivateFieldLooseKey("changeClientContext");
|
|
42
42
|
var _getInitialFlags = /*#__PURE__*/_classPrivateFieldLooseKey("getInitialFlags");
|
|
43
43
|
var _didFlagChange = /*#__PURE__*/_classPrivateFieldLooseKey("didFlagChange");
|
|
44
44
|
var _setupFlagSubcription = /*#__PURE__*/_classPrivateFieldLooseKey("setupFlagSubcription");
|
|
@@ -99,39 +99,39 @@ var LaunchDarklyAdapter = /*#__PURE__*/function () {
|
|
|
99
99
|
}));
|
|
100
100
|
}
|
|
101
101
|
});
|
|
102
|
-
Object.defineProperty(this,
|
|
102
|
+
Object.defineProperty(this, _getIsAnonymousContext, {
|
|
103
103
|
writable: true,
|
|
104
|
-
value: function value(
|
|
105
|
-
return !(
|
|
104
|
+
value: function value(context) {
|
|
105
|
+
return !(context !== null && context !== void 0 && context.key);
|
|
106
106
|
}
|
|
107
107
|
});
|
|
108
|
-
Object.defineProperty(this,
|
|
108
|
+
Object.defineProperty(this, _ensureContext, {
|
|
109
109
|
writable: true,
|
|
110
|
-
value: function value(
|
|
111
|
-
var
|
|
110
|
+
value: function value(context) {
|
|
111
|
+
var isAnonymousContext = _classPrivateFieldLooseBase(_this, _getIsAnonymousContext)[_getIsAnonymousContext](context);
|
|
112
112
|
|
|
113
113
|
// NOTE: When marked `anonymous` the SDK will generate a unique key and cache it in local storage
|
|
114
|
-
return merge__default["default"](
|
|
115
|
-
key:
|
|
116
|
-
anonymous:
|
|
114
|
+
return merge__default["default"](context, {
|
|
115
|
+
key: isAnonymousContext ? undefined : context.key,
|
|
116
|
+
anonymous: isAnonymousContext
|
|
117
117
|
});
|
|
118
118
|
}
|
|
119
119
|
});
|
|
120
120
|
Object.defineProperty(this, _initializeClient, {
|
|
121
121
|
writable: true,
|
|
122
|
-
value: function value(clientSideId,
|
|
123
|
-
return launchdarklyJsClientSdk.initialize(clientSideId,
|
|
122
|
+
value: function value(clientSideId, context, options) {
|
|
123
|
+
return launchdarklyJsClientSdk.initialize(clientSideId, context, options);
|
|
124
124
|
}
|
|
125
125
|
});
|
|
126
|
-
Object.defineProperty(this,
|
|
126
|
+
Object.defineProperty(this, _changeClientContext, {
|
|
127
127
|
writable: true,
|
|
128
128
|
value: function () {
|
|
129
|
-
var _value = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee(
|
|
129
|
+
var _value = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee(nextContext) {
|
|
130
130
|
var _classPrivateFieldLoo;
|
|
131
131
|
return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
|
|
132
132
|
while (1) switch (_context.prev = _context.next) {
|
|
133
133
|
case 0:
|
|
134
|
-
return _context.abrupt("return", (_classPrivateFieldLoo = _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState].client) !== null && _classPrivateFieldLoo !== void 0 && _classPrivateFieldLoo.identify ? _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState].client.identify(
|
|
134
|
+
return _context.abrupt("return", (_classPrivateFieldLoo = _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState].client) !== null && _classPrivateFieldLoo !== void 0 && _classPrivateFieldLoo.identify ? _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState].client.identify(nextContext) : Promise.reject(new Error('Can not change user context: client not yet initialized.')));
|
|
135
135
|
case 1:
|
|
136
136
|
case "end":
|
|
137
137
|
return _context.stop();
|
|
@@ -277,6 +277,7 @@ var LaunchDarklyAdapter = /*#__PURE__*/function () {
|
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
279
|
});
|
|
280
|
+
// External. Flags are autolocked when updated.
|
|
280
281
|
this.updateFlags = function (flags, options) {
|
|
281
282
|
_classPrivateFieldLooseBase(_this, _updateFlagsInAdapterState)[_updateFlagsInAdapterState](flags, options);
|
|
282
283
|
|
|
@@ -292,7 +293,7 @@ var LaunchDarklyAdapter = /*#__PURE__*/function () {
|
|
|
292
293
|
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState] = {
|
|
293
294
|
subscriptionStatus: types.AdapterSubscriptionStatus.Subscribed,
|
|
294
295
|
configurationStatus: types.AdapterConfigurationStatus.Unconfigured,
|
|
295
|
-
|
|
296
|
+
context: undefined,
|
|
296
297
|
client: undefined,
|
|
297
298
|
flags: {},
|
|
298
299
|
// Typings are incorrect and state that mitt is not callable.
|
|
@@ -309,7 +310,7 @@ var LaunchDarklyAdapter = /*#__PURE__*/function () {
|
|
|
309
310
|
var _configure = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee5(adapterArgs, adapterEventHandlers) {
|
|
310
311
|
var _this2 = this,
|
|
311
312
|
_sdk$clientOptions;
|
|
312
|
-
var handleFlagsChange, handleStatusChange, sdk,
|
|
313
|
+
var handleFlagsChange, handleStatusChange, sdk, context, flags, _adapterArgs$subscrib, subscribeToFlagChanges, _adapterArgs$throwOnI, throwOnInitializationFailure, flagsUpdateDelayMs;
|
|
313
314
|
return _regeneratorRuntime__default["default"].wrap(function _callee5$(_context5) {
|
|
314
315
|
while (1) switch (_context5.prev = _context5.next) {
|
|
315
316
|
case 0:
|
|
@@ -333,9 +334,9 @@ var LaunchDarklyAdapter = /*#__PURE__*/function () {
|
|
|
333
334
|
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].emitter.emit('statusStateChange', {
|
|
334
335
|
configurationStatus: _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].configurationStatus
|
|
335
336
|
});
|
|
336
|
-
sdk = adapterArgs.sdk,
|
|
337
|
-
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].
|
|
338
|
-
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].client = _classPrivateFieldLooseBase(this, _initializeClient)[_initializeClient](sdk.clientSideId, _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].
|
|
337
|
+
sdk = adapterArgs.sdk, context = adapterArgs.context, flags = adapterArgs.flags, _adapterArgs$subscrib = adapterArgs.subscribeToFlagChanges, subscribeToFlagChanges = _adapterArgs$subscrib === void 0 ? true : _adapterArgs$subscrib, _adapterArgs$throwOnI = adapterArgs.throwOnInitializationFailure, throwOnInitializationFailure = _adapterArgs$throwOnI === void 0 ? false : _adapterArgs$throwOnI, flagsUpdateDelayMs = adapterArgs.flagsUpdateDelayMs;
|
|
338
|
+
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].context = _classPrivateFieldLooseBase(this, _ensureContext)[_ensureContext](context);
|
|
339
|
+
_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 : {});
|
|
339
340
|
return _context5.abrupt("return", _classPrivateFieldLooseBase(this, _getInitialFlags)[_getInitialFlags]({
|
|
340
341
|
flags: flags,
|
|
341
342
|
throwOnInitializationFailure: throwOnInitializationFailure
|
|
@@ -365,7 +366,7 @@ var LaunchDarklyAdapter = /*#__PURE__*/function () {
|
|
|
365
366
|
key: "reconfigure",
|
|
366
367
|
value: function () {
|
|
367
368
|
var _reconfigure = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee6(adapterArgs, _adapterEventHandlers) {
|
|
368
|
-
var
|
|
369
|
+
var nextContext;
|
|
369
370
|
return _regeneratorRuntime__default["default"].wrap(function _callee6$(_context6) {
|
|
370
371
|
while (1) switch (_context6.prev = _context6.next) {
|
|
371
372
|
case 0:
|
|
@@ -375,14 +376,14 @@ var LaunchDarklyAdapter = /*#__PURE__*/function () {
|
|
|
375
376
|
}
|
|
376
377
|
return _context6.abrupt("return", Promise.reject(new Error('@flopflip/launchdarkly-adapter: please configure adapter before reconfiguring.')));
|
|
377
378
|
case 2:
|
|
378
|
-
|
|
379
|
-
if (isEqual__default["default"](_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].
|
|
379
|
+
nextContext = adapterArgs.context;
|
|
380
|
+
if (isEqual__default["default"](_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].context, nextContext)) {
|
|
380
381
|
_context6.next = 8;
|
|
381
382
|
break;
|
|
382
383
|
}
|
|
383
|
-
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].
|
|
384
|
+
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].context = _classPrivateFieldLooseBase(this, _ensureContext)[_ensureContext](nextContext);
|
|
384
385
|
_context6.next = 7;
|
|
385
|
-
return _classPrivateFieldLooseBase(this,
|
|
386
|
+
return _classPrivateFieldLooseBase(this, _changeClientContext)[_changeClientContext](_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].context);
|
|
386
387
|
case 7:
|
|
387
388
|
return _context6.abrupt("return", Promise.resolve({
|
|
388
389
|
initializationStatus: types.AdapterInitializationStatus.Succeeded
|
|
@@ -426,32 +427,32 @@ var LaunchDarklyAdapter = /*#__PURE__*/function () {
|
|
|
426
427
|
return _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].flags[flagName];
|
|
427
428
|
}
|
|
428
429
|
}, {
|
|
429
|
-
key: "
|
|
430
|
+
key: "updateClientContext",
|
|
430
431
|
value: function () {
|
|
431
|
-
var
|
|
432
|
+
var _updateClientContext = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee7(updatedContextProps) {
|
|
432
433
|
var isAdapterConfigured;
|
|
433
434
|
return _regeneratorRuntime__default["default"].wrap(function _callee7$(_context7) {
|
|
434
435
|
while (1) switch (_context7.prev = _context7.next) {
|
|
435
436
|
case 0:
|
|
436
437
|
isAdapterConfigured = this.getIsConfigurationStatus(types.AdapterConfigurationStatus.Configured);
|
|
437
|
-
warning__default["default"](isAdapterConfigured, '@flopflip/launchdarkly-adapter: adapter not configured.
|
|
438
|
+
warning__default["default"](isAdapterConfigured, '@flopflip/launchdarkly-adapter: adapter not configured. Client context can not be updated before.');
|
|
438
439
|
if (isAdapterConfigured) {
|
|
439
440
|
_context7.next = 4;
|
|
440
441
|
break;
|
|
441
442
|
}
|
|
442
|
-
return _context7.abrupt("return", Promise.reject(new Error('Can not update
|
|
443
|
+
return _context7.abrupt("return", Promise.reject(new Error('Can not update client context: adapter not yet configured.')));
|
|
443
444
|
case 4:
|
|
444
|
-
return _context7.abrupt("return", _classPrivateFieldLooseBase(this,
|
|
445
|
+
return _context7.abrupt("return", _classPrivateFieldLooseBase(this, _changeClientContext)[_changeClientContext](_objectSpread(_objectSpread({}, _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].context), updatedContextProps)));
|
|
445
446
|
case 5:
|
|
446
447
|
case "end":
|
|
447
448
|
return _context7.stop();
|
|
448
449
|
}
|
|
449
450
|
}, _callee7, this);
|
|
450
451
|
}));
|
|
451
|
-
function
|
|
452
|
-
return
|
|
452
|
+
function updateClientContext(_x7) {
|
|
453
|
+
return _updateClientContext.apply(this, arguments);
|
|
453
454
|
}
|
|
454
|
-
return
|
|
455
|
+
return updateClientContext;
|
|
455
456
|
}()
|
|
456
457
|
}]);
|
|
457
458
|
return LaunchDarklyAdapter;
|
|
@@ -459,7 +460,7 @@ var LaunchDarklyAdapter = /*#__PURE__*/function () {
|
|
|
459
460
|
var adapter = new LaunchDarklyAdapter();
|
|
460
461
|
adapterUtilities.exposeGlobally(adapter);
|
|
461
462
|
|
|
462
|
-
var version = "
|
|
463
|
+
var version = "13.0.0";
|
|
463
464
|
|
|
464
465
|
exports["default"] = adapter;
|
|
465
466
|
exports.version = version;
|
|
@@ -22,10 +22,10 @@ var _getIsAdapterUnsubscribed = /*#__PURE__*/_classPrivateFieldLooseKey("getIsAd
|
|
|
22
22
|
var _getIsFlagUnsubcribed = /*#__PURE__*/_classPrivateFieldLooseKey("getIsFlagUnsubcribed");
|
|
23
23
|
var _getIsFlagLocked = /*#__PURE__*/_classPrivateFieldLooseKey("getIsFlagLocked");
|
|
24
24
|
var _withoutUnsubscribedOrLockedFlags = /*#__PURE__*/_classPrivateFieldLooseKey("withoutUnsubscribedOrLockedFlags");
|
|
25
|
-
var
|
|
26
|
-
var
|
|
25
|
+
var _getIsAnonymousContext = /*#__PURE__*/_classPrivateFieldLooseKey("getIsAnonymousContext");
|
|
26
|
+
var _ensureContext = /*#__PURE__*/_classPrivateFieldLooseKey("ensureContext");
|
|
27
27
|
var _initializeClient = /*#__PURE__*/_classPrivateFieldLooseKey("initializeClient");
|
|
28
|
-
var
|
|
28
|
+
var _changeClientContext = /*#__PURE__*/_classPrivateFieldLooseKey("changeClientContext");
|
|
29
29
|
var _getInitialFlags = /*#__PURE__*/_classPrivateFieldLooseKey("getInitialFlags");
|
|
30
30
|
var _didFlagChange = /*#__PURE__*/_classPrivateFieldLooseKey("didFlagChange");
|
|
31
31
|
var _setupFlagSubcription = /*#__PURE__*/_classPrivateFieldLooseKey("setupFlagSubcription");
|
|
@@ -86,39 +86,39 @@ var LaunchDarklyAdapter = /*#__PURE__*/function () {
|
|
|
86
86
|
}));
|
|
87
87
|
}
|
|
88
88
|
});
|
|
89
|
-
Object.defineProperty(this,
|
|
89
|
+
Object.defineProperty(this, _getIsAnonymousContext, {
|
|
90
90
|
writable: true,
|
|
91
|
-
value: function value(
|
|
92
|
-
return !(
|
|
91
|
+
value: function value(context) {
|
|
92
|
+
return !(context !== null && context !== void 0 && context.key);
|
|
93
93
|
}
|
|
94
94
|
});
|
|
95
|
-
Object.defineProperty(this,
|
|
95
|
+
Object.defineProperty(this, _ensureContext, {
|
|
96
96
|
writable: true,
|
|
97
|
-
value: function value(
|
|
98
|
-
var
|
|
97
|
+
value: function value(context) {
|
|
98
|
+
var isAnonymousContext = _classPrivateFieldLooseBase(_this, _getIsAnonymousContext)[_getIsAnonymousContext](context);
|
|
99
99
|
|
|
100
100
|
// NOTE: When marked `anonymous` the SDK will generate a unique key and cache it in local storage
|
|
101
|
-
return merge(
|
|
102
|
-
key:
|
|
103
|
-
anonymous:
|
|
101
|
+
return merge(context, {
|
|
102
|
+
key: isAnonymousContext ? undefined : context.key,
|
|
103
|
+
anonymous: isAnonymousContext
|
|
104
104
|
});
|
|
105
105
|
}
|
|
106
106
|
});
|
|
107
107
|
Object.defineProperty(this, _initializeClient, {
|
|
108
108
|
writable: true,
|
|
109
|
-
value: function value(clientSideId,
|
|
110
|
-
return initialize(clientSideId,
|
|
109
|
+
value: function value(clientSideId, context, options) {
|
|
110
|
+
return initialize(clientSideId, context, options);
|
|
111
111
|
}
|
|
112
112
|
});
|
|
113
|
-
Object.defineProperty(this,
|
|
113
|
+
Object.defineProperty(this, _changeClientContext, {
|
|
114
114
|
writable: true,
|
|
115
115
|
value: function () {
|
|
116
|
-
var _value = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(
|
|
116
|
+
var _value = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(nextContext) {
|
|
117
117
|
var _classPrivateFieldLoo;
|
|
118
118
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
119
119
|
while (1) switch (_context.prev = _context.next) {
|
|
120
120
|
case 0:
|
|
121
|
-
return _context.abrupt("return", (_classPrivateFieldLoo = _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState].client) !== null && _classPrivateFieldLoo !== void 0 && _classPrivateFieldLoo.identify ? _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState].client.identify(
|
|
121
|
+
return _context.abrupt("return", (_classPrivateFieldLoo = _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState].client) !== null && _classPrivateFieldLoo !== void 0 && _classPrivateFieldLoo.identify ? _classPrivateFieldLooseBase(_this, _adapterState)[_adapterState].client.identify(nextContext) : Promise.reject(new Error('Can not change user context: client not yet initialized.')));
|
|
122
122
|
case 1:
|
|
123
123
|
case "end":
|
|
124
124
|
return _context.stop();
|
|
@@ -264,6 +264,7 @@ var LaunchDarklyAdapter = /*#__PURE__*/function () {
|
|
|
264
264
|
}
|
|
265
265
|
}
|
|
266
266
|
});
|
|
267
|
+
// External. Flags are autolocked when updated.
|
|
267
268
|
this.updateFlags = function (flags, options) {
|
|
268
269
|
_classPrivateFieldLooseBase(_this, _updateFlagsInAdapterState)[_updateFlagsInAdapterState](flags, options);
|
|
269
270
|
|
|
@@ -279,7 +280,7 @@ var LaunchDarklyAdapter = /*#__PURE__*/function () {
|
|
|
279
280
|
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState] = {
|
|
280
281
|
subscriptionStatus: AdapterSubscriptionStatus.Subscribed,
|
|
281
282
|
configurationStatus: AdapterConfigurationStatus.Unconfigured,
|
|
282
|
-
|
|
283
|
+
context: undefined,
|
|
283
284
|
client: undefined,
|
|
284
285
|
flags: {},
|
|
285
286
|
// Typings are incorrect and state that mitt is not callable.
|
|
@@ -296,7 +297,7 @@ var LaunchDarklyAdapter = /*#__PURE__*/function () {
|
|
|
296
297
|
var _configure = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(adapterArgs, adapterEventHandlers) {
|
|
297
298
|
var _this2 = this,
|
|
298
299
|
_sdk$clientOptions;
|
|
299
|
-
var handleFlagsChange, handleStatusChange, sdk,
|
|
300
|
+
var handleFlagsChange, handleStatusChange, sdk, context, flags, _adapterArgs$subscrib, subscribeToFlagChanges, _adapterArgs$throwOnI, throwOnInitializationFailure, flagsUpdateDelayMs;
|
|
300
301
|
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
301
302
|
while (1) switch (_context5.prev = _context5.next) {
|
|
302
303
|
case 0:
|
|
@@ -320,9 +321,9 @@ var LaunchDarklyAdapter = /*#__PURE__*/function () {
|
|
|
320
321
|
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].emitter.emit('statusStateChange', {
|
|
321
322
|
configurationStatus: _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].configurationStatus
|
|
322
323
|
});
|
|
323
|
-
sdk = adapterArgs.sdk,
|
|
324
|
-
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].
|
|
325
|
-
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].client = _classPrivateFieldLooseBase(this, _initializeClient)[_initializeClient](sdk.clientSideId, _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].
|
|
324
|
+
sdk = adapterArgs.sdk, context = adapterArgs.context, flags = adapterArgs.flags, _adapterArgs$subscrib = adapterArgs.subscribeToFlagChanges, subscribeToFlagChanges = _adapterArgs$subscrib === void 0 ? true : _adapterArgs$subscrib, _adapterArgs$throwOnI = adapterArgs.throwOnInitializationFailure, throwOnInitializationFailure = _adapterArgs$throwOnI === void 0 ? false : _adapterArgs$throwOnI, flagsUpdateDelayMs = adapterArgs.flagsUpdateDelayMs;
|
|
325
|
+
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].context = _classPrivateFieldLooseBase(this, _ensureContext)[_ensureContext](context);
|
|
326
|
+
_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 : {});
|
|
326
327
|
return _context5.abrupt("return", _classPrivateFieldLooseBase(this, _getInitialFlags)[_getInitialFlags]({
|
|
327
328
|
flags: flags,
|
|
328
329
|
throwOnInitializationFailure: throwOnInitializationFailure
|
|
@@ -352,7 +353,7 @@ var LaunchDarklyAdapter = /*#__PURE__*/function () {
|
|
|
352
353
|
key: "reconfigure",
|
|
353
354
|
value: function () {
|
|
354
355
|
var _reconfigure = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(adapterArgs, _adapterEventHandlers) {
|
|
355
|
-
var
|
|
356
|
+
var nextContext;
|
|
356
357
|
return _regeneratorRuntime.wrap(function _callee6$(_context6) {
|
|
357
358
|
while (1) switch (_context6.prev = _context6.next) {
|
|
358
359
|
case 0:
|
|
@@ -362,14 +363,14 @@ var LaunchDarklyAdapter = /*#__PURE__*/function () {
|
|
|
362
363
|
}
|
|
363
364
|
return _context6.abrupt("return", Promise.reject(new Error('@flopflip/launchdarkly-adapter: please configure adapter before reconfiguring.')));
|
|
364
365
|
case 2:
|
|
365
|
-
|
|
366
|
-
if (isEqual(_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].
|
|
366
|
+
nextContext = adapterArgs.context;
|
|
367
|
+
if (isEqual(_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].context, nextContext)) {
|
|
367
368
|
_context6.next = 8;
|
|
368
369
|
break;
|
|
369
370
|
}
|
|
370
|
-
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].
|
|
371
|
+
_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].context = _classPrivateFieldLooseBase(this, _ensureContext)[_ensureContext](nextContext);
|
|
371
372
|
_context6.next = 7;
|
|
372
|
-
return _classPrivateFieldLooseBase(this,
|
|
373
|
+
return _classPrivateFieldLooseBase(this, _changeClientContext)[_changeClientContext](_classPrivateFieldLooseBase(this, _adapterState)[_adapterState].context);
|
|
373
374
|
case 7:
|
|
374
375
|
return _context6.abrupt("return", Promise.resolve({
|
|
375
376
|
initializationStatus: AdapterInitializationStatus.Succeeded
|
|
@@ -413,32 +414,32 @@ var LaunchDarklyAdapter = /*#__PURE__*/function () {
|
|
|
413
414
|
return _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].flags[flagName];
|
|
414
415
|
}
|
|
415
416
|
}, {
|
|
416
|
-
key: "
|
|
417
|
+
key: "updateClientContext",
|
|
417
418
|
value: function () {
|
|
418
|
-
var
|
|
419
|
+
var _updateClientContext = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(updatedContextProps) {
|
|
419
420
|
var isAdapterConfigured;
|
|
420
421
|
return _regeneratorRuntime.wrap(function _callee7$(_context7) {
|
|
421
422
|
while (1) switch (_context7.prev = _context7.next) {
|
|
422
423
|
case 0:
|
|
423
424
|
isAdapterConfigured = this.getIsConfigurationStatus(AdapterConfigurationStatus.Configured);
|
|
424
|
-
warning(isAdapterConfigured, '@flopflip/launchdarkly-adapter: adapter not configured.
|
|
425
|
+
warning(isAdapterConfigured, '@flopflip/launchdarkly-adapter: adapter not configured. Client context can not be updated before.');
|
|
425
426
|
if (isAdapterConfigured) {
|
|
426
427
|
_context7.next = 4;
|
|
427
428
|
break;
|
|
428
429
|
}
|
|
429
|
-
return _context7.abrupt("return", Promise.reject(new Error('Can not update
|
|
430
|
+
return _context7.abrupt("return", Promise.reject(new Error('Can not update client context: adapter not yet configured.')));
|
|
430
431
|
case 4:
|
|
431
|
-
return _context7.abrupt("return", _classPrivateFieldLooseBase(this,
|
|
432
|
+
return _context7.abrupt("return", _classPrivateFieldLooseBase(this, _changeClientContext)[_changeClientContext](_objectSpread(_objectSpread({}, _classPrivateFieldLooseBase(this, _adapterState)[_adapterState].context), updatedContextProps)));
|
|
432
433
|
case 5:
|
|
433
434
|
case "end":
|
|
434
435
|
return _context7.stop();
|
|
435
436
|
}
|
|
436
437
|
}, _callee7, this);
|
|
437
438
|
}));
|
|
438
|
-
function
|
|
439
|
-
return
|
|
439
|
+
function updateClientContext(_x7) {
|
|
440
|
+
return _updateClientContext.apply(this, arguments);
|
|
440
441
|
}
|
|
441
|
-
return
|
|
442
|
+
return updateClientContext;
|
|
442
443
|
}()
|
|
443
444
|
}]);
|
|
444
445
|
return LaunchDarklyAdapter;
|
|
@@ -446,6 +447,6 @@ var LaunchDarklyAdapter = /*#__PURE__*/function () {
|
|
|
446
447
|
var adapter = new LaunchDarklyAdapter();
|
|
447
448
|
exposeGlobally(adapter);
|
|
448
449
|
|
|
449
|
-
var version = "
|
|
450
|
+
var version = "13.0.0";
|
|
450
451
|
|
|
451
452
|
export { adapter as default, version };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flopflip/launchdarkly-adapter",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "13.0.0",
|
|
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,9 @@
|
|
|
26
26
|
"globalthis": "1.0.3"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@babel/runtime": "7.
|
|
30
|
-
"@flopflip/adapter-utilities": "
|
|
31
|
-
"@flopflip/types": "
|
|
29
|
+
"@babel/runtime": "7.21.0",
|
|
30
|
+
"@flopflip/adapter-utilities": "13.0.0",
|
|
31
|
+
"@flopflip/types": "13.0.0",
|
|
32
32
|
"debounce-fn": "4.0.0",
|
|
33
33
|
"launchdarkly-js-client-sdk": "3.1.1",
|
|
34
34
|
"lodash": "4.17.21",
|