@visulima/pail 3.1.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/LICENSE.md +1 -408
  3. package/README.md +298 -0
  4. package/dist/index.browser.d.ts +3 -3
  5. package/dist/index.browser.js +12 -1
  6. package/dist/index.server.d.ts +8 -5
  7. package/dist/index.server.js +535 -2
  8. package/dist/interactive/index.js +2 -1
  9. package/dist/object-tree.js +89 -2
  10. package/dist/packem_shared/AbstractJsonReporter-intFdT_A.js +204 -0
  11. package/dist/packem_shared/InteractiveManager-CZ85hGNW.js +172 -0
  12. package/dist/packem_shared/InteractiveStreamHook-DiSubbJ1.js +21 -0
  13. package/dist/packem_shared/JsonReporter-BqWsVkHP.js +60 -0
  14. package/dist/packem_shared/JsonReporter-DcM2LBX9.js +28 -0
  15. package/dist/packem_shared/PrettyReporter-BFWaYP_J.js +222 -0
  16. package/dist/packem_shared/PrettyReporter-CuLLKr6-.js +169 -0
  17. package/dist/packem_shared/{abstract-json-reporter-CPsNkpz8.d.ts → abstract-json-reporter-DiyVyU0j.d.ts} +1 -1
  18. package/dist/packem_shared/{abstract-pretty-reporter-DB2G-qlI.d.ts → abstract-pretty-reporter-BbOWXMCs.d.ts} +1 -1
  19. package/dist/packem_shared/abstract-pretty-reporter-DMPDCslJ.js +50 -0
  20. package/dist/packem_shared/constants-DfDr4MHC.js +119 -0
  21. package/dist/packem_shared/format-label-Btft2KGP.js +1194 -0
  22. package/dist/packem_shared/get-longest-label-C9PWeyKq.js +9 -0
  23. package/dist/packem_shared/index-BomQ3E6J.js +650 -0
  24. package/dist/packem_shared/index-DqKWykfa.js +1146 -0
  25. package/dist/packem_shared/interactive-stream-hook-DG4BtN12.js +141 -0
  26. package/dist/packem_shared/{pail.browser-CmWcqnn9.d.ts → pail.browser-By9KjOH7.d.ts} +8 -3
  27. package/dist/packem_shared/pail.browser-CPDOE_d1.js +1427 -0
  28. package/dist/packem_shared/{types-DVzG8TWL.d.ts → types-D3ycu8-x.d.ts} +1 -1
  29. package/dist/packem_shared/write-console-log-based-on-level-DBmRYXpj.js +14 -0
  30. package/dist/packem_shared/write-stream-BG8fhcs3.js +6 -0
  31. package/dist/processor/caller/caller-processor.d.ts +1 -1
  32. package/dist/processor/caller/caller-processor.js +59 -1
  33. package/dist/processor/message-formatter-processor.d.ts +1 -1
  34. package/dist/processor/message-formatter-processor.js +67 -1
  35. package/dist/processor/opentelemetry-processor.d.ts +19 -0
  36. package/dist/processor/opentelemetry-processor.js +52 -0
  37. package/dist/processor/redact-processor.d.ts +1 -1
  38. package/dist/processor/redact-processor.js +30 -1
  39. package/dist/progress-bar.js +404 -1
  40. package/dist/reporter/file/json-file-reporter.d.ts +2 -2
  41. package/dist/reporter/file/json-file-reporter.js +136 -4
  42. package/dist/reporter/http/abstract-http-reporter.d.ts +102 -0
  43. package/dist/reporter/http/abstract-http-reporter.js +435 -0
  44. package/dist/reporter/http/http-reporter.d.ts +13 -0
  45. package/dist/reporter/http/http-reporter.edge-light.d.ts +168 -0
  46. package/dist/reporter/http/http-reporter.edge-light.js +651 -0
  47. package/dist/reporter/http/http-reporter.js +13 -0
  48. package/dist/reporter/json/index.browser.d.ts +2 -2
  49. package/dist/reporter/json/index.browser.js +2 -1
  50. package/dist/reporter/json/index.d.ts +2 -2
  51. package/dist/reporter/json/index.js +2 -1
  52. package/dist/reporter/pretty/index.browser.d.ts +2 -2
  53. package/dist/reporter/pretty/index.browser.js +1 -1
  54. package/dist/reporter/pretty/index.d.ts +2 -2
  55. package/dist/reporter/pretty/index.js +1 -1
  56. package/dist/reporter/simple/simple-reporter.server.d.ts +2 -2
  57. package/dist/reporter/simple/simple-reporter.server.js +186 -8
  58. package/dist/spinner.js +2150 -1
  59. package/package.json +53 -3
  60. package/dist/packem_shared/AbstractJsonReporter-UftN6CIL.js +0 -1
  61. package/dist/packem_shared/InteractiveManager-CgmJyW9x.js +0 -3
  62. package/dist/packem_shared/InteractiveStreamHook-NtJu71aN.js +0 -1
  63. package/dist/packem_shared/JsonReporter-DTBtHNaD.js +0 -2
  64. package/dist/packem_shared/JsonReporter-Dl4m0xZe.js +0 -1
  65. package/dist/packem_shared/PrettyReporter-Bns0ZWLy.js +0 -12
  66. package/dist/packem_shared/PrettyReporter-CGKSTI7X.js +0 -5
  67. package/dist/packem_shared/abstract-pretty-reporter-CUtSm20r.js +0 -1
  68. package/dist/packem_shared/constants-DKfCaSUR.js +0 -1
  69. package/dist/packem_shared/format-label-CpyyTBom.js +0 -26
  70. package/dist/packem_shared/get-longest-label-B0NrI-o2.js +0 -1
  71. package/dist/packem_shared/index-CysYvHXs.js +0 -8
  72. package/dist/packem_shared/index-D9hWq9ka.js +0 -1
  73. package/dist/packem_shared/interactive-stream-hook-CeVo4Kth.js +0 -2
  74. package/dist/packem_shared/pail.browser-BmHoDvEA.js +0 -19
  75. package/dist/packem_shared/write-console-log-based-on-level-BP95fgQZ.js +0 -1
  76. package/dist/packem_shared/write-stream-CD8XFv1L.js +0 -1
