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