fireberry-api-client 1.0.2-beta.1.3 → 1.0.2-beta.2.0

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
@@ -1077,6 +1077,7 @@ function chunkArray(array, size) {
1077
1077
  var HTTPTransport = class {
1078
1078
  config;
1079
1079
  constructor(config) {
1080
+ console.log("[HTTPTransport] CONSTRUCTOR CALLED", config);
1080
1081
  this.config = {
1081
1082
  apiKey: config.apiKey,
1082
1083
  baseUrl: config.baseUrl || "https://api.fireberry.com",
@@ -1296,14 +1297,20 @@ var HTTPTransport = class {
1296
1297
  };
1297
1298
  }
1298
1299
  /**
1299
- * Executes a fetch request with retry logic for 429 errors
1300
+ * Executes a fetch request with retry logic for 429 errors and timeouts
1301
+ * Implements exponential backoff for timeout duration
1300
1302
  */
1301
1303
  async executeWithRetry(url, options, retryCount = 0) {
1302
1304
  try {
1305
+ const maxTimeout = 3e5;
1306
+ const currentTimeout = Math.min(
1307
+ this.config.timeout * Math.pow(2, retryCount),
1308
+ maxTimeout
1309
+ );
1303
1310
  const timeoutController = new AbortController();
1304
1311
  const timeoutId = setTimeout(() => {
1305
1312
  timeoutController.abort();
1306
- }, this.config.timeout);
1313
+ }, currentTimeout);
1307
1314
  const combinedSignal = options.signal ? this.combineSignals([options.signal, timeoutController.signal]) : timeoutController.signal;
1308
1315
  const response = await fetch(url, {
1309
1316
  ...options,
@@ -1334,7 +1341,17 @@ var HTTPTransport = class {
1334
1341
  return body;
1335
1342
  } catch (error) {
1336
1343
  if (error instanceof Error && error.name === "AbortError") {
1337
- throw createNetworkError(error);
1344
+ if (options.signal?.aborted) {
1345
+ throw createNetworkError(error);
1346
+ }
1347
+ if (this.config.retryOn429 && retryCount < this.config.maxRetries) {
1348
+ await wait(this.config.retryDelay);
1349
+ return this.executeWithRetry(url, options, retryCount + 1);
1350
+ }
1351
+ throw new FireberryError("Request timeout after max retries", {
1352
+ code: "TIMEOUT" /* TIMEOUT */,
1353
+ context: { retryCount }
1354
+ });
1338
1355
  }
1339
1356
  if (error instanceof FireberryError) {
1340
1357
  throw error;
@@ -1363,6 +1380,7 @@ var BATCH_SIZE = 20;
1363
1380
  var SDKTransport = class {
1364
1381
  sdk;
1365
1382
  constructor(config) {
1383
+ console.log("[SDKTransport] CONSTRUCTOR CALLED", config);
1366
1384
  this.sdk = config.sdk;
1367
1385
  }
1368
1386
  getType() {
@@ -1616,10 +1634,16 @@ var SDKTransport = class {
1616
1634
 
1617
1635
  // src/utils/transport.ts
1618
1636
  function createTransport(config) {
1637
+ console.log("[createTransport] config:", config);
1638
+ console.log("[createTransport] config.sdk:", config.sdk);
1639
+ console.log("[createTransport] config.apiKey:", config.apiKey);
1640
+ console.log("[createTransport] !!config.sdk:", !!config.sdk);
1619
1641
  if (config.sdk) {
1642
+ console.log("[createTransport] Using SDKTransport");
1620
1643
  return new SDKTransport({ sdk: config.sdk });
1621
1644
  }
1622
1645
  if (config.apiKey) {
1646
+ console.log("[createTransport] Using HTTPTransport");
1623
1647
  return new HTTPTransport({
1624
1648
  apiKey: config.apiKey,
1625
1649
  baseUrl: config.baseUrl,