New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@atlaskit/feature-gate-js-client

Package Overview
Dependencies
Maintainers
0
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@atlaskit/feature-gate-js-client - npm Package Compare versions

Comparing version 4.20.0 to 4.20.1

9

CHANGELOG.md
# @atlaskit/feature-gate-js-client
## 4.20.1
### Patch Changes
- [#153087](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/153087)
[`476c1b4e48adb`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/476c1b4e48adb) -
Bugfixes - subscriptions method support when update user without using a provider, and fix to
update user with provider when update fails
## 4.20.0

@@ -4,0 +13,0 @@

165

dist/cjs/client/index.js

@@ -109,2 +109,3 @@ "use strict";

FeatureGates.initCompleted = true;
FeatureGates.initWithDefaults = true;
}).finally(function () {

@@ -165,24 +166,21 @@ var endTime = performance.now();

FeatureGates.initOptions = clientOptions;
FeatureGates.subscriptions = new _subscriptions.default();
FeatureGates.provider = provider;
FeatureGates.provider.setClientVersion(_version.CLIENT_VERSION);
if (FeatureGates.provider.setApplyUpdateCallback) {
FeatureGates.provider.setApplyUpdateCallback(function (experimentsResult) {
_statsigJsLite.default.setInitializeValues(experimentsResult.experimentValues);
FeatureGates.subscriptions.anyUpdated();
});
FeatureGates.provider.setApplyUpdateCallback(this.applyUpdateCallback);
}
FeatureGates.initPromise = FeatureGates.initWithProvider(clientOptions, identifiers, customAttributes).then(function () {
FeatureGates.initCompleted = true;
FeatureGates.initWithDefaults = true;
}).finally(function () {
var endTime = performance.now();
var totalTime = endTime - startTime;
FeatureGates.fireClientEvent(startTime, totalTime, 'initialize', FeatureGates.initCompleted, provider.getApiKey ? provider.getApiKey() : undefined);
FeatureGates.fireClientEvent(startTime, totalTime, 'initializeWithProvider', FeatureGates.initCompleted, provider.getApiKey ? provider.getApiKey() : undefined);
});
return _context2.abrupt("return", FeatureGates.initPromise);
case 11:
case 10:
case "end":
return _context2.stop();
}
}, _callee2);
}, _callee2, this);
}));

@@ -195,2 +193,15 @@ function initializeWithProvider(_x4, _x5, _x6, _x7) {

}, {
key: "applyUpdateCallback",
value: function applyUpdateCallback(experimentsResult) {
try {
if (FeatureGates.initCompleted || FeatureGates.initWithDefaults) {
_statsigJsLite.default.setInitializeValues(experimentsResult.experimentValues);
FeatureGates.subscriptions.anyUpdated();
}
} catch (error) {
// eslint-disable-next-line no-console
console.warn('Error when attempting to apply update', error);
}
}
}, {
key: "fireClientEvent",

@@ -249,2 +260,3 @@ value: function fireClientEvent(startTime, totalTime, action, success) {

FeatureGates.initCompleted = true;
FeatureGates.initWithDefaults = true;
}).finally(function () {

@@ -324,6 +336,9 @@ var endTime = performance.now();

_context5.next = 4;
return FeatureGates.provider.setProfile(FeatureGates.initOptions, identifiers, customAttributes);
case 4:
_context5.next = 6;
return FeatureGates.updateUserUsingInitializeValuesProducer(function () {
return FeatureGates.provider.getExperimentValues(FeatureGates.initOptions, identifiers, customAttributes);
return FeatureGates.provider.getExperimentValues();
}, identifiers, customAttributes);
case 4:
case 6:
case "end":

@@ -818,12 +833,15 @@ return _context5.stop();

_context8.prev = 1;
_context8.next = 4;
return FeatureGates.provider.setProfile(baseClientOptions, identifiers, customAttributes);
case 4:
// If client sdk key fetch fails, an error would be thrown and handled instead of waiting for the experiment
// values request to be settled, and it will fall back to use default values.
clientSdkKeyPromise = FeatureGates.provider.getClientSdkKey(baseClientOptions).then(function (value) {
clientSdkKeyPromise = FeatureGates.provider.getClientSdkKey().then(function (value) {
return fromValuesClientOptions.sdkKey = value;
});
experimentValuesPromise = FeatureGates.provider.getExperimentValues(baseClientOptions, identifiers, customAttributes); // Only wait for the experiment values request to finish and try to initialise the client with experiment
experimentValuesPromise = FeatureGates.provider.getExperimentValues(); // Only wait for the experiment values request to finish and try to initialise the client with experiment
// values if both requests are successful. Else an error would be thrown and handled by the catch
_context8.next = 6;
_context8.next = 8;
return Promise.all([clientSdkKeyPromise, experimentValuesPromise]);
case 6:
case 8:
_yield$Promise$all3 = _context8.sent;

@@ -834,6 +852,6 @@ _yield$Promise$all4 = (0, _slicedToArray2.default)(_yield$Promise$all3, 2);

customAttributesFromResult = experimentValuesResult.customAttributesFromFetch;
_context8.next = 20;
_context8.next = 22;
break;
case 13:
_context8.prev = 13;
case 15:
_context8.prev = 15;
_context8.t0 = _context8["catch"](1);

@@ -846,14 +864,14 @@ if (_context8.t0 instanceof Error) {

console.warn("Initialising Statsig client without values");
_context8.next = 19;
_context8.next = 21;
return FeatureGates.initFromValues(fromValuesClientOptions, identifiers, customAttributes);
case 19:
case 21:
throw _context8.t0;
case 20:
_context8.next = 22;
case 22:
_context8.next = 24;
return this.initFromValues(fromValuesClientOptions, identifiers, customAttributesFromResult, experimentValues);
case 22:
case 24:
case "end":
return _context8.stop();
}
}, _callee8, this, [[1, 13]]);
}, _callee8, this, [[1, 15]]);
}));

