pinata 2.5.0 → 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,9 +2457,8 @@ var createSignedUploadURL = async (config, options, network) => {
2457
2457
  Source: "sdk/createSignURL"
2458
2458
  };
2459
2459
  }
2460
- let retryCount = 0;
2461
2460
  const maxRetries = 3;
2462
- while (retryCount <= maxRetries) {
2461
+ for (let attempt = 0; attempt <= maxRetries; attempt++) {
2463
2462
  try {
2464
2463
  const request = await fetch(`${endpoint}/files/sign`, {
2465
2464
  method: "POST",
@@ -2482,21 +2481,13 @@ var createSignedUploadURL = async (config, options, network) => {
2482
2481
  }
2483
2482
  );
2484
2483
  }
2485
- const error = new NetworkError(
2486
- `HTTP error: ${errorData}`,
2487
- request.status,
2488
- {
2489
- error: errorData,
2490
- code: "HTTP_ERROR",
2491
- metadata: {
2492
- requestUrl: request.url
2493
- }
2484
+ throw new NetworkError(`HTTP error: ${errorData}`, request.status, {
2485
+ error: errorData,
2486
+ code: "HTTP_ERROR",
2487
+ metadata: {
2488
+ requestUrl: request.url
2494
2489
  }
2495
- );
2496
- if (request.status >= 400 && request.status < 500 && request.status !== 429) {
2497
- throw error;
2498
- }
2499
- throw error;
2490
+ });
2500
2491
  }
2501
2492
  const res = await request.json();
2502
2493
  return res.data;
@@ -2507,27 +2498,24 @@ var createSignedUploadURL = async (config, options, network) => {
2507
2498
  if (error instanceof NetworkError && error.statusCode && error.statusCode >= 400 && error.statusCode < 500 && error.statusCode !== 429) {
2508
2499
  throw error;
2509
2500
  }
2510
- retryCount++;
2511
- if (retryCount > maxRetries) {
2501
+ if (attempt === maxRetries) {
2512
2502
  if (error instanceof PinataError) {
2513
2503
  throw error;
2514
2504
  }
2515
2505
  if (error instanceof Error) {
2516
2506
  throw new PinataError(
2517
- `Error processing createSignedURL after ${maxRetries} retries: ${error.message}`
2507
+ `Error processing createSignedURL: ${error.message}`
2518
2508
  );
2519
2509
  }
2520
2510
  throw new PinataError(
2521
- `An unknown error occurred while getting signed url after ${maxRetries} retries`
2511
+ "An unknown error occurred while getting signed url"
2522
2512
  );
2523
2513
  }
2524
- const delay = Math.min(1e3 * Math.pow(2, retryCount - 1), 4e3);
2514
+ const delay = Math.min(1e3 * Math.pow(2, attempt), 4e3);
2525
2515
  await new Promise((resolve) => setTimeout(resolve, delay));
2526
2516
  }
2527
2517
  }
2528
- return Promise.reject(
2529
- new PinataError("Unexpected error: retry loop completed without resolution")
2530
- );
2518
+ throw new PinataError("An unknown error occurred while getting signed url");
2531
2519
  };
2532
2520
 
2533
2521
  // src/core/functions/uploads/file.ts
@@ -2564,6 +2552,9 @@ var uploadFile = async (config, file, network, options) => {
2564
2552
  if (options?.streamable) {
2565
2553
  metadata += `,streamable ${btoa("true")}`;
2566
2554
  }
2555
+ if (options?.car) {
2556
+ metadata += `,car ${btoa("true")}`;
2557
+ }
2567
2558
  let updatedEndpoint = `${endpoint}/files`;
2568
2559
  if (options?.url) {
2569
2560
  updatedEndpoint = options.url;
@@ -2727,6 +2718,9 @@ var uploadFile = async (config, file, network, options) => {
2727
2718
  if (options?.streamable) {
2728
2719
  data.append("streamable", "true");
2729
2720
  }
2721
+ if (options?.car) {
2722
+ data.append("car", "true");
2723
+ }
2730
2724
  if (options?.url) {
2731
2725
  try {
2732
2726
  const request = await fetch(options.url, {
@@ -4261,6 +4255,10 @@ var UploadBuilder = class {
4261
4255
  this.isStreamable = true;
4262
4256
  return this;
4263
4257
  }
4258
+ car() {
4259
+ this.carFormat = true;
4260
+ return this;
4261
+ }
4264
4262
  peerAddress(peerAddresses) {
4265
4263
  this.peerAddresses = peerAddresses;
4266
4264
  return this;
@@ -4288,6 +4286,9 @@ var UploadBuilder = class {
4288
4286
  if (this.peerAddresses) {
4289
4287
  options.peerAddresses = this.peerAddresses;
4290
4288
  }
4289
+ if (this.carFormat) {
4290
+ options.car = this.carFormat;
4291
+ }
4291
4292
  this.args[this.args.length - 1] = options;
4292
4293
  return this.uploadFunction(this.config, ...this.args).then(
4293
4294
  onfulfilled,