@posthog/browser 0.0.0-stage → 0.1.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 (121) hide show
  1. package/ARCHITECTURE.md +559 -0
  2. package/LICENSE +417 -0
  3. package/README.md +302 -2
  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 +163 -0
  63. package/dist/flags.mjs +122 -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 +823 -0
  90. package/dist/posthog.mjs +785 -0
  91. package/dist/rate-limiter.d.ts +19 -0
  92. package/dist/rate-limiter.js +89 -0
  93. package/dist/rate-limiter.mjs +51 -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 +7 -0
  113. package/dist/surveys.js +48 -0
  114. package/dist/surveys.mjs +7 -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 +88 -3
@@ -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
+ });
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,15 @@
1
+ import type { Disposable, Extension, ExtensionToken } from '@posthog/browser-common';
2
+ import type { FeatureFlagResult, FeatureFlagsReloadResult, FlagsCallback, JsonType } from './flags-options';
3
+ import type { BrowserClient } from './browser-client';
4
+ export interface FeatureFlags extends Extension {
5
+ setup(client: BrowserClient): void | Promise<void>;
6
+ getFeatureFlag(key: string): FeatureFlagResult | undefined;
7
+ /** Refresh remotely and await its outcome. Calls during an active evaluation wait for a follow-up request. */
8
+ reloadFeatureFlags(): Promise<FeatureFlagsReloadResult>;
9
+ onFeatureFlags(callback: FlagsCallback): Disposable;
10
+ updateFlags(flags: Record<string, boolean | string>, payloads?: Record<string, JsonType>, options?: {
11
+ merge?: boolean;
12
+ }): void;
13
+ }
14
+ /** Resolve installed feature flags without importing their implementation. */
15
+ export declare const FeatureFlagsExtension: ExtensionToken<FeatureFlags>;
@@ -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 FeatureFlagsExtension = 'featureFlags';
31
+ __webpack_require__.d(__webpack_exports__, {}, {
32
+ FeatureFlagsExtension: FeatureFlagsExtension
33
+ });
34
+ exports.FeatureFlagsExtension = __webpack_exports__.FeatureFlagsExtension;
35
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
36
+ "FeatureFlagsExtension"
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 FeatureFlagsExtension = 'featureFlags';
2
+ export { FeatureFlagsExtension };
@@ -0,0 +1,6 @@
1
+ import type { FlagsOptions } from './flags-options';
2
+ import { type FeatureFlags } from './flags-token';
3
+ export { FeatureFlagsExtension, type FeatureFlags } from './flags-token';
4
+ export type { FlagsOptions, FlagsCallback, FeatureFlagResult, FeatureFlagsReloadResult } from './flags-options';
5
+ /** Statically include feature flags, bypassing the default runtime module load. */
6
+ export declare const flags: (options?: FlagsOptions) => FeatureFlags;
package/dist/flags.js ADDED
@@ -0,0 +1,163 @@
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
+ FeatureFlagsExtension: ()=>external_flags_token_js_namespaceObject.FeatureFlagsExtension,
32
+ flags: ()=>flags
33
+ });
34
+ const constants_namespaceObject = require("@posthog/browser-common/constants");
35
+ const feature_flags_namespaceObject = require("@posthog/browser-common/feature-flags");
36
+ const extension_tokens_namespaceObject = require("@posthog/browser-common/extension-tokens");
37
+ const external_flags_token_js_namespaceObject = require("./flags-token.js");
38
+ const flags = (options = {})=>{
39
+ const snapshot = JSON.parse(JSON.stringify(options));
40
+ const config = {
41
+ bootstrap: snapshot.bootstrap ?? {},
42
+ remoteRequestsDisabled: false,
43
+ featureFlagsDisabled: false === snapshot.featureFlagEvaluation,
44
+ onlyEvaluateSurveyFeatureFlags: snapshot.onlyEvaluateSurveyFeatureFlags ?? false,
45
+ deduplicateCallsPerSession: snapshot.deduplicateCallsPerSession ?? false,
46
+ ...void 0 === snapshot.cacheTtlMs ? {} : {
47
+ cacheTtlMs: snapshot.cacheTtlMs
48
+ },
49
+ refreshIntervalMs: false === snapshot.featureFlagEvaluation ? 0 : snapshot.refreshIntervalMs ?? 300000,
50
+ idleRefreshBackoff: void 0 === snapshot.refreshIntervalMs,
51
+ requestTimeoutMs: snapshot.requestTimeoutMs ?? 3000,
52
+ evaluationContexts: snapshot.evaluationContexts ?? [],
53
+ ...void 0 === snapshot.flagKeys ? {} : {
54
+ flagKeys: snapshot.flagKeys
55
+ }
56
+ };
57
+ let client;
58
+ let disposed = false;
59
+ const subscriptions = [];
60
+ const shared = new feature_flags_namespaceObject.PostHogFeatureFlags({
61
+ get: ()=>config
62
+ });
63
+ const extension = {
64
+ name: external_flags_token_js_namespaceObject.FeatureFlagsExtension,
65
+ bindings: {
66
+ [extension_tokens_namespaceObject.FeatureFlagsCommonExtension]: shared
67
+ },
68
+ getSurveyContext: ()=>({
69
+ remoteEvaluation: !config.featureFlagsDisabled,
70
+ personProperties: client?.kv.get(constants_namespaceObject.STORED_PERSON_PROPERTIES_KEY)
71
+ }),
72
+ setup: async (value)=>{
73
+ client = value;
74
+ await shared.setup(value);
75
+ if (disposed) return;
76
+ subscriptions.push(value.onIdentify(({ distinctId, previousDistinctId, wasIdentified, set, setOnce })=>{
77
+ if (distinctId !== previousDistinctId) {
78
+ shared.resetFlagCallReported();
79
+ if (!wasIdentified) shared.setAnonymousDistinctId(previousDistinctId);
80
+ }
81
+ if (set || setOnce) shared.setPersonPropertiesForFlags({
82
+ $set: set ?? {},
83
+ $set_once: setOnce ?? {}
84
+ }, false);
85
+ shared.reloadFeatureFlags();
86
+ }));
87
+ subscriptions.push(value.onGroup(({ type, changed, properties })=>{
88
+ if (changed) shared.resetGroupPropertiesForFlags(type);
89
+ if (properties) shared.setGroupPropertiesForFlags({
90
+ [type]: properties
91
+ }, false);
92
+ shared.reloadFeatureFlags();
93
+ }));
94
+ subscriptions.push(value.onReset(()=>{
95
+ shared.reset();
96
+ shared.reloadFeatureFlags();
97
+ }));
98
+ shared.setPersonPropertiesForFlags({
99
+ ...value.initialPersonProperties
100
+ }, false);
101
+ shared.ensureFlagsLoaded();
102
+ },
103
+ getFeatureFlag: (key)=>{
104
+ if (disposed) return;
105
+ try {
106
+ return shared.getFeatureFlagResult(key);
107
+ } catch (error) {
108
+ client?.logger.error('Feature flag read failed', error);
109
+ return;
110
+ }
111
+ },
112
+ reloadFeatureFlags: async ()=>{
113
+ if (disposed) return {
114
+ status: 'cancelled'
115
+ };
116
+ try {
117
+ return await shared.reloadFeatureFlagsAsync();
118
+ } catch (error) {
119
+ client?.logger.error('Feature flags reload failed', error);
120
+ return {
121
+ status: 'error'
122
+ };
123
+ }
124
+ },
125
+ onFeatureFlags: (callback)=>{
126
+ if (!disposed) try {
127
+ const unsubscribe = shared.onFeatureFlags((_keys, _variants, context)=>callback(shared.getAllFeatureFlags(), !!context?.errorsLoading));
128
+ return {
129
+ dispose: unsubscribe
130
+ };
131
+ } catch (error) {
132
+ client?.logger.error("Feature flags subscription failed", error);
133
+ }
134
+ return {
135
+ dispose () {}
136
+ };
137
+ },
138
+ updateFlags: (values, payloads, settings)=>{
139
+ if (disposed) return;
140
+ try {
141
+ shared.updateFlags(values, payloads, settings);
142
+ } catch (error) {
143
+ client?.logger.error('Feature flags update failed', error);
144
+ }
145
+ },
146
+ dispose: ()=>{
147
+ if (disposed) return;
148
+ disposed = true;
149
+ subscriptions.splice(0).forEach((subscription)=>subscription.dispose());
150
+ shared.dispose();
151
+ }
152
+ };
153
+ return extension;
154
+ };
155
+ exports.FeatureFlagsExtension = __webpack_exports__.FeatureFlagsExtension;
156
+ exports.flags = __webpack_exports__.flags;
157
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
158
+ "FeatureFlagsExtension",
159
+ "flags"
160
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
161
+ Object.defineProperty(exports, '__esModule', {
162
+ value: true
163
+ });
package/dist/flags.mjs ADDED
@@ -0,0 +1,122 @@
1
+ import { STORED_PERSON_PROPERTIES_KEY } from "@posthog/browser-common/constants";
2
+ import { PostHogFeatureFlags } from "@posthog/browser-common/feature-flags";
3
+ import { FeatureFlagsCommonExtension } from "@posthog/browser-common/extension-tokens";
4
+ import { FeatureFlagsExtension } from "./flags-token.mjs";
5
+ const flags = (options = {})=>{
6
+ const snapshot = JSON.parse(JSON.stringify(options));
7
+ const config = {
8
+ bootstrap: snapshot.bootstrap ?? {},
9
+ remoteRequestsDisabled: false,
10
+ featureFlagsDisabled: false === snapshot.featureFlagEvaluation,
11
+ onlyEvaluateSurveyFeatureFlags: snapshot.onlyEvaluateSurveyFeatureFlags ?? false,
12
+ deduplicateCallsPerSession: snapshot.deduplicateCallsPerSession ?? false,
13
+ ...void 0 === snapshot.cacheTtlMs ? {} : {
14
+ cacheTtlMs: snapshot.cacheTtlMs
15
+ },
16
+ refreshIntervalMs: false === snapshot.featureFlagEvaluation ? 0 : snapshot.refreshIntervalMs ?? 300000,
17
+ idleRefreshBackoff: void 0 === snapshot.refreshIntervalMs,
18
+ requestTimeoutMs: snapshot.requestTimeoutMs ?? 3000,
19
+ evaluationContexts: snapshot.evaluationContexts ?? [],
20
+ ...void 0 === snapshot.flagKeys ? {} : {
21
+ flagKeys: snapshot.flagKeys
22
+ }
23
+ };
24
+ let client;
25
+ let disposed = false;
26
+ const subscriptions = [];
27
+ const shared = new PostHogFeatureFlags({
28
+ get: ()=>config
29
+ });
30
+ const extension = {
31
+ name: FeatureFlagsExtension,
32
+ bindings: {
33
+ [FeatureFlagsCommonExtension]: shared
34
+ },
35
+ getSurveyContext: ()=>({
36
+ remoteEvaluation: !config.featureFlagsDisabled,
37
+ personProperties: client?.kv.get(STORED_PERSON_PROPERTIES_KEY)
38
+ }),
39
+ setup: async (value)=>{
40
+ client = value;
41
+ await shared.setup(value);
42
+ if (disposed) return;
43
+ subscriptions.push(value.onIdentify(({ distinctId, previousDistinctId, wasIdentified, set, setOnce })=>{
44
+ if (distinctId !== previousDistinctId) {
45
+ shared.resetFlagCallReported();
46
+ if (!wasIdentified) shared.setAnonymousDistinctId(previousDistinctId);
47
+ }
48
+ if (set || setOnce) shared.setPersonPropertiesForFlags({
49
+ $set: set ?? {},
50
+ $set_once: setOnce ?? {}
51
+ }, false);
52
+ shared.reloadFeatureFlags();
53
+ }));
54
+ subscriptions.push(value.onGroup(({ type, changed, properties })=>{
55
+ if (changed) shared.resetGroupPropertiesForFlags(type);
56
+ if (properties) shared.setGroupPropertiesForFlags({
57
+ [type]: properties
58
+ }, false);
59
+ shared.reloadFeatureFlags();
60
+ }));
61
+ subscriptions.push(value.onReset(()=>{
62
+ shared.reset();
63
+ shared.reloadFeatureFlags();
64
+ }));
65
+ shared.setPersonPropertiesForFlags({
66
+ ...value.initialPersonProperties
67
+ }, false);
68
+ shared.ensureFlagsLoaded();
69
+ },
70
+ getFeatureFlag: (key)=>{
71
+ if (disposed) return;
72
+ try {
73
+ return shared.getFeatureFlagResult(key);
74
+ } catch (error) {
75
+ client?.logger.error('Feature flag read failed', error);
76
+ return;
77
+ }
78
+ },
79
+ reloadFeatureFlags: async ()=>{
80
+ if (disposed) return {
81
+ status: 'cancelled'
82
+ };
83
+ try {
84
+ return await shared.reloadFeatureFlagsAsync();
85
+ } catch (error) {
86
+ client?.logger.error('Feature flags reload failed', error);
87
+ return {
88
+ status: 'error'
89
+ };
90
+ }
91
+ },
92
+ onFeatureFlags: (callback)=>{
93
+ if (!disposed) try {
94
+ const unsubscribe = shared.onFeatureFlags((_keys, _variants, context)=>callback(shared.getAllFeatureFlags(), !!context?.errorsLoading));
95
+ return {
96
+ dispose: unsubscribe
97
+ };
98
+ } catch (error) {
99
+ client?.logger.error("Feature flags subscription failed", error);
100
+ }
101
+ return {
102
+ dispose () {}
103
+ };
104
+ },
105
+ updateFlags: (values, payloads, settings)=>{
106
+ if (disposed) return;
107
+ try {
108
+ shared.updateFlags(values, payloads, settings);
109
+ } catch (error) {
110
+ client?.logger.error('Feature flags update failed', error);
111
+ }
112
+ },
113
+ dispose: ()=>{
114
+ if (disposed) return;
115
+ disposed = true;
116
+ subscriptions.splice(0).forEach((subscription)=>subscription.dispose());
117
+ shared.dispose();
118
+ }
119
+ };
120
+ return extension;
121
+ };
122
+ export { FeatureFlagsExtension, flags };
package/dist/id.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare const createId: () => string;
package/dist/id.js ADDED
@@ -0,0 +1,61 @@
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
+ let fallbackSequence = 0;
31
+ const createId = ()=>{
32
+ try {
33
+ const crypto = globalThis.crypto;
34
+ if (crypto?.randomUUID) return crypto.randomUUID();
35
+ if (crypto?.getRandomValues) {
36
+ const bytes = crypto.getRandomValues(new Uint8Array(16));
37
+ bytes[6] = (bytes[6] ?? 0) & 0x0f | 0x40;
38
+ bytes[8] = (bytes[8] ?? 0) & 0x3f | 0x80;
39
+ const hex = bytes.reduce((value, byte)=>value + byte.toString(16).padStart(2, '0'), '');
40
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
41
+ }
42
+ } catch {}
43
+ let seed = Date.now() + fallbackSequence++;
44
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (character)=>{
45
+ let random = 15 & seed++;
46
+ try {
47
+ random = Math.floor(16 * Math.random());
48
+ } catch {}
49
+ return ('x' === character ? random : 3 & random | 8).toString(16);
50
+ });
51
+ };
52
+ __webpack_require__.d(__webpack_exports__, {}, {
53
+ createId: createId
54
+ });
55
+ exports.createId = __webpack_exports__.createId;
56
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
57
+ "createId"
58
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
59
+ Object.defineProperty(exports, '__esModule', {
60
+ value: true
61
+ });
package/dist/id.mjs ADDED
@@ -0,0 +1,23 @@
1
+ let fallbackSequence = 0;
2
+ const createId = ()=>{
3
+ try {
4
+ const crypto = globalThis.crypto;
5
+ if (crypto?.randomUUID) return crypto.randomUUID();
6
+ if (crypto?.getRandomValues) {
7
+ const bytes = crypto.getRandomValues(new Uint8Array(16));
8
+ bytes[6] = (bytes[6] ?? 0) & 0x0f | 0x40;
9
+ bytes[8] = (bytes[8] ?? 0) & 0x3f | 0x80;
10
+ const hex = bytes.reduce((value, byte)=>value + byte.toString(16).padStart(2, '0'), '');
11
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
12
+ }
13
+ } catch {}
14
+ let seed = Date.now() + fallbackSequence++;
15
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (character)=>{
16
+ let random = 15 & seed++;
17
+ try {
18
+ random = Math.floor(16 * Math.random());
19
+ } catch {}
20
+ return ('x' === character ? random : 3 & random | 8).toString(16);
21
+ });
22
+ };
23
+ export { createId };
@@ -0,0 +1,11 @@
1
+ import type { PostHog, PostHogOptions } from './types';
2
+ /** Creates a browser client with first-party analytics delivery loaded lazily by default. */
3
+ export declare const createPostHog: (options: PostHogOptions) => Promise<PostHog>;
4
+ export { version } from './version';
5
+ export { FeatureFlagsExtension, type FeatureFlags } from './flags-token';
6
+ export type { BrowserClient, IdentifyInfo, GroupInfo } from './browser-client';
7
+ export type { AnalyticsConfiguration, AnalyticsOptions, ApiResponse, AutomaticAnalyticsOptions, BrowserFetch, BrowserNavigator, CaptureOptions, CaptureOutcome, CaptureOutcomeStatus, CaptureSummary, CorePostHogOptions, Disposable, Extension, LoadStrategy, NewSessionInfo, NewSessionReason, PostHog, PostHogOptions, RemoteConfig, SendRequestInit, SessionContext, StorageLike, } from './types';
8
+ export type { FlagsOptions, FlagsConfiguration, FlagsCallback, FeatureFlagResult, FeatureFlagsReloadResult, } from './flags-options';
9
+ export type { LogsOptions, LogsConfiguration, CaptureLogOptions } from './logs-options';
10
+ export type { SurveysOptions, SurveysConfiguration, Survey, SurveyCallback, DisplaySurveyOptions, SurveyRenderReason, } from './surveys-options';
11
+ export type { AutocaptureOptions, AutocaptureConfiguration, RageclickOptions } from './autocapture-options';
package/dist/index.js ADDED
@@ -0,0 +1,119 @@
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
+ FeatureFlagsExtension: ()=>external_flags_token_js_namespaceObject.FeatureFlagsExtension,
32
+ createPostHog: ()=>createPostHog,
33
+ version: ()=>external_version_js_namespaceObject.version
34
+ });
35
+ const external_autocapture_options_js_namespaceObject = require("./autocapture-options.js");
36
+ const external_surveys_options_js_namespaceObject = require("./surveys-options.js");
37
+ const external_logs_options_js_namespaceObject = require("./logs-options.js");
38
+ const external_posthog_js_namespaceObject = require("./posthog.js");
39
+ const external_analytics_internal_js_namespaceObject = require("./analytics-internal.js");
40
+ const external_automatic_analytics_js_namespaceObject = require("./automatic-analytics.js");
41
+ const external_version_js_namespaceObject = require("./version.js");
42
+ const external_flags_token_js_namespaceObject = require("./flags-token.js");
43
+ const createPostHog = async (options)=>{
44
+ const extensions = [
45
+ ...options?.extensions ?? []
46
+ ];
47
+ const loadingErrors = [];
48
+ const install = (label, matches, load, prepend = false)=>{
49
+ if (extensions.some(matches)) return;
50
+ const add = (extension)=>{
51
+ if (prepend) extensions.unshift(extension);
52
+ else extensions.push(extension);
53
+ };
54
+ const failed = (error)=>{
55
+ if (error) loadingErrors.push([
56
+ label,
57
+ error
58
+ ]);
59
+ };
60
+ try {
61
+ const extension = load();
62
+ if (extension instanceof Promise) return extension.then(add).catch(failed);
63
+ if (extension) add(extension);
64
+ } catch (error) {
65
+ failed(error);
66
+ }
67
+ };
68
+ install('analytics', external_analytics_internal_js_namespaceObject.isAnalyticsExtension, ()=>{
69
+ let configuration = {
70
+ load: 'lazy'
71
+ };
72
+ try {
73
+ configuration = options?.analytics ?? configuration;
74
+ } catch {}
75
+ return false === configuration ? void 0 : (0, external_automatic_analytics_js_namespaceObject.analytics)(configuration);
76
+ }, true);
77
+ const flagsLoading = install('flags', (extension)=>'featureFlags' === extension.name, ()=>{
78
+ const configuration = options?.flags;
79
+ if (false === configuration) return;
80
+ const snapshot = configuration && JSON.parse(JSON.stringify(configuration));
81
+ return import("./flags.js").then(({ flags })=>flags(snapshot));
82
+ });
83
+ if (flagsLoading) await flagsLoading;
84
+ const logsLoading = install('logs', (extension)=>'logs' === extension.name, ()=>{
85
+ const configuration = options?.logs;
86
+ if (false === configuration) return;
87
+ const snapshot = (0, external_logs_options_js_namespaceObject.snapshotLogsOptions)(configuration);
88
+ return import("./logs.js").then(({ logs })=>logs(snapshot));
89
+ });
90
+ if (logsLoading) await logsLoading;
91
+ const surveysLoading = install('surveys', (extension)=>'surveys' === extension.name, ()=>{
92
+ const configuration = options?.surveys;
93
+ if (false === configuration) return;
94
+ const snapshot = (0, external_surveys_options_js_namespaceObject.snapshotSurveysOptions)(configuration);
95
+ return import("./automatic-surveys.js").then(({ surveys })=>surveys(snapshot));
96
+ });
97
+ if (surveysLoading) await surveysLoading;
98
+ const autocaptureLoading = install('autocapture', (extension)=>'autocapture' === extension.name, ()=>{
99
+ const configuration = options?.autocapture;
100
+ if (false === configuration) return;
101
+ const snapshot = (0, external_autocapture_options_js_namespaceObject.snapshotAutocaptureOptions)(configuration);
102
+ return import("./autocapture.js").then(({ autocapture })=>autocapture(snapshot));
103
+ });
104
+ if (autocaptureLoading) await autocaptureLoading;
105
+ const client = await (0, external_posthog_js_namespaceObject.createPostHogCore)(options, extensions);
106
+ for (const [label, error] of loadingErrors.reverse())client.logger.error(`Automatic ${label} loading failed`, error);
107
+ return client;
108
+ };
109
+ exports.FeatureFlagsExtension = __webpack_exports__.FeatureFlagsExtension;
110
+ exports.createPostHog = __webpack_exports__.createPostHog;
111
+ exports.version = __webpack_exports__.version;
112
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
113
+ "FeatureFlagsExtension",
114
+ "createPostHog",
115
+ "version"
116
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
117
+ Object.defineProperty(exports, '__esModule', {
118
+ value: true
119
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,75 @@
1
+ import { snapshotAutocaptureOptions } from "./autocapture-options.mjs";
2
+ import { snapshotSurveysOptions } from "./surveys-options.mjs";
3
+ import { snapshotLogsOptions } from "./logs-options.mjs";
4
+ import { createPostHogCore } from "./posthog.mjs";
5
+ import { isAnalyticsExtension } from "./analytics-internal.mjs";
6
+ import { analytics } from "./automatic-analytics.mjs";
7
+ const createPostHog = async (options)=>{
8
+ const extensions = [
9
+ ...options?.extensions ?? []
10
+ ];
11
+ const loadingErrors = [];
12
+ const install = (label, matches, load, prepend = false)=>{
13
+ if (extensions.some(matches)) return;
14
+ const add = (extension)=>{
15
+ if (prepend) extensions.unshift(extension);
16
+ else extensions.push(extension);
17
+ };
18
+ const failed = (error)=>{
19
+ if (error) loadingErrors.push([
20
+ label,
21
+ error
22
+ ]);
23
+ };
24
+ try {
25
+ const extension = load();
26
+ if (extension instanceof Promise) return extension.then(add).catch(failed);
27
+ if (extension) add(extension);
28
+ } catch (error) {
29
+ failed(error);
30
+ }
31
+ };
32
+ install('analytics', isAnalyticsExtension, ()=>{
33
+ let configuration = {
34
+ load: 'lazy'
35
+ };
36
+ try {
37
+ configuration = options?.analytics ?? configuration;
38
+ } catch {}
39
+ return false === configuration ? void 0 : analytics(configuration);
40
+ }, true);
41
+ const flagsLoading = install('flags', (extension)=>'featureFlags' === extension.name, ()=>{
42
+ const configuration = options?.flags;
43
+ if (false === configuration) return;
44
+ const snapshot = configuration && JSON.parse(JSON.stringify(configuration));
45
+ return import("./flags.mjs").then(({ flags })=>flags(snapshot));
46
+ });
47
+ if (flagsLoading) await flagsLoading;
48
+ const logsLoading = install('logs', (extension)=>'logs' === extension.name, ()=>{
49
+ const configuration = options?.logs;
50
+ if (false === configuration) return;
51
+ const snapshot = snapshotLogsOptions(configuration);
52
+ return import("./logs.mjs").then(({ logs })=>logs(snapshot));
53
+ });
54
+ if (logsLoading) await logsLoading;
55
+ const surveysLoading = install('surveys', (extension)=>'surveys' === extension.name, ()=>{
56
+ const configuration = options?.surveys;
57
+ if (false === configuration) return;
58
+ const snapshot = snapshotSurveysOptions(configuration);
59
+ return import("./automatic-surveys.mjs").then(({ surveys })=>surveys(snapshot));
60
+ });
61
+ if (surveysLoading) await surveysLoading;
62
+ const autocaptureLoading = install('autocapture', (extension)=>'autocapture' === extension.name, ()=>{
63
+ const configuration = options?.autocapture;
64
+ if (false === configuration) return;
65
+ const snapshot = snapshotAutocaptureOptions(configuration);
66
+ return import("./autocapture.mjs").then(({ autocapture })=>autocapture(snapshot));
67
+ });
68
+ if (autocaptureLoading) await autocaptureLoading;
69
+ const client = await createPostHogCore(options, extensions);
70
+ for (const [label, error] of loadingErrors.reverse())client.logger.error(`Automatic ${label} loading failed`, error);
71
+ return client;
72
+ };
73
+ export { version } from "./version.mjs";
74
+ export { FeatureFlagsExtension } from "./flags-token.mjs";
75
+ export { createPostHog };