pinata 2.0.1 → 2.1.1
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/README.md +13 -13
- package/dist/index.d.mts +13 -5
- package/dist/index.d.ts +13 -5
- package/dist/index.js +92 -38
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +91 -38
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1143,7 +1143,7 @@ var vectorizeQuery = async (config, options) => {
|
|
|
1143
1143
|
throw new PinataError(`No files returned in query to fetch`);
|
|
1144
1144
|
}
|
|
1145
1145
|
const cid = resData.matches[0].cid;
|
|
1146
|
-
const fileRes = await getCid(config, cid,
|
|
1146
|
+
const fileRes = await getCid(config, cid, "files");
|
|
1147
1147
|
return fileRes;
|
|
1148
1148
|
}
|
|
1149
1149
|
return resData;
|
|
@@ -1169,21 +1169,23 @@ var queue = async (config, options) => {
|
|
|
1169
1169
|
includesCount: "false"
|
|
1170
1170
|
});
|
|
1171
1171
|
if (options) {
|
|
1172
|
-
const {
|
|
1172
|
+
const { cid, status, sort, limit, pageToken } = options;
|
|
1173
1173
|
if (cid)
|
|
1174
|
-
params.append("
|
|
1174
|
+
params.append("cid", cid.toString());
|
|
1175
1175
|
if (status)
|
|
1176
1176
|
params.append("status", status.toString());
|
|
1177
1177
|
if (sort)
|
|
1178
1178
|
params.append("sort", sort.toString());
|
|
1179
1179
|
if (limit)
|
|
1180
1180
|
params.append("limit", limit.toString());
|
|
1181
|
+
if (pageToken)
|
|
1182
|
+
params.append("pageToken", pageToken.toString());
|
|
1181
1183
|
}
|
|
1182
|
-
let endpoint = "https://api.pinata.cloud";
|
|
1184
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
1183
1185
|
if (config.endpointUrl) {
|
|
1184
1186
|
endpoint = config.endpointUrl;
|
|
1185
1187
|
}
|
|
1186
|
-
const url = `${endpoint}/
|
|
1188
|
+
const url = `${endpoint}/files/public/pin_by_cid?${params.toString()}`;
|
|
1187
1189
|
let headers;
|
|
1188
1190
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1189
1191
|
headers = {
|
|
@@ -1225,15 +1227,7 @@ var queue = async (config, options) => {
|
|
|
1225
1227
|
});
|
|
1226
1228
|
}
|
|
1227
1229
|
const res = await request.json();
|
|
1228
|
-
const resData =
|
|
1229
|
-
rows: res.rows.map((row) => ({
|
|
1230
|
-
...row,
|
|
1231
|
-
cid: row.ipfs_pin_hash,
|
|
1232
|
-
ipfs_pin_hash: void 0
|
|
1233
|
-
})),
|
|
1234
|
-
next_page_token: ""
|
|
1235
|
-
// Assuming API returns this
|
|
1236
|
-
};
|
|
1230
|
+
const resData = res.data;
|
|
1237
1231
|
return resData;
|
|
1238
1232
|
} catch (error) {
|
|
1239
1233
|
if (error instanceof PinataError) {
|
|
@@ -1246,6 +1240,69 @@ var queue = async (config, options) => {
|
|
|
1246
1240
|
}
|
|
1247
1241
|
};
|
|
1248
1242
|
|
|
1243
|
+
// src/core/functions/files/deletePinRequest.ts
|
|
1244
|
+
var deletePinRequest = async (config, id) => {
|
|
1245
|
+
if (!config) {
|
|
1246
|
+
throw new ValidationError("Pinata configuration is missing");
|
|
1247
|
+
}
|
|
1248
|
+
let headers;
|
|
1249
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1250
|
+
headers = {
|
|
1251
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1252
|
+
...config.customHeaders
|
|
1253
|
+
};
|
|
1254
|
+
} else {
|
|
1255
|
+
headers = {
|
|
1256
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1257
|
+
Source: "sdk/deletePinRequest"
|
|
1258
|
+
};
|
|
1259
|
+
}
|
|
1260
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
1261
|
+
if (config.endpointUrl) {
|
|
1262
|
+
endpoint = config.endpointUrl;
|
|
1263
|
+
}
|
|
1264
|
+
try {
|
|
1265
|
+
const response = await fetch(`${endpoint}/files/public/pin_by_cid/${id}`, {
|
|
1266
|
+
method: "DELETE",
|
|
1267
|
+
headers
|
|
1268
|
+
});
|
|
1269
|
+
if (!response.ok) {
|
|
1270
|
+
const errorData = await response.text();
|
|
1271
|
+
if (response.status === 401) {
|
|
1272
|
+
throw new AuthenticationError(
|
|
1273
|
+
`Authentication failed: ${errorData}`,
|
|
1274
|
+
response.status,
|
|
1275
|
+
{
|
|
1276
|
+
error: errorData,
|
|
1277
|
+
code: "HTTP_ERROR",
|
|
1278
|
+
metadata: {
|
|
1279
|
+
requestUrl: response.url
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
);
|
|
1283
|
+
}
|
|
1284
|
+
throw new NetworkError(`HTTP error`, response.status, {
|
|
1285
|
+
error: errorData,
|
|
1286
|
+
code: "HTTP_ERROR",
|
|
1287
|
+
metadata: {
|
|
1288
|
+
requestUrl: response.url
|
|
1289
|
+
}
|
|
1290
|
+
});
|
|
1291
|
+
}
|
|
1292
|
+
return "OK";
|
|
1293
|
+
} catch (error) {
|
|
1294
|
+
if (error instanceof PinataError) {
|
|
1295
|
+
throw error;
|
|
1296
|
+
}
|
|
1297
|
+
if (error instanceof Error) {
|
|
1298
|
+
throw new PinataError(`Error deleting pin by request: ${error.message}`);
|
|
1299
|
+
}
|
|
1300
|
+
throw new PinataError(
|
|
1301
|
+
"An unknown error occurred while deleting pin by CID request"
|
|
1302
|
+
);
|
|
1303
|
+
}
|
|
1304
|
+
};
|
|
1305
|
+
|
|
1249
1306
|
// src/core/functions/gateway/getCid.ts
|
|
1250
1307
|
var getCid = async (config, cid, gatewayType, options) => {
|
|
1251
1308
|
if (!config) {
|
|
@@ -1481,12 +1538,12 @@ async function convertToDesiredGateway(sourceUrl, desiredGatewayPrefix) {
|
|
|
1481
1538
|
throw new Error("url does not contain CID");
|
|
1482
1539
|
}
|
|
1483
1540
|
if (!sourceUrl.startsWith("https") && !sourceUrl.startsWith("ipfs://")) {
|
|
1484
|
-
return `${desiredGatewayPrefix}/
|
|
1541
|
+
return `${desiredGatewayPrefix}/ipfs/${sourceUrl}`;
|
|
1485
1542
|
}
|
|
1486
1543
|
const urlObj = new URL(sourceUrl);
|
|
1487
1544
|
const path = urlObj.pathname + urlObj.search + urlObj.hash;
|
|
1488
1545
|
if (sourceUrl.startsWith(`ipfs://${results.cid}`)) {
|
|
1489
|
-
return `${desiredGatewayPrefix}/
|
|
1546
|
+
return `${desiredGatewayPrefix}/ipfs/${results.cid}${path}`;
|
|
1490
1547
|
}
|
|
1491
1548
|
if (sourceUrl.includes(`/ipfs/${results.cid}`)) {
|
|
1492
1549
|
return `${desiredGatewayPrefix}${path}`;
|
|
@@ -1495,7 +1552,7 @@ async function convertToDesiredGateway(sourceUrl, desiredGatewayPrefix) {
|
|
|
1495
1552
|
return `${desiredGatewayPrefix}${path}`;
|
|
1496
1553
|
}
|
|
1497
1554
|
if (urlObj.hostname.includes(results.cid)) {
|
|
1498
|
-
return `${desiredGatewayPrefix}/
|
|
1555
|
+
return `${desiredGatewayPrefix}/ipfs/${results.cid}${path}`;
|
|
1499
1556
|
}
|
|
1500
1557
|
throw new Error(
|
|
1501
1558
|
"unsupported URL pattern, please submit a github issue with the URL utilized"
|
|
@@ -3337,23 +3394,20 @@ var uploadCid = async (config, cid, options) => {
|
|
|
3337
3394
|
Source: "sdk/cid"
|
|
3338
3395
|
};
|
|
3339
3396
|
}
|
|
3340
|
-
const
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
}
|
|
3350
|
-
});
|
|
3351
|
-
let endpoint = "https://api.pinata.cloud";
|
|
3397
|
+
const requestBody = {
|
|
3398
|
+
cid,
|
|
3399
|
+
name: options?.metadata ? options?.metadata?.name : cid,
|
|
3400
|
+
keyvalues: options?.metadata?.keyvalues,
|
|
3401
|
+
group_id: options?.groupId,
|
|
3402
|
+
host_nodes: options?.peerAddresses
|
|
3403
|
+
};
|
|
3404
|
+
const data = JSON.stringify(requestBody);
|
|
3405
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
3352
3406
|
if (config.endpointUrl) {
|
|
3353
3407
|
endpoint = config.endpointUrl;
|
|
3354
3408
|
}
|
|
3355
3409
|
try {
|
|
3356
|
-
const request = await fetch(`${endpoint}/
|
|
3410
|
+
const request = await fetch(`${endpoint}/files/public/pin_by_cid`, {
|
|
3357
3411
|
method: "POST",
|
|
3358
3412
|
headers,
|
|
3359
3413
|
body: data
|
|
@@ -3382,12 +3436,7 @@ var uploadCid = async (config, cid, options) => {
|
|
|
3382
3436
|
});
|
|
3383
3437
|
}
|
|
3384
3438
|
const res = await request.json();
|
|
3385
|
-
const resData =
|
|
3386
|
-
id: res.id,
|
|
3387
|
-
cid: res.ipfsHash,
|
|
3388
|
-
name: res.name,
|
|
3389
|
-
status: res.status
|
|
3390
|
-
};
|
|
3439
|
+
const resData = res.data;
|
|
3391
3440
|
return resData;
|
|
3392
3441
|
} catch (error) {
|
|
3393
3442
|
if (error instanceof PinataError) {
|
|
@@ -4135,7 +4184,7 @@ var FilterQueue = class {
|
|
|
4135
4184
|
this.config = config;
|
|
4136
4185
|
}
|
|
4137
4186
|
cid(cid) {
|
|
4138
|
-
this.query.
|
|
4187
|
+
this.query.cid = cid;
|
|
4139
4188
|
return this;
|
|
4140
4189
|
}
|
|
4141
4190
|
status(status) {
|
|
@@ -4228,6 +4277,9 @@ var PublicFiles = class {
|
|
|
4228
4277
|
queue() {
|
|
4229
4278
|
return new FilterQueue(this.config);
|
|
4230
4279
|
}
|
|
4280
|
+
deletePinRequest(requestId) {
|
|
4281
|
+
return deletePinRequest(this.config, requestId);
|
|
4282
|
+
}
|
|
4231
4283
|
};
|
|
4232
4284
|
|
|
4233
4285
|
// src/core/classes/files/PrivateFiles.ts
|
|
@@ -4343,7 +4395,7 @@ var UploadBuilder = class {
|
|
|
4343
4395
|
if (this.uploadUrl) {
|
|
4344
4396
|
options.url = this.uploadUrl;
|
|
4345
4397
|
}
|
|
4346
|
-
if (this.peerAddresses
|
|
4398
|
+
if (this.peerAddresses) {
|
|
4347
4399
|
options.peerAddresses = this.peerAddresses;
|
|
4348
4400
|
}
|
|
4349
4401
|
this.args[this.args.length - 1] = options;
|
|
@@ -4789,6 +4841,7 @@ export {
|
|
|
4789
4841
|
deleteFile,
|
|
4790
4842
|
deleteFileVectors,
|
|
4791
4843
|
deleteGroup,
|
|
4844
|
+
deletePinRequest,
|
|
4792
4845
|
deleteSwap,
|
|
4793
4846
|
formatConfig,
|
|
4794
4847
|
getCid,
|