pinata 0.1.10 → 0.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 +89 -1
- package/dist/index.d.ts +89 -1
- package/dist/index.js +772 -314
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +772 -314
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -31,21 +31,24 @@ var testAuthentication = async (config) => {
|
|
|
31
31
|
if (!config || !config.pinataJwt) {
|
|
32
32
|
throw new ValidationError("Pinata configuration or JWT is missing");
|
|
33
33
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
let headers;
|
|
35
|
+
let endpoint = "https://api.pinata.cloud";
|
|
36
|
+
if (config.endpointUrl) {
|
|
37
|
+
endpoint = config.endpointUrl;
|
|
38
|
+
}
|
|
39
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
40
|
+
headers = { ...config.customHeaders };
|
|
41
|
+
} else {
|
|
42
|
+
headers = {
|
|
43
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
44
|
+
Source: "sdk/testAuthentication"
|
|
45
|
+
};
|
|
39
46
|
}
|
|
40
|
-
headers["Source"] = headers["Source"] || "sdk/testAuthentication";
|
|
41
47
|
try {
|
|
42
|
-
const request = await fetch(
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
headers
|
|
47
|
-
}
|
|
48
|
-
);
|
|
48
|
+
const request = await fetch(`${endpoint}/data/testAuthentication`, {
|
|
49
|
+
method: "GET",
|
|
50
|
+
headers
|
|
51
|
+
});
|
|
49
52
|
if (!request.ok) {
|
|
50
53
|
const errorData = await request.json();
|
|
51
54
|
if (request.status === 401) {
|
|
@@ -96,26 +99,29 @@ var uploadFile = async (config, file, options) => {
|
|
|
96
99
|
data.append(
|
|
97
100
|
"pinataMetadata",
|
|
98
101
|
JSON.stringify({
|
|
99
|
-
name: options?.metadata
|
|
102
|
+
name: options?.metadata?.name || file.name || "File from SDK",
|
|
100
103
|
keyvalues: options?.metadata?.keyValues
|
|
101
104
|
})
|
|
102
105
|
);
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
106
|
+
let headers;
|
|
107
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
108
|
+
headers = { ...config.customHeaders };
|
|
109
|
+
} else {
|
|
110
|
+
headers = {
|
|
111
|
+
Authorization: `Bearer ${jwt}`,
|
|
112
|
+
Source: "sdk/file"
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
let endpoint = "https://api.pinata.cloud";
|
|
116
|
+
if (config.endpointUrl) {
|
|
117
|
+
endpoint = config.endpointUrl;
|
|
108
118
|
}
|
|
109
|
-
headers["Source"] = headers["Source"] || "sdk/file";
|
|
110
119
|
try {
|
|
111
|
-
const request = await fetch(
|
|
112
|
-
"
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
body: data
|
|
117
|
-
}
|
|
118
|
-
);
|
|
120
|
+
const request = await fetch(`${endpoint}/pinning/pinFileToIPFS`, {
|
|
121
|
+
method: "POST",
|
|
122
|
+
headers,
|
|
123
|
+
body: data
|
|
124
|
+
});
|
|
119
125
|
if (!request.ok) {
|
|
120
126
|
const errorData = await request.json();
|
|
121
127
|
if (request.status === 401) {
|
|
@@ -150,7 +156,7 @@ var uploadFileArray = async (config, files, options) => {
|
|
|
150
156
|
throw new ValidationError("Pinata configuration or JWT is missing");
|
|
151
157
|
}
|
|
152
158
|
const jwt = options?.keys || config?.pinataJwt;
|
|
153
|
-
const folder = options?.metadata?.name
|
|
159
|
+
const folder = options?.metadata?.name || "folder_from_sdk";
|
|
154
160
|
const data = new FormData();
|
|
155
161
|
for (const file of Array.from(files)) {
|
|
156
162
|
data.append("file", file, `${folder}/${file.name}`);
|
|
@@ -169,22 +175,25 @@ var uploadFileArray = async (config, files, options) => {
|
|
|
169
175
|
groupId: options?.groupId
|
|
170
176
|
})
|
|
171
177
|
);
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
178
|
+
let headers;
|
|
179
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
180
|
+
headers = { ...config.customHeaders };
|
|
181
|
+
} else {
|
|
182
|
+
headers = {
|
|
183
|
+
Authorization: `Bearer ${jwt}`,
|
|
184
|
+
Source: "sdk/fileArray"
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
let endpoint = "https://api.pinata.cloud";
|
|
188
|
+
if (config.endpointUrl) {
|
|
189
|
+
endpoint = config.endpointUrl;
|
|
177
190
|
}
|
|
178
|
-
headers["Source"] = headers["Source"] || "sdk/fileArray";
|
|
179
191
|
try {
|
|
180
|
-
const request = await fetch(
|
|
181
|
-
"
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
body: data
|
|
186
|
-
}
|
|
187
|
-
);
|
|
192
|
+
const request = await fetch(`${endpoint}/pinning/pinFileToIPFS`, {
|
|
193
|
+
method: "POST",
|
|
194
|
+
headers,
|
|
195
|
+
body: data
|
|
196
|
+
});
|
|
188
197
|
if (!request.ok) {
|
|
189
198
|
const errorData = await request.json();
|
|
190
199
|
if (request.status === 401) {
|
|
@@ -240,22 +249,25 @@ var uploadBase64 = async (config, base64String, options) => {
|
|
|
240
249
|
keyvalues: options?.metadata?.keyValues
|
|
241
250
|
})
|
|
242
251
|
);
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
252
|
+
let headers;
|
|
253
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
254
|
+
headers = { ...config.customHeaders };
|
|
255
|
+
} else {
|
|
256
|
+
headers = {
|
|
257
|
+
Authorization: `Bearer ${jwt}`,
|
|
258
|
+
Source: "sdk/base64"
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
let endpoint = "https://api.pinata.cloud";
|
|
262
|
+
if (config.endpointUrl) {
|
|
263
|
+
endpoint = config.endpointUrl;
|
|
248
264
|
}
|
|
249
|
-
headers["Source"] = headers["Source"] || "sdk/base64";
|
|
250
265
|
try {
|
|
251
|
-
const request = await fetch(
|
|
252
|
-
"
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
body: data
|
|
257
|
-
}
|
|
258
|
-
);
|
|
266
|
+
const request = await fetch(`${endpoint}/pinning/pinFileToIPFS`, {
|
|
267
|
+
method: "POST",
|
|
268
|
+
headers,
|
|
269
|
+
body: data
|
|
270
|
+
});
|
|
259
271
|
if (!request.ok) {
|
|
260
272
|
const errorData = await request.json();
|
|
261
273
|
if (request.status === 401) {
|
|
@@ -321,22 +333,25 @@ var uploadUrl = async (config, url, options) => {
|
|
|
321
333
|
keyvalues: options?.metadata?.keyValues
|
|
322
334
|
})
|
|
323
335
|
);
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
336
|
+
let headers;
|
|
337
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
338
|
+
headers = { ...config.customHeaders };
|
|
339
|
+
} else {
|
|
340
|
+
headers = {
|
|
341
|
+
Authorization: `Bearer ${jwt}`,
|
|
342
|
+
Source: "sdk/url"
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
let endpoint = "https://api.pinata.cloud";
|
|
346
|
+
if (config.endpointUrl) {
|
|
347
|
+
endpoint = config.endpointUrl;
|
|
329
348
|
}
|
|
330
|
-
headers["Source"] = headers["Source"] || "sdk/url";
|
|
331
349
|
try {
|
|
332
|
-
const request = await fetch(
|
|
333
|
-
"
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
body: data
|
|
338
|
-
}
|
|
339
|
-
);
|
|
350
|
+
const request = await fetch(`${endpoint}/pinning/pinFileToIPFS`, {
|
|
351
|
+
method: "POST",
|
|
352
|
+
headers,
|
|
353
|
+
body: data
|
|
354
|
+
});
|
|
340
355
|
if (!request.ok) {
|
|
341
356
|
const errorData = await request.json();
|
|
342
357
|
if (request.status === 401) {
|
|
@@ -378,27 +393,30 @@ var uploadJson = async (config, jsonData, options) => {
|
|
|
378
393
|
groupId: options?.groupId
|
|
379
394
|
},
|
|
380
395
|
pinataMetadata: {
|
|
381
|
-
name: options?.metadata
|
|
396
|
+
name: options?.metadata?.name || "json",
|
|
382
397
|
keyvalues: options?.metadata?.keyValues
|
|
383
398
|
}
|
|
384
399
|
});
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
|
|
400
|
+
let headers;
|
|
401
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
402
|
+
headers = { ...config.customHeaders };
|
|
403
|
+
} else {
|
|
404
|
+
headers = {
|
|
405
|
+
Authorization: `Bearer ${jwt}`,
|
|
406
|
+
"Content-Type": "application/json",
|
|
407
|
+
Source: "sdk/json"
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
let endpoint = "https://api.pinata.cloud";
|
|
411
|
+
if (config.endpointUrl) {
|
|
412
|
+
endpoint = config.endpointUrl;
|
|
391
413
|
}
|
|
392
|
-
headers["Source"] = headers["Source"] || "sdk/json";
|
|
393
414
|
try {
|
|
394
|
-
const request = await fetch(
|
|
395
|
-
"
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
body: data
|
|
400
|
-
}
|
|
401
|
-
);
|
|
415
|
+
const request = await fetch(`${endpoint}/pinning/pinJSONToIPFS`, {
|
|
416
|
+
method: "POST",
|
|
417
|
+
headers,
|
|
418
|
+
body: data
|
|
419
|
+
});
|
|
402
420
|
if (!request.ok) {
|
|
403
421
|
const errorData = await request.json();
|
|
404
422
|
if (request.status === 401) {
|
|
@@ -433,14 +451,16 @@ var uploadCid = async (config, cid, options) => {
|
|
|
433
451
|
throw new ValidationError("Pinata configuration or JWT is missing");
|
|
434
452
|
}
|
|
435
453
|
const jwt = options?.keys || config?.pinataJwt;
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
|
|
454
|
+
let headers;
|
|
455
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
456
|
+
headers = { ...config.customHeaders };
|
|
457
|
+
} else {
|
|
458
|
+
headers = {
|
|
459
|
+
Authorization: `Bearer ${jwt}`,
|
|
460
|
+
"Content-Type": "application/json",
|
|
461
|
+
Source: "sdk/cid"
|
|
462
|
+
};
|
|
442
463
|
}
|
|
443
|
-
headers["Source"] = headers["Source"] || "sdk/cid";
|
|
444
464
|
const data = JSON.stringify({
|
|
445
465
|
hashToPin: cid,
|
|
446
466
|
pinataMetadata: {
|
|
@@ -452,8 +472,12 @@ var uploadCid = async (config, cid, options) => {
|
|
|
452
472
|
groupId: options?.groupId
|
|
453
473
|
}
|
|
454
474
|
});
|
|
475
|
+
let endpoint = "https://api.pinata.cloud";
|
|
476
|
+
if (config.endpointUrl) {
|
|
477
|
+
endpoint = config.endpointUrl;
|
|
478
|
+
}
|
|
455
479
|
try {
|
|
456
|
-
const request = await fetch(
|
|
480
|
+
const request = await fetch(`${endpoint}/pinning/pinByHash`, {
|
|
457
481
|
method: "POST",
|
|
458
482
|
headers,
|
|
459
483
|
body: data
|
|
@@ -497,23 +521,25 @@ var unpinFile = async (config, files) => {
|
|
|
497
521
|
throw new ValidationError("Pinata configuration or JWT is missing");
|
|
498
522
|
}
|
|
499
523
|
const responses = [];
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
|
|
524
|
+
let headers;
|
|
525
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
526
|
+
headers = { ...config.customHeaders };
|
|
527
|
+
} else {
|
|
528
|
+
headers = {
|
|
529
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
530
|
+
Source: "sdk/unpin"
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
let endpoint = "https://api.pinata.cloud";
|
|
534
|
+
if (config.endpointUrl) {
|
|
535
|
+
endpoint = config.endpointUrl;
|
|
506
536
|
}
|
|
507
|
-
headers["Source"] = headers["Source"] || "sdk/unpin";
|
|
508
537
|
for (const hash of files) {
|
|
509
538
|
try {
|
|
510
|
-
const response = await fetch(
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
headers
|
|
515
|
-
}
|
|
516
|
-
);
|
|
539
|
+
const response = await fetch(`${endpoint}/pinning/unpin/${hash}`, {
|
|
540
|
+
method: "DELETE",
|
|
541
|
+
headers
|
|
542
|
+
});
|
|
517
543
|
await wait(300);
|
|
518
544
|
if (!response.ok) {
|
|
519
545
|
const errorData = await response.json();
|
|
@@ -601,15 +627,21 @@ var listFiles = async (config, options) => {
|
|
|
601
627
|
params.append("metadata[keyvalues]", keyValueParam);
|
|
602
628
|
}
|
|
603
629
|
}
|
|
604
|
-
|
|
630
|
+
let endpoint = "https://api.pinata.cloud";
|
|
631
|
+
if (config.endpointUrl) {
|
|
632
|
+
endpoint = config.endpointUrl;
|
|
633
|
+
}
|
|
634
|
+
const url = `${endpoint}/data/pinList?status=pinned&${params.toString()}`;
|
|
605
635
|
try {
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
636
|
+
let headers;
|
|
637
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
638
|
+
headers = { ...config.customHeaders };
|
|
639
|
+
} else {
|
|
640
|
+
headers = {
|
|
641
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
642
|
+
Source: "sdk/listFiles"
|
|
643
|
+
};
|
|
611
644
|
}
|
|
612
|
-
headers["Source"] = headers["Source"] || "sdk/listFiles";
|
|
613
645
|
const request = await fetch(url, {
|
|
614
646
|
method: "GET",
|
|
615
647
|
headers
|
|
@@ -652,23 +684,26 @@ var updateMetadata = async (config, options) => {
|
|
|
652
684
|
name: options.name,
|
|
653
685
|
keyvalues: options.keyValues
|
|
654
686
|
};
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
|
|
687
|
+
let headers;
|
|
688
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
689
|
+
headers = { ...config.customHeaders };
|
|
690
|
+
} else {
|
|
691
|
+
headers = {
|
|
692
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
693
|
+
"Content-Type": "application/json",
|
|
694
|
+
Source: "sdk/updateMetadata"
|
|
695
|
+
};
|
|
696
|
+
}
|
|
697
|
+
let endpoint = "https://api.pinata.cloud";
|
|
698
|
+
if (config.endpointUrl) {
|
|
699
|
+
endpoint = config.endpointUrl;
|
|
661
700
|
}
|
|
662
|
-
headers["Source"] = headers["Source"] || "sdk/updateMetadata";
|
|
663
701
|
try {
|
|
664
|
-
const request = await fetch(
|
|
665
|
-
"
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
body: JSON.stringify(data)
|
|
670
|
-
}
|
|
671
|
-
);
|
|
702
|
+
const request = await fetch(`${endpoint}/pinning/hashMetadata`, {
|
|
703
|
+
method: "PUT",
|
|
704
|
+
headers,
|
|
705
|
+
body: JSON.stringify(data)
|
|
706
|
+
});
|
|
672
707
|
if (!request.ok) {
|
|
673
708
|
const errorData = await request.json();
|
|
674
709
|
if (request.status === 401) {
|
|
@@ -883,14 +918,20 @@ var pinJobs = async (config, options) => {
|
|
|
883
918
|
if (offset)
|
|
884
919
|
params.append("offset", offset.toString());
|
|
885
920
|
}
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
}
|
|
890
|
-
|
|
891
|
-
|
|
921
|
+
let endpoint = "https://api.pinata.cloud";
|
|
922
|
+
if (config.endpointUrl) {
|
|
923
|
+
endpoint = config.endpointUrl;
|
|
924
|
+
}
|
|
925
|
+
const url = `${endpoint}/pinning/pinJobs?${params.toString()}`;
|
|
926
|
+
let headers;
|
|
927
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
928
|
+
headers = { ...config.customHeaders };
|
|
929
|
+
} else {
|
|
930
|
+
headers = {
|
|
931
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
932
|
+
Source: "sdk/pinJobs"
|
|
933
|
+
};
|
|
892
934
|
}
|
|
893
|
-
headers["Source"] = headers["Source"] || "sdk/pinJobs";
|
|
894
935
|
try {
|
|
895
936
|
const request = await fetch(url, {
|
|
896
937
|
method: "GET",
|
|
@@ -929,16 +970,21 @@ var pinnedFileCount = async (config) => {
|
|
|
929
970
|
if (!config || !config.pinataJwt) {
|
|
930
971
|
throw new ValidationError("Pinata configuration or JWT is missing");
|
|
931
972
|
}
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
}
|
|
936
|
-
|
|
937
|
-
|
|
973
|
+
let endpoint = "https://api.pinata.cloud";
|
|
974
|
+
if (config.endpointUrl) {
|
|
975
|
+
endpoint = config.endpointUrl;
|
|
976
|
+
}
|
|
977
|
+
let headers;
|
|
978
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
979
|
+
headers = { ...config.customHeaders };
|
|
980
|
+
} else {
|
|
981
|
+
headers = {
|
|
982
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
983
|
+
Source: "sdk/pinnedFileUsage"
|
|
984
|
+
};
|
|
938
985
|
}
|
|
939
|
-
headers["Source"] = headers["Source"] || "sdk/pinnedFileUsage";
|
|
940
986
|
try {
|
|
941
|
-
const request = await fetch(
|
|
987
|
+
const request = await fetch(`${endpoint}/data/userPinnedDataTotal`, {
|
|
942
988
|
method: "GET",
|
|
943
989
|
headers
|
|
944
990
|
});
|
|
@@ -979,16 +1025,21 @@ var totalStorageUsage = async (config) => {
|
|
|
979
1025
|
if (!config || !config.pinataJwt) {
|
|
980
1026
|
throw new ValidationError("Pinata configuration or JWT is missing");
|
|
981
1027
|
}
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
}
|
|
986
|
-
|
|
987
|
-
|
|
1028
|
+
let endpoint = "https://api.pinata.cloud";
|
|
1029
|
+
if (config.endpointUrl) {
|
|
1030
|
+
endpoint = config.endpointUrl;
|
|
1031
|
+
}
|
|
1032
|
+
let headers;
|
|
1033
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1034
|
+
headers = { ...config.customHeaders };
|
|
1035
|
+
} else {
|
|
1036
|
+
headers = {
|
|
1037
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1038
|
+
Source: "sdk/totalStorageUsage"
|
|
1039
|
+
};
|
|
988
1040
|
}
|
|
989
|
-
headers["Source"] = headers["Source"] || "sdk/totalStorageUsage";
|
|
990
1041
|
try {
|
|
991
|
-
const request = await fetch(
|
|
1042
|
+
const request = await fetch(`${endpoint}/data/userPinnedDataTotal`, {
|
|
992
1043
|
method: "GET",
|
|
993
1044
|
headers
|
|
994
1045
|
});
|
|
@@ -1029,17 +1080,23 @@ var createKey = async (config, options) => {
|
|
|
1029
1080
|
if (!config || !config.pinataJwt) {
|
|
1030
1081
|
throw new ValidationError("Pinata configuration or JWT is missing");
|
|
1031
1082
|
}
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
}
|
|
1036
|
-
|
|
1037
|
-
|
|
1083
|
+
let headers;
|
|
1084
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1085
|
+
headers = { ...config.customHeaders };
|
|
1086
|
+
} else {
|
|
1087
|
+
headers = {
|
|
1088
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1089
|
+
"Content-Type": "application/json",
|
|
1090
|
+
Source: "sdk/createKey"
|
|
1091
|
+
};
|
|
1038
1092
|
}
|
|
1039
|
-
headers["Source"] = headers["Source"] || "sdk/createKey";
|
|
1040
1093
|
const data = JSON.stringify(options);
|
|
1094
|
+
let endpoint = "https://api.pinata.cloud";
|
|
1095
|
+
if (config.endpointUrl) {
|
|
1096
|
+
endpoint = config.endpointUrl;
|
|
1097
|
+
}
|
|
1041
1098
|
try {
|
|
1042
|
-
const request = await fetch(
|
|
1099
|
+
const request = await fetch(`${endpoint}/v3/pinata/keys`, {
|
|
1043
1100
|
method: "POST",
|
|
1044
1101
|
headers,
|
|
1045
1102
|
body: data
|
|
@@ -1077,14 +1134,16 @@ var listKeys = async (config, options) => {
|
|
|
1077
1134
|
if (!config || !config.pinataJwt) {
|
|
1078
1135
|
throw new ValidationError("Pinata configuration or JWT is missing");
|
|
1079
1136
|
}
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
}
|
|
1084
|
-
|
|
1085
|
-
|
|
1137
|
+
let headers;
|
|
1138
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1139
|
+
headers = { ...config.customHeaders };
|
|
1140
|
+
} else {
|
|
1141
|
+
headers = {
|
|
1142
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1143
|
+
"Content-Type": "application/json",
|
|
1144
|
+
Source: "sdk/listKeys"
|
|
1145
|
+
};
|
|
1086
1146
|
}
|
|
1087
|
-
headers["Source"] = headers["Source"] || "sdk/listKeys";
|
|
1088
1147
|
const params = new URLSearchParams();
|
|
1089
1148
|
if (options) {
|
|
1090
1149
|
const { offset, name, revoked, limitedUse, exhausted } = options;
|
|
@@ -1099,12 +1158,18 @@ var listKeys = async (config, options) => {
|
|
|
1099
1158
|
if (name)
|
|
1100
1159
|
params.append("name", name);
|
|
1101
1160
|
}
|
|
1102
|
-
|
|
1161
|
+
let endpoint = "https://api.pinata.cloud";
|
|
1162
|
+
if (config.endpointUrl) {
|
|
1163
|
+
endpoint = config.endpointUrl;
|
|
1164
|
+
}
|
|
1103
1165
|
try {
|
|
1104
|
-
const request = await fetch(
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1166
|
+
const request = await fetch(
|
|
1167
|
+
`${endpoint}/v3/pinata/keys?${params.toString()}`,
|
|
1168
|
+
{
|
|
1169
|
+
method: "GET",
|
|
1170
|
+
headers
|
|
1171
|
+
}
|
|
1172
|
+
);
|
|
1108
1173
|
if (!request.ok) {
|
|
1109
1174
|
const errorData = await request.json();
|
|
1110
1175
|
if (request.status === 401) {
|
|
@@ -1143,24 +1208,27 @@ var revokeKeys = async (config, keys) => {
|
|
|
1143
1208
|
if (!config || !config.pinataJwt) {
|
|
1144
1209
|
throw new ValidationError("Pinata configuration or JWT is missing");
|
|
1145
1210
|
}
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
}
|
|
1150
|
-
|
|
1151
|
-
|
|
1211
|
+
let headers;
|
|
1212
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1213
|
+
headers = { ...config.customHeaders };
|
|
1214
|
+
} else {
|
|
1215
|
+
headers = {
|
|
1216
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1217
|
+
"Content-Type": "application/json",
|
|
1218
|
+
Source: "sdk/revokeKeys"
|
|
1219
|
+
};
|
|
1152
1220
|
}
|
|
1153
|
-
headers["Source"] = headers["Source"] || "sdk/revokeKeys";
|
|
1154
1221
|
const responses = [];
|
|
1222
|
+
let endpoint = "https://api.pinata.cloud";
|
|
1223
|
+
if (config.endpointUrl) {
|
|
1224
|
+
endpoint = config.endpointUrl;
|
|
1225
|
+
}
|
|
1155
1226
|
for (const key of keys) {
|
|
1156
1227
|
try {
|
|
1157
|
-
const request = await fetch(
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
headers
|
|
1162
|
-
}
|
|
1163
|
-
);
|
|
1228
|
+
const request = await fetch(`${endpoint}/v3/pinata/keys/${key}`, {
|
|
1229
|
+
method: "PUT",
|
|
1230
|
+
headers
|
|
1231
|
+
});
|
|
1164
1232
|
await wait2(300);
|
|
1165
1233
|
if (!request.ok) {
|
|
1166
1234
|
const errorData = await request.json();
|
|
@@ -1206,16 +1274,22 @@ var createGroup = async (config, options) => {
|
|
|
1206
1274
|
throw new ValidationError("Pinata configuration or JWT is missing");
|
|
1207
1275
|
}
|
|
1208
1276
|
const data = JSON.stringify(options);
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
}
|
|
1213
|
-
|
|
1214
|
-
|
|
1277
|
+
let headers;
|
|
1278
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1279
|
+
headers = { ...config.customHeaders };
|
|
1280
|
+
} else {
|
|
1281
|
+
headers = {
|
|
1282
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1283
|
+
"Content-Type": "application/json",
|
|
1284
|
+
Source: "sdk/createGroup"
|
|
1285
|
+
};
|
|
1286
|
+
}
|
|
1287
|
+
let endpoint = "https://api.pinata.cloud";
|
|
1288
|
+
if (config.endpointUrl) {
|
|
1289
|
+
endpoint = config.endpointUrl;
|
|
1215
1290
|
}
|
|
1216
|
-
headers["Source"] = headers["Source"] || "sdk/createGroup";
|
|
1217
1291
|
try {
|
|
1218
|
-
const request = await fetch(
|
|
1292
|
+
const request = await fetch(`${endpoint}/groups`, {
|
|
1219
1293
|
method: "POST",
|
|
1220
1294
|
headers,
|
|
1221
1295
|
body: data
|
|
@@ -1253,14 +1327,16 @@ var listGroups = async (config, options) => {
|
|
|
1253
1327
|
if (!config || !config.pinataJwt) {
|
|
1254
1328
|
throw new ValidationError("Pinata configuration or JWT is missing");
|
|
1255
1329
|
}
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
}
|
|
1260
|
-
|
|
1261
|
-
|
|
1330
|
+
let headers;
|
|
1331
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1332
|
+
headers = { ...config.customHeaders };
|
|
1333
|
+
} else {
|
|
1334
|
+
headers = {
|
|
1335
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1336
|
+
"Content-Type": "application/json",
|
|
1337
|
+
Source: "sdk/listGroups"
|
|
1338
|
+
};
|
|
1262
1339
|
}
|
|
1263
|
-
headers["Source"] = headers["Source"] || "sdk/listGroups";
|
|
1264
1340
|
const params = new URLSearchParams();
|
|
1265
1341
|
if (options) {
|
|
1266
1342
|
const { offset, nameContains, limit } = options;
|
|
@@ -1271,9 +1347,12 @@ var listGroups = async (config, options) => {
|
|
|
1271
1347
|
if (limit !== void 0)
|
|
1272
1348
|
params.append("limit", limit.toString());
|
|
1273
1349
|
}
|
|
1274
|
-
|
|
1350
|
+
let endpoint = "https://api.pinata.cloud";
|
|
1351
|
+
if (config.endpointUrl) {
|
|
1352
|
+
endpoint = config.endpointUrl;
|
|
1353
|
+
}
|
|
1275
1354
|
try {
|
|
1276
|
-
const request = await fetch(
|
|
1355
|
+
const request = await fetch(`${endpoint}/groups?${params.toString()}`, {
|
|
1277
1356
|
method: "GET",
|
|
1278
1357
|
headers
|
|
1279
1358
|
});
|
|
@@ -1310,22 +1389,25 @@ var getGroup = async (config, options) => {
|
|
|
1310
1389
|
if (!config || !config.pinataJwt) {
|
|
1311
1390
|
throw new ValidationError("Pinata configuration or JWT is missing");
|
|
1312
1391
|
}
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
}
|
|
1317
|
-
|
|
1318
|
-
|
|
1392
|
+
let headers;
|
|
1393
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1394
|
+
headers = { ...config.customHeaders };
|
|
1395
|
+
} else {
|
|
1396
|
+
headers = {
|
|
1397
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1398
|
+
"Content-Type": "application/json",
|
|
1399
|
+
Source: "sdk/getGroup"
|
|
1400
|
+
};
|
|
1401
|
+
}
|
|
1402
|
+
let endpoint = "https://api.pinata.cloud";
|
|
1403
|
+
if (config.endpointUrl) {
|
|
1404
|
+
endpoint = config.endpointUrl;
|
|
1319
1405
|
}
|
|
1320
|
-
headers["Source"] = headers["Source"] || "sdk/getGroup";
|
|
1321
1406
|
try {
|
|
1322
|
-
const request = await fetch(
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
headers
|
|
1327
|
-
}
|
|
1328
|
-
);
|
|
1407
|
+
const request = await fetch(`${endpoint}/groups/${options.groupId}`, {
|
|
1408
|
+
method: "GET",
|
|
1409
|
+
headers
|
|
1410
|
+
});
|
|
1329
1411
|
if (!request.ok) {
|
|
1330
1412
|
const errorData = await request.json();
|
|
1331
1413
|
if (request.status === 401) {
|
|
@@ -1364,23 +1446,26 @@ var addToGroup = async (config, options) => {
|
|
|
1364
1446
|
const data = JSON.stringify({
|
|
1365
1447
|
cids: options.cids
|
|
1366
1448
|
});
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
}
|
|
1371
|
-
|
|
1372
|
-
|
|
1449
|
+
let headers;
|
|
1450
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1451
|
+
headers = { ...config.customHeaders };
|
|
1452
|
+
} else {
|
|
1453
|
+
headers = {
|
|
1454
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1455
|
+
"Content-Type": "application/json",
|
|
1456
|
+
Source: "sdk/addToGroup"
|
|
1457
|
+
};
|
|
1458
|
+
}
|
|
1459
|
+
let endpoint = "https://api.pinata.cloud";
|
|
1460
|
+
if (config.endpointUrl) {
|
|
1461
|
+
endpoint = config.endpointUrl;
|
|
1373
1462
|
}
|
|
1374
|
-
headers["Source"] = headers["Source"] || "sdk/addToGroup";
|
|
1375
1463
|
try {
|
|
1376
|
-
const request = await fetch(
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
body: data
|
|
1382
|
-
}
|
|
1383
|
-
);
|
|
1464
|
+
const request = await fetch(`${endpoint}/groups/${options.groupId}/cids`, {
|
|
1465
|
+
method: "PUT",
|
|
1466
|
+
headers,
|
|
1467
|
+
body: data
|
|
1468
|
+
});
|
|
1384
1469
|
if (!request.ok) {
|
|
1385
1470
|
const errorData = await request.json();
|
|
1386
1471
|
if (request.status === 401) {
|
|
@@ -1419,23 +1504,26 @@ var updateGroup = async (config, options) => {
|
|
|
1419
1504
|
const data = JSON.stringify({
|
|
1420
1505
|
name: options.name
|
|
1421
1506
|
});
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
}
|
|
1426
|
-
|
|
1427
|
-
|
|
1507
|
+
let headers;
|
|
1508
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1509
|
+
headers = { ...config.customHeaders };
|
|
1510
|
+
} else {
|
|
1511
|
+
headers = {
|
|
1512
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1513
|
+
"Content-Type": "application/json",
|
|
1514
|
+
Source: "sdk/updateGroup"
|
|
1515
|
+
};
|
|
1516
|
+
}
|
|
1517
|
+
let endpoint = "https://api.pinata.cloud";
|
|
1518
|
+
if (config.endpointUrl) {
|
|
1519
|
+
endpoint = config.endpointUrl;
|
|
1428
1520
|
}
|
|
1429
|
-
headers["Source"] = headers["Source"] || "sdk/updateGroup";
|
|
1430
1521
|
try {
|
|
1431
|
-
const request = await fetch(
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
body: data
|
|
1437
|
-
}
|
|
1438
|
-
);
|
|
1522
|
+
const request = await fetch(`${endpoint}/groups/${options.groupId}`, {
|
|
1523
|
+
method: "PUT",
|
|
1524
|
+
headers,
|
|
1525
|
+
body: data
|
|
1526
|
+
});
|
|
1439
1527
|
if (!request.ok) {
|
|
1440
1528
|
const errorData = await request.json();
|
|
1441
1529
|
if (request.status === 401) {
|
|
@@ -1469,26 +1557,29 @@ var removeFromGroup = async (config, options) => {
|
|
|
1469
1557
|
if (!config || !config.pinataJwt) {
|
|
1470
1558
|
throw new ValidationError("Pinata configuration or JWT is missing");
|
|
1471
1559
|
}
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
}
|
|
1476
|
-
|
|
1477
|
-
|
|
1560
|
+
let headers;
|
|
1561
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1562
|
+
headers = { ...config.customHeaders };
|
|
1563
|
+
} else {
|
|
1564
|
+
headers = {
|
|
1565
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1566
|
+
"Content-Type": "application/json",
|
|
1567
|
+
Source: "sdk/removeFromGroup"
|
|
1568
|
+
};
|
|
1478
1569
|
}
|
|
1479
|
-
headers["Source"] = headers["Source"] || "sdk/removeFromGroup";
|
|
1480
1570
|
const data = JSON.stringify({
|
|
1481
1571
|
cids: options.cids
|
|
1482
1572
|
});
|
|
1573
|
+
let endpoint = "https://api.pinata.cloud";
|
|
1574
|
+
if (config.endpointUrl) {
|
|
1575
|
+
endpoint = config.endpointUrl;
|
|
1576
|
+
}
|
|
1483
1577
|
try {
|
|
1484
|
-
const request = await fetch(
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
body: data
|
|
1490
|
-
}
|
|
1491
|
-
);
|
|
1578
|
+
const request = await fetch(`${endpoint}/groups/${options.groupId}/cids`, {
|
|
1579
|
+
method: "DELETE",
|
|
1580
|
+
headers,
|
|
1581
|
+
body: data
|
|
1582
|
+
});
|
|
1492
1583
|
if (!request.ok) {
|
|
1493
1584
|
const errorData = await request.json();
|
|
1494
1585
|
if (request.status === 401) {
|
|
@@ -1526,22 +1617,25 @@ var deleteGroup = async (config, options) => {
|
|
|
1526
1617
|
if (!config || !config.pinataJwt) {
|
|
1527
1618
|
throw new ValidationError("Pinata configuration or JWT is missing");
|
|
1528
1619
|
}
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
}
|
|
1533
|
-
|
|
1534
|
-
|
|
1620
|
+
let headers;
|
|
1621
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1622
|
+
headers = { ...config.customHeaders };
|
|
1623
|
+
} else {
|
|
1624
|
+
headers = {
|
|
1625
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1626
|
+
"Content-Type": "application/json",
|
|
1627
|
+
Source: "sdk/deleteGroup"
|
|
1628
|
+
};
|
|
1629
|
+
}
|
|
1630
|
+
let endpoint = "https://api.pinata.cloud";
|
|
1631
|
+
if (config.endpointUrl) {
|
|
1632
|
+
endpoint = config.endpointUrl;
|
|
1535
1633
|
}
|
|
1536
|
-
headers["Source"] = headers["Source"] || "sdk/deleteGroup";
|
|
1537
1634
|
try {
|
|
1538
|
-
const request = await fetch(
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
headers
|
|
1543
|
-
}
|
|
1544
|
-
);
|
|
1635
|
+
const request = await fetch(`${endpoint}/groups/${options.groupId}`, {
|
|
1636
|
+
method: "DELETE",
|
|
1637
|
+
headers
|
|
1638
|
+
});
|
|
1545
1639
|
if (!request.ok) {
|
|
1546
1640
|
const errorData = await request.json();
|
|
1547
1641
|
if (request.status === 401) {
|
|
@@ -1578,17 +1672,23 @@ var addSignature = async (config, options) => {
|
|
|
1578
1672
|
const data = JSON.stringify({
|
|
1579
1673
|
signature: options.signature
|
|
1580
1674
|
});
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
}
|
|
1585
|
-
|
|
1586
|
-
|
|
1675
|
+
let headers;
|
|
1676
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1677
|
+
headers = { ...config.customHeaders };
|
|
1678
|
+
} else {
|
|
1679
|
+
headers = {
|
|
1680
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1681
|
+
"Content-Type": "application/json",
|
|
1682
|
+
Source: "sdk/addSignature"
|
|
1683
|
+
};
|
|
1684
|
+
}
|
|
1685
|
+
let endpoint = "https://api.pinata.cloud";
|
|
1686
|
+
if (config.endpointUrl) {
|
|
1687
|
+
endpoint = config.endpointUrl;
|
|
1587
1688
|
}
|
|
1588
|
-
headers["Source"] = headers["Source"] || "sdk/addSignature";
|
|
1589
1689
|
try {
|
|
1590
1690
|
const request = await fetch(
|
|
1591
|
-
|
|
1691
|
+
`${endpoint}/v3/ipfs/signature/${options.cid}`,
|
|
1592
1692
|
{
|
|
1593
1693
|
method: "POST",
|
|
1594
1694
|
headers,
|
|
@@ -1637,22 +1737,25 @@ var getSignature = async (config, cid) => {
|
|
|
1637
1737
|
if (!config || !config.pinataJwt) {
|
|
1638
1738
|
throw new ValidationError("Pinata configuration or JWT is missing");
|
|
1639
1739
|
}
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
}
|
|
1644
|
-
|
|
1645
|
-
|
|
1740
|
+
let headers;
|
|
1741
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1742
|
+
headers = { ...config.customHeaders };
|
|
1743
|
+
} else {
|
|
1744
|
+
headers = {
|
|
1745
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1746
|
+
"Content-Type": "application/json",
|
|
1747
|
+
Source: "sdk/getSignature"
|
|
1748
|
+
};
|
|
1749
|
+
}
|
|
1750
|
+
let endpoint = "https://api.pinata.cloud";
|
|
1751
|
+
if (config.endpointUrl) {
|
|
1752
|
+
endpoint = config.endpointUrl;
|
|
1646
1753
|
}
|
|
1647
|
-
headers["Source"] = headers["Source"] || "sdk/getSignature";
|
|
1648
1754
|
try {
|
|
1649
|
-
const request = await fetch(
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
headers
|
|
1654
|
-
}
|
|
1655
|
-
);
|
|
1755
|
+
const request = await fetch(`${endpoint}/v3/ipfs/signature/${cid}`, {
|
|
1756
|
+
method: "GET",
|
|
1757
|
+
headers
|
|
1758
|
+
});
|
|
1656
1759
|
if (!request.ok) {
|
|
1657
1760
|
const errorData = await request.json();
|
|
1658
1761
|
if (request.status === 401) {
|
|
@@ -1688,22 +1791,25 @@ var removeSignature = async (config, cid) => {
|
|
|
1688
1791
|
if (!config || !config.pinataJwt) {
|
|
1689
1792
|
throw new ValidationError("Pinata configuration or JWT is missing");
|
|
1690
1793
|
}
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
}
|
|
1695
|
-
|
|
1696
|
-
|
|
1794
|
+
let headers;
|
|
1795
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1796
|
+
headers = { ...config.customHeaders };
|
|
1797
|
+
} else {
|
|
1798
|
+
headers = {
|
|
1799
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1800
|
+
"Content-Type": "application/json",
|
|
1801
|
+
Source: "sdk/removeSignature"
|
|
1802
|
+
};
|
|
1803
|
+
}
|
|
1804
|
+
let endpoint = "https://api.pinata.cloud";
|
|
1805
|
+
if (config.endpointUrl) {
|
|
1806
|
+
endpoint = config.endpointUrl;
|
|
1697
1807
|
}
|
|
1698
|
-
headers["Source"] = headers["Source"] || "sdk/removeSignature";
|
|
1699
1808
|
try {
|
|
1700
|
-
const request = await fetch(
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
headers
|
|
1705
|
-
}
|
|
1706
|
-
);
|
|
1809
|
+
const request = await fetch(`${endpoint}/v3/ipfs/signature/${cid}`, {
|
|
1810
|
+
method: "DELETE",
|
|
1811
|
+
headers
|
|
1812
|
+
});
|
|
1707
1813
|
if (!request.ok) {
|
|
1708
1814
|
const errorData = await request.json();
|
|
1709
1815
|
if (request.status === 401) {
|
|
@@ -1733,6 +1839,210 @@ var removeSignature = async (config, cid) => {
|
|
|
1733
1839
|
}
|
|
1734
1840
|
};
|
|
1735
1841
|
|
|
1842
|
+
// src/core/gateway/analyticsTopUsage.ts
|
|
1843
|
+
var analyticsTopUsage = async (config, options) => {
|
|
1844
|
+
if (!config || !config.pinataJwt) {
|
|
1845
|
+
throw new ValidationError("Pinata configuration or JWT is missing");
|
|
1846
|
+
}
|
|
1847
|
+
const params = new URLSearchParams({
|
|
1848
|
+
includesCount: "false"
|
|
1849
|
+
});
|
|
1850
|
+
if (options) {
|
|
1851
|
+
const {
|
|
1852
|
+
cid,
|
|
1853
|
+
gateway_domain,
|
|
1854
|
+
start_date,
|
|
1855
|
+
end_date,
|
|
1856
|
+
file_name,
|
|
1857
|
+
user_agent,
|
|
1858
|
+
country,
|
|
1859
|
+
region,
|
|
1860
|
+
referer,
|
|
1861
|
+
limit,
|
|
1862
|
+
sort_order,
|
|
1863
|
+
sort_by,
|
|
1864
|
+
attribute
|
|
1865
|
+
} = options;
|
|
1866
|
+
if (cid)
|
|
1867
|
+
params.append("cid", cid);
|
|
1868
|
+
if (gateway_domain)
|
|
1869
|
+
params.append("gateway_domain", gateway_domain);
|
|
1870
|
+
if (start_date)
|
|
1871
|
+
params.append("start_date", start_date);
|
|
1872
|
+
if (end_date)
|
|
1873
|
+
params.append("end_date", end_date);
|
|
1874
|
+
if (file_name)
|
|
1875
|
+
params.append("file_name", file_name);
|
|
1876
|
+
if (user_agent)
|
|
1877
|
+
params.append("user_agent", user_agent.toString());
|
|
1878
|
+
if (country)
|
|
1879
|
+
params.append("country", country.toString());
|
|
1880
|
+
if (region)
|
|
1881
|
+
params.append("region", region);
|
|
1882
|
+
if (referer)
|
|
1883
|
+
params.append("referer", referer.toString());
|
|
1884
|
+
if (limit)
|
|
1885
|
+
params.append("limit", limit.toString());
|
|
1886
|
+
if (sort_order)
|
|
1887
|
+
params.append("sort_order", sort_order);
|
|
1888
|
+
if (sort_by)
|
|
1889
|
+
params.append("sort_by", sort_by);
|
|
1890
|
+
if (attribute)
|
|
1891
|
+
params.append("by", attribute);
|
|
1892
|
+
}
|
|
1893
|
+
let endpoint = "https://api.pinata.cloud";
|
|
1894
|
+
if (config.endpointUrl) {
|
|
1895
|
+
endpoint = config.endpointUrl;
|
|
1896
|
+
}
|
|
1897
|
+
const url = `${endpoint}/v3/ipfs/gateway_analytics_top?${params.toString()}`;
|
|
1898
|
+
try {
|
|
1899
|
+
let headers;
|
|
1900
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1901
|
+
headers = { ...config.customHeaders };
|
|
1902
|
+
} else {
|
|
1903
|
+
headers = {
|
|
1904
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1905
|
+
Source: "sdk/analyticsTopUsage"
|
|
1906
|
+
};
|
|
1907
|
+
}
|
|
1908
|
+
const request = await fetch(url, {
|
|
1909
|
+
method: "GET",
|
|
1910
|
+
headers
|
|
1911
|
+
});
|
|
1912
|
+
if (!request.ok) {
|
|
1913
|
+
const errorData = await request.json();
|
|
1914
|
+
if (request.status === 401) {
|
|
1915
|
+
throw new AuthenticationError(
|
|
1916
|
+
"Authentication failed",
|
|
1917
|
+
request.status,
|
|
1918
|
+
errorData
|
|
1919
|
+
);
|
|
1920
|
+
}
|
|
1921
|
+
throw new NetworkError(
|
|
1922
|
+
`HTTP error! status: ${request.status}`,
|
|
1923
|
+
request.status,
|
|
1924
|
+
errorData
|
|
1925
|
+
);
|
|
1926
|
+
}
|
|
1927
|
+
const res = await request.json();
|
|
1928
|
+
const resData = res.data;
|
|
1929
|
+
return resData;
|
|
1930
|
+
} catch (error) {
|
|
1931
|
+
if (error instanceof PinataError) {
|
|
1932
|
+
throw error;
|
|
1933
|
+
}
|
|
1934
|
+
if (error instanceof Error) {
|
|
1935
|
+
throw new PinataError(
|
|
1936
|
+
`Error processing anaytics usage: ${error.message}`
|
|
1937
|
+
);
|
|
1938
|
+
}
|
|
1939
|
+
throw new PinataError(
|
|
1940
|
+
"An unknown error occurred while fetching gateway usage"
|
|
1941
|
+
);
|
|
1942
|
+
}
|
|
1943
|
+
};
|
|
1944
|
+
|
|
1945
|
+
// src/core/gateway/analyticsDateInterval.ts
|
|
1946
|
+
var analyticsDateInterval = async (config, options) => {
|
|
1947
|
+
if (!config || !config.pinataJwt) {
|
|
1948
|
+
throw new ValidationError("Pinata configuration or JWT is missing");
|
|
1949
|
+
}
|
|
1950
|
+
const params = new URLSearchParams();
|
|
1951
|
+
if (options) {
|
|
1952
|
+
const {
|
|
1953
|
+
cid,
|
|
1954
|
+
gateway_domain,
|
|
1955
|
+
start_date,
|
|
1956
|
+
end_date,
|
|
1957
|
+
file_name,
|
|
1958
|
+
user_agent,
|
|
1959
|
+
country,
|
|
1960
|
+
region,
|
|
1961
|
+
referer,
|
|
1962
|
+
limit,
|
|
1963
|
+
sort_order,
|
|
1964
|
+
date_interval,
|
|
1965
|
+
sort_by
|
|
1966
|
+
} = options;
|
|
1967
|
+
if (cid)
|
|
1968
|
+
params.append("cid", cid);
|
|
1969
|
+
if (gateway_domain)
|
|
1970
|
+
params.append("gateway_domain", gateway_domain);
|
|
1971
|
+
if (start_date)
|
|
1972
|
+
params.append("start_date", start_date);
|
|
1973
|
+
if (end_date)
|
|
1974
|
+
params.append("end_date", end_date);
|
|
1975
|
+
if (file_name)
|
|
1976
|
+
params.append("file_name", file_name);
|
|
1977
|
+
if (user_agent)
|
|
1978
|
+
params.append("user_agent", user_agent.toString());
|
|
1979
|
+
if (country)
|
|
1980
|
+
params.append("country", country.toString());
|
|
1981
|
+
if (region)
|
|
1982
|
+
params.append("region", region);
|
|
1983
|
+
if (referer)
|
|
1984
|
+
params.append("referer", referer.toString());
|
|
1985
|
+
if (limit)
|
|
1986
|
+
params.append("limit", limit.toString());
|
|
1987
|
+
if (sort_order)
|
|
1988
|
+
params.append("sort_order", sort_order);
|
|
1989
|
+
if (sort_by)
|
|
1990
|
+
params.append("sort_by", sort_by);
|
|
1991
|
+
if (date_interval)
|
|
1992
|
+
params.append("by", date_interval);
|
|
1993
|
+
}
|
|
1994
|
+
let endpoint = "https://api.pinata.cloud";
|
|
1995
|
+
if (config.endpointUrl) {
|
|
1996
|
+
endpoint = config.endpointUrl;
|
|
1997
|
+
}
|
|
1998
|
+
const url = `${endpoint}/v3/ipfs/gateway_analytics_time_series?${params.toString()}`;
|
|
1999
|
+
try {
|
|
2000
|
+
let headers;
|
|
2001
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
2002
|
+
headers = { ...config.customHeaders };
|
|
2003
|
+
} else {
|
|
2004
|
+
headers = {
|
|
2005
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
2006
|
+
Source: "sdk/analyticsDateInterval"
|
|
2007
|
+
};
|
|
2008
|
+
}
|
|
2009
|
+
const request = await fetch(url, {
|
|
2010
|
+
method: "GET",
|
|
2011
|
+
headers
|
|
2012
|
+
});
|
|
2013
|
+
if (!request.ok) {
|
|
2014
|
+
const errorData = await request.json();
|
|
2015
|
+
if (request.status === 401) {
|
|
2016
|
+
throw new AuthenticationError(
|
|
2017
|
+
"Authentication failed",
|
|
2018
|
+
request.status,
|
|
2019
|
+
errorData
|
|
2020
|
+
);
|
|
2021
|
+
}
|
|
2022
|
+
throw new NetworkError(
|
|
2023
|
+
`HTTP error! status: ${request.status}`,
|
|
2024
|
+
request.status,
|
|
2025
|
+
errorData
|
|
2026
|
+
);
|
|
2027
|
+
}
|
|
2028
|
+
const res = await request.json();
|
|
2029
|
+
const resData = res.data;
|
|
2030
|
+
return resData;
|
|
2031
|
+
} catch (error) {
|
|
2032
|
+
if (error instanceof PinataError) {
|
|
2033
|
+
throw error;
|
|
2034
|
+
}
|
|
2035
|
+
if (error instanceof Error) {
|
|
2036
|
+
throw new PinataError(
|
|
2037
|
+
`Error processing anaytics usage: ${error.message}`
|
|
2038
|
+
);
|
|
2039
|
+
}
|
|
2040
|
+
throw new PinataError(
|
|
2041
|
+
"An unknown error occurred while fetching gateway usage"
|
|
2042
|
+
);
|
|
2043
|
+
}
|
|
2044
|
+
};
|
|
2045
|
+
|
|
1736
2046
|
// src/core/pinataSDK.ts
|
|
1737
2047
|
var formatConfig = (config) => {
|
|
1738
2048
|
let gateway = config?.pinataGateway;
|
|
@@ -1754,6 +2064,18 @@ var PinataSDK = class {
|
|
|
1754
2064
|
this.groups = new Groups(this.config);
|
|
1755
2065
|
this.signatures = new Signatures(this.config);
|
|
1756
2066
|
}
|
|
2067
|
+
setNewHeaders(headers) {
|
|
2068
|
+
if (!this.config) {
|
|
2069
|
+
this.config = { pinataJwt: "", customHeaders: {} };
|
|
2070
|
+
}
|
|
2071
|
+
this.config.customHeaders = { ...this.config.customHeaders, ...headers };
|
|
2072
|
+
this.upload.updateConfig(this.config);
|
|
2073
|
+
this.gateways.updateConfig(this.config);
|
|
2074
|
+
this.usage.updateConfig(this.config);
|
|
2075
|
+
this.keys.updateConfig(this.config);
|
|
2076
|
+
this.groups.updateConfig(this.config);
|
|
2077
|
+
this.signatures.updateConfig(this.config);
|
|
2078
|
+
}
|
|
1757
2079
|
testAuthentication() {
|
|
1758
2080
|
return testAuthentication(this.config);
|
|
1759
2081
|
}
|
|
@@ -1825,6 +2147,9 @@ var Upload = class {
|
|
|
1825
2147
|
constructor(config) {
|
|
1826
2148
|
this.config = formatConfig(config);
|
|
1827
2149
|
}
|
|
2150
|
+
updateConfig(newConfig) {
|
|
2151
|
+
this.config = newConfig;
|
|
2152
|
+
}
|
|
1828
2153
|
file(file, options) {
|
|
1829
2154
|
return new UploadBuilder(this.config, uploadFile, file, options);
|
|
1830
2155
|
}
|
|
@@ -1946,12 +2271,34 @@ var Gateways = class {
|
|
|
1946
2271
|
constructor(config) {
|
|
1947
2272
|
this.config = formatConfig(config);
|
|
1948
2273
|
}
|
|
2274
|
+
updateConfig(newConfig) {
|
|
2275
|
+
this.config = newConfig;
|
|
2276
|
+
}
|
|
1949
2277
|
get(cid) {
|
|
1950
2278
|
return getCid(this.config, cid);
|
|
1951
2279
|
}
|
|
1952
2280
|
convert(url) {
|
|
1953
2281
|
return convertIPFSUrl(this.config, url);
|
|
1954
2282
|
}
|
|
2283
|
+
topUsageAnalytics(options) {
|
|
2284
|
+
return new TopGatewayAnalyticsBuilder(
|
|
2285
|
+
this.config,
|
|
2286
|
+
options.domain,
|
|
2287
|
+
options.start,
|
|
2288
|
+
options.end,
|
|
2289
|
+
options.sortBy,
|
|
2290
|
+
options.attribute
|
|
2291
|
+
);
|
|
2292
|
+
}
|
|
2293
|
+
dateIntervalAnalytics(options) {
|
|
2294
|
+
return new TimeIntervalGatewayAnalyticsBuilder(
|
|
2295
|
+
this.config,
|
|
2296
|
+
options.domain,
|
|
2297
|
+
options.start,
|
|
2298
|
+
options.end,
|
|
2299
|
+
options.interval
|
|
2300
|
+
);
|
|
2301
|
+
}
|
|
1955
2302
|
};
|
|
1956
2303
|
var FilterPinJobs = class {
|
|
1957
2304
|
constructor(config) {
|
|
@@ -2031,6 +2378,9 @@ var Usage = class {
|
|
|
2031
2378
|
constructor(config) {
|
|
2032
2379
|
this.config = formatConfig(config);
|
|
2033
2380
|
}
|
|
2381
|
+
updateConfig(newConfig) {
|
|
2382
|
+
this.config = newConfig;
|
|
2383
|
+
}
|
|
2034
2384
|
pinnedFileCount() {
|
|
2035
2385
|
return pinnedFileCount(this.config);
|
|
2036
2386
|
}
|
|
@@ -2042,6 +2392,9 @@ var Keys = class {
|
|
|
2042
2392
|
constructor(config) {
|
|
2043
2393
|
this.config = formatConfig(config);
|
|
2044
2394
|
}
|
|
2395
|
+
updateConfig(newConfig) {
|
|
2396
|
+
this.config = newConfig;
|
|
2397
|
+
}
|
|
2045
2398
|
create(options) {
|
|
2046
2399
|
return createKey(this.config, options);
|
|
2047
2400
|
}
|
|
@@ -2128,6 +2481,9 @@ var Groups = class {
|
|
|
2128
2481
|
constructor(config) {
|
|
2129
2482
|
this.config = formatConfig(config);
|
|
2130
2483
|
}
|
|
2484
|
+
updateConfig(newConfig) {
|
|
2485
|
+
this.config = newConfig;
|
|
2486
|
+
}
|
|
2131
2487
|
create(options) {
|
|
2132
2488
|
return createGroup(this.config, options);
|
|
2133
2489
|
}
|
|
@@ -2218,6 +2574,9 @@ var Signatures = class {
|
|
|
2218
2574
|
constructor(config) {
|
|
2219
2575
|
this.config = formatConfig(config);
|
|
2220
2576
|
}
|
|
2577
|
+
updateConfig(newConfig) {
|
|
2578
|
+
this.config = newConfig;
|
|
2579
|
+
}
|
|
2221
2580
|
add(options) {
|
|
2222
2581
|
return addSignature(this.config, options);
|
|
2223
2582
|
}
|
|
@@ -2228,6 +2587,105 @@ var Signatures = class {
|
|
|
2228
2587
|
return removeSignature(this.config, cid);
|
|
2229
2588
|
}
|
|
2230
2589
|
};
|
|
2590
|
+
var GatewayAnalyticsBuilder = class {
|
|
2591
|
+
constructor(config, query) {
|
|
2592
|
+
this.requestCount = 0;
|
|
2593
|
+
this.lastRequestTime = 0;
|
|
2594
|
+
this.MAX_REQUESTS_PER_MINUTE = 30;
|
|
2595
|
+
this.MINUTE_IN_MS = 6e4;
|
|
2596
|
+
this.config = config;
|
|
2597
|
+
this.query = query;
|
|
2598
|
+
}
|
|
2599
|
+
cid(cid) {
|
|
2600
|
+
this.query.cid = cid;
|
|
2601
|
+
return this;
|
|
2602
|
+
}
|
|
2603
|
+
fileName(fileName) {
|
|
2604
|
+
this.query.file_name = fileName;
|
|
2605
|
+
return this;
|
|
2606
|
+
}
|
|
2607
|
+
userAgent(userAgent) {
|
|
2608
|
+
this.query.user_agent = userAgent;
|
|
2609
|
+
return this;
|
|
2610
|
+
}
|
|
2611
|
+
country(country) {
|
|
2612
|
+
this.query.country = country;
|
|
2613
|
+
return this;
|
|
2614
|
+
}
|
|
2615
|
+
region(region) {
|
|
2616
|
+
this.query.region = region;
|
|
2617
|
+
return this;
|
|
2618
|
+
}
|
|
2619
|
+
referer(referer) {
|
|
2620
|
+
this.query.referer = referer;
|
|
2621
|
+
return this;
|
|
2622
|
+
}
|
|
2623
|
+
limit(limit) {
|
|
2624
|
+
this.query.limit = limit;
|
|
2625
|
+
return this;
|
|
2626
|
+
}
|
|
2627
|
+
sort(order) {
|
|
2628
|
+
this.query.sort_order = order;
|
|
2629
|
+
return this;
|
|
2630
|
+
}
|
|
2631
|
+
async rateLimit() {
|
|
2632
|
+
this.requestCount++;
|
|
2633
|
+
const now = Date.now();
|
|
2634
|
+
if (this.requestCount >= this.MAX_REQUESTS_PER_MINUTE) {
|
|
2635
|
+
const timePassedSinceLastRequest = now - this.lastRequestTime;
|
|
2636
|
+
if (timePassedSinceLastRequest < this.MINUTE_IN_MS) {
|
|
2637
|
+
const delayTime = this.MINUTE_IN_MS - timePassedSinceLastRequest;
|
|
2638
|
+
await new Promise((resolve) => setTimeout(resolve, delayTime));
|
|
2639
|
+
}
|
|
2640
|
+
this.requestCount = 0;
|
|
2641
|
+
}
|
|
2642
|
+
this.lastRequestTime = Date.now();
|
|
2643
|
+
}
|
|
2644
|
+
async getAnalytics() {
|
|
2645
|
+
await this.rateLimit();
|
|
2646
|
+
throw new Error("getAnalytics method must be implemented in derived class");
|
|
2647
|
+
}
|
|
2648
|
+
then(onfulfilled) {
|
|
2649
|
+
return this.getAnalytics().then(onfulfilled);
|
|
2650
|
+
}
|
|
2651
|
+
};
|
|
2652
|
+
var TopGatewayAnalyticsBuilder = class extends GatewayAnalyticsBuilder {
|
|
2653
|
+
constructor(config, domain, start, end, sortBy, attribute) {
|
|
2654
|
+
super(config, {
|
|
2655
|
+
gateway_domain: domain,
|
|
2656
|
+
start_date: start,
|
|
2657
|
+
end_date: end,
|
|
2658
|
+
sort_by: sortBy,
|
|
2659
|
+
attribute
|
|
2660
|
+
});
|
|
2661
|
+
}
|
|
2662
|
+
async getAnalytics() {
|
|
2663
|
+
return analyticsTopUsage(this.config, this.query);
|
|
2664
|
+
}
|
|
2665
|
+
async all() {
|
|
2666
|
+
return this.getAnalytics();
|
|
2667
|
+
}
|
|
2668
|
+
};
|
|
2669
|
+
var TimeIntervalGatewayAnalyticsBuilder = class extends GatewayAnalyticsBuilder {
|
|
2670
|
+
constructor(config, domain, start, end, dateInterval) {
|
|
2671
|
+
super(config, {
|
|
2672
|
+
gateway_domain: domain,
|
|
2673
|
+
start_date: start,
|
|
2674
|
+
end_date: end,
|
|
2675
|
+
date_interval: dateInterval
|
|
2676
|
+
});
|
|
2677
|
+
}
|
|
2678
|
+
sortBy(sortBy) {
|
|
2679
|
+
this.query.sort_by = sortBy;
|
|
2680
|
+
return this;
|
|
2681
|
+
}
|
|
2682
|
+
async getAnalytics() {
|
|
2683
|
+
return analyticsDateInterval(this.config, this.query);
|
|
2684
|
+
}
|
|
2685
|
+
async all() {
|
|
2686
|
+
return this.getAnalytics();
|
|
2687
|
+
}
|
|
2688
|
+
};
|
|
2231
2689
|
export {
|
|
2232
2690
|
PinataSDK
|
|
2233
2691
|
};
|