@statsig/client-core 3.1.0 → 3.2.0-beta.1

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.1.0",
3
+ "version": "3.2.0-beta.1",
4
4
  "dependencies": {},
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -26,11 +26,10 @@ const DEDUPER_WINDOW_DURATION_MS = 60000;
26
26
  const MAX_FAILED_LOGS = 500;
27
27
  const QUICK_FLUSH_WINDOW_MS = 200;
28
28
  const EVENT_LOGGER_MAP = {};
29
- var RetryFailedLogsTrigger;
30
- (function (RetryFailedLogsTrigger) {
31
- RetryFailedLogsTrigger[RetryFailedLogsTrigger["Startup"] = 0] = "Startup";
32
- RetryFailedLogsTrigger[RetryFailedLogsTrigger["GainedFocus"] = 1] = "GainedFocus";
33
- })(RetryFailedLogsTrigger || (RetryFailedLogsTrigger = {}));
29
+ const RetryFailedLogsTrigger = {
30
+ Startup: 'startup',
31
+ GainedFocus: 'gained_focus',
32
+ };
34
33
  class EventLogger {
35
34
  static _safeFlushAndForget(sdkKey) {
36
35
  var _a;
@@ -101,6 +100,7 @@ class EventLogger {
101
100
  clearInterval(this._flushIntervalId);
102
101
  this._flushIntervalId = null;
103
102
  }
103
+ delete EVENT_LOGGER_MAP[this._sdkKey];
104
104
  yield this.flush();
105
105
  });
106
106
  }
