pinata 0.1.9 → 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 +90 -2
- package/dist/index.d.ts +90 -2
- package/dist/index.js +816 -351
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +816 -351
- package/dist/index.mjs.map +1 -1
- package/package.json +44 -50
package/dist/index.js
CHANGED
|
@@ -67,21 +67,24 @@ var testAuthentication = async (config) => {
|
|
|
67
67
|
if (!config || !config.pinataJwt) {
|
|
68
68
|
throw new ValidationError("Pinata configuration or JWT is missing");
|
|
69
69
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
70
|
+
let headers;
|
|
71
|
+
let endpoint = "https://api.pinata.cloud";
|
|
72
|
+
if (config.endpointUrl) {
|
|
73
|
+
endpoint = config.endpointUrl;
|
|
74
|
+
}
|
|
75
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
76
|
+
headers = { ...config.customHeaders };
|
|
77
|
+
} else {
|
|
78
|
+
headers = {
|
|
79
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
80
|
+
Source: "sdk/testAuthentication"
|
|
81
|
+
};
|
|
75
82
|
}
|
|
76
|
-
headers["Source"] = headers["Source"] || "sdk/testAuthentication";
|
|
77
83
|
try {
|
|
78
|
-
const request = await fetch(
|
|
79
|
-
"
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
headers
|
|
83
|
-
}
|
|
84
|
-
);
|
|
84
|
+
const request = await fetch(`${endpoint}/data/testAuthentication`, {
|
|
85
|
+
method: "GET",
|
|
86
|
+
headers
|
|
87
|
+
});
|
|
85
88
|
if (!request.ok) {
|
|
86
89
|
const errorData = await request.json();
|
|
87
90
|
if (request.status === 401) {
|
|
@@ -132,26 +135,29 @@ var uploadFile = async (config, file, options) => {
|
|
|
132
135
|
data.append(
|
|
133
136
|
"pinataMetadata",
|
|
134
137
|
JSON.stringify({
|
|
135
|
-
name: options?.metadata
|
|
138
|
+
name: options?.metadata?.name || file.name || "File from SDK",
|
|
136
139
|
keyvalues: options?.metadata?.keyValues
|
|
137
140
|
})
|
|
138
141
|
);
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
142
|
+
let headers;
|
|
143
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
144
|
+
headers = { ...config.customHeaders };
|
|
145
|
+
} else {
|
|
146
|
+
headers = {
|
|
147
|
+
Authorization: `Bearer ${jwt}`,
|
|
148
|
+
Source: "sdk/file"
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
let endpoint = "https://api.pinata.cloud";
|
|
152
|
+
if (config.endpointUrl) {
|
|
153
|
+
endpoint = config.endpointUrl;
|
|
144
154
|
}
|
|
145
|
-
headers["Source"] = headers["Source"] || "sdk/file";
|
|
146
155
|
try {
|
|
147
|
-
const request = await fetch(
|
|
148
|
-
"
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
body: data
|
|
153
|
-
}
|
|
154
|
-
);
|
|
156
|
+
const request = await fetch(`${endpoint}/pinning/pinFileToIPFS`, {
|
|
157
|
+
method: "POST",
|
|
158
|
+
headers,
|
|
159
|
+
body: data
|
|
160
|
+
});
|
|
155
161
|
if (!request.ok) {
|
|
156
162
|
const errorData = await request.json();
|
|
157
163
|
if (request.status === 401) {
|
|
@@ -186,7 +192,7 @@ var uploadFileArray = async (config, files, options) => {
|
|
|
186
192
|
throw new ValidationError("Pinata configuration or JWT is missing");
|
|
187
193
|
}
|
|
188
194
|
const jwt = options?.keys || config?.pinataJwt;
|
|
189
|
-
const folder = options?.metadata?.name
|
|
195
|
+
const folder = options?.metadata?.name || "folder_from_sdk";
|
|
190
196
|
const data = new FormData();
|
|
191
197
|
for (const file of Array.from(files)) {
|
|
192
198
|
data.append("file", file, `${folder}/${file.name}`);
|
|
@@ -205,22 +211,25 @@ var uploadFileArray = async (config, files, options) => {
|
|
|
205
211
|
groupId: options?.groupId
|
|
206
212
|
})
|
|
207
213
|
);
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
214
|
+
let headers;
|
|
215
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
216
|
+
headers = { ...config.customHeaders };
|
|
217
|
+
} else {
|
|
218
|
+
headers = {
|
|
219
|
+
Authorization: `Bearer ${jwt}`,
|
|
220
|
+
Source: "sdk/fileArray"
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
let endpoint = "https://api.pinata.cloud";
|
|
224
|
+
if (config.endpointUrl) {
|
|
225
|
+
endpoint = config.endpointUrl;
|
|
213
226
|
}
|
|
214
|
-
headers["Source"] = headers["Source"] || "sdk/fileArray";
|
|
215
227
|
try {
|
|
216
|
-
const request = await fetch(
|
|
217
|
-
"
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
body: data
|
|
222
|
-
}
|
|
223
|
-
);
|
|
228
|
+
const request = await fetch(`${endpoint}/pinning/pinFileToIPFS`, {
|
|
229
|
+
method: "POST",
|
|
230
|
+
headers,
|
|
231
|
+
body: data
|
|
232
|
+
});
|
|
224
233
|
if (!request.ok) {
|
|
225
234
|
const errorData = await request.json();
|
|
226
235
|
if (request.status === 401) {
|
|
@@ -276,22 +285,25 @@ var uploadBase64 = async (config, base64String, options) => {
|
|
|
276
285
|
keyvalues: options?.metadata?.keyValues
|
|
277
286
|
})
|
|
278
287
|
);
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
288
|
+
let headers;
|
|
289
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
290
|
+
headers = { ...config.customHeaders };
|
|
291
|
+
} else {
|
|
292
|
+
headers = {
|
|
293
|
+
Authorization: `Bearer ${jwt}`,
|
|
294
|
+
Source: "sdk/base64"
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
let endpoint = "https://api.pinata.cloud";
|
|
298
|
+
if (config.endpointUrl) {
|
|
299
|
+
endpoint = config.endpointUrl;
|
|
284
300
|
}
|
|
285
|
-
headers["Source"] = headers["Source"] || "sdk/base64";
|
|
286
301
|
try {
|
|
287
|
-
const request = await fetch(
|
|
288
|
-
"
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
body: data
|
|
293
|
-
}
|
|
294
|
-
);
|
|
302
|
+
const request = await fetch(`${endpoint}/pinning/pinFileToIPFS`, {
|
|
303
|
+
method: "POST",
|
|
304
|
+
headers,
|
|
305
|
+
body: data
|
|
306
|
+
});
|
|
295
307
|
if (!request.ok) {
|
|
296
308
|
const errorData = await request.json();
|
|
297
309
|
if (request.status === 401) {
|
|
@@ -357,22 +369,25 @@ var uploadUrl = async (config, url, options) => {
|
|
|
357
369
|
keyvalues: options?.metadata?.keyValues
|
|
358
370
|
})
|
|
359
371
|
);
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
372
|
+
let headers;
|
|
373
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
374
|
+
headers = { ...config.customHeaders };
|
|
375
|
+
} else {
|
|
376
|
+
headers = {
|
|
377
|
+
Authorization: `Bearer ${jwt}`,
|
|
378
|
+
Source: "sdk/url"
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
let endpoint = "https://api.pinata.cloud";
|
|
382
|
+
if (config.endpointUrl) {
|
|
383
|
+
endpoint = config.endpointUrl;
|
|
365
384
|
}
|
|
366
|
-
headers["Source"] = headers["Source"] || "sdk/url";
|
|
367
385
|
try {
|
|
368
|
-
const request = await fetch(
|
|
369
|
-
"
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
body: data
|
|
374
|
-
}
|
|
375
|
-
);
|
|
386
|
+
const request = await fetch(`${endpoint}/pinning/pinFileToIPFS`, {
|
|
387
|
+
method: "POST",
|
|
388
|
+
headers,
|
|
389
|
+
body: data
|
|
390
|
+
});
|
|
376
391
|
if (!request.ok) {
|
|
377
392
|
const errorData = await request.json();
|
|
378
393
|
if (request.status === 401) {
|
|
@@ -414,27 +429,30 @@ var uploadJson = async (config, jsonData, options) => {
|
|
|
414
429
|
groupId: options?.groupId
|
|
415
430
|
},
|
|
416
431
|
pinataMetadata: {
|
|
417
|
-
name: options?.metadata
|
|
432
|
+
name: options?.metadata?.name || "json",
|
|
418
433
|
keyvalues: options?.metadata?.keyValues
|
|
419
434
|
}
|
|
420
435
|
});
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
|
|
436
|
+
let headers;
|
|
437
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
438
|
+
headers = { ...config.customHeaders };
|
|
439
|
+
} else {
|
|
440
|
+
headers = {
|
|
441
|
+
Authorization: `Bearer ${jwt}`,
|
|
442
|
+
"Content-Type": "application/json",
|
|
443
|
+
Source: "sdk/json"
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
let endpoint = "https://api.pinata.cloud";
|
|
447
|
+
if (config.endpointUrl) {
|
|
448
|
+
endpoint = config.endpointUrl;
|
|
427
449
|
}
|
|
428
|
-
headers["Source"] = headers["Source"] || "sdk/json";
|
|
429
450
|
try {
|
|
430
|
-
const request = await fetch(
|
|
431
|
-
"
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
body: data
|
|
436
|
-
}
|
|
437
|
-
);
|
|
451
|
+
const request = await fetch(`${endpoint}/pinning/pinJSONToIPFS`, {
|
|
452
|
+
method: "POST",
|
|
453
|
+
headers,
|
|
454
|
+
body: data
|
|
455
|
+
});
|
|
438
456
|
if (!request.ok) {
|
|
439
457
|
const errorData = await request.json();
|
|
440
458
|
if (request.status === 401) {
|
|
@@ -464,23 +482,25 @@ var uploadJson = async (config, jsonData, options) => {
|
|
|
464
482
|
};
|
|
465
483
|
|
|
466
484
|
// src/core/pinning/cid.ts
|
|
467
|
-
var uploadCid = async (config,
|
|
485
|
+
var uploadCid = async (config, cid, options) => {
|
|
468
486
|
if (!config || !config.pinataJwt) {
|
|
469
487
|
throw new ValidationError("Pinata configuration or JWT is missing");
|
|
470
488
|
}
|
|
471
489
|
const jwt = options?.keys || config?.pinataJwt;
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
|
|
490
|
+
let headers;
|
|
491
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
492
|
+
headers = { ...config.customHeaders };
|
|
493
|
+
} else {
|
|
494
|
+
headers = {
|
|
495
|
+
Authorization: `Bearer ${jwt}`,
|
|
496
|
+
"Content-Type": "application/json",
|
|
497
|
+
Source: "sdk/cid"
|
|
498
|
+
};
|
|
478
499
|
}
|
|
479
|
-
headers["Source"] = headers["Source"] || "sdk/cid";
|
|
480
500
|
const data = JSON.stringify({
|
|
481
|
-
hashToPin:
|
|
501
|
+
hashToPin: cid,
|
|
482
502
|
pinataMetadata: {
|
|
483
|
-
name: options?.metadata ? options?.metadata?.name :
|
|
503
|
+
name: options?.metadata ? options?.metadata?.name : cid,
|
|
484
504
|
keyvalues: options?.metadata?.keyValues
|
|
485
505
|
},
|
|
486
506
|
pinataOptions: {
|
|
@@ -488,8 +508,12 @@ var uploadCid = async (config, cid2, options) => {
|
|
|
488
508
|
groupId: options?.groupId
|
|
489
509
|
}
|
|
490
510
|
});
|
|
511
|
+
let endpoint = "https://api.pinata.cloud";
|
|
512
|
+
if (config.endpointUrl) {
|
|
513
|
+
endpoint = config.endpointUrl;
|
|
514
|
+
}
|
|
491
515
|
try {
|
|
492
|
-
const request = await fetch(
|
|
516
|
+
const request = await fetch(`${endpoint}/pinning/pinByHash`, {
|
|
493
517
|
method: "POST",
|
|
494
518
|
headers,
|
|
495
519
|
body: data
|
|
@@ -533,23 +557,25 @@ var unpinFile = async (config, files) => {
|
|
|
533
557
|
throw new ValidationError("Pinata configuration or JWT is missing");
|
|
534
558
|
}
|
|
535
559
|
const responses = [];
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
|
|
560
|
+
let headers;
|
|
561
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
562
|
+
headers = { ...config.customHeaders };
|
|
563
|
+
} else {
|
|
564
|
+
headers = {
|
|
565
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
566
|
+
Source: "sdk/unpin"
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
let endpoint = "https://api.pinata.cloud";
|
|
570
|
+
if (config.endpointUrl) {
|
|
571
|
+
endpoint = config.endpointUrl;
|
|
542
572
|
}
|
|
543
|
-
headers["Source"] = headers["Source"] || "sdk/unpin";
|
|
544
573
|
for (const hash of files) {
|
|
545
574
|
try {
|
|
546
|
-
const response = await fetch(
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
headers
|
|
551
|
-
}
|
|
552
|
-
);
|
|
575
|
+
const response = await fetch(`${endpoint}/pinning/unpin/${hash}`, {
|
|
576
|
+
method: "DELETE",
|
|
577
|
+
headers
|
|
578
|
+
});
|
|
553
579
|
await wait(300);
|
|
554
580
|
if (!response.ok) {
|
|
555
581
|
const errorData = await response.json();
|
|
@@ -599,7 +625,7 @@ var listFiles = async (config, options) => {
|
|
|
599
625
|
});
|
|
600
626
|
if (options) {
|
|
601
627
|
const {
|
|
602
|
-
cid
|
|
628
|
+
cid,
|
|
603
629
|
pinStart,
|
|
604
630
|
pinEnd,
|
|
605
631
|
pinSizeMin,
|
|
@@ -612,8 +638,8 @@ var listFiles = async (config, options) => {
|
|
|
612
638
|
operator,
|
|
613
639
|
groupId
|
|
614
640
|
} = options;
|
|
615
|
-
if (
|
|
616
|
-
params.append("cid",
|
|
641
|
+
if (cid)
|
|
642
|
+
params.append("cid", cid);
|
|
617
643
|
if (pinStart)
|
|
618
644
|
params.append("pinStart", pinStart);
|
|
619
645
|
if (pinEnd)
|
|
@@ -637,15 +663,21 @@ var listFiles = async (config, options) => {
|
|
|
637
663
|
params.append("metadata[keyvalues]", keyValueParam);
|
|
638
664
|
}
|
|
639
665
|
}
|
|
640
|
-
|
|
666
|
+
let endpoint = "https://api.pinata.cloud";
|
|
667
|
+
if (config.endpointUrl) {
|
|
668
|
+
endpoint = config.endpointUrl;
|
|
669
|
+
}
|
|
670
|
+
const url = `${endpoint}/data/pinList?status=pinned&${params.toString()}`;
|
|
641
671
|
try {
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
672
|
+
let headers;
|
|
673
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
674
|
+
headers = { ...config.customHeaders };
|
|
675
|
+
} else {
|
|
676
|
+
headers = {
|
|
677
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
678
|
+
Source: "sdk/listFiles"
|
|
679
|
+
};
|
|
647
680
|
}
|
|
648
|
-
headers["Source"] = headers["Source"] || "sdk/listFiles";
|
|
649
681
|
const request = await fetch(url, {
|
|
650
682
|
method: "GET",
|
|
651
683
|
headers
|
|
@@ -688,23 +720,26 @@ var updateMetadata = async (config, options) => {
|
|
|
688
720
|
name: options.name,
|
|
689
721
|
keyvalues: options.keyValues
|
|
690
722
|
};
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
|
|
723
|
+
let headers;
|
|
724
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
725
|
+
headers = { ...config.customHeaders };
|
|
726
|
+
} else {
|
|
727
|
+
headers = {
|
|
728
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
729
|
+
"Content-Type": "application/json",
|
|
730
|
+
Source: "sdk/updateMetadata"
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
let endpoint = "https://api.pinata.cloud";
|
|
734
|
+
if (config.endpointUrl) {
|
|
735
|
+
endpoint = config.endpointUrl;
|
|
697
736
|
}
|
|
698
|
-
headers["Source"] = headers["Source"] || "sdk/updateMetadata";
|
|
699
737
|
try {
|
|
700
|
-
const request = await fetch(
|
|
701
|
-
"
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
body: JSON.stringify(data)
|
|
706
|
-
}
|
|
707
|
-
);
|
|
738
|
+
const request = await fetch(`${endpoint}/pinning/hashMetadata`, {
|
|
739
|
+
method: "PUT",
|
|
740
|
+
headers,
|
|
741
|
+
body: JSON.stringify(data)
|
|
742
|
+
});
|
|
708
743
|
if (!request.ok) {
|
|
709
744
|
const errorData = await request.json();
|
|
710
745
|
if (request.status === 401) {
|
|
@@ -736,11 +771,18 @@ var updateMetadata = async (config, options) => {
|
|
|
736
771
|
};
|
|
737
772
|
|
|
738
773
|
// src/utils/gateway-tools.ts
|
|
739
|
-
var
|
|
740
|
-
function
|
|
774
|
+
var isIPFSModule;
|
|
775
|
+
async function getIsIPFS() {
|
|
776
|
+
if (!isIPFSModule) {
|
|
777
|
+
isIPFSModule = await import("is-ipfs");
|
|
778
|
+
}
|
|
779
|
+
return isIPFSModule;
|
|
780
|
+
}
|
|
781
|
+
async function containsCID(input) {
|
|
741
782
|
if (typeof input !== "string") {
|
|
742
783
|
throw new Error("Input is not a string");
|
|
743
784
|
}
|
|
785
|
+
const isIPFS = await getIsIPFS();
|
|
744
786
|
const startsWithCID = (str) => {
|
|
745
787
|
const parts = str.split("/");
|
|
746
788
|
return isIPFS.cid(parts[0]) ? parts[0] : null;
|
|
@@ -758,11 +800,11 @@ function containsCID(input) {
|
|
|
758
800
|
} catch (error) {
|
|
759
801
|
const parts = input.split(/\/|\?/);
|
|
760
802
|
for (const part of parts) {
|
|
761
|
-
const
|
|
762
|
-
if (
|
|
803
|
+
const cid = startsWithCID(part);
|
|
804
|
+
if (cid) {
|
|
763
805
|
return {
|
|
764
806
|
containsCid: true,
|
|
765
|
-
cid
|
|
807
|
+
cid
|
|
766
808
|
};
|
|
767
809
|
}
|
|
768
810
|
}
|
|
@@ -782,11 +824,11 @@ function containsCID(input) {
|
|
|
782
824
|
}
|
|
783
825
|
const pathParts = url.pathname.split("/");
|
|
784
826
|
for (const part of pathParts) {
|
|
785
|
-
const
|
|
786
|
-
if (
|
|
827
|
+
const cid = startsWithCID(part);
|
|
828
|
+
if (cid) {
|
|
787
829
|
return {
|
|
788
830
|
containsCid: true,
|
|
789
|
-
cid
|
|
831
|
+
cid
|
|
790
832
|
};
|
|
791
833
|
}
|
|
792
834
|
}
|
|
@@ -795,8 +837,8 @@ function containsCID(input) {
|
|
|
795
837
|
cid: null
|
|
796
838
|
};
|
|
797
839
|
}
|
|
798
|
-
function convertToDesiredGateway(sourceUrl, desiredGatewayPrefix) {
|
|
799
|
-
const results = containsCID(sourceUrl);
|
|
840
|
+
async function convertToDesiredGateway(sourceUrl, desiredGatewayPrefix) {
|
|
841
|
+
const results = await containsCID(sourceUrl);
|
|
800
842
|
if (results.containsCid !== true) {
|
|
801
843
|
throw new Error("url does not contain CID");
|
|
802
844
|
}
|
|
@@ -823,13 +865,13 @@ function convertToDesiredGateway(sourceUrl, desiredGatewayPrefix) {
|
|
|
823
865
|
}
|
|
824
866
|
|
|
825
867
|
// src/core/gateway/getCid.ts
|
|
826
|
-
var getCid = async (config,
|
|
868
|
+
var getCid = async (config, cid) => {
|
|
827
869
|
if (!config || !config.pinataJwt) {
|
|
828
870
|
throw new ValidationError("Pinata configuration or JWT is missing");
|
|
829
871
|
}
|
|
830
872
|
let data;
|
|
831
873
|
let newUrl;
|
|
832
|
-
newUrl = convertToDesiredGateway(
|
|
874
|
+
newUrl = await convertToDesiredGateway(cid, config?.pinataGateway);
|
|
833
875
|
if (config?.pinataGatewayKey) {
|
|
834
876
|
newUrl = `${newUrl}?pinataGatewayToken=${config?.pinataGatewayKey}`;
|
|
835
877
|
}
|
|
@@ -882,9 +924,9 @@ var getCid = async (config, cid2) => {
|
|
|
882
924
|
};
|
|
883
925
|
|
|
884
926
|
// src/core/gateway/convertIPFSUrl.ts
|
|
885
|
-
var convertIPFSUrl = (config, url) => {
|
|
927
|
+
var convertIPFSUrl = async (config, url) => {
|
|
886
928
|
let newUrl;
|
|
887
|
-
newUrl = convertToDesiredGateway(url, config?.pinataGateway);
|
|
929
|
+
newUrl = await convertToDesiredGateway(url, config?.pinataGateway);
|
|
888
930
|
if (config?.pinataGatewayKey) {
|
|
889
931
|
`${newUrl}?pinataGatewayToken=${config?.pinataGatewayKey}`;
|
|
890
932
|
}
|
|
@@ -900,9 +942,9 @@ var pinJobs = async (config, options) => {
|
|
|
900
942
|
includesCount: "false"
|
|
901
943
|
});
|
|
902
944
|
if (options) {
|
|
903
|
-
const { ipfs_pin_hash:
|
|
904
|
-
if (
|
|
905
|
-
params.append("ipfs_pin_hash",
|
|
945
|
+
const { ipfs_pin_hash: cid, status, sort, limit, offset } = options;
|
|
946
|
+
if (cid)
|
|
947
|
+
params.append("ipfs_pin_hash", cid.toString());
|
|
906
948
|
if (status)
|
|
907
949
|
params.append("status", status.toString());
|
|
908
950
|
if (sort)
|
|
@@ -912,14 +954,20 @@ var pinJobs = async (config, options) => {
|
|
|
912
954
|
if (offset)
|
|
913
955
|
params.append("offset", offset.toString());
|
|
914
956
|
}
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
}
|
|
919
|
-
|
|
920
|
-
|
|
957
|
+
let endpoint = "https://api.pinata.cloud";
|
|
958
|
+
if (config.endpointUrl) {
|
|
959
|
+
endpoint = config.endpointUrl;
|
|
960
|
+
}
|
|
961
|
+
const url = `${endpoint}/pinning/pinJobs?${params.toString()}`;
|
|
962
|
+
let headers;
|
|
963
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
964
|
+
headers = { ...config.customHeaders };
|
|
965
|
+
} else {
|
|
966
|
+
headers = {
|
|
967
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
968
|
+
Source: "sdk/pinJobs"
|
|
969
|
+
};
|
|
921
970
|
}
|
|
922
|
-
headers["Source"] = headers["Source"] || "sdk/pinJobs";
|
|
923
971
|
try {
|
|
924
972
|
const request = await fetch(url, {
|
|
925
973
|
method: "GET",
|
|
@@ -958,16 +1006,21 @@ var pinnedFileCount = async (config) => {
|
|
|
958
1006
|
if (!config || !config.pinataJwt) {
|
|
959
1007
|
throw new ValidationError("Pinata configuration or JWT is missing");
|
|
960
1008
|
}
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
}
|
|
965
|
-
|
|
966
|
-
|
|
1009
|
+
let endpoint = "https://api.pinata.cloud";
|
|
1010
|
+
if (config.endpointUrl) {
|
|
1011
|
+
endpoint = config.endpointUrl;
|
|
1012
|
+
}
|
|
1013
|
+
let headers;
|
|
1014
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1015
|
+
headers = { ...config.customHeaders };
|
|
1016
|
+
} else {
|
|
1017
|
+
headers = {
|
|
1018
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1019
|
+
Source: "sdk/pinnedFileUsage"
|
|
1020
|
+
};
|
|
967
1021
|
}
|
|
968
|
-
headers["Source"] = headers["Source"] || "sdk/pinnedFileUsage";
|
|
969
1022
|
try {
|
|
970
|
-
const request = await fetch(
|
|
1023
|
+
const request = await fetch(`${endpoint}/data/userPinnedDataTotal`, {
|
|
971
1024
|
method: "GET",
|
|
972
1025
|
headers
|
|
973
1026
|
});
|
|
@@ -1008,16 +1061,21 @@ var totalStorageUsage = async (config) => {
|
|
|
1008
1061
|
if (!config || !config.pinataJwt) {
|
|
1009
1062
|
throw new ValidationError("Pinata configuration or JWT is missing");
|
|
1010
1063
|
}
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
}
|
|
1015
|
-
|
|
1016
|
-
|
|
1064
|
+
let endpoint = "https://api.pinata.cloud";
|
|
1065
|
+
if (config.endpointUrl) {
|
|
1066
|
+
endpoint = config.endpointUrl;
|
|
1067
|
+
}
|
|
1068
|
+
let headers;
|
|
1069
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1070
|
+
headers = { ...config.customHeaders };
|
|
1071
|
+
} else {
|
|
1072
|
+
headers = {
|
|
1073
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1074
|
+
Source: "sdk/totalStorageUsage"
|
|
1075
|
+
};
|
|
1017
1076
|
}
|
|
1018
|
-
headers["Source"] = headers["Source"] || "sdk/totalStorageUsage";
|
|
1019
1077
|
try {
|
|
1020
|
-
const request = await fetch(
|
|
1078
|
+
const request = await fetch(`${endpoint}/data/userPinnedDataTotal`, {
|
|
1021
1079
|
method: "GET",
|
|
1022
1080
|
headers
|
|
1023
1081
|
});
|
|
@@ -1058,17 +1116,23 @@ var createKey = async (config, options) => {
|
|
|
1058
1116
|
if (!config || !config.pinataJwt) {
|
|
1059
1117
|
throw new ValidationError("Pinata configuration or JWT is missing");
|
|
1060
1118
|
}
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
}
|
|
1065
|
-
|
|
1066
|
-
|
|
1119
|
+
let headers;
|
|
1120
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1121
|
+
headers = { ...config.customHeaders };
|
|
1122
|
+
} else {
|
|
1123
|
+
headers = {
|
|
1124
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1125
|
+
"Content-Type": "application/json",
|
|
1126
|
+
Source: "sdk/createKey"
|
|
1127
|
+
};
|
|
1067
1128
|
}
|
|
1068
|
-
headers["Source"] = headers["Source"] || "sdk/createKey";
|
|
1069
1129
|
const data = JSON.stringify(options);
|
|
1130
|
+
let endpoint = "https://api.pinata.cloud";
|
|
1131
|
+
if (config.endpointUrl) {
|
|
1132
|
+
endpoint = config.endpointUrl;
|
|
1133
|
+
}
|
|
1070
1134
|
try {
|
|
1071
|
-
const request = await fetch(
|
|
1135
|
+
const request = await fetch(`${endpoint}/v3/pinata/keys`, {
|
|
1072
1136
|
method: "POST",
|
|
1073
1137
|
headers,
|
|
1074
1138
|
body: data
|
|
@@ -1106,14 +1170,16 @@ var listKeys = async (config, options) => {
|
|
|
1106
1170
|
if (!config || !config.pinataJwt) {
|
|
1107
1171
|
throw new ValidationError("Pinata configuration or JWT is missing");
|
|
1108
1172
|
}
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
}
|
|
1113
|
-
|
|
1114
|
-
|
|
1173
|
+
let headers;
|
|
1174
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1175
|
+
headers = { ...config.customHeaders };
|
|
1176
|
+
} else {
|
|
1177
|
+
headers = {
|
|
1178
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1179
|
+
"Content-Type": "application/json",
|
|
1180
|
+
Source: "sdk/listKeys"
|
|
1181
|
+
};
|
|
1115
1182
|
}
|
|
1116
|
-
headers["Source"] = headers["Source"] || "sdk/listKeys";
|
|
1117
1183
|
const params = new URLSearchParams();
|
|
1118
1184
|
if (options) {
|
|
1119
1185
|
const { offset, name, revoked, limitedUse, exhausted } = options;
|
|
@@ -1128,12 +1194,18 @@ var listKeys = async (config, options) => {
|
|
|
1128
1194
|
if (name)
|
|
1129
1195
|
params.append("name", name);
|
|
1130
1196
|
}
|
|
1131
|
-
|
|
1197
|
+
let endpoint = "https://api.pinata.cloud";
|
|
1198
|
+
if (config.endpointUrl) {
|
|
1199
|
+
endpoint = config.endpointUrl;
|
|
1200
|
+
}
|
|
1132
1201
|
try {
|
|
1133
|
-
const request = await fetch(
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1202
|
+
const request = await fetch(
|
|
1203
|
+
`${endpoint}/v3/pinata/keys?${params.toString()}`,
|
|
1204
|
+
{
|
|
1205
|
+
method: "GET",
|
|
1206
|
+
headers
|
|
1207
|
+
}
|
|
1208
|
+
);
|
|
1137
1209
|
if (!request.ok) {
|
|
1138
1210
|
const errorData = await request.json();
|
|
1139
1211
|
if (request.status === 401) {
|
|
@@ -1172,24 +1244,27 @@ var revokeKeys = async (config, keys) => {
|
|
|
1172
1244
|
if (!config || !config.pinataJwt) {
|
|
1173
1245
|
throw new ValidationError("Pinata configuration or JWT is missing");
|
|
1174
1246
|
}
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
}
|
|
1179
|
-
|
|
1180
|
-
|
|
1247
|
+
let headers;
|
|
1248
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1249
|
+
headers = { ...config.customHeaders };
|
|
1250
|
+
} else {
|
|
1251
|
+
headers = {
|
|
1252
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1253
|
+
"Content-Type": "application/json",
|
|
1254
|
+
Source: "sdk/revokeKeys"
|
|
1255
|
+
};
|
|
1181
1256
|
}
|
|
1182
|
-
headers["Source"] = headers["Source"] || "sdk/revokeKeys";
|
|
1183
1257
|
const responses = [];
|
|
1258
|
+
let endpoint = "https://api.pinata.cloud";
|
|
1259
|
+
if (config.endpointUrl) {
|
|
1260
|
+
endpoint = config.endpointUrl;
|
|
1261
|
+
}
|
|
1184
1262
|
for (const key of keys) {
|
|
1185
1263
|
try {
|
|
1186
|
-
const request = await fetch(
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
headers
|
|
1191
|
-
}
|
|
1192
|
-
);
|
|
1264
|
+
const request = await fetch(`${endpoint}/v3/pinata/keys/${key}`, {
|
|
1265
|
+
method: "PUT",
|
|
1266
|
+
headers
|
|
1267
|
+
});
|
|
1193
1268
|
await wait2(300);
|
|
1194
1269
|
if (!request.ok) {
|
|
1195
1270
|
const errorData = await request.json();
|
|
@@ -1235,16 +1310,22 @@ var createGroup = async (config, options) => {
|
|
|
1235
1310
|
throw new ValidationError("Pinata configuration or JWT is missing");
|
|
1236
1311
|
}
|
|
1237
1312
|
const data = JSON.stringify(options);
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
}
|
|
1242
|
-
|
|
1243
|
-
|
|
1313
|
+
let headers;
|
|
1314
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1315
|
+
headers = { ...config.customHeaders };
|
|
1316
|
+
} else {
|
|
1317
|
+
headers = {
|
|
1318
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1319
|
+
"Content-Type": "application/json",
|
|
1320
|
+
Source: "sdk/createGroup"
|
|
1321
|
+
};
|
|
1322
|
+
}
|
|
1323
|
+
let endpoint = "https://api.pinata.cloud";
|
|
1324
|
+
if (config.endpointUrl) {
|
|
1325
|
+
endpoint = config.endpointUrl;
|
|
1244
1326
|
}
|
|
1245
|
-
headers["Source"] = headers["Source"] || "sdk/createGroup";
|
|
1246
1327
|
try {
|
|
1247
|
-
const request = await fetch(
|
|
1328
|
+
const request = await fetch(`${endpoint}/groups`, {
|
|
1248
1329
|
method: "POST",
|
|
1249
1330
|
headers,
|
|
1250
1331
|
body: data
|
|
@@ -1282,14 +1363,16 @@ var listGroups = async (config, options) => {
|
|
|
1282
1363
|
if (!config || !config.pinataJwt) {
|
|
1283
1364
|
throw new ValidationError("Pinata configuration or JWT is missing");
|
|
1284
1365
|
}
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
}
|
|
1289
|
-
|
|
1290
|
-
|
|
1366
|
+
let headers;
|
|
1367
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1368
|
+
headers = { ...config.customHeaders };
|
|
1369
|
+
} else {
|
|
1370
|
+
headers = {
|
|
1371
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1372
|
+
"Content-Type": "application/json",
|
|
1373
|
+
Source: "sdk/listGroups"
|
|
1374
|
+
};
|
|
1291
1375
|
}
|
|
1292
|
-
headers["Source"] = headers["Source"] || "sdk/listGroups";
|
|
1293
1376
|
const params = new URLSearchParams();
|
|
1294
1377
|
if (options) {
|
|
1295
1378
|
const { offset, nameContains, limit } = options;
|
|
@@ -1300,9 +1383,12 @@ var listGroups = async (config, options) => {
|
|
|
1300
1383
|
if (limit !== void 0)
|
|
1301
1384
|
params.append("limit", limit.toString());
|
|
1302
1385
|
}
|
|
1303
|
-
|
|
1386
|
+
let endpoint = "https://api.pinata.cloud";
|
|
1387
|
+
if (config.endpointUrl) {
|
|
1388
|
+
endpoint = config.endpointUrl;
|
|
1389
|
+
}
|
|
1304
1390
|
try {
|
|
1305
|
-
const request = await fetch(
|
|
1391
|
+
const request = await fetch(`${endpoint}/groups?${params.toString()}`, {
|
|
1306
1392
|
method: "GET",
|
|
1307
1393
|
headers
|
|
1308
1394
|
});
|
|
@@ -1339,22 +1425,25 @@ var getGroup = async (config, options) => {
|
|
|
1339
1425
|
if (!config || !config.pinataJwt) {
|
|
1340
1426
|
throw new ValidationError("Pinata configuration or JWT is missing");
|
|
1341
1427
|
}
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
}
|
|
1346
|
-
|
|
1347
|
-
|
|
1428
|
+
let headers;
|
|
1429
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1430
|
+
headers = { ...config.customHeaders };
|
|
1431
|
+
} else {
|
|
1432
|
+
headers = {
|
|
1433
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1434
|
+
"Content-Type": "application/json",
|
|
1435
|
+
Source: "sdk/getGroup"
|
|
1436
|
+
};
|
|
1437
|
+
}
|
|
1438
|
+
let endpoint = "https://api.pinata.cloud";
|
|
1439
|
+
if (config.endpointUrl) {
|
|
1440
|
+
endpoint = config.endpointUrl;
|
|
1348
1441
|
}
|
|
1349
|
-
headers["Source"] = headers["Source"] || "sdk/getGroup";
|
|
1350
1442
|
try {
|
|
1351
|
-
const request = await fetch(
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
headers
|
|
1356
|
-
}
|
|
1357
|
-
);
|
|
1443
|
+
const request = await fetch(`${endpoint}/groups/${options.groupId}`, {
|
|
1444
|
+
method: "GET",
|
|
1445
|
+
headers
|
|
1446
|
+
});
|
|
1358
1447
|
if (!request.ok) {
|
|
1359
1448
|
const errorData = await request.json();
|
|
1360
1449
|
if (request.status === 401) {
|
|
@@ -1393,23 +1482,26 @@ var addToGroup = async (config, options) => {
|
|
|
1393
1482
|
const data = JSON.stringify({
|
|
1394
1483
|
cids: options.cids
|
|
1395
1484
|
});
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
}
|
|
1400
|
-
|
|
1401
|
-
|
|
1485
|
+
let headers;
|
|
1486
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1487
|
+
headers = { ...config.customHeaders };
|
|
1488
|
+
} else {
|
|
1489
|
+
headers = {
|
|
1490
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1491
|
+
"Content-Type": "application/json",
|
|
1492
|
+
Source: "sdk/addToGroup"
|
|
1493
|
+
};
|
|
1494
|
+
}
|
|
1495
|
+
let endpoint = "https://api.pinata.cloud";
|
|
1496
|
+
if (config.endpointUrl) {
|
|
1497
|
+
endpoint = config.endpointUrl;
|
|
1402
1498
|
}
|
|
1403
|
-
headers["Source"] = headers["Source"] || "sdk/addToGroup";
|
|
1404
1499
|
try {
|
|
1405
|
-
const request = await fetch(
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
body: data
|
|
1411
|
-
}
|
|
1412
|
-
);
|
|
1500
|
+
const request = await fetch(`${endpoint}/groups/${options.groupId}/cids`, {
|
|
1501
|
+
method: "PUT",
|
|
1502
|
+
headers,
|
|
1503
|
+
body: data
|
|
1504
|
+
});
|
|
1413
1505
|
if (!request.ok) {
|
|
1414
1506
|
const errorData = await request.json();
|
|
1415
1507
|
if (request.status === 401) {
|
|
@@ -1448,23 +1540,26 @@ var updateGroup = async (config, options) => {
|
|
|
1448
1540
|
const data = JSON.stringify({
|
|
1449
1541
|
name: options.name
|
|
1450
1542
|
});
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
}
|
|
1455
|
-
|
|
1456
|
-
|
|
1543
|
+
let headers;
|
|
1544
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1545
|
+
headers = { ...config.customHeaders };
|
|
1546
|
+
} else {
|
|
1547
|
+
headers = {
|
|
1548
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1549
|
+
"Content-Type": "application/json",
|
|
1550
|
+
Source: "sdk/updateGroup"
|
|
1551
|
+
};
|
|
1552
|
+
}
|
|
1553
|
+
let endpoint = "https://api.pinata.cloud";
|
|
1554
|
+
if (config.endpointUrl) {
|
|
1555
|
+
endpoint = config.endpointUrl;
|
|
1457
1556
|
}
|
|
1458
|
-
headers["Source"] = headers["Source"] || "sdk/updateGroup";
|
|
1459
1557
|
try {
|
|
1460
|
-
const request = await fetch(
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
body: data
|
|
1466
|
-
}
|
|
1467
|
-
);
|
|
1558
|
+
const request = await fetch(`${endpoint}/groups/${options.groupId}`, {
|
|
1559
|
+
method: "PUT",
|
|
1560
|
+
headers,
|
|
1561
|
+
body: data
|
|
1562
|
+
});
|
|
1468
1563
|
if (!request.ok) {
|
|
1469
1564
|
const errorData = await request.json();
|
|
1470
1565
|
if (request.status === 401) {
|
|
@@ -1498,26 +1593,29 @@ var removeFromGroup = async (config, options) => {
|
|
|
1498
1593
|
if (!config || !config.pinataJwt) {
|
|
1499
1594
|
throw new ValidationError("Pinata configuration or JWT is missing");
|
|
1500
1595
|
}
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
}
|
|
1505
|
-
|
|
1506
|
-
|
|
1596
|
+
let headers;
|
|
1597
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1598
|
+
headers = { ...config.customHeaders };
|
|
1599
|
+
} else {
|
|
1600
|
+
headers = {
|
|
1601
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1602
|
+
"Content-Type": "application/json",
|
|
1603
|
+
Source: "sdk/removeFromGroup"
|
|
1604
|
+
};
|
|
1507
1605
|
}
|
|
1508
|
-
headers["Source"] = headers["Source"] || "sdk/removeFromGroup";
|
|
1509
1606
|
const data = JSON.stringify({
|
|
1510
1607
|
cids: options.cids
|
|
1511
1608
|
});
|
|
1609
|
+
let endpoint = "https://api.pinata.cloud";
|
|
1610
|
+
if (config.endpointUrl) {
|
|
1611
|
+
endpoint = config.endpointUrl;
|
|
1612
|
+
}
|
|
1512
1613
|
try {
|
|
1513
|
-
const request = await fetch(
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
body: data
|
|
1519
|
-
}
|
|
1520
|
-
);
|
|
1614
|
+
const request = await fetch(`${endpoint}/groups/${options.groupId}/cids`, {
|
|
1615
|
+
method: "DELETE",
|
|
1616
|
+
headers,
|
|
1617
|
+
body: data
|
|
1618
|
+
});
|
|
1521
1619
|
if (!request.ok) {
|
|
1522
1620
|
const errorData = await request.json();
|
|
1523
1621
|
if (request.status === 401) {
|
|
@@ -1555,22 +1653,25 @@ var deleteGroup = async (config, options) => {
|
|
|
1555
1653
|
if (!config || !config.pinataJwt) {
|
|
1556
1654
|
throw new ValidationError("Pinata configuration or JWT is missing");
|
|
1557
1655
|
}
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
}
|
|
1562
|
-
|
|
1563
|
-
|
|
1656
|
+
let headers;
|
|
1657
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1658
|
+
headers = { ...config.customHeaders };
|
|
1659
|
+
} else {
|
|
1660
|
+
headers = {
|
|
1661
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1662
|
+
"Content-Type": "application/json",
|
|
1663
|
+
Source: "sdk/deleteGroup"
|
|
1664
|
+
};
|
|
1665
|
+
}
|
|
1666
|
+
let endpoint = "https://api.pinata.cloud";
|
|
1667
|
+
if (config.endpointUrl) {
|
|
1668
|
+
endpoint = config.endpointUrl;
|
|
1564
1669
|
}
|
|
1565
|
-
headers["Source"] = headers["Source"] || "sdk/deleteGroup";
|
|
1566
1670
|
try {
|
|
1567
|
-
const request = await fetch(
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
headers
|
|
1572
|
-
}
|
|
1573
|
-
);
|
|
1671
|
+
const request = await fetch(`${endpoint}/groups/${options.groupId}`, {
|
|
1672
|
+
method: "DELETE",
|
|
1673
|
+
headers
|
|
1674
|
+
});
|
|
1574
1675
|
if (!request.ok) {
|
|
1575
1676
|
const errorData = await request.json();
|
|
1576
1677
|
if (request.status === 401) {
|
|
@@ -1607,17 +1708,23 @@ var addSignature = async (config, options) => {
|
|
|
1607
1708
|
const data = JSON.stringify({
|
|
1608
1709
|
signature: options.signature
|
|
1609
1710
|
});
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
}
|
|
1614
|
-
|
|
1615
|
-
|
|
1711
|
+
let headers;
|
|
1712
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1713
|
+
headers = { ...config.customHeaders };
|
|
1714
|
+
} else {
|
|
1715
|
+
headers = {
|
|
1716
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1717
|
+
"Content-Type": "application/json",
|
|
1718
|
+
Source: "sdk/addSignature"
|
|
1719
|
+
};
|
|
1720
|
+
}
|
|
1721
|
+
let endpoint = "https://api.pinata.cloud";
|
|
1722
|
+
if (config.endpointUrl) {
|
|
1723
|
+
endpoint = config.endpointUrl;
|
|
1616
1724
|
}
|
|
1617
|
-
headers["Source"] = headers["Source"] || "sdk/addSignature";
|
|
1618
1725
|
try {
|
|
1619
1726
|
const request = await fetch(
|
|
1620
|
-
|
|
1727
|
+
`${endpoint}/v3/ipfs/signature/${options.cid}`,
|
|
1621
1728
|
{
|
|
1622
1729
|
method: "POST",
|
|
1623
1730
|
headers,
|
|
@@ -1662,26 +1769,29 @@ var addSignature = async (config, options) => {
|
|
|
1662
1769
|
};
|
|
1663
1770
|
|
|
1664
1771
|
// src/core/signatures/getSignature.ts
|
|
1665
|
-
var getSignature = async (config,
|
|
1772
|
+
var getSignature = async (config, cid) => {
|
|
1666
1773
|
if (!config || !config.pinataJwt) {
|
|
1667
1774
|
throw new ValidationError("Pinata configuration or JWT is missing");
|
|
1668
1775
|
}
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
}
|
|
1673
|
-
|
|
1674
|
-
|
|
1776
|
+
let headers;
|
|
1777
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1778
|
+
headers = { ...config.customHeaders };
|
|
1779
|
+
} else {
|
|
1780
|
+
headers = {
|
|
1781
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1782
|
+
"Content-Type": "application/json",
|
|
1783
|
+
Source: "sdk/getSignature"
|
|
1784
|
+
};
|
|
1785
|
+
}
|
|
1786
|
+
let endpoint = "https://api.pinata.cloud";
|
|
1787
|
+
if (config.endpointUrl) {
|
|
1788
|
+
endpoint = config.endpointUrl;
|
|
1675
1789
|
}
|
|
1676
|
-
headers["Source"] = headers["Source"] || "sdk/getSignature";
|
|
1677
1790
|
try {
|
|
1678
|
-
const request = await fetch(
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
headers
|
|
1683
|
-
}
|
|
1684
|
-
);
|
|
1791
|
+
const request = await fetch(`${endpoint}/v3/ipfs/signature/${cid}`, {
|
|
1792
|
+
method: "GET",
|
|
1793
|
+
headers
|
|
1794
|
+
});
|
|
1685
1795
|
if (!request.ok) {
|
|
1686
1796
|
const errorData = await request.json();
|
|
1687
1797
|
if (request.status === 401) {
|
|
@@ -1713,26 +1823,29 @@ var getSignature = async (config, cid2) => {
|
|
|
1713
1823
|
};
|
|
1714
1824
|
|
|
1715
1825
|
// src/core/signatures/removeSignature.ts
|
|
1716
|
-
var removeSignature = async (config,
|
|
1826
|
+
var removeSignature = async (config, cid) => {
|
|
1717
1827
|
if (!config || !config.pinataJwt) {
|
|
1718
1828
|
throw new ValidationError("Pinata configuration or JWT is missing");
|
|
1719
1829
|
}
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
}
|
|
1724
|
-
|
|
1725
|
-
|
|
1830
|
+
let headers;
|
|
1831
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1832
|
+
headers = { ...config.customHeaders };
|
|
1833
|
+
} else {
|
|
1834
|
+
headers = {
|
|
1835
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1836
|
+
"Content-Type": "application/json",
|
|
1837
|
+
Source: "sdk/removeSignature"
|
|
1838
|
+
};
|
|
1839
|
+
}
|
|
1840
|
+
let endpoint = "https://api.pinata.cloud";
|
|
1841
|
+
if (config.endpointUrl) {
|
|
1842
|
+
endpoint = config.endpointUrl;
|
|
1726
1843
|
}
|
|
1727
|
-
headers["Source"] = headers["Source"] || "sdk/removeSignature";
|
|
1728
1844
|
try {
|
|
1729
|
-
const request = await fetch(
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
headers
|
|
1734
|
-
}
|
|
1735
|
-
);
|
|
1845
|
+
const request = await fetch(`${endpoint}/v3/ipfs/signature/${cid}`, {
|
|
1846
|
+
method: "DELETE",
|
|
1847
|
+
headers
|
|
1848
|
+
});
|
|
1736
1849
|
if (!request.ok) {
|
|
1737
1850
|
const errorData = await request.json();
|
|
1738
1851
|
if (request.status === 401) {
|
|
@@ -1762,6 +1875,210 @@ var removeSignature = async (config, cid2) => {
|
|
|
1762
1875
|
}
|
|
1763
1876
|
};
|
|
1764
1877
|
|
|
1878
|
+
// src/core/gateway/analyticsTopUsage.ts
|
|
1879
|
+
var analyticsTopUsage = async (config, options) => {
|
|
1880
|
+
if (!config || !config.pinataJwt) {
|
|
1881
|
+
throw new ValidationError("Pinata configuration or JWT is missing");
|
|
1882
|
+
}
|
|
1883
|
+
const params = new URLSearchParams({
|
|
1884
|
+
includesCount: "false"
|
|
1885
|
+
});
|
|
1886
|
+
if (options) {
|
|
1887
|
+
const {
|
|
1888
|
+
cid,
|
|
1889
|
+
gateway_domain,
|
|
1890
|
+
start_date,
|
|
1891
|
+
end_date,
|
|
1892
|
+
file_name,
|
|
1893
|
+
user_agent,
|
|
1894
|
+
country,
|
|
1895
|
+
region,
|
|
1896
|
+
referer,
|
|
1897
|
+
limit,
|
|
1898
|
+
sort_order,
|
|
1899
|
+
sort_by,
|
|
1900
|
+
attribute
|
|
1901
|
+
} = options;
|
|
1902
|
+
if (cid)
|
|
1903
|
+
params.append("cid", cid);
|
|
1904
|
+
if (gateway_domain)
|
|
1905
|
+
params.append("gateway_domain", gateway_domain);
|
|
1906
|
+
if (start_date)
|
|
1907
|
+
params.append("start_date", start_date);
|
|
1908
|
+
if (end_date)
|
|
1909
|
+
params.append("end_date", end_date);
|
|
1910
|
+
if (file_name)
|
|
1911
|
+
params.append("file_name", file_name);
|
|
1912
|
+
if (user_agent)
|
|
1913
|
+
params.append("user_agent", user_agent.toString());
|
|
1914
|
+
if (country)
|
|
1915
|
+
params.append("country", country.toString());
|
|
1916
|
+
if (region)
|
|
1917
|
+
params.append("region", region);
|
|
1918
|
+
if (referer)
|
|
1919
|
+
params.append("referer", referer.toString());
|
|
1920
|
+
if (limit)
|
|
1921
|
+
params.append("limit", limit.toString());
|
|
1922
|
+
if (sort_order)
|
|
1923
|
+
params.append("sort_order", sort_order);
|
|
1924
|
+
if (sort_by)
|
|
1925
|
+
params.append("sort_by", sort_by);
|
|
1926
|
+
if (attribute)
|
|
1927
|
+
params.append("by", attribute);
|
|
1928
|
+
}
|
|
1929
|
+
let endpoint = "https://api.pinata.cloud";
|
|
1930
|
+
if (config.endpointUrl) {
|
|
1931
|
+
endpoint = config.endpointUrl;
|
|
1932
|
+
}
|
|
1933
|
+
const url = `${endpoint}/v3/ipfs/gateway_analytics_top?${params.toString()}`;
|
|
1934
|
+
try {
|
|
1935
|
+
let headers;
|
|
1936
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1937
|
+
headers = { ...config.customHeaders };
|
|
1938
|
+
} else {
|
|
1939
|
+
headers = {
|
|
1940
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1941
|
+
Source: "sdk/analyticsTopUsage"
|
|
1942
|
+
};
|
|
1943
|
+
}
|
|
1944
|
+
const request = await fetch(url, {
|
|
1945
|
+
method: "GET",
|
|
1946
|
+
headers
|
|
1947
|
+
});
|
|
1948
|
+
if (!request.ok) {
|
|
1949
|
+
const errorData = await request.json();
|
|
1950
|
+
if (request.status === 401) {
|
|
1951
|
+
throw new AuthenticationError(
|
|
1952
|
+
"Authentication failed",
|
|
1953
|
+
request.status,
|
|
1954
|
+
errorData
|
|
1955
|
+
);
|
|
1956
|
+
}
|
|
1957
|
+
throw new NetworkError(
|
|
1958
|
+
`HTTP error! status: ${request.status}`,
|
|
1959
|
+
request.status,
|
|
1960
|
+
errorData
|
|
1961
|
+
);
|
|
1962
|
+
}
|
|
1963
|
+
const res = await request.json();
|
|
1964
|
+
const resData = res.data;
|
|
1965
|
+
return resData;
|
|
1966
|
+
} catch (error) {
|
|
1967
|
+
if (error instanceof PinataError) {
|
|
1968
|
+
throw error;
|
|
1969
|
+
}
|
|
1970
|
+
if (error instanceof Error) {
|
|
1971
|
+
throw new PinataError(
|
|
1972
|
+
`Error processing anaytics usage: ${error.message}`
|
|
1973
|
+
);
|
|
1974
|
+
}
|
|
1975
|
+
throw new PinataError(
|
|
1976
|
+
"An unknown error occurred while fetching gateway usage"
|
|
1977
|
+
);
|
|
1978
|
+
}
|
|
1979
|
+
};
|
|
1980
|
+
|
|
1981
|
+
// src/core/gateway/analyticsDateInterval.ts
|
|
1982
|
+
var analyticsDateInterval = async (config, options) => {
|
|
1983
|
+
if (!config || !config.pinataJwt) {
|
|
1984
|
+
throw new ValidationError("Pinata configuration or JWT is missing");
|
|
1985
|
+
}
|
|
1986
|
+
const params = new URLSearchParams();
|
|
1987
|
+
if (options) {
|
|
1988
|
+
const {
|
|
1989
|
+
cid,
|
|
1990
|
+
gateway_domain,
|
|
1991
|
+
start_date,
|
|
1992
|
+
end_date,
|
|
1993
|
+
file_name,
|
|
1994
|
+
user_agent,
|
|
1995
|
+
country,
|
|
1996
|
+
region,
|
|
1997
|
+
referer,
|
|
1998
|
+
limit,
|
|
1999
|
+
sort_order,
|
|
2000
|
+
date_interval,
|
|
2001
|
+
sort_by
|
|
2002
|
+
} = options;
|
|
2003
|
+
if (cid)
|
|
2004
|
+
params.append("cid", cid);
|
|
2005
|
+
if (gateway_domain)
|
|
2006
|
+
params.append("gateway_domain", gateway_domain);
|
|
2007
|
+
if (start_date)
|
|
2008
|
+
params.append("start_date", start_date);
|
|
2009
|
+
if (end_date)
|
|
2010
|
+
params.append("end_date", end_date);
|
|
2011
|
+
if (file_name)
|
|
2012
|
+
params.append("file_name", file_name);
|
|
2013
|
+
if (user_agent)
|
|
2014
|
+
params.append("user_agent", user_agent.toString());
|
|
2015
|
+
if (country)
|
|
2016
|
+
params.append("country", country.toString());
|
|
2017
|
+
if (region)
|
|
2018
|
+
params.append("region", region);
|
|
2019
|
+
if (referer)
|
|
2020
|
+
params.append("referer", referer.toString());
|
|
2021
|
+
if (limit)
|
|
2022
|
+
params.append("limit", limit.toString());
|
|
2023
|
+
if (sort_order)
|
|
2024
|
+
params.append("sort_order", sort_order);
|
|
2025
|
+
if (sort_by)
|
|
2026
|
+
params.append("sort_by", sort_by);
|
|
2027
|
+
if (date_interval)
|
|
2028
|
+
params.append("by", date_interval);
|
|
2029
|
+
}
|
|
2030
|
+
let endpoint = "https://api.pinata.cloud";
|
|
2031
|
+
if (config.endpointUrl) {
|
|
2032
|
+
endpoint = config.endpointUrl;
|
|
2033
|
+
}
|
|
2034
|
+
const url = `${endpoint}/v3/ipfs/gateway_analytics_time_series?${params.toString()}`;
|
|
2035
|
+
try {
|
|
2036
|
+
let headers;
|
|
2037
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
2038
|
+
headers = { ...config.customHeaders };
|
|
2039
|
+
} else {
|
|
2040
|
+
headers = {
|
|
2041
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
2042
|
+
Source: "sdk/analyticsDateInterval"
|
|
2043
|
+
};
|
|
2044
|
+
}
|
|
2045
|
+
const request = await fetch(url, {
|
|
2046
|
+
method: "GET",
|
|
2047
|
+
headers
|
|
2048
|
+
});
|
|
2049
|
+
if (!request.ok) {
|
|
2050
|
+
const errorData = await request.json();
|
|
2051
|
+
if (request.status === 401) {
|
|
2052
|
+
throw new AuthenticationError(
|
|
2053
|
+
"Authentication failed",
|
|
2054
|
+
request.status,
|
|
2055
|
+
errorData
|
|
2056
|
+
);
|
|
2057
|
+
}
|
|
2058
|
+
throw new NetworkError(
|
|
2059
|
+
`HTTP error! status: ${request.status}`,
|
|
2060
|
+
request.status,
|
|
2061
|
+
errorData
|
|
2062
|
+
);
|
|
2063
|
+
}
|
|
2064
|
+
const res = await request.json();
|
|
2065
|
+
const resData = res.data;
|
|
2066
|
+
return resData;
|
|
2067
|
+
} catch (error) {
|
|
2068
|
+
if (error instanceof PinataError) {
|
|
2069
|
+
throw error;
|
|
2070
|
+
}
|
|
2071
|
+
if (error instanceof Error) {
|
|
2072
|
+
throw new PinataError(
|
|
2073
|
+
`Error processing anaytics usage: ${error.message}`
|
|
2074
|
+
);
|
|
2075
|
+
}
|
|
2076
|
+
throw new PinataError(
|
|
2077
|
+
"An unknown error occurred while fetching gateway usage"
|
|
2078
|
+
);
|
|
2079
|
+
}
|
|
2080
|
+
};
|
|
2081
|
+
|
|
1765
2082
|
// src/core/pinataSDK.ts
|
|
1766
2083
|
var formatConfig = (config) => {
|
|
1767
2084
|
let gateway = config?.pinataGateway;
|
|
@@ -1783,6 +2100,18 @@ var PinataSDK = class {
|
|
|
1783
2100
|
this.groups = new Groups(this.config);
|
|
1784
2101
|
this.signatures = new Signatures(this.config);
|
|
1785
2102
|
}
|
|
2103
|
+
setNewHeaders(headers) {
|
|
2104
|
+
if (!this.config) {
|
|
2105
|
+
this.config = { pinataJwt: "", customHeaders: {} };
|
|
2106
|
+
}
|
|
2107
|
+
this.config.customHeaders = { ...this.config.customHeaders, ...headers };
|
|
2108
|
+
this.upload.updateConfig(this.config);
|
|
2109
|
+
this.gateways.updateConfig(this.config);
|
|
2110
|
+
this.usage.updateConfig(this.config);
|
|
2111
|
+
this.keys.updateConfig(this.config);
|
|
2112
|
+
this.groups.updateConfig(this.config);
|
|
2113
|
+
this.signatures.updateConfig(this.config);
|
|
2114
|
+
}
|
|
1786
2115
|
testAuthentication() {
|
|
1787
2116
|
return testAuthentication(this.config);
|
|
1788
2117
|
}
|
|
@@ -1854,6 +2183,9 @@ var Upload = class {
|
|
|
1854
2183
|
constructor(config) {
|
|
1855
2184
|
this.config = formatConfig(config);
|
|
1856
2185
|
}
|
|
2186
|
+
updateConfig(newConfig) {
|
|
2187
|
+
this.config = newConfig;
|
|
2188
|
+
}
|
|
1857
2189
|
file(file, options) {
|
|
1858
2190
|
return new UploadBuilder(this.config, uploadFile, file, options);
|
|
1859
2191
|
}
|
|
@@ -1869,8 +2201,8 @@ var Upload = class {
|
|
|
1869
2201
|
json(data, options) {
|
|
1870
2202
|
return new UploadBuilder(this.config, uploadJson, data, options);
|
|
1871
2203
|
}
|
|
1872
|
-
cid(
|
|
1873
|
-
return new UploadBuilder(this.config, uploadCid,
|
|
2204
|
+
cid(cid, options) {
|
|
2205
|
+
return new UploadBuilder(this.config, uploadCid, cid, options);
|
|
1874
2206
|
}
|
|
1875
2207
|
};
|
|
1876
2208
|
var FilterFiles = class {
|
|
@@ -1883,8 +2215,8 @@ var FilterFiles = class {
|
|
|
1883
2215
|
this.MINUTE_IN_MS = 6e4;
|
|
1884
2216
|
this.config = config;
|
|
1885
2217
|
}
|
|
1886
|
-
cid(
|
|
1887
|
-
this.query.cid =
|
|
2218
|
+
cid(cid) {
|
|
2219
|
+
this.query.cid = cid;
|
|
1888
2220
|
return this;
|
|
1889
2221
|
}
|
|
1890
2222
|
pinStart(date) {
|
|
@@ -1975,12 +2307,34 @@ var Gateways = class {
|
|
|
1975
2307
|
constructor(config) {
|
|
1976
2308
|
this.config = formatConfig(config);
|
|
1977
2309
|
}
|
|
1978
|
-
|
|
1979
|
-
|
|
2310
|
+
updateConfig(newConfig) {
|
|
2311
|
+
this.config = newConfig;
|
|
2312
|
+
}
|
|
2313
|
+
get(cid) {
|
|
2314
|
+
return getCid(this.config, cid);
|
|
1980
2315
|
}
|
|
1981
2316
|
convert(url) {
|
|
1982
2317
|
return convertIPFSUrl(this.config, url);
|
|
1983
2318
|
}
|
|
2319
|
+
topUsageAnalytics(options) {
|
|
2320
|
+
return new TopGatewayAnalyticsBuilder(
|
|
2321
|
+
this.config,
|
|
2322
|
+
options.domain,
|
|
2323
|
+
options.start,
|
|
2324
|
+
options.end,
|
|
2325
|
+
options.sortBy,
|
|
2326
|
+
options.attribute
|
|
2327
|
+
);
|
|
2328
|
+
}
|
|
2329
|
+
dateIntervalAnalytics(options) {
|
|
2330
|
+
return new TimeIntervalGatewayAnalyticsBuilder(
|
|
2331
|
+
this.config,
|
|
2332
|
+
options.domain,
|
|
2333
|
+
options.start,
|
|
2334
|
+
options.end,
|
|
2335
|
+
options.interval
|
|
2336
|
+
);
|
|
2337
|
+
}
|
|
1984
2338
|
};
|
|
1985
2339
|
var FilterPinJobs = class {
|
|
1986
2340
|
constructor(config) {
|
|
@@ -1992,8 +2346,8 @@ var FilterPinJobs = class {
|
|
|
1992
2346
|
this.MINUTE_IN_MS = 6e4;
|
|
1993
2347
|
this.config = config;
|
|
1994
2348
|
}
|
|
1995
|
-
cid(
|
|
1996
|
-
this.query.ipfs_pin_hash =
|
|
2349
|
+
cid(cid) {
|
|
2350
|
+
this.query.ipfs_pin_hash = cid;
|
|
1997
2351
|
return this;
|
|
1998
2352
|
}
|
|
1999
2353
|
status(status) {
|
|
@@ -2060,6 +2414,9 @@ var Usage = class {
|
|
|
2060
2414
|
constructor(config) {
|
|
2061
2415
|
this.config = formatConfig(config);
|
|
2062
2416
|
}
|
|
2417
|
+
updateConfig(newConfig) {
|
|
2418
|
+
this.config = newConfig;
|
|
2419
|
+
}
|
|
2063
2420
|
pinnedFileCount() {
|
|
2064
2421
|
return pinnedFileCount(this.config);
|
|
2065
2422
|
}
|
|
@@ -2071,6 +2428,9 @@ var Keys = class {
|
|
|
2071
2428
|
constructor(config) {
|
|
2072
2429
|
this.config = formatConfig(config);
|
|
2073
2430
|
}
|
|
2431
|
+
updateConfig(newConfig) {
|
|
2432
|
+
this.config = newConfig;
|
|
2433
|
+
}
|
|
2074
2434
|
create(options) {
|
|
2075
2435
|
return createKey(this.config, options);
|
|
2076
2436
|
}
|
|
@@ -2157,6 +2517,9 @@ var Groups = class {
|
|
|
2157
2517
|
constructor(config) {
|
|
2158
2518
|
this.config = formatConfig(config);
|
|
2159
2519
|
}
|
|
2520
|
+
updateConfig(newConfig) {
|
|
2521
|
+
this.config = newConfig;
|
|
2522
|
+
}
|
|
2160
2523
|
create(options) {
|
|
2161
2524
|
return createGroup(this.config, options);
|
|
2162
2525
|
}
|
|
@@ -2247,14 +2610,116 @@ var Signatures = class {
|
|
|
2247
2610
|
constructor(config) {
|
|
2248
2611
|
this.config = formatConfig(config);
|
|
2249
2612
|
}
|
|
2613
|
+
updateConfig(newConfig) {
|
|
2614
|
+
this.config = newConfig;
|
|
2615
|
+
}
|
|
2250
2616
|
add(options) {
|
|
2251
2617
|
return addSignature(this.config, options);
|
|
2252
2618
|
}
|
|
2253
|
-
get(
|
|
2254
|
-
return getSignature(this.config,
|
|
2619
|
+
get(cid) {
|
|
2620
|
+
return getSignature(this.config, cid);
|
|
2255
2621
|
}
|
|
2256
|
-
delete(
|
|
2257
|
-
return removeSignature(this.config,
|
|
2622
|
+
delete(cid) {
|
|
2623
|
+
return removeSignature(this.config, cid);
|
|
2624
|
+
}
|
|
2625
|
+
};
|
|
2626
|
+
var GatewayAnalyticsBuilder = class {
|
|
2627
|
+
constructor(config, query) {
|
|
2628
|
+
this.requestCount = 0;
|
|
2629
|
+
this.lastRequestTime = 0;
|
|
2630
|
+
this.MAX_REQUESTS_PER_MINUTE = 30;
|
|
2631
|
+
this.MINUTE_IN_MS = 6e4;
|
|
2632
|
+
this.config = config;
|
|
2633
|
+
this.query = query;
|
|
2634
|
+
}
|
|
2635
|
+
cid(cid) {
|
|
2636
|
+
this.query.cid = cid;
|
|
2637
|
+
return this;
|
|
2638
|
+
}
|
|
2639
|
+
fileName(fileName) {
|
|
2640
|
+
this.query.file_name = fileName;
|
|
2641
|
+
return this;
|
|
2642
|
+
}
|
|
2643
|
+
userAgent(userAgent) {
|
|
2644
|
+
this.query.user_agent = userAgent;
|
|
2645
|
+
return this;
|
|
2646
|
+
}
|
|
2647
|
+
country(country) {
|
|
2648
|
+
this.query.country = country;
|
|
2649
|
+
return this;
|
|
2650
|
+
}
|
|
2651
|
+
region(region) {
|
|
2652
|
+
this.query.region = region;
|
|
2653
|
+
return this;
|
|
2654
|
+
}
|
|
2655
|
+
referer(referer) {
|
|
2656
|
+
this.query.referer = referer;
|
|
2657
|
+
return this;
|
|
2658
|
+
}
|
|
2659
|
+
limit(limit) {
|
|
2660
|
+
this.query.limit = limit;
|
|
2661
|
+
return this;
|
|
2662
|
+
}
|
|
2663
|
+
sort(order) {
|
|
2664
|
+
this.query.sort_order = order;
|
|
2665
|
+
return this;
|
|
2666
|
+
}
|
|
2667
|
+
async rateLimit() {
|
|
2668
|
+
this.requestCount++;
|
|
2669
|
+
const now = Date.now();
|
|
2670
|
+
if (this.requestCount >= this.MAX_REQUESTS_PER_MINUTE) {
|
|
2671
|
+
const timePassedSinceLastRequest = now - this.lastRequestTime;
|
|
2672
|
+
if (timePassedSinceLastRequest < this.MINUTE_IN_MS) {
|
|
2673
|
+
const delayTime = this.MINUTE_IN_MS - timePassedSinceLastRequest;
|
|
2674
|
+
await new Promise((resolve) => setTimeout(resolve, delayTime));
|
|
2675
|
+
}
|
|
2676
|
+
this.requestCount = 0;
|
|
2677
|
+
}
|
|
2678
|
+
this.lastRequestTime = Date.now();
|
|
2679
|
+
}
|
|
2680
|
+
async getAnalytics() {
|
|
2681
|
+
await this.rateLimit();
|
|
2682
|
+
throw new Error("getAnalytics method must be implemented in derived class");
|
|
2683
|
+
}
|
|
2684
|
+
then(onfulfilled) {
|
|
2685
|
+
return this.getAnalytics().then(onfulfilled);
|
|
2686
|
+
}
|
|
2687
|
+
};
|
|
2688
|
+
var TopGatewayAnalyticsBuilder = class extends GatewayAnalyticsBuilder {
|
|
2689
|
+
constructor(config, domain, start, end, sortBy, attribute) {
|
|
2690
|
+
super(config, {
|
|
2691
|
+
gateway_domain: domain,
|
|
2692
|
+
start_date: start,
|
|
2693
|
+
end_date: end,
|
|
2694
|
+
sort_by: sortBy,
|
|
2695
|
+
attribute
|
|
2696
|
+
});
|
|
2697
|
+
}
|
|
2698
|
+
async getAnalytics() {
|
|
2699
|
+
return analyticsTopUsage(this.config, this.query);
|
|
2700
|
+
}
|
|
2701
|
+
async all() {
|
|
2702
|
+
return this.getAnalytics();
|
|
2703
|
+
}
|
|
2704
|
+
};
|
|
2705
|
+
var TimeIntervalGatewayAnalyticsBuilder = class extends GatewayAnalyticsBuilder {
|
|
2706
|
+
constructor(config, domain, start, end, dateInterval) {
|
|
2707
|
+
super(config, {
|
|
2708
|
+
gateway_domain: domain,
|
|
2709
|
+
start_date: start,
|
|
2710
|
+
end_date: end,
|
|
2711
|
+
date_interval: dateInterval
|
|
2712
|
+
});
|
|
2713
|
+
}
|
|
2714
|
+
sortBy(sortBy) {
|
|
2715
|
+
this.query.sort_by = sortBy;
|
|
2716
|
+
return this;
|
|
2717
|
+
}
|
|
2718
|
+
async getAnalytics() {
|
|
2719
|
+
return analyticsDateInterval(this.config, this.query);
|
|
2720
|
+
}
|
|
2721
|
+
async all() {
|
|
2722
|
+
return this.getAnalytics();
|
|
2258
2723
|
}
|
|
2259
2724
|
};
|
|
2260
2725
|
// Annotate the CommonJS export names for ESM import in node:
|