@loggerjs/browser 0.5.5 → 0.6.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/README.md +11 -14
- package/dist/http-transport.cjs +110 -47
- package/dist/http-transport.cjs.map +1 -1
- package/dist/http-transport.d.ts +1 -0
- package/dist/http-transport.d.ts.map +1 -1
- package/dist/http-transport.js +110 -47
- package/dist/http-transport.js.map +1 -1
- package/dist/index.cjs +111 -47
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +111 -47
- package/dist/index.js.map +1 -1
- package/dist/indexeddb-transport.cjs.map +1 -1
- package/dist/indexeddb-transport.js.map +1 -1
- package/dist/offline-first-transport.cjs +1 -0
- package/dist/offline-first-transport.cjs.map +1 -1
- package/dist/offline-first-transport.d.ts.map +1 -1
- package/dist/offline-first-transport.js +1 -0
- package/dist/offline-first-transport.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://jskits.github.io/loggerjs/"><img src="https://raw.githubusercontent.com/jskits/loggerjs/main/docs/public/logo.png" alt="LoggerJS logo" width="64" height="64" /></a>
|
|
3
|
+
</p>
|
|
4
|
+
|
|
1
5
|
# @loggerjs/browser
|
|
2
6
|
|
|
3
7
|
> Browser transports, offline persistence, and 19 automatic integrations — re-exports all of `@loggerjs/core`.
|
|
@@ -62,7 +66,7 @@ Logs batch over HTTP, queue while offline, replay with backoff when the network
|
|
|
62
66
|
| `browserWebSocketTransport` | a WebSocket (codec-encoded batches, queues while closed) |
|
|
63
67
|
| `browserServiceWorkerTransport` | a service worker for centralized delivery; `ready()` waits for `serviceWorker.ready` with `target: "ready"` |
|
|
64
68
|
| `browserBroadcastChannelTransport` | other tabs via `BroadcastChannel` |
|
|
65
|
-
| `offlineFirstTransport` |
|
|
69
|
+
| `offlineFirstTransport` | your remote transport, queueing to IndexedDB while offline or when delivery fails and replaying later |
|
|
66
70
|
|
|
67
71
|
### Offline queues & export
|
|
68
72
|
|
|
@@ -71,8 +75,7 @@ Logs batch over HTTP, queue while offline, replay with backoff when the network
|
|
|
71
75
|
- `exportLogsToZip()` + `downloadBlob()` — export a persisted store as a zip containing `logs.ndjson` or `logs.json`, `manifest.json`, optional per-session files, and optional `recent.ndjson` or `recent.json`.
|
|
72
76
|
- Call the `indexedDbTransport()` instance's `stats()` to read flush, prune, query, drop, and buffer-depth counters.
|
|
73
77
|
|
|
74
|
-
For a support-log store that survives reloads and exports per page session, the
|
|
75
|
-
short setup is:
|
|
78
|
+
For a support-log store that survives reloads and exports per page session, the short setup is:
|
|
76
79
|
|
|
77
80
|
```ts
|
|
78
81
|
import { createLogger } from "@loggerjs/core";
|
|
@@ -102,17 +105,9 @@ export async function downloadSupportLogs() {
|
|
|
102
105
|
}
|
|
103
106
|
```
|
|
104
107
|
|
|
105
|
-
`indexedDbTransport()` assigns a page-session id by default for browser support
|
|
106
|
-
stores. Use `query({ sessionId })`, `sessions()`, and
|
|
107
|
-
`exportLogsToZip(..., { groupBySession: true, includeRecent: true })` to build
|
|
108
|
-
support bundles around reload-sized sessions. Enable `localStorageSpill` only
|
|
109
|
-
as a bounded last-chance buffer for the still-unconfirmed memory tail during
|
|
110
|
-
ordinary reloads or tab closes; IndexedDB remains the queryable source of truth.
|
|
108
|
+
`indexedDbTransport()` assigns a page-session id by default for browser support stores. Use `query({ sessionId })`, `sessions()`, and `exportLogsToZip(..., { groupBySession: true, includeRecent: true })` to build support bundles around reload-sized sessions. Enable `localStorageSpill` only as a bounded last-chance buffer for the still-unconfirmed memory tail during ordinary reloads or tab closes; IndexedDB remains the queryable source of truth.
|
|
111
109
|
|
|
112
|
-
Browser delivery has runtime loss windows: tab close can cut off async work,
|
|
113
|
-
`sendBeacon` is size- and user-agent-limited, service worker delivery depends on
|
|
114
|
-
activation and lifetime, and IndexedDB persistence depends on quota and browser
|
|
115
|
-
storage policy. Use an IndexedDB offline queue when reload survival matters.
|
|
110
|
+
Browser delivery has runtime loss windows: tab close can cut off async work, `sendBeacon` is size- and user-agent-limited, service worker delivery depends on activation and lifetime, and IndexedDB persistence depends on quota and browser storage policy. Use an IndexedDB offline queue when reload survival matters.
|
|
116
111
|
|
|
117
112
|
## Integrations (19)
|
|
118
113
|
|
|
@@ -134,7 +129,9 @@ const frameworkErrors = captureFrameworkErrorsIntegration({ framework: "react" }
|
|
|
134
129
|
|
|
135
130
|
## Subpath exports
|
|
136
131
|
|
|
137
|
-
Transports — `transport-http` · `transport-indexeddb` · `transport-websocket` · `transport-service-worker` · `transport-broadcast-channel` · `offline-first-transport`
|
|
132
|
+
Transports — `transport-http` · `transport-indexeddb` · `transport-websocket` · `transport-service-worker` · `transport-broadcast-channel` · `offline-first-transport`
|
|
133
|
+
|
|
134
|
+
Utilities — `offline-indexeddb` · `export-zip` · `payload-transforms`
|
|
138
135
|
|
|
139
136
|
Integrations — `integration-console` · `integration-errors` · `integration-framework-errors` · `integration-reporting` · `integration-fetch` · `integration-xhr` · `integration-websocket` · `integration-web-vitals` · `integration-performance` · `integration-router` · `integration-framework-routers` · `integration-page-lifecycle` · `integration-user-actions` · `integration-service-worker` · `integration-runtime-host` · `integration-context`
|
|
140
137
|
|
package/dist/http-transport.cjs
CHANGED
|
@@ -62,6 +62,7 @@ function browserHttpTransport(options) {
|
|
|
62
62
|
const beaconCodec = options.beaconCodec ?? codec;
|
|
63
63
|
const queue = [];
|
|
64
64
|
const maxBatchSize = options.maxBatchSize ?? 50;
|
|
65
|
+
if (!Number.isSafeInteger(maxBatchSize) || maxBatchSize <= 0) throw new RangeError("maxBatchSize must be a positive safe integer");
|
|
65
66
|
const flushIntervalMs = options.flushIntervalMs ?? 2e3;
|
|
66
67
|
const maxQueueSize = options.maxQueueSize ?? 1e3;
|
|
67
68
|
const dropPolicy = options.dropPolicy ?? "drop-oldest";
|
|
@@ -74,8 +75,9 @@ function browserHttpTransport(options) {
|
|
|
74
75
|
const fetchFn = options.fetchFn ?? globalThis.fetch?.bind(globalThis);
|
|
75
76
|
let offlineEntrySeq = 0;
|
|
76
77
|
let timer;
|
|
77
|
-
let
|
|
78
|
-
let
|
|
78
|
+
let activeFlush;
|
|
79
|
+
let flushingBeacon = false;
|
|
80
|
+
let replayPromise;
|
|
79
81
|
let lastContext;
|
|
80
82
|
const headers = (payloadHeaders, contentType = codec.contentType) => ({
|
|
81
83
|
"content-type": contentType,
|
|
@@ -100,9 +102,18 @@ function browserHttpTransport(options) {
|
|
|
100
102
|
};
|
|
101
103
|
const createBeaconChunks = (batch) => {
|
|
102
104
|
const chunks = [];
|
|
105
|
+
const oversized = [];
|
|
103
106
|
let currentEvents = [];
|
|
104
107
|
let currentPayload;
|
|
105
108
|
for (const event of batch) {
|
|
109
|
+
if (currentEvents.length === maxBatchSize && currentPayload !== void 0) {
|
|
110
|
+
chunks.push({
|
|
111
|
+
events: currentEvents,
|
|
112
|
+
payload: currentPayload
|
|
113
|
+
});
|
|
114
|
+
currentEvents = [];
|
|
115
|
+
currentPayload = void 0;
|
|
116
|
+
}
|
|
106
117
|
const candidateEvents = [...currentEvents, event];
|
|
107
118
|
const candidatePayload = beaconCodec.encode(candidateEvents);
|
|
108
119
|
if (payloadByteLength(candidatePayload) <= beaconMaxBytes) {
|
|
@@ -110,7 +121,7 @@ function browserHttpTransport(options) {
|
|
|
110
121
|
currentPayload = candidatePayload;
|
|
111
122
|
continue;
|
|
112
123
|
}
|
|
113
|
-
if (currentEvents.length > 0 && currentPayload) chunks.push({
|
|
124
|
+
if (currentEvents.length > 0 && currentPayload !== void 0) chunks.push({
|
|
114
125
|
events: currentEvents,
|
|
115
126
|
payload: currentPayload
|
|
116
127
|
});
|
|
@@ -121,33 +132,32 @@ function browserHttpTransport(options) {
|
|
|
121
132
|
} else {
|
|
122
133
|
currentEvents = [];
|
|
123
134
|
currentPayload = void 0;
|
|
124
|
-
|
|
135
|
+
oversized.push(event);
|
|
125
136
|
}
|
|
126
137
|
}
|
|
127
|
-
if (currentEvents.length > 0 && currentPayload) chunks.push({
|
|
138
|
+
if (currentEvents.length > 0 && currentPayload !== void 0) chunks.push({
|
|
128
139
|
events: currentEvents,
|
|
129
140
|
payload: currentPayload
|
|
130
141
|
});
|
|
142
|
+
for (const event of oversized) reportDrop(event, "beacon-too-large");
|
|
131
143
|
return chunks;
|
|
132
144
|
};
|
|
133
145
|
const sendBeaconBatch = (batch) => {
|
|
134
|
-
if (typeof navigator === "undefined" || !navigator.sendBeacon) return {
|
|
135
|
-
ok: false,
|
|
136
|
-
remaining: batch
|
|
137
|
-
};
|
|
146
|
+
if (typeof navigator === "undefined" || !navigator.sendBeacon) return { remaining: batch };
|
|
138
147
|
const chunks = createBeaconChunks(batch);
|
|
139
148
|
for (let index = 0; index < chunks.length; index++) {
|
|
140
149
|
const chunk = chunks[index];
|
|
141
150
|
if (!chunk) continue;
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
151
|
+
try {
|
|
152
|
+
if (!navigator.sendBeacon(options.url, payloadToBeaconBody(chunk.payload, beaconCodec.contentType))) return { remaining: remainingEvents(chunks, index) };
|
|
153
|
+
} catch (error) {
|
|
154
|
+
return {
|
|
155
|
+
remaining: remainingEvents(chunks, index),
|
|
156
|
+
failure: { error }
|
|
157
|
+
};
|
|
158
|
+
}
|
|
146
159
|
}
|
|
147
|
-
return {
|
|
148
|
-
ok: true,
|
|
149
|
-
remaining: []
|
|
150
|
-
};
|
|
160
|
+
return { remaining: [] };
|
|
151
161
|
};
|
|
152
162
|
const sendPayload = async (entry) => {
|
|
153
163
|
if (!fetchFn) throw new Error("fetch is not available for browserHttpTransport");
|
|
@@ -183,17 +193,18 @@ function browserHttpTransport(options) {
|
|
|
183
193
|
(0, _loggerjs_core.incrementLoggerMetaCounter)("transport.offline.queued");
|
|
184
194
|
return true;
|
|
185
195
|
};
|
|
196
|
+
const isOnline = () => typeof navigator === "undefined" || navigator.onLine !== false;
|
|
186
197
|
const sendFetchBatch = async (batch) => {
|
|
187
|
-
if (batch.length === 0) return;
|
|
188
198
|
const transformed = await encodeTransformedPayload(batch);
|
|
189
|
-
if (offlineQueue &&
|
|
199
|
+
if (offlineQueue && !isOnline()) {
|
|
190
200
|
await enqueueOfflinePayload(transformed.payload, transformed.headers, transformed.contentType);
|
|
191
|
-
return;
|
|
201
|
+
return "queued";
|
|
192
202
|
}
|
|
193
203
|
try {
|
|
194
204
|
await sendPayload(createOfflineEntry(transformed.payload, transformed.headers, transformed.contentType));
|
|
205
|
+
return "sent";
|
|
195
206
|
} catch (error) {
|
|
196
|
-
if (await enqueueOfflinePayload(transformed.payload, transformed.headers, transformed.contentType)) return;
|
|
207
|
+
if (await enqueueOfflinePayload(transformed.payload, transformed.headers, transformed.contentType)) return "queued";
|
|
197
208
|
throw error;
|
|
198
209
|
}
|
|
199
210
|
};
|
|
@@ -215,40 +226,88 @@ function browserHttpTransport(options) {
|
|
|
215
226
|
await sleep(replayRetryDelay(attempt));
|
|
216
227
|
}
|
|
217
228
|
};
|
|
218
|
-
const replayOfflineQueue =
|
|
219
|
-
if (!offlineQueue
|
|
220
|
-
|
|
229
|
+
const replayOfflineQueue = () => {
|
|
230
|
+
if (!offlineQueue) return Promise.resolve();
|
|
231
|
+
replayPromise ??= (async () => {
|
|
232
|
+
try {
|
|
233
|
+
await offlineQueue.replay(sendOfflineEntryWithRetry);
|
|
234
|
+
} finally {
|
|
235
|
+
replayPromise = void 0;
|
|
236
|
+
}
|
|
237
|
+
})();
|
|
238
|
+
return replayPromise;
|
|
239
|
+
};
|
|
240
|
+
const replayOfflineQueueSafely = async (operation) => {
|
|
241
|
+
if (!offlineQueue || !isOnline()) return;
|
|
221
242
|
try {
|
|
222
|
-
await
|
|
223
|
-
}
|
|
224
|
-
|
|
243
|
+
await replayOfflineQueue();
|
|
244
|
+
} catch (error) {
|
|
245
|
+
reportInternalError(error, operation);
|
|
225
246
|
}
|
|
226
247
|
};
|
|
227
|
-
const
|
|
228
|
-
if (
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
const batch = queue.splice(0, queue.length);
|
|
232
|
-
let pendingBatch = batch;
|
|
248
|
+
const flushBeaconQueue = () => {
|
|
249
|
+
if (flushingBeacon || options.transformPayload || queue.length === 0) return;
|
|
250
|
+
flushingBeacon = true;
|
|
251
|
+
let pending = queue.splice(0, queue.length);
|
|
233
252
|
try {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
pendingBatch = beaconResult.remaining;
|
|
238
|
-
}
|
|
239
|
-
await sendFetchBatch(pendingBatch);
|
|
240
|
-
pendingBatch = [];
|
|
241
|
-
} catch (error) {
|
|
242
|
-
if (pendingBatch.length > 0) queue.unshift(...pendingBatch);
|
|
243
|
-
throw error;
|
|
253
|
+
const result = sendBeaconBatch(pending);
|
|
254
|
+
pending = result.remaining;
|
|
255
|
+
if (result.failure) throw result.failure.error;
|
|
244
256
|
} finally {
|
|
245
|
-
|
|
246
|
-
|
|
257
|
+
if (pending.length > 0) queue.unshift(...pending);
|
|
258
|
+
flushingBeacon = false;
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
const flush = (preferBeacon = false) => {
|
|
262
|
+
if (activeFlush) {
|
|
263
|
+
if (preferBeacon) try {
|
|
264
|
+
flushBeaconQueue();
|
|
265
|
+
} catch (error) {
|
|
266
|
+
return activeFlush.then(() => {
|
|
267
|
+
throw error;
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
return activeFlush;
|
|
247
271
|
}
|
|
272
|
+
if (queue.length === 0) return preferBeacon ? Promise.resolve() : replayOfflineQueueSafely("replay");
|
|
273
|
+
clearTimer();
|
|
274
|
+
let resolve;
|
|
275
|
+
let reject;
|
|
276
|
+
const task = new Promise((onResolve, onReject) => {
|
|
277
|
+
resolve = onResolve;
|
|
278
|
+
reject = onReject;
|
|
279
|
+
});
|
|
280
|
+
activeFlush = task;
|
|
281
|
+
(async () => {
|
|
282
|
+
try {
|
|
283
|
+
if (preferBeacon) flushBeaconQueue();
|
|
284
|
+
let sent = false;
|
|
285
|
+
let queued = false;
|
|
286
|
+
while (queue.length > 0) {
|
|
287
|
+
const batch = queue.splice(0, maxBatchSize);
|
|
288
|
+
try {
|
|
289
|
+
if (await sendFetchBatch(batch) === "sent") sent = true;
|
|
290
|
+
else queued = true;
|
|
291
|
+
} catch (error) {
|
|
292
|
+
queue.unshift(...batch);
|
|
293
|
+
throw error;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
if (!preferBeacon && sent && !queued) await replayOfflineQueueSafely("replay");
|
|
297
|
+
resolve();
|
|
298
|
+
} catch (error) {
|
|
299
|
+
reject(error);
|
|
300
|
+
} finally {
|
|
301
|
+
activeFlush = void 0;
|
|
302
|
+
if (queue.length > 0) schedule();
|
|
303
|
+
}
|
|
304
|
+
})();
|
|
305
|
+
return task;
|
|
248
306
|
};
|
|
249
307
|
const schedule = () => {
|
|
250
|
-
if (timer || flushIntervalMs <= 0) return;
|
|
308
|
+
if (activeFlush || timer || flushIntervalMs <= 0) return;
|
|
251
309
|
timer = setTimeout(() => {
|
|
310
|
+
timer = void 0;
|
|
252
311
|
flush(false).catch((error) => reportInternalError(error, "flush"));
|
|
253
312
|
}, flushIntervalMs);
|
|
254
313
|
};
|
|
@@ -265,7 +324,10 @@ function browserHttpTransport(options) {
|
|
|
265
324
|
globalThis.addEventListener?.("pagehide", onPageHide);
|
|
266
325
|
globalThis.addEventListener?.("visibilitychange", onVisibilityChange);
|
|
267
326
|
}
|
|
268
|
-
if (offlineQueue)
|
|
327
|
+
if (offlineQueue) {
|
|
328
|
+
globalThis.addEventListener?.("online", onOnline);
|
|
329
|
+
if (options.offlineReplayOnStart ?? true) setTimeout(() => void replayOfflineQueueSafely("startup-replay"), 0);
|
|
330
|
+
}
|
|
269
331
|
return {
|
|
270
332
|
name: options.name ?? "browser-http",
|
|
271
333
|
minLevel: options.minLevel,
|
|
@@ -281,6 +343,7 @@ function browserHttpTransport(options) {
|
|
|
281
343
|
if (dropped) reportDrop(dropped, "queue-full");
|
|
282
344
|
}
|
|
283
345
|
queue.push(event);
|
|
346
|
+
if (activeFlush) return;
|
|
284
347
|
if (queue.length >= maxBatchSize) flush(false).catch((error) => reportInternalError(error, "flush"));
|
|
285
348
|
else schedule();
|
|
286
349
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-transport.cjs","names":[],"sources":["../src/http-transport.ts"],"sourcesContent":["import {\n applyPayloadTransforms,\n incrementLoggerMetaCounter,\n safeJsonCodec,\n toLevelValue,\n type Codec,\n type EncodedPayload,\n type LogEvent,\n type LoggerLevel,\n type PayloadTransform,\n type Transport,\n type TransportContext,\n} from \"@loggerjs/core\";\n\nexport type BrowserHttpDropPolicy = \"drop-oldest\" | \"drop-newest\";\n\nconst DEFAULT_BEACON_MAX_BYTES = 60 * 1024;\n\nconst sleep = (delayMs: number) =>\n delayMs <= 0 ? Promise.resolve() : new Promise<void>((resolve) => setTimeout(resolve, delayMs));\n\nexport interface BrowserHttpOfflineEntry {\n id: string;\n url: string;\n method: \"POST\" | \"PUT\";\n headers: Record<string, string>;\n body: string | Uint8Array;\n credentials?: RequestCredentials;\n keepalive: boolean;\n createdAt: number;\n}\n\nexport interface BrowserHttpOfflineQueue {\n enqueue: (entry: BrowserHttpOfflineEntry) => void | Promise<void>;\n replay: (send: (entry: BrowserHttpOfflineEntry) => Promise<void>) => void | Promise<void>;\n}\n\nexport interface MemoryBrowserHttpOfflineQueueOptions {\n maxEntries?: number;\n dropPolicy?: BrowserHttpDropPolicy;\n onDrop?: (entry: BrowserHttpOfflineEntry, reason: string) => void;\n}\n\nexport interface BrowserHttpTransportOptions {\n url: string;\n name?: string;\n method?: \"POST\" | \"PUT\";\n headers?: Record<string, string>;\n credentials?: RequestCredentials;\n keepalive?: boolean;\n codec?: Codec<string | Uint8Array>;\n beaconCodec?: Codec<string | Uint8Array>;\n minLevel?: LoggerLevel;\n maxBatchSize?: number;\n flushIntervalMs?: number;\n maxQueueSize?: number;\n dropPolicy?: BrowserHttpDropPolicy;\n useBeaconOnPageHide?: boolean;\n beaconMaxBytes?: number;\n offlineQueue?: BrowserHttpOfflineQueue;\n offlineReplayMaxRetries?: number;\n offlineReplayBaseDelayMs?: number;\n offlineReplayMaxDelayMs?: number;\n random?: () => number;\n fetchFn?: typeof fetch;\n transformPayload?: PayloadTransform | readonly PayloadTransform[];\n onDrop?: (event: LogEvent, reason: string) => void;\n}\n\nexport function memoryBrowserHttpOfflineQueue(\n options: MemoryBrowserHttpOfflineQueueOptions = {},\n): BrowserHttpOfflineQueue & { size: () => number } {\n const entries: BrowserHttpOfflineEntry[] = [];\n const maxEntries = options.maxEntries ?? 1000;\n const dropPolicy = options.dropPolicy ?? \"drop-oldest\";\n\n const drop = (entry: BrowserHttpOfflineEntry, reason: string) => {\n incrementLoggerMetaCounter(\"transport.offline.dropped\");\n incrementLoggerMetaCounter(`transport.offline.dropped.${reason}`);\n options.onDrop?.(entry, reason);\n };\n\n return {\n enqueue(entry) {\n if (entries.length >= maxEntries) {\n if (dropPolicy === \"drop-newest\") {\n drop(entry, \"queue-full\");\n return;\n }\n const dropped = entries.shift();\n if (dropped) drop(dropped, \"queue-full\");\n }\n entries.push(entry);\n },\n async replay(send) {\n while (entries.length > 0) {\n const entry = entries[0];\n if (!entry) return;\n // oxlint-disable-next-line no-await-in-loop -- Replay must remove entries only after each send succeeds.\n await send(entry);\n entries.shift();\n }\n },\n size() {\n return entries.length;\n },\n };\n}\n\nfunction payloadToBody(payload: EncodedPayload): BodyInit {\n if (typeof payload === \"string\") return payload;\n return Uint8Array.from(payload);\n}\n\nfunction payloadByteLength(payload: EncodedPayload): number {\n if (typeof payload !== \"string\") return payload.byteLength;\n if (typeof TextEncoder !== \"undefined\") return new TextEncoder().encode(payload).byteLength;\n return new Blob([payload]).size;\n}\n\nfunction payloadToBeaconBody(payload: EncodedPayload, contentType: string): BodyInit {\n return new Blob([typeof payload === \"string\" ? payload : Uint8Array.from(payload)], {\n type: contentType,\n });\n}\n\ninterface BeaconChunk {\n events: LogEvent[];\n payload: string | Uint8Array;\n}\n\nfunction remainingEvents(chunks: BeaconChunk[], startIndex: number): LogEvent[] {\n const events: LogEvent[] = [];\n for (let index = startIndex; index < chunks.length; index++) {\n const chunk = chunks[index];\n if (chunk) events.push(...chunk.events);\n }\n return events;\n}\n\nexport function browserHttpTransport(options: BrowserHttpTransportOptions): Transport {\n const codec = options.codec ?? safeJsonCodec();\n const beaconCodec = options.beaconCodec ?? codec;\n const queue: LogEvent[] = [];\n const maxBatchSize = options.maxBatchSize ?? 50;\n const flushIntervalMs = options.flushIntervalMs ?? 2000;\n const maxQueueSize = options.maxQueueSize ?? 1000;\n const dropPolicy = options.dropPolicy ?? \"drop-oldest\";\n const beaconMaxBytes = options.beaconMaxBytes ?? DEFAULT_BEACON_MAX_BYTES;\n const offlineQueue = options.offlineQueue;\n const offlineReplayMaxRetries = options.offlineReplayMaxRetries ?? 3;\n const offlineReplayBaseDelayMs = options.offlineReplayBaseDelayMs ?? 250;\n const offlineReplayMaxDelayMs = options.offlineReplayMaxDelayMs ?? 5000;\n const random = options.random ?? Math.random;\n const fetchFn = options.fetchFn ?? globalThis.fetch?.bind(globalThis);\n let offlineEntrySeq = 0;\n let timer: ReturnType<typeof setTimeout> | undefined;\n let flushing = false;\n let replayingOffline = false;\n let lastContext: TransportContext | undefined;\n\n const headers = (payloadHeaders?: Record<string, string>, contentType = codec.contentType) => ({\n \"content-type\": contentType,\n ...payloadHeaders,\n ...options.headers,\n });\n\n const clearTimer = () => {\n if (timer) clearTimeout(timer);\n timer = undefined;\n };\n\n const reportDrop = (event: LogEvent, reason: string) => {\n incrementLoggerMetaCounter(\"transport.dropped\");\n incrementLoggerMetaCounter(`transport.dropped.${reason}`);\n options.onDrop?.(event, reason);\n };\n\n const reportInternalError = (error: unknown, operation: string) => {\n lastContext?.reportInternalError(error, {\n phase: \"transport\",\n transport: options.name ?? \"browser-http\",\n operation,\n });\n };\n\n const createBeaconChunks = (batch: LogEvent[]): BeaconChunk[] => {\n const chunks: BeaconChunk[] = [];\n let currentEvents: LogEvent[] = [];\n let currentPayload: string | Uint8Array | undefined;\n\n for (const event of batch) {\n const candidateEvents = [...currentEvents, event];\n const candidatePayload = beaconCodec.encode(candidateEvents);\n if (payloadByteLength(candidatePayload) <= beaconMaxBytes) {\n currentEvents = candidateEvents;\n currentPayload = candidatePayload;\n continue;\n }\n\n if (currentEvents.length > 0 && currentPayload) {\n chunks.push({ events: currentEvents, payload: currentPayload });\n }\n\n const singlePayload = beaconCodec.encode([event]);\n if (payloadByteLength(singlePayload) <= beaconMaxBytes) {\n currentEvents = [event];\n currentPayload = singlePayload;\n } else {\n currentEvents = [];\n currentPayload = undefined;\n reportDrop(event, \"beacon-too-large\");\n }\n }\n\n if (currentEvents.length > 0 && currentPayload) {\n chunks.push({ events: currentEvents, payload: currentPayload });\n }\n\n return chunks;\n };\n\n const sendBeaconBatch = (batch: LogEvent[]): { ok: boolean; remaining: LogEvent[] } => {\n if (typeof navigator === \"undefined\" || !navigator.sendBeacon) {\n return { ok: false, remaining: batch };\n }\n\n const chunks = createBeaconChunks(batch);\n for (let index = 0; index < chunks.length; index++) {\n const chunk = chunks[index];\n if (!chunk) continue;\n const ok = navigator.sendBeacon(\n options.url,\n payloadToBeaconBody(chunk.payload, beaconCodec.contentType),\n );\n if (!ok) return { ok: false, remaining: remainingEvents(chunks, index) };\n }\n\n return { ok: true, remaining: [] };\n };\n\n const sendPayload = async (entry: BrowserHttpOfflineEntry) => {\n if (!fetchFn) throw new Error(\"fetch is not available for browserHttpTransport\");\n const response = await fetchFn(entry.url, {\n method: entry.method,\n headers: entry.headers,\n body: payloadToBody(entry.body),\n credentials: entry.credentials,\n keepalive: entry.keepalive,\n });\n if (!response.ok) throw new Error(`browserHttpTransport failed with status ${response.status}`);\n };\n\n const encodeTransformedPayload = async (batch: LogEvent[]) => {\n const encoded = codec.encode(batch);\n return applyPayloadTransforms(\n encoded,\n {\n contentType: codec.contentType,\n events: batch,\n transport: options.name ?? \"browser-http\",\n },\n options.transformPayload,\n );\n };\n\n const createOfflineEntry = (\n payload: string | Uint8Array,\n payloadHeaders?: Record<string, string>,\n contentType?: string,\n ): BrowserHttpOfflineEntry => ({\n id: `${Date.now().toString(36)}-${(offlineEntrySeq++).toString(36)}`,\n url: options.url,\n method: options.method ?? \"POST\",\n headers: headers(payloadHeaders, contentType),\n body: payload,\n credentials: options.credentials,\n keepalive: options.keepalive ?? true,\n createdAt: Date.now(),\n });\n\n const enqueueOfflinePayload = async (\n payload: string | Uint8Array,\n payloadHeaders?: Record<string, string>,\n contentType?: string,\n ) => {\n if (!offlineQueue) return false;\n await offlineQueue.enqueue(createOfflineEntry(payload, payloadHeaders, contentType));\n incrementLoggerMetaCounter(\"transport.offline.queued\");\n return true;\n };\n\n const sendFetchBatch = async (batch: LogEvent[]) => {\n if (batch.length === 0) return;\n const transformed = await encodeTransformedPayload(batch);\n if (offlineQueue && typeof navigator !== \"undefined\" && navigator.onLine === false) {\n await enqueueOfflinePayload(\n transformed.payload,\n transformed.headers,\n transformed.contentType,\n );\n return;\n }\n try {\n await sendPayload(\n createOfflineEntry(transformed.payload, transformed.headers, transformed.contentType),\n );\n } catch (error) {\n if (\n await enqueueOfflinePayload(\n transformed.payload,\n transformed.headers,\n transformed.contentType,\n )\n ) {\n return;\n }\n throw error;\n }\n };\n\n const replayRetryDelay = (attempt: number): number => {\n const cap = Math.min(offlineReplayMaxDelayMs, offlineReplayBaseDelayMs * 2 ** attempt);\n return cap <= 0 ? 0 : random() * cap;\n };\n\n const sendOfflineEntryWithRetry = async (entry: BrowserHttpOfflineEntry) => {\n for (let attempt = 0; ; attempt++) {\n try {\n // oxlint-disable-next-line no-await-in-loop -- Retry attempts must run sequentially.\n await sendPayload(entry);\n incrementLoggerMetaCounter(\"transport.offline.replayed\");\n return;\n } catch (error) {\n if (attempt >= offlineReplayMaxRetries) {\n incrementLoggerMetaCounter(\"transport.offline.replay.failed\");\n throw error;\n }\n incrementLoggerMetaCounter(\"transport.offline.retry\");\n // oxlint-disable-next-line no-await-in-loop -- Backoff must complete before the next retry.\n await sleep(replayRetryDelay(attempt));\n }\n }\n };\n\n const replayOfflineQueue = async () => {\n if (!offlineQueue || replayingOffline) return;\n replayingOffline = true;\n try {\n await offlineQueue.replay(sendOfflineEntryWithRetry);\n } finally {\n replayingOffline = false;\n }\n };\n\n const flush = async (preferBeacon = false) => {\n if (flushing || queue.length === 0) return;\n flushing = true;\n clearTimer();\n const batch = queue.splice(0, queue.length);\n let pendingBatch = batch;\n\n try {\n if (preferBeacon && !options.transformPayload) {\n const beaconResult = sendBeaconBatch(batch);\n if (beaconResult.ok || beaconResult.remaining.length === 0) return;\n pendingBatch = beaconResult.remaining;\n }\n\n await sendFetchBatch(pendingBatch);\n pendingBatch = [];\n } catch (error) {\n if (pendingBatch.length > 0) queue.unshift(...pendingBatch);\n throw error;\n } finally {\n flushing = false;\n if (queue.length > 0) schedule();\n }\n };\n\n const schedule = () => {\n if (timer || flushIntervalMs <= 0) return;\n timer = setTimeout(() => {\n void flush(false).catch((error: unknown) => reportInternalError(error, \"flush\"));\n }, flushIntervalMs);\n };\n\n const onPageHide = () => {\n void flush(true).catch((error: unknown) => reportInternalError(error, \"pagehide-flush\"));\n };\n const onVisibilityChange = () => {\n if (typeof document !== \"undefined\" && document.visibilityState === \"hidden\") {\n void flush(true).catch((error: unknown) => reportInternalError(error, \"visibility-flush\"));\n }\n };\n const onOnline = () => {\n void replayOfflineQueue().catch((error: unknown) => reportInternalError(error, \"replay\"));\n };\n\n if (options.useBeaconOnPageHide ?? true) {\n globalThis.addEventListener?.(\"pagehide\", onPageHide);\n globalThis.addEventListener?.(\"visibilitychange\", onVisibilityChange);\n }\n if (offlineQueue) globalThis.addEventListener?.(\"online\", onOnline);\n\n return {\n name: options.name ?? \"browser-http\",\n minLevel: options.minLevel,\n log(event, context) {\n if (options.minLevel !== undefined && event.level < toLevelValue(options.minLevel)) return;\n lastContext = context;\n if (queue.length >= maxQueueSize) {\n if (dropPolicy === \"drop-newest\") {\n reportDrop(event, \"queue-full\");\n return;\n }\n const dropped = queue.shift();\n if (dropped) reportDrop(dropped, \"queue-full\");\n }\n queue.push(event);\n if (queue.length >= maxBatchSize) {\n void flush(false).catch((error: unknown) => reportInternalError(error, \"flush\"));\n } else schedule();\n },\n flush() {\n return flush(false);\n },\n close() {\n globalThis.removeEventListener?.(\"pagehide\", onPageHide);\n globalThis.removeEventListener?.(\"visibilitychange\", onVisibilityChange);\n globalThis.removeEventListener?.(\"online\", onOnline);\n return flush(true);\n },\n };\n}\n"],"mappings":";;;AAgBA,MAAM,2BAA2B,KAAK;AAEtC,MAAM,SAAS,YACb,WAAW,IAAI,QAAQ,QAAQ,IAAI,IAAI,SAAe,YAAY,WAAW,SAAS,OAAO,CAAC;AAkDhG,SAAgB,8BACd,UAAgD,CAAC,GACC;CAClD,MAAM,UAAqC,CAAC;CAC5C,MAAM,aAAa,QAAQ,cAAc;CACzC,MAAM,aAAa,QAAQ,cAAc;CAEzC,MAAM,QAAQ,OAAgC,WAAmB;EAC/D,CAAA,GAAA,eAAA,2BAAA,CAA2B,2BAA2B;EACtD,CAAA,GAAA,eAAA,2BAAA,CAA2B,6BAA6B,QAAQ;EAChE,QAAQ,SAAS,OAAO,MAAM;CAChC;CAEA,OAAO;EACL,QAAQ,OAAO;GACb,IAAI,QAAQ,UAAU,YAAY;IAChC,IAAI,eAAe,eAAe;KAChC,KAAK,OAAO,YAAY;KACxB;IACF;IACA,MAAM,UAAU,QAAQ,MAAM;IAC9B,IAAI,SAAS,KAAK,SAAS,YAAY;GACzC;GACA,QAAQ,KAAK,KAAK;EACpB;EACA,MAAM,OAAO,MAAM;GACjB,OAAO,QAAQ,SAAS,GAAG;IACzB,MAAM,QAAQ,QAAQ;IACtB,IAAI,CAAC,OAAO;IAEZ,MAAM,KAAK,KAAK;IAChB,QAAQ,MAAM;GAChB;EACF;EACA,OAAO;GACL,OAAO,QAAQ;EACjB;CACF;AACF;AAEA,SAAS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AQ;CAElE,OAAO;EACL,MAAM,QAAQ,QAAQ;EACtB,UAAU,QAAQ;EAClB,IAAI,OAAO,SAAS;GAClB,IAAI,QAAQ,aAAa,KAAA,KAAa,MAAM,SAAA,GAAA,eAAA,aAAA,CAAqB,QAAQ,QAAQ,GAAG;GACpF,cAAc;GACd,IAAI,MAAM,UAAU,cAAc;IAChC,IAAI,eAAe,eAAe;KAChC,WAAW,OAAO,YAAY;KAC9B;IACF;IACA,MAAM,UAAU,MAAM,MAAM;IAC5B,IAAI,SAAS,WAAW,SAAS,YAAY;GAC/C;GACA,MAAM,KAAK,KAAK;GAChB,IAAI,MAAM,UAAU,cAClB,MAAW,KAAK,CAAC,CAAC,OAAO,UAAmB,oBAAoB,OAAO,OAAO,CAAC;QAC1E,SAAS;EAClB;EACA,QAAQ;GACN,OAAO,MAAM,KAAK;EACpB;EACA,QAAQ;GACN,WAAW,sBAAsB,YAAY,UAAU;GACvD,WAAW,sBAAsB,oBAAoB,kBAAkB;GACvE,WAAW,sBAAsB,UAAU,QAAQ;GACnD,OAAO,MAAM,IAAI;EACnB;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"http-transport.cjs","names":[],"sources":["../src/http-transport.ts"],"sourcesContent":["import {\n applyPayloadTransforms,\n incrementLoggerMetaCounter,\n safeJsonCodec,\n toLevelValue,\n type Codec,\n type EncodedPayload,\n type LogEvent,\n type LoggerLevel,\n type PayloadTransform,\n type Transport,\n type TransportContext,\n} from \"@loggerjs/core\";\n\nexport type BrowserHttpDropPolicy = \"drop-oldest\" | \"drop-newest\";\n\nconst DEFAULT_BEACON_MAX_BYTES = 60 * 1024;\n\nconst sleep = (delayMs: number) =>\n delayMs <= 0 ? Promise.resolve() : new Promise<void>((resolve) => setTimeout(resolve, delayMs));\n\nexport interface BrowserHttpOfflineEntry {\n id: string;\n url: string;\n method: \"POST\" | \"PUT\";\n headers: Record<string, string>;\n body: string | Uint8Array;\n credentials?: RequestCredentials;\n keepalive: boolean;\n createdAt: number;\n}\n\nexport interface BrowserHttpOfflineQueue {\n enqueue: (entry: BrowserHttpOfflineEntry) => void | Promise<void>;\n replay: (send: (entry: BrowserHttpOfflineEntry) => Promise<void>) => void | Promise<void>;\n}\n\nexport interface MemoryBrowserHttpOfflineQueueOptions {\n maxEntries?: number;\n dropPolicy?: BrowserHttpDropPolicy;\n onDrop?: (entry: BrowserHttpOfflineEntry, reason: string) => void;\n}\n\nexport interface BrowserHttpTransportOptions {\n url: string;\n name?: string;\n method?: \"POST\" | \"PUT\";\n headers?: Record<string, string>;\n credentials?: RequestCredentials;\n keepalive?: boolean;\n codec?: Codec<string | Uint8Array>;\n beaconCodec?: Codec<string | Uint8Array>;\n minLevel?: LoggerLevel;\n maxBatchSize?: number;\n flushIntervalMs?: number;\n maxQueueSize?: number;\n dropPolicy?: BrowserHttpDropPolicy;\n useBeaconOnPageHide?: boolean;\n beaconMaxBytes?: number;\n offlineQueue?: BrowserHttpOfflineQueue;\n offlineReplayMaxRetries?: number;\n offlineReplayBaseDelayMs?: number;\n offlineReplayMaxDelayMs?: number;\n offlineReplayOnStart?: boolean;\n random?: () => number;\n fetchFn?: typeof fetch;\n transformPayload?: PayloadTransform | readonly PayloadTransform[];\n onDrop?: (event: LogEvent, reason: string) => void;\n}\n\nexport function memoryBrowserHttpOfflineQueue(\n options: MemoryBrowserHttpOfflineQueueOptions = {},\n): BrowserHttpOfflineQueue & { size: () => number } {\n const entries: BrowserHttpOfflineEntry[] = [];\n const maxEntries = options.maxEntries ?? 1000;\n const dropPolicy = options.dropPolicy ?? \"drop-oldest\";\n\n const drop = (entry: BrowserHttpOfflineEntry, reason: string) => {\n incrementLoggerMetaCounter(\"transport.offline.dropped\");\n incrementLoggerMetaCounter(`transport.offline.dropped.${reason}`);\n options.onDrop?.(entry, reason);\n };\n\n return {\n enqueue(entry) {\n if (entries.length >= maxEntries) {\n if (dropPolicy === \"drop-newest\") {\n drop(entry, \"queue-full\");\n return;\n }\n const dropped = entries.shift();\n if (dropped) drop(dropped, \"queue-full\");\n }\n entries.push(entry);\n },\n async replay(send) {\n while (entries.length > 0) {\n const entry = entries[0];\n if (!entry) return;\n // oxlint-disable-next-line no-await-in-loop -- Replay must remove entries only after each send succeeds.\n await send(entry);\n entries.shift();\n }\n },\n size() {\n return entries.length;\n },\n };\n}\n\nfunction payloadToBody(payload: EncodedPayload): BodyInit {\n if (typeof payload === \"string\") return payload;\n return Uint8Array.from(payload);\n}\n\nfunction payloadByteLength(payload: EncodedPayload): number {\n if (typeof payload !== \"string\") return payload.byteLength;\n if (typeof TextEncoder !== \"undefined\") return new TextEncoder().encode(payload).byteLength;\n return new Blob([payload]).size;\n}\n\nfunction payloadToBeaconBody(payload: EncodedPayload, contentType: string): BodyInit {\n return new Blob([typeof payload === \"string\" ? payload : Uint8Array.from(payload)], {\n type: contentType,\n });\n}\n\ninterface BeaconChunk {\n events: LogEvent[];\n payload: string | Uint8Array;\n}\n\nfunction remainingEvents(chunks: BeaconChunk[], startIndex: number): LogEvent[] {\n const events: LogEvent[] = [];\n for (let index = startIndex; index < chunks.length; index++) {\n const chunk = chunks[index];\n if (chunk) events.push(...chunk.events);\n }\n return events;\n}\n\nexport function browserHttpTransport(options: BrowserHttpTransportOptions): Transport {\n const codec = options.codec ?? safeJsonCodec();\n const beaconCodec = options.beaconCodec ?? codec;\n const queue: LogEvent[] = [];\n const maxBatchSize = options.maxBatchSize ?? 50;\n if (!Number.isSafeInteger(maxBatchSize) || maxBatchSize <= 0) {\n throw new RangeError(\"maxBatchSize must be a positive safe integer\");\n }\n const flushIntervalMs = options.flushIntervalMs ?? 2000;\n const maxQueueSize = options.maxQueueSize ?? 1000;\n const dropPolicy = options.dropPolicy ?? \"drop-oldest\";\n const beaconMaxBytes = options.beaconMaxBytes ?? DEFAULT_BEACON_MAX_BYTES;\n const offlineQueue = options.offlineQueue;\n const offlineReplayMaxRetries = options.offlineReplayMaxRetries ?? 3;\n const offlineReplayBaseDelayMs = options.offlineReplayBaseDelayMs ?? 250;\n const offlineReplayMaxDelayMs = options.offlineReplayMaxDelayMs ?? 5000;\n const random = options.random ?? Math.random;\n const fetchFn = options.fetchFn ?? globalThis.fetch?.bind(globalThis);\n let offlineEntrySeq = 0;\n let timer: ReturnType<typeof setTimeout> | undefined;\n let activeFlush: Promise<void> | undefined;\n let flushingBeacon = false;\n let replayPromise: Promise<void> | undefined;\n let lastContext: TransportContext | undefined;\n\n const headers = (payloadHeaders?: Record<string, string>, contentType = codec.contentType) => ({\n \"content-type\": contentType,\n ...payloadHeaders,\n ...options.headers,\n });\n\n const clearTimer = () => {\n if (timer) clearTimeout(timer);\n timer = undefined;\n };\n\n const reportDrop = (event: LogEvent, reason: string) => {\n incrementLoggerMetaCounter(\"transport.dropped\");\n incrementLoggerMetaCounter(`transport.dropped.${reason}`);\n options.onDrop?.(event, reason);\n };\n\n const reportInternalError = (error: unknown, operation: string) => {\n lastContext?.reportInternalError(error, {\n phase: \"transport\",\n transport: options.name ?? \"browser-http\",\n operation,\n });\n };\n\n const createBeaconChunks = (batch: LogEvent[]): BeaconChunk[] => {\n const chunks: BeaconChunk[] = [];\n const oversized: LogEvent[] = [];\n let currentEvents: LogEvent[] = [];\n let currentPayload: string | Uint8Array | undefined;\n\n for (const event of batch) {\n if (currentEvents.length === maxBatchSize && currentPayload !== undefined) {\n chunks.push({ events: currentEvents, payload: currentPayload });\n currentEvents = [];\n currentPayload = undefined;\n }\n const candidateEvents = [...currentEvents, event];\n const candidatePayload = beaconCodec.encode(candidateEvents);\n if (payloadByteLength(candidatePayload) <= beaconMaxBytes) {\n currentEvents = candidateEvents;\n currentPayload = candidatePayload;\n continue;\n }\n\n if (currentEvents.length > 0 && currentPayload !== undefined) {\n chunks.push({ events: currentEvents, payload: currentPayload });\n }\n\n const singlePayload = beaconCodec.encode([event]);\n if (payloadByteLength(singlePayload) <= beaconMaxBytes) {\n currentEvents = [event];\n currentPayload = singlePayload;\n } else {\n currentEvents = [];\n currentPayload = undefined;\n oversized.push(event);\n }\n }\n\n if (currentEvents.length > 0 && currentPayload !== undefined) {\n chunks.push({ events: currentEvents, payload: currentPayload });\n }\n\n for (const event of oversized) reportDrop(event, \"beacon-too-large\");\n return chunks;\n };\n\n const sendBeaconBatch = (\n batch: LogEvent[],\n ): { remaining: LogEvent[]; failure?: { error: unknown } } => {\n if (typeof navigator === \"undefined\" || !navigator.sendBeacon) {\n return { remaining: batch };\n }\n\n const chunks = createBeaconChunks(batch);\n for (let index = 0; index < chunks.length; index++) {\n const chunk = chunks[index];\n if (!chunk) continue;\n try {\n const ok = navigator.sendBeacon(\n options.url,\n payloadToBeaconBody(chunk.payload, beaconCodec.contentType),\n );\n if (!ok) return { remaining: remainingEvents(chunks, index) };\n } catch (error) {\n return { remaining: remainingEvents(chunks, index), failure: { error } };\n }\n }\n\n return { remaining: [] };\n };\n\n const sendPayload = async (entry: BrowserHttpOfflineEntry) => {\n if (!fetchFn) throw new Error(\"fetch is not available for browserHttpTransport\");\n const response = await fetchFn(entry.url, {\n method: entry.method,\n headers: entry.headers,\n body: payloadToBody(entry.body),\n credentials: entry.credentials,\n keepalive: entry.keepalive,\n });\n if (!response.ok) throw new Error(`browserHttpTransport failed with status ${response.status}`);\n };\n\n const encodeTransformedPayload = async (batch: LogEvent[]) => {\n const encoded = codec.encode(batch);\n return applyPayloadTransforms(\n encoded,\n {\n contentType: codec.contentType,\n events: batch,\n transport: options.name ?? \"browser-http\",\n },\n options.transformPayload,\n );\n };\n\n const createOfflineEntry = (\n payload: string | Uint8Array,\n payloadHeaders?: Record<string, string>,\n contentType?: string,\n ): BrowserHttpOfflineEntry => ({\n id: `${Date.now().toString(36)}-${(offlineEntrySeq++).toString(36)}`,\n url: options.url,\n method: options.method ?? \"POST\",\n headers: headers(payloadHeaders, contentType),\n body: payload,\n credentials: options.credentials,\n keepalive: options.keepalive ?? true,\n createdAt: Date.now(),\n });\n\n const enqueueOfflinePayload = async (\n payload: string | Uint8Array,\n payloadHeaders?: Record<string, string>,\n contentType?: string,\n ) => {\n if (!offlineQueue) return false;\n await offlineQueue.enqueue(createOfflineEntry(payload, payloadHeaders, contentType));\n incrementLoggerMetaCounter(\"transport.offline.queued\");\n return true;\n };\n\n const isOnline = () => typeof navigator === \"undefined\" || navigator.onLine !== false;\n\n // Resolves to \"sent\" when the collector accepted the batch and \"queued\" when\n // the offline queue took it instead.\n const sendFetchBatch = async (batch: LogEvent[]): Promise<\"sent\" | \"queued\"> => {\n const transformed = await encodeTransformedPayload(batch);\n if (offlineQueue && !isOnline()) {\n await enqueueOfflinePayload(\n transformed.payload,\n transformed.headers,\n transformed.contentType,\n );\n return \"queued\";\n }\n try {\n await sendPayload(\n createOfflineEntry(transformed.payload, transformed.headers, transformed.contentType),\n );\n return \"sent\";\n } catch (error) {\n if (\n await enqueueOfflinePayload(\n transformed.payload,\n transformed.headers,\n transformed.contentType,\n )\n ) {\n return \"queued\";\n }\n throw error;\n }\n };\n\n const replayRetryDelay = (attempt: number): number => {\n const cap = Math.min(offlineReplayMaxDelayMs, offlineReplayBaseDelayMs * 2 ** attempt);\n return cap <= 0 ? 0 : random() * cap;\n };\n\n const sendOfflineEntryWithRetry = async (entry: BrowserHttpOfflineEntry) => {\n for (let attempt = 0; ; attempt++) {\n try {\n // oxlint-disable-next-line no-await-in-loop -- Retry attempts must run sequentially.\n await sendPayload(entry);\n incrementLoggerMetaCounter(\"transport.offline.replayed\");\n return;\n } catch (error) {\n if (attempt >= offlineReplayMaxRetries) {\n incrementLoggerMetaCounter(\"transport.offline.replay.failed\");\n throw error;\n }\n incrementLoggerMetaCounter(\"transport.offline.retry\");\n // oxlint-disable-next-line no-await-in-loop -- Backoff must complete before the next retry.\n await sleep(replayRetryDelay(attempt));\n }\n }\n };\n\n const replayOfflineQueue = (): Promise<void> => {\n if (!offlineQueue) return Promise.resolve();\n replayPromise ??= (async () => {\n try {\n await offlineQueue.replay(sendOfflineEntryWithRetry);\n } finally {\n replayPromise = undefined;\n }\n })();\n return replayPromise;\n };\n\n // Stored entries stay in the offline queue when replay fails, so a failed\n // replay is reported instead of failing the flush that triggered it.\n const replayOfflineQueueSafely = async (operation: string) => {\n if (!offlineQueue || !isOnline()) return;\n try {\n await replayOfflineQueue();\n } catch (error) {\n reportInternalError(error, operation);\n }\n };\n\n // Beacon submission is synchronous, even while an earlier Fetch is pending.\n // Only queued events are eligible; the active Fetch batch keeps its ownership.\n const flushBeaconQueue = () => {\n if (flushingBeacon || options.transformPayload || queue.length === 0) return;\n flushingBeacon = true;\n let pending = queue.splice(0, queue.length);\n try {\n const result = sendBeaconBatch(pending);\n pending = result.remaining;\n if (result.failure) throw result.failure.error;\n } finally {\n if (pending.length > 0) queue.unshift(...pending);\n flushingBeacon = false;\n }\n };\n\n const flush = (preferBeacon = false): Promise<void> => {\n if (activeFlush) {\n if (preferBeacon) {\n try {\n flushBeaconQueue();\n } catch (error) {\n // close() must still wait for the active delivery before reporting a Beacon error.\n return activeFlush.then(() => {\n throw error;\n });\n }\n }\n return activeFlush;\n }\n if (queue.length === 0) {\n // An explicit flush with nothing live still retries stored payloads, so\n // entries queued during a server outage do not wait for an `online` event.\n return preferBeacon ? Promise.resolve() : replayOfflineQueueSafely(\"replay\");\n }\n clearTimer();\n\n // Publish the task before invoking user codecs/transforms, which may reenter log().\n let resolve!: () => void;\n let reject!: (error: unknown) => void;\n const task = new Promise<void>((onResolve, onReject) => {\n resolve = onResolve;\n reject = onReject;\n });\n activeFlush = task;\n void (async () => {\n try {\n if (preferBeacon) flushBeaconQueue();\n let sent = false;\n let queued = false;\n while (queue.length > 0) {\n const batch = queue.splice(0, maxBatchSize);\n try {\n // oxlint-disable-next-line no-await-in-loop -- Preserve batch order and stop on the first unhandled failure.\n const outcome = await sendFetchBatch(batch);\n if (outcome === \"sent\") sent = true;\n else queued = true;\n } catch (error) {\n queue.unshift(...batch);\n throw error;\n }\n }\n // A live batch reached the collector and none fell back to the offline\n // queue, so the collector is reachable again: replay stored payloads.\n if (!preferBeacon && sent && !queued) await replayOfflineQueueSafely(\"replay\");\n resolve();\n } catch (error) {\n reject(error);\n } finally {\n activeFlush = undefined;\n if (queue.length > 0) schedule();\n }\n })();\n return task;\n };\n\n const schedule = () => {\n if (activeFlush || timer || flushIntervalMs <= 0) return;\n timer = setTimeout(() => {\n timer = undefined;\n void flush(false).catch((error: unknown) => reportInternalError(error, \"flush\"));\n }, flushIntervalMs);\n };\n\n const onPageHide = () => {\n void flush(true).catch((error: unknown) => reportInternalError(error, \"pagehide-flush\"));\n };\n const onVisibilityChange = () => {\n if (typeof document !== \"undefined\" && document.visibilityState === \"hidden\") {\n void flush(true).catch((error: unknown) => reportInternalError(error, \"visibility-flush\"));\n }\n };\n const onOnline = () => {\n void replayOfflineQueue().catch((error: unknown) => reportInternalError(error, \"replay\"));\n };\n\n if (options.useBeaconOnPageHide ?? true) {\n globalThis.addEventListener?.(\"pagehide\", onPageHide);\n globalThis.addEventListener?.(\"visibilitychange\", onVisibilityChange);\n }\n if (offlineQueue) {\n globalThis.addEventListener?.(\"online\", onOnline);\n // Payloads persisted by an earlier page load (for example in IndexedDB)\n // would otherwise wait for an `online` event that may never fire.\n if (options.offlineReplayOnStart ?? true) {\n setTimeout(() => void replayOfflineQueueSafely(\"startup-replay\"), 0);\n }\n }\n\n return {\n name: options.name ?? \"browser-http\",\n minLevel: options.minLevel,\n log(event, context) {\n if (options.minLevel !== undefined && event.level < toLevelValue(options.minLevel)) return;\n lastContext = context;\n if (queue.length >= maxQueueSize) {\n if (dropPolicy === \"drop-newest\") {\n reportDrop(event, \"queue-full\");\n return;\n }\n const dropped = queue.shift();\n if (dropped) reportDrop(dropped, \"queue-full\");\n }\n queue.push(event);\n if (activeFlush) return;\n if (queue.length >= maxBatchSize) {\n void flush(false).catch((error: unknown) => reportInternalError(error, \"flush\"));\n } else schedule();\n },\n flush() {\n return flush(false);\n },\n close() {\n globalThis.removeEventListener?.(\"pagehide\", onPageHide);\n globalThis.removeEventListener?.(\"visibilitychange\", onVisibilityChange);\n globalThis.removeEventListener?.(\"online\", onOnline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,OAAO,SAAS;GAClB,IAAI,QAAQ,aAAa,KAAA,KAAa,MAAM,SAAA,GAAA,eAAA,aAAA,CAAqB,QAAQ,QAAQ,GAAG;GACpF,cAAc;GACd,IAAI,MAAM,UAAU,cAAc;IAChC,IAAI,eAAe,eAAe;KAChC,WAAW,OAAO,YAAY;KAC9B;IACF;IACA,MAAM,UAAU,MAAM,MAAM;IAC5B,IAAI,SAAS,WAAW,SAAS,YAAY;GAC/C;GACA,MAAM,KAAK,KAAK;GAChB,IAAI,aAAa;GACjB,IAAI,MAAM,UAAU,cAClB,MAAW,KAAK,CAAC,CAAC,OAAO,UAAmB,oBAAoB,OAAO,OAAO,CAAC;QAC1E,SAAS;EAClB;EACA,QAAQ;GACN,OAAO,MAAM,KAAK;EACpB;EACA,QAAQ;GACN,WAAW,sBAAsB,YAAY,UAAU;GACvD,WAAW,sBAAsB,oBAAoB,kBAAkB;GACvE,WAAW,sBAAsB,UAAU,QAAQ;GACnD,OAAO,MAAM,IAAI;EACnB;CACF;AACF"}
|
package/dist/http-transport.d.ts
CHANGED
|
@@ -39,6 +39,7 @@ export interface BrowserHttpTransportOptions {
|
|
|
39
39
|
offlineReplayMaxRetries?: number;
|
|
40
40
|
offlineReplayBaseDelayMs?: number;
|
|
41
41
|
offlineReplayMaxDelayMs?: number;
|
|
42
|
+
offlineReplayOnStart?: boolean;
|
|
42
43
|
random?: () => number;
|
|
43
44
|
fetchFn?: typeof fetch;
|
|
44
45
|
transformPayload?: PayloadTransform | readonly PayloadTransform[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-transport.d.ts","sourceRoot":"","sources":["../src/http-transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,KAAK,EAEV,KAAK,QAAQ,EACb,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,SAAS,EAEf,MAAM,gBAAgB,CAAC;AAExB,MAAM,MAAM,qBAAqB,GAAG,aAAa,GAAG,aAAa,CAAC;AAO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