package/src/Log.d.ts CHANGED
@@ -1,10 +1,11 @@
1
- export declare enum LogLevel {
2
- None = 0,
3
- Error = 1,
4
- Warn = 2,
5
- Info = 3,
6
- Debug = 4
7
- }
1
+ export declare const LogLevel: {
2
+ readonly None: 0;
3
+ readonly Error: 1;
4
+ readonly Warn: 2;
5
+ readonly Info: 3;
6
+ readonly Debug: 4;
7
+ };
8
+ export type LogLevel = (typeof LogLevel)[keyof typeof LogLevel];
8
9
  export declare abstract class Log {
9
10
  static level: LogLevel;
10
11
  static info(...args: unknown[]): void;
package/src/Log.js CHANGED
@@ -11,35 +11,34 @@ function addTag(args) {
11
11
  args.unshift('[Statsig]');
12
12
  return args; // ['[Statsig]', ...args];
13
13
  }
14
- var LogLevel;
15
- (function (LogLevel) {
16
- LogLevel[LogLevel["None"] = 0] = "None";
17
- LogLevel[LogLevel["Error"] = 1] = "Error";
18
- LogLevel[LogLevel["Warn"] = 2] = "Warn";
19
- LogLevel[LogLevel["Info"] = 3] = "Info";
20
- LogLevel[LogLevel["Debug"] = 4] = "Debug";
21
- })(LogLevel || (exports.LogLevel = LogLevel = {}));
14
+ exports.LogLevel = {
15
+ None: 0,
16
+ Error: 1,
17
+ Warn: 2,
18
+ Info: 3,
19
+ Debug: 4,
20
+ };
22
21
  class Log {
23
22
  static info(...args) {
24
- if (this.level >= LogLevel.Info) {
23
+ if (this.level >= exports.LogLevel.Info) {
25
24
  console.info(_INFO, ...addTag(args));
26
25
  }
27
26
  }
28
27
  static debug(...args) {
29
- if (this.level >= LogLevel.Debug) {
28
+ if (this.level >= exports.LogLevel.Debug) {
30
29
  console.debug(DEBUG, ...addTag(args));
31
30
  }
32
31
  }
33
32
  static warn(...args) {
34
- if (this.level >= LogLevel.Warn) {
33
+ if (this.level >= exports.LogLevel.Warn) {
35
34
  console.warn(_WARN, ...addTag(args));
36
35
  }
37
36
  }
38
37
  static error(...args) {
39
- if (this.level >= LogLevel.Error) {
38
+ if (this.level >= exports.LogLevel.Error) {
40
39
  console.error(ERROR, ...addTag(args));
41
40
  }
42
41
  }
43
42
  }
44
43
  exports.Log = Log;
45
- Log.level = LogLevel.Warn;
44
+ Log.level = exports.LogLevel.Warn;
@@ -7,13 +7,14 @@ export type NetworkPriority = 'high' | 'low' | 'auto';
7
7
  export type NetworkArgs = RequestInit & {
8
8
  priority?: NetworkPriority;
9
9
  };
10
- export declare enum NetworkParam {
11
- EventCount = "ec",
12
- SdkKey = "k",
13
- SdkType = "st",
14
- SdkVersion = "sv",
15
- Time = "t",
16
- SessionID = "sid",
17
- StatsigEncoded = "se",
18
- IsGzipped = "gz"
19
- }
10
+ export declare const NetworkParam: {
11
+ readonly EventCount: "ec";
12
+ readonly SdkKey: "k";
13
+ readonly SdkType: "st";
14
+ readonly SdkVersion: "sv";
15
+ readonly Time: "t";
16
+ readonly SessionID: "sid";
17
+ readonly StatsigEncoded: "se";
18
+ readonly IsGzipped: "gz";
19
+ };
20
+ export type NetworkParam = (typeof NetworkParam)[keyof typeof NetworkParam];
@@ -6,14 +6,13 @@ exports.NetworkDefault = {
6
6
  initializeApi: 'https://featureassets.org/v1',
7
7
  specsApi: 'https://assetsconfigcdn.org/v1',
8
8
  };
9
- var NetworkParam;
10
- (function (NetworkParam) {
11
- NetworkParam["EventCount"] = "ec";
12
- NetworkParam["SdkKey"] = "k";
13
- NetworkParam["SdkType"] = "st";
14
- NetworkParam["SdkVersion"] = "sv";
15
- NetworkParam["Time"] = "t";
16
- NetworkParam["SessionID"] = "sid";
17
- NetworkParam["StatsigEncoded"] = "se";
18
- NetworkParam["IsGzipped"] = "gz";
19
- })(NetworkParam || (exports.NetworkParam = NetworkParam = {}));
9
+ exports.NetworkParam = {
10
+ EventCount: 'ec',
11
+ SdkKey: 'k',
12
+ SdkType: 'st',
13
+ SdkVersion: 'sv',
14
+ Time: 't',
15
+ SessionID: 'sid',
16
+ StatsigEncoded: 'se',
17
+ IsGzipped: 'gz',
18
+ };
@@ -25,6 +25,7 @@ export declare abstract class StatsigClientBase<TAdapter extends EvaluationsData
25
25
  protected readonly _options: AnyStatsigOptions;
26
26
  protected readonly _errorBoundary: ErrorBoundary;
27
27
  protected readonly _logger: EventLogger;
28
+ protected _initializePromise: Promise<void> | null;
28
29
  private _listeners;
29
30
  constructor(sdkKey: string, adapter: TAdapter, network: NetworkCore, options: AnyStatsigOptions | null);
30
31
  /**
@@ -20,8 +20,9 @@ const SessionID_1 = require("./SessionID");
20
20
  const StorageProvider_1 = require("./StorageProvider");
21
21
  class StatsigClientBase {
22
22
  constructor(sdkKey, adapter, network, options) {
23
- var _a, _b;
23
+ var _a;
24
24
  this.loadingStatus = 'Uninitialized';
25
+ this._initializePromise = null;
25
26
  this._listeners = {};
26
27
  const emitter = this.$emt.bind(this);
27
28
  (options === null || options === void 0 ? void 0 : options.logLevel) != null && (Log_1.Log.level = options.logLevel);
@@ -38,22 +39,11 @@ class StatsigClientBase {
38
39
  this._errorBoundary.wrap(network);
39
40
  this._errorBoundary.wrap(adapter);
40
41
  this._errorBoundary.wrap(this._logger);
41
- if (!(0, SafeJs_1._isServerEnv)()) {
42
- const statsigGlobal = (0, __StatsigGlobal_1._getStatsigGlobal)();
43
- const instances = (_b = statsigGlobal.instances) !== null && _b !== void 0 ? _b : {};
44
- const inst = this;
45
- if (instances[sdkKey] != null) {
46
- 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.');
47
- }
48
- instances[sdkKey] = inst;
49
- statsigGlobal.lastInstance = inst;
50
- statsigGlobal.instances = instances;
51
- __STATSIG__ = statsigGlobal;
52
- }
53
42
  this.dataAdapter = adapter;
54
43
  this.dataAdapter.attach(sdkKey, options);
55
44
  this.storageProvider = StorageProvider_1.Storage;
56
45
  this._primeReadyRipcord();
46
+ _assignGlobalInstance(sdkKey, this);
57
47
  }
58
48
  /**
59
49
  * Updates runtime configuration options for the SDK, allowing toggling of certain behaviors such as logging and storage to comply with user preferences or regulations such as GDPR.
@@ -85,6 +75,8 @@ class StatsigClientBase {
85
75
  shutdown() {
86
76
  return __awaiter(this, void 0, void 0, function* () {
87
77
  this.$emt({ name: 'pre_shutdown' });
78
+ this._setStatus('Uninitialized', null);
79
+ this._initializePromise = null;
88
80
  yield this._logger.stop();
89
81
  });
90
82
  }
@@ -153,3 +145,19 @@ class StatsigClientBase {
153
145
  }
154
146
  }
155
147
  exports.StatsigClientBase = StatsigClientBase;
148
+ function _assignGlobalInstance(sdkKey, client) {
149
+ var _a;
150
+ if ((0, SafeJs_1._isServerEnv)()) {
151
+ return;
152
+ }
153
+ const statsigGlobal = (0, __StatsigGlobal_1._getStatsigGlobal)();
154
+ const instances = (_a = statsigGlobal.instances) !== null && _a !== void 0 ? _a : {};
155
+ const inst = client;
156
+ if (instances[sdkKey] != null) {
157
+ 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.');
158
+ }
159
+ instances[sdkKey] = inst;
160
+ statsigGlobal.lastInstance = inst;
161
+ statsigGlobal.instances = instances;
162
+ __STATSIG__ = statsigGlobal;
163
+ }
@@ -1,4 +1,4 @@
1
- export declare const SDK_VERSION = "3.1.0";
1
+ export declare const SDK_VERSION = "3.2.0-beta.1";
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.1.0';
4
+ exports.SDK_VERSION = '3.2.0-beta.1';
5
5
  let metadata = {
6
6
  sdkVersion: exports.SDK_VERSION,
7
7
  sdkType: 'js-mono', // js-mono is overwritten by Precomp and OnDevice clients
@@ -0,0 +1,5 @@
1
+ import { StatsigClientInterface } from './ClientInterfaces';
2
+ export type StatsigPlugin<T extends StatsigClientInterface> = {
3
+ readonly __plugin: 'session-replay' | 'auto-capture';
4
+ bind: (client: T) => void;
5
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/src/index.d.ts CHANGED
@@ -33,6 +33,7 @@ export * from './StatsigOptionsCommon';
33
33
  export * from './StatsigTypeFactories';
34
34
  export * from './StatsigTypes';
35
35
  export * from './StatsigUser';
36
+ export * from './StatsigPlugin';
36
37
  export * from './StorageProvider';
37
38
  export * from './TypedJsonParse';
38
39
  export * from './TypingUtils';
package/src/index.js CHANGED
@@ -55,6 +55,7 @@ __exportStar(require("./StatsigOptionsCommon"), exports);
55
55
  __exportStar(require("./StatsigTypeFactories"), exports);
56
56
  __exportStar(require("./StatsigTypes"), exports);
57
57
  __exportStar(require("./StatsigUser"), exports);
58
+ __exportStar(require("./StatsigPlugin"), exports);
58
59
  __exportStar(require("./StorageProvider"), exports);
59
60
  __exportStar(require("./TypedJsonParse"), exports);
60
61
  __exportStar(require("./TypingUtils"), exports);