pinata 0.3.4 → 0.4.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
@@ -829,15 +829,44 @@ async function convertToDesiredGateway(sourceUrl, desiredGatewayPrefix) {
829
829
  }
830
830
 
831
831
  // src/core/gateway/getCid.ts
832
- var getCid = async (config, cid) => {
832
+ var getCid = async (config, cid, options) => {
833
833
  if (!config) {
834
834
  throw new ValidationError("Pinata configuration is missing");
835
835
  }
836
836
  let data;
837
837
  let newUrl;
838
838
  newUrl = await convertToDesiredGateway(cid, config?.pinataGateway);
839
+ const params = new URLSearchParams();
839
840
  if (config?.pinataGatewayKey) {
840
- newUrl = `${newUrl}?pinataGatewayToken=${config?.pinataGatewayKey}`;
841
+ params.append("pinataGatewayToken", config.pinataGatewayKey);
842
+ }
843
+ if (options) {
844
+ if (options.width)
845
+ params.append("img-width", options.width.toString());
846
+ if (options.height)
847
+ params.append("img-height", options.height.toString());
848
+ if (options.dpr)
849
+ params.append("img-dpr", options.dpr.toString());
850
+ if (options.fit)
851
+ params.append("img-fit", options.fit);
852
+ if (options.gravity)
853
+ params.append("img-gravity", options.gravity);
854
+ if (options.quality)
855
+ params.append("img-quality", options.quality.toString());
856
+ if (options.format)
857
+ params.append("img-format", options.format);
858
+ if (options.animation !== void 0)
859
+ params.append("img-anim", options.animation.toString());
860
+ if (options.sharpen)
861
+ params.append("img-sharpen", options.sharpen.toString());
862
+ if (options.onError === true)
863
+ params.append("img-onerror", "redirect");
864
+ if (options.metadata)
865
+ params.append("img-metadata", options.metadata);
866
+ }
867
+ const queryString = params.toString();
868
+ if (queryString) {
869
+ newUrl += `?${queryString}`;
841
870
  }
842
871
  try {
843
872
  const request = await fetch(newUrl);
@@ -883,9 +912,10 @@ var getCid = async (config, cid) => {
883
912
  };
884
913
 
885
914
  // src/core/gateway/convertIPFSUrl.ts
886
- var convertIPFSUrl = async (config, url) => {
915
+ var convertIPFSUrl = async (config, url, gatewayPrefix) => {
887
916
  let newUrl;
888
- newUrl = await convertToDesiredGateway(url, config?.pinataGateway);
917
+ let prefix = gatewayPrefix || config?.pinataGateway || "https://gateway.pinata.cloud";
918
+ newUrl = await convertToDesiredGateway(url, prefix);
889
919
  if (config?.pinataGatewayKey) {
890
920
  `${newUrl}?pinataGatewayToken=${config?.pinataGatewayKey}`;
891
921
  }
@@ -2471,10 +2501,13 @@ var Gateways = class {
2471
2501
  this.config = newConfig;
2472
2502
  }
2473
2503
  get(cid) {
2474
- return getCid(this.config, cid);
2504
+ return new OptimizeImage(this.config, cid);
2475
2505
  }
2476
- convert(url) {
2477
- return convertIPFSUrl(this.config, url);
2506
+ convert(url, gatewayPrefix) {
2507
+ return convertIPFSUrl(this.config, url, gatewayPrefix);
2508
+ }
2509
+ containsCID(cid) {
2510
+ return containsCID(cid);
2478
2511
  }
2479
2512
  topUsageAnalytics(options) {
2480
2513
  return new TopGatewayAnalyticsBuilder(
@@ -2505,6 +2538,20 @@ var Gateways = class {
2505
2538
  return deleteSwap(this.config, cid);
2506
2539
  }
2507
2540
  };
2541
+ var OptimizeImage = class {
2542
+ constructor(config, cid) {
2543
+ this.options = {};
2544
+ this.config = config;
2545
+ this.cid = cid;
2546
+ }
2547
+ optimizeImage(options) {
2548
+ this.options = { ...this.options, ...options };
2549
+ return this;
2550
+ }
2551
+ then(onfulfilled) {
2552
+ return getCid(this.config, this.cid, this.options).then(onfulfilled);
2553
+ }
2554
+ };
2508
2555
  var FilterPinJobs = class {
2509
2556
  constructor(config) {
2510
2557
  this.query = {};