@loglayer/transport-http 1.1.0 → 1.1.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.
package/dist/index.d.ts CHANGED
@@ -1,134 +1,161 @@
1
- import { LoggerlessTransportConfig, LoggerlessTransport, LogLayerTransportParams } from '@loglayer/transport';
1
+ import { LogLayerTransportParams, LoggerlessTransport, LoggerlessTransportConfig } from "@loglayer/transport";
2
2
 
3
+ //#region src/errors.d.ts
4
+ /**
5
+ * Error thrown when HTTP request fails
6
+ */
7
+ declare class HttpTransportError extends Error {
8
+ status?: number;
9
+ response?: Response;
10
+ constructor(message: string, status?: number, response?: Response);
11
+ }
12
+ /**
13
+ * Error thrown when rate limit is exceeded
14
+ */
15
+ declare class RateLimitError extends Error {
16
+ retryAfter: number;
17
+ constructor(message: string, retryAfter: number);
18
+ }
19
+ /**
20
+ * Error thrown when log entry exceeds size limits
21
+ */
22
+ declare class LogSizeError extends Error {
23
+ logEntry: Record<string, any>;
24
+ size: number;
25
+ limit: number;
26
+ constructor(message: string, logEntry: Record<string, any>, size: number, limit: number);
27
+ }
28
+ //#endregion
29
+ //#region src/HttpTransport.d.ts
3
30
  /**
4
31
  * Configuration options for the HTTP transport.
5
32
  */
