pinata 2.3.0 → 2.4.0

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,30 +1,5 @@
1
- // src/utils/custom-errors.ts
2
- var PinataError = class extends Error {
3
- constructor(message, statusCode, details) {
4
- super(message);
5
- this.statusCode = statusCode;
6
- this.details = details;
7
- this.name = "PinataError";
8
- }
9
- };
10
- var NetworkError = class extends PinataError {
11
- constructor(message, statusCode, details) {
12
- super(message, statusCode, details);
13
- this.name = "NetworkError";
14
- }
15
- };
16
- var AuthenticationError = class extends PinataError {
17
- constructor(message, statusCode, details) {
18
- super(message, statusCode, details);
19
- this.name = "AuthenticationError";
20
- }
21
- };
22
- var ValidationError = class extends PinataError {
23
- constructor(message, details) {
24
- super(message, void 0, details);
25
- this.name = "ValidationError";
26
- }
27
- };
1
+ import { ValidationError, AuthenticationError, NetworkError, PinataError, convertToDesiredGateway, getFileIdFromUrl, formatConfig } from './chunk-7UIMBFJ5.mjs';
2
+ export { AuthenticationError, NetworkError, PinataError, ValidationError, containsCID, convertToDesiredGateway as convert, convertToDesiredGateway, formatConfig, getFileIdFromUrl, useUpload } from './chunk-7UIMBFJ5.mjs';
28
3
 
29
4
  // src/core/functions/analytics/analyticsDateInterval.ts
30
5
  var analyticsDateInterval = async (config, options) => {
@@ -1417,102 +1392,6 @@ var getCid = async (config, cid, gatewayType, options) => {
1417
1392
  }
1418
1393
  };
1419
1394
 
1420
- // src/utils/gateway-tools.ts
1421
- function isValidCIDv0(cid) {
1422
- return /^Qm[1-9A-HJ-NP-Za-km-z]{44}$/.test(cid);
1423
- }
1424
- function isValidCIDv1(cid) {
1425
- return /^b[a-z2-7]{58,}$/.test(cid);
1426
- }
1427
- function isCID(str) {
1428
- str = str.trim();
1429
- return isValidCIDv0(str) || isValidCIDv1(str);
1430
- }
1431
- async function containsCID(input) {
1432
- if (typeof input !== "string") {
1433
- throw new Error("Input is not a string");
1434
- }
1435
- const startsWithCID = (str) => {
1436
- const parts = str.split("/");
1437
- return isCID(parts[0]) ? parts[0] : null;
1438
- };
1439
- const directCID = startsWithCID(input);
1440
- if (directCID) {
1441
- return {
1442
- containsCid: true,
1443
- cid: directCID
1444
- };
1445
- }
1446
- let url;
1447
- try {
1448
- url = new URL(input);
1449
- } catch (error) {
1450
- const parts = input.split(/\/|\?/);
1451
- for (const part of parts) {
1452
- const cid = startsWithCID(part);
1453
- if (cid) {
1454
- return {
1455
- containsCid: true,
1456
- cid
1457
- };
1458
- }
1459
- }
1460
- return {
1461
- containsCid: false,
1462
- cid: null
1463
- };
1464
- }
1465
- const subdomains = url.hostname.split(".");
1466
- for (const subdomain of subdomains) {
1467
- if (isCID(subdomain)) {
1468
- return {
1469
- containsCid: true,
1470
- cid: subdomain
1471
- };
1472
- }
1473
- }
1474
- const pathParts = url.pathname.split("/");
1475
- for (const part of pathParts) {
1476
- const cid = startsWithCID(part);
1477
- if (cid) {
1478
- return {
1479
- containsCid: true,
1480
- cid
1481
- };
1482
- }
1483
- }
1484
- return {
1485
- containsCid: false,
1486
- cid: null
1487
- };
1488
- }
1489
- async function convertToDesiredGateway(sourceUrl, desiredGatewayPrefix) {
1490
- const results = await containsCID(sourceUrl);
1491
- if (results.containsCid !== true) {
1492
- throw new Error("url does not contain CID");
1493
- }
1494
- if (!sourceUrl.startsWith("https") && !sourceUrl.startsWith("ipfs://")) {
1495
- return `${desiredGatewayPrefix}/ipfs/${sourceUrl}`;
1496
- }
1497
- const urlObj = new URL(sourceUrl);
1498
- const path = urlObj.pathname + urlObj.search + urlObj.hash;
1499
- if (sourceUrl.startsWith(`ipfs://${results.cid}`)) {
1500
- return `${desiredGatewayPrefix}/ipfs/${results.cid}${path}`;
1501
- }
1502
- if (sourceUrl.includes(`/ipfs/${results.cid}`)) {
1503
- return `${desiredGatewayPrefix}${path}`;
1504
- }
1505
- if (sourceUrl.includes(`/ipns/${results.cid}`)) {
1506
- return `${desiredGatewayPrefix}${path}`;
1507
- }
1508
- if (urlObj.hostname.includes(results.cid)) {
1509
- return `${desiredGatewayPrefix}/ipfs/${results.cid}${path}`;
1510
- }
1511
- throw new Error(
1512
- "unsupported URL pattern, please submit a github issue with the URL utilized"
1513
- );
1514
- }
1515
-
1516
1395
  // src/core/functions/gateway/convertIPFSUrl.ts
