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.d.mts CHANGED
@@ -124,6 +124,19 @@ type GetCIDResponse = {
124
124
  data?: JSON | string | Blob | null;
125
125
  contentType: ContentType;
126
126
  };
127
+ type OptimizeImageOptions = {
128
+ width?: number;
129
+ height?: number;
130
+ dpr?: number;
131
+ fit?: "scaleDown" | "contain" | "cover" | "crop" | "pad";
132
+ gravity?: "auto" | "side" | string;
133
+ quality?: number;
134
+ format?: "auto" | "webp";
135
+ animation?: boolean;
136
+ sharpen?: number;
137
+ onError?: boolean;
138
+ metadata?: "keep" | "copyright" | "none";
139
+ };
127
140
  type GatewayAnalyticsQuery = {
128
141
  gateway_domain: string;
129
142
  start_date: string;
@@ -280,6 +293,10 @@ type SwapCidResponse = {
280
293
  mappedCid: string;
281
294
  createdAt: string;
282
295
  };
296
+ type ContainsCIDResponse = {
297
+ containsCid: boolean;
298
+ cid: string | null;
299
+ };
283
300
 
284
301
  declare class PinataSDK {
285
302
  config: PinataConfig | undefined;
@@ -352,8 +369,9 @@ declare class Gateways {
352
369
  config: PinataConfig | undefined;
353
370
  constructor(config?: PinataConfig);
354
371
  updateConfig(newConfig: PinataConfig): void;
355
- get(cid: string): Promise<GetCIDResponse>;
356
- convert(url: string): Promise<string>;
372
+ get(cid: string): OptimizeImage;
373
+ convert(url: string, gatewayPrefix?: string): Promise<string>;
374
+ containsCID(cid: string): Promise<ContainsCIDResponse>;
357
375
  topUsageAnalytics(options: {
358
376
  domain: string;
359
377
  start: string;
@@ -371,6 +389,14 @@ declare class Gateways {
371
389
  swapHistory(options: SwapHistoryOptions): Promise<SwapCidResponse[]>;
372
390
  deleteSwap(cid: string): Promise<string>;
373
391
  }
392
+ declare class OptimizeImage {
393
+ private config;
394
+ private cid;
395
+ private options;
396
+ constructor(config: PinataConfig | undefined, cid: string);
397
+ optimizeImage(options: OptimizeImageOptions): OptimizeImage;
398
+ then(onfulfilled?: ((value: GetCIDResponse) => any) | null): Promise<any>;
399
+ }
374
400
  declare class FilterPinJobs {
375
401
  private config;
376
402
  private query;
@@ -445,7 +471,7 @@ declare class FilterGroups {
445
471
  offset(offset: number): FilterGroups;
446
472
  name(nameContains: string): FilterGroups;
447
473
  limit(limit: number): FilterGroups;
448
- then(onfulfilled?: ((value: GroupResponseItem[]) => any) | null): Promise<any>;
474
+ then(onfulfilled?: ((value: GroupResponseItem[]) => any) | null): Promise<GroupResponseItem[]>;
449
475
  private rateLimit;
450
476
  [Symbol.asyncIterator](): AsyncGenerator<GroupResponseItem, void, unknown>;
451
477
  all(): Promise<GroupResponseItem[]>;
@@ -490,4 +516,4 @@ declare class TimeIntervalGatewayAnalyticsBuilder extends GatewayAnalyticsBuilde
490
516
  all(): Promise<TimeIntervalGatewayAnalyticsResponse>;
491
517
  }
492
518
 
493
- export { type AuthTestResponse, type ContentType, type DataEndponts, type Endpoints, type FileObject, type GatewayAnalyticsQuery, type GetCIDResponse, type GetGroupOptions, type GroupCIDOptions, type GroupOptions, type GroupQueryOptions, type GroupResponseItem, type JsonBody, type KeyListItem, type KeyListQuery, type KeyListResponse, type KeyOptions, type KeyPermissions, type KeyResponse, type PinByCIDResponse, type PinJobItem, type PinJobQuery, type PinJobResponse, type PinListItem, type PinListQuery, type PinListResponse, type PinResponse, type PinataConfig, type PinataMetadata, type PinataMetadataUpdate, PinataSDK, type PinningEndpoints, type RevokeKeyResponse, type SignatureOptions, type SignatureResponse, type SwapCidOptions, type SwapCidResponse, type SwapHistoryOptions, type TimeIntervalGatewayAnalyticsQuery, type TimeIntervalGatewayAnalyticsResponse, type TimePeriodItem, type TopGatewayAnalyticsItem, type TopGatewayAnalyticsQuery, type UnpinResponse, type UpdateGroupOptions, type UploadCIDOptions, type UploadOptions, type UserPinnedDataResponse };
519
+ export { type AuthTestResponse, type ContainsCIDResponse, type ContentType, type DataEndponts, type Endpoints, type FileObject, type GatewayAnalyticsQuery, type GetCIDResponse, type GetGroupOptions, type GroupCIDOptions, type GroupOptions, type GroupQueryOptions, type GroupResponseItem, type JsonBody, type KeyListItem, type KeyListQuery, type KeyListResponse, type KeyOptions, type KeyPermissions, type KeyResponse, type OptimizeImageOptions, type PinByCIDResponse, type PinJobItem, type PinJobQuery, type PinJobResponse, type PinListItem, type PinListQuery, type PinListResponse, type PinResponse, type PinataConfig, type PinataMetadata, type PinataMetadataUpdate, PinataSDK, type PinningEndpoints, type RevokeKeyResponse, type SignatureOptions, type SignatureResponse, type SwapCidOptions, type SwapCidResponse, type SwapHistoryOptions, type TimeIntervalGatewayAnalyticsQuery, type TimeIntervalGatewayAnalyticsResponse, type TimePeriodItem, type TopGatewayAnalyticsItem, type TopGatewayAnalyticsQuery, type UnpinResponse, type UpdateGroupOptions, type UploadCIDOptions, type UploadOptions, type UserPinnedDataResponse };
package/dist/index.d.ts CHANGED
@@ -124,6 +124,19 @@ type GetCIDResponse = {
124
124
  data?: JSON | string | Blob | null;
125
125
  contentType: ContentType;
126
126
  };
127
+ type OptimizeImageOptions = {
128
+ width?: number;
129
+ height?: number;
130
+ dpr?: number;
131
+ fit?: "scaleDown" | "contain" | "cover" | "crop" | "pad";
132
+ gravity?: "auto" | "side" | string;
133
+ quality?: number;
134
+ format?: "auto" | "webp";
135
+ animation?: boolean;
136
+ sharpen?: number;
137
+ onError?: boolean;
138
+ metadata?: "keep" | "copyright" | "none";
139
+ };
127
140
  type GatewayAnalyticsQuery = {
128
141
  gateway_domain: string;
129
142
  start_date: string;
@@ -280,6 +293,10 @@ type SwapCidResponse = {
280
293
  mappedCid: string;
281
294
  createdAt: string;
282
295
  };
296
+ type ContainsCIDResponse = {
297
+ containsCid: boolean;
298
+ cid: string | null;
299
+ };
283
300
 
284
301
  declare class PinataSDK {
285
302
  config: PinataConfig | undefined;
@@ -352,8 +369,9 @@ declare class Gateways {
352
369
  config: PinataConfig | undefined;
353
370
  constructor(config?: PinataConfig);
354
371
  updateConfig(newConfig: PinataConfig): void;
355
- get(cid: string): Promise<GetCIDResponse>;
356
- convert(url: string): Promise<string>;
372
+ get(cid: string): OptimizeImage;
373
+ convert(url: string, gatewayPrefix?: string): Promise<string>;
374
+ containsCID(cid: string): Promise<ContainsCIDResponse>;
357
375
  topUsageAnalytics(options: {
358
376
  domain: string;
359
377
  start: string;
@@ -371,6 +389,14 @@ declare class Gateways {
371
389
  swapHistory(options: SwapHistoryOptions): Promise<SwapCidResponse[]>;
372
390
  deleteSwap(cid: string): Promise<string>;
373
391
  }
392
+ declare class OptimizeImage {
393
+ private config;
394
+ private cid;
395
+ private options;
396
+ constructor(config: PinataConfig | undefined, cid: string);
397
+ optimizeImage(options: OptimizeImageOptions): OptimizeImage;
398
+ then(onfulfilled?: ((value: GetCIDResponse) => any) | null): Promise<any>;
399
+ }
374
400
  declare class FilterPinJobs {
375
401
  private config;
376
402
  private query;
@@ -445,7 +471,7 @@ declare class FilterGroups {
445
471
  offset(offset: number): FilterGroups;
446
472
  name(nameContains: string): FilterGroups;
447
473
  limit(limit: number): FilterGroups;
448
- then(onfulfilled?: ((value: GroupResponseItem[]) => any) | null): Promise<any>;
474
+ then(onfulfilled?: ((value: GroupResponseItem[]) => any) | null): Promise<GroupResponseItem[]>;
449
475
  private rateLimit;
450
476
  [Symbol.asyncIterator](): AsyncGenerator<GroupResponseItem, void, unknown>;
451
477
  all(): Promise<GroupResponseItem[]>;
@@ -490,4 +516,4 @@ declare class TimeIntervalGatewayAnalyticsBuilder extends GatewayAnalyticsBuilde
490
516
  all(): Promise<TimeIntervalGatewayAnalyticsResponse>;
491
517
  }
492
518
 
493
- export { type AuthTestResponse, type ContentType, type DataEndponts, type Endpoints, type FileObject, type GatewayAnalyticsQuery, type GetCIDResponse, type GetGroupOptions, type GroupCIDOptions, type GroupOptions, type GroupQueryOptions, type GroupResponseItem, type JsonBody, type KeyListItem, type KeyListQuery, type KeyListResponse, type KeyOptions, type KeyPermissions, type KeyResponse, type PinByCIDResponse, type PinJobItem, type PinJobQuery, type PinJobResponse, type PinListItem, type PinListQuery, type PinListResponse, type PinResponse, type PinataConfig, type PinataMetadata, type PinataMetadataUpdate, PinataSDK, type PinningEndpoints, type RevokeKeyResponse, type SignatureOptions, type SignatureResponse, type SwapCidOptions, type SwapCidResponse, type SwapHistoryOptions, type TimeIntervalGatewayAnalyticsQuery, type TimeIntervalGatewayAnalyticsResponse, type TimePeriodItem, type TopGatewayAnalyticsItem, type TopGatewayAnalyticsQuery, type UnpinResponse, type UpdateGroupOptions, type UploadCIDOptions, type UploadOptions, type UserPinnedDataResponse };
519
+ export { type AuthTestResponse, type ContainsCIDResponse, type ContentType, type DataEndponts, type Endpoints, type FileObject, type GatewayAnalyticsQuery, type GetCIDResponse, type GetGroupOptions, type GroupCIDOptions, type GroupOptions, type GroupQueryOptions, type GroupResponseItem, type JsonBody, type KeyListItem, type KeyListQuery, type KeyListResponse, type KeyOptions, type KeyPermissions, type KeyResponse, type OptimizeImageOptions, type PinByCIDResponse, type PinJobItem, type PinJobQuery, type PinJobResponse, type PinListItem, type PinListQuery, type PinListResponse, type PinResponse, type PinataConfig, type PinataMetadata, type PinataMetadataUpdate, PinataSDK, type PinningEndpoints, type RevokeKeyResponse, type SignatureOptions, type SignatureResponse, type SwapCidOptions, type SwapCidResponse, type SwapHistoryOptions, type TimeIntervalGatewayAnalyticsQuery, type TimeIntervalGatewayAnalyticsResponse, type TimePeriodItem, type TopGatewayAnalyticsItem, type TopGatewayAnalyticsQuery, type UnpinResponse, type UpdateGroupOptions, type UploadCIDOptions, type UploadOptions, type UserPinnedDataResponse };
package/dist/index.js CHANGED
@@ -865,15 +865,44 @@ async function convertToDesiredGateway(sourceUrl, desiredGatewayPrefix) {
865
865
  }
866
866
 
867
867
  // src/core/gateway/getCid.ts
868
- var getCid = async (config, cid) => {
868
+ var getCid = async (config, cid, options) => {
869
869
  if (!config) {
870
870
  throw new ValidationError("Pinata configuration is missing");
871
871
  }
872
872
  let data;
873
873
  let newUrl;
874
874
  newUrl = await convertToDesiredGateway(cid, config?.pinataGateway);
875
+ const params = new URLSearchParams();
875
876
  if (config?.pinataGatewayKey) {
876
- newUrl = `${newUrl}?pinataGatewayToken=${config?.pinataGatewayKey}`;
877
+ params.append("pinataGatewayToken", config.pinataGatewayKey);
878
+ }
879
+ if (options) {
880
+ if (options.width)
881
+ params.append("img-width", options.width.toString());
882
+ if (options.height)
883
+ params.append("img-height", options.height.toString());
884
+ if (options.dpr)
885
+ params.append("img-dpr", options.dpr.toString());
886
+ if (options.fit)
887
+ params.append("img-fit", options.fit);
888
+ if (options.gravity)
889
+ params.append("img-gravity", options.gravity);
890
+ if (options.quality)
891
+ params.append("img-quality", options.quality.toString());
892
+ if (options.format)
893
+ params.append("img-format", options.format);
894
+ if (options.animation !== void 0)
895
+ params.append("img-anim", options.animation.toString());
896
+ if (options.sharpen)
897
+ params.append("img-sharpen", options.sharpen.toString());
898
+ if (options.onError === true)
899
+ params.append("img-onerror", "redirect");
900
+ if (options.metadata)
901
+ params.append("img-metadata", options.metadata);
902
+ }
903
+ const queryString = params.toString();
904
+ if (queryString) {
905
+ newUrl += `?${queryString}`;
877
906
  }
878
907
  try {
879
908
  const request = await fetch(newUrl);
@@ -919,9 +948,10 @@ var getCid = async (config, cid) => {
919
948
  };
920
949
 
921
950
  // src/core/gateway/convertIPFSUrl.ts
922
- var convertIPFSUrl = async (config, url) => {
951
+ var convertIPFSUrl = async (config, url, gatewayPrefix) => {
923
952
  let newUrl;
924
- newUrl = await convertToDesiredGateway(url, config?.pinataGateway);
953
+ let prefix = gatewayPrefix || config?.pinataGateway || "https://gateway.pinata.cloud";
954
+ newUrl = await convertToDesiredGateway(url, prefix);
925
955
  if (config?.pinataGatewayKey) {
926
956
  `${newUrl}?pinataGatewayToken=${config?.pinataGatewayKey}`;
927
957
  }
@@ -2507,10 +2537,13 @@ var Gateways = class {
2507
2537
  this.config = newConfig;
2508
2538
  }
2509
2539
  get(cid) {
2510
- return getCid(this.config, cid);
2540
+ return new OptimizeImage(this.config, cid);
2511
2541
  }
2512
- convert(url) {
2513
- return convertIPFSUrl(this.config, url);
2542
+ convert(url, gatewayPrefix) {
2543
+ return convertIPFSUrl(this.config, url, gatewayPrefix);
2544
+ }
2545
+ containsCID(cid) {
2546
+ return containsCID(cid);
2514
2547
  }
2515
2548
  topUsageAnalytics(options) {
2516
2549
  return new TopGatewayAnalyticsBuilder(
@@ -2541,6 +2574,20 @@ var Gateways = class {
2541
2574
  return deleteSwap(this.config, cid);
2542
2575
  }
2543
2576
  };
2577
+ var OptimizeImage = class {
2578
+ constructor(config, cid) {
2579
+ this.options = {};
2580
+ this.config = config;
2581
+ this.cid = cid;
2582
+ }
2583
+ optimizeImage(options) {
2584
+ this.options = { ...this.options, ...options };
2585
+ return this;
2586
+ }
2587
+ then(onfulfilled) {
2588
+ return getCid(this.config, this.cid, this.options).then(onfulfilled);
2589
+ }
2590
+ };
2544
2591
  var FilterPinJobs = class {
2545
2592
  constructor(config) {
2546
2593
  this.query = {};