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.d.mts +30 -4
- package/dist/index.d.ts +30 -4
- package/dist/index.js +183 -136
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +183 -136
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -50,16 +50,16 @@ var testAuthentication = async (config) => {
|
|
|
50
50
|
headers
|
|
51
51
|
});
|
|
52
52
|
if (!request.ok) {
|
|
53
|
-
const errorData = await request.
|
|
54
|
-
if (request.status === 401) {
|
|
53
|
+
const errorData = await request.text();
|
|
54
|
+
if (request.status === 401 || request.status === 403) {
|
|
55
55
|
throw new AuthenticationError(
|
|
56
|
-
|
|
56
|
+
`Authentication failed: ${errorData}`,
|
|
57
57
|
request.status,
|
|
58
58
|
errorData
|
|
59
59
|
);
|
|
60
60
|
}
|
|
61
61
|
throw new NetworkError(
|
|
62
|
-
`HTTP error
|
|
62
|
+
`HTTP error: ${errorData}`,
|
|
63
63
|
request.status,
|
|
64
64
|
errorData
|
|
65
65
|
);
|
|
@@ -123,16 +123,16 @@ var uploadFile = async (config, file, options) => {
|
|
|
123
123
|
body: data
|
|
124
124
|
});
|
|
125
125
|
if (!request.ok) {
|
|
126
|
-
const errorData = await request.
|
|
127
|
-
if (request.status === 401) {
|
|
126
|
+
const errorData = await request.text();
|
|
127
|
+
if (request.status === 401 || request.status === 403) {
|
|
128
128
|
throw new AuthenticationError(
|
|
129
|
-
|
|
129
|
+
`Authentication failed: ${errorData}`,
|
|
130
130
|
request.status,
|
|
131
131
|
errorData
|
|
132
132
|
);
|
|
133
133
|
}
|
|
134
134
|
throw new NetworkError(
|
|
135
|
-
`HTTP error
|
|
135
|
+
`HTTP error: ${errorData}`,
|
|
136
136
|
request.status,
|
|
137
137
|
errorData
|
|
138
138
|
);
|
|
@@ -195,16 +195,16 @@ var uploadFileArray = async (config, files, options) => {
|
|
|
195
195
|
body: data
|
|
196
196
|
});
|
|
197
197
|
if (!request.ok) {
|
|
198
|
-
const errorData = await request.
|
|
199
|
-
if (request.status === 401) {
|
|
198
|
+
const errorData = await request.text();
|
|
199
|
+
if (request.status === 401 || request.status === 403) {
|
|
200
200
|
throw new AuthenticationError(
|
|
201
|
-
|
|
201
|
+
`Authentication failed: ${errorData}`,
|
|
202
202
|
request.status,
|
|
203
203
|
errorData
|
|
204
204
|
);
|
|
205
205
|
}
|
|
206
206
|
throw new NetworkError(
|
|
207
|
-
`HTTP error
|
|
207
|
+
`HTTP error: ${errorData}`,
|
|
208
208
|
request.status,
|
|
209
209
|
errorData
|
|
210
210
|
);
|
|
@@ -269,16 +269,16 @@ var uploadBase64 = async (config, base64String, options) => {
|
|
|
269
269
|
body: data
|
|
270
270
|
});
|
|
271
271
|
if (!request.ok) {
|
|
272
|
-
const errorData = await request.
|
|
273
|
-
if (request.status === 401) {
|
|
272
|
+
const errorData = await request.text();
|
|
273
|
+
if (request.status === 401 || request.status === 403) {
|
|
274
274
|
throw new AuthenticationError(
|
|
275
|
-
|
|
275
|
+
`Authentication failed: ${errorData}`,
|
|
276
276
|
request.status,
|
|
277
277
|
errorData
|
|
278
278
|
);
|
|
279
279
|
}
|
|
280
280
|
throw new NetworkError(
|
|
281
|
-
`HTTP error
|
|
281
|
+
`HTTP error: ${errorData}`,
|
|
282
282
|
request.status,
|
|
283
283
|
errorData
|
|
284
284
|
);
|
|
@@ -307,9 +307,9 @@ var uploadUrl = async (config, url, options) => {
|
|
|
307
307
|
const data = new FormData();
|
|
308
308
|
const stream = await fetch(url);
|
|
309
309
|
if (!stream.ok) {
|
|
310
|
-
const errorData = await stream.
|
|
310
|
+
const errorData = await stream.text();
|
|
311
311
|
throw new NetworkError(
|
|
312
|
-
`HTTP error
|
|
312
|
+
`HTTP error: ${errorData}`,
|
|
313
313
|
stream.status,
|
|
314
314
|
errorData
|
|
315
315
|
);
|
|
@@ -353,16 +353,16 @@ var uploadUrl = async (config, url, options) => {
|
|
|
353
353
|
body: data
|
|
354
354
|
});
|
|
355
355
|
if (!request.ok) {
|
|
356
|
-
const errorData = await request.
|
|
357
|
-
if (request.status === 401) {
|
|
356
|
+
const errorData = await request.text();
|
|
357
|
+
if (request.status === 401 || request.status === 403) {
|
|
358
358
|
throw new AuthenticationError(
|
|
359
|
-
|
|
359
|
+
`Authentication failed: ${errorData}`,
|
|
360
360
|
request.status,
|
|
361
361
|
errorData
|
|
362
362
|
);
|
|
363
363
|
}
|
|
364
364
|
throw new NetworkError(
|
|
365
|
-
`HTTP error
|
|
365
|
+
`HTTP error: ${errorData}`,
|
|
366
366
|
request.status,
|
|
367
367
|
errorData
|
|
368
368
|
);
|
|
@@ -418,16 +418,16 @@ var uploadJson = async (config, jsonData, options) => {
|
|
|
418
418
|
body: data
|
|
419
419
|
});
|
|
420
420
|
if (!request.ok) {
|
|
421
|
-
const errorData = await request.
|
|
422
|
-
if (request.status === 401) {
|
|
421
|
+
const errorData = await request.text();
|
|
422
|
+
if (request.status === 401 || request.status === 403) {
|
|
423
423
|
throw new AuthenticationError(
|
|
424
|
-
|
|
424
|
+
`Authentication failed: ${errorData}`,
|
|
425
425
|
request.status,
|
|
426
426
|
errorData
|
|
427
427
|
);
|
|
428
428
|
}
|
|
429
429
|
throw new NetworkError(
|
|
430
|
-
`HTTP error
|
|
430
|
+
`HTTP error: ${errorData}`,
|
|
431
431
|
request.status,
|
|
432
432
|
errorData
|
|
433
433
|
);
|
|
@@ -483,16 +483,16 @@ var uploadCid = async (config, cid, options) => {
|
|
|
483
483
|
body: data
|
|
484
484
|
});
|
|
485
485
|
if (!request.ok) {
|
|
486
|
-
const errorData = await request.
|
|
487
|
-
if (request.status === 401) {
|
|
486
|
+
const errorData = await request.text();
|
|
487
|
+
if (request.status === 401 || request.status === 403) {
|
|
488
488
|
throw new AuthenticationError(
|
|
489
|
-
|
|
489
|
+
`Authentication failed: ${errorData}`,
|
|
490
490
|
request.status,
|
|
491
491
|
errorData
|
|
492
492
|
);
|
|
493
493
|
}
|
|
494
494
|
throw new NetworkError(
|
|
495
|
-
`HTTP error
|
|
495
|
+
`HTTP error: ${errorData}`,
|
|
496
496
|
request.status,
|
|
497
497
|
errorData
|
|
498
498
|
);
|
|
@@ -542,16 +542,16 @@ var unpinFile = async (config, files) => {
|
|
|
542
542
|
});
|
|
543
543
|
await wait(300);
|
|
544
544
|
if (!response.ok) {
|
|
545
|
-
const errorData = await response.
|
|
545
|
+
const errorData = await response.text();
|
|
546
546
|
if (response.status === 401) {
|
|
547
547
|
throw new AuthenticationError(
|
|
548
|
-
|
|
548
|
+
`Authentication failed: ${errorData}`,
|
|
549
549
|
response.status,
|
|
550
550
|
errorData
|
|
551
551
|
);
|
|
552
552
|
}
|
|
553
553
|
throw new NetworkError(
|
|
554
|
-
`HTTP error
|
|
554
|
+
`HTTP error: ${errorData}`,
|
|
555
555
|
response.status,
|
|
556
556
|
errorData
|
|
557
557
|
);
|
|
@@ -647,16 +647,16 @@ var listFiles = async (config, options) => {
|
|
|
647
647
|
headers
|
|
648
648
|
});
|
|
649
649
|
if (!request.ok) {
|
|
650
|
-
const errorData = await request.
|
|
651
|
-
if (request.status === 401) {
|
|
650
|
+
const errorData = await request.text();
|
|
651
|
+
if (request.status === 401 || request.status === 403) {
|
|
652
652
|
throw new AuthenticationError(
|
|
653
|
-
|
|
653
|
+
`Authentication failed: ${errorData}`,
|
|
654
654
|
request.status,
|
|
655
655
|
errorData
|
|
656
656
|
);
|
|
657
657
|
}
|
|
658
658
|
throw new NetworkError(
|
|
659
|
-
`HTTP error
|
|
659
|
+
`HTTP error: ${errorData}`,
|
|
660
660
|
request.status,
|
|
661
661
|
errorData
|
|
662
662
|
);
|
|
@@ -705,16 +705,16 @@ var updateMetadata = async (config, options) => {
|
|
|
705
705
|
body: JSON.stringify(data)
|
|
706
706
|
});
|
|
707
707
|
if (!request.ok) {
|
|
708
|
-
const errorData = await request.
|
|
709
|
-
if (request.status === 401) {
|
|
708
|
+
const errorData = await request.text();
|
|
709
|
+
if (request.status === 401 || request.status === 403) {
|
|
710
710
|
throw new AuthenticationError(
|
|
711
|
-
|
|
711
|
+
`Authentication failed: ${errorData}`,
|
|
712
712
|
request.status,
|
|
713
713
|
errorData
|
|
714
714
|
);
|
|
715
715
|
}
|
|
716
716
|
throw new NetworkError(
|
|
717
|
-
`HTTP error
|
|
717
|
+
`HTTP error: ${errorData}`,
|
|
718
718
|
request.status,
|
|
719
719
|
errorData
|
|
720
720
|
);
|
|
@@ -829,29 +829,58 @@ 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
|
-
|
|
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);
|
|
844
873
|
if (!request.ok) {
|
|
845
|
-
const errorData = await request.
|
|
846
|
-
if (request.status === 401) {
|
|
874
|
+
const errorData = await request.text();
|
|
875
|
+
if (request.status === 401 || request.status === 403) {
|
|
847
876
|
throw new AuthenticationError(
|
|
848
|
-
|
|
877
|
+
`Authentication Failed: ${errorData}`,
|
|
849
878
|
request.status,
|
|
850
879
|
errorData
|
|
851
880
|
);
|
|
852
881
|
}
|
|
853
882
|
throw new NetworkError(
|
|
854
|
-
`HTTP error
|
|
883
|
+
`HTTP error: ${errorData}`,
|
|
855
884
|
request.status,
|
|
856
885
|
errorData
|
|
857
886
|
);
|
|
@@ -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
|
-
|
|
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
|
}
|
|
@@ -933,16 +963,16 @@ var pinJobs = async (config, options) => {
|
|
|
933
963
|
headers
|
|
934
964
|
});
|
|
935
965
|
if (!request.ok) {
|
|
936
|
-
const errorData = await request.
|
|
937
|
-
if (request.status === 401) {
|
|
966
|
+
const errorData = await request.text();
|
|
967
|
+
if (request.status === 401 || request.status === 403) {
|
|
938
968
|
throw new AuthenticationError(
|
|
939
|
-
|
|
969
|
+
`Authentication failed: ${errorData}`,
|
|
940
970
|
request.status,
|
|
941
971
|
errorData
|
|
942
972
|
);
|
|
943
973
|
}
|
|
944
974
|
throw new NetworkError(
|
|
945
|
-
`HTTP error
|
|
975
|
+
`HTTP error: ${errorData}`,
|
|
946
976
|
request.status,
|
|
947
977
|
errorData
|
|
948
978
|
);
|
|
@@ -984,16 +1014,16 @@ var pinnedFileCount = async (config) => {
|
|
|
984
1014
|
headers
|
|
985
1015
|
});
|
|
986
1016
|
if (!request.ok) {
|
|
987
|
-
const errorData = await request.
|
|
988
|
-
if (request.status === 401) {
|
|
1017
|
+
const errorData = await request.text();
|
|
1018
|
+
if (request.status === 401 || request.status === 403) {
|
|
989
1019
|
throw new AuthenticationError(
|
|
990
|
-
|
|
1020
|
+
`Authentication failed: ${errorData}`,
|
|
991
1021
|
request.status,
|
|
992
1022
|
errorData
|
|
993
1023
|
);
|
|
994
1024
|
}
|
|
995
1025
|
throw new NetworkError(
|
|
996
|
-
`HTTP error
|
|
1026
|
+
`HTTP error: ${errorData}`,
|
|
997
1027
|
request.status,
|
|
998
1028
|
errorData
|
|
999
1029
|
);
|
|
@@ -1039,16 +1069,16 @@ var totalStorageUsage = async (config) => {
|
|
|
1039
1069
|
headers
|
|
1040
1070
|
});
|
|
1041
1071
|
if (!request.ok) {
|
|
1042
|
-
const errorData = await request.
|
|
1043
|
-
if (request.status === 401) {
|
|
1072
|
+
const errorData = await request.text();
|
|
1073
|
+
if (request.status === 401 || request.status === 403) {
|
|
1044
1074
|
throw new AuthenticationError(
|
|
1045
|
-
|
|
1075
|
+
`Authentication failed: ${errorData}`,
|
|
1046
1076
|
request.status,
|
|
1047
1077
|
errorData
|
|
1048
1078
|
);
|
|
1049
1079
|
}
|
|
1050
1080
|
throw new NetworkError(
|
|
1051
|
-
`HTTP error
|
|
1081
|
+
`HTTP error: ${errorData}`,
|
|
1052
1082
|
request.status,
|
|
1053
1083
|
errorData
|
|
1054
1084
|
);
|
|
@@ -1097,16 +1127,16 @@ var createKey = async (config, options) => {
|
|
|
1097
1127
|
body: data
|
|
1098
1128
|
});
|
|
1099
1129
|
if (!request.ok) {
|
|
1100
|
-
const errorData = await request.
|
|
1101
|
-
if (request.status === 401) {
|
|
1130
|
+
const errorData = await request.text();
|
|
1131
|
+
if (request.status === 401 || request.status === 403) {
|
|
1102
1132
|
throw new AuthenticationError(
|
|
1103
|
-
|
|
1133
|
+
`Authentication failed: ${errorData}`,
|
|
1104
1134
|
request.status,
|
|
1105
1135
|
errorData
|
|
1106
1136
|
);
|
|
1107
1137
|
}
|
|
1108
1138
|
throw new NetworkError(
|
|
1109
|
-
`HTTP error
|
|
1139
|
+
`HTTP error: ${errorData}`,
|
|
1110
1140
|
request.status,
|
|
1111
1141
|
errorData
|
|
1112
1142
|
);
|
|
@@ -1166,16 +1196,16 @@ var listKeys = async (config, options) => {
|
|
|
1166
1196
|
}
|
|
1167
1197
|
);
|
|
1168
1198
|
if (!request.ok) {
|
|
1169
|
-
const errorData = await request.
|
|
1170
|
-
if (request.status === 401) {
|
|
1199
|
+
const errorData = await request.text();
|
|
1200
|
+
if (request.status === 401 || request.status === 403) {
|
|
1171
1201
|
throw new AuthenticationError(
|
|
1172
|
-
|
|
1202
|
+
`Authentication failed: ${errorData}`,
|
|
1173
1203
|
request.status,
|
|
1174
1204
|
errorData
|
|
1175
1205
|
);
|
|
1176
1206
|
}
|
|
1177
1207
|
throw new NetworkError(
|
|
1178
|
-
`HTTP error
|
|
1208
|
+
`HTTP error: ${errorData}`,
|
|
1179
1209
|
request.status,
|
|
1180
1210
|
errorData
|
|
1181
1211
|
);
|
|
@@ -1226,16 +1256,16 @@ var revokeKeys = async (config, keys) => {
|
|
|
1226
1256
|
});
|
|
1227
1257
|
await wait2(300);
|
|
1228
1258
|
if (!request.ok) {
|
|
1229
|
-
const errorData = await request.
|
|
1230
|
-
if (request.status === 401) {
|
|
1259
|
+
const errorData = await request.text();
|
|
1260
|
+
if (request.status === 401 || request.status === 403) {
|
|
1231
1261
|
throw new AuthenticationError(
|
|
1232
|
-
|
|
1262
|
+
`Authentication failed: ${errorData}`,
|
|
1233
1263
|
request.status,
|
|
1234
1264
|
errorData
|
|
1235
1265
|
);
|
|
1236
1266
|
}
|
|
1237
1267
|
throw new NetworkError(
|
|
1238
|
-
`HTTP error
|
|
1268
|
+
`HTTP error: ${errorData}`,
|
|
1239
1269
|
request.status,
|
|
1240
1270
|
errorData
|
|
1241
1271
|
);
|
|
@@ -1290,16 +1320,16 @@ var createGroup = async (config, options) => {
|
|
|
1290
1320
|
body: data
|
|
1291
1321
|
});
|
|
1292
1322
|
if (!request.ok) {
|
|
1293
|
-
const errorData = await request.
|
|
1294
|
-
if (request.status === 401) {
|
|
1323
|
+
const errorData = await request.text();
|
|
1324
|
+
if (request.status === 401 || request.status === 403) {
|
|
1295
1325
|
throw new AuthenticationError(
|
|
1296
|
-
|
|
1326
|
+
`Authentication failed: ${errorData}`,
|
|
1297
1327
|
request.status,
|
|
1298
1328
|
errorData
|
|
1299
1329
|
);
|
|
1300
1330
|
}
|
|
1301
1331
|
throw new NetworkError(
|
|
1302
|
-
`HTTP error
|
|
1332
|
+
`HTTP error: ${errorData}`,
|
|
1303
1333
|
request.status,
|
|
1304
1334
|
errorData
|
|
1305
1335
|
);
|
|
@@ -1352,16 +1382,16 @@ var listGroups = async (config, options) => {
|
|
|
1352
1382
|
headers
|
|
1353
1383
|
});
|
|
1354
1384
|
if (!request.ok) {
|
|
1355
|
-
const errorData = await request.
|
|
1356
|
-
if (request.status === 401) {
|
|
1385
|
+
const errorData = await request.text();
|
|
1386
|
+
if (request.status === 401 || request.status === 403) {
|
|
1357
1387
|
throw new AuthenticationError(
|
|
1358
|
-
|
|
1388
|
+
`Authentication failed: ${errorData}`,
|
|
1359
1389
|
request.status,
|
|
1360
1390
|
errorData
|
|
1361
1391
|
);
|
|
1362
1392
|
}
|
|
1363
1393
|
throw new NetworkError(
|
|
1364
|
-
`HTTP error
|
|
1394
|
+
`HTTP error: ${errorData}`,
|
|
1365
1395
|
request.status,
|
|
1366
1396
|
errorData
|
|
1367
1397
|
);
|
|
@@ -1404,16 +1434,16 @@ var getGroup = async (config, options) => {
|
|
|
1404
1434
|
headers
|
|
1405
1435
|
});
|
|
1406
1436
|
if (!request.ok) {
|
|
1407
|
-
const errorData = await request.
|
|
1408
|
-
if (request.status === 401) {
|
|
1437
|
+
const errorData = await request.text();
|
|
1438
|
+
if (request.status === 401 || request.status === 403) {
|
|
1409
1439
|
throw new AuthenticationError(
|
|
1410
|
-
|
|
1440
|
+
`Authentication failed: ${errorData}`,
|
|
1411
1441
|
request.status,
|
|
1412
1442
|
errorData
|
|
1413
1443
|
);
|
|
1414
1444
|
}
|
|
1415
1445
|
throw new NetworkError(
|
|
1416
|
-
`HTTP error
|
|
1446
|
+
`HTTP error: ${errorData}`,
|
|
1417
1447
|
request.status,
|
|
1418
1448
|
errorData
|
|
1419
1449
|
);
|
|
@@ -1462,16 +1492,16 @@ var addToGroup = async (config, options) => {
|
|
|
1462
1492
|
body: data
|
|
1463
1493
|
});
|
|
1464
1494
|
if (!request.ok) {
|
|
1465
|
-
const errorData = await request.
|
|
1466
|
-
if (request.status === 401) {
|
|
1495
|
+
const errorData = await request.text();
|
|
1496
|
+
if (request.status === 401 || request.status === 403) {
|
|
1467
1497
|
throw new AuthenticationError(
|
|
1468
|
-
|
|
1498
|
+
`Authentication failed: ${errorData}`,
|
|
1469
1499
|
request.status,
|
|
1470
1500
|
errorData
|
|
1471
1501
|
);
|
|
1472
1502
|
}
|
|
1473
1503
|
throw new NetworkError(
|
|
1474
|
-
`HTTP error
|
|
1504
|
+
`HTTP error: ${errorData}`,
|
|
1475
1505
|
request.status,
|
|
1476
1506
|
errorData
|
|
1477
1507
|
);
|
|
@@ -1520,16 +1550,16 @@ var updateGroup = async (config, options) => {
|
|
|
1520
1550
|
body: data
|
|
1521
1551
|
});
|
|
1522
1552
|
if (!request.ok) {
|
|
1523
|
-
const errorData = await request.
|
|
1524
|
-
if (request.status === 401) {
|
|
1553
|
+
const errorData = await request.text();
|
|
1554
|
+
if (request.status === 401 || request.status === 403) {
|
|
1525
1555
|
throw new AuthenticationError(
|
|
1526
|
-
|
|
1556
|
+
`Authentication failed: ${errorData}`,
|
|
1527
1557
|
request.status,
|
|
1528
1558
|
errorData
|
|
1529
1559
|
);
|
|
1530
1560
|
}
|
|
1531
1561
|
throw new NetworkError(
|
|
1532
|
-
`HTTP error
|
|
1562
|
+
`HTTP error: ${errorData}`,
|
|
1533
1563
|
request.status,
|
|
1534
1564
|
errorData
|
|
1535
1565
|
);
|
|
@@ -1576,16 +1606,16 @@ var removeFromGroup = async (config, options) => {
|
|
|
1576
1606
|
body: data
|
|
1577
1607
|
});
|
|
1578
1608
|
if (!request.ok) {
|
|
1579
|
-
const errorData = await request.
|
|
1580
|
-
if (request.status === 401) {
|
|
1609
|
+
const errorData = await request.text();
|
|
1610
|
+
if (request.status === 401 || request.status === 403) {
|
|
1581
1611
|
throw new AuthenticationError(
|
|
1582
|
-
|
|
1612
|
+
`Authentication failed: ${errorData}`,
|
|
1583
1613
|
request.status,
|
|
1584
1614
|
errorData
|
|
1585
1615
|
);
|
|
1586
1616
|
}
|
|
1587
1617
|
throw new NetworkError(
|
|
1588
|
-
`HTTP error
|
|
1618
|
+
`HTTP error: ${errorData}`,
|
|
1589
1619
|
request.status,
|
|
1590
1620
|
errorData
|
|
1591
1621
|
);
|
|
@@ -1632,16 +1662,16 @@ var deleteGroup = async (config, options) => {
|
|
|
1632
1662
|
headers
|
|
1633
1663
|
});
|
|
1634
1664
|
if (!request.ok) {
|
|
1635
|
-
const errorData = await request.
|
|
1636
|
-
if (request.status === 401) {
|
|
1665
|
+
const errorData = await request.text();
|
|
1666
|
+
if (request.status === 401 || request.status === 403) {
|
|
1637
1667
|
throw new AuthenticationError(
|
|
1638
|
-
|
|
1668
|
+
`Authentication failed: ${errorData}`,
|
|
1639
1669
|
request.status,
|
|
1640
1670
|
errorData
|
|
1641
1671
|
);
|
|
1642
1672
|
}
|
|
1643
1673
|
throw new NetworkError(
|
|
1644
|
-
`HTTP error
|
|
1674
|
+
`HTTP error: ${errorData}`,
|
|
1645
1675
|
request.status,
|
|
1646
1676
|
errorData
|
|
1647
1677
|
);
|
|
@@ -1691,10 +1721,10 @@ var addSignature = async (config, options) => {
|
|
|
1691
1721
|
}
|
|
1692
1722
|
);
|
|
1693
1723
|
if (!request.ok) {
|
|
1694
|
-
const errorData = await request.
|
|
1695
|
-
if (request.status === 401) {
|
|
1724
|
+
const errorData = await request.text();
|
|
1725
|
+
if (request.status === 401 || request.status === 403) {
|
|
1696
1726
|
throw new AuthenticationError(
|
|
1697
|
-
|
|
1727
|
+
`Authentication failed: ${errorData}`,
|
|
1698
1728
|
request.status,
|
|
1699
1729
|
errorData
|
|
1700
1730
|
);
|
|
@@ -1707,7 +1737,7 @@ var addSignature = async (config, options) => {
|
|
|
1707
1737
|
);
|
|
1708
1738
|
}
|
|
1709
1739
|
throw new NetworkError(
|
|
1710
|
-
`HTTP error
|
|
1740
|
+
`HTTP error: ${errorData}`,
|
|
1711
1741
|
request.status,
|
|
1712
1742
|
errorData
|
|
1713
1743
|
);
|
|
@@ -1752,16 +1782,16 @@ var getSignature = async (config, cid) => {
|
|
|
1752
1782
|
headers
|
|
1753
1783
|
});
|
|
1754
1784
|
if (!request.ok) {
|
|
1755
|
-
const errorData = await request.
|
|
1756
|
-
if (request.status === 401) {
|
|
1785
|
+
const errorData = await request.text();
|
|
1786
|
+
if (request.status === 401 || request.status === 403) {
|
|
1757
1787
|
throw new AuthenticationError(
|
|
1758
|
-
|
|
1788
|
+
`Authentication failed: ${errorData}`,
|
|
1759
1789
|
request.status,
|
|
1760
1790
|
errorData
|
|
1761
1791
|
);
|
|
1762
1792
|
}
|
|
1763
1793
|
throw new NetworkError(
|
|
1764
|
-
`HTTP error
|
|
1794
|
+
`HTTP error: ${errorData}`,
|
|
1765
1795
|
request.status,
|
|
1766
1796
|
errorData
|
|
1767
1797
|
);
|
|
@@ -1806,16 +1836,16 @@ var removeSignature = async (config, cid) => {
|
|
|
1806
1836
|
headers
|
|
1807
1837
|
});
|
|
1808
1838
|
if (!request.ok) {
|
|
1809
|
-
const errorData = await request.
|
|
1810
|
-
if (request.status === 401) {
|
|
1839
|
+
const errorData = await request.text();
|
|
1840
|
+
if (request.status === 401 || request.status === 403) {
|
|
1811
1841
|
throw new AuthenticationError(
|
|
1812
|
-
|
|
1842
|
+
`Authentication failed: ${errorData}`,
|
|
1813
1843
|
request.status,
|
|
1814
1844
|
errorData
|
|
1815
1845
|
);
|
|
1816
1846
|
}
|
|
1817
1847
|
throw new NetworkError(
|
|
1818
|
-
`HTTP error
|
|
1848
|
+
`HTTP error: ${errorData}`,
|
|
1819
1849
|
request.status,
|
|
1820
1850
|
errorData
|
|
1821
1851
|
);
|
|
@@ -1905,16 +1935,16 @@ var analyticsTopUsage = async (config, options) => {
|
|
|
1905
1935
|
headers
|
|
1906
1936
|
});
|
|
1907
1937
|
if (!request.ok) {
|
|
1908
|
-
const errorData = await request.
|
|
1909
|
-
if (request.status === 401) {
|
|
1938
|
+
const errorData = await request.text();
|
|
1939
|
+
if (request.status === 401 || request.status === 403) {
|
|
1910
1940
|
throw new AuthenticationError(
|
|
1911
|
-
|
|
1941
|
+
`Authentication failed: ${errorData}`,
|
|
1912
1942
|
request.status,
|
|
1913
1943
|
errorData
|
|
1914
1944
|
);
|
|
1915
1945
|
}
|
|
1916
1946
|
throw new NetworkError(
|
|
1917
|
-
`HTTP error
|
|
1947
|
+
`HTTP error: ${errorData}`,
|
|
1918
1948
|
request.status,
|
|
1919
1949
|
errorData
|
|
1920
1950
|
);
|
|
@@ -2006,16 +2036,16 @@ var analyticsDateInterval = async (config, options) => {
|
|
|
2006
2036
|
headers
|
|
2007
2037
|
});
|
|
2008
2038
|
if (!request.ok) {
|
|
2009
|
-
const errorData = await request.
|
|
2010
|
-
if (request.status === 401) {
|
|
2039
|
+
const errorData = await request.text();
|
|
2040
|
+
if (request.status === 401 || request.status === 403) {
|
|
2011
2041
|
throw new AuthenticationError(
|
|
2012
|
-
|
|
2042
|
+
`Authentication failed: ${errorData}`,
|
|
2013
2043
|
request.status,
|
|
2014
2044
|
errorData
|
|
2015
2045
|
);
|
|
2016
2046
|
}
|
|
2017
2047
|
throw new NetworkError(
|
|
2018
|
-
`HTTP error
|
|
2048
|
+
`HTTP error: ${errorData}`,
|
|
2019
2049
|
request.status,
|
|
2020
2050
|
errorData
|
|
2021
2051
|
);
|
|
@@ -2067,10 +2097,10 @@ var swapCid = async (config, options) => {
|
|
|
2067
2097
|
body: data
|
|
2068
2098
|
});
|
|
2069
2099
|
if (!request.ok) {
|
|
2070
|
-
const errorData = await request.
|
|
2071
|
-
if (request.status === 401) {
|
|
2100
|
+
const errorData = await request.text();
|
|
2101
|
+
if (request.status === 401 || request.status === 403) {
|
|
2072
2102
|
throw new AuthenticationError(
|
|
2073
|
-
|
|
2103
|
+
`Authentication failed: ${errorData}`,
|
|
2074
2104
|
request.status,
|
|
2075
2105
|
errorData
|
|
2076
2106
|
);
|
|
@@ -2090,7 +2120,7 @@ var swapCid = async (config, options) => {
|
|
|
2090
2120
|
);
|
|
2091
2121
|
}
|
|
2092
2122
|
throw new NetworkError(
|
|
2093
|
-
`HTTP error
|
|
2123
|
+
`HTTP error: ${errorData}`,
|
|
2094
2124
|
request.status,
|
|
2095
2125
|
errorData
|
|
2096
2126
|
);
|
|
@@ -2137,10 +2167,10 @@ var swapHistory = async (config, options) => {
|
|
|
2137
2167
|
}
|
|
2138
2168
|
);
|
|
2139
2169
|
if (!request.ok) {
|
|
2140
|
-
const errorData = await request.
|
|
2141
|
-
if (request.status === 401) {
|
|
2170
|
+
const errorData = await request.text();
|
|
2171
|
+
if (request.status === 401 || request.status === 403) {
|
|
2142
2172
|
throw new AuthenticationError(
|
|
2143
|
-
|
|
2173
|
+
`Authentication failed: ${errorData}`,
|
|
2144
2174
|
request.status,
|
|
2145
2175
|
errorData
|
|
2146
2176
|
);
|
|
@@ -2153,7 +2183,7 @@ var swapHistory = async (config, options) => {
|
|
|
2153
2183
|
);
|
|
2154
2184
|
}
|
|
2155
2185
|
throw new NetworkError(
|
|
2156
|
-
`HTTP error
|
|
2186
|
+
`HTTP error: ${errorData}`,
|
|
2157
2187
|
request.status,
|
|
2158
2188
|
errorData
|
|
2159
2189
|
);
|
|
@@ -2199,10 +2229,10 @@ var deleteSwap = async (config, cid) => {
|
|
|
2199
2229
|
headers
|
|
2200
2230
|
});
|
|
2201
2231
|
if (!request.ok) {
|
|
2202
|
-
const errorData = await request.
|
|
2203
|
-
if (request.status === 401) {
|
|
2232
|
+
const errorData = await request.text();
|
|
2233
|
+
if (request.status === 401 || request.status === 403) {
|
|
2204
2234
|
throw new AuthenticationError(
|
|
2205
|
-
|
|
2235
|
+
`Authentication failed: ${errorData}`,
|
|
2206
2236
|
request.status,
|
|
2207
2237
|
errorData
|
|
2208
2238
|
);
|
|
@@ -2222,7 +2252,7 @@ var deleteSwap = async (config, cid) => {
|
|
|
2222
2252
|
);
|
|
2223
2253
|
}
|
|
2224
2254
|
throw new NetworkError(
|
|
2225
|
-
`HTTP error
|
|
2255
|
+
`HTTP error: ${errorData}`,
|
|
2226
2256
|
request.status,
|
|
2227
2257
|
errorData
|
|
2228
2258
|
);
|
|
@@ -2471,10 +2501,13 @@ var Gateways = class {
|
|
|
2471
2501
|
this.config = newConfig;
|
|
2472
2502
|
}
|
|
2473
2503
|
get(cid) {
|
|
2474
|
-
return
|
|
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 = {};
|