pinata 1.1.0 → 1.2.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.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
- const signedUrlRequest = await fetch(
549
- "https://api.pinata.cloud/v3/files/sign",
550
- {
551
- method: "POST",
552
- headers: {
553
- "Content-Type": "application/json",
554
- Authorization: `Bearer ${config?.pinataJwt}`
555
- },
556
- body: payload
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, nameContains, limit, isPublic } = options;
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 (nameContains !== void 0)
877
- params.append("nameContains", nameContains.toString());
915
+ if (name)
916
+ params.append("name", name);
878
917
  if (limit !== void 0)
879
918
  params.append("limit", limit.toString());
880
919
  }
@@ -1085,11 +1124,40 @@ var deleteGroup = async (config, options) => {
1085
1124
  };
1086
1125
 
1087
1126
  // src/core/gateway/createSignedURL.ts
1088
- var createSignedURL = async (config, options) => {
1127
+ var createSignedURL = async (config, options, imgOpts) => {
1089
1128
  if (!config) {
1090
1129
  throw new ValidationError("Pinata configuration is missing");
1091
1130
  }
1092
1131
  let newUrl = `${config?.pinataGateway}/files/${options.cid}`;
1132
+ const params = new URLSearchParams();
1133
+ if (imgOpts) {
1134
+ if (imgOpts.width)
1135
+ params.append("img-width", imgOpts.width.toString());
1136
+ if (imgOpts.height)
1137
+ params.append("img-height", imgOpts.height.toString());
1138
+ if (imgOpts.dpr)
1139
+ params.append("img-dpr", imgOpts.dpr.toString());
1140
+ if (imgOpts.fit)
1141
+ params.append("img-fit", imgOpts.fit);
1142
+ if (imgOpts.gravity)
1143
+ params.append("img-gravity", imgOpts.gravity);
1144
+ if (imgOpts.quality)
1145
+ params.append("img-quality", imgOpts.quality.toString());
1146
+ if (imgOpts.format)
1147
+ params.append("img-format", imgOpts.format);
1148
+ if (imgOpts.animation !== void 0)
1149
+ params.append("img-anim", imgOpts.animation.toString());
1150
+ if (imgOpts.sharpen)
1151
+ params.append("img-sharpen", imgOpts.sharpen.toString());
1152
+ if (imgOpts.onError === true)
1153
+ params.append("img-onerror", "redirect");
1154
+ if (imgOpts.metadata)
1155
+ params.append("img-metadata", imgOpts.metadata);
1156
+ }
1157
+ const queryString = params.toString();
1158
+ if (queryString) {
1159
+ newUrl += `?${queryString}`;
1160
+ }
1093
1161
  const date = options?.date || Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3);
1094
1162
  const payload = JSON.stringify({
1095
1163
  url: newUrl,
@@ -1269,6 +1337,26 @@ var FilterFiles = class {
1269
1337
  this.query = {};
1270
1338
  this.config = config;
1271
1339
  }
1340
+ name(name) {
1341
+ this.query.name = name;
1342
+ return this;
1343
+ }
1344
+ group(group) {
1345
+ this.query.group = group;
1346
+ return this;
1347
+ }
1348
+ cid(cid) {
1349
+ this.query.cid = cid;
1350
+ return this;
1351
+ }
1352
+ mimeType(mimeType) {
1353
+ this.query.mimeType = mimeType;
1354
+ return this;
1355
+ }
1356
+ order(order) {
1357
+ this.query.order = order;
1358
+ return this;
1359
+ }
1272
1360
  limit(limit) {
1273
1361
  this.query.limit = limit;
1274
1362
  return this;
@@ -1333,10 +1421,10 @@ var Gateways = class {
1333
1421
  this.config = newConfig;
1334
1422
  }
1335
1423
  get(cid) {
1336
- return getCid(this.config, cid);
1424
+ return new OptimizeImageGetCid(this.config, cid);
1337
1425
  }
1338
1426
  createSignedURL(options) {
1339
- return createSignedURL(this.config, options);
1427
+ return new OptimizeImageCreateSignedURL(this.config, options);
1340
1428
  }
1341
1429
  // get(cid: string): OptimizeImage {
1342
1430
  // return new OptimizeImage(this.config, cid);
@@ -1393,6 +1481,36 @@ var Gateways = class {
1393
1481
  // return deleteSwap(this.config, cid);
1394
1482
  // }
1395
1483
  };
1484
+ var OptimizeImageGetCid = class {
1485
+ constructor(config, cid) {
1486
+ this.options = {};
1487
+ this.config = config;
1488
+ this.cid = cid;
1489
+ }
1490
+ optimizeImage(options) {
1491
+ this.options = { ...this.options, ...options };
1492
+ return this;
1493
+ }
1494
+ then(onfulfilled) {
1495
+ return getCid(this.config, this.cid, this.options).then(onfulfilled);
1496
+ }
1497
+ };
1498
+ var OptimizeImageCreateSignedURL = class {
1499
+ constructor(config, urlOpts) {
1500
+ this.imgOpts = {};
1501
+ this.config = config;
1502
+ this.urlOpts = urlOpts;
1503
+ }
1504
+ optimizeImage(options) {
1505
+ this.imgOpts = { ...this.imgOpts, ...options };
1506
+ return this;
1507
+ }
1508
+ then(onfulfilled) {
1509
+ return createSignedURL(this.config, this.urlOpts, this.imgOpts).then(
1510
+ onfulfilled
1511
+ );
1512
+ }
1513
+ };
1396
1514
  var Keys = class {
1397
1515
  constructor(config) {
1398
1516
  this.config = formatConfig(config);
@@ -1514,10 +1632,10 @@ var FilterGroups = class {
1514
1632
  this.query = {};
1515
1633
  this.config = config;
1516
1634
  }
1517
- // name(nameContains: string): FilterGroups {
1518
- // this.query.nameContains = nameContains;
1519
- // return this;
1520
- // }
1635
+ name(name) {
1636
+ this.query.name = name;
1637
+ return this;
1638
+ }
1521
1639
  limit(limit) {
1522
1640
  this.query.limit = limit;
1523
1641
  return this;