@atlaskit/feature-gate-js-client
Advanced tools
Comparing version
# @atlaskit/feature-gate-js-client | ||
## 4.26.0 | ||
### Minor Changes | ||
- [#116594](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/116594) | ||
[`0390682da69b2`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/0390682da69b2) - - | ||
Added ability to control the local storage key where overrides are saved per Client | ||
- Setting overrides now no longer requires the client to be initialised | ||
- Fixed an issue when reading overrides from local storage (hashes are now set) | ||
- Fixed an issue with polling updates not being applied in the client | ||
- **Please note that this bug existed between `4.23.3` and this version** | ||
### Patch Changes | ||
- [#117445](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/117445) | ||
[`af35867237785`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/af35867237785) - | ||
Fixed gates evaluating with reason "stable ID mismatch". | ||
## 4.25.2 | ||
@@ -4,0 +22,0 @@ |
@@ -13,3 +13,3 @@ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; | ||
import { NoFetchDataAdapter } from './NoFetchDataAdapter'; | ||
import { PersistentOverrideAdapter } from './PersistentOverrideAdapter'; | ||
import { LOCAL_STORAGE_KEY, PersistentOverrideAdapter } from './PersistentOverrideAdapter'; | ||
import { FeatureGateEnvironment, PerimeterType } from './types'; | ||
@@ -22,3 +22,5 @@ import { getOptionsWithDefaults, migrateInitializationOptions, shallowEquals, toStatsigUser } from './utils'; | ||
export class Client { | ||
constructor() { | ||
constructor({ | ||
localStorageKey = LOCAL_STORAGE_KEY | ||
} = {}) { | ||
_defineProperty(this, "initPromise", null); | ||
@@ -40,3 +42,2 @@ /** True if an initialize method was called and completed successfully. */ | ||
_defineProperty(this, "dataAdapter", new NoFetchDataAdapter()); | ||
_defineProperty(this, "overrideAdapter", new PersistentOverrideAdapter()); | ||
/** | ||
@@ -55,3 +56,5 @@ * Call this if modifying the values being served by the Statsig library since it has its own | ||
}); | ||
this.overrideAdapter = new PersistentOverrideAdapter(localStorageKey); | ||
} | ||
/** | ||
@@ -126,3 +129,3 @@ * @description | ||
if (this.provider.setApplyUpdateCallback) { | ||
this.provider.setApplyUpdateCallback(this.applyUpdateCallback); | ||
this.provider.setApplyUpdateCallback(this.applyUpdateCallback.bind(this)); | ||
} | ||
@@ -492,7 +495,7 @@ this.initPromise = this.initWithProvider(clientOptionsWithDefaults, provider, identifiers, customAttributes).then(() => { | ||
overrideGate(gateName, value) { | ||
this.assertInitialized(this.statsigClient); | ||
this.overrideAdapter.overrideGate(gateName, value); | ||
// Trigger a reset of the memoized gate value | ||
if (this.user) { | ||
this.statsigClient.updateUserSync(this.user, { | ||
var _this$statsigClient; | ||
(_this$statsigClient = this.statsigClient) === null || _this$statsigClient === void 0 || _this$statsigClient.updateUserSync(this.user, { | ||
disableBackgroundCacheRefresh: true | ||
@@ -508,3 +511,2 @@ }); | ||
clearGateOverride(gateName) { | ||
this.assertInitialized(this.statsigClient); | ||
this.overrideAdapter.removeGateOverride(gateName); | ||
@@ -530,3 +532,2 @@ this.statsigValuesUpdated(); | ||
overrideConfig(experimentName, values) { | ||
this.assertInitialized(this.statsigClient); | ||
this.overrideAdapter.overrideDynamicConfig(experimentName, values); | ||
@@ -541,3 +542,2 @@ this.statsigValuesUpdated(); | ||
clearConfigOverride(experimentName) { | ||
this.assertInitialized(this.statsigClient); | ||
this.overrideAdapter.removeDynamicConfigOverride(experimentName); | ||
@@ -561,3 +561,2 @@ this.statsigValuesUpdated(); | ||
setOverrides(overrides) { | ||
this.assertInitialized(this.statsigClient); | ||
this.overrideAdapter.setOverrides(overrides); | ||
@@ -571,3 +570,2 @@ this.statsigValuesUpdated(); | ||
getOverrides() { | ||
this.assertInitialized(this.statsigClient); | ||
return this.overrideAdapter.getOverrides(); | ||
@@ -580,3 +578,2 @@ } | ||
clearAllOverrides() { | ||
this.assertInitialized(this.statsigClient); | ||
this.overrideAdapter.removeAllOverrides(); | ||
@@ -748,3 +745,2 @@ this.statsigValuesUpdated(); | ||
this.overrideAdapter.initFromStoredOverrides(); | ||
this.user = toStatsigUser(identifiers, customAttributes); | ||
this.currentIdentifiers = identifiers; | ||
@@ -772,2 +768,4 @@ this.currentAttributes = customAttributes; | ||
restClientOptions = _objectWithoutProperties(newClientOptions, _excluded); | ||
this.sdkKey = sdkKey; | ||
this.user = toStatsigUser(identifiers, customAttributes, this.sdkKey); | ||
const statsigOptions = _objectSpread(_objectSpread({}, restClientOptions), {}, { | ||
@@ -862,3 +860,3 @@ environment: { | ||
initializeValues = await initializeValuesPromise; | ||
user = toStatsigUser(identifiers, initializeValues.customAttributesFromFetch); | ||
user = toStatsigUser(identifiers, initializeValues.customAttributesFromFetch, this.sdkKey); | ||
} catch (err) { | ||
@@ -865,0 +863,0 @@ var _updateUserCompletion, _ref; |
@@ -23,8 +23,9 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty"; | ||
export class PersistentOverrideAdapter { | ||
constructor() { | ||
constructor(localStorageKey) { | ||
this._overrides = makeEmptyStore(); | ||
this._localStorageKey = localStorageKey; | ||
} | ||
parseStoredOverrides(localStorageKey) { | ||
try { | ||
const json = window.localStorage.getItem(LOCAL_STORAGE_KEY); | ||
const json = window.localStorage.getItem(localStorageKey); | ||
if (!json) { | ||
@@ -41,9 +42,12 @@ return makeEmptyStore(); | ||
for (const overrides of allOverrides) { | ||
for (const [name, value] of Object.entries(overrides.gates)) { | ||
for (const [name, value] of Object.entries((_overrides$gates = overrides.gates) !== null && _overrides$gates !== void 0 ? _overrides$gates : {})) { | ||
var _overrides$gates; | ||
merged.gates[name] = value; | ||
} | ||
for (const [name, value] of Object.entries(overrides.configs)) { | ||
for (const [name, value] of Object.entries((_overrides$configs = overrides.configs) !== null && _overrides$configs !== void 0 ? _overrides$configs : {})) { | ||
var _overrides$configs; | ||
merged.configs[name] = value; | ||
} | ||
for (const [name, value] of Object.entries(overrides.layers)) { | ||
for (const [name, value] of Object.entries((_overrides$layers = overrides.layers) !== null && _overrides$layers !== void 0 ? _overrides$layers : {})) { | ||
var _overrides$layers; | ||
merged.layers[name] = value; | ||
@@ -55,6 +59,11 @@ } | ||
initFromStoredOverrides() { | ||
this._overrides = this.mergeOverrides(this.parseStoredOverrides(LEGACY_LOCAL_STORAGE_KEY), this.parseStoredOverrides(LOCAL_STORAGE_KEY)); | ||
this.setOverrides(this.mergeOverrides(this._overrides, this.parseStoredOverrides(LEGACY_LOCAL_STORAGE_KEY), this.parseStoredOverrides(this._localStorageKey))); | ||
} | ||
saveOverrides() { | ||
window.localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(this._overrides)); | ||
try { | ||
window.localStorage.setItem(this._localStorageKey, JSON.stringify(this._overrides)); | ||
} catch (_unused2) { | ||
// ignored - window is not defined in non-browser environments, and we don't save things there | ||
// (things like SSR, etc) | ||
} | ||
} | ||
@@ -61,0 +70,0 @@ getOverrides() { |
@@ -6,2 +6,3 @@ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; | ||
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } | ||
import { StableID } from '@statsig/js-client'; | ||
import { isFedRamp } from '@atlaskit/atlassian-context'; | ||
@@ -46,5 +47,7 @@ import { EvaluationReason } from './compat/types'; | ||
*/ | ||
export const toStatsigUser = (identifiers, customAttributes) => { | ||
export const toStatsigUser = (identifiers, customAttributes, sdkKey) => { | ||
const user = { | ||
customIDs: identifiers, | ||
customIDs: !(customAttributes !== null && customAttributes !== void 0 && customAttributes.stableID) && sdkKey ? _objectSpread({ | ||
stableID: StableID.get(sdkKey) | ||
}, identifiers) : identifiers, | ||
custom: customAttributes | ||
@@ -51,0 +54,0 @@ }; |
/// <reference types="node" /> | ||
export const CLIENT_VERSION = "4.25.2"; | ||
export const CLIENT_VERSION = "4.26.0"; |
@@ -13,3 +13,3 @@ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; | ||
import { NoFetchDataAdapter } from './NoFetchDataAdapter'; | ||
import { PersistentOverrideAdapter } from './PersistentOverrideAdapter'; | ||
import { LOCAL_STORAGE_KEY, PersistentOverrideAdapter } from './PersistentOverrideAdapter'; | ||
import { FeatureGateEnvironment, PerimeterType } from './types'; | ||
@@ -22,3 +22,5 @@ import { getOptionsWithDefaults, migrateInitializationOptions, shallowEquals, toStatsigUser } from './utils'; | ||
export class Client { | ||
constructor() { | ||
constructor({ | ||
localStorageKey = LOCAL_STORAGE_KEY | ||
} = {}) { | ||
_defineProperty(this, "initPromise", null); | ||
@@ -40,3 +42,2 @@ /** True if an initialize method was called and completed successfully. */ | ||
_defineProperty(this, "dataAdapter", new NoFetchDataAdapter()); | ||
_defineProperty(this, "overrideAdapter", new PersistentOverrideAdapter()); | ||
/** | ||
@@ -55,3 +56,5 @@ * Call this if modifying the values being served by the Statsig library since it has its own | ||
}); | ||
this.overrideAdapter = new PersistentOverrideAdapter(localStorageKey); | ||
} | ||
/** | ||
@@ -126,3 +129,3 @@ * @description | ||
if (this.provider.setApplyUpdateCallback) { | ||
this.provider.setApplyUpdateCallback(this.applyUpdateCallback); | ||
this.provider.setApplyUpdateCallback(this.applyUpdateCallback.bind(this)); | ||
} | ||
@@ -492,7 +495,7 @@ this.initPromise = this.initWithProvider(clientOptionsWithDefaults, provider, identifiers, customAttributes).then(() => { | ||
overrideGate(gateName, value) { | ||
this.assertInitialized(this.statsigClient); | ||
this.overrideAdapter.overrideGate(gateName, value); | ||
// Trigger a reset of the memoized gate value | ||
if (this.user) { | ||
this.statsigClient.updateUserSync(this.user, { | ||
var _this$statsigClient; | ||
(_this$statsigClient = this.statsigClient) === null || _this$statsigClient === void 0 ? void 0 : _this$statsigClient.updateUserSync(this.user, { | ||
disableBackgroundCacheRefresh: true | ||
@@ -508,3 +511,2 @@ }); | ||
clearGateOverride(gateName) { | ||
this.assertInitialized(this.statsigClient); | ||
this.overrideAdapter.removeGateOverride(gateName); | ||
@@ -530,3 +532,2 @@ this.statsigValuesUpdated(); | ||
overrideConfig(experimentName, values) { | ||
this.assertInitialized(this.statsigClient); | ||
this.overrideAdapter.overrideDynamicConfig(experimentName, values); | ||
@@ -541,3 +542,2 @@ this.statsigValuesUpdated(); | ||
clearConfigOverride(experimentName) { | ||
this.assertInitialized(this.statsigClient); | ||
this.overrideAdapter.removeDynamicConfigOverride(experimentName); | ||
@@ -561,3 +561,2 @@ this.statsigValuesUpdated(); | ||
setOverrides(overrides) { | ||
this.assertInitialized(this.statsigClient); | ||
this.overrideAdapter.setOverrides(overrides); | ||
@@ -571,3 +570,2 @@ this.statsigValuesUpdated(); | ||
getOverrides() { | ||
this.assertInitialized(this.statsigClient); | ||
return this.overrideAdapter.getOverrides(); | ||
@@ -580,3 +578,2 @@ } | ||
clearAllOverrides() { | ||
this.assertInitialized(this.statsigClient); | ||
this.overrideAdapter.removeAllOverrides(); | ||
@@ -748,3 +745,2 @@ this.statsigValuesUpdated(); | ||
this.overrideAdapter.initFromStoredOverrides(); | ||
this.user = toStatsigUser(identifiers, customAttributes); | ||
this.currentIdentifiers = identifiers; | ||
@@ -772,2 +768,4 @@ this.currentAttributes = customAttributes; | ||
restClientOptions = _objectWithoutProperties(newClientOptions, _excluded); | ||
this.sdkKey = sdkKey; | ||
this.user = toStatsigUser(identifiers, customAttributes, this.sdkKey); | ||
const statsigOptions = _objectSpread(_objectSpread({}, restClientOptions), {}, { | ||
@@ -862,3 +860,3 @@ environment: { | ||
initializeValues = await initializeValuesPromise; | ||
user = toStatsigUser(identifiers, initializeValues.customAttributesFromFetch); | ||
user = toStatsigUser(identifiers, initializeValues.customAttributesFromFetch, this.sdkKey); | ||
} catch (err) { | ||
@@ -865,0 +863,0 @@ var _updateUserCompletion, _ref; |
@@ -23,8 +23,9 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty"; | ||
export class PersistentOverrideAdapter { | ||
constructor() { | ||
constructor(localStorageKey) { | ||
this._overrides = makeEmptyStore(); | ||
this._localStorageKey = localStorageKey; | ||
} | ||
parseStoredOverrides(localStorageKey) { | ||
try { | ||
const json = window.localStorage.getItem(LOCAL_STORAGE_KEY); | ||
const json = window.localStorage.getItem(localStorageKey); | ||
if (!json) { | ||
@@ -41,9 +42,12 @@ return makeEmptyStore(); | ||
for (const overrides of allOverrides) { | ||
for (const [name, value] of Object.entries(overrides.gates)) { | ||
for (const [name, value] of Object.entries((_overrides$gates = overrides.gates) !== null && _overrides$gates !== void 0 ? _overrides$gates : {})) { | ||
var _overrides$gates; | ||
merged.gates[name] = value; | ||
} | ||
for (const [name, value] of Object.entries(overrides.configs)) { | ||
for (const [name, value] of Object.entries((_overrides$configs = overrides.configs) !== null && _overrides$configs !== void 0 ? _overrides$configs : {})) { | ||
var _overrides$configs; | ||
merged.configs[name] = value; | ||
} | ||
for (const [name, value] of Object.entries(overrides.layers)) { | ||
for (const [name, value] of Object.entries((_overrides$layers = overrides.layers) !== null && _overrides$layers !== void 0 ? _overrides$layers : {})) { | ||
var _overrides$layers; | ||
merged.layers[name] = value; | ||
@@ -55,6 +59,11 @@ } | ||
initFromStoredOverrides() { | ||
this._overrides = this.mergeOverrides(this.parseStoredOverrides(LEGACY_LOCAL_STORAGE_KEY), this.parseStoredOverrides(LOCAL_STORAGE_KEY)); | ||
this.setOverrides(this.mergeOverrides(this._overrides, this.parseStoredOverrides(LEGACY_LOCAL_STORAGE_KEY), this.parseStoredOverrides(this._localStorageKey))); | ||
} | ||
saveOverrides() { | ||
window.localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(this._overrides)); | ||
try { | ||
window.localStorage.setItem(this._localStorageKey, JSON.stringify(this._overrides)); | ||
} catch (_unused2) { | ||
// ignored - window is not defined in non-browser environments, and we don't save things there | ||
// (things like SSR, etc) | ||
} | ||
} | ||
@@ -61,0 +70,0 @@ getOverrides() { |
@@ -6,2 +6,3 @@ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; | ||
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } | ||
import { StableID } from '@statsig/js-client'; | ||
import { isFedRamp } from '@atlaskit/atlassian-context'; | ||
@@ -46,5 +47,7 @@ import { EvaluationReason } from './compat/types'; | ||
*/ | ||
export const toStatsigUser = (identifiers, customAttributes) => { | ||
export const toStatsigUser = (identifiers, customAttributes, sdkKey) => { | ||
const user = { | ||
customIDs: identifiers, | ||
customIDs: !(customAttributes !== null && customAttributes !== void 0 && customAttributes.stableID) && sdkKey ? _objectSpread({ | ||
stableID: StableID.get(sdkKey) | ||
}, identifiers) : identifiers, | ||
custom: customAttributes | ||
@@ -51,0 +54,0 @@ }; |
/// <reference types="node" /> | ||
export const CLIENT_VERSION = "4.25.2"; | ||
export const CLIENT_VERSION = "4.26.0"; |
@@ -13,3 +13,3 @@ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; | ||
import { NoFetchDataAdapter } from './NoFetchDataAdapter'; | ||
import { PersistentOverrideAdapter } from './PersistentOverrideAdapter'; | ||
import { LOCAL_STORAGE_KEY, PersistentOverrideAdapter } from './PersistentOverrideAdapter'; | ||
import { FeatureGateEnvironment, PerimeterType } from './types'; | ||
@@ -22,3 +22,5 @@ import { getOptionsWithDefaults, migrateInitializationOptions, shallowEquals, toStatsigUser } from './utils'; | ||
export class Client { | ||
constructor() { | ||
constructor({ | ||
localStorageKey = LOCAL_STORAGE_KEY | ||
} = {}) { | ||
_defineProperty(this, "initPromise", null); | ||
@@ -40,3 +42,2 @@ /** True if an initialize method was called and completed successfully. */ | ||
_defineProperty(this, "dataAdapter", new NoFetchDataAdapter()); | ||
_defineProperty(this, "overrideAdapter", new PersistentOverrideAdapter()); | ||
/** | ||
@@ -55,3 +56,5 @@ * Call this if modifying the values being served by the Statsig library since it has its own | ||
}); | ||
this.overrideAdapter = new PersistentOverrideAdapter(localStorageKey); | ||
} | ||
/** | ||
@@ -126,3 +129,3 @@ * @description | ||
if (this.provider.setApplyUpdateCallback) { | ||
this.provider.setApplyUpdateCallback(this.applyUpdateCallback); | ||
this.provider.setApplyUpdateCallback(this.applyUpdateCallback.bind(this)); | ||
} | ||
@@ -492,7 +495,7 @@ this.initPromise = this.initWithProvider(clientOptionsWithDefaults, provider, identifiers, customAttributes).then(() => { | ||
overrideGate(gateName, value) { | ||
this.assertInitialized(this.statsigClient); | ||
this.overrideAdapter.overrideGate(gateName, value); | ||
// Trigger a reset of the memoized gate value | ||
if (this.user) { | ||
this.statsigClient.updateUserSync(this.user, { | ||
var _this$statsigClient; | ||
(_this$statsigClient = this.statsigClient) === null || _this$statsigClient === void 0 || _this$statsigClient.updateUserSync(this.user, { | ||
disableBackgroundCacheRefresh: true | ||
@@ -508,3 +511,2 @@ }); | ||
clearGateOverride(gateName) { | ||
this.assertInitialized(this.statsigClient); | ||
this.overrideAdapter.removeGateOverride(gateName); | ||
@@ -530,3 +532,2 @@ this.statsigValuesUpdated(); | ||
overrideConfig(experimentName, values) { | ||
this.assertInitialized(this.statsigClient); | ||
this.overrideAdapter.overrideDynamicConfig(experimentName, values); | ||
@@ -541,3 +542,2 @@ this.statsigValuesUpdated(); | ||
clearConfigOverride(experimentName) { | ||
this.assertInitialized(this.statsigClient); | ||
this.overrideAdapter.removeDynamicConfigOverride(experimentName); | ||
@@ -561,3 +561,2 @@ this.statsigValuesUpdated(); | ||
setOverrides(overrides) { | ||
this.assertInitialized(this.statsigClient); | ||
this.overrideAdapter.setOverrides(overrides); | ||
@@ -571,3 +570,2 @@ this.statsigValuesUpdated(); | ||
getOverrides() { | ||
this.assertInitialized(this.statsigClient); | ||
return this.overrideAdapter.getOverrides(); | ||
@@ -580,3 +578,2 @@ } | ||
clearAllOverrides() { | ||
this.assertInitialized(this.statsigClient); | ||
this.overrideAdapter.removeAllOverrides(); | ||
@@ -748,3 +745,2 @@ this.statsigValuesUpdated(); | ||
this.overrideAdapter.initFromStoredOverrides(); | ||
this.user = toStatsigUser(identifiers, customAttributes); | ||
this.currentIdentifiers = identifiers; | ||
@@ -772,2 +768,4 @@ this.currentAttributes = customAttributes; | ||
restClientOptions = _objectWithoutProperties(newClientOptions, _excluded); | ||
this.sdkKey = sdkKey; | ||
this.user = toStatsigUser(identifiers, customAttributes, this.sdkKey); | ||
const statsigOptions = _objectSpread(_objectSpread({}, restClientOptions), {}, { | ||
@@ -862,3 +860,3 @@ environment: { | ||
initializeValues = await initializeValuesPromise; | ||
user = toStatsigUser(identifiers, initializeValues.customAttributesFromFetch); | ||
user = toStatsigUser(identifiers, initializeValues.customAttributesFromFetch, this.sdkKey); | ||
} catch (err) { | ||
@@ -865,0 +863,0 @@ var _updateUserCompletion, _ref; |
@@ -23,8 +23,9 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty"; | ||
export class PersistentOverrideAdapter { | ||
constructor() { | ||
constructor(localStorageKey) { | ||
this._overrides = makeEmptyStore(); | ||
this._localStorageKey = localStorageKey; | ||
} | ||
parseStoredOverrides(localStorageKey) { | ||
try { | ||
const json = window.localStorage.getItem(LOCAL_STORAGE_KEY); | ||
const json = window.localStorage.getItem(localStorageKey); | ||
if (!json) { | ||
@@ -41,9 +42,12 @@ return makeEmptyStore(); | ||
for (const overrides of allOverrides) { | ||
for (const [name, value] of Object.entries(overrides.gates)) { | ||
for (const [name, value] of Object.entries((_overrides$gates = overrides.gates) !== null && _overrides$gates !== void 0 ? _overrides$gates : {})) { | ||
var _overrides$gates; | ||
merged.gates[name] = value; | ||
} | ||
for (const [name, value] of Object.entries(overrides.configs)) { | ||
for (const [name, value] of Object.entries((_overrides$configs = overrides.configs) !== null && _overrides$configs !== void 0 ? _overrides$configs : {})) { | ||
var _overrides$configs; | ||
merged.configs[name] = value; | ||
} | ||
for (const [name, value] of Object.entries(overrides.layers)) { | ||
for (const [name, value] of Object.entries((_overrides$layers = overrides.layers) !== null && _overrides$layers !== void 0 ? _overrides$layers : {})) { | ||
var _overrides$layers; | ||
merged.layers[name] = value; | ||
@@ -55,6 +59,11 @@ } | ||
initFromStoredOverrides() { | ||
this._overrides = this.mergeOverrides(this.parseStoredOverrides(LEGACY_LOCAL_STORAGE_KEY), this.parseStoredOverrides(LOCAL_STORAGE_KEY)); | ||
this.setOverrides(this.mergeOverrides(this._overrides, this.parseStoredOverrides(LEGACY_LOCAL_STORAGE_KEY), this.parseStoredOverrides(this._localStorageKey))); | ||
} | ||
saveOverrides() { | ||
window.localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(this._overrides)); | ||
try { | ||
window.localStorage.setItem(this._localStorageKey, JSON.stringify(this._overrides)); | ||
} catch (_unused2) { | ||
// ignored - window is not defined in non-browser environments, and we don't save things there | ||
// (things like SSR, etc) | ||
} | ||
} | ||
@@ -61,0 +70,0 @@ getOverrides() { |
@@ -6,2 +6,3 @@ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; | ||
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } | ||
import { StableID } from '@statsig/js-client'; | ||
import { isFedRamp } from '@atlaskit/atlassian-context'; | ||
@@ -46,5 +47,7 @@ import { EvaluationReason } from './compat/types'; | ||
*/ | ||
export const toStatsigUser = (identifiers, customAttributes) => { | ||
export const toStatsigUser = (identifiers, customAttributes, sdkKey) => { | ||
const user = { | ||
customIDs: identifiers, | ||
customIDs: !(customAttributes !== null && customAttributes !== void 0 && customAttributes.stableID) && sdkKey ? _objectSpread({ | ||
stableID: StableID.get(sdkKey) | ||
}, identifiers) : identifiers, | ||
custom: customAttributes | ||
@@ -51,0 +54,0 @@ }; |
/// <reference types="node" /> | ||
export const CLIENT_VERSION = "4.25.2"; | ||
export const CLIENT_VERSION = "4.26.0"; |
@@ -11,2 +11,3 @@ import { StatsigClient } from '@statsig/js-client'; | ||
private initOptions?; | ||
private sdkKey?; | ||
private initPromise; | ||
@@ -32,2 +33,5 @@ /** True if an initialize method was called and completed successfully. */ | ||
private overrideAdapter; | ||
constructor({ localStorageKey }?: { | ||
localStorageKey?: string; | ||
}); | ||
/** | ||
@@ -34,0 +38,0 @@ * @description |
@@ -18,3 +18,4 @@ import { type DynamicConfig, type Experiment, type FeatureGate, type Layer, type OverrideAdapter, type StatsigUser } from '@statsig/client-core'; | ||
private _overrides; | ||
constructor(); | ||
private _localStorageKey; | ||
constructor(localStorageKey: string); | ||
private parseStoredOverrides; | ||
@@ -21,0 +22,0 @@ private mergeOverrides; |
@@ -1,2 +0,2 @@ | ||
import type { EvaluationDetails as NewEvaluationDetails, StatsigUser } from '@statsig/js-client'; | ||
import { type EvaluationDetails as NewEvaluationDetails, type StatsigUser } from '@statsig/js-client'; | ||
import { type EvaluationDetails } from './compat/types'; | ||
@@ -10,4 +10,4 @@ import { type BaseClientOptions, type CustomAttributes, type FeatureGateOptions, type Identifiers, type NewFeatureGateOptions, type OptionsWithDefaults } from './types'; | ||
*/ | ||
export declare const toStatsigUser: (identifiers: Identifiers, customAttributes?: CustomAttributes) => StatsigUser; | ||
export declare const toStatsigUser: (identifiers: Identifiers, customAttributes?: CustomAttributes, sdkKey?: string) => StatsigUser; | ||
export declare const migrateInitializationOptions: <T extends FeatureGateOptions>(options: T) => Omit<T, keyof FeatureGateOptions> & NewFeatureGateOptions; | ||
export declare const migrateEvaluationDetails: (details: NewEvaluationDetails) => EvaluationDetails; |
@@ -11,2 +11,3 @@ import { StatsigClient } from '@statsig/js-client'; | ||
private initOptions?; | ||
private sdkKey?; | ||
private initPromise; | ||
@@ -32,2 +33,5 @@ /** True if an initialize method was called and completed successfully. */ | ||
private overrideAdapter; | ||
constructor({ localStorageKey }?: { | ||
localStorageKey?: string; | ||
}); | ||
/** | ||
@@ -34,0 +38,0 @@ * @description |
@@ -18,3 +18,4 @@ import { type DynamicConfig, type Experiment, type FeatureGate, type Layer, type OverrideAdapter, type StatsigUser } from '@statsig/client-core'; | ||
private _overrides; | ||
constructor(); | ||
private _localStorageKey; | ||
constructor(localStorageKey: string); | ||
private parseStoredOverrides; | ||
@@ -21,0 +22,0 @@ private mergeOverrides; |
@@ -1,2 +0,2 @@ | ||
import type { EvaluationDetails as NewEvaluationDetails, StatsigUser } from '@statsig/js-client'; | ||
import { type EvaluationDetails as NewEvaluationDetails, type StatsigUser } from '@statsig/js-client'; | ||
import { type EvaluationDetails } from './compat/types'; | ||
@@ -10,4 +10,4 @@ import { type BaseClientOptions, type CustomAttributes, type FeatureGateOptions, type Identifiers, type NewFeatureGateOptions, type OptionsWithDefaults } from './types'; | ||
*/ | ||
export declare const toStatsigUser: (identifiers: Identifiers, customAttributes?: CustomAttributes) => StatsigUser; | ||
export declare const toStatsigUser: (identifiers: Identifiers, customAttributes?: CustomAttributes, sdkKey?: string) => StatsigUser; | ||
export declare const migrateInitializationOptions: <T extends FeatureGateOptions>(options: T) => Omit<T, keyof FeatureGateOptions> & NewFeatureGateOptions; | ||
export declare const migrateEvaluationDetails: (details: NewEvaluationDetails) => EvaluationDetails; |
{ | ||
"name": "@atlaskit/feature-gate-js-client", | ||
"version": "4.25.2", | ||
"version": "4.26.0", | ||
"description": "Atlassians wrapper for the Statsig js-lite client.", | ||
@@ -5,0 +5,0 @@ "author": "Atlassian Pty Ltd", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
811486
0.59%14062
0.33%