pinata 0.3.3 → 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.js CHANGED
@@ -86,16 +86,16 @@ var testAuthentication = async (config) => {
86
86
  headers
87
87
  });
88
88
  if (!request.ok) {
89
- const errorData = await request.json();
90
- if (request.status === 401) {
89
+ const errorData = await request.text();
90
+ if (request.status === 401 || request.status === 403) {
91
91
  throw new AuthenticationError(
92
- "Authentication failed",
92
+ `Authentication failed: ${errorData}`,
93
93
  request.status,
94
94
  errorData
95
95
  );
96
96
  }
97
97
  throw new NetworkError(
98
- `HTTP error! status: ${request.status}`,
98
+ `HTTP error: ${errorData}`,
99
99
  request.status,
100
100
  errorData
101
101
  );
@@ -159,16 +159,16 @@ var uploadFile = async (config, file, options) => {
159
159
  body: data
160
160
  });
161
161
  if (!request.ok) {
162
- const errorData = await request.json();
163
- if (request.status === 401) {
162
+ const errorData = await request.text();
163
+ if (request.status === 401 || request.status === 403) {
164
164
  throw new AuthenticationError(
165
- "Authentication failed",
165
+ `Authentication failed: ${errorData}`,
166
166
  request.status,
167
167
  errorData
168
168
  );
169
169
  }
170
170
  throw new NetworkError(
171
- `HTTP error! status: ${request.status}`,
171
+ `HTTP error: ${errorData}`,
172
172
  request.status,
173
173
  errorData
174
174
  );
@@ -231,16 +231,16 @@ var uploadFileArray = async (config, files, options) => {
231
231
  body: data
232
232
  });
233
233
  if (!request.ok) {
234
- const errorData = await request.json();
235
- if (request.status === 401) {
234
+ const errorData = await request.text();
235
+ if (request.status === 401 || request.status === 403) {
236
236
  throw new AuthenticationError(
237
- "Authentication failed",
237
+ `Authentication failed: ${errorData}`,
238
238
  request.status,
239
239
  errorData
240
240
  );
241
241
  }
242
242
  throw new NetworkError(
243
- `HTTP error! status: ${request.status}`,
243
+ `HTTP error: ${errorData}`,
244
244
  request.status,
245
245
  errorData
246
246
  );
@@ -305,16 +305,16 @@ var uploadBase64 = async (config, base64String, options) => {
305
305
  body: data
306
306
  });
307
307
  if (!request.ok) {
308
- const errorData = await request.json();
309
- if (request.status === 401) {
308
+ const errorData = await request.text();
309
+ if (request.status === 401 || request.status === 403) {
310
310
  throw new AuthenticationError(
311
- "Authentication failed",
311
+ `Authentication failed: ${errorData}`,
312
312
  request.status,
313
313
  errorData
314
314
  );
315
315
  }
316
316
  throw new NetworkError(
317
- `HTTP error! status: ${request.status}`,
317
+ `HTTP error: ${errorData}`,
318
318
  request.status,
319
319
  errorData
320
320
  );
@@ -343,9 +343,9 @@ var uploadUrl = async (config, url, options) => {
343
343
  const data = new FormData();
344
344
  const stream = await fetch(url);
345
345
  if (!stream.ok) {
346
- const errorData = await stream.json();
346
+ const errorData = await stream.text();
347
347
  throw new NetworkError(
348
- `HTTP error! status: ${stream.status}`,
348
+ `HTTP error: ${errorData}`,
349
349
  stream.status,
350
350
  errorData
351
351
  );
@@ -389,16 +389,16 @@ var uploadUrl = async (config, url, options) => {
389
389
  body: data
390
390
  });
391
391
  if (!request.ok) {
392
- const errorData = await request.json();
393
- if (request.status === 401) {
392
+ const errorData = await request.text();
393
+ if (request.status === 401 || request.status === 403) {
394
394
  throw new AuthenticationError(
395
- "Authentication failed",
395
+ `Authentication failed: ${errorData}`,
396
396
  request.status,
397
397
  errorData
398
398
  );
399
399
  }
400
400
  throw new NetworkError(
401
- `HTTP error! status: ${request.status}`,
401
+ `HTTP error: ${errorData}`,
402
402
  request.status,
403
403
  errorData
404
404
  );
@@ -454,16 +454,16 @@ var uploadJson = async (config, jsonData, options) => {
454
454
  body: data
455
455
  });
456
456
  if (!request.ok) {
457
- const errorData = await request.json();
458
- if (request.status === 401) {
457
+ const errorData = await request.text();
458
+ if (request.status === 401 || request.status === 403) {
459
459
  throw new AuthenticationError(
460
- "Authentication failed",
460
+ `Authentication failed: ${errorData}`,
461
461
  request.status,
462
462
  errorData
463
463
  );
464
464
  }
465
465
  throw new NetworkError(
466
- `HTTP error! status: ${request.status}`,
466
+ `HTTP error: ${errorData}`,
467
467
  request.status,
468
468
  errorData
469
469
  );
@@ -519,16 +519,16 @@ var uploadCid = async (config, cid, options) => {
519
519
  body: data
520
520
  });
521
521
  if (!request.ok) {
522
- const errorData = await request.json();
523
- if (request.status === 401) {
522
+ const errorData = await request.text();
523
+ if (request.status === 401 || request.status === 403) {
524
524
  throw new AuthenticationError(
525
- "Authentication failed",
525
+ `Authentication failed: ${errorData}`,
526
526
  request.status,
527
527
  errorData
528
528
  );
529
529
  }
530
530
  throw new NetworkError(
531
- `HTTP error! status: ${request.status}`,
531
+ `HTTP error: ${errorData}`,
532
532
  request.status,
533
533
  errorData
534
534
  );
@@ -578,16 +578,16 @@ var unpinFile = async (config, files) => {
578
578
  });
579
579
  await wait(300);
580
580
  if (!response.ok) {
581
- const errorData = await response.json();
581
+ const errorData = await response.text();
582
582
  if (response.status === 401) {
583
583
  throw new AuthenticationError(
584
- "Authentication failed",
584
+ `Authentication failed: ${errorData}`,
585
585
  response.status,
586
586
  errorData
587
587
  );
588
588
  }
589
589
  throw new NetworkError(
590
- `HTTP error! status: ${response.status}`,
590
+ `HTTP error: ${errorData}`,
591
591
  response.status,
592
592
  errorData
593
593
  );
@@ -683,16 +683,16 @@ var listFiles = async (config, options) => {
683
683
  headers
684
684
  });
685
685
  if (!request.ok) {
686
- const errorData = await request.json();
687
- if (request.status === 401) {
686
+ const errorData = await request.text();
687
+ if (request.status === 401 || request.status === 403) {
688
688
  throw new AuthenticationError(
689
- "Authentication failed",
689
+ `Authentication failed: ${errorData}`,
690
690
  request.status,
691
691
  errorData
692
692
  );
693
693
  }
694
694
  throw new NetworkError(
695
- `HTTP error! status: ${request.status}`,
695
+ `HTTP error: ${errorData}`,
696
696
  request.status,
697
697
  errorData
698
698
  );
@@ -741,16 +741,16 @@ var updateMetadata = async (config, options) => {
741
741
  body: JSON.stringify(data)
742
742
  });
743
743
  if (!request.ok) {
744
- const errorData = await request.json();
745
- if (request.status === 401) {
744
+ const errorData = await request.text();
745
+ if (request.status === 401 || request.status === 403) {
746
746
  throw new AuthenticationError(
747
- "Authentication failed",
747
+ `Authentication failed: ${errorData}`,
748
748
  request.status,
749
749
  errorData
750
750
  );
751
751
  }
752
752
  throw new NetworkError(
753
- `HTTP error! status: ${request.status}`,
753
+ `HTTP error: ${errorData}`,
754
754
  request.status,
755
755
  errorData
756
756
  );
@@ -865,29 +865,58 @@ 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);
880
909
  if (!request.ok) {
881
- const errorData = await request.json();
882
- if (request.status === 401) {
910
+ const errorData = await request.text();
911
+ if (request.status === 401 || request.status === 403) {
883
912
  throw new AuthenticationError(
884
- "Authentication failed",
913
+ `Authentication Failed: ${errorData}`,
885
914
  request.status,
886
915
  errorData
887
916
  );
888
917
  }
889
918
  throw new NetworkError(
890
- `HTTP error! status: ${request.status}`,
919
+ `HTTP error: ${errorData}`,
891
920
  request.status,
892
921
  errorData
893
922
  );
@@ -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
  }
@@ -969,16 +999,16 @@ var pinJobs = async (config, options) => {
969
999
  headers
970
1000
  });
971
1001
  if (!request.ok) {
972
- const errorData = await request.json();
973
- if (request.status === 401) {
1002
+ const errorData = await request.text();
1003
+ if (request.status === 401 || request.status === 403) {
974
1004
  throw new AuthenticationError(
975
- "Authentication failed",
1005
+ `Authentication failed: ${errorData}`,
976
1006
  request.status,
977
1007
  errorData
978
1008
  );
979
1009
  }
980
1010
  throw new NetworkError(
981
- `HTTP error! status: ${request.status}`,
1011
+ `HTTP error: ${errorData}`,
982
1012
  request.status,
983
1013
  errorData
984
1014
  );
@@ -1020,16 +1050,16 @@ var pinnedFileCount = async (config) => {
1020
1050
  headers
1021
1051
  });
1022
1052
  if (!request.ok) {
1023
- const errorData = await request.json();
1024
- if (request.status === 401) {
1053
+ const errorData = await request.text();
1054
+ if (request.status === 401 || request.status === 403) {
1025
1055
  throw new AuthenticationError(
1026
- "Authentication failed",
1056
+ `Authentication failed: ${errorData}`,
1027
1057
  request.status,
1028
1058
  errorData
1029
1059
  );
1030
1060
  }
1031
1061
  throw new NetworkError(
1032
- `HTTP error! status: ${request.status}`,
1062
+ `HTTP error: ${errorData}`,
1033
1063
  request.status,
1034
1064
  errorData
1035
1065
  );
@@ -1075,16 +1105,16 @@ var totalStorageUsage = async (config) => {
1075
1105
  headers
1076
1106
  });
1077
1107
  if (!request.ok) {
1078
- const errorData = await request.json();
1079
- if (request.status === 401) {
1108
+ const errorData = await request.text();
1109
+ if (request.status === 401 || request.status === 403) {
1080
1110
  throw new AuthenticationError(
1081
- "Authentication failed",
1111
+ `Authentication failed: ${errorData}`,
1082
1112
  request.status,
1083
1113
  errorData
1084
1114
  );
1085
1115
  }
1086
1116
  throw new NetworkError(
1087
- `HTTP error! status: ${request.status}`,
1117
+ `HTTP error: ${errorData}`,
1088
1118
  request.status,
1089
1119
  errorData
1090
1120
  );
@@ -1133,16 +1163,16 @@ var createKey = async (config, options) => {
1133
1163
  body: data
1134
1164
  });
1135
1165
  if (!request.ok) {
1136
- const errorData = await request.json();
1137
- if (request.status === 401) {
1166
+ const errorData = await request.text();
1167
+ if (request.status === 401 || request.status === 403) {
1138
1168
  throw new AuthenticationError(
1139
- "Authentication failed",
1169
+ `Authentication failed: ${errorData}`,
1140
1170
  request.status,
1141
1171
  errorData
1142
1172
  );
1143
1173
  }
1144
1174
  throw new NetworkError(
1145
- `HTTP error! status: ${request.status}`,
1175
+ `HTTP error: ${errorData}`,
1146
1176
  request.status,
1147
1177
  errorData
1148
1178
  );
@@ -1202,16 +1232,16 @@ var listKeys = async (config, options) => {
1202
1232
  }
1203
1233
  );
1204
1234
  if (!request.ok) {
1205
- const errorData = await request.json();
1206
- if (request.status === 401) {
1235
+ const errorData = await request.text();
1236
+ if (request.status === 401 || request.status === 403) {
1207
1237
  throw new AuthenticationError(
1208
- "Authentication failed",
1238
+ `Authentication failed: ${errorData}`,
1209
1239
  request.status,
1210
1240
  errorData
1211
1241
  );
1212
1242
  }
1213
1243
  throw new NetworkError(
1214
- `HTTP error! status: ${request.status}`,
1244
+ `HTTP error: ${errorData}`,
1215
1245
  request.status,
1216
1246
  errorData
1217
1247
  );
@@ -1262,16 +1292,16 @@ var revokeKeys = async (config, keys) => {
1262
1292
  });
1263
1293
  await wait2(300);
1264
1294
  if (!request.ok) {
1265
- const errorData = await request.json();
1266
- if (request.status === 401) {
1295
+ const errorData = await request.text();
1296
+ if (request.status === 401 || request.status === 403) {
1267
1297
  throw new AuthenticationError(
1268
- "Authentication failed",
1298
+ `Authentication failed: ${errorData}`,
1269
1299
  request.status,
1270
1300
  errorData
1271
1301
  );
1272
1302
  }
1273
1303
  throw new NetworkError(
1274
- `HTTP error! status: ${request.status}`,
1304
+ `HTTP error: ${errorData}`,
1275
1305
  request.status,
1276
1306
  errorData
1277
1307
  );
@@ -1326,16 +1356,16 @@ var createGroup = async (config, options) => {
1326
1356
  body: data
1327
1357
  });
1328
1358
  if (!request.ok) {
1329
- const errorData = await request.json();
1330
- if (request.status === 401) {
1359
+ const errorData = await request.text();
1360
+ if (request.status === 401 || request.status === 403) {
1331
1361
  throw new AuthenticationError(
1332
- "Authentication failed",
1362
+ `Authentication failed: ${errorData}`,
1333
1363
  request.status,
1334
1364
  errorData
1335
1365
  );
1336
1366
  }
1337
1367
  throw new NetworkError(
1338
- `HTTP error! status: ${request.status}`,
1368
+ `HTTP error: ${errorData}`,
1339
1369
  request.status,
1340
1370
  errorData
1341
1371
  );
@@ -1388,16 +1418,16 @@ var listGroups = async (config, options) => {
1388
1418
  headers
1389
1419
  });
1390
1420
  if (!request.ok) {
1391
- const errorData = await request.json();
1392
- if (request.status === 401) {
1421
+ const errorData = await request.text();
1422
+ if (request.status === 401 || request.status === 403) {
1393
1423
  throw new AuthenticationError(
1394
- "Authentication failed",
1424
+ `Authentication failed: ${errorData}`,
1395
1425
  request.status,
1396
1426
  errorData
1397
1427
  );
1398
1428
  }
1399
1429
  throw new NetworkError(
1400
- `HTTP error! status: ${request.status}`,
1430
+ `HTTP error: ${errorData}`,
1401
1431
  request.status,
1402
1432
  errorData
1403
1433
  );
@@ -1440,16 +1470,16 @@ var getGroup = async (config, options) => {
1440
1470
  headers
1441
1471
  });
1442
1472
  if (!request.ok) {
1443
- const errorData = await request.json();
1444
- if (request.status === 401) {
1473
+ const errorData = await request.text();
1474
+ if (request.status === 401 || request.status === 403) {
1445
1475
  throw new AuthenticationError(
1446
- "Authentication failed",
1476
+ `Authentication failed: ${errorData}`,
1447
1477
  request.status,
1448
1478
  errorData
1449
1479
  );
1450
1480
  }
1451
1481
  throw new NetworkError(
1452
- `HTTP error! status: ${request.status}`,
1482
+ `HTTP error: ${errorData}`,
1453
1483
  request.status,
1454
1484
  errorData
1455
1485
  );
@@ -1498,16 +1528,16 @@ var addToGroup = async (config, options) => {
1498
1528
  body: data
1499
1529
  });
1500
1530
  if (!request.ok) {
1501
- const errorData = await request.json();
1502
- if (request.status === 401) {
1531
+ const errorData = await request.text();
1532
+ if (request.status === 401 || request.status === 403) {
1503
1533
  throw new AuthenticationError(
1504
- "Authentication failed",
1534
+ `Authentication failed: ${errorData}`,
1505
1535
  request.status,
1506
1536
  errorData
1507
1537
  );
1508
1538
  }
1509
1539
  throw new NetworkError(
1510
- `HTTP error! status: ${request.status}`,
1540
+ `HTTP error: ${errorData}`,
1511
1541
  request.status,
1512
1542
  errorData
1513
1543
  );
@@ -1556,16 +1586,16 @@ var updateGroup = async (config, options) => {
1556
1586
  body: data
1557
1587
  });
1558
1588
  if (!request.ok) {
1559
- const errorData = await request.json();
1560
- if (request.status === 401) {
1589
+ const errorData = await request.text();
1590
+ if (request.status === 401 || request.status === 403) {
1561
1591
  throw new AuthenticationError(
1562
- "Authentication failed",
1592
+ `Authentication failed: ${errorData}`,
1563
1593
  request.status,
1564
1594
  errorData
1565
1595
  );
1566
1596
  }
1567
1597
  throw new NetworkError(
1568
- `HTTP error! status: ${request.status}`,
1598
+ `HTTP error: ${errorData}`,
1569
1599
  request.status,
1570
1600
  errorData
1571
1601
  );
@@ -1612,16 +1642,16 @@ var removeFromGroup = async (config, options) => {
1612
1642
  body: data
1613
1643
  });
1614
1644
  if (!request.ok) {
1615
- const errorData = await request.json();
1616
- if (request.status === 401) {
1645
+ const errorData = await request.text();
1646
+ if (request.status === 401 || request.status === 403) {
1617
1647
  throw new AuthenticationError(
1618
- "Authentication failed",
1648
+ `Authentication failed: ${errorData}`,
1619
1649
  request.status,
1620
1650
  errorData
1621
1651
  );
1622
1652
  }
1623
1653
  throw new NetworkError(
1624
- `HTTP error! status: ${request.status}`,
1654
+ `HTTP error: ${errorData}`,
1625
1655
  request.status,
1626
1656
  errorData
1627
1657
  );
@@ -1668,16 +1698,16 @@ var deleteGroup = async (config, options) => {
1668
1698
  headers
1669
1699
  });
1670
1700
  if (!request.ok) {
1671
- const errorData = await request.json();
1672
- if (request.status === 401) {
1701
+ const errorData = await request.text();
1702
+ if (request.status === 401 || request.status === 403) {
1673
1703
  throw new AuthenticationError(
1674
- "Authentication failed",
1704
+ `Authentication failed: ${errorData}`,
1675
1705
  request.status,
1676
1706
  errorData
1677
1707
  );
1678
1708
  }
1679
1709
  throw new NetworkError(
1680
- `HTTP error! status: ${request.status}`,
1710
+ `HTTP error: ${errorData}`,
1681
1711
  request.status,
1682
1712
  errorData
1683
1713
  );
@@ -1727,10 +1757,10 @@ var addSignature = async (config, options) => {
1727
1757
  }
1728
1758
  );
1729
1759
  if (!request.ok) {
1730
- const errorData = await request.json();
1731
- if (request.status === 401) {
1760
+ const errorData = await request.text();
1761
+ if (request.status === 401 || request.status === 403) {
1732
1762
  throw new AuthenticationError(
1733
- "Authentication failed",
1763
+ `Authentication failed: ${errorData}`,
1734
1764
  request.status,
1735
1765
  errorData
1736
1766
  );
@@ -1743,7 +1773,7 @@ var addSignature = async (config, options) => {
1743
1773
  );
1744
1774
  }
1745
1775
  throw new NetworkError(
1746
- `HTTP error! status: ${request.status}`,
1776
+ `HTTP error: ${errorData}`,
1747
1777
  request.status,
1748
1778
  errorData
1749
1779
  );
@@ -1788,16 +1818,16 @@ var getSignature = async (config, cid) => {
1788
1818
  headers
1789
1819
  });
1790
1820
  if (!request.ok) {
1791
- const errorData = await request.json();
1792
- if (request.status === 401) {
1821
+ const errorData = await request.text();
1822
+ if (request.status === 401 || request.status === 403) {
1793
1823
  throw new AuthenticationError(
1794
- "Authentication failed",
1824
+ `Authentication failed: ${errorData}`,
1795
1825
  request.status,
1796
1826
  errorData
1797
1827
  );
1798
1828
  }
1799
1829
  throw new NetworkError(
1800
- `HTTP error! status: ${request.status}`,
1830
+ `HTTP error: ${errorData}`,
1801
1831
  request.status,
1802
1832
  errorData
1803
1833
  );
@@ -1842,16 +1872,16 @@ var removeSignature = async (config, cid) => {
1842
1872
  headers
1843
1873
  });
1844
1874
  if (!request.ok) {
1845
- const errorData = await request.json();
1846
- if (request.status === 401) {
1875
+ const errorData = await request.text();
1876
+ if (request.status === 401 || request.status === 403) {
1847
1877
  throw new AuthenticationError(
1848
- "Authentication failed",
1878
+ `Authentication failed: ${errorData}`,
1849
1879
  request.status,
1850
1880
  errorData
1851
1881
  );
1852
1882
  }
1853
1883
  throw new NetworkError(
1854
- `HTTP error! status: ${request.status}`,
1884
+ `HTTP error: ${errorData}`,
1855
1885
  request.status,
1856
1886
  errorData
1857
1887
  );
@@ -1941,16 +1971,16 @@ var analyticsTopUsage = async (config, options) => {
1941
1971
  headers
1942
1972
  });
1943
1973
  if (!request.ok) {
1944
- const errorData = await request.json();
1945
- if (request.status === 401) {
1974
+ const errorData = await request.text();
1975
+ if (request.status === 401 || request.status === 403) {
1946
1976
  throw new AuthenticationError(
1947
- "Authentication failed",
1977
+ `Authentication failed: ${errorData}`,
1948
1978
  request.status,
1949
1979
  errorData
1950
1980
  );
1951
1981
  }
1952
1982
  throw new NetworkError(
1953
- `HTTP error! status: ${request.status}`,
1983
+ `HTTP error: ${errorData}`,
1954
1984
  request.status,
1955
1985
  errorData
1956
1986
  );
@@ -2042,16 +2072,16 @@ var analyticsDateInterval = async (config, options) => {
2042
2072
  headers
2043
2073
  });
2044
2074
  if (!request.ok) {
2045
- const errorData = await request.json();
2046
- if (request.status === 401) {
2075
+ const errorData = await request.text();
2076
+ if (request.status === 401 || request.status === 403) {
2047
2077
  throw new AuthenticationError(
2048
- "Authentication failed",
2078
+ `Authentication failed: ${errorData}`,
2049
2079
  request.status,
2050
2080
  errorData
2051
2081
  );
2052
2082
  }
2053
2083
  throw new NetworkError(
2054
- `HTTP error! status: ${request.status}`,
2084
+ `HTTP error: ${errorData}`,
2055
2085
  request.status,
2056
2086
  errorData
2057
2087
  );
@@ -2103,10 +2133,10 @@ var swapCid = async (config, options) => {
2103
2133
  body: data
2104
2134
  });
2105
2135
  if (!request.ok) {
2106
- const errorData = await request.json();
2107
- if (request.status === 401) {
2136
+ const errorData = await request.text();
2137
+ if (request.status === 401 || request.status === 403) {
2108
2138
  throw new AuthenticationError(
2109
- "Authentication failed",
2139
+ `Authentication failed: ${errorData}`,
2110
2140
  request.status,
2111
2141
  errorData
2112
2142
  );
@@ -2126,7 +2156,7 @@ var swapCid = async (config, options) => {
2126
2156
  );
2127
2157
  }
2128
2158
  throw new NetworkError(
2129
- `HTTP error! status: ${request.status}`,
2159
+ `HTTP error: ${errorData}`,
2130
2160
  request.status,
2131
2161
  errorData
2132
2162
  );
@@ -2173,10 +2203,10 @@ var swapHistory = async (config, options) => {
2173
2203
  }
2174
2204
  );
2175
2205
  if (!request.ok) {
2176
- const errorData = await request.json();
2177
- if (request.status === 401) {
2206
+ const errorData = await request.text();
2207
+ if (request.status === 401 || request.status === 403) {
2178
2208
  throw new AuthenticationError(
2179
- "Authentication failed",
2209
+ `Authentication failed: ${errorData}`,
2180
2210
  request.status,
2181
2211
  errorData
2182
2212
  );
@@ -2189,7 +2219,7 @@ var swapHistory = async (config, options) => {
2189
2219
  );
2190
2220
  }
2191
2221
  throw new NetworkError(
2192
- `HTTP error! status: ${request.status}`,
2222
+ `HTTP error: ${errorData}`,
2193
2223
  request.status,
2194
2224
  errorData
2195
2225
  );
@@ -2235,10 +2265,10 @@ var deleteSwap = async (config, cid) => {
2235
2265
  headers
2236
2266
  });
2237
2267
  if (!request.ok) {
2238
- const errorData = await request.json();
2239
- if (request.status === 401) {
2268
+ const errorData = await request.text();
2269
+ if (request.status === 401 || request.status === 403) {
2240
2270
  throw new AuthenticationError(
2241
- "Authentication failed",
2271
+ `Authentication failed: ${errorData}`,
2242
2272
  request.status,
2243
2273
  errorData
2244
2274
  );
@@ -2258,7 +2288,7 @@ var deleteSwap = async (config, cid) => {
2258
2288
  );
2259
2289
  }
2260
2290
  throw new NetworkError(
2261
- `HTTP error! status: ${request.status}`,
2291
+ `HTTP error: ${errorData}`,
2262
2292
  request.status,
2263
2293
  errorData
2264
2294
  );
@@ -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 = {};