@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 CHANGED
@@ -1,336 +1,343 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } var _class;// src/HttpTransport.ts
2
- var _transport = require('@loglayer/transport');
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+
23
+ //#endregion
24
+ let __loglayer_transport = require("@loglayer/transport");
25
+ __loglayer_transport = __toESM(__loglayer_transport);
26
+
27
+ //#region src/errors.ts
28
+ /**
29
+ * Error thrown when HTTP request fails
30
+ */
3
31
  var HttpTransportError = class extends Error {
4
- constructor(message, status, response) {
5
- super(message);
6
- this.status = status;
7
- this.response = response;
8
- this.name = "HttpTransportError";
9
- }
32
+ constructor(message, status, response) {
33
+ super(message);
34
+ this.status = status;
35
+ this.response = response;
36
+ this.name = "HttpTransportError";
37
+ }
10
38
  };
39
+ /**
40
+ * Error thrown when rate limit is exceeded
41
+ */
11
42
  var RateLimitError = class extends Error {
12
- constructor(message, retryAfter) {
13
- super(message);
14
- this.retryAfter = retryAfter;
15
- this.name = "RateLimitError";
16
- }
43
+ constructor(message, retryAfter) {
44
+ super(message);
45
+ this.retryAfter = retryAfter;
46
+ this.name = "RateLimitError";
47
+ }
17
48
  };
49
+ /**
50
+ * Error thrown when log entry exceeds size limits
51
+ */
18
52
  var LogSizeError = class extends Error {
19
- constructor(message, logEntry, size, limit) {
20
- super(message);
21
- this.logEntry = logEntry;
22
- this.size = size;
23
- this.limit = limit;
24
- this.name = "LogSizeError";
25
- }
53
+ constructor(message, logEntry, size, limit) {
54
+ super(message);
55
+ this.logEntry = logEntry;
56
+ this.size = size;
57
+ this.limit = limit;
58
+ this.name = "LogSizeError";
59
+ }
26
60
  };
61
+
62
+ //#endregion
63
+ //#region src/utils.ts
64
+ /**
65
+ * Compresses data using gzip compression
66
+ */
27
67
  async function compressData(data) {
28
- const encoder = new TextEncoder();
29
- const dataBytes = encoder.encode(data);
30
- if (typeof CompressionStream !== "undefined") {
31
- const stream = new CompressionStream("gzip");
32
- const writer = stream.writable.getWriter();
33
- const reader = stream.readable.getReader();
34
- await writer.write(dataBytes);
35
- await writer.close();
36
- const chunks = [];
37
- while (true) {
38
- const { done, value } = await reader.read();
39
- if (done) break;
40
- chunks.push(value);
41
- }
42
- const totalLength = chunks.reduce((acc, chunk) => acc + chunk.length, 0);
43
- const result = new Uint8Array(totalLength);
44
- let offset = 0;
45
- for (const chunk of chunks) {
46
- result.set(chunk, offset);
47
- offset += chunk.length;
48
- }
49
- return result;
50
- }
51
- throw new Error("Gzip compression not supported in this environment");
68
+ const dataBytes = new TextEncoder().encode(data);
69
+ if (typeof CompressionStream !== "undefined") {
70
+ const stream = new CompressionStream("gzip");
71
+ const writer = stream.writable.getWriter();
72
+ const reader = stream.readable.getReader();
73
+ await writer.write(dataBytes);
74
+ await writer.close();
75
+ const chunks = [];
76
+ while (true) {
77
+ const { done, value } = await reader.read();
78
+ if (done) break;
79
+ chunks.push(value);
80
+ }
81
+ const totalLength = chunks.reduce((acc, chunk) => acc + chunk.length, 0);
82
+ const result = new Uint8Array(totalLength);
83
+ let offset = 0;
84
+ for (const chunk of chunks) {
85
+ result.set(chunk, offset);
86
+ offset += chunk.length;
87
+ }
88
+ return result;
89
+ }
90
+ throw new Error("Gzip compression not supported in this environment");
52
91
  }
92
+ /**
93
+ * Sends HTTP request with retry logic and rate limiting
94
+ */
53
95
  async function sendWithRetry(url, method, headers, payload, maxRetries, retryDelay, respectRateLimit = true, onDebugReqRes, onError) {
54
- let lastError;
55
- for (let attempt = 0; attempt <= maxRetries; attempt++) {
56
- try {
57
- const response = await fetch(url, {
58
- method,
59
- headers,
60
- body: payload
61
- });
62
- if (onDebugReqRes) {
63
- try {
64
- const responseBody = await response.clone().text();
65
- const responseHeaders = {};
66
- response.headers.forEach((value, key) => {
67
- responseHeaders[key] = value;
68
- });
69
- onDebugReqRes({
70
- req: {
71
- url,
72
- method,
73
- headers,
74
- body: payload
75
- },
76
- res: {
77
- status: response.status,
78
- statusText: response.statusText,
79
- headers: responseHeaders,
80
- body: responseBody
81
- }
82
- });
83
- } catch (debugError) {
84
- if (onError) {
85
- onError(new Error(`Debug callback error: ${debugError}`));
86
- }
87
- }
88
- }
89
- if (response.status === 429 && respectRateLimit) {
90
- const retryAfter = response.headers.get("retry-after");
91
- const waitTime = retryAfter ? Number.parseInt(retryAfter, 10) * 1e3 : retryDelay;
92
- throw new RateLimitError(`Rate limit exceeded. Retry after ${waitTime}ms`, waitTime);
93
- }
94
- if (response.status !== 200 && onError) {
95
- onError(new Error(`HTTP request failed with status ${response.status}: ${response.statusText}`));
96
- }
97
- if (!response.ok) {
98
- throw new HttpTransportError(`HTTP ${response.status}: ${response.statusText}`, response.status, response);
99
- }
100
- return response;
101
- } catch (error) {
102
- lastError = error;
103
- if (error instanceof RateLimitError && respectRateLimit) {
104
- await new Promise((resolve) => setTimeout(resolve, error.retryAfter));
105
- continue;
106
- }
107
- if (attempt === maxRetries) {
108
- throw error;
109
- }
110
- const waitTime = retryDelay * 2 ** attempt;
111
- await new Promise((resolve) => setTimeout(resolve, waitTime));
112
- }
113
- }
114
- throw lastError;
96
+ let lastError;
97
+ for (let attempt = 0; attempt <= maxRetries; attempt++) try {
98
+ const response = await fetch(url, {
99
+ method,
100
+ headers,
101
+ body: payload
102
+ });
103
+ if (onDebugReqRes) try {
104
+ const responseBody = await response.clone().text();
105
+ const responseHeaders = {};
106
+ response.headers.forEach((value, key) => {
107
+ responseHeaders[key] = value;
108
+ });
109
+ onDebugReqRes({
110
+ req: {
111
+ url,
112
+ method,
113
+ headers,
114
+ body: payload
115
+ },
116
+ res: {
117
+ status: response.status,
118
+ statusText: response.statusText,
119
+ headers: responseHeaders,
120
+ body: responseBody
121
+ }
122
+ });
123
+ } catch (debugError) {
124
+ if (onError) onError(/* @__PURE__ */ new Error(`Debug callback error: ${debugError}`));
125
+ }
126
+ if (response.status === 429 && respectRateLimit) {
127
+ const retryAfter = response.headers.get("retry-after");
128
+ const waitTime = retryAfter ? Number.parseInt(retryAfter, 10) * 1e3 : retryDelay;
129
+ throw new RateLimitError(`Rate limit exceeded. Retry after ${waitTime}ms`, waitTime);
130
+ }
131
+ if (response.status < 200 || response.status >= 300) {
132
+ if (onError) onError(/* @__PURE__ */ new Error(`HTTP request failed with status ${response.status}: ${response.statusText}`));
133
+ }
134
+ if (!response.ok) throw new HttpTransportError(`HTTP ${response.status}: ${response.statusText}`, response.status, response);
135
+ return response;
136
+ } catch (error) {
137
+ lastError = error;
138
+ if (error instanceof RateLimitError && respectRateLimit) {
139
+ await new Promise((resolve) => setTimeout(resolve, error.retryAfter));
140
+ continue;
141
+ }
142
+ if (attempt === maxRetries) throw error;
143
+ const waitTime = retryDelay * 2 ** attempt;
144
+ await new Promise((resolve) => setTimeout(resolve, waitTime));
145
+ }
146
+ throw lastError;
115
147
  }
116
- var HttpTransport = (_class = class extends _transport.LoggerlessTransport {
117
-
118
-
119
-
120
-
121
-
122
-
123
-
124
-
125
-
126
-
127
-
128
-
129
-
130
-
131
-
132
-
133
-
134
-
135
-
136
-
137
-
138
-
139
- // Batch management
140
- __init() {this.batchQueue = []}
141
-
142
- __init2() {this.isProcessingBatch = false}
143
- __init3() {this.currentBatchSize = 0}
144
- // Track uncompressed size of current batch
145
- /**
146
- * Creates a new instance of HttpTransport.
147
- *
148
- * @param config - Configuration options for the transport
149
- */
150
- constructor(config) {
151
- super(config);_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);;
152
- this.url = config.url;
153
- this.method = _nullishCoalesce(config.method, () => ( "POST"));
154
- this.headers = _nullishCoalesce(config.headers, () => ( {}));
155
- this.contentType = _nullishCoalesce(config.contentType, () => ( "application/json"));
156
- this.batchContentType = _nullishCoalesce(config.batchContentType, () => ( "application/json"));
157
- this.onError = config.onError;
158
- this.onDebug = config.onDebug;
159
- this.onDebugReqRes = config.onDebugReqRes;
160
- this.payloadTemplate = config.payloadTemplate;
161
- this.compression = _nullishCoalesce(config.compression, () => ( false));
162
- this.maxRetries = _nullishCoalesce(config.maxRetries, () => ( 3));
163
- this.retryDelay = _nullishCoalesce(config.retryDelay, () => ( 1e3));
164
- this.respectRateLimit = _nullishCoalesce(config.respectRateLimit, () => ( true));
165
- this.enableBatchSend = _nullishCoalesce(config.enableBatchSend, () => ( true));
166
- this.batchSize = _nullishCoalesce(config.batchSize, () => ( 100));
167
- this.batchSendTimeout = _nullishCoalesce(config.batchSendTimeout, () => ( 5e3));
168
- this.batchSendDelimiter = _nullishCoalesce(config.batchSendDelimiter, () => ( "\n"));
169
- this.batchMode = _nullishCoalesce(config.batchMode, () => ( "delimiter"));
170
- this.batchFieldName = config.batchFieldName;
171
- if (this.batchMode === "field" && !this.batchFieldName) {
172
- throw new Error("batchFieldName is required when batchMode is 'field'");
173
- }
174
- this.maxLogSize = _nullishCoalesce(config.maxLogSize, () => ( 1048576));
175
- this.maxPayloadSize = _nullishCoalesce(config.maxPayloadSize, () => ( 5242880));
176
- this.enableNextJsEdgeCompat = _nullishCoalesce(config.enableNextJsEdgeCompat, () => ( false));
177
- }
178
- /**
179
- * Processes and ships log entries to the HTTP endpoint.
180
- *
181
- * @param params - Log parameters including level, messages, and metadata
182
- * @returns The original messages array
183
- */
184
- shipToLogger({ logLevel, messages, data, hasData }) {
185
- try {
186
- const message = messages.join(" ");
187
- const payloadTemplate = {
188
- logLevel,
189
- message
190
- };
191
- if (hasData) {
192
- payloadTemplate["data"] = data;
193
- }
194
- const payload = this.payloadTemplate(payloadTemplate);
195
- if (this.onDebug) {
196
- this.onDebug({ logLevel, message, data });
197
- }
198
- let logEntrySize;
199
- if (this.enableNextJsEdgeCompat || typeof TextEncoder === "undefined") {
200
- logEntrySize = Buffer.byteLength(payload, "utf8");
201
- } else {
202
- logEntrySize = new TextEncoder().encode(payload).length;
203
- }
204
- if (logEntrySize > this.maxLogSize) {
205
- const error = new LogSizeError(
206
- `Log entry exceeds maximum size of ${this.maxLogSize} bytes. Size: ${logEntrySize} bytes`,
207
- { logLevel, message, data },
208
- logEntrySize,
209
- this.maxLogSize
210
- );
211
- if (this.onError) {
212
- this.onError(error);
213
- }
214
- return messages;
215
- }
216
- if (this.enableBatchSend) {
217
- this.addToBatch(payload, logEntrySize);
218
- } else {
219
- this.sendPayload(payload).catch((err) => {
220
- if (this.onError) {
221
- this.onError(err);
222
- }
223
- });
224
- }
225
- } catch (error) {
226
- if (this.onError) {
227
- this.onError(error);
228
- }
229
- }
230
- return messages;
231
- }
232
- /**
233
- * Adds a payload to the batch queue and triggers sending if conditions are met
234
- */
235
- addToBatch(payload, logEntrySize) {
236
- const payloadSizeWithEntry = this.currentBatchSize + logEntrySize + this.batchSendDelimiter.length;
237
- const payloadSizeThreshold = this.maxPayloadSize * 0.9;
238
- if (payloadSizeWithEntry > payloadSizeThreshold && this.batchQueue.length > 0) {
239
- this.processBatch();
240
- }
241
- this.batchQueue.push(payload);
242
- this.currentBatchSize += logEntrySize + this.batchSendDelimiter.length;
243
- if (!this.batchTimeout) {
244
- this.batchTimeout = setTimeout(() => {
245
- this.processBatch();
246
- }, this.batchSendTimeout);
247
- }
248
- if (this.batchQueue.length >= this.batchSize) {
249
- this.processBatch();
250
- }
251
- }
252
- /**
253
- * Processes the current batch and sends it to the HTTP endpoint
254
- */
255
- async processBatch() {
256
- if (this.isProcessingBatch || this.batchQueue.length === 0) {
257
- return;
258
- }
259
- this.isProcessingBatch = true;
260
- if (this.batchTimeout) {
261
- clearTimeout(this.batchTimeout);
262
- this.batchTimeout = void 0;
263
- }
264
- const batch = this.batchQueue.splice(0, this.batchSize);
265
- this.currentBatchSize = 0;
266
- try {
267
- await this.sendBatch(batch);
268
- } catch (error) {
269
- if (this.onError) {
270
- this.onError(error);
271
- }
272
- } finally {
273
- this.isProcessingBatch = false;
274
- if (this.batchQueue.length > 0) {
275
- this.processBatch();
276
- }
277
- }
278
- }
279
- /**
280
- * Sends a batch of payloads to the HTTP endpoint
281
- */
282
- async sendBatch(batch) {
283
- let batchPayload;
284
- switch (this.batchMode) {
285
- case "array":
286
- const batchEntries = batch.map((payload) => JSON.parse(payload));
287
- batchPayload = JSON.stringify(batchEntries);
288
- break;
289
- case "field":
290
- const fieldEntries = batch.map((payload) => JSON.parse(payload));
291
- const batchObject = { [this.batchFieldName]: fieldEntries };
292
- batchPayload = JSON.stringify(batchObject);
293
- break;
294
- case "delimiter":
295
- default:
296
- batchPayload = batch.join(this.batchSendDelimiter);
297
- break;
298
- }
299
- await this.sendPayload(batchPayload, this.batchContentType);
300
- }
301
- /**
302
- * Sends a single payload to the HTTP endpoint
303
- */
304
- async sendPayload(payload, contentType) {
305
- const headers = typeof this.headers === "function" ? this.headers() : { ...this.headers };
306
- if (!headers["content-type"]) {
307
- headers["content-type"] = _nullishCoalesce(contentType, () => ( this.contentType));
308
- }
309
- let finalPayload = payload;
310
- if (this.compression && !this.enableNextJsEdgeCompat) {
311
- try {
312
- finalPayload = await compressData(payload);
313
- headers["content-encoding"] = "gzip";
314
- } catch (error) {
315
- if (this.onError) {
316
- this.onError(new Error(`Compression failed: ${error}`));
317
- }
318
- }
319
- }
320
- await sendWithRetry(
321
- this.url,
322
- this.method,
323
- headers,
324
- finalPayload,
325
- this.maxRetries,
326
- this.retryDelay,
327
- this.respectRateLimit,
328
- this.onDebugReqRes,
329
- this.onError
330
- );
331
- }
332
- }, _class);
333
148
 
149
+ //#endregion
150
+ //#region src/HttpTransport.ts
151
+ /**
152
+ * HttpTransport is responsible for sending logs to any HTTP endpoint.
153
+ * It supports batching, compression, retries, and rate limiting.
154
+ *
155
+ * Features:
156
+ * - Configurable HTTP method and headers
157
+ * - Custom payload template function
158
+ * - Gzip compression support
159
+ * - Retry logic with exponential backoff
160
+ * - Rate limiting support
161
+ * - Batch sending with configurable size and timeout
162
+ * - Error and debug callbacks
163
+ * - Log size validation
164
+ * - Payload size tracking for batching
165
+ */
166
+ var HttpTransport = class extends __loglayer_transport.LoggerlessTransport {
167
+ url;
168
+ method;
169
+ headers;
170
+ contentType;
171
+ batchContentType;
172
+ onError;
173
+ onDebug;
174
+ onDebugReqRes;
175
+ payloadTemplate;
176
+ compression;
177
+ maxRetries;
178
+ retryDelay;
179
+ respectRateLimit;
180
+ enableBatchSend;
181
+ batchSize;
182
+ batchSendTimeout;
183
+ batchSendDelimiter;
184
+ batchMode;
185
+ batchFieldName;
186
+ maxLogSize;
187
+ maxPayloadSize;
188
+ enableNextJsEdgeCompat;
189
+ batchQueue = [];
190
+ batchTimeout;
191
+ isProcessingBatch = false;
192
+ currentBatchSize = 0;
193
+ /**
194
+ * Creates a new instance of HttpTransport.
195
+ *
196
+ * @param config - Configuration options for the transport
197
+ */
198
+ constructor(config) {
199
+ super(config);
200
+ this.url = config.url;
201
+ this.method = config.method ?? "POST";
202
+ this.headers = config.headers ?? {};
203
+ this.contentType = config.contentType ?? "application/json";
204
+ this.batchContentType = config.batchContentType ?? "application/json";
205
+ this.onError = config.onError;
206
+ this.onDebug = config.onDebug;
207
+ this.onDebugReqRes = config.onDebugReqRes;
208
+ this.payloadTemplate = config.payloadTemplate;
209
+ this.compression = config.compression ?? false;
210
+ this.maxRetries = config.maxRetries ?? 3;
211
+ this.retryDelay = config.retryDelay ?? 1e3;
212
+ this.respectRateLimit = config.respectRateLimit ?? true;
213
+ this.enableBatchSend = config.enableBatchSend ?? true;
214
+ this.batchSize = config.batchSize ?? 100;
215
+ this.batchSendTimeout = config.batchSendTimeout ?? 5e3;
216
+ this.batchSendDelimiter = config.batchSendDelimiter ?? "\n";
217
+ this.batchMode = config.batchMode ?? "delimiter";
218
+ this.batchFieldName = config.batchFieldName;
219
+ if (this.batchMode === "field" && !this.batchFieldName) throw new Error("batchFieldName is required when batchMode is 'field'");
220
+ this.maxLogSize = config.maxLogSize ?? 1048576;
221
+ this.maxPayloadSize = config.maxPayloadSize ?? 5242880;
222
+ this.enableNextJsEdgeCompat = config.enableNextJsEdgeCompat ?? false;
223
+ }
224
+ /**
225
+ * Processes and ships log entries to the HTTP endpoint.
226
+ *
227
+ * @param params - Log parameters including level, messages, and metadata
228
+ * @returns The original messages array
229
+ */
230
+ shipToLogger({ logLevel, messages, data, hasData }) {
231
+ try {
232
+ const message = messages.join(" ");
233
+ const payloadTemplate = {
234
+ logLevel,
235
+ message
236
+ };
237
+ if (hasData) payloadTemplate["data"] = data;
238
+ const payload = this.payloadTemplate(payloadTemplate);
239
+ if (this.onDebug) this.onDebug({
240
+ logLevel,
241
+ message,
242
+ data
243
+ });
244
+ let logEntrySize;
245
+ if (this.enableNextJsEdgeCompat || typeof TextEncoder === "undefined") logEntrySize = Buffer.byteLength(payload, "utf8");
246
+ else logEntrySize = new TextEncoder().encode(payload).length;
247
+ if (logEntrySize > this.maxLogSize) {
248
+ const error = new LogSizeError(`Log entry exceeds maximum size of ${this.maxLogSize} bytes. Size: ${logEntrySize} bytes`, {
249
+ logLevel,
250
+ message,
251
+ data
252
+ }, logEntrySize, this.maxLogSize);
253
+ if (this.onError) this.onError(error);
254
+ return messages;
255
+ }
256
+ if (this.enableBatchSend) this.addToBatch(payload, logEntrySize);
257
+ else this.sendPayload(payload).catch((err) => {
258
+ if (this.onError) this.onError(err);
259
+ });
260
+ } catch (error) {
261
+ if (this.onError) this.onError(error);
262
+ }
263
+ return messages;
264
+ }
265
+ /**
266
+ * Adds a payload to the batch queue and triggers sending if conditions are met
267
+ */
268
+ addToBatch(payload, logEntrySize) {
269
+ if (this.currentBatchSize + logEntrySize + this.batchSendDelimiter.length > this.maxPayloadSize * .9 && this.batchQueue.length > 0) this.processBatch();
270
+ this.batchQueue.push(payload);
271
+ this.currentBatchSize += logEntrySize + this.batchSendDelimiter.length;
272
+ if (!this.batchTimeout) this.batchTimeout = setTimeout(() => {
273
+ this.processBatch();
274
+ }, this.batchSendTimeout);
275
+ if (this.batchQueue.length >= this.batchSize) this.processBatch();
276
+ }
277
+ /**
278
+ * Processes the current batch and sends it to the HTTP endpoint
279
+ */
280
+ async processBatch() {
281
+ if (this.isProcessingBatch || this.batchQueue.length === 0) return;
282
+ this.isProcessingBatch = true;
283
+ if (this.batchTimeout) {
284
+ clearTimeout(this.batchTimeout);
285
+ this.batchTimeout = void 0;
286
+ }
287
+ const batch = this.batchQueue.splice(0, this.batchSize);
288
+ this.currentBatchSize = 0;
289
+ try {
290
+ await this.sendBatch(batch);
291
+ } catch (error) {
292
+ if (this.onError) this.onError(error);
293
+ } finally {
294
+ this.isProcessingBatch = false;
295
+ if (this.batchQueue.length > 0) this.processBatch();
296
+ }
297
+ }
298
+ /**
299
+ * Sends a batch of payloads to the HTTP endpoint
300
+ */
301
+ async sendBatch(batch) {
302
+ let batchPayload;
303
+ switch (this.batchMode) {
304
+ case "array": {
305
+ const batchEntries = batch.map((payload) => JSON.parse(payload));
306
+ batchPayload = JSON.stringify(batchEntries);
307
+ break;
308
+ }
309
+ case "field": {
310
+ const fieldEntries = batch.map((payload) => JSON.parse(payload));
311
+ const batchObject = { [this.batchFieldName]: fieldEntries };
312
+ batchPayload = JSON.stringify(batchObject);
313
+ break;
314
+ }
315
+ default:
316
+ batchPayload = batch.join(this.batchSendDelimiter);
317
+ break;
318
+ }
319
+ await this.sendPayload(batchPayload, this.batchContentType);
320
+ }
321
+ /**
322
+ * Sends a single payload to the HTTP endpoint
323
+ */
324
+ async sendPayload(payload, contentType) {
325
+ const headers = typeof this.headers === "function" ? this.headers() : { ...this.headers };
326
+ if (!headers["content-type"]) headers["content-type"] = contentType ?? this.contentType;
327
+ let finalPayload = payload;
328
+ if (this.compression && !this.enableNextJsEdgeCompat) try {
329
+ finalPayload = await compressData(payload);
330
+ headers["content-encoding"] = "gzip";
331
+ } catch (error) {
332
+ if (this.onError) this.onError(/* @__PURE__ */ new Error(`Compression failed: ${error}`));
333
+ }
334
+ await sendWithRetry(this.url, this.method, headers, finalPayload, this.maxRetries, this.retryDelay, this.respectRateLimit, this.onDebugReqRes, this.onError);
335
+ }
336
+ };
334
337
 
338
+ //#endregion
335
339
  exports.HttpTransport = HttpTransport;
340
+ exports.HttpTransportError = HttpTransportError;
341
+ exports.LogSizeError = LogSizeError;
342
+ exports.RateLimitError = RateLimitError;
336
343
  //# sourceMappingURL=index.cjs.map