@statsig/client-core 3.3.0-beta.1 → 3.3.0-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": "3.3.0-beta.1",
3
+ "version": "3.3.0-beta.3",
4
4
  "dependencies": {},
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -69,7 +69,11 @@ class ErrorBoundary {
69
69
  }
70
70
  this._seen.add(name);
71
71
  if ((_b = (_a = this._options) === null || _a === void 0 ? void 0 : _a.networkConfig) === null || _b === void 0 ? void 0 : _b.preventAllNetworkTraffic) {
72
- (_c = this._emitter) === null || _c === void 0 ? void 0 : _c.call(this, { name: 'error', error });
72
+ (_c = this._emitter) === null || _c === void 0 ? void 0 : _c.call(this, {
73
+ name: 'error',
74
+ error,
75
+ tag,
76
+ });
73
77
  return;
74
78
  }
75
79
  const sdkType = SDKType_1.SDKType._get(this._sdkKey);
@@ -87,7 +91,11 @@ class ErrorBoundary {
87
91
  },
88
92
  body,
89
93
  });
90
- (_g = this._emitter) === null || _g === void 0 ? void 0 : _g.call(this, { name: 'error', error });
94
+ (_g = this._emitter) === null || _g === void 0 ? void 0 : _g.call(this, {
95
+ name: 'error',
96
+ error,
97
+ tag,
98
+ });
91
99
  });
92
100
  impl()
