@visulima/pail 4.0.0-alpha.9 → 4.0.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 (145) hide show
  1. package/CHANGELOG.md +511 -0
  2. package/LICENSE.md +270 -166
  3. package/README.md +53 -24
  4. package/dist/error.d.ts +95 -96
  5. package/dist/error.js +5 -76
  6. package/dist/index.browser.d.ts +568 -47
  7. package/dist/index.browser.js +19 -1499
  8. package/dist/index.server.d.ts +749 -65
  9. package/dist/index.server.js +32 -3179
  10. package/dist/middleware/elysia.d.ts +66 -63
  11. package/dist/middleware/elysia.js +1 -70
  12. package/dist/middleware/express.d.ts +74 -71
  13. package/dist/middleware/express.js +1 -29
  14. package/dist/middleware/fastify.d.ts +70 -67
  15. package/dist/middleware/fastify.js +1 -46
  16. package/dist/middleware/hono.d.ts +75 -72
  17. package/dist/middleware/hono.js +1 -33
  18. package/dist/middleware/next/handler.d.ts +102 -34
  19. package/dist/middleware/next/handler.js +1 -53
  20. package/dist/middleware/sveltekit.d.ts +101 -98
  21. package/dist/middleware/sveltekit.js +1 -43
  22. package/dist/object-tree.d.ts +67 -70
  23. package/dist/object-tree.js +2 -89
  24. package/dist/packem_shared/AbstractJsonReporter-Bp_JCrMQ.js +1 -0
  25. package/dist/packem_shared/AbstractJsonReporter-w_bGGiD-.js +1 -0
  26. package/dist/packem_shared/JsonReporter-Sd_lJGS-.js +2 -0
  27. package/dist/packem_shared/JsonReporter-bmem9lcg.js +1 -0
  28. package/dist/packem_shared/PailError-CbU1Ogfa.js +5 -0
  29. package/dist/packem_shared/PrettyReporter-CcDdPQSt.js +44 -0
  30. package/dist/packem_shared/PrettyReporter-DsHfKOU7.js +5 -0
  31. package/dist/packem_shared/abstract-json-reporter.d-wfESoEa-.d.ts +62 -0
  32. package/dist/packem_shared/abstract-pretty-reporter-DrLBJ6ds.js +57 -0
  33. package/dist/packem_shared/addKnownErrorConstructor-C1OJTj2D-0FlJMfXz.js +25 -0
  34. package/dist/packem_shared/constants-DKfCaSUR.js +1 -0
  35. package/dist/packem_shared/constants-ep2nsfdy.js +1 -0
  36. package/dist/packem_shared/create-middleware-logger.d-B-JmQ1Sl.d.ts +47 -0
  37. package/dist/packem_shared/headers-DH0H2s8W.js +1 -0
  38. package/dist/packem_shared/index-Q1764hvO.js +1 -0
  39. package/dist/packem_shared/index.d-T71KjNAr.d.ts +16 -0
  40. package/dist/packem_shared/pailMiddleware-B5DJoBYl.js +1 -0
  41. package/dist/packem_shared/serializeError-C-NFvZ8_-D0CA_Qlx.js +1 -0
  42. package/dist/packem_shared/storage-DaXAlpiO.js +1 -0
  43. package/dist/packem_shared/types.d-Cz9S7jZh.d.ts +201 -0
  44. package/dist/packem_shared/types.d-bWnqHJKL.d.ts +211 -0
  45. package/dist/packem_shared/types.d-xxE3FOD3.d.ts +229 -0
  46. package/dist/packem_shared/useLogger-DB34CuU5.js +1 -0
  47. package/dist/packem_shared/wide-event.d-D3ATYpoK.d.ts +717 -0
  48. package/dist/packem_shared/write-console-log-based-on-level-BqjxV016.js +1 -0
  49. package/dist/packem_shared/write-stream-C7jxLxIT.js +1 -0
  50. package/dist/processor/caller/caller-processor.d.ts +50 -47
  51. package/dist/processor/caller/caller-processor.js +1 -59
  52. package/dist/processor/environment-processor.d.ts +114 -113
  53. package/dist/processor/environment-processor.js +1 -78
  54. package/dist/processor/message-formatter-processor.d.ts +59 -49
  55. package/dist/processor/message-formatter-processor.js +1 -713
  56. package/dist/processor/opentelemetry-processor.d.ts +70 -66
  57. package/dist/processor/opentelemetry-processor.js +1 -52
  58. package/dist/processor/redact-processor.d.ts +99 -41
  59. package/dist/processor/redact-processor.js +1 -30
  60. package/dist/processor/sampling-processor.d.ts +103 -101
  61. package/dist/processor/sampling-processor.js +1 -59
  62. package/dist/reporter/file/json-file-reporter.d.ts +109 -42
  63. package/dist/reporter/file/json-file-reporter.js +2 -136
  64. package/dist/reporter/http/abstract-http-reporter.d.ts +256 -211
  65. package/dist/reporter/http/abstract-http-reporter.js +2 -435
  66. package/dist/reporter/http/http-reporter.d.ts +41 -36
  67. package/dist/reporter/http/http-reporter.edge-light.d.ts +487 -39
  68. package/dist/reporter/http/http-reporter.edge-light.js +2 -733
  69. package/dist/reporter/http/http-reporter.js +1 -13
  70. package/dist/reporter/json/index.browser.d.ts +98 -3
  71. package/dist/reporter/json/index.browser.js +1 -2
  72. package/dist/reporter/json/index.d.ts +53 -3
  73. package/dist/reporter/json/index.js +1 -2
  74. package/dist/reporter/pretty/index.browser.d.ts +105 -2
  75. package/dist/reporter/pretty/index.browser.js +1 -1
  76. package/dist/reporter/pretty/index.d.ts +270 -2
  77. package/dist/reporter/pretty/index.js +1 -1
  78. package/dist/reporter/simple/simple-reporter.server.d.ts +215 -18
  79. package/dist/reporter/simple/simple-reporter.server.js +8 -182
  80. package/dist/wide-event.d.ts +6 -300
  81. package/dist/wide-event.js +1 -281
  82. package/package.json +22 -37
  83. package/dist/constants.d.ts +0 -37
  84. package/dist/interactive/index.d.ts +0 -2
  85. package/dist/interactive/index.js +0 -2
  86. package/dist/interactive/interactive-manager.d.ts +0 -108
  87. package/dist/interactive/interactive-stream-hook.d.ts +0 -68
  88. package/dist/middleware/next/middleware.d.ts +0 -59
  89. package/dist/middleware/next/storage.d.ts +0 -14
  90. package/dist/middleware/shared/create-middleware-logger.d.ts +0 -82
  91. package/dist/middleware/shared/headers.d.ts +0 -14
  92. package/dist/middleware/shared/routes.d.ts +0 -30
  93. package/dist/middleware/shared/storage.d.ts +0 -29
  94. package/dist/packem_shared/AbstractJsonReporter-CGKHS8_M.js +0 -286
  95. package/dist/packem_shared/AbstractJsonReporter-DDjDkciI.js +0 -286
  96. package/dist/packem_shared/InteractiveManager-Cd6A14ZK.js +0 -172
  97. package/dist/packem_shared/InteractiveStreamHook-ePIURL_U.js +0 -133
  98. package/dist/packem_shared/JsonReporter-B3XX8GHN.js +0 -58
  99. package/dist/packem_shared/JsonReporter-p_BXg6Sj.js +0 -28
  100. package/dist/packem_shared/PrettyReporter-BYL3NrdA.js +0 -214
  101. package/dist/packem_shared/PrettyReporter-CvBn-hxP.js +0 -1459
  102. package/dist/packem_shared/Spinner-DIdVcfWq.js +0 -2183
  103. package/dist/packem_shared/abstract-pretty-reporter-jU8WL_6c.js +0 -2602
  104. package/dist/packem_shared/constants-B1RjD_ps.js +0 -99
  105. package/dist/packem_shared/constants-omsTHUWB.js +0 -119
  106. package/dist/packem_shared/createPailError-B11aRfrT.js +0 -76
  107. package/dist/packem_shared/getBarChar-BWj1UrH3.js +0 -404
  108. package/dist/packem_shared/headers-Cp4uLtr4.js +0 -123
  109. package/dist/packem_shared/index-DnkF86LQ.js +0 -658
  110. package/dist/packem_shared/index-frijFf5m.js +0 -1252
  111. package/dist/packem_shared/pailMiddleware-Ci88geIF.js +0 -24
  112. package/dist/packem_shared/storage-D0vqz8OX.js +0 -36
  113. package/dist/packem_shared/useLogger-D0rU3lcX.js +0 -33
  114. package/dist/packem_shared/write-console-log-based-on-level-DBmRYXpj.js +0 -14
  115. package/dist/packem_shared/write-stream-BG8fhcs3.js +0 -6
  116. package/dist/pail.browser.d.ts +0 -412
  117. package/dist/pail.server.d.ts +0 -233
  118. package/dist/processor/caller/get-caller-filename.d.ts +0 -23
  119. package/dist/progress-bar.d.ts +0 -136
  120. package/dist/progress-bar.js +0 -404
  121. package/dist/reporter/file/utils/rotating-file-stream.d.ts +0 -48
  122. package/dist/reporter/http/utils/compression.d.ts +0 -7
  123. package/dist/reporter/http/utils/log-size-error.d.ts +0 -30
  124. package/dist/reporter/http/utils/retry.d.ts +0 -27
  125. package/dist/reporter/json/abstract-json-reporter.d.ts +0 -61
  126. package/dist/reporter/json/json-reporter.browser.d.ts +0 -40
  127. package/dist/reporter/json/json-reporter.server.d.ts +0 -50
  128. package/dist/reporter/pretty/abstract-pretty-reporter.d.ts +0 -83
  129. package/dist/reporter/pretty/pretty-reporter.browser.d.ts +0 -36
  130. package/dist/reporter/pretty/pretty-reporter.server.d.ts +0 -70
  131. package/dist/reporter/raw/raw-reporter.browser.d.ts +0 -5
  132. package/dist/reporter/raw/raw-reporter.server.d.ts +0 -13
  133. package/dist/reporter/utils/default-inspector-config.d.ts +0 -3
  134. package/dist/reporter/utils/format-label.d.ts +0 -3
  135. package/dist/spinner.d.ts +0 -220
  136. package/dist/spinner.js +0 -2183
  137. package/dist/types.d.ts +0 -241
  138. package/dist/utils/ansi-escapes.d.ts +0 -4
  139. package/dist/utils/arrayify.d.ts +0 -2
  140. package/dist/utils/get-longest-badge.d.ts +0 -4
  141. package/dist/utils/get-longest-label.d.ts +0 -4
  142. package/dist/utils/merge-types.d.ts +0 -4
  143. package/dist/utils/stream/safe-stream-handler.d.ts +0 -21
  144. package/dist/utils/write-console-log-based-on-level.d.ts +0 -4
  145. package/dist/utils/write-stream.d.ts +0 -2
