@posthog/browser 0.0.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.
Files changed (121) hide show
  1. package/ARCHITECTURE.md +559 -0
  2. package/LICENSE +417 -0
  3. package/README.md +286 -28
  4. package/dist/analytics-buffer.d.ts +4 -0
  5. package/dist/analytics-buffer.js +200 -0
  6. package/dist/analytics-buffer.mjs +162 -0
  7. package/dist/analytics-delivery.d.ts +3 -0
  8. package/dist/analytics-delivery.js +231 -0
  9. package/dist/analytics-delivery.mjs +193 -0
  10. package/dist/analytics-internal.d.ts +64 -0
  11. package/dist/analytics-internal.js +52 -0
  12. package/dist/analytics-internal.mjs +5 -0
  13. package/dist/analytics-options.d.ts +14 -0
  14. package/dist/analytics-options.js +18 -0
  15. package/dist/analytics-options.mjs +1 -0
  16. package/dist/analytics.d.ts +5 -0
  17. package/dist/analytics.js +42 -0
  18. package/dist/analytics.mjs +4 -0
  19. package/dist/autocapture-options.d.ts +32 -0
  20. package/dist/autocapture-options.js +49 -0
  21. package/dist/autocapture-options.mjs +11 -0
  22. package/dist/autocapture.d.ts +5 -0
  23. package/dist/autocapture.js +108 -0
  24. package/dist/autocapture.mjs +70 -0
  25. package/dist/automatic-analytics.d.ts +3 -0
  26. package/dist/automatic-analytics.js +44 -0
  27. package/dist/automatic-analytics.mjs +6 -0
  28. package/dist/automatic-surveys.d.ts +2 -0
  29. package/dist/automatic-surveys.js +41 -0
  30. package/dist/automatic-surveys.mjs +3 -0
  31. package/dist/bot-filter.d.ts +2 -0
  32. package/dist/bot-filter.js +87 -0
  33. package/dist/bot-filter.mjs +49 -0
  34. package/dist/browser-client.d.ts +30 -0
  35. package/dist/browser-client.js +18 -0
  36. package/dist/browser-client.mjs +1 -0
  37. package/dist/capture-summary.d.ts +3 -0
  38. package/dist/capture-summary.js +63 -0
  39. package/dist/capture-summary.mjs +22 -0
  40. package/dist/capture-v1.d.ts +105 -0
  41. package/dist/capture-v1.js +781 -0
  42. package/dist/capture-v1.mjs +722 -0
  43. package/dist/core.d.ts +7 -0
  44. package/dist/core.js +49 -0
  45. package/dist/core.mjs +5 -0
  46. package/dist/event-buffer.d.ts +41 -0
  47. package/dist/event-buffer.js +158 -0
  48. package/dist/event-buffer.mjs +120 -0
  49. package/dist/extensions/registry.d.ts +16 -0
  50. package/dist/extensions/registry.js +128 -0
  51. package/dist/extensions/registry.mjs +90 -0
  52. package/dist/flags-internal.d.ts +8 -0
  53. package/dist/flags-internal.js +18 -0
  54. package/dist/flags-internal.mjs +1 -0
  55. package/dist/flags-options.d.ts +22 -0
  56. package/dist/flags-options.js +18 -0
  57. package/dist/flags-options.mjs +1 -0
  58. package/dist/flags-token.d.ts +15 -0
  59. package/dist/flags-token.js +40 -0
  60. package/dist/flags-token.mjs +2 -0
  61. package/dist/flags.d.ts +6 -0
  62. package/dist/flags.js +164 -0
  63. package/dist/flags.mjs +123 -0
  64. package/dist/id.d.ts +1 -0
  65. package/dist/id.js +61 -0
  66. package/dist/id.mjs +23 -0
  67. package/dist/index.d.ts +11 -0
  68. package/dist/index.js +119 -0
  69. package/dist/index.mjs +75 -0
  70. package/dist/lane.d.ts +57 -0
  71. package/dist/lane.js +363 -0
  72. package/dist/lane.mjs +325 -0
  73. package/dist/logger.d.ts +4 -0
  74. package/dist/logger.js +57 -0
  75. package/dist/logger.mjs +19 -0
  76. package/dist/logs-internal.d.ts +7 -0
  77. package/dist/logs-internal.js +18 -0
  78. package/dist/logs-internal.mjs +1 -0
  79. package/dist/logs-options.d.ts +11 -0
  80. package/dist/logs-options.js +57 -0
  81. package/dist/logs-options.mjs +19 -0
  82. package/dist/logs.d.ts +6 -0
  83. package/dist/logs.js +140 -0
  84. package/dist/logs.mjs +102 -0
  85. package/dist/named-error.d.ts +7 -0
  86. package/dist/named-error.js +49 -0
  87. package/dist/named-error.mjs +11 -0
  88. package/dist/posthog.d.ts +3 -0
  89. package/dist/posthog.js +829 -0
  90. package/dist/posthog.mjs +791 -0
  91. package/dist/rate-limiter.d.ts +24 -0
  92. package/dist/rate-limiter.js +95 -0
  93. package/dist/rate-limiter.mjs +57 -0
  94. package/dist/remote-config.d.ts +3 -0
  95. package/dist/remote-config.js +47 -0
  96. package/dist/remote-config.mjs +9 -0
  97. package/dist/request.d.ts +14 -0
  98. package/dist/request.js +130 -0
  99. package/dist/request.mjs +89 -0
  100. package/dist/state.d.ts +82 -0
  101. package/dist/state.js +625 -0
  102. package/dist/state.mjs +581 -0
  103. package/dist/surveys-extension.d.ts +9 -0
  104. package/dist/surveys-extension.js +272 -0
  105. package/dist/surveys-extension.mjs +234 -0
  106. package/dist/surveys-internal.d.ts +12 -0
  107. package/dist/surveys-internal.js +18 -0
  108. package/dist/surveys-internal.mjs +1 -0
  109. package/dist/surveys-options.d.ts +18 -0
  110. package/dist/surveys-options.js +42 -0
  111. package/dist/surveys-options.mjs +4 -0
  112. package/dist/surveys.d.ts +6 -0
  113. package/dist/surveys.js +45 -0
  114. package/dist/surveys.mjs +4 -0
  115. package/dist/types.d.ts +114 -0
  116. package/dist/types.js +18 -0
  117. package/dist/types.mjs +1 -0
  118. package/dist/version.d.ts +1 -0
  119. package/dist/version.js +40 -0
  120. package/dist/version.mjs +2 -0
  121. package/package.json +89 -8
