@posthog/core 1.46.7 → 1.46.8
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"posthog-core-stateless.d.ts","sourceRoot":"","sources":["../src/posthog-core-stateless.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AACzE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAA;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAGnD,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,sBAAsB,EACtB,qBAAqB,EACrB,QAAQ,EACR,mBAAmB,EACnB,gBAAgB,EAGhB,yBAAyB,EACzB,iBAAiB,EACjB,cAAc,EACd,oBAAoB,EACpB,mBAAmB,EACnB,wBAAwB,EAExB,MAAM,EACN,cAAc,EAEf,MAAM,SAAS,CAAA;AAChB,OAAO,EAML,gBAAgB,EAOjB,MAAM,SAAS,CAAA;AAEhB,OAAO,EACL,sBAAsB,EAMvB,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"posthog-core-stateless.d.ts","sourceRoot":"","sources":["../src/posthog-core-stateless.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AACzE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAA;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAGnD,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,sBAAsB,EACtB,qBAAqB,EACrB,QAAQ,EACR,mBAAmB,EACnB,gBAAgB,EAGhB,yBAAyB,EACzB,iBAAiB,EACjB,cAAc,EACd,oBAAoB,EACpB,mBAAmB,EACnB,wBAAwB,EAExB,MAAM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;;;;;;;;;;OA2BG;IACH,SAAS,CAAC,wBAAwB,IAAI,OAAO,CAAC,IAAI,CAAC;IAInD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAItB,OAAO,CAAC,aAAa;IAmDrB,SAAS,CAAC,gBAAgB,IAAI;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE;IAavD;;;;;;;;;;;OAWG;cACa,SAAS,CACvB,aAAa,EAAE,CAAC,sBAAsB,GAAG,SAAS,CAAC,EAAE,EACrD,YAAY,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,EACxC,MAAM,GAAE,MAA4B,GACnC,OAAO,CAAC,IAAI,CAAC;YAgCF,MAAM;YAmCN,WAAW;IAsFzB;;;;;;;;;OASG;IACG,cAAc,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,oBAAoB,CAAC;IA6C7E;;;;;OAKG;IACG,iBAAiB,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,uBAAuB,CAAC;IAgDtF,OAAO,CAAC,cAAc;IAsJhB,SAAS,CAAC,iBAAiB,GAAE,MAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAyDjE;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACG,QAAQ,CAAC,iBAAiB,GAAE,MAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAYjE"}
|
|
@@ -39,17 +39,56 @@ const index_js_namespaceObject = require("./utils/index.js");
|
|
|
39
39
|
const uuidv7_js_namespaceObject = require("./vendor/uuidv7.js");
|
|
40
40
|
const external_error_tracking_index_js_namespaceObject = require("./error-tracking/index.js");
|
|
41
41
|
class PostHogFetchHttpError extends Error {
|
|
42
|
-
constructor(response, reqByteLength){
|
|
43
|
-
super('HTTP error while fetching PostHog: status=' + response.status + ', reqByteLength=' + reqByteLength), this.response = response, this.reqByteLength = reqByteLength, this.name = 'PostHogFetchHttpError';
|
|
42
|
+
constructor(response, reqByteLength, responseBodyDeadline, abortController){
|
|
43
|
+
super('HTTP error while fetching PostHog: status=' + response.status + ', reqByteLength=' + reqByteLength), this.response = response, this.reqByteLength = reqByteLength, this.responseBodyDeadline = responseBodyDeadline, this.abortController = abortController, this.name = 'PostHogFetchHttpError', this._bodyReadTimedOut = false;
|
|
44
44
|
}
|
|
45
45
|
get status() {
|
|
46
46
|
return this.response.status;
|
|
47
47
|
}
|
|
48
|
+
get bodyReadTimedOut() {
|
|
49
|
+
return this._bodyReadTimedOut;
|
|
50
|
+
}
|
|
48
51
|
get text() {
|
|
49
|
-
|
|
52
|
+
if (!this.responseBodyTextPromise) if (Date.now() >= this.responseBodyDeadline) {
|
|
53
|
+
this._bodyReadTimedOut = true;
|
|
54
|
+
const timeoutError = new Error('Response body read timed out');
|
|
55
|
+
timeoutError.name = 'AbortError';
|
|
56
|
+
this.cancelResponseBody(timeoutError);
|
|
57
|
+
this.responseBodyTextPromise = Promise.reject(timeoutError);
|
|
58
|
+
} else {
|
|
59
|
+
const responseBodyTimeout = new Promise((_resolve, reject)=>{
|
|
60
|
+
this.responseBodyTimer = (0, index_js_namespaceObject.safeSetTimeout)(()=>{
|
|
61
|
+
this._bodyReadTimedOut = true;
|
|
62
|
+
const timeoutError = new Error('Response body read timed out');
|
|
63
|
+
timeoutError.name = 'AbortError';
|
|
64
|
+
reject(timeoutError);
|
|
65
|
+
this.cancelResponseBody(timeoutError);
|
|
66
|
+
}, this.responseBodyDeadline - Date.now());
|
|
67
|
+
});
|
|
68
|
+
let responseBodyText;
|
|
69
|
+
try {
|
|
70
|
+
responseBodyText = Promise.resolve(this.response.text());
|
|
71
|
+
} catch (error) {
|
|
72
|
+
responseBodyText = Promise.reject(error);
|
|
73
|
+
}
|
|
74
|
+
this.responseBodyTextPromise = Promise.race([
|
|
75
|
+
responseBodyText,
|
|
76
|
+
responseBodyTimeout
|
|
77
|
+
]).finally(()=>clearTimeout(this.responseBodyTimer));
|
|
78
|
+
}
|
|
79
|
+
return this.responseBodyTextPromise;
|
|
50
80
|
}
|
|
51
81
|
get json() {
|
|
52
|
-
return this.
|
|
82
|
+
return this.text.then((text)=>JSON.parse(text));
|
|
83
|
+
}
|
|
84
|
+
cancelResponseBody(reason) {
|
|
85
|
+
clearTimeout(this.responseBodyTimer);
|
|
86
|
+
if (!this.abortController.signal.aborted) this.abortController.abort(reason);
|
|
87
|
+
(async ()=>{
|
|
88
|
+
try {
|
|
89
|
+
await this.response.body?.cancel();
|
|
90
|
+
} catch {}
|
|
91
|
+
})();
|
|
53
92
|
}
|
|
54
93
|
}
|
|
55
94
|
class PostHogFetchNetworkError extends Error {
|
|
@@ -70,7 +109,9 @@ async function logFlushError(err) {
|
|
|
70
109
|
let text = '';
|
|
71
110
|
try {
|
|
72
111
|
text = await err.text;
|
|
73
|
-
} catch {
|
|
112
|
+
} catch {
|
|
113
|
+
if (err.bodyReadTimedOut) text = '<response body read timed out>';
|
|
114
|
+
}
|
|
74
115
|
console.error(`Error while flushing PostHog: message=${err.message}, response body=${text}`, err);
|
|
75
116
|
} else console.error('Error while flushing PostHog', err);
|
|
76
117
|
return Promise.resolve();
|
|
@@ -332,8 +373,11 @@ class PostHogCoreStateless {
|
|
|
332
373
|
}
|
|
333
374
|
};
|
|
334
375
|
return this.fetchWithRetry(url, fetchOptions, {
|
|
376
|
+
type: 'required',
|
|
377
|
+
consume: (response)=>response.json()
|
|
378
|
+
}, {
|
|
335
379
|
retryCount: 0
|
|
336
|
-
}, this.remoteConfigRequestTimeoutMs).
|
|
380
|
+
}, this.remoteConfigRequestTimeoutMs).catch((error)=>{
|
|
337
381
|
this._logger.error('Remote config could not be loaded', error);
|
|
338
382
|
this._events.emit('error', error);
|
|
339
383
|
});
|
|
@@ -362,9 +406,12 @@ class PostHogCoreStateless {
|
|
|
362
406
|
};
|
|
363
407
|
this._logger.info('Flags URL', url);
|
|
364
408
|
return this.fetchWithRetry(url, fetchOptions, {
|
|
409
|
+
type: 'required',
|
|
410
|
+
consume: (response)=>response.json()
|
|
411
|
+
}, {
|
|
365
412
|
retryCount: this.featureFlagsRequestMaxRetries,
|
|
366
413
|
retryCheck: isRetryableFlagsFetchError
|
|
367
|
-
}, this.featureFlagsRequestTimeoutMs).then((response)=>
|
|
414
|
+
}, this.featureFlagsRequestTimeoutMs).then((response)=>({
|
|
368
415
|
success: true,
|
|
369
416
|
response: (0, external_featureFlagUtils_js_namespaceObject.normalizeFlagsResponse)(response)
|
|
370
417
|
})).catch((error)=>{
|
|
@@ -491,15 +538,18 @@ class PostHogCoreStateless {
|
|
|
491
538
|
'Content-Type': 'application/json'
|
|
492
539
|
}
|
|
493
540
|
};
|
|
494
|
-
const response = await this.fetchWithRetry(url, fetchOptions
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
541
|
+
const response = await this.fetchWithRetry(url, fetchOptions, {
|
|
542
|
+
type: 'required',
|
|
543
|
+
consume: (response)=>{
|
|
544
|
+
if (200 !== response.status || !response.json) {
|
|
545
|
+
const msg = `Surveys API could not be loaded: ${response.status}`;
|
|
546
|
+
const error = new Error(msg);
|
|
547
|
+
this._logger.error(error);
|
|
548
|
+
this._events.emit('error', new Error(msg));
|
|
549
|
+
return Promise.resolve(void 0);
|
|
550
|
+
}
|
|
551
|
+
return response.json();
|
|
501
552
|
}
|
|
502
|
-
return response.json();
|
|
503
553
|
}).catch((error)=>{
|
|
504
554
|
this._logger.error('Surveys API could not be loaded', error);
|
|
505
555
|
this._events.emit('error', error);
|
|
@@ -706,8 +756,9 @@ class PostHogCoreStateless {
|
|
|
706
756
|
},
|
|
707
757
|
body: gzippedPayload || payload
|
|
708
758
|
};
|
|
709
|
-
|
|
710
|
-
|
|
759
|
+
await this.fetchWithRetry(url, fetchOptions, {
|
|
760
|
+
type: 'successful-write'
|
|
761
|
+
}, retryOptions);
|
|
711
762
|
}
|
|
712
763
|
async _flush() {
|
|
713
764
|
this.clearFlushTimer();
|
|
@@ -794,6 +845,8 @@ class PostHogCoreStateless {
|
|
|
794
845
|
};
|
|
795
846
|
try {
|
|
796
847
|
await this.fetchWithRetry(url, fetchOptions, {
|
|
848
|
+
type: 'successful-write'
|
|
849
|
+
}, {
|
|
797
850
|
retryCheck: (err)=>{
|
|
798
851
|
if (isPostHogFetchContentTooLargeError(err)) return false;
|
|
799
852
|
return isPostHogFetchRetryableError(err);
|
|
@@ -837,6 +890,8 @@ class PostHogCoreStateless {
|
|
|
837
890
|
};
|
|
838
891
|
try {
|
|
839
892
|
await this.fetchWithRetry(url, fetchOptions, {
|
|
893
|
+
type: 'successful-write'
|
|
894
|
+
}, {
|
|
840
895
|
retryCheck: (err)=>{
|
|
841
896
|
if (isPostHogFetchContentTooLargeError(err)) return false;
|
|
842
897
|
return isPostHogFetchRetryableError(err);
|
|
@@ -859,7 +914,7 @@ class PostHogCoreStateless {
|
|
|
859
914
|
};
|
|
860
915
|
}
|
|
861
916
|
}
|
|
862
|
-
async fetchWithRetry(url, options, retryOptions, requestTimeout) {
|
|
917
|
+
async fetchWithRetry(url, options, responseHandling, retryOptions, requestTimeout) {
|
|
863
918
|
const body = options.body ? options.body : '';
|
|
864
919
|
let reqByteLength = -1;
|
|
865
920
|
try {
|
|
@@ -871,27 +926,86 @@ class PostHogCoreStateless {
|
|
|
871
926
|
reqByteLength = encoded.length;
|
|
872
927
|
}
|
|
873
928
|
}
|
|
929
|
+
const retriableOptions = {
|
|
930
|
+
...this._retryOptions,
|
|
931
|
+
...retryOptions
|
|
932
|
+
};
|
|
933
|
+
let attempt = 0;
|
|
874
934
|
return await (0, index_js_namespaceObject.retriable)(async ()=>{
|
|
935
|
+
attempt++;
|
|
875
936
|
const ctrl = new AbortController();
|
|
876
937
|
const timeoutMs = requestTimeout ?? this.requestTimeout;
|
|
877
|
-
const
|
|
878
|
-
let
|
|
938
|
+
const requestDeadline = Date.now() + timeoutMs;
|
|
939
|
+
let timer;
|
|
940
|
+
const deadline = new Promise((_resolve, reject)=>{
|
|
941
|
+
timer = (0, index_js_namespaceObject.safeSetTimeout)(()=>{
|
|
942
|
+
const timeoutError = new Error(`Request timed out after ${timeoutMs}ms`);
|
|
943
|
+
timeoutError.name = 'AbortError';
|
|
944
|
+
reject(timeoutError);
|
|
945
|
+
ctrl.abort(timeoutError);
|
|
946
|
+
}, timeoutMs);
|
|
947
|
+
});
|
|
948
|
+
let res;
|
|
949
|
+
let responseAccepted = false;
|
|
950
|
+
let cancellation;
|
|
951
|
+
const cancelBody = ()=>cancellation ??= (async ()=>{
|
|
952
|
+
try {
|
|
953
|
+
await res?.body?.cancel();
|
|
954
|
+
} catch {}
|
|
955
|
+
})();
|
|
879
956
|
try {
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
957
|
+
let fetchPromise;
|
|
958
|
+
try {
|
|
959
|
+
fetchPromise = this.fetch(url, {
|
|
960
|
+
signal: ctrl.signal,
|
|
961
|
+
...options
|
|
962
|
+
});
|
|
963
|
+
} catch (e) {
|
|
964
|
+
throw new PostHogFetchNetworkError(e);
|
|
965
|
+
}
|
|
966
|
+
fetchPromise.then((lateResponse)=>{
|
|
967
|
+
if (ctrl.signal.aborted && !responseAccepted) Promise.resolve(lateResponse.body?.cancel()).catch(()=>{});
|
|
968
|
+
}).catch(()=>{});
|
|
969
|
+
try {
|
|
970
|
+
res = await Promise.race([
|
|
971
|
+
fetchPromise,
|
|
972
|
+
deadline
|
|
973
|
+
]);
|
|
974
|
+
responseAccepted = true;
|
|
975
|
+
} catch (e) {
|
|
976
|
+
throw new PostHogFetchNetworkError(e);
|
|
977
|
+
}
|
|
978
|
+
const isNoCors = 'no-cors' === options.mode;
|
|
979
|
+
if (!isNoCors && (res.status < 200 || res.status >= 400)) throw new PostHogFetchHttpError(res, reqByteLength, requestDeadline, ctrl);
|
|
980
|
+
if ('successful-write' === responseHandling.type) {
|
|
981
|
+
try {
|
|
982
|
+
await Promise.race([
|
|
983
|
+
cancelBody(),
|
|
984
|
+
deadline
|
|
985
|
+
]);
|
|
986
|
+
} catch {}
|
|
987
|
+
return;
|
|
988
|
+
}
|
|
989
|
+
try {
|
|
990
|
+
return await Promise.race([
|
|
991
|
+
responseHandling.consume(res),
|
|
992
|
+
deadline
|
|
993
|
+
]);
|
|
994
|
+
} catch (e) {
|
|
995
|
+
if (ctrl.signal.aborted) throw new PostHogFetchNetworkError(e);
|
|
996
|
+
throw e;
|
|
997
|
+
}
|
|
886
998
|
} finally{
|
|
887
999
|
clearTimeout(timer);
|
|
1000
|
+
if (ctrl.signal.aborted && res) cancelBody();
|
|
888
1001
|
}
|
|
889
|
-
const isNoCors = 'no-cors' === options.mode;
|
|
890
|
-
if (!isNoCors && (res.status < 200 || res.status >= 400)) throw new PostHogFetchHttpError(res, reqByteLength);
|
|
891
|
-
return res;
|
|
892
1002
|
}, {
|
|
893
|
-
...
|
|
894
|
-
|
|
1003
|
+
...retriableOptions,
|
|
1004
|
+
retryCheck: (error)=>{
|
|
1005
|
+
const shouldRetry = retriableOptions.retryCheck(error);
|
|
1006
|
+
if (shouldRetry && attempt <= retriableOptions.retryCount && error instanceof PostHogFetchHttpError) error.cancelResponseBody();
|
|
1007
|
+
return shouldRetry;
|
|
1008
|
+
}
|
|
895
1009
|
});
|
|
896
1010
|
}
|
|
897
1011
|
async _shutdown(shutdownTimeoutMs = 30000) {
|
|
@@ -6,17 +6,56 @@ import { PromiseQueue, STRING_FORMAT, allSettled, createLogger, currentISOTime,
|
|
|
6
6
|
import { uuidv7 } from "./vendor/uuidv7.mjs";
|
|
7
7
|
import { ErrorCoercer, ErrorPropertiesBuilder, ObjectCoercer, PrimitiveCoercer, StringCoercer, createDefaultStackParser } from "./error-tracking/index.mjs";
|
|
8
8
|
class PostHogFetchHttpError extends Error {
|
|
9
|
-
constructor(response, reqByteLength){
|
|
10
|
-
super('HTTP error while fetching PostHog: status=' + response.status + ', reqByteLength=' + reqByteLength), this.response = response, this.reqByteLength = reqByteLength, this.name = 'PostHogFetchHttpError';
|
|
9
|
+
constructor(response, reqByteLength, responseBodyDeadline, abortController){
|
|
10
|
+
super('HTTP error while fetching PostHog: status=' + response.status + ', reqByteLength=' + reqByteLength), this.response = response, this.reqByteLength = reqByteLength, this.responseBodyDeadline = responseBodyDeadline, this.abortController = abortController, this.name = 'PostHogFetchHttpError', this._bodyReadTimedOut = false;
|
|
11
11
|
}
|
|
12
12
|
get status() {
|
|
13
13
|
return this.response.status;
|
|
14
14
|
}
|
|
15
|
+
get bodyReadTimedOut() {
|
|
16
|
+
return this._bodyReadTimedOut;
|
|
17
|
+
}
|
|
15
18
|
get text() {
|
|
16
|
-
|
|
19
|
+
if (!this.responseBodyTextPromise) if (Date.now() >= this.responseBodyDeadline) {
|
|
20
|
+
this._bodyReadTimedOut = true;
|
|
21
|
+
const timeoutError = new Error('Response body read timed out');
|
|
22
|
+
timeoutError.name = 'AbortError';
|
|
23
|
+
this.cancelResponseBody(timeoutError);
|
|
24
|
+
this.responseBodyTextPromise = Promise.reject(timeoutError);
|
|
25
|
+
} else {
|
|
26
|
+
const responseBodyTimeout = new Promise((_resolve, reject)=>{
|
|
27
|
+
this.responseBodyTimer = safeSetTimeout(()=>{
|
|
28
|
+
this._bodyReadTimedOut = true;
|
|
29
|
+
const timeoutError = new Error('Response body read timed out');
|
|
30
|
+
timeoutError.name = 'AbortError';
|
|
31
|
+
reject(timeoutError);
|
|
32
|
+
this.cancelResponseBody(timeoutError);
|
|
33
|
+
}, this.responseBodyDeadline - Date.now());
|
|
34
|
+
});
|
|
35
|
+
let responseBodyText;
|
|
36
|
+
try {
|
|
37
|
+
responseBodyText = Promise.resolve(this.response.text());
|
|
38
|
+
} catch (error) {
|
|
39
|
+
responseBodyText = Promise.reject(error);
|
|
40
|
+
}
|
|
41
|
+
this.responseBodyTextPromise = Promise.race([
|
|
42
|
+
responseBodyText,
|
|
43
|
+
responseBodyTimeout
|
|
44
|
+
]).finally(()=>clearTimeout(this.responseBodyTimer));
|
|
45
|
+
}
|
|
46
|
+
return this.responseBodyTextPromise;
|
|
17
47
|
}
|
|
18
48
|
get json() {
|
|
19
|
-
return this.
|
|
49
|
+
return this.text.then((text)=>JSON.parse(text));
|
|
50
|
+
}
|
|
51
|
+
cancelResponseBody(reason) {
|
|
52
|
+
clearTimeout(this.responseBodyTimer);
|
|
53
|
+
if (!this.abortController.signal.aborted) this.abortController.abort(reason);
|
|
54
|
+
(async ()=>{
|
|
55
|
+
try {
|
|
56
|
+
await this.response.body?.cancel();
|
|
57
|
+
} catch {}
|
|
58
|
+
})();
|
|
20
59
|
}
|
|
21
60
|
}
|
|
22
61
|
class PostHogFetchNetworkError extends Error {
|
|
@@ -37,7 +76,9 @@ async function logFlushError(err) {
|
|
|
37
76
|
let text = '';
|
|
38
77
|
try {
|
|
39
78
|
text = await err.text;
|
|
40
|
-
} catch {
|
|
79
|
+
} catch {
|
|
80
|
+
if (err.bodyReadTimedOut) text = '<response body read timed out>';
|
|
81
|
+
}
|
|
41
82
|
console.error(`Error while flushing PostHog: message=${err.message}, response body=${text}`, err);
|
|
42
83
|
} else console.error('Error while flushing PostHog', err);
|
|
43
84
|
return Promise.resolve();
|
|
@@ -299,8 +340,11 @@ class PostHogCoreStateless {
|
|
|
299
340
|
}
|
|
300
341
|
};
|
|
301
342
|
return this.fetchWithRetry(url, fetchOptions, {
|
|
343
|
+
type: 'required',
|
|
344
|
+
consume: (response)=>response.json()
|
|
345
|
+
}, {
|
|
302
346
|
retryCount: 0
|
|
303
|
-
}, this.remoteConfigRequestTimeoutMs).
|
|
347
|
+
}, this.remoteConfigRequestTimeoutMs).catch((error)=>{
|
|
304
348
|
this._logger.error('Remote config could not be loaded', error);
|
|
305
349
|
this._events.emit('error', error);
|
|
306
350
|
});
|
|
@@ -329,9 +373,12 @@ class PostHogCoreStateless {
|
|
|
329
373
|
};
|
|
330
374
|
this._logger.info('Flags URL', url);
|
|
331
375
|
return this.fetchWithRetry(url, fetchOptions, {
|
|
376
|
+
type: 'required',
|
|
377
|
+
consume: (response)=>response.json()
|
|
378
|
+
}, {
|
|
332
379
|
retryCount: this.featureFlagsRequestMaxRetries,
|
|
333
380
|
retryCheck: isRetryableFlagsFetchError
|
|
334
|
-
}, this.featureFlagsRequestTimeoutMs).then((response)=>
|
|
381
|
+
}, this.featureFlagsRequestTimeoutMs).then((response)=>({
|
|
335
382
|
success: true,
|
|
336
383
|
response: normalizeFlagsResponse(response)
|
|
337
384
|
})).catch((error)=>{
|
|
@@ -458,15 +505,18 @@ class PostHogCoreStateless {
|
|
|
458
505
|
'Content-Type': 'application/json'
|
|
459
506
|
}
|
|
460
507
|
};
|
|
461
|
-
const response = await this.fetchWithRetry(url, fetchOptions
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
508
|
+
const response = await this.fetchWithRetry(url, fetchOptions, {
|
|
509
|
+
type: 'required',
|
|
510
|
+
consume: (response)=>{
|
|
511
|
+
if (200 !== response.status || !response.json) {
|
|
512
|
+
const msg = `Surveys API could not be loaded: ${response.status}`;
|
|
513
|
+
const error = new Error(msg);
|
|
514
|
+
this._logger.error(error);
|
|
515
|
+
this._events.emit('error', new Error(msg));
|
|
516
|
+
return Promise.resolve(void 0);
|
|
517
|
+
}
|
|
518
|
+
return response.json();
|
|
468
519
|
}
|
|
469
|
-
return response.json();
|
|
470
520
|
}).catch((error)=>{
|
|
471
521
|
this._logger.error('Surveys API could not be loaded', error);
|
|
472
522
|
this._events.emit('error', error);
|
|
@@ -673,8 +723,9 @@ class PostHogCoreStateless {
|
|
|
673
723
|
},
|
|
674
724
|
body: gzippedPayload || payload
|
|
675
725
|
};
|
|
676
|
-
|
|
677
|
-
|
|
726
|
+
await this.fetchWithRetry(url, fetchOptions, {
|
|
727
|
+
type: 'successful-write'
|
|
728
|
+
}, retryOptions);
|
|
678
729
|
}
|
|
679
730
|
async _flush() {
|
|
680
731
|
this.clearFlushTimer();
|
|
@@ -761,6 +812,8 @@ class PostHogCoreStateless {
|
|
|
761
812
|
};
|
|
762
813
|
try {
|
|
763
814
|
await this.fetchWithRetry(url, fetchOptions, {
|
|
815
|
+
type: 'successful-write'
|
|
816
|
+
}, {
|
|
764
817
|
retryCheck: (err)=>{
|
|
765
818
|
if (isPostHogFetchContentTooLargeError(err)) return false;
|
|
766
819
|
return isPostHogFetchRetryableError(err);
|
|
@@ -804,6 +857,8 @@ class PostHogCoreStateless {
|
|
|
804
857
|
};
|
|
805
858
|
try {
|
|
806
859
|
await this.fetchWithRetry(url, fetchOptions, {
|
|
860
|
+
type: 'successful-write'
|
|
861
|
+
}, {
|
|
807
862
|
retryCheck: (err)=>{
|
|
808
863
|
if (isPostHogFetchContentTooLargeError(err)) return false;
|
|
809
864
|
return isPostHogFetchRetryableError(err);
|
|
@@ -826,7 +881,7 @@ class PostHogCoreStateless {
|
|
|
826
881
|
};
|
|
827
882
|
}
|
|
828
883
|
}
|
|
829
|
-
async fetchWithRetry(url, options, retryOptions, requestTimeout) {
|
|
884
|
+
async fetchWithRetry(url, options, responseHandling, retryOptions, requestTimeout) {
|
|
830
885
|
const body = options.body ? options.body : '';
|
|
831
886
|
let reqByteLength = -1;
|
|
832
887
|
try {
|
|
@@ -838,27 +893,86 @@ class PostHogCoreStateless {
|
|
|
838
893
|
reqByteLength = encoded.length;
|
|
839
894
|
}
|
|
840
895
|
}
|
|
896
|
+
const retriableOptions = {
|
|
897
|
+
...this._retryOptions,
|
|
898
|
+
...retryOptions
|
|
899
|
+
};
|
|
900
|
+
let attempt = 0;
|
|
841
901
|
return await retriable(async ()=>{
|
|
902
|
+
attempt++;
|
|
842
903
|
const ctrl = new AbortController();
|
|
843
904
|
const timeoutMs = requestTimeout ?? this.requestTimeout;
|
|
844
|
-
const
|
|
845
|
-
let
|
|
905
|
+
const requestDeadline = Date.now() + timeoutMs;
|
|
906
|
+
let timer;
|
|
907
|
+
const deadline = new Promise((_resolve, reject)=>{
|
|
908
|
+
timer = safeSetTimeout(()=>{
|
|
909
|
+
const timeoutError = new Error(`Request timed out after ${timeoutMs}ms`);
|
|
910
|
+
timeoutError.name = 'AbortError';
|
|
911
|
+
reject(timeoutError);
|
|
912
|
+
ctrl.abort(timeoutError);
|
|
913
|
+
}, timeoutMs);
|
|
914
|
+
});
|
|
915
|
+
let res;
|
|
916
|
+
let responseAccepted = false;
|
|
917
|
+
let cancellation;
|
|
918
|
+
const cancelBody = ()=>cancellation ??= (async ()=>{
|
|
919
|
+
try {
|
|
920
|
+
await res?.body?.cancel();
|
|
921
|
+
} catch {}
|
|
922
|
+
})();
|
|
846
923
|
try {
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
924
|
+
let fetchPromise;
|
|
925
|
+
try {
|
|
926
|
+
fetchPromise = this.fetch(url, {
|
|
927
|
+
signal: ctrl.signal,
|
|
928
|
+
...options
|
|
929
|
+
});
|
|
930
|
+
} catch (e) {
|
|
931
|
+
throw new PostHogFetchNetworkError(e);
|
|
932
|
+
}
|
|
933
|
+
fetchPromise.then((lateResponse)=>{
|
|
934
|
+
if (ctrl.signal.aborted && !responseAccepted) Promise.resolve(lateResponse.body?.cancel()).catch(()=>{});
|
|
935
|
+
}).catch(()=>{});
|
|
936
|
+
try {
|
|
937
|
+
res = await Promise.race([
|
|
938
|
+
fetchPromise,
|
|
939
|
+
deadline
|
|
940
|
+
]);
|
|
941
|
+
responseAccepted = true;
|
|
942
|
+
} catch (e) {
|
|
943
|
+
throw new PostHogFetchNetworkError(e);
|
|
944
|
+
}
|
|
945
|
+
const isNoCors = 'no-cors' === options.mode;
|
|
946
|
+
if (!isNoCors && (res.status < 200 || res.status >= 400)) throw new PostHogFetchHttpError(res, reqByteLength, requestDeadline, ctrl);
|
|
947
|
+
if ('successful-write' === responseHandling.type) {
|
|
948
|
+
try {
|
|
949
|
+
await Promise.race([
|
|
950
|
+
cancelBody(),
|
|
951
|
+
deadline
|
|
952
|
+
]);
|
|
953
|
+
} catch {}
|
|
954
|
+
return;
|
|
955
|
+
}
|
|
956
|
+
try {
|
|
957
|
+
return await Promise.race([
|
|
958
|
+
responseHandling.consume(res),
|
|
959
|
+
deadline
|
|
960
|
+
]);
|
|
961
|
+
} catch (e) {
|
|
962
|
+
if (ctrl.signal.aborted) throw new PostHogFetchNetworkError(e);
|
|
963
|
+
throw e;
|
|
964
|
+
}
|
|
853
965
|
} finally{
|
|
854
966
|
clearTimeout(timer);
|
|
967
|
+
if (ctrl.signal.aborted && res) cancelBody();
|
|
855
968
|
}
|
|
856
|
-
const isNoCors = 'no-cors' === options.mode;
|
|
857
|
-
if (!isNoCors && (res.status < 200 || res.status >= 400)) throw new PostHogFetchHttpError(res, reqByteLength);
|
|
858
|
-
return res;
|
|
859
969
|
}, {
|
|
860
|
-
...
|
|
861
|
-
|
|
970
|
+
...retriableOptions,
|
|
971
|
+
retryCheck: (error)=>{
|
|
972
|
+
const shouldRetry = retriableOptions.retryCheck(error);
|
|
973
|
+
if (shouldRetry && attempt <= retriableOptions.retryCount && error instanceof PostHogFetchHttpError) error.cancelResponseBody();
|
|
974
|
+
return shouldRetry;
|
|
975
|
+
}
|
|
862
976
|
});
|
|
863
977
|
}
|
|
864
978
|
async _shutdown(shutdownTimeoutMs = 30000) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@posthog/core",
|
|
3
|
-
"version": "1.46.
|
|
3
|
+
"version": "1.46.8",
|
|
4
4
|
"bugs": {
|
|
5
5
|
"url": "https://github.com/PostHog/posthog-js/issues"
|
|
6
6
|
},
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
}
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@posthog/types": "^1.401.
|
|
73
|
+
"@posthog/types": "^1.401.1"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
76
|
"@rslib/core": "0.10.6",
|
|
@@ -50,10 +50,15 @@ import {
|
|
|
50
50
|
|
|
51
51
|
class PostHogFetchHttpError extends Error {
|
|
52
52
|
name = 'PostHogFetchHttpError'
|
|
53
|
+
private responseBodyTextPromise?: Promise<string>
|
|
54
|
+
private responseBodyTimer?: ReturnType<typeof safeSetTimeout>
|
|
55
|
+
private _bodyReadTimedOut = false
|
|
53
56
|
|
|
54
57
|
constructor(
|
|
55
58
|
public response: PostHogFetchResponse,
|
|
56
|
-
public reqByteLength: number
|
|
59
|
+
public reqByteLength: number,
|
|
60
|
+
private responseBodyDeadline: number,
|
|
61
|
+
private abortController: AbortController
|
|
57
62
|
) {
|
|
58
63
|
super('HTTP error while fetching PostHog: status=' + response.status + ', reqByteLength=' + reqByteLength)
|
|
59
64
|
}
|
|
@@ -62,12 +67,57 @@ class PostHogFetchHttpError extends Error {
|
|
|
62
67
|
return this.response.status
|
|
63
68
|
}
|
|
64
69
|
|
|
70
|
+
get bodyReadTimedOut(): boolean {
|
|
71
|
+
return this._bodyReadTimedOut
|
|
72
|
+
}
|
|
73
|
+
|
|
65
74
|
get text(): Promise<string> {
|
|
66
|
-
|
|
75
|
+
if (!this.responseBodyTextPromise) {
|
|
76
|
+
if (Date.now() >= this.responseBodyDeadline) {
|
|
77
|
+
this._bodyReadTimedOut = true
|
|
78
|
+
const timeoutError = new Error('Response body read timed out')
|
|
79
|
+
timeoutError.name = 'AbortError'
|
|
80
|
+
this.cancelResponseBody(timeoutError)
|
|
81
|
+
this.responseBodyTextPromise = Promise.reject(timeoutError)
|
|
82
|
+
} else {
|
|
83
|
+
const responseBodyTimeout = new Promise<never>((_resolve, reject) => {
|
|
84
|
+
this.responseBodyTimer = safeSetTimeout(() => {
|
|
85
|
+
this._bodyReadTimedOut = true
|
|
86
|
+
const timeoutError = new Error('Response body read timed out')
|
|
87
|
+
timeoutError.name = 'AbortError'
|
|
88
|
+
// Reject first so the timeout remains the diagnostic if abort rejects the body read synchronously.
|
|
89
|
+
reject(timeoutError)
|
|
90
|
+
this.cancelResponseBody(timeoutError)
|
|
91
|
+
}, this.responseBodyDeadline - Date.now())
|
|
92
|
+
})
|
|
93
|
+
let responseBodyText: Promise<string>
|
|
94
|
+
try {
|
|
95
|
+
responseBodyText = Promise.resolve(this.response.text())
|
|
96
|
+
} catch (error) {
|
|
97
|
+
responseBodyText = Promise.reject(error)
|
|
98
|
+
}
|
|
99
|
+
this.responseBodyTextPromise = Promise.race([responseBodyText, responseBodyTimeout]).finally(() =>
|
|
100
|
+
clearTimeout(this.responseBodyTimer)
|
|
101
|
+
)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return this.responseBodyTextPromise
|
|
67
105
|
}
|
|
68
106
|
|
|
69
107
|
get json(): Promise<any> {
|
|
70
|
-
return this.
|
|
108
|
+
return this.text.then((text) => JSON.parse(text))
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
cancelResponseBody(reason?: unknown): void {
|
|
112
|
+
clearTimeout(this.responseBodyTimer)
|
|
113
|
+
if (!this.abortController.signal.aborted) {
|
|
114
|
+
this.abortController.abort(reason)
|
|
115
|
+
}
|
|
116
|
+
void (async () => {
|
|
117
|
+
try {
|
|
118
|
+
await this.response.body?.cancel()
|
|
119
|
+
} catch {}
|
|
120
|
+
})()
|
|
71
121
|
}
|
|
72
122
|
}
|
|
73
123
|
|
|
@@ -81,6 +131,15 @@ class PostHogFetchNetworkError extends Error {
|
|
|
81
131
|
}
|
|
82
132
|
}
|
|
83
133
|
|
|
134
|
+
type RequiredResponseHandling<T> = {
|
|
135
|
+
type: 'required'
|
|
136
|
+
consume: (response: PostHogFetchResponse) => Promise<T>
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
type SuccessfulWriteResponseHandling = {
|
|
140
|
+
type: 'successful-write'
|
|
141
|
+
}
|
|
142
|
+
|
|
84
143
|
export const maybeAdd = (key: string, value: JsonType | undefined): Record<string, JsonType> =>
|
|
85
144
|
value !== undefined ? { [key]: value } : {}
|
|
86
145
|
|
|
@@ -101,7 +160,11 @@ export async function logFlushError(err: any): Promise<void> {
|
|
|
101
160
|
let text = ''
|
|
102
161
|
try {
|
|
103
162
|
text = await err.text
|
|
104
|
-
} catch {
|
|
163
|
+
} catch {
|
|
164
|
+
if (err.bodyReadTimedOut) {
|
|
165
|
+
text = '<response body read timed out>'
|
|
166
|
+
}
|
|
167
|
+
}
|
|
105
168
|
|
|
106
169
|
console.error(`Error while flushing PostHog: message=${err.message}, response body=${text}`, err)
|
|
107
170
|
} else {
|
|
@@ -612,13 +675,17 @@ export abstract class PostHogCoreStateless {
|
|
|
612
675
|
headers: { ...this.getCustomHeaders(), 'Content-Type': 'application/json' },
|
|
613
676
|
}
|
|
614
677
|
// Don't retry remote config API calls
|
|
615
|
-
return this.fetchWithRetry(
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
678
|
+
return this.fetchWithRetry(
|
|
679
|
+
url,
|
|
680
|
+
fetchOptions,
|
|
681
|
+
{ type: 'required', consume: (response) => response.json() as Promise<PostHogRemoteConfig> },
|
|
682
|
+
{ retryCount: 0 },
|
|
683
|
+
this.remoteConfigRequestTimeoutMs
|
|
684
|
+
).catch((error) => {
|
|
685
|
+
this._logger.error('Remote config could not be loaded', error)
|
|
686
|
+
this._events.emit('error', error)
|
|
687
|
+
return undefined
|
|
688
|
+
})
|
|
622
689
|
}
|
|
623
690
|
|
|
624
691
|
/***
|
|
@@ -669,10 +736,13 @@ export abstract class PostHogCoreStateless {
|
|
|
669
736
|
return this.fetchWithRetry(
|
|
670
737
|
url,
|
|
671
738
|
fetchOptions,
|
|
739
|
+
{
|
|
740
|
+
type: 'required',
|
|
741
|
+
consume: (response) => response.json() as Promise<PostHogV1FlagsResponse | PostHogV2FlagsResponse>,
|
|
742
|
+
},
|
|
672
743
|
{ retryCount: this.featureFlagsRequestMaxRetries, retryCheck: isRetryableFlagsFetchError },
|
|
673
744
|
this.featureFlagsRequestTimeoutMs
|
|
674
745
|
)
|
|
675
|
-
.then((response) => response.json() as Promise<PostHogV1FlagsResponse | PostHogV2FlagsResponse>)
|
|
676
746
|
.then((response) => ({ success: true as const, response: normalizeFlagsResponse(response) }))
|
|
677
747
|
.catch((error): GetFlagsResult => {
|
|
678
748
|
this._events.emit('error', error)
|
|
@@ -972,25 +1042,26 @@ export abstract class PostHogCoreStateless {
|
|
|
972
1042
|
headers: { ...this.getCustomHeaders(), 'Content-Type': 'application/json' },
|
|
973
1043
|
}
|
|
974
1044
|
|
|
975
|
-
const response = await this.fetchWithRetry(url, fetchOptions
|
|
976
|
-
|
|
1045
|
+
const response = await this.fetchWithRetry(url, fetchOptions, {
|
|
1046
|
+
type: 'required',
|
|
1047
|
+
consume: (response) => {
|
|
977
1048
|
if (response.status !== 200 || !response.json) {
|
|
978
1049
|
const msg = `Surveys API could not be loaded: ${response.status}`
|
|
979
1050
|
const error = new Error(msg)
|
|
980
1051
|
this._logger.error(error)
|
|
981
1052
|
|
|
982
1053
|
this._events.emit('error', new Error(msg))
|
|
983
|
-
return undefined
|
|
1054
|
+
return Promise.resolve(undefined)
|
|
984
1055
|
}
|
|
985
1056
|
|
|
986
1057
|
return response.json() as Promise<SurveyResponse>
|
|
987
|
-
}
|
|
988
|
-
|
|
989
|
-
|
|
1058
|
+
},
|
|
1059
|
+
}).catch((error) => {
|
|
1060
|
+
this._logger.error('Surveys API could not be loaded', error)
|
|
990
1061
|
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
1062
|
+
this._events.emit('error', error)
|
|
1063
|
+
return undefined
|
|
1064
|
+
})
|
|
994
1065
|
|
|
995
1066
|
const newSurveys = response?.surveys
|
|
996
1067
|
|
|
@@ -1394,11 +1465,10 @@ export abstract class PostHogCoreStateless {
|
|
|
1394
1465
|
body: gzippedPayload || payload,
|
|
1395
1466
|
}
|
|
1396
1467
|
|
|
1397
|
-
|
|
1398
|
-
//
|
|
1468
|
+
await this.fetchWithRetry(url, fetchOptions, { type: 'successful-write' }, retryOptions)
|
|
1469
|
+
// The response handler above cancels the body to prevent cross-request promise warnings
|
|
1399
1470
|
// in runtimes like Cloudflare Workers that enforce body consumption.
|
|
1400
1471
|
// See: https://github.com/PostHog/posthog-js/issues/3173
|
|
1401
|
-
await response.body?.cancel()?.catch(() => {})
|
|
1402
1472
|
}
|
|
1403
1473
|
|
|
1404
1474
|
private async _flush(): Promise<void> {
|
|
@@ -1552,14 +1622,19 @@ export abstract class PostHogCoreStateless {
|
|
|
1552
1622
|
}
|
|
1553
1623
|
|
|
1554
1624
|
try {
|
|
1555
|
-
await this.fetchWithRetry(
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1625
|
+
await this.fetchWithRetry(
|
|
1626
|
+
url,
|
|
1627
|
+
fetchOptions,
|
|
1628
|
+
{ type: 'successful-write' },
|
|
1629
|
+
{
|
|
1630
|
+
retryCheck: (err) => {
|
|
1631
|
+
if (isPostHogFetchContentTooLargeError(err)) {
|
|
1632
|
+
return false
|
|
1633
|
+
}
|
|
1634
|
+
return isPostHogFetchRetryableError(err)
|
|
1635
|
+
},
|
|
1636
|
+
}
|
|
1637
|
+
)
|
|
1563
1638
|
return { kind: 'ok' }
|
|
1564
1639
|
} catch (err) {
|
|
1565
1640
|
if (isPostHogFetchContentTooLargeError(err)) {
|
|
@@ -1598,14 +1673,19 @@ export abstract class PostHogCoreStateless {
|
|
|
1598
1673
|
}
|
|
1599
1674
|
|
|
1600
1675
|
try {
|
|
1601
|
-
await this.fetchWithRetry(
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1676
|
+
await this.fetchWithRetry(
|
|
1677
|
+
url,
|
|
1678
|
+
fetchOptions,
|
|
1679
|
+
{ type: 'successful-write' },
|
|
1680
|
+
{
|
|
1681
|
+
retryCheck: (err) => {
|
|
1682
|
+
if (isPostHogFetchContentTooLargeError(err)) {
|
|
1683
|
+
return false
|
|
1684
|
+
}
|
|
1685
|
+
return isPostHogFetchRetryableError(err)
|
|
1686
|
+
},
|
|
1687
|
+
}
|
|
1688
|
+
)
|
|
1609
1689
|
return { kind: 'ok' }
|
|
1610
1690
|
} catch (err) {
|
|
1611
1691
|
if (isPostHogFetchContentTooLargeError(err)) {
|
|
@@ -1621,12 +1701,27 @@ export abstract class PostHogCoreStateless {
|
|
|
1621
1701
|
}
|
|
1622
1702
|
}
|
|
1623
1703
|
|
|
1624
|
-
private
|
|
1704
|
+
private fetchWithRetry<T>(
|
|
1625
1705
|
url: string,
|
|
1626
1706
|
options: PostHogFetchOptions,
|
|
1707
|
+
responseHandling: RequiredResponseHandling<T>,
|
|
1627
1708
|
retryOptions?: Partial<RetriableOptions>,
|
|
1628
1709
|
requestTimeout?: number
|
|
1629
|
-
): Promise<
|
|
1710
|
+
): Promise<T>
|
|
1711
|
+
private fetchWithRetry(
|
|
1712
|
+
url: string,
|
|
1713
|
+
options: PostHogFetchOptions,
|
|
1714
|
+
responseHandling: SuccessfulWriteResponseHandling,
|
|
1715
|
+
retryOptions?: Partial<RetriableOptions>,
|
|
1716
|
+
requestTimeout?: number
|
|
1717
|
+
): Promise<void>
|
|
1718
|
+
private async fetchWithRetry<T>(
|
|
1719
|
+
url: string,
|
|
1720
|
+
options: PostHogFetchOptions,
|
|
1721
|
+
responseHandling: RequiredResponseHandling<T> | SuccessfulWriteResponseHandling,
|
|
1722
|
+
retryOptions?: Partial<RetriableOptions>,
|
|
1723
|
+
requestTimeout?: number
|
|
1724
|
+
): Promise<T | void> {
|
|
1630
1725
|
const body = options.body ? options.body : ''
|
|
1631
1726
|
let reqByteLength = -1
|
|
1632
1727
|
try {
|
|
@@ -1644,34 +1739,115 @@ export abstract class PostHogCoreStateless {
|
|
|
1644
1739
|
}
|
|
1645
1740
|
}
|
|
1646
1741
|
|
|
1742
|
+
const retriableOptions = { ...this._retryOptions, ...retryOptions }
|
|
1743
|
+
let attempt = 0
|
|
1744
|
+
|
|
1647
1745
|
return await retriable(
|
|
1648
1746
|
async () => {
|
|
1747
|
+
attempt++
|
|
1649
1748
|
const ctrl = new AbortController()
|
|
1650
1749
|
const timeoutMs = requestTimeout ?? this.requestTimeout
|
|
1651
|
-
const
|
|
1750
|
+
const requestDeadline = Date.now() + timeoutMs
|
|
1751
|
+
let timer: ReturnType<typeof safeSetTimeout>
|
|
1752
|
+
// `fetch` is SDK-injectable, so it may ignore abort while resolving headers or
|
|
1753
|
+
// consuming the body. Race both phases against one request deadline rather than
|
|
1754
|
+
// relying only on standards-compliant AbortSignal behavior.
|
|
1755
|
+
const deadline = new Promise<never>((_resolve, reject) => {
|
|
1756
|
+
timer = safeSetTimeout(() => {
|
|
1757
|
+
const timeoutError = new Error(`Request timed out after ${timeoutMs}ms`)
|
|
1758
|
+
timeoutError.name = 'AbortError'
|
|
1759
|
+
// Reject first so this error wins if an abort-aware injected fetch rejects synchronously.
|
|
1760
|
+
reject(timeoutError)
|
|
1761
|
+
ctrl.abort(timeoutError)
|
|
1762
|
+
}, timeoutMs)
|
|
1763
|
+
})
|
|
1764
|
+
|
|
1765
|
+
let res: PostHogFetchResponse | undefined
|
|
1766
|
+
let responseAccepted = false
|
|
1767
|
+
let cancellation: Promise<void> | undefined
|
|
1768
|
+
const cancelBody = (): Promise<void> =>
|
|
1769
|
+
(cancellation ??= (async () => {
|
|
1770
|
+
try {
|
|
1771
|
+
await res?.body?.cancel()
|
|
1772
|
+
} catch {}
|
|
1773
|
+
})())
|
|
1652
1774
|
|
|
1653
|
-
let res: PostHogFetchResponse | null = null
|
|
1654
1775
|
try {
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1776
|
+
let fetchPromise: Promise<PostHogFetchResponse>
|
|
1777
|
+
try {
|
|
1778
|
+
fetchPromise = this.fetch(url, {
|
|
1779
|
+
signal: ctrl.signal,
|
|
1780
|
+
...options,
|
|
1781
|
+
})
|
|
1782
|
+
} catch (e) {
|
|
1783
|
+
throw new PostHogFetchNetworkError(e)
|
|
1784
|
+
}
|
|
1785
|
+
void fetchPromise
|
|
1786
|
+
.then((lateResponse) => {
|
|
1787
|
+
if (ctrl.signal.aborted && !responseAccepted) {
|
|
1788
|
+
// Release a late response from an injected fetch that ignored the header deadline.
|
|
1789
|
+
void Promise.resolve(lateResponse.body?.cancel()).catch(() => {})
|
|
1790
|
+
}
|
|
1791
|
+
})
|
|
1792
|
+
.catch(() => {})
|
|
1793
|
+
|
|
1794
|
+
try {
|
|
1795
|
+
res = await Promise.race([fetchPromise, deadline])
|
|
1796
|
+
responseAccepted = true
|
|
1797
|
+
} catch (e) {
|
|
1798
|
+
// Fetch only throws on network errors or timeouts. The explicit deadline also
|
|
1799
|
+
// reaches injected fetch implementations that ignore the abort signal.
|
|
1800
|
+
throw new PostHogFetchNetworkError(e)
|
|
1801
|
+
}
|
|
1802
|
+
|
|
1803
|
+
// If we're in no-cors mode, we can't access the response status.
|
|
1804
|
+
// We only throw on HTTP errors if we're not in no-cors mode.
|
|
1805
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/Request/mode#no-cors
|
|
1806
|
+
const isNoCors = options.mode === 'no-cors'
|
|
1807
|
+
if (!isNoCors && (res.status < 200 || res.status >= 400)) {
|
|
1808
|
+
// Read error bodies lazily so retryable statuses are retried immediately. The
|
|
1809
|
+
// getter still uses this attempt's deadline when diagnostics request the body.
|
|
1810
|
+
throw new PostHogFetchHttpError(res, reqByteLength, requestDeadline, ctrl)
|
|
1811
|
+
}
|
|
1812
|
+
|
|
1813
|
+
if (responseHandling.type === 'successful-write') {
|
|
1814
|
+
try {
|
|
1815
|
+
await Promise.race([cancelBody(), deadline])
|
|
1816
|
+
} catch {
|
|
1817
|
+
// Once a write endpoint has returned success, a stalled body cancellation
|
|
1818
|
+
// must not retry the accepted payload. Cancellation was attempted for the
|
|
1819
|
+
// full remaining deadline and continues best-effort in `finally`.
|
|
1820
|
+
}
|
|
1821
|
+
return
|
|
1822
|
+
}
|
|
1823
|
+
|
|
1824
|
+
try {
|
|
1825
|
+
return await Promise.race([responseHandling.consume(res), deadline])
|
|
1826
|
+
} catch (e) {
|
|
1827
|
+
if (ctrl.signal.aborted) {
|
|
1828
|
+
throw new PostHogFetchNetworkError(e)
|
|
1829
|
+
}
|
|
1830
|
+
throw e
|
|
1831
|
+
}
|
|
1662
1832
|
} finally {
|
|
1663
1833
|
clearTimeout(timer)
|
|
1834
|
+
if (ctrl.signal.aborted && res) {
|
|
1835
|
+
// Do not await after the deadline: injected body cancellation may itself never settle.
|
|
1836
|
+
void cancelBody()
|
|
1837
|
+
}
|
|
1664
1838
|
}
|
|
1665
|
-
// If we're in no-cors mode, we can't access the response status
|
|
1666
|
-
// We only throw on HTTP errors if we're not in no-cors mode
|
|
1667
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/Request/mode#no-cors
|
|
1668
|
-
const isNoCors = options.mode === 'no-cors'
|
|
1669
|
-
if (!isNoCors && (res.status < 200 || res.status >= 400)) {
|
|
1670
|
-
throw new PostHogFetchHttpError(res, reqByteLength)
|
|
1671
|
-
}
|
|
1672
|
-
return res
|
|
1673
1839
|
},
|
|
1674
|
-
{
|
|
1840
|
+
{
|
|
1841
|
+
...retriableOptions,
|
|
1842
|
+
retryCheck: (error) => {
|
|
1843
|
+
const shouldRetry = retriableOptions.retryCheck(error)
|
|
1844
|
+
if (shouldRetry && attempt <= retriableOptions.retryCount && error instanceof PostHogFetchHttpError) {
|
|
1845
|
+
// This response will not be surfaced, so release its body without delaying the retry.
|
|
1846
|
+
error.cancelResponseBody()
|
|
1847
|
+
}
|
|
1848
|
+
return shouldRetry
|
|
1849
|
+
},
|
|
1850
|
+
}
|
|
1675
1851
|
)
|
|
1676
1852
|
}
|
|
1677
1853
|
|