pinata 2.4.9 → 2.5.1

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.mjs CHANGED
@@ -2457,49 +2457,65 @@ var createSignedUploadURL = async (config, options, network) => {
2457
2457
  Source: "sdk/createSignURL"
2458
2458
  };
2459
2459
  }
2460
- try {
2461
- const request = await fetch(`${endpoint}/files/sign`, {
2462
- method: "POST",
2463
- headers,
2464
- cache: "no-store",
2465
- body: JSON.stringify(payload)
2466
- });
2467
- if (!request.ok) {
2468
- const errorData = await request.text();
2469
- if (request.status === 401 || request.status === 403) {
2470
- throw new AuthenticationError(
2471
- `Authentication Failed: ${errorData}`,
2472
- request.status,
2473
- {
2474
- error: errorData,
2475
- code: "AUTH_ERROR",
2476
- metadata: {
2477
- requestUrl: request.url
2460
+ const maxRetries = 3;
2461
+ for (let attempt = 0; attempt <= maxRetries; attempt++) {
2462
+ try {
2463
+ const request = await fetch(`${endpoint}/files/sign`, {
2464
+ method: "POST",
2465
+ headers,
2466
+ cache: "no-store",
2467
+ body: JSON.stringify(payload)
2468
+ });
2469
+ if (!request.ok) {
2470
+ const errorData = await request.text();
2471
+ if (request.status === 401 || request.status === 403) {
2472
+ throw new AuthenticationError(
2473
+ `Authentication Failed: ${errorData}`,
2474
+ request.status,
2475
+ {
2476
+ error: errorData,
2477
+ code: "AUTH_ERROR",
2478
+ metadata: {
2479
+ requestUrl: request.url
2480
+ }
2478
2481
  }
2482
+ );
2483
+ }
2484
+ throw new NetworkError(`HTTP error: ${errorData}`, request.status, {
2485
+ error: errorData,
2486
+ code: "HTTP_ERROR",
2487
+ metadata: {
2488
+ requestUrl: request.url
2479
2489
  }
2480
- );
2490
+ });
2481
2491
  }
2482
- throw new NetworkError(`HTTP error: ${errorData}`, request.status, {
2483
- error: errorData,
2484
- code: "HTTP_ERROR",
2485
- metadata: {
2486
- requestUrl: request.url
2492
+ const res = await request.json();
2493
+ return res.data;
2494
+ } catch (error) {
2495
+ if (error instanceof AuthenticationError) {
2496
+ throw error;
2497
+ }
2498
+ if (error instanceof NetworkError && error.statusCode && error.statusCode >= 400 && error.statusCode < 500 && error.statusCode !== 429) {
2499
+ throw error;
2500
+ }
2501
+ if (attempt === maxRetries) {
2502
+ if (error instanceof PinataError) {
2503
+ throw error;
2487
2504
  }
2488
- });
2489
- }
2490
- const res = await request.json();
2491
- return res.data;
2492
- } catch (error) {
2493
- if (error instanceof PinataError) {
2494
- throw error;
2495
- }
2496
- if (error instanceof Error) {
2497
- throw new PinataError(
2498
- `Error processing createSignedURL: ${error.message}`
2499
- );
2505
+ if (error instanceof Error) {
2506
+ throw new PinataError(
2507
+ `Error processing createSignedURL: ${error.message}`
2508
+ );
2509
+ }
2510
+ throw new PinataError(
2511
+ "An unknown error occurred while getting signed url"
2512
+ );
2513
+ }
2514
+ const delay = Math.min(1e3 * Math.pow(2, attempt), 4e3);
2515
+ await new Promise((resolve) => setTimeout(resolve, delay));
2500
2516
  }
2501
- throw new PinataError("An unknown error occurred while getting signed url");
2502
2517
  }
2518
+ throw new PinataError("An unknown error occurred while getting signed url");
2503
2519
  };
2504
2520
 
2505
2521
  // src/core/functions/uploads/file.ts
@@ -2536,6 +2552,9 @@ var uploadFile = async (config, file, network, options) => {
2536
2552
  if (options?.streamable) {
2537
2553
  metadata += `,streamable ${btoa("true")}`;
2538
2554
  }
2555
+ if (options?.car) {
2556
+ metadata += `,car ${btoa("true")}`;
2557
+ }
2539
2558
  let updatedEndpoint = `${endpoint}/files`;
2540
2559
  if (options?.url) {
2541
2560
  updatedEndpoint = options.url;
@@ -2699,6 +2718,9 @@ var uploadFile = async (config, file, network, options) => {
2699
2718
  if (options?.streamable) {
2700
2719
  data.append("streamable", "true");
2701
2720
  }
2721
+ if (options?.car) {
2722
+ data.append("car", "true");
2723
+ }
2702
2724
  if (options?.url) {
2703
2725
  try {
2704
2726
  const request = await fetch(options.url, {
@@ -4233,6 +4255,10 @@ var UploadBuilder = class {
4233
4255
  this.isStreamable = true;
4234
4256
  return this;
4235
4257
  }
4258
+ car() {
4259
+ this.carFormat = true;
4260
+ return this;
4261
+ }
4236
4262
  peerAddress(peerAddresses) {
4237
4263
  this.peerAddresses = peerAddresses;
4238
4264
  return this;
@@ -4260,6 +4286,9 @@ var UploadBuilder = class {
4260
4286
  if (this.peerAddresses) {
4261
4287
  options.peerAddresses = this.peerAddresses;
4262
4288
  }
4289
+ if (this.carFormat) {
4290
+ options.car = this.carFormat;
4291
+ }
4263
4292
  this.args[this.args.length - 1] = options;
4264
4293
  return this.uploadFunction(this.config, ...this.args).then(
4265
4294
  onfulfilled,