@posthog/browser 0.1.1 → 0.3.0

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 (73) hide show
  1. package/ARCHITECTURE.md +28 -22
  2. package/README.md +94 -29
  3. package/dist/analytics-api.d.ts +32 -0
  4. package/dist/analytics-api.js +18 -0
  5. package/dist/analytics-api.mjs +1 -0
  6. package/dist/analytics-buffer.d.ts +3 -3
  7. package/dist/analytics-buffer.js +2 -161
  8. package/dist/analytics-buffer.mjs +2 -161
  9. package/dist/analytics-extension.d.ts +87 -0
  10. package/dist/analytics-extension.js +649 -0
  11. package/dist/analytics-extension.mjs +611 -0
  12. package/dist/analytics-internal.d.ts +33 -18
  13. package/dist/analytics-options.d.ts +7 -2
  14. package/dist/analytics-options.js +38 -1
  15. package/dist/analytics-options.mjs +17 -1
  16. package/dist/analytics-properties.d.ts +12 -0
  17. package/dist/analytics-properties.js +88 -0
  18. package/dist/analytics-properties.mjs +46 -0
  19. package/dist/analytics-session-properties.d.ts +12 -0
  20. package/dist/analytics-session-properties.js +84 -0
  21. package/dist/analytics-session-properties.mjs +46 -0
  22. package/dist/analytics.d.ts +4 -3
  23. package/dist/autocapture.d.ts +2 -2
  24. package/dist/autocapture.js +21 -10
  25. package/dist/autocapture.mjs +21 -10
  26. package/dist/automatic-analytics.d.ts +2 -2
  27. package/dist/browser-client.d.ts +44 -4
  28. package/dist/capture-properties.d.ts +15 -0
  29. package/dist/capture-properties.js +101 -0
  30. package/dist/capture-properties.mjs +57 -0
  31. package/dist/capture-v1.js +7 -19
  32. package/dist/capture-v1.mjs +1 -13
  33. package/dist/core.d.ts +7 -5
  34. package/dist/extensions/registry.d.ts +42 -7
  35. package/dist/extensions/registry.js +194 -37
  36. package/dist/extensions/registry.mjs +194 -37
  37. package/dist/flags-token.d.ts +4 -4
  38. package/dist/flags.js +15 -2
  39. package/dist/flags.mjs +15 -2
  40. package/dist/immutable.d.ts +1 -0
  41. package/dist/immutable.js +46 -0
  42. package/dist/immutable.mjs +8 -0
  43. package/dist/index.d.ts +7 -5
  44. package/dist/index.js +3 -67
  45. package/dist/index.mjs +3 -67
  46. package/dist/key-value-store.d.ts +21 -0
  47. package/dist/key-value-store.js +117 -0
  48. package/dist/key-value-store.mjs +72 -0
  49. package/dist/logs-internal.d.ts +2 -2
  50. package/dist/logs.js +5 -2
  51. package/dist/logs.mjs +5 -2
  52. package/dist/person-processing.d.ts +11 -0
  53. package/dist/person-processing.js +84 -0
  54. package/dist/person-processing.mjs +37 -0
  55. package/dist/posthog.d.ts +4 -3
  56. package/dist/posthog.js +154 -353
  57. package/dist/posthog.mjs +154 -353
  58. package/dist/root-composition.d.ts +11 -0
  59. package/dist/root-composition.js +138 -0
  60. package/dist/root-composition.mjs +100 -0
  61. package/dist/state.d.ts +6 -0
  62. package/dist/state.js +50 -56
  63. package/dist/state.mjs +50 -56
  64. package/dist/surveys-extension.js +11 -6
  65. package/dist/surveys-extension.mjs +11 -6
  66. package/dist/surveys-internal.d.ts +3 -2
  67. package/dist/types.d.ts +13 -19
  68. package/dist/utf8.d.ts +1 -0
  69. package/dist/utf8.js +52 -0
  70. package/dist/utf8.mjs +14 -0
  71. package/dist/version.js +1 -1
  72. package/dist/version.mjs +1 -1
  73. package/package.json +3 -3