93
101
  .then(() => {
@@ -20,6 +20,7 @@ const SDKType_1 = require("./SDKType");
20
20
  const SafeJs_1 = require("./SafeJs");
21
21
  const SessionID_1 = require("./SessionID");
22
22
  const StableID_1 = require("./StableID");
23
+ const StatsigClientEventEmitter_1 = require("./StatsigClientEventEmitter");
23
24
  const StatsigMetadata_1 = require("./StatsigMetadata");
24
25
  const VisibilityObserving_1 = require("./VisibilityObserving");
25
26
  const DEFAULT_TIMEOUT_MS = 10000;
@@ -134,7 +135,12 @@ class NetworkCore {
134
135
  if (!retries ||
135
136
  currentAttempt > retries ||
136
137
  !RETRYABLE_CODES.has((_b = response === null || response === void 0 ? void 0 : response.status) !== null && _b !== void 0 ? _b : 500)) {
137
- (_c = this._emitter) === null || _c === void 0 ? void 0 : _c.call(this, { name: 'error', error });
138
+ (_c = this._emitter) === null || _c === void 0 ? void 0 : _c.call(this, {
139
+ name: 'error',
140
+ error,
141
+ tag: StatsigClientEventEmitter_1.ErrorTag.NetworkError,
142
+ requestArgs: args,
143
+ });
138
144
  Log_1.Log.error(`A networking error occured during ${method} request to ${populatedUrl}.`, errorMessage, error);
139
145
  return null;
140
146
  }
@@ -7,11 +7,13 @@ export declare class NetworkFallbackResolver {
7
7
  private _fallbackInfo;
8
8
  private _errorBoundary;
9
9
  private _networkOverrideFunc?;
10
+ private _cooldowns;
10
11
  constructor(options: AnyStatsigOptions);
11
12
  setErrorBoundary(errorBoundary: ErrorBoundary): void;
12
13
  tryBumpExpiryTime(sdkKey: string, url: string): void;
13
14
  getFallbackUrl(sdkKey: string, url: string): string | null;
14
15
  tryFetchUpdatedFallbackInfo(sdkKey: string, url: string, errorMessage: string | null, timedOut: boolean): Promise<boolean>;
16
+ private _updateFallbackInfoWithNewUrl;
15
17
  private _fetchFallbackUrl;
16
18
  }
17
19
  export declare function _isDefaultUrl(url: string): boolean;
@@ -15,12 +15,14 @@ const Hashing_1 = require("./Hashing");
15
15
  const Log_1 = require("./Log");
16
16
  const NetworkConfig_1 = require("./NetworkConfig");
17
17
  const StorageProvider_1 = require("./StorageProvider");
18
- const DEFAULT_TTL = 7 * 24 * 60 * 60 * 1000; // 7 days
18
+ const DEFAULT_TTL_MS = 7 * 24 * 60 * 60 * 1000; // 7 days
19
+ const COOLDOWN_TIME_MS = 4 * 60 * 60 * 1000; // 4 hours
19
20
  class NetworkFallbackResolver {
20
21
  constructor(options) {
21
22
  var _a;
22
23
  this._fallbackInfo = null;
23
24
  this._errorBoundary = null;
25
+ this._cooldowns = {};
24
26
  this._networkOverrideFunc = (_a = options.networkConfig) === null || _a === void 0 ? void 0 : _a.networkOverrideFunc;
25
27
  }
26
28
  setErrorBoundary(errorBoundary) {
@@ -36,7 +38,7 @@ class NetworkFallbackResolver {
36
38
  if (!info) {
37
39
  return;
38
40
  }
39
- info.expiryTime = Date.now() + DEFAULT_TTL;
41
+ info.expiryTime = Date.now() + DEFAULT_TTL_MS;
40
42
  _tryWriteFallbackInfoToCache(sdkKey, Object.assign(Object.assign({}, this._fallbackInfo), { [domainKey]: info }));
41
43
  }
42
44
  getFallbackUrl(sdkKey, url) {
@@ -64,43 +66,52 @@ class NetworkFallbackResolver {
64
66
  return null;
65
67
  }
66
68
  tryFetchUpdatedFallbackInfo(sdkKey, url, errorMessage, timedOut) {
67
- var _a, _b, _c, _d;
69
+ var _a;
68
70
  return __awaiter(this, void 0, void 0, function* () {
69
71
  try {
70
72
  const domainKey = _getDomainKeyFromEndpoint(url);
71
73
  if (!_isDomainFailure(errorMessage, timedOut) || !domainKey) {
72
74
  return false;
73
75
  }
76
+ if (this._cooldowns[domainKey] &&
77
+ Date.now() < this._cooldowns[domainKey]) {
78
+ return false;
79
+ }
80
+ this._cooldowns[domainKey] = Date.now() + COOLDOWN_TIME_MS;
74
81
  const newUrl = yield this._fetchFallbackUrl(domainKey);
75
82
  if (!newUrl) {
76
83
  return false;
77
84
  }
78
- const newFallbackInfo = {
79
- url: newUrl,
80
- expiryTime: Date.now() + DEFAULT_TTL,
81
- previous: [],
82
- };
83
- const previousInfo = (_a = this._fallbackInfo) === null || _a === void 0 ? void 0 : _a[domainKey];
84
- if (previousInfo) {
85
- newFallbackInfo.previous.push(...previousInfo.previous);
86
- }
87
- if (newFallbackInfo.previous.length > 10) {
88
- newFallbackInfo.previous = [];
89
- }
90
- const previousUrl = (_c = (_b = this._fallbackInfo) === null || _b === void 0 ? void 0 : _b[domainKey]) === null || _c === void 0 ? void 0 : _c.url;
91
- if (previousUrl != null) {
92
- newFallbackInfo.previous.push(previousUrl);
93
- }
94
- this._fallbackInfo = Object.assign(Object.assign({}, this._fallbackInfo), { [domainKey]: newFallbackInfo });
95
- _tryWriteFallbackInfoToCache(sdkKey, this._fallbackInfo);
85
+ this._updateFallbackInfoWithNewUrl(sdkKey, domainKey, newUrl);
96
86
  return true;
97
87
  }
98
88
  catch (error) {
99
- (_d = this._errorBoundary) === null || _d === void 0 ? void 0 : _d.logError('tryFetchUpdatedFallbackInfo', error);
89
+ (_a = this._errorBoundary) === null || _a === void 0 ? void 0 : _a.logError('tryFetchUpdatedFallbackInfo', error);
100
90
  return false;
101
91
  }
102
92
  });
103
93
  }
94
+ _updateFallbackInfoWithNewUrl(sdkKey, domainKey, newUrl) {
95
+ var _a, _b, _c;
96
+ const newFallbackInfo = {
97
+ url: newUrl,
98
+ expiryTime: Date.now() + DEFAULT_TTL_MS,
99
+ previous: [],
100
+ };
101
+ const previousInfo = (_a = this._fallbackInfo) === null || _a === void 0 ? void 0 : _a[domainKey];
102
+ if (previousInfo) {
103
+ newFallbackInfo.previous.push(...previousInfo.previous);
104
+ }
105
+ if (newFallbackInfo.previous.length > 10) {
106
+ newFallbackInfo.previous = [];
107
+ }
108
+ const previousUrl = (_c = (_b = this._fallbackInfo) === null || _b === void 0 ? void 0 : _b[domainKey]) === null || _c === void 0 ? void 0 : _c.url;
109
+ if (previousUrl != null) {
110
+ newFallbackInfo.previous.push(previousUrl);
111
+ }
112
+ this._fallbackInfo = Object.assign(Object.assign({}, this._fallbackInfo), { [domainKey]: newFallbackInfo });
113
+ _tryWriteFallbackInfoToCache(sdkKey, this._fallbackInfo);
114
+ }
104
115
  _fetchFallbackUrl(domainKey) {
105
116
  var _a, _b, _c, _d, _e, _f;
106
117
  return __awaiter(this, void 0, void 0, function* () {
@@ -2,15 +2,25 @@ import { DataAdapterResult } from './StatsigDataAdapter';
2
2
  import { DynamicConfig, Experiment, FeatureGate, Layer } from './StatsigTypes';
3
3
  import { Flatten } from './TypingUtils';
4
4
  export type StatsigLoadingStatus = 'Uninitialized' | 'Loading' | 'Ready';
5
+ export declare const ErrorTag: {
6
+ readonly NetworkError: "NetworkError";
7
+ };
8
+ export type ErrorTag = (typeof ErrorTag)[keyof typeof ErrorTag];
9
+ type ErrorEventData = {
10
+ error: unknown;
11
+ tag: ErrorTag | string;
12
+ } | {
13
+ error: unknown;
14
+ tag: 'NetworkError';
15
+ requestArgs: Record<string, unknown>;
16
+ };
5
17
  type EventNameToEventDataMap = {
6
18
  values_updated: {
7
19
  status: StatsigLoadingStatus;
8
20
  values: DataAdapterResult | null;
9
21
  };
10
22
  session_expired: object;
11
- error: {
12
- error: unknown;
13
- };
23
+ error: ErrorEventData;
14
24
  logs_flushed: {
15
25
  events: Record<string, unknown>[];
16
26
  };
@@ -34,12 +44,16 @@ type EventNameToEventDataMap = {
34
44
  *
35
45
  * `values_updated` - When the Statsig clients internal values change as the result of an initialize/update operation.
36
46
  *
47
+ * `session_expired` - When the current session has expired.
48
+ *
37
49
  * `error` - When an unexpected error occurs within the Statsig client.
38
50
  *
39
51
  * `logs_flushed` - When queued StatsigEvents are flushed to Statsig servers.
40
52
  *
41
53
  * `pre_shutdown` - Fired just before the SDK is shutdown
42
54
  *
55
+ * `initialization_failure` - Fired when the client fails to initialize.
56
+ *
43
57
  * `gate_evaluation` - Fired when any gate is checked from the Statsig client.
44
58
  *
45
59
  * `dynamic_config_evaluation` - Fired when any dyanamic config is checked from the Statsig client.
@@ -1,2 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ErrorTag = void 0;
4
+ exports.ErrorTag = {
5
+ NetworkError: 'NetworkError',
6
+ };
@@ -1,4 +1,4 @@
1
- export declare const SDK_VERSION = "3.3.0-beta.1";
1
+ export declare const SDK_VERSION = "3.3.0-beta.3";
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 = '3.3.0-beta.1';
4
+ exports.SDK_VERSION = '3.3.0-beta.3';
5
5
  let metadata = {
6
6
  sdkVersion: exports.SDK_VERSION,
7
7
  sdkType: 'js-mono', // js-mono is overwritten by Precomp and OnDevice clients