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.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
type PinataConfig = {
|
|
2
|
-
pinataJwt
|
|
2
|
+
pinataJwt?: string;
|
|
3
3
|
pinataGateway?: string;
|
|
4
4
|
pinataGatewayKey?: string;
|
|
5
5
|
customHeaders?: Record<string, string>;
|
|
@@ -34,6 +34,7 @@ type PinataMetadata = {
|
|
|
34
34
|
type UpdateFileOptions = {
|
|
35
35
|
id: string;
|
|
36
36
|
name?: string;
|
|
37
|
+
keyvalues?: Record<string, string>;
|
|
37
38
|
};
|
|
38
39
|
type UploadOptions = {
|
|
39
40
|
metadata?: PinataMetadata;
|
|
@@ -51,6 +52,7 @@ type FileListItem = {
|
|
|
51
52
|
size: number;
|
|
52
53
|
number_of_files: number;
|
|
53
54
|
mime_type: string;
|
|
55
|
+
keyvalues: Record<string, string>;
|
|
54
56
|
group_id: string | null;
|
|
55
57
|
created_at: string;
|
|
56
58
|
};
|
|
@@ -64,6 +66,7 @@ type FileListQuery = {
|
|
|
64
66
|
mimeType?: string;
|
|
65
67
|
cid?: string;
|
|
66
68
|
cidPending?: boolean;
|
|
69
|
+
metadata?: Record<string, string>;
|
|
67
70
|
order?: "ASC" | "DESC";
|
|
68
71
|
limit?: number;
|
|
69
72
|
pageToken?: string;
|
|
@@ -294,6 +297,7 @@ declare class PinataSDK {
|
|
|
294
297
|
groups: Groups;
|
|
295
298
|
constructor(config?: PinataConfig);
|
|
296
299
|
setNewHeaders(headers: Record<string, string>): void;
|
|
300
|
+
setNewJwt(jwt: string): void;
|
|
297
301
|
testAuthentication(): Promise<AuthTestResponse>;
|
|
298
302
|
}
|
|
299
303
|
declare class Files {
|
|
@@ -341,6 +345,7 @@ declare class FilterFiles {
|
|
|
341
345
|
order(order: "ASC" | "DESC"): FilterFiles;
|
|
342
346
|
limit(limit: number): FilterFiles;
|
|
343
347
|
cidPending(cidPending: boolean): FilterFiles;
|
|
348
|
+
metadata(keyvalues: Record<string, string>): FilterFiles;
|
|
344
349
|
pageToken(pageToken: string): FilterFiles;
|
|
345
350
|
then(onfulfilled?: ((value: FileListResponse) => any) | null): Promise<any>;
|
|
346
351
|
private fetchPage;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
type PinataConfig = {
|
|
2
|
-
pinataJwt
|
|
2
|
+
pinataJwt?: string;
|
|
3
3
|
pinataGateway?: string;
|
|
4
4
|
pinataGatewayKey?: string;
|
|
5
5
|
customHeaders?: Record<string, string>;
|
|
@@ -34,6 +34,7 @@ type PinataMetadata = {
|
|
|
34
34
|
type UpdateFileOptions = {
|
|
35
35
|
id: string;
|
|
36
36
|
name?: string;
|
|
37
|
+
keyvalues?: Record<string, string>;
|
|
37
38
|
};
|
|
38
39
|
type UploadOptions = {
|
|
39
40
|
metadata?: PinataMetadata;
|
|
@@ -51,6 +52,7 @@ type FileListItem = {
|
|
|
51
52
|
size: number;
|
|
52
53
|
number_of_files: number;
|
|
53
54
|
mime_type: string;
|
|
55
|
+
keyvalues: Record<string, string>;
|
|
54
56
|
group_id: string | null;
|
|
55
57
|
created_at: string;
|
|
56
58
|
};
|
|
@@ -64,6 +66,7 @@ type FileListQuery = {
|
|
|
64
66
|
mimeType?: string;
|
|
65
67
|
cid?: string;
|
|
66
68
|
cidPending?: boolean;
|
|
69
|
+
metadata?: Record<string, string>;
|
|
67
70
|
order?: "ASC" | "DESC";
|
|
68
71
|
limit?: number;
|
|
69
72
|
pageToken?: string;
|
|
@@ -294,6 +297,7 @@ declare class PinataSDK {
|
|
|
294
297
|
groups: Groups;
|
|
295
298
|
constructor(config?: PinataConfig);
|
|
296
299
|
setNewHeaders(headers: Record<string, string>): void;
|
|
300
|
+
setNewJwt(jwt: string): void;
|
|
297
301
|
testAuthentication(): Promise<AuthTestResponse>;
|
|
298
302
|
}
|
|
299
303
|
declare class Files {
|
|
@@ -341,6 +345,7 @@ declare class FilterFiles {
|
|
|
341
345
|
order(order: "ASC" | "DESC"): FilterFiles;
|
|
342
346
|
limit(limit: number): FilterFiles;
|
|
343
347
|
cidPending(cidPending: boolean): FilterFiles;
|
|
348
|
+
metadata(keyvalues: Record<string, string>): FilterFiles;
|
|
344
349
|
pageToken(pageToken: string): FilterFiles;
|
|
345
350
|
then(onfulfilled?: ((value: FileListResponse) => any) | null): Promise<any>;
|
|
346
351
|
private fetchPage;
|
package/dist/index.js
CHANGED
|
@@ -63,7 +63,10 @@ var testAuthentication = async (config) => {
|
|
|
63
63
|
endpoint = config.endpointUrl;
|
|
64
64
|
}
|
|
65
65
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
66
|
-
headers = {
|
|
66
|
+
headers = {
|
|
67
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
68
|
+
...config.customHeaders
|
|
69
|
+
};
|
|
67
70
|
} else {
|
|
68
71
|
headers = {
|
|
69
72
|
Authorization: `Bearer ${config.pinataJwt}`,
|
|
@@ -121,7 +124,10 @@ var uploadFile = async (config, file, options) => {
|
|
|
121
124
|
}
|
|
122
125
|
let headers;
|
|
123
126
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
124
|
-
headers = {
|
|
127
|
+
headers = {
|
|
128
|
+
Authorization: `Bearer ${jwt}`,
|
|
129
|
+
...config.customHeaders
|
|
130
|
+
};
|
|
125
131
|
} else {
|
|
126
132
|
headers = {
|
|
127
133
|
Authorization: `Bearer ${jwt}`,
|
|
@@ -184,7 +190,10 @@ var uploadBase64 = async (config, base64String, options) => {
|
|
|
184
190
|
}
|
|
185
191
|
let headers;
|
|
186
192
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
187
|
-
headers = {
|
|
193
|
+
headers = {
|
|
194
|
+
Authorization: `Bearer ${jwt}`,
|
|
195
|
+
...config.customHeaders
|
|
196
|
+
};
|
|
188
197
|
} else {
|
|
189
198
|
headers = {
|
|
190
199
|
Authorization: `Bearer ${jwt}`,
|
|
@@ -259,7 +268,10 @@ var uploadUrl = async (config, url, options) => {
|
|
|
259
268
|
}
|
|
260
269
|
let headers;
|
|
261
270
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
262
|
-
headers = {
|
|
271
|
+
headers = {
|
|
272
|
+
Authorization: `Bearer ${jwt}`,
|
|
273
|
+
...config.customHeaders
|
|
274
|
+
};
|
|
263
275
|
} else {
|
|
264
276
|
headers = {
|
|
265
277
|
Authorization: `Bearer ${jwt}`,
|
|
@@ -322,7 +334,10 @@ var uploadJson = async (config, jsonData, options) => {
|
|
|
322
334
|
}
|
|
323
335
|
let headers;
|
|
324
336
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
325
|
-
headers = {
|
|
337
|
+
headers = {
|
|
338
|
+
Authorization: `Bearer ${jwt}`,
|
|
339
|
+
...config.customHeaders
|
|
340
|
+
};
|
|
326
341
|
} else {
|
|
327
342
|
headers = {
|
|
328
343
|
Authorization: `Bearer ${jwt}`,
|
|
@@ -381,7 +396,10 @@ var deleteFile = async (config, files) => {
|
|
|
381
396
|
const responses = [];
|
|
382
397
|
let headers;
|
|
383
398
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
384
|
-
headers = {
|
|
399
|
+
headers = {
|
|
400
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
401
|
+
...config.customHeaders
|
|
402
|
+
};
|
|
385
403
|
} else {
|
|
386
404
|
headers = {
|
|
387
405
|
Authorization: `Bearer ${config.pinataJwt}`,
|
|
@@ -443,7 +461,17 @@ var listFiles = async (config, options) => {
|
|
|
443
461
|
}
|
|
444
462
|
const params = new URLSearchParams();
|
|
445
463
|
if (options) {
|
|
446
|
-
const {
|
|
464
|
+
const {
|
|
465
|
+
name,
|
|
466
|
+
group,
|
|
467
|
+
cid,
|
|
468
|
+
order,
|
|
469
|
+
limit,
|
|
470
|
+
mimeType,
|
|
471
|
+
pageToken,
|
|
472
|
+
cidPending,
|
|
473
|
+
metadata
|
|
474
|
+
} = options;
|
|
447
475
|
if (limit)
|
|
448
476
|
params.append("limit", limit.toString());
|
|
449
477
|
if (name)
|
|
@@ -460,6 +488,11 @@ var listFiles = async (config, options) => {
|
|
|
460
488
|
params.append("pageToken", pageToken);
|
|
461
489
|
if (cidPending)
|
|
462
490
|
params.append("cidPending", "true");
|
|
491
|
+
if (metadata && typeof metadata === "object") {
|
|
492
|
+
Object.entries(metadata).forEach(([key, value]) => {
|
|
493
|
+
params.append(`metadata[${key}]`, value.toString());
|
|
494
|
+
});
|
|
495
|
+
}
|
|
463
496
|
}
|
|
464
497
|
let endpoint = "https://api.pinata.cloud/v3";
|
|
465
498
|
if (config.endpointUrl) {
|
|
@@ -469,7 +502,10 @@ var listFiles = async (config, options) => {
|
|
|
469
502
|
try {
|
|
470
503
|
let headers;
|
|
471
504
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
472
|
-
headers = {
|
|
505
|
+
headers = {
|
|
506
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
507
|
+
...config.customHeaders
|
|
508
|
+
};
|
|
473
509
|
} else {
|
|
474
510
|
headers = {
|
|
475
511
|
Authorization: `Bearer ${config.pinataJwt}`,
|
|
@@ -514,12 +550,26 @@ var updateFile = async (config, options) => {
|
|
|
514
550
|
if (!config) {
|
|
515
551
|
throw new ValidationError("Pinata configuration is missing");
|
|
516
552
|
}
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
553
|
+
if (!options.name && (!options.keyvalues || Object.keys(options.keyvalues).length === 0)) {
|
|
554
|
+
throw new ValidationError(
|
|
555
|
+
"At least one of 'name' or 'keyvalues' must be provided"
|
|
556
|
+
);
|
|
557
|
+
}
|
|
558
|
+
const data = {};
|
|
559
|
+
if (options.name !== void 0) {
|
|
560
|
+
data.name = options.name;
|
|
561
|
+
}
|
|
562
|
+
if (options.keyvalues && Object.keys(options.keyvalues).length > 0) {
|
|
563
|
+
data.keyvalues = options.keyvalues;
|
|
564
|
+
}
|
|
565
|
+
const body = JSON.stringify(data);
|
|
520
566
|
let headers;
|
|
521
567
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
522
|
-
headers = {
|
|
568
|
+
headers = {
|
|
569
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
570
|
+
"Content-Type": "application/json",
|
|
571
|
+
...config.customHeaders
|
|
572
|
+
};
|
|
523
573
|
} else {
|
|
524
574
|
headers = {
|
|
525
575
|
Authorization: `Bearer ${config.pinataJwt}`,
|
|
@@ -535,7 +585,7 @@ var updateFile = async (config, options) => {
|
|
|
535
585
|
const request = await fetch(`${endpoint}/files/${options.id}`, {
|
|
536
586
|
method: "PUT",
|
|
537
587
|
headers,
|
|
538
|
-
body
|
|
588
|
+
body
|
|
539
589
|
});
|
|
540
590
|
if (!request.ok) {
|
|
541
591
|
const errorData = await request.text();
|
|
@@ -615,7 +665,11 @@ var getCid = async (config, cid, options) => {
|
|
|
615
665
|
}
|
|
616
666
|
let headers;
|
|
617
667
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
618
|
-
headers = {
|
|
668
|
+
headers = {
|
|
669
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
670
|
+
"Content-Type": "application/json",
|
|
671
|
+
...config.customHeaders
|
|
672
|
+
};
|
|
619
673
|
} else {
|
|
620
674
|
headers = {
|
|
621
675
|
"Content-Type": "application/json",
|
|
@@ -679,7 +733,11 @@ var createKey = async (config, options) => {
|
|
|
679
733
|
}
|
|
680
734
|
let headers;
|
|
681
735
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
682
|
-
headers = {
|
|
736
|
+
headers = {
|
|
737
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
738
|
+
"Content-Type": "application/json",
|
|
739
|
+
...config.customHeaders
|
|
740
|
+
};
|
|
683
741
|
} else {
|
|
684
742
|
headers = {
|
|
685
743
|
Authorization: `Bearer ${config.pinataJwt}`,
|
|
@@ -733,7 +791,11 @@ var listKeys = async (config, options) => {
|
|
|
733
791
|
}
|
|
734
792
|
let headers;
|
|
735
793
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
736
|
-
headers = {
|
|
794
|
+
headers = {
|
|
795
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
796
|
+
"Content-Type": "application/json",
|
|
797
|
+
...config.customHeaders
|
|
798
|
+
};
|
|
737
799
|
} else {
|
|
738
800
|
headers = {
|
|
739
801
|
Authorization: `Bearer ${config.pinataJwt}`,
|
|
@@ -807,6 +869,11 @@ var revokeKeys = async (config, keys) => {
|
|
|
807
869
|
}
|
|
808
870
|
let headers;
|
|
809
871
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
872
|
+
headers = {
|
|
873
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
874
|
+
"Content-Type": "application/json",
|
|
875
|
+
...config.customHeaders
|
|
876
|
+
};
|
|
810
877
|
headers = { ...config.customHeaders };
|
|
811
878
|
} else {
|
|
812
879
|
headers = {
|
|
@@ -876,7 +943,11 @@ var createGroup = async (config, options) => {
|
|
|
876
943
|
});
|
|
877
944
|
let headers;
|
|
878
945
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
879
|
-
headers = {
|
|
946
|
+
headers = {
|
|
947
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
948
|
+
"Content-Type": "application/json",
|
|
949
|
+
...config.customHeaders
|
|
950
|
+
};
|
|
880
951
|
} else {
|
|
881
952
|
headers = {
|
|
882
953
|
Authorization: `Bearer ${config.pinataJwt}`,
|
|
@@ -930,7 +1001,11 @@ var listGroups = async (config, options) => {
|
|
|
930
1001
|
}
|
|
931
1002
|
let headers;
|
|
932
1003
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
933
|
-
headers = {
|
|
1004
|
+
headers = {
|
|
1005
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1006
|
+
"Content-Type": "application/json",
|
|
1007
|
+
...config.customHeaders
|
|
1008
|
+
};
|
|
934
1009
|
} else {
|
|
935
1010
|
headers = {
|
|
936
1011
|
Authorization: `Bearer ${config.pinataJwt}`,
|
|
@@ -998,7 +1073,11 @@ var getGroup = async (config, options) => {
|
|
|
998
1073
|
}
|
|
999
1074
|
let headers;
|
|
1000
1075
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1001
|
-
headers = {
|
|
1076
|
+
headers = {
|
|
1077
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1078
|
+
"Content-Type": "application/json",
|
|
1079
|
+
...config.customHeaders
|
|
1080
|
+
};
|
|
1002
1081
|
} else {
|
|
1003
1082
|
headers = {
|
|
1004
1083
|
Authorization: `Bearer ${config.pinataJwt}`,
|
|
@@ -1057,7 +1136,11 @@ var updateGroup = async (config, options) => {
|
|
|
1057
1136
|
});
|
|
1058
1137
|
let headers;
|
|
1059
1138
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1060
|
-
headers = {
|
|
1139
|
+
headers = {
|
|
1140
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1141
|
+
"Content-Type": "application/json",
|
|
1142
|
+
...config.customHeaders
|
|
1143
|
+
};
|
|
1061
1144
|
} else {
|
|
1062
1145
|
headers = {
|
|
1063
1146
|
Authorization: `Bearer ${config.pinataJwt}`,
|
|
@@ -1111,6 +1194,11 @@ var deleteGroup = async (config, options) => {
|
|
|
1111
1194
|
}
|
|
1112
1195
|
let headers;
|
|
1113
1196
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1197
|
+
headers = {
|
|
1198
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1199
|
+
"Content-Type": "application/json",
|
|
1200
|
+
...config.customHeaders
|
|
1201
|
+
};
|
|
1114
1202
|
headers = { ...config.customHeaders };
|
|
1115
1203
|
} else {
|
|
1116
1204
|
headers = {
|
|
@@ -1166,7 +1254,11 @@ var swapCid = async (config, options) => {
|
|
|
1166
1254
|
});
|
|
1167
1255
|
let headers;
|
|
1168
1256
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1169
|
-
headers = {
|
|
1257
|
+
headers = {
|
|
1258
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1259
|
+
"Content-Type": "application/json",
|
|
1260
|
+
...config.customHeaders
|
|
1261
|
+
};
|
|
1170
1262
|
} else {
|
|
1171
1263
|
headers = {
|
|
1172
1264
|
Authorization: `Bearer ${config.pinataJwt}`,
|
|
@@ -1234,7 +1326,11 @@ var swapHistory = async (config, options) => {
|
|
|
1234
1326
|
}
|
|
1235
1327
|
let headers;
|
|
1236
1328
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1237
|
-
headers = {
|
|
1329
|
+
headers = {
|
|
1330
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1331
|
+
"Content-Type": "application/json",
|
|
1332
|
+
...config.customHeaders
|
|
1333
|
+
};
|
|
1238
1334
|
} else {
|
|
1239
1335
|
headers = {
|
|
1240
1336
|
Authorization: `Bearer ${config.pinataJwt}`,
|
|
@@ -1299,7 +1395,11 @@ var deleteSwap = async (config, cid) => {
|
|
|
1299
1395
|
}
|
|
1300
1396
|
let headers;
|
|
1301
1397
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1302
|
-
headers = {
|
|
1398
|
+
headers = {
|
|
1399
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1400
|
+
"Content-Type": "application/json",
|
|
1401
|
+
...config.customHeaders
|
|
1402
|
+
};
|
|
1303
1403
|
} else {
|
|
1304
1404
|
headers = {
|
|
1305
1405
|
Authorization: `Bearer ${config.pinataJwt}`,
|
|
@@ -1411,7 +1511,11 @@ var createSignedURL = async (config, options, imgOpts) => {
|
|
|
1411
1511
|
}
|
|
1412
1512
|
let headers;
|
|
1413
1513
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1414
|
-
headers = {
|
|
1514
|
+
headers = {
|
|
1515
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1516
|
+
"Content-Type": "application/json",
|
|
1517
|
+
...config.customHeaders
|
|
1518
|
+
};
|
|
1415
1519
|
} else {
|
|
1416
1520
|
headers = {
|
|
1417
1521
|
"Content-Type": "application/json",
|
|
@@ -1487,6 +1591,17 @@ var PinataSDK = class {
|
|
|
1487
1591
|
this.keys.updateConfig(this.config);
|
|
1488
1592
|
this.groups.updateConfig(this.config);
|
|
1489
1593
|
}
|
|
1594
|
+
setNewJwt(jwt) {
|
|
1595
|
+
if (!this.config) {
|
|
1596
|
+
this.config = { pinataJwt: "" };
|
|
1597
|
+
}
|
|
1598
|
+
this.config.pinataJwt = jwt;
|
|
1599
|
+
this.files.updateConfig(this.config);
|
|
1600
|
+
this.upload.updateConfig(this.config);
|
|
1601
|
+
this.gateways.updateConfig(this.config);
|
|
1602
|
+
this.keys.updateConfig(this.config);
|
|
1603
|
+
this.groups.updateConfig(this.config);
|
|
1604
|
+
}
|
|
1490
1605
|
testAuthentication() {
|
|
1491
1606
|
return testAuthentication(this.config);
|
|
1492
1607
|
}
|
|
@@ -1621,6 +1736,10 @@ var FilterFiles = class {
|
|
|
1621
1736
|
this.query.cidPending = cidPending;
|
|
1622
1737
|
return this;
|
|
1623
1738
|
}
|
|
1739
|
+
metadata(keyvalues) {
|
|
1740
|
+
this.query.metadata = keyvalues;
|
|
1741
|
+
return this;
|
|
1742
|
+
}
|
|
1624
1743
|
pageToken(pageToken) {
|
|
1625
1744
|
this.query.pageToken = pageToken;
|
|
1626
1745
|
return this;
|