@@ -1,5 +1,8 @@
1
- /** Scheduling options shared by automatic and explicitly composed analytics delivery. */
1
+ export type PersonProfileMode = 'always' | 'never' | 'identified_only';
2
+ /** Options owned by the analytics product, whether loaded automatically or explicitly composed. */
2
3
  export interface AnalyticsOptions {
4
+ /** Controls person processing. Defaults to `identified_only`. */
5
+ personProfiles?: PersonProfileMode;
3
6
  /** Number of queued events that triggers delivery. Defaults to 20; clamped to the V1 limit of 100. */
4
7
  flushAt?: number;
5
8
  /** Maximum delay in milliseconds before queued events are delivered. Defaults to 3000; 0 disables it. */
@@ -8,7 +11,9 @@ export interface AnalyticsOptions {
8
11
  export type LoadStrategy = 'lazy' | 'eager';
9
12
  /** Automatic analytics loading configured by the default package entrypoint. */
10
13
  export interface AutomaticAnalyticsOptions extends AnalyticsOptions {
11
- /** Load after the first admitted event, or while the client initializes. Defaults to `lazy`. */
14
+ /** Acquire analytics on demand and load delivery after admission, or acquire and start delivery during initialization. Defaults to `lazy`. */
12
15
  load?: LoadStrategy;
13
16
  }
14
17
  export type AnalyticsConfiguration = false | AutomaticAnalyticsOptions;
18
+ /** Capture configuration at client creation, independently of when the product loads. */
19
+ export declare const snapshotAutomaticAnalyticsOptions: (options?: AutomaticAnalyticsOptions) => AutomaticAnalyticsOptions;
@@ -1,5 +1,20 @@
1
1
  "use strict";
2
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
+ })();
3
18
  (()=>{
4
19
  __webpack_require__.r = (exports1)=>{
5
20
  if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
@@ -12,7 +27,29 @@ var __webpack_require__ = {};
12
27
  })();
13
28
  var __webpack_exports__ = {};
14
29
  __webpack_require__.r(__webpack_exports__);
15
- for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
30
+ const snapshotAutomaticAnalyticsOptions = (options = {})=>{
31
+ const snapshot = {};
32
+ for (const key of [
33
+ 'flushAt',
34
+ 'flushInterval',
35
+ 'personProfiles',
36
+ 'load'
37
+ ])try {
38
+ const value = options[key];
39
+ if (void 0 !== value) Object.defineProperty(snapshot, key, {
40
+ value,
41
+ enumerable: true
42
+ });
43
+ } catch {}
44
+ return snapshot;
45
+ };
46
+ __webpack_require__.d(__webpack_exports__, {}, {
47
+ snapshotAutomaticAnalyticsOptions: snapshotAutomaticAnalyticsOptions
48
+ });
49
+ exports.snapshotAutomaticAnalyticsOptions = __webpack_exports__.snapshotAutomaticAnalyticsOptions;
50
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
51
+ "snapshotAutomaticAnalyticsOptions"
52
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
16
53
  Object.defineProperty(exports, '__esModule', {
17
54
  value: true
18
55
  });
@@ -1 +1,17 @@
1
- export { };
1
+ const snapshotAutomaticAnalyticsOptions = (options = {})=>{
2
+ const snapshot = {};
3
+ for (const key of [
4
+ 'flushAt',
5
+ 'flushInterval',
6
+ 'personProfiles',
7
+ 'load'
8
+ ])try {
9
+ const value = options[key];
10
+ if (void 0 !== value) Object.defineProperty(snapshot, key, {
11
+ value,
12
+ enumerable: true
13
+ });
14
+ } catch {}
15
+ return snapshot;
16
+ };
17
+ export { snapshotAutomaticAnalyticsOptions };
@@ -0,0 +1,12 @@
1
+ import type { KeyValueStore } from '@posthog/browser-common';
2
+ export declare const snapshotRegisteredProperties: (value: Record<string, unknown>) => Record<string, unknown> | undefined;
3
+ /** Persistent event context in analytics' existing host-owned namespace. */
4
+ export declare class RegisteredProperties {
5
+ private readonly _kv;
6
+ constructor(_kv: KeyValueStore);
7
+ values(): Record<string, unknown>;
8
+ get(property: string): unknown;
9
+ register(properties: Record<string, unknown>): void;
10
+ registerOnce(properties: Record<string, unknown>, defaultValue: unknown): void;
11
+ unregister(property: string): void;
12
+ }
@@ -0,0 +1,88 @@
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 REGISTERED_PROPERTIES = 'superProperties';
31
+ const isPropertyMap = (value)=>'object' == typeof value && null !== value && !Array.isArray(value);
32
+ const snapshotRegisteredProperties = (value)=>{
33
+ try {
34
+ if (!isPropertyMap(value)) return;
35
+ const snapshot = JSON.parse(JSON.stringify(value));
36
+ return isPropertyMap(snapshot) ? snapshot : void 0;
37
+ } catch {
38
+ return;
39
+ }
40
+ };
41
+ class RegisteredProperties {
42
+ constructor(_kv){
43
+ this._kv = _kv;
44
+ }
45
+ values() {
46
+ const value = this._kv.get(REGISTERED_PROPERTIES);
47
+ return isPropertyMap(value) ? value : {};
48
+ }
49
+ get(property) {
50
+ const values = this.values();
51
+ return Object.prototype.hasOwnProperty.call(values, property) ? values[property] : void 0;
52
+ }
53
+ register(properties) {
54
+ this._kv.set(REGISTERED_PROPERTIES, {
55
+ ...this.values(),
56
+ ...properties
57
+ });
58
+ }
59
+ registerOnce(properties, defaultValue) {
60
+ const values = this.values();
61
+ const additions = Object.fromEntries(Object.entries(properties).filter(([key])=>!Object.prototype.hasOwnProperty.call(values, key) || values[key] === defaultValue));
62
+ if (0 === Object.keys(additions).length) return;
63
+ this._kv.set(REGISTERED_PROPERTIES, {
64
+ ...values,
65
+ ...additions
66
+ });
67
+ }
68
+ unregister(property) {
69
+ const values = this.values();
70
+ if (!Object.prototype.hasOwnProperty.call(values, property)) return;
71
+ delete values[property];
72
+ this._kv.set(REGISTERED_PROPERTIES, values);
73
+ }
74
+ }
75
+ __webpack_require__.d(__webpack_exports__, {
76
+ RegisteredProperties: ()=>RegisteredProperties
77
+ }, {
78
+ snapshotRegisteredProperties: snapshotRegisteredProperties
79
+ });
80
+ exports.RegisteredProperties = __webpack_exports__.RegisteredProperties;
81
+ exports.snapshotRegisteredProperties = __webpack_exports__.snapshotRegisteredProperties;
82
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
83
+ "RegisteredProperties",
84
+ "snapshotRegisteredProperties"
85
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
86
+ Object.defineProperty(exports, '__esModule', {
87
+ value: true
88
+ });
@@ -0,0 +1,46 @@
1
+ const REGISTERED_PROPERTIES = 'superProperties';
2
+ const isPropertyMap = (value)=>'object' == typeof value && null !== value && !Array.isArray(value);
3
+ const snapshotRegisteredProperties = (value)=>{
4
+ try {
5
+ if (!isPropertyMap(value)) return;
6
+ const snapshot = JSON.parse(JSON.stringify(value));
7
+ return isPropertyMap(snapshot) ? snapshot : void 0;
8
+ } catch {
9
+ return;
10
+ }
11
+ };
12
+ class RegisteredProperties {
13
+ constructor(_kv){
14
+ this._kv = _kv;
15
+ }
16
+ values() {
17
+ const value = this._kv.get(REGISTERED_PROPERTIES);
18
+ return isPropertyMap(value) ? value : {};
19
+ }
20
+ get(property) {
21
+ const values = this.values();
22
+ return Object.prototype.hasOwnProperty.call(values, property) ? values[property] : void 0;
23
+ }
24
+ register(properties) {
25
+ this._kv.set(REGISTERED_PROPERTIES, {
26
+ ...this.values(),
27
+ ...properties
28
+ });
29
+ }
30
+ registerOnce(properties, defaultValue) {
31
+ const values = this.values();
32
+ const additions = Object.fromEntries(Object.entries(properties).filter(([key])=>!Object.prototype.hasOwnProperty.call(values, key) || values[key] === defaultValue));
33
+ if (0 === Object.keys(additions).length) return;
34
+ this._kv.set(REGISTERED_PROPERTIES, {
35
+ ...values,
36
+ ...additions
37
+ });
38
+ }
39
+ unregister(property) {
40
+ const values = this.values();
41
+ if (!Object.prototype.hasOwnProperty.call(values, property)) return;
42
+ delete values[property];
43
+ this._kv.set(REGISTERED_PROPERTIES, values);
44
+ }
45
+ }
46
+ export { RegisteredProperties, snapshotRegisteredProperties };
@@ -0,0 +1,12 @@
1
+ import type { KeyValueStore } from '@posthog/browser-common';
2
+ /** Property scope is labelled by core's SDK session, never by an independent clock. */
3
+ export declare class SessionRegisteredProperties {
4
+ private readonly _kv;
5
+ private readonly _properties;
6
+ constructor(_kv: KeyValueStore);
7
+ values(sessionId: string | undefined): Record<string, unknown>;
8
+ register(properties: Record<string, unknown>, sessionId: string | undefined): void;
9
+ unregister(property: string, sessionId: string | undefined): void;
10
+ admitted(sessionId: string): void;
11
+ clear(): void;
12
+ }
@@ -0,0 +1,84 @@
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
+ __webpack_require__.d(__webpack_exports__, {
31
+ SessionRegisteredProperties: ()=>SessionRegisteredProperties
32
+ });
33
+ const external_analytics_properties_js_namespaceObject = require("./analytics-properties.js");
34
+ class SessionRegisteredProperties {
35
+ constructor(_kv){
36
+ this._kv = _kv;
37
+ this._properties = new external_analytics_properties_js_namespaceObject.RegisteredProperties(_kv);
38
+ }
39
+ values(sessionId) {
40
+ const scope = this._kv.get('sessionId');
41
+ return void 0 === scope || scope === sessionId ? this._properties.values() : {};
42
+ }
43
+ register(properties, sessionId) {
44
+ this._kv.set({
45
+ superProperties: {
46
+ ...this.values(sessionId),
47
+ ...properties
48
+ },
49
+ sessionId
50
+ });
51
+ }
52
+ unregister(property, sessionId) {
53
+ const values = this.values(sessionId);
54
+ if (!Object.prototype.hasOwnProperty.call(values, property)) return;
55
+ delete values[property];
56
+ this._kv.set({
57
+ superProperties: values,
58
+ sessionId
59
+ });
60
+ }
61
+ admitted(sessionId) {
62
+ const scope = this._kv.get('sessionId');
63
+ if (scope === sessionId) return;
64
+ const properties = this._properties.values();
65
+ if (void 0 === scope && 0 === Object.keys(properties).length) return;
66
+ this._kv.set({
67
+ superProperties: this.values(sessionId),
68
+ sessionId
69
+ });
70
+ }
71
+ clear() {
72
+ this._kv.remove([
73
+ 'superProperties',
74
+ 'sessionId'
75
+ ]);
76
+ }
77
+ }
78
+ exports.SessionRegisteredProperties = __webpack_exports__.SessionRegisteredProperties;
79
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
80
+ "SessionRegisteredProperties"
81
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
82
+ Object.defineProperty(exports, '__esModule', {
83
+ value: true
84
+ });
@@ -0,0 +1,46 @@
1
+ import { RegisteredProperties } from "./analytics-properties.mjs";
2
+ class SessionRegisteredProperties {
3
+ constructor(_kv){
4
+ this._kv = _kv;
5
+ this._properties = new RegisteredProperties(_kv);
6
+ }
7
+ values(sessionId) {
8
+ const scope = this._kv.get('sessionId');
9
+ return void 0 === scope || scope === sessionId ? this._properties.values() : {};
10
+ }
11
+ register(properties, sessionId) {
12
+ this._kv.set({
13
+ superProperties: {
14
+ ...this.values(sessionId),
15
+ ...properties
16
+ },
17
+ sessionId
18
+ });
19
+ }
20
+ unregister(property, sessionId) {
21
+ const values = this.values(sessionId);
22
+ if (!Object.prototype.hasOwnProperty.call(values, property)) return;
23
+ delete values[property];
24
+ this._kv.set({
25
+ superProperties: values,
26
+ sessionId
27
+ });
28
+ }
29
+ admitted(sessionId) {
30
+ const scope = this._kv.get('sessionId');
31
+ if (scope === sessionId) return;
32
+ const properties = this._properties.values();
33
+ if (void 0 === scope && 0 === Object.keys(properties).length) return;
34
+ this._kv.set({
35
+ superProperties: this.values(sessionId),
36
+ sessionId
37
+ });
38
+ }
39
+ clear() {
40
+ this._kv.remove([
41
+ 'superProperties',
42
+ 'sessionId'
43
+ ]);
44
+ }
45
+ }
46
+ export { SessionRegisteredProperties };
@@ -1,5 +1,6 @@
1
- import type { Extension } from '@posthog/browser-common';
1
+ import type { IAnalytics } from './analytics-api';
2
2
  import type { AnalyticsOptions } from './analytics-options';
3
- export type { AnalyticsOptions } from './analytics-options';
3
+ export type { IAnalytics } from './analytics-api';
4
+ export type { AnalyticsOptions, PersonProfileMode } from './analytics-options';
4
5
  /** Creates analytics with its buffer and Capture V1 delivery statically included. */
5
- export declare const analytics: (options?: AnalyticsOptions) => Extension;
6
+ export declare const analytics: (options?: AnalyticsOptions) => IAnalytics;
@@ -1,5 +1,5 @@
1
- import type { Extension } from '@posthog/browser-common';
1
+ import type { BrowserProducts } from './browser-client';
2
2
  import { type AutocaptureOptions } from './autocapture-options';
3
3
  export type { AutocaptureOptions, RageclickOptions } from './autocapture-options';
4
4
  /** Include DOM autocapture statically instead of loading it during initialization. */
5
- export declare const autocapture: (options?: AutocaptureOptions) => Extension;
5
+ export declare const autocapture: (options?: AutocaptureOptions) => BrowserProducts['autocapture'];
@@ -86,18 +86,29 @@ const autocapture = (options = {})=>{
86
86
  } : {},
87
87
  capture_copied_text: snapshot.captureCopiedText ?? false
88
88
  };
