@statsig/client-core 0.0.1-beta.2 → 0.0.1-beta.3

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@statsig/client-core",
3
- "version": "0.0.1-beta.2",
3
+ "version": "0.0.1-beta.3",
4
4
  "dependencies": {},
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
package/src/StableID.js CHANGED
@@ -64,7 +64,7 @@ exports.StableID = {
64
64
  },
65
65
  };
66
66
  function _getStableIDStorageKey(sdkKey) {
67
- return "STATSIG_STABLE_ID:".concat((0, Hashing_1.DJB2)(sdkKey));
67
+ return "statsig.stable_id:".concat((0, Hashing_1.DJB2)(sdkKey));
68
68
  }
69
69
  function _persistToStorage(stableID, sdkKey) {
70
70
  var storageKey = _getStableIDStorageKey(sdkKey);
@@ -30,8 +30,8 @@ export declare class StatsigClientBase implements StatsigClientEventEmitterInter
30
30
  protected _setStatus(newStatus: StatsigLoadingStatus): void;
31
31
  protected _getDataFromProviders(user?: StatsigUser): DataProviderResult;
32
32
  protected _getDataFromProvidersAsync(user?: StatsigUser): Promise<DataProviderResult>;
33
- protected _getDataPostInitFromProviders(user?: StatsigUser): Promise<DataProviderResult>;
34
- protected _saveToDataProviders(data: string | null, user?: StatsigUser): void;
33
+ protected _getDataPostInitFromProviders(currentData: string | null, user?: StatsigUser): Promise<DataProviderResult>;
34
+ protected _saveToDataProviders(currentData: string | null, user?: StatsigUser): void;
35
35
  protected _enqueueExposure(options: EvaluationOptions, exposure: StatsigEventInternal): void;
36
36
  }
37
37
  export {};
@@ -67,7 +67,7 @@ var StatsigClientBase = /** @class */ (function () {
67
67
  var instances = (_a = __STATSIG__.instances) !== null && _a !== void 0 ? _a : new Set();
68
68
  instances.add(this);
69
69
  __STATSIG__.instances = instances;
70
- Log_1.Log.level = (_b = options === null || options === void 0 ? void 0 : options.logLevel) !== null && _b !== void 0 ? _b : Log_1.LogLevel.Error;
70
+ Log_1.Log.level = (_b = options === null || options === void 0 ? void 0 : options.logLevel) !== null && _b !== void 0 ? _b : Log_1.LogLevel.Warn;
71
71
  this._dataProviders = dataProviders;
72
72
  }
73
73
  StatsigClientBase.prototype.on = function (event, listener) {
@@ -155,7 +155,7 @@ var StatsigClientBase = /** @class */ (function () {
155
155
  });
156
156
  });
157
157
  };
