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 CHANGED
@@ -418,23 +418,45 @@ var EventQueue = class {
418
418
  }
419
419
  createBatchSender() {
420
420
  return async (events) => {
421
- const payloads = events.map((e) => e.payload);
422
- const response = await fetch(this.endpoint, {
423
- method: "POST",
424
- headers: this.headers,
425
- body: JSON.stringify({ events: payloads })
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 text = await response.text();
428
- let responseBody;
429
- try {
430
- responseBody = text ? JSON.parse(text) : null;
431
- } catch {
432
- responseBody = text;
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 (!response.ok) {
435
- throw new Error(`HTTP ${response.status} ${response.statusText}: ${text}`);
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 responseBody;
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 batchEndpoint = `${this.baseUrl}${routes["raw-events-batch"]}`;
494
- this.eventQueue = new EventQueue(batchEndpoint, this._headers(), {
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 payloads = events.map((e) => e.payload);
375
- const response = await fetch(this.endpoint, {
376
- method: "POST",
377
- headers: this.headers,
378
- body: JSON.stringify({ events: payloads })
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 text = await response.text();
381
- let responseBody;
382
- try {
383
- responseBody = text ? JSON.parse(text) : null;
384
- } catch {
385
- responseBody = text;
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 (!response.ok) {
388
- throw new Error(`HTTP ${response.status} ${response.statusText}: ${text}`);
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 responseBody;
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 batchEndpoint = `${this.baseUrl}${routes["raw-events-batch"]}`;
447
- this.eventQueue = new EventQueue(batchEndpoint, this._headers(), {
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "primeorbit",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Official PrimeOrbit SDK for Node.js - Track conversations, model responses, user feedback, and custom analytics",
5
5
  "type": "module",
6
6
  "license": "MIT",