pinata 1.1.0 → 1.3.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.d.mts +36 -6
- package/dist/index.d.ts +36 -6
- package/dist/index.js +351 -41
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +351 -41
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -417,9 +417,19 @@ var listFiles = async (config, options) => {
|
|
|
417
417
|
}
|
|
418
418
|
const params = new URLSearchParams();
|
|
419
419
|
if (options) {
|
|
420
|
-
const { limit, pageToken, cidPending } = options;
|
|
420
|
+
const { name, group, cid, order, limit, mimeType, pageToken, cidPending } = options;
|
|
421
421
|
if (limit)
|
|
422
422
|
params.append("limit", limit.toString());
|
|
423
|
+
if (name)
|
|
424
|
+
params.append("name", name);
|
|
425
|
+
if (group)
|
|
426
|
+
params.append("group", group);
|
|
427
|
+
if (cid)
|
|
428
|
+
params.append("cid", cid);
|
|
429
|
+
if (mimeType)
|
|
430
|
+
params.append("mimeType", mimeType);
|
|
431
|
+
if (order)
|
|
432
|
+
params.append("order", order);
|
|
423
433
|
if (pageToken)
|
|
424
434
|
params.append("pageToken", pageToken);
|
|
425
435
|
if (cidPending)
|
|
@@ -531,13 +541,41 @@ var updateFile = async (config, options) => {
|
|
|
531
541
|
};
|
|
532
542
|
|
|
533
543
|
// src/core/gateway/getCid.ts
|
|
534
|
-
var getCid = async (config, cid) => {
|
|
544
|
+
var getCid = async (config, cid, options) => {
|
|
535
545
|
if (!config) {
|
|
536
546
|
throw new ValidationError("Pinata configuration is missing");
|
|
537
547
|
}
|
|
538
548
|
let data;
|
|
539
549
|
let newUrl = `${config?.pinataGateway}/files/${cid}`;
|
|
540
550
|
const params = new URLSearchParams();
|
|
551
|
+
if (options) {
|
|
552
|
+
if (options.width)
|
|
553
|
+
params.append("img-width", options.width.toString());
|
|
554
|
+
if (options.height)
|
|
555
|
+
params.append("img-height", options.height.toString());
|
|
556
|
+
if (options.dpr)
|
|
557
|
+
params.append("img-dpr", options.dpr.toString());
|
|
558
|
+
if (options.fit)
|
|
559
|
+
params.append("img-fit", options.fit);
|
|
560
|
+
if (options.gravity)
|
|
561
|
+
params.append("img-gravity", options.gravity);
|
|
562
|
+
if (options.quality)
|
|
563
|
+
params.append("img-quality", options.quality.toString());
|
|
564
|
+
if (options.format)
|
|
565
|
+
params.append("img-format", options.format);
|
|
566
|
+
if (options.animation !== void 0)
|
|
567
|
+
params.append("img-anim", options.animation.toString());
|
|
568
|
+
if (options.sharpen)
|
|
569
|
+
params.append("img-sharpen", options.sharpen.toString());
|
|
570
|
+
if (options.onError === true)
|
|
571
|
+
params.append("img-onerror", "redirect");
|
|
572
|
+
if (options.metadata)
|
|
573
|
+
params.append("img-metadata", options.metadata);
|
|
574
|
+
}
|
|
575
|
+
const queryString = params.toString();
|
|
576
|
+
if (queryString) {
|
|
577
|
+
newUrl += `?${queryString}`;
|
|
578
|
+
}
|
|
541
579
|
const date = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3);
|
|
542
580
|
const payload = JSON.stringify({
|
|
543
581
|
url: newUrl,
|
|
@@ -545,17 +583,18 @@ var getCid = async (config, cid) => {
|
|
|
545
583
|
expires: 30,
|
|
546
584
|
method: "GET"
|
|
547
585
|
});
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
}
|
|
558
|
-
|
|
586
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
587
|
+
if (config.endpointUrl) {
|
|
588
|
+
endpoint = config.endpointUrl;
|
|
589
|
+
}
|
|
590
|
+
const signedUrlRequest = await fetch(`${endpoint}/files/sign`, {
|
|
591
|
+
method: "POST",
|
|
592
|
+
headers: {
|
|
593
|
+
"Content-Type": "application/json",
|
|
594
|
+
Authorization: `Bearer ${config?.pinataJwt}`
|
|
595
|
+
},
|
|
596
|
+
body: payload
|
|
597
|
+
});
|
|
559
598
|
const signedUrl = await signedUrlRequest.json();
|
|
560
599
|
try {
|
|
561
600
|
const request = await fetch(signedUrl.data);
|
|
@@ -868,13 +907,13 @@ var listGroups = async (config, options) => {
|
|
|
868
907
|
}
|
|
869
908
|
const params = new URLSearchParams();
|
|
870
909
|
if (options) {
|
|
871
|
-
const { pageToken,
|
|
910
|
+
const { pageToken, name, limit, isPublic } = options;
|
|
872
911
|
if (pageToken)
|
|
873
912
|
params.append("pageToken", pageToken.toString());
|
|
874
913
|
if (isPublic)
|
|
875
914
|
params.append("isPublic", isPublic.toString());
|
|
876
|
-
if (
|
|
877
|
-
params.append("
|
|
915
|
+
if (name)
|
|
916
|
+
params.append("name", name);
|
|
878
917
|
if (limit !== void 0)
|
|
879
918
|
params.append("limit", limit.toString());
|
|
880
919
|
}
|
|
@@ -1084,12 +1123,242 @@ var deleteGroup = async (config, options) => {
|
|
|
1084
1123
|
}
|
|
1085
1124
|
};
|
|
1086
1125
|
|
|
1126
|
+
// src/core/files/swapCid.ts
|
|
1127
|
+
var swapCid = async (config, options) => {
|
|
1128
|
+
if (!config) {
|
|
1129
|
+
throw new ValidationError("Pinata configuration is missing");
|
|
1130
|
+
}
|
|
1131
|
+
const data = JSON.stringify({
|
|
1132
|
+
swap_cid: options.swapCid
|
|
1133
|
+
});
|
|
1134
|
+
let headers;
|
|
1135
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1136
|
+
headers = { ...config.customHeaders };
|
|
1137
|
+
} else {
|
|
1138
|
+
headers = {
|
|
1139
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1140
|
+
"Content-Type": "application/json",
|
|
1141
|
+
Source: "sdk/swapCid"
|
|
1142
|
+
};
|
|
1143
|
+
}
|
|
1144
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
1145
|
+
if (config.endpointUrl) {
|
|
1146
|
+
endpoint = config.endpointUrl;
|
|
1147
|
+
}
|
|
1148
|
+
try {
|
|
1149
|
+
const request = await fetch(`${endpoint}/files/swap/${options.cid}`, {
|
|
1150
|
+
method: "PUT",
|
|
1151
|
+
headers,
|
|
1152
|
+
body: data
|
|
1153
|
+
});
|
|
1154
|
+
if (!request.ok) {
|
|
1155
|
+
const errorData = await request.text();
|
|
1156
|
+
if (request.status === 401 || request.status === 403) {
|
|
1157
|
+
throw new AuthenticationError(
|
|
1158
|
+
`Authentication failed: ${errorData}`,
|
|
1159
|
+
request.status,
|
|
1160
|
+
errorData
|
|
1161
|
+
);
|
|
1162
|
+
}
|
|
1163
|
+
if (request.status === 403) {
|
|
1164
|
+
throw new PinataError(
|
|
1165
|
+
"Unauthorized CID Swap",
|
|
1166
|
+
request.status,
|
|
1167
|
+
errorData
|
|
1168
|
+
);
|
|
1169
|
+
}
|
|
1170
|
+
if (request.status === 404) {
|
|
1171
|
+
throw new PinataError(
|
|
1172
|
+
"CID not pinned to account",
|
|
1173
|
+
request.status,
|
|
1174
|
+
errorData
|
|
1175
|
+
);
|
|
1176
|
+
}
|
|
1177
|
+
throw new NetworkError(
|
|
1178
|
+
`HTTP error: ${errorData}`,
|
|
1179
|
+
request.status,
|
|
1180
|
+
errorData
|
|
1181
|
+
);
|
|
1182
|
+
}
|
|
1183
|
+
const res = await request.json();
|
|
1184
|
+
const resData = res.data;
|
|
1185
|
+
return resData;
|
|
1186
|
+
} catch (error) {
|
|
1187
|
+
if (error instanceof PinataError) {
|
|
1188
|
+
throw error;
|
|
1189
|
+
}
|
|
1190
|
+
if (error instanceof Error) {
|
|
1191
|
+
throw new PinataError(`Error processing CID Swap: ${error.message}`);
|
|
1192
|
+
}
|
|
1193
|
+
throw new PinataError("An unknown error occurred while swapping CID");
|
|
1194
|
+
}
|
|
1195
|
+
};
|
|
1196
|
+
|
|
1197
|
+
// src/core/files/swapHistory.ts
|
|
1198
|
+
var swapHistory = async (config, options) => {
|
|
1199
|
+
if (!config) {
|
|
1200
|
+
throw new ValidationError("Pinata configuration is missing");
|
|
1201
|
+
}
|
|
1202
|
+
let headers;
|
|
1203
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1204
|
+
headers = { ...config.customHeaders };
|
|
1205
|
+
} else {
|
|
1206
|
+
headers = {
|
|
1207
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1208
|
+
"Content-Type": "application/json",
|
|
1209
|
+
Source: "sdk/swapHistory"
|
|
1210
|
+
};
|
|
1211
|
+
}
|
|
1212
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
1213
|
+
if (config.endpointUrl) {
|
|
1214
|
+
endpoint = config.endpointUrl;
|
|
1215
|
+
}
|
|
1216
|
+
try {
|
|
1217
|
+
const request = await fetch(
|
|
1218
|
+
`${endpoint}/files/swap/${options.cid}?domain=${options.domain}`,
|
|
1219
|
+
{
|
|
1220
|
+
method: "GET",
|
|
1221
|
+
headers
|
|
1222
|
+
}
|
|
1223
|
+
);
|
|
1224
|
+
if (!request.ok) {
|
|
1225
|
+
const errorData = await request.text();
|
|
1226
|
+
if (request.status === 401 || request.status === 403) {
|
|
1227
|
+
throw new AuthenticationError(
|
|
1228
|
+
`Authentication failed: ${errorData}`,
|
|
1229
|
+
request.status,
|
|
1230
|
+
errorData
|
|
1231
|
+
);
|
|
1232
|
+
}
|
|
1233
|
+
if (request.status === 404) {
|
|
1234
|
+
throw new PinataError(
|
|
1235
|
+
"CID does not have history",
|
|
1236
|
+
request.status,
|
|
1237
|
+
errorData
|
|
1238
|
+
);
|
|
1239
|
+
}
|
|
1240
|
+
throw new NetworkError(
|
|
1241
|
+
`HTTP error: ${errorData}`,
|
|
1242
|
+
request.status,
|
|
1243
|
+
errorData
|
|
1244
|
+
);
|
|
1245
|
+
}
|
|
1246
|
+
const res = await request.json();
|
|
1247
|
+
const resData = res.data;
|
|
1248
|
+
return resData;
|
|
1249
|
+
} catch (error) {
|
|
1250
|
+
if (error instanceof PinataError) {
|
|
1251
|
+
throw error;
|
|
1252
|
+
}
|
|
1253
|
+
if (error instanceof Error) {
|
|
1254
|
+
throw new PinataError(`Error fetching swap history: ${error.message}`);
|
|
1255
|
+
}
|
|
1256
|
+
throw new PinataError(
|
|
1257
|
+
"An unknown error occurred while fetching swap history"
|
|
1258
|
+
);
|
|
1259
|
+
}
|
|
1260
|
+
};
|
|
1261
|
+
|
|
1262
|
+
// src/core/files/deleteSwap.ts
|
|
1263
|
+
var deleteSwap = async (config, cid) => {
|
|
1264
|
+
if (!config) {
|
|
1265
|
+
throw new ValidationError("Pinata configuration is missing");
|
|
1266
|
+
}
|
|
1267
|
+
let headers;
|
|
1268
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1269
|
+
headers = { ...config.customHeaders };
|
|
1270
|
+
} else {
|
|
1271
|
+
headers = {
|
|
1272
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1273
|
+
"Content-Type": "application/json",
|
|
1274
|
+
Source: "sdk/deleteSwap"
|
|
1275
|
+
};
|
|
1276
|
+
}
|
|
1277
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
1278
|
+
if (config.endpointUrl) {
|
|
1279
|
+
endpoint = config.endpointUrl;
|
|
1280
|
+
}
|
|
1281
|
+
try {
|
|
1282
|
+
const request = await fetch(`${endpoint}/files/swap/${cid}`, {
|
|
1283
|
+
method: "DELETE",
|
|
1284
|
+
headers
|
|
1285
|
+
});
|
|
1286
|
+
if (!request.ok) {
|
|
1287
|
+
const errorData = await request.text();
|
|
1288
|
+
if (request.status === 401 || request.status === 403) {
|
|
1289
|
+
throw new AuthenticationError(
|
|
1290
|
+
`Authentication failed: ${errorData}`,
|
|
1291
|
+
request.status,
|
|
1292
|
+
errorData
|
|
1293
|
+
);
|
|
1294
|
+
}
|
|
1295
|
+
if (request.status === 403) {
|
|
1296
|
+
throw new PinataError(
|
|
1297
|
+
"Unauthorized CID Swap Deletion",
|
|
1298
|
+
request.status,
|
|
1299
|
+
errorData
|
|
1300
|
+
);
|
|
1301
|
+
}
|
|
1302
|
+
if (request.status === 404) {
|
|
1303
|
+
throw new PinataError(
|
|
1304
|
+
"CID not pinned to account",
|
|
1305
|
+
request.status,
|
|
1306
|
+
errorData
|
|
1307
|
+
);
|
|
1308
|
+
}
|
|
1309
|
+
throw new NetworkError(
|
|
1310
|
+
`HTTP error: ${errorData}`,
|
|
1311
|
+
request.status,
|
|
1312
|
+
errorData
|
|
1313
|
+
);
|
|
1314
|
+
}
|
|
1315
|
+
return request.statusText;
|
|
1316
|
+
} catch (error) {
|
|
1317
|
+
if (error instanceof PinataError) {
|
|
1318
|
+
throw error;
|
|
1319
|
+
}
|
|
1320
|
+
if (error instanceof Error) {
|
|
1321
|
+
throw new PinataError(`Error processing deleteSwap: ${error.message}`);
|
|
1322
|
+
}
|
|
1323
|
+
throw new PinataError("An unknown error occurred while deleting swap");
|
|
1324
|
+
}
|
|
1325
|
+
};
|
|
1326
|
+
|
|
1087
1327
|
// src/core/gateway/createSignedURL.ts
|
|
1088
|
-
var createSignedURL = async (config, options) => {
|
|
1328
|
+
var createSignedURL = async (config, options, imgOpts) => {
|
|
1089
1329
|
if (!config) {
|
|
1090
1330
|
throw new ValidationError("Pinata configuration is missing");
|
|
1091
1331
|
}
|
|
1092
1332
|
let newUrl = `${config?.pinataGateway}/files/${options.cid}`;
|
|
1333
|
+
const params = new URLSearchParams();
|
|
1334
|
+
if (imgOpts) {
|
|
1335
|
+
if (imgOpts.width)
|
|
1336
|
+
params.append("img-width", imgOpts.width.toString());
|
|
1337
|
+
if (imgOpts.height)
|
|
1338
|
+
params.append("img-height", imgOpts.height.toString());
|
|
1339
|
+
if (imgOpts.dpr)
|
|
1340
|
+
params.append("img-dpr", imgOpts.dpr.toString());
|
|
1341
|
+
if (imgOpts.fit)
|
|
1342
|
+
params.append("img-fit", imgOpts.fit);
|
|
1343
|
+
if (imgOpts.gravity)
|
|
1344
|
+
params.append("img-gravity", imgOpts.gravity);
|
|
1345
|
+
if (imgOpts.quality)
|
|
1346
|
+
params.append("img-quality", imgOpts.quality.toString());
|
|
1347
|
+
if (imgOpts.format)
|
|
1348
|
+
params.append("img-format", imgOpts.format);
|
|
1349
|
+
if (imgOpts.animation !== void 0)
|
|
1350
|
+
params.append("img-anim", imgOpts.animation.toString());
|
|
1351
|
+
if (imgOpts.sharpen)
|
|
1352
|
+
params.append("img-sharpen", imgOpts.sharpen.toString());
|
|
1353
|
+
if (imgOpts.onError === true)
|
|
1354
|
+
params.append("img-onerror", "redirect");
|
|
1355
|
+
if (imgOpts.metadata)
|
|
1356
|
+
params.append("img-metadata", imgOpts.metadata);
|
|
1357
|
+
}
|
|
1358
|
+
const queryString = params.toString();
|
|
1359
|
+
if (queryString) {
|
|
1360
|
+
newUrl += `?${queryString}`;
|
|
1361
|
+
}
|
|
1093
1362
|
const date = options?.date || Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3);
|
|
1094
1363
|
const payload = JSON.stringify({
|
|
1095
1364
|
url: newUrl,
|
|
@@ -1192,6 +1461,15 @@ var Files = class {
|
|
|
1192
1461
|
update(options) {
|
|
1193
1462
|
return updateFile(this.config, options);
|
|
1194
1463
|
}
|
|
1464
|
+
addSwap(options) {
|
|
1465
|
+
return swapCid(this.config, options);
|
|
1466
|
+
}
|
|
1467
|
+
getSwapHistory(options) {
|
|
1468
|
+
return swapHistory(this.config, options);
|
|
1469
|
+
}
|
|
1470
|
+
deleteSwap(cid) {
|
|
1471
|
+
return deleteSwap(this.config, cid);
|
|
1472
|
+
}
|
|
1195
1473
|
};
|
|
1196
1474
|
var UploadBuilder = class {
|
|
1197
1475
|
constructor(config, uploadFunction, ...args) {
|
|
@@ -1269,6 +1547,26 @@ var FilterFiles = class {
|
|
|
1269
1547
|
this.query = {};
|
|
1270
1548
|
this.config = config;
|
|
1271
1549
|
}
|
|
1550
|
+
name(name) {
|
|
1551
|
+
this.query.name = name;
|
|
1552
|
+
return this;
|
|
1553
|
+
}
|
|
1554
|
+
group(group) {
|
|
1555
|
+
this.query.group = group;
|
|
1556
|
+
return this;
|
|
1557
|
+
}
|
|
1558
|
+
cid(cid) {
|
|
1559
|
+
this.query.cid = cid;
|
|
1560
|
+
return this;
|
|
1561
|
+
}
|
|
1562
|
+
mimeType(mimeType) {
|
|
1563
|
+
this.query.mimeType = mimeType;
|
|
1564
|
+
return this;
|
|
1565
|
+
}
|
|
1566
|
+
order(order) {
|
|
1567
|
+
this.query.order = order;
|
|
1568
|
+
return this;
|
|
1569
|
+
}
|
|
1272
1570
|
limit(limit) {
|
|
1273
1571
|
this.query.limit = limit;
|
|
1274
1572
|
return this;
|
|
@@ -1333,20 +1631,11 @@ var Gateways = class {
|
|
|
1333
1631
|
this.config = newConfig;
|
|
1334
1632
|
}
|
|
1335
1633
|
get(cid) {
|
|
1336
|
-
return
|
|
1634
|
+
return new OptimizeImageGetCid(this.config, cid);
|
|
1337
1635
|
}
|
|
1338
1636
|
createSignedURL(options) {
|
|
1339
|
-
return
|
|
1637
|
+
return new OptimizeImageCreateSignedURL(this.config, options);
|
|
1340
1638
|
}
|
|
1341
|
-
// get(cid: string): OptimizeImage {
|
|
1342
|
-
// return new OptimizeImage(this.config, cid);
|
|
1343
|
-
// }
|
|
1344
|
-
// convert(url: string, gatewayPrefix?: string): Promise<string> {
|
|
1345
|
-
// return convertIPFSUrl(this.config, url, gatewayPrefix);
|
|
1346
|
-
// }
|
|
1347
|
-
// containsCID(cid: string): Promise<ContainsCIDResponse> {
|
|
1348
|
-
// return containsCID(cid);
|
|
1349
|
-
// }
|
|
1350
1639
|
// topUsageAnalytics(options: {
|
|
1351
1640
|
// domain: string;
|
|
1352
1641
|
// start: string;
|
|
@@ -1383,15 +1672,36 @@ var Gateways = class {
|
|
|
1383
1672
|
// options.interval,
|
|
1384
1673
|
// );
|
|
1385
1674
|
// }
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1675
|
+
};
|
|
1676
|
+
var OptimizeImageGetCid = class {
|
|
1677
|
+
constructor(config, cid) {
|
|
1678
|
+
this.options = {};
|
|
1679
|
+
this.config = config;
|
|
1680
|
+
this.cid = cid;
|
|
1681
|
+
}
|
|
1682
|
+
optimizeImage(options) {
|
|
1683
|
+
this.options = { ...this.options, ...options };
|
|
1684
|
+
return this;
|
|
1685
|
+
}
|
|
1686
|
+
then(onfulfilled) {
|
|
1687
|
+
return getCid(this.config, this.cid, this.options).then(onfulfilled);
|
|
1688
|
+
}
|
|
1689
|
+
};
|
|
1690
|
+
var OptimizeImageCreateSignedURL = class {
|
|
1691
|
+
constructor(config, urlOpts) {
|
|
1692
|
+
this.imgOpts = {};
|
|
1693
|
+
this.config = config;
|
|
1694
|
+
this.urlOpts = urlOpts;
|
|
1695
|
+
}
|
|
1696
|
+
optimizeImage(options) {
|
|
1697
|
+
this.imgOpts = { ...this.imgOpts, ...options };
|
|
1698
|
+
return this;
|
|
1699
|
+
}
|
|
1700
|
+
then(onfulfilled) {
|
|
1701
|
+
return createSignedURL(this.config, this.urlOpts, this.imgOpts).then(
|
|
1702
|
+
onfulfilled
|
|
1703
|
+
);
|
|
1704
|
+
}
|
|
1395
1705
|
};
|
|
1396
1706
|
var Keys = class {
|
|
1397
1707
|
constructor(config) {
|
|
@@ -1514,10 +1824,10 @@ var FilterGroups = class {
|
|
|
1514
1824
|
this.query = {};
|
|
1515
1825
|
this.config = config;
|
|
1516
1826
|
}
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1827
|
+
name(name) {
|
|
1828
|
+
this.query.name = name;
|
|
1829
|
+
return this;
|
|
1830
|
+
}
|
|
1521
1831
|
limit(limit) {
|
|
1522
1832
|
this.query.limit = limit;
|
|
1523
1833
|
return this;
|