6
33
  interface HttpTransportConfig extends LoggerlessTransportConfig {
7
- /**
8
- * The URL to send logs to
9
- */
10
- url: string;
11
- /**
12
- * HTTP method to use for requests
13
- * @default "POST"
14
- */
15
- method?: string;
16
- /**
17
- * Headers to include in the request. Can be an object or a function that returns headers.
18
- */
19
- headers?: Record<string, string> | (() => Record<string, string>);
20
- /**
21
- * Content type for single log requests. User-specified headers take precedence.
22
- * @default "application/json"
23
- */
24
- contentType?: string;
25
- /**
26
- * Content type for batch log requests. User-specified headers take precedence.
27
- * @default "application/json"
28
- */
29
- batchContentType?: string;
30
- /**
31
- * Optional callback for error handling
32
- */
33
- onError?: (err: Error) => void;
34
- /**
35
- * Optional callback for debugging log entries before they are sent
36
- */
37
- onDebug?: (entry: Record<string, any>) => void;
38
- /**
39
- * Optional callback for debugging HTTP requests and responses
40
- */
41
- onDebugReqRes?: (reqRes: {
42
- req: {
43
- url: string;
44
- method: string;
45
- headers: Record<string, string>;
46
- body: string | Uint8Array;
47
- };
48
- res: {
49
- status: number;
50
- statusText: string;
51
- headers: Record<string, string>;
52
- body: string;
53
- };
54
- }) => void;
55
- /**
56
- * Function to transform log data into the payload format
57
- */
58
- payloadTemplate: (data: {
59
- logLevel: string;
60
- message: string;
61
- data?: Record<string, any>;
62
- }) => string;
63
- /**
64
- * Whether to use gzip compression
65
- * @default false
66
- */
67
- compression?: boolean;
68
- /**
69
- * Number of retry attempts before giving up
70
- * @default 3
71
- */
72
- maxRetries?: number;
73
- /**
74
- * Base delay between retries in milliseconds
75
- * @default 1000
76
- */
77
- retryDelay?: number;
78
- /**
79
- * Whether to respect rate limiting by waiting when a 429 response is received
80
- * @default true
81
- */
82
- respectRateLimit?: boolean;
83
- /**
84
- * Whether to enable batch sending
85
- * @default true
86
- */
87
- enableBatchSend?: boolean;
88
- /**
89
- * Number of log entries to batch before sending
90
- * @default 100
91
- */
92
- batchSize?: number;
93
- /**
94
- * Timeout in milliseconds for sending batches regardless of size
95
- * @default 5000
96
- */
97
- batchSendTimeout?: number;
98
- /**
99
- * Delimiter to use between log entries in batch mode
100
- * @default "\n"
101
- */
102
- batchSendDelimiter?: string;
103
- /**
104
- * Batch mode for sending multiple log entries
105
- * - "delimiter": Join entries with a delimiter (default)
106
- * - "field": Wrap entries in an object with a field name
107
- * - "array": Send entries as a plain JSON array
108
- * @default "delimiter"
109
- */
110
- batchMode?: "delimiter" | "field" | "array";
111
- /**
112
- * Field name to wrap batch entries in when batchMode is "field" (e.g., "batch" for Logflare)
113
- * @default undefined
114
- */
115
- batchFieldName?: string;
116
- /**
117
- * Maximum size of a single log entry in bytes
118
- * @default 1048576 (1MB)
119
- */
120
- maxLogSize?: number;
121
- /**
122
- * Maximum size of the payload (uncompressed) in bytes
123
- * @default 5242880 (5MB)
124
- */
125
- maxPayloadSize?: number;
126
- /**
127
- * Whether to enable Next.js Edge Runtime compatibility mode
128
- * When enabled, TextEncoder and compression are disabled
129
- * @default false
130
- */
131
- enableNextJsEdgeCompat?: boolean;
34
+ /**
35
+ * The URL to send logs to
36
+ */
37
+ url: string;
38
+ /**
39
+ * HTTP method to use for requests
40
+ * @default "POST"
41
+ */
42
+ method?: string;
43
+ /**
44
+ * Headers to include in the request. Can be an object or a function that returns headers.
45
+ */
46
+ headers?: Record<string, string> | (() => Record<string, string>);
47
+ /**
48
+ * Content type for single log requests. User-specified headers take precedence.
49
+ * @default "application/json"
50
+ */
51
+ contentType?: string;
52
+ /**
53
+ * Content type for batch log requests. User-specified headers take precedence.
54
+ * @default "application/json"
55
+ */
56
+ batchContentType?: string;
57
+ /**
58
+ * Optional callback for error handling
59
+ */
60
+ onError?: (err: Error) => void;
61
+ /**
62
+ * Optional callback for debugging log entries before they are sent
63
+ */
64
+ onDebug?: (entry: Record<string, any>) => void;
65
+ /**
66
+ * Optional callback for debugging HTTP requests and responses
67
+ */
68
+ onDebugReqRes?: (reqRes: {
69
+ req: {
70
+ url: string;
71
+ method: string;
72
+ headers: Record<string, string>;
73
+ body: string | Uint8Array;
74
+ };
75
+ res: {
76
+ status: number;
77
+ statusText: string;
78
+ headers: Record<string, string>;
79
+ body: string;
80
+ };
81
+ }) => void;
82
+ /**
83
+ * Function to transform log data into the payload format
84
+ */
85
+ payloadTemplate: (data: {
86
+ logLevel: string;
87
+ message: string;
88
+ data?: Record<string, any>;
89
+ }) => string;
90
+ /**
91
+ * Whether to use gzip compression
92
+ * @default false
93
+ */
94
+ compression?: boolean;
95
+ /**
96
+ * Number of retry attempts before giving up
97
+ * @default 3
98
+ */
99
+ maxRetries?: number;
100
+ /**
101
+ * Base delay between retries in milliseconds
102
+ * @default 1000
103
+ */
104
+ retryDelay?: number;
105
+ /**
106
+ * Whether to respect rate limiting by waiting when a 429 response is received
107
+ * @default true
108
+ */
109
+ respectRateLimit?: boolean;
110
+ /**
111
+ * Whether to enable batch sending
112
+ * @default true
113
+ */
114
+ enableBatchSend?: boolean;
115
+ /**
116
+ * Number of log entries to batch before sending
117
+ * @default 100
118
+ */
119
+ batchSize?: number;
120
+ /**
121
+ * Timeout in milliseconds for sending batches regardless of size
122
+ * @default 5000
123
+ */
124
+ batchSendTimeout?: number;
125
+ /**
126
+ * Delimiter to use between log entries in batch mode
127
+ * @default "\n"
128
+ */
129
+ batchSendDelimiter?: string;
130
+ /**
131
+ * Batch mode for sending multiple log entries
132
+ * - "delimiter": Join entries with a delimiter (default)
133
+ * - "field": Wrap entries in an object with a field name
134
+ * - "array": Send entries as a plain JSON array
135
+ * @default "delimiter"
136
+ */
137
+ batchMode?: "delimiter" | "field" | "array";
138
+ /**
139
+ * Field name to wrap batch entries in when batchMode is "field" (e.g., "batch" for Logflare)
140
+ * @default undefined
141
+ */
142
+ batchFieldName?: string;
143
+ /**
144
+ * Maximum size of a single log entry in bytes
145
+ * @default 1048576 (1MB)
146
+ */
147
+ maxLogSize?: number;
148
+ /**
149
+ * Maximum size of the payload (uncompressed) in bytes
150
+ * @default 5242880 (5MB)
151
+ */
152
+ maxPayloadSize?: number;
153
+ /**
154
+ * Whether to enable Next.js Edge Runtime compatibility mode
155
+ * When enabled, TextEncoder and compression are disabled
156
+ * @default false
157
+ */
158
+ enableNextJsEdgeCompat?: boolean;
132
159
  }
