@posthog/core 1.39.2 → 1.39.4
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/dist/posthog-core-stateless.d.ts +4 -0
- package/dist/posthog-core-stateless.d.ts.map +1 -1
- package/dist/posthog-core-stateless.js +36 -5
- package/dist/posthog-core-stateless.mjs +36 -5
- package/dist/testing/PostHogCoreTestClient.d.ts +1 -0
- package/dist/testing/PostHogCoreTestClient.d.ts.map +1 -1
- package/dist/testing/PostHogCoreTestClient.js +3 -0
- package/dist/testing/PostHogCoreTestClient.mjs +3 -0
- package/dist/utils/promise-queue.d.ts +3 -0
- package/dist/utils/promise-queue.d.ts.map +1 -1
- package/dist/utils/promise-queue.js +15 -3
- package/dist/utils/promise-queue.mjs +15 -3
- package/package.json +1 -1
- package/src/posthog-core-stateless.ts +61 -10
- package/src/testing/PostHogCoreTestClient.ts +4 -0
- package/src/utils/promise-queue.ts +17 -4
|
@@ -55,6 +55,7 @@ export declare abstract class PostHogCoreStateless {
|
|
|
55
55
|
private maxQueueSize;
|
|
56
56
|
private flushInterval;
|
|
57
57
|
private flushPromise;
|
|
58
|
+
private flushPromises;
|
|
58
59
|
private shutdownPromise;
|
|
59
60
|
private requestTimeout;
|
|
60
61
|
private featureFlagsRequestTimeoutMs;
|
|
@@ -222,6 +223,7 @@ export declare abstract class PostHogCoreStateless {
|
|
|
222
223
|
* Avoids unnecessary promise errors
|
|
223
224
|
*/
|
|
224
225
|
private flushBackground;
|
|
226
|
+
private waitForPendingPromises;
|
|
225
227
|
/**
|
|
226
228
|
* Flushes the queue of pending events.
|
|
227
229
|
*
|
|
@@ -250,7 +252,9 @@ export declare abstract class PostHogCoreStateless {
|
|
|
250
252
|
* @throws PostHogFetchNetworkError
|
|
251
253
|
* @throws Error
|
|
252
254
|
*/
|
|
255
|
+
protected flushWithPendingPromises(): Promise<void>;
|
|
253
256
|
flush(): Promise<void>;
|
|
257
|
+
private flushInternal;
|
|
254
258
|
protected getCustomHeaders(): {
|
|
255
259
|
[key: string]: string;
|
|
256
260
|
};
|
|
@@ -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,MAAM,gBAAgB,CAAA;AACrD,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,EAMjB,MAAM,SAAS,CAAA;AAEhB,OAAO,EACL,sBAAsB,EAMvB,MAAM,kBAAkB,CAAA;AAyBzB,cAAM,wBAAyB,SAAQ,KAAK;IAGvB,KAAK,EAAE,OAAO;IAFjC,IAAI,SAA6B;gBAEd,KAAK,EAAE,OAAO;CAMlC;AAED,eAAO,MAAM,QAAQ,GAAI,KAAK,MAAM,EAAE,OAAO,QAAQ,GAAG,SAAS,KAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,CAC9C,CAAA;AAE7C,wBAAsB,aAAa,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAY3D;AAMD;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,wBAAwB,CAExF;
|
|
1
|
+
{"version":3,"file":"posthog-core-stateless.d.ts","sourceRoot":"","sources":["../src/posthog-core-stateless.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,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IACG,cAAc,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,oBAAoB,CAAC;YAwC/D,cAAc;IAsDtB,SAAS,CAAC,iBAAiB,GAAE,MAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IA0DjE;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACG,QAAQ,CAAC,iBAAiB,GAAE,MAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAYjE"}
|
|
@@ -78,6 +78,7 @@ function isPostHogFetchNetworkError(err) {
|
|
|
78
78
|
return err instanceof PostHogFetchNetworkError;
|
|
79
79
|
}
|
|
80
80
|
function isRetryableFlagsFetchError(err) {
|
|
81
|
+
if (err instanceof PostHogFetchHttpError) return 502 === err.status || 504 === err.status;
|
|
81
82
|
if (!(err instanceof PostHogFetchNetworkError)) return false;
|
|
82
83
|
const cause = err.error;
|
|
83
84
|
const code = cause?.code ?? cause?.cause?.code;
|
|
@@ -113,6 +114,7 @@ class PostHogCoreStateless {
|
|
|
113
114
|
}
|
|
114
115
|
constructor(apiKey, options = {}){
|
|
115
116
|
this.flushPromise = null;
|
|
117
|
+
this.flushPromises = new Set();
|
|
116
118
|
this.shutdownPromise = null;
|
|
117
119
|
this.promiseQueue = new index_js_namespaceObject.PromiseQueue();
|
|
118
120
|
this._events = new external_eventemitter_js_namespaceObject.SimpleEventEmitter();
|
|
@@ -619,16 +621,45 @@ class PostHogCoreStateless {
|
|
|
619
621
|
await logFlushError(err);
|
|
620
622
|
});
|
|
621
623
|
}
|
|
622
|
-
async
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
624
|
+
async waitForPendingPromises(maxPromiseId, ignoredPromises = []) {
|
|
625
|
+
const ignoredPendingPromises = ignoredPromises.filter((promise)=>!!promise);
|
|
626
|
+
let iteration = 0;
|
|
627
|
+
while(true){
|
|
628
|
+
const promises = this.promiseQueue.getPromises([
|
|
629
|
+
...ignoredPendingPromises,
|
|
630
|
+
...this.flushPromises
|
|
631
|
+
], maxPromiseId);
|
|
632
|
+
if (0 === promises.length) return;
|
|
633
|
+
if (iteration > 0) this._logger.debug(`flush() re-checking ${promises.length} pending promise(s) before flushing`);
|
|
634
|
+
await Promise.all(promises.map((promise)=>promise.catch(()=>{})));
|
|
635
|
+
iteration++;
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
flushWithPendingPromises() {
|
|
639
|
+
return this.flushInternal(true);
|
|
640
|
+
}
|
|
641
|
+
flush() {
|
|
642
|
+
return this.flushInternal(false);
|
|
643
|
+
}
|
|
644
|
+
flushInternal(waitForPendingPromises) {
|
|
645
|
+
if (this.disabled) return Promise.resolve();
|
|
646
|
+
const previousFlushPromise = this.flushPromise;
|
|
647
|
+
const maxPromiseId = this.promiseQueue.maxId;
|
|
648
|
+
const nextFlushPromise = Promise.resolve().then(()=>{
|
|
649
|
+
if (waitForPendingPromises) return this.waitForPendingPromises(maxPromiseId, [
|
|
650
|
+
previousFlushPromise,
|
|
651
|
+
nextFlushPromise
|
|
652
|
+
]);
|
|
653
|
+
}).then(()=>(0, index_js_namespaceObject.allSettled)([
|
|
654
|
+
previousFlushPromise
|
|
655
|
+
])).then(()=>this._flush());
|
|
627
656
|
this.flushPromise = nextFlushPromise;
|
|
657
|
+
this.flushPromises.add(nextFlushPromise);
|
|
628
658
|
this.addPendingPromise(nextFlushPromise);
|
|
629
659
|
(0, index_js_namespaceObject.allSettled)([
|
|
630
660
|
nextFlushPromise
|
|
631
661
|
]).then(()=>{
|
|
662
|
+
this.flushPromises.delete(nextFlushPromise);
|
|
632
663
|
if (this.flushPromise === nextFlushPromise) this.flushPromise = null;
|
|
633
664
|
});
|
|
634
665
|
return nextFlushPromise;
|
|
@@ -46,6 +46,7 @@ function isPostHogFetchNetworkError(err) {
|
|
|
46
46
|
return err instanceof PostHogFetchNetworkError;
|
|
47
47
|
}
|
|
48
48
|
function isRetryableFlagsFetchError(err) {
|
|
49
|
+
if (err instanceof PostHogFetchHttpError) return 502 === err.status || 504 === err.status;
|
|
49
50
|
if (!(err instanceof PostHogFetchNetworkError)) return false;
|
|
50
51
|
const cause = err.error;
|
|
51
52
|
const code = cause?.code ?? cause?.cause?.code;
|
|
@@ -81,6 +82,7 @@ class PostHogCoreStateless {
|
|
|
81
82
|
}
|
|
82
83
|
constructor(apiKey, options = {}){
|
|
83
84
|
this.flushPromise = null;
|
|
85
|
+
this.flushPromises = new Set();
|
|
84
86
|
this.shutdownPromise = null;
|
|
85
87
|
this.promiseQueue = new PromiseQueue();
|
|
86
88
|
this._events = new SimpleEventEmitter();
|
|
@@ -587,16 +589,45 @@ class PostHogCoreStateless {
|
|
|
587
589
|
await logFlushError(err);
|
|
588
590
|
});
|
|
589
591
|
}
|
|
590
|
-
async
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
592
|
+
async waitForPendingPromises(maxPromiseId, ignoredPromises = []) {
|
|
593
|
+
const ignoredPendingPromises = ignoredPromises.filter((promise)=>!!promise);
|
|
594
|
+
let iteration = 0;
|
|
595
|
+
while(true){
|
|
596
|
+
const promises = this.promiseQueue.getPromises([
|
|
597
|
+
...ignoredPendingPromises,
|
|
598
|
+
...this.flushPromises
|
|
599
|
+
], maxPromiseId);
|
|
600
|
+
if (0 === promises.length) return;
|
|
601
|
+
if (iteration > 0) this._logger.debug(`flush() re-checking ${promises.length} pending promise(s) before flushing`);
|
|
602
|
+
await Promise.all(promises.map((promise)=>promise.catch(()=>{})));
|
|
603
|
+
iteration++;
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
flushWithPendingPromises() {
|
|
607
|
+
return this.flushInternal(true);
|
|
608
|
+
}
|
|
609
|
+
flush() {
|
|
610
|
+
return this.flushInternal(false);
|
|
611
|
+
}
|
|
612
|
+
flushInternal(waitForPendingPromises) {
|
|
613
|
+
if (this.disabled) return Promise.resolve();
|
|
614
|
+
const previousFlushPromise = this.flushPromise;
|
|
615
|
+
const maxPromiseId = this.promiseQueue.maxId;
|
|
616
|
+
const nextFlushPromise = Promise.resolve().then(()=>{
|
|
617
|
+
if (waitForPendingPromises) return this.waitForPendingPromises(maxPromiseId, [
|
|
618
|
+
previousFlushPromise,
|
|
619
|
+
nextFlushPromise
|
|
620
|
+
]);
|
|
621
|
+
}).then(()=>allSettled([
|
|
622
|
+
previousFlushPromise
|
|
623
|
+
])).then(()=>this._flush());
|
|
595
624
|
this.flushPromise = nextFlushPromise;
|
|
625
|
+
this.flushPromises.add(nextFlushPromise);
|
|
596
626
|
this.addPendingPromise(nextFlushPromise);
|
|
597
627
|
allSettled([
|
|
598
628
|
nextFlushPromise
|
|
599
629
|
]).then(()=>{
|
|
630
|
+
this.flushPromises.delete(nextFlushPromise);
|
|
600
631
|
if (this.flushPromise === nextFlushPromise) this.flushPromise = null;
|
|
601
632
|
});
|
|
602
633
|
return nextFlushPromise;
|
|
@@ -12,6 +12,7 @@ export declare class PostHogCoreTestClient extends PostHogCore {
|
|
|
12
12
|
_cachedDistinctId?: string;
|
|
13
13
|
constructor(mocks: PostHogCoreTestClientMocks, apiKey: string, options?: PostHogCoreOptions);
|
|
14
14
|
getFlags(distinctId: string, groups?: Record<string, string | number>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, extraPayload?: Record<string, any>): Promise<GetFlagsResult>;
|
|
15
|
+
flushWithPendingPromises(): Promise<void>;
|
|
15
16
|
getPersistedProperty<T>(key: string): T;
|
|
16
17
|
setPersistedProperty<T>(key: string, value: T | null): void;
|
|
17
18
|
fetch(url: string, options: PostHogFetchOptions): Promise<PostHogFetchResponse>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PostHogCoreTestClient.d.ts","sourceRoot":"","sources":["../../src/testing/PostHogCoreTestClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAA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M;CAG7B;AAED,eAAO,MAAM,gBAAgB,GAC3B,QAAQ,MAAM,EACd,UAAU,kBAAkB,EAC5B,aAAa,CAAC,KAAK,EAAE,0BAA0B,KAAK,IAAI,EACxD,eAAc;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAA;CAAO,KACtD,CAAC,qBAAqB,EAAE,0BAA0B,CAsBpD,CAAA"}
|
|
@@ -37,6 +37,9 @@ class PostHogCoreTestClient extends external_posthog_core_js_namespaceObject.Pos
|
|
|
37
37
|
getFlags(distinctId, groups = {}, personProperties = {}, groupProperties = {}, extraPayload = {}) {
|
|
38
38
|
return super.getFlags(distinctId, groups, personProperties, groupProperties, extraPayload);
|
|
39
39
|
}
|
|
40
|
+
flushWithPendingPromises() {
|
|
41
|
+
return super.flushWithPendingPromises();
|
|
42
|
+
}
|
|
40
43
|
getPersistedProperty(key) {
|
|
41
44
|
return this.mocks.storage.getItem(key);
|
|
42
45
|
}
|
|
@@ -8,6 +8,9 @@ class PostHogCoreTestClient extends PostHogCore {
|
|
|
8
8
|
getFlags(distinctId, groups = {}, personProperties = {}, groupProperties = {}, extraPayload = {}) {
|
|
9
9
|
return super.getFlags(distinctId, groups, personProperties, groupProperties, extraPayload);
|
|
10
10
|
}
|
|
11
|
+
flushWithPendingPromises() {
|
|
12
|
+
return super.flushWithPendingPromises();
|
|
13
|
+
}
|
|
11
14
|
getPersistedProperty(key) {
|
|
12
15
|
return this.mocks.storage.getItem(key);
|
|
13
16
|
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
export declare class PromiseQueue {
|
|
2
2
|
private promiseByIds;
|
|
3
|
+
private nextId;
|
|
3
4
|
add(promise: Promise<any>): Promise<any>;
|
|
4
5
|
join(): Promise<void>;
|
|
6
|
+
getPromises(ignoredPromises?: Promise<any>[], maxId?: number): Promise<any>[];
|
|
7
|
+
get maxId(): number;
|
|
5
8
|
get length(): number;
|
|
6
9
|
}
|
|
7
10
|
//# sourceMappingURL=promise-queue.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promise-queue.d.ts","sourceRoot":"","sources":["../../src/utils/promise-queue.ts"],"names":[],"mappings":"AAEA,qBAAa,YAAY;IACvB,OAAO,CAAC,YAAY,
|
|
1
|
+
{"version":3,"file":"promise-queue.d.ts","sourceRoot":"","sources":["../../src/utils/promise-queue.ts"],"names":[],"mappings":"AAEA,qBAAa,YAAY;IACvB,OAAO,CAAC,YAAY,CAA4D;IAChF,OAAO,CAAC,MAAM,CAAY;IAEnB,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC;IAYlC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAU3B,WAAW,CAAC,eAAe,GAAE,OAAO,CAAC,GAAG,CAAC,EAAO,EAAE,KAAK,GAAE,MAAoB,GAAG,OAAO,CAAC,GAAG,CAAC,EAAE;IAOrG,IAAW,KAAK,IAAI,MAAM,CAEzB;IAED,IAAW,MAAM,IAAI,MAAM,CAE1B;CACF"}
|
|
@@ -30,26 +30,38 @@ const uuidv7_js_namespaceObject = require("../vendor/uuidv7.js");
|
|
|
30
30
|
class PromiseQueue {
|
|
31
31
|
add(promise) {
|
|
32
32
|
const promiseUUID = (0, uuidv7_js_namespaceObject.uuidv7)();
|
|
33
|
-
|
|
33
|
+
const id = ++this.nextId;
|
|
34
|
+
this.promiseByIds[promiseUUID] = {
|
|
35
|
+
id,
|
|
36
|
+
promise
|
|
37
|
+
};
|
|
34
38
|
promise.catch(()=>{}).finally(()=>{
|
|
35
39
|
delete this.promiseByIds[promiseUUID];
|
|
36
40
|
});
|
|
37
41
|
return promise;
|
|
38
42
|
}
|
|
39
43
|
async join() {
|
|
40
|
-
let promises = Object.values(this.promiseByIds);
|
|
44
|
+
let promises = Object.values(this.promiseByIds).map((item)=>item.promise);
|
|
41
45
|
let length = promises.length;
|
|
42
46
|
while(length > 0){
|
|
43
47
|
await Promise.all(promises);
|
|
44
|
-
promises = Object.values(this.promiseByIds);
|
|
48
|
+
promises = Object.values(this.promiseByIds).map((item)=>item.promise);
|
|
45
49
|
length = promises.length;
|
|
46
50
|
}
|
|
47
51
|
}
|
|
52
|
+
getPromises(ignoredPromises = [], maxId = this.nextId) {
|
|
53
|
+
const ignoredPromiseSet = new Set(ignoredPromises);
|
|
54
|
+
return Object.values(this.promiseByIds).filter((item)=>item.id <= maxId && !ignoredPromiseSet.has(item.promise)).map((item)=>item.promise);
|
|
55
|
+
}
|
|
56
|
+
get maxId() {
|
|
57
|
+
return this.nextId;
|
|
58
|
+
}
|
|
48
59
|
get length() {
|
|
49
60
|
return Object.keys(this.promiseByIds).length;
|
|
50
61
|
}
|
|
51
62
|
constructor(){
|
|
52
63
|
this.promiseByIds = {};
|
|
64
|
+
this.nextId = 0;
|
|
53
65
|
}
|
|
54
66
|
}
|
|
55
67
|
exports.PromiseQueue = __webpack_exports__.PromiseQueue;
|
|
@@ -2,26 +2,38 @@ import { uuidv7 } from "../vendor/uuidv7.mjs";
|
|
|
2
2
|
class PromiseQueue {
|
|
3
3
|
add(promise) {
|
|
4
4
|
const promiseUUID = uuidv7();
|
|
5
|
-
|
|
5
|
+
const id = ++this.nextId;
|
|
6
|
+
this.promiseByIds[promiseUUID] = {
|
|
7
|
+
id,
|
|
8
|
+
promise
|
|
9
|
+
};
|
|
6
10
|
promise.catch(()=>{}).finally(()=>{
|
|
7
11
|
delete this.promiseByIds[promiseUUID];
|
|
8
12
|
});
|
|
9
13
|
return promise;
|
|
10
14
|
}
|
|
11
15
|
async join() {
|
|
12
|
-
let promises = Object.values(this.promiseByIds);
|
|
16
|
+
let promises = Object.values(this.promiseByIds).map((item)=>item.promise);
|
|
13
17
|
let length = promises.length;
|
|
14
18
|
while(length > 0){
|
|
15
19
|
await Promise.all(promises);
|
|
16
|
-
promises = Object.values(this.promiseByIds);
|
|
20
|
+
promises = Object.values(this.promiseByIds).map((item)=>item.promise);
|
|
17
21
|
length = promises.length;
|
|
18
22
|
}
|
|
19
23
|
}
|
|
24
|
+
getPromises(ignoredPromises = [], maxId = this.nextId) {
|
|
25
|
+
const ignoredPromiseSet = new Set(ignoredPromises);
|
|
26
|
+
return Object.values(this.promiseByIds).filter((item)=>item.id <= maxId && !ignoredPromiseSet.has(item.promise)).map((item)=>item.promise);
|
|
27
|
+
}
|
|
28
|
+
get maxId() {
|
|
29
|
+
return this.nextId;
|
|
30
|
+
}
|
|
20
31
|
get length() {
|
|
21
32
|
return Object.keys(this.promiseByIds).length;
|
|
22
33
|
}
|
|
23
34
|
constructor(){
|
|
24
35
|
this.promiseByIds = {};
|
|
36
|
+
this.nextId = 0;
|
|
25
37
|
}
|
|
26
38
|
}
|
|
27
39
|
export { PromiseQueue };
|
package/package.json
CHANGED
|
@@ -113,7 +113,13 @@ export function isPostHogFetchNetworkError(err: unknown): err is PostHogFetchNet
|
|
|
113
113
|
return err instanceof PostHogFetchNetworkError
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
function isRetryableFlagsFetchError(
|
|
116
|
+
function isRetryableFlagsFetchError(
|
|
117
|
+
err: unknown
|
|
118
|
+
): err is PostHogFetchNetworkError | (PostHogFetchHttpError & { status: 502 | 504 }) {
|
|
119
|
+
if (err instanceof PostHogFetchHttpError) {
|
|
120
|
+
return err.status === 502 || err.status === 504
|
|
121
|
+
}
|
|
122
|
+
|
|
117
123
|
if (!(err instanceof PostHogFetchNetworkError)) {
|
|
118
124
|
return false
|
|
119
125
|
}
|
|
@@ -171,6 +177,7 @@ export abstract class PostHogCoreStateless {
|
|
|
171
177
|
private maxQueueSize: number
|
|
172
178
|
private flushInterval: number
|
|
173
179
|
private flushPromise: Promise<any> | null = null
|
|
180
|
+
private flushPromises: Set<Promise<any>> = new Set()
|
|
174
181
|
private shutdownPromise: Promise<void> | null = null
|
|
175
182
|
private requestTimeout: number
|
|
176
183
|
private featureFlagsRequestTimeoutMs: number
|
|
@@ -615,7 +622,7 @@ export abstract class PostHogCoreStateless {
|
|
|
615
622
|
|
|
616
623
|
this._logger.info('Flags URL', url)
|
|
617
624
|
|
|
618
|
-
// Retry only network/transport/timeout failures
|
|
625
|
+
// Retry only network/transport/timeout failures and selected gateway HTTP errors for /flags.
|
|
619
626
|
return this.fetchWithRetry(
|
|
620
627
|
url,
|
|
621
628
|
fetchOptions,
|
|
@@ -1174,6 +1181,28 @@ export abstract class PostHogCoreStateless {
|
|
|
1174
1181
|
})
|
|
1175
1182
|
}
|
|
1176
1183
|
|
|
1184
|
+
private async waitForPendingPromises(
|
|
1185
|
+
maxPromiseId: number,
|
|
1186
|
+
ignoredPromises: (Promise<any> | null | undefined)[] = []
|
|
1187
|
+
): Promise<void> {
|
|
1188
|
+
const ignoredPendingPromises = ignoredPromises.filter((promise): promise is Promise<any> => !!promise)
|
|
1189
|
+
let iteration = 0
|
|
1190
|
+
|
|
1191
|
+
while (true) {
|
|
1192
|
+
const promises = this.promiseQueue.getPromises([...ignoredPendingPromises, ...this.flushPromises], maxPromiseId)
|
|
1193
|
+
if (promises.length === 0) {
|
|
1194
|
+
return
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
if (iteration > 0) {
|
|
1198
|
+
this._logger.debug(`flush() re-checking ${promises.length} pending promise(s) before flushing`)
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
await Promise.all(promises.map((promise) => promise.catch(() => {})))
|
|
1202
|
+
iteration++
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1177
1206
|
/**
|
|
1178
1207
|
* Flushes the queue of pending events.
|
|
1179
1208
|
*
|
|
@@ -1202,22 +1231,44 @@ export abstract class PostHogCoreStateless {
|
|
|
1202
1231
|
* @throws PostHogFetchNetworkError
|
|
1203
1232
|
* @throws Error
|
|
1204
1233
|
*/
|
|
1205
|
-
|
|
1234
|
+
protected flushWithPendingPromises(): Promise<void> {
|
|
1235
|
+
return this.flushInternal(true)
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
flush(): Promise<void> {
|
|
1239
|
+
return this.flushInternal(false)
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1242
|
+
private flushInternal(waitForPendingPromises: boolean): Promise<void> {
|
|
1206
1243
|
if (this.disabled) {
|
|
1207
|
-
return
|
|
1244
|
+
return Promise.resolve()
|
|
1208
1245
|
}
|
|
1209
1246
|
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1247
|
+
const previousFlushPromise = this.flushPromise
|
|
1248
|
+
const maxPromiseId = this.promiseQueue.maxId
|
|
1249
|
+
|
|
1250
|
+
// Register this flush in the promise queue synchronously so shutdown() can't miss it,
|
|
1251
|
+
// but exclude it from the pending-work wait to avoid self-waiting.
|
|
1252
|
+
const nextFlushPromise: Promise<void> = Promise.resolve()
|
|
1253
|
+
.then(() => {
|
|
1254
|
+
if (waitForPendingPromises) {
|
|
1255
|
+
return this.waitForPendingPromises(maxPromiseId, [previousFlushPromise, nextFlushPromise])
|
|
1256
|
+
}
|
|
1257
|
+
})
|
|
1258
|
+
// Wait for the current flush operation to finish (regardless of success or failure), then try to flush again.
|
|
1259
|
+
// Use allSettled instead of finally to be defensive around flush throwing errors immediately rather than rejecting.
|
|
1260
|
+
// Use a custom allSettled implementation to avoid issues with patching Promise on RN
|
|
1261
|
+
.then(() => allSettled([previousFlushPromise]))
|
|
1262
|
+
.then(() => {
|
|
1263
|
+
return this._flush()
|
|
1264
|
+
})
|
|
1216
1265
|
|
|
1217
1266
|
this.flushPromise = nextFlushPromise
|
|
1267
|
+
this.flushPromises.add(nextFlushPromise)
|
|
1218
1268
|
void this.addPendingPromise(nextFlushPromise)
|
|
1219
1269
|
|
|
1220
1270
|
allSettled([nextFlushPromise]).then(() => {
|
|
1271
|
+
this.flushPromises.delete(nextFlushPromise)
|
|
1221
1272
|
// If there are no others waiting to flush, clear the promise.
|
|
1222
1273
|
// We don't strictly need to do this, but it could make debugging easier
|
|
1223
1274
|
if (this.flushPromise === nextFlushPromise) {
|
|
@@ -35,6 +35,10 @@ export class PostHogCoreTestClient extends PostHogCore {
|
|
|
35
35
|
return super.getFlags(distinctId, groups, personProperties, groupProperties, extraPayload)
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
public flushWithPendingPromises(): Promise<void> {
|
|
39
|
+
return super.flushWithPendingPromises()
|
|
40
|
+
}
|
|
41
|
+
|
|
38
42
|
getPersistedProperty<T>(key: string): T {
|
|
39
43
|
return this.mocks.storage.getItem(key)
|
|
40
44
|
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { uuidv7 } from '../vendor/uuidv7'
|
|
2
2
|
|
|
3
3
|
export class PromiseQueue {
|
|
4
|
-
private promiseByIds: Record<string, Promise<any
|
|
4
|
+
private promiseByIds: Record<string, { id: number; promise: Promise<any> }> = {}
|
|
5
|
+
private nextId: number = 0
|
|
5
6
|
|
|
6
7
|
public add(promise: Promise<any>): Promise<any> {
|
|
7
8
|
const promiseUUID = uuidv7()
|
|
8
|
-
|
|
9
|
+
const id = ++this.nextId
|
|
10
|
+
this.promiseByIds[promiseUUID] = { id, promise }
|
|
9
11
|
promise
|
|
10
12
|
.catch(() => {})
|
|
11
13
|
.finally(() => {
|
|
@@ -15,15 +17,26 @@ export class PromiseQueue {
|
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
public async join(): Promise<void> {
|
|
18
|
-
let promises = Object.values(this.promiseByIds)
|
|
20
|
+
let promises = Object.values(this.promiseByIds).map((item) => item.promise)
|
|
19
21
|
let length = promises.length
|
|
20
22
|
while (length > 0) {
|
|
21
23
|
await Promise.all(promises)
|
|
22
|
-
promises = Object.values(this.promiseByIds)
|
|
24
|
+
promises = Object.values(this.promiseByIds).map((item) => item.promise)
|
|
23
25
|
length = promises.length
|
|
24
26
|
}
|
|
25
27
|
}
|
|
26
28
|
|
|
29
|
+
public getPromises(ignoredPromises: Promise<any>[] = [], maxId: number = this.nextId): Promise<any>[] {
|
|
30
|
+
const ignoredPromiseSet = new Set(ignoredPromises)
|
|
31
|
+
return Object.values(this.promiseByIds)
|
|
32
|
+
.filter((item) => item.id <= maxId && !ignoredPromiseSet.has(item.promise))
|
|
33
|
+
.map((item) => item.promise)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public get maxId(): number {
|
|
37
|
+
return this.nextId
|
|
38
|
+
}
|
|
39
|
+
|
|
27
40
|
public get length(): number {
|
|
28
41
|
return Object.keys(this.promiseByIds).length
|
|
29
42
|
}
|