pinata 2.5.0 → 2.5.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/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,11 +2552,24 @@ 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
+ }
2558
+ if (options?.cid_version !== void 0) {
2559
+ metadata += `,cid_version ${btoa(options.cid_version)}`;
2560
+ }
2567
2561
  let updatedEndpoint = `${endpoint}/files`;
2568
2562
  if (options?.url) {
2569
2563
  updatedEndpoint = options.url;
2570
2564
  }
2571
- const urlReq = await fetch(updatedEndpoint, {
2565
+ const requestUrl = new URL(updatedEndpoint);
2566
+ if (options?.cid_version !== void 0) {
2567
+ requestUrl.searchParams.set(
2568
+ "X-Upload-Option-Cid-Version",
2569
+ options.cid_version.toString()
2570
+ );
2571
+ }
2572
+ const urlReq = await fetch(requestUrl.toString(), {
2572
2573
  method: "POST",
2573
2574
  headers: {
2574
2575
  "Upload-Length": `${file.size}`,
@@ -2727,9 +2728,16 @@ var uploadFile = async (config, file, network, options) => {
2727
2728
  if (options?.streamable) {
2728
2729
  data.append("streamable", "true");
2729
2730
  }
2731
+ if (options?.car) {
2732
+ data.append("car", "true");
2733
+ }
2734
+ if (options?.cid_version !== void 0) {
2735
+ data.append("cid_version", options.cid_version.toString());
2736
+ }
2730
2737
  if (options?.url) {
2731
2738
  try {
2732
- const request = await fetch(options.url, {
2739
+ const url = new URL(options.url);
2740
+ const request = await fetch(url.toString(), {
2733
2741
  method: "POST",
2734
2742
  headers,
2735
2743
  body: data
@@ -4249,10 +4257,10 @@ var UploadBuilder = class {
4249
4257
  this.uploadUrl = url;
4250
4258
  return this;
4251
4259
  }
4252
- // cidVersion(v: 0 | 1): UploadBuilder<T> {
4253
- // this.version = v;
4254
- // return this;
4255
- // }
4260
+ cidVersion(v) {
4261
+ this._cidVersion = v;
4262
+ return this;
4263
+ }
4256
4264
  group(groupId) {
4257
4265
  this.groupId = groupId;
4258
4266
  return this;
@@ -4261,6 +4269,10 @@ var UploadBuilder = class {
4261
4269
  this.isStreamable = true;
4262
4270
  return this;
4263
4271
  }
4272
+ car() {
4273
+ this.carFormat = true;
4274
+ return this;
4275
+ }
4264
4276
  peerAddress(peerAddresses) {
4265
4277
  this.peerAddresses = peerAddresses;
4266
4278
  return this;
@@ -4288,6 +4300,12 @@ var UploadBuilder = class {
4288
4300
  if (this.peerAddresses) {
4289
4301
  options.peerAddresses = this.peerAddresses;
4290
4302
  }
4303
+ if (this.carFormat) {
4304
+ options.car = this.carFormat;
4305
+ }
4306
+ if (this._cidVersion !== void 0) {
4307
+ options.cid_version = this._cidVersion;
4308
+ }
4291
4309
  this.args[this.args.length - 1] = options;
4292
4310
  return this.uploadFunction(this.config, ...this.args).then(
4293
4311
  onfulfilled,