pinata 1.4.0 → 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 CHANGED
@@ -1,5 +1,5 @@
1
1
  type PinataConfig = {
2
- pinataJwt: string | undefined;
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: string | undefined;
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 = { ...config.customHeaders };
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 = { ...config.customHeaders };
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 = { ...config.customHeaders };
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 = { ...config.customHeaders };
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 = { ...config.customHeaders };
337
+ headers = {
338
+ Authorization: `Bearer ${jwt}`,
339
+ ...config.customHeaders
340
+ };
326
341
  } else {
327
342
  headers = {
328
343
  Authorization: `Bearer ${jwt}`,
@@ -381,11 +396,14 @@ 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 = { ...config.customHeaders };
399
+ headers = {
400
+ Authorization: `Bearer ${config.pinataJwt}`,
401
+ ...config.customHeaders
402
+ };
385
403
  } else {
386
404
  headers = {
387
405
  Authorization: `Bearer ${config.pinataJwt}`,
388
- Source: "sdk/unpin"
406
+ Source: "sdk/deleteFile"
389
407
  };
390
408
  }
391
409
  let endpoint = "https://api.pinata.cloud/v3";
@@ -443,7 +461,17 @@ var listFiles = async (config, options) => {
443
461
  }
444
462
  const params = new URLSearchParams();
445
463
  if (options) {
446
- const { name, group, cid, order, limit, mimeType, pageToken, cidPending } = options;
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 = { ...config.customHeaders };
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
- const data = JSON.stringify({
518
- name: options.name
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 = { ...config.customHeaders };
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: data
588
+ body
539
589
  });
540
590
  if (!request.ok) {
541
591
  const errorData = await request.text();
@@ -613,12 +663,23 @@ var getCid = async (config, cid, options) => {
613
663
  if (config.endpointUrl) {
614
664
  endpoint = config.endpointUrl;
615
665
  }
666
+ let headers;
667
+ if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
668
+ headers = {
669
+ Authorization: `Bearer ${config.pinataJwt}`,
670
+ "Content-Type": "application/json",
671
+ ...config.customHeaders
672
+ };
673
+ } else {
674
+ headers = {
675
+ "Content-Type": "application/json",
676
+ Authorization: `Bearer ${config.pinataJwt}`,
677
+ Source: "sdk/getCid"
678
+ };
679
+ }
616
680
  const signedUrlRequest = await fetch(`${endpoint}/files/sign`, {
617
681
  method: "POST",
618
- headers: {
619
- "Content-Type": "application/json",
620
- Authorization: `Bearer ${config?.pinataJwt}`
621
- },
682
+ headers,
622
683
  body: payload
623
684
  });
624
685
  const signedUrl = await signedUrlRequest.json();
@@ -672,7 +733,11 @@ var createKey = async (config, options) => {
672
733
  }
673
734
  let headers;
674
735
  if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
675
- headers = { ...config.customHeaders };
736
+ headers = {
737
+ Authorization: `Bearer ${config.pinataJwt}`,
738
+ "Content-Type": "application/json",
739
+ ...config.customHeaders
740
+ };
676
741
  } else {
677
742
  headers = {
678
743
  Authorization: `Bearer ${config.pinataJwt}`,
@@ -726,7 +791,11 @@ var listKeys = async (config, options) => {
726
791
  }
727
792
  let headers;
728
793
  if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
729
- headers = { ...config.customHeaders };
794
+ headers = {
795
+ Authorization: `Bearer ${config.pinataJwt}`,
796
+ "Content-Type": "application/json",
797
+ ...config.customHeaders
798
+ };
730
799
  } else {
731
800
  headers = {
732
801
  Authorization: `Bearer ${config.pinataJwt}`,
@@ -800,6 +869,11 @@ var revokeKeys = async (config, keys) => {
800
869
  }
801
870
  let headers;
802
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
+ };
803
877
  headers = { ...config.customHeaders };
804
878
  } else {
805
879
  headers = {
@@ -869,7 +943,11 @@ var createGroup = async (config, options) => {
869
943
  });
870
944
  let headers;
871
945
  if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
872
- headers = { ...config.customHeaders };
946
+ headers = {
947
+ Authorization: `Bearer ${config.pinataJwt}`,
948
+ "Content-Type": "application/json",
949
+ ...config.customHeaders
950
+ };
873
951
  } else {
874
952
  headers = {
875
953
  Authorization: `Bearer ${config.pinataJwt}`,
@@ -923,7 +1001,11 @@ var listGroups = async (config, options) => {
923
1001
  }
924
1002
  let headers;
925
1003
  if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
926
- headers = { ...config.customHeaders };
1004
+ headers = {
1005
+ Authorization: `Bearer ${config.pinataJwt}`,
1006
+ "Content-Type": "application/json",
1007
+ ...config.customHeaders
1008
+ };
927
1009
  } else {
928
1010
  headers = {
929
1011
  Authorization: `Bearer ${config.pinataJwt}`,
@@ -991,7 +1073,11 @@ var getGroup = async (config, options) => {
991
1073
  }
992
1074
  let headers;
993
1075
  if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
994
- headers = { ...config.customHeaders };
1076
+ headers = {
1077
+ Authorization: `Bearer ${config.pinataJwt}`,
1078
+ "Content-Type": "application/json",
1079
+ ...config.customHeaders
1080
+ };
995
1081
  } else {
996
1082
  headers = {
997
1083
  Authorization: `Bearer ${config.pinataJwt}`,
@@ -1050,7 +1136,11 @@ var updateGroup = async (config, options) => {
1050
1136
  });
1051
1137
  let headers;
1052
1138
  if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
1053
- headers = { ...config.customHeaders };
1139
+ headers = {
1140
+ Authorization: `Bearer ${config.pinataJwt}`,
1141
+ "Content-Type": "application/json",
1142
+ ...config.customHeaders
1143
+ };
1054
1144
  } else {
1055
1145
  headers = {
1056
1146
  Authorization: `Bearer ${config.pinataJwt}`,
@@ -1104,6 +1194,11 @@ var deleteGroup = async (config, options) => {
1104
1194
  }
1105
1195
  let headers;
1106
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
+ };
1107
1202
  headers = { ...config.customHeaders };
1108
1203
  } else {
1109
1204
  headers = {
@@ -1159,7 +1254,11 @@ var swapCid = async (config, options) => {
1159
1254
  });
1160
1255
  let headers;
1161
1256
  if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
1162
- headers = { ...config.customHeaders };
1257
+ headers = {
1258
+ Authorization: `Bearer ${config.pinataJwt}`,
1259
+ "Content-Type": "application/json",
1260
+ ...config.customHeaders
1261
+ };
1163
1262
  } else {
1164
1263
  headers = {
1165
1264
  Authorization: `Bearer ${config.pinataJwt}`,
@@ -1227,7 +1326,11 @@ var swapHistory = async (config, options) => {
1227
1326
  }
1228
1327
  let headers;
1229
1328
  if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
1230
- headers = { ...config.customHeaders };
1329
+ headers = {
1330
+ Authorization: `Bearer ${config.pinataJwt}`,
1331
+ "Content-Type": "application/json",
1332
+ ...config.customHeaders
1333
+ };
1231
1334
  } else {
1232
1335
  headers = {
1233
1336
  Authorization: `Bearer ${config.pinataJwt}`,
@@ -1292,7 +1395,11 @@ var deleteSwap = async (config, cid) => {
1292
1395
  }
1293
1396
  let headers;
1294
1397
  if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
1295
- headers = { ...config.customHeaders };
1398
+ headers = {
1399
+ Authorization: `Bearer ${config.pinataJwt}`,
1400
+ "Content-Type": "application/json",
1401
+ ...config.customHeaders
1402
+ };
1296
1403
  } else {
1297
1404
  headers = {
1298
1405
  Authorization: `Bearer ${config.pinataJwt}`,
@@ -1402,13 +1509,24 @@ var createSignedURL = async (config, options, imgOpts) => {
1402
1509
  if (config.endpointUrl) {
1403
1510
  endpoint = config.endpointUrl;
1404
1511
  }
1512
+ let headers;
1513
+ if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
1514
+ headers = {
1515
+ Authorization: `Bearer ${config.pinataJwt}`,
1516
+ "Content-Type": "application/json",
1517
+ ...config.customHeaders
1518
+ };
1519
+ } else {
1520
+ headers = {
1521
+ "Content-Type": "application/json",
1522
+ Authorization: `Bearer ${config.pinataJwt}`,
1523
+ Source: "sdk/createSignURL"
1524
+ };
1525
+ }
1405
1526
  try {
1406
1527
  const request = await fetch(`${endpoint}/files/sign`, {
1407
1528
  method: "POST",
1408
- headers: {
1409
- "Content-Type": "application/json",
1410
- Authorization: `Bearer ${config?.pinataJwt}`
1411
- },
1529
+ headers,
1412
1530
  body: payload
1413
1531
  });
1414
1532
  if (!request.ok) {
@@ -1473,6 +1591,17 @@ var PinataSDK = class {
1473
1591
  this.keys.updateConfig(this.config);
1474
1592
  this.groups.updateConfig(this.config);
1475
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
+ }
1476
1605
  testAuthentication() {
1477
1606
  return testAuthentication(this.config);
1478
1607
  }
@@ -1607,6 +1736,10 @@ var FilterFiles = class {
1607
1736
  this.query.cidPending = cidPending;
1608
1737
  return this;
1609
1738
  }
1739
+ metadata(keyvalues) {
1740
+ this.query.metadata = keyvalues;
1741
+ return this;
1742
+ }
1610
1743
  pageToken(pageToken) {
1611
1744
  this.query.pageToken = pageToken;
1612
1745
  return this;