pinata 2.4.2 → 2.4.4

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.js CHANGED
@@ -2462,6 +2462,7 @@ var createSignedUploadURL = async (config, options, network) => {
2462
2462
  const request = await fetch(`${endpoint}/files/sign`, {
2463
2463
  method: "POST",
2464
2464
  headers,
2465
+ cache: "no-store",
2465
2466
  body: JSON.stringify(payload)
2466
2467
  });
2467
2468
  if (!request.ok) {
@@ -2566,33 +2567,50 @@ var uploadFile = async (config, file, network, options) => {
2566
2567
  let uploadReq;
2567
2568
  for (let i = 0; i < totalChunks; i++) {
2568
2569
  const chunk = file.slice(offset, offset + chunkSize);
2569
- uploadReq = await fetch(url, {
2570
- method: "PATCH",
2571
- headers: {
2572
- "Content-Type": "application/offset+octet-stream",
2573
- "Upload-Offset": offset.toString(),
2574
- ...headers2
2575
- },
2576
- body: chunk
2577
- });
2578
- if (!uploadReq.ok) {
2579
- const errorData = await uploadReq.text();
2580
- throw new chunkP556VRQU_js.NetworkError(
2581
- `HTTP error during chunk upload: ${errorData}`,
2582
- uploadReq.status,
2583
- {
2584
- error: errorData,
2585
- code: "HTTP_ERROR",
2586
- metadata: {
2587
- requestUrl: uploadReq.url
2588
- }
2570
+ let retryCount = 0;
2571
+ const maxRetries = 5;
2572
+ while (retryCount <= maxRetries) {
2573
+ try {
2574
+ uploadReq = await fetch(url, {
2575
+ method: "PATCH",
2576
+ headers: {
2577
+ "Content-Type": "application/offset+octet-stream",
2578
+ "Upload-Offset": offset.toString(),
2579
+ ...headers2
2580
+ },
2581
+ body: chunk
2582
+ });
2583
+ if (uploadReq.ok) {
2584
+ break;
2585
+ } else {
2586
+ const errorData = await uploadReq.text();
2587
+ throw new Error(`HTTP ${uploadReq.status}: ${errorData}`);
2589
2588
  }
2590
- );
2589
+ } catch (error) {
2590
+ retryCount++;
2591
+ if (retryCount > maxRetries) {
2592
+ const errorData = uploadReq ? await uploadReq.text().catch(() => "Unknown error") : error instanceof Error ? error.message : String(error);
2593
+ throw new chunkP556VRQU_js.NetworkError(
2594
+ `HTTP error during chunk upload after ${maxRetries} retries: ${errorData}`,
2595
+ uploadReq?.status || 0,
2596
+ {
2597
+ error: errorData,
2598
+ code: "HTTP_ERROR",
2599
+ metadata: {
2600
+ requestUrl: uploadReq?.url || url,
2601
+ retriesAttempted: maxRetries
2602
+ }
2603
+ }
2604
+ );
2605
+ }
2606
+ const delay = Math.min(1e3 * Math.pow(2, retryCount - 1), 1e4);
2607
+ await new Promise((resolve) => setTimeout(resolve, delay));
2608
+ }
2591
2609
  }
2592
2610
  offset += chunk.size;
2593
2611
  }
2594
2612
  if (uploadReq.status === 204) {
2595
- const fileId = chunkP556VRQU_js.getFileIdFromUrl(url);
2613
+ const cid = uploadReq.headers.get("upload-cid");
2596
2614
  let dataEndpoint;
2597
2615
  if (config.endpointUrl) {
2598
2616
  dataEndpoint = config.endpointUrl;
@@ -2600,7 +2618,7 @@ var uploadFile = async (config, file, network, options) => {
2600
2618
  dataEndpoint = "https://api.pinata.cloud/v3";
2601
2619
  }
2602
2620
  const fileInfoReq = await fetch(
2603
- `${dataEndpoint}/files/${network}/${fileId}`,
2621
+ `${dataEndpoint}/files/${network}?cid=${cid}`,
2604
2622
  {
2605
2623
  method: "GET",
2606
2624
  headers: {
@@ -2609,7 +2627,7 @@ var uploadFile = async (config, file, network, options) => {
2609
2627
  }
2610
2628
  );
2611
2629
  const fileInfo = await fileInfoReq.json();
2612
- const data2 = fileInfo.data;
2630
+ const data2 = fileInfo.data.files[0];
2613
2631
  if (options?.vectorize) {
2614
2632
  const vectorReq = await fetch(
2615
2633
  `${endpoint}/vectorize/files/${data2.id}`,