@visulima/pail 3.2.0 → 3.2.2

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 (64) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/LICENSE.md +3 -0
  3. package/dist/constants.d.ts +37 -0
  4. package/dist/index.browser.d.ts +47 -12
  5. package/dist/index.browser.js +1 -1
  6. package/dist/index.server.d.ts +65 -43
  7. package/dist/index.server.js +1 -3
  8. package/dist/interactive/index.d.ts +2 -28
  9. package/dist/interactive/interactive-manager.d.ts +108 -0
  10. package/dist/interactive/interactive-stream-hook.d.ts +68 -0
  11. package/dist/object-tree.d.ts +65 -7
  12. package/dist/packem_shared/{JsonReporter-BqWsVkHP.js → JsonReporter-C0AXk99i.js} +0 -2
  13. package/dist/packem_shared/{pail.browser-CPDOE_d1.js → pail.browser-CPjQrsyy.js} +3 -3
  14. package/dist/pail.browser.d.ts +412 -0
  15. package/dist/pail.server.d.ts +233 -0
  16. package/dist/processor/caller/caller-processor.d.ts +40 -7
  17. package/dist/processor/caller/get-caller-filename.d.ts +23 -0
  18. package/dist/processor/message-formatter-processor.d.ts +44 -9
  19. package/dist/processor/message-formatter-processor.js +1 -1
  20. package/dist/processor/opentelemetry-processor.d.ts +61 -10
  21. package/dist/processor/redact-processor.d.ts +39 -8
  22. package/dist/progress-bar.d.ts +75 -15
  23. package/dist/reporter/file/json-file-reporter.d.ts +39 -20
  24. package/dist/reporter/file/utils/rotating-file-stream.d.ts +48 -0
  25. package/dist/reporter/http/abstract-http-reporter.d.ts +125 -12
  26. package/dist/reporter/http/http-reporter.d.ts +36 -10
  27. package/dist/reporter/http/http-reporter.edge-light.d.ts +37 -165
  28. package/dist/reporter/http/utils/compression.d.ts +7 -0
  29. package/dist/reporter/http/utils/log-size-error.d.ts +30 -0
  30. package/dist/reporter/http/utils/retry.d.ts +27 -0
  31. package/dist/reporter/json/abstract-json-reporter.d.ts +61 -0
  32. package/dist/reporter/json/index.browser.d.ts +3 -13
  33. package/dist/reporter/json/index.d.ts +3 -16
  34. package/dist/reporter/json/index.js +1 -1
  35. package/dist/reporter/json/json-reporter.browser.d.ts +40 -0
  36. package/dist/reporter/json/json-reporter.server.d.ts +50 -0
  37. package/dist/reporter/pretty/abstract-pretty-reporter.d.ts +83 -0
  38. package/dist/reporter/pretty/index.browser.d.ts +2 -13
  39. package/dist/reporter/pretty/index.d.ts +2 -25
  40. package/dist/reporter/pretty/pretty-reporter.browser.d.ts +36 -0
  41. package/dist/reporter/pretty/pretty-reporter.server.d.ts +70 -0
  42. package/dist/reporter/raw/raw-reporter.browser.d.ts +5 -0
  43. package/dist/reporter/raw/raw-reporter.server.d.ts +13 -0
  44. package/dist/reporter/simple/simple-reporter.server.d.ts +10 -14
  45. package/dist/reporter/utils/default-inspector-config.d.ts +3 -0
  46. package/dist/reporter/utils/format-label.d.ts +3 -0
  47. package/dist/spinner.d.ts +170 -104
  48. package/dist/spinner.js +89 -89
  49. package/dist/types.d.ts +241 -0
  50. package/dist/utils/ansi-escapes.d.ts +4 -0
  51. package/dist/utils/arrayify.d.ts +2 -0
  52. package/dist/utils/get-longest-badge.d.ts +4 -0
  53. package/dist/utils/get-longest-label.d.ts +4 -0
  54. package/dist/utils/merge-types.d.ts +4 -0
  55. package/dist/utils/stream/safe-stream-handler.d.ts +21 -0
  56. package/dist/utils/write-console-log-based-on-level.d.ts +4 -0
  57. package/dist/utils/write-stream.d.ts +2 -0
  58. package/package.json +3 -4
  59. package/dist/packem_shared/abstract-json-reporter-DiyVyU0j.d.ts +0 -22
  60. package/dist/packem_shared/abstract-pretty-reporter-BbOWXMCs.d.ts +0 -28
  61. package/dist/packem_shared/index.d-BR1GjZri.d.ts +0 -53
  62. package/dist/packem_shared/index.d-oxZvg_y7.d.ts +0 -20
  63. package/dist/packem_shared/pail.browser-By9KjOH7.d.ts +0 -69
  64. package/dist/packem_shared/types-D3ycu8-x.d.ts +0 -95
