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

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.31",
3
+ "version": "0.0.1-beta.33",
4
4
  "dependencies": {},
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -1,4 +1,5 @@
1
1
  import { DownloadConfigSpecsResponse } from './DownloadConfigSpecsResponse';
2
+ import { ErrorBoundary } from './ErrorBoundary';
2
3
  import { DynamicConfigEvaluationOptions, ExperimentEvaluationOptions, FeatureGateEvaluationOptions, LayerEvaluationOptions } from './EvaluationOptions';
3
4
  import { InitializeResponseWithUpdates } from './InitializeResponse';
4
5
  import { StatsigClientEventEmitterInterface } from './StatsigClientEventEmitter';
@@ -18,6 +19,7 @@ export interface StatsigClientCommonInterface extends StatsigClientEventEmitterI
18
19
  export type CommonContext = {
19
20
  sdkKey: string;
20
21
  options: AnyStatsigOptions;
22
+ errorBoundary: ErrorBoundary;
21
23
  };
22
24
  export type AsyncCommonContext = {
23
25
  sessionID: string;
@@ -1,5 +1,5 @@
1
1
  import { ErrorBoundary } from './ErrorBoundary';
2
- import { DataAdapterResult } from './StatsigDataAdapter';
2
+ import { DataAdapterAsyncOptions, DataAdapterResult } from './StatsigDataAdapter';
3
3
  import { AnyStatsigOptions } from './StatsigOptionsCommon';
4
4
  import { StatsigUser } from './StatsigUser';
5
5
  export declare abstract class DataAdapterCore {
@@ -12,8 +12,6 @@ export declare abstract class DataAdapterCore {
12
12
  protected constructor(_adapterName: string, _cacheSuffix: string);
13
13
  attach(sdkKey: string, _options: AnyStatsigOptions | null): void;
14
14
  getDataSync(user?: StatsigUser | undefined): DataAdapterResult | null;
15
- getDataAsync(current: DataAdapterResult | null, user?: StatsigUser): Promise<DataAdapterResult | null>;
16
- prefetchData(user?: StatsigUser | undefined): Promise<void>;
17
15
  setData(data: string, user?: StatsigUser): void;
18
16
  /**
19
17
  * (Internal Use Only) - Used by \@statsig/react-native-bindings to prime the cache from AsyncStorage
@@ -21,6 +19,8 @@ export declare abstract class DataAdapterCore {
21
19
  * @param {Record<string, DataAdapterResult>} cache The values to merge into _inMemoryCache
22
20
  */
23
21
  __primeInMemoryCache(cache: Record<string, DataAdapterResult>): void;
22
+ protected _getDataAsyncImpl(current: DataAdapterResult | null, user?: StatsigUser, options?: DataAdapterAsyncOptions): Promise<DataAdapterResult | null>;
23
+ protected _prefetchDataImpl(user?: StatsigUser, options?: DataAdapterAsyncOptions): Promise<void>;
24
24
  protected abstract _fetchFromNetwork(current: string | null, user?: StatsigUser): Promise<string | null>;
25
25
  private _fetchLatest;
26
26
  protected _getSdkKey(): string;
@@ -12,7 +12,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.DataAdapterCore = void 0;
13
13
  const ErrorBoundary_1 = require("./ErrorBoundary");
14
14
  const Log_1 = require("./Log");
15
- const Monitoring_1 = require("./Monitoring");
16
15
  const StatsigDataAdapter_1 = require("./StatsigDataAdapter");
17
16
  const StatsigUser_1 = require("./StatsigUser");
18
17
  const StorageProvider_1 = require("./StorageProvider");
@@ -30,7 +29,6 @@ class DataAdapterCore {
30
29
  attach(sdkKey, _options) {
31
30
  this._sdkKey = sdkKey;
32
31
  this._errorBoundary = new ErrorBoundary_1.ErrorBoundary(sdkKey);
33
- (0, Monitoring_1.monitorClass)(this._errorBoundary, this);
34
32
  }
35
33
  getDataSync(user) {
36
34
  const cacheKey = this._getCacheKey(user);
@@ -45,31 +43,6 @@ class DataAdapterCore {
45
43
  }
46
44
  return null;
47
45
  }
48
- getDataAsync(current, user) {
49
- var _a;
50
- return __awaiter(this, void 0, void 0, function* () {
51
- const cache = current !== null && current !== void 0 ? current : this.getDataSync(user);
52
- const latest = yield this._fetchLatest((_a = cache === null || cache === void 0 ? void 0 : cache.data) !== null && _a !== void 0 ? _a : null, user);
53
- const cacheKey = this._getCacheKey(user);
54
- if (latest) {
55
- this._addToInMemoryCache(cacheKey, latest);
56
- }
57
- if ((latest === null || latest === void 0 ? void 0 : latest.source) === 'Network' ||
58
- (latest === null || latest === void 0 ? void 0 : latest.source) === 'NetworkNotModified') {
59
- yield this._writeToCache(cacheKey, latest);
60
- }
61
- return latest;
62
- });
63
- }
64
- prefetchData(user) {
65
- return __awaiter(this, void 0, void 0, function* () {
66
- const cacheKey = this._getCacheKey(user);
67
- const result = yield this.getDataAsync(null, user);
68
- if (result) {
69
- this._addToInMemoryCache(cacheKey, Object.assign(Object.assign({}, result), { source: 'Prefetch' }));
70
- }
71
- });
72
- }
73
46
  setData(data, user) {
74
47
  const cacheKey = this._getCacheKey(user);
75
48
  this._addToInMemoryCache(cacheKey, {
@@ -86,6 +59,29 @@ class DataAdapterCore {
86
59
  __primeInMemoryCache(cache) {
87
60
  this._inMemoryCache = Object.assign(Object.assign({}, this._inMemoryCache), cache);
88
61
  }
62
+ _getDataAsyncImpl(current, user, options) {
63
+ var _a;
64
+ return __awaiter(this, void 0, void 0, function* () {
65
+ const cache = current !== null && current !== void 0 ? current : this.getDataSync(user);
66
+ const ops = [this._fetchLatest((_a = cache === null || cache === void 0 ? void 0 : cache.data) !== null && _a !== void 0 ? _a : null, user)];
67
+ if (options === null || options === void 0 ? void 0 : options.timeoutMs) {
68
+ ops.push(new Promise((r) => setTimeout(r, options.timeoutMs)).then(() => {
69
+ Log_1.Log.debug('Fetching latest value timed out');
70
+ return null;
71
+ }));
72
+ }
73
+ return yield Promise.race(ops);
74
+ });
75
+ }
76
+ _prefetchDataImpl(user, options) {
77
+ return __awaiter(this, void 0, void 0, function* () {
78
+ const cacheKey = this._getCacheKey(user);
79
+ const result = yield this._getDataAsyncImpl(null, user, options);
80
+ if (result) {
81
+ this._addToInMemoryCache(cacheKey, Object.assign(Object.assign({}, result), { source: 'Prefetch' }));
82
+ }
83
+ });
84
+ }
89
85
  _fetchLatest(current, user) {
90
86
  return __awaiter(this, void 0, void 0, function* () {
91
87
  const latest = yield this._fetchFromNetwork(current, user);
@@ -94,17 +90,24 @@ class DataAdapterCore {
94
90
  return null;
95
91
  }
96
92
  const response = (0, TypedJsonParse_1.typedJsonParse)(latest, 'has_updates', 'Failure while attempting to persist latest value');
97
- if (current && (response === null || response === void 0 ? void 0 : response.has_updates) === false) {
98
- return {
93
+ let result = null;
94
+ if ((response === null || response === void 0 ? void 0 : response.has_updates) === true) {
95
+ result = { source: 'Network', data: latest, receivedAt: Date.now() };
96
+ }
97
+ else if (current && (response === null || response === void 0 ? void 0 : response.has_updates) === false) {
98
+ result = {
99
99
  source: 'NetworkNotModified',
100
100
  data: current,
101
101
  receivedAt: Date.now(),
102
102
  };
103
103
  }
104
- if ((response === null || response === void 0 ? void 0 : response.has_updates) !== true) {
104
+ if (!result) {
105
105
  return null;
106
106
  }
107
- return { source: 'Network', data: latest, receivedAt: Date.now() };
107
+ const cacheKey = this._getCacheKey(user);
108
+ this._addToInMemoryCache(cacheKey, result);
109
+ yield this._writeToCache(cacheKey, result);
110
+ return result;
108
111
  });
109
112
  }
110
113
  _getSdkKey() {
@@ -1,5 +1,3 @@
1
- export declare function captureDiagnostics(func: string, task: () => unknown): unknown;
2
1
  export declare abstract class Diagnostics {
3
- static mark(tag: string, metadata?: Record<string, unknown>): void;
4
- static flush(): void;
2
+ static mark(): void;
5
3
  }
@@ -1,52 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Diagnostics = exports.captureDiagnostics = void 0;
4
- const Log_1 = require("./Log");
5
- const NetworkDefaults_1 = require("./NetworkDefaults");
6
- const SUPPORTS_PERFORMANCE_API = typeof performance !== 'undefined' && typeof performance.mark !== 'undefined';
7
- let markers = [];
8
- function captureDiagnostics(func, task) {
9
- Diagnostics.mark(`${func}:start`);
10
- const result = task();
11
- const markEnd = () => {
12
- Diagnostics.mark(`${func}:end`);
13
- maybeFlush(`${func}:end`);
14
- };
15
- if (result && result instanceof Promise) {
16
- return result.finally(() => markEnd());
17
- }
18
- else {
19
- markEnd();
20
- }
21
- return result;
22
- }
23
- exports.captureDiagnostics = captureDiagnostics;
3
+ exports.Diagnostics = void 0;
24
4
  class Diagnostics {
25
- static mark(tag, metadata) {
26
- if (!SUPPORTS_PERFORMANCE_API) {
27
- return;
28
- }
29
- const marker = performance.mark(tag, { detail: metadata });
30
- markers.push(marker);
31
- }
32
- static flush() {
33
- const resources = performance
34
- .getEntriesByType('resource')
35
- .filter((resource) => resource.name.startsWith(NetworkDefaults_1.NetworkDefault.initializeApi) ||
36
- resource.name.startsWith(NetworkDefaults_1.NetworkDefault.specsApi) ||
37
- resource.name.startsWith(NetworkDefaults_1.NetworkDefault.eventsApi));
38
- const payload = {
39
- markers,
40
- resources,
41
- };
42
- // TODO: Send as log to Statsig
43
- Log_1.Log.debug('Diagnostics', payload, JSON.stringify(payload));
44
- markers = [];
5
+ static mark() {
6
+ //
45
7
  }
46
8
  }
47
9
  exports.Diagnostics = Diagnostics;
48
- function maybeFlush(tag) {
49
- if (tag.startsWith('initialize:')) {
50
- Diagnostics.flush();
51
- }
52
- }
@@ -2,9 +2,11 @@ import { StatsigClientEmitEventFunc } from './StatsigClientBase';
2
2
  export declare const EXCEPTION_ENDPOINT = "https://statsigapi.net/v1/sdk_exception";
3
3
  export declare class ErrorBoundary {
4
4
  private _sdkKey;
5
+ private _emitter?;
5
6
  private _seen;
6
- constructor(_sdkKey: string);
7
- capture(tag: string, task: () => unknown, emitter?: StatsigClientEmitEventFunc): unknown;
7
+ constructor(_sdkKey: string, _emitter?: StatsigClientEmitEventFunc | undefined);
8
+ wrap(instance: unknown): void;
9
+ capture(tag: string, task: () => unknown): unknown;
8
10
  logError(tag: string, error: unknown): void;
9
11
  private _onError;
10
12
  }
@@ -15,30 +15,50 @@ const SDKType_1 = require("./SDKType");
15
15
  const StatsigMetadata_1 = require("./StatsigMetadata");
16
16
  exports.EXCEPTION_ENDPOINT = 'https://statsigapi.net/v1/sdk_exception';
17
17
  class ErrorBoundary {
18
- constructor(_sdkKey) {
18
+ constructor(_sdkKey, _emitter) {
19
19
  this._sdkKey = _sdkKey;
20
+ this._emitter = _emitter;
20
21
  this._seen = new Set();
21
22
  }
22
- capture(tag, task, emitter) {
23
+ wrap(instance) {
24
+ try {
25
+ const obj = instance;
26
+ _getAllInstanceMethodNames(obj).forEach((name) => {
27
+ const original = obj[name];
28
+ if ('$EB' in original) {
29
+ return;
30
+ }
31
+ obj[name] = (...args) => {
32
+ return this.capture(name, () => original.apply(instance, args));
33
+ };
34
+ obj[name].$EB = true;
35
+ });
36
+ }
37
+ catch (err) {
38
+ this._onError('eb:wrap', err);
39
+ }
40
+ }
41
+ capture(tag, task) {
23
42
  try {
24
43
  const res = task();
25
44
  if (res && res instanceof Promise) {
26
- return res.catch((err) => this._onError(tag, err, emitter));
45
+ return res.catch((err) => this._onError(tag, err));
27
46
  }
28
47
  return res;
29
48
  }
30
49
  catch (error) {
31
- this._onError(tag, error, emitter);
50
+ this._onError(tag, error);
32
51
  return null;
33
52
  }
34
53
  }
35
54
  logError(tag, error) {
36
55
  this._onError(tag, error);
37
56
  }
38
- _onError(tag, error, emitter) {
57
+ _onError(tag, error) {
39
58
  try {
40
59
  Log_1.Log.warn(`Caught error in ${tag}`, { error });
41
60
  const impl = () => __awaiter(this, void 0, void 0, function* () {
61
+ var _a;
42
62
  const unwrapped = (error !== null && error !== void 0 ? error : Error('[Statsig] Error was empty'));
43
63
  const isError = unwrapped instanceof Error;
44
64
  const name = isError ? unwrapped.name : 'No Name';
@@ -60,7 +80,7 @@ class ErrorBoundary {
60
80
  },
61
81
  body,
62
82
  });
63
- emitter === null || emitter === void 0 ? void 0 : emitter({ name: 'error', error });
83
+ (_a = this._emitter) === null || _a === void 0 ? void 0 : _a.call(this, { name: 'error', error });
64
84
  });
65
85
  impl()
66
86
  .then(() => {
@@ -84,3 +104,14 @@ function _getDescription(obj) {
84
104
  return '[Statsig] Failed to get string for error.';
85
105
  }
86
106
  }
107
+ function _getAllInstanceMethodNames(instance) {
108
+ const names = new Set();
109
+ let proto = Object.getPrototypeOf(instance);
110
+ while (proto && proto !== Object.prototype) {
111
+ Object.getOwnPropertyNames(proto)
112
+ .filter((prop) => typeof (proto === null || proto === void 0 ? void 0 : proto[prop]) === 'function')
113
+ .forEach((name) => names.add(name));
114
+ proto = Object.getPrototypeOf(proto);
115
+ }
116
+ return Array.from(names);
117
+ }
@@ -14,6 +14,7 @@ const Hashing_1 = require("./Hashing");
14
14
  const Log_1 = require("./Log");
15
15
  const NetworkDefaults_1 = require("./NetworkDefaults");
16
16
  const NetworkParams_1 = require("./NetworkParams");
17
+ const SafeJs_1 = require("./SafeJs");
17
18
  const StatsigEvent_1 = require("./StatsigEvent");
18
19
  const StorageProvider_1 = require("./StorageProvider");
19
20
  const TypedJsonParse_1 = require("./TypedJsonParse");
@@ -249,15 +250,7 @@ class EventLogger {
249
250
  if (((_a = this._options) === null || _a === void 0 ? void 0 : _a.includeCurrentPageUrlWithEvents) === false) {
250
251
  return;
251
252
  }
252
- if (typeof window === 'undefined' || typeof window.location !== 'object') {
253
- return;
254
- }
255
- try {
256
- return window.location.href.split(/[?#]/)[0];
257
- }
258
- catch (_b) {
259
- return;
260
- }
253
+ return (0, SafeJs_1._getCurrentPageUrlSafe)();
261
254
  }
262
255
  }
263
256
  exports.EventLogger = EventLogger;
@@ -76,10 +76,7 @@ class NetworkCore {
76
76
  throw err;
77
77
  }
78
78
  const text = yield response.text();
79
- Diagnostics_1.Diagnostics.mark('_sendRequest:response-received', {
80
- status: response.status,
81
- contentLength: response.headers.get('content-length'),
82
- });
79
+ Diagnostics_1.Diagnostics.mark();
83
80
  return {
84
81
  body: text,
85
82
  code: response.status,
@@ -87,11 +84,7 @@ class NetworkCore {
87
84
  }
88
85
  catch (error) {
89
86
  const errorMessage = _getErrorMessage(controller, error);
90
- Diagnostics_1.Diagnostics.mark('_sendRequest:error', {
91
- error: errorMessage,
92
- status: response === null || response === void 0 ? void 0 : response.status,
93
- contentLength: response === null || response === void 0 ? void 0 : response.headers.get('content-length'),
94
- });
87
+ Diagnostics_1.Diagnostics.mark();
95
88
  if (!retries || retries <= 0) {
96
89
  (_a = this._emitter) === null || _a === void 0 ? void 0 : _a.call(this, { name: 'error', error });
97
90
  Log_1.Log.error(`A networking error occured during ${method} request to ${url}.`, errorMessage, error);
package/src/SafeJs.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  export declare const _getWindowSafe: () => Window | null;
2
2
  export declare const _getDocumentSafe: () => Document | null;
3
+ export declare const _isBrowserEnv: () => boolean;
3
4
  export declare const _addWindowEventListenerSafe: (key: string, listener: () => void) => void;
4
5
  export declare const _addDocumentEventListenerSafe: (key: string, listener: () => void) => void;
6
+ export declare const _getCurrentPageUrlSafe: () => string | undefined;
package/src/SafeJs.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports._addDocumentEventListenerSafe = exports._addWindowEventListenerSafe = exports._getDocumentSafe = exports._getWindowSafe = void 0;
3
+ exports._getCurrentPageUrlSafe = exports._addDocumentEventListenerSafe = exports._addWindowEventListenerSafe = exports._isBrowserEnv = exports._getDocumentSafe = exports._getWindowSafe = void 0;
4
4
  const _getWindowSafe = () => {
5
5
  return typeof window !== 'undefined' ? window : null;
6
6
  };
@@ -11,6 +11,10 @@ const _getDocumentSafe = () => {
11
11
  return (_a = win === null || win === void 0 ? void 0 : win.document) !== null && _a !== void 0 ? _a : null;
12
12
  };
13
13
  exports._getDocumentSafe = _getDocumentSafe;
14
+ const _isBrowserEnv = () => {
15
+ return (0, exports._getDocumentSafe)() != null;
16
+ };
17
+ exports._isBrowserEnv = _isBrowserEnv;
14
18
  const _addWindowEventListenerSafe = (key, listener) => {
15
19
  const win = (0, exports._getWindowSafe)();
16
20
  if (typeof (win === null || win === void 0 ? void 0 : win.addEventListener) === 'function') {
@@ -25,3 +29,13 @@ const _addDocumentEventListenerSafe = (key, listener) => {
25
29
  }
26
30
  };
27
31
  exports._addDocumentEventListenerSafe = _addDocumentEventListenerSafe;
32
+ const _getCurrentPageUrlSafe = () => {
33
+ var _a;
34
+ try {
35
+ return (_a = (0, exports._getWindowSafe)()) === null || _a === void 0 ? void 0 : _a.location.href.split(/[?#]/)[0];
36
+ }
37
+ catch (_b) {
38
+ return;
39
+ }
40
+ };
41
+ exports._getCurrentPageUrlSafe = _getCurrentPageUrlSafe;
@@ -15,32 +15,37 @@ const __StatsigGlobal_1 = require("./$_StatsigGlobal");
15
15
  const ErrorBoundary_1 = require("./ErrorBoundary");
16
16
  const EventLogger_1 = require("./EventLogger");
17
17
  const Log_1 = require("./Log");
18
+ const SafeJs_1 = require("./SafeJs");
18
19
  const SessionID_1 = require("./SessionID");
19
20
  const StableID_1 = require("./StableID");
20
21
  const StorageProvider_1 = require("./StorageProvider");
21
22
  class StatsigClientBase {
22
23
  constructor(sdkKey, adapter, network, options) {
23
- var _a, _b, _c;
24
+ var _a, _b;
24
25
  this.loadingStatus = 'Uninitialized';
25
26
  this._listeners = {};
26
- this._sdkKey = sdkKey;
27
- this._options = options !== null && options !== void 0 ? options : {};
27
+ const emitter = this._emit.bind(this);
28
+ const statsigGlobal = (0, __StatsigGlobal_1._getStatsigGlobal)();
29
+ const instances = (_a = statsigGlobal.instances) !== null && _a !== void 0 ? _a : {};
30
+ const inst = this;
31
+ (options === null || options === void 0 ? void 0 : options.logLevel) && (Log_1.Log.level = options === null || options === void 0 ? void 0 : options.logLevel);
28
32
  (options === null || options === void 0 ? void 0 : options.disableStorage) && StorageProvider_1.Storage._setDisabled(true);
29
33
  (options === null || options === void 0 ? void 0 : options.overrideStableID) &&
30
34
  StableID_1.StableID.setOverride(options.overrideStableID, sdkKey);
31
- Log_1.Log.level = (_a = options === null || options === void 0 ? void 0 : options.logLevel) !== null && _a !== void 0 ? _a : Log_1.LogLevel.Warn;
35
+ this._errorBoundary = new ErrorBoundary_1.ErrorBoundary(sdkKey, emitter);
36
+ this._errorBoundary.wrap(this);
37
+ this._errorBoundary.wrap(network);
38
+ this._errorBoundary.wrap(adapter);
39
+ this._sdkKey = sdkKey;
40
+ this._options = options !== null && options !== void 0 ? options : {};
32
41
  this._overrideAdapter = (_b = options === null || options === void 0 ? void 0 : options.overrideAdapter) !== null && _b !== void 0 ? _b : null;
33
- this._logger = new EventLogger_1.EventLogger(sdkKey, this._emit.bind(this), network, options);
42
+ this._logger = new EventLogger_1.EventLogger(sdkKey, emitter, network, options);
34
43
  SessionID_1.SessionID._setEmitFunction(() => {
35
44
  this._emit({ name: 'session_expired' });
36
45
  }, sdkKey);
37
- this._errorBoundary = new ErrorBoundary_1.ErrorBoundary(sdkKey);
38
- const statsigGlobal = (0, __StatsigGlobal_1._getStatsigGlobal)();
39
- const instances = (_c = statsigGlobal.instances) !== null && _c !== void 0 ? _c : {};
40
- if (instances[sdkKey] != null) {
46
+ if (instances[sdkKey] != null && (0, SafeJs_1._isBrowserEnv)()) {
41
47
  Log_1.Log.warn('Creating multiple Statsig clients with the same SDK key can lead to unexpected behavior. Multi-instance support requires different SDK keys.');
42
48
  }
43
- const inst = this;
44
49
  instances[sdkKey] = inst;
45
50
  statsigGlobal.lastInstance = inst;
46
51
  statsigGlobal.instances = instances;
@@ -1,4 +1,4 @@
1
- import { AnyStatsigOptions } from './StatsigOptionsCommon';
1
+ import type { AnyStatsigOptions, NetworkConfigCommon } from './StatsigOptionsCommon';
2
2
  import { StatsigUser } from './StatsigUser';
3
3
  export type DataSource = 'Uninitialized' | 'Loading' | 'NoValues' | 'Cache' | 'Network' | 'NetworkNotModified' | 'Bootstrap' | 'Prefetch';
4
4
  export type DataAdapterResult = {
@@ -6,12 +6,21 @@ export type DataAdapterResult = {
6
6
  readonly data: string;
7
7
  readonly receivedAt: number;
8
8
  };
9
+ export type DataAdapterAsyncOptions = {
10
+ /**
11
+ * The maximum amount of time (in milliseconds) this operation is permitted to run.
12
+ * If the timeout is hit, null is returned but any in-flight requests are kept alive with results going to cache for future updates.
13
+ *
14
+ * Note: If no timeout is given, the {@link NetworkConfigCommon.networkTimeoutMs|StatsigOptions.networkConfig.networkTimeoutMs} is used.
15
+ */
16
+ readonly timeoutMs?: NetworkConfigCommon['networkTimeoutMs'];
17
+ };
9
18
  export declare const DataAdapterCachePrefix = "statsig.cached";
10
19
  /**
11
20
  * Describes a type that is used during intialize/update operations of a Statsig client.
12
21
  *
13
22
  * See below to find the default adapters, but know that it is possible to create your
14
- * own StatsigDataAdapter and provide it via {@link StatsigOptionsCommon.dataAdapter}.
23
+ * own StatsigDataAdapter and provide it via {@link AnyStatsigOptions.dataAdapter}.
15
24
  *
16
25
  * Defaults:
17
26
  *
@@ -49,13 +58,13 @@ export type EvaluationsDataAdapter = DataAdapterCommon & {
49
58
  * @param {StatsigUser} user The StatsigUser to get data for.
50
59
  * @returns {DataAdapterResult | null} The data that was found for the given StatsigUser.
51
60
  */
52
- readonly getDataAsync: (current: DataAdapterResult | null, user: StatsigUser) => Promise<DataAdapterResult | null>;
61
+ readonly getDataAsync: (current: DataAdapterResult | null, user: StatsigUser, options?: DataAdapterAsyncOptions) => Promise<DataAdapterResult | null>;
53
62
  /**
54
63
  * Manually trigger a fetch for new evaluations data for the given user.
55
64
  *
56
65
  * @param {StatsigUser} user The StatsigUser to get data for.
57
66
  */
58
- readonly prefetchData: (user: StatsigUser) => Promise<void>;
67
+ readonly prefetchData: (user: StatsigUser, options?: DataAdapterAsyncOptions) => Promise<void>;
59
68
  /**
60
69
  * Manually set evaluations data for the given user.
61
70
  *
@@ -76,11 +85,11 @@ export type SpecsDataAdapter = DataAdapterCommon & {
76
85
  * @param {DataAdapterResult | null} current The data that was found synchronously (Cache). Will be used as fallback if getDataAsync fails
77
86
  * @returns {DataAdapterResult | null} The data that was found for the given StatsigUser.
78
87
  */
79
- readonly getDataAsync: (current: DataAdapterResult | null) => Promise<DataAdapterResult | null>;
88
+ readonly getDataAsync: (current: DataAdapterResult | null, options?: DataAdapterAsyncOptions) => Promise<DataAdapterResult | null>;
80
89
  /**
81
90
  * Manually trigger a fetch for new specs data.
82
91
  */
83
- readonly prefetchData: () => Promise<void>;
92
+ readonly prefetchData: (options?: DataAdapterAsyncOptions) => Promise<void>;
84
93
  /**
85
94
  * Manually set specs data (Bootstrap).
86
95
  */
@@ -1,4 +1,4 @@
1
- export declare const SDK_VERSION = "0.0.1-beta.31";
1
+ export declare const SDK_VERSION = "0.0.1-beta.33";
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.31';
4
+ exports.SDK_VERSION = '0.0.1-beta.33';
5
5
  let metadata = {
6
6
  sdkVersion: exports.SDK_VERSION,
7
7
  sdkType: 'js-mono', // js-mono is overwritten by Precomp and OnDevice clients
package/src/index.d.ts CHANGED
@@ -13,7 +13,6 @@ export * from './EvaluationTypes';
13
13
  export * from './Hashing';
14
14
  export * from './InitializeResponse';
15
15
  export * from './Log';
16
- export * from './Monitoring';
17
16
  export * from './NetworkParams';
18
17
  export * from './NetworkCore';
19
18
  export * from './NetworkDefaults';
package/src/index.js CHANGED
@@ -35,7 +35,6 @@ __exportStar(require("./EvaluationTypes"), exports);
35
35
  __exportStar(require("./Hashing"), exports);
36
36
  __exportStar(require("./InitializeResponse"), exports);
37
37
  __exportStar(require("./Log"), exports);
38
- __exportStar(require("./Monitoring"), exports);
39
38
  __exportStar(require("./NetworkParams"), exports);
40
39
  __exportStar(require("./NetworkCore"), exports);
41
40
  __exportStar(require("./NetworkDefaults"), exports);
@@ -1,2 +0,0 @@
1
- import { ErrorBoundary } from './ErrorBoundary';
2
- export declare function monitorClass(errorBoundary: ErrorBoundary, instance: object): void;
package/src/Monitoring.js DELETED
@@ -1,74 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.monitorClass = void 0;
4
- const Diagnostics_1 = require("./Diagnostics");
5
- const StatsigClientBase_1 = require("./StatsigClientBase");
6
- function monitorClass(errorBoundary, instance) {
7
- try {
8
- _monitorClassImpl(errorBoundary, instance);
9
- }
10
- catch (error) {
11
- errorBoundary.logError('monitorClass', error);
12
- }
13
- }
14
- exports.monitorClass = monitorClass;
15
- function _monitorFunction(errorBoundary, tag, func, instance) {
16
- const emitFunc = instance instanceof StatsigClientBase_1.StatsigClientBase
17
- ? instance['_emit'].bind(instance)
18
- : undefined;
19
- return errorBoundary.capture(tag, () => (0, Diagnostics_1.captureDiagnostics)(tag, () => func.apply(instance)), emitFunc);
20
- }
21
- function _getProtoSafe(instance) {
22
- if (typeof instance === 'object') {
23
- const proto = Object.getPrototypeOf(instance);
24
- return proto && typeof proto === 'object'
25
- ? proto
26
- : null;
27
- }
28
- return null;
29
- }
30
- function _getAllInstanceMethodNames(instance) {
31
- const names = new Set();
32
- let proto = _getProtoSafe(instance);
33
- while (proto && proto !== Object.prototype) {
34
- Object.getOwnPropertyNames(proto)
35
- .filter((prop) => typeof (proto === null || proto === void 0 ? void 0 : proto[prop]) === 'function')
36
- .forEach((name) => names.add(name));
37
- proto = Object.getPrototypeOf(proto);
38
- }
39
- return Array.from(names);
40
- }
41
- function _getAllStaticMethodNames(instance) {
42
- const names = new Set();
43
- const proto = _getProtoSafe(instance);
44
- Object.getOwnPropertyNames((proto === null || proto === void 0 ? void 0 : proto.constructor) || {})
45
- .filter((prop) => {
46
- var _a;
47
- if (prop === 'caller' || prop === 'arguments' || prop === 'callee') {
48
- return false;
49
- }
50
- return (typeof ((_a = proto === null || proto === void 0 ? void 0 : proto.constructor) === null || _a === void 0 ? void 0 : _a[prop]) === 'function');
51
- })
52
- .forEach((name) => names.add(name));
53
- return Array.from(names);
54
- }
55
- function _monitorClassImpl(errorBoundary, instance) {
56
- var _a;
57
- const obj = instance;
58
- for (const method of _getAllInstanceMethodNames(obj)) {
59
- if (method === 'constructor') {
60
- continue;
61
- }
62
- const original = obj[method];
63
- obj[method] = function (...args) {
64
- return _monitorFunction(errorBoundary, method, () => original.apply(this, args), instance);
65
- };
66
- }
67
- for (const method of _getAllStaticMethodNames(obj)) {
68
- const original = (_a = obj === null || obj === void 0 ? void 0 : obj.constructor) === null || _a === void 0 ? void 0 : _a[method];
69
- (obj === null || obj === void 0 ? void 0 : obj.constructor)[method] =
70
- function (...args) {
71
- return _monitorFunction(errorBoundary, `${obj.constructor.name}.${method}`, () => original.apply(obj.constructor, args), instance);
72
- };
73
- }
74
- }