89
- return new class extends autocapture_namespaceObject.Autocapture {
90
- setup(client) {
91
- const selectors = client.getExtension('surveys')?.getElementSelectors?.();
92
- if (selectors) this.setElementSelectors(selectors);
93
- super.setup(client);
94
- }
95
- setElementSelectors(selectors) {
96
- super.setElementSelectors(new Set(selectors));
97
- }
98
- }({
89
+ let disposed = false;
90
+ const shared = new autocapture_namespaceObject.Autocapture({
99
91
  refresh: (target)=>Object.assign(target, config)
100
92
  });
93
+ const extension = {
94
+ name: 'autocapture',
95
+ bindings: {
96
+ autocapture: shared
97
+ },
98
+ async setup (client) {
99
+ await client.resolveExtension('analytics');
100
+ if (disposed) return;
101
+ const selectors = client.surveys?.getElementSelectors?.();
102
+ if (selectors) extension.setElementSelectors(selectors);
103
+ shared.setup(client.sharedClient);
104
+ },
105
+ setElementSelectors: (selectors)=>shared.setElementSelectors(new Set(selectors)),
106
+ dispose: ()=>{
107
+ disposed = true;
108
+ shared.dispose();
109
+ }
110
+ };
111
+ return extension;
101
112
  };
102
113
  exports.autocapture = __webpack_exports__.autocapture;
103
114
  for(var __rspack_i in __webpack_exports__)if (-1 === [
@@ -54,17 +54,28 @@ const autocapture = (options = {})=>{
54
54
  } : {},
55
55
  capture_copied_text: snapshot.captureCopiedText ?? false
56
56
  };
57
- return new class extends Autocapture {
58
- setup(client) {
59
- const selectors = client.getExtension('surveys')?.getElementSelectors?.();
60
- if (selectors) this.setElementSelectors(selectors);
61
- super.setup(client);
62
- }
63
- setElementSelectors(selectors) {
64
- super.setElementSelectors(new Set(selectors));
65
- }
66
- }({
57
+ let disposed = false;
58
+ const shared = new Autocapture({
67
59
  refresh: (target)=>Object.assign(target, config)
68
60
  });
61
+ const extension = {
62
+ name: 'autocapture',
63
+ bindings: {
64
+ autocapture: shared
65
+ },
66
+ async setup (client) {
67
+ await client.resolveExtension('analytics');
68
+ if (disposed) return;
69
+ const selectors = client.surveys?.getElementSelectors?.();
70
+ if (selectors) extension.setElementSelectors(selectors);
71
+ shared.setup(client.sharedClient);
72
+ },
73
+ setElementSelectors: (selectors)=>shared.setElementSelectors(new Set(selectors)),
74
+ dispose: ()=>{
75
+ disposed = true;
76
+ shared.dispose();
77
+ }
78
+ };
79
+ return extension;
69
80
  };
70
81
  export { autocapture };
@@ -1,3 +1,3 @@
1
- import type { AnalyticsExtension } from './analytics-internal';
1
+ import type { IAnalyticsExtension } from './analytics-internal';
2
2
  import type { AutomaticAnalyticsOptions } from './analytics-options';
3
- export declare const analytics: (options: AutomaticAnalyticsOptions) => AnalyticsExtension;
3
+ export declare const analytics: (options: AutomaticAnalyticsOptions) => IAnalyticsExtension;
@@ -1,4 +1,10 @@
1
- import type { Client, DeepReadonly, Listener } from '@posthog/browser-common';
1
+ import type { Client, DeepReadonly, Extension, ExtensionToken, Listener } from '@posthog/browser-common';
2
+ import type { IAnalytics } from './analytics-api';
3
+ import type { IAnalyticsExtension } from './analytics-internal';
4
+ import type { FeatureFlags } from './flags-token';
5
+ import type { FlagsExtension } from './flags-internal';
6
+ import type { LogsExtension } from './logs-internal';
7
+ import type { SurveysExtension } from './surveys-internal';
2
8
  import type { ConsentState } from './state';
3
9
  export interface IdentifyInfo {
4
10
  readonly distinctId: string;
@@ -6,6 +12,12 @@ export interface IdentifyInfo {
6
12
  readonly wasIdentified: boolean;
7
13
  readonly set: DeepReadonly<Record<string, unknown>> | undefined;
8
14
  readonly setOnce: DeepReadonly<Record<string, unknown>> | undefined;
15
+ readonly unset?: readonly string[];
16
+ }
17
+ export interface ChangePropertiesInfo {
18
+ readonly set?: DeepReadonly<Record<string, unknown>> | undefined;
19
+ readonly setOnce?: DeepReadonly<Record<string, unknown>> | undefined;
20
+ readonly unset?: readonly string[];
9
21
  }
10
22
  export interface GroupInfo {
11
23
  readonly type: string;
@@ -17,14 +29,42 @@ export interface ConsentChangeInfo {
17
29
  readonly current: ConsentState;
18
30
  readonly previous: ConsentState;
19
31
  }
20
- /** Host capabilities supplied to browser-next extensions during setup. */
21
- export interface BrowserClient extends Client {
32
+ export type BrowserExtension = Extension<IPostHogInternal>;
33
+ export interface BrowserProducts {
34
+ analytics: IAnalytics;
35
+ featureFlags: FeatureFlags;
36
+ logs: LogsExtension;
37
+ surveys: SurveysExtension;
38
+ autocapture: BrowserExtension & {
39
+ setElementSelectors(selectors: Set<string>): void;
40
+ };
41
+ }
42
+ export interface InternalBrowserProducts extends BrowserProducts {
43
+ analytics: IAnalyticsExtension;
44
+ featureFlags: FlagsExtension;
45
+ }
46
+ export type BrowserExtensionAccess<Products extends BrowserProducts = BrowserProducts> = Readonly<Partial<Products>> & {
47
+ resolveExtension<T extends BrowserExtension>(token: ExtensionToken<T>): Promise<T | undefined>;
48
+ resolveExtension<Name extends keyof Products>(name: Name): Promise<Products[Name] | undefined>;
49
+ resolveExtension<T extends BrowserExtension = BrowserExtension>(name: string): Promise<T | undefined>;
50
+ };
51
+ /** Shared Core capabilities, without application administration or product controls. */
52
+ export interface ICoreCapabilities extends Omit<Client, 'getExtension' | 'capture' | 'registerDynamicEventProperties' | 'isRateLimited' | 'onEvent'> {
22
53
  /** Fires when consent changes, including changes observed from another tab. Does not replay. */
23
54
  readonly onConsentChange: Listener<ConsentChangeInfo>;
24
- /** Fires after identification or person-property updates, independently of capture consent. Does not replay. */
55
+ /** Fires after identification, independently of capture consent. Does not replay. */
25
56
  readonly onIdentify: Listener<IdentifyInfo>;
26
57
  /** Fires after group membership or property updates, independently of capture consent. Does not replay. */
27
58
  readonly onGroup: Listener<GroupInfo>;
59
+ /** Fires after group-only reset clears local membership. Does not replay. */
60
+ readonly onGroupsReset: Listener<void>;
28
61
  /** Fires after local identity and persisted extension state are reset. Does not replay. */
29
62
  readonly onReset: Listener<void>;
30
63
  }
64
+ /** SDK-internal scoped view; shared implementations receive a separate Client adapter. */
65
+ export interface IPostHogInternal extends ICoreCapabilities, BrowserExtensionAccess<InternalBrowserProducts> {
66
+ readonly sharedClient: Client;
67
+ /** Local person-property changes, independently of capture consent. Does not replay. */
68
+ readonly onChangeProperties: Listener<ChangePropertiesInfo>;
69
+ readonly onEvent: Client['onEvent'];
70
+ }
@@ -0,0 +1,15 @@
1
+ import type { CaptureOptions } from '@posthog/browser-common';
2
+ export interface CaptureProperties {
3
+ message: Record<string, unknown>;
4
+ observed: Record<string, unknown>;
5
+ /** Explicit caller and dynamic keys that session defaults cannot replace. */
6
+ overrides: ReadonlySet<string>;
7
+ uuid: string | undefined;
8
+ timestamp: Date | undefined;
9
+ }
10
+ /** Invoke caller serialization once, before selecting the authoritative session. */
11
+ export declare const snapshotCaptureProperties: (registered: Record<string, unknown> | undefined, dynamic: Record<string, unknown>, properties: Record<string, unknown> | null, options: CaptureOptions) => CaptureProperties;
12
+ /** Session values override persistent defaults, not explicit caller or dynamic values. */
13
+ export declare const applySessionProperties: (snapshot: CaptureProperties, values: Record<string, unknown>) => boolean;
14
+ /** A session layer cannot shrink explicit caller values or protected SDK metadata. */
15
+ export declare const unavoidableProperties: (snapshot: CaptureProperties, metadata: Record<string, unknown>) => Record<string, unknown>;