@statsig/client-core 1.5.0 → 1.7.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@statsig/client-core",
3
- "version": "1.5.0",
3
+ "version": "1.7.0",
4
4
  "dependencies": {},
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -21,7 +21,8 @@ export declare class EventLogger {
21
21
  enqueue(event: StatsigEventInternal): void;
22
22
  incrementNonExposureCount(name: string): void;
23
23
  reset(): void;
24
- shutdown(): Promise<void>;
24
+ start(): void;
25
+ stop(): Promise<void>;
25
26
  flush(): Promise<void>;
26
27
  /**
27
28
  * We 'Quick Flush' following the very first event enqueued
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.EventLogger = void 0;
13
+ const CacheKey_1 = require("./CacheKey");
13
14
  const Hashing_1 = require("./Hashing");
14
15
  const Log_1 = require("./Log");
15
16
  const NetworkConfig_1 = require("./NetworkConfig");
@@ -43,18 +44,10 @@ class EventLogger {
43
44
  this._nonExposedChecks = {};
44
45
  this._hasRunQuickFlush = false;
45
46
  this._creationTime = Date.now();
46
- EVENT_LOGGER_MAP[_sdkKey] = this;
47
47
  this._isLoggingDisabled = (_options === null || _options === void 0 ? void 0 : _options.disableLogging) === true;
48
48
  this._maxQueueSize = (_a = _options === null || _options === void 0 ? void 0 : _options.loggingBufferMaxSize) !== null && _a !== void 0 ? _a : DEFAULT_QUEUE_SIZE;
49
49
  const config = _options === null || _options === void 0 ? void 0 : _options.networkConfig;
50
50
  this._logEventUrl = (0, UrlOverrides_1._getOverridableUrl)(config === null || config === void 0 ? void 0 : config.logEventUrl, config === null || config === void 0 ? void 0 : config.api, '/rgstr', NetworkConfig_1.NetworkDefault.eventsApi);
51
- (0, VisibilityObserving_1._subscribeToVisiblityChanged)((visibility) => {
52
- if (visibility === 'background') {
53
- _safeFlushAndForget(_sdkKey);
54
- }
55
- });
56
- this._retryFailedLogs();
57
- this._startBackgroundFlushInterval();
58
51
  }
59
52
  setLoggingDisabled(isDisabled) {
60
53
  this._isLoggingDisabled = isDisabled;
@@ -77,7 +70,20 @@ class EventLogger {
77
70
  reset() {
78
71
  this._lastExposureTimeMap = {};
79
72
  }
80
- shutdown() {
73
+ start() {
74
+ if ((0, SafeJs_1._isServerEnv)()) {
75
+ return; // do not run in server environments
76
+ }
77
+ EVENT_LOGGER_MAP[this._sdkKey] = this;
78
+ (0, VisibilityObserving_1._subscribeToVisiblityChanged)((visibility) => {
79
+ if (visibility === 'background') {
80
+ _safeFlushAndForget(this._sdkKey);
81
+ }
82
+ });
83
+ this._retryFailedLogs();
84
+ this._startBackgroundFlushInterval();
85
+ }
86
+ stop() {
81
87
  return __awaiter(this, void 0, void 0, function* () {
82
88
  if (this._flushIntervalId) {
83
89
  clearInterval(this._flushIntervalId);
@@ -116,10 +122,11 @@ class EventLogger {
116
122
  return true;
117
123
  }
118
124
  const user = event.user ? event.user : { statsigEnvironment: undefined };
125
+ const userKey = (0, CacheKey_1._getUserStorageKey)(this._sdkKey, user);
119
126
  const metadata = event.metadata ? event.metadata : {};
120
127
  const key = [
121
128
  event.eventName,
122
- user.userID,
129
+ userKey,
123
130
  metadata['gate'],
124
131
  metadata['config'],
125
132
  metadata['ruleID'],
@@ -256,9 +263,6 @@ class EventLogger {
256
263
  }
257
264
  _startBackgroundFlushInterval() {
258
265
  var _a, _b;
259
- if ((0, SafeJs_1._isServerEnv)()) {
260
- return; // do not run in server environments
261
- }
262
266
  const flushInterval = (_b = (_a = this._options) === null || _a === void 0 ? void 0 : _a.loggingIntervalMs) !== null && _b !== void 0 ? _b : DEFAULT_FLUSH_INTERVAL_MS;
263
267
  const intervalId = setInterval(() => {
264
268
  const logger = EVENT_LOGGER_MAP[this._sdkKey];
@@ -18,11 +18,11 @@ export type StatsigContext = {
18
18
  export declare abstract class StatsigClientBase<TAdapter extends EvaluationsDataAdapter | SpecsDataAdapter> implements StatsigClientEventEmitterInterface {
19
19
  loadingStatus: StatsigLoadingStatus;
20
20
  readonly dataAdapter: TAdapter;
21
+ readonly overrideAdapter: OverrideAdapter | null;
21
22
  protected readonly _sdkKey: string;
22
23
  protected readonly _options: AnyStatsigOptions;
23
24
  protected readonly _errorBoundary: ErrorBoundary;
24
25
  protected readonly _logger: EventLogger;
25
- protected readonly _overrideAdapter: OverrideAdapter | null;
26
26
  private _listeners;
27
27
  constructor(sdkKey: string, adapter: TAdapter, network: NetworkCore, options: AnyStatsigOptions | null);
28
28
  /**
@@ -30,7 +30,7 @@ class StatsigClientBase {
30
30
  SessionID_1.StatsigSession.overrideInitialSessionID(options.initialSessionID, sdkKey);
31
31
  this._sdkKey = sdkKey;
32
32
  this._options = options !== null && options !== void 0 ? options : {};
33
- this._overrideAdapter = (_a = options === null || options === void 0 ? void 0 : options.overrideAdapter) !== null && _a !== void 0 ? _a : null;
33
+ this.overrideAdapter = (_a = options === null || options === void 0 ? void 0 : options.overrideAdapter) !== null && _a !== void 0 ? _a : null;
34
34
  this._logger = new EventLogger_1.EventLogger(sdkKey, emitter, network, options);
35
35
  this._errorBoundary = new ErrorBoundary_1.ErrorBoundary(sdkKey, options, emitter);
36
36
  this._errorBoundary.wrap(this);
@@ -83,7 +83,7 @@ class StatsigClientBase {
83
83
  shutdown() {
84
84
  return __awaiter(this, void 0, void 0, function* () {
85
85
  this.$emt({ name: 'pre_shutdown' });
86
- yield this._logger.shutdown();
86
+ yield this._logger.stop();
87
87
  });
88
88
  }
89
89
  /**
@@ -1,4 +1,4 @@
1
- export declare const SDK_VERSION = "1.5.0";
1
+ export declare const SDK_VERSION = "1.7.0";
2
2
  export type StatsigMetadata = {
3
3
  readonly [key: string]: string | undefined;
4
4
  readonly appVersion?: string;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StatsigMetadataProvider = exports.SDK_VERSION = void 0;
4
- exports.SDK_VERSION = '1.5.0';
4
+ exports.SDK_VERSION = '1.7.0';
5
5
  let metadata = {
6
6
  sdkVersion: exports.SDK_VERSION,
7
7
  sdkType: 'js-mono', // js-mono is overwritten by Precomp and OnDevice clients