pinata 0.1.9 → 0.1.10
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.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +46 -39
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +46 -39
- package/dist/index.mjs.map +1 -1
- package/package.json +44 -50
package/dist/index.mjs
CHANGED
|
@@ -428,7 +428,7 @@ var uploadJson = async (config, jsonData, options) => {
|
|
|
428
428
|
};
|
|
429
429
|
|
|
430
430
|
// src/core/pinning/cid.ts
|
|
431
|
-
var uploadCid = async (config,
|
|
431
|
+
var uploadCid = async (config, cid, options) => {
|
|
432
432
|
if (!config || !config.pinataJwt) {
|
|
433
433
|
throw new ValidationError("Pinata configuration or JWT is missing");
|
|
434
434
|
}
|
|
@@ -442,9 +442,9 @@ var uploadCid = async (config, cid2, options) => {
|
|
|
442
442
|
}
|
|
443
443
|
headers["Source"] = headers["Source"] || "sdk/cid";
|
|
444
444
|
const data = JSON.stringify({
|
|
445
|
-
hashToPin:
|
|
445
|
+
hashToPin: cid,
|
|
446
446
|
pinataMetadata: {
|
|
447
|
-
name: options?.metadata ? options?.metadata?.name :
|
|
447
|
+
name: options?.metadata ? options?.metadata?.name : cid,
|
|
448
448
|
keyvalues: options?.metadata?.keyValues
|
|
449
449
|
},
|
|
450
450
|
pinataOptions: {
|
|
@@ -563,7 +563,7 @@ var listFiles = async (config, options) => {
|
|
|
563
563
|
});
|
|
564
564
|
if (options) {
|
|
565
565
|
const {
|
|
566
|
-
cid
|
|
566
|
+
cid,
|
|
567
567
|
pinStart,
|
|
568
568
|
pinEnd,
|
|
569
569
|
pinSizeMin,
|
|
@@ -576,8 +576,8 @@ var listFiles = async (config, options) => {
|
|
|
576
576
|
operator,
|
|
577
577
|
groupId
|
|
578
578
|
} = options;
|
|
579
|
-
if (
|
|
580
|
-
params.append("cid",
|
|
579
|
+
if (cid)
|
|
580
|
+
params.append("cid", cid);
|
|
581
581
|
if (pinStart)
|
|
582
582
|
params.append("pinStart", pinStart);
|
|
583
583
|
if (pinEnd)
|
|
@@ -700,11 +700,18 @@ var updateMetadata = async (config, options) => {
|
|
|
700
700
|
};
|
|
701
701
|
|
|
702
702
|
// src/utils/gateway-tools.ts
|
|
703
|
-
|
|
704
|
-
function
|
|
703
|
+
var isIPFSModule;
|
|
704
|
+
async function getIsIPFS() {
|
|
705
|
+
if (!isIPFSModule) {
|
|
706
|
+
isIPFSModule = await import("is-ipfs");
|
|
707
|
+
}
|
|
708
|
+
return isIPFSModule;
|
|
709
|
+
}
|
|
710
|
+
async function containsCID(input) {
|
|
705
711
|
if (typeof input !== "string") {
|
|
706
712
|
throw new Error("Input is not a string");
|
|
707
713
|
}
|
|
714
|
+
const isIPFS = await getIsIPFS();
|
|
708
715
|
const startsWithCID = (str) => {
|
|
709
716
|
const parts = str.split("/");
|
|
710
717
|
return isIPFS.cid(parts[0]) ? parts[0] : null;
|
|
@@ -722,11 +729,11 @@ function containsCID(input) {
|
|
|
722
729
|
} catch (error) {
|
|
723
730
|
const parts = input.split(/\/|\?/);
|
|
724
731
|
for (const part of parts) {
|
|
725
|
-
const
|
|
726
|
-
if (
|
|
732
|
+
const cid = startsWithCID(part);
|
|
733
|
+
if (cid) {
|
|
727
734
|
return {
|
|
728
735
|
containsCid: true,
|
|
729
|
-
cid
|
|
736
|
+
cid
|
|
730
737
|
};
|
|
731
738
|
}
|
|
732
739
|
}
|
|
@@ -746,11 +753,11 @@ function containsCID(input) {
|
|
|
746
753
|
}
|
|
747
754
|
const pathParts = url.pathname.split("/");
|
|
748
755
|
for (const part of pathParts) {
|
|
749
|
-
const
|
|
750
|
-
if (
|
|
756
|
+
const cid = startsWithCID(part);
|
|
757
|
+
if (cid) {
|
|
751
758
|
return {
|
|
752
759
|
containsCid: true,
|
|
753
|
-
cid
|
|
760
|
+
cid
|
|
754
761
|
};
|
|
755
762
|
}
|
|
756
763
|
}
|
|
@@ -759,8 +766,8 @@ function containsCID(input) {
|
|
|
759
766
|
cid: null
|
|
760
767
|
};
|
|
761
768
|
}
|
|
762
|
-
function convertToDesiredGateway(sourceUrl, desiredGatewayPrefix) {
|
|
763
|
-
const results = containsCID(sourceUrl);
|
|
769
|
+
async function convertToDesiredGateway(sourceUrl, desiredGatewayPrefix) {
|
|
770
|
+
const results = await containsCID(sourceUrl);
|
|
764
771
|
if (results.containsCid !== true) {
|
|
765
772
|
throw new Error("url does not contain CID");
|
|
766
773
|
}
|
|
@@ -787,13 +794,13 @@ function convertToDesiredGateway(sourceUrl, desiredGatewayPrefix) {
|
|
|
787
794
|
}
|
|
788
795
|
|
|
789
796
|
// src/core/gateway/getCid.ts
|
|
790
|
-
var getCid = async (config,
|
|
797
|
+
var getCid = async (config, cid) => {
|
|
791
798
|
if (!config || !config.pinataJwt) {
|
|
792
799
|
throw new ValidationError("Pinata configuration or JWT is missing");
|
|
793
800
|
}
|
|
794
801
|
let data;
|
|
795
802
|
let newUrl;
|
|
796
|
-
newUrl = convertToDesiredGateway(
|
|
803
|
+
newUrl = await convertToDesiredGateway(cid, config?.pinataGateway);
|
|
797
804
|
if (config?.pinataGatewayKey) {
|
|
798
805
|
newUrl = `${newUrl}?pinataGatewayToken=${config?.pinataGatewayKey}`;
|
|
799
806
|
}
|
|
@@ -846,9 +853,9 @@ var getCid = async (config, cid2) => {
|
|
|
846
853
|
};
|
|
847
854
|
|
|
848
855
|
// src/core/gateway/convertIPFSUrl.ts
|
|
849
|
-
var convertIPFSUrl = (config, url) => {
|
|
856
|
+
var convertIPFSUrl = async (config, url) => {
|
|
850
857
|
let newUrl;
|
|
851
|
-
newUrl = convertToDesiredGateway(url, config?.pinataGateway);
|
|
858
|
+
newUrl = await convertToDesiredGateway(url, config?.pinataGateway);
|
|
852
859
|
if (config?.pinataGatewayKey) {
|
|
853
860
|
`${newUrl}?pinataGatewayToken=${config?.pinataGatewayKey}`;
|
|
854
861
|
}
|
|
@@ -864,9 +871,9 @@ var pinJobs = async (config, options) => {
|
|
|
864
871
|
includesCount: "false"
|
|
865
872
|
});
|
|
866
873
|
if (options) {
|
|
867
|
-
const { ipfs_pin_hash:
|
|
868
|
-
if (
|
|
869
|
-
params.append("ipfs_pin_hash",
|
|
874
|
+
const { ipfs_pin_hash: cid, status, sort, limit, offset } = options;
|
|
875
|
+
if (cid)
|
|
876
|
+
params.append("ipfs_pin_hash", cid.toString());
|
|
870
877
|
if (status)
|
|
871
878
|
params.append("status", status.toString());
|
|
872
879
|
if (sort)
|
|
@@ -1626,7 +1633,7 @@ var addSignature = async (config, options) => {
|
|
|
1626
1633
|
};
|
|
1627
1634
|
|
|
1628
1635
|
// src/core/signatures/getSignature.ts
|
|
1629
|
-
var getSignature = async (config,
|
|
1636
|
+
var getSignature = async (config, cid) => {
|
|
1630
1637
|
if (!config || !config.pinataJwt) {
|
|
1631
1638
|
throw new ValidationError("Pinata configuration or JWT is missing");
|
|
1632
1639
|
}
|
|
@@ -1640,7 +1647,7 @@ var getSignature = async (config, cid2) => {
|
|
|
1640
1647
|
headers["Source"] = headers["Source"] || "sdk/getSignature";
|
|
1641
1648
|
try {
|
|
1642
1649
|
const request = await fetch(
|
|
1643
|
-
`https://api.pinata.cloud/v3/ipfs/signature/${
|
|
1650
|
+
`https://api.pinata.cloud/v3/ipfs/signature/${cid}`,
|
|
1644
1651
|
{
|
|
1645
1652
|
method: "GET",
|
|
1646
1653
|
headers
|
|
@@ -1677,7 +1684,7 @@ var getSignature = async (config, cid2) => {
|
|
|
1677
1684
|
};
|
|
1678
1685
|
|
|
1679
1686
|
// src/core/signatures/removeSignature.ts
|
|
1680
|
-
var removeSignature = async (config,
|
|
1687
|
+
var removeSignature = async (config, cid) => {
|
|
1681
1688
|
if (!config || !config.pinataJwt) {
|
|
1682
1689
|
throw new ValidationError("Pinata configuration or JWT is missing");
|
|
1683
1690
|
}
|
|
@@ -1691,7 +1698,7 @@ var removeSignature = async (config, cid2) => {
|
|
|
1691
1698
|
headers["Source"] = headers["Source"] || "sdk/removeSignature";
|
|
1692
1699
|
try {
|
|
1693
1700
|
const request = await fetch(
|
|
1694
|
-
`https://api.pinata.cloud/v3/ipfs/signature/${
|
|
1701
|
+
`https://api.pinata.cloud/v3/ipfs/signature/${cid}`,
|
|
1695
1702
|
{
|
|
1696
1703
|
method: "DELETE",
|
|
1697
1704
|
headers
|
|
@@ -1833,8 +1840,8 @@ var Upload = class {
|
|
|
1833
1840
|
json(data, options) {
|
|
1834
1841
|
return new UploadBuilder(this.config, uploadJson, data, options);
|
|
1835
1842
|
}
|
|
1836
|
-
cid(
|
|
1837
|
-
return new UploadBuilder(this.config, uploadCid,
|
|
1843
|
+
cid(cid, options) {
|
|
1844
|
+
return new UploadBuilder(this.config, uploadCid, cid, options);
|
|
1838
1845
|
}
|
|
1839
1846
|
};
|
|
1840
1847
|
var FilterFiles = class {
|
|
@@ -1847,8 +1854,8 @@ var FilterFiles = class {
|
|
|
1847
1854
|
this.MINUTE_IN_MS = 6e4;
|
|
1848
1855
|
this.config = config;
|
|
1849
1856
|
}
|
|
1850
|
-
cid(
|
|
1851
|
-
this.query.cid =
|
|
1857
|
+
cid(cid) {
|
|
1858
|
+
this.query.cid = cid;
|
|
1852
1859
|
return this;
|
|
1853
1860
|
}
|
|
1854
1861
|
pinStart(date) {
|
|
@@ -1939,8 +1946,8 @@ var Gateways = class {
|
|
|
1939
1946
|
constructor(config) {
|
|
1940
1947
|
this.config = formatConfig(config);
|
|
1941
1948
|
}
|
|
1942
|
-
get(
|
|
1943
|
-
return getCid(this.config,
|
|
1949
|
+
get(cid) {
|
|
1950
|
+
return getCid(this.config, cid);
|
|
1944
1951
|
}
|
|
1945
1952
|
convert(url) {
|
|
1946
1953
|
return convertIPFSUrl(this.config, url);
|
|
@@ -1956,8 +1963,8 @@ var FilterPinJobs = class {
|
|
|
1956
1963
|
this.MINUTE_IN_MS = 6e4;
|
|
1957
1964
|
this.config = config;
|
|
1958
1965
|
}
|
|
1959
|
-
cid(
|
|
1960
|
-
this.query.ipfs_pin_hash =
|
|
1966
|
+
cid(cid) {
|
|
1967
|
+
this.query.ipfs_pin_hash = cid;
|
|
1961
1968
|
return this;
|
|
1962
1969
|
}
|
|
1963
1970
|
status(status) {
|
|
@@ -2214,11 +2221,11 @@ var Signatures = class {
|
|
|
2214
2221
|
add(options) {
|
|
2215
2222
|
return addSignature(this.config, options);
|
|
2216
2223
|
}
|
|
2217
|
-
get(
|
|
2218
|
-
return getSignature(this.config,
|
|
2224
|
+
get(cid) {
|
|
2225
|
+
return getSignature(this.config, cid);
|
|
2219
2226
|
}
|
|
2220
|
-
delete(
|
|
2221
|
-
return removeSignature(this.config,
|
|
2227
|
+
delete(cid) {
|
|
2228
|
+
return removeSignature(this.config, cid);
|
|
2222
2229
|
}
|
|
2223
2230
|
};
|
|
2224
2231
|
export {
|