@statsig/client-core 0.0.1-beta.33 → 0.0.1-beta.35

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.33",
3
+ "version": "0.0.1-beta.35",
4
4
  "dependencies": {},
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -24,14 +24,12 @@ export declare class EventLogger {
24
24
  reset(): void;
25
25
  shutdown(): Promise<void>;
26
26
  flush(): Promise<void>;
27
- private _onVisibilityChanged;
28
27
  /**
29
28
  * We 'Quick Flush' following the very first event enqueued
30
29
  * within the quick flush window
31
30
  */
32
31
  private _quickFlushIfNeeded;
33
32
  private _shouldLogEvent;
34
- private _flushAndForget;
35
33
  private _sendEvents;
36
34
  private _sendEventsViaPost;
37
35
  private _sendEventsViaBeacon;
@@ -26,6 +26,13 @@ const MAX_DEDUPER_KEYS = 1000;
26
26
  const DEDUPER_WINDOW_DURATION_MS = 60000;
27
27
  const MAX_FAILED_LOGS = 500;
28
28
  const QUICK_FLUSH_WINDOW_MS = 200;
29
+ const EVENT_LOGGER_MAP = {};
30
+ const _safeFlushAndForget = (sdkKey) => {
31
+ var _a;
32
+ (_a = EVENT_LOGGER_MAP[sdkKey]) === null || _a === void 0 ? void 0 : _a.flush().catch(() => {
33
+ // noop
34
+ });
35
+ };
29
36
  class EventLogger {
30
37
  constructor(_sdkKey, _emitter, _network, _options) {
31
38
  var _a, _b;
@@ -38,14 +45,27 @@ class EventLogger {
38
45
  this._nonExposedChecks = {};
39
46
  this._hasRunQuickFlush = false;
40
47
  this._creationTime = Date.now();
48
+ EVENT_LOGGER_MAP[_sdkKey] = this;
41
49
  this._isLoggingDisabled = (_options === null || _options === void 0 ? void 0 : _options.disableLogging) === true;
42
50
  this._maxQueueSize = (_a = _options === null || _options === void 0 ? void 0 : _options.loggingBufferMaxSize) !== null && _a !== void 0 ? _a : DEFAULT_QUEUE_SIZE;
43
51
  const flushInterval = (_b = _options === null || _options === void 0 ? void 0 : _options.loggingIntervalMs) !== null && _b !== void 0 ? _b : DEFAULT_FLUSH_INTERVAL_MS;
44
- this._flushTimer = setInterval(() => this._flushAndForget(), flushInterval);
52
+ const intervalId = setInterval(() => {
53
+ const logger = EVENT_LOGGER_MAP[_sdkKey];
54
+ if (!logger) {
55
+ clearInterval(intervalId);
56
+ return;
57
+ }
58
+ _safeFlushAndForget(_sdkKey);
59
+ }, flushInterval);
60
+ this._flushTimer = intervalId;
45
61
  const config = _options === null || _options === void 0 ? void 0 : _options.networkConfig;
46
62
  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', NetworkDefaults_1.NetworkDefault.eventsApi);
47
63
  this._logEventBeaconUrl = (0, UrlOverrides_1._getOverridableUrl)(config === null || config === void 0 ? void 0 : config.logEventBeaconUrl, config === null || config === void 0 ? void 0 : config.api, '/log_event_beacon', NetworkDefaults_1.NetworkDefault.eventsApi);
48
- (0, VisibilityObserving_1._subscribeToVisiblityChanged)(this._onVisibilityChanged.bind(this));
64
+ (0, VisibilityObserving_1._subscribeToVisiblityChanged)((visibility) => {
65
+ if (visibility === 'background') {
66
+ _safeFlushAndForget(_sdkKey);
67
+ }
68
+ });
49
69
  this._retryFailedLogs();
50
70
  }
51
71
  setLoggingDisabled(isDisabled) {
@@ -58,7 +78,7 @@ class EventLogger {
58
78
  this._normalizeAndAppendEvent(event);
59
79
  this._quickFlushIfNeeded();
60
80
  if (this._queue.length > this._maxQueueSize) {
61
- this._flushAndForget();
81
+ _safeFlushAndForget(this._sdkKey);
62
82
  }
63
83
  }
64
84
  incrementNonExposureCount(name) {
@@ -89,11 +109,6 @@ class EventLogger {
89
109
  yield this._sendEvents(events);
90
110
  });
91
111
  }
92
- _onVisibilityChanged(visibility) {
93
- if (visibility === 'background') {
94
- this._flushAndForget();
95
- }
96
- }
97
112
  /**
98
113
  * We 'Quick Flush' following the very first event enqueued
99
114
  * within the quick flush window
@@ -106,7 +121,7 @@ class EventLogger {
106
121
  if (Date.now() - this._creationTime > QUICK_FLUSH_WINDOW_MS) {
107
122
  return;
108
123
  }
109
- setTimeout(() => this._flushAndForget(), QUICK_FLUSH_WINDOW_MS);
124
+ setTimeout(() => _safeFlushAndForget(this._sdkKey), QUICK_FLUSH_WINDOW_MS);
110
125
  }
111
126
  _shouldLogEvent(event) {
112
127
  var _a, _b, _c, _d;
@@ -131,11 +146,6 @@ class EventLogger {
131
146
  this._lastExposureTimeMap[key] = now;
132
147
  return true;
133
148
  }
134
- _flushAndForget() {
135
- this.flush().catch(() => {
136
- // noop
137
- });
138
- }
139
149
  _sendEvents(events) {
140
150
  return __awaiter(this, void 0, void 0, function* () {
141
151
  if (this._isLoggingDisabled) {
@@ -1,4 +1,4 @@
1
- export declare const SDK_VERSION = "0.0.1-beta.33";
1
+ export declare const SDK_VERSION = "0.0.1-beta.35";
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 = '0.0.1-beta.33';
4
+ exports.SDK_VERSION = '0.0.1-beta.35';
5
5
  let metadata = {
6
6
  sdkVersion: exports.SDK_VERSION,
7
7
  sdkType: 'js-mono', // js-mono is overwritten by Precomp and OnDevice clients