@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
package/dist/core.d.ts ADDED
@@ -0,0 +1,7 @@
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>;
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 { AnalyticsOptions, ApiResponse, BrowserFetch, BrowserNavigator, CaptureOptions, CaptureOutcome, CaptureOutcomeStatus, CaptureSummary, CorePostHogOptions, Disposable, Extension, NewSessionInfo, NewSessionReason, PostHog, RemoteConfig, SendRequestInit, SessionContext, StorageLike, } from './types';
package/dist/core.js ADDED
@@ -0,0 +1,49 @@
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_posthog_js_namespaceObject = require("./posthog.js");
36
+ const external_version_js_namespaceObject = require("./version.js");
37
+ const external_flags_token_js_namespaceObject = require("./flags-token.js");
38
+ const createPostHog = async (options)=>(0, external_posthog_js_namespaceObject.createPostHogCore)(options);
39
+ exports.FeatureFlagsExtension = __webpack_exports__.FeatureFlagsExtension;
40
+ exports.createPostHog = __webpack_exports__.createPostHog;
41
+ exports.version = __webpack_exports__.version;
42
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
43
+ "FeatureFlagsExtension",
44
+ "createPostHog",
45
+ "version"
46
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
47
+ Object.defineProperty(exports, '__esModule', {
48
+ value: true
49
+ });
package/dist/core.mjs ADDED
@@ -0,0 +1,5 @@
1
+ import { createPostHogCore } from "./posthog.mjs";
2
+ const createPostHog = async (options)=>createPostHogCore(options);
3
+ export { version } from "./version.mjs";
4
+ export { FeatureFlagsExtension } from "./flags-token.mjs";
5
+ export { createPostHog };
@@ -0,0 +1,41 @@
1
+ export type LaneDropReason = 'overflow' | 'expired' | 'oversized';
2
+ export type QueueEntry<E> = [
3
+ id: number,
4
+ event: E,
5
+ bytes: number,
6
+ admittedAt: number,
7
+ lastAttemptEpoch: number,
8
+ retryAfter: number
9
+ ];
10
+ type BufferChange = 'enqueue' | 'discard' | 'drop' | 'purge' | 'cleared';
11
+ /** Bounded event storage, available before its delivery driver is loaded. */
12
+ export declare class EventBuffer<E> {
13
+ readonly _capacity: number;
14
+ readonly _onDrop: (total: number, count?: number, reason?: LaneDropReason) => void;
15
+ readonly _maxBytes: number;
16
+ readonly _maxAgeMs: number;
17
+ private readonly _clock;
18
+ readonly _queue: QueueEntry<E>[];
19
+ _activeEntries: QueueEntry<E>[] | undefined;
20
+ _disposed: boolean;
21
+ _generation: number;
22
+ _nextId: number;
23
+ _queuedBytes: number;
24
+ _activeBytes: number;
25
+ onChange: ((change: BufferChange) => void) | undefined;
26
+ private _dropped;
27
+ private _lastNow;
28
+ constructor(_capacity: number, _onDrop: (total: number, count?: number, reason?: LaneDropReason) => void, _maxBytes?: number, _maxAgeMs?: number, _clock?: () => number);
29
+ enqueue(event: E, bytes?: number): boolean;
30
+ discardQueued(event: E): boolean;
31
+ hasPending(): boolean;
32
+ purge(): void;
33
+ dispose(): void;
34
+ _now(): number;
35
+ _isExpired(entry: QueueEntry<E>, now: number): boolean;
36
+ _expireQueue(now: number): void;
37
+ _takeQueue(count: number): QueueEntry<E>[];
38
+ _drop(entries: QueueEntry<E>[], reason: LaneDropReason): void;
39
+ _reportDrop(count: number, reason: LaneDropReason): void;
40
+ }
41
+ export {};
@@ -0,0 +1,158 @@
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
+ class EventBuffer {
31
+ constructor(_capacity, _onDrop, _maxBytes = Number.MAX_SAFE_INTEGER, _maxAgeMs = Number.MAX_SAFE_INTEGER, _clock = Date.now){
32
+ this._capacity = _capacity;
33
+ this._onDrop = _onDrop;
34
+ this._maxBytes = _maxBytes;
35
+ this._maxAgeMs = _maxAgeMs;
36
+ this._clock = _clock;
37
+ this._queue = [];
38
+ this._disposed = false;
39
+ this._generation = 0;
40
+ this._nextId = 0;
41
+ this._queuedBytes = 0;
42
+ this._activeBytes = 0;
43
+ this._dropped = 0;
44
+ this._lastNow = 0;
45
+ }
46
+ enqueue(event, bytes = 0) {
47
+ if (this._disposed) return false;
48
+ const now = this._now();
49
+ this._expireQueue(now);
50
+ const eventBytes = Number.isFinite(bytes) ? Math.max(0, Math.floor(bytes)) : this._maxBytes + 1;
51
+ if (eventBytes > this._maxBytes) {
52
+ this._reportDrop(1, 'oversized');
53
+ return false;
54
+ }
55
+ if (this._activeBytes + eventBytes > this._maxBytes) {
56
+ this._reportDrop(1, 'overflow');
57
+ return false;
58
+ }
59
+ const generation = this._generation;
60
+ let remove = 0;
61
+ let queuedBytes = this._queuedBytes;
62
+ while(remove < this._queue.length && (this._queue.length - remove >= this._capacity || this._activeBytes + queuedBytes + eventBytes > this._maxBytes)){
63
+ queuedBytes -= this._queue[remove][2];
64
+ remove++;
65
+ }
66
+ if (remove > 0) {
67
+ const dropped = this._queue.splice(0, remove);
68
+ this._queuedBytes = queuedBytes;
69
+ this._drop(dropped, 'overflow');
70
+ }
71
+ if (generation !== this._generation || this._queue.length >= this._capacity || this._activeBytes + this._queuedBytes + eventBytes > this._maxBytes) {
72
+ this._reportDrop(1, 'overflow');
73
+ return false;
74
+ }
75
+ this._queue.push([
76
+ ++this._nextId,
77
+ event,
78
+ eventBytes,
79
+ now,
80
+ 0,
81
+ 0
82
+ ]);
83
+ this._queuedBytes += eventBytes;
84
+ this.onChange?.('enqueue');
85
+ return true;
86
+ }
87
+ discardQueued(event) {
88
+ for(let index = this._queue.length - 1; index >= 0; index--){
89
+ const entry = this._queue[index];
90
+ if (entry[1] === event) {
91
+ this._queue.splice(index, 1);
92
+ this._queuedBytes -= entry[2];
93
+ this.onChange?.('discard');
94
+ return true;
95
+ }
96
+ }
97
+ return false;
98
+ }
99
+ hasPending() {
100
+ if (this._disposed) return false;
101
+ this._expireQueue(this._now());
102
+ return void 0 !== this._activeEntries || this._queue.length > 0;
103
+ }
104
+ purge() {
105
+ this._generation++;
106
+ this.onChange?.('purge');
107
+ this._activeEntries = void 0;
108
+ this._activeBytes = 0;
109
+ this._queue.length = 0;
110
+ this._queuedBytes = 0;
111
+ this.onChange?.('cleared');
112
+ }
113
+ dispose() {
114
+ this._disposed = true;
115
+ this.purge();
116
+ }
117
+ _now() {
118
+ try {
119
+ const now = this._clock();
120
+ if (Number.isFinite(now)) this._lastNow = Math.max(this._lastNow, now);
121
+ } catch {}
122
+ return this._lastNow;
123
+ }
124
+ _isExpired(entry, now) {
125
+ return now - entry[3] > this._maxAgeMs;
126
+ }
127
+ _expireQueue(now) {
128
+ let count = 0;
129
+ while(count < this._queue.length && this._isExpired(this._queue[count], now))count++;
130
+ if (count > 0) this._drop(this._takeQueue(count), 'expired');
131
+ }
132
+ _takeQueue(count) {
133
+ const entries = this._queue.splice(0, count);
134
+ for (const entry of entries)this._queuedBytes -= entry[2];
135
+ return entries;
136
+ }
137
+ _drop(entries, reason) {
138
+ if (0 === entries.length) return;
139
+ this._reportDrop(entries.length, reason);
140
+ this.onChange?.('drop');
141
+ }
142
+ _reportDrop(count, reason) {
143
+ this._dropped += count;
144
+ try {
145
+ this._onDrop(this._dropped, count, reason);
146
+ } catch {}
147
+ }
148
+ }
149
+ __webpack_require__.d(__webpack_exports__, {
150
+ EventBuffer: ()=>EventBuffer
151
+ });
152
+ exports.EventBuffer = __webpack_exports__.EventBuffer;
153
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
154
+ "EventBuffer"
155
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
156
+ Object.defineProperty(exports, '__esModule', {
157
+ value: true
158
+ });
@@ -0,0 +1,120 @@
1
+ class EventBuffer {
2
+ constructor(_capacity, _onDrop, _maxBytes = Number.MAX_SAFE_INTEGER, _maxAgeMs = Number.MAX_SAFE_INTEGER, _clock = Date.now){
3
+ this._capacity = _capacity;
4
+ this._onDrop = _onDrop;
5
+ this._maxBytes = _maxBytes;
6
+ this._maxAgeMs = _maxAgeMs;
7
+ this._clock = _clock;
8
+ this._queue = [];
9
+ this._disposed = false;
10
+ this._generation = 0;
11
+ this._nextId = 0;
12
+ this._queuedBytes = 0;
13
+ this._activeBytes = 0;
14
+ this._dropped = 0;
15
+ this._lastNow = 0;
16
+ }
17
+ enqueue(event, bytes = 0) {
18
+ if (this._disposed) return false;
19
+ const now = this._now();
20
+ this._expireQueue(now);
21
+ const eventBytes = Number.isFinite(bytes) ? Math.max(0, Math.floor(bytes)) : this._maxBytes + 1;
22
+ if (eventBytes > this._maxBytes) {
23
+ this._reportDrop(1, 'oversized');
24
+ return false;
25
+ }
26
+ if (this._activeBytes + eventBytes > this._maxBytes) {
27
+ this._reportDrop(1, 'overflow');
28
+ return false;
29
+ }
30
+ const generation = this._generation;
31
+ let remove = 0;
32
+ let queuedBytes = this._queuedBytes;
33
+ while(remove < this._queue.length && (this._queue.length - remove >= this._capacity || this._activeBytes + queuedBytes + eventBytes > this._maxBytes)){
34
+ queuedBytes -= this._queue[remove][2];
35
+ remove++;
36
+ }
37
+ if (remove > 0) {
38
+ const dropped = this._queue.splice(0, remove);
39
+ this._queuedBytes = queuedBytes;
40
+ this._drop(dropped, 'overflow');
41
+ }
42
+ if (generation !== this._generation || this._queue.length >= this._capacity || this._activeBytes + this._queuedBytes + eventBytes > this._maxBytes) {
43
+ this._reportDrop(1, 'overflow');
44
+ return false;
45
+ }
46
+ this._queue.push([
47
+ ++this._nextId,
48
+ event,
49
+ eventBytes,
50
+ now,
51
+ 0,
52
+ 0
53
+ ]);
54
+ this._queuedBytes += eventBytes;
55
+ this.onChange?.('enqueue');
56
+ return true;
57
+ }
58
+ discardQueued(event) {
59
+ for(let index = this._queue.length - 1; index >= 0; index--){
60
+ const entry = this._queue[index];
61
+ if (entry[1] === event) {
62
+ this._queue.splice(index, 1);
63
+ this._queuedBytes -= entry[2];
64
+ this.onChange?.('discard');
65
+ return true;
66
+ }
67
+ }
68
+ return false;
69
+ }
70
+ hasPending() {
71
+ if (this._disposed) return false;
72
+ this._expireQueue(this._now());
73
+ return void 0 !== this._activeEntries || this._queue.length > 0;
74
+ }
75
+ purge() {
76
+ this._generation++;
77
+ this.onChange?.('purge');
78
+ this._activeEntries = void 0;
79
+ this._activeBytes = 0;
80
+ this._queue.length = 0;
81
+ this._queuedBytes = 0;
82
+ this.onChange?.('cleared');
83
+ }
84
+ dispose() {
85
+ this._disposed = true;
86
+ this.purge();
87
+ }
88
+ _now() {
89
+ try {
90
+ const now = this._clock();
91
+ if (Number.isFinite(now)) this._lastNow = Math.max(this._lastNow, now);
92
+ } catch {}
93
+ return this._lastNow;
94
+ }
95
+ _isExpired(entry, now) {
96
+ return now - entry[3] > this._maxAgeMs;
97
+ }
98
+ _expireQueue(now) {
99
+ let count = 0;
100
+ while(count < this._queue.length && this._isExpired(this._queue[count], now))count++;
101
+ if (count > 0) this._drop(this._takeQueue(count), 'expired');
102
+ }
103
+ _takeQueue(count) {
104
+ const entries = this._queue.splice(0, count);
105
+ for (const entry of entries)this._queuedBytes -= entry[2];
106
+ return entries;
107
+ }
108
+ _drop(entries, reason) {
109
+ if (0 === entries.length) return;
110
+ this._reportDrop(entries.length, reason);
111
+ this.onChange?.('drop');
112
+ }
113
+ _reportDrop(count, reason) {
114
+ this._dropped += count;
115
+ try {
116
+ this._onDrop(this._dropped, count, reason);
117
+ } catch {}
118
+ }
119
+ }
120
+ export { EventBuffer };
@@ -0,0 +1,16 @@
1
+ import type { Client, Extension } from '@posthog/browser-common';
2
+ export declare class ExtensionRegistry {
3
+ private readonly _records;
4
+ private readonly _extensions;
5
+ 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>;
12
+ flush(reason?: 'flush' | 'shutdown'): Promise<void>;
13
+ dispose(): Promise<void>;
14
+ private _removeRecord;
15
+ private _disposeRecord;
16
+ }
@@ -0,0 +1,128 @@
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
+ class ExtensionRegistry {
31
+ constructor(createClient, logger){
32
+ this._records = new Map();
33
+ this._extensions = new Map();
34
+ this._disposed = false;
35
+ this._createClient = createClient;
36
+ this._logger = logger;
37
+ }
38
+ get(name) {
39
+ return this._extensions.get(name);
40
+ }
41
+ async install(extension) {
42
+ if (this._disposed) throw new Error('The extension registry is disposed');
43
+ const { name } = extension;
44
+ const bindings = [
45
+ [
46
+ name,
47
+ extension
48
+ ],
49
+ ...Object.entries(extension.bindings ?? {})
50
+ ];
51
+ const names = new Set();
52
+ for (const [key] of bindings){
53
+ if (!key || names.has(key) || this._extensions.has(key)) throw new Error(`An extension named "${key}" is already installed or the name is invalid`);
54
+ names.add(key);
55
+ }
56
+ const record = [
57
+ extension,
58
+ false,
59
+ [
60
+ ...names
61
+ ]
62
+ ];
63
+ this._records.set(name, record);
64
+ for (const [key, target] of bindings)this._extensions.set(key, target);
65
+ try {
66
+ await extension.setup(this._createClient(name));
67
+ if (this._disposed || record[1]) throw new Error('The extension registry was disposed during setup');
68
+ } catch (error) {
69
+ if (this._records.get(name) === record) this._removeRecord(record);
70
+ try {
71
+ await this._disposeRecord(record);
72
+ } catch (disposeError) {
73
+ this._logger.error('Extension cleanup failed after setup failed', disposeError);
74
+ }
75
+ throw error;
76
+ }
77
+ }
78
+ async rollback(extension) {
79
+ const record = this._records.get(extension.name);
80
+ if (record?.[0] === extension) {
81
+ this._removeRecord(record);
82
+ await this._disposeRecord(record);
83
+ }
84
+ }
85
+ async flush(reason = 'flush') {
86
+ await Promise.all(Array.from(this._records.values()).map(async ([extension])=>{
87
+ try {
88
+ await extension.flush?.(reason);
89
+ } catch (error) {
90
+ this._logger.error(`Extension "${extension.name}" flush failed`, error);
91
+ }
92
+ }));
93
+ }
94
+ async dispose() {
95
+ if (this._disposed) return;
96
+ this._disposed = true;
97
+ const records = Array.from(this._records.values()).reverse();
98
+ this._records.clear();
99
+ this._extensions.clear();
100
+ await Promise.all(records.map(async (record)=>{
101
+ try {
102
+ await this._disposeRecord(record);
103
+ } catch (error) {
104
+ this._logger.error(`Extension "${record[0].name}" cleanup failed`, error);
105
+ }
106
+ }));
107
+ }
108
+ _removeRecord(record) {
109
+ this._records.delete(record[0].name);
110
+ for (const name of record[2])this._extensions.delete(name);
111
+ }
112
+ async _disposeRecord(record) {
113
+ if (!record[1]) {
114
+ record[1] = true;
115
+ await record[0].dispose?.();
116
+ }
117
+ }
118
+ }
119
+ __webpack_require__.d(__webpack_exports__, {
120
+ ExtensionRegistry: ()=>ExtensionRegistry
121
+ });
122
+ exports.ExtensionRegistry = __webpack_exports__.ExtensionRegistry;
123
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
124
+ "ExtensionRegistry"
125
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
126
+ Object.defineProperty(exports, '__esModule', {
127
+ value: true
128
+ });
@@ -0,0 +1,90 @@
1
+ class ExtensionRegistry {
2
+ constructor(createClient, logger){
3
+ this._records = new Map();
4
+ this._extensions = new Map();
5
+ this._disposed = false;
6
+ this._createClient = createClient;
7
+ this._logger = logger;
8
+ }
9
+ get(name) {
10
+ return this._extensions.get(name);
11
+ }
12
+ async install(extension) {
13
+ if (this._disposed) throw new Error('The extension registry is disposed');
14
+ const { name } = extension;
15
+ const bindings = [
16
+ [
17
+ name,
18
+ extension
19
+ ],
20
+ ...Object.entries(extension.bindings ?? {})
21
+ ];
22
+ const names = new Set();
23
+ for (const [key] of bindings){
24
+ if (!key || names.has(key) || this._extensions.has(key)) throw new Error(`An extension named "${key}" is already installed or the name is invalid`);
25
+ names.add(key);
26
+ }
27
+ const record = [
28
+ extension,
29
+ false,
30
+ [
31
+ ...names
32
+ ]
33
+ ];
34
+ this._records.set(name, record);
35
+ for (const [key, target] of bindings)this._extensions.set(key, target);
36
+ try {
37
+ await extension.setup(this._createClient(name));
38
+ if (this._disposed || record[1]) throw new Error('The extension registry was disposed during setup');
39
+ } catch (error) {
40
+ if (this._records.get(name) === record) this._removeRecord(record);
41
+ try {
42
+ await this._disposeRecord(record);
43
+ } catch (disposeError) {
44
+ this._logger.error('Extension cleanup failed after setup failed', disposeError);
45
+ }
46
+ throw error;
47
+ }
48
+ }
49
+ async rollback(extension) {
50
+ const record = this._records.get(extension.name);
51
+ if (record?.[0] === extension) {
52
+ this._removeRecord(record);
53
+ await this._disposeRecord(record);
54
+ }
55
+ }
56
+ async flush(reason = 'flush') {
57
+ await Promise.all(Array.from(this._records.values()).map(async ([extension])=>{
58
+ try {
59
+ await extension.flush?.(reason);
60
+ } catch (error) {
61
+ this._logger.error(`Extension "${extension.name}" flush failed`, error);
62
+ }
63
+ }));
64
+ }
65
+ async dispose() {
66
+ if (this._disposed) return;
67
+ this._disposed = true;
68
+ const records = Array.from(this._records.values()).reverse();
69
+ this._records.clear();
70
+ this._extensions.clear();
71
+ await Promise.all(records.map(async (record)=>{
72
+ try {
73
+ await this._disposeRecord(record);
74
+ } catch (error) {
75
+ this._logger.error(`Extension "${record[0].name}" cleanup failed`, error);
76
+ }
77
+ }));
78
+ }
79
+ _removeRecord(record) {
80
+ this._records.delete(record[0].name);
81
+ for (const name of record[2])this._extensions.delete(name);
82
+ }
83
+ async _disposeRecord(record) {
84
+ if (!record[1]) {
85
+ record[1] = true;
86
+ await record[0].dispose?.();
87
+ }
88
+ }
89
+ }
90
+ export { ExtensionRegistry };
@@ -0,0 +1,8 @@
1
+ import type { FeatureFlags } from './flags-token';
2
+ /** SDK-specific flags configuration and persisted survey targeting context. */
3
+ export interface FlagsExtension extends FeatureFlags {
4
+ getSurveyContext(): {
5
+ remoteEvaluation: boolean;
6
+ personProperties: Record<string, unknown> | undefined;
7
+ };
8
+ }
@@ -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,22 @@
1
+ import type { FeatureFlagResult, JsonType } from '@posthog/types';
2
+ export interface FlagsOptions {
3
+ /** Evaluate flags remotely. Defaults to true; false retains bootstrap and injected values. */
4
+ featureFlagEvaluation?: boolean;
5
+ bootstrap?: {
6
+ featureFlags?: Readonly<Record<string, boolean | string>>;
7
+ featureFlagPayloads?: Readonly<Record<string, JsonType>>;
8
+ };
9
+ evaluationContexts?: readonly string[];
10
+ flagKeys?: readonly string[];
11
+ /** Request timeout in milliseconds. Defaults to 3000. */
12
+ requestTimeoutMs?: number;
13
+ cacheTtlMs?: number;
14
+ /** Refresh interval in milliseconds. Defaults to five minutes with idle backoff; 0 disables it. */
15
+ refreshIntervalMs?: number;
16
+ deduplicateCallsPerSession?: boolean;
17
+ onlyEvaluateSurveyFeatureFlags?: boolean;
18
+ }
19
+ export type FlagsConfiguration = false | FlagsOptions;
20
+ export type FlagsCallback = (flags: FeatureFlagResult[], errorsLoading: boolean) => void;
21
+ export type { FeatureFlagResult, JsonType };
22
+ export type { FeatureFlagsReloadResult } from '@posthog/browser-common/feature-flags';