pinata 1.0.6 → 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.d.mts CHANGED
@@ -59,9 +59,14 @@ type FileListResponse = {
59
59
  next_page_token: string;
60
60
  };
61
61
  type FileListQuery = {
62
+ name?: string;
63
+ group?: string;
64
+ mimeType?: string;
65
+ cid?: string;
66
+ cidPending?: boolean;
67
+ order?: "ASC" | "DESC";
62
68
  limit?: number;
63
69
  pageToken?: string;
64
- cidPending?: boolean;
65
70
  };
66
71
  type PinJobQuery = {
67
72
  sort?: "ASC" | "DSC";
@@ -245,7 +250,7 @@ type GroupResponseItem = {
245
250
  createdAt: string;
246
251
  };
247
252
  type GroupQueryOptions = {
248
- nameContains?: string;
253
+ name?: string;
249
254
  limit?: number;
250
255
  pageToken?: string;
251
256
  isPublic?: boolean;
@@ -325,9 +330,15 @@ declare class FilterFiles {
325
330
  private query;
326
331
  private currentPageToken;
327
332
  constructor(config: PinataConfig | undefined);
333
+ name(name: string): FilterFiles;
334
+ group(group: string): FilterFiles;
335
+ cid(cid: string): FilterFiles;
336
+ mimeType(mimeType: string): FilterFiles;
337
+ order(order: "ASC" | "DESC"): FilterFiles;
328
338
  limit(limit: number): FilterFiles;
329
339
  cidPending(cidPending: boolean): FilterFiles;
330
- then(onfulfilled?: ((value: FileListItem[]) => any) | null): Promise<any>;
340
+ pageToken(pageToken: string): FilterFiles;
341
+ then(onfulfilled?: ((value: FileListResponse) => any) | null): Promise<any>;
331
342
  private fetchPage;
332
343
  [Symbol.asyncIterator](): AsyncGenerator<FileListItem, void, unknown>;
333
344
  all(): Promise<FileListItem[]>;
@@ -336,8 +347,24 @@ declare class Gateways {
336
347
  config: PinataConfig | undefined;
337
348
  constructor(config?: PinataConfig);
338
349
  updateConfig(newConfig: PinataConfig): void;
339
- get(cid: string): Promise<GetCIDResponse>;
340
- createSignedURL(options: SignedUrlOptions): Promise<string>;
350
+ get(cid: string): OptimizeImageGetCid;
351
+ createSignedURL(options: SignedUrlOptions): OptimizeImageCreateSignedURL;
352
+ }
353
+ declare class OptimizeImageGetCid {
354
+ private config;
355
+ private cid;
356
+ private options;
357
+ constructor(config: PinataConfig | undefined, cid: string);
358
+ optimizeImage(options: OptimizeImageOptions): OptimizeImageGetCid;
359
+ then(onfulfilled?: ((value: GetCIDResponse) => any) | null): Promise<any>;
360
+ }
361
+ declare class OptimizeImageCreateSignedURL {
362
+ private config;
363
+ private urlOpts;
364
+ private imgOpts;
365
+ constructor(config: PinataConfig | undefined, urlOpts: SignedUrlOptions);
366
+ optimizeImage(options: OptimizeImageOptions): OptimizeImageCreateSignedURL;
367
+ then(onfulfilled?: ((value: string) => any) | null): Promise<any>;
341
368
  }
342
369
  declare class Keys {
343
370
  config: PinataConfig | undefined;
@@ -375,9 +402,11 @@ declare class FilterGroups {
375
402
  private query;
376
403
  private nextPageToken;
377
404
  constructor(config: PinataConfig | undefined);
405
+ name(name: string): FilterGroups;
378
406
  limit(limit: number): FilterGroups;
379
407
  isPublic(isPublic: boolean): FilterGroups;
380
- then(onfulfilled?: ((value: GroupResponseItem[]) => any) | null): Promise<GroupResponseItem[]>;
408
+ pageToken(pageToken: string): FilterGroups;
409
+ then(onfulfilled?: ((value: GroupListResponse) => any) | null): Promise<GroupListResponse>;
381
410
  private fetchPage;
382
411
  [Symbol.asyncIterator](): AsyncGenerator<GroupResponseItem, void, unknown>;
383
412
  all(): Promise<GroupResponseItem[]>;
package/dist/index.d.ts CHANGED
@@ -59,9 +59,14 @@ type FileListResponse = {
59
59
  next_page_token: string;
60
60
  };
61
61
  type FileListQuery = {
62
+ name?: string;
63
+ group?: string;
64
+ mimeType?: string;
65
+ cid?: string;
66
+ cidPending?: boolean;
67
+ order?: "ASC" | "DESC";
62
68
  limit?: number;
63
69
  pageToken?: string;
64
- cidPending?: boolean;
65
70
  };
66
71
  type PinJobQuery = {
67
72
  sort?: "ASC" | "DSC";
@@ -245,7 +250,7 @@ type GroupResponseItem = {
245
250
  createdAt: string;
246
251
  };
247
252
  type GroupQueryOptions = {
248
- nameContains?: string;
253
+ name?: string;
249
254
  limit?: number;
250
255
  pageToken?: string;
251
256
  isPublic?: boolean;
@@ -325,9 +330,15 @@ declare class FilterFiles {
325
330
  private query;
326
331
  private currentPageToken;
327
332
  constructor(config: PinataConfig | undefined);
333
+ name(name: string): FilterFiles;
334
+ group(group: string): FilterFiles;
335
+ cid(cid: string): FilterFiles;
336
+ mimeType(mimeType: string): FilterFiles;
337
+ order(order: "ASC" | "DESC"): FilterFiles;
328
338
  limit(limit: number): FilterFiles;
329
339
  cidPending(cidPending: boolean): FilterFiles;
330
- then(onfulfilled?: ((value: FileListItem[]) => any) | null): Promise<any>;
340
+ pageToken(pageToken: string): FilterFiles;
341
+ then(onfulfilled?: ((value: FileListResponse) => any) | null): Promise<any>;
331
342
  private fetchPage;
332
343
  [Symbol.asyncIterator](): AsyncGenerator<FileListItem, void, unknown>;
333
344
  all(): Promise<FileListItem[]>;
@@ -336,8 +347,24 @@ declare class Gateways {
336
347
  config: PinataConfig | undefined;
337
348
  constructor(config?: PinataConfig);
338
349
  updateConfig(newConfig: PinataConfig): void;
339
- get(cid: string): Promise<GetCIDResponse>;
340
- createSignedURL(options: SignedUrlOptions): Promise<string>;
350
+ get(cid: string): OptimizeImageGetCid;
351
+ createSignedURL(options: SignedUrlOptions): OptimizeImageCreateSignedURL;
352
+ }
353
+ declare class OptimizeImageGetCid {
354
+ private config;
355
+ private cid;
356
+ private options;
357
+ constructor(config: PinataConfig | undefined, cid: string);
358
+ optimizeImage(options: OptimizeImageOptions): OptimizeImageGetCid;
359
+ then(onfulfilled?: ((value: GetCIDResponse) => any) | null): Promise<any>;
360
+ }
361
+ declare class OptimizeImageCreateSignedURL {
362
+ private config;
363
+ private urlOpts;
364
+ private imgOpts;
365
+ constructor(config: PinataConfig | undefined, urlOpts: SignedUrlOptions);
366
+ optimizeImage(options: OptimizeImageOptions): OptimizeImageCreateSignedURL;
367
+ then(onfulfilled?: ((value: string) => any) | null): Promise<any>;
341
368
  }
342
369
  declare class Keys {
343
370
  config: PinataConfig | undefined;
@@ -375,9 +402,11 @@ declare class FilterGroups {
375
402
  private query;
376
403
  private nextPageToken;
377
404
  constructor(config: PinataConfig | undefined);
405
+ name(name: string): FilterGroups;
378
406
  limit(limit: number): FilterGroups;
379
407
  isPublic(isPublic: boolean): FilterGroups;
380
- then(onfulfilled?: ((value: GroupResponseItem[]) => any) | null): Promise<GroupResponseItem[]>;
408
+ pageToken(pageToken: string): FilterGroups;
409
+ then(onfulfilled?: ((value: GroupListResponse) => any) | null): Promise<GroupListResponse>;
381
410
  private fetchPage;
382
411
  [Symbol.asyncIterator](): AsyncGenerator<GroupResponseItem, void, unknown>;
383
412
  all(): Promise<GroupResponseItem[]>;
package/dist/index.js CHANGED
@@ -443,9 +443,19 @@ var listFiles = async (config, options) => {
443
443
  }
444
444
  const params = new URLSearchParams();
445
445
  if (options) {
446
- const { limit, pageToken, cidPending } = options;
446
+ const { name, group, cid, order, limit, mimeType, pageToken, cidPending } = options;
447
447
  if (limit)
448
448
  params.append("limit", limit.toString());
449
+ if (name)
450
+ params.append("name", name);
451
+ if (group)
452
+ params.append("group", group);
453
+ if (cid)
454
+ params.append("cid", cid);
455
+ if (mimeType)
456
+ params.append("mimeType", mimeType);
457
+ if (order)
458
+ params.append("order", order);
449
459
  if (pageToken)
450
460
  params.append("pageToken", pageToken);
451
461
  if (cidPending)
@@ -557,13 +567,41 @@ var updateFile = async (config, options) => {
557
567
  };
558
568
 
559
569
  // src/core/gateway/getCid.ts
560
- var getCid = async (config, cid) => {
570
+ var getCid = async (config, cid, options) => {
561
571
  if (!config) {
562
572
  throw new ValidationError("Pinata configuration is missing");
563
573
  }
564
574
  let data;
565
575
  let newUrl = `${config?.pinataGateway}/files/${cid}`;
566
576
  const params = new URLSearchParams();
577
+ if (options) {
578
+ if (options.width)
579
+ params.append("img-width", options.width.toString());
580
+ if (options.height)
581
+ params.append("img-height", options.height.toString());
582
+ if (options.dpr)
583
+ params.append("img-dpr", options.dpr.toString());
584
+ if (options.fit)
585
+ params.append("img-fit", options.fit);
586
+ if (options.gravity)
587
+ params.append("img-gravity", options.gravity);
588
+ if (options.quality)
589
+ params.append("img-quality", options.quality.toString());
590
+ if (options.format)
591
+ params.append("img-format", options.format);
592
+ if (options.animation !== void 0)
593
+ params.append("img-anim", options.animation.toString());
594
+ if (options.sharpen)
595
+ params.append("img-sharpen", options.sharpen.toString());
596
+ if (options.onError === true)
597
+ params.append("img-onerror", "redirect");
598
+ if (options.metadata)
599
+ params.append("img-metadata", options.metadata);
600
+ }
601
+ const queryString = params.toString();
602
+ if (queryString) {
603
+ newUrl += `?${queryString}`;
604
+ }
567
605
  const date = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3);
568
606
  const payload = JSON.stringify({
569
607
  url: newUrl,
@@ -571,17 +609,18 @@ var getCid = async (config, cid) => {
571
609
  expires: 30,
572
610
  method: "GET"
573
611
  });
574
- const signedUrlRequest = await fetch(
575
- "https://api.pinata.cloud/v3/files/sign",
576
- {
577
- method: "POST",
578
- headers: {
579
- "Content-Type": "application/json",
580
- Authorization: `Bearer ${config?.pinataJwt}`
581
- },
582
- body: payload
583
- }
584
- );
612
+ let endpoint = "https://api.pinata.cloud/v3";
613
+ if (config.endpointUrl) {
614
+ endpoint = config.endpointUrl;
615
+ }
616
+ const signedUrlRequest = await fetch(`${endpoint}/files/sign`, {
617
+ method: "POST",
618
+ headers: {
619
+ "Content-Type": "application/json",
620
+ Authorization: `Bearer ${config?.pinataJwt}`
621
+ },
622
+ body: payload
623
+ });
585
624
  const signedUrl = await signedUrlRequest.json();
586
625
  try {
587
626
  const request = await fetch(signedUrl.data);
@@ -894,13 +933,13 @@ var listGroups = async (config, options) => {
894
933
  }
895
934
  const params = new URLSearchParams();
896
935
  if (options) {
897
- const { pageToken, nameContains, limit, isPublic } = options;
936
+ const { pageToken, name, limit, isPublic } = options;
898
937
  if (pageToken)
899
938
  params.append("pageToken", pageToken.toString());
900
939
  if (isPublic)
901
940
  params.append("isPublic", isPublic.toString());
902
- if (nameContains !== void 0)
903
- params.append("nameContains", nameContains.toString());
941
+ if (name)
942
+ params.append("name", name);
904
943
  if (limit !== void 0)
905
944
  params.append("limit", limit.toString());
906
945
  }
@@ -1111,11 +1150,40 @@ var deleteGroup = async (config, options) => {
1111
1150
  };
1112
1151
 
1113
1152
  // src/core/gateway/createSignedURL.ts
1114
- var createSignedURL = async (config, options) => {
1153
+ var createSignedURL = async (config, options, imgOpts) => {
1115
1154
  if (!config) {
1116
1155
  throw new ValidationError("Pinata configuration is missing");
1117
1156
  }
1118
1157
  let newUrl = `${config?.pinataGateway}/files/${options.cid}`;
1158
+ const params = new URLSearchParams();
1159
+ if (imgOpts) {
1160
+ if (imgOpts.width)
1161
+ params.append("img-width", imgOpts.width.toString());
1162
+ if (imgOpts.height)
1163
+ params.append("img-height", imgOpts.height.toString());
1164
+ if (imgOpts.dpr)
1165
+ params.append("img-dpr", imgOpts.dpr.toString());
1166
+ if (imgOpts.fit)
1167
+ params.append("img-fit", imgOpts.fit);
1168
+ if (imgOpts.gravity)
1169
+ params.append("img-gravity", imgOpts.gravity);
1170
+ if (imgOpts.quality)
1171
+ params.append("img-quality", imgOpts.quality.toString());
1172
+ if (imgOpts.format)
1173
+ params.append("img-format", imgOpts.format);
1174
+ if (imgOpts.animation !== void 0)
1175
+ params.append("img-anim", imgOpts.animation.toString());
1176
+ if (imgOpts.sharpen)
1177
+ params.append("img-sharpen", imgOpts.sharpen.toString());
1178
+ if (imgOpts.onError === true)
1179
+ params.append("img-onerror", "redirect");
1180
+ if (imgOpts.metadata)
1181
+ params.append("img-metadata", imgOpts.metadata);
1182
+ }
1183
+ const queryString = params.toString();
1184
+ if (queryString) {
1185
+ newUrl += `?${queryString}`;
1186
+ }
1119
1187
  const date = options?.date || Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3);
1120
1188
  const payload = JSON.stringify({
1121
1189
  url: newUrl,
@@ -1295,6 +1363,26 @@ var FilterFiles = class {
1295
1363
  this.query = {};
1296
1364
  this.config = config;
1297
1365
  }
1366
+ name(name) {
1367
+ this.query.name = name;
1368
+ return this;
1369
+ }
1370
+ group(group) {
1371
+ this.query.group = group;
1372
+ return this;
1373
+ }
1374
+ cid(cid) {
1375
+ this.query.cid = cid;
1376
+ return this;
1377
+ }
1378
+ mimeType(mimeType) {
1379
+ this.query.mimeType = mimeType;
1380
+ return this;
1381
+ }
1382
+ order(order) {
1383
+ this.query.order = order;
1384
+ return this;
1385
+ }
1298
1386
  limit(limit) {
1299
1387
  this.query.limit = limit;
1300
1388
  return this;
@@ -1303,6 +1391,10 @@ var FilterFiles = class {
1303
1391
  this.query.cidPending = cidPending;
1304
1392
  return this;
1305
1393
  }
1394
+ pageToken(pageToken) {
1395
+ this.query.pageToken = pageToken;
1396
+ return this;
1397
+ }
1306
1398
  then(onfulfilled) {
1307
1399
  return this.fetchPage().then(onfulfilled);
1308
1400
  }
@@ -1312,7 +1404,7 @@ var FilterFiles = class {
1312
1404
  }
1313
1405
  const response = await listFiles(this.config, this.query);
1314
1406
  this.currentPageToken = response.next_page_token;
1315
- return response.files;
1407
+ return response;
1316
1408
  }
1317
1409
  // // rate limit, hopefully temporary?
1318
1410
  // private async rateLimit(): Promise<void> {
@@ -1331,7 +1423,7 @@ var FilterFiles = class {
1331
1423
  async *[Symbol.asyncIterator]() {
1332
1424
  while (true) {
1333
1425
  const items = await this.fetchPage();
1334
- for (const item of items) {
1426
+ for (const item of items.files) {
1335
1427
  yield item;
1336
1428
  }
1337
1429
  if (!this.currentPageToken) {
@@ -1355,10 +1447,10 @@ var Gateways = class {
1355
1447
  this.config = newConfig;
1356
1448
  }
1357
1449
  get(cid) {
1358
- return getCid(this.config, cid);
1450
+ return new OptimizeImageGetCid(this.config, cid);
1359
1451
  }
1360
1452
  createSignedURL(options) {
1361
- return createSignedURL(this.config, options);
1453
+ return new OptimizeImageCreateSignedURL(this.config, options);
1362
1454
  }
1363
1455
  // get(cid: string): OptimizeImage {
1364
1456
  // return new OptimizeImage(this.config, cid);
@@ -1415,6 +1507,36 @@ var Gateways = class {
1415
1507
  // return deleteSwap(this.config, cid);
1416
1508
  // }
1417
1509
  };
1510
+ var OptimizeImageGetCid = class {
1511
+ constructor(config, cid) {
1512
+ this.options = {};
1513
+ this.config = config;
1514
+ this.cid = cid;
1515
+ }
1516
+ optimizeImage(options) {
1517
+ this.options = { ...this.options, ...options };
1518
+ return this;
1519
+ }
1520
+ then(onfulfilled) {
1521
+ return getCid(this.config, this.cid, this.options).then(onfulfilled);
1522
+ }
1523
+ };
1524
+ var OptimizeImageCreateSignedURL = class {
1525
+ constructor(config, urlOpts) {
1526
+ this.imgOpts = {};
1527
+ this.config = config;
1528
+ this.urlOpts = urlOpts;
1529
+ }
1530
+ optimizeImage(options) {
1531
+ this.imgOpts = { ...this.imgOpts, ...options };
1532
+ return this;
1533
+ }
1534
+ then(onfulfilled) {
1535
+ return createSignedURL(this.config, this.urlOpts, this.imgOpts).then(
1536
+ onfulfilled
1537
+ );
1538
+ }
1539
+ };
1418
1540
  var Keys = class {
1419
1541
  constructor(config) {
1420
1542
  this.config = formatConfig(config);
@@ -1536,10 +1658,10 @@ var FilterGroups = class {
1536
1658
  this.query = {};
1537
1659
  this.config = config;
1538
1660
  }
1539
- // name(nameContains: string): FilterGroups {
1540
- // this.query.nameContains = nameContains;
1541
- // return this;
1542
- // }
1661
+ name(name) {
1662
+ this.query.name = name;
1663
+ return this;
1664
+ }
1543
1665
  limit(limit) {
1544
1666
  this.query.limit = limit;
1545
1667
  return this;
@@ -1548,10 +1670,14 @@ var FilterGroups = class {
1548
1670
  this.query.isPublic = isPublic;
1549
1671
  return this;
1550
1672
  }
1673
+ pageToken(pageToken) {
1674
+ this.query.pageToken = pageToken;
1675
+ return this;
1676
+ }
1551
1677
  then(onfulfilled) {
1552
1678
  return this.fetchPage().then((response) => {
1553
1679
  this.nextPageToken = response.next_page_token;
1554
- return response.groups;
1680
+ return response;
1555
1681
  }).then(onfulfilled);
1556
1682
  }
1557
1683
  async fetchPage() {