@statsig/client-core 1.8.0-beta.5 → 1.8.0-beta.7
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 -15
- 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,15 +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
|
-
this.networkEvents = [];
|
|
52
|
-
args.data['events'] = events;
|
|
50
|
+
if (!this.sdkKey) {
|
|
51
|
+
this.sdkKey = args.sdkKey;
|
|
53
52
|
}
|
|
54
53
|
let body = yield this._getPopulatedBody(Object.assign(Object.assign({}, args), proxyConfigArgs));
|
|
55
54
|
if (args.isStatsigEncodable) {
|
|
@@ -59,6 +58,9 @@ class NetworkCore {
|
|
|
59
58
|
});
|
|
60
59
|
}
|
|
61
60
|
get(args) {
|
|
61
|
+
if (!this.sdkKey) {
|
|
62
|
+
this.sdkKey = args.sdkKey;
|
|
63
|
+
}
|
|
62
64
|
return this._sendRequest(Object.assign({ method: 'GET' }, args));
|
|
63
65
|
}
|
|
64
66
|
isBeaconSupported() {
|
|
@@ -93,17 +95,10 @@ class NetworkCore {
|
|
|
93
95
|
controller === null || controller === void 0 ? void 0 : controller.abort(`Timeout of ${this._timeout}ms expired.`);
|
|
94
96
|
}, this._timeout);
|
|
95
97
|
const proxyUrl = (_a = args.proxyUrl) !== null && _a !== void 0 ? _a : this._proxy.getProxyUrl(args.sdkKey, args.url);
|
|
96
|
-
const isProxy = proxyUrl != null;
|
|
97
98
|
const url = yield this._getPopulatedURL(Object.assign({ proxyUrl }, args));
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
eventName: 'proxy::network_request_tracking',
|
|
102
|
-
metadata: {
|
|
103
|
-
url,
|
|
104
|
-
},
|
|
105
|
-
time: Date.now(),
|
|
106
|
-
});
|
|
99
|
+
const isProxy = !url.includes('https://statsigapi.net/v1');
|
|
100
|
+
const parsedUrl = new URL(url);
|
|
101
|
+
const endpoint = parsedUrl.pathname;
|
|
107
102
|
let response = null;
|
|
108
103
|
const keepalive = (0, VisibilityObserving_1._isUnloading)();
|
|
109
104
|
try {
|
|
@@ -133,12 +128,38 @@ class NetworkCore {
|
|
|
133
128
|
if (args.isInitialize) {
|
|
134
129
|
Diagnostics_1.Diagnostics._markInitNetworkReqEnd(args.sdkKey, Diagnostics_1.Diagnostics._getDiagnosticsData(response, currentAttempt, text));
|
|
135
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
|
+
}
|
|
136
144
|
return {
|
|
137
145
|
body: text,
|
|
138
146
|
code: response.status,
|
|
139
147
|
};
|
|
140
148
|
}
|
|
141
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
|
+
}
|
|
142
163
|
const errorMessage = _getErrorMessage(controller, error);
|
|
143
164
|
const timedOut = _didTimeout(controller);
|
|
144
165
|
if (args.isInitialize) {
|
|
@@ -205,6 +226,25 @@ class NetworkCore {
|
|
|
205
226
|
proxyUrl: proxyUrl !== null && proxyUrl !== void 0 ? proxyUrl : null,
|
|
206
227
|
};
|
|
207
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
|
+
}
|
|
208
248
|
}
|
|
209
249
|
exports.NetworkCore = NetworkCore;
|
|
210
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.7';
|
|
5
5
|
let metadata = {
|
|
6
6
|
sdkVersion: exports.SDK_VERSION,
|
|
7
7
|
sdkType: 'js-mono', // js-mono is overwritten by Precomp and OnDevice clients
|