@@ -906,3 +924,3 @@ function initWithProvider(_x21, _x22, _x23) {

case 12:
_context9.next = 21;
_context9.next = 22;
break;

@@ -923,4 +941,5 @@ case 14:

case 20:
FeatureGates.initWithDefaults = true;
throw _context9.t0;
case 21:
case 22:
case "end":

@@ -970,9 +989,9 @@ return _context9.stop();

value: (function () {
var _updateUserUsingInitializeValuesProducer = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee10(getInitializeValues, identifiers, customAttributes) {
var _updateUserUsingInitializeValuesProducer = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee11(getInitializeValues, identifiers, customAttributes) {
var originalInitPromise, initializeValuesPromise, updateUserPromise;
return _regenerator.default.wrap(function _callee10$(_context10) {
while (1) switch (_context10.prev = _context10.next) {
return _regenerator.default.wrap(function _callee11$(_context11) {
while (1) switch (_context11.prev = _context11.next) {
case 0:
if (FeatureGates.initPromise) {
_context10.next = 2;
_context11.next = 2;
break;

@@ -983,18 +1002,18 @@ }

if (!FeatureGates.isCurrentUser(identifiers, customAttributes)) {
_context10.next = 4;
_context11.next = 4;
break;
}
return _context10.abrupt("return", FeatureGates.initPromise);
return _context11.abrupt("return", FeatureGates.initPromise);
case 4:
// Wait for the current initialize/update to finish
originalInitPromise = FeatureGates.initPromise;
_context10.prev = 5;
_context10.next = 8;
_context11.prev = 5;
_context11.next = 8;
return FeatureGates.initPromise;
case 8:
_context10.next = 12;
_context11.next = 12;
break;
case 10:
_context10.prev = 10;
_context10.t0 = _context10["catch"](5);
_context11.prev = 10;
_context11.t0 = _context11["catch"](5);
case 12:

@@ -1004,12 +1023,28 @@ initializeValuesPromise = getInitializeValues();

// Any subsequent calls to await FeatureGates.initialize() or FeatureGates.updateUser() will now also await this user update.
FeatureGates.initPromise = updateUserPromise.catch(function () {
// If the update failed then it changed nothing, so revert back to the original promise.
FeatureGates.initPromise = originalInitPromise;
});
return _context10.abrupt("return", updateUserPromise);
FeatureGates.initPromise = updateUserPromise.catch( /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee10() {
return _regenerator.default.wrap(function _callee10$(_context10) {
while (1) switch (_context10.prev = _context10.next) {
case 0:
// If the update failed then it changed nothing, so revert back to the original promise.
FeatureGates.initPromise = originalInitPromise;
// Set the user profile again to revert back to the current user
if (!FeatureGates.provider) {
_context10.next = 4;
break;
}
_context10.next = 4;
return FeatureGates.provider.setProfile(FeatureGates.initOptions, FeatureGates.currentIdentifiers, FeatureGates.currentAttributes);
case 4:
case "end":
return _context10.stop();
}
}, _callee10);
})));
return _context11.abrupt("return", updateUserPromise);
case 16:
case "end":
return _context10.stop();
return _context11.stop();
}
}, _callee10, null, [[5, 10]]);
}, _callee11, null, [[5, 10]]);
}));

@@ -1033,27 +1068,27 @@ function updateUserUsingInitializeValuesProducer(_x27, _x28, _x29) {

value: (function () {
var _updateStatsigClientUser = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee11(initializeValuesPromise, identifiers, customAttributes) {
var _updateStatsigClientUser = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee12(initializeValuesPromise, identifiers, customAttributes) {
var initializeValues, user, _FeatureGates$initOpt2, _FeatureGates$initOpt3, errMsg, success;
return _regenerator.default.wrap(function _callee11$(_context11) {
while (1) switch (_context11.prev = _context11.next) {
return _regenerator.default.wrap(function _callee12$(_context12) {
while (1) switch (_context12.prev = _context12.next) {
case 0:
_context11.prev = 0;
_context11.next = 3;
_context12.prev = 0;
_context12.next = 3;
return initializeValuesPromise;
case 3:
initializeValues = _context11.sent;
initializeValues = _context12.sent;
user = FeatureGates.toStatsigUser(identifiers, initializeValues.customAttributesFromFetch);
_context11.next = 12;
_context12.next = 12;
break;
case 7:
_context11.prev = 7;
_context11.t0 = _context11["catch"](0);
_context12.prev = 7;
_context12.t0 = _context12["catch"](0);
// Make sure the updateUserCompletionCallback is called for any errors in our custom code.
// This is not necessary for the updateUserWithValues call, because the Statsig client will already invoke the callback itself.
errMsg = _context11.t0 instanceof Error ? _context11.t0.message : JSON.stringify(_context11.t0);
errMsg = _context12.t0 instanceof Error ? _context12.t0.message : JSON.stringify(_context12.t0);
(_FeatureGates$initOpt2 = (_FeatureGates$initOpt3 = FeatureGates.initOptions).updateUserCompletionCallback) === null || _FeatureGates$initOpt2 === void 0 || _FeatureGates$initOpt2.call(_FeatureGates$initOpt3, false, errMsg);
throw _context11.t0;
throw _context12.t0;
case 12:
success = _statsigJsLite.default.updateUserWithValues(user, initializeValues.experimentValues);
if (!success) {
_context11.next = 18;
_context12.next = 19;
break;

@@ -1063,11 +1098,12 @@ }

FeatureGates.currentAttributes = customAttributes;
_context11.next = 19;
FeatureGates.subscriptions.anyUpdated();
_context12.next = 20;
break;
case 18:
case 19:
throw new Error('Failed to update user. An unexpected error occured.');
case 19:
case 20:
case "end":
return _context11.stop();
return _context12.stop();
}
}, _callee11, null, [[0, 7]]);
}, _callee12, null, [[0, 7]]);
}));

@@ -1137,7 +1173,7 @@ function updateStatsigClientUser(_x30, _x31, _x32) {

}
var ascendingKeyOrder = function ascendingKeyOrder(_ref2, _ref3) {
var _ref4 = (0, _slicedToArray2.default)(_ref2, 1),
key1 = _ref4[0];
var ascendingKeyOrder = function ascendingKeyOrder(_ref3, _ref4) {
var _ref5 = (0, _slicedToArray2.default)(_ref3, 1),
key2 = _ref5[0];
key1 = _ref5[0];
var _ref6 = (0, _slicedToArray2.default)(_ref4, 1),
key2 = _ref6[0];
return key1.localeCompare(key2);

@@ -1266,2 +1302,3 @@ };

(0, _defineProperty2.default)(FeatureGates, "initCompleted", false);
(0, _defineProperty2.default)(FeatureGates, "initWithDefaults", false);
(0, _defineProperty2.default)(FeatureGates, "hasGetExperimentErrorOccurred", false);

@@ -1268,0 +1305,0 @@ (0, _defineProperty2.default)(FeatureGates, "hasGetExperimentValueErrorOccurred", false);

@@ -8,2 +8,2 @@ "use strict";

/// <reference types="node" />
var CLIENT_VERSION = exports.CLIENT_VERSION = "4.20.0";
var CLIENT_VERSION = exports.CLIENT_VERSION = "4.20.1";

@@ -49,2 +49,3 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";

FeatureGates.initCompleted = true;
FeatureGates.initWithDefaults = true;
}).finally(() => {

@@ -85,20 +86,28 @@ const endTime = performance.now();

FeatureGates.initOptions = clientOptions;
FeatureGates.subscriptions = new Subscriptions();
FeatureGates.provider = provider;
FeatureGates.provider.setClientVersion(CLIENT_VERSION);
if (FeatureGates.provider.setApplyUpdateCallback) {
FeatureGates.provider.setApplyUpdateCallback(experimentsResult => {
Statsig.setInitializeValues(experimentsResult.experimentValues);
FeatureGates.subscriptions.anyUpdated();
});
FeatureGates.provider.setApplyUpdateCallback(this.applyUpdateCallback);
}
FeatureGates.initPromise = FeatureGates.initWithProvider(clientOptions, identifiers, customAttributes).then(() => {
FeatureGates.initCompleted = true;
FeatureGates.initWithDefaults = true;
}).finally(() => {
const endTime = performance.now();
const totalTime = endTime - startTime;
FeatureGates.fireClientEvent(startTime, totalTime, 'initialize', FeatureGates.initCompleted, provider.getApiKey ? provider.getApiKey() : undefined);
FeatureGates.fireClientEvent(startTime, totalTime, 'initializeWithProvider', FeatureGates.initCompleted, provider.getApiKey ? provider.getApiKey() : undefined);
});
return FeatureGates.initPromise;
}
static applyUpdateCallback(experimentsResult) {
try {
if (FeatureGates.initCompleted || FeatureGates.initWithDefaults) {
Statsig.setInitializeValues(experimentsResult.experimentValues);
FeatureGates.subscriptions.anyUpdated();
}
} catch (error) {
// eslint-disable-next-line no-console
console.warn('Error when attempting to apply update', error);
}
}
static fireClientEvent(startTime, totalTime, action, success, apiKey = undefined) {

@@ -143,2 +152,3 @@ var _FeatureGates$initOpt;

FeatureGates.initCompleted = true;
FeatureGates.initWithDefaults = true;
}).finally(() => {

@@ -178,3 +188,4 @@ const endTime = performance.now();

}
await FeatureGates.updateUserUsingInitializeValuesProducer(() => FeatureGates.provider.getExperimentValues(FeatureGates.initOptions, identifiers, customAttributes), identifiers, customAttributes);
await FeatureGates.provider.setProfile(FeatureGates.initOptions, identifiers, customAttributes);
await FeatureGates.updateUserUsingInitializeValuesProducer(() => FeatureGates.provider.getExperimentValues(), identifiers, customAttributes);
}

@@ -569,6 +580,8 @@

try {
await FeatureGates.provider.setProfile(baseClientOptions, identifiers, customAttributes);
// If client sdk key fetch fails, an error would be thrown and handled instead of waiting for the experiment
// values request to be settled, and it will fall back to use default values.
const clientSdkKeyPromise = FeatureGates.provider.getClientSdkKey(baseClientOptions).then(value => fromValuesClientOptions.sdkKey = value);
const experimentValuesPromise = FeatureGates.provider.getExperimentValues(baseClientOptions, identifiers, customAttributes);
const clientSdkKeyPromise = FeatureGates.provider.getClientSdkKey().then(value => fromValuesClientOptions.sdkKey = value);
const experimentValuesPromise = FeatureGates.provider.getExperimentValues();

@@ -633,2 +646,3 @@ // Only wait for the experiment values request to finish and try to initialise the client with experiment

});
FeatureGates.initWithDefaults = true;
throw error;

@@ -689,5 +703,10 @@ }

// Any subsequent calls to await FeatureGates.initialize() or FeatureGates.updateUser() will now also await this user update.
FeatureGates.initPromise = updateUserPromise.catch(() => {
FeatureGates.initPromise = updateUserPromise.catch(async () => {
// If the update failed then it changed nothing, so revert back to the original promise.
FeatureGates.initPromise = originalInitPromise;
// Set the user profile again to revert back to the current user
if (FeatureGates.provider) {
await FeatureGates.provider.setProfile(FeatureGates.initOptions, FeatureGates.currentIdentifiers, FeatureGates.currentAttributes);
}
});

@@ -722,2 +741,3 @@ return updateUserPromise;

FeatureGates.currentAttributes = customAttributes;
FeatureGates.subscriptions.anyUpdated();
} else {

@@ -902,2 +922,3 @@ throw new Error('Failed to update user. An unexpected error occured.');

_defineProperty(FeatureGates, "initCompleted", false);
_defineProperty(FeatureGates, "initWithDefaults", false);
_defineProperty(FeatureGates, "hasGetExperimentErrorOccurred", false);

@@ -904,0 +925,0 @@ _defineProperty(FeatureGates, "hasGetExperimentValueErrorOccurred", false);

/// <reference types="node" />
export const CLIENT_VERSION = "4.20.0";
export const CLIENT_VERSION = "4.20.1";

@@ -72,2 +72,3 @@ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";

FeatureGates.initCompleted = true;
FeatureGates.initWithDefaults = true;
}).finally(function () {

@@ -128,24 +129,21 @@ var endTime = performance.now();

FeatureGates.initOptions = clientOptions;
FeatureGates.subscriptions = new Subscriptions();
FeatureGates.provider = provider;
FeatureGates.provider.setClientVersion(CLIENT_VERSION);
if (FeatureGates.provider.setApplyUpdateCallback) {
FeatureGates.provider.setApplyUpdateCallback(function (experimentsResult) {
Statsig.setInitializeValues(experimentsResult.experimentValues);
FeatureGates.subscriptions.anyUpdated();
});
FeatureGates.provider.setApplyUpdateCallback(this.applyUpdateCallback);
}
FeatureGates.initPromise = FeatureGates.initWithProvider(clientOptions, identifiers, customAttributes).then(function () {
FeatureGates.initCompleted = true;
FeatureGates.initWithDefaults = true;
}).finally(function () {
var endTime = performance.now();
var totalTime = endTime - startTime;
FeatureGates.fireClientEvent(startTime, totalTime, 'initialize', FeatureGates.initCompleted, provider.getApiKey ? provider.getApiKey() : undefined);
FeatureGates.fireClientEvent(startTime, totalTime, 'initializeWithProvider', FeatureGates.initCompleted, provider.getApiKey ? provider.getApiKey() : undefined);
});
return _context2.abrupt("return", FeatureGates.initPromise);
case 11:
case 10:
case "end":
return _context2.stop();
}
}, _callee2);
}, _callee2, this);
}));

