@posthog/browser 0.1.1 → 0.2.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 (64) hide show
  1. package/ARCHITECTURE.md +28 -22
  2. package/README.md +65 -29
  3. package/dist/analytics-api.d.ts +26 -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 +76 -0
  10. package/dist/analytics-extension.js +589 -0
  11. package/dist/analytics-extension.mjs +551 -0
  12. package/dist/analytics-internal.d.ts +32 -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.d.ts +4 -3
  17. package/dist/autocapture.d.ts +2 -2
  18. package/dist/autocapture.js +21 -10
  19. package/dist/autocapture.mjs +21 -10
  20. package/dist/automatic-analytics.d.ts +2 -2
  21. package/dist/browser-client.d.ts +44 -4
  22. package/dist/capture-properties.d.ts +9 -0
  23. package/dist/capture-properties.js +68 -0
  24. package/dist/capture-properties.mjs +30 -0
  25. package/dist/capture-v1.js +7 -19
  26. package/dist/capture-v1.mjs +1 -13
  27. package/dist/core.d.ts +7 -5
  28. package/dist/extensions/registry.d.ts +42 -7
  29. package/dist/extensions/registry.js +194 -37
  30. package/dist/extensions/registry.mjs +194 -37
  31. package/dist/flags-token.d.ts +4 -4
  32. package/dist/flags.js +15 -2
  33. package/dist/flags.mjs +15 -2
  34. package/dist/immutable.d.ts +1 -0
  35. package/dist/immutable.js +46 -0
  36. package/dist/immutable.mjs +8 -0
  37. package/dist/index.d.ts +7 -5
  38. package/dist/index.js +3 -67
  39. package/dist/index.mjs +3 -67
  40. package/dist/logs-internal.d.ts +2 -2
  41. package/dist/logs.js +5 -2
  42. package/dist/logs.mjs +5 -2
  43. package/dist/person-processing.d.ts +11 -0
  44. package/dist/person-processing.js +84 -0
  45. package/dist/person-processing.mjs +37 -0
  46. package/dist/posthog.d.ts +4 -3
  47. package/dist/posthog.js +153 -353
  48. package/dist/posthog.mjs +153 -353
  49. package/dist/root-composition.d.ts +11 -0
  50. package/dist/root-composition.js +138 -0
  51. package/dist/root-composition.mjs +100 -0
  52. package/dist/state.d.ts +1 -0
  53. package/dist/state.js +4 -0
  54. package/dist/state.mjs +4 -0
  55. package/dist/surveys-extension.js +11 -6
  56. package/dist/surveys-extension.mjs +11 -6
  57. package/dist/surveys-internal.d.ts +3 -2
  58. package/dist/types.d.ts +13 -19
  59. package/dist/utf8.d.ts +1 -0
  60. package/dist/utf8.js +52 -0
  61. package/dist/utf8.mjs +14 -0
  62. package/dist/version.js +1 -1
  63. package/dist/version.mjs +1 -1
  64. package/package.json +5 -5
