pinata 2.4.6 → 2.4.8
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/chunk-BK3CLF3Z.js +163 -0
- package/dist/chunk-BK3CLF3Z.js.map +1 -0
- package/dist/chunk-ME652TQB.mjs +154 -0
- package/dist/chunk-ME652TQB.mjs.map +1 -0
- package/dist/{index-CQFQEo3K.d.mts → gateway-tools-l9hk7kz4.d.mts} +1 -18
- package/dist/{index-CQFQEo3K.d.ts → gateway-tools-l9hk7kz4.d.ts} +1 -18
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +308 -300
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +21 -5
- package/dist/index.mjs.map +1 -1
- package/dist/react/index.d.mts +21 -1
- package/dist/react/index.d.ts +21 -1
- package/dist/react/index.js +271 -11
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +269 -1
- package/dist/react/index.mjs.map +1 -1
- package/package.json +9 -3
- package/dist/chunk-7UIMBFJ5.mjs +0 -423
- package/dist/chunk-7UIMBFJ5.mjs.map +0 -1
- package/dist/chunk-P556VRQU.js +0 -433
- package/dist/chunk-P556VRQU.js.map +0 -1
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/utils/custom-errors.ts
|
|
4
|
+
var PinataError = class extends Error {
|
|
5
|
+
constructor(message, statusCode, details) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.statusCode = statusCode;
|
|
8
|
+
this.details = details;
|
|
9
|
+
this.name = "PinataError";
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
var NetworkError = class extends PinataError {
|
|
13
|
+
constructor(message, statusCode, details) {
|
|
14
|
+
super(message, statusCode, details);
|
|
15
|
+
this.name = "NetworkError";
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
var AuthenticationError = class extends PinataError {
|
|
19
|
+
constructor(message, statusCode, details) {
|
|
20
|
+
super(message, statusCode, details);
|
|
21
|
+
this.name = "AuthenticationError";
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
var ValidationError = class extends PinataError {
|
|
25
|
+
constructor(message, details) {
|
|
26
|
+
super(message, void 0, details);
|
|
27
|
+
this.name = "ValidationError";
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// src/utils/gateway-tools.ts
|
|
32
|
+
function isValidCIDv0(cid) {
|
|
33
|
+
return /^Qm[1-9A-HJ-NP-Za-km-z]{44}$/.test(cid);
|
|
34
|
+
}
|
|
35
|
+
function isValidCIDv1(cid) {
|
|
36
|
+
return /^b[a-z2-7]{58,}$/.test(cid);
|
|
37
|
+
}
|
|
38
|
+
function isCID(str) {
|
|
39
|
+
str = str.trim();
|
|
40
|
+
return isValidCIDv0(str) || isValidCIDv1(str);
|
|
41
|
+
}
|
|
42
|
+
async function containsCID(input) {
|
|
43
|
+
if (typeof input !== "string") {
|
|
44
|
+
throw new Error("Input is not a string");
|
|
45
|
+
}
|
|
46
|
+
const startsWithCID = (str) => {
|
|
47
|
+
const parts = str.split("/");
|
|
48
|
+
return isCID(parts[0]) ? parts[0] : null;
|
|
49
|
+
};
|
|
50
|
+
const directCID = startsWithCID(input);
|
|
51
|
+
if (directCID) {
|
|
52
|
+
return {
|
|
53
|
+
containsCid: true,
|
|
54
|
+
cid: directCID
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
let url;
|
|
58
|
+
try {
|
|
59
|
+
url = new URL(input);
|
|
60
|
+
} catch (error) {
|
|
61
|
+
const parts = input.split(/\/|\?/);
|
|
62
|
+
for (const part of parts) {
|
|
63
|
+
const cid = startsWithCID(part);
|
|
64
|
+
if (cid) {
|
|
65
|
+
return {
|
|
66
|
+
containsCid: true,
|
|
67
|
+
cid
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
containsCid: false,
|
|
73
|
+
cid: null
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
const subdomains = url.hostname.split(".");
|
|
77
|
+
for (const subdomain of subdomains) {
|
|
78
|
+
if (isCID(subdomain)) {
|
|
79
|
+
return {
|
|
80
|
+
containsCid: true,
|
|
81
|
+
cid: subdomain
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const pathParts = url.pathname.split("/");
|
|
86
|
+
for (const part of pathParts) {
|
|
87
|
+
const cid = startsWithCID(part);
|
|
88
|
+
if (cid) {
|
|
89
|
+
return {
|
|
90
|
+
containsCid: true,
|
|
91
|
+
cid
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
containsCid: false,
|
|
97
|
+
cid: null
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
async function convertToDesiredGateway(sourceUrl, desiredGatewayPrefix) {
|
|
101
|
+
const results = await containsCID(sourceUrl);
|
|
102
|
+
if (results.containsCid !== true) {
|
|
103
|
+
throw new Error("url does not contain CID");
|
|
104
|
+
}
|
|
105
|
+
if (!sourceUrl.startsWith("https") && !sourceUrl.startsWith("ipfs://")) {
|
|
106
|
+
return `${desiredGatewayPrefix}/ipfs/${sourceUrl}`;
|
|
107
|
+
}
|
|
108
|
+
const urlObj = new URL(sourceUrl);
|
|
109
|
+
const path = urlObj.pathname + urlObj.search + urlObj.hash;
|
|
110
|
+
if (sourceUrl.startsWith(`ipfs://${results.cid}`)) {
|
|
111
|
+
return `${desiredGatewayPrefix}/ipfs/${results.cid}${path}`;
|
|
112
|
+
}
|
|
113
|
+
if (sourceUrl.includes(`/ipfs/${results.cid}`)) {
|
|
114
|
+
return `${desiredGatewayPrefix}${path}`;
|
|
115
|
+
}
|
|
116
|
+
if (sourceUrl.includes(`/ipns/${results.cid}`)) {
|
|
117
|
+
return `${desiredGatewayPrefix}${path}`;
|
|
118
|
+
}
|
|
119
|
+
if (urlObj.hostname.includes(results.cid)) {
|
|
120
|
+
return `${desiredGatewayPrefix}/ipfs/${results.cid}${path}`;
|
|
121
|
+
}
|
|
122
|
+
throw new Error(
|
|
123
|
+
"unsupported URL pattern, please submit a github issue with the URL utilized"
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// src/utils/resumable.ts
|
|
128
|
+
function getFileIdFromUrl(url) {
|
|
129
|
+
const match = url.match(/\/files\/([^\/]+)/);
|
|
130
|
+
if (match && match[1]) {
|
|
131
|
+
return match[1];
|
|
132
|
+
}
|
|
133
|
+
throw new NetworkError("File ID not found in URL", 400, {
|
|
134
|
+
error: "File ID not found in URL",
|
|
135
|
+
code: "HTTP_ERROR",
|
|
136
|
+
metadata: {
|
|
137
|
+
requestUrl: url
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// src/utils/format-config.ts
|
|
143
|
+
var formatConfig = (config) => {
|
|
144
|
+
let gateway = config?.pinataGateway;
|
|
145
|
+
if (config && gateway) {
|
|
146
|
+
if (gateway && !gateway.startsWith("https://")) {
|
|
147
|
+
gateway = `https://${gateway}`;
|
|
148
|
+
}
|
|
149
|
+
config.pinataGateway = gateway;
|
|
150
|
+
}
|
|
151
|
+
return config;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
exports.AuthenticationError = AuthenticationError;
|
|
155
|
+
exports.NetworkError = NetworkError;
|
|
156
|
+
exports.PinataError = PinataError;
|
|
157
|
+
exports.ValidationError = ValidationError;
|
|
158
|
+
exports.containsCID = containsCID;
|
|
159
|
+
exports.convertToDesiredGateway = convertToDesiredGateway;
|
|
160
|
+
exports.formatConfig = formatConfig;
|
|
161
|
+
exports.getFileIdFromUrl = getFileIdFromUrl;
|
|
162
|
+
//# sourceMappingURL=chunk-BK3CLF3Z.js.map
|
|
163
|
+
//# sourceMappingURL=chunk-BK3CLF3Z.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/custom-err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B,GAAA,OAAA;AAAA;AAExB,EAAO,OAAA,MAAA;AACR","file":"chunk-BK3CLF3Z.js","sourcesContent":["interface ErrorDetails {\n\terror?: string;\n\tcode?: string;\n\tmetadata?: Record<string, any>;\n}\n\nexport class PinataError extends Error {\n\tconstructor(\n\t\tmessage: string,\n\t\tpublic statusCode?: number,\n\t\tpublic details?: ErrorDetails,\n\t) {\n\t\tsuper(message);\n\t\tthis.name = \"PinataError\";\n\t}\n}\n\nexport class NetworkError extends PinataError {\n\tconstructor(message: string, statusCode?: number, details?: ErrorDetails) {\n\t\tsuper(message, statusCode, details);\n\t\tthis.name = \"NetworkError\";\n\t}\n}\n\nexport class AuthenticationError extends PinataError {\n\tconstructor(message: string, statusCode?: number, details?: ErrorDetails) {\n\t\tsuper(message, statusCode, details);\n\t\tthis.name = \"AuthenticationError\";\n\t}\n}\n\nexport class ValidationError extends PinataError {\n\tconstructor(message: string, details?: ErrorDetails) {\n\t\tsuper(message, undefined, details);\n\t\tthis.name = \"ValidationError\";\n\t}\n}\n","import { ContainsCIDResponse } from \"../core/types\";\n\nfunction isValidCIDv0(cid: string): boolean {\n\t// CIDv0 is a 46-character base58-encoded string starting with \"Qm\"\n\treturn /^Qm[1-9A-HJ-NP-Za-km-z]{44}$/.test(cid);\n}\n\nfunction isValidCIDv1(cid: string): boolean {\n\t// CIDv1 typically starts with \"b\" and uses base32 encoding\n\treturn /^b[a-z2-7]{58,}$/.test(cid);\n}\n\nfunction isCID(str: string): boolean {\n\t// Remove any leading/trailing whitespace\n\tstr = str.trim();\n\treturn isValidCIDv0(str) || isValidCIDv1(str);\n}\n\nexport async function containsCID(input: string): Promise<ContainsCIDResponse> {\n\tif (typeof input !== \"string\") {\n\t\tthrow new Error(\"Input is not a string\");\n\t}\n\n\t// Helper function to check if a string starts with a CID\n\tconst startsWithCID = (str: string) => {\n\t\tconst parts = str.split(\"/\");\n\t\treturn isCID(parts[0]) ? parts[0] : null;\n\t};\n\n\t// Check if the input itself is a CID or starts with a CID\n\tconst directCID = startsWithCID(input);\n\tif (directCID) {\n\t\treturn {\n\t\t\tcontainsCid: true,\n\t\t\tcid: directCID,\n\t\t};\n\t}\n\n\tlet url: URL;\n\ttry {\n\t\t// Try to parse the input as a URL\n\t\turl = new URL(input);\n\t} catch (error) {\n\t\t// If parsing fails, treat the input as a potential path-like string\n\t\tconst parts = input.split(/\\/|\\?/);\n\t\tfor (const part of parts) {\n\t\t\tconst cid = startsWithCID(part);\n\t\t\tif (cid) {\n\t\t\t\treturn {\n\t\t\t\t\tcontainsCid: true,\n\t\t\t\t\tcid: cid,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\tcontainsCid: false,\n\t\t\tcid: null,\n\t\t};\n\t}\n\n\t// Check for CID in subdomain\n\tconst subdomains = url.hostname.split(\".\");\n\tfor (const subdomain of subdomains) {\n\t\tif (isCID(subdomain)) {\n\t\t\treturn {\n\t\t\t\tcontainsCid: true,\n\t\t\t\tcid: subdomain,\n\t\t\t};\n\t\t}\n\t}\n\n\t// Check for CID in path\n\tconst pathParts = url.pathname.split(\"/\");\n\tfor (const part of pathParts) {\n\t\tconst cid = startsWithCID(part);\n\t\tif (cid) {\n\t\t\treturn {\n\t\t\t\tcontainsCid: true,\n\t\t\t\tcid: cid,\n\t\t\t};\n\t\t}\n\t}\n\n\treturn {\n\t\tcontainsCid: false,\n\t\tcid: null,\n\t};\n}\n\nexport async function convertToDesiredGateway(\n\tsourceUrl: string,\n\tdesiredGatewayPrefix: string | undefined,\n) {\n\tconst results = await containsCID(sourceUrl);\n\n\tif (results.containsCid !== true) {\n\t\tthrow new Error(\"url does not contain CID\");\n\t}\n\n\tif (!sourceUrl.startsWith(\"https\") && !sourceUrl.startsWith(\"ipfs://\")) {\n\t\treturn `${desiredGatewayPrefix}/ipfs/${sourceUrl}`;\n\t}\n\n\tconst urlObj = new URL(sourceUrl);\n\tconst path = urlObj.pathname + urlObj.search + urlObj.hash;\n\n\t//case 1 - the ipfs://cid path\n\tif (sourceUrl.startsWith(`ipfs://${results.cid}`)) {\n\t\treturn `${desiredGatewayPrefix}/ipfs/${results.cid}${path}`;\n\t}\n\n\t//case 2 - the /ipfs/cid path (this should cover ipfs://ipfs/cid as well)\n\tif (sourceUrl.includes(`/ipfs/${results.cid}`)) {\n\t\treturn `${desiredGatewayPrefix}${path}`;\n\t}\n\n\t//case 3 - the /ipns/cid path\n\tif (sourceUrl.includes(`/ipns/${results.cid}`)) {\n\t\treturn `${desiredGatewayPrefix}${path}`;\n\t}\n\n\t//case 4 - the CID is in the subdomain\n\tif (urlObj.hostname.includes(results.cid!)) {\n\t\treturn `${desiredGatewayPrefix}/ipfs/${results.cid}${path}`;\n\t}\n\n\t//this is the fallback if no supported patterns are provided\n\tthrow new Error(\n\t\t\"unsupported URL pattern, please submit a github issue with the URL utilized\",\n\t);\n}\n","import { NetworkError } from \"./custom-errors\";\n\nexport function getFileIdFromUrl(url: string): string {\n\tconst match = url.match(/\\/files\\/([^\\/]+)/);\n\tif (match && match[1]) {\n\t\treturn match[1];\n\t}\n\tthrow new NetworkError(\"File ID not found in URL\", 400, {\n\t\terror: \"File ID not found in URL\",\n\t\tcode: \"HTTP_ERROR\",\n\t\tmetadata: {\n\t\t\trequestUrl: url,\n\t\t},\n\t});\n}\n","import { PinataConfig } from \"../core/types\";\n\nexport const formatConfig = (config: PinataConfig | undefined) => {\n\tlet gateway = config?.pinataGateway;\n\tif (config && gateway) {\n\t\tif (gateway && !gateway.startsWith(\"https://\")) {\n\t\t\tgateway = `https://${gateway}`;\n\t\t}\n\t\tconfig.pinataGateway = gateway;\n\t}\n\treturn config;\n};\n"]}
|
|
@@ -0,0 +1,154 @@
|
|
|
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
|
+
};
|
|
28
|
+
|
|
29
|
+
// src/utils/gateway-tools.ts
|
|
30
|
+
function isValidCIDv0(cid) {
|
|
31
|
+
return /^Qm[1-9A-HJ-NP-Za-km-z]{44}$/.test(cid);
|
|
32
|
+
}
|
|
33
|
+
function isValidCIDv1(cid) {
|
|
34
|
+
return /^b[a-z2-7]{58,}$/.test(cid);
|
|
35
|
+
}
|
|
36
|
+
function isCID(str) {
|
|
37
|
+
str = str.trim();
|
|
38
|
+
return isValidCIDv0(str) || isValidCIDv1(str);
|
|
39
|
+
}
|
|
40
|
+
async function containsCID(input) {
|
|
41
|
+
if (typeof input !== "string") {
|
|
42
|
+
throw new Error("Input is not a string");
|
|
43
|
+
}
|
|
44
|
+
const startsWithCID = (str) => {
|
|
45
|
+
const parts = str.split("/");
|
|
46
|
+
return isCID(parts[0]) ? parts[0] : null;
|
|
47
|
+
};
|
|
48
|
+
const directCID = startsWithCID(input);
|
|
49
|
+
if (directCID) {
|
|
50
|
+
return {
|
|
51
|
+
containsCid: true,
|
|
52
|
+
cid: directCID
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
let url;
|
|
56
|
+
try {
|
|
57
|
+
url = new URL(input);
|
|
58
|
+
} catch (error) {
|
|
59
|
+
const parts = input.split(/\/|\?/);
|
|
60
|
+
for (const part of parts) {
|
|
61
|
+
const cid = startsWithCID(part);
|
|
62
|
+
if (cid) {
|
|
63
|
+
return {
|
|
64
|
+
containsCid: true,
|
|
65
|
+
cid
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
containsCid: false,
|
|
71
|
+
cid: null
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
const subdomains = url.hostname.split(".");
|
|
75
|
+
for (const subdomain of subdomains) {
|
|
76
|
+
if (isCID(subdomain)) {
|
|
77
|
+
return {
|
|
78
|
+
containsCid: true,
|
|
79
|
+
cid: subdomain
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const pathParts = url.pathname.split("/");
|
|
84
|
+
for (const part of pathParts) {
|
|
85
|
+
const cid = startsWithCID(part);
|
|
86
|
+
if (cid) {
|
|
87
|
+
return {
|
|
88
|
+
containsCid: true,
|
|
89
|
+
cid
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
containsCid: false,
|
|
95
|
+
cid: null
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
async function convertToDesiredGateway(sourceUrl, desiredGatewayPrefix) {
|
|
99
|
+
const results = await containsCID(sourceUrl);
|
|
100
|
+
if (results.containsCid !== true) {
|
|
101
|
+
throw new Error("url does not contain CID");
|
|
102
|
+
}
|
|
103
|
+
if (!sourceUrl.startsWith("https") && !sourceUrl.startsWith("ipfs://")) {
|
|
104
|
+
return `${desiredGatewayPrefix}/ipfs/${sourceUrl}`;
|
|
105
|
+
}
|
|
106
|
+
const urlObj = new URL(sourceUrl);
|
|
107
|
+
const path = urlObj.pathname + urlObj.search + urlObj.hash;
|
|
108
|
+
if (sourceUrl.startsWith(`ipfs://${results.cid}`)) {
|
|
109
|
+
return `${desiredGatewayPrefix}/ipfs/${results.cid}${path}`;
|
|
110
|
+
}
|
|
111
|
+
if (sourceUrl.includes(`/ipfs/${results.cid}`)) {
|
|
112
|
+
return `${desiredGatewayPrefix}${path}`;
|
|
113
|
+
}
|
|
114
|
+
if (sourceUrl.includes(`/ipns/${results.cid}`)) {
|
|
115
|
+
return `${desiredGatewayPrefix}${path}`;
|
|
116
|
+
}
|
|
117
|
+
if (urlObj.hostname.includes(results.cid)) {
|
|
118
|
+
return `${desiredGatewayPrefix}/ipfs/${results.cid}${path}`;
|
|
119
|
+
}
|
|
120
|
+
throw new Error(
|
|
121
|
+
"unsupported URL pattern, please submit a github issue with the URL utilized"
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// src/utils/resumable.ts
|
|
126
|
+
function getFileIdFromUrl(url) {
|
|
127
|
+
const match = url.match(/\/files\/([^\/]+)/);
|
|
128
|
+
if (match && match[1]) {
|
|
129
|
+
return match[1];
|
|
130
|
+
}
|
|
131
|
+
throw new NetworkError("File ID not found in URL", 400, {
|
|
132
|
+
error: "File ID not found in URL",
|
|
133
|
+
code: "HTTP_ERROR",
|
|
134
|
+
metadata: {
|
|
135
|
+
requestUrl: url
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// src/utils/format-config.ts
|
|
141
|
+
var formatConfig = (config) => {
|
|
142
|
+
let gateway = config?.pinataGateway;
|
|
143
|
+
if (config && gateway) {
|
|
144
|
+
if (gateway && !gateway.startsWith("https://")) {
|
|
145
|
+
gateway = `https://${gateway}`;
|
|
146
|
+
}
|
|
147
|
+
config.pinataGateway = gateway;
|
|
148
|
+
}
|
|
149
|
+
return config;
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
export { AuthenticationError, NetworkError, PinataError, ValidationError, containsCID, convertToDesiredGateway, formatConfig, getFileIdFromUrl };
|
|
153
|
+
//# sourceMappingURL=chunk-ME652TQB.mjs.map
|
|
154
|
+
//# sourceMappingURL=chunk-ME652TQB.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/custom-errors.ts","../src/utils/gateway-tools.ts","../src/utils/resumable.ts","../src/utils/format-config.ts"],"names":[],"mappings":";AAMa,IAAA,WAAA,GAAN,cAA0B,KAAM,CAAA;AAAA,EACtC,WAAA,CACC,OACO,EAAA,UAAA,EACA,OACN,EAAA;AACD,IAAA,KAAA,CAAM,OAAO,CAAA;AAHN,IAAA,IAAA,CAAA,UAAA,GAAA,UAAA;AACA,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA;AAGP,IAAA,IAAA,CAAK,IAAO,GAAA,aAAA;AAAA;AAEd;AAEa,IAAA,YAAA,GAAN,cAA2B,WAAY,CAAA;AAAA,EAC7C,WAAA,CAAY,OAAiB,EAAA,UAAA,EAAqB,OAAwB,EAAA;AACzE,IAAM,KAAA,CAAA,OAAA,EAAS,YAAY,OAAO,CAAA;AAClC,IAAA,IAAA,CAAK,IAAO,GAAA,cAAA;AAAA;AAEd;AAEa,IAAA,mBAAA,GAAN,cAAkC,WAAY,CAAA;AAAA,EACpD,WAAA,CAAY,OAAiB,EAAA,UAAA,EAAqB,OAAwB,EAAA;AACzE,IAAM,KAAA,CAAA,OAAA,EAAS,YAAY,OAAO,CAAA;AAClC,IAAA,IAAA,CAAK,IAAO,GAAA,qBAAA;AAAA;AAEd;AAEa,IAAA,eAAA,GAAN,cAA8B,WAAY,CAAA;AAAA,EAChD,WAAA,CAAY,SAAiB,OAAwB,EAAA;AACpD,IAAM,KAAA,CAAA,OAAA,EAAS,QAAW,OAAO,CAAA;AACjC,IAAA,IAAA,CAAK,IAAO,GAAA,iBAAA;AAAA;AAEd;;;AClCA,SAAS,aAAa,GAAsB,EAAA;AAE3C,EAAO,OAAA,8BAAA,CAA+B,KAAK,GAAG,CAAA;AAC/C;AAEA,SAAS,aAAa,GAAsB,EAAA;AAE3C,EAAO,OAAA,kBAAA,CAAmB,KAAK,GAAG,CAAA;AACnC;AAEA,SAAS,MAAM,GAAsB,EAAA;AAEpC,EAAA,GAAA,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,IAAA,MAAA,CAAO,aAAgB,GAAA,OAAA;AAAA;AAExB,EAAO,OAAA,MAAA;AACR","file":"chunk-ME652TQB.mjs","sourcesContent":["interface ErrorDetails {\n\terror?: string;\n\tcode?: string;\n\tmetadata?: Record<string, any>;\n}\n\nexport class PinataError extends Error {\n\tconstructor(\n\t\tmessage: string,\n\t\tpublic statusCode?: number,\n\t\tpublic details?: ErrorDetails,\n\t) {\n\t\tsuper(message);\n\t\tthis.name = \"PinataError\";\n\t}\n}\n\nexport class NetworkError extends PinataError {\n\tconstructor(message: string, statusCode?: number, details?: ErrorDetails) {\n\t\tsuper(message, statusCode, details);\n\t\tthis.name = \"NetworkError\";\n\t}\n}\n\nexport class AuthenticationError extends PinataError {\n\tconstructor(message: string, statusCode?: number, details?: ErrorDetails) {\n\t\tsuper(message, statusCode, details);\n\t\tthis.name = \"AuthenticationError\";\n\t}\n}\n\nexport class ValidationError extends PinataError {\n\tconstructor(message: string, details?: ErrorDetails) {\n\t\tsuper(message, undefined, details);\n\t\tthis.name = \"ValidationError\";\n\t}\n}\n","import { ContainsCIDResponse } from \"../core/types\";\n\nfunction isValidCIDv0(cid: string): boolean {\n\t// CIDv0 is a 46-character base58-encoded string starting with \"Qm\"\n\treturn /^Qm[1-9A-HJ-NP-Za-km-z]{44}$/.test(cid);\n}\n\nfunction isValidCIDv1(cid: string): boolean {\n\t// CIDv1 typically starts with \"b\" and uses base32 encoding\n\treturn /^b[a-z2-7]{58,}$/.test(cid);\n}\n\nfunction isCID(str: string): boolean {\n\t// Remove any leading/trailing whitespace\n\tstr = str.trim();\n\treturn isValidCIDv0(str) || isValidCIDv1(str);\n}\n\nexport async function containsCID(input: string): Promise<ContainsCIDResponse> {\n\tif (typeof input !== \"string\") {\n\t\tthrow new Error(\"Input is not a string\");\n\t}\n\n\t// Helper function to check if a string starts with a CID\n\tconst startsWithCID = (str: string) => {\n\t\tconst parts = str.split(\"/\");\n\t\treturn isCID(parts[0]) ? parts[0] : null;\n\t};\n\n\t// Check if the input itself is a CID or starts with a CID\n\tconst directCID = startsWithCID(input);\n\tif (directCID) {\n\t\treturn {\n\t\t\tcontainsCid: true,\n\t\t\tcid: directCID,\n\t\t};\n\t}\n\n\tlet url: URL;\n\ttry {\n\t\t// Try to parse the input as a URL\n\t\turl = new URL(input);\n\t} catch (error) {\n\t\t// If parsing fails, treat the input as a potential path-like string\n\t\tconst parts = input.split(/\\/|\\?/);\n\t\tfor (const part of parts) {\n\t\t\tconst cid = startsWithCID(part);\n\t\t\tif (cid) {\n\t\t\t\treturn {\n\t\t\t\t\tcontainsCid: true,\n\t\t\t\t\tcid: cid,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\tcontainsCid: false,\n\t\t\tcid: null,\n\t\t};\n\t}\n\n\t// Check for CID in subdomain\n\tconst subdomains = url.hostname.split(\".\");\n\tfor (const subdomain of subdomains) {\n\t\tif (isCID(subdomain)) {\n\t\t\treturn {\n\t\t\t\tcontainsCid: true,\n\t\t\t\tcid: subdomain,\n\t\t\t};\n\t\t}\n\t}\n\n\t// Check for CID in path\n\tconst pathParts = url.pathname.split(\"/\");\n\tfor (const part of pathParts) {\n\t\tconst cid = startsWithCID(part);\n\t\tif (cid) {\n\t\t\treturn {\n\t\t\t\tcontainsCid: true,\n\t\t\t\tcid: cid,\n\t\t\t};\n\t\t}\n\t}\n\n\treturn {\n\t\tcontainsCid: false,\n\t\tcid: null,\n\t};\n}\n\nexport async function convertToDesiredGateway(\n\tsourceUrl: string,\n\tdesiredGatewayPrefix: string | undefined,\n) {\n\tconst results = await containsCID(sourceUrl);\n\n\tif (results.containsCid !== true) {\n\t\tthrow new Error(\"url does not contain CID\");\n\t}\n\n\tif (!sourceUrl.startsWith(\"https\") && !sourceUrl.startsWith(\"ipfs://\")) {\n\t\treturn `${desiredGatewayPrefix}/ipfs/${sourceUrl}`;\n\t}\n\n\tconst urlObj = new URL(sourceUrl);\n\tconst path = urlObj.pathname + urlObj.search + urlObj.hash;\n\n\t//case 1 - the ipfs://cid path\n\tif (sourceUrl.startsWith(`ipfs://${results.cid}`)) {\n\t\treturn `${desiredGatewayPrefix}/ipfs/${results.cid}${path}`;\n\t}\n\n\t//case 2 - the /ipfs/cid path (this should cover ipfs://ipfs/cid as well)\n\tif (sourceUrl.includes(`/ipfs/${results.cid}`)) {\n\t\treturn `${desiredGatewayPrefix}${path}`;\n\t}\n\n\t//case 3 - the /ipns/cid path\n\tif (sourceUrl.includes(`/ipns/${results.cid}`)) {\n\t\treturn `${desiredGatewayPrefix}${path}`;\n\t}\n\n\t//case 4 - the CID is in the subdomain\n\tif (urlObj.hostname.includes(results.cid!)) {\n\t\treturn `${desiredGatewayPrefix}/ipfs/${results.cid}${path}`;\n\t}\n\n\t//this is the fallback if no supported patterns are provided\n\tthrow new Error(\n\t\t\"unsupported URL pattern, please submit a github issue with the URL utilized\",\n\t);\n}\n","import { NetworkError } from \"./custom-errors\";\n\nexport function getFileIdFromUrl(url: string): string {\n\tconst match = url.match(/\\/files\\/([^\\/]+)/);\n\tif (match && match[1]) {\n\t\treturn match[1];\n\t}\n\tthrow new NetworkError(\"File ID not found in URL\", 400, {\n\t\terror: \"File ID not found in URL\",\n\t\tcode: \"HTTP_ERROR\",\n\t\tmetadata: {\n\t\t\trequestUrl: url,\n\t\t},\n\t});\n}\n","import { PinataConfig } from \"../core/types\";\n\nexport const formatConfig = (config: PinataConfig | undefined) => {\n\tlet gateway = config?.pinataGateway;\n\tif (config && gateway) {\n\t\tif (gateway && !gateway.startsWith(\"https://\")) {\n\t\t\tgateway = `https://${gateway}`;\n\t\t}\n\t\tconfig.pinataGateway = gateway;\n\t}\n\treturn config;\n};\n"]}
|
|
@@ -208,21 +208,4 @@ declare class ValidationError extends PinataError {
|
|
|
208
208
|
declare function containsCID(input: string): Promise<ContainsCIDResponse>;
|
|
209
209
|
declare function convertToDesiredGateway(sourceUrl: string, desiredGatewayPrefix: string | undefined): Promise<string>;
|
|
210
210
|
|
|
211
|
-
type
|
|
212
|
-
interface ReactUploadOptions extends UploadOptions {
|
|
213
|
-
chunkSize?: number;
|
|
214
|
-
}
|
|
215
|
-
type UseUploadReturn = {
|
|
216
|
-
progress: number;
|
|
217
|
-
loading: boolean;
|
|
218
|
-
error: Error | null;
|
|
219
|
-
uploadResponse: UploadResult | null;
|
|
220
|
-
upload: (file: File, network: "public" | "private", url: string, options?: UploadOptions) => Promise<void>;
|
|
221
|
-
pause: () => void;
|
|
222
|
-
resume: () => void;
|
|
223
|
-
cancel: () => void;
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
declare const useUpload: () => UseUploadReturn;
|
|
227
|
-
|
|
228
|
-
export { type AccessLinkOptions as A, type ContentType as C, type DeleteResponse as D, type FileListQuery as F, type GetCIDResponse as G, type JsonBody as J, NetworkError as N, type OptimizeImageOptions as O, type PinQueueQuery as P, type ReactUploadOptions as R, type SwapCidOptions as S, type UpdateFileOptions as U, type VectorizeFileResponse as V, type FileListResponse as a, type SwapCidResponse as b, type SwapHistoryOptions as c, type FileListItem as d, type VectorizeQuery as e, type VectorizeQueryResponse as f, type PinQueueResponse as g, type UploadOptions as h, type UploadResponse as i, type SignedUploadUrlOptions as j, type UploadCIDOptions as k, type PinByCIDResponse as l, type PinQueueItem as m, type FileObject as n, type PinataMetadata as o, type VectorQueryMatch as p, type ContainsCIDResponse as q, PinataError as r, AuthenticationError as s, ValidationError as t, containsCID as u, convertToDesiredGateway as v, useUpload as w, type UploadResult as x, type UseUploadReturn as y };
|
|
211
|
+
export { type AccessLinkOptions as A, type ContentType as C, type DeleteResponse as D, type FileListQuery as F, type GetCIDResponse as G, type JsonBody as J, NetworkError as N, type OptimizeImageOptions as O, type PinQueueQuery as P, type SwapCidOptions as S, type UpdateFileOptions as U, type VectorizeFileResponse as V, type FileListResponse as a, type SwapCidResponse as b, type SwapHistoryOptions as c, type FileListItem as d, type VectorizeQuery as e, type VectorizeQueryResponse as f, type PinQueueResponse as g, type UploadOptions as h, type UploadResponse as i, type SignedUploadUrlOptions as j, type UploadCIDOptions as k, type PinByCIDResponse as l, type PinQueueItem as m, type FileObject as n, type PinataMetadata as o, type VectorQueryMatch as p, type ContainsCIDResponse as q, PinataError as r, AuthenticationError as s, ValidationError as t, containsCID as u, convertToDesiredGateway as v };
|
|
@@ -208,21 +208,4 @@ declare class ValidationError extends PinataError {
|
|
|
208
208
|
declare function containsCID(input: string): Promise<ContainsCIDResponse>;
|
|
209
209
|
declare function convertToDesiredGateway(sourceUrl: string, desiredGatewayPrefix: string | undefined): Promise<string>;
|
|
210
210
|
|
|
211
|
-
type
|
|
212
|
-
interface ReactUploadOptions extends UploadOptions {
|
|
213
|
-
chunkSize?: number;
|
|
214
|
-
}
|
|
215
|
-
type UseUploadReturn = {
|
|
216
|
-
progress: number;
|
|
217
|
-
loading: boolean;
|
|
218
|
-
error: Error | null;
|
|
219
|
-
uploadResponse: UploadResult | null;
|
|
220
|
-
upload: (file: File, network: "public" | "private", url: string, options?: UploadOptions) => Promise<void>;
|
|
221
|
-
pause: () => void;
|
|
222
|
-
resume: () => void;
|
|
223
|
-
cancel: () => void;
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
declare const useUpload: () => UseUploadReturn;
|
|
227
|
-
|
|
228
|
-
export { type AccessLinkOptions as A, type ContentType as C, type DeleteResponse as D, type FileListQuery as F, type GetCIDResponse as G, type JsonBody as J, NetworkError as N, type OptimizeImageOptions as O, type PinQueueQuery as P, type ReactUploadOptions as R, type SwapCidOptions as S, type UpdateFileOptions as U, type VectorizeFileResponse as V, type FileListResponse as a, type SwapCidResponse as b, type SwapHistoryOptions as c, type FileListItem as d, type VectorizeQuery as e, type VectorizeQueryResponse as f, type PinQueueResponse as g, type UploadOptions as h, type UploadResponse as i, type SignedUploadUrlOptions as j, type UploadCIDOptions as k, type PinByCIDResponse as l, type PinQueueItem as m, type FileObject as n, type PinataMetadata as o, type VectorQueryMatch as p, type ContainsCIDResponse as q, PinataError as r, AuthenticationError as s, ValidationError as t, containsCID as u, convertToDesiredGateway as v, useUpload as w, type UploadResult as x, type UseUploadReturn as y };
|
|
211
|
+
export { type AccessLinkOptions as A, type ContentType as C, type DeleteResponse as D, type FileListQuery as F, type GetCIDResponse as G, type JsonBody as J, NetworkError as N, type OptimizeImageOptions as O, type PinQueueQuery as P, type SwapCidOptions as S, type UpdateFileOptions as U, type VectorizeFileResponse as V, type FileListResponse as a, type SwapCidResponse as b, type SwapHistoryOptions as c, type FileListItem as d, type VectorizeQuery as e, type VectorizeQueryResponse as f, type PinQueueResponse as g, type UploadOptions as h, type UploadResponse as i, type SignedUploadUrlOptions as j, type UploadCIDOptions as k, type PinByCIDResponse as l, type PinQueueItem as m, type FileObject as n, type PinataMetadata as o, type VectorQueryMatch as p, type ContainsCIDResponse as q, PinataError as r, AuthenticationError as s, ValidationError as t, containsCID as u, convertToDesiredGateway as v };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { D as DeleteResponse, V as VectorizeFileResponse, F as FileListQuery, a as FileListResponse, S as SwapCidOptions, b as SwapCidResponse, c as SwapHistoryOptions, U as UpdateFileOptions, d as FileListItem, e as VectorizeQuery, f as VectorizeQueryResponse, G as GetCIDResponse, P as PinQueueQuery, g as PinQueueResponse, O as OptimizeImageOptions, A as AccessLinkOptions, h as UploadOptions, i as UploadResponse, j as SignedUploadUrlOptions, J as JsonBody, k as UploadCIDOptions, l as PinByCIDResponse, m as PinQueueItem } from './
|
|
2
|
-
export { s as AuthenticationError, q as ContainsCIDResponse, C as ContentType, n as FileObject, N as NetworkError, r as PinataError, o as PinataMetadata,
|
|
1
|
+
import { D as DeleteResponse, V as VectorizeFileResponse, F as FileListQuery, a as FileListResponse, S as SwapCidOptions, b as SwapCidResponse, c as SwapHistoryOptions, U as UpdateFileOptions, d as FileListItem, e as VectorizeQuery, f as VectorizeQueryResponse, G as GetCIDResponse, P as PinQueueQuery, g as PinQueueResponse, O as OptimizeImageOptions, A as AccessLinkOptions, h as UploadOptions, i as UploadResponse, j as SignedUploadUrlOptions, J as JsonBody, k as UploadCIDOptions, l as PinByCIDResponse, m as PinQueueItem } from './gateway-tools-l9hk7kz4.mjs';
|
|
2
|
+
export { s as AuthenticationError, q as ContainsCIDResponse, C as ContentType, n as FileObject, N as NetworkError, r as PinataError, o as PinataMetadata, t as ValidationError, p as VectorQueryMatch, u as containsCID, v as convertToDesiredGateway } from './gateway-tools-l9hk7kz4.mjs';
|
|
3
3
|
|
|
4
4
|
type PinataConfig = {
|
|
5
5
|
pinataJwt?: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { D as DeleteResponse, V as VectorizeFileResponse, F as FileListQuery, a as FileListResponse, S as SwapCidOptions, b as SwapCidResponse, c as SwapHistoryOptions, U as UpdateFileOptions, d as FileListItem, e as VectorizeQuery, f as VectorizeQueryResponse, G as GetCIDResponse, P as PinQueueQuery, g as PinQueueResponse, O as OptimizeImageOptions, A as AccessLinkOptions, h as UploadOptions, i as UploadResponse, j as SignedUploadUrlOptions, J as JsonBody, k as UploadCIDOptions, l as PinByCIDResponse, m as PinQueueItem } from './
|
|
2
|
-
export { s as AuthenticationError, q as ContainsCIDResponse, C as ContentType, n as FileObject, N as NetworkError, r as PinataError, o as PinataMetadata,
|
|
1
|
+
import { D as DeleteResponse, V as VectorizeFileResponse, F as FileListQuery, a as FileListResponse, S as SwapCidOptions, b as SwapCidResponse, c as SwapHistoryOptions, U as UpdateFileOptions, d as FileListItem, e as VectorizeQuery, f as VectorizeQueryResponse, G as GetCIDResponse, P as PinQueueQuery, g as PinQueueResponse, O as OptimizeImageOptions, A as AccessLinkOptions, h as UploadOptions, i as UploadResponse, j as SignedUploadUrlOptions, J as JsonBody, k as UploadCIDOptions, l as PinByCIDResponse, m as PinQueueItem } from './gateway-tools-l9hk7kz4.js';
|
|
2
|
+
export { s as AuthenticationError, q as ContainsCIDResponse, C as ContentType, n as FileObject, N as NetworkError, r as PinataError, o as PinataMetadata, t as ValidationError, p as VectorQueryMatch, u as containsCID, v as convertToDesiredGateway } from './gateway-tools-l9hk7kz4.js';
|
|
3
3
|
|
|
4
4
|
type PinataConfig = {
|
|
5
5
|
pinataJwt?: string;
|