@posthog/browser 0.1.0 → 0.1.1
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/ARCHITECTURE.md +2 -2
- package/README.md +1 -1
- package/dist/flags.js +1 -0
- package/dist/flags.mjs +1 -0
- package/dist/lane.js +1 -1
- package/dist/lane.mjs +1 -1
- package/dist/posthog.js +9 -3
- package/dist/posthog.mjs +9 -3
- package/dist/rate-limiter.d.ts +5 -0
- package/dist/rate-limiter.js +14 -8
- package/dist/rate-limiter.mjs +14 -8
- package/dist/surveys.d.ts +0 -1
- package/dist/surveys.js +1 -4
- package/dist/surveys.mjs +1 -4
- package/dist/version.js +1 -1
- package/dist/version.mjs +1 -1
- package/package.json +5 -5
package/ARCHITECTURE.md
CHANGED
|
@@ -231,9 +231,9 @@ The logs extension subscribes to the browser client's reset and consent-change n
|
|
|
231
231
|
|
|
232
232
|
### Surveys
|
|
233
233
|
|
|
234
|
-
The root loads only optional surveys orchestration during initialization; it awaits setup, not remote configuration, renderer loading, or survey definitions. The orchestration module owns the literal dynamic import of the shared renderer. A successful remote configuration with a truthy surveys gate loads UI automatically. A false or unavailable gate leaves it deferred, while explicit survey APIs may initialize a non-automatic manager. If enabled remote configuration arrives later, that same manager starts its idempotent automatic-display loop unless automatic display is disabled; it is not replaced or duplicated.
|
|
234
|
+
The root loads only optional surveys orchestration during initialization; it awaits setup, not remote configuration, renderer loading, or survey definitions. The orchestration module owns the literal dynamic import of the shared renderer. A successful remote configuration with a truthy surveys gate loads UI automatically. A false or unavailable gate leaves it deferred, while explicit survey APIs may initialize a non-automatic manager. If enabled remote configuration arrives later, that same manager starts its idempotent automatic-display loop unless automatic display is disabled; it is not replaced or duplicated. The explicit `@posthog/browser/surveys` factory includes orchestration only and defers the same renderer through a literal dynamic import. Preact, CSS, and DOMPurify belong behind that boundary; DOMPurify initializes browser capabilities when its module loads, so it must not enter the import-pure factory graph. An explicit instance wins over `surveys`, and `surveys: false` omits automatic inclusion.
|
|
235
235
|
|
|
236
|
-
Application-facing survey controls belong to the extension reference, obtained from the
|
|
236
|
+
Application-facing survey controls belong to the extension reference, obtained from the explicit factory or `getExtension()`. The extension receives host capabilities through ordinary setup and subscribes to `BrowserClient.onReset` for runtime cleanup. Renderer waiting and call coordination stay in the optional module; no post-init public registry installation is introduced. Manual `canRenderSurvey` resolves unavailable when disposed during loading or fetch. Callback delivery is suppressed after disposal.
|
|
237
237
|
|
|
238
238
|
The shared renderer, Preact components, CSS string, event/action receiver, and matching helpers are reused by legacy adapters. Capture, flags, submission IDs, configuration, and stylesheet preparation are explicit runtime capabilities, not a concrete PostHog facade. Legacy global routing, preview wrappers, and UUID behavior remain legacy-owned. Native capability reads occur at invocation/setup, preserving strict static-entry import purity.
|
|
239
239
|
|
package/README.md
CHANGED
|
@@ -246,7 +246,7 @@ const eligibility = await feedback?.canRenderSurvey('feedback')
|
|
|
246
246
|
|
|
247
247
|
The options are `automaticDisplay` (default `true`), `requestTimeoutMs` (default `10_000`), `prefillFromUrl` (default `false`), `overrideDisplayLanguage`, `prepareStylesheet`, and `getCurrentUrl`. `getActiveMatchingSurveys(callback, forceReload?)` applies targeting; `onSurveysLoaded(callback)` returns a disposable subscription; `cancelPendingSurvey(id)` cancels pending display. Capture consent still gates rendering and responses.
|
|
248
248
|
|
|
249
|
-
Use `surveys: false` to omit automatic inclusion. An explicitly supplied instance takes precedence, including over `false`.
|
|
249
|
+
Use `surveys: false` to omit automatic inclusion. An explicitly supplied instance takes precedence, including over `false`. Importing the factory below includes orchestration only; rendering, styles, and HTML sanitization still load dynamically when needed. Importing the entrypoint or constructing the extension does not access browser globals.
|
|
250
250
|
|
|
251
251
|
```ts
|
|
252
252
|
import { surveys } from '@posthog/browser/surveys'
|
package/dist/flags.js
CHANGED
package/dist/flags.mjs
CHANGED
package/dist/lane.js
CHANGED
|
@@ -295,7 +295,7 @@ class Lane {
|
|
|
295
295
|
}
|
|
296
296
|
let retryEntries = [];
|
|
297
297
|
try {
|
|
298
|
-
const retry = result
|
|
298
|
+
const retry = result ? result.retry : void 0;
|
|
299
299
|
if (Array.isArray(retry)) {
|
|
300
300
|
const selected = [];
|
|
301
301
|
const length = Math.min(retry.length, entries.length);
|
package/dist/lane.mjs
CHANGED
|
@@ -266,7 +266,7 @@ class Lane {
|
|
|
266
266
|
}
|
|
267
267
|
let retryEntries = [];
|
|
268
268
|
try {
|
|
269
|
-
const retry = result
|
|
269
|
+
const retry = result ? result.retry : void 0;
|
|
270
270
|
if (Array.isArray(retry)) {
|
|
271
271
|
const selected = [];
|
|
272
272
|
const length = Math.min(retry.length, entries.length);
|
package/dist/posthog.js
CHANGED
|
@@ -230,19 +230,22 @@ class PostHogBrowserClient {
|
|
|
230
230
|
get canCapture() {
|
|
231
231
|
return !this._closing && !this._disposed && !this._blocked && !this.hasOptedOut() && this._state.prepare();
|
|
232
232
|
}
|
|
233
|
+
get isRateLimited() {
|
|
234
|
+
return this._rateLimiter.wouldLimit;
|
|
235
|
+
}
|
|
233
236
|
capture(event, properties = null, options = {}) {
|
|
234
237
|
try {
|
|
235
238
|
if ('unload' === options.delivery && !this._captureSink?.isTearingDown) {
|
|
236
239
|
const authority = this._immediateAuthority;
|
|
237
240
|
const message = this._admitCapture(event, properties, options, false, true);
|
|
238
241
|
if (message) this._captureSink?.deliverUnload(message, ()=>this._immediateAuthority === authority);
|
|
239
|
-
return;
|
|
242
|
+
return !!message || !this._rateLimiter.limited;
|
|
240
243
|
}
|
|
241
244
|
} catch (error) {
|
|
242
245
|
this.logger.error('Unload capture failed', error);
|
|
243
|
-
return;
|
|
246
|
+
return true;
|
|
244
247
|
}
|
|
245
|
-
this._capture(event, properties, options);
|
|
248
|
+
return this._capture(event, properties, options) || !this._rateLimiter.limited;
|
|
246
249
|
}
|
|
247
250
|
async captureImmediate(event, properties = null, options = {}) {
|
|
248
251
|
try {
|
|
@@ -756,6 +759,9 @@ class PostHogBrowserClient {
|
|
|
756
759
|
get canCapture () {
|
|
757
760
|
return host.canCapture;
|
|
758
761
|
},
|
|
762
|
+
get isRateLimited () {
|
|
763
|
+
return host.isRateLimited;
|
|
764
|
+
},
|
|
759
765
|
capture: (event, properties, options)=>host.capture(event, properties, options),
|
|
760
766
|
registerDynamicEventProperties: (producer)=>host.registerDynamicEventProperties(producer),
|
|
761
767
|
getExtension: (name)=>host.getExtension(name),
|
package/dist/posthog.mjs
CHANGED
|
@@ -198,19 +198,22 @@ class PostHogBrowserClient {
|
|
|
198
198
|
get canCapture() {
|
|
199
199
|
return !this._closing && !this._disposed && !this._blocked && !this.hasOptedOut() && this._state.prepare();
|
|
200
200
|
}
|
|
201
|
+
get isRateLimited() {
|
|
202
|
+
return this._rateLimiter.wouldLimit;
|
|
203
|
+
}
|
|
201
204
|
capture(event, properties = null, options = {}) {
|
|
202
205
|
try {
|
|
203
206
|
if ('unload' === options.delivery && !this._captureSink?.isTearingDown) {
|
|
204
207
|
const authority = this._immediateAuthority;
|
|
205
208
|
const message = this._admitCapture(event, properties, options, false, true);
|
|
206
209
|
if (message) this._captureSink?.deliverUnload(message, ()=>this._immediateAuthority === authority);
|
|
207
|
-
return;
|
|
210
|
+
return !!message || !this._rateLimiter.limited;
|
|
208
211
|
}
|
|
209
212
|
} catch (error) {
|
|
210
213
|
this.logger.error('Unload capture failed', error);
|
|
211
|
-
return;
|
|
214
|
+
return true;
|
|
212
215
|
}
|
|
213
|
-
this._capture(event, properties, options);
|
|
216
|
+
return this._capture(event, properties, options) || !this._rateLimiter.limited;
|
|
214
217
|
}
|
|
215
218
|
async captureImmediate(event, properties = null, options = {}) {
|
|
216
219
|
try {
|
|
@@ -724,6 +727,9 @@ class PostHogBrowserClient {
|
|
|
724
727
|
get canCapture () {
|
|
725
728
|
return host.canCapture;
|
|
726
729
|
},
|
|
730
|
+
get isRateLimited () {
|
|
731
|
+
return host.isRateLimited;
|
|
732
|
+
},
|
|
727
733
|
capture: (event, properties, options)=>host.capture(event, properties, options),
|
|
728
734
|
registerDynamicEventProperties: (producer)=>host.registerDynamicEventProperties(producer),
|
|
729
735
|
getExtension: (name)=>host.getExtension(name),
|
package/dist/rate-limiter.d.ts
CHANGED
|
@@ -14,6 +14,11 @@ export declare class ClientRateLimiter {
|
|
|
14
14
|
private _unreportedDropped;
|
|
15
15
|
constructor(_eventsPerSecond?: number, _burst?: number, _clock?: () => number);
|
|
16
16
|
consume(): ClientRateLimitResult;
|
|
17
|
+
/** Whether `consume()` refuses a token now. It changes no state. */
|
|
18
|
+
get wouldLimit(): boolean;
|
|
19
|
+
/** Whether the last consumed token was refused. */
|
|
20
|
+
get limited(): boolean;
|
|
17
21
|
reported(): void;
|
|
22
|
+
private _tokensAt;
|
|
18
23
|
private _now;
|
|
19
24
|
}
|
package/dist/rate-limiter.js
CHANGED
|
@@ -40,14 +40,9 @@ class ClientRateLimiter {
|
|
|
40
40
|
}
|
|
41
41
|
consume() {
|
|
42
42
|
const now = this._now();
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
this._tokens = Math.min(this._burst, this._tokens + elapsed / 1000 * this._eventsPerSecond);
|
|
47
|
-
} else {
|
|
48
|
-
this._initialized = true;
|
|
49
|
-
this._last = now;
|
|
50
|
-
}
|
|
43
|
+
this._tokens = this._tokensAt(now);
|
|
44
|
+
this._last = this._initialized ? Math.max(this._last, now) : now;
|
|
45
|
+
this._initialized = true;
|
|
51
46
|
if (this._tokens >= 1) {
|
|
52
47
|
this._tokens = Math.max(0, this._tokens - 1);
|
|
53
48
|
this._limited = false;
|
|
@@ -65,9 +60,20 @@ class ClientRateLimiter {
|
|
|
65
60
|
}
|
|
66
61
|
};
|
|
67
62
|
}
|
|
63
|
+
get wouldLimit() {
|
|
64
|
+
return this._tokensAt(this._now()) < 1;
|
|
65
|
+
}
|
|
66
|
+
get limited() {
|
|
67
|
+
return this._limited;
|
|
68
|
+
}
|
|
68
69
|
reported() {
|
|
69
70
|
this._unreportedDropped = 0;
|
|
70
71
|
}
|
|
72
|
+
_tokensAt(now) {
|
|
73
|
+
if (!this._initialized) return this._tokens;
|
|
74
|
+
const elapsed = Math.max(0, now - this._last);
|
|
75
|
+
return Math.min(this._burst, this._tokens + elapsed / 1000 * this._eventsPerSecond);
|
|
76
|
+
}
|
|
71
77
|
_now() {
|
|
72
78
|
try {
|
|
73
79
|
const value = this._clock();
|
package/dist/rate-limiter.mjs
CHANGED
|
@@ -11,14 +11,9 @@ class ClientRateLimiter {
|
|
|
11
11
|
}
|
|
12
12
|
consume() {
|
|
13
13
|
const now = this._now();
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
this._tokens = Math.min(this._burst, this._tokens + elapsed / 1000 * this._eventsPerSecond);
|
|
18
|
-
} else {
|
|
19
|
-
this._initialized = true;
|
|
20
|
-
this._last = now;
|
|
21
|
-
}
|
|
14
|
+
this._tokens = this._tokensAt(now);
|
|
15
|
+
this._last = this._initialized ? Math.max(this._last, now) : now;
|
|
16
|
+
this._initialized = true;
|
|
22
17
|
if (this._tokens >= 1) {
|
|
23
18
|
this._tokens = Math.max(0, this._tokens - 1);
|
|
24
19
|
this._limited = false;
|
|
@@ -36,9 +31,20 @@ class ClientRateLimiter {
|
|
|
36
31
|
}
|
|
37
32
|
};
|
|
38
33
|
}
|
|
34
|
+
get wouldLimit() {
|
|
35
|
+
return this._tokensAt(this._now()) < 1;
|
|
36
|
+
}
|
|
37
|
+
get limited() {
|
|
38
|
+
return this._limited;
|
|
39
|
+
}
|
|
39
40
|
reported() {
|
|
40
41
|
this._unreportedDropped = 0;
|
|
41
42
|
}
|
|
43
|
+
_tokensAt(now) {
|
|
44
|
+
if (!this._initialized) return this._tokens;
|
|
45
|
+
const elapsed = Math.max(0, now - this._last);
|
|
46
|
+
return Math.min(this._burst, this._tokens + elapsed / 1000 * this._eventsPerSecond);
|
|
47
|
+
}
|
|
42
48
|
_now() {
|
|
43
49
|
try {
|
|
44
50
|
const value = this._clock();
|
package/dist/surveys.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { SurveysOptions } from './surveys-options';
|
|
2
2
|
import type { SurveysExtension } from './surveys-internal';
|
|
3
3
|
export type { SurveysExtension } from './surveys-internal';
|
|
4
|
-
/** Statically include survey orchestration and rendering, avoiding runtime module loading. */
|
|
5
4
|
export declare const surveys: (options?: SurveysOptions) => SurveysExtension;
|
|
6
5
|
export type { SurveysOptions, Survey, SurveyCallback, DisplaySurveyOptions, SurveyRenderReason, } from './surveys-options';
|
|
7
6
|
export { DisplaySurveyType } from '@posthog/browser-common/surveys';
|
package/dist/surveys.js
CHANGED
|
@@ -31,12 +31,9 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
31
31
|
DisplaySurveyType: ()=>surveys_namespaceObject.DisplaySurveyType,
|
|
32
32
|
surveys: ()=>surveys
|
|
33
33
|
});
|
|
34
|
-
const surveys_renderer_namespaceObject = require("@posthog/browser-common/surveys-renderer");
|
|
35
34
|
const external_surveys_extension_js_namespaceObject = require("./surveys-extension.js");
|
|
36
35
|
const surveys_namespaceObject = require("@posthog/browser-common/surveys");
|
|
37
|
-
const surveys = (options = {})=>(0, external_surveys_extension_js_namespaceObject.createSurveys)(options,
|
|
38
|
-
generateSurveys: surveys_renderer_namespaceObject.generateSurveys
|
|
39
|
-
}));
|
|
36
|
+
const surveys = (options = {})=>(0, external_surveys_extension_js_namespaceObject.createSurveys)(options, ()=>import("@posthog/browser-common/surveys-renderer"));
|
|
40
37
|
exports.DisplaySurveyType = __webpack_exports__.DisplaySurveyType;
|
|
41
38
|
exports.surveys = __webpack_exports__.surveys;
|
|
42
39
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
package/dist/surveys.mjs
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import { generateSurveys } from "@posthog/browser-common/surveys-renderer";
|
|
2
1
|
import { createSurveys } from "./surveys-extension.mjs";
|
|
3
|
-
const surveys = (options = {})=>createSurveys(options,
|
|
4
|
-
generateSurveys: generateSurveys
|
|
5
|
-
}));
|
|
2
|
+
const surveys = (options = {})=>createSurveys(options, ()=>import("@posthog/browser-common/surveys-renderer"));
|
|
6
3
|
export { DisplaySurveyType } from "@posthog/browser-common/surveys";
|
|
7
4
|
export { surveys };
|
package/dist/version.js
CHANGED
package/dist/version.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const version = "0.1.
|
|
1
|
+
const version = "0.1.1";
|
|
2
2
|
export { version };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@posthog/browser",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "A small, extension-based PostHog client for modern browsers",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
}
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@posthog/browser-common": "^0.10.
|
|
59
|
-
"@posthog/types": "^1.
|
|
58
|
+
"@posthog/browser-common": "^0.10.6",
|
|
59
|
+
"@posthog/types": "^1.419.0"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@playwright/test": "1.52.0",
|
|
@@ -66,8 +66,8 @@
|
|
|
66
66
|
"typescript": "7.0.2",
|
|
67
67
|
"typescript-legacy": "npm:typescript@5.8.2",
|
|
68
68
|
"vitest": "^1.6.1",
|
|
69
|
-
"@posthog-tooling/
|
|
70
|
-
"@posthog-tooling/
|
|
69
|
+
"@posthog-tooling/sdk-mock-server": "0.0.0",
|
|
70
|
+
"@posthog-tooling/tsconfig-base": "1.1.1"
|
|
71
71
|
},
|
|
72
72
|
"scripts": {
|
|
73
73
|
"clean": "rimraf dist dist-cdn",
|