@@ -158,2 +156,15 @@ function initializeWithProvider(_x4, _x5, _x6, _x7) {

}, {
key: "applyUpdateCallback",
value: function applyUpdateCallback(experimentsResult) {
try {
if (FeatureGates.initCompleted || FeatureGates.initWithDefaults) {
Statsig.setInitializeValues(experimentsResult.experimentValues);
FeatureGates.subscriptions.anyUpdated();
}
} catch (error) {
// eslint-disable-next-line no-console
console.warn('Error when attempting to apply update', error);
}
}
}, {
key: "fireClientEvent",

@@ -212,2 +223,3 @@ value: function fireClientEvent(startTime, totalTime, action, success) {

FeatureGates.initCompleted = true;
FeatureGates.initWithDefaults = true;
}).finally(function () {

@@ -287,6 +299,9 @@ var endTime = performance.now();

_context5.next = 4;
return FeatureGates.provider.setProfile(FeatureGates.initOptions, identifiers, customAttributes);
case 4:
_context5.next = 6;
return FeatureGates.updateUserUsingInitializeValuesProducer(function () {
return FeatureGates.provider.getExperimentValues(FeatureGates.initOptions, identifiers, customAttributes);
return FeatureGates.provider.getExperimentValues();
}, identifiers, customAttributes);
case 4:
case 6:
case "end":

@@ -781,12 +796,15 @@ return _context5.stop();

_context8.prev = 1;
_context8.next = 4;
return FeatureGates.provider.setProfile(baseClientOptions, identifiers, customAttributes);
case 4:
// If client sdk key fetch fails, an error would be thrown and handled instead of waiting for the experiment
// values request to be settled, and it will fall back to use default values.
clientSdkKeyPromise = FeatureGates.provider.getClientSdkKey(baseClientOptions).then(function (value) {
clientSdkKeyPromise = FeatureGates.provider.getClientSdkKey().then(function (value) {
return fromValuesClientOptions.sdkKey = value;
});
experimentValuesPromise = FeatureGates.provider.getExperimentValues(baseClientOptions, identifiers, customAttributes); // Only wait for the experiment values request to finish and try to initialise the client with experiment
experimentValuesPromise = FeatureGates.provider.getExperimentValues(); // Only wait for the experiment values request to finish and try to initialise the client with experiment
// values if both requests are successful. Else an error would be thrown and handled by the catch
_context8.next = 6;
_context8.next = 8;
return Promise.all([clientSdkKeyPromise, experimentValuesPromise]);
case 6:
case 8:
_yield$Promise$all3 = _context8.sent;

@@ -797,6 +815,6 @@ _yield$Promise$all4 = _slicedToArray(_yield$Promise$all3, 2);

customAttributesFromResult = experimentValuesResult.customAttributesFromFetch;
_context8.next = 20;
_context8.next = 22;
break;
case 13:
_context8.prev = 13;
case 15:
_context8.prev = 15;
_context8.t0 = _context8["catch"](1);

@@ -809,14 +827,14 @@ if (_context8.t0 instanceof Error) {

console.warn("Initialising Statsig client without values");
_context8.next = 19;
_context8.next = 21;
return FeatureGates.initFromValues(fromValuesClientOptions, identifiers, customAttributes);
case 19:
case 21:
throw _context8.t0;
case 20:
_context8.next = 22;
case 22:
_context8.next = 24;
return this.initFromValues(fromValuesClientOptions, identifiers, customAttributesFromResult, experimentValues);
case 22:
case 24:
case "end":
return _context8.stop();
}
}, _callee8, this, [[1, 13]]);
}, _callee8, this, [[1, 15]]);
}));