@@ -1,27 +1,96 @@
1
- import { LiteralUnion } from 'type-fest';
2
- import { f as StringifyAwareReporter, E as ExtendedRfc5424LogLevels } from '../../packem_shared/types-D3ycu8-x.js';
3
- import { a as AbstractJsonReporterOptions, A as AbstractJsonReporter } from '../../packem_shared/abstract-json-reporter-DiyVyU0j.js';
4
- import '@visulima/colorize';
5
- import '../../interactive/index.js';
6
- import '../../packem_shared/index.d-oxZvg_y7.js';
7
-
8
- type AbstractHttpReporterOptions = AbstractJsonReporterOptions & {
1
+ import type { LiteralUnion } from "type-fest";
2
+ import type { ExtendedRfc5424LogLevels, StringifyAwareReporter } from "../../types.d.ts";
3
+ import type { AbstractJsonReporterOptions } from "../json/abstract-json-reporter.d.ts";
4
+ import { AbstractJsonReporter } from "../json/abstract-json-reporter.d.ts";
5
+ /**
6
+ * Configuration options for the HTTP reporter.
7
+ */
8
+ export type AbstractHttpReporterOptions = AbstractJsonReporterOptions & {
9
+ /**
10
+ * Content type for batch log requests. User-specified headers take precedence.
11
+ * @default "application/json"
12
+ */
9
13
  batchContentType?: string;
14
+ /**
15
+ * Field name to wrap batch entries in when batchMode is "field" (e.g., "batch" for Logflare)
16
+ * @default undefined
17
+ */
10
18
  batchFieldName?: string;
19
+ /**
20
+ * Batch mode for sending multiple log entries
21
+ * - "delimiter": Join entries with a delimiter (default)
22
+ * - "field": Wrap entries in an object with a field name
23
+ * - "array": Send entries as a plain JSON array
24
+ * @default "delimiter"
25
+ */
11
26
  batchMode?: "delimiter" | "field" | "array";
27
+ /**
28
+ * Delimiter to use between log entries in batch mode
29
+ * @default "\n"
30
+ */
12
31
  batchSendDelimiter?: string;
32
+ /**
33
+ * Timeout in milliseconds for sending batches regardless of size
34
+ * @default 5000
35
+ */
13
36
  batchSendTimeout?: number;
37
+ /**
38
+ * Number of log entries to batch before sending
39
+ * @default 100
40
+ */
14
41
  batchSize?: number;
42
+ /**
43
+ * Whether to use gzip compression
44
+ * @default false
45
+ */
15
46
  compression?: boolean;
47
+ /**
48
+ * Content type for single log requests. User-specified headers take precedence.
49
+ * @default "application/json"
50
+ */
16
51
  contentType?: string;
52
+ /**
53
+ * Whether to enable Edge Runtime compatibility mode
54
+ * When enabled, TextEncoder and compression are disabled
55
+ * @default false
56
+ */
17
57
  edgeCompat?: boolean;
58
+ /**
59
+ * Whether to enable batch sending
60
+ * @default true
61
+ */
18
62
  enableBatchSend?: boolean;
63
+ /**
64
+ * Headers to include in the request. Can be an object or a function that returns headers.
65
+ */
19
66
  headers?: Record<string, string> | (() => Record<string, string>);
67
+ /**
68
+ * Maximum size of a single log entry in bytes
69
+ * @default 1048576 (1MB)
70
+ */
20
71
  maxLogSize?: number;
72
+ /**
73
+ * Maximum size of the payload (uncompressed) in bytes
74
+ * @default 5242880 (5MB)
75
+ */
21
76
  maxPayloadSize?: number;
77
+ /**
78
+ * Number of retry attempts before giving up
79
+ * @default 3
80
+ */
22
81
  maxRetries?: number;
82
+ /**
83
+ * HTTP method to use for requests
84
+ * @default "POST"
85
+ */
23
86
  method?: string;
87
+ /**
88
+ * Optional callback for debugging log entries before they are sent
89
+ */
24
90
  onDebug?: (entry: Record<string, unknown>) => void;
91
+ /**
92
+ * Optional callback for debugging HTTP requests and responses
93
+ */
25
94
  onDebugRequestResponse?: (requestResponse: {
26
95
  req: {
27
96
  body: string | Uint8Array;
@@ -36,17 +105,42 @@ type AbstractHttpReporterOptions = AbstractJsonReporterOptions & {
36
105
  statusText: string;
37
106
  };
38
107
  }) => void;
108
+ /**
109
+ * Optional callback for error handling
110
+ */
39
111
  onError?: (error: Error) => void;
112
+ /**
113
+ * Function to transform log data into the payload format.
114
+ * By default, uses the JSON stringified log entry.
115
+ */
40
116
  payloadTemplate?: (data: {
41
117
  data?: Record<string, unknown>;
42
118
  logLevel: string;
43
119
  message: string;
44
120
  }) => string;
121
+ /**
122
+ * Whether to respect rate limiting by waiting when a 429 response is received
123
+ * @default true
124
+ */
45
125
  respectRateLimit?: boolean;
126
+ /**
127
+ * Base delay between retries in milliseconds
128
+ * @default 1000
129
+ */
46
130
  retryDelay?: number;
131
+ /**
132
+ * The URL to send logs to
133
+ */
47
134
  url: string;
48
135
  };
49
- declare abstract class AbstractHttpReporter<L extends string = string> extends AbstractJsonReporter<L> implements StringifyAwareReporter<L> {
136
+ /**
137
+ * Abstract HTTP Reporter.
138
+ *
139
+ * Base class for HTTP-based reporters that sends logs to HTTP endpoints.
140
+ * Supports batching, compression, retries, and rate limiting.
141
+ * @template L - The log level type
142
+ */
143
+ export declare abstract class AbstractHttpReporter<L extends string = string> extends AbstractJsonReporter<L> implements StringifyAwareReporter<L> {
50
144
  protected url: string;
51
145
  protected method: string;
52
146
  protected headers: Record<string, string> | (() => Record<string, string>);
@@ -90,13 +184,32 @@ declare abstract class AbstractHttpReporter<L extends string = string> extends A
90
184
  protected batchTimeout?: ReturnType<typeof setTimeout>;
91
185
  protected isProcessingBatch: boolean;
92
186
  protected currentBatchSize: number;
187
+ /**
188
+ * Creates a new instance of AbstractHttpReporter.
189
+ * @param config Configuration options for the reporter
190
+ */
93
191
  constructor(config: AbstractHttpReporterOptions);
192
+ /**
193
+ * Processes and ships log entries to the HTTP endpoint.
194
+ * @param message The JSON-formatted log message
195
+ * @param logLevel The log level of the message
196
+ * @protected
197
+ */
94
198
  protected _log(message: string, logLevel: LiteralUnion<ExtendedRfc5424LogLevels, L>): void;
199
+ /**
200
+ * Adds a payload to the batch queue and triggers sending if conditions are met.
201
+ */
95
202
  protected addToBatch(payload: string, logEntrySize: number): void;
203
+ /**
204
+ * Processes the current batch and sends it to the HTTP endpoint.
205
+ */
96
206
  protected processBatch(): Promise<void>;
207
+ /**
208
+ * Sends a batch of payloads to the HTTP endpoint.
209
+ */
97
210
  protected sendBatch(batch: string[]): Promise<void>;
211
+ /**
212
+ * Sends a single payload to the HTTP endpoint.
213
+ */
98
214
  protected sendPayload(payload: string, contentType?: string): Promise<void>;
99
215
  }
100
-
101
- export { AbstractHttpReporter };
102
- export type { AbstractHttpReporterOptions };
@@ -1,13 +1,39 @@
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
-
1
+ import type { AbstractHttpReporterOptions } from "./abstract-http-reporter.d.ts";
2
+ import { AbstractHttpReporter } from "./abstract-http-reporter.d.ts";
3
+ /**
4
+ * HTTP Reporter.
5
+ *
6
+ * A reporter that sends logs to HTTP endpoints.
7
+ * Supports batching, compression, retries, and rate limiting.
8
+ * Works in both Node.js server and browser environments.
9
+ * @template L - The log level type
10
+ * @example
11
+ * ```typescript
12
+ * import { createPail } from "@visulima/pail";
13
+ * import { HttpReporter } from "@visulima/pail/reporter/http";
14
+ *
15
+ * const logger = createPail({
16
+ * reporters: [
17
+ * new HttpReporter({
18
+ * url: "https://api.example.com/logs",
19
+ * method: "POST",
20
+ * headers: {
21
+ * "Authorization": "Bearer token"
22
+ * },
23
+ * enableBatchSend: true,
24
+ * batchSize: 100
25
+ * })
26
+ * ]
27
+ * });
28
+ *
29
+ * logger.info("Application started", { version: "1.0.0" });
30
+ * ```
31
+ */
9
32
  declare class HttpReporter<L extends string = string> extends AbstractHttpReporter<L> {
33
+ /**
34
+ * Creates a new HTTP Reporter instance.
35
+ * @param options Configuration options for HTTP reporting
36
+ */
10
37
  constructor(options: AbstractHttpReporterOptions);
11
38
  }
12
-
13
- export { HttpReporter as default };
39
+ export default HttpReporter;
@@ -1,168 +1,40 @@
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
-
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
+ */
164
32
  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
+ */
165
38
  constructor(options: Omit<AbstractHttpReporterOptions, "edgeCompat">);
166
39
  }
167
-
168
- export { HttpReporterEdgeLight as default };
40
+ export default HttpReporterEdgeLight;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Compresses data using gzip compression.
3
+ * @param data The data to compress as a string
4
+ * @returns A Promise that resolves to the compressed data as Uint8Array
5
+ */
6
+ declare const compressData: (data: string) => Promise<Uint8Array>;
7
+ export default compressData;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Error thrown when a log entry exceeds the maximum allowed size.
3
+ */
4
+ declare class LogSizeError extends Error {
5
+ /**
6
+ * The log entry data that caused the error
7
+ */
8
+ readonly logData: Record<string, unknown>;
9
+ /**
10
+ * The actual size of the log entry in bytes
11
+ */
12
+ readonly actualSize: number;
13
+ /**
14
+ * The maximum allowed size in bytes
15
+ */
16
+ readonly maxSize: number;
17
+ /**
18
+ * Creates a new LogSizeError instance.
19
+ * @param message Descriptive error message explaining the size violation
20
+ * @param logData The log entry data that caused the error
21
+ * @param actualSize Size of the log entry in bytes
22
+ * @param maxSize Maximum allowed size in bytes
23
+ * @example
24
+ * ```typescript
25
+ * throw new LogSizeError("Log too large", logData, 2000000, 1000000);
26
+ * ```
27
+ */
28
+ constructor(message: string, logData: Record<string, unknown>, actualSize: number, maxSize: number);
29
+ }
30
+ export default LogSizeError;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Sends an HTTP request with retry logic and rate limiting support.
3
+ * @param url The URL to send the request to
4
+ * @param method The HTTP method to use
5
+ * @param headers Request headers
6
+ * @param body The request body (string or Uint8Array)
7
+ * @param maxRetries Maximum number of retry attempts
8
+ * @param retryDelay Base delay between retries in milliseconds
9
+ * @param respectRateLimit Whether to respect rate limiting (429 responses)
10
+ * @param onDebugRequestResponse Optional callback for debugging requests/responses
11
+ * @param onError Optional callback for error handling
12
+ */
13
+ declare const sendWithRetry: (url: string, method: string, headers: Record<string, string>, body: string | Uint8Array, maxRetries: number, retryDelay: number, respectRateLimit: boolean, onDebugRequestResponse?: (requestResponse: {
14
+ req: {
15
+ body: string | Uint8Array;
16
+ headers: Record<string, string>;
17
+ method: string;
18
+ url: string;
19
+ };
20
+ res: {
21
+ body: string;
22
+ headers: Record<string, string>;
23
+ status: number;
24
+ statusText: string;
25
+ };
26
+ }) => void, onError?: (error: Error) => void) => Promise<void>;
27
+ export default sendWithRetry;
@@ -0,0 +1,61 @@
1
+ import type { stringify } from "safe-stable-stringify";
2
+ import type { LiteralUnion } from "type-fest";
3
+ import type { ExtendedRfc5424LogLevels, ReadonlyMeta, StringifyAwareReporter } from "../../types.d.ts";
4
+ /**
5
+ * Options for configuring JSON reporters.
6
+ */
7
+ export type AbstractJsonReporterOptions = {
8
+ /** Error serialization options */
9
+ error: Partial<{
10
+ /** Properties to exclude from error serialization */
11
+ exclude?: string[];
12
+ /** Maximum depth for error object serialization */
13
+ maxDepth?: number;
14
+ /** Whether to use toJSON methods during serialization */
15
+ useToJSON?: boolean;
16
+ }>;
17
+ };
18
+ /**
19
+ * Abstract JSON Reporter.
20
+ *
21
+ * Base class for JSON-based reporters that provides common functionality
22
+ * for serializing log metadata to JSON format. Handles error serialization,
23
+ * context processing, and provides a template method for actual output.
24
+ * @template L - The log level type
25
+ * @example
26
+ * ```typescript
27
+ * class CustomJsonReporter extends AbstractJsonReporter {
28
+ * protected _log(message: string): void {
29
+ * console.log(message);
30
+ * }
31
+ * }
32
+ * ```
33
+ */
34
+ export declare abstract class AbstractJsonReporter<L extends string = string> implements StringifyAwareReporter<L> {
35
+ /** Custom stringify function for object serialization */
36
+ protected stringify: typeof stringify | undefined;
37
+ /** Error serialization options */
38
+ protected errorOptions: AbstractJsonReporterOptions["error"];
39
+ /**
40
+ * Creates a new AbstractJsonReporter instance.
41
+ * @param options Configuration options for JSON formatting and error handling
42
+ */
43
+ constructor(options?: Partial<AbstractJsonReporterOptions>);
44
+ /**
45
+ * Sets a custom stringify function for object serialization.
46
+ * @param function_ The stringify function to use for serialization
47
+ */
48
+ setStringify(function_: any): void;
49
+ log(meta: ReadonlyMeta<L>): void;
50
+ /**
51
+ * Template method for outputting the JSON log message.
52
+ *
53
+ * Subclasses must implement this method to define how the JSON message
54
+ * is actually written (to console, file, network, etc.).
55
+ * @param message The JSON-formatted log message
56
+ * @param logLevel The log level of the message
57
+ * @protected
58
+ * @abstract
59
+ */
60
+ protected abstract _log(message: string, logLevel: LiteralUnion<ExtendedRfc5424LogLevels, L>): void;
61
+ }
@@ -1,13 +1,3 @@
1
- import { A as AbstractJsonReporter, a as AbstractJsonReporterOptions } from '../../packem_shared/abstract-json-reporter-DiyVyU0j.js';
2
- import { LiteralUnion } from 'type-fest';
3
- import { E as ExtendedRfc5424LogLevels } from '../../packem_shared/types-D3ycu8-x.js';
4
- import '../../packem_shared/index.d-oxZvg_y7.js';
5
- import '@visulima/colorize';
6
- import '../../interactive/index.js';
7
-
8
- declare class JsonReporter<L extends string = string> extends AbstractJsonReporter<L> {
9
- constructor(options?: Partial<AbstractJsonReporterOptions>);
10
- protected _log(message: string, logLevel: LiteralUnion<ExtendedRfc5424LogLevels, L>): void;
11
- }
12
-
13
- export { AbstractJsonReporter, AbstractJsonReporterOptions, JsonReporter };
1
+ export type { AbstractJsonReporterOptions } from "./abstract-json-reporter.d.ts";
2
+ export { AbstractJsonReporter } from "./abstract-json-reporter.d.ts";
3
+ export { default as JsonReporter } from "./json-reporter.d.ts";
@@ -1,16 +1,3 @@
1
- import { A as AbstractJsonReporter, a as AbstractJsonReporterOptions } from '../../packem_shared/abstract-json-reporter-DiyVyU0j.js';
2
- import { LiteralUnion } from 'type-fest';
3
- import { S as StreamAwareReporter, E as ExtendedRfc5424LogLevels } from '../../packem_shared/types-D3ycu8-x.js';
4
- import '../../packem_shared/index.d-oxZvg_y7.js';
5
- import '@visulima/colorize';
6
- import '../../interactive/index.js';
7
-
8
- declare class JsonReporter<L extends string = string> extends AbstractJsonReporter<L> implements StreamAwareReporter<L> {
9
- #private;
10
- constructor(options?: Partial<AbstractJsonReporterOptions>);
11
- setStdout(stdout_: NodeJS.WriteStream): void;
12
- setStderr(stderr_: NodeJS.WriteStream): void;
13
- protected _log(message: string, logLevel: LiteralUnion<ExtendedRfc5424LogLevels, L>): void;
14
- }
15
-
16
- export { AbstractJsonReporter, AbstractJsonReporterOptions, JsonReporter };
1
+ export type { AbstractJsonReporterOptions } from "./abstract-json-reporter.d.ts";
2
+ export { AbstractJsonReporter } from "./abstract-json-reporter.d.ts";
3
+ export { default as JsonReporter } from "./json-reporter.d.ts";
@@ -1,2 +1,2 @@
1
1
  export { AbstractJsonReporter } from '../../packem_shared/AbstractJsonReporter-intFdT_A.js';
2
- export { default as JsonReporter } from '../../packem_shared/JsonReporter-BqWsVkHP.js';
2
+ export { default as JsonReporter } from '../../packem_shared/JsonReporter-C0AXk99i.js';
@@ -0,0 +1,40 @@
1
+ import type { LiteralUnion } from "type-fest";
2
+ import type { ExtendedRfc5424LogLevels } from "../../types.d.ts";
3
+ import type { AbstractJsonReporterOptions } from "./abstract-json-reporter.d.ts";
4
+ import { AbstractJsonReporter } from "./abstract-json-reporter.d.ts";
5
+ /**
6
+ * Browser JSON Reporter.
7
+ *
8
+ * A JSON reporter for browser environments that outputs structured log data
9
+ * to the browser console. Uses appropriate console methods based on log level.
10
+ * @template L - The log level type
11
+ * @example
12
+ * ```typescript
13
+ * import { createPail } from "@visulima/pail";
14
+ *
15
+ * const logger = createPail({
16
+ * reporters: [new JsonReporter()]
17
+ * });
18
+ *
19
+ * logger.info("Application started", { version: "1.0.0" });
20
+ * // Outputs: {"level":"info","message":"Application started","context":[{"version":"1.0.0"}],...}
21
+ * ```
22
+ */
23
+ declare class JsonReporter<L extends string = string> extends AbstractJsonReporter<L> {
24
+ /**
25
+ * Creates a new Browser JSON Reporter instance.
26
+ * @param options Configuration options for JSON formatting
27
+ */
28
+ constructor(options?: Partial<AbstractJsonReporterOptions>);
29
+ /**
30
+ * Outputs the JSON message to the browser console.
31
+ *
32
+ * Uses the appropriate console method based on the log level
33
+ * (console.log, console.error, console.warn, etc.).
34
+ * @param message The JSON-formatted log message
35
+ * @param logLevel The log level determining which console method to use
36
+ * @protected
37
+ */
38
+ protected _log(message: string, logLevel: LiteralUnion<ExtendedRfc5424LogLevels, L>): void;
39
+ }
40
+ export default JsonReporter;