@statsig/client-core 1.8.0-beta.4 → 1.8.0-beta.6
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 +1 -1
- package/src/NetworkCore.d.ts +3 -0
- package/src/NetworkCore.js +55 -16
- package/src/StatsigMetadata.d.ts +1 -1
- package/src/StatsigMetadata.js +1 -1
package/package.json
CHANGED
package/src/NetworkCore.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ export declare class NetworkCore {
|
|
|
30
30
|
private readonly _options;
|
|
31
31
|
private _proxy;
|
|
32
32
|
private networkEvents;
|
|
33
|
+
private sdkKey;
|
|
33
34
|
constructor(options: AnyStatsigOptions | null, _emitter?: StatsigClientEmitEventFunc | undefined);
|
|
34
35
|
post(args: RequestArgsWithData): Promise<NetworkResponse | null>;
|
|
35
36
|
get(args: RequestArgs): Promise<NetworkResponse | null>;
|
|
@@ -40,5 +41,7 @@ export declare class NetworkCore {
|
|
|
40
41
|
private _getPopulatedBody;
|
|
41
42
|
private _attemptToEncodeString;
|
|
42
43
|
private _getNetworkProxyArgs;
|
|
44
|
+
private _flushNetworkEvents;
|
|
45
|
+
private _startBackgroundFlushNetworkEvents;
|
|
43
46
|
}
|
|
44
47
|
export {};
|
package/src/NetworkCore.js
CHANGED
|
@@ -31,6 +31,7 @@ class NetworkCore {
|
|
|
31
31
|
this._netConfig = {};
|
|
32
32
|
this._options = {};
|
|
33
33
|
this.networkEvents = [];
|
|
34
|
+
this.sdkKey = null;
|
|
34
35
|
if (options) {
|
|
35
36
|
this._options = options;
|
|
36
37
|
}
|
|
@@ -41,16 +42,13 @@ class NetworkCore {
|
|
|
41
42
|
this._timeout = this._netConfig.networkTimeoutMs;
|
|
42
43
|
}
|
|
43
44
|
this._proxy = new NetworkProxy_1.NetworkProxy(this._options);
|
|
45
|
+
this._startBackgroundFlushNetworkEvents();
|
|
44
46
|
}
|
|
45
47
|
post(args) {
|
|
46
48
|
return __awaiter(this, void 0, void 0, function* () {
|
|
47
49
|
const proxyConfigArgs = this._getNetworkProxyArgs(args);
|
|
48
|
-
if (
|
|
49
|
-
|
|
50
|
-
events.push(...this.networkEvents);
|
|
51
|
-
console.log('events', events);
|
|
52
|
-
this.networkEvents = [];
|
|
53
|
-
args.data['events'] = events;
|
|
50
|
+
if (!this.sdkKey) {
|
|
51
|
+
this.sdkKey = args.sdkKey;
|
|
54
52
|
}
|
|
55
53
|
let body = yield this._getPopulatedBody(Object.assign(Object.assign({}, args), proxyConfigArgs));
|
|
56
54
|
if (args.isStatsigEncodable) {
|
|
@@ -60,6 +58,9 @@ class NetworkCore {
|
|
|
60
58
|
});
|
|
61
59
|
}
|
|
62
60
|
get(args) {
|
|
61
|
+
if (!this.sdkKey) {
|
|
62
|
+
this.sdkKey = args.sdkKey;
|
|
63
|
+
}
|
|
63
64
|
return this._sendRequest(Object.assign({ method: 'GET' }, args));
|
|
64
65
|
}
|
|
65
66
|
isBeaconSupported() {
|
|
@@ -94,17 +95,10 @@ class NetworkCore {
|
|
|
94
95
|
controller === null || controller === void 0 ? void 0 : controller.abort(`Timeout of ${this._timeout}ms expired.`);
|
|
95
96
|
}, this._timeout);
|
|
96
97
|
const proxyUrl = (_a = args.proxyUrl) !== null && _a !== void 0 ? _a : this._proxy.getProxyUrl(args.sdkKey, args.url);
|
|
97
|
-
const isProxy = proxyUrl != null;
|
|
98
98
|
const url = yield this._getPopulatedURL(Object.assign({ proxyUrl }, args));
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
eventName: 'proxy::network_request_tracking',
|
|
103
|
-
metadata: {
|
|
104
|
-
url,
|
|
105
|
-
},
|
|
106
|
-
time: Date.now(),
|
|
107
|
-
});
|
|
99
|
+
const isProxy = !url.includes('https://statsigapi.net/v1');
|
|
100
|
+
const parsedUrl = new URL(url);
|
|
101
|
+
const endpoint = parsedUrl.pathname;
|
|
108
102
|
let response = null;
|
|
109
103
|
const keepalive = (0, VisibilityObserving_1._isUnloading)();
|
|
110
104
|
try {
|
|
@@ -134,12 +128,38 @@ class NetworkCore {
|
|
|
134
128
|
if (args.isInitialize) {
|
|
135
129
|
Diagnostics_1.Diagnostics._markInitNetworkReqEnd(args.sdkKey, Diagnostics_1.Diagnostics._getDiagnosticsData(response, currentAttempt, text));
|
|
136
130
|
}
|
|
131
|
+
if (!url.includes('https://prodregistryv2.org')) {
|
|
132
|
+
this.networkEvents.push({
|
|
133
|
+
value: isProxy ? 'proxy' : 'statsig',
|
|
134
|
+
eventName: 'proxy::network_request_tracking',
|
|
135
|
+
metadata: {
|
|
136
|
+
url,
|
|
137
|
+
success: true,
|
|
138
|
+
endpoint,
|
|
139
|
+
},
|
|
140
|
+
time: Date.now(),
|
|
141
|
+
user: null,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
137
144
|
return {
|
|
138
145
|
body: text,
|
|
139
146
|
code: response.status,
|
|
140
147
|
};
|
|
141
148
|
}
|
|
142
149
|
catch (error) {
|
|
150
|
+
if (!url.includes('https://prodregistryv2.org')) {
|
|
151
|
+
this.networkEvents.push({
|
|
152
|
+
value: isProxy ? 'proxy' : 'statsig',
|
|
153
|
+
eventName: 'proxy::network_request_tracking',
|
|
154
|
+
metadata: {
|
|
155
|
+
url,
|
|
156
|
+
success: false,
|
|
157
|
+
endpoint,
|
|
158
|
+
},
|
|
159
|
+
time: Date.now(),
|
|
160
|
+
user: null,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
143
163
|
const errorMessage = _getErrorMessage(controller, error);
|
|
144
164
|
const timedOut = _didTimeout(controller);
|
|
145
165
|
if (args.isInitialize) {
|
|
@@ -206,6 +226,25 @@ class NetworkCore {
|
|
|
206
226
|
proxyUrl: proxyUrl !== null && proxyUrl !== void 0 ? proxyUrl : null,
|
|
207
227
|
};
|
|
208
228
|
}
|
|
229
|
+
_flushNetworkEvents() {
|
|
230
|
+
var _a;
|
|
231
|
+
if (this.networkEvents.length === 0) {
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
this.post({
|
|
235
|
+
sdkKey: (_a = this.sdkKey) !== null && _a !== void 0 ? _a : '',
|
|
236
|
+
url: 'https://prodregistryv2.org/v1/rgstr',
|
|
237
|
+
data: {
|
|
238
|
+
events: this.networkEvents,
|
|
239
|
+
},
|
|
240
|
+
});
|
|
241
|
+
this.networkEvents = [];
|
|
242
|
+
}
|
|
243
|
+
_startBackgroundFlushNetworkEvents() {
|
|
244
|
+
setInterval(() => {
|
|
245
|
+
this._flushNetworkEvents();
|
|
246
|
+
}, 10000);
|
|
247
|
+
}
|
|
209
248
|
}
|
|
210
249
|
exports.NetworkCore = NetworkCore;
|
|
211
250
|
const _ensureValidSdkKey = (args) => {
|
package/src/StatsigMetadata.d.ts
CHANGED
package/src/StatsigMetadata.js
CHANGED
|
@@ -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.
|
|
4
|
+
exports.SDK_VERSION = '1.8.0-beta.6';
|
|
5
5
|
let metadata = {
|
|
6
6
|
sdkVersion: exports.SDK_VERSION,
|
|
7
7
|
sdkType: 'js-mono', // js-mono is overwritten by Precomp and OnDevice clients
|