pinata 0.4.0 → 1.0.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/README.md +15 -7
- package/dist/index.d.mts +64 -200
- package/dist/index.d.ts +64 -200
- package/dist/index.js +400 -1788
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +400 -1778
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -3
package/dist/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
|
|
30
20
|
// src/index.ts
|
|
@@ -117,7 +107,7 @@ var testAuthentication = async (config) => {
|
|
|
117
107
|
}
|
|
118
108
|
};
|
|
119
109
|
|
|
120
|
-
// src/core/
|
|
110
|
+
// src/core/uploads/file.ts
|
|
121
111
|
var uploadFile = async (config, file, options) => {
|
|
122
112
|
if (!config) {
|
|
123
113
|
throw new ValidationError("Pinata configuration is missing");
|
|
@@ -125,20 +115,10 @@ var uploadFile = async (config, file, options) => {
|
|
|
125
115
|
const jwt = options?.keys || config.pinataJwt;
|
|
126
116
|
const data = new FormData();
|
|
127
117
|
data.append("file", file, file.name);
|
|
128
|
-
data.append(
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
groupId: options?.groupId
|
|
133
|
-
})
|
|
134
|
-
);
|
|
135
|
-
data.append(
|
|
136
|
-
"pinataMetadata",
|
|
137
|
-
JSON.stringify({
|
|
138
|
-
name: options?.metadata?.name || file.name || "File from SDK",
|
|
139
|
-
keyvalues: options?.metadata?.keyValues
|
|
140
|
-
})
|
|
141
|
-
);
|
|
118
|
+
data.append("name", options?.metadata?.name || file.name || "File from SDK");
|
|
119
|
+
if (options?.groupId) {
|
|
120
|
+
data.append("group_id", options.groupId);
|
|
121
|
+
}
|
|
142
122
|
let headers;
|
|
143
123
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
144
124
|
headers = { ...config.customHeaders };
|
|
@@ -148,12 +128,12 @@ var uploadFile = async (config, file, options) => {
|
|
|
148
128
|
Source: "sdk/file"
|
|
149
129
|
};
|
|
150
130
|
}
|
|
151
|
-
let endpoint = "https://
|
|
131
|
+
let endpoint = "https://uploads.pinata.cloud/v3";
|
|
152
132
|
if (config.endpointUrl) {
|
|
153
133
|
endpoint = config.endpointUrl;
|
|
154
134
|
}
|
|
155
135
|
try {
|
|
156
|
-
const request = await fetch(`${endpoint}/
|
|
136
|
+
const request = await fetch(`${endpoint}/files`, {
|
|
157
137
|
method: "POST",
|
|
158
138
|
headers,
|
|
159
139
|
body: data
|
|
@@ -186,81 +166,7 @@ var uploadFile = async (config, file, options) => {
|
|
|
186
166
|
}
|
|
187
167
|
};
|
|
188
168
|
|
|
189
|
-
// src/core/
|
|
190
|
-
var uploadFileArray = async (config, files, options) => {
|
|
191
|
-
if (!config) {
|
|
192
|
-
throw new ValidationError("Pinata configuration is missing");
|
|
193
|
-
}
|
|
194
|
-
const jwt = options?.keys || config?.pinataJwt;
|
|
195
|
-
const folder = options?.metadata?.name || "folder_from_sdk";
|
|
196
|
-
const data = new FormData();
|
|
197
|
-
for (const file of Array.from(files)) {
|
|
198
|
-
data.append("file", file, `${folder}/${file.name}`);
|
|
199
|
-
}
|
|
200
|
-
data.append(
|
|
201
|
-
"pinataMetadata",
|
|
202
|
-
JSON.stringify({
|
|
203
|
-
name: folder,
|
|
204
|
-
keyvalues: options?.metadata?.keyValues
|
|
205
|
-
})
|
|
206
|
-
);
|
|
207
|
-
data.append(
|
|
208
|
-
"pinataOptions",
|
|
209
|
-
JSON.stringify({
|
|
210
|
-
cidVersion: options?.cidVersion,
|
|
211
|
-
groupId: options?.groupId
|
|
212
|
-
})
|
|
213
|
-
);
|
|
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;
|
|
226
|
-
}
|
|
227
|
-
try {
|
|
228
|
-
const request = await fetch(`${endpoint}/pinning/pinFileToIPFS`, {
|
|
229
|
-
method: "POST",
|
|
230
|
-
headers,
|
|
231
|
-
body: data
|
|
232
|
-
});
|
|
233
|
-
if (!request.ok) {
|
|
234
|
-
const errorData = await request.text();
|
|
235
|
-
if (request.status === 401 || request.status === 403) {
|
|
236
|
-
throw new AuthenticationError(
|
|
237
|
-
`Authentication failed: ${errorData}`,
|
|
238
|
-
request.status,
|
|
239
|
-
errorData
|
|
240
|
-
);
|
|
241
|
-
}
|
|
242
|
-
throw new NetworkError(
|
|
243
|
-
`HTTP error: ${errorData}`,
|
|
244
|
-
request.status,
|
|
245
|
-
errorData
|
|
246
|
-
);
|
|
247
|
-
}
|
|
248
|
-
const res = await request.json();
|
|
249
|
-
return res;
|
|
250
|
-
} catch (error) {
|
|
251
|
-
if (error instanceof PinataError) {
|
|
252
|
-
throw error;
|
|
253
|
-
}
|
|
254
|
-
if (error instanceof Error) {
|
|
255
|
-
throw new PinataError(`Error processing fileArray: ${error.message}`);
|
|
256
|
-
}
|
|
257
|
-
throw new PinataError(
|
|
258
|
-
"An unknown error occurred while uploading an array of files"
|
|
259
|
-
);
|
|
260
|
-
}
|
|
261
|
-
};
|
|
262
|
-
|
|
263
|
-
// src/core/pinning/base64.ts
|
|
169
|
+
// src/core/uploads/base64.ts
|
|
264
170
|
var uploadBase64 = async (config, base64String, options) => {
|
|
265
171
|
if (!config) {
|
|
266
172
|
throw new ValidationError("Pinata configuration is missing");
|
|
@@ -271,20 +177,10 @@ var uploadBase64 = async (config, base64String, options) => {
|
|
|
271
177
|
const blob = new Blob([buffer]);
|
|
272
178
|
const data = new FormData();
|
|
273
179
|
data.append("file", blob, name);
|
|
274
|
-
data.append(
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
groupId: options?.groupId
|
|
279
|
-
})
|
|
280
|
-
);
|
|
281
|
-
data.append(
|
|
282
|
-
"pinataMetadata",
|
|
283
|
-
JSON.stringify({
|
|
284
|
-
name,
|
|
285
|
-
keyvalues: options?.metadata?.keyValues
|
|
286
|
-
})
|
|
287
|
-
);
|
|
180
|
+
data.append("name", name);
|
|
181
|
+
if (options?.groupId) {
|
|
182
|
+
data.append("group_id", options.groupId);
|
|
183
|
+
}
|
|
288
184
|
let headers;
|
|
289
185
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
290
186
|
headers = { ...config.customHeaders };
|
|
@@ -294,12 +190,12 @@ var uploadBase64 = async (config, base64String, options) => {
|
|
|
294
190
|
Source: "sdk/base64"
|
|
295
191
|
};
|
|
296
192
|
}
|
|
297
|
-
let endpoint = "https://
|
|
193
|
+
let endpoint = "https://uploads.pinata.cloud/v3";
|
|
298
194
|
if (config.endpointUrl) {
|
|
299
195
|
endpoint = config.endpointUrl;
|
|
300
196
|
}
|
|
301
197
|
try {
|
|
302
|
-
const request = await fetch(`${endpoint}/
|
|
198
|
+
const request = await fetch(`${endpoint}/files`, {
|
|
303
199
|
method: "POST",
|
|
304
200
|
headers,
|
|
305
201
|
body: data
|
|
@@ -334,7 +230,7 @@ var uploadBase64 = async (config, base64String, options) => {
|
|
|
334
230
|
}
|
|
335
231
|
};
|
|
336
232
|
|
|
337
|
-
// src/core/
|
|
233
|
+
// src/core/uploads/url.ts
|
|
338
234
|
var uploadUrl = async (config, url, options) => {
|
|
339
235
|
if (!config) {
|
|
340
236
|
throw new ValidationError("Pinata configuration is missing");
|
|
@@ -355,20 +251,10 @@ var uploadUrl = async (config, url, options) => {
|
|
|
355
251
|
const name = options?.metadata?.name ?? "url_upload";
|
|
356
252
|
const file = new File([blob], name);
|
|
357
253
|
data.append("file", file, name);
|
|
358
|
-
data.append(
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
groupId: options?.groupId
|
|
363
|
-
})
|
|
364
|
-
);
|
|
365
|
-
data.append(
|
|
366
|
-
"pinataMetadata",
|
|
367
|
-
JSON.stringify({
|
|
368
|
-
name,
|
|
369
|
-
keyvalues: options?.metadata?.keyValues
|
|
370
|
-
})
|
|
371
|
-
);
|
|
254
|
+
data.append("name", name);
|
|
255
|
+
if (options?.groupId) {
|
|
256
|
+
data.append("group_id", options.groupId);
|
|
257
|
+
}
|
|
372
258
|
let headers;
|
|
373
259
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
374
260
|
headers = { ...config.customHeaders };
|
|
@@ -378,12 +264,12 @@ var uploadUrl = async (config, url, options) => {
|
|
|
378
264
|
Source: "sdk/url"
|
|
379
265
|
};
|
|
380
266
|
}
|
|
381
|
-
let endpoint = "https://
|
|
267
|
+
let endpoint = "https://uploads.pinata.cloud/v3";
|
|
382
268
|
if (config.endpointUrl) {
|
|
383
269
|
endpoint = config.endpointUrl;
|
|
384
270
|
}
|
|
385
271
|
try {
|
|
386
|
-
const request = await fetch(`${endpoint}/
|
|
272
|
+
const request = await fetch(`${endpoint}/files`, {
|
|
387
273
|
method: "POST",
|
|
388
274
|
headers,
|
|
389
275
|
body: data
|
|
@@ -416,39 +302,36 @@ var uploadUrl = async (config, url, options) => {
|
|
|
416
302
|
}
|
|
417
303
|
};
|
|
418
304
|
|
|
419
|
-
// src/core/
|
|
305
|
+
// src/core/uploads/json.ts
|
|
420
306
|
var uploadJson = async (config, jsonData, options) => {
|
|
421
307
|
if (!config) {
|
|
422
308
|
throw new ValidationError("Pinata configuration is missing");
|
|
423
309
|
}
|
|
424
310
|
const jwt = options?.keys || config?.pinataJwt;
|
|
425
|
-
const
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
}
|
|
435
|
-
});
|
|
311
|
+
const json = JSON.stringify(jsonData);
|
|
312
|
+
const blob = new Blob([json]);
|
|
313
|
+
const file = new File([blob], "data.json", { type: "application/json" });
|
|
314
|
+
const data = new FormData();
|
|
315
|
+
data.append("file", file, file.name);
|
|
316
|
+
data.append("name", options?.metadata?.name || file.name || "File from SDK");
|
|
317
|
+
if (options?.groupId) {
|
|
318
|
+
data.append("group_id", options.groupId);
|
|
319
|
+
}
|
|
436
320
|
let headers;
|
|
437
321
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
438
322
|
headers = { ...config.customHeaders };
|
|
439
323
|
} else {
|
|
440
324
|
headers = {
|
|
441
325
|
Authorization: `Bearer ${jwt}`,
|
|
442
|
-
"Content-Type": "application/json",
|
|
443
326
|
Source: "sdk/json"
|
|
444
327
|
};
|
|
445
328
|
}
|
|
446
|
-
let endpoint = "https://
|
|
329
|
+
let endpoint = "https://uploads.pinata.cloud/v3";
|
|
447
330
|
if (config.endpointUrl) {
|
|
448
331
|
endpoint = config.endpointUrl;
|
|
449
332
|
}
|
|
450
333
|
try {
|
|
451
|
-
const request = await fetch(`${endpoint}/
|
|
334
|
+
const request = await fetch(`${endpoint}/files`, {
|
|
452
335
|
method: "POST",
|
|
453
336
|
headers,
|
|
454
337
|
body: data
|
|
@@ -481,78 +364,13 @@ var uploadJson = async (config, jsonData, options) => {
|
|
|
481
364
|
}
|
|
482
365
|
};
|
|
483
366
|
|
|
484
|
-
// src/core/
|
|
485
|
-
var uploadCid = async (config, cid, options) => {
|
|
486
|
-
if (!config) {
|
|
487
|
-
throw new ValidationError("Pinata configuration is missing");
|
|
488
|
-
}
|
|
489
|
-
const jwt = options?.keys || config?.pinataJwt;
|
|
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
|
-
};
|
|
499
|
-
}
|
|
500
|
-
const data = JSON.stringify({
|
|
501
|
-
hashToPin: cid,
|
|
502
|
-
pinataMetadata: {
|
|
503
|
-
name: options?.metadata ? options?.metadata?.name : cid,
|
|
504
|
-
keyvalues: options?.metadata?.keyValues
|
|
505
|
-
},
|
|
506
|
-
pinataOptions: {
|
|
507
|
-
hostNodes: options?.peerAddresses ? options.peerAddresses : "",
|
|
508
|
-
groupId: options?.groupId
|
|
509
|
-
}
|
|
510
|
-
});
|
|
511
|
-
let endpoint = "https://api.pinata.cloud";
|
|
512
|
-
if (config.endpointUrl) {
|
|
513
|
-
endpoint = config.endpointUrl;
|
|
514
|
-
}
|
|
515
|
-
try {
|
|
516
|
-
const request = await fetch(`${endpoint}/pinning/pinByHash`, {
|
|
517
|
-
method: "POST",
|
|
518
|
-
headers,
|
|
519
|
-
body: data
|
|
520
|
-
});
|
|
521
|
-
if (!request.ok) {
|
|
522
|
-
const errorData = await request.text();
|
|
523
|
-
if (request.status === 401 || request.status === 403) {
|
|
524
|
-
throw new AuthenticationError(
|
|
525
|
-
`Authentication failed: ${errorData}`,
|
|
526
|
-
request.status,
|
|
527
|
-
errorData
|
|
528
|
-
);
|
|
529
|
-
}
|
|
530
|
-
throw new NetworkError(
|
|
531
|
-
`HTTP error: ${errorData}`,
|
|
532
|
-
request.status,
|
|
533
|
-
errorData
|
|
534
|
-
);
|
|
535
|
-
}
|
|
536
|
-
const res = await request.json();
|
|
537
|
-
return res;
|
|
538
|
-
} catch (error) {
|
|
539
|
-
if (error instanceof PinataError) {
|
|
540
|
-
throw error;
|
|
541
|
-
}
|
|
542
|
-
if (error instanceof Error) {
|
|
543
|
-
throw new PinataError(`Error processing cid: ${error.message}`);
|
|
544
|
-
}
|
|
545
|
-
throw new PinataError("An unknown error occurred while pinning by CID");
|
|
546
|
-
}
|
|
547
|
-
};
|
|
548
|
-
|
|
549
|
-
// src/core/pinning/unpin.ts
|
|
367
|
+
// src/core/files/delete.ts
|
|
550
368
|
var wait = (milliseconds) => {
|
|
551
369
|
return new Promise((resolve) => {
|
|
552
370
|
setTimeout(resolve, milliseconds);
|
|
553
371
|
});
|
|
554
372
|
};
|
|
555
|
-
var
|
|
373
|
+
var deleteFile = async (config, files) => {
|
|
556
374
|
if (!config) {
|
|
557
375
|
throw new ValidationError("Pinata configuration is missing");
|
|
558
376
|
}
|
|
@@ -566,13 +384,13 @@ var unpinFile = async (config, files) => {
|
|
|
566
384
|
Source: "sdk/unpin"
|
|
567
385
|
};
|
|
568
386
|
}
|
|
569
|
-
let endpoint = "https://api.pinata.cloud";
|
|
387
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
570
388
|
if (config.endpointUrl) {
|
|
571
389
|
endpoint = config.endpointUrl;
|
|
572
390
|
}
|
|
573
|
-
for (const
|
|
391
|
+
for (const id of files) {
|
|
574
392
|
try {
|
|
575
|
-
const response = await fetch(`${endpoint}/
|
|
393
|
+
const response = await fetch(`${endpoint}/files/${id}`, {
|
|
576
394
|
method: "DELETE",
|
|
577
395
|
headers
|
|
578
396
|
});
|
|
@@ -592,22 +410,21 @@ var unpinFile = async (config, files) => {
|
|
|
592
410
|
errorData
|
|
593
411
|
);
|
|
594
412
|
}
|
|
595
|
-
const result = await response.text();
|
|
596
413
|
responses.push({
|
|
597
|
-
|
|
598
|
-
status:
|
|
414
|
+
id,
|
|
415
|
+
status: response.statusText
|
|
599
416
|
});
|
|
600
417
|
} catch (error) {
|
|
601
418
|
let errorMessage;
|
|
602
419
|
if (error instanceof PinataError) {
|
|
603
420
|
errorMessage = error.message;
|
|
604
421
|
} else if (error instanceof Error) {
|
|
605
|
-
errorMessage = `Error
|
|
422
|
+
errorMessage = `Error deleting file ${id}: ${error.message}`;
|
|
606
423
|
} else {
|
|
607
|
-
errorMessage = `An unknown error occurred while
|
|
424
|
+
errorMessage = `An unknown error occurred while deleting file ${id}`;
|
|
608
425
|
}
|
|
609
426
|
responses.push({
|
|
610
|
-
|
|
427
|
+
id,
|
|
611
428
|
status: errorMessage
|
|
612
429
|
});
|
|
613
430
|
}
|
|
@@ -615,59 +432,26 @@ var unpinFile = async (config, files) => {
|
|
|
615
432
|
return responses;
|
|
616
433
|
};
|
|
617
434
|
|
|
618
|
-
// src/core/
|
|
435
|
+
// src/core/files/list.ts
|
|
619
436
|
var listFiles = async (config, options) => {
|
|
620
437
|
if (!config) {
|
|
621
438
|
throw new ValidationError("Pinata configuration is missing");
|
|
622
439
|
}
|
|
623
|
-
const params = new URLSearchParams(
|
|
624
|
-
includesCount: "false"
|
|
625
|
-
});
|
|
440
|
+
const params = new URLSearchParams();
|
|
626
441
|
if (options) {
|
|
627
|
-
const {
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
pageOffset,
|
|
635
|
-
name,
|
|
636
|
-
key,
|
|
637
|
-
value,
|
|
638
|
-
operator,
|
|
639
|
-
groupId
|
|
640
|
-
} = options;
|
|
641
|
-
if (cid)
|
|
642
|
-
params.append("cid", cid);
|
|
643
|
-
if (pinStart)
|
|
644
|
-
params.append("pinStart", pinStart);
|
|
645
|
-
if (pinEnd)
|
|
646
|
-
params.append("pinEnd", pinEnd);
|
|
647
|
-
if (pinSizeMin)
|
|
648
|
-
params.append("pinSizeMin", pinSizeMin.toString());
|
|
649
|
-
if (pinSizeMax)
|
|
650
|
-
params.append("pinSizeMax", pinSizeMax.toString());
|
|
651
|
-
if (pageLimit)
|
|
652
|
-
params.append("pageLimit", pageLimit.toString());
|
|
653
|
-
if (pageOffset)
|
|
654
|
-
params.append("pageOffset", pageOffset.toString());
|
|
655
|
-
if (groupId)
|
|
656
|
-
params.append("groupId", groupId);
|
|
657
|
-
if (name)
|
|
658
|
-
params.append("metadata[name]", name);
|
|
659
|
-
if (key && value) {
|
|
660
|
-
const keyValueParam = JSON.stringify({
|
|
661
|
-
[key]: { value, op: operator || "eq" }
|
|
662
|
-
});
|
|
663
|
-
params.append("metadata[keyvalues]", keyValueParam);
|
|
664
|
-
}
|
|
442
|
+
const { limit, pageToken, cidPending } = options;
|
|
443
|
+
if (limit)
|
|
444
|
+
params.append("limit", limit.toString());
|
|
445
|
+
if (pageToken)
|
|
446
|
+
params.append("pageToken", pageToken);
|
|
447
|
+
if (cidPending)
|
|
448
|
+
params.append("cidPending", "true");
|
|
665
449
|
}
|
|
666
|
-
let endpoint = "https://api.pinata.cloud";
|
|
450
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
667
451
|
if (config.endpointUrl) {
|
|
668
452
|
endpoint = config.endpointUrl;
|
|
669
453
|
}
|
|
670
|
-
const url = `${endpoint}/
|
|
454
|
+
const url = `${endpoint}/files?${params.toString()}`;
|
|
671
455
|
try {
|
|
672
456
|
let headers;
|
|
673
457
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
@@ -698,7 +482,8 @@ var listFiles = async (config, options) => {
|
|
|
698
482
|
);
|
|
699
483
|
}
|
|
700
484
|
const res = await request.json();
|
|
701
|
-
|
|
485
|
+
const resData = res.data;
|
|
486
|
+
return resData;
|
|
702
487
|
} catch (error) {
|
|
703
488
|
if (error instanceof PinataError) {
|
|
704
489
|
throw error;
|
|
@@ -710,16 +495,14 @@ var listFiles = async (config, options) => {
|
|
|
710
495
|
}
|
|
711
496
|
};
|
|
712
497
|
|
|
713
|
-
// src/core/
|
|
714
|
-
var
|
|
498
|
+
// src/core/files/updateFile.ts
|
|
499
|
+
var updateFile = async (config, options) => {
|
|
715
500
|
if (!config) {
|
|
716
501
|
throw new ValidationError("Pinata configuration is missing");
|
|
717
502
|
}
|
|
718
|
-
const data = {
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
keyvalues: options.keyValues
|
|
722
|
-
};
|
|
503
|
+
const data = JSON.stringify({
|
|
504
|
+
name: options.name
|
|
505
|
+
});
|
|
723
506
|
let headers;
|
|
724
507
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
725
508
|
headers = { ...config.customHeaders };
|
|
@@ -730,15 +513,15 @@ var updateMetadata = async (config, options) => {
|
|
|
730
513
|
Source: "sdk/updateMetadata"
|
|
731
514
|
};
|
|
732
515
|
}
|
|
733
|
-
let endpoint = "https://api.pinata.cloud";
|
|
516
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
734
517
|
if (config.endpointUrl) {
|
|
735
518
|
endpoint = config.endpointUrl;
|
|
736
519
|
}
|
|
737
520
|
try {
|
|
738
|
-
const request = await fetch(`${endpoint}/
|
|
521
|
+
const request = await fetch(`${endpoint}/files/${options.id}`, {
|
|
739
522
|
method: "PUT",
|
|
740
523
|
headers,
|
|
741
|
-
body:
|
|
524
|
+
body: data
|
|
742
525
|
});
|
|
743
526
|
if (!request.ok) {
|
|
744
527
|
const errorData = await request.text();
|
|
@@ -755,157 +538,49 @@ var updateMetadata = async (config, options) => {
|
|
|
755
538
|
errorData
|
|
756
539
|
);
|
|
757
540
|
}
|
|
758
|
-
const res = await request.
|
|
759
|
-
|
|
541
|
+
const res = await request.json();
|
|
542
|
+
const resData = res.data;
|
|
543
|
+
return resData;
|
|
760
544
|
} catch (error) {
|
|
761
545
|
if (error instanceof PinataError) {
|
|
762
546
|
throw error;
|
|
763
547
|
}
|
|
764
548
|
if (error instanceof Error) {
|
|
765
|
-
throw new PinataError(
|
|
766
|
-
`Error processing updateMetadata: ${error.message}`
|
|
767
|
-
);
|
|
549
|
+
throw new PinataError(`Error processing updateFile: ${error.message}`);
|
|
768
550
|
}
|
|
769
|
-
throw new PinataError("An unknown error occurred while updating
|
|
551
|
+
throw new PinataError("An unknown error occurred while updating file");
|
|
770
552
|
}
|
|
771
553
|
};
|
|
772
554
|
|
|
773
|
-
// src/utils/gateway-tools.ts
|
|
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) {
|
|
782
|
-
if (typeof input !== "string") {
|
|
783
|
-
throw new Error("Input is not a string");
|
|
784
|
-
}
|
|
785
|
-
const isIPFS = await getIsIPFS();
|
|
786
|
-
const startsWithCID = (str) => {
|
|
787
|
-
const parts = str.split("/");
|
|
788
|
-
return isIPFS.cid(parts[0]) ? parts[0] : null;
|
|
789
|
-
};
|
|
790
|
-
const directCID = startsWithCID(input);
|
|
791
|
-
if (directCID) {
|
|
792
|
-
return {
|
|
793
|
-
containsCid: true,
|
|
794
|
-
cid: directCID
|
|
795
|
-
};
|
|
796
|
-
}
|
|
797
|
-
let url;
|
|
798
|
-
try {
|
|
799
|
-
url = new URL(input);
|
|
800
|
-
} catch (error) {
|
|
801
|
-
const parts = input.split(/\/|\?/);
|
|
802
|
-
for (const part of parts) {
|
|
803
|
-
const cid = startsWithCID(part);
|
|
804
|
-
if (cid) {
|
|
805
|
-
return {
|
|
806
|
-
containsCid: true,
|
|
807
|
-
cid
|
|
808
|
-
};
|
|
809
|
-
}
|
|
810
|
-
}
|
|
811
|
-
return {
|
|
812
|
-
containsCid: false,
|
|
813
|
-
cid: null
|
|
814
|
-
};
|
|
815
|
-
}
|
|
816
|
-
const subdomains = url.hostname.split(".");
|
|
817
|
-
for (const subdomain of subdomains) {
|
|
818
|
-
if (isIPFS.cid(subdomain)) {
|
|
819
|
-
return {
|
|
820
|
-
containsCid: true,
|
|
821
|
-
cid: subdomain
|
|
822
|
-
};
|
|
823
|
-
}
|
|
824
|
-
}
|
|
825
|
-
const pathParts = url.pathname.split("/");
|
|
826
|
-
for (const part of pathParts) {
|
|
827
|
-
const cid = startsWithCID(part);
|
|
828
|
-
if (cid) {
|
|
829
|
-
return {
|
|
830
|
-
containsCid: true,
|
|
831
|
-
cid
|
|
832
|
-
};
|
|
833
|
-
}
|
|
834
|
-
}
|
|
835
|
-
return {
|
|
836
|
-
containsCid: false,
|
|
837
|
-
cid: null
|
|
838
|
-
};
|
|
839
|
-
}
|
|
840
|
-
async function convertToDesiredGateway(sourceUrl, desiredGatewayPrefix) {
|
|
841
|
-
const results = await containsCID(sourceUrl);
|
|
842
|
-
if (results.containsCid !== true) {
|
|
843
|
-
throw new Error("url does not contain CID");
|
|
844
|
-
}
|
|
845
|
-
if (!sourceUrl.startsWith("https") && !sourceUrl.startsWith("ipfs://")) {
|
|
846
|
-
return `${desiredGatewayPrefix}/ipfs/${sourceUrl}`;
|
|
847
|
-
}
|
|
848
|
-
const urlObj = new URL(sourceUrl);
|
|
849
|
-
const path = urlObj.pathname + urlObj.search + urlObj.hash;
|
|
850
|
-
if (sourceUrl.startsWith(`ipfs://${results.cid}`)) {
|
|
851
|
-
return `${desiredGatewayPrefix}/ipfs/${results.cid}${path}`;
|
|
852
|
-
}
|
|
853
|
-
if (sourceUrl.includes(`/ipfs/${results.cid}`)) {
|
|
854
|
-
return `${desiredGatewayPrefix}${path}`;
|
|
855
|
-
}
|
|
856
|
-
if (sourceUrl.includes(`/ipns/${results.cid}`)) {
|
|
857
|
-
return `${desiredGatewayPrefix}${path}`;
|
|
858
|
-
}
|
|
859
|
-
if (urlObj.hostname.includes(results.cid)) {
|
|
860
|
-
return `${desiredGatewayPrefix}/ipfs/${results.cid}${path}`;
|
|
861
|
-
}
|
|
862
|
-
throw new Error(
|
|
863
|
-
"unsupported URL pattern, please submit a github issue with the URL utilized"
|
|
864
|
-
);
|
|
865
|
-
}
|
|
866
|
-
|
|
867
555
|
// src/core/gateway/getCid.ts
|
|
868
|
-
var getCid = async (config, cid
|
|
556
|
+
var getCid = async (config, cid) => {
|
|
869
557
|
if (!config) {
|
|
870
558
|
throw new ValidationError("Pinata configuration is missing");
|
|
871
559
|
}
|
|
872
560
|
let data;
|
|
873
|
-
let newUrl
|
|
874
|
-
newUrl = await convertToDesiredGateway(cid, config?.pinataGateway);
|
|
561
|
+
let newUrl = `${config?.pinataGateway}/files/${cid}`;
|
|
875
562
|
const params = new URLSearchParams();
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
params.append("img-anim", options.animation.toString());
|
|
896
|
-
if (options.sharpen)
|
|
897
|
-
params.append("img-sharpen", options.sharpen.toString());
|
|
898
|
-
if (options.onError === true)
|
|
899
|
-
params.append("img-onerror", "redirect");
|
|
900
|
-
if (options.metadata)
|
|
901
|
-
params.append("img-metadata", options.metadata);
|
|
902
|
-
}
|
|
903
|
-
const queryString = params.toString();
|
|
904
|
-
if (queryString) {
|
|
905
|
-
newUrl += `?${queryString}`;
|
|
906
|
-
}
|
|
563
|
+
const date = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3);
|
|
564
|
+
const payload = JSON.stringify({
|
|
565
|
+
url: newUrl,
|
|
566
|
+
date,
|
|
567
|
+
expires: 30,
|
|
568
|
+
method: "GET"
|
|
569
|
+
});
|
|
570
|
+
const signedUrlRequest = await fetch(
|
|
571
|
+
"https://api.pinata.cloud/v3/files/sign",
|
|
572
|
+
{
|
|
573
|
+
method: "POST",
|
|
574
|
+
headers: {
|
|
575
|
+
"Content-Type": "application/json",
|
|
576
|
+
Authorization: `Bearer ${config?.pinataJwt}`
|
|
577
|
+
},
|
|
578
|
+
body: payload
|
|
579
|
+
}
|
|
580
|
+
);
|
|
581
|
+
const signedUrl = await signedUrlRequest.json();
|
|
907
582
|
try {
|
|
908
|
-
const request = await fetch(
|
|
583
|
+
const request = await fetch(signedUrl.data);
|
|
909
584
|
if (!request.ok) {
|
|
910
585
|
const errorData = await request.text();
|
|
911
586
|
if (request.status === 401 || request.status === 403) {
|
|
@@ -947,56 +622,31 @@ var getCid = async (config, cid, options) => {
|
|
|
947
622
|
}
|
|
948
623
|
};
|
|
949
624
|
|
|
950
|
-
// src/core/
|
|
951
|
-
var
|
|
952
|
-
let newUrl;
|
|
953
|
-
let prefix = gatewayPrefix || config?.pinataGateway || "https://gateway.pinata.cloud";
|
|
954
|
-
newUrl = await convertToDesiredGateway(url, prefix);
|
|
955
|
-
if (config?.pinataGatewayKey) {
|
|
956
|
-
`${newUrl}?pinataGatewayToken=${config?.pinataGatewayKey}`;
|
|
957
|
-
}
|
|
958
|
-
return newUrl;
|
|
959
|
-
};
|
|
960
|
-
|
|
961
|
-
// src/core/data/pinJobs.ts
|
|
962
|
-
var pinJobs = async (config, options) => {
|
|
625
|
+
// src/core/keys/createKey.ts
|
|
626
|
+
var createKey = async (config, options) => {
|
|
963
627
|
if (!config) {
|
|
964
628
|
throw new ValidationError("Pinata configuration is missing");
|
|
965
629
|
}
|
|
966
|
-
const params = new URLSearchParams({
|
|
967
|
-
includesCount: "false"
|
|
968
|
-
});
|
|
969
|
-
if (options) {
|
|
970
|
-
const { ipfs_pin_hash: cid, status, sort, limit, offset } = options;
|
|
971
|
-
if (cid)
|
|
972
|
-
params.append("ipfs_pin_hash", cid.toString());
|
|
973
|
-
if (status)
|
|
974
|
-
params.append("status", status.toString());
|
|
975
|
-
if (sort)
|
|
976
|
-
params.append("sort", sort.toString());
|
|
977
|
-
if (limit)
|
|
978
|
-
params.append("limit", limit.toString());
|
|
979
|
-
if (offset)
|
|
980
|
-
params.append("offset", offset.toString());
|
|
981
|
-
}
|
|
982
|
-
let endpoint = "https://api.pinata.cloud";
|
|
983
|
-
if (config.endpointUrl) {
|
|
984
|
-
endpoint = config.endpointUrl;
|
|
985
|
-
}
|
|
986
|
-
const url = `${endpoint}/pinning/pinJobs?${params.toString()}`;
|
|
987
630
|
let headers;
|
|
988
631
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
989
632
|
headers = { ...config.customHeaders };
|
|
990
633
|
} else {
|
|
991
634
|
headers = {
|
|
992
635
|
Authorization: `Bearer ${config.pinataJwt}`,
|
|
993
|
-
|
|
636
|
+
"Content-Type": "application/json",
|
|
637
|
+
Source: "sdk/createKey"
|
|
994
638
|
};
|
|
995
639
|
}
|
|
640
|
+
const data = JSON.stringify(options);
|
|
641
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
642
|
+
if (config.endpointUrl) {
|
|
643
|
+
endpoint = config.endpointUrl;
|
|
644
|
+
}
|
|
996
645
|
try {
|
|
997
|
-
const request = await fetch(
|
|
998
|
-
method: "
|
|
999
|
-
headers
|
|
646
|
+
const request = await fetch(`${endpoint}/pinata/keys`, {
|
|
647
|
+
method: "POST",
|
|
648
|
+
headers,
|
|
649
|
+
body: data
|
|
1000
650
|
});
|
|
1001
651
|
if (!request.ok) {
|
|
1002
652
|
const errorData = await request.text();
|
|
@@ -1014,41 +664,59 @@ var pinJobs = async (config, options) => {
|
|
|
1014
664
|
);
|
|
1015
665
|
}
|
|
1016
666
|
const res = await request.json();
|
|
1017
|
-
return res
|
|
667
|
+
return res;
|
|
1018
668
|
} catch (error) {
|
|
1019
669
|
if (error instanceof PinataError) {
|
|
1020
670
|
throw error;
|
|
1021
671
|
}
|
|
1022
672
|
if (error instanceof Error) {
|
|
1023
|
-
throw new PinataError(`Error processing
|
|
673
|
+
throw new PinataError(`Error processing createKey: ${error.message}`);
|
|
1024
674
|
}
|
|
1025
|
-
throw new PinataError("An unknown error occurred while
|
|
675
|
+
throw new PinataError("An unknown error occurred while creating API key");
|
|
1026
676
|
}
|
|
1027
677
|
};
|
|
1028
678
|
|
|
1029
|
-
// src/core/
|
|
1030
|
-
var
|
|
679
|
+
// src/core/keys/listKeys.ts
|
|
680
|
+
var listKeys = async (config, options) => {
|
|
1031
681
|
if (!config) {
|
|
1032
682
|
throw new ValidationError("Pinata configuration is missing");
|
|
1033
683
|
}
|
|
1034
|
-
let endpoint = "https://api.pinata.cloud";
|
|
1035
|
-
if (config.endpointUrl) {
|
|
1036
|
-
endpoint = config.endpointUrl;
|
|
1037
|
-
}
|
|
1038
684
|
let headers;
|
|
1039
685
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1040
686
|
headers = { ...config.customHeaders };
|
|
1041
687
|
} else {
|
|
1042
688
|
headers = {
|
|
1043
689
|
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1044
|
-
|
|
690
|
+
"Content-Type": "application/json",
|
|
691
|
+
Source: "sdk/listKeys"
|
|
1045
692
|
};
|
|
1046
693
|
}
|
|
694
|
+
const params = new URLSearchParams();
|
|
695
|
+
if (options) {
|
|
696
|
+
const { offset, name, revoked, limitedUse, exhausted } = options;
|
|
697
|
+
if (offset)
|
|
698
|
+
params.append("offset", offset.toString());
|
|
699
|
+
if (revoked !== void 0)
|
|
700
|
+
params.append("revoked", revoked.toString());
|
|
701
|
+
if (limitedUse !== void 0)
|
|
702
|
+
params.append("limitedUse", limitedUse.toString());
|
|
703
|
+
if (exhausted !== void 0)
|
|
704
|
+
params.append("exhausted", exhausted.toString());
|
|
705
|
+
if (name)
|
|
706
|
+
params.append("name", name);
|
|
707
|
+
}
|
|
708
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
709
|
+
if (config.endpointUrl) {
|
|
710
|
+
endpoint = config.endpointUrl;
|
|
711
|
+
}
|
|
1047
712
|
try {
|
|
1048
|
-
const request = await fetch(
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
713
|
+
const request = await fetch(
|
|
714
|
+
`${endpoint}/pinata/keys?${params.toString()}`,
|
|
715
|
+
{
|
|
716
|
+
method: "GET",
|
|
717
|
+
headers
|
|
718
|
+
}
|
|
719
|
+
);
|
|
1052
720
|
if (!request.ok) {
|
|
1053
721
|
const errorData = await request.text();
|
|
1054
722
|
if (request.status === 401 || request.status === 403) {
|
|
@@ -1065,207 +733,25 @@ var pinnedFileCount = async (config) => {
|
|
|
1065
733
|
);
|
|
1066
734
|
}
|
|
1067
735
|
const res = await request.json();
|
|
1068
|
-
return res.
|
|
736
|
+
return res.keys;
|
|
1069
737
|
} catch (error) {
|
|
1070
738
|
if (error instanceof PinataError) {
|
|
1071
739
|
throw error;
|
|
1072
740
|
}
|
|
1073
741
|
if (error instanceof Error) {
|
|
1074
|
-
throw new PinataError(
|
|
1075
|
-
`Error processing pinnedFileUsage: ${error.message}`
|
|
1076
|
-
);
|
|
742
|
+
throw new PinataError(`Error processing listKeys: ${error.message}`);
|
|
1077
743
|
}
|
|
1078
|
-
throw new PinataError(
|
|
1079
|
-
"An unknown error occurred while getting pinned file usage"
|
|
1080
|
-
);
|
|
744
|
+
throw new PinataError("An unknown error occurred while listing API keys");
|
|
1081
745
|
}
|
|
1082
746
|
};
|
|
1083
747
|
|
|
1084
|
-
// src/core/
|
|
1085
|
-
var
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
}
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
endpoint = config.endpointUrl;
|
|
1092
|
-
}
|
|
1093
|
-
let headers;
|
|
1094
|
-
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1095
|
-
headers = { ...config.customHeaders };
|
|
1096
|
-
} else {
|
|
1097
|
-
headers = {
|
|
1098
|
-
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1099
|
-
Source: "sdk/totalStorageUsage"
|
|
1100
|
-
};
|
|
1101
|
-
}
|
|
1102
|
-
try {
|
|
1103
|
-
const request = await fetch(`${endpoint}/data/userPinnedDataTotal`, {
|
|
1104
|
-
method: "GET",
|
|
1105
|
-
headers
|
|
1106
|
-
});
|
|
1107
|
-
if (!request.ok) {
|
|
1108
|
-
const errorData = await request.text();
|
|
1109
|
-
if (request.status === 401 || request.status === 403) {
|
|
1110
|
-
throw new AuthenticationError(
|
|
1111
|
-
`Authentication failed: ${errorData}`,
|
|
1112
|
-
request.status,
|
|
1113
|
-
errorData
|
|
1114
|
-
);
|
|
1115
|
-
}
|
|
1116
|
-
throw new NetworkError(
|
|
1117
|
-
`HTTP error: ${errorData}`,
|
|
1118
|
-
request.status,
|
|
1119
|
-
errorData
|
|
1120
|
-
);
|
|
1121
|
-
}
|
|
1122
|
-
const res = await request.json();
|
|
1123
|
-
return res.pin_size_total;
|
|
1124
|
-
} catch (error) {
|
|
1125
|
-
if (error instanceof PinataError) {
|
|
1126
|
-
throw error;
|
|
1127
|
-
}
|
|
1128
|
-
if (error instanceof Error) {
|
|
1129
|
-
throw new PinataError(
|
|
1130
|
-
`Error processing totalStorageUsage: ${error.message}`
|
|
1131
|
-
);
|
|
1132
|
-
}
|
|
1133
|
-
throw new PinataError(
|
|
1134
|
-
"An unknown error occurred while getting total storage usage"
|
|
1135
|
-
);
|
|
1136
|
-
}
|
|
1137
|
-
};
|
|
1138
|
-
|
|
1139
|
-
// src/core/keys/createKey.ts
|
|
1140
|
-
var createKey = async (config, options) => {
|
|
1141
|
-
if (!config) {
|
|
1142
|
-
throw new ValidationError("Pinata configuration is missing");
|
|
1143
|
-
}
|
|
1144
|
-
let headers;
|
|
1145
|
-
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1146
|
-
headers = { ...config.customHeaders };
|
|
1147
|
-
} else {
|
|
1148
|
-
headers = {
|
|
1149
|
-
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1150
|
-
"Content-Type": "application/json",
|
|
1151
|
-
Source: "sdk/createKey"
|
|
1152
|
-
};
|
|
1153
|
-
}
|
|
1154
|
-
const data = JSON.stringify(options);
|
|
1155
|
-
let endpoint = "https://api.pinata.cloud";
|
|
1156
|
-
if (config.endpointUrl) {
|
|
1157
|
-
endpoint = config.endpointUrl;
|
|
1158
|
-
}
|
|
1159
|
-
try {
|
|
1160
|
-
const request = await fetch(`${endpoint}/v3/pinata/keys`, {
|
|
1161
|
-
method: "POST",
|
|
1162
|
-
headers,
|
|
1163
|
-
body: data
|
|
1164
|
-
});
|
|
1165
|
-
if (!request.ok) {
|
|
1166
|
-
const errorData = await request.text();
|
|
1167
|
-
if (request.status === 401 || request.status === 403) {
|
|
1168
|
-
throw new AuthenticationError(
|
|
1169
|
-
`Authentication failed: ${errorData}`,
|
|
1170
|
-
request.status,
|
|
1171
|
-
errorData
|
|
1172
|
-
);
|
|
1173
|
-
}
|
|
1174
|
-
throw new NetworkError(
|
|
1175
|
-
`HTTP error: ${errorData}`,
|
|
1176
|
-
request.status,
|
|
1177
|
-
errorData
|
|
1178
|
-
);
|
|
1179
|
-
}
|
|
1180
|
-
const res = await request.json();
|
|
1181
|
-
return res;
|
|
1182
|
-
} catch (error) {
|
|
1183
|
-
if (error instanceof PinataError) {
|
|
1184
|
-
throw error;
|
|
1185
|
-
}
|
|
1186
|
-
if (error instanceof Error) {
|
|
1187
|
-
throw new PinataError(`Error processing createKey: ${error.message}`);
|
|
1188
|
-
}
|
|
1189
|
-
throw new PinataError("An unknown error occurred while creating API key");
|
|
1190
|
-
}
|
|
1191
|
-
};
|
|
1192
|
-
|
|
1193
|
-
// src/core/keys/listKeys.ts
|
|
1194
|
-
var listKeys = async (config, options) => {
|
|
1195
|
-
if (!config) {
|
|
1196
|
-
throw new ValidationError("Pinata configuration is missing");
|
|
1197
|
-
}
|
|
1198
|
-
let headers;
|
|
1199
|
-
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1200
|
-
headers = { ...config.customHeaders };
|
|
1201
|
-
} else {
|
|
1202
|
-
headers = {
|
|
1203
|
-
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1204
|
-
"Content-Type": "application/json",
|
|
1205
|
-
Source: "sdk/listKeys"
|
|
1206
|
-
};
|
|
1207
|
-
}
|
|
1208
|
-
const params = new URLSearchParams();
|
|
1209
|
-
if (options) {
|
|
1210
|
-
const { offset, name, revoked, limitedUse, exhausted } = options;
|
|
1211
|
-
if (offset)
|
|
1212
|
-
params.append("offset", offset.toString());
|
|
1213
|
-
if (revoked !== void 0)
|
|
1214
|
-
params.append("revoked", revoked.toString());
|
|
1215
|
-
if (limitedUse !== void 0)
|
|
1216
|
-
params.append("limitedUse", limitedUse.toString());
|
|
1217
|
-
if (exhausted !== void 0)
|
|
1218
|
-
params.append("exhausted", exhausted.toString());
|
|
1219
|
-
if (name)
|
|
1220
|
-
params.append("name", name);
|
|
1221
|
-
}
|
|
1222
|
-
let endpoint = "https://api.pinata.cloud";
|
|
1223
|
-
if (config.endpointUrl) {
|
|
1224
|
-
endpoint = config.endpointUrl;
|
|
1225
|
-
}
|
|
1226
|
-
try {
|
|
1227
|
-
const request = await fetch(
|
|
1228
|
-
`${endpoint}/v3/pinata/keys?${params.toString()}`,
|
|
1229
|
-
{
|
|
1230
|
-
method: "GET",
|
|
1231
|
-
headers
|
|
1232
|
-
}
|
|
1233
|
-
);
|
|
1234
|
-
if (!request.ok) {
|
|
1235
|
-
const errorData = await request.text();
|
|
1236
|
-
if (request.status === 401 || request.status === 403) {
|
|
1237
|
-
throw new AuthenticationError(
|
|
1238
|
-
`Authentication failed: ${errorData}`,
|
|
1239
|
-
request.status,
|
|
1240
|
-
errorData
|
|
1241
|
-
);
|
|
1242
|
-
}
|
|
1243
|
-
throw new NetworkError(
|
|
1244
|
-
`HTTP error: ${errorData}`,
|
|
1245
|
-
request.status,
|
|
1246
|
-
errorData
|
|
1247
|
-
);
|
|
1248
|
-
}
|
|
1249
|
-
const res = await request.json();
|
|
1250
|
-
return res.keys;
|
|
1251
|
-
} catch (error) {
|
|
1252
|
-
if (error instanceof PinataError) {
|
|
1253
|
-
throw error;
|
|
1254
|
-
}
|
|
1255
|
-
if (error instanceof Error) {
|
|
1256
|
-
throw new PinataError(`Error processing listKeys: ${error.message}`);
|
|
1257
|
-
}
|
|
1258
|
-
throw new PinataError("An unknown error occurred while listing API keys");
|
|
1259
|
-
}
|
|
1260
|
-
};
|
|
1261
|
-
|
|
1262
|
-
// src/core/keys/revokeKeys.ts
|
|
1263
|
-
var wait2 = (milliseconds) => {
|
|
1264
|
-
return new Promise((resolve) => {
|
|
1265
|
-
setTimeout(resolve, milliseconds);
|
|
1266
|
-
});
|
|
1267
|
-
};
|
|
1268
|
-
var revokeKeys = async (config, keys) => {
|
|
748
|
+
// src/core/keys/revokeKeys.ts
|
|
749
|
+
var wait2 = (milliseconds) => {
|
|
750
|
+
return new Promise((resolve) => {
|
|
751
|
+
setTimeout(resolve, milliseconds);
|
|
752
|
+
});
|
|
753
|
+
};
|
|
754
|
+
var revokeKeys = async (config, keys) => {
|
|
1269
755
|
if (!config) {
|
|
1270
756
|
throw new ValidationError("Pinata configuration is missing");
|
|
1271
757
|
}
|
|
@@ -1280,13 +766,13 @@ var revokeKeys = async (config, keys) => {
|
|
|
1280
766
|
};
|
|
1281
767
|
}
|
|
1282
768
|
const responses = [];
|
|
1283
|
-
let endpoint = "https://api.pinata.cloud";
|
|
769
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
1284
770
|
if (config.endpointUrl) {
|
|
1285
771
|
endpoint = config.endpointUrl;
|
|
1286
772
|
}
|
|
1287
773
|
for (const key of keys) {
|
|
1288
774
|
try {
|
|
1289
|
-
const request = await fetch(`${endpoint}/
|
|
775
|
+
const request = await fetch(`${endpoint}/pinata/keys/${key}`, {
|
|
1290
776
|
method: "PUT",
|
|
1291
777
|
headers
|
|
1292
778
|
});
|
|
@@ -1334,7 +820,10 @@ var createGroup = async (config, options) => {
|
|
|
1334
820
|
if (!config) {
|
|
1335
821
|
throw new ValidationError("Pinata configuration is missing");
|
|
1336
822
|
}
|
|
1337
|
-
const data = JSON.stringify(
|
|
823
|
+
const data = JSON.stringify({
|
|
824
|
+
name: options.name,
|
|
825
|
+
is_public: options.isPublic
|
|
826
|
+
});
|
|
1338
827
|
let headers;
|
|
1339
828
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1340
829
|
headers = { ...config.customHeaders };
|
|
@@ -1345,12 +834,12 @@ var createGroup = async (config, options) => {
|
|
|
1345
834
|
Source: "sdk/createGroup"
|
|
1346
835
|
};
|
|
1347
836
|
}
|
|
1348
|
-
let endpoint = "https://api.pinata.cloud";
|
|
837
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
1349
838
|
if (config.endpointUrl) {
|
|
1350
839
|
endpoint = config.endpointUrl;
|
|
1351
840
|
}
|
|
1352
841
|
try {
|
|
1353
|
-
const request = await fetch(`${endpoint}/groups`, {
|
|
842
|
+
const request = await fetch(`${endpoint}/files/groups`, {
|
|
1354
843
|
method: "POST",
|
|
1355
844
|
headers,
|
|
1356
845
|
body: data
|
|
@@ -1371,7 +860,8 @@ var createGroup = async (config, options) => {
|
|
|
1371
860
|
);
|
|
1372
861
|
}
|
|
1373
862
|
const res = await request.json();
|
|
1374
|
-
|
|
863
|
+
const resData = res.data;
|
|
864
|
+
return resData;
|
|
1375
865
|
} catch (error) {
|
|
1376
866
|
if (error instanceof PinataError) {
|
|
1377
867
|
throw error;
|
|
@@ -1400,23 +890,28 @@ var listGroups = async (config, options) => {
|
|
|
1400
890
|
}
|
|
1401
891
|
const params = new URLSearchParams();
|
|
1402
892
|
if (options) {
|
|
1403
|
-
const {
|
|
1404
|
-
if (
|
|
1405
|
-
params.append("
|
|
893
|
+
const { pageToken, nameContains, limit, isPublic } = options;
|
|
894
|
+
if (pageToken)
|
|
895
|
+
params.append("pageToken", pageToken.toString());
|
|
896
|
+
if (isPublic)
|
|
897
|
+
params.append("isPublic", isPublic.toString());
|
|
1406
898
|
if (nameContains !== void 0)
|
|
1407
899
|
params.append("nameContains", nameContains.toString());
|
|
1408
900
|
if (limit !== void 0)
|
|
1409
901
|
params.append("limit", limit.toString());
|
|
1410
902
|
}
|
|
1411
|
-
let endpoint = "https://api.pinata.cloud";
|
|
903
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
1412
904
|
if (config.endpointUrl) {
|
|
1413
905
|
endpoint = config.endpointUrl;
|
|
1414
906
|
}
|
|
1415
907
|
try {
|
|
1416
|
-
const request = await fetch(
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
908
|
+
const request = await fetch(
|
|
909
|
+
`${endpoint}/files/groups?${params.toString()}`,
|
|
910
|
+
{
|
|
911
|
+
method: "GET",
|
|
912
|
+
headers
|
|
913
|
+
}
|
|
914
|
+
);
|
|
1420
915
|
if (!request.ok) {
|
|
1421
916
|
const errorData = await request.text();
|
|
1422
917
|
if (request.status === 401 || request.status === 403) {
|
|
@@ -1433,7 +928,8 @@ var listGroups = async (config, options) => {
|
|
|
1433
928
|
);
|
|
1434
929
|
}
|
|
1435
930
|
const res = await request.json();
|
|
1436
|
-
|
|
931
|
+
const resData = res.data;
|
|
932
|
+
return resData;
|
|
1437
933
|
} catch (error) {
|
|
1438
934
|
if (error instanceof PinataError) {
|
|
1439
935
|
throw error;
|
|
@@ -1460,12 +956,12 @@ var getGroup = async (config, options) => {
|
|
|
1460
956
|
Source: "sdk/getGroup"
|
|
1461
957
|
};
|
|
1462
958
|
}
|
|
1463
|
-
let endpoint = "https://api.pinata.cloud";
|
|
959
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
1464
960
|
if (config.endpointUrl) {
|
|
1465
961
|
endpoint = config.endpointUrl;
|
|
1466
962
|
}
|
|
1467
963
|
try {
|
|
1468
|
-
const request = await fetch(`${endpoint}/groups/${options.groupId}`, {
|
|
964
|
+
const request = await fetch(`${endpoint}/files/groups/${options.groupId}`, {
|
|
1469
965
|
method: "GET",
|
|
1470
966
|
headers
|
|
1471
967
|
});
|
|
@@ -1485,7 +981,8 @@ var getGroup = async (config, options) => {
|
|
|
1485
981
|
);
|
|
1486
982
|
}
|
|
1487
983
|
const res = await request.json();
|
|
1488
|
-
|
|
984
|
+
const resData = res.data;
|
|
985
|
+
return resData;
|
|
1489
986
|
} catch (error) {
|
|
1490
987
|
if (error instanceof PinataError) {
|
|
1491
988
|
throw error;
|
|
@@ -1499,71 +996,14 @@ var getGroup = async (config, options) => {
|
|
|
1499
996
|
}
|
|
1500
997
|
};
|
|
1501
998
|
|
|
1502
|
-
// src/core/groups/addToGroup.ts
|
|
1503
|
-
var addToGroup = async (config, options) => {
|
|
1504
|
-
if (!config) {
|
|
1505
|
-
throw new ValidationError("Pinata configuration is missing");
|
|
1506
|
-
}
|
|
1507
|
-
const data = JSON.stringify({
|
|
1508
|
-
cids: options.cids
|
|
1509
|
-
});
|
|
1510
|
-
let headers;
|
|
1511
|
-
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1512
|
-
headers = { ...config.customHeaders };
|
|
1513
|
-
} else {
|
|
1514
|
-
headers = {
|
|
1515
|
-
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1516
|
-
"Content-Type": "application/json",
|
|
1517
|
-
Source: "sdk/addToGroup"
|
|
1518
|
-
};
|
|
1519
|
-
}
|
|
1520
|
-
let endpoint = "https://api.pinata.cloud";
|
|
1521
|
-
if (config.endpointUrl) {
|
|
1522
|
-
endpoint = config.endpointUrl;
|
|
1523
|
-
}
|
|
1524
|
-
try {
|
|
1525
|
-
const request = await fetch(`${endpoint}/groups/${options.groupId}/cids`, {
|
|
1526
|
-
method: "PUT",
|
|
1527
|
-
headers,
|
|
1528
|
-
body: data
|
|
1529
|
-
});
|
|
1530
|
-
if (!request.ok) {
|
|
1531
|
-
const errorData = await request.text();
|
|
1532
|
-
if (request.status === 401 || request.status === 403) {
|
|
1533
|
-
throw new AuthenticationError(
|
|
1534
|
-
`Authentication failed: ${errorData}`,
|
|
1535
|
-
request.status,
|
|
1536
|
-
errorData
|
|
1537
|
-
);
|
|
1538
|
-
}
|
|
1539
|
-
throw new NetworkError(
|
|
1540
|
-
`HTTP error: ${errorData}`,
|
|
1541
|
-
request.status,
|
|
1542
|
-
errorData
|
|
1543
|
-
);
|
|
1544
|
-
}
|
|
1545
|
-
const res = await request.text();
|
|
1546
|
-
return res;
|
|
1547
|
-
} catch (error) {
|
|
1548
|
-
if (error instanceof PinataError) {
|
|
1549
|
-
throw error;
|
|
1550
|
-
}
|
|
1551
|
-
if (error instanceof Error) {
|
|
1552
|
-
throw new PinataError(`Error processing addToGroup: ${error.message}`);
|
|
1553
|
-
}
|
|
1554
|
-
throw new PinataError(
|
|
1555
|
-
"An unknown error occurred while adding CIDs to group"
|
|
1556
|
-
);
|
|
1557
|
-
}
|
|
1558
|
-
};
|
|
1559
|
-
|
|
1560
999
|
// src/core/groups/updateGroup.ts
|
|
1561
1000
|
var updateGroup = async (config, options) => {
|
|
1562
1001
|
if (!config) {
|
|
1563
1002
|
throw new ValidationError("Pinata configuration is missing");
|
|
1564
1003
|
}
|
|
1565
1004
|
const data = JSON.stringify({
|
|
1566
|
-
name: options.name
|
|
1005
|
+
name: options.name,
|
|
1006
|
+
is_public: options.isPublic
|
|
1567
1007
|
});
|
|
1568
1008
|
let headers;
|
|
1569
1009
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
@@ -1575,12 +1015,12 @@ var updateGroup = async (config, options) => {
|
|
|
1575
1015
|
Source: "sdk/updateGroup"
|
|
1576
1016
|
};
|
|
1577
1017
|
}
|
|
1578
|
-
let endpoint = "https://api.pinata.cloud";
|
|
1018
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
1579
1019
|
if (config.endpointUrl) {
|
|
1580
1020
|
endpoint = config.endpointUrl;
|
|
1581
1021
|
}
|
|
1582
1022
|
try {
|
|
1583
|
-
const request = await fetch(`${endpoint}/groups/${options.groupId}`, {
|
|
1023
|
+
const request = await fetch(`${endpoint}/files/groups/${options.groupId}`, {
|
|
1584
1024
|
method: "PUT",
|
|
1585
1025
|
headers,
|
|
1586
1026
|
body: data
|
|
@@ -1588,569 +1028,8 @@ var updateGroup = async (config, options) => {
|
|
|
1588
1028
|
if (!request.ok) {
|
|
1589
1029
|
const errorData = await request.text();
|
|
1590
1030
|
if (request.status === 401 || request.status === 403) {
|
|
1591
|
-
throw new AuthenticationError(
|
|
1592
|
-
`Authentication failed: ${errorData}`,
|
|
1593
|
-
request.status,
|
|
1594
|
-
errorData
|
|
1595
|
-
);
|
|
1596
|
-
}
|
|
1597
|
-
throw new NetworkError(
|
|
1598
|
-
`HTTP error: ${errorData}`,
|
|
1599
|
-
request.status,
|
|
1600
|
-
errorData
|
|
1601
|
-
);
|
|
1602
|
-
}
|
|
1603
|
-
const res = await request.json();
|
|
1604
|
-
return res;
|
|
1605
|
-
} catch (error) {
|
|
1606
|
-
if (error instanceof PinataError) {
|
|
1607
|
-
throw error;
|
|
1608
|
-
}
|
|
1609
|
-
if (error instanceof Error) {
|
|
1610
|
-
throw new PinataError(`Error processing updateGroup: ${error.message}`);
|
|
1611
|
-
}
|
|
1612
|
-
throw new PinataError("An unknown error occurred while updating group");
|
|
1613
|
-
}
|
|
1614
|
-
};
|
|
1615
|
-
|
|
1616
|
-
// src/core/groups/removeFromGroup.ts
|
|
1617
|
-
var removeFromGroup = async (config, options) => {
|
|
1618
|
-
if (!config) {
|
|
1619
|
-
throw new ValidationError("Pinata configuration is missing");
|
|
1620
|
-
}
|
|
1621
|
-
let headers;
|
|
1622
|
-
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1623
|
-
headers = { ...config.customHeaders };
|
|
1624
|
-
} else {
|
|
1625
|
-
headers = {
|
|
1626
|
-
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1627
|
-
"Content-Type": "application/json",
|
|
1628
|
-
Source: "sdk/removeFromGroup"
|
|
1629
|
-
};
|
|
1630
|
-
}
|
|
1631
|
-
const data = JSON.stringify({
|
|
1632
|
-
cids: options.cids
|
|
1633
|
-
});
|
|
1634
|
-
let endpoint = "https://api.pinata.cloud";
|
|
1635
|
-
if (config.endpointUrl) {
|
|
1636
|
-
endpoint = config.endpointUrl;
|
|
1637
|
-
}
|
|
1638
|
-
try {
|
|
1639
|
-
const request = await fetch(`${endpoint}/groups/${options.groupId}/cids`, {
|
|
1640
|
-
method: "DELETE",
|
|
1641
|
-
headers,
|
|
1642
|
-
body: data
|
|
1643
|
-
});
|
|
1644
|
-
if (!request.ok) {
|
|
1645
|
-
const errorData = await request.text();
|
|
1646
|
-
if (request.status === 401 || request.status === 403) {
|
|
1647
|
-
throw new AuthenticationError(
|
|
1648
|
-
`Authentication failed: ${errorData}`,
|
|
1649
|
-
request.status,
|
|
1650
|
-
errorData
|
|
1651
|
-
);
|
|
1652
|
-
}
|
|
1653
|
-
throw new NetworkError(
|
|
1654
|
-
`HTTP error: ${errorData}`,
|
|
1655
|
-
request.status,
|
|
1656
|
-
errorData
|
|
1657
|
-
);
|
|
1658
|
-
}
|
|
1659
|
-
const res = await request.text();
|
|
1660
|
-
return res;
|
|
1661
|
-
} catch (error) {
|
|
1662
|
-
if (error instanceof PinataError) {
|
|
1663
|
-
throw error;
|
|
1664
|
-
}
|
|
1665
|
-
if (error instanceof Error) {
|
|
1666
|
-
throw new PinataError(
|
|
1667
|
-
`Error processing removeFromGroup: ${error.message}`
|
|
1668
|
-
);
|
|
1669
|
-
}
|
|
1670
|
-
throw new PinataError(
|
|
1671
|
-
"An unknown error occurred while removing CIDs from a group"
|
|
1672
|
-
);
|
|
1673
|
-
}
|
|
1674
|
-
};
|
|
1675
|
-
|
|
1676
|
-
// src/core/groups/deleteGroup.ts
|
|
1677
|
-
var deleteGroup = async (config, options) => {
|
|
1678
|
-
if (!config) {
|
|
1679
|
-
throw new ValidationError("Pinata configuration is missing");
|
|
1680
|
-
}
|
|
1681
|
-
let headers;
|
|
1682
|
-
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1683
|
-
headers = { ...config.customHeaders };
|
|
1684
|
-
} else {
|
|
1685
|
-
headers = {
|
|
1686
|
-
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1687
|
-
"Content-Type": "application/json",
|
|
1688
|
-
Source: "sdk/deleteGroup"
|
|
1689
|
-
};
|
|
1690
|
-
}
|
|
1691
|
-
let endpoint = "https://api.pinata.cloud";
|
|
1692
|
-
if (config.endpointUrl) {
|
|
1693
|
-
endpoint = config.endpointUrl;
|
|
1694
|
-
}
|
|
1695
|
-
try {
|
|
1696
|
-
const request = await fetch(`${endpoint}/groups/${options.groupId}`, {
|
|
1697
|
-
method: "DELETE",
|
|
1698
|
-
headers
|
|
1699
|
-
});
|
|
1700
|
-
if (!request.ok) {
|
|
1701
|
-
const errorData = await request.text();
|
|
1702
|
-
if (request.status === 401 || request.status === 403) {
|
|
1703
|
-
throw new AuthenticationError(
|
|
1704
|
-
`Authentication failed: ${errorData}`,
|
|
1705
|
-
request.status,
|
|
1706
|
-
errorData
|
|
1707
|
-
);
|
|
1708
|
-
}
|
|
1709
|
-
throw new NetworkError(
|
|
1710
|
-
`HTTP error: ${errorData}`,
|
|
1711
|
-
request.status,
|
|
1712
|
-
errorData
|
|
1713
|
-
);
|
|
1714
|
-
}
|
|
1715
|
-
const res = await request.text();
|
|
1716
|
-
return res;
|
|
1717
|
-
} catch (error) {
|
|
1718
|
-
if (error instanceof PinataError) {
|
|
1719
|
-
throw error;
|
|
1720
|
-
}
|
|
1721
|
-
if (error instanceof Error) {
|
|
1722
|
-
throw new PinataError(`Error processing deleteGroup: ${error.message}`);
|
|
1723
|
-
}
|
|
1724
|
-
throw new PinataError("An unknown error occurred while deleting a group");
|
|
1725
|
-
}
|
|
1726
|
-
};
|
|
1727
|
-
|
|
1728
|
-
// src/core/signatures/addSignature.ts
|
|
1729
|
-
var addSignature = async (config, options) => {
|
|
1730
|
-
if (!config) {
|
|
1731
|
-
throw new ValidationError("Pinata configuration is missing");
|
|
1732
|
-
}
|
|
1733
|
-
const data = JSON.stringify({
|
|
1734
|
-
signature: options.signature
|
|
1735
|
-
});
|
|
1736
|
-
let headers;
|
|
1737
|
-
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1738
|
-
headers = { ...config.customHeaders };
|
|
1739
|
-
} else {
|
|
1740
|
-
headers = {
|
|
1741
|
-
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1742
|
-
"Content-Type": "application/json",
|
|
1743
|
-
Source: "sdk/addSignature"
|
|
1744
|
-
};
|
|
1745
|
-
}
|
|
1746
|
-
let endpoint = "https://api.pinata.cloud";
|
|
1747
|
-
if (config.endpointUrl) {
|
|
1748
|
-
endpoint = config.endpointUrl;
|
|
1749
|
-
}
|
|
1750
|
-
try {
|
|
1751
|
-
const request = await fetch(
|
|
1752
|
-
`${endpoint}/v3/ipfs/signature/${options.cid}`,
|
|
1753
|
-
{
|
|
1754
|
-
method: "POST",
|
|
1755
|
-
headers,
|
|
1756
|
-
body: data
|
|
1757
|
-
}
|
|
1758
|
-
);
|
|
1759
|
-
if (!request.ok) {
|
|
1760
|
-
const errorData = await request.text();
|
|
1761
|
-
if (request.status === 401 || request.status === 403) {
|
|
1762
|
-
throw new AuthenticationError(
|
|
1763
|
-
`Authentication failed: ${errorData}`,
|
|
1764
|
-
request.status,
|
|
1765
|
-
errorData
|
|
1766
|
-
);
|
|
1767
|
-
}
|
|
1768
|
-
if (request.status === 403) {
|
|
1769
|
-
throw new PinataError(
|
|
1770
|
-
"Unauthorized signing, you must be the original owner of the file and it must not have a signature",
|
|
1771
|
-
request.status,
|
|
1772
|
-
errorData
|
|
1773
|
-
);
|
|
1774
|
-
}
|
|
1775
|
-
throw new NetworkError(
|
|
1776
|
-
`HTTP error: ${errorData}`,
|
|
1777
|
-
request.status,
|
|
1778
|
-
errorData
|
|
1779
|
-
);
|
|
1780
|
-
}
|
|
1781
|
-
const res = await request.json();
|
|
1782
|
-
return res.data;
|
|
1783
|
-
} catch (error) {
|
|
1784
|
-
if (error instanceof PinataError) {
|
|
1785
|
-
throw error;
|
|
1786
|
-
}
|
|
1787
|
-
if (error instanceof Error) {
|
|
1788
|
-
throw new PinataError(`Error processing addSignature: ${error.message}`);
|
|
1789
|
-
}
|
|
1790
|
-
throw new PinataError(
|
|
1791
|
-
"An unknown error occurred while adding signature to CID"
|
|
1792
|
-
);
|
|
1793
|
-
}
|
|
1794
|
-
};
|
|
1795
|
-
|
|
1796
|
-
// src/core/signatures/getSignature.ts
|
|
1797
|
-
var getSignature = async (config, cid) => {
|
|
1798
|
-
if (!config) {
|
|
1799
|
-
throw new ValidationError("Pinata configuration is missing");
|
|
1800
|
-
}
|
|
1801
|
-
let headers;
|
|
1802
|
-
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1803
|
-
headers = { ...config.customHeaders };
|
|
1804
|
-
} else {
|
|
1805
|
-
headers = {
|
|
1806
|
-
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1807
|
-
"Content-Type": "application/json",
|
|
1808
|
-
Source: "sdk/getSignature"
|
|
1809
|
-
};
|
|
1810
|
-
}
|
|
1811
|
-
let endpoint = "https://api.pinata.cloud";
|
|
1812
|
-
if (config.endpointUrl) {
|
|
1813
|
-
endpoint = config.endpointUrl;
|
|
1814
|
-
}
|
|
1815
|
-
try {
|
|
1816
|
-
const request = await fetch(`${endpoint}/v3/ipfs/signature/${cid}`, {
|
|
1817
|
-
method: "GET",
|
|
1818
|
-
headers
|
|
1819
|
-
});
|
|
1820
|
-
if (!request.ok) {
|
|
1821
|
-
const errorData = await request.text();
|
|
1822
|
-
if (request.status === 401 || request.status === 403) {
|
|
1823
|
-
throw new AuthenticationError(
|
|
1824
|
-
`Authentication failed: ${errorData}`,
|
|
1825
|
-
request.status,
|
|
1826
|
-
errorData
|
|
1827
|
-
);
|
|
1828
|
-
}
|
|
1829
|
-
throw new NetworkError(
|
|
1830
|
-
`HTTP error: ${errorData}`,
|
|
1831
|
-
request.status,
|
|
1832
|
-
errorData
|
|
1833
|
-
);
|
|
1834
|
-
}
|
|
1835
|
-
const res = await request.json();
|
|
1836
|
-
return res.data;
|
|
1837
|
-
} catch (error) {
|
|
1838
|
-
if (error instanceof PinataError) {
|
|
1839
|
-
throw error;
|
|
1840
|
-
}
|
|
1841
|
-
if (error instanceof Error) {
|
|
1842
|
-
throw new PinataError(`Error processing getSignature: ${error.message}`);
|
|
1843
|
-
}
|
|
1844
|
-
throw new PinataError(
|
|
1845
|
-
"An unknown error occurred while fetching signature for CID"
|
|
1846
|
-
);
|
|
1847
|
-
}
|
|
1848
|
-
};
|
|
1849
|
-
|
|
1850
|
-
// src/core/signatures/removeSignature.ts
|
|
1851
|
-
var removeSignature = async (config, cid) => {
|
|
1852
|
-
if (!config) {
|
|
1853
|
-
throw new ValidationError("Pinata configuration is missing");
|
|
1854
|
-
}
|
|
1855
|
-
let headers;
|
|
1856
|
-
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1857
|
-
headers = { ...config.customHeaders };
|
|
1858
|
-
} else {
|
|
1859
|
-
headers = {
|
|
1860
|
-
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1861
|
-
"Content-Type": "application/json",
|
|
1862
|
-
Source: "sdk/removeSignature"
|
|
1863
|
-
};
|
|
1864
|
-
}
|
|
1865
|
-
let endpoint = "https://api.pinata.cloud";
|
|
1866
|
-
if (config.endpointUrl) {
|
|
1867
|
-
endpoint = config.endpointUrl;
|
|
1868
|
-
}
|
|
1869
|
-
try {
|
|
1870
|
-
const request = await fetch(`${endpoint}/v3/ipfs/signature/${cid}`, {
|
|
1871
|
-
method: "DELETE",
|
|
1872
|
-
headers
|
|
1873
|
-
});
|
|
1874
|
-
if (!request.ok) {
|
|
1875
|
-
const errorData = await request.text();
|
|
1876
|
-
if (request.status === 401 || request.status === 403) {
|
|
1877
|
-
throw new AuthenticationError(
|
|
1878
|
-
`Authentication failed: ${errorData}`,
|
|
1879
|
-
request.status,
|
|
1880
|
-
errorData
|
|
1881
|
-
);
|
|
1882
|
-
}
|
|
1883
|
-
throw new NetworkError(
|
|
1884
|
-
`HTTP error: ${errorData}`,
|
|
1885
|
-
request.status,
|
|
1886
|
-
errorData
|
|
1887
|
-
);
|
|
1888
|
-
}
|
|
1889
|
-
return "OK";
|
|
1890
|
-
} catch (error) {
|
|
1891
|
-
if (error instanceof PinataError) {
|
|
1892
|
-
throw error;
|
|
1893
|
-
}
|
|
1894
|
-
if (error instanceof Error) {
|
|
1895
|
-
throw new PinataError(`Error processing addSignature: ${error.message}`);
|
|
1896
|
-
}
|
|
1897
|
-
throw new PinataError(
|
|
1898
|
-
"An unknown error occurred while adding signature to CID"
|
|
1899
|
-
);
|
|
1900
|
-
}
|
|
1901
|
-
};
|
|
1902
|
-
|
|
1903
|
-
// src/core/gateway/analyticsTopUsage.ts
|
|
1904
|
-
var analyticsTopUsage = async (config, options) => {
|
|
1905
|
-
if (!config) {
|
|
1906
|
-
throw new ValidationError("Pinata configuration is missing");
|
|
1907
|
-
}
|
|
1908
|
-
const params = new URLSearchParams({
|
|
1909
|
-
includesCount: "false"
|
|
1910
|
-
});
|
|
1911
|
-
if (options) {
|
|
1912
|
-
const {
|
|
1913
|
-
cid,
|
|
1914
|
-
gateway_domain,
|
|
1915
|
-
start_date,
|
|
1916
|
-
end_date,
|
|
1917
|
-
file_name,
|
|
1918
|
-
user_agent,
|
|
1919
|
-
country,
|
|
1920
|
-
region,
|
|
1921
|
-
referer,
|
|
1922
|
-
limit,
|
|
1923
|
-
sort_order,
|
|
1924
|
-
sort_by,
|
|
1925
|
-
attribute
|
|
1926
|
-
} = options;
|
|
1927
|
-
if (cid)
|
|
1928
|
-
params.append("cid", cid);
|
|
1929
|
-
if (gateway_domain)
|
|
1930
|
-
params.append("gateway_domain", gateway_domain);
|
|
1931
|
-
if (start_date)
|
|
1932
|
-
params.append("start_date", start_date);
|
|
1933
|
-
if (end_date)
|
|
1934
|
-
params.append("end_date", end_date);
|
|
1935
|
-
if (file_name)
|
|
1936
|
-
params.append("file_name", file_name);
|
|
1937
|
-
if (user_agent)
|
|
1938
|
-
params.append("user_agent", user_agent.toString());
|
|
1939
|
-
if (country)
|
|
1940
|
-
params.append("country", country.toString());
|
|
1941
|
-
if (region)
|
|
1942
|
-
params.append("region", region);
|
|
1943
|
-
if (referer)
|
|
1944
|
-
params.append("referer", referer.toString());
|
|
1945
|
-
if (limit)
|
|
1946
|
-
params.append("limit", limit.toString());
|
|
1947
|
-
if (sort_order)
|
|
1948
|
-
params.append("sort_order", sort_order);
|
|
1949
|
-
if (sort_by)
|
|
1950
|
-
params.append("sort_by", sort_by);
|
|
1951
|
-
if (attribute)
|
|
1952
|
-
params.append("by", attribute);
|
|
1953
|
-
}
|
|
1954
|
-
let endpoint = "https://api.pinata.cloud";
|
|
1955
|
-
if (config.endpointUrl) {
|
|
1956
|
-
endpoint = config.endpointUrl;
|
|
1957
|
-
}
|
|
1958
|
-
const url = `${endpoint}/v3/ipfs/gateway_analytics_top?${params.toString()}`;
|
|
1959
|
-
try {
|
|
1960
|
-
let headers;
|
|
1961
|
-
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1962
|
-
headers = { ...config.customHeaders };
|
|
1963
|
-
} else {
|
|
1964
|
-
headers = {
|
|
1965
|
-
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1966
|
-
Source: "sdk/analyticsTopUsage"
|
|
1967
|
-
};
|
|
1968
|
-
}
|
|
1969
|
-
const request = await fetch(url, {
|
|
1970
|
-
method: "GET",
|
|
1971
|
-
headers
|
|
1972
|
-
});
|
|
1973
|
-
if (!request.ok) {
|
|
1974
|
-
const errorData = await request.text();
|
|
1975
|
-
if (request.status === 401 || request.status === 403) {
|
|
1976
|
-
throw new AuthenticationError(
|
|
1977
|
-
`Authentication failed: ${errorData}`,
|
|
1978
|
-
request.status,
|
|
1979
|
-
errorData
|
|
1980
|
-
);
|
|
1981
|
-
}
|
|
1982
|
-
throw new NetworkError(
|
|
1983
|
-
`HTTP error: ${errorData}`,
|
|
1984
|
-
request.status,
|
|
1985
|
-
errorData
|
|
1986
|
-
);
|
|
1987
|
-
}
|
|
1988
|
-
const res = await request.json();
|
|
1989
|
-
const resData = res.data;
|
|
1990
|
-
return resData;
|
|
1991
|
-
} catch (error) {
|
|
1992
|
-
if (error instanceof PinataError) {
|
|
1993
|
-
throw error;
|
|
1994
|
-
}
|
|
1995
|
-
if (error instanceof Error) {
|
|
1996
|
-
throw new PinataError(
|
|
1997
|
-
`Error processing anaytics usage: ${error.message}`
|
|
1998
|
-
);
|
|
1999
|
-
}
|
|
2000
|
-
throw new PinataError(
|
|
2001
|
-
"An unknown error occurred while fetching gateway usage"
|
|
2002
|
-
);
|
|
2003
|
-
}
|
|
2004
|
-
};
|
|
2005
|
-
|
|
2006
|
-
// src/core/gateway/analyticsDateInterval.ts
|
|
2007
|
-
var analyticsDateInterval = async (config, options) => {
|
|
2008
|
-
if (!config) {
|
|
2009
|
-
throw new ValidationError("Pinata configuration is missing");
|
|
2010
|
-
}
|
|
2011
|
-
const params = new URLSearchParams();
|
|
2012
|
-
if (options) {
|
|
2013
|
-
const {
|
|
2014
|
-
cid,
|
|
2015
|
-
gateway_domain,
|
|
2016
|
-
start_date,
|
|
2017
|
-
end_date,
|
|
2018
|
-
file_name,
|
|
2019
|
-
user_agent,
|
|
2020
|
-
country,
|
|
2021
|
-
region,
|
|
2022
|
-
referer,
|
|
2023
|
-
limit,
|
|
2024
|
-
sort_order,
|
|
2025
|
-
date_interval,
|
|
2026
|
-
sort_by
|
|
2027
|
-
} = options;
|
|
2028
|
-
if (cid)
|
|
2029
|
-
params.append("cid", cid);
|
|
2030
|
-
if (gateway_domain)
|
|
2031
|
-
params.append("gateway_domain", gateway_domain);
|
|
2032
|
-
if (start_date)
|
|
2033
|
-
params.append("start_date", start_date);
|
|
2034
|
-
if (end_date)
|
|
2035
|
-
params.append("end_date", end_date);
|
|
2036
|
-
if (file_name)
|
|
2037
|
-
params.append("file_name", file_name);
|
|
2038
|
-
if (user_agent)
|
|
2039
|
-
params.append("user_agent", user_agent.toString());
|
|
2040
|
-
if (country)
|
|
2041
|
-
params.append("country", country.toString());
|
|
2042
|
-
if (region)
|
|
2043
|
-
params.append("region", region);
|
|
2044
|
-
if (referer)
|
|
2045
|
-
params.append("referer", referer.toString());
|
|
2046
|
-
if (limit)
|
|
2047
|
-
params.append("limit", limit.toString());
|
|
2048
|
-
if (sort_order)
|
|
2049
|
-
params.append("sort_order", sort_order);
|
|
2050
|
-
if (sort_by)
|
|
2051
|
-
params.append("sort_by", sort_by);
|
|
2052
|
-
if (date_interval)
|
|
2053
|
-
params.append("by", date_interval);
|
|
2054
|
-
}
|
|
2055
|
-
let endpoint = "https://api.pinata.cloud";
|
|
2056
|
-
if (config.endpointUrl) {
|
|
2057
|
-
endpoint = config.endpointUrl;
|
|
2058
|
-
}
|
|
2059
|
-
const url = `${endpoint}/v3/ipfs/gateway_analytics_time_series?${params.toString()}`;
|
|
2060
|
-
try {
|
|
2061
|
-
let headers;
|
|
2062
|
-
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
2063
|
-
headers = { ...config.customHeaders };
|
|
2064
|
-
} else {
|
|
2065
|
-
headers = {
|
|
2066
|
-
Authorization: `Bearer ${config.pinataJwt}`,
|
|
2067
|
-
Source: "sdk/analyticsDateInterval"
|
|
2068
|
-
};
|
|
2069
|
-
}
|
|
2070
|
-
const request = await fetch(url, {
|
|
2071
|
-
method: "GET",
|
|
2072
|
-
headers
|
|
2073
|
-
});
|
|
2074
|
-
if (!request.ok) {
|
|
2075
|
-
const errorData = await request.text();
|
|
2076
|
-
if (request.status === 401 || request.status === 403) {
|
|
2077
|
-
throw new AuthenticationError(
|
|
2078
|
-
`Authentication failed: ${errorData}`,
|
|
2079
|
-
request.status,
|
|
2080
|
-
errorData
|
|
2081
|
-
);
|
|
2082
|
-
}
|
|
2083
|
-
throw new NetworkError(
|
|
2084
|
-
`HTTP error: ${errorData}`,
|
|
2085
|
-
request.status,
|
|
2086
|
-
errorData
|
|
2087
|
-
);
|
|
2088
|
-
}
|
|
2089
|
-
const res = await request.json();
|
|
2090
|
-
const resData = res.data;
|
|
2091
|
-
return resData;
|
|
2092
|
-
} catch (error) {
|
|
2093
|
-
if (error instanceof PinataError) {
|
|
2094
|
-
throw error;
|
|
2095
|
-
}
|
|
2096
|
-
if (error instanceof Error) {
|
|
2097
|
-
throw new PinataError(
|
|
2098
|
-
`Error processing anaytics usage: ${error.message}`
|
|
2099
|
-
);
|
|
2100
|
-
}
|
|
2101
|
-
throw new PinataError(
|
|
2102
|
-
"An unknown error occurred while fetching gateway usage"
|
|
2103
|
-
);
|
|
2104
|
-
}
|
|
2105
|
-
};
|
|
2106
|
-
|
|
2107
|
-
// src/core/gateway/swapCid.ts
|
|
2108
|
-
var swapCid = async (config, options) => {
|
|
2109
|
-
if (!config) {
|
|
2110
|
-
throw new ValidationError("Pinata configuration is missing");
|
|
2111
|
-
}
|
|
2112
|
-
const data = JSON.stringify({
|
|
2113
|
-
swapCid: options.swapCid
|
|
2114
|
-
});
|
|
2115
|
-
let headers;
|
|
2116
|
-
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
2117
|
-
headers = { ...config.customHeaders };
|
|
2118
|
-
} else {
|
|
2119
|
-
headers = {
|
|
2120
|
-
Authorization: `Bearer ${config.pinataJwt}`,
|
|
2121
|
-
"Content-Type": "application/json",
|
|
2122
|
-
Source: "sdk/swapCid"
|
|
2123
|
-
};
|
|
2124
|
-
}
|
|
2125
|
-
let endpoint = "https://api.pinata.cloud";
|
|
2126
|
-
if (config.endpointUrl) {
|
|
2127
|
-
endpoint = config.endpointUrl;
|
|
2128
|
-
}
|
|
2129
|
-
try {
|
|
2130
|
-
const request = await fetch(`${endpoint}/v3/ipfs/swap/${options.cid}`, {
|
|
2131
|
-
method: "PUT",
|
|
2132
|
-
headers,
|
|
2133
|
-
body: data
|
|
2134
|
-
});
|
|
2135
|
-
if (!request.ok) {
|
|
2136
|
-
const errorData = await request.text();
|
|
2137
|
-
if (request.status === 401 || request.status === 403) {
|
|
2138
|
-
throw new AuthenticationError(
|
|
2139
|
-
`Authentication failed: ${errorData}`,
|
|
2140
|
-
request.status,
|
|
2141
|
-
errorData
|
|
2142
|
-
);
|
|
2143
|
-
}
|
|
2144
|
-
if (request.status === 403) {
|
|
2145
|
-
throw new PinataError(
|
|
2146
|
-
"Unauthorized CID Swap",
|
|
2147
|
-
request.status,
|
|
2148
|
-
errorData
|
|
2149
|
-
);
|
|
2150
|
-
}
|
|
2151
|
-
if (request.status === 404) {
|
|
2152
|
-
throw new PinataError(
|
|
2153
|
-
"CID not pinned to account",
|
|
1031
|
+
throw new AuthenticationError(
|
|
1032
|
+
`Authentication failed: ${errorData}`,
|
|
2154
1033
|
request.status,
|
|
2155
1034
|
errorData
|
|
2156
1035
|
);
|
|
@@ -2169,14 +1048,14 @@ var swapCid = async (config, options) => {
|
|
|
2169
1048
|
throw error;
|
|
2170
1049
|
}
|
|
2171
1050
|
if (error instanceof Error) {
|
|
2172
|
-
throw new PinataError(`Error processing
|
|
1051
|
+
throw new PinataError(`Error processing updateGroup: ${error.message}`);
|
|
2173
1052
|
}
|
|
2174
|
-
throw new PinataError("An unknown error occurred while
|
|
1053
|
+
throw new PinataError("An unknown error occurred while updating group");
|
|
2175
1054
|
}
|
|
2176
1055
|
};
|
|
2177
1056
|
|
|
2178
|
-
// src/core/
|
|
2179
|
-
var
|
|
1057
|
+
// src/core/groups/deleteGroup.ts
|
|
1058
|
+
var deleteGroup = async (config, options) => {
|
|
2180
1059
|
if (!config) {
|
|
2181
1060
|
throw new ValidationError("Pinata configuration is missing");
|
|
2182
1061
|
}
|
|
@@ -2187,21 +1066,18 @@ var swapHistory = async (config, options) => {
|
|
|
2187
1066
|
headers = {
|
|
2188
1067
|
Authorization: `Bearer ${config.pinataJwt}`,
|
|
2189
1068
|
"Content-Type": "application/json",
|
|
2190
|
-
Source: "sdk/
|
|
1069
|
+
Source: "sdk/deleteGroup"
|
|
2191
1070
|
};
|
|
2192
1071
|
}
|
|
2193
|
-
let endpoint = "https://api.pinata.cloud";
|
|
1072
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
2194
1073
|
if (config.endpointUrl) {
|
|
2195
1074
|
endpoint = config.endpointUrl;
|
|
2196
1075
|
}
|
|
2197
1076
|
try {
|
|
2198
|
-
const request = await fetch(
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
headers
|
|
2203
|
-
}
|
|
2204
|
-
);
|
|
1077
|
+
const request = await fetch(`${endpoint}/files/groups/${options.groupId}`, {
|
|
1078
|
+
method: "DELETE",
|
|
1079
|
+
headers
|
|
1080
|
+
});
|
|
2205
1081
|
if (!request.ok) {
|
|
2206
1082
|
const errorData = await request.text();
|
|
2207
1083
|
if (request.status === 401 || request.status === 403) {
|
|
@@ -2211,78 +1087,52 @@ var swapHistory = async (config, options) => {
|
|
|
2211
1087
|
errorData
|
|
2212
1088
|
);
|
|
2213
1089
|
}
|
|
2214
|
-
if (request.status === 404) {
|
|
2215
|
-
throw new PinataError(
|
|
2216
|
-
"CID does not have history",
|
|
2217
|
-
request.status,
|
|
2218
|
-
errorData
|
|
2219
|
-
);
|
|
2220
|
-
}
|
|
2221
1090
|
throw new NetworkError(
|
|
2222
1091
|
`HTTP error: ${errorData}`,
|
|
2223
1092
|
request.status,
|
|
2224
1093
|
errorData
|
|
2225
1094
|
);
|
|
2226
1095
|
}
|
|
2227
|
-
const res =
|
|
2228
|
-
|
|
2229
|
-
return resData;
|
|
1096
|
+
const res = request.statusText;
|
|
1097
|
+
return res;
|
|
2230
1098
|
} catch (error) {
|
|
2231
1099
|
if (error instanceof PinataError) {
|
|
2232
1100
|
throw error;
|
|
2233
1101
|
}
|
|
2234
1102
|
if (error instanceof Error) {
|
|
2235
|
-
throw new PinataError(`Error
|
|
1103
|
+
throw new PinataError(`Error processing deleteGroup: ${error.message}`);
|
|
2236
1104
|
}
|
|
2237
|
-
throw new PinataError(
|
|
2238
|
-
"An unknown error occurred while fetching swap history"
|
|
2239
|
-
);
|
|
1105
|
+
throw new PinataError("An unknown error occurred while deleting a group");
|
|
2240
1106
|
}
|
|
2241
1107
|
};
|
|
2242
1108
|
|
|
2243
|
-
// src/core/gateway/
|
|
2244
|
-
var
|
|
1109
|
+
// src/core/gateway/createSignedURL.ts
|
|
1110
|
+
var createSignedURL = async (config, options) => {
|
|
2245
1111
|
if (!config) {
|
|
2246
1112
|
throw new ValidationError("Pinata configuration is missing");
|
|
2247
1113
|
}
|
|
2248
|
-
let
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
};
|
|
2257
|
-
}
|
|
2258
|
-
let endpoint = "https://api.pinata.cloud";
|
|
2259
|
-
if (config.endpointUrl) {
|
|
2260
|
-
endpoint = config.endpointUrl;
|
|
2261
|
-
}
|
|
1114
|
+
let newUrl = `${config?.pinataGateway}/files/${options.cid}`;
|
|
1115
|
+
const date = options?.date || Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3);
|
|
1116
|
+
const payload = JSON.stringify({
|
|
1117
|
+
url: newUrl,
|
|
1118
|
+
date,
|
|
1119
|
+
expires: options.expires,
|
|
1120
|
+
method: "GET"
|
|
1121
|
+
});
|
|
2262
1122
|
try {
|
|
2263
|
-
const request = await fetch(
|
|
2264
|
-
method: "
|
|
2265
|
-
headers
|
|
1123
|
+
const request = await fetch("https://api.pinata.cloud/v3/files/sign", {
|
|
1124
|
+
method: "POST",
|
|
1125
|
+
headers: {
|
|
1126
|
+
"Content-Type": "application/json",
|
|
1127
|
+
Authorization: `Bearer ${config?.pinataJwt}`
|
|
1128
|
+
},
|
|
1129
|
+
body: payload
|
|
2266
1130
|
});
|
|
2267
1131
|
if (!request.ok) {
|
|
2268
1132
|
const errorData = await request.text();
|
|
2269
1133
|
if (request.status === 401 || request.status === 403) {
|
|
2270
1134
|
throw new AuthenticationError(
|
|
2271
|
-
`Authentication
|
|
2272
|
-
request.status,
|
|
2273
|
-
errorData
|
|
2274
|
-
);
|
|
2275
|
-
}
|
|
2276
|
-
if (request.status === 403) {
|
|
2277
|
-
throw new PinataError(
|
|
2278
|
-
"Unauthorized CID Swap Deletion",
|
|
2279
|
-
request.status,
|
|
2280
|
-
errorData
|
|
2281
|
-
);
|
|
2282
|
-
}
|
|
2283
|
-
if (request.status === 404) {
|
|
2284
|
-
throw new PinataError(
|
|
2285
|
-
"CID not pinned to account",
|
|
1135
|
+
`Authentication Failed: ${errorData}`,
|
|
2286
1136
|
request.status,
|
|
2287
1137
|
errorData
|
|
2288
1138
|
);
|
|
@@ -2293,15 +1143,18 @@ var deleteSwap = async (config, cid) => {
|
|
|
2293
1143
|
errorData
|
|
2294
1144
|
);
|
|
2295
1145
|
}
|
|
2296
|
-
|
|
1146
|
+
const res = await request.json();
|
|
1147
|
+
return res.data;
|
|
2297
1148
|
} catch (error) {
|
|
2298
1149
|
if (error instanceof PinataError) {
|
|
2299
1150
|
throw error;
|
|
2300
1151
|
}
|
|
2301
1152
|
if (error instanceof Error) {
|
|
2302
|
-
throw new PinataError(
|
|
1153
|
+
throw new PinataError(
|
|
1154
|
+
`Error processing createSignedURL: ${error.message}`
|
|
1155
|
+
);
|
|
2303
1156
|
}
|
|
2304
|
-
throw new PinataError("An unknown error occurred while
|
|
1157
|
+
throw new PinataError("An unknown error occurred while getting signed url");
|
|
2305
1158
|
}
|
|
2306
1159
|
};
|
|
2307
1160
|
|
|
@@ -2317,41 +1170,45 @@ var formatConfig = (config) => {
|
|
|
2317
1170
|
return config;
|
|
2318
1171
|
};
|
|
2319
1172
|
var PinataSDK = class {
|
|
1173
|
+
//signatures: Signatures;
|
|
2320
1174
|
constructor(config) {
|
|
2321
1175
|
this.config = formatConfig(config);
|
|
1176
|
+
this.files = new Files(this.config);
|
|
2322
1177
|
this.upload = new Upload(this.config);
|
|
2323
1178
|
this.gateways = new Gateways(this.config);
|
|
2324
|
-
this.usage = new Usage(this.config);
|
|
2325
1179
|
this.keys = new Keys(this.config);
|
|
2326
1180
|
this.groups = new Groups(this.config);
|
|
2327
|
-
this.signatures = new Signatures(this.config);
|
|
2328
1181
|
}
|
|
2329
1182
|
setNewHeaders(headers) {
|
|
2330
1183
|
if (!this.config) {
|
|
2331
1184
|
this.config = { pinataJwt: "", customHeaders: {} };
|
|
2332
1185
|
}
|
|
2333
1186
|
this.config.customHeaders = { ...this.config.customHeaders, ...headers };
|
|
1187
|
+
this.files.updateConfig(this.config);
|
|
2334
1188
|
this.upload.updateConfig(this.config);
|
|
2335
1189
|
this.gateways.updateConfig(this.config);
|
|
2336
|
-
this.usage.updateConfig(this.config);
|
|
2337
1190
|
this.keys.updateConfig(this.config);
|
|
2338
1191
|
this.groups.updateConfig(this.config);
|
|
2339
|
-
this.signatures.updateConfig(this.config);
|
|
2340
1192
|
}
|
|
2341
1193
|
testAuthentication() {
|
|
2342
1194
|
return testAuthentication(this.config);
|
|
2343
1195
|
}
|
|
2344
|
-
|
|
2345
|
-
|
|
1196
|
+
};
|
|
1197
|
+
var Files = class {
|
|
1198
|
+
constructor(config) {
|
|
1199
|
+
this.config = formatConfig(config);
|
|
1200
|
+
}
|
|
1201
|
+
updateConfig(newConfig) {
|
|
1202
|
+
this.config = newConfig;
|
|
2346
1203
|
}
|
|
2347
|
-
|
|
1204
|
+
list() {
|
|
2348
1205
|
return new FilterFiles(this.config);
|
|
2349
1206
|
}
|
|
2350
|
-
|
|
2351
|
-
return
|
|
1207
|
+
delete(files) {
|
|
1208
|
+
return deleteFile(this.config, files);
|
|
2352
1209
|
}
|
|
2353
|
-
|
|
2354
|
-
return
|
|
1210
|
+
update(options) {
|
|
1211
|
+
return updateFile(this.config, options);
|
|
2355
1212
|
}
|
|
2356
1213
|
};
|
|
2357
1214
|
var UploadBuilder = class {
|
|
@@ -2359,7 +1216,6 @@ var UploadBuilder = class {
|
|
|
2359
1216
|
this.config = config;
|
|
2360
1217
|
this.uploadFunction = uploadFunction;
|
|
2361
1218
|
this.args = args;
|
|
2362
|
-
this.version = 1;
|
|
2363
1219
|
}
|
|
2364
1220
|
addMetadata(metadata) {
|
|
2365
1221
|
this.metadata = metadata;
|
|
@@ -2369,18 +1225,14 @@ var UploadBuilder = class {
|
|
|
2369
1225
|
this.keys = jwt;
|
|
2370
1226
|
return this;
|
|
2371
1227
|
}
|
|
2372
|
-
cidVersion(v) {
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
}
|
|
1228
|
+
// cidVersion(v: 0 | 1): UploadBuilder<T> {
|
|
1229
|
+
// this.version = v;
|
|
1230
|
+
// return this;
|
|
1231
|
+
// }
|
|
2376
1232
|
group(groupId) {
|
|
2377
1233
|
this.groupId = groupId;
|
|
2378
1234
|
return this;
|
|
2379
1235
|
}
|
|
2380
|
-
peerAddress(peerAddresses) {
|
|
2381
|
-
this.peerAddresses = peerAddresses;
|
|
2382
|
-
return this;
|
|
2383
|
-
}
|
|
2384
1236
|
then(onfulfilled, onrejected) {
|
|
2385
1237
|
const options = this.args[this.args.length - 1] || {};
|
|
2386
1238
|
if (this.metadata) {
|
|
@@ -2392,12 +1244,6 @@ var UploadBuilder = class {
|
|
|
2392
1244
|
if (this.groupId) {
|
|
2393
1245
|
options.groupId = this.groupId;
|
|
2394
1246
|
}
|
|
2395
|
-
if (this.version) {
|
|
2396
|
-
options.cidVersion = this.version;
|
|
2397
|
-
}
|
|
2398
|
-
if (this.peerAddresses && "peerAddresses" in options) {
|
|
2399
|
-
options.peerAddresses = this.peerAddresses;
|
|
2400
|
-
}
|
|
2401
1247
|
this.args[this.args.length - 1] = options;
|
|
2402
1248
|
return this.uploadFunction(this.config, ...this.args).then(
|
|
2403
1249
|
onfulfilled,
|
|
@@ -2415,9 +1261,12 @@ var Upload = class {
|
|
|
2415
1261
|
file(file, options) {
|
|
2416
1262
|
return new UploadBuilder(this.config, uploadFile, file, options);
|
|
2417
1263
|
}
|
|
2418
|
-
fileArray(
|
|
2419
|
-
|
|
2420
|
-
|
|
1264
|
+
// fileArray(
|
|
1265
|
+
// files: FileObject[],
|
|
1266
|
+
// options?: UploadOptions,
|
|
1267
|
+
// ): UploadBuilder<UploadResponse> {
|
|
1268
|
+
// return new UploadBuilder(this.config, uploadFileArray, files, options);
|
|
1269
|
+
// }
|
|
2421
1270
|
base64(base64String, options) {
|
|
2422
1271
|
return new UploadBuilder(this.config, uploadBase64, base64String, options);
|
|
2423
1272
|
}
|
|
@@ -2427,97 +1276,58 @@ var Upload = class {
|
|
|
2427
1276
|
json(data, options) {
|
|
2428
1277
|
return new UploadBuilder(this.config, uploadJson, data, options);
|
|
2429
1278
|
}
|
|
2430
|
-
cid(cid, options) {
|
|
2431
|
-
return new UploadBuilder(this.config, uploadCid, cid, options);
|
|
2432
|
-
}
|
|
2433
1279
|
};
|
|
2434
1280
|
var FilterFiles = class {
|
|
1281
|
+
// rate limit vars
|
|
1282
|
+
// private requestCount = 0;
|
|
1283
|
+
// private lastRequestTime = 0;
|
|
1284
|
+
// private readonly MAX_REQUESTS_PER_MINUTE = 30;
|
|
1285
|
+
// private readonly MINUTE_IN_MS = 60000;
|
|
2435
1286
|
constructor(config) {
|
|
2436
1287
|
this.query = {};
|
|
2437
|
-
// rate limit vars
|
|
2438
|
-
this.requestCount = 0;
|
|
2439
|
-
this.lastRequestTime = 0;
|
|
2440
|
-
this.MAX_REQUESTS_PER_MINUTE = 30;
|
|
2441
|
-
this.MINUTE_IN_MS = 6e4;
|
|
2442
1288
|
this.config = config;
|
|
2443
1289
|
}
|
|
2444
|
-
|
|
2445
|
-
this.query.
|
|
2446
|
-
return this;
|
|
2447
|
-
}
|
|
2448
|
-
pinStart(date) {
|
|
2449
|
-
this.query.pinStart = date;
|
|
2450
|
-
return this;
|
|
2451
|
-
}
|
|
2452
|
-
pinEnd(date) {
|
|
2453
|
-
this.query.pinEnd = date;
|
|
2454
|
-
return this;
|
|
2455
|
-
}
|
|
2456
|
-
pinSizeMin(size) {
|
|
2457
|
-
this.query.pinSizeMin = size;
|
|
2458
|
-
return this;
|
|
2459
|
-
}
|
|
2460
|
-
pinSizeMax(size) {
|
|
2461
|
-
this.query.pinSizeMax = size;
|
|
2462
|
-
return this;
|
|
2463
|
-
}
|
|
2464
|
-
pageLimit(limit) {
|
|
2465
|
-
this.query.pageLimit = limit;
|
|
2466
|
-
return this;
|
|
2467
|
-
}
|
|
2468
|
-
pageOffset(offset) {
|
|
2469
|
-
this.query.pageOffset = offset;
|
|
2470
|
-
return this;
|
|
2471
|
-
}
|
|
2472
|
-
name(name) {
|
|
2473
|
-
this.query.name = name;
|
|
2474
|
-
return this;
|
|
2475
|
-
}
|
|
2476
|
-
group(groupId) {
|
|
2477
|
-
this.query.groupId = groupId;
|
|
1290
|
+
limit(limit) {
|
|
1291
|
+
this.query.limit = limit;
|
|
2478
1292
|
return this;
|
|
2479
1293
|
}
|
|
2480
|
-
|
|
2481
|
-
this.query.
|
|
2482
|
-
this.query.value = value;
|
|
2483
|
-
if (operator) {
|
|
2484
|
-
this.query.operator = operator;
|
|
2485
|
-
}
|
|
1294
|
+
cidPending(cidPending) {
|
|
1295
|
+
this.query.cidPending = cidPending;
|
|
2486
1296
|
return this;
|
|
2487
1297
|
}
|
|
2488
1298
|
then(onfulfilled) {
|
|
2489
|
-
return
|
|
2490
|
-
}
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
1299
|
+
return this.fetchPage().then(onfulfilled);
|
|
1300
|
+
}
|
|
1301
|
+
async fetchPage() {
|
|
1302
|
+
if (this.currentPageToken) {
|
|
1303
|
+
this.query.pageToken = this.currentPageToken;
|
|
1304
|
+
}
|
|
1305
|
+
const response = await listFiles(this.config, this.query);
|
|
1306
|
+
this.currentPageToken = response.next_page_token;
|
|
1307
|
+
return response.files;
|
|
1308
|
+
}
|
|
1309
|
+
// // rate limit, hopefully temporary?
|
|
1310
|
+
// private async rateLimit(): Promise<void> {
|
|
1311
|
+
// this.requestCount++;
|
|
1312
|
+
// const now = Date.now();
|
|
1313
|
+
// if (this.requestCount >= this.MAX_REQUESTS_PER_MINUTE) {
|
|
1314
|
+
// const timePassedSinceLastRequest = now - this.lastRequestTime;
|
|
1315
|
+
// if (timePassedSinceLastRequest < this.MINUTE_IN_MS) {
|
|
1316
|
+
// const delayTime = this.MINUTE_IN_MS - timePassedSinceLastRequest;
|
|
1317
|
+
// await new Promise((resolve) => setTimeout(resolve, delayTime));
|
|
1318
|
+
// }
|
|
1319
|
+
// this.requestCount = 0;
|
|
1320
|
+
// }
|
|
1321
|
+
// this.lastRequestTime = Date.now();
|
|
1322
|
+
// }
|
|
2505
1323
|
async *[Symbol.asyncIterator]() {
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
const limit = this.query.pageLimit || 10;
|
|
2509
|
-
while (hasMore) {
|
|
2510
|
-
await this.rateLimit();
|
|
2511
|
-
this.query.pageOffset = offset;
|
|
2512
|
-
this.query.pageLimit = limit;
|
|
2513
|
-
const items = await listFiles(this.config, this.query);
|
|
1324
|
+
while (true) {
|
|
1325
|
+
const items = await this.fetchPage();
|
|
2514
1326
|
for (const item of items) {
|
|
2515
1327
|
yield item;
|
|
2516
1328
|
}
|
|
2517
|
-
if (
|
|
2518
|
-
|
|
2519
|
-
} else {
|
|
2520
|
-
offset += items.length;
|
|
1329
|
+
if (!this.currentPageToken) {
|
|
1330
|
+
break;
|
|
2521
1331
|
}
|
|
2522
1332
|
}
|
|
2523
1333
|
}
|
|
@@ -2537,144 +1347,65 @@ var Gateways = class {
|
|
|
2537
1347
|
this.config = newConfig;
|
|
2538
1348
|
}
|
|
2539
1349
|
get(cid) {
|
|
2540
|
-
return
|
|
2541
|
-
}
|
|
2542
|
-
|
|
2543
|
-
return
|
|
2544
|
-
}
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
}
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
}
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
}
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
}
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
this.config = config;
|
|
2600
|
-
}
|
|
2601
|
-
cid(cid) {
|
|
2602
|
-
this.query.ipfs_pin_hash = cid;
|
|
2603
|
-
return this;
|
|
2604
|
-
}
|
|
2605
|
-
status(status) {
|
|
2606
|
-
this.query.status = status;
|
|
2607
|
-
return this;
|
|
2608
|
-
}
|
|
2609
|
-
pageLimit(limit) {
|
|
2610
|
-
this.query.limit = limit;
|
|
2611
|
-
return this;
|
|
2612
|
-
}
|
|
2613
|
-
pageOffset(offset) {
|
|
2614
|
-
this.query.offset = offset;
|
|
2615
|
-
return this;
|
|
2616
|
-
}
|
|
2617
|
-
sort(sort) {
|
|
2618
|
-
this.query.sort = sort;
|
|
2619
|
-
return this;
|
|
2620
|
-
}
|
|
2621
|
-
then(onfulfilled) {
|
|
2622
|
-
return pinJobs(this.config, this.query).then(onfulfilled);
|
|
2623
|
-
}
|
|
2624
|
-
// rate limit, hopefully temporary?
|
|
2625
|
-
async rateLimit() {
|
|
2626
|
-
this.requestCount++;
|
|
2627
|
-
const now = Date.now();
|
|
2628
|
-
if (this.requestCount >= this.MAX_REQUESTS_PER_MINUTE) {
|
|
2629
|
-
const timePassedSinceLastRequest = now - this.lastRequestTime;
|
|
2630
|
-
if (timePassedSinceLastRequest < this.MINUTE_IN_MS) {
|
|
2631
|
-
const delayTime = this.MINUTE_IN_MS - timePassedSinceLastRequest;
|
|
2632
|
-
await new Promise((resolve) => setTimeout(resolve, delayTime));
|
|
2633
|
-
}
|
|
2634
|
-
this.requestCount = 0;
|
|
2635
|
-
}
|
|
2636
|
-
this.lastRequestTime = Date.now();
|
|
2637
|
-
}
|
|
2638
|
-
async *[Symbol.asyncIterator]() {
|
|
2639
|
-
let hasMore = true;
|
|
2640
|
-
let offset = 0;
|
|
2641
|
-
const limit = this.query.limit || 10;
|
|
2642
|
-
while (hasMore) {
|
|
2643
|
-
await this.rateLimit();
|
|
2644
|
-
this.query.offset = offset;
|
|
2645
|
-
this.query.limit = limit;
|
|
2646
|
-
const items = await pinJobs(this.config, this.query);
|
|
2647
|
-
for (const item of items) {
|
|
2648
|
-
yield item;
|
|
2649
|
-
}
|
|
2650
|
-
if (items.length === 0) {
|
|
2651
|
-
hasMore = false;
|
|
2652
|
-
} else {
|
|
2653
|
-
offset += items.length;
|
|
2654
|
-
}
|
|
2655
|
-
}
|
|
2656
|
-
}
|
|
2657
|
-
async all() {
|
|
2658
|
-
const allItems = [];
|
|
2659
|
-
for await (const item of this) {
|
|
2660
|
-
allItems.push(item);
|
|
2661
|
-
}
|
|
2662
|
-
return allItems;
|
|
2663
|
-
}
|
|
2664
|
-
};
|
|
2665
|
-
var Usage = class {
|
|
2666
|
-
constructor(config) {
|
|
2667
|
-
this.config = formatConfig(config);
|
|
2668
|
-
}
|
|
2669
|
-
updateConfig(newConfig) {
|
|
2670
|
-
this.config = newConfig;
|
|
2671
|
-
}
|
|
2672
|
-
pinnedFileCount() {
|
|
2673
|
-
return pinnedFileCount(this.config);
|
|
2674
|
-
}
|
|
2675
|
-
totalStorageSize() {
|
|
2676
|
-
return totalStorageUsage(this.config);
|
|
2677
|
-
}
|
|
1350
|
+
return getCid(this.config, cid);
|
|
1351
|
+
}
|
|
1352
|
+
createSignedURL(options) {
|
|
1353
|
+
return createSignedURL(this.config, options);
|
|
1354
|
+
}
|
|
1355
|
+
// get(cid: string): OptimizeImage {
|
|
1356
|
+
// return new OptimizeImage(this.config, cid);
|
|
1357
|
+
// }
|
|
1358
|
+
// convert(url: string, gatewayPrefix?: string): Promise<string> {
|
|
1359
|
+
// return convertIPFSUrl(this.config, url, gatewayPrefix);
|
|
1360
|
+
// }
|
|
1361
|
+
// containsCID(cid: string): Promise<ContainsCIDResponse> {
|
|
1362
|
+
// return containsCID(cid);
|
|
1363
|
+
// }
|
|
1364
|
+
// topUsageAnalytics(options: {
|
|
1365
|
+
// domain: string;
|
|
1366
|
+
// start: string;
|
|
1367
|
+
// end: string;
|
|
1368
|
+
// sortBy: "requests" | "bandwidth";
|
|
1369
|
+
// attribute:
|
|
1370
|
+
// | "cid"
|
|
1371
|
+
// | "country"
|
|
1372
|
+
// | "region"
|
|
1373
|
+
// | "user_agent"
|
|
1374
|
+
// | "referer"
|
|
1375
|
+
// | "file_name";
|
|
1376
|
+
// }): TopGatewayAnalyticsBuilder {
|
|
1377
|
+
// return new TopGatewayAnalyticsBuilder(
|
|
1378
|
+
// this.config,
|
|
1379
|
+
// options.domain,
|
|
1380
|
+
// options.start,
|
|
1381
|
+
// options.end,
|
|
1382
|
+
// options.sortBy,
|
|
1383
|
+
// options.attribute,
|
|
1384
|
+
// );
|
|
1385
|
+
// }
|
|
1386
|
+
// dateIntervalAnalytics(options: {
|
|
1387
|
+
// domain: string;
|
|
1388
|
+
// start: string;
|
|
1389
|
+
// end: string;
|
|
1390
|
+
// interval: "day" | "week";
|
|
1391
|
+
// }): TimeIntervalGatewayAnalyticsBuilder {
|
|
1392
|
+
// return new TimeIntervalGatewayAnalyticsBuilder(
|
|
1393
|
+
// this.config,
|
|
1394
|
+
// options.domain,
|
|
1395
|
+
// options.start,
|
|
1396
|
+
// options.end,
|
|
1397
|
+
// options.interval,
|
|
1398
|
+
// );
|
|
1399
|
+
// }
|
|
1400
|
+
// swapCid(options: SwapCidOptions): Promise<SwapCidResponse> {
|
|
1401
|
+
// return swapCid(this.config, options);
|
|
1402
|
+
// }
|
|
1403
|
+
// swapHistory(options: SwapHistoryOptions): Promise<SwapCidResponse[]> {
|
|
1404
|
+
// return swapHistory(this.config, options);
|
|
1405
|
+
// }
|
|
1406
|
+
// deleteSwap(cid: string): Promise<string> {
|
|
1407
|
+
// return deleteSwap(this.config, cid);
|
|
1408
|
+
// }
|
|
2678
1409
|
};
|
|
2679
1410
|
var Keys = class {
|
|
2680
1411
|
constructor(config) {
|
|
@@ -2694,13 +1425,13 @@ var Keys = class {
|
|
|
2694
1425
|
}
|
|
2695
1426
|
};
|
|
2696
1427
|
var FilterKeys = class {
|
|
1428
|
+
// rate limit vars
|
|
1429
|
+
// private requestCount = 0;
|
|
1430
|
+
// private lastRequestTime = 0;
|
|
1431
|
+
// private readonly MAX_REQUESTS_PER_MINUTE = 30;
|
|
1432
|
+
// private readonly MINUTE_IN_MS = 60000;
|
|
2697
1433
|
constructor(config) {
|
|
2698
1434
|
this.query = {};
|
|
2699
|
-
// rate limit vars
|
|
2700
|
-
this.requestCount = 0;
|
|
2701
|
-
this.lastRequestTime = 0;
|
|
2702
|
-
this.MAX_REQUESTS_PER_MINUTE = 30;
|
|
2703
|
-
this.MINUTE_IN_MS = 6e4;
|
|
2704
1435
|
this.config = config;
|
|
2705
1436
|
}
|
|
2706
1437
|
offset(offset) {
|
|
@@ -2726,25 +1457,23 @@ var FilterKeys = class {
|
|
|
2726
1457
|
then(onfulfilled) {
|
|
2727
1458
|
return listKeys(this.config, this.query).then(onfulfilled);
|
|
2728
1459
|
}
|
|
2729
|
-
//
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
}
|
|
1460
|
+
// private async rateLimit(): Promise<void> {
|
|
1461
|
+
// this.requestCount++;
|
|
1462
|
+
// const now = Date.now();
|
|
1463
|
+
// if (this.requestCount >= this.MAX_REQUESTS_PER_MINUTE) {
|
|
1464
|
+
// const timePassedSinceLastRequest = now - this.lastRequestTime;
|
|
1465
|
+
// if (timePassedSinceLastRequest < this.MINUTE_IN_MS) {
|
|
1466
|
+
// const delayTime = this.MINUTE_IN_MS - timePassedSinceLastRequest;
|
|
1467
|
+
// await new Promise((resolve) => setTimeout(resolve, delayTime));
|
|
1468
|
+
// }
|
|
1469
|
+
// this.requestCount = 0;
|
|
1470
|
+
// }
|
|
1471
|
+
// this.lastRequestTime = Date.now();
|
|
1472
|
+
// }
|
|
2743
1473
|
async *[Symbol.asyncIterator]() {
|
|
2744
1474
|
let hasMore = true;
|
|
2745
1475
|
let offset = 0;
|
|
2746
1476
|
while (hasMore) {
|
|
2747
|
-
await this.rateLimit();
|
|
2748
1477
|
this.query.offset = offset;
|
|
2749
1478
|
const items = await listKeys(this.config, this.query);
|
|
2750
1479
|
for (const item of items) {
|
|
@@ -2781,12 +1510,12 @@ var Groups = class {
|
|
|
2781
1510
|
get(options) {
|
|
2782
1511
|
return getGroup(this.config, options);
|
|
2783
1512
|
}
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
}
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
}
|
|
1513
|
+
// addFiles(options: GroupCIDOptions): Promise<string> {
|
|
1514
|
+
// return addToGroup(this.config, options);
|
|
1515
|
+
// }
|
|
1516
|
+
// removeFiles(options: GroupCIDOptions): Promise<string> {
|
|
1517
|
+
// return removeFromGroup(this.config, options);
|
|
1518
|
+
// }
|
|
2790
1519
|
update(options) {
|
|
2791
1520
|
return updateGroup(this.config, options);
|
|
2792
1521
|
}
|
|
@@ -2797,57 +1526,56 @@ var Groups = class {
|
|
|
2797
1526
|
var FilterGroups = class {
|
|
2798
1527
|
constructor(config) {
|
|
2799
1528
|
this.query = {};
|
|
2800
|
-
// rate limit vars
|
|
2801
|
-
this.requestCount = 0;
|
|
2802
|
-
this.lastRequestTime = 0;
|
|
2803
|
-
this.MAX_REQUESTS_PER_MINUTE = 30;
|
|
2804
|
-
this.MINUTE_IN_MS = 6e4;
|
|
2805
1529
|
this.config = config;
|
|
2806
1530
|
}
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
}
|
|
2811
|
-
name(nameContains) {
|
|
2812
|
-
this.query.nameContains = nameContains;
|
|
2813
|
-
return this;
|
|
2814
|
-
}
|
|
1531
|
+
// name(nameContains: string): FilterGroups {
|
|
1532
|
+
// this.query.nameContains = nameContains;
|
|
1533
|
+
// return this;
|
|
1534
|
+
// }
|
|
2815
1535
|
limit(limit) {
|
|
2816
1536
|
this.query.limit = limit;
|
|
2817
1537
|
return this;
|
|
2818
1538
|
}
|
|
1539
|
+
isPublic(isPublic) {
|
|
1540
|
+
this.query.isPublic = isPublic;
|
|
1541
|
+
return this;
|
|
1542
|
+
}
|
|
2819
1543
|
then(onfulfilled) {
|
|
2820
|
-
return
|
|
1544
|
+
return this.fetchPage().then((response) => {
|
|
1545
|
+
this.nextPageToken = response.next_page_token;
|
|
1546
|
+
return response.groups;
|
|
1547
|
+
}).then(onfulfilled);
|
|
2821
1548
|
}
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
const now = Date.now();
|
|
2826
|
-
if (this.requestCount >= this.MAX_REQUESTS_PER_MINUTE) {
|
|
2827
|
-
const timePassedSinceLastRequest = now - this.lastRequestTime;
|
|
2828
|
-
if (timePassedSinceLastRequest < this.MINUTE_IN_MS) {
|
|
2829
|
-
const delayTime = this.MINUTE_IN_MS - timePassedSinceLastRequest;
|
|
2830
|
-
await new Promise((resolve) => setTimeout(resolve, delayTime));
|
|
2831
|
-
}
|
|
2832
|
-
this.requestCount = 0;
|
|
1549
|
+
async fetchPage() {
|
|
1550
|
+
if (this.nextPageToken) {
|
|
1551
|
+
this.query.pageToken = this.nextPageToken;
|
|
2833
1552
|
}
|
|
2834
|
-
this.
|
|
1553
|
+
return listGroups(this.config, this.query);
|
|
2835
1554
|
}
|
|
1555
|
+
// rate limit, hopefully temporary?
|
|
1556
|
+
// private async rateLimit(): Promise<void> {
|
|
1557
|
+
// this.requestCount++;
|
|
1558
|
+
// const now = Date.now();
|
|
1559
|
+
// if (this.requestCount >= this.MAX_REQUESTS_PER_MINUTE) {
|
|
1560
|
+
// const timePassedSinceLastRequest = now - this.lastRequestTime;
|
|
1561
|
+
// if (timePassedSinceLastRequest < this.MINUTE_IN_MS) {
|
|
1562
|
+
// const delayTime = this.MINUTE_IN_MS - timePassedSinceLastRequest;
|
|
1563
|
+
// await new Promise((resolve) => setTimeout(resolve, delayTime));
|
|
1564
|
+
// }
|
|
1565
|
+
// this.requestCount = 0;
|
|
1566
|
+
// }
|
|
1567
|
+
// this.lastRequestTime = Date.now();
|
|
1568
|
+
// }
|
|
2836
1569
|
async *[Symbol.asyncIterator]() {
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
await this.rateLimit();
|
|
2841
|
-
this.query.offset = offset;
|
|
2842
|
-
const items = await listGroups(this.config, this.query);
|
|
2843
|
-
for (const item of items) {
|
|
1570
|
+
while (true) {
|
|
1571
|
+
const response = await this.fetchPage();
|
|
1572
|
+
for (const item of response.groups) {
|
|
2844
1573
|
yield item;
|
|
2845
1574
|
}
|
|
2846
|
-
if (
|
|
2847
|
-
|
|
2848
|
-
} else {
|
|
2849
|
-
offset += items.length;
|
|
1575
|
+
if (!response.next_page_token) {
|
|
1576
|
+
break;
|
|
2850
1577
|
}
|
|
1578
|
+
this.nextPageToken = response.next_page_token;
|
|
2851
1579
|
}
|
|
2852
1580
|
}
|
|
2853
1581
|
async all() {
|
|
@@ -2858,122 +1586,6 @@ var FilterGroups = class {
|
|
|
2858
1586
|
return allItems;
|
|
2859
1587
|
}
|
|
2860
1588
|
};
|
|
2861
|
-
var Signatures = class {
|
|
2862
|
-
constructor(config) {
|
|
2863
|
-
this.config = formatConfig(config);
|
|
2864
|
-
}
|
|
2865
|
-
updateConfig(newConfig) {
|
|
2866
|
-
this.config = newConfig;
|
|
2867
|
-
}
|
|
2868
|
-
add(options) {
|
|
2869
|
-
return addSignature(this.config, options);
|
|
2870
|
-
}
|
|
2871
|
-
get(cid) {
|
|
2872
|
-
return getSignature(this.config, cid);
|
|
2873
|
-
}
|
|
2874
|
-
delete(cid) {
|
|
2875
|
-
return removeSignature(this.config, cid);
|
|
2876
|
-
}
|
|
2877
|
-
};
|
|
2878
|
-
var GatewayAnalyticsBuilder = class {
|
|
2879
|
-
constructor(config, query) {
|
|
2880
|
-
this.requestCount = 0;
|
|
2881
|
-
this.lastRequestTime = 0;
|
|
2882
|
-
this.MAX_REQUESTS_PER_MINUTE = 30;
|
|
2883
|
-
this.MINUTE_IN_MS = 6e4;
|
|
2884
|
-
this.config = config;
|
|
2885
|
-
this.query = query;
|
|
2886
|
-
}
|
|
2887
|
-
cid(cid) {
|
|
2888
|
-
this.query.cid = cid;
|
|
2889
|
-
return this;
|
|
2890
|
-
}
|
|
2891
|
-
fileName(fileName) {
|
|
2892
|
-
this.query.file_name = fileName;
|
|
2893
|
-
return this;
|
|
2894
|
-
}
|
|
2895
|
-
userAgent(userAgent) {
|
|
2896
|
-
this.query.user_agent = userAgent;
|
|
2897
|
-
return this;
|
|
2898
|
-
}
|
|
2899
|
-
country(country) {
|
|
2900
|
-
this.query.country = country;
|
|
2901
|
-
return this;
|
|
2902
|
-
}
|
|
2903
|
-
region(region) {
|
|
2904
|
-
this.query.region = region;
|
|
2905
|
-
return this;
|
|
2906
|
-
}
|
|
2907
|
-
referer(referer) {
|
|
2908
|
-
this.query.referer = referer;
|
|
2909
|
-
return this;
|
|
2910
|
-
}
|
|
2911
|
-
limit(limit) {
|
|
2912
|
-
this.query.limit = limit;
|
|
2913
|
-
return this;
|
|
2914
|
-
}
|
|
2915
|
-
sort(order) {
|
|
2916
|
-
this.query.sort_order = order;
|
|
2917
|
-
return this;
|
|
2918
|
-
}
|
|
2919
|
-
async rateLimit() {
|
|
2920
|
-
this.requestCount++;
|
|
2921
|
-
const now = Date.now();
|
|
2922
|
-
if (this.requestCount >= this.MAX_REQUESTS_PER_MINUTE) {
|
|
2923
|
-
const timePassedSinceLastRequest = now - this.lastRequestTime;
|
|
2924
|
-
if (timePassedSinceLastRequest < this.MINUTE_IN_MS) {
|
|
2925
|
-
const delayTime = this.MINUTE_IN_MS - timePassedSinceLastRequest;
|
|
2926
|
-
await new Promise((resolve) => setTimeout(resolve, delayTime));
|
|
2927
|
-
}
|
|
2928
|
-
this.requestCount = 0;
|
|
2929
|
-
}
|
|
2930
|
-
this.lastRequestTime = Date.now();
|
|
2931
|
-
}
|
|
2932
|
-
async getAnalytics() {
|
|
2933
|
-
await this.rateLimit();
|
|
2934
|
-
throw new Error("getAnalytics method must be implemented in derived class");
|
|
2935
|
-
}
|
|
2936
|
-
then(onfulfilled) {
|
|
2937
|
-
return this.getAnalytics().then(onfulfilled);
|
|
2938
|
-
}
|
|
2939
|
-
};
|
|
2940
|
-
var TopGatewayAnalyticsBuilder = class extends GatewayAnalyticsBuilder {
|
|
2941
|
-
constructor(config, domain, start, end, sortBy, attribute) {
|
|
2942
|
-
super(config, {
|
|
2943
|
-
gateway_domain: domain,
|
|
2944
|
-
start_date: start,
|
|
2945
|
-
end_date: end,
|
|
2946
|
-
sort_by: sortBy,
|
|
2947
|
-
attribute
|
|
2948
|
-
});
|
|
2949
|
-
}
|
|
2950
|
-
async getAnalytics() {
|
|
2951
|
-
return analyticsTopUsage(this.config, this.query);
|
|
2952
|
-
}
|
|
2953
|
-
async all() {
|
|
2954
|
-
return this.getAnalytics();
|
|
2955
|
-
}
|
|
2956
|
-
};
|
|
2957
|
-
var TimeIntervalGatewayAnalyticsBuilder = class extends GatewayAnalyticsBuilder {
|
|
2958
|
-
constructor(config, domain, start, end, dateInterval) {
|
|
2959
|
-
super(config, {
|
|
2960
|
-
gateway_domain: domain,
|
|
2961
|
-
start_date: start,
|
|
2962
|
-
end_date: end,
|
|
2963
|
-
date_interval: dateInterval
|
|
2964
|
-
});
|
|
2965
|
-
}
|
|
2966
|
-
sortBy(sortBy) {
|
|
2967
|
-
this.query.sort_by = sortBy;
|
|
2968
|
-
return this;
|
|
2969
|
-
}
|
|
2970
|
-
async getAnalytics() {
|
|
2971
|
-
return analyticsDateInterval(this.config, this.query);
|
|
2972
|
-
}
|
|
2973
|
-
async all() {
|
|
2974
|
-
return this.getAnalytics();
|
|
2975
|
-
}
|
|
2976
|
-
};
|
|
2977
1589
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2978
1590
|
0 && (module.exports = {
|
|
2979
1591
|
PinataSDK
|