@posthog/core 1.20.1 → 1.20.2
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.d.ts +1 -0
- package/dist/posthog-core.d.ts.map +1 -1
- package/dist/posthog-core.js +19 -2
- package/dist/posthog-core.mjs +19 -2
- package/package.json +1 -1
- package/src/posthog-core.ts +35 -2
package/dist/posthog-core.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export declare abstract class PostHogCore extends PostHogCoreStateless {
|
|
|
9
9
|
protected _sessionExpirationTimeSeconds: number;
|
|
10
10
|
private _sessionMaxLengthSeconds;
|
|
11
11
|
protected sessionProps: PostHogEventProperties;
|
|
12
|
+
private _pendingFlagsRequest?;
|
|
12
13
|
protected _personProfiles: 'always' | 'identified_only' | 'never';
|
|
13
14
|
protected _cachedPersonProperties: string | null;
|
|
14
15
|
constructor(apiKey: string, options?: PostHogCoreOptions);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"posthog-core.d.ts","sourceRoot":"","sources":["../src/posthog-core.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,yBAAyB,EACzB,oBAAoB,EACpB,2BAA2B,EAC3B,kBAAkB,EAClB,sBAAsB,EACtB,qBAAqB,EACrB,QAAQ,EACR,mBAAmB,EACnB,gBAAgB,EAGhB,yBAAyB,EAKzB,sBAAsB,EAGvB,MAAM,SAAS,CAAA;AAShB,OAAO,EAAiC,wBAAwB,EAAE,MAAM,SAAS,CAAA;AACjF,OAAO,EAAY,oBAAoB,EAAuB,MAAM,0BAA0B,CAAA;
|
|
1
|
+
{"version":3,"file":"posthog-core.d.ts","sourceRoot":"","sources":["../src/posthog-core.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,yBAAyB,EACzB,oBAAoB,EACpB,2BAA2B,EAC3B,kBAAkB,EAClB,sBAAsB,EACtB,qBAAqB,EACrB,QAAQ,EACR,mBAAmB,EACnB,gBAAgB,EAG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;;;;;OAmCG;IACH,mBAAmB,CACjB,mBAAmB,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAAA;KAAE,EACjD,uBAAuB,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAAA;KAAE,EACrD,kBAAkB,UAAO,GACxB,IAAI;IAiCP;;;;;;;;OAQG;IACH,SAAS,CAAC,oBAAoB,CAAC,OAAO,EAAE,sBAAsB,GAAG,sBAAsB,GAAG,IAAI;IA+C9F;;;;;;OAMG;IACH,OAAO,CAAC,cAAc;CAsBvB"}
|
package/dist/posthog-core.js
CHANGED
|
@@ -296,7 +296,18 @@ class PostHogCore extends external_posthog_core_stateless_js_namespaceObject.Pos
|
|
|
296
296
|
}
|
|
297
297
|
async flagsAsync(sendAnonDistinctId = true, fetchConfig = true) {
|
|
298
298
|
await this._initPromise;
|
|
299
|
-
if (this._flagsResponsePromise)
|
|
299
|
+
if (this._flagsResponsePromise) {
|
|
300
|
+
this._logger.info('Feature flags are being loaded already, queuing reload.');
|
|
301
|
+
if (this._pendingFlagsRequest) this._flagsResponsePromise.then(this._pendingFlagsRequest.resolve).catch(this._pendingFlagsRequest.reject);
|
|
302
|
+
return new Promise((resolve, reject)=>{
|
|
303
|
+
this._pendingFlagsRequest = {
|
|
304
|
+
sendAnonDistinctId,
|
|
305
|
+
fetchConfig,
|
|
306
|
+
resolve,
|
|
307
|
+
reject
|
|
308
|
+
};
|
|
309
|
+
});
|
|
310
|
+
}
|
|
300
311
|
return this._flagsAsync(sendAnonDistinctId, fetchConfig);
|
|
301
312
|
}
|
|
302
313
|
cacheSessionReplay(source, response) {
|
|
@@ -369,7 +380,7 @@ class PostHogCore extends external_posthog_core_stateless_js_namespaceObject.Pos
|
|
|
369
380
|
flags: this.getKnownFeatureFlagDetails()?.flags ?? {},
|
|
370
381
|
quotaLimited: res.quotaLimited
|
|
371
382
|
});
|
|
372
|
-
|
|
383
|
+
this._logger.warn('[FEATURE FLAGS] Feature flags quota limit exceeded. Learn more about billing limits at https://posthog.com/docs/billing/limits-alerts');
|
|
373
384
|
return res;
|
|
374
385
|
}
|
|
375
386
|
if (res?.featureFlags) {
|
|
@@ -401,6 +412,12 @@ class PostHogCore extends external_posthog_core_stateless_js_namespaceObject.Pos
|
|
|
401
412
|
return res;
|
|
402
413
|
}).finally(()=>{
|
|
403
414
|
this._flagsResponsePromise = void 0;
|
|
415
|
+
const pendingRequest = this._pendingFlagsRequest;
|
|
416
|
+
if (pendingRequest) {
|
|
417
|
+
this._pendingFlagsRequest = void 0;
|
|
418
|
+
this._logger.info('Executing pending feature flags reload.');
|
|
419
|
+
this.flagsAsync(pendingRequest.sendAnonDistinctId, pendingRequest.fetchConfig).then(pendingRequest.resolve).catch(pendingRequest.reject);
|
|
420
|
+
}
|
|
404
421
|
});
|
|
405
422
|
return this._flagsResponsePromise;
|
|
406
423
|
}
|
package/dist/posthog-core.mjs
CHANGED
|
@@ -268,7 +268,18 @@ class PostHogCore extends PostHogCoreStateless {
|
|
|
268
268
|
}
|
|
269
269
|
async flagsAsync(sendAnonDistinctId = true, fetchConfig = true) {
|
|
270
270
|
await this._initPromise;
|
|
271
|
-
if (this._flagsResponsePromise)
|
|
271
|
+
if (this._flagsResponsePromise) {
|
|
272
|
+
this._logger.info('Feature flags are being loaded already, queuing reload.');
|
|
273
|
+
if (this._pendingFlagsRequest) this._flagsResponsePromise.then(this._pendingFlagsRequest.resolve).catch(this._pendingFlagsRequest.reject);
|
|
274
|
+
return new Promise((resolve, reject)=>{
|
|
275
|
+
this._pendingFlagsRequest = {
|
|
276
|
+
sendAnonDistinctId,
|
|
277
|
+
fetchConfig,
|
|
278
|
+
resolve,
|
|
279
|
+
reject
|
|
280
|
+
};
|
|
281
|
+
});
|
|
282
|
+
}
|
|
272
283
|
return this._flagsAsync(sendAnonDistinctId, fetchConfig);
|
|
273
284
|
}
|
|
274
285
|
cacheSessionReplay(source, response) {
|
|
@@ -341,7 +352,7 @@ class PostHogCore extends PostHogCoreStateless {
|
|
|
341
352
|
flags: this.getKnownFeatureFlagDetails()?.flags ?? {},
|
|
342
353
|
quotaLimited: res.quotaLimited
|
|
343
354
|
});
|
|
344
|
-
|
|
355
|
+
this._logger.warn('[FEATURE FLAGS] Feature flags quota limit exceeded. Learn more about billing limits at https://posthog.com/docs/billing/limits-alerts');
|
|
345
356
|
return res;
|
|
346
357
|
}
|
|
347
358
|
if (res?.featureFlags) {
|
|
@@ -373,6 +384,12 @@ class PostHogCore extends PostHogCoreStateless {
|
|
|
373
384
|
return res;
|
|
374
385
|
}).finally(()=>{
|
|
375
386
|
this._flagsResponsePromise = void 0;
|
|
387
|
+
const pendingRequest = this._pendingFlagsRequest;
|
|
388
|
+
if (pendingRequest) {
|
|
389
|
+
this._pendingFlagsRequest = void 0;
|
|
390
|
+
this._logger.info('Executing pending feature flags reload.');
|
|
391
|
+
this.flagsAsync(pendingRequest.sendAnonDistinctId, pendingRequest.fetchConfig).then(pendingRequest.resolve).catch(pendingRequest.reject);
|
|
392
|
+
}
|
|
376
393
|
});
|
|
377
394
|
return this._flagsResponsePromise;
|
|
378
395
|
}
|
package/package.json
CHANGED
package/src/posthog-core.ts
CHANGED
|
@@ -32,6 +32,14 @@ import { maybeAdd, PostHogCoreStateless, QuotaLimitedFeature } from './posthog-c
|
|
|
32
32
|
import { uuidv7 } from './vendor/uuidv7'
|
|
33
33
|
import { isEmptyObject, isNullish, isPlainError, getPersonPropertiesHash, isObject } from './utils'
|
|
34
34
|
|
|
35
|
+
// Stores the parameters for a pending feature flags reload request
|
|
36
|
+
interface PendingFlagsRequest {
|
|
37
|
+
sendAnonDistinctId: boolean
|
|
38
|
+
fetchConfig: boolean
|
|
39
|
+
resolve: (value: PostHogFeatureFlagsResponse | undefined) => void
|
|
40
|
+
reject: (reason?: unknown) => void
|
|
41
|
+
}
|
|
42
|
+
|
|
35
43
|
export abstract class PostHogCore extends PostHogCoreStateless {
|
|
36
44
|
// options
|
|
37
45
|
private sendFeatureFlagEvent: boolean
|
|
@@ -44,6 +52,10 @@ export abstract class PostHogCore extends PostHogCoreStateless {
|
|
|
44
52
|
private _sessionMaxLengthSeconds: number = 24 * 60 * 60 // 24 hours
|
|
45
53
|
protected sessionProps: PostHogEventProperties = {}
|
|
46
54
|
|
|
55
|
+
// Track if an additional reload was requested while a request was in flight
|
|
56
|
+
// This prevents dropping reload requests (e.g., from identify()) when preload is in progress
|
|
57
|
+
private _pendingFlagsRequest?: PendingFlagsRequest
|
|
58
|
+
|
|
47
59
|
// person profiles
|
|
48
60
|
protected _personProfiles: 'always' | 'identified_only' | 'never'
|
|
49
61
|
|
|
@@ -516,7 +528,17 @@ export abstract class PostHogCore extends PostHogCoreStateless {
|
|
|
516
528
|
): Promise<PostHogFeatureFlagsResponse | undefined> {
|
|
517
529
|
await this._initPromise
|
|
518
530
|
if (this._flagsResponsePromise) {
|
|
519
|
-
|
|
531
|
+
// Queue the reload request instead of dropping it
|
|
532
|
+
// This ensures that requests with $anon_distinct_id (from identify()) are not lost
|
|
533
|
+
this._logger.info('Feature flags are being loaded already, queuing reload.')
|
|
534
|
+
// Resolve any existing pending promise with the in-flight request's result to avoid hanging promises
|
|
535
|
+
if (this._pendingFlagsRequest) {
|
|
536
|
+
this._flagsResponsePromise.then(this._pendingFlagsRequest.resolve).catch(this._pendingFlagsRequest.reject)
|
|
537
|
+
}
|
|
538
|
+
// Return a promise that resolves when the pending request completes
|
|
539
|
+
return new Promise((resolve, reject) => {
|
|
540
|
+
this._pendingFlagsRequest = { sendAnonDistinctId, fetchConfig, resolve, reject }
|
|
541
|
+
})
|
|
520
542
|
}
|
|
521
543
|
return this._flagsAsync(sendAnonDistinctId, fetchConfig)
|
|
522
544
|
}
|
|
@@ -650,7 +672,7 @@ export abstract class PostHogCore extends PostHogCoreStateless {
|
|
|
650
672
|
flags: this.getKnownFeatureFlagDetails()?.flags ?? {},
|
|
651
673
|
quotaLimited: res.quotaLimited,
|
|
652
674
|
})
|
|
653
|
-
|
|
675
|
+
this._logger.warn(
|
|
654
676
|
'[FEATURE FLAGS] Feature flags quota limit exceeded. Learn more about billing limits at https://posthog.com/docs/billing/limits-alerts'
|
|
655
677
|
)
|
|
656
678
|
return res
|
|
@@ -694,6 +716,17 @@ export abstract class PostHogCore extends PostHogCoreStateless {
|
|
|
694
716
|
})
|
|
695
717
|
.finally(() => {
|
|
696
718
|
this._flagsResponsePromise = undefined
|
|
719
|
+
|
|
720
|
+
// Check if there's a pending reload request and execute it
|
|
721
|
+
const pendingRequest = this._pendingFlagsRequest
|
|
722
|
+
if (pendingRequest) {
|
|
723
|
+
this._pendingFlagsRequest = undefined
|
|
724
|
+
this._logger.info('Executing pending feature flags reload.')
|
|
725
|
+
// Execute the pending request and resolve its promise with the result
|
|
726
|
+
this.flagsAsync(pendingRequest.sendAnonDistinctId, pendingRequest.fetchConfig)
|
|
727
|
+
.then(pendingRequest.resolve)
|
|
728
|
+
.catch(pendingRequest.reject)
|
|
729
|
+
}
|
|
697
730
|
})
|
|
698
731
|
return this._flagsResponsePromise
|
|
699
732
|
}
|