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