pinata 2.4.9 → 2.5.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/LICENSE CHANGED
File without changes
package/README.md CHANGED
File without changes
package/dist/index.js CHANGED
@@ -2458,49 +2458,77 @@ var createSignedUploadURL = async (config, options, network) => {
2458
2458
  Source: "sdk/createSignURL"
2459
2459
  };
2460
2460
  }
2461
- try {
2462
- const request = await fetch(`${endpoint}/files/sign`, {
2463
- method: "POST",
2464
- headers,
2465
- cache: "no-store",
2466
- body: JSON.stringify(payload)
2467
- });
2468
- if (!request.ok) {
2469
- const errorData = await request.text();
2470
- if (request.status === 401 || request.status === 403) {
2471
- throw new chunkBK3CLF3Z_js.AuthenticationError(
2472
- `Authentication Failed: ${errorData}`,
2461
+ let retryCount = 0;
2462
+ const maxRetries = 3;
2463
+ while (retryCount <= maxRetries) {
2464
+ try {
2465
+ const request = await fetch(`${endpoint}/files/sign`, {
2466
+ method: "POST",
2467
+ headers,
2468
+ cache: "no-store",
2469
+ body: JSON.stringify(payload)
2470
+ });
2471
+ if (!request.ok) {
2472
+ const errorData = await request.text();
2473
+ if (request.status === 401 || request.status === 403) {
2474
+ throw new chunkBK3CLF3Z_js.AuthenticationError(
2475
+ `Authentication Failed: ${errorData}`,
2476
+ request.status,
2477
+ {
2478
+ error: errorData,
2479
+ code: "AUTH_ERROR",
2480
+ metadata: {
2481
+ requestUrl: request.url
2482
+ }
2483
+ }
2484
+ );
2485
+ }
2486
+ const error = new chunkBK3CLF3Z_js.NetworkError(
2487
+ `HTTP error: ${errorData}`,
2473
2488
  request.status,
2474
2489
  {
2475
2490
  error: errorData,
2476
- code: "AUTH_ERROR",
2491
+ code: "HTTP_ERROR",
2477
2492
  metadata: {
2478
2493
  requestUrl: request.url
2479
2494
  }
2480
2495
  }
2481
2496
  );
2497
+ if (request.status >= 400 && request.status < 500 && request.status !== 429) {
2498
+ throw error;
2499
+ }
2500
+ throw error;
2482
2501
  }
2483
- throw new chunkBK3CLF3Z_js.NetworkError(`HTTP error: ${errorData}`, request.status, {
2484
- error: errorData,
2485
- code: "HTTP_ERROR",
2486
- metadata: {
2487
- requestUrl: request.url
2502
+ const res = await request.json();
2503
+ return res.data;
2504
+ } catch (error) {
2505
+ if (error instanceof chunkBK3CLF3Z_js.AuthenticationError) {
2506
+ throw error;
2507
+ }
2508
+ if (error instanceof chunkBK3CLF3Z_js.NetworkError && error.statusCode && error.statusCode >= 400 && error.statusCode < 500 && error.statusCode !== 429) {
2509
+ throw error;
2510
+ }
2511
+ retryCount++;
2512
+ if (retryCount > maxRetries) {
2513
+ if (error instanceof chunkBK3CLF3Z_js.PinataError) {
2514
+ throw error;
2488
2515
  }
2489
- });
2490
- }
2491
- const res = await request.json();
2492
- return res.data;
2493
- } catch (error) {
2494
- if (error instanceof chunkBK3CLF3Z_js.PinataError) {
2495
- throw error;
2496
- }
2497
- if (error instanceof Error) {
2498
- throw new chunkBK3CLF3Z_js.PinataError(
2499
- `Error processing createSignedURL: ${error.message}`
2500
- );
2516
+ if (error instanceof Error) {
2517
+ throw new chunkBK3CLF3Z_js.PinataError(
2518
+ `Error processing createSignedURL after ${maxRetries} retries: ${error.message}`
2519
+ );
2520
+ }
2521
+ throw new chunkBK3CLF3Z_js.PinataError(
2522
+ `An unknown error occurred while getting signed url after ${maxRetries} retries`
2523
+ );
2524
+ }
2525
+ const delay = Math.min(1e3 * Math.pow(2, retryCount - 1), 4e3);
2526
+ await new Promise((resolve) => setTimeout(resolve, delay));
2501
2527
  }
2502
- throw new chunkBK3CLF3Z_js.PinataError("An unknown error occurred while getting signed url");
2503
2528
  }
2529
+ return Promise.reject(
2530
+ new chunkBK3CLF3Z_js.PinataError("Unexpected error: retry loop completed without resolution")
2531
+ );
2504
2532
  };
2505
2533
 
2506
2534
  // src/core/functions/uploads/file.ts