@@ -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 };
@@ -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,9 @@
1
+ import type { CaptureOptions } from '@posthog/browser-common';
2
+ export interface CaptureProperties {
3
+ message: Record<string, unknown>;
4
+ observed: Record<string, unknown>;
5
+ uuid: string | undefined;
6
+ timestamp: Date | undefined;
7
+ }
8
+ /** Invoke caller serialization once, before selecting the authoritative session. */
9
+ export declare const snapshotCaptureProperties: (dynamic: Record<string, unknown>, properties: Record<string, unknown> | null, options: CaptureOptions) => CaptureProperties;
@@ -0,0 +1,68 @@
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 isRecord = (value)=>'object' == typeof value && null !== value && !Array.isArray(value);
31
+ const parseMessageProperties = (json)=>{
32
+ const properties = JSON.parse(json, function(_key, value) {
33
+ return null !== value || Array.isArray(this) ? value : void 0;
34
+ });
35
+ if (!isRecord(properties)) throw new Error('Event properties must serialize to an object');
36
+ return properties;
37
+ };
38
+ const snapshotCaptureProperties = (dynamic, properties, options)=>{
39
+ const supplied = {
40
+ ...dynamic,
41
+ ...properties ?? {}
42
+ };
43
+ const set = options.set;
44
+ const setOnce = options.setOnce;
45
+ const uuid = options.uuid;
46
+ const timestamp = options.timestamp;
47
+ if (set) supplied['$set'] = set;
48
+ if (setOnce) supplied['$set_once'] = setOnce;
49
+ const json = JSON.stringify(supplied);
50
+ const message = parseMessageProperties(json);
51
+ const observed = JSON.parse(json);
52
+ return {
53
+ message,
54
+ observed,
55
+ uuid,
56
+ timestamp
57
+ };
58
+ };
59
+ __webpack_require__.d(__webpack_exports__, {}, {
60
+ snapshotCaptureProperties: snapshotCaptureProperties
61
+ });
62
+ exports.snapshotCaptureProperties = __webpack_exports__.snapshotCaptureProperties;
63
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
64
+ "snapshotCaptureProperties"
65
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
66
+ Object.defineProperty(exports, '__esModule', {
67
+ value: true
68
+ });
@@ -0,0 +1,30 @@
1
+ const isRecord = (value)=>'object' == typeof value && null !== value && !Array.isArray(value);
2
+ const parseMessageProperties = (json)=>{
3
+ const properties = JSON.parse(json, function(_key, value) {
4
+ return null !== value || Array.isArray(this) ? value : void 0;
5
+ });
6
+ if (!isRecord(properties)) throw new Error('Event properties must serialize to an object');
7
+ return properties;
8
+ };
9
+ const snapshotCaptureProperties = (dynamic, properties, options)=>{
10
+ const supplied = {
11
+ ...dynamic,
12
+ ...properties ?? {}
13
+ };
14
+ const set = options.set;
15
+ const setOnce = options.setOnce;
16
+ const uuid = options.uuid;
17
+ const timestamp = options.timestamp;
18
+ if (set) supplied['$set'] = set;
19
+ if (setOnce) supplied['$set_once'] = setOnce;
20
+ const json = JSON.stringify(supplied);
21
+ const message = parseMessageProperties(json);
22
+ const observed = JSON.parse(json);
23
+ return {
24
+ message,
25
+ observed,
26
+ uuid,
27
+ timestamp
28
+ };
29
+ };
30
+ export { snapshotCaptureProperties };
@@ -40,6 +40,7 @@ __webpack_require__.d(__webpack_exports__, {
40
40
  const external_analytics_internal_js_namespaceObject = require("./analytics-internal.js");
41
41
  const external_id_js_namespaceObject = require("./id.js");
42
42
  const external_named_error_js_namespaceObject = require("./named-error.js");
43
+ const external_utf8_js_namespaceObject = require("./utf8.js");
43
44
  const RETRYABLE_STATUSES = [
44
45
  408,
45
46
  500,
@@ -73,19 +74,6 @@ const failedResult = (events, error, statusCode = 0)=>({
73
74
  error,
74
75
  terminalError: error
75
76
  });
76
- const utf8Bytes = (value)=>{
77
- let bytes = 0;
78
- for(let index = 0; index < value.length; index++){
79
- const code = value.charCodeAt(index);
80
- if (code < 0x80) bytes++;
81
- else if (code < 0x800) bytes += 2;
82
- else if (code >= 0xd800 && code <= 0xdbff && value.charCodeAt(index + 1) >= 0xdc00) {
83
- bytes += 4;
84
- index++;
85
- } else bytes += 3;
86
- }
87
- return bytes;
88
- };
89
77
  const prepareEvents = (messages)=>messages.map((source)=>{
90
78
  const event = buildCaptureV1Event(source);
91
79
  const json = JSON.stringify(event);
@@ -94,13 +82,13 @@ const prepareEvents = (messages)=>messages.map((source)=>{
94
82
  event,
95
83
  uuid: event.uuid,
96
84
  json,
97
- bytes: utf8Bytes(json)
85
+ bytes: (0, external_utf8_js_namespaceObject.utf8Bytes)(json)
98
86
  };
99
87
  });
100
88
  const serializeEnvelope = (createdAt, events)=>`{"created_at":${JSON.stringify(createdAt)},"batch":[${events.map(({ json })=>json).join(',')}]}`;
101
89
  const partitionEvents = (events, createdAt, maxBatchEvents, targetBatchBytes)=>{
102
90
  const batches = [];
103
- const emptyBytes = utf8Bytes(serializeEnvelope(createdAt, []));
91
+ const emptyBytes = (0, external_utf8_js_namespaceObject.utf8Bytes)(serializeEnvelope(createdAt, []));
104
92
  let batch = [];
105
93
  let bytes = emptyBytes;
106
94
  for (const event of events){
@@ -356,14 +344,14 @@ const attemptOnce = async (runtime, events, libraryVersion, createdAt, requestId
356
344
  'PostHog-Request-Timestamp': isoNow(now)
357
345
  };
358
346
  let requestBody = body;
359
- if (compressionEnabled && utf8Bytes(body) >= compressionThresholdBytes) {
347
+ if (compressionEnabled && (0, external_utf8_js_namespaceObject.utf8Bytes)(body) >= compressionThresholdBytes) {
360
348
  const compressed = await compressWithDeadline(body, Math.max(1, Math.min(compressionTimeoutMs, remainingTime())), signal, compress);
361
349
  if (signal?.aborted || !canContinue(continuationCheck)) return [
362
350
  failedResult(events, cancellationError()),
363
351
  events,
364
352
  void 0
365
353
  ];
366
- if (compressed && compressed.size < utf8Bytes(body)) {
354
+ if (compressed && compressed.size < (0, external_utf8_js_namespaceObject.utf8Bytes)(body)) {
367
355
  requestBody = compressed;
368
356
  headers['Content-Encoding'] = 'gzip';
369
357
  }
@@ -632,14 +620,14 @@ const sendCaptureV1TeardownBatches = (runtime, messages, libraryVersion, options
632
620
  const createdAt = isoNow(now);
633
621
  const batch = [];
634
622
  let body = serializeEnvelope(createdAt, batch);
635
- let bodyBytes = utf8Bytes(body);
623
+ let bodyBytes = (0, external_utf8_js_namespaceObject.utf8Bytes)(body);
636
624
  while(index + batch.length < prepared.length && batch.length < CAPTURE_V1_MAX_BATCH_EVENTS){
637
625
  const candidate = prepared[index + batch.length];
638
626
  const candidateBody = serializeEnvelope(createdAt, [
639
627
  ...batch,
640
628
  candidate
641
629
  ]);
642
- const candidateBytes = utf8Bytes(candidateBody);
630
+ const candidateBytes = (0, external_utf8_js_namespaceObject.utf8Bytes)(candidateBody);
643
631
  if (candidateBytes > remaining || batch.length > 0 && candidateBytes > CAPTURE_V1_BATCH_TARGET_BYTES) break;
644
632
  batch.push(candidate);
645
633
  body = candidateBody;
@@ -1,6 +1,7 @@
1
1
  import { MAX_ANALYTICS_BATCH_EVENTS } from "./analytics-internal.mjs";
2
2
  import { createId } from "./id.mjs";
3
3
  import { defineErrorName } from "./named-error.mjs";
4
+ import { utf8Bytes } from "./utf8.mjs";
4
5
  const RETRYABLE_STATUSES = [
5
6
  408,
6
7
  500,
@@ -34,19 +35,6 @@ const failedResult = (events, error, statusCode = 0)=>({
34
35
  error,
35
36
  terminalError: error
36
37
  });
37
- const utf8Bytes = (value)=>{
38
- let bytes = 0;
39
- for(let index = 0; index < value.length; index++){
40
- const code = value.charCodeAt(index);
41
- if (code < 0x80) bytes++;
42
- else if (code < 0x800) bytes += 2;
43
- else if (code >= 0xd800 && code <= 0xdbff && value.charCodeAt(index + 1) >= 0xdc00) {
44
- bytes += 4;
45
- index++;
46
- } else bytes += 3;
47
- }
48
- return bytes;
49
- };
50
38
  const prepareEvents = (messages)=>messages.map((source)=>{
51
39
  const event = buildCaptureV1Event(source);
52
40
  const json = JSON.stringify(event);
package/dist/core.d.ts CHANGED
@@ -1,7 +1,9 @@
1
- import type { CorePostHogOptions, PostHog } from './types';
2
- /** Creates a buffer-only client unless analytics delivery is supplied through `extensions`. */
3
- export declare const createPostHog: (options: CorePostHogOptions) => Promise<PostHog>;
1
+ import type { CorePostHogOptions, IPostHog } from './types';
2
+ /** Creates a host with only explicitly supplied products and no automatic product imports. */
3
+ export declare const createPostHog: (options: CorePostHogOptions) => Promise<IPostHog>;
4
4
  export { version } from './version';
5
5
  export { FeatureFlagsExtension, type FeatureFlags } from './flags-token';
6
- export type { BrowserClient, IdentifyInfo, GroupInfo } from './browser-client';
7
- export type { AnalyticsOptions, ApiResponse, BrowserFetch, BrowserNavigator, CaptureOptions, CaptureOutcome, CaptureOutcomeStatus, CaptureSummary, CorePostHogOptions, Disposable, Extension, NewSessionInfo, NewSessionReason, PostHog, RemoteConfig, SendRequestInit, SessionContext, StorageLike, } from './types';
6
+ export type { IPostHogInternal, BrowserExtension, IdentifyInfo, GroupInfo } from './browser-client';
7
+ export type { IAnalytics } from './analytics-api';
8
+ export type { AnalyticsOptions, ApiResponse, BrowserFetch, BrowserNavigator, CaptureOptions, CaptureOutcome, CaptureOutcomeStatus, CaptureSummary, CorePostHogOptions, Disposable, Extension, NewSessionInfo, NewSessionReason, IPostHog, RemoteConfig, SendRequestInit, SessionContext, StorageLike, } from './types';
9
+ export type { PersonProfileMode } from './analytics-options';
@@ -1,16 +1,51 @@
1
1
  import type { Client, Extension } from '@posthog/browser-common';
2
- export declare class ExtensionRegistry {
2
+ export type ExtensionLoader<Host = Client> = (host: Host) => Extension<Host> | Promise<Extension<Host>>;
3
+ type Resolver<Host> = (name: string) => Promise<Extension<Host> | undefined>;
4
+ export interface AutomaticExtension<Host = Client> {
5
+ name: string;
6
+ activate(host: Host, acquire: () => Promise<Extension<Host> | undefined>): void | Promise<unknown>;
7
+ }
8
+ /** Owns product acquisition, installed views and one lifecycle per configured owner. */
9
+ export declare class ExtensionRegistry<Host = Client> {
10
+ private readonly _createClient;
11
+ private readonly _logger;
12
+ private readonly _loaders;
13
+ private readonly _setup;
14
+ private readonly _canInstall;
3
15
  private readonly _records;
16
+ private readonly _retired;
4
17
  private readonly _extensions;
18
+ private readonly _shared;
19
+ private readonly _sharedReservations;
20
+ private readonly _pending;
21
+ private readonly _dependencies;
22
+ private readonly _views;
23
+ private readonly _clients;
24
+ private readonly _publications;
5
25
  private _disposed;
6
- private readonly _createClient;
7
- private readonly _logger;
8
- constructor(createClient: (extensionName: string) => Client, logger: Client['logger']);
9
- get<T extends Extension = Extension>(name: string): T | undefined;
10
- install(extension: Extension): Promise<void>;
11
- rollback(extension: Extension): Promise<void>;
26
+ constructor(_createClient: (extensionName: string, resolve: Resolver<Host>) => Host, _logger: Client['logger'], _loaders?: Readonly<Record<string, ExtensionLoader<Host>>>, _setup?: (extension: Extension<Host>, host: Host) => void | Promise<void>, _canInstall?: () => boolean);
27
+ expose(target: object): void;
28
+ get<T extends Extension<Host> = Extension<Host>>(name: string): T | undefined;
29
+ getShared<T extends Extension = Extension>(name: string): T | undefined;
30
+ resolve(name: string): Promise<Extension<Host> | undefined>;
31
+ activate({ name, activate }: AutomaticExtension<Host>): Promise<void>;
32
+ install(extension: Extension<Host>): Promise<void>;
33
+ private _existingResolution;
34
+ private _reserveInstallation;
35
+ private _bindingEntries;
36
+ private _publishInstallation;
37
+ rollback(extension: Extension<Host>): Promise<void>;
12
38
  flush(reason?: 'flush' | 'shutdown'): Promise<void>;
13
39
  dispose(): Promise<void>;
40
+ private _client;
41
+ private _load;
42
+ private _resolveDependency;
43
+ private _reaches;
14
44
  private _removeRecord;
45
+ private _assertNameAvailable;
46
+ private _publish;
47
+ private _removePublication;
48
+ private _unpublish;
15
49
  private _disposeRecord;
16
50
  }
51
+ export {};