1517
1396
  var convertIPFSUrl = async (config, url, gatewayPrefix) => {
1518
1397
  let newUrl;
@@ -2622,21 +2501,6 @@ var createSignedUploadURL = async (config, options, network) => {
2622
2501
  }
2623
2502
  };
2624
2503
 
2625
- // src/utils/resumable.ts
2626
- function getFileIdFromUrl(url) {
2627
- const match = url.match(/\/files\/([^\/]+)/);
2628
- if (match && match[1]) {
2629
- return match[1];
2630
- }
2631
- throw new NetworkError("File ID not found in URL", 400, {
2632
- error: "File ID not found in URL",
2633
- code: "HTTP_ERROR",
2634
- metadata: {
2635
- requestUrl: url
2636
- }
2637
- });
2638
- }
2639
-
2640
2504
  // src/core/functions/uploads/file.ts
2641
2505
  var uploadFile = async (config, file, network, options) => {
2642
2506
  if (!config) {
@@ -3403,18 +3267,6 @@ var uploadCid = async (config, cid, options) => {
3403
3267
  }
3404
3268
  };
3405
3269
 
3406
- // src/utils/format-config.ts
3407
- var formatConfig = (config) => {
3408
- let gateway = config?.pinataGateway;
3409
- if (config && gateway) {
3410
- if (gateway && !gateway.startsWith("https://")) {
3411
- gateway = `https://${gateway}`;
3412
- }
3413
- config.pinataGateway = gateway;
3414
- }
3415
- return config;
3416
- };
3417
-
3418
3270
  // src/core/classes/analytics/Analytics.ts
3419
3271
  var Analytics = class {
3420
3272
  constructor(config) {
@@ -4779,51 +4631,7 @@ var PinataSDK = class {
4779
4631
  return testAuthentication(this.config);
4780
4632
  }
4781
4633
  };
4782
- export {
4783
- AuthenticationError,
4784
- NetworkError,
4785
- PinataError,
4786
- PinataSDK,
4787
- ValidationError,
4788
- addToGroup,
4789
- analyticsDateInterval,
4790
- analyticsTopUsage,
4791
- containsCID,
4792
- convertIPFSUrl,
4793
- convertToDesiredGateway,
4794
- createAccessLink,
4795
- createGroup,
4796
- createKey,
4797
- createSignedUploadURL,
4798
- deleteFile,
4799
- deleteFileVectors,
4800
- deleteGroup,
4801
- deletePinRequest,
4802
- deleteSwap,
4803
- formatConfig,
4804
- getCid,
4805
- getFileIdFromUrl,
4806
- getGroup,
4807
- listFiles,
4808
- listGroups,
4809
- listKeys,
4810
- pinnedFileCount,
4811
- queue,
4812
- removeFromGroup,
4813
- revokeKeys,
4814
- swapCid,
4815
- swapHistory,
4816
- testAuthentication,
4817
- totalStorageUsage,
4818
- updateFile,
4819
- updateGroup,
4820
- uploadBase64,
4821
- uploadCid,
4822
- uploadFile,
4823
- uploadFileArray,
4824
- uploadJson,
4825
- uploadUrl,
4826
- vectorizeFile,
4827
- vectorizeQuery
4828
- };
4634
+
4635
+ export { PinataSDK, addToGroup, analyticsDateInterval, analyticsTopUsage, convertIPFSUrl, createAccessLink, createGroup, createKey, createSignedUploadURL, deleteFile, deleteFileVectors, deleteGroup, deletePinRequest, deleteSwap, getCid, getGroup, listFiles, listGroups, listKeys, pinnedFileCount, queue, removeFromGroup, revokeKeys, swapCid, swapHistory, testAuthentication, totalStorageUsage, updateFile, updateGroup, uploadBase64, uploadCid, uploadFile, uploadFileArray, uploadJson, uploadUrl, vectorizeFile, vectorizeQuery };
4636
+ //# sourceMappingURL=index.mjs.map
4829
4637
  //# sourceMappingURL=index.mjs.map