@statsig/client-core 1.8.0-beta.1 → 1.8.0-beta.10

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.8.0-beta.1",
3
+ "version": "1.8.0-beta.10",
4
4
  "dependencies": {},
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -1,7 +1,7 @@
1
1
  export declare const NetworkDefault: {
2
- eventsApi: "https://prodregistryv2.org/v1";
3
- initializeApi: "https://featureassets.org/v1";
4
- specsApi: "https://assetsconfigcdn.org/v1";
2
+ eventsApi: "https://statsigapi.net/v1";
3
+ initializeApi: "https://statsigapi.net/v1";
4
+ specsApi: "https://statsigapi.net/v1";
5
5
  };
6
6
  export type NetworkPriority = 'high' | 'low' | 'auto';
7
7
  export type NetworkArgs = RequestInit & {
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NetworkParam = exports.NetworkDefault = void 0;
4
4
  exports.NetworkDefault = {
5
- eventsApi: 'https://prodregistryv2.org/v1',
6
- initializeApi: 'https://featureassets.org/v1',
7
- specsApi: 'https://assetsconfigcdn.org/v1',
5
+ eventsApi: 'https://statsigapi.net/v1',
6
+ initializeApi: 'https://statsigapi.net/v1',
7
+ specsApi: 'https://statsigapi.net/v1',
8
8
  };
9
9
  var NetworkParam;
10
10
  (function (NetworkParam) {
@@ -29,6 +29,8 @@ export declare class NetworkCore {
29
29
  private readonly _netConfig;
30
30
  private readonly _options;
31
31
  private _proxy;
32
+ private networkEvents;
33
+ private sdkKey;
32
34
  constructor(options: AnyStatsigOptions | null, _emitter?: StatsigClientEmitEventFunc | undefined);
33
35
  post(args: RequestArgsWithData): Promise<NetworkResponse | null>;
34
36
  get(args: RequestArgs): Promise<NetworkResponse | null>;
@@ -39,5 +41,7 @@ export declare class NetworkCore {
39
41
  private _getPopulatedBody;
40
42
  private _attemptToEncodeString;
41
43
  private _getNetworkProxyArgs;
44
+ private _flushNetworkEvents;
45
+ private _startBackgroundFlushNetworkEvents;
42
46
  }
43
47
  export {};
@@ -30,6 +30,8 @@ class NetworkCore {
30
30
  this._timeout = DEFAULT_TIMEOUT_MS;
31
31
  this._netConfig = {};
32
32
  this._options = {};
33
+ this.networkEvents = [];
34
+ this.sdkKey = null;
33
35
  if (options) {
34
36
  this._options = options;
35
37
  }
@@ -40,10 +42,14 @@ class NetworkCore {
40
42
  this._timeout = this._netConfig.networkTimeoutMs;
41
43
  }
42
44
  this._proxy = new NetworkProxy_1.NetworkProxy(this._options);
45
+ this._startBackgroundFlushNetworkEvents();
43
46
  }
44
47
  post(args) {
45
48
  return __awaiter(this, void 0, void 0, function* () {
46
49
  const proxyConfigArgs = this._getNetworkProxyArgs(args);
50
+ if (!this.sdkKey) {
51
+ this.sdkKey = args.sdkKey;
52
+ }
47
53
  let body = yield this._getPopulatedBody(Object.assign(Object.assign({}, args), proxyConfigArgs));
48
54
  if (args.isStatsigEncodable) {
49
55
  body = this._attemptToEncodeString(args, body);
@@ -52,6 +58,9 @@ class NetworkCore {
52
58
  });
53
59
  }
54
60
  get(args) {
61
+ if (!this.sdkKey) {
62
+ this.sdkKey = args.sdkKey;
63
+ }
55
64
  return this._sendRequest(Object.assign({ method: 'GET' }, args));
56
65
  }
57
66
  isBeaconSupported() {
@@ -87,6 +96,9 @@ class NetworkCore {
87
96
  }, this._timeout);
88
97
  const proxyUrl = (_a = args.proxyUrl) !== null && _a !== void 0 ? _a : this._proxy.getProxyUrl(args.sdkKey, args.url);
89
98
  const url = yield this._getPopulatedURL(Object.assign({ proxyUrl }, args));
99
+ const isProxy = !url.includes('https://statsigapi.net/v1');
100
+ const parsedUrl = new URL(url);
101
+ const endpoint = parsedUrl.pathname;
90
102
  let response = null;
91
103
  const keepalive = (0, VisibilityObserving_1._isUnloading)();
92
104
  try {
@@ -109,6 +121,7 @@ class NetworkCore {
109
121
  if (!response.ok) {
110
122
  const text = yield response.text().catch(() => 'No Text');
111
123
  const err = new Error(`NetworkError: ${url} ${text}`);
124
+ console.log('response not ok!!', err);
112
125
  err.name = 'NetworkError';
113
126
  throw err;
114
127
  }
@@ -116,12 +129,40 @@ class NetworkCore {
116
129
  if (args.isInitialize) {
117
130
  Diagnostics_1.Diagnostics._markInitNetworkReqEnd(args.sdkKey, Diagnostics_1.Diagnostics._getDiagnosticsData(response, currentAttempt, text));
118
131
  }
132
+ console.log('network success!!');
133
+ if (!url.includes('https://prodregistryv2.org')) {
134
+ this.networkEvents.push({
135
+ value: isProxy ? 'proxy' : 'statsig',
136
+ eventName: 'proxy::network_request_tracking',
137
+ metadata: {
138
+ url,
139
+ success: true,
140
+ endpoint,
141
+ },
142
+ time: Date.now(),
143
+ user: null,
144
+ });
145
+ }
119
146
  return {
120
147
  body: text,
121
148
  code: response.status,
122
149
  };
123
150
  }
124
151
  catch (error) {
152
+ console.log('network error!!', error);
153
+ if (!url.includes('https://prodregistryv2.org')) {
154
+ this.networkEvents.push({
155
+ value: isProxy ? 'proxy' : 'statsig',
156
+ eventName: 'proxy::network_request_tracking',
157
+ metadata: {
158
+ url,
159
+ success: false,
160
+ endpoint,
161
+ },
162
+ time: Date.now(),
163
+ user: null,
164
+ });
165
+ }
125
166
  const errorMessage = _getErrorMessage(controller, error);
126
167
  const timedOut = _didTimeout(controller);
127
168
  if (args.isInitialize) {
@@ -188,6 +229,26 @@ class NetworkCore {
188
229
  proxyUrl: proxyUrl !== null && proxyUrl !== void 0 ? proxyUrl : null,
189
230
  };
190
231
  }
232
+ _flushNetworkEvents() {
233
+ var _a;
234
+ if (this.networkEvents.length === 0) {
235
+ return;
236
+ }
237
+ console.log('flushing network events!!', this.networkEvents);
238
+ this.post({
239
+ sdkKey: (_a = this.sdkKey) !== null && _a !== void 0 ? _a : '',
240
+ url: 'https://prodregistryv2.org/v1/rgstr',
241
+ data: {
242
+ events: [...this.networkEvents],
243
+ },
244
+ });
245
+ this.networkEvents = [];
246
+ }
247
+ _startBackgroundFlushNetworkEvents() {
248
+ setInterval(() => {
249
+ this._flushNetworkEvents();
250
+ }, 10000);
251
+ }
191
252
  }
192
253
  exports.NetworkCore = NetworkCore;
193
254
  const _ensureValidSdkKey = (args) => {
@@ -1,4 +1,4 @@
1
- export declare const SDK_VERSION = "1.8.0-beta.1";
1
+ export declare const SDK_VERSION = "1.8.0-beta.10";
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.8.0-beta.1';
4
+ exports.SDK_VERSION = '1.8.0-beta.10';
5
5
  let metadata = {
6
6
  sdkVersion: exports.SDK_VERSION,
7
7
  sdkType: 'js-mono', // js-mono is overwritten by Precomp and OnDevice clients