@@ -1,40 +1,488 @@
1
- import type { AbstractHttpReporterOptions } from "./abstract-http-reporter.d.ts";
2
- import { AbstractHttpReporter } from "./abstract-http-reporter.d.ts";
3
- /**
4
- * HTTP Reporter for Edge Runtime environments.
5
- *
6
- * A reporter optimized for Edge Runtime environments (Next.js Edge, Cloudflare Workers, etc.)
7
- * that sends logs to HTTP endpoints. Edge compatibility mode is enabled by default.
8
- * Supports batching, retries, and rate limiting. Compression is disabled for Edge compatibility.
9
- * @template L - The log level type
10
- * @example
11
- * ```typescript
12
- * import { createPail } from "@visulima/pail";
13
- * import { HttpReporterEdgeLight } from "@visulima/pail/reporter/http/edge-light";
14
- *
15
- * const logger = createPail({
16
- * reporters: [
17
- * new HttpReporterEdgeLight({
18
- * url: "https://api.example.com/logs",
19
- * method: "POST",
20
- * headers: {
21
- * "Authorization": "Bearer token"
22
- * },
23
- * enableBatchSend: true,
24
- * batchSize: 50
25
- * })
26
- * ]
27
- * });
28
- *
29
- * logger.info("Edge function started");
30
- * ```
31
- */
1
+ import '@visulima/colorize';
2
+ import '@visulima/interactive-manager';
3
+ /**
4
+ Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
5
+
6
+ @category Type
7
+ */
8
+ type Primitive = null | undefined | string | number | boolean | symbol | bigint;
9
+ /**
10
+ Create a union type by combining primitive types and literal types without sacrificing auto-completion in IDEs for the literal type part of the union.
11
+
12
+ Currently, when a union type of a primitive type is combined with literal types, TypeScript loses all information about the combined literals. Thus, when such type is used in an IDE with autocompletion, no suggestions are made for the declared literals.
13
+
14
+ This type is a workaround for [Microsoft/TypeScript#29729](https://github.com/Microsoft/TypeScript/issues/29729). It will be removed as soon as it's not needed anymore.
15
+
16
+ @example
17
+ ```
18
+ import type {LiteralUnion} from 'type-fest';
19
+
20
+ // Before
21
+
22
+ type Pet = 'dog' | 'cat' | string;
23
+
24
+ const petWithoutAutocomplete: Pet = '';
25
+ // Start typing in your TypeScript-enabled IDE.
26
+ // You **will not** get auto-completion for `dog` and `cat` literals.
27
+
28
+ // After
29
+
30
+ type Pet2 = LiteralUnion<'dog' | 'cat', string>;
31
+
32
+ const petWithAutoComplete: Pet2 = '';
33
+ // You **will** get auto-completion for `dog` and `cat` literals.
34
+ ```
35
+
36
+ @category Type
37
+ */
38
+ type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
39
+ /**
40
+ * Global namespace for extending Pail's metadata interface.
41
+ *
42
+ * This global declaration allows other packages and applications to extend
43
+ * the Meta interface with custom properties by declaring additional properties
44
+ * in the VisulimaPail.CustomMeta interface.
45
+ * @example
46
+ * ```typescript
47
+ * declare global {
48
+ * namespace VisulimaPail {
49
+ * interface CustomMeta<L> {
50
+ * userId?: string;
51
+ * requestId?: string;
52
+ * }
53
+ * }
54
+ * }
55
+ * ```
56
+ */
57
+ declare global {
58
+ namespace VisulimaPail {
59
+ interface CustomMeta<L> {}
60
+ }
61
+ }
62
+ /**
63
+ * Metadata object containing all information about a log entry.
64
+ *
65
+ * This interface defines the structure of metadata that is passed to reporters
66
+ * and processors. It contains all the contextual information about a log message
67
+ * including the message itself, timing information, error details, and more.
68
+ * @template L - The log level type
69
+ */
70
+ interface Meta<L> extends VisulimaPail.CustomMeta<L> {
71
+ badge: string | undefined;
72
+ context: any[] | undefined;
73
+ date: Date | string;
74
+ error: Error | undefined;
75
+ groups: string[];
76
+ label: string | undefined;
77
+ message: Primitive | ReadonlyArray<unknown> | Record<PropertyKey, unknown>;
78
+ prefix: string | undefined;
79
+ repeated?: number;
80
+ scope: string[] | undefined;
81
+ suffix: string | undefined;
82
+ traceError: Error | undefined;
83
+ type: {
84
+ level: ExtendedRfc5424LogLevels | L;
85
+ name: string;
86
+ };
87
+ }
88
+ /**
89
+ * Extended RFC 5424 Log Levels.
90
+ *
91
+ * Standard syslog severity levels as defined in RFC 5424, plus additional
92
+ * levels commonly used in modern applications. Each level has a numeric
93
+ * priority where lower numbers indicate higher severity.
94
+ * @see https://datatracker.ietf.org/doc/html/rfc5424#section-6.2.1
95
+ */
96
+ type ExtendedRfc5424LogLevels = "alert" | "critical" | "debug" | "emergency" | "error" | "informational" | "notice" | "trace" | "warning";
97
+ /**
98
+ * Read-only Metadata.
99
+ *
100
+ * Immutable version of the Meta interface for use in reporters.
101
+ * @template L - The log level type
102
+ */
103
+ type ReadonlyMeta<L extends string> = Readonly<Meta<L>>;
104
+ /**
105
+ * Reporter Interface.
106
+ *
107
+ * Base interface for all reporters. Reporters are responsible for
108
+ * outputting log messages to various destinations (console, files, etc.).
109
+ * @template L - The log level type
110
+ */
111
+ interface Reporter<L extends string> {
112
+ log: (meta: ReadonlyMeta<L>) => void;
113
+ }
114
+ /**
115
+ * Stringify-Aware Reporter Interface.
116
+ *
117
+ * Extends Reporter with the ability to receive a custom stringify function.
118
+ * Useful for reporters that need to serialize complex objects.
119
+ * @template L - The log level type
120
+ */
121
+ interface StringifyAwareReporter<L extends string> extends Reporter<L> {
122
+ /** Set the stringify function for object serialization */
123
+ setStringify: (stringify: any) => void;
124
+ }
125
+ type Replacer = (number | string)[] | null | undefined | ((key: string, value: unknown) => string | number | boolean | null | object);
126
+ declare function stringify(value: undefined | symbol | ((...args: unknown[]) => unknown), replacer?: Replacer, space?: string | number): undefined;
127
+ declare function stringify(value: string | number | unknown[] | null | boolean | object, replacer?: Replacer, space?: string | number): string;
128
+ declare function stringify(value: unknown, replacer?: ((key: string, value: unknown) => unknown) | (number | string)[] | null | undefined, space?: string | number): string | undefined;
129
+ declare namespace stringify {
130
+ export function configure(options: StringifyOptions): typeof stringify;
131
+ }
132
+ interface StringifyOptions {
133
+ bigint?: boolean;
134
+ circularValue?: string | null | TypeErrorConstructor | ErrorConstructor;
135
+ deterministic?: boolean | ((a: string, b: string) => number);
136
+ maximumBreadth?: number;
137
+ maximumDepth?: number;
138
+ strict?: boolean;
139
+ }
140
+ /**
141
+ * Options for configuring JSON reporters.
142
+ */
143
+ type AbstractJsonReporterOptions = {
144
+ /** Error serialization options */
145
+ error: Partial<{
146
+ /** Properties to exclude from error serialization */
147
+ exclude?: string[];
148
+ /** Maximum depth for error object serialization */
149
+ maxDepth?: number;
150
+ /** Whether to use toJSON methods during serialization */
151
+ useToJSON?: boolean;
152
+ }>;
153
+ };
154
+ /**
155
+ * Abstract JSON Reporter.
156
+ *
157
+ * Base class for JSON-based reporters that provides common functionality
158
+ * for serializing log metadata to JSON format. Handles error serialization,
159
+ * context processing, and provides a template method for actual output.
160
+ * @template L - The log level type
161
+ * @example
162
+ * ```typescript
163
+ * class CustomJsonReporter extends AbstractJsonReporter {
164
+ * protected _log(message: string): void {
165
+ * console.log(message);
166
+ * }
167
+ * }
168
+ * ```
169
+ */
170
+ declare abstract class AbstractJsonReporter<L extends string = string> implements StringifyAwareReporter<L> {
171
+ /** Custom stringify function for object serialization */
172
+ protected stringify: typeof stringify | undefined;
173
+ /** Error serialization options */
174
+ protected errorOptions: AbstractJsonReporterOptions["error"];
175
+ /**
176
+ * Creates a new AbstractJsonReporter instance.
177
+ * @param options Configuration options for JSON formatting and error handling
178
+ */
179
+ constructor(options?: Partial<AbstractJsonReporterOptions>);
180
+ /**
181
+ * Sets a custom stringify function for object serialization.
182
+ * @param function_ The stringify function to use for serialization
183
+ */
184
+ setStringify(function_: typeof stringify): void;
185
+ log(meta: ReadonlyMeta<L>): void;
186
+ /**
187
+ * Template method for outputting the JSON log message.
188
+ *
189
+ * Subclasses must implement this method to define how the JSON message
190
+ * is actually written (to console, file, network, etc.).
191
+ * @param message The JSON-formatted log message
192
+ * @param logLevel The log level of the message
193
+ * @protected
194
+ * @abstract
195
+ */
196
+ protected abstract _log(message: string, logLevel: LiteralUnion<ExtendedRfc5424LogLevels, L>): void;
197
+ }
198
+ /**
199
+ * Configuration options for the HTTP reporter.
200
+ */
201
+ type AbstractHttpReporterOptions = AbstractJsonReporterOptions & {
202
+ /**
203
+ * Content type for batch log requests. User-specified headers take precedence.
204
+ * @default "application/json"
205
+ */
206
+ batchContentType?: string;
207
+ /**
208
+ * Field name to wrap batch entries in when batchMode is "field" (e.g., "batch" for Logflare)
209
+ * @default undefined
210
+ */
211
+ batchFieldName?: string;
212
+ /**
213
+ * Batch mode for sending multiple log entries
214
+ * - "delimiter": Join entries with a delimiter (default)
215
+ * - "field": Wrap entries in an object with a field name
216
+ * - "array": Send entries as a plain JSON array
217
+ * @default "delimiter"
218
+ */
219
+ batchMode?: "delimiter" | "field" | "array";
220
+ /**
221
+ * Delimiter to use between log entries in batch mode
222
+ * @default "\n"
223
+ */
224
+ batchSendDelimiter?: string;
225
+ /**
226
+ * Timeout in milliseconds for sending batches regardless of size
227
+ * @default 5000
228
+ */
229
+ batchSendTimeout?: number;
230
+ /**
231
+ * Number of log entries to batch before sending
232
+ * @default 100
233
+ */
234
+ batchSize?: number;
235
+ /**
236
+ * Whether to use gzip compression
237
+ * @default false
238
+ */
239
+ compression?: boolean;
240
+ /**
241
+ * Content type for single log requests. User-specified headers take precedence.
242
+ * @default "application/json"
243
+ */
244
+ contentType?: string;
245
+ /**
246
+ * Whether to enable Edge Runtime compatibility mode
247
+ * When enabled, TextEncoder and compression are disabled
248
+ * @default false
249
+ */
250
+ edgeCompat?: boolean;
251
+ /**
252
+ * Whether to enable batch sending
253
+ * @default true
254
+ */
255
+ enableBatchSend?: boolean;
256
+ /**
257
+ * Headers to include in the request. Can be an object or a function that returns headers.
258
+ */
259
+ headers?: Record<string, string> | (() => Record<string, string>);
260
+ /**
261
+ * Maximum size of a single log entry in bytes
262
+ * @default 1048576 (1MB)
263
+ */
264
+ maxLogSize?: number;
265
+ /**
266
+ * Maximum size of the payload (uncompressed) in bytes
267
+ * @default 5242880 (5MB)
268
+ */
269
+ maxPayloadSize?: number;
270
+ /**
271
+ * Maximum number of entries to keep queued while the endpoint is unavailable.
272
+ * When the queue exceeds this limit, the oldest entries are dropped (drop-oldest)
273
+ * so a sustained outage cannot grow memory without bound.
274
+ * @default 10000
275
+ */
276
+ maxQueueSize?: number;
277
+ /**
278
+ * Number of retry attempts before giving up
279
+ * @default 3
280
+ */
281
+ maxRetries?: number;
282
+ /**
283
+ * HTTP method to use for requests
284
+ * @default "POST"
285
+ */
286
+ method?: string;
287
+ /**
288
+ * Optional callback for debugging log entries before they are sent
289
+ */
290
+ onDebug?: (entry: Record<string, unknown>) => void;
291
+ /**
292
+ * Optional callback for debugging HTTP requests and responses
293
+ */
294
+ onDebugRequestResponse?: (requestResponse: {
295
+ req: {
296
+ body: string | Uint8Array;
297
+ headers: Record<string, string>;
298
+ method: string;
299
+ url: string;
300
+ };
301
+ res: {
302
+ body: string;
303
+ headers: Record<string, string>;
304
+ status: number;
305
+ statusText: string;
306
+ };
307
+ }) => void;
308
+ /**
309
+ * Optional callback invoked when queued log entries are dropped because the queue
310
+ * exceeded `maxQueueSize`. Receives the number of dropped entries.
311
+ */
312
+ onDrop?: (droppedCount: number) => void;
313
+ /**
314
+ * Optional callback for error handling
315
+ */
316
+ onError?: (error: Error) => void;
317
+ /**
318
+ * Function to transform log data into the payload format.
319
+ * By default, uses the JSON stringified log entry.
320
+ */
321
+ payloadTemplate?: (data: {
322
+ data?: Record<string, unknown>;
323
+ logLevel: string;
324
+ message: string;
325
+ }) => string;
326
+ /**
327
+ * Whether to respect rate limiting by waiting when a 429 response is received
328
+ * @default true
329
+ */
330
+ respectRateLimit?: boolean;
331
+ /**
332
+ * Base delay between retries in milliseconds
333
+ * @default 1000
334
+ */
335
+ retryDelay?: number;
336
+ /**
337
+ * The URL to send logs to
338
+ */
339
+ url: string;
340
+ };
341
+ /**
342
+ * Abstract HTTP Reporter.
343
+ *
344
+ * Base class for HTTP-based reporters that sends logs to HTTP endpoints.
345
+ * Supports batching, compression, retries, and rate limiting.
346
+ * @template L - The log level type
347
+ */
348
+ declare abstract class AbstractHttpReporter<L extends string = string> extends AbstractJsonReporter<L> implements StringifyAwareReporter<L> {
349
+ #private;
350
+ protected url: string;
351
+ protected method: string;
352
+ protected headers: Record<string, string> | (() => Record<string, string>);
353
+ protected contentType: string;
354
+ protected batchContentType: string;
355
+ protected onError?: (error: Error) => void;
356
+ protected onDrop?: (droppedCount: number) => void;
357
+ protected maxQueueSize: number;
358
+ protected onDebug?: (entry: Record<string, unknown>) => void;
359
+ protected onDebugRequestResponse?: (requestResponse: {
360
+ req: {
361
+ body: string | Uint8Array;
362
+ headers: Record<string, string>;
363
+ method: string;
364
+ url: string;
365
+ };
366
+ res: {
367
+ body: string;
368
+ headers: Record<string, string>;
369
+ status: number;
370
+ statusText: string;
371
+ };
372
+ }) => void;
373
+ protected payloadTemplate: (data: {
374
+ data?: Record<string, unknown>;
375
+ logLevel: string;
376
+ message: string;
377
+ }) => string;
378
+ protected compression: boolean;
379
+ protected maxRetries: number;
380
+ protected retryDelay: number;
381
+ protected respectRateLimit: boolean;
382
+ protected enableBatchSend: boolean;
383
+ protected batchSize: number;
384
+ protected batchSendTimeout: number;
385
+ protected batchSendDelimiter: string;
386
+ protected batchMode: "delimiter" | "field" | "array";
387
+ protected batchFieldName?: string;
388
+ protected maxLogSize: number;
389
+ protected maxPayloadSize: number;
390
+ protected edgeCompat: boolean;
391
+ protected batchQueue: string[];
392
+ protected batchTimeout?: ReturnType<typeof setTimeout>;
393
+ protected isProcessingBatch: boolean;
394
+ protected currentBatchSize: number;
395
+ /**
396
+ * Creates a new instance of AbstractHttpReporter.
397
+ * @param config Configuration options for the reporter
398
+ */
399
+ constructor(config: AbstractHttpReporterOptions);
400
+ /**
401
+ * Flushes all queued log entries to the HTTP endpoint immediately.
402
+ *
403
+ * Returns a promise that resolves once the queue has been drained (or rejects
404
+ * if a batch send fails terminally). Use this before a serverless function or
405
+ * short-lived process exits so the tail of the batch is not lost.
406
+ * @example
407
+ * ```typescript
408
+ * await reporter.flush();
409
+ * ```
410
+ */
411
+ flush(): Promise<void>;
412
+ /**
413
+ * Flushes any remaining queued entries and clears pending timers.
414
+ *
415
+ * Counterpart to a transport lifecycle `end`/`dispose`. After calling `close()`
416
+ * the reporter can still be used, but any pending batch timeout is cleared.
417
+ * @example
418
+ * ```typescript
419
+ * process.on("beforeExit", () => reporter.close());
420
+ * ```
421
+ */
422
+ close(): Promise<void>;
423
+ /**
424
+ * Alias for {@link close} to match common transport `dispose` conventions.
425
+ */
426
+ dispose(): Promise<void>;
427
+ /**
428
+ * Processes and ships log entries to the HTTP endpoint.
429
+ * @param message The JSON-formatted log message
430
+ * @param logLevel The log level of the message
431
+ * @protected
432
+ */
433
+ protected override _log(message: string, logLevel: LiteralUnion<ExtendedRfc5424LogLevels, L>): void;
434
+ /**
435
+ * Adds a payload to the batch queue and triggers sending if conditions are met.
436
+ */
437
+ protected addToBatch(payload: string, logEntrySize: number): void;
438
+ /**
439
+ * Processes the current batch and sends it to the HTTP endpoint.
440
+ */
441
+ protected processBatch(): Promise<void>;
442
+ /**
443
+ * Sends a batch of payloads to the HTTP endpoint.
444
+ */
445
+ protected sendBatch(batch: string[]): Promise<void>;
446
+ /**
447
+ * Sends a single payload to the HTTP endpoint.
448
+ */
449
+ protected sendPayload(payload: string, contentType?: string): Promise<void>;
450
+ }
451
+ /**
452
+ * HTTP Reporter for Edge Runtime environments.
453
+ *
454
+ * A reporter optimized for Edge Runtime environments (Next.js Edge, Cloudflare Workers, etc.)
455
+ * that sends logs to HTTP endpoints. Edge compatibility mode is enabled by default.
456
+ * Supports batching, retries, and rate limiting. Compression is disabled for Edge compatibility.
457
+ * @template L - The log level type
458
+ * @example
459
+ * ```typescript
460
+ * import { createPail } from "@visulima/pail";
461
+ * import { HttpReporterEdgeLight } from "@visulima/pail/reporter/http/edge-light";
462
+ *
463
+ * const logger = createPail({
464
+ * reporters: [
465
+ * new HttpReporterEdgeLight({
466
+ * url: "https://api.example.com/logs",
467
+ * method: "POST",
468
+ * headers: {
469
+ * "Authorization": "Bearer token"
470
+ * },
471
+ * enableBatchSend: true,
472
+ * batchSize: 50
473
+ * })
474
+ * ]
475
+ * });
476
+ *
477
+ * logger.info("Edge function started");
478
+ * ```
479
+ */
32
480
  declare class HttpReporterEdgeLight<L extends string = string> extends AbstractHttpReporter<L> {
33
- /**
34
- * Creates a new HTTP Reporter Edge Light instance.
35
- * Edge compatibility mode is automatically enabled.
36
- * @param options Configuration options for HTTP reporting
37
- */
38
- constructor(options: Omit<AbstractHttpReporterOptions, "edgeCompat">);
39
- }
40
- export default HttpReporterEdgeLight;
481
+ /**
482
+ * Creates a new HTTP Reporter Edge Light instance.
483
+ * Edge compatibility mode is automatically enabled.
484
+ * @param options Configuration options for HTTP reporting
485
+ */
486
+ constructor(options: Omit<AbstractHttpReporterOptions, "edgeCompat">);
487
+ }
488
+ export { HttpReporterEdgeLight as default };