@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.cjs +329 -322
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +216 -183
- package/dist/index.d.ts +216 -183
- package/dist/index.js +302 -322
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,134 +1,161 @@
|
|
|
1
|
-
import {
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
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
|