@@ -869,3 +887,3 @@ function initWithProvider(_x21, _x22, _x23) {

case 12:
_context9.next = 21;
_context9.next = 22;
break;

@@ -886,4 +904,5 @@ case 14:

case 20:
FeatureGates.initWithDefaults = true;
throw _context9.t0;
case 21:
case 22:
case "end":

@@ -933,9 +952,9 @@ return _context9.stop();

value: (function () {
var _updateUserUsingInitializeValuesProducer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(getInitializeValues, identifiers, customAttributes) {
var _updateUserUsingInitializeValuesProducer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(getInitializeValues, identifiers, customAttributes) {
var originalInitPromise, initializeValuesPromise, updateUserPromise;
return _regeneratorRuntime.wrap(function _callee10$(_context10) {
while (1) switch (_context10.prev = _context10.next) {
return _regeneratorRuntime.wrap(function _callee11$(_context11) {
while (1) switch (_context11.prev = _context11.next) {
case 0:
if (FeatureGates.initPromise) {
_context10.next = 2;
_context11.next = 2;
break;

@@ -946,18 +965,18 @@ }

if (!FeatureGates.isCurrentUser(identifiers, customAttributes)) {
_context10.next = 4;
_context11.next = 4;
break;
}
return _context10.abrupt("return", FeatureGates.initPromise);
return _context11.abrupt("return", FeatureGates.initPromise);
case 4:
// Wait for the current initialize/update to finish
originalInitPromise = FeatureGates.initPromise;
_context10.prev = 5;
_context10.next = 8;
_context11.prev = 5;
_context11.next = 8;
return FeatureGates.initPromise;
case 8:
_context10.next = 12;
_context11.next = 12;
break;
case 10:
_context10.prev = 10;
_context10.t0 = _context10["catch"](5);
_context11.prev = 10;
_context11.t0 = _context11["catch"](5);
case 12:

@@ -967,12 +986,28 @@ initializeValuesPromise = getInitializeValues();

// Any subsequent calls to await FeatureGates.initialize() or FeatureGates.updateUser() will now also await this user update.
FeatureGates.initPromise = updateUserPromise.catch(function () {
// If the update failed then it changed nothing, so revert back to the original promise.
FeatureGates.initPromise = originalInitPromise;
});
return _context10.abrupt("return", updateUserPromise);
FeatureGates.initPromise = updateUserPromise.catch( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10() {
return _regeneratorRuntime.wrap(function _callee10$(_context10) {
while (1) switch (_context10.prev = _context10.next) {
case 0:
// If the update failed then it changed nothing, so revert back to the original promise.
FeatureGates.initPromise = originalInitPromise;
// Set the user profile again to revert back to the current user
if (!FeatureGates.provider) {
_context10.next = 4;
break;
}
_context10.next = 4;
return FeatureGates.provider.setProfile(FeatureGates.initOptions, FeatureGates.currentIdentifiers, FeatureGates.currentAttributes);
case 4:
case "end":
return _context10.stop();
}
}, _callee10);
})));
return _context11.abrupt("return", updateUserPromise);
case 16:
case "end":
return _context10.stop();
return _context11.stop();
}
}, _callee10, null, [[5, 10]]);
}, _callee11, null, [[5, 10]]);
}));

@@ -996,27 +1031,27 @@ function updateUserUsingInitializeValuesProducer(_x27, _x28, _x29) {

value: (function () {
var _updateStatsigClientUser = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(initializeValuesPromise, identifiers, customAttributes) {
var _updateStatsigClientUser = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(initializeValuesPromise, identifiers, customAttributes) {
var initializeValues, user, _FeatureGates$initOpt2, _FeatureGates$initOpt3, errMsg, success;
return _regeneratorRuntime.wrap(function _callee11$(_context11) {
while (1) switch (_context11.prev = _context11.next) {
return _regeneratorRuntime.wrap(function _callee12$(_context12) {
while (1) switch (_context12.prev = _context12.next) {
case 0:
_context11.prev = 0;
_context11.next = 3;
_context12.prev = 0;
_context12.next = 3;
return initializeValuesPromise;
case 3:
initializeValues = _context11.sent;
initializeValues = _context12.sent;
user = FeatureGates.toStatsigUser(identifiers, initializeValues.customAttributesFromFetch);
_context11.next = 12;
_context12.next = 12;
break;
case 7:
_context11.prev = 7;
_context11.t0 = _context11["catch"](0);
_context12.prev = 7;
_context12.t0 = _context12["catch"](0);
// Make sure the updateUserCompletionCallback is called for any errors in our custom code.
// This is not necessary for the updateUserWithValues call, because the Statsig client will already invoke the callback itself.
errMsg = _context11.t0 instanceof Error ? _context11.t0.message : JSON.stringify(_context11.t0);
errMsg = _context12.t0 instanceof Error ? _context12.t0.message : JSON.stringify(_context12.t0);
(_FeatureGates$initOpt2 = (_FeatureGates$initOpt3 = FeatureGates.initOptions).updateUserCompletionCallback) === null || _FeatureGates$initOpt2 === void 0 || _FeatureGates$initOpt2.call(_FeatureGates$initOpt3, false, errMsg);
throw _context11.t0;
throw _context12.t0;
case 12:
success = Statsig.updateUserWithValues(user, initializeValues.experimentValues);
if (!success) {
_context11.next = 18;
_context12.next = 19;
break;

@@ -1026,11 +1061,12 @@ }

FeatureGates.currentAttributes = customAttributes;
_context11.next = 19;
FeatureGates.subscriptions.anyUpdated();
_context12.next = 20;
break;
case 18:
case 19:
throw new Error('Failed to update user. An unexpected error occured.');
case 19:
case 20:
case "end":
return _context11.stop();
return _context12.stop();
}
}, _callee11, null, [[0, 7]]);
}, _callee12, null, [[0, 7]]);
}));

@@ -1100,7 +1136,7 @@ function updateStatsigClientUser(_x30, _x31, _x32) {

}
var ascendingKeyOrder = function ascendingKeyOrder(_ref2, _ref3) {
var _ref4 = _slicedToArray(_ref2, 1),
key1 = _ref4[0];
var ascendingKeyOrder = function ascendingKeyOrder(_ref3, _ref4) {
var _ref5 = _slicedToArray(_ref3, 1),
key2 = _ref5[0];
key1 = _ref5[0];
var _ref6 = _slicedToArray(_ref4, 1),
key2 = _ref6[0];
return key1.localeCompare(key2);

@@ -1229,2 +1265,3 @@ };

_defineProperty(FeatureGates, "initCompleted", false);
_defineProperty(FeatureGates, "initWithDefaults", false);
_defineProperty(FeatureGates, "hasGetExperimentErrorOccurred", false);

@@ -1231,0 +1268,0 @@ _defineProperty(FeatureGates, "hasGetExperimentValueErrorOccurred", false);

/// <reference types="node" />
export var CLIENT_VERSION = "4.20.0";
export var CLIENT_VERSION = "4.20.1";

@@ -24,2 +24,3 @@ import { DynamicConfig, Layer, type LocalOverrides } from 'statsig-js-lite';

private static initCompleted;
private static initWithDefaults;
private static currentIdentifiers;

@@ -33,3 +34,3 @@ private static currentAttributes?;

private static provider;
private static subscriptions;
private static readonly subscriptions;
/**

@@ -70,2 +71,3 @@ * @description

static initializeWithProvider(clientOptions: BaseClientOptions, provider: Provider, identifiers: Identifiers, customAttributes?: CustomAttributes): Promise<void>;
private static applyUpdateCallback;
private static fireClientEvent;

@@ -72,0 +74,0 @@ static initializeFromValues(clientOptions: FromValuesClientOptions, identifiers: Identifiers, customAttributes?: CustomAttributes, initializeValues?: Record<string, unknown>): Promise<void>;

@@ -111,7 +111,8 @@ import { type StatsigOptions } from 'statsig-js-lite';

setClientVersion: (clientVersion: string) => void;
setProfile: (clientOptions: BaseClientOptions, identifiers: Identifiers, customAttributes?: CustomAttributes) => Promise<void>;
setApplyUpdateCallback?: (applyUpdate: (experimentsResult: FrontendExperimentsResult) => void) => void;
getExperimentValues: (clientOptions: BaseClientOptions, identifiers: Identifiers, customAttributes?: CustomAttributes) => Promise<FrontendExperimentsResult>;
getClientSdkKey: (clientOptions: BaseClientOptions) => Promise<string>;
getExperimentValues: () => Promise<FrontendExperimentsResult>;
getClientSdkKey: () => Promise<string>;
getApiKey?: () => string;
}
export {};

@@ -24,2 +24,3 @@ import { DynamicConfig, Layer, type LocalOverrides } from 'statsig-js-lite';

private static initCompleted;
private static initWithDefaults;
private static currentIdentifiers;

@@ -33,3 +34,3 @@ private static currentAttributes?;

private static provider;
private static subscriptions;
private static readonly subscriptions;
/**

@@ -70,2 +71,3 @@ * @description

static initializeWithProvider(clientOptions: BaseClientOptions, provider: Provider, identifiers: Identifiers, customAttributes?: CustomAttributes): Promise<void>;
private static applyUpdateCallback;
private static fireClientEvent;

@@ -72,0 +74,0 @@ static initializeFromValues(clientOptions: FromValuesClientOptions, identifiers: Identifiers, customAttributes?: CustomAttributes, initializeValues?: Record<string, unknown>): Promise<void>;

@@ -111,7 +111,8 @@ import { type StatsigOptions } from 'statsig-js-lite';

setClientVersion: (clientVersion: string) => void;
setProfile: (clientOptions: BaseClientOptions, identifiers: Identifiers, customAttributes?: CustomAttributes) => Promise<void>;
setApplyUpdateCallback?: (applyUpdate: (experimentsResult: FrontendExperimentsResult) => void) => void;
getExperimentValues: (clientOptions: BaseClientOptions, identifiers: Identifiers, customAttributes?: CustomAttributes) => Promise<FrontendExperimentsResult>;
getClientSdkKey: (clientOptions: BaseClientOptions) => Promise<string>;
getExperimentValues: () => Promise<FrontendExperimentsResult>;
getClientSdkKey: () => Promise<string>;
getApiKey?: () => string;
}
export {};
{
"name": "@atlaskit/feature-gate-js-client",
"version": "4.20.0",
"version": "4.20.1",
"description": "Atlassians wrapper for the Statsig js-lite client.",

@@ -5,0 +5,0 @@ "author": "Atlassian Pty Ltd",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc