primeorbit 0.1.1 → 0.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/build/index.cjs +38 -16
- package/build/index.js +38 -16
- package/package.json +1 -1
package/build/index.cjs
CHANGED
|
@@ -418,23 +418,45 @@ var EventQueue = class {
|
|
|
418
418
|
}
|
|
419
419
|
createBatchSender() {
|
|
420
420
|
return async (events) => {
|
|
421
|
-
const
|
|
422
|
-
const
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
421
|
+
const results = [];
|
|
422
|
+
const errors = [];
|
|
423
|
+
const sendPromises = events.map(async (event) => {
|
|
424
|
+
const response = await fetch(this.endpoint, {
|
|
425
|
+
method: "POST",
|
|
426
|
+
headers: this.headers,
|
|
427
|
+
body: JSON.stringify(event.payload)
|
|
428
|
+
});
|
|
429
|
+
const text = await response.text();
|
|
430
|
+
if (!response.ok) {
|
|
431
|
+
throw new Error(
|
|
432
|
+
`HTTP ${response.status} ${response.statusText}: ${text}`
|
|
433
|
+
);
|
|
434
|
+
}
|
|
435
|
+
let responseBody;
|
|
436
|
+
try {
|
|
437
|
+
responseBody = text ? JSON.parse(text) : null;
|
|
438
|
+
} catch {
|
|
439
|
+
responseBody = text;
|
|
440
|
+
}
|
|
441
|
+
return responseBody;
|
|
426
442
|
});
|
|
427
|
-
const
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
443
|
+
const settled = await Promise.allSettled(sendPromises);
|
|
444
|
+
for (const result of settled) {
|
|
445
|
+
if (result.status === "fulfilled") {
|
|
446
|
+
results.push(result.value);
|
|
447
|
+
} else {
|
|
448
|
+
errors.push(
|
|
449
|
+
result.reason instanceof Error ? result.reason : new Error(String(result.reason))
|
|
450
|
+
);
|
|
451
|
+
}
|
|
433
452
|
}
|
|
434
|
-
if (
|
|
435
|
-
|
|
453
|
+
if (errors.length > 0) {
|
|
454
|
+
const firstError = errors[0];
|
|
455
|
+
throw new Error(
|
|
456
|
+
`${errors.length}/${events.length} events failed: ${firstError?.message ?? "Unknown error"}`
|
|
457
|
+
);
|
|
436
458
|
}
|
|
437
|
-
return
|
|
459
|
+
return results;
|
|
438
460
|
};
|
|
439
461
|
}
|
|
440
462
|
sleep(ms) {
|
|
@@ -490,8 +512,8 @@ var PrimeOrbitClient = class {
|
|
|
490
512
|
}
|
|
491
513
|
}
|
|
492
514
|
initializeEventQueue(queueOptions) {
|
|
493
|
-
const
|
|
494
|
-
this.eventQueue = new EventQueue(
|
|
515
|
+
const eventEndpoint = `${this.baseUrl}${routes["raw-events"]}`;
|
|
516
|
+
this.eventQueue = new EventQueue(eventEndpoint, this._headers(), {
|
|
495
517
|
batchSize: 100,
|
|
496
518
|
flushIntervalMs: 5e3,
|
|
497
519
|
maxConcurrentRequests: 5,
|
package/build/index.js
CHANGED
|
@@ -371,23 +371,45 @@ var EventQueue = class {
|
|
|
371
371
|
}
|
|
372
372
|
createBatchSender() {
|
|
373
373
|
return async (events) => {
|
|
374
|
-
const
|
|
375
|
-
const
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
374
|
+
const results = [];
|
|
375
|
+
const errors = [];
|
|
376
|
+
const sendPromises = events.map(async (event) => {
|
|
377
|
+
const response = await fetch(this.endpoint, {
|
|
378
|
+
method: "POST",
|
|
379
|
+
headers: this.headers,
|
|
380
|
+
body: JSON.stringify(event.payload)
|
|
381
|
+
});
|
|
382
|
+
const text = await response.text();
|
|
383
|
+
if (!response.ok) {
|
|
384
|
+
throw new Error(
|
|
385
|
+
`HTTP ${response.status} ${response.statusText}: ${text}`
|
|
386
|
+
);
|
|
387
|
+
}
|
|
388
|
+
let responseBody;
|
|
389
|
+
try {
|
|
390
|
+
responseBody = text ? JSON.parse(text) : null;
|
|
391
|
+
} catch {
|
|
392
|
+
responseBody = text;
|
|
393
|
+
}
|
|
394
|
+
return responseBody;
|
|
379
395
|
});
|
|
380
|
-
const
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
396
|
+
const settled = await Promise.allSettled(sendPromises);
|
|
397
|
+
for (const result of settled) {
|
|
398
|
+
if (result.status === "fulfilled") {
|
|
399
|
+
results.push(result.value);
|
|
400
|
+
} else {
|
|
401
|
+
errors.push(
|
|
402
|
+
result.reason instanceof Error ? result.reason : new Error(String(result.reason))
|
|
403
|
+
);
|
|
404
|
+
}
|
|
386
405
|
}
|
|
387
|
-
if (
|
|
388
|
-
|
|
406
|
+
if (errors.length > 0) {
|
|
407
|
+
const firstError = errors[0];
|
|
408
|
+
throw new Error(
|
|
409
|
+
`${errors.length}/${events.length} events failed: ${firstError?.message ?? "Unknown error"}`
|
|
410
|
+
);
|
|
389
411
|
}
|
|
390
|
-
return
|
|
412
|
+
return results;
|
|
391
413
|
};
|
|
392
414
|
}
|
|
393
415
|
sleep(ms) {
|
|
@@ -443,8 +465,8 @@ var PrimeOrbitClient = class {
|
|
|
443
465
|
}
|
|
444
466
|
}
|
|
445
467
|
initializeEventQueue(queueOptions) {
|
|
446
|
-
const
|
|
447
|
-
this.eventQueue = new EventQueue(
|
|
468
|
+
const eventEndpoint = `${this.baseUrl}${routes["raw-events"]}`;
|
|
469
|
+
this.eventQueue = new EventQueue(eventEndpoint, this._headers(), {
|
|
448
470
|
batchSize: 100,
|
|
449
471
|
flushIntervalMs: 5e3,
|
|
450
472
|
maxConcurrentRequests: 5,
|
package/package.json
CHANGED