@statsig/client-core 1.8.0-beta.1 → 1.8.0-beta.11
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/NetworkConfig.d.ts +3 -3
- package/src/NetworkConfig.js +3 -3
- package/src/NetworkCore.d.ts +4 -0
- package/src/NetworkCore.js +63 -0
- package/src/StatsigMetadata.d.ts +1 -1
- package/src/StatsigMetadata.js +1 -1
package/package.json
CHANGED
package/src/NetworkConfig.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const NetworkDefault: {
|
|
2
|
-
eventsApi: "https://
|
|
3
|
-
initializeApi: "https://
|
|
4
|
-
specsApi: "https://
|
|
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 & {
|
package/src/NetworkConfig.js
CHANGED
|
@@ -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://
|
|
6
|
-
initializeApi: 'https://
|
|
7
|
-
specsApi: 'https://
|
|
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) {
|
package/src/NetworkCore.d.ts
CHANGED
|
@@ -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 {};
|
package/src/NetworkCore.js
CHANGED
|
@@ -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,42 @@ 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
|
+
console.log('pushing success network event!!');
|
|
135
|
+
this.networkEvents.push({
|
|
136
|
+
value: isProxy ? 'proxy' : 'statsig',
|
|
137
|
+
eventName: 'proxy::network_request_tracking',
|
|
138
|
+
metadata: {
|
|
139
|
+
url,
|
|
140
|
+
success: true,
|
|
141
|
+
endpoint,
|
|
142
|
+
},
|
|
143
|
+
time: Date.now(),
|
|
144
|
+
user: null,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
119
147
|
return {
|
|
120
148
|
body: text,
|
|
121
149
|
code: response.status,
|
|
122
150
|
};
|
|
123
151
|
}
|
|
124
152
|
catch (error) {
|
|
153
|
+
console.log('network error!!', error);
|
|
154
|
+
if (!url.includes('https://prodregistryv2.org')) {
|
|
155
|
+
console.log('pushing failure network event!!');
|
|
156
|
+
this.networkEvents.push({
|
|
157
|
+
value: isProxy ? 'proxy' : 'statsig',
|
|
158
|
+
eventName: 'proxy::network_request_tracking',
|
|
159
|
+
metadata: {
|
|
160
|
+
url,
|
|
161
|
+
success: false,
|
|
162
|
+
endpoint,
|
|
163
|
+
},
|
|
164
|
+
time: Date.now(),
|
|
165
|
+
user: null,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
125
168
|
const errorMessage = _getErrorMessage(controller, error);
|
|
126
169
|
const timedOut = _didTimeout(controller);
|
|
127
170
|
if (args.isInitialize) {
|
|
@@ -188,6 +231,26 @@ class NetworkCore {
|
|
|
188
231
|
proxyUrl: proxyUrl !== null && proxyUrl !== void 0 ? proxyUrl : null,
|
|
189
232
|
};
|
|
190
233
|
}
|
|
234
|
+
_flushNetworkEvents() {
|
|
235
|
+
var _a;
|
|
236
|
+
console.log('flushing network events!!', this.networkEvents);
|
|
237
|
+
if (this.networkEvents.length === 0) {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
this.post({
|
|
241
|
+
sdkKey: (_a = this.sdkKey) !== null && _a !== void 0 ? _a : '',
|
|
242
|
+
url: 'https://prodregistryv2.org/v1/rgstr',
|
|
243
|
+
data: {
|
|
244
|
+
events: [...this.networkEvents],
|
|
245
|
+
},
|
|
246
|
+
});
|
|
247
|
+
this.networkEvents = [];
|
|
248
|
+
}
|
|
249
|
+
_startBackgroundFlushNetworkEvents() {
|
|
250
|
+
setInterval(() => {
|
|
251
|
+
this._flushNetworkEvents();
|
|
252
|
+
}, 10000);
|
|
253
|
+
}
|
|
191
254
|
}
|
|
192
255
|
exports.NetworkCore = NetworkCore;
|
|
193
256
|
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.11';
|
|
5
5
|
let metadata = {
|
|
6
6
|
sdkVersion: exports.SDK_VERSION,
|
|
7
7
|
sdkType: 'js-mono', // js-mono is overwritten by Precomp and OnDevice clients
|