pinata 2.4.3 → 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.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { ValidationError, AuthenticationError, NetworkError, PinataError, convertToDesiredGateway, getFileIdFromUrl, formatConfig } from './chunk-7UIMBFJ5.mjs';
1
+ import { ValidationError, AuthenticationError, NetworkError, PinataError, convertToDesiredGateway, formatConfig } from './chunk-7UIMBFJ5.mjs';
2
2
  export { AuthenticationError, NetworkError, PinataError, ValidationError, containsCID, convertToDesiredGateway as convert, convertToDesiredGateway, formatConfig, getFileIdFromUrl, useUpload } from './chunk-7UIMBFJ5.mjs';
3
3
 
4
4
  // src/core/functions/analytics/analyticsDateInterval.ts
@@ -2566,33 +2566,50 @@ var uploadFile = async (config, file, network, options) => {
2566
2566
  let uploadReq;
2567
2567
  for (let i = 0; i < totalChunks; i++) {
2568
2568
  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 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
- }
2569
+ let retryCount = 0;
2570
+ const maxRetries = 5;
2571
+ while (retryCount <= maxRetries) {
2572
+ try {
2573
+ uploadReq = await fetch(url, {
2574
+ method: "PATCH",
2575
+ headers: {
2576
+ "Content-Type": "application/offset+octet-stream",
2577
+ "Upload-Offset": offset.toString(),
2578
+ ...headers2
2579
+ },
2580
+ body: chunk
2581
+ });
2582
+ if (uploadReq.ok) {
2583
+ break;
2584
+ } else {
2585
+ const errorData = await uploadReq.text();
2586
+ throw new Error(`HTTP ${uploadReq.status}: ${errorData}`);
2589
2587
  }
2590
- );
2588
+ } catch (error) {
2589
+ retryCount++;
2590
+ if (retryCount > maxRetries) {
2591
+ const errorData = uploadReq ? await uploadReq.text().catch(() => "Unknown error") : error instanceof Error ? error.message : String(error);
2592
+ throw new NetworkError(
2593
+ `HTTP error during chunk upload after ${maxRetries} retries: ${errorData}`,
2594
+ uploadReq?.status || 0,
2595
+ {
2596
+ error: errorData,
2597
+ code: "HTTP_ERROR",
2598
+ metadata: {
2599
+ requestUrl: uploadReq?.url || url,
2600
+ retriesAttempted: maxRetries
2601
+ }
2602
+ }
2603
+ );
2604
+ }
2605
+ const delay = Math.min(1e3 * Math.pow(2, retryCount - 1), 1e4);
2606
+ await new Promise((resolve) => setTimeout(resolve, delay));
2607
+ }
2591
2608
  }
2592
2609
  offset += chunk.size;
2593
2610
  }
2594
2611
  if (uploadReq.status === 204) {
2595
- const fileId = getFileIdFromUrl(url);
2612
+ const cid = uploadReq.headers.get("upload-cid");
2596
2613
  let dataEndpoint;
2597
2614
  if (config.endpointUrl) {
2598
2615
  dataEndpoint = config.endpointUrl;
@@ -2600,7 +2617,7 @@ var uploadFile = async (config, file, network, options) => {
2600
2617
  dataEndpoint = "https://api.pinata.cloud/v3";
2601
2618
  }
2602
2619
  const fileInfoReq = await fetch(
2603
- `${dataEndpoint}/files/${network}/${fileId}`,
2620
+ `${dataEndpoint}/files/${network}?cid=${cid}`,
2604
2621
  {
2605
2622
  method: "GET",
2606
2623
  headers: {
@@ -2609,7 +2626,7 @@ var uploadFile = async (config, file, network, options) => {
2609
2626
  }
2610
2627
  );
2611
2628
  const fileInfo = await fileInfoReq.json();
2612
- const data2 = fileInfo.data;
2629
+ const data2 = fileInfo.data.files[0];
2613
2630
  if (options?.vectorize) {
2614
2631
  const vectorReq = await fetch(
2615
2632
  `${endpoint}/vectorize/files/${data2.id}`,