133
160
  /**
134
161
  * HttpTransport is responsible for sending logs to any HTTP endpoint.
@@ -146,61 +173,67 @@ interface HttpTransportConfig extends LoggerlessTransportConfig {
146
173
  * - Payload size tracking for batching
147
174
  */
148
175
  declare class HttpTransport extends LoggerlessTransport {
149
- private url;
150
- private method;
151
- private headers;
152
- private contentType;
153
- private batchContentType;
154
- private onError?;
155
- private onDebug?;
156
- private onDebugReqRes?;
157
- private payloadTemplate;
158
- private compression;
159
- private maxRetries;
160
- private retryDelay;
161
- private respectRateLimit;
162
- private enableBatchSend;
163
- private batchSize;
164
- private batchSendTimeout;
165
- private batchSendDelimiter;
166
- private batchMode;
167
- private batchFieldName?;
168
- private maxLogSize;
169
- private maxPayloadSize;
170
- private enableNextJsEdgeCompat;
171
- private batchQueue;
172
- private batchTimeout?;
173
- private isProcessingBatch;
174
- private currentBatchSize;
175
- /**
176
- * Creates a new instance of HttpTransport.
177
- *
178
- * @param config - Configuration options for the transport
179
- */
180
- constructor(config: HttpTransportConfig);
181
- /**
182
- * Processes and ships log entries to the HTTP endpoint.
183
- *
184
- * @param params - Log parameters including level, messages, and metadata
185
- * @returns The original messages array
186
- */
187
- shipToLogger({ logLevel, messages, data, hasData }: LogLayerTransportParams): any[];
188
- /**
189
- * Adds a payload to the batch queue and triggers sending if conditions are met
190
- */
191
- private addToBatch;
192
- /**
193
- * Processes the current batch and sends it to the HTTP endpoint
194
- */
195
- private processBatch;
196
- /**
197
- * Sends a batch of payloads to the HTTP endpoint
198
- */
199
- private sendBatch;
200
- /**
201
- * Sends a single payload to the HTTP endpoint
202
- */
203
- private sendPayload;
176
+ private url;
177
+ private method;
178
+ private headers;
179
+ private contentType;
180
+ private batchContentType;
181
+ private onError?;
182
+ private onDebug?;
183
+ private onDebugReqRes?;
184
+ private payloadTemplate;
185
+ private compression;
186
+ private maxRetries;
187
+ private retryDelay;
188
+ private respectRateLimit;
189
+ private enableBatchSend;
190
+ private batchSize;
191
+ private batchSendTimeout;
192
+ private batchSendDelimiter;
193
+ private batchMode;
194
+ private batchFieldName?;
195
+ private maxLogSize;
196
+ private maxPayloadSize;
197
+ private enableNextJsEdgeCompat;
198
+ private batchQueue;
199
+ private batchTimeout?;
200
+ private isProcessingBatch;
201
+ private currentBatchSize;
202
+ /**
203
+ * Creates a new instance of HttpTransport.
204
+ *
205
+ * @param config - Configuration options for the transport
206
+ */
207
+ constructor(config: HttpTransportConfig);
208
+ /**
209
+ * Processes and ships log entries to the HTTP endpoint.
210
+ *
211
+ * @param params - Log parameters including level, messages, and metadata
212
+ * @returns The original messages array
213
+ */
214
+ shipToLogger({
215
+ logLevel,
216
+ messages,
217
+ data,
218
+ hasData
219
+ }: LogLayerTransportParams): any[];
220
+ /**
221
+ * Adds a payload to the batch queue and triggers sending if conditions are met
222
+ */
223
+ private addToBatch;
224
+ /**
225
+ * Processes the current batch and sends it to the HTTP endpoint
226
+ */
227
+ private processBatch;
228
+ /**
229
+ * Sends a batch of payloads to the HTTP endpoint
230
+ */
231
+ private sendBatch;
232
+ /**
233
+ * Sends a single payload to the HTTP endpoint
234
+ */
235
+ private sendPayload;
204
236
  }
205
-
206
- export { HttpTransport, type HttpTransportConfig };
237
+ //#endregion
238
+ export { HttpTransport, type HttpTransportConfig, HttpTransportError, LogSizeError, RateLimitError };
239
+ //# sourceMappingURL=index.d.ts.map