@@ -0,0 +1,435 @@
1
+ import { createRequire as __cjs_createRequire } from "node:module";
2
+
3
+ const __cjs_require = __cjs_createRequire(import.meta.url);
4
+
5
+ const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
6
+
7
+ const __cjs_getBuiltinModule = (module) => {
8
+ // Check if we're in Node.js and version supports getBuiltinModule
9
+ if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
10
+ const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
11
+ // Node.js 20.16.0+ and 22.3.0+
12
+ if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
13
+ return __cjs_getProcess.getBuiltinModule(module);
14
+ }
15
+ }
16
+ // Fallback to createRequire
17
+ return __cjs_require(module);
18
+ };
19
+
20
+ const {
21
+ Buffer
22
+ } = __cjs_getBuiltinModule("node:buffer");
23
+ import { AbstractJsonReporter } from '../../packem_shared/AbstractJsonReporter-intFdT_A.js';
24
+ const {
25
+ gzipSync
26
+ } = __cjs_getBuiltinModule("node:zlib");
27
+
28
+ const compressData = async (data) => {
29
+ const CompressionStreamClass = globalThis.CompressionStream;
30
+ if (CompressionStreamClass) {
31
+ const stream = new CompressionStreamClass("gzip");
32
+ const writer = stream.writable.getWriter();
33
+ const reader = stream.readable.getReader();
34
+ const encoder = new TextEncoder();
35
+ const chunks = [];
36
+ writer.write(encoder.encode(data));
37
+ writer.close();
38
+ let done = false;
39
+ while (!done) {
40
+ const result2 = await reader.read();
41
+ done = result2.done ?? false;
42
+ if (result2.value) {
43
+ chunks.push(result2.value);
44
+ }
45
+ }
46
+ const totalLength = chunks.reduce((accumulator, chunk) => accumulator + chunk.length, 0);
47
+ const result = new Uint8Array(totalLength);
48
+ let offset = 0;
49
+ for (const chunk of chunks) {
50
+ result.set(chunk, offset);
51
+ offset += chunk.length;
52
+ }
53
+ return result;
54
+ }
55
+ return gzipSync(data);
56
+ };
57
+
58
+ class LogSizeError extends Error {
59
+ /**
60
+ * The log entry data that caused the error
61
+ */
62
+ logData;
63
+ /**
64
+ * The actual size of the log entry in bytes
65
+ */
66
+ actualSize;
67
+ /**
68
+ * The maximum allowed size in bytes
69
+ */
70
+ maxSize;
71
+ /**
72
+ * Creates a new LogSizeError instance.
73
+ * @param message Descriptive error message explaining the size violation
74
+ * @param logData The log entry data that caused the error
75
+ * @param actualSize Size of the log entry in bytes
76
+ * @param maxSize Maximum allowed size in bytes
77
+ * @example
78
+ * ```typescript
79
+ * throw new LogSizeError("Log too large", logData, 2000000, 1000000);
80
+ * ```
81
+ */
82
+ constructor(message, logData, actualSize, maxSize) {
83
+ super(message);
84
+ this.name = "LogSizeError";
85
+ this.logData = logData;
86
+ this.actualSize = actualSize;
87
+ this.maxSize = maxSize;
88
+ }
89
+ }
90
+
91
+ const calculateBackoffDelay = (baseDelay, attempt) => baseDelay * 2 ** attempt;
92
+ const sleep = (delay) => new Promise((resolve) => {
93
+ setTimeout(resolve, delay);
94
+ });
95
+ const prepareRequestBody = (body) => {
96
+ if (typeof body === "string") {
97
+ return body;
98
+ }
99
+ return new Uint8Array(body.buffer, body.byteOffset, body.byteLength);
100
+ };
101
+ const processResponse = async (response, url, method, headers, body, onDebugRequestResponse, onError) => {
102
+ const responseHeaders = {};
103
+ response.headers.forEach((value, key) => {
104
+ responseHeaders[key] = value;
105
+ });
106
+ const responseBody = await response.text();
107
+ const requestResponse = {
108
+ req: {
109
+ body,
110
+ headers,
111
+ method,
112
+ url
113
+ },
114
+ res: {
115
+ body: responseBody,
116
+ headers: responseHeaders,
117
+ status: response.status,
118
+ statusText: response.statusText
119
+ }
120
+ };
121
+ if (onDebugRequestResponse) {
122
+ onDebugRequestResponse(requestResponse);
123
+ }
124
+ if (response.ok) {
125
+ return false;
126
+ }
127
+ if (response.status < 500 && response.status !== 429) {
128
+ const error = new Error(`HTTP ${response.status}: ${response.statusText}`);
129
+ if (onError) {
130
+ onError(error);
131
+ }
132
+ throw error;
133
+ }
134
+ return true;
135
+ };
136
+ const handleRateLimit = (response, respectRateLimit, retryDelay, attempt, maxRetries) => {
137
+ if (response.status === 429 && respectRateLimit && attempt < maxRetries) {
138
+ const retryAfter = response.headers.get("retry-after");
139
+ return retryAfter ? Number.parseInt(retryAfter, 10) * 1e3 : calculateBackoffDelay(retryDelay, attempt);
140
+ }
141
+ return void 0;
142
+ };
143
+ const handleServerError = (response, retryDelay, attempt, maxRetries) => {
144
+ if (response.status >= 500 && attempt < maxRetries) {
145
+ return calculateBackoffDelay(retryDelay, attempt);
146
+ }
147
+ return void 0;
148
+ };
149
+ const calculateRetryDelay = (response, respectRateLimit, retryDelay, attempt, maxRetries) => {
150
+ const rateLimitDelay = handleRateLimit(response, respectRateLimit, retryDelay, attempt, maxRetries);
151
+ if (rateLimitDelay !== void 0) {
152
+ return rateLimitDelay;
153
+ }
154
+ return handleServerError(response, retryDelay, attempt, maxRetries);
155
+ };
156
+ const handleRetryError = async (error, attempt, maxRetries, retryDelay, onError) => {
157
+ if (attempt < maxRetries) {
158
+ const delay = calculateBackoffDelay(retryDelay, attempt);
159
+ await sleep(delay);
160
+ return true;
161
+ }
162
+ if (onError) {
163
+ onError(error);
164
+ }
165
+ return false;
166
+ };
167
+ const sendWithRetry = async (url, method, headers, body, maxRetries, retryDelay, respectRateLimit, onDebugRequestResponse, onError) => {
168
+ let attempt = 0;
169
+ while (attempt <= maxRetries) {
170
+ try {
171
+ const requestBody = prepareRequestBody(body);
172
+ const response = await fetch(url, {
173
+ body: requestBody,
174
+ headers,
175
+ method
176
+ });
177
+ const shouldRetry = await processResponse(response, url, method, headers, body, onDebugRequestResponse, onError);
178
+ if (!shouldRetry) {
179
+ return;
180
+ }
181
+ const retryDelayValue = calculateRetryDelay(response, respectRateLimit, retryDelay, attempt, maxRetries);
182
+ if (retryDelayValue !== void 0) {
183
+ await sleep(retryDelayValue);
184
+ attempt += 1;
185
+ continue;
186
+ }
187
+ if (!response.ok) {
188
+ const error = new Error(`HTTP ${response.status}: ${response.statusText}`);
189
+ if (onError) {
190
+ onError(error);
191
+ }
192
+ throw error;
193
+ }
194
+ return;
195
+ } catch (error) {
196
+ const shouldRetry = await handleRetryError(error, attempt, maxRetries, retryDelay, onError);
197
+ if (shouldRetry) {
198
+ attempt += 1;
199
+ continue;
200
+ }
201
+ throw error;
202
+ }
203
+ }
204
+ };
205
+
206
+ class AbstractHttpReporter extends AbstractJsonReporter {
207
+ url;
208
+ method;
209
+ headers;
210
+ contentType;
211
+ batchContentType;
212
+ onError;
213
+ onDebug;
214
+ onDebugRequestResponse;
215
+ payloadTemplate;
216
+ compression;
217
+ maxRetries;
218
+ retryDelay;
219
+ respectRateLimit;
220
+ enableBatchSend;
221
+ batchSize;
222
+ batchSendTimeout;
223
+ batchSendDelimiter;
224
+ batchMode;
225
+ batchFieldName;
226
+ maxLogSize;
227
+ maxPayloadSize;
228
+ edgeCompat;
229
+ // Batch management
230
+ batchQueue = [];
231
+ batchTimeout;
232
+ isProcessingBatch = false;
233
+ currentBatchSize = 0;
234
+ // Track uncompressed size of current batch
235
+ /**
236
+ * Creates a new instance of AbstractHttpReporter.
237
+ * @param config Configuration options for the reporter
238
+ */
239
+ constructor(config) {
240
+ super(config);
241
+ this.url = config.url;
242
+ this.method = config.method ?? "POST";
243
+ this.headers = config.headers ?? {};
244
+ this.contentType = config.contentType ?? "application/json";
245
+ this.batchContentType = config.batchContentType ?? "application/json";
246
+ this.onError = config.onError;
247
+ this.onDebug = config.onDebug;
248
+ this.onDebugRequestResponse = config.onDebugRequestResponse;
249
+ this.payloadTemplate = config.payloadTemplate ?? ((data) => JSON.stringify(data));
250
+ this.compression = config.compression ?? false;
251
+ this.maxRetries = config.maxRetries ?? 3;
252
+ this.retryDelay = config.retryDelay ?? 1e3;
253
+ this.respectRateLimit = config.respectRateLimit ?? true;
254
+ this.enableBatchSend = config.enableBatchSend ?? true;
255
+ this.batchSize = config.batchSize ?? 100;
256
+ this.batchSendTimeout = config.batchSendTimeout ?? 5e3;
257
+ this.batchSendDelimiter = config.batchSendDelimiter ?? "\n";
258
+ this.batchMode = config.batchMode ?? "delimiter";
259
+ this.batchFieldName = config.batchFieldName;
260
+ if (this.batchMode === "field" && !this.batchFieldName) {
261
+ throw new Error("batchFieldName is required when batchMode is 'field'");
262
+ }
263
+ this.maxLogSize = config.maxLogSize ?? 1048576;
264
+ this.maxPayloadSize = config.maxPayloadSize ?? 5242880;
265
+ this.edgeCompat = config.edgeCompat ?? false;
266
+ }
267
+ /**
268
+ * Processes and ships log entries to the HTTP endpoint.
269
+ * @param message The JSON-formatted log message
270
+ * @param logLevel The log level of the message
271
+ * @protected
272
+ */
273
+ // eslint-disable-next-line no-underscore-dangle
274
+ _log(message, logLevel) {
275
+ try {
276
+ const logData = JSON.parse(message);
277
+ const logLevelString = logLevel;
278
+ const messageString = logData.message;
279
+ const payloadTemplate = {
280
+ logLevel: logLevelString,
281
+ message: messageString ?? ""
282
+ };
283
+ if (logData.data) {
284
+ payloadTemplate["data"] = logData.data;
285
+ } else if (logData.context) {
286
+ payloadTemplate["data"] = logData.context;
287
+ } else {
288
+ const rest = { ...logData };
289
+ delete rest.message;
290
+ if (Object.keys(rest).length > 0) {
291
+ payloadTemplate["data"] = rest;
292
+ }
293
+ }
294
+ const payload = this.payloadTemplate(payloadTemplate);
295
+ if (this.onDebug) {
296
+ this.onDebug({ data: payloadTemplate.data, logLevel: logLevelString, message: messageString });
297
+ }
298
+ const logEntrySize = this.edgeCompat || typeof TextEncoder === "undefined" ? Buffer.byteLength(payload, "utf8") : new TextEncoder().encode(payload).length;
299
+ if (logEntrySize > this.maxLogSize) {
300
+ const error = new LogSizeError(
301
+ `Log entry exceeds maximum size of ${this.maxLogSize} bytes. Size: ${logEntrySize} bytes`,
302
+ { data: payloadTemplate.data, logLevel: logLevelString, message: messageString },
303
+ logEntrySize,
304
+ this.maxLogSize
305
+ );
306
+ if (this.onError) {
307
+ this.onError(error);
308
+ }
309
+ return;
310
+ }
311
+ if (this.enableBatchSend) {
312
+ this.addToBatch(payload, logEntrySize);
313
+ } else {
314
+ this.sendPayload(payload).catch((error) => {
315
+ if (this.onError) {
316
+ this.onError(error);
317
+ }
318
+ });
319
+ }
320
+ } catch (error) {
321
+ if (this.onError) {
322
+ this.onError(error);
323
+ }
324
+ }
325
+ }
326
+ /**
327
+ * Adds a payload to the batch queue and triggers sending if conditions are met.
328
+ */
329
+ addToBatch(payload, logEntrySize) {
330
+ const payloadSizeWithEntry = this.currentBatchSize + logEntrySize + this.batchSendDelimiter.length;
331
+ const payloadSizeThreshold = this.maxPayloadSize * 0.9;
332
+ if (payloadSizeWithEntry > payloadSizeThreshold && this.batchQueue.length > 0) {
333
+ this.processBatch();
334
+ }
335
+ this.batchQueue.push(payload);
336
+ this.currentBatchSize += logEntrySize + this.batchSendDelimiter.length;
337
+ if (!this.batchTimeout) {
338
+ this.batchTimeout = setTimeout(() => {
339
+ this.processBatch();
340
+ }, this.batchSendTimeout);
341
+ }
342
+ if (this.batchQueue.length >= this.batchSize) {
343
+ this.processBatch();
344
+ }
345
+ }
346
+ /**
347
+ * Processes the current batch and sends it to the HTTP endpoint.
348
+ */
349
+ async processBatch() {
350
+ if (this.isProcessingBatch || this.batchQueue.length === 0) {
351
+ return;
352
+ }
353
+ this.isProcessingBatch = true;
354
+ if (this.batchTimeout) {
355
+ clearTimeout(this.batchTimeout);
356
+ this.batchTimeout = void 0;
357
+ }
358
+ const batch = this.batchQueue.splice(0, this.batchSize);
359
+ this.currentBatchSize = 0;
360
+ for (let i = 0; i < this.batchQueue.length; i += 1) {
361
+ const payload = this.batchQueue[i];
362
+ const payloadSize = this.edgeCompat || typeof TextEncoder === "undefined" ? Buffer.byteLength(payload, "utf8") : new TextEncoder().encode(payload).length;
363
+ this.currentBatchSize += payloadSize + (i < this.batchQueue.length - 1 ? this.batchSendDelimiter.length : 0);
364
+ }
365
+ try {
366
+ await this.sendBatch(batch);
367
+ } catch (error) {
368
+ if (this.onError) {
369
+ this.onError(error);
370
+ }
371
+ } finally {
372
+ this.isProcessingBatch = false;
373
+ if (this.batchQueue.length > 0) {
374
+ this.processBatch();
375
+ }
376
+ }
377
+ }
378
+ /**
379
+ * Sends a batch of payloads to the HTTP endpoint.
380
+ */
381
+ async sendBatch(batch) {
382
+ let batchPayload;
383
+ switch (this.batchMode) {
384
+ case "array": {
385
+ const batchEntries = batch.map((payload) => JSON.parse(payload));
386
+ batchPayload = JSON.stringify(batchEntries);
387
+ break;
388
+ }
389
+ case "field": {
390
+ const fieldEntries = batch.map((payload) => JSON.parse(payload));
391
+ const batchObject = this.batchFieldName ? { [this.batchFieldName]: fieldEntries } : {};
392
+ batchPayload = JSON.stringify(batchObject);
393
+ break;
394
+ }
395
+ default: {
396
+ batchPayload = batch.join(this.batchSendDelimiter);
397
+ break;
398
+ }
399
+ }
400
+ await this.sendPayload(batchPayload, this.batchContentType);
401
+ }
402
+ /**
403
+ * Sends a single payload to the HTTP endpoint.
404
+ */
405
+ async sendPayload(payload, contentType) {
406
+ const headers = typeof this.headers === "function" ? this.headers() : { ...this.headers };
407
+ if (!headers["content-type"]) {
408
+ headers["content-type"] = contentType ?? this.contentType;
409
+ }
410
+ let finalPayload = payload;
411
+ if (this.compression && !this.edgeCompat) {
412
+ try {
413
+ finalPayload = await compressData(payload);
414
+ headers["content-encoding"] = "gzip";
415
+ } catch (error) {
416
+ if (this.onError) {
417
+ this.onError(new Error(`Compression failed: ${error}`));
418
+ }
419
+ }
420
+ }
421
+ await sendWithRetry(
422
+ this.url,
423
+ this.method,
424
+ headers,
425
+ finalPayload,
426
+ this.maxRetries,
427
+ this.retryDelay,
428
+ this.respectRateLimit,
429
+ this.onDebugRequestResponse,
430
+ this.onError
431
+ );
432
+ }
433
+ }
434
+
435
+ export { AbstractHttpReporter };
@@ -0,0 +1,13 @@
1
+ import { AbstractHttpReporter, AbstractHttpReporterOptions } from './abstract-http-reporter.js';
2
+ import 'type-fest';
3
+ import '../../packem_shared/types-D3ycu8-x.js';
4
+ import '@visulima/colorize';
5
+ import '../../interactive/index.js';
6
+ import '../../packem_shared/abstract-json-reporter-DiyVyU0j.js';
7
+ import '../../packem_shared/index.d-oxZvg_y7.js';
8
+
9
+ declare class HttpReporter<L extends string = string> extends AbstractHttpReporter<L> {
10
+ constructor(options: AbstractHttpReporterOptions);
11
+ }
12
+
13
+ export { HttpReporter as default };
@@ -0,0 +1,168 @@
1
+ import { Primitive, LiteralUnion } from 'type-fest';
2
+
3
+ declare global {
4
+ namespace VisulimaPail {
5
+ interface CustomMeta<L> {
6
+ }
7
+ }
8
+ }
9
+ interface Meta<L> extends VisulimaPail.CustomMeta<L> {
10
+ badge: string | undefined;
11
+ context: any[] | undefined;
12
+ date: Date | string;
13
+ error: Error | undefined;
14
+ groups: string[];
15
+ label: string | undefined;
16
+ message: Primitive | ReadonlyArray<unknown> | Record<PropertyKey, unknown>;
17
+ prefix: string | undefined;
18
+ repeated?: number | undefined;
19
+ scope: string[] | undefined;
20
+ suffix: string | undefined;
21
+ traceError: Error | undefined;
22
+ type: {
23
+ level: ExtendedRfc5424LogLevels | L;
24
+ name: string;
25
+ };
26
+ }
27
+ type ExtendedRfc5424LogLevels = "alert" | "critical" | "debug" | "emergency" | "error" | "informational" | "notice" | "trace" | "warning";
28
+ type ReadonlyMeta<L extends string> = Readonly<Meta<L>>;
29
+ interface Reporter<L extends string> {
30
+ log: (meta: ReadonlyMeta<L>) => void;
31
+ }
32
+ interface StringifyAwareReporter<L extends string> extends Reporter<L> {
33
+ setStringify: (stringify: typeof JSON.stringify) => void;
34
+ }
35
+
36
+ type Replacer = (number | string)[] | null | undefined | ((key: string, value: unknown) => string | number | boolean | null | object)
37
+
38
+ interface StringifyOptions {
39
+ bigint?: boolean,
40
+ circularValue?: string | null | TypeErrorConstructor | ErrorConstructor,
41
+ deterministic?: boolean | ((a: string, b: string) => number),
42
+ maximumBreadth?: number,
43
+ maximumDepth?: number,
44
+ strict?: boolean,
45
+ }
46
+
47
+ declare function stringify(value: undefined | symbol | ((...args: unknown[]) => unknown), replacer?: Replacer, space?: string | number): undefined
48
+ declare function stringify(value: string | number | unknown[] | null | boolean | object, replacer?: Replacer, space?: string | number): string
49
+ declare function stringify(value: unknown, replacer?: ((key: string, value: unknown) => unknown) | (number | string)[] | null | undefined, space?: string | number): string | undefined
50
+
51
+ declare namespace stringify {
52
+ export function configure(options: StringifyOptions): typeof stringify
53
+ }
54
+
55
+ type AbstractJsonReporterOptions = {
56
+ error: Partial<{
57
+ exclude?: string[];
58
+ maxDepth?: number;
59
+ useToJSON?: boolean;
60
+ }>;
61
+ };
62
+ declare abstract class AbstractJsonReporter<L extends string = string> implements StringifyAwareReporter<L> {
63
+ protected stringify: typeof stringify | undefined;
64
+ protected errorOptions: AbstractJsonReporterOptions["error"];
65
+ constructor(options?: Partial<AbstractJsonReporterOptions>);
66
+ setStringify(function_: any): void;
67
+ log(meta: ReadonlyMeta<L>): void;
68
+ protected abstract _log(message: string, logLevel: LiteralUnion<ExtendedRfc5424LogLevels, L>): void;
69
+ }
70
+
71
+ type AbstractHttpReporterOptions = AbstractJsonReporterOptions & {
72
+ batchContentType?: string;
73
+ batchFieldName?: string;
74
+ batchMode?: "delimiter" | "field" | "array";
75
+ batchSendDelimiter?: string;
76
+ batchSendTimeout?: number;
77
+ batchSize?: number;
78
+ compression?: boolean;
79
+ contentType?: string;
80
+ edgeCompat?: boolean;
81
+ enableBatchSend?: boolean;
82
+ headers?: Record<string, string> | (() => Record<string, string>);
83
+ maxLogSize?: number;
84
+ maxPayloadSize?: number;
85
+ maxRetries?: number;
86
+ method?: string;
87
+ onDebug?: (entry: Record<string, unknown>) => void;
88
+ onDebugRequestResponse?: (requestResponse: {
89
+ req: {
90
+ body: string | Uint8Array;
91
+ headers: Record<string, string>;
92
+ method: string;
93
+ url: string;
94
+ };
95
+ res: {
96
+ body: string;
97
+ headers: Record<string, string>;
98
+ status: number;
99
+ statusText: string;
100
+ };
101
+ }) => void;
102
+ onError?: (error: Error) => void;
103
+ payloadTemplate?: (data: {
104
+ data?: Record<string, unknown>;
105
+ logLevel: string;
106
+ message: string;
107
+ }) => string;
108
+ respectRateLimit?: boolean;
109
+ retryDelay?: number;
110
+ url: string;
111
+ };
112
+ declare abstract class AbstractHttpReporter<L extends string = string> extends AbstractJsonReporter<L> implements StringifyAwareReporter<L> {
113
+ protected url: string;
114
+ protected method: string;
115
+ protected headers: Record<string, string> | (() => Record<string, string>);
116
+ protected contentType: string;
117
+ protected batchContentType: string;
118
+ protected onError?: (error: Error) => void;
119
+ protected onDebug?: (entry: Record<string, unknown>) => void;
120
+ protected onDebugRequestResponse?: (requestResponse: {
121
+ req: {
122
+ body: string | Uint8Array;
123
+ headers: Record<string, string>;
124
+ method: string;
125
+ url: string;
126
+ };
127
+ res: {
128
+ body: string;
129
+ headers: Record<string, string>;
130
+ status: number;
131
+ statusText: string;
132
+ };
133
+ }) => void;
134
+ protected payloadTemplate: (data: {
135
+ data?: Record<string, unknown>;
136
+ logLevel: string;
137
+ message: string;
138
+ }) => string;
139
+ protected compression: boolean;
140
+ protected maxRetries: number;
141
+ protected retryDelay: number;
142
+ protected respectRateLimit: boolean;
143
+ protected enableBatchSend: boolean;
144
+ protected batchSize: number;
145
+ protected batchSendTimeout: number;
146
+ protected batchSendDelimiter: string;
147
+ protected batchMode: "delimiter" | "field" | "array";
148
+ protected batchFieldName?: string;
149
+ protected maxLogSize: number;
150
+ protected maxPayloadSize: number;
151
+ protected edgeCompat: boolean;
152
+ protected batchQueue: string[];
153
+ protected batchTimeout?: ReturnType<typeof setTimeout>;
154
+ protected isProcessingBatch: boolean;
155
+ protected currentBatchSize: number;
156
+ constructor(config: AbstractHttpReporterOptions);
157
+ protected _log(message: string, logLevel: LiteralUnion<ExtendedRfc5424LogLevels, L>): void;
158
+ protected addToBatch(payload: string, logEntrySize: number): void;
159
+ protected processBatch(): Promise<void>;
160
+ protected sendBatch(batch: string[]): Promise<void>;
161
+ protected sendPayload(payload: string, contentType?: string): Promise<void>;
162
+ }
163
+
164
+ declare class HttpReporterEdgeLight<L extends string = string> extends AbstractHttpReporter<L> {
165
+ constructor(options: Omit<AbstractHttpReporterOptions, "edgeCompat">);
166
+ }
167
+
168
+ export { HttpReporterEdgeLight as default };