@@ -0,0 +1,114 @@
1
+ import type { FlagsConfiguration } from './flags-options';
2
+ import type { BrowserClient } from './browser-client';
3
+ import type { LogsConfiguration } from './logs-options';
4
+ import type { SurveysConfiguration } from './surveys-options';
5
+ import type { AutocaptureConfiguration } from './autocapture-options';
6
+ import type { AnalyticsConfiguration, AnalyticsOptions, AutomaticAnalyticsOptions, LoadStrategy } from './analytics-options';
7
+ import type { ApiResponse, CaptureOptions, Disposable, Extension, ExtensionToken, Listener, RemoteConfig, SendRequestInit, SessionContext } from '@posthog/browser-common';
8
+ export interface StorageLike {
9
+ getItem(key: string): string | null;
10
+ setItem(key: string, value: string): void;
11
+ removeItem(key: string): void;
12
+ /** Observe external changes when the adapter can provide prompt notification. */
13
+ subscribe?(key: string, listener: () => void): Disposable;
14
+ }
15
+ export interface BrowserNavigator {
16
+ readonly userAgent?: string;
17
+ readonly webdriver?: boolean;
18
+ readonly onLine?: boolean;
19
+ sendBeacon?(url: string, data?: BodyInit | null): boolean;
20
+ }
21
+ export type BrowserFetch = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
22
+ export type NewSessionReason = 'idleTimeout' | 'maxLength' | 'reset';
23
+ export interface NewSessionInfo extends SessionContext {
24
+ readonly reason: NewSessionReason;
25
+ }
26
+ export interface PostHogOptions {
27
+ /** PostHog project token. */
28
+ projectToken: string;
29
+ /** PostHog API origin. */
30
+ apiHost?: string;
31
+ /** Origin used for requests targeting feature flags. Defaults to `apiHost`. */
32
+ flagsHost?: string;
33
+ /** Storage implementation. Pass `false` to keep all state in memory. */
34
+ storage?: StorageLike | false;
35
+ /** Override the storage key. */
36
+ persistenceKey?: string;
37
+ /** Override the consent key verbatim. Defaults to `__ph_opt_in_out_<projectToken>`. */
38
+ consentPersistenceName?: string;
39
+ /** Fetch implementation. Pass `false` to disable network requests. */
40
+ fetch?: BrowserFetch | false;
41
+ /** Navigator implementation. Pass `false` to disable navigator capabilities. */
42
+ navigator?: BrowserNavigator | false;
43
+ /** Start with capture disabled until `optIn()` runs. */
44
+ optOutByDefault?: boolean;
45
+ /** Capture one initial `$pageview` after configured extensions install. Defaults to `true`. */
46
+ capturePageview?: boolean;
47
+ /** Initial person properties exposed to feature-evaluation extensions. */
48
+ initialPersonProperties?: Record<string, unknown>;
49
+ /** Disable the default user-agent bot filter. */
50
+ disableBotDetection?: boolean;
51
+ /** Add blocked user-agent fragments to the default bot filter. */
52
+ blockedUserAgents?: readonly string[];
53
+ /** Enable SDK diagnostic logs. */
54
+ debug?: boolean;
55
+ /** Supply initial remote configuration without a request. */
56
+ remoteConfig?: RemoteConfig;
57
+ /** Stop waiting for remote configuration after this duration in milliseconds. Defaults to 10,000. */
58
+ remoteConfigTimeoutMs?: number;
59
+ /**
60
+ * Automatic first-party analytics delivery. Defaults to lazy loading after the first admitted event.
61
+ * Pass `false` to retain events without automatically loading delivery.
62
+ */
63
+ analytics?: AnalyticsConfiguration;
64
+ /** Automatic DOM autocapture. Pass false to omit it; an explicit extension takes precedence. */
65
+ autocapture?: AutocaptureConfiguration;
66
+ /** Dynamically include flags by default. Explicit extensions take precedence over this option. */
67
+ flags?: FlagsConfiguration;
68
+ /** Load survey orchestration dynamically; renderer waits for remote enablement or a manual call. */
69
+ surveys?: SurveysConfiguration;
70
+ /** Automatically load logs. False disables automatic inclusion; explicit extensions take precedence. */
71
+ logs?: LogsConfiguration;
72
+ /** Install extensions before the factory resolves. A preinstalled analytics extension satisfies delivery. */
73
+ extensions?: readonly Extension[];
74
+ }
75
+ /** Options for the delivery-free `@posthog/browser/core` entrypoint. */
76
+ export type CorePostHogOptions = Omit<PostHogOptions, 'analytics' | 'flags' | 'logs' | 'surveys' | 'autocapture'>;
77
+ /** Capture V1's terminal verdict for one reported event. */
78
+ export type CaptureOutcomeStatus = 'ok' | 'warning' | 'drop' | 'retry';
79
+ /** A backend-reported Capture V1 event verdict. */
80
+ export interface CaptureOutcome {
81
+ readonly result: CaptureOutcomeStatus;
82
+ readonly details?: string;
83
+ }
84
+ /** Terminal outcome of an immediate Capture V1 operation. */
85
+ export interface CaptureSummary {
86
+ /** Number of finalized events handed to the sender; zero if its summary is unavailable. */
87
+ readonly submitted: number;
88
+ /** Submitted events without an `ok` or `warning` verdict. */
89
+ readonly notPersisted: number;
90
+ /** Whether every submitted event received an `ok` or `warning` verdict and no operation error occurred. */
91
+ readonly allPersisted: boolean;
92
+ /** Backend-reported outcomes keyed by event UUID. Missing outcomes count as not persisted. */
93
+ readonly results: Readonly<Record<string, CaptureOutcome>>;
94
+ /** Operation-level failure, with any known partial results retained. Errors always set `allPersisted` to false. */
95
+ readonly error?: Error;
96
+ }
97
+ export interface PostHog extends BrowserClient, Disposable {
98
+ readonly onNewSession: Listener<NewSessionInfo>;
99
+ /** Sends one finalized event inline. Resolves with an outcome or `summary.error` instead of rejecting. */
100
+ captureImmediate(event: string, properties?: Record<string, unknown> | null, options?: CaptureOptions): Promise<CaptureSummary>;
101
+ identify(distinctId: string, set?: Record<string, unknown>, setOnce?: Record<string, unknown>): Promise<void>;
102
+ group(type: string, key: string, properties?: Record<string, unknown>): Promise<void>;
103
+ reset(): void;
104
+ flush(): Promise<void>;
105
+ shutdown(shutdownTimeoutMs?: number): Promise<void>;
106
+ dispose(): Promise<void>;
107
+ optIn(): void;
108
+ optOut(): void;
109
+ hasOptedOut(): boolean;
110
+ getExtension<T extends Extension>(token: ExtensionToken<T>): T | undefined;
111
+ getExtension<T extends Extension = Extension>(name: string): T | undefined;
112
+ getRemoteConfig(): Promise<RemoteConfig | undefined>;
113
+ }
114
+ export type { AnalyticsConfiguration, AnalyticsOptions, AutomaticAnalyticsOptions, LoadStrategy, ApiResponse, CaptureOptions, Disposable, Extension, RemoteConfig, SendRequestInit, SessionContext, };
package/dist/types.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.r = (exports1)=>{
5
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
6
+ value: 'Module'
7
+ });
8
+ Object.defineProperty(exports1, '__esModule', {
9
+ value: true
10
+ });
11
+ };
12
+ })();
13
+ var __webpack_exports__ = {};
14
+ __webpack_require__.r(__webpack_exports__);
15
+ for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
16
+ Object.defineProperty(exports, '__esModule', {
17
+ value: true
18
+ });
package/dist/types.mjs ADDED
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1 @@
1
+ export declare const version: string;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ const version = "0.1.1";
31
+ __webpack_require__.d(__webpack_exports__, {}, {
32
+ version: version
33
+ });
34
+ exports.version = __webpack_exports__.version;
35
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
36
+ "version"
37
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
38
+ Object.defineProperty(exports, '__esModule', {
39
+ value: true
40
+ });
@@ -0,0 +1,2 @@
1
+ const version = "0.1.1";
2
+ export { version };
package/package.json CHANGED
@@ -1,10 +1,91 @@
1
1
  {
2
2
  "name": "@posthog/browser",
3
- "version": "0.0.0",
4
- "description": "OIDC trusted publishing setup package for @posthog/browser",
5
- "keywords": [
6
- "oidc",
7
- "trusted-publishing",
8
- "setup"
9
- ]
10
- }
3
+ "version": "0.1.1",
4
+ "description": "A small, extension-based PostHog client for modern browsers",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/PostHog/posthog-js.git",
9
+ "directory": "packages/browser-next"
10
+ },
11
+ "sideEffects": false,
12
+ "files": [
13
+ "dist",
14
+ "ARCHITECTURE.md",
15
+ "README.md"
16
+ ],
17
+ "main": "dist/index.js",
18
+ "module": "dist/index.mjs",
19
+ "types": "dist/index.d.ts",
20
+ "exports": {
21
+ ".": {
22
+ "types": "./dist/index.d.ts",
23
+ "require": "./dist/index.js",
24
+ "import": "./dist/index.mjs"
25
+ },
26
+ "./core": {
27
+ "types": "./dist/core.d.ts",
28
+ "require": "./dist/core.js",
29
+ "import": "./dist/core.mjs"
30
+ },
31
+ "./flags": {
32
+ "types": "./dist/flags.d.ts",
33
+ "require": "./dist/flags.js",
34
+ "import": "./dist/flags.mjs"
35
+ },
36
+ "./analytics": {
37
+ "types": "./dist/analytics.d.ts",
38
+ "require": "./dist/analytics.js",
39
+ "import": "./dist/analytics.mjs"
40
+ },
41
+ "./logs": {
42
+ "types": "./dist/logs.d.ts",
43
+ "import": "./dist/logs.mjs",
44
+ "require": "./dist/logs.js"
45
+ },
46
+ "./surveys": {
47
+ "types": "./dist/surveys.d.ts",
48
+ "require": "./dist/surveys.js",
49
+ "import": "./dist/surveys.mjs"
50
+ },
51
+ "./autocapture": {
52
+ "types": "./dist/autocapture.d.ts",
53
+ "require": "./dist/autocapture.js",
54
+ "import": "./dist/autocapture.mjs"
55
+ }
56
+ },
57
+ "dependencies": {
58
+ "@posthog/browser-common": "^0.10.6",
59
+ "@posthog/types": "^1.419.0"
60
+ },
61
+ "devDependencies": {
62
+ "@playwright/test": "1.52.0",
63
+ "@rslib/core": "0.23.2",
64
+ "@rspack/core": "2.1.10",
65
+ "esbuild": "^0.25.0",
66
+ "typescript": "7.0.2",
67
+ "typescript-legacy": "npm:typescript@5.8.2",
68
+ "vitest": "^1.6.1",
69
+ "@posthog-tooling/sdk-mock-server": "0.0.0",
70
+ "@posthog-tooling/tsconfig-base": "1.1.1"
71
+ },
72
+ "scripts": {
73
+ "clean": "rimraf dist dist-cdn",
74
+ "lint": "oxlint --report-unused-disable-directives-severity error src snippet tests fixtures playwright playwright*.config.ts scripts/*.mjs",
75
+ "lint:fix": "oxlint --report-unused-disable-directives-severity error src snippet tests fixtures playwright playwright*.config.ts scripts/*.mjs --fix",
76
+ "build": "rslib build",
77
+ "dev": "rslib build -w",
78
+ "test:unit": "vitest run",
79
+ "test:built": "node scripts/check-mixed-module-delivery.mjs",
80
+ "test:browser": "pnpm --filter @posthog-tooling/sdk-mock-server build && playwright test --config playwright.config.ts",
81
+ "test:capture-v1-live": "pnpm build && node scripts/check-capture-v1-live.mjs",
82
+ "test:mixed-modules": "rslib build && node scripts/check-mixed-module-delivery.mjs",
83
+ "check-types": "node node_modules/typescript-legacy/bin/tsc --noEmit --project tsconfig.json",
84
+ "bundle-size": "pnpm build && node scripts/check-bundle-size.mjs",
85
+ "package": "pnpm pack --out $PACKAGE_DEST/%s.tgz",
86
+ "test:fixture-server": "pnpm --filter @posthog-tooling/sdk-mock-server build && node --test scripts/serve-browser-tests.test.mjs",
87
+ "build:cdn": "node scripts/build-cdn.mjs",
88
+ "test:snippet": "pnpm --filter @posthog-tooling/sdk-mock-server build && pnpm build:cdn && node scripts/check-cdn-bundle.mjs && playwright test --config playwright.snippet.config.ts",
89
+ "bundle-size:cdn": "pnpm build:cdn && node scripts/check-cdn-bundle.mjs"
90
+ }
91
+ }