158
- StatsigClientBase.prototype._getDataPostInitFromProviders = function (user) {
158
+ StatsigClientBase.prototype._getDataPostInitFromProviders = function (currentData, user) {
159
159
  var _a, e_2, _b, _c;
160
160
  var _d;
161
161
  return __awaiter(this, void 0, void 0, function () {
@@ -172,7 +172,7 @@ var StatsigClientBase = /** @class */ (function () {
172
172
  _c = _g.value;
173
173
  _e = false;
174
174
  provider = _c;
175
- return [4 /*yield*/, ((_d = provider.getDataPostInit) === null || _d === void 0 ? void 0 : _d.call(provider, this._sdkKey, user))];
175
+ return [4 /*yield*/, ((_d = provider.getDataPostInit) === null || _d === void 0 ? void 0 : _d.call(provider, this._sdkKey, currentData, user))];
176
176
  case 3:
177
177
  data = _h.sent();
178
178
  if (data) {
@@ -204,18 +204,18 @@ var StatsigClientBase = /** @class */ (function () {
204
204
  });
205
205
  });
206
206
  };
207
- StatsigClientBase.prototype._saveToDataProviders = function (data, user) {
207
+ StatsigClientBase.prototype._saveToDataProviders = function (currentData, user) {
208
208
  var _this = this;
209
209
  (function () { return __awaiter(_this, void 0, void 0, function () {
210
- var localResult, _a, _b, _c, provider, e_3_1;
210
+ var latest, data, _a, _b, _c, provider, e_3_1;
211
211
  var _d, e_3, _e, _f;
212
212
  var _g, _h;
213
213
  return __generator(this, function (_j) {
214
214
  switch (_j.label) {
215
- case 0: return [4 /*yield*/, this._getDataPostInitFromProviders(user)];
215
+ case 0: return [4 /*yield*/, this._getDataPostInitFromProviders(currentData, user)];
216
216
  case 1:
217
- localResult = _j.sent();
218
- data = (_g = localResult.data) !== null && _g !== void 0 ? _g : data;
217
+ latest = _j.sent();
218
+ data = (_g = latest.data) !== null && _g !== void 0 ? _g : currentData;
219
219
  if (!data) {
220
220
  return [2 /*return*/];
221
221
  }
@@ -3,7 +3,7 @@ export type DataSource = 'Uninitialized' | 'Loading' | 'NoValues' | 'Cache' | 'N
3
3
  export type StatsigDataProvider = {
4
4
  readonly getData?: (sdkKey: string, user?: StatsigUser) => string | null;
5
5
  readonly getDataAsync?: (sdkKey: string, user?: StatsigUser) => Promise<string | null>;
6
- readonly getDataPostInit?: (sdkKey: string, user?: StatsigUser) => Promise<string | null>;
6
+ readonly getDataPostInit?: (sdkKey: string, currentData: string | null, user?: StatsigUser) => Promise<string | null>;
7
7
  readonly setDataPostInit?: (sdkKey: string, data: string, user?: StatsigUser) => Promise<void>;
8
8
  readonly source: DataSource;
9
9
  };
@@ -12,7 +12,7 @@ var __assign = (this && this.__assign) || function () {
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.StatsigMetadataProvider = void 0;
15
- var SDK_VERSION = '0.0.1-beta.2';
15
+ var SDK_VERSION = '0.0.1-beta.3';
16
16
  var metadata = {
17
17
  sdkVersion: SDK_VERSION,
18
18
  sdkType: 'js-mono', // js-mono is overwritten by Precomp and OnDevice clients
@@ -18,7 +18,7 @@ export type StatsigOptionsCommon = {
18
18
  overrideStableID?: string;
19
19
  /**
20
20
  * How much information is allowed to be printed to the console.
21
- * Default: LogLevel.Error
21
+ * Default: LogLevel.Warn
22
22
  */
23
23
  logLevel?: LogLevel;
24
24
  /**
@@ -16,22 +16,22 @@ function normalizeUser(original, environment) {
16
16
  }
17
17
  exports.normalizeUser = normalizeUser;
18
18
  function getUserStorageKey(sdkKey, user) {
19
- var _a, _b;
20
- var parts = [
21
- "uid:".concat((_a = user === null || user === void 0 ? void 0 : user.userID) !== null && _a !== void 0 ? _a : ''),
22
- "cids:".concat(Object.entries((_b = user === null || user === void 0 ? void 0 : user.customIDs) !== null && _b !== void 0 ? _b : {})
23
- .sort(function (_a, _b) {
24
- var leftKey = _a[0];
25
- var rightKey = _b[0];
26
- return leftKey.localeCompare(rightKey);
27
- })
28
- .map(function (_a) {
29
- var key = _a[0], value = _a[1];
30
- return "".concat(key, "-").concat(value);
31
- })
32
- .join(',')),
33
- "k:".concat(sdkKey),
34
- ];
35
- return (0, Hashing_1.DJB2)(parts.join('|'));
19
+ var key = (0, Hashing_1.DJB2)(JSON.stringify(_getSortedObject({ sdkKey: sdkKey, user: user })));
20
+ return "statsig.user_cache.".concat(key);
36
21
  }
37
22
  exports.getUserStorageKey = getUserStorageKey;
23
+ function _getSortedObject(object) {
24
+ if (object == null) {
25
+ return null;
26
+ }
27
+ var keys = Object.keys(object).sort();
28
+ var sortedObject = {};
29
+ keys.forEach(function (key) {
30
+ var value = object[key];
31
+ if (value instanceof Object) {
32
+ value = _getSortedObject(value);
33
+ }
34
+ sortedObject[key] = value;
35
+ });
36
+ return sortedObject;
37
+ }
@@ -24,12 +24,15 @@ var VisibilityChangeObserver = /** @class */ (function () {
24
24
  this._listeners.forEach(function (l) { return l.onVisibilityChanged(visibility); });
25
25
  };
26
26
  VisibilityChangeObserver._listeners = [];
27
- VisibilityChangeObserver._current = null;
27
+ VisibilityChangeObserver._current = 'foreground';
28
28
  return VisibilityChangeObserver;
29
29
  }());
30
30
  exports.VisibilityChangeObserver = VisibilityChangeObserver;
31
31
  if (typeof window !== 'undefined' &&
32
32
  typeof window.addEventListener === 'function') {
33
+ window.addEventListener('focus', function () {
34
+ return VisibilityChangeObserver.notify('foreground');
35
+ });
33
36
  window.addEventListener('blur', function () {
34
37
  return VisibilityChangeObserver.notify('background');
35
38
  });