pinata 2.2.2 → 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;
@@ -2551,6 +2430,9 @@ var createSignedUploadURL = async (config, options, network) => {
2551
2430
  if (network) {
2552
2431
  payload.network = network;
2553
2432
  }
2433
+ if (options.streamable) {
2434
+ payload.streamable = options.streamable;
2435
+ }
2554
2436
  if (options.maxFileSize) {
2555
2437
  payload.max_file_size = options.maxFileSize;
2556
2438
  }
@@ -2619,21 +2501,6 @@ var createSignedUploadURL = async (config, options, network) => {
2619
2501
  }
2620
2502
  };
2621
2503
 
2622
- // src/utils/resumable.ts
2623
- function getFileIdFromUrl(url) {
2624
- const match = url.match(/\/files\/([^\/]+)/);
2625
- if (match && match[1]) {
2626
- return match[1];
2627
- }
2628
- throw new NetworkError("File ID not found in URL", 400, {
2629
- error: "File ID not found in URL",
2630
- code: "HTTP_ERROR",
2631
- metadata: {
2632
- requestUrl: url
2633
- }
2634
- });
2635
- }
2636
-
2637
2504
  // src/core/functions/uploads/file.ts
2638
2505
  var uploadFile = async (config, file, network, options) => {
2639
2506
  if (!config) {
@@ -2665,6 +2532,9 @@ var uploadFile = async (config, file, network, options) => {
2665
2532
  if (options?.metadata?.keyvalues) {
2666
2533
  metadata + `,keyvalues ${btoa(JSON.stringify(options.metadata.keyvalues))}`;
2667
2534
  }
2535
+ if (options?.streamable) {
2536
+ metadata + `,keyvalues ${btoa("true")}`;
2537
+ }
2668
2538
  let updatedEndpoint = `${endpoint}/files`;
2669
2539
  if (options?.url) {
2670
2540
  updatedEndpoint = options.url;
@@ -2792,6 +2662,9 @@ var uploadFile = async (config, file, network, options) => {
2792
2662
  if (options?.metadata?.keyvalues) {
2793
2663
  data.append("keyvalues", JSON.stringify(options.metadata.keyvalues));
2794
2664
  }
2665
+ if (options?.streamable) {
2666
+ data.append("streamable", "true");
2667
+ }
2795
2668
  if (options?.url) {
2796
2669
  try {
2797
2670
  const request = await fetch(options.url, {
@@ -3394,18 +3267,6 @@ var uploadCid = async (config, cid, options) => {
3394
3267
  }
3395
3268
  };
3396
3269
 
3397
- // src/utils/format-config.ts
3398
- var formatConfig = (config) => {
3399
- let gateway = config?.pinataGateway;
3400
- if (config && gateway) {
3401
- if (gateway && !gateway.startsWith("https://")) {
3402
- gateway = `https://${gateway}`;
3403
- }
3404
- config.pinataGateway = gateway;
3405
- }
3406
- return config;
3407
- };
3408
-
3409
3270
  // src/core/classes/analytics/Analytics.ts
3410
3271
  var Analytics = class {
3411
3272
  constructor(config) {
@@ -4315,6 +4176,10 @@ var UploadBuilder = class {
4315
4176
  this.groupId = groupId;
4316
4177
  return this;
4317
4178
  }
4179
+ streamable() {
4180
+ this.isStreamable = true;
4181
+ return this;
4182
+ }
4318
4183
  peerAddress(peerAddresses) {
4319
4184
  this.peerAddresses = peerAddresses;
4320
4185
  return this;
@@ -4336,6 +4201,9 @@ var UploadBuilder = class {
4336
4201
  if (this.uploadUrl) {
4337
4202
  options.url = this.uploadUrl;
4338
4203
  }
4204
+ if (this.isStreamable) {
4205
+ options.streamable = this.isStreamable;
4206
+ }
4339
4207
  if (this.peerAddresses) {
4340
4208
  options.peerAddresses = this.peerAddresses;
4341
4209
  }
@@ -4763,51 +4631,7 @@ var PinataSDK = class {
4763
4631
  return testAuthentication(this.config);
4764
4632
  }
4765
4633
  };
4766
- export {
4767
- AuthenticationError,
4768
- NetworkError,
4769
- PinataError,
4770
- PinataSDK,
4771
- ValidationError,
4772
- addToGroup,
4773
- analyticsDateInterval,
4774
- analyticsTopUsage,
4775
- containsCID,
4776
- convertIPFSUrl,
4777
- convertToDesiredGateway,
4778
- createAccessLink,
4779
- createGroup,
4780
- createKey,
4781
- createSignedUploadURL,
4782
- deleteFile,
4783
- deleteFileVectors,
4784
- deleteGroup,
4785
- deletePinRequest,
4786
- deleteSwap,
4787
- formatConfig,
4788
- getCid,
4789
- getFileIdFromUrl,
4790
- getGroup,
4791
- listFiles,
4792
- listGroups,
4793
- listKeys,
4794
- pinnedFileCount,
4795
- queue,
4796
- removeFromGroup,
4797
- revokeKeys,
4798
- swapCid,
4799
- swapHistory,
4800
- testAuthentication,
4801
- totalStorageUsage,
4802
- updateFile,
4803
- updateGroup,
4804
- uploadBase64,
4805
- uploadCid,
4806
- uploadFile,
4807
- uploadFileArray,
4808
- uploadJson,
4809
- uploadUrl,
4810
- vectorizeFile,
4811
- vectorizeQuery
4812
- };
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
4813
4637
  //# sourceMappingURL=index.mjs.map