@posthog/browser 0.0.0 → 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.
- package/ARCHITECTURE.md +559 -0
- package/LICENSE +417 -0
- package/README.md +286 -28
- package/dist/analytics-buffer.d.ts +4 -0
- package/dist/analytics-buffer.js +200 -0
- package/dist/analytics-buffer.mjs +162 -0
- package/dist/analytics-delivery.d.ts +3 -0
- package/dist/analytics-delivery.js +231 -0
- package/dist/analytics-delivery.mjs +193 -0
- package/dist/analytics-internal.d.ts +64 -0
- package/dist/analytics-internal.js +52 -0
- package/dist/analytics-internal.mjs +5 -0
- package/dist/analytics-options.d.ts +14 -0
- package/dist/analytics-options.js +18 -0
- package/dist/analytics-options.mjs +1 -0
- package/dist/analytics.d.ts +5 -0
- package/dist/analytics.js +42 -0
- package/dist/analytics.mjs +4 -0
- package/dist/autocapture-options.d.ts +32 -0
- package/dist/autocapture-options.js +49 -0
- package/dist/autocapture-options.mjs +11 -0
- package/dist/autocapture.d.ts +5 -0
- package/dist/autocapture.js +108 -0
- package/dist/autocapture.mjs +70 -0
- package/dist/automatic-analytics.d.ts +3 -0
- package/dist/automatic-analytics.js +44 -0
- package/dist/automatic-analytics.mjs +6 -0
- package/dist/automatic-surveys.d.ts +2 -0
- package/dist/automatic-surveys.js +41 -0
- package/dist/automatic-surveys.mjs +3 -0
- package/dist/bot-filter.d.ts +2 -0
- package/dist/bot-filter.js +87 -0
- package/dist/bot-filter.mjs +49 -0
- package/dist/browser-client.d.ts +30 -0
- package/dist/browser-client.js +18 -0
- package/dist/browser-client.mjs +1 -0
- package/dist/capture-summary.d.ts +3 -0
- package/dist/capture-summary.js +63 -0
- package/dist/capture-summary.mjs +22 -0
- package/dist/capture-v1.d.ts +105 -0
- package/dist/capture-v1.js +781 -0
- package/dist/capture-v1.mjs +722 -0
- package/dist/core.d.ts +7 -0
- package/dist/core.js +49 -0
- package/dist/core.mjs +5 -0
- package/dist/event-buffer.d.ts +41 -0
- package/dist/event-buffer.js +158 -0
- package/dist/event-buffer.mjs +120 -0
- package/dist/extensions/registry.d.ts +16 -0
- package/dist/extensions/registry.js +128 -0
- package/dist/extensions/registry.mjs +90 -0
- package/dist/flags-internal.d.ts +8 -0
- package/dist/flags-internal.js +18 -0
- package/dist/flags-internal.mjs +1 -0
- package/dist/flags-options.d.ts +22 -0
- package/dist/flags-options.js +18 -0
- package/dist/flags-options.mjs +1 -0
- package/dist/flags-token.d.ts +15 -0
- package/dist/flags-token.js +40 -0
- package/dist/flags-token.mjs +2 -0
- package/dist/flags.d.ts +6 -0
- package/dist/flags.js +163 -0
- package/dist/flags.mjs +122 -0
- package/dist/id.d.ts +1 -0
- package/dist/id.js +61 -0
- package/dist/id.mjs +23 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +119 -0
- package/dist/index.mjs +75 -0
- package/dist/lane.d.ts +57 -0
- package/dist/lane.js +363 -0
- package/dist/lane.mjs +325 -0
- package/dist/logger.d.ts +4 -0
- package/dist/logger.js +57 -0
- package/dist/logger.mjs +19 -0
- package/dist/logs-internal.d.ts +7 -0
- package/dist/logs-internal.js +18 -0
- package/dist/logs-internal.mjs +1 -0
- package/dist/logs-options.d.ts +11 -0
- package/dist/logs-options.js +57 -0
- package/dist/logs-options.mjs +19 -0
- package/dist/logs.d.ts +6 -0
- package/dist/logs.js +140 -0
- package/dist/logs.mjs +102 -0
- package/dist/named-error.d.ts +7 -0
- package/dist/named-error.js +49 -0
- package/dist/named-error.mjs +11 -0
- package/dist/posthog.d.ts +3 -0
- package/dist/posthog.js +823 -0
- package/dist/posthog.mjs +785 -0
- package/dist/rate-limiter.d.ts +19 -0
- package/dist/rate-limiter.js +89 -0
- package/dist/rate-limiter.mjs +51 -0
- package/dist/remote-config.d.ts +3 -0
- package/dist/remote-config.js +47 -0
- package/dist/remote-config.mjs +9 -0
- package/dist/request.d.ts +14 -0
- package/dist/request.js +130 -0
- package/dist/request.mjs +89 -0
- package/dist/state.d.ts +82 -0
- package/dist/state.js +625 -0
- package/dist/state.mjs +581 -0
- package/dist/surveys-extension.d.ts +9 -0
- package/dist/surveys-extension.js +272 -0
- package/dist/surveys-extension.mjs +234 -0
- package/dist/surveys-internal.d.ts +12 -0
- package/dist/surveys-internal.js +18 -0
- package/dist/surveys-internal.mjs +1 -0
- package/dist/surveys-options.d.ts +18 -0
- package/dist/surveys-options.js +42 -0
- package/dist/surveys-options.mjs +4 -0
- package/dist/surveys.d.ts +7 -0
- package/dist/surveys.js +48 -0
- package/dist/surveys.mjs +7 -0
- package/dist/types.d.ts +114 -0
- package/dist/types.js +18 -0
- package/dist/types.mjs +1 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +40 -0
- package/dist/version.mjs +2 -0
- package/package.json +89 -8
package/dist/lane.mjs
ADDED
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
class Lane {
|
|
2
|
+
constructor(_buffer, _onError = ()=>{}, _onAvailable = ()=>{}){
|
|
3
|
+
this._buffer = _buffer;
|
|
4
|
+
this._onError = _onError;
|
|
5
|
+
this._onAvailable = _onAvailable;
|
|
6
|
+
this._flushWaiters = [];
|
|
7
|
+
this._retryBlocked = false;
|
|
8
|
+
this._settledId = 0;
|
|
9
|
+
this._driveEpoch = 0;
|
|
10
|
+
this._activeEpoch = 0;
|
|
11
|
+
_buffer.onChange = (change)=>{
|
|
12
|
+
if ('enqueue' === change) {
|
|
13
|
+
if (this._retryBlocked && _buffer._queue.length >= this._readFlushAt(this._delivery)) this._retryBlocked = false;
|
|
14
|
+
this._schedule();
|
|
15
|
+
} else if ('purge' === change) {
|
|
16
|
+
this._retryBlocked = false;
|
|
17
|
+
this._forceTarget = void 0;
|
|
18
|
+
this._clearTimer();
|
|
19
|
+
this._cancelActive();
|
|
20
|
+
} else {
|
|
21
|
+
this._updateSettled();
|
|
22
|
+
if ('discard' === change && 0 === _buffer._queue.length) this._clearTimer();
|
|
23
|
+
if ('cleared' === change) this._resolveFlushWaiters(true);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
attach(delivery) {
|
|
28
|
+
if (this._buffer._disposed) throw new Error('The lane is disposed');
|
|
29
|
+
if (this._delivery) throw new Error('A delivery policy is already installed');
|
|
30
|
+
this._delivery = delivery;
|
|
31
|
+
this._retryBlocked = false;
|
|
32
|
+
this._buffer._expireQueue(this._buffer._now());
|
|
33
|
+
this._schedule();
|
|
34
|
+
}
|
|
35
|
+
flush() {
|
|
36
|
+
this._buffer._expireQueue(this._buffer._now());
|
|
37
|
+
const attached = this._delivery;
|
|
38
|
+
if (!attached || !this._buffer._activeEntries && 0 === this._buffer._queue.length || !this._canDeliver(attached)) return Promise.resolve();
|
|
39
|
+
const target = this._buffer._nextId;
|
|
40
|
+
this._retryBlocked = false;
|
|
41
|
+
this._clearTimer();
|
|
42
|
+
this._forceTarget = Math.max(this._forceTarget ?? 0, target);
|
|
43
|
+
const epoch = this._drain ? this._activeEpoch : this._beginDrive(true);
|
|
44
|
+
if (!epoch) return Promise.resolve();
|
|
45
|
+
return new Promise((resolve)=>{
|
|
46
|
+
this._flushWaiters.push([
|
|
47
|
+
target,
|
|
48
|
+
epoch,
|
|
49
|
+
resolve
|
|
50
|
+
]);
|
|
51
|
+
this._resolveFlushWaiters(false);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
pause() {
|
|
55
|
+
this._clearTimer();
|
|
56
|
+
}
|
|
57
|
+
retryNow() {
|
|
58
|
+
if (this._buffer._disposed || 0 === this._buffer._queue.length) return;
|
|
59
|
+
this._retryBlocked = false;
|
|
60
|
+
this._clearTimer();
|
|
61
|
+
if (!this._drain) this._beginDrive(true);
|
|
62
|
+
}
|
|
63
|
+
teardown(maxBytes) {
|
|
64
|
+
this._buffer._expireQueue(this._buffer._now());
|
|
65
|
+
const attached = this._delivery;
|
|
66
|
+
if (this._buffer._disposed || !attached || !this._canDeliver(attached)) return;
|
|
67
|
+
let teardown;
|
|
68
|
+
try {
|
|
69
|
+
teardown = attached.teardown;
|
|
70
|
+
} catch (error) {
|
|
71
|
+
this._reportError(error);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (!teardown) return;
|
|
75
|
+
const entries = [
|
|
76
|
+
...this._buffer._activeEntries ?? [],
|
|
77
|
+
...this._buffer._queue
|
|
78
|
+
];
|
|
79
|
+
if (0 === entries.length) return;
|
|
80
|
+
try {
|
|
81
|
+
teardown(entries.map((entry)=>entry[1]), Math.max(0, Math.floor(Number.isFinite(maxBytes) ? maxBytes : 0)));
|
|
82
|
+
} catch (error) {
|
|
83
|
+
this._reportError(error);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async dispose() {
|
|
87
|
+
if (this._buffer._disposed) return;
|
|
88
|
+
this._delivery = void 0;
|
|
89
|
+
this._buffer.dispose();
|
|
90
|
+
await this._drain;
|
|
91
|
+
}
|
|
92
|
+
_cancelActive() {
|
|
93
|
+
try {
|
|
94
|
+
this._abort?.abort();
|
|
95
|
+
} catch {}
|
|
96
|
+
}
|
|
97
|
+
_clearTimer() {
|
|
98
|
+
const timer = this._timer;
|
|
99
|
+
this._timer = void 0;
|
|
100
|
+
if (void 0 !== timer) try {
|
|
101
|
+
globalThis.clearTimeout(timer);
|
|
102
|
+
} catch {}
|
|
103
|
+
}
|
|
104
|
+
_trimQueue() {
|
|
105
|
+
let remove = 0;
|
|
106
|
+
let bytes = this._buffer._queuedBytes;
|
|
107
|
+
while(remove < this._buffer._queue.length && (this._buffer._queue.length - remove > this._buffer._capacity || bytes > this._buffer._maxBytes)){
|
|
108
|
+
bytes -= this._buffer._queue[remove][2];
|
|
109
|
+
remove++;
|
|
110
|
+
}
|
|
111
|
+
if (remove > 0) {
|
|
112
|
+
const entries = this._buffer._queue.splice(0, remove);
|
|
113
|
+
this._buffer._queuedBytes = bytes;
|
|
114
|
+
this._buffer._drop(entries, 'overflow');
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
_updateSettled() {
|
|
118
|
+
const activeId = this._buffer._activeEntries?.[0]?.[0];
|
|
119
|
+
const queuedId = this._buffer._queue[0]?.[0];
|
|
120
|
+
const firstPending = void 0 === activeId ? queuedId : void 0 === queuedId ? activeId : Math.min(activeId, queuedId);
|
|
121
|
+
this._settledId = void 0 === firstPending ? this._buffer._nextId : firstPending - 1;
|
|
122
|
+
if (void 0 !== this._forceTarget && this._settledId >= this._forceTarget) this._forceTarget = void 0;
|
|
123
|
+
if (!this._drain) this._resolveFlushWaiters(false);
|
|
124
|
+
}
|
|
125
|
+
_reportError(error) {
|
|
126
|
+
try {
|
|
127
|
+
this._onError(error);
|
|
128
|
+
} catch {}
|
|
129
|
+
}
|
|
130
|
+
_reportAvailable() {
|
|
131
|
+
try {
|
|
132
|
+
this._onAvailable();
|
|
133
|
+
} catch (error) {
|
|
134
|
+
this._reportError(error);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
_resolveFlushWaiters(force) {
|
|
138
|
+
for(let index = this._flushWaiters.length - 1; index >= 0; index--){
|
|
139
|
+
const [target, epoch, resolve] = this._flushWaiters[index];
|
|
140
|
+
let complete = force;
|
|
141
|
+
if (!complete) {
|
|
142
|
+
const active = this._buffer._activeEntries?.[0];
|
|
143
|
+
if (active && active[0] <= target) complete = false;
|
|
144
|
+
else {
|
|
145
|
+
const queued = this._buffer._queue[0];
|
|
146
|
+
complete = !queued || queued[0] > target || queued[4] >= epoch;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (complete) {
|
|
150
|
+
this._flushWaiters.splice(index, 1);
|
|
151
|
+
resolve();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
_readNumber(get, fallback, minimum) {
|
|
156
|
+
try {
|
|
157
|
+
const value = get();
|
|
158
|
+
return Math.max(minimum, Math.floor(Number.isFinite(value) ? value : fallback));
|
|
159
|
+
} catch (error) {
|
|
160
|
+
this._reportError(error);
|
|
161
|
+
return fallback;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
_readFlushAt(attached) {
|
|
165
|
+
return attached ? this._readNumber(()=>attached.flushAt, 1, 1) : 1;
|
|
166
|
+
}
|
|
167
|
+
_readFlushInterval(attached) {
|
|
168
|
+
return this._readNumber(()=>attached.flushInterval, 0, 0);
|
|
169
|
+
}
|
|
170
|
+
_readBatchSize(attached) {
|
|
171
|
+
try {
|
|
172
|
+
const value = attached.batchSize;
|
|
173
|
+
return void 0 === value ? this._buffer._queue.length : Math.max(1, Math.floor(Number.isFinite(value) ? value : 1));
|
|
174
|
+
} catch (error) {
|
|
175
|
+
this._reportError(error);
|
|
176
|
+
return 1;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
_canDeliver(attached) {
|
|
180
|
+
try {
|
|
181
|
+
return attached.canDeliver?.() ?? true;
|
|
182
|
+
} catch (error) {
|
|
183
|
+
this._reportError(error);
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
_armTimer(attached) {
|
|
188
|
+
if (void 0 !== this._timer || this._buffer._disposed || 0 === this._buffer._queue.length || !this._canDeliver(attached)) return;
|
|
189
|
+
const interval = this._readFlushInterval(attached);
|
|
190
|
+
if (interval <= 0) return;
|
|
191
|
+
const head = this._buffer._queue[0];
|
|
192
|
+
const dueAt = head[5] || head[3] + interval;
|
|
193
|
+
const delay = Math.max(0, dueAt - this._buffer._now());
|
|
194
|
+
const generation = this._buffer._generation;
|
|
195
|
+
try {
|
|
196
|
+
this._timer = globalThis.setTimeout(()=>{
|
|
197
|
+
this._timer = void 0;
|
|
198
|
+
if (!this._buffer._disposed && this._delivery === attached && this._buffer._generation === generation && this._canDeliver(attached)) {
|
|
199
|
+
this._retryBlocked = false;
|
|
200
|
+
this._beginDrive(true);
|
|
201
|
+
}
|
|
202
|
+
}, delay);
|
|
203
|
+
} catch (error) {
|
|
204
|
+
this._reportError(error);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
_schedule() {
|
|
208
|
+
this._buffer._expireQueue(this._buffer._now());
|
|
209
|
+
const attached = this._delivery;
|
|
210
|
+
if (this._buffer._disposed || this._drain || !attached || 0 === this._buffer._queue.length) {
|
|
211
|
+
if (0 === this._buffer._queue.length) this._clearTimer();
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
if (!this._canDeliver(attached)) return void this._clearTimer();
|
|
215
|
+
const forced = void 0 !== this._forceTarget && this._buffer._queue[0][0] <= this._forceTarget;
|
|
216
|
+
if (forced || !this._retryBlocked && this._buffer._queue.length >= this._readFlushAt(attached)) {
|
|
217
|
+
this._clearTimer();
|
|
218
|
+
this._beginDrive(false);
|
|
219
|
+
} else this._armTimer(attached);
|
|
220
|
+
}
|
|
221
|
+
_beginDrive(allowOne) {
|
|
222
|
+
const attached = this._delivery;
|
|
223
|
+
if (this._buffer._disposed || this._drain || !attached || 0 === this._buffer._queue.length || !this._canDeliver(attached)) return 0;
|
|
224
|
+
const epoch = ++this._driveEpoch;
|
|
225
|
+
const generation = this._buffer._generation;
|
|
226
|
+
let controller;
|
|
227
|
+
try {
|
|
228
|
+
controller = new AbortController();
|
|
229
|
+
} catch {}
|
|
230
|
+
this._abort = controller;
|
|
231
|
+
this._activeEpoch = epoch;
|
|
232
|
+
const canContinue = ()=>!this._buffer._disposed && this._delivery === attached && this._buffer._generation === generation && !(controller?.signal.aborted ?? false);
|
|
233
|
+
this._drain = Promise.resolve().then(async ()=>{
|
|
234
|
+
let first = true;
|
|
235
|
+
while(canContinue() && this._canDeliver(attached)){
|
|
236
|
+
this._buffer._expireQueue(this._buffer._now());
|
|
237
|
+
const head = this._buffer._queue[0];
|
|
238
|
+
if (!head || head[4] >= epoch) break;
|
|
239
|
+
const forced = void 0 !== this._forceTarget && head[0] <= this._forceTarget;
|
|
240
|
+
const threshold = !this._retryBlocked && this._buffer._queue.length >= this._readFlushAt(attached);
|
|
241
|
+
if (!forced && !threshold && !(first && allowOne)) break;
|
|
242
|
+
first = false;
|
|
243
|
+
let batchSize = this._readBatchSize(attached);
|
|
244
|
+
if (forced && void 0 !== this._forceTarget) {
|
|
245
|
+
let throughTarget = 0;
|
|
246
|
+
while(throughTarget < this._buffer._queue.length && this._buffer._queue[throughTarget][0] <= this._forceTarget)throughTarget++;
|
|
247
|
+
batchSize = Math.min(batchSize, Math.max(throughTarget, 1));
|
|
248
|
+
}
|
|
249
|
+
const entries = this._buffer._takeQueue(batchSize);
|
|
250
|
+
if (0 === entries.length) break;
|
|
251
|
+
this._buffer._activeEntries = entries;
|
|
252
|
+
this._buffer._activeBytes = entries.reduce((total, entry)=>total + entry[2], 0);
|
|
253
|
+
let result;
|
|
254
|
+
let deliveryFailed = false;
|
|
255
|
+
try {
|
|
256
|
+
result = await attached.deliver(entries.map((entry)=>entry[1]), {
|
|
257
|
+
signal: controller?.signal,
|
|
258
|
+
canContinue
|
|
259
|
+
});
|
|
260
|
+
} catch (error) {
|
|
261
|
+
deliveryFailed = true;
|
|
262
|
+
result = {
|
|
263
|
+
retry: entries.map((entry)=>entry[1])
|
|
264
|
+
};
|
|
265
|
+
this._reportError(error);
|
|
266
|
+
}
|
|
267
|
+
let retryEntries = [];
|
|
268
|
+
try {
|
|
269
|
+
const retry = result?.retry;
|
|
270
|
+
if (Array.isArray(retry)) {
|
|
271
|
+
const selected = [];
|
|
272
|
+
const length = Math.min(retry.length, entries.length);
|
|
273
|
+
for(let index = 0; index < length; index++){
|
|
274
|
+
const retryEvent = retry[index];
|
|
275
|
+
const entry = entries.find((candidate)=>candidate[1] === retryEvent && !selected.includes(candidate));
|
|
276
|
+
if (entry) selected.push(entry);
|
|
277
|
+
}
|
|
278
|
+
retryEntries = entries.filter((entry)=>selected.includes(entry));
|
|
279
|
+
} else if (deliveryFailed) retryEntries = entries;
|
|
280
|
+
} catch (error) {
|
|
281
|
+
retryEntries = entries;
|
|
282
|
+
this._reportError(error);
|
|
283
|
+
}
|
|
284
|
+
this._buffer._activeEntries = void 0;
|
|
285
|
+
this._buffer._activeBytes = 0;
|
|
286
|
+
if (retryEntries.length > 0 && !this._buffer._disposed && canContinue()) {
|
|
287
|
+
const now = this._buffer._now();
|
|
288
|
+
const expired = [];
|
|
289
|
+
const retained = [];
|
|
290
|
+
const retryAfter = now + this._readFlushInterval(attached);
|
|
291
|
+
for (const entry of retryEntries){
|
|
292
|
+
entry[4] = epoch;
|
|
293
|
+
entry[5] = retryAfter;
|
|
294
|
+
(this._buffer._isExpired(entry, now) ? expired : retained).push(entry);
|
|
295
|
+
}
|
|
296
|
+
const completionGeneration = this._buffer._generation;
|
|
297
|
+
this._buffer._queue.unshift(...retained);
|
|
298
|
+
this._buffer._queuedBytes += retained.reduce((total, entry)=>total + entry[2], 0);
|
|
299
|
+
if (expired.length > 0) this._buffer._reportDrop(expired.length, 'expired');
|
|
300
|
+
if (completionGeneration === this._buffer._generation) {
|
|
301
|
+
this._trimQueue();
|
|
302
|
+
this._retryBlocked = true;
|
|
303
|
+
this._forceTarget = void 0;
|
|
304
|
+
this._updateSettled();
|
|
305
|
+
}
|
|
306
|
+
} else this._updateSettled();
|
|
307
|
+
this._reportAvailable();
|
|
308
|
+
if (retryEntries.length > 0) break;
|
|
309
|
+
this._resolveFlushWaiters(false);
|
|
310
|
+
}
|
|
311
|
+
}).finally(()=>{
|
|
312
|
+
if (this._abort === controller) this._abort = void 0;
|
|
313
|
+
this._activeEpoch = 0;
|
|
314
|
+
this._drain = void 0;
|
|
315
|
+
this._resolveFlushWaiters(false);
|
|
316
|
+
if (!this._delivery) {
|
|
317
|
+
this._forceTarget = void 0;
|
|
318
|
+
this._resolveFlushWaiters(true);
|
|
319
|
+
}
|
|
320
|
+
this._schedule();
|
|
321
|
+
});
|
|
322
|
+
return epoch;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
export { Lane };
|
package/dist/logger.d.ts
ADDED
package/dist/logger.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
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
|
+
createLogger: ()=>createLogger
|
|
32
|
+
});
|
|
33
|
+
const console_original_namespaceObject = require("@posthog/browser-common/utils/console-original");
|
|
34
|
+
const createLogger = (prefix, enabled)=>{
|
|
35
|
+
const write = (level, args)=>{
|
|
36
|
+
if (!enabled) return;
|
|
37
|
+
try {
|
|
38
|
+
const console = globalThis.console;
|
|
39
|
+
(0, console_original_namespaceObject.originalConsoleMethod)(console?.[level])?.call(console, prefix, ...args);
|
|
40
|
+
} catch {}
|
|
41
|
+
};
|
|
42
|
+
return {
|
|
43
|
+
debug: (...args)=>write('debug', args),
|
|
44
|
+
info: (...args)=>write('log', args),
|
|
45
|
+
warn: (...args)=>write('warn', args),
|
|
46
|
+
error: (...args)=>write('error', args),
|
|
47
|
+
critical: (...args)=>write('error', args),
|
|
48
|
+
createLogger: (childPrefix)=>createLogger(`${prefix} ${childPrefix}`, enabled)
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
exports.createLogger = __webpack_exports__.createLogger;
|
|
52
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
53
|
+
"createLogger"
|
|
54
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
55
|
+
Object.defineProperty(exports, '__esModule', {
|
|
56
|
+
value: true
|
|
57
|
+
});
|
package/dist/logger.mjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { originalConsoleMethod } from "@posthog/browser-common/utils/console-original";
|
|
2
|
+
const createLogger = (prefix, enabled)=>{
|
|
3
|
+
const write = (level, args)=>{
|
|
4
|
+
if (!enabled) return;
|
|
5
|
+
try {
|
|
6
|
+
const console = globalThis.console;
|
|
7
|
+
originalConsoleMethod(console?.[level])?.call(console, prefix, ...args);
|
|
8
|
+
} catch {}
|
|
9
|
+
};
|
|
10
|
+
return {
|
|
11
|
+
debug: (...args)=>write('debug', args),
|
|
12
|
+
info: (...args)=>write('log', args),
|
|
13
|
+
warn: (...args)=>write('warn', args),
|
|
14
|
+
error: (...args)=>write('error', args),
|
|
15
|
+
critical: (...args)=>write('error', args),
|
|
16
|
+
createLogger: (childPrefix)=>createLogger(`${prefix} ${childPrefix}`, enabled)
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export { createLogger };
|
|
@@ -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,11 @@
|
|
|
1
|
+
import type { BrowserLogsConfig } from '@posthog/browser-common/logs-config';
|
|
2
|
+
import type { UrlCaptureOptions } from '@posthog/browser-common/utils/sanitize-url';
|
|
3
|
+
export type { UrlCaptureOptions } from '@posthog/browser-common/utils/sanitize-url';
|
|
4
|
+
export interface LogsOptions extends BrowserLogsConfig {
|
|
5
|
+
/** URL parts included in log context. Defaults to path only, without query parameters or fragments. */
|
|
6
|
+
urlCapture?: UrlCaptureOptions;
|
|
7
|
+
}
|
|
8
|
+
export type LogsConfiguration = false | LogsOptions;
|
|
9
|
+
export type { CaptureLogOptions } from '@posthog/types';
|
|
10
|
+
/** Snapshot mutable configuration while retaining callable beforeSend hooks. */
|
|
11
|
+
export declare const snapshotLogsOptions: (options?: LogsOptions) => LogsOptions;
|
|
@@ -0,0 +1,57 @@
|
|
|
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 snapshotLogsOptions = (options = {})=>({
|
|
31
|
+
...options,
|
|
32
|
+
...options.urlCapture ? {
|
|
33
|
+
urlCapture: {
|
|
34
|
+
...options.urlCapture
|
|
35
|
+
}
|
|
36
|
+
} : {},
|
|
37
|
+
...options.resourceAttributes ? {
|
|
38
|
+
resourceAttributes: {
|
|
39
|
+
...options.resourceAttributes
|
|
40
|
+
}
|
|
41
|
+
} : {},
|
|
42
|
+
...Array.isArray(options.beforeSend) ? {
|
|
43
|
+
beforeSend: [
|
|
44
|
+
...options.beforeSend
|
|
45
|
+
]
|
|
46
|
+
} : {}
|
|
47
|
+
});
|
|
48
|
+
__webpack_require__.d(__webpack_exports__, {}, {
|
|
49
|
+
snapshotLogsOptions: snapshotLogsOptions
|
|
50
|
+
});
|
|
51
|
+
exports.snapshotLogsOptions = __webpack_exports__.snapshotLogsOptions;
|
|
52
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
53
|
+
"snapshotLogsOptions"
|
|
54
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
55
|
+
Object.defineProperty(exports, '__esModule', {
|
|
56
|
+
value: true
|
|
57
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const snapshotLogsOptions = (options = {})=>({
|
|
2
|
+
...options,
|
|
3
|
+
...options.urlCapture ? {
|
|
4
|
+
urlCapture: {
|
|
5
|
+
...options.urlCapture
|
|
6
|
+
}
|
|
7
|
+
} : {},
|
|
8
|
+
...options.resourceAttributes ? {
|
|
9
|
+
resourceAttributes: {
|
|
10
|
+
...options.resourceAttributes
|
|
11
|
+
}
|
|
12
|
+
} : {},
|
|
13
|
+
...Array.isArray(options.beforeSend) ? {
|
|
14
|
+
beforeSend: [
|
|
15
|
+
...options.beforeSend
|
|
16
|
+
]
|
|
17
|
+
} : {}
|
|
18
|
+
});
|
|
19
|
+
export { snapshotLogsOptions };
|
package/dist/logs.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { LogsExtension } from './logs-internal';
|
|
2
|
+
import { type LogsOptions } from './logs-options';
|
|
3
|
+
export type { LogsOptions, CaptureLogOptions, UrlCaptureOptions } from './logs-options';
|
|
4
|
+
export type { LogsExtension } from './logs-internal';
|
|
5
|
+
/** Include logs and console capture statically instead of loading the product at initialization. */
|
|
6
|
+
export declare const logs: (options?: LogsOptions) => LogsExtension;
|
package/dist/logs.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
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
|
+
logs: ()=>logs
|
|
32
|
+
});
|
|
33
|
+
const sanitize_url_namespaceObject = require("@posthog/browser-common/utils/sanitize-url");
|
|
34
|
+
const logs_namespaceObject = require("@posthog/browser-common/logs");
|
|
35
|
+
const console_logs_namespaceObject = require("@posthog/browser-common/console-logs");
|
|
36
|
+
const extension_tokens_namespaceObject = require("@posthog/browser-common/extension-tokens");
|
|
37
|
+
const external_logs_options_js_namespaceObject = require("./logs-options.js");
|
|
38
|
+
const readSdkContext = (environment, config)=>{
|
|
39
|
+
const client = environment.client;
|
|
40
|
+
const session = client.session;
|
|
41
|
+
const distinctId = client.distinctId;
|
|
42
|
+
let currentUrl;
|
|
43
|
+
try {
|
|
44
|
+
const href = environment.browserWindow?.location?.href;
|
|
45
|
+
if (href) currentUrl = (0, sanitize_url_namespaceObject.sanitizeUrl)(href, config.urlCapture ?? {});
|
|
46
|
+
} catch {}
|
|
47
|
+
const keys = client.getExtension(extension_tokens_namespaceObject.FeatureFlagsCommonExtension)?.getFlags();
|
|
48
|
+
return {
|
|
49
|
+
distinctId,
|
|
50
|
+
...session?.sessionId ? session : {},
|
|
51
|
+
...currentUrl ? {
|
|
52
|
+
currentUrl
|
|
53
|
+
} : {},
|
|
54
|
+
...keys?.length ? {
|
|
55
|
+
activeFeatureFlags: keys
|
|
56
|
+
} : {}
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
class BrowserNextLogs extends logs_namespaceObject.PostHogLogs {
|
|
60
|
+
constructor(config, _environment){
|
|
61
|
+
super({
|
|
62
|
+
get: ()=>config,
|
|
63
|
+
captureHintKey: 'consoleCaptureEnabled',
|
|
64
|
+
remoteConfigWillArrive: true
|
|
65
|
+
}, ()=>readSdkContext(_environment, config)), this._environment = _environment;
|
|
66
|
+
}
|
|
67
|
+
_getConsoleLoader() {
|
|
68
|
+
const browserWindow = this._environment.browserWindow;
|
|
69
|
+
const console = browserWindow?.console;
|
|
70
|
+
if (!console) return;
|
|
71
|
+
const consoleHost = {
|
|
72
|
+
console,
|
|
73
|
+
hostname: browserWindow?.location?.host ?? '',
|
|
74
|
+
getCapturingLogs: ()=>!this._environment.disposed && this._environment.client?.canCapture ? this : void 0
|
|
75
|
+
};
|
|
76
|
+
return (callback)=>callback(void 0, {
|
|
77
|
+
initialize: ()=>(0, console_logs_namespaceObject.initializeLogs)(consoleHost),
|
|
78
|
+
replay: (_client, entries)=>(0, console_logs_namespaceObject.replayConsoleBuffer)(consoleHost, entries)
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const logs = (options = {})=>{
|
|
83
|
+
const environment = {
|
|
84
|
+
client: void 0,
|
|
85
|
+
disposed: false
|
|
86
|
+
};
|
|
87
|
+
const subscriptions = [];
|
|
88
|
+
const shared = new BrowserNextLogs((0, external_logs_options_js_namespaceObject.snapshotLogsOptions)(options), environment);
|
|
89
|
+
const pagehide = ()=>{
|
|
90
|
+
if (!environment.disposed) shared.flushLogs('sendBeacon');
|
|
91
|
+
};
|
|
92
|
+
return {
|
|
93
|
+
name: 'logs',
|
|
94
|
+
setup: async (value)=>{
|
|
95
|
+
environment.client = value;
|
|
96
|
+
try {
|
|
97
|
+
environment.browserWindow = globalThis.window;
|
|
98
|
+
} catch {}
|
|
99
|
+
subscriptions.push(value.onReset(()=>shared.reset()), value.onConsentChange(({ current })=>{
|
|
100
|
+
if ('denied' === current) shared.reset();
|
|
101
|
+
}));
|
|
102
|
+
await shared.setup(value);
|
|
103
|
+
if (environment.disposed) return;
|
|
104
|
+
environment.browserWindow?.addEventListener('pagehide', pagehide);
|
|
105
|
+
},
|
|
106
|
+
captureLog: (record)=>{
|
|
107
|
+
if (environment.disposed) return;
|
|
108
|
+
try {
|
|
109
|
+
if (environment.client?.canCapture) shared.captureLog(record);
|
|
110
|
+
} catch (error) {
|
|
111
|
+
environment.client?.logger.error('Log capture failed', error);
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
flush: async ()=>{
|
|
115
|
+
if (!environment.disposed) await shared.flush();
|
|
116
|
+
},
|
|
117
|
+
reset: ()=>shared.reset(),
|
|
118
|
+
dispose: ()=>{
|
|
119
|
+
environment.disposed = true;
|
|
120
|
+
subscriptions.splice(0).forEach((subscription)=>subscription.dispose());
|
|
121
|
+
try {
|
|
122
|
+
environment.browserWindow?.removeEventListener('pagehide', pagehide);
|
|
123
|
+
} finally{
|
|
124
|
+
try {
|
|
125
|
+
shared.reset();
|
|
126
|
+
} finally{
|
|
127
|
+
shared.dispose();
|
|
128
|
+
environment.client = void 0;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
exports.logs = __webpack_exports__.logs;
|
|
135
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
136
|
+
"logs"
|
|
137
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
138
|
+
Object.defineProperty(exports, '__esModule', {
|
|
139
|
+
value: true
|
|
140
|
+
});
|