pinata 1.4.1 → 1.5.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 +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +143 -24
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +143 -24
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -37,7 +37,10 @@ var testAuthentication = async (config) => {
|
|
|
37
37
|
endpoint = config.endpointUrl;
|
|
38
38
|
}
|
|
39
39
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
40
|
-
headers = {
|
|
40
|
+
headers = {
|
|
41
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
42
|
+
...config.customHeaders
|
|
43
|
+
};
|
|
41
44
|
} else {
|
|
42
45
|
headers = {
|
|
43
46
|
Authorization: `Bearer ${config.pinataJwt}`,
|
|
@@ -95,7 +98,10 @@ var uploadFile = async (config, file, options) => {
|
|
|
95
98
|
}
|
|
96
99
|
let headers;
|
|
97
100
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
98
|
-
headers = {
|
|
101
|
+
headers = {
|
|
102
|
+
Authorization: `Bearer ${jwt}`,
|
|
103
|
+
...config.customHeaders
|
|
104
|
+
};
|
|
99
105
|
} else {
|
|
100
106
|
headers = {
|
|
101
107
|
Authorization: `Bearer ${jwt}`,
|
|
@@ -158,7 +164,10 @@ var uploadBase64 = async (config, base64String, options) => {
|
|
|
158
164
|
}
|
|
159
165
|
let headers;
|
|
160
166
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
161
|
-
headers = {
|
|
167
|
+
headers = {
|
|
168
|
+
Authorization: `Bearer ${jwt}`,
|
|
169
|
+
...config.customHeaders
|
|
170
|
+
};
|
|
162
171
|
} else {
|
|
163
172
|
headers = {
|
|
164
173
|
Authorization: `Bearer ${jwt}`,
|
|
@@ -233,7 +242,10 @@ var uploadUrl = async (config, url, options) => {
|
|
|
233
242
|
}
|
|
234
243
|
let headers;
|
|
235
244
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
236
|
-
headers = {
|
|
245
|
+
headers = {
|
|
246
|
+
Authorization: `Bearer ${jwt}`,
|
|
247
|
+
...config.customHeaders
|
|
248
|
+
};
|
|
237
249
|
} else {
|
|
238
250
|
headers = {
|
|
239
251
|
Authorization: `Bearer ${jwt}`,
|
|
@@ -296,7 +308,10 @@ var uploadJson = async (config, jsonData, options) => {
|
|
|
296
308
|
}
|
|
297
309
|
let headers;
|
|
298
310
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
299
|
-
headers = {
|
|
311
|
+
headers = {
|
|
312
|
+
Authorization: `Bearer ${jwt}`,
|
|
313
|
+
...config.customHeaders
|
|
314
|
+
};
|
|
300
315
|
} else {
|
|
301
316
|
headers = {
|
|
302
317
|
Authorization: `Bearer ${jwt}`,
|
|
@@ -355,7 +370,10 @@ var deleteFile = async (config, files) => {
|
|
|
355
370
|
const responses = [];
|
|
356
371
|
let headers;
|
|
357
372
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
358
|
-
headers = {
|
|
373
|
+
headers = {
|
|
374
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
375
|
+
...config.customHeaders
|
|
376
|
+
};
|
|
359
377
|
} else {
|
|
360
378
|
headers = {
|
|
361
379
|
Authorization: `Bearer ${config.pinataJwt}`,
|
|
@@ -417,7 +435,17 @@ var listFiles = async (config, options) => {
|
|
|
417
435
|
}
|
|
418
436
|
const params = new URLSearchParams();
|
|
419
437
|
if (options) {
|
|
420
|
-
const {
|
|
438
|
+
const {
|
|
439
|
+
name,
|
|
440
|
+
group,
|
|
441
|
+
cid,
|
|
442
|
+
order,
|
|
443
|
+
limit,
|
|
444
|
+
mimeType,
|
|
445
|
+
pageToken,
|
|
446
|
+
cidPending,
|
|
447
|
+
metadata
|
|
448
|
+
} = options;
|
|
421
449
|
if (limit)
|
|
422
450
|
params.append("limit", limit.toString());
|
|
423
451
|
if (name)
|
|
@@ -434,6 +462,11 @@ var listFiles = async (config, options) => {
|
|
|
434
462
|
params.append("pageToken", pageToken);
|
|
435
463
|
if (cidPending)
|
|
436
464
|
params.append("cidPending", "true");
|
|
465
|
+
if (metadata && typeof metadata === "object") {
|
|
466
|
+
Object.entries(metadata).forEach(([key, value]) => {
|
|
467
|
+
params.append(`metadata[${key}]`, value.toString());
|
|
468
|
+
});
|
|
469
|
+
}
|
|
437
470
|
}
|
|
438
471
|
let endpoint = "https://api.pinata.cloud/v3";
|
|
439
472
|
if (config.endpointUrl) {
|
|
@@ -443,7 +476,10 @@ var listFiles = async (config, options) => {
|
|
|
443
476
|
try {
|
|
444
477
|
let headers;
|
|
445
478
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
446
|
-
headers = {
|
|
479
|
+
headers = {
|
|
480
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
481
|
+
...config.customHeaders
|
|
482
|
+
};
|
|
447
483
|
} else {
|
|
448
484
|
headers = {
|
|
449
485
|
Authorization: `Bearer ${config.pinataJwt}`,
|
|
@@ -488,12 +524,26 @@ var updateFile = async (config, options) => {
|
|
|
488
524
|
if (!config) {
|
|
489
525
|
throw new ValidationError("Pinata configuration is missing");
|
|
490
526
|
}
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
527
|
+
if (!options.name && (!options.keyvalues || Object.keys(options.keyvalues).length === 0)) {
|
|
528
|
+
throw new ValidationError(
|
|
529
|
+
"At least one of 'name' or 'keyvalues' must be provided"
|
|
530
|
+
);
|
|
531
|
+
}
|
|
532
|
+
const data = {};
|
|
533
|
+
if (options.name !== void 0) {
|
|
534
|
+
data.name = options.name;
|
|
535
|
+
}
|
|
536
|
+
if (options.keyvalues && Object.keys(options.keyvalues).length > 0) {
|
|
537
|
+
data.keyvalues = options.keyvalues;
|
|
538
|
+
}
|
|
539
|
+
const body = JSON.stringify(data);
|
|
494
540
|
let headers;
|
|
495
541
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
496
|
-
headers = {
|
|
542
|
+
headers = {
|
|
543
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
544
|
+
"Content-Type": "application/json",
|
|
545
|
+
...config.customHeaders
|
|
546
|
+
};
|
|
497
547
|
} else {
|
|
498
548
|
headers = {
|
|
499
549
|
Authorization: `Bearer ${config.pinataJwt}`,
|
|
@@ -509,7 +559,7 @@ var updateFile = async (config, options) => {
|
|
|
509
559
|
const request = await fetch(`${endpoint}/files/${options.id}`, {
|
|
510
560
|
method: "PUT",
|
|
511
561
|
headers,
|
|
512
|
-
body
|
|
562
|
+
body
|
|
513
563
|
});
|
|
514
564
|
if (!request.ok) {
|
|
515
565
|
const errorData = await request.text();
|
|
@@ -589,7 +639,11 @@ var getCid = async (config, cid, options) => {
|
|
|
589
639
|
}
|
|
590
640
|
let headers;
|
|
591
641
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
592
|
-
headers = {
|
|
642
|
+
headers = {
|
|
643
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
644
|
+
"Content-Type": "application/json",
|
|
645
|
+
...config.customHeaders
|
|
646
|
+
};
|
|
593
647
|
} else {
|
|
594
648
|
headers = {
|
|
595
649
|
"Content-Type": "application/json",
|
|
@@ -653,7 +707,11 @@ var createKey = async (config, options) => {
|
|
|
653
707
|
}
|
|
654
708
|
let headers;
|
|
655
709
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
656
|
-
headers = {
|
|
710
|
+
headers = {
|
|
711
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
712
|
+
"Content-Type": "application/json",
|
|
713
|
+
...config.customHeaders
|
|
714
|
+
};
|
|
657
715
|
} else {
|
|
658
716
|
headers = {
|
|
659
717
|
Authorization: `Bearer ${config.pinataJwt}`,
|
|
@@ -707,7 +765,11 @@ var listKeys = async (config, options) => {
|
|
|
707
765
|
}
|
|
708
766
|
let headers;
|
|
709
767
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
710
|
-
headers = {
|
|
768
|
+
headers = {
|
|
769
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
770
|
+
"Content-Type": "application/json",
|
|
771
|
+
...config.customHeaders
|
|
772
|
+
};
|
|
711
773
|
} else {
|
|
712
774
|
headers = {
|
|
713
775
|
Authorization: `Bearer ${config.pinataJwt}`,
|
|
@@ -781,6 +843,11 @@ var revokeKeys = async (config, keys) => {
|
|
|
781
843
|
}
|
|
782
844
|
let headers;
|
|
783
845
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
846
|
+
headers = {
|
|
847
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
848
|
+
"Content-Type": "application/json",
|
|
849
|
+
...config.customHeaders
|
|
850
|
+
};
|
|
784
851
|
headers = { ...config.customHeaders };
|
|
785
852
|
} else {
|
|
786
853
|
headers = {
|
|
@@ -850,7 +917,11 @@ var createGroup = async (config, options) => {
|
|
|
850
917
|
});
|
|
851
918
|
let headers;
|
|
852
919
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
853
|
-
headers = {
|
|
920
|
+
headers = {
|
|
921
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
922
|
+
"Content-Type": "application/json",
|
|
923
|
+
...config.customHeaders
|
|
924
|
+
};
|
|
854
925
|
} else {
|
|
855
926
|
headers = {
|
|
856
927
|
Authorization: `Bearer ${config.pinataJwt}`,
|
|
@@ -904,7 +975,11 @@ var listGroups = async (config, options) => {
|
|
|
904
975
|
}
|
|
905
976
|
let headers;
|
|
906
977
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
907
|
-
headers = {
|
|
978
|
+
headers = {
|
|
979
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
980
|
+
"Content-Type": "application/json",
|
|
981
|
+
...config.customHeaders
|
|
982
|
+
};
|
|
908
983
|
} else {
|
|
909
984
|
headers = {
|
|
910
985
|
Authorization: `Bearer ${config.pinataJwt}`,
|
|
@@ -972,7 +1047,11 @@ var getGroup = async (config, options) => {
|
|
|
972
1047
|
}
|
|
973
1048
|
let headers;
|
|
974
1049
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
975
|
-
headers = {
|
|
1050
|
+
headers = {
|
|
1051
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1052
|
+
"Content-Type": "application/json",
|
|
1053
|
+
...config.customHeaders
|
|
1054
|
+
};
|
|
976
1055
|
} else {
|
|
977
1056
|
headers = {
|
|
978
1057
|
Authorization: `Bearer ${config.pinataJwt}`,
|
|
@@ -1031,7 +1110,11 @@ var updateGroup = async (config, options) => {
|
|
|
1031
1110
|
});
|
|
1032
1111
|
let headers;
|
|
1033
1112
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1034
|
-
headers = {
|
|
1113
|
+
headers = {
|
|
1114
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1115
|
+
"Content-Type": "application/json",
|
|
1116
|
+
...config.customHeaders
|
|
1117
|
+
};
|
|
1035
1118
|
} else {
|
|
1036
1119
|
headers = {
|
|
1037
1120
|
Authorization: `Bearer ${config.pinataJwt}`,
|
|
@@ -1085,6 +1168,11 @@ var deleteGroup = async (config, options) => {
|
|
|
1085
1168
|
}
|
|
1086
1169
|
let headers;
|
|
1087
1170
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1171
|
+
headers = {
|
|
1172
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1173
|
+
"Content-Type": "application/json",
|
|
1174
|
+
...config.customHeaders
|
|
1175
|
+
};
|
|
1088
1176
|
headers = { ...config.customHeaders };
|
|
1089
1177
|
} else {
|
|
1090
1178
|
headers = {
|
|
@@ -1140,7 +1228,11 @@ var swapCid = async (config, options) => {
|
|
|
1140
1228
|
});
|
|
1141
1229
|
let headers;
|
|
1142
1230
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1143
|
-
headers = {
|
|
1231
|
+
headers = {
|
|
1232
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1233
|
+
"Content-Type": "application/json",
|
|
1234
|
+
...config.customHeaders
|
|
1235
|
+
};
|
|
1144
1236
|
} else {
|
|
1145
1237
|
headers = {
|
|
1146
1238
|
Authorization: `Bearer ${config.pinataJwt}`,
|
|
@@ -1208,7 +1300,11 @@ var swapHistory = async (config, options) => {
|
|
|
1208
1300
|
}
|
|
1209
1301
|
let headers;
|
|
1210
1302
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1211
|
-
headers = {
|
|
1303
|
+
headers = {
|
|
1304
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1305
|
+
"Content-Type": "application/json",
|
|
1306
|
+
...config.customHeaders
|
|
1307
|
+
};
|
|
1212
1308
|
} else {
|
|
1213
1309
|
headers = {
|
|
1214
1310
|
Authorization: `Bearer ${config.pinataJwt}`,
|
|
@@ -1273,7 +1369,11 @@ var deleteSwap = async (config, cid) => {
|
|
|
1273
1369
|
}
|
|
1274
1370
|
let headers;
|
|
1275
1371
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1276
|
-
headers = {
|
|
1372
|
+
headers = {
|
|
1373
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1374
|
+
"Content-Type": "application/json",
|
|
1375
|
+
...config.customHeaders
|
|
1376
|
+
};
|
|
1277
1377
|
} else {
|
|
1278
1378
|
headers = {
|
|
1279
1379
|
Authorization: `Bearer ${config.pinataJwt}`,
|
|
@@ -1385,7 +1485,11 @@ var createSignedURL = async (config, options, imgOpts) => {
|
|
|
1385
1485
|
}
|
|
1386
1486
|
let headers;
|
|
1387
1487
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1388
|
-
headers = {
|
|
1488
|
+
headers = {
|
|
1489
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1490
|
+
"Content-Type": "application/json",
|
|
1491
|
+
...config.customHeaders
|
|
1492
|
+
};
|
|
1389
1493
|
} else {
|
|
1390
1494
|
headers = {
|
|
1391
1495
|
"Content-Type": "application/json",
|
|
@@ -1461,6 +1565,17 @@ var PinataSDK = class {
|
|
|
1461
1565
|
this.keys.updateConfig(this.config);
|
|
1462
1566
|
this.groups.updateConfig(this.config);
|
|
1463
1567
|
}
|
|
1568
|
+
setNewJwt(jwt) {
|
|
1569
|
+
if (!this.config) {
|
|
1570
|
+
this.config = { pinataJwt: "" };
|
|
1571
|
+
}
|
|
1572
|
+
this.config.pinataJwt = jwt;
|
|
1573
|
+
this.files.updateConfig(this.config);
|
|
1574
|
+
this.upload.updateConfig(this.config);
|
|
1575
|
+
this.gateways.updateConfig(this.config);
|
|
1576
|
+
this.keys.updateConfig(this.config);
|
|
1577
|
+
this.groups.updateConfig(this.config);
|
|
1578
|
+
}
|
|
1464
1579
|
testAuthentication() {
|
|
1465
1580
|
return testAuthentication(this.config);
|
|
1466
1581
|
}
|
|
@@ -1595,6 +1710,10 @@ var FilterFiles = class {
|
|
|
1595
1710
|
this.query.cidPending = cidPending;
|
|
1596
1711
|
return this;
|
|
1597
1712
|
}
|
|
1713
|
+
metadata(keyvalues) {
|
|
1714
|
+
this.query.metadata = keyvalues;
|
|
1715
|
+
return this;
|
|
1716
|
+
}
|
|
1598
1717
|
pageToken(pageToken) {
|
|
1599
1718
|
this.query.pageToken = pageToken;
|
|
1600
1719
|
return this;
|