pinata 0.3.4 → 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 +81 -191
- package/dist/index.d.ts +81 -191
- package/dist/index.js +396 -1737
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +396 -1727
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -3
package/dist/index.mjs
CHANGED
|
@@ -81,7 +81,7 @@ var testAuthentication = async (config) => {
|
|
|
81
81
|
}
|
|
82
82
|
};
|
|
83
83
|
|
|
84
|
-
// src/core/
|
|
84
|
+
// src/core/uploads/file.ts
|
|
85
85
|
var uploadFile = async (config, file, options) => {
|
|
86
86
|
if (!config) {
|
|
87
87
|
throw new ValidationError("Pinata configuration is missing");
|
|
@@ -89,20 +89,10 @@ var uploadFile = async (config, file, options) => {
|
|
|
89
89
|
const jwt = options?.keys || config.pinataJwt;
|
|
90
90
|
const data = new FormData();
|
|
91
91
|
data.append("file", file, file.name);
|
|
92
|
-
data.append(
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
groupId: options?.groupId
|
|
97
|
-
})
|
|
98
|
-
);
|
|
99
|
-
data.append(
|
|
100
|
-
"pinataMetadata",
|
|
101
|
-
JSON.stringify({
|
|
102
|
-
name: options?.metadata?.name || file.name || "File from SDK",
|
|
103
|
-
keyvalues: options?.metadata?.keyValues
|
|
104
|
-
})
|
|
105
|
-
);
|
|
92
|
+
data.append("name", options?.metadata?.name || file.name || "File from SDK");
|
|
93
|
+
if (options?.groupId) {
|
|
94
|
+
data.append("group_id", options.groupId);
|
|
95
|
+
}
|
|
106
96
|
let headers;
|
|
107
97
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
108
98
|
headers = { ...config.customHeaders };
|
|
@@ -112,12 +102,12 @@ var uploadFile = async (config, file, options) => {
|
|
|
112
102
|
Source: "sdk/file"
|
|
113
103
|
};
|
|
114
104
|
}
|
|
115
|
-
let endpoint = "https://
|
|
105
|
+
let endpoint = "https://uploads.pinata.cloud/v3";
|
|
116
106
|
if (config.endpointUrl) {
|
|
117
107
|
endpoint = config.endpointUrl;
|
|
118
108
|
}
|
|
119
109
|
try {
|
|
120
|
-
const request = await fetch(`${endpoint}/
|
|
110
|
+
const request = await fetch(`${endpoint}/files`, {
|
|
121
111
|
method: "POST",
|
|
122
112
|
headers,
|
|
123
113
|
body: data
|
|
@@ -150,81 +140,7 @@ var uploadFile = async (config, file, options) => {
|
|
|
150
140
|
}
|
|
151
141
|
};
|
|
152
142
|
|
|
153
|
-
// src/core/
|
|
154
|
-
var uploadFileArray = async (config, files, options) => {
|
|
155
|
-
if (!config) {
|
|
156
|
-
throw new ValidationError("Pinata configuration is missing");
|
|
157
|
-
}
|
|
158
|
-
const jwt = options?.keys || config?.pinataJwt;
|
|
159
|
-
const folder = options?.metadata?.name || "folder_from_sdk";
|
|
160
|
-
const data = new FormData();
|
|
161
|
-
for (const file of Array.from(files)) {
|
|
162
|
-
data.append("file", file, `${folder}/${file.name}`);
|
|
163
|
-
}
|
|
164
|
-
data.append(
|
|
165
|
-
"pinataMetadata",
|
|
166
|
-
JSON.stringify({
|
|
167
|
-
name: folder,
|
|
168
|
-
keyvalues: options?.metadata?.keyValues
|
|
169
|
-
})
|
|
170
|
-
);
|
|
171
|
-
data.append(
|
|
172
|
-
"pinataOptions",
|
|
173
|
-
JSON.stringify({
|
|
174
|
-
cidVersion: options?.cidVersion,
|
|
175
|
-
groupId: options?.groupId
|
|
176
|
-
})
|
|
177
|
-
);
|
|
178
|
-
let headers;
|
|
179
|
-
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
180
|
-
headers = { ...config.customHeaders };
|
|
181
|
-
} else {
|
|
182
|
-
headers = {
|
|
183
|
-
Authorization: `Bearer ${jwt}`,
|
|
184
|
-
Source: "sdk/fileArray"
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
let endpoint = "https://api.pinata.cloud";
|
|
188
|
-
if (config.endpointUrl) {
|
|
189
|
-
endpoint = config.endpointUrl;
|
|
190
|
-
}
|
|
191
|
-
try {
|
|
192
|
-
const request = await fetch(`${endpoint}/pinning/pinFileToIPFS`, {
|
|
193
|
-
method: "POST",
|
|
194
|
-
headers,
|
|
195
|
-
body: data
|
|
196
|
-
});
|
|
197
|
-
if (!request.ok) {
|
|
198
|
-
const errorData = await request.text();
|
|
199
|
-
if (request.status === 401 || request.status === 403) {
|
|
200
|
-
throw new AuthenticationError(
|
|
201
|
-
`Authentication failed: ${errorData}`,
|
|
202
|
-
request.status,
|
|
203
|
-
errorData
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
|
-
throw new NetworkError(
|
|
207
|
-
`HTTP error: ${errorData}`,
|
|
208
|
-
request.status,
|
|
209
|
-
errorData
|
|
210
|
-
);
|
|
211
|
-
}
|
|
212
|
-
const res = await request.json();
|
|
213
|
-
return res;
|
|
214
|
-
} catch (error) {
|
|
215
|
-
if (error instanceof PinataError) {
|
|
216
|
-
throw error;
|
|
217
|
-
}
|
|
218
|
-
if (error instanceof Error) {
|
|
219
|
-
throw new PinataError(`Error processing fileArray: ${error.message}`);
|
|
220
|
-
}
|
|
221
|
-
throw new PinataError(
|
|
222
|
-
"An unknown error occurred while uploading an array of files"
|
|
223
|
-
);
|
|
224
|
-
}
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
// src/core/pinning/base64.ts
|
|
143
|
+
// src/core/uploads/base64.ts
|
|
228
144
|
var uploadBase64 = async (config, base64String, options) => {
|
|
229
145
|
if (!config) {
|
|
230
146
|
throw new ValidationError("Pinata configuration is missing");
|
|
@@ -235,20 +151,10 @@ var uploadBase64 = async (config, base64String, options) => {
|
|
|
235
151
|
const blob = new Blob([buffer]);
|
|
236
152
|
const data = new FormData();
|
|
237
153
|
data.append("file", blob, name);
|
|
238
|
-
data.append(
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
groupId: options?.groupId
|
|
243
|
-
})
|
|
244
|
-
);
|
|
245
|
-
data.append(
|
|
246
|
-
"pinataMetadata",
|
|
247
|
-
JSON.stringify({
|
|
248
|
-
name,
|
|
249
|
-
keyvalues: options?.metadata?.keyValues
|
|
250
|
-
})
|
|
251
|
-
);
|
|
154
|
+
data.append("name", name);
|
|
155
|
+
if (options?.groupId) {
|
|
156
|
+
data.append("group_id", options.groupId);
|
|
157
|
+
}
|
|
252
158
|
let headers;
|
|
253
159
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
254
160
|
headers = { ...config.customHeaders };
|
|
@@ -258,12 +164,12 @@ var uploadBase64 = async (config, base64String, options) => {
|
|
|
258
164
|
Source: "sdk/base64"
|
|
259
165
|
};
|
|
260
166
|
}
|
|
261
|
-
let endpoint = "https://
|
|
167
|
+
let endpoint = "https://uploads.pinata.cloud/v3";
|
|
262
168
|
if (config.endpointUrl) {
|
|
263
169
|
endpoint = config.endpointUrl;
|
|
264
170
|
}
|
|
265
171
|
try {
|
|
266
|
-
const request = await fetch(`${endpoint}/
|
|
172
|
+
const request = await fetch(`${endpoint}/files`, {
|
|
267
173
|
method: "POST",
|
|
268
174
|
headers,
|
|
269
175
|
body: data
|
|
@@ -298,7 +204,7 @@ var uploadBase64 = async (config, base64String, options) => {
|
|
|
298
204
|
}
|
|
299
205
|
};
|
|
300
206
|
|
|
301
|
-
// src/core/
|
|
207
|
+
// src/core/uploads/url.ts
|
|
302
208
|
var uploadUrl = async (config, url, options) => {
|
|
303
209
|
if (!config) {
|
|
304
210
|
throw new ValidationError("Pinata configuration is missing");
|
|
@@ -319,20 +225,10 @@ var uploadUrl = async (config, url, options) => {
|
|
|
319
225
|
const name = options?.metadata?.name ?? "url_upload";
|
|
320
226
|
const file = new File([blob], name);
|
|
321
227
|
data.append("file", file, name);
|
|
322
|
-
data.append(
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
groupId: options?.groupId
|
|
327
|
-
})
|
|
328
|
-
);
|
|
329
|
-
data.append(
|
|
330
|
-
"pinataMetadata",
|
|
331
|
-
JSON.stringify({
|
|
332
|
-
name,
|
|
333
|
-
keyvalues: options?.metadata?.keyValues
|
|
334
|
-
})
|
|
335
|
-
);
|
|
228
|
+
data.append("name", name);
|
|
229
|
+
if (options?.groupId) {
|
|
230
|
+
data.append("group_id", options.groupId);
|
|
231
|
+
}
|
|
336
232
|
let headers;
|
|
337
233
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
338
234
|
headers = { ...config.customHeaders };
|
|
@@ -342,12 +238,12 @@ var uploadUrl = async (config, url, options) => {
|
|
|
342
238
|
Source: "sdk/url"
|
|
343
239
|
};
|
|
344
240
|
}
|
|
345
|
-
let endpoint = "https://
|
|
241
|
+
let endpoint = "https://uploads.pinata.cloud/v3";
|
|
346
242
|
if (config.endpointUrl) {
|
|
347
243
|
endpoint = config.endpointUrl;
|
|
348
244
|
}
|
|
349
245
|
try {
|
|
350
|
-
const request = await fetch(`${endpoint}/
|
|
246
|
+
const request = await fetch(`${endpoint}/files`, {
|
|
351
247
|
method: "POST",
|
|
352
248
|
headers,
|
|
353
249
|
body: data
|
|
@@ -380,39 +276,36 @@ var uploadUrl = async (config, url, options) => {
|
|
|
380
276
|
}
|
|
381
277
|
};
|
|
382
278
|
|
|
383
|
-
// src/core/
|
|
279
|
+
// src/core/uploads/json.ts
|
|
384
280
|
var uploadJson = async (config, jsonData, options) => {
|
|
385
281
|
if (!config) {
|
|
386
282
|
throw new ValidationError("Pinata configuration is missing");
|
|
387
283
|
}
|
|
388
284
|
const jwt = options?.keys || config?.pinataJwt;
|
|
389
|
-
const
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
}
|
|
399
|
-
});
|
|
285
|
+
const json = JSON.stringify(jsonData);
|
|
286
|
+
const blob = new Blob([json]);
|
|
287
|
+
const file = new File([blob], "data.json", { type: "application/json" });
|
|
288
|
+
const data = new FormData();
|
|
289
|
+
data.append("file", file, file.name);
|
|
290
|
+
data.append("name", options?.metadata?.name || file.name || "File from SDK");
|
|
291
|
+
if (options?.groupId) {
|
|
292
|
+
data.append("group_id", options.groupId);
|
|
293
|
+
}
|
|
400
294
|
let headers;
|
|
401
295
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
402
296
|
headers = { ...config.customHeaders };
|
|
403
297
|
} else {
|
|
404
298
|
headers = {
|
|
405
299
|
Authorization: `Bearer ${jwt}`,
|
|
406
|
-
"Content-Type": "application/json",
|
|
407
300
|
Source: "sdk/json"
|
|
408
301
|
};
|
|
409
302
|
}
|
|
410
|
-
let endpoint = "https://
|
|
303
|
+
let endpoint = "https://uploads.pinata.cloud/v3";
|
|
411
304
|
if (config.endpointUrl) {
|
|
412
305
|
endpoint = config.endpointUrl;
|
|
413
306
|
}
|
|
414
307
|
try {
|
|
415
|
-
const request = await fetch(`${endpoint}/
|
|
308
|
+
const request = await fetch(`${endpoint}/files`, {
|
|
416
309
|
method: "POST",
|
|
417
310
|
headers,
|
|
418
311
|
body: data
|
|
@@ -445,78 +338,13 @@ var uploadJson = async (config, jsonData, options) => {
|
|
|
445
338
|
}
|
|
446
339
|
};
|
|
447
340
|
|
|
448
|
-
// src/core/
|
|
449
|
-
var uploadCid = async (config, cid, options) => {
|
|
450
|
-
if (!config) {
|
|
451
|
-
throw new ValidationError("Pinata configuration is missing");
|
|
452
|
-
}
|
|
453
|
-
const jwt = options?.keys || config?.pinataJwt;
|
|
454
|
-
let headers;
|
|
455
|
-
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
456
|
-
headers = { ...config.customHeaders };
|
|
457
|
-
} else {
|
|
458
|
-
headers = {
|
|
459
|
-
Authorization: `Bearer ${jwt}`,
|
|
460
|
-
"Content-Type": "application/json",
|
|
461
|
-
Source: "sdk/cid"
|
|
462
|
-
};
|
|
463
|
-
}
|
|
464
|
-
const data = JSON.stringify({
|
|
465
|
-
hashToPin: cid,
|
|
466
|
-
pinataMetadata: {
|
|
467
|
-
name: options?.metadata ? options?.metadata?.name : cid,
|
|
468
|
-
keyvalues: options?.metadata?.keyValues
|
|
469
|
-
},
|
|
470
|
-
pinataOptions: {
|
|
471
|
-
hostNodes: options?.peerAddresses ? options.peerAddresses : "",
|
|
472
|
-
groupId: options?.groupId
|
|
473
|
-
}
|
|
474
|
-
});
|
|
475
|
-
let endpoint = "https://api.pinata.cloud";
|
|
476
|
-
if (config.endpointUrl) {
|
|
477
|
-
endpoint = config.endpointUrl;
|
|
478
|
-
}
|
|
479
|
-
try {
|
|
480
|
-
const request = await fetch(`${endpoint}/pinning/pinByHash`, {
|
|
481
|
-
method: "POST",
|
|
482
|
-
headers,
|
|
483
|
-
body: data
|
|
484
|
-
});
|
|
485
|
-
if (!request.ok) {
|
|
486
|
-
const errorData = await request.text();
|
|
487
|
-
if (request.status === 401 || request.status === 403) {
|
|
488
|
-
throw new AuthenticationError(
|
|
489
|
-
`Authentication failed: ${errorData}`,
|
|
490
|
-
request.status,
|
|
491
|
-
errorData
|
|
492
|
-
);
|
|
493
|
-
}
|
|
494
|
-
throw new NetworkError(
|
|
495
|
-
`HTTP error: ${errorData}`,
|
|
496
|
-
request.status,
|
|
497
|
-
errorData
|
|
498
|
-
);
|
|
499
|
-
}
|
|
500
|
-
const res = await request.json();
|
|
501
|
-
return res;
|
|
502
|
-
} catch (error) {
|
|
503
|
-
if (error instanceof PinataError) {
|
|
504
|
-
throw error;
|
|
505
|
-
}
|
|
506
|
-
if (error instanceof Error) {
|
|
507
|
-
throw new PinataError(`Error processing cid: ${error.message}`);
|
|
508
|
-
}
|
|
509
|
-
throw new PinataError("An unknown error occurred while pinning by CID");
|
|
510
|
-
}
|
|
511
|
-
};
|
|
512
|
-
|
|
513
|
-
// src/core/pinning/unpin.ts
|
|
341
|
+
// src/core/files/delete.ts
|
|
514
342
|
var wait = (milliseconds) => {
|
|
515
343
|
return new Promise((resolve) => {
|
|
516
344
|
setTimeout(resolve, milliseconds);
|
|
517
345
|
});
|
|
518
346
|
};
|
|
519
|
-
var
|
|
347
|
+
var deleteFile = async (config, files) => {
|
|
520
348
|
if (!config) {
|
|
521
349
|
throw new ValidationError("Pinata configuration is missing");
|
|
522
350
|
}
|
|
@@ -530,13 +358,13 @@ var unpinFile = async (config, files) => {
|
|
|
530
358
|
Source: "sdk/unpin"
|
|
531
359
|
};
|
|
532
360
|
}
|
|
533
|
-
let endpoint = "https://api.pinata.cloud";
|
|
361
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
534
362
|
if (config.endpointUrl) {
|
|
535
363
|
endpoint = config.endpointUrl;
|
|
536
364
|
}
|
|
537
|
-
for (const
|
|
365
|
+
for (const id of files) {
|
|
538
366
|
try {
|
|
539
|
-
const response = await fetch(`${endpoint}/
|
|
367
|
+
const response = await fetch(`${endpoint}/files/${id}`, {
|
|
540
368
|
method: "DELETE",
|
|
541
369
|
headers
|
|
542
370
|
});
|
|
@@ -556,22 +384,21 @@ var unpinFile = async (config, files) => {
|
|
|
556
384
|
errorData
|
|
557
385
|
);
|
|
558
386
|
}
|
|
559
|
-
const result = await response.text();
|
|
560
387
|
responses.push({
|
|
561
|
-
|
|
562
|
-
status:
|
|
388
|
+
id,
|
|
389
|
+
status: response.statusText
|
|
563
390
|
});
|
|
564
391
|
} catch (error) {
|
|
565
392
|
let errorMessage;
|
|
566
393
|
if (error instanceof PinataError) {
|
|
567
394
|
errorMessage = error.message;
|
|
568
395
|
} else if (error instanceof Error) {
|
|
569
|
-
errorMessage = `Error
|
|
396
|
+
errorMessage = `Error deleting file ${id}: ${error.message}`;
|
|
570
397
|
} else {
|
|
571
|
-
errorMessage = `An unknown error occurred while
|
|
398
|
+
errorMessage = `An unknown error occurred while deleting file ${id}`;
|
|
572
399
|
}
|
|
573
400
|
responses.push({
|
|
574
|
-
|
|
401
|
+
id,
|
|
575
402
|
status: errorMessage
|
|
576
403
|
});
|
|
577
404
|
}
|
|
@@ -579,59 +406,26 @@ var unpinFile = async (config, files) => {
|
|
|
579
406
|
return responses;
|
|
580
407
|
};
|
|
581
408
|
|
|
582
|
-
// src/core/
|
|
409
|
+
// src/core/files/list.ts
|
|
583
410
|
var listFiles = async (config, options) => {
|
|
584
411
|
if (!config) {
|
|
585
412
|
throw new ValidationError("Pinata configuration is missing");
|
|
586
413
|
}
|
|
587
|
-
const params = new URLSearchParams(
|
|
588
|
-
includesCount: "false"
|
|
589
|
-
});
|
|
414
|
+
const params = new URLSearchParams();
|
|
590
415
|
if (options) {
|
|
591
|
-
const {
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
pageOffset,
|
|
599
|
-
name,
|
|
600
|
-
key,
|
|
601
|
-
value,
|
|
602
|
-
operator,
|
|
603
|
-
groupId
|
|
604
|
-
} = options;
|
|
605
|
-
if (cid)
|
|
606
|
-
params.append("cid", cid);
|
|
607
|
-
if (pinStart)
|
|
608
|
-
params.append("pinStart", pinStart);
|
|
609
|
-
if (pinEnd)
|
|
610
|
-
params.append("pinEnd", pinEnd);
|
|
611
|
-
if (pinSizeMin)
|
|
612
|
-
params.append("pinSizeMin", pinSizeMin.toString());
|
|
613
|
-
if (pinSizeMax)
|
|
614
|
-
params.append("pinSizeMax", pinSizeMax.toString());
|
|
615
|
-
if (pageLimit)
|
|
616
|
-
params.append("pageLimit", pageLimit.toString());
|
|
617
|
-
if (pageOffset)
|
|
618
|
-
params.append("pageOffset", pageOffset.toString());
|
|
619
|
-
if (groupId)
|
|
620
|
-
params.append("groupId", groupId);
|
|
621
|
-
if (name)
|
|
622
|
-
params.append("metadata[name]", name);
|
|
623
|
-
if (key && value) {
|
|
624
|
-
const keyValueParam = JSON.stringify({
|
|
625
|
-
[key]: { value, op: operator || "eq" }
|
|
626
|
-
});
|
|
627
|
-
params.append("metadata[keyvalues]", keyValueParam);
|
|
628
|
-
}
|
|
416
|
+
const { limit, pageToken, cidPending } = options;
|
|
417
|
+
if (limit)
|
|
418
|
+
params.append("limit", limit.toString());
|
|
419
|
+
if (pageToken)
|
|
420
|
+
params.append("pageToken", pageToken);
|
|
421
|
+
if (cidPending)
|
|
422
|
+
params.append("cidPending", "true");
|
|
629
423
|
}
|
|
630
|
-
let endpoint = "https://api.pinata.cloud";
|
|
424
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
631
425
|
if (config.endpointUrl) {
|
|
632
426
|
endpoint = config.endpointUrl;
|
|
633
427
|
}
|
|
634
|
-
const url = `${endpoint}/
|
|
428
|
+
const url = `${endpoint}/files?${params.toString()}`;
|
|
635
429
|
try {
|
|
636
430
|
let headers;
|
|
637
431
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
@@ -662,7 +456,8 @@ var listFiles = async (config, options) => {
|
|
|
662
456
|
);
|
|
663
457
|
}
|
|
664
458
|
const res = await request.json();
|
|
665
|
-
|
|
459
|
+
const resData = res.data;
|
|
460
|
+
return resData;
|
|
666
461
|
} catch (error) {
|
|
667
462
|
if (error instanceof PinataError) {
|
|
668
463
|
throw error;
|
|
@@ -674,16 +469,14 @@ var listFiles = async (config, options) => {
|
|
|
674
469
|
}
|
|
675
470
|
};
|
|
676
471
|
|
|
677
|
-
// src/core/
|
|
678
|
-
var
|
|
472
|
+
// src/core/files/updateFile.ts
|
|
473
|
+
var updateFile = async (config, options) => {
|
|
679
474
|
if (!config) {
|
|
680
475
|
throw new ValidationError("Pinata configuration is missing");
|
|
681
476
|
}
|
|
682
|
-
const data = {
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
keyvalues: options.keyValues
|
|
686
|
-
};
|
|
477
|
+
const data = JSON.stringify({
|
|
478
|
+
name: options.name
|
|
479
|
+
});
|
|
687
480
|
let headers;
|
|
688
481
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
689
482
|
headers = { ...config.customHeaders };
|
|
@@ -694,15 +487,15 @@ var updateMetadata = async (config, options) => {
|
|
|
694
487
|
Source: "sdk/updateMetadata"
|
|
695
488
|
};
|
|
696
489
|
}
|
|
697
|
-
let endpoint = "https://api.pinata.cloud";
|
|
490
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
698
491
|
if (config.endpointUrl) {
|
|
699
492
|
endpoint = config.endpointUrl;
|
|
700
493
|
}
|
|
701
494
|
try {
|
|
702
|
-
const request = await fetch(`${endpoint}/
|
|
495
|
+
const request = await fetch(`${endpoint}/files/${options.id}`, {
|
|
703
496
|
method: "PUT",
|
|
704
497
|
headers,
|
|
705
|
-
body:
|
|
498
|
+
body: data
|
|
706
499
|
});
|
|
707
500
|
if (!request.ok) {
|
|
708
501
|
const errorData = await request.text();
|
|
@@ -719,128 +512,49 @@ var updateMetadata = async (config, options) => {
|
|
|
719
512
|
errorData
|
|
720
513
|
);
|
|
721
514
|
}
|
|
722
|
-
const res = await request.
|
|
723
|
-
|
|
515
|
+
const res = await request.json();
|
|
516
|
+
const resData = res.data;
|
|
517
|
+
return resData;
|
|
724
518
|
} catch (error) {
|
|
725
519
|
if (error instanceof PinataError) {
|
|
726
520
|
throw error;
|
|
727
521
|
}
|
|
728
522
|
if (error instanceof Error) {
|
|
729
|
-
throw new PinataError(
|
|
730
|
-
`Error processing updateMetadata: ${error.message}`
|
|
731
|
-
);
|
|
523
|
+
throw new PinataError(`Error processing updateFile: ${error.message}`);
|
|
732
524
|
}
|
|
733
|
-
throw new PinataError("An unknown error occurred while updating
|
|
525
|
+
throw new PinataError("An unknown error occurred while updating file");
|
|
734
526
|
}
|
|
735
527
|
};
|
|
736
528
|
|
|
737
|
-
// src/utils/gateway-tools.ts
|
|
738
|
-
var isIPFSModule;
|
|
739
|
-
async function getIsIPFS() {
|
|
740
|
-
if (!isIPFSModule) {
|
|
741
|
-
isIPFSModule = await import("is-ipfs");
|
|
742
|
-
}
|
|
743
|
-
return isIPFSModule;
|
|
744
|
-
}
|
|
745
|
-
async function containsCID(input) {
|
|
746
|
-
if (typeof input !== "string") {
|
|
747
|
-
throw new Error("Input is not a string");
|
|
748
|
-
}
|
|
749
|
-
const isIPFS = await getIsIPFS();
|
|
750
|
-
const startsWithCID = (str) => {
|
|
751
|
-
const parts = str.split("/");
|
|
752
|
-
return isIPFS.cid(parts[0]) ? parts[0] : null;
|
|
753
|
-
};
|
|
754
|
-
const directCID = startsWithCID(input);
|
|
755
|
-
if (directCID) {
|
|
756
|
-
return {
|
|
757
|
-
containsCid: true,
|
|
758
|
-
cid: directCID
|
|
759
|
-
};
|
|
760
|
-
}
|
|
761
|
-
let url;
|
|
762
|
-
try {
|
|
763
|
-
url = new URL(input);
|
|
764
|
-
} catch (error) {
|
|
765
|
-
const parts = input.split(/\/|\?/);
|
|
766
|
-
for (const part of parts) {
|
|
767
|
-
const cid = startsWithCID(part);
|
|
768
|
-
if (cid) {
|
|
769
|
-
return {
|
|
770
|
-
containsCid: true,
|
|
771
|
-
cid
|
|
772
|
-
};
|
|
773
|
-
}
|
|
774
|
-
}
|
|
775
|
-
return {
|
|
776
|
-
containsCid: false,
|
|
777
|
-
cid: null
|
|
778
|
-
};
|
|
779
|
-
}
|
|
780
|
-
const subdomains = url.hostname.split(".");
|
|
781
|
-
for (const subdomain of subdomains) {
|
|
782
|
-
if (isIPFS.cid(subdomain)) {
|
|
783
|
-
return {
|
|
784
|
-
containsCid: true,
|
|
785
|
-
cid: subdomain
|
|
786
|
-
};
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
const pathParts = url.pathname.split("/");
|
|
790
|
-
for (const part of pathParts) {
|
|
791
|
-
const cid = startsWithCID(part);
|
|
792
|
-
if (cid) {
|
|
793
|
-
return {
|
|
794
|
-
containsCid: true,
|
|
795
|
-
cid
|
|
796
|
-
};
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
return {
|
|
800
|
-
containsCid: false,
|
|
801
|
-
cid: null
|
|
802
|
-
};
|
|
803
|
-
}
|
|
804
|
-
async function convertToDesiredGateway(sourceUrl, desiredGatewayPrefix) {
|
|
805
|
-
const results = await containsCID(sourceUrl);
|
|
806
|
-
if (results.containsCid !== true) {
|
|
807
|
-
throw new Error("url does not contain CID");
|
|
808
|
-
}
|
|
809
|
-
if (!sourceUrl.startsWith("https") && !sourceUrl.startsWith("ipfs://")) {
|
|
810
|
-
return `${desiredGatewayPrefix}/ipfs/${sourceUrl}`;
|
|
811
|
-
}
|
|
812
|
-
const urlObj = new URL(sourceUrl);
|
|
813
|
-
const path = urlObj.pathname + urlObj.search + urlObj.hash;
|
|
814
|
-
if (sourceUrl.startsWith(`ipfs://${results.cid}`)) {
|
|
815
|
-
return `${desiredGatewayPrefix}/ipfs/${results.cid}${path}`;
|
|
816
|
-
}
|
|
817
|
-
if (sourceUrl.includes(`/ipfs/${results.cid}`)) {
|
|
818
|
-
return `${desiredGatewayPrefix}${path}`;
|
|
819
|
-
}
|
|
820
|
-
if (sourceUrl.includes(`/ipns/${results.cid}`)) {
|
|
821
|
-
return `${desiredGatewayPrefix}${path}`;
|
|
822
|
-
}
|
|
823
|
-
if (urlObj.hostname.includes(results.cid)) {
|
|
824
|
-
return `${desiredGatewayPrefix}/ipfs/${results.cid}${path}`;
|
|
825
|
-
}
|
|
826
|
-
throw new Error(
|
|
827
|
-
"unsupported URL pattern, please submit a github issue with the URL utilized"
|
|
828
|
-
);
|
|
829
|
-
}
|
|
830
|
-
|
|
831
529
|
// src/core/gateway/getCid.ts
|
|
832
530
|
var getCid = async (config, cid) => {
|
|
833
531
|
if (!config) {
|
|
834
532
|
throw new ValidationError("Pinata configuration is missing");
|
|
835
533
|
}
|
|
836
534
|
let data;
|
|
837
|
-
let newUrl
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
535
|
+
let newUrl = `${config?.pinataGateway}/files/${cid}`;
|
|
536
|
+
const params = new URLSearchParams();
|
|
537
|
+
const date = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3);
|
|
538
|
+
const payload = JSON.stringify({
|
|
539
|
+
url: newUrl,
|
|
540
|
+
date,
|
|
541
|
+
expires: 30,
|
|
542
|
+
method: "GET"
|
|
543
|
+
});
|
|
544
|
+
const signedUrlRequest = await fetch(
|
|
545
|
+
"https://api.pinata.cloud/v3/files/sign",
|
|
546
|
+
{
|
|
547
|
+
method: "POST",
|
|
548
|
+
headers: {
|
|
549
|
+
"Content-Type": "application/json",
|
|
550
|
+
Authorization: `Bearer ${config?.pinataJwt}`
|
|
551
|
+
},
|
|
552
|
+
body: payload
|
|
553
|
+
}
|
|
554
|
+
);
|
|
555
|
+
const signedUrl = await signedUrlRequest.json();
|
|
842
556
|
try {
|
|
843
|
-
const request = await fetch(
|
|
557
|
+
const request = await fetch(signedUrl.data);
|
|
844
558
|
if (!request.ok) {
|
|
845
559
|
const errorData = await request.text();
|
|
846
560
|
if (request.status === 401 || request.status === 403) {
|
|
@@ -882,55 +596,31 @@ var getCid = async (config, cid) => {
|
|
|
882
596
|
}
|
|
883
597
|
};
|
|
884
598
|
|
|
885
|
-
// src/core/
|
|
886
|
-
var
|
|
887
|
-
let newUrl;
|
|
888
|
-
newUrl = await convertToDesiredGateway(url, config?.pinataGateway);
|
|
889
|
-
if (config?.pinataGatewayKey) {
|
|
890
|
-
`${newUrl}?pinataGatewayToken=${config?.pinataGatewayKey}`;
|
|
891
|
-
}
|
|
892
|
-
return newUrl;
|
|
893
|
-
};
|
|
894
|
-
|
|
895
|
-
// src/core/data/pinJobs.ts
|
|
896
|
-
var pinJobs = async (config, options) => {
|
|
599
|
+
// src/core/keys/createKey.ts
|
|
600
|
+
var createKey = async (config, options) => {
|
|
897
601
|
if (!config) {
|
|
898
602
|
throw new ValidationError("Pinata configuration is missing");
|
|
899
603
|
}
|
|
900
|
-
const params = new URLSearchParams({
|
|
901
|
-
includesCount: "false"
|
|
902
|
-
});
|
|
903
|
-
if (options) {
|
|
904
|
-
const { ipfs_pin_hash: cid, status, sort, limit, offset } = options;
|
|
905
|
-
if (cid)
|
|
906
|
-
params.append("ipfs_pin_hash", cid.toString());
|
|
907
|
-
if (status)
|
|
908
|
-
params.append("status", status.toString());
|
|
909
|
-
if (sort)
|
|
910
|
-
params.append("sort", sort.toString());
|
|
911
|
-
if (limit)
|
|
912
|
-
params.append("limit", limit.toString());
|
|
913
|
-
if (offset)
|
|
914
|
-
params.append("offset", offset.toString());
|
|
915
|
-
}
|
|
916
|
-
let endpoint = "https://api.pinata.cloud";
|
|
917
|
-
if (config.endpointUrl) {
|
|
918
|
-
endpoint = config.endpointUrl;
|
|
919
|
-
}
|
|
920
|
-
const url = `${endpoint}/pinning/pinJobs?${params.toString()}`;
|
|
921
604
|
let headers;
|
|
922
605
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
923
606
|
headers = { ...config.customHeaders };
|
|
924
607
|
} else {
|
|
925
608
|
headers = {
|
|
926
609
|
Authorization: `Bearer ${config.pinataJwt}`,
|
|
927
|
-
|
|
610
|
+
"Content-Type": "application/json",
|
|
611
|
+
Source: "sdk/createKey"
|
|
928
612
|
};
|
|
929
613
|
}
|
|
614
|
+
const data = JSON.stringify(options);
|
|
615
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
616
|
+
if (config.endpointUrl) {
|
|
617
|
+
endpoint = config.endpointUrl;
|
|
618
|
+
}
|
|
930
619
|
try {
|
|
931
|
-
const request = await fetch(
|
|
932
|
-
method: "
|
|
933
|
-
headers
|
|
620
|
+
const request = await fetch(`${endpoint}/pinata/keys`, {
|
|
621
|
+
method: "POST",
|
|
622
|
+
headers,
|
|
623
|
+
body: data
|
|
934
624
|
});
|
|
935
625
|
if (!request.ok) {
|
|
936
626
|
const errorData = await request.text();
|
|
@@ -948,41 +638,59 @@ var pinJobs = async (config, options) => {
|
|
|
948
638
|
);
|
|
949
639
|
}
|
|
950
640
|
const res = await request.json();
|
|
951
|
-
return res
|
|
641
|
+
return res;
|
|
952
642
|
} catch (error) {
|
|
953
643
|
if (error instanceof PinataError) {
|
|
954
644
|
throw error;
|
|
955
645
|
}
|
|
956
646
|
if (error instanceof Error) {
|
|
957
|
-
throw new PinataError(`Error processing
|
|
647
|
+
throw new PinataError(`Error processing createKey: ${error.message}`);
|
|
958
648
|
}
|
|
959
|
-
throw new PinataError("An unknown error occurred while
|
|
649
|
+
throw new PinataError("An unknown error occurred while creating API key");
|
|
960
650
|
}
|
|
961
651
|
};
|
|
962
652
|
|
|
963
|
-
// src/core/
|
|
964
|
-
var
|
|
653
|
+
// src/core/keys/listKeys.ts
|
|
654
|
+
var listKeys = async (config, options) => {
|
|
965
655
|
if (!config) {
|
|
966
656
|
throw new ValidationError("Pinata configuration is missing");
|
|
967
657
|
}
|
|
968
|
-
let endpoint = "https://api.pinata.cloud";
|
|
969
|
-
if (config.endpointUrl) {
|
|
970
|
-
endpoint = config.endpointUrl;
|
|
971
|
-
}
|
|
972
658
|
let headers;
|
|
973
659
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
974
660
|
headers = { ...config.customHeaders };
|
|
975
661
|
} else {
|
|
976
662
|
headers = {
|
|
977
663
|
Authorization: `Bearer ${config.pinataJwt}`,
|
|
978
|
-
|
|
664
|
+
"Content-Type": "application/json",
|
|
665
|
+
Source: "sdk/listKeys"
|
|
979
666
|
};
|
|
980
667
|
}
|
|
668
|
+
const params = new URLSearchParams();
|
|
669
|
+
if (options) {
|
|
670
|
+
const { offset, name, revoked, limitedUse, exhausted } = options;
|
|
671
|
+
if (offset)
|
|
672
|
+
params.append("offset", offset.toString());
|
|
673
|
+
if (revoked !== void 0)
|
|
674
|
+
params.append("revoked", revoked.toString());
|
|
675
|
+
if (limitedUse !== void 0)
|
|
676
|
+
params.append("limitedUse", limitedUse.toString());
|
|
677
|
+
if (exhausted !== void 0)
|
|
678
|
+
params.append("exhausted", exhausted.toString());
|
|
679
|
+
if (name)
|
|
680
|
+
params.append("name", name);
|
|
681
|
+
}
|
|
682
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
683
|
+
if (config.endpointUrl) {
|
|
684
|
+
endpoint = config.endpointUrl;
|
|
685
|
+
}
|
|
981
686
|
try {
|
|
982
|
-
const request = await fetch(
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
687
|
+
const request = await fetch(
|
|
688
|
+
`${endpoint}/pinata/keys?${params.toString()}`,
|
|
689
|
+
{
|
|
690
|
+
method: "GET",
|
|
691
|
+
headers
|
|
692
|
+
}
|
|
693
|
+
);
|
|
986
694
|
if (!request.ok) {
|
|
987
695
|
const errorData = await request.text();
|
|
988
696
|
if (request.status === 401 || request.status === 403) {
|
|
@@ -999,207 +707,25 @@ var pinnedFileCount = async (config) => {
|
|
|
999
707
|
);
|
|
1000
708
|
}
|
|
1001
709
|
const res = await request.json();
|
|
1002
|
-
return res.
|
|
710
|
+
return res.keys;
|
|
1003
711
|
} catch (error) {
|
|
1004
712
|
if (error instanceof PinataError) {
|
|
1005
713
|
throw error;
|
|
1006
714
|
}
|
|
1007
715
|
if (error instanceof Error) {
|
|
1008
|
-
throw new PinataError(
|
|
1009
|
-
`Error processing pinnedFileUsage: ${error.message}`
|
|
1010
|
-
);
|
|
716
|
+
throw new PinataError(`Error processing listKeys: ${error.message}`);
|
|
1011
717
|
}
|
|
1012
|
-
throw new PinataError(
|
|
1013
|
-
"An unknown error occurred while getting pinned file usage"
|
|
1014
|
-
);
|
|
718
|
+
throw new PinataError("An unknown error occurred while listing API keys");
|
|
1015
719
|
}
|
|
1016
720
|
};
|
|
1017
721
|
|
|
1018
|
-
// src/core/
|
|
1019
|
-
var
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
}
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
endpoint = config.endpointUrl;
|
|
1026
|
-
}
|
|
1027
|
-
let headers;
|
|
1028
|
-
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1029
|
-
headers = { ...config.customHeaders };
|
|
1030
|
-
} else {
|
|
1031
|
-
headers = {
|
|
1032
|
-
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1033
|
-
Source: "sdk/totalStorageUsage"
|
|
1034
|
-
};
|
|
1035
|
-
}
|
|
1036
|
-
try {
|
|
1037
|
-
const request = await fetch(`${endpoint}/data/userPinnedDataTotal`, {
|
|
1038
|
-
method: "GET",
|
|
1039
|
-
headers
|
|
1040
|
-
});
|
|
1041
|
-
if (!request.ok) {
|
|
1042
|
-
const errorData = await request.text();
|
|
1043
|
-
if (request.status === 401 || request.status === 403) {
|
|
1044
|
-
throw new AuthenticationError(
|
|
1045
|
-
`Authentication failed: ${errorData}`,
|
|
1046
|
-
request.status,
|
|
1047
|
-
errorData
|
|
1048
|
-
);
|
|
1049
|
-
}
|
|
1050
|
-
throw new NetworkError(
|
|
1051
|
-
`HTTP error: ${errorData}`,
|
|
1052
|
-
request.status,
|
|
1053
|
-
errorData
|
|
1054
|
-
);
|
|
1055
|
-
}
|
|
1056
|
-
const res = await request.json();
|
|
1057
|
-
return res.pin_size_total;
|
|
1058
|
-
} catch (error) {
|
|
1059
|
-
if (error instanceof PinataError) {
|
|
1060
|
-
throw error;
|
|
1061
|
-
}
|
|
1062
|
-
if (error instanceof Error) {
|
|
1063
|
-
throw new PinataError(
|
|
1064
|
-
`Error processing totalStorageUsage: ${error.message}`
|
|
1065
|
-
);
|
|
1066
|
-
}
|
|
1067
|
-
throw new PinataError(
|
|
1068
|
-
"An unknown error occurred while getting total storage usage"
|
|
1069
|
-
);
|
|
1070
|
-
}
|
|
1071
|
-
};
|
|
1072
|
-
|
|
1073
|
-
// src/core/keys/createKey.ts
|
|
1074
|
-
var createKey = async (config, options) => {
|
|
1075
|
-
if (!config) {
|
|
1076
|
-
throw new ValidationError("Pinata configuration is missing");
|
|
1077
|
-
}
|
|
1078
|
-
let headers;
|
|
1079
|
-
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1080
|
-
headers = { ...config.customHeaders };
|
|
1081
|
-
} else {
|
|
1082
|
-
headers = {
|
|
1083
|
-
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1084
|
-
"Content-Type": "application/json",
|
|
1085
|
-
Source: "sdk/createKey"
|
|
1086
|
-
};
|
|
1087
|
-
}
|
|
1088
|
-
const data = JSON.stringify(options);
|
|
1089
|
-
let endpoint = "https://api.pinata.cloud";
|
|
1090
|
-
if (config.endpointUrl) {
|
|
1091
|
-
endpoint = config.endpointUrl;
|
|
1092
|
-
}
|
|
1093
|
-
try {
|
|
1094
|
-
const request = await fetch(`${endpoint}/v3/pinata/keys`, {
|
|
1095
|
-
method: "POST",
|
|
1096
|
-
headers,
|
|
1097
|
-
body: data
|
|
1098
|
-
});
|
|
1099
|
-
if (!request.ok) {
|
|
1100
|
-
const errorData = await request.text();
|
|
1101
|
-
if (request.status === 401 || request.status === 403) {
|
|
1102
|
-
throw new AuthenticationError(
|
|
1103
|
-
`Authentication failed: ${errorData}`,
|
|
1104
|
-
request.status,
|
|
1105
|
-
errorData
|
|
1106
|
-
);
|
|
1107
|
-
}
|
|
1108
|
-
throw new NetworkError(
|
|
1109
|
-
`HTTP error: ${errorData}`,
|
|
1110
|
-
request.status,
|
|
1111
|
-
errorData
|
|
1112
|
-
);
|
|
1113
|
-
}
|
|
1114
|
-
const res = await request.json();
|
|
1115
|
-
return res;
|
|
1116
|
-
} catch (error) {
|
|
1117
|
-
if (error instanceof PinataError) {
|
|
1118
|
-
throw error;
|
|
1119
|
-
}
|
|
1120
|
-
if (error instanceof Error) {
|
|
1121
|
-
throw new PinataError(`Error processing createKey: ${error.message}`);
|
|
1122
|
-
}
|
|
1123
|
-
throw new PinataError("An unknown error occurred while creating API key");
|
|
1124
|
-
}
|
|
1125
|
-
};
|
|
1126
|
-
|
|
1127
|
-
// src/core/keys/listKeys.ts
|
|
1128
|
-
var listKeys = async (config, options) => {
|
|
1129
|
-
if (!config) {
|
|
1130
|
-
throw new ValidationError("Pinata configuration is missing");
|
|
1131
|
-
}
|
|
1132
|
-
let headers;
|
|
1133
|
-
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1134
|
-
headers = { ...config.customHeaders };
|
|
1135
|
-
} else {
|
|
1136
|
-
headers = {
|
|
1137
|
-
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1138
|
-
"Content-Type": "application/json",
|
|
1139
|
-
Source: "sdk/listKeys"
|
|
1140
|
-
};
|
|
1141
|
-
}
|
|
1142
|
-
const params = new URLSearchParams();
|
|
1143
|
-
if (options) {
|
|
1144
|
-
const { offset, name, revoked, limitedUse, exhausted } = options;
|
|
1145
|
-
if (offset)
|
|
1146
|
-
params.append("offset", offset.toString());
|
|
1147
|
-
if (revoked !== void 0)
|
|
1148
|
-
params.append("revoked", revoked.toString());
|
|
1149
|
-
if (limitedUse !== void 0)
|
|
1150
|
-
params.append("limitedUse", limitedUse.toString());
|
|
1151
|
-
if (exhausted !== void 0)
|
|
1152
|
-
params.append("exhausted", exhausted.toString());
|
|
1153
|
-
if (name)
|
|
1154
|
-
params.append("name", name);
|
|
1155
|
-
}
|
|
1156
|
-
let endpoint = "https://api.pinata.cloud";
|
|
1157
|
-
if (config.endpointUrl) {
|
|
1158
|
-
endpoint = config.endpointUrl;
|
|
1159
|
-
}
|
|
1160
|
-
try {
|
|
1161
|
-
const request = await fetch(
|
|
1162
|
-
`${endpoint}/v3/pinata/keys?${params.toString()}`,
|
|
1163
|
-
{
|
|
1164
|
-
method: "GET",
|
|
1165
|
-
headers
|
|
1166
|
-
}
|
|
1167
|
-
);
|
|
1168
|
-
if (!request.ok) {
|
|
1169
|
-
const errorData = await request.text();
|
|
1170
|
-
if (request.status === 401 || request.status === 403) {
|
|
1171
|
-
throw new AuthenticationError(
|
|
1172
|
-
`Authentication failed: ${errorData}`,
|
|
1173
|
-
request.status,
|
|
1174
|
-
errorData
|
|
1175
|
-
);
|
|
1176
|
-
}
|
|
1177
|
-
throw new NetworkError(
|
|
1178
|
-
`HTTP error: ${errorData}`,
|
|
1179
|
-
request.status,
|
|
1180
|
-
errorData
|
|
1181
|
-
);
|
|
1182
|
-
}
|
|
1183
|
-
const res = await request.json();
|
|
1184
|
-
return res.keys;
|
|
1185
|
-
} catch (error) {
|
|
1186
|
-
if (error instanceof PinataError) {
|
|
1187
|
-
throw error;
|
|
1188
|
-
}
|
|
1189
|
-
if (error instanceof Error) {
|
|
1190
|
-
throw new PinataError(`Error processing listKeys: ${error.message}`);
|
|
1191
|
-
}
|
|
1192
|
-
throw new PinataError("An unknown error occurred while listing API keys");
|
|
1193
|
-
}
|
|
1194
|
-
};
|
|
1195
|
-
|
|
1196
|
-
// src/core/keys/revokeKeys.ts
|
|
1197
|
-
var wait2 = (milliseconds) => {
|
|
1198
|
-
return new Promise((resolve) => {
|
|
1199
|
-
setTimeout(resolve, milliseconds);
|
|
1200
|
-
});
|
|
1201
|
-
};
|
|
1202
|
-
var revokeKeys = async (config, keys) => {
|
|
722
|
+
// src/core/keys/revokeKeys.ts
|
|
723
|
+
var wait2 = (milliseconds) => {
|
|
724
|
+
return new Promise((resolve) => {
|
|
725
|
+
setTimeout(resolve, milliseconds);
|
|
726
|
+
});
|
|
727
|
+
};
|
|
728
|
+
var revokeKeys = async (config, keys) => {
|
|
1203
729
|
if (!config) {
|
|
1204
730
|
throw new ValidationError("Pinata configuration is missing");
|
|
1205
731
|
}
|
|
@@ -1214,13 +740,13 @@ var revokeKeys = async (config, keys) => {
|
|
|
1214
740
|
};
|
|
1215
741
|
}
|
|
1216
742
|
const responses = [];
|
|
1217
|
-
let endpoint = "https://api.pinata.cloud";
|
|
743
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
1218
744
|
if (config.endpointUrl) {
|
|
1219
745
|
endpoint = config.endpointUrl;
|
|
1220
746
|
}
|
|
1221
747
|
for (const key of keys) {
|
|
1222
748
|
try {
|
|
1223
|
-
const request = await fetch(`${endpoint}/
|
|
749
|
+
const request = await fetch(`${endpoint}/pinata/keys/${key}`, {
|
|
1224
750
|
method: "PUT",
|
|
1225
751
|
headers
|
|
1226
752
|
});
|
|
@@ -1268,7 +794,10 @@ var createGroup = async (config, options) => {
|
|
|
1268
794
|
if (!config) {
|
|
1269
795
|
throw new ValidationError("Pinata configuration is missing");
|
|
1270
796
|
}
|
|
1271
|
-
const data = JSON.stringify(
|
|
797
|
+
const data = JSON.stringify({
|
|
798
|
+
name: options.name,
|
|
799
|
+
is_public: options.isPublic
|
|
800
|
+
});
|
|
1272
801
|
let headers;
|
|
1273
802
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1274
803
|
headers = { ...config.customHeaders };
|
|
@@ -1279,12 +808,12 @@ var createGroup = async (config, options) => {
|
|
|
1279
808
|
Source: "sdk/createGroup"
|
|
1280
809
|
};
|
|
1281
810
|
}
|
|
1282
|
-
let endpoint = "https://api.pinata.cloud";
|
|
811
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
1283
812
|
if (config.endpointUrl) {
|
|
1284
813
|
endpoint = config.endpointUrl;
|
|
1285
814
|
}
|
|
1286
815
|
try {
|
|
1287
|
-
const request = await fetch(`${endpoint}/groups`, {
|
|
816
|
+
const request = await fetch(`${endpoint}/files/groups`, {
|
|
1288
817
|
method: "POST",
|
|
1289
818
|
headers,
|
|
1290
819
|
body: data
|
|
@@ -1305,7 +834,8 @@ var createGroup = async (config, options) => {
|
|
|
1305
834
|
);
|
|
1306
835
|
}
|
|
1307
836
|
const res = await request.json();
|
|
1308
|
-
|
|
837
|
+
const resData = res.data;
|
|
838
|
+
return resData;
|
|
1309
839
|
} catch (error) {
|
|
1310
840
|
if (error instanceof PinataError) {
|
|
1311
841
|
throw error;
|
|
@@ -1334,23 +864,28 @@ var listGroups = async (config, options) => {
|
|
|
1334
864
|
}
|
|
1335
865
|
const params = new URLSearchParams();
|
|
1336
866
|
if (options) {
|
|
1337
|
-
const {
|
|
1338
|
-
if (
|
|
1339
|
-
params.append("
|
|
867
|
+
const { pageToken, nameContains, limit, isPublic } = options;
|
|
868
|
+
if (pageToken)
|
|
869
|
+
params.append("pageToken", pageToken.toString());
|
|
870
|
+
if (isPublic)
|
|
871
|
+
params.append("isPublic", isPublic.toString());
|
|
1340
872
|
if (nameContains !== void 0)
|
|
1341
873
|
params.append("nameContains", nameContains.toString());
|
|
1342
874
|
if (limit !== void 0)
|
|
1343
875
|
params.append("limit", limit.toString());
|
|
1344
876
|
}
|
|
1345
|
-
let endpoint = "https://api.pinata.cloud";
|
|
877
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
1346
878
|
if (config.endpointUrl) {
|
|
1347
879
|
endpoint = config.endpointUrl;
|
|
1348
880
|
}
|
|
1349
881
|
try {
|
|
1350
|
-
const request = await fetch(
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
882
|
+
const request = await fetch(
|
|
883
|
+
`${endpoint}/files/groups?${params.toString()}`,
|
|
884
|
+
{
|
|
885
|
+
method: "GET",
|
|
886
|
+
headers
|
|
887
|
+
}
|
|
888
|
+
);
|
|
1354
889
|
if (!request.ok) {
|
|
1355
890
|
const errorData = await request.text();
|
|
1356
891
|
if (request.status === 401 || request.status === 403) {
|
|
@@ -1367,7 +902,8 @@ var listGroups = async (config, options) => {
|
|
|
1367
902
|
);
|
|
1368
903
|
}
|
|
1369
904
|
const res = await request.json();
|
|
1370
|
-
|
|
905
|
+
const resData = res.data;
|
|
906
|
+
return resData;
|
|
1371
907
|
} catch (error) {
|
|
1372
908
|
if (error instanceof PinataError) {
|
|
1373
909
|
throw error;
|
|
@@ -1394,12 +930,12 @@ var getGroup = async (config, options) => {
|
|
|
1394
930
|
Source: "sdk/getGroup"
|
|
1395
931
|
};
|
|
1396
932
|
}
|
|
1397
|
-
let endpoint = "https://api.pinata.cloud";
|
|
933
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
1398
934
|
if (config.endpointUrl) {
|
|
1399
935
|
endpoint = config.endpointUrl;
|
|
1400
936
|
}
|
|
1401
937
|
try {
|
|
1402
|
-
const request = await fetch(`${endpoint}/groups/${options.groupId}`, {
|
|
938
|
+
const request = await fetch(`${endpoint}/files/groups/${options.groupId}`, {
|
|
1403
939
|
method: "GET",
|
|
1404
940
|
headers
|
|
1405
941
|
});
|
|
@@ -1419,7 +955,8 @@ var getGroup = async (config, options) => {
|
|
|
1419
955
|
);
|
|
1420
956
|
}
|
|
1421
957
|
const res = await request.json();
|
|
1422
|
-
|
|
958
|
+
const resData = res.data;
|
|
959
|
+
return resData;
|
|
1423
960
|
} catch (error) {
|
|
1424
961
|
if (error instanceof PinataError) {
|
|
1425
962
|
throw error;
|
|
@@ -1433,71 +970,14 @@ var getGroup = async (config, options) => {
|
|
|
1433
970
|
}
|
|
1434
971
|
};
|
|
1435
972
|
|
|
1436
|
-
// src/core/groups/addToGroup.ts
|
|
1437
|
-
var addToGroup = async (config, options) => {
|
|
1438
|
-
if (!config) {
|
|
1439
|
-
throw new ValidationError("Pinata configuration is missing");
|
|
1440
|
-
}
|
|
1441
|
-
const data = JSON.stringify({
|
|
1442
|
-
cids: options.cids
|
|
1443
|
-
});
|
|
1444
|
-
let headers;
|
|
1445
|
-
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1446
|
-
headers = { ...config.customHeaders };
|
|
1447
|
-
} else {
|
|
1448
|
-
headers = {
|
|
1449
|
-
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1450
|
-
"Content-Type": "application/json",
|
|
1451
|
-
Source: "sdk/addToGroup"
|
|
1452
|
-
};
|
|
1453
|
-
}
|
|
1454
|
-
let endpoint = "https://api.pinata.cloud";
|
|
1455
|
-
if (config.endpointUrl) {
|
|
1456
|
-
endpoint = config.endpointUrl;
|
|
1457
|
-
}
|
|
1458
|
-
try {
|
|
1459
|
-
const request = await fetch(`${endpoint}/groups/${options.groupId}/cids`, {
|
|
1460
|
-
method: "PUT",
|
|
1461
|
-
headers,
|
|
1462
|
-
body: data
|
|
1463
|
-
});
|
|
1464
|
-
if (!request.ok) {
|
|
1465
|
-
const errorData = await request.text();
|
|
1466
|
-
if (request.status === 401 || request.status === 403) {
|
|
1467
|
-
throw new AuthenticationError(
|
|
1468
|
-
`Authentication failed: ${errorData}`,
|
|
1469
|
-
request.status,
|
|
1470
|
-
errorData
|
|
1471
|
-
);
|
|
1472
|
-
}
|
|
1473
|
-
throw new NetworkError(
|
|
1474
|
-
`HTTP error: ${errorData}`,
|
|
1475
|
-
request.status,
|
|
1476
|
-
errorData
|
|
1477
|
-
);
|
|
1478
|
-
}
|
|
1479
|
-
const res = await request.text();
|
|
1480
|
-
return res;
|
|
1481
|
-
} catch (error) {
|
|
1482
|
-
if (error instanceof PinataError) {
|
|
1483
|
-
throw error;
|
|
1484
|
-
}
|
|
1485
|
-
if (error instanceof Error) {
|
|
1486
|
-
throw new PinataError(`Error processing addToGroup: ${error.message}`);
|
|
1487
|
-
}
|
|
1488
|
-
throw new PinataError(
|
|
1489
|
-
"An unknown error occurred while adding CIDs to group"
|
|
1490
|
-
);
|
|
1491
|
-
}
|
|
1492
|
-
};
|
|
1493
|
-
|
|
1494
973
|
// src/core/groups/updateGroup.ts
|
|
1495
974
|
var updateGroup = async (config, options) => {
|
|
1496
975
|
if (!config) {
|
|
1497
976
|
throw new ValidationError("Pinata configuration is missing");
|
|
1498
977
|
}
|
|
1499
978
|
const data = JSON.stringify({
|
|
1500
|
-
name: options.name
|
|
979
|
+
name: options.name,
|
|
980
|
+
is_public: options.isPublic
|
|
1501
981
|
});
|
|
1502
982
|
let headers;
|
|
1503
983
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
@@ -1509,559 +989,12 @@ var updateGroup = async (config, options) => {
|
|
|
1509
989
|
Source: "sdk/updateGroup"
|
|
1510
990
|
};
|
|
1511
991
|
}
|
|
1512
|
-
let endpoint = "https://api.pinata.cloud";
|
|
1513
|
-
if (config.endpointUrl) {
|
|
1514
|
-
endpoint = config.endpointUrl;
|
|
1515
|
-
}
|
|
1516
|
-
try {
|
|
1517
|
-
const request = await fetch(`${endpoint}/groups/${options.groupId}`, {
|
|
1518
|
-
method: "PUT",
|
|
1519
|
-
headers,
|
|
1520
|
-
body: data
|
|
1521
|
-
});
|
|
1522
|
-
if (!request.ok) {
|
|
1523
|
-
const errorData = await request.text();
|
|
1524
|
-
if (request.status === 401 || request.status === 403) {
|
|
1525
|
-
throw new AuthenticationError(
|
|
1526
|
-
`Authentication failed: ${errorData}`,
|
|
1527
|
-
request.status,
|
|
1528
|
-
errorData
|
|
1529
|
-
);
|
|
1530
|
-
}
|
|
1531
|
-
throw new NetworkError(
|
|
1532
|
-
`HTTP error: ${errorData}`,
|
|
1533
|
-
request.status,
|
|
1534
|
-
errorData
|
|
1535
|
-
);
|
|
1536
|
-
}
|
|
1537
|
-
const res = await request.json();
|
|
1538
|
-
return res;
|
|
1539
|
-
} catch (error) {
|
|
1540
|
-
if (error instanceof PinataError) {
|
|
1541
|
-
throw error;
|
|
1542
|
-
}
|
|
1543
|
-
if (error instanceof Error) {
|
|
1544
|
-
throw new PinataError(`Error processing updateGroup: ${error.message}`);
|
|
1545
|
-
}
|
|
1546
|
-
throw new PinataError("An unknown error occurred while updating group");
|
|
1547
|
-
}
|
|
1548
|
-
};
|
|
1549
|
-
|
|
1550
|
-
// src/core/groups/removeFromGroup.ts
|
|
1551
|
-
var removeFromGroup = async (config, options) => {
|
|
1552
|
-
if (!config) {
|
|
1553
|
-
throw new ValidationError("Pinata configuration is missing");
|
|
1554
|
-
}
|
|
1555
|
-
let headers;
|
|
1556
|
-
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1557
|
-
headers = { ...config.customHeaders };
|
|
1558
|
-
} else {
|
|
1559
|
-
headers = {
|
|
1560
|
-
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1561
|
-
"Content-Type": "application/json",
|
|
1562
|
-
Source: "sdk/removeFromGroup"
|
|
1563
|
-
};
|
|
1564
|
-
}
|
|
1565
|
-
const data = JSON.stringify({
|
|
1566
|
-
cids: options.cids
|
|
1567
|
-
});
|
|
1568
|
-
let endpoint = "https://api.pinata.cloud";
|
|
1569
|
-
if (config.endpointUrl) {
|
|
1570
|
-
endpoint = config.endpointUrl;
|
|
1571
|
-
}
|
|
1572
|
-
try {
|
|
1573
|
-
const request = await fetch(`${endpoint}/groups/${options.groupId}/cids`, {
|
|
1574
|
-
method: "DELETE",
|
|
1575
|
-
headers,
|
|
1576
|
-
body: data
|
|
1577
|
-
});
|
|
1578
|
-
if (!request.ok) {
|
|
1579
|
-
const errorData = await request.text();
|
|
1580
|
-
if (request.status === 401 || request.status === 403) {
|
|
1581
|
-
throw new AuthenticationError(
|
|
1582
|
-
`Authentication failed: ${errorData}`,
|
|
1583
|
-
request.status,
|
|
1584
|
-
errorData
|
|
1585
|
-
);
|
|
1586
|
-
}
|
|
1587
|
-
throw new NetworkError(
|
|
1588
|
-
`HTTP error: ${errorData}`,
|
|
1589
|
-
request.status,
|
|
1590
|
-
errorData
|
|
1591
|
-
);
|
|
1592
|
-
}
|
|
1593
|
-
const res = await request.text();
|
|
1594
|
-
return res;
|
|
1595
|
-
} catch (error) {
|
|
1596
|
-
if (error instanceof PinataError) {
|
|
1597
|
-
throw error;
|
|
1598
|
-
}
|
|
1599
|
-
if (error instanceof Error) {
|
|
1600
|
-
throw new PinataError(
|
|
1601
|
-
`Error processing removeFromGroup: ${error.message}`
|
|
1602
|
-
);
|
|
1603
|
-
}
|
|
1604
|
-
throw new PinataError(
|
|
1605
|
-
"An unknown error occurred while removing CIDs from a group"
|
|
1606
|
-
);
|
|
1607
|
-
}
|
|
1608
|
-
};
|
|
1609
|
-
|
|
1610
|
-
// src/core/groups/deleteGroup.ts
|
|
1611
|
-
var deleteGroup = async (config, options) => {
|
|
1612
|
-
if (!config) {
|
|
1613
|
-
throw new ValidationError("Pinata configuration is missing");
|
|
1614
|
-
}
|
|
1615
|
-
let headers;
|
|
1616
|
-
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1617
|
-
headers = { ...config.customHeaders };
|
|
1618
|
-
} else {
|
|
1619
|
-
headers = {
|
|
1620
|
-
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1621
|
-
"Content-Type": "application/json",
|
|
1622
|
-
Source: "sdk/deleteGroup"
|
|
1623
|
-
};
|
|
1624
|
-
}
|
|
1625
|
-
let endpoint = "https://api.pinata.cloud";
|
|
1626
|
-
if (config.endpointUrl) {
|
|
1627
|
-
endpoint = config.endpointUrl;
|
|
1628
|
-
}
|
|
1629
|
-
try {
|
|
1630
|
-
const request = await fetch(`${endpoint}/groups/${options.groupId}`, {
|
|
1631
|
-
method: "DELETE",
|
|
1632
|
-
headers
|
|
1633
|
-
});
|
|
1634
|
-
if (!request.ok) {
|
|
1635
|
-
const errorData = await request.text();
|
|
1636
|
-
if (request.status === 401 || request.status === 403) {
|
|
1637
|
-
throw new AuthenticationError(
|
|
1638
|
-
`Authentication failed: ${errorData}`,
|
|
1639
|
-
request.status,
|
|
1640
|
-
errorData
|
|
1641
|
-
);
|
|
1642
|
-
}
|
|
1643
|
-
throw new NetworkError(
|
|
1644
|
-
`HTTP error: ${errorData}`,
|
|
1645
|
-
request.status,
|
|
1646
|
-
errorData
|
|
1647
|
-
);
|
|
1648
|
-
}
|
|
1649
|
-
const res = await request.text();
|
|
1650
|
-
return res;
|
|
1651
|
-
} catch (error) {
|
|
1652
|
-
if (error instanceof PinataError) {
|
|
1653
|
-
throw error;
|
|
1654
|
-
}
|
|
1655
|
-
if (error instanceof Error) {
|
|
1656
|
-
throw new PinataError(`Error processing deleteGroup: ${error.message}`);
|
|
1657
|
-
}
|
|
1658
|
-
throw new PinataError("An unknown error occurred while deleting a group");
|
|
1659
|
-
}
|
|
1660
|
-
};
|
|
1661
|
-
|
|
1662
|
-
// src/core/signatures/addSignature.ts
|
|
1663
|
-
var addSignature = async (config, options) => {
|
|
1664
|
-
if (!config) {
|
|
1665
|
-
throw new ValidationError("Pinata configuration is missing");
|
|
1666
|
-
}
|
|
1667
|
-
const data = JSON.stringify({
|
|
1668
|
-
signature: options.signature
|
|
1669
|
-
});
|
|
1670
|
-
let headers;
|
|
1671
|
-
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1672
|
-
headers = { ...config.customHeaders };
|
|
1673
|
-
} else {
|
|
1674
|
-
headers = {
|
|
1675
|
-
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1676
|
-
"Content-Type": "application/json",
|
|
1677
|
-
Source: "sdk/addSignature"
|
|
1678
|
-
};
|
|
1679
|
-
}
|
|
1680
|
-
let endpoint = "https://api.pinata.cloud";
|
|
1681
|
-
if (config.endpointUrl) {
|
|
1682
|
-
endpoint = config.endpointUrl;
|
|
1683
|
-
}
|
|
1684
|
-
try {
|
|
1685
|
-
const request = await fetch(
|
|
1686
|
-
`${endpoint}/v3/ipfs/signature/${options.cid}`,
|
|
1687
|
-
{
|
|
1688
|
-
method: "POST",
|
|
1689
|
-
headers,
|
|
1690
|
-
body: data
|
|
1691
|
-
}
|
|
1692
|
-
);
|
|
1693
|
-
if (!request.ok) {
|
|
1694
|
-
const errorData = await request.text();
|
|
1695
|
-
if (request.status === 401 || request.status === 403) {
|
|
1696
|
-
throw new AuthenticationError(
|
|
1697
|
-
`Authentication failed: ${errorData}`,
|
|
1698
|
-
request.status,
|
|
1699
|
-
errorData
|
|
1700
|
-
);
|
|
1701
|
-
}
|
|
1702
|
-
if (request.status === 403) {
|
|
1703
|
-
throw new PinataError(
|
|
1704
|
-
"Unauthorized signing, you must be the original owner of the file and it must not have a signature",
|
|
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.json();
|
|
1716
|
-
return res.data;
|
|
1717
|
-
} catch (error) {
|
|
1718
|
-
if (error instanceof PinataError) {
|
|
1719
|
-
throw error;
|
|
1720
|
-
}
|
|
1721
|
-
if (error instanceof Error) {
|
|
1722
|
-
throw new PinataError(`Error processing addSignature: ${error.message}`);
|
|
1723
|
-
}
|
|
1724
|
-
throw new PinataError(
|
|
1725
|
-
"An unknown error occurred while adding signature to CID"
|
|
1726
|
-
);
|
|
1727
|
-
}
|
|
1728
|
-
};
|
|
1729
|
-
|
|
1730
|
-
// src/core/signatures/getSignature.ts
|
|
1731
|
-
var getSignature = async (config, cid) => {
|
|
1732
|
-
if (!config) {
|
|
1733
|
-
throw new ValidationError("Pinata configuration is missing");
|
|
1734
|
-
}
|
|
1735
|
-
let headers;
|
|
1736
|
-
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1737
|
-
headers = { ...config.customHeaders };
|
|
1738
|
-
} else {
|
|
1739
|
-
headers = {
|
|
1740
|
-
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1741
|
-
"Content-Type": "application/json",
|
|
1742
|
-
Source: "sdk/getSignature"
|
|
1743
|
-
};
|
|
1744
|
-
}
|
|
1745
|
-
let endpoint = "https://api.pinata.cloud";
|
|
1746
|
-
if (config.endpointUrl) {
|
|
1747
|
-
endpoint = config.endpointUrl;
|
|
1748
|
-
}
|
|
1749
|
-
try {
|
|
1750
|
-
const request = await fetch(`${endpoint}/v3/ipfs/signature/${cid}`, {
|
|
1751
|
-
method: "GET",
|
|
1752
|
-
headers
|
|
1753
|
-
});
|
|
1754
|
-
if (!request.ok) {
|
|
1755
|
-
const errorData = await request.text();
|
|
1756
|
-
if (request.status === 401 || request.status === 403) {
|
|
1757
|
-
throw new AuthenticationError(
|
|
1758
|
-
`Authentication failed: ${errorData}`,
|
|
1759
|
-
request.status,
|
|
1760
|
-
errorData
|
|
1761
|
-
);
|
|
1762
|
-
}
|
|
1763
|
-
throw new NetworkError(
|
|
1764
|
-
`HTTP error: ${errorData}`,
|
|
1765
|
-
request.status,
|
|
1766
|
-
errorData
|
|
1767
|
-
);
|
|
1768
|
-
}
|
|
1769
|
-
const res = await request.json();
|
|
1770
|
-
return res.data;
|
|
1771
|
-
} catch (error) {
|
|
1772
|
-
if (error instanceof PinataError) {
|
|
1773
|
-
throw error;
|
|
1774
|
-
}
|
|
1775
|
-
if (error instanceof Error) {
|
|
1776
|
-
throw new PinataError(`Error processing getSignature: ${error.message}`);
|
|
1777
|
-
}
|
|
1778
|
-
throw new PinataError(
|
|
1779
|
-
"An unknown error occurred while fetching signature for CID"
|
|
1780
|
-
);
|
|
1781
|
-
}
|
|
1782
|
-
};
|
|
1783
|
-
|
|
1784
|
-
// src/core/signatures/removeSignature.ts
|
|
1785
|
-
var removeSignature = async (config, cid) => {
|
|
1786
|
-
if (!config) {
|
|
1787
|
-
throw new ValidationError("Pinata configuration is missing");
|
|
1788
|
-
}
|
|
1789
|
-
let headers;
|
|
1790
|
-
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1791
|
-
headers = { ...config.customHeaders };
|
|
1792
|
-
} else {
|
|
1793
|
-
headers = {
|
|
1794
|
-
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1795
|
-
"Content-Type": "application/json",
|
|
1796
|
-
Source: "sdk/removeSignature"
|
|
1797
|
-
};
|
|
1798
|
-
}
|
|
1799
|
-
let endpoint = "https://api.pinata.cloud";
|
|
1800
|
-
if (config.endpointUrl) {
|
|
1801
|
-
endpoint = config.endpointUrl;
|
|
1802
|
-
}
|
|
1803
|
-
try {
|
|
1804
|
-
const request = await fetch(`${endpoint}/v3/ipfs/signature/${cid}`, {
|
|
1805
|
-
method: "DELETE",
|
|
1806
|
-
headers
|
|
1807
|
-
});
|
|
1808
|
-
if (!request.ok) {
|
|
1809
|
-
const errorData = await request.text();
|
|
1810
|
-
if (request.status === 401 || request.status === 403) {
|
|
1811
|
-
throw new AuthenticationError(
|
|
1812
|
-
`Authentication failed: ${errorData}`,
|
|
1813
|
-
request.status,
|
|
1814
|
-
errorData
|
|
1815
|
-
);
|
|
1816
|
-
}
|
|
1817
|
-
throw new NetworkError(
|
|
1818
|
-
`HTTP error: ${errorData}`,
|
|
1819
|
-
request.status,
|
|
1820
|
-
errorData
|
|
1821
|
-
);
|
|
1822
|
-
}
|
|
1823
|
-
return "OK";
|
|
1824
|
-
} catch (error) {
|
|
1825
|
-
if (error instanceof PinataError) {
|
|
1826
|
-
throw error;
|
|
1827
|
-
}
|
|
1828
|
-
if (error instanceof Error) {
|
|
1829
|
-
throw new PinataError(`Error processing addSignature: ${error.message}`);
|
|
1830
|
-
}
|
|
1831
|
-
throw new PinataError(
|
|
1832
|
-
"An unknown error occurred while adding signature to CID"
|
|
1833
|
-
);
|
|
1834
|
-
}
|
|
1835
|
-
};
|
|
1836
|
-
|
|
1837
|
-
// src/core/gateway/analyticsTopUsage.ts
|
|
1838
|
-
var analyticsTopUsage = async (config, options) => {
|
|
1839
|
-
if (!config) {
|
|
1840
|
-
throw new ValidationError("Pinata configuration is missing");
|
|
1841
|
-
}
|
|
1842
|
-
const params = new URLSearchParams({
|
|
1843
|
-
includesCount: "false"
|
|
1844
|
-
});
|
|
1845
|
-
if (options) {
|
|
1846
|
-
const {
|
|
1847
|
-
cid,
|
|
1848
|
-
gateway_domain,
|
|
1849
|
-
start_date,
|
|
1850
|
-
end_date,
|
|
1851
|
-
file_name,
|
|
1852
|
-
user_agent,
|
|
1853
|
-
country,
|
|
1854
|
-
region,
|
|
1855
|
-
referer,
|
|
1856
|
-
limit,
|
|
1857
|
-
sort_order,
|
|
1858
|
-
sort_by,
|
|
1859
|
-
attribute
|
|
1860
|
-
} = options;
|
|
1861
|
-
if (cid)
|
|
1862
|
-
params.append("cid", cid);
|
|
1863
|
-
if (gateway_domain)
|
|
1864
|
-
params.append("gateway_domain", gateway_domain);
|
|
1865
|
-
if (start_date)
|
|
1866
|
-
params.append("start_date", start_date);
|
|
1867
|
-
if (end_date)
|
|
1868
|
-
params.append("end_date", end_date);
|
|
1869
|
-
if (file_name)
|
|
1870
|
-
params.append("file_name", file_name);
|
|
1871
|
-
if (user_agent)
|
|
1872
|
-
params.append("user_agent", user_agent.toString());
|
|
1873
|
-
if (country)
|
|
1874
|
-
params.append("country", country.toString());
|
|
1875
|
-
if (region)
|
|
1876
|
-
params.append("region", region);
|
|
1877
|
-
if (referer)
|
|
1878
|
-
params.append("referer", referer.toString());
|
|
1879
|
-
if (limit)
|
|
1880
|
-
params.append("limit", limit.toString());
|
|
1881
|
-
if (sort_order)
|
|
1882
|
-
params.append("sort_order", sort_order);
|
|
1883
|
-
if (sort_by)
|
|
1884
|
-
params.append("sort_by", sort_by);
|
|
1885
|
-
if (attribute)
|
|
1886
|
-
params.append("by", attribute);
|
|
1887
|
-
}
|
|
1888
|
-
let endpoint = "https://api.pinata.cloud";
|
|
1889
|
-
if (config.endpointUrl) {
|
|
1890
|
-
endpoint = config.endpointUrl;
|
|
1891
|
-
}
|
|
1892
|
-
const url = `${endpoint}/v3/ipfs/gateway_analytics_top?${params.toString()}`;
|
|
1893
|
-
try {
|
|
1894
|
-
let headers;
|
|
1895
|
-
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1896
|
-
headers = { ...config.customHeaders };
|
|
1897
|
-
} else {
|
|
1898
|
-
headers = {
|
|
1899
|
-
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1900
|
-
Source: "sdk/analyticsTopUsage"
|
|
1901
|
-
};
|
|
1902
|
-
}
|
|
1903
|
-
const request = await fetch(url, {
|
|
1904
|
-
method: "GET",
|
|
1905
|
-
headers
|
|
1906
|
-
});
|
|
1907
|
-
if (!request.ok) {
|
|
1908
|
-
const errorData = await request.text();
|
|
1909
|
-
if (request.status === 401 || request.status === 403) {
|
|
1910
|
-
throw new AuthenticationError(
|
|
1911
|
-
`Authentication failed: ${errorData}`,
|
|
1912
|
-
request.status,
|
|
1913
|
-
errorData
|
|
1914
|
-
);
|
|
1915
|
-
}
|
|
1916
|
-
throw new NetworkError(
|
|
1917
|
-
`HTTP error: ${errorData}`,
|
|
1918
|
-
request.status,
|
|
1919
|
-
errorData
|
|
1920
|
-
);
|
|
1921
|
-
}
|
|
1922
|
-
const res = await request.json();
|
|
1923
|
-
const resData = res.data;
|
|
1924
|
-
return resData;
|
|
1925
|
-
} catch (error) {
|
|
1926
|
-
if (error instanceof PinataError) {
|
|
1927
|
-
throw error;
|
|
1928
|
-
}
|
|
1929
|
-
if (error instanceof Error) {
|
|
1930
|
-
throw new PinataError(
|
|
1931
|
-
`Error processing anaytics usage: ${error.message}`
|
|
1932
|
-
);
|
|
1933
|
-
}
|
|
1934
|
-
throw new PinataError(
|
|
1935
|
-
"An unknown error occurred while fetching gateway usage"
|
|
1936
|
-
);
|
|
1937
|
-
}
|
|
1938
|
-
};
|
|
1939
|
-
|
|
1940
|
-
// src/core/gateway/analyticsDateInterval.ts
|
|
1941
|
-
var analyticsDateInterval = async (config, options) => {
|
|
1942
|
-
if (!config) {
|
|
1943
|
-
throw new ValidationError("Pinata configuration is missing");
|
|
1944
|
-
}
|
|
1945
|
-
const params = new URLSearchParams();
|
|
1946
|
-
if (options) {
|
|
1947
|
-
const {
|
|
1948
|
-
cid,
|
|
1949
|
-
gateway_domain,
|
|
1950
|
-
start_date,
|
|
1951
|
-
end_date,
|
|
1952
|
-
file_name,
|
|
1953
|
-
user_agent,
|
|
1954
|
-
country,
|
|
1955
|
-
region,
|
|
1956
|
-
referer,
|
|
1957
|
-
limit,
|
|
1958
|
-
sort_order,
|
|
1959
|
-
date_interval,
|
|
1960
|
-
sort_by
|
|
1961
|
-
} = options;
|
|
1962
|
-
if (cid)
|
|
1963
|
-
params.append("cid", cid);
|
|
1964
|
-
if (gateway_domain)
|
|
1965
|
-
params.append("gateway_domain", gateway_domain);
|
|
1966
|
-
if (start_date)
|
|
1967
|
-
params.append("start_date", start_date);
|
|
1968
|
-
if (end_date)
|
|
1969
|
-
params.append("end_date", end_date);
|
|
1970
|
-
if (file_name)
|
|
1971
|
-
params.append("file_name", file_name);
|
|
1972
|
-
if (user_agent)
|
|
1973
|
-
params.append("user_agent", user_agent.toString());
|
|
1974
|
-
if (country)
|
|
1975
|
-
params.append("country", country.toString());
|
|
1976
|
-
if (region)
|
|
1977
|
-
params.append("region", region);
|
|
1978
|
-
if (referer)
|
|
1979
|
-
params.append("referer", referer.toString());
|
|
1980
|
-
if (limit)
|
|
1981
|
-
params.append("limit", limit.toString());
|
|
1982
|
-
if (sort_order)
|
|
1983
|
-
params.append("sort_order", sort_order);
|
|
1984
|
-
if (sort_by)
|
|
1985
|
-
params.append("sort_by", sort_by);
|
|
1986
|
-
if (date_interval)
|
|
1987
|
-
params.append("by", date_interval);
|
|
1988
|
-
}
|
|
1989
|
-
let endpoint = "https://api.pinata.cloud";
|
|
1990
|
-
if (config.endpointUrl) {
|
|
1991
|
-
endpoint = config.endpointUrl;
|
|
1992
|
-
}
|
|
1993
|
-
const url = `${endpoint}/v3/ipfs/gateway_analytics_time_series?${params.toString()}`;
|
|
1994
|
-
try {
|
|
1995
|
-
let headers;
|
|
1996
|
-
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1997
|
-
headers = { ...config.customHeaders };
|
|
1998
|
-
} else {
|
|
1999
|
-
headers = {
|
|
2000
|
-
Authorization: `Bearer ${config.pinataJwt}`,
|
|
2001
|
-
Source: "sdk/analyticsDateInterval"
|
|
2002
|
-
};
|
|
2003
|
-
}
|
|
2004
|
-
const request = await fetch(url, {
|
|
2005
|
-
method: "GET",
|
|
2006
|
-
headers
|
|
2007
|
-
});
|
|
2008
|
-
if (!request.ok) {
|
|
2009
|
-
const errorData = await request.text();
|
|
2010
|
-
if (request.status === 401 || request.status === 403) {
|
|
2011
|
-
throw new AuthenticationError(
|
|
2012
|
-
`Authentication failed: ${errorData}`,
|
|
2013
|
-
request.status,
|
|
2014
|
-
errorData
|
|
2015
|
-
);
|
|
2016
|
-
}
|
|
2017
|
-
throw new NetworkError(
|
|
2018
|
-
`HTTP error: ${errorData}`,
|
|
2019
|
-
request.status,
|
|
2020
|
-
errorData
|
|
2021
|
-
);
|
|
2022
|
-
}
|
|
2023
|
-
const res = await request.json();
|
|
2024
|
-
const resData = res.data;
|
|
2025
|
-
return resData;
|
|
2026
|
-
} catch (error) {
|
|
2027
|
-
if (error instanceof PinataError) {
|
|
2028
|
-
throw error;
|
|
2029
|
-
}
|
|
2030
|
-
if (error instanceof Error) {
|
|
2031
|
-
throw new PinataError(
|
|
2032
|
-
`Error processing anaytics usage: ${error.message}`
|
|
2033
|
-
);
|
|
2034
|
-
}
|
|
2035
|
-
throw new PinataError(
|
|
2036
|
-
"An unknown error occurred while fetching gateway usage"
|
|
2037
|
-
);
|
|
2038
|
-
}
|
|
2039
|
-
};
|
|
2040
|
-
|
|
2041
|
-
// src/core/gateway/swapCid.ts
|
|
2042
|
-
var swapCid = async (config, options) => {
|
|
2043
|
-
if (!config) {
|
|
2044
|
-
throw new ValidationError("Pinata configuration is missing");
|
|
2045
|
-
}
|
|
2046
|
-
const data = JSON.stringify({
|
|
2047
|
-
swapCid: options.swapCid
|
|
2048
|
-
});
|
|
2049
|
-
let headers;
|
|
2050
|
-
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
2051
|
-
headers = { ...config.customHeaders };
|
|
2052
|
-
} else {
|
|
2053
|
-
headers = {
|
|
2054
|
-
Authorization: `Bearer ${config.pinataJwt}`,
|
|
2055
|
-
"Content-Type": "application/json",
|
|
2056
|
-
Source: "sdk/swapCid"
|
|
2057
|
-
};
|
|
2058
|
-
}
|
|
2059
|
-
let endpoint = "https://api.pinata.cloud";
|
|
992
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
2060
993
|
if (config.endpointUrl) {
|
|
2061
994
|
endpoint = config.endpointUrl;
|
|
2062
995
|
}
|
|
2063
996
|
try {
|
|
2064
|
-
const request = await fetch(`${endpoint}/
|
|
997
|
+
const request = await fetch(`${endpoint}/files/groups/${options.groupId}`, {
|
|
2065
998
|
method: "PUT",
|
|
2066
999
|
headers,
|
|
2067
1000
|
body: data
|
|
@@ -2075,20 +1008,6 @@ var swapCid = async (config, options) => {
|
|
|
2075
1008
|
errorData
|
|
2076
1009
|
);
|
|
2077
1010
|
}
|
|
2078
|
-
if (request.status === 403) {
|
|
2079
|
-
throw new PinataError(
|
|
2080
|
-
"Unauthorized CID Swap",
|
|
2081
|
-
request.status,
|
|
2082
|
-
errorData
|
|
2083
|
-
);
|
|
2084
|
-
}
|
|
2085
|
-
if (request.status === 404) {
|
|
2086
|
-
throw new PinataError(
|
|
2087
|
-
"CID not pinned to account",
|
|
2088
|
-
request.status,
|
|
2089
|
-
errorData
|
|
2090
|
-
);
|
|
2091
|
-
}
|
|
2092
1011
|
throw new NetworkError(
|
|
2093
1012
|
`HTTP error: ${errorData}`,
|
|
2094
1013
|
request.status,
|
|
@@ -2103,14 +1022,14 @@ var swapCid = async (config, options) => {
|
|
|
2103
1022
|
throw error;
|
|
2104
1023
|
}
|
|
2105
1024
|
if (error instanceof Error) {
|
|
2106
|
-
throw new PinataError(`Error processing
|
|
1025
|
+
throw new PinataError(`Error processing updateGroup: ${error.message}`);
|
|
2107
1026
|
}
|
|
2108
|
-
throw new PinataError("An unknown error occurred while
|
|
1027
|
+
throw new PinataError("An unknown error occurred while updating group");
|
|
2109
1028
|
}
|
|
2110
1029
|
};
|
|
2111
1030
|
|
|
2112
|
-
// src/core/
|
|
2113
|
-
var
|
|
1031
|
+
// src/core/groups/deleteGroup.ts
|
|
1032
|
+
var deleteGroup = async (config, options) => {
|
|
2114
1033
|
if (!config) {
|
|
2115
1034
|
throw new ValidationError("Pinata configuration is missing");
|
|
2116
1035
|
}
|
|
@@ -2121,21 +1040,18 @@ var swapHistory = async (config, options) => {
|
|
|
2121
1040
|
headers = {
|
|
2122
1041
|
Authorization: `Bearer ${config.pinataJwt}`,
|
|
2123
1042
|
"Content-Type": "application/json",
|
|
2124
|
-
Source: "sdk/
|
|
1043
|
+
Source: "sdk/deleteGroup"
|
|
2125
1044
|
};
|
|
2126
1045
|
}
|
|
2127
|
-
let endpoint = "https://api.pinata.cloud";
|
|
1046
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
2128
1047
|
if (config.endpointUrl) {
|
|
2129
1048
|
endpoint = config.endpointUrl;
|
|
2130
1049
|
}
|
|
2131
1050
|
try {
|
|
2132
|
-
const request = await fetch(
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
headers
|
|
2137
|
-
}
|
|
2138
|
-
);
|
|
1051
|
+
const request = await fetch(`${endpoint}/files/groups/${options.groupId}`, {
|
|
1052
|
+
method: "DELETE",
|
|
1053
|
+
headers
|
|
1054
|
+
});
|
|
2139
1055
|
if (!request.ok) {
|
|
2140
1056
|
const errorData = await request.text();
|
|
2141
1057
|
if (request.status === 401 || request.status === 403) {
|
|
@@ -2145,78 +1061,52 @@ var swapHistory = async (config, options) => {
|
|
|
2145
1061
|
errorData
|
|
2146
1062
|
);
|
|
2147
1063
|
}
|
|
2148
|
-
if (request.status === 404) {
|
|
2149
|
-
throw new PinataError(
|
|
2150
|
-
"CID does not have history",
|
|
2151
|
-
request.status,
|
|
2152
|
-
errorData
|
|
2153
|
-
);
|
|
2154
|
-
}
|
|
2155
1064
|
throw new NetworkError(
|
|
2156
1065
|
`HTTP error: ${errorData}`,
|
|
2157
1066
|
request.status,
|
|
2158
1067
|
errorData
|
|
2159
1068
|
);
|
|
2160
1069
|
}
|
|
2161
|
-
const res =
|
|
2162
|
-
|
|
2163
|
-
return resData;
|
|
1070
|
+
const res = request.statusText;
|
|
1071
|
+
return res;
|
|
2164
1072
|
} catch (error) {
|
|
2165
1073
|
if (error instanceof PinataError) {
|
|
2166
1074
|
throw error;
|
|
2167
1075
|
}
|
|
2168
1076
|
if (error instanceof Error) {
|
|
2169
|
-
throw new PinataError(`Error
|
|
1077
|
+
throw new PinataError(`Error processing deleteGroup: ${error.message}`);
|
|
2170
1078
|
}
|
|
2171
|
-
throw new PinataError(
|
|
2172
|
-
"An unknown error occurred while fetching swap history"
|
|
2173
|
-
);
|
|
1079
|
+
throw new PinataError("An unknown error occurred while deleting a group");
|
|
2174
1080
|
}
|
|
2175
1081
|
};
|
|
2176
1082
|
|
|
2177
|
-
// src/core/gateway/
|
|
2178
|
-
var
|
|
1083
|
+
// src/core/gateway/createSignedURL.ts
|
|
1084
|
+
var createSignedURL = async (config, options) => {
|
|
2179
1085
|
if (!config) {
|
|
2180
1086
|
throw new ValidationError("Pinata configuration is missing");
|
|
2181
1087
|
}
|
|
2182
|
-
let
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
};
|
|
2191
|
-
}
|
|
2192
|
-
let endpoint = "https://api.pinata.cloud";
|
|
2193
|
-
if (config.endpointUrl) {
|
|
2194
|
-
endpoint = config.endpointUrl;
|
|
2195
|
-
}
|
|
1088
|
+
let newUrl = `${config?.pinataGateway}/files/${options.cid}`;
|
|
1089
|
+
const date = options?.date || Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3);
|
|
1090
|
+
const payload = JSON.stringify({
|
|
1091
|
+
url: newUrl,
|
|
1092
|
+
date,
|
|
1093
|
+
expires: options.expires,
|
|
1094
|
+
method: "GET"
|
|
1095
|
+
});
|
|
2196
1096
|
try {
|
|
2197
|
-
const request = await fetch(
|
|
2198
|
-
method: "
|
|
2199
|
-
headers
|
|
1097
|
+
const request = await fetch("https://api.pinata.cloud/v3/files/sign", {
|
|
1098
|
+
method: "POST",
|
|
1099
|
+
headers: {
|
|
1100
|
+
"Content-Type": "application/json",
|
|
1101
|
+
Authorization: `Bearer ${config?.pinataJwt}`
|
|
1102
|
+
},
|
|
1103
|
+
body: payload
|
|
2200
1104
|
});
|
|
2201
1105
|
if (!request.ok) {
|
|
2202
1106
|
const errorData = await request.text();
|
|
2203
1107
|
if (request.status === 401 || request.status === 403) {
|
|
2204
1108
|
throw new AuthenticationError(
|
|
2205
|
-
`Authentication
|
|
2206
|
-
request.status,
|
|
2207
|
-
errorData
|
|
2208
|
-
);
|
|
2209
|
-
}
|
|
2210
|
-
if (request.status === 403) {
|
|
2211
|
-
throw new PinataError(
|
|
2212
|
-
"Unauthorized CID Swap Deletion",
|
|
2213
|
-
request.status,
|
|
2214
|
-
errorData
|
|
2215
|
-
);
|
|
2216
|
-
}
|
|
2217
|
-
if (request.status === 404) {
|
|
2218
|
-
throw new PinataError(
|
|
2219
|
-
"CID not pinned to account",
|
|
1109
|
+
`Authentication Failed: ${errorData}`,
|
|
2220
1110
|
request.status,
|
|
2221
1111
|
errorData
|
|
2222
1112
|
);
|
|
@@ -2227,15 +1117,18 @@ var deleteSwap = async (config, cid) => {
|
|
|
2227
1117
|
errorData
|
|
2228
1118
|
);
|
|
2229
1119
|
}
|
|
2230
|
-
|
|
1120
|
+
const res = await request.json();
|
|
1121
|
+
return res.data;
|
|
2231
1122
|
} catch (error) {
|
|
2232
1123
|
if (error instanceof PinataError) {
|
|
2233
1124
|
throw error;
|
|
2234
1125
|
}
|
|
2235
1126
|
if (error instanceof Error) {
|
|
2236
|
-
throw new PinataError(
|
|
1127
|
+
throw new PinataError(
|
|
1128
|
+
`Error processing createSignedURL: ${error.message}`
|
|
1129
|
+
);
|
|
2237
1130
|
}
|
|
2238
|
-
throw new PinataError("An unknown error occurred while
|
|
1131
|
+
throw new PinataError("An unknown error occurred while getting signed url");
|
|
2239
1132
|
}
|
|
2240
1133
|
};
|
|
2241
1134
|
|
|
@@ -2251,41 +1144,45 @@ var formatConfig = (config) => {
|
|
|
2251
1144
|
return config;
|
|
2252
1145
|
};
|
|
2253
1146
|
var PinataSDK = class {
|
|
1147
|
+
//signatures: Signatures;
|
|
2254
1148
|
constructor(config) {
|
|
2255
1149
|
this.config = formatConfig(config);
|
|
1150
|
+
this.files = new Files(this.config);
|
|
2256
1151
|
this.upload = new Upload(this.config);
|
|
2257
1152
|
this.gateways = new Gateways(this.config);
|
|
2258
|
-
this.usage = new Usage(this.config);
|
|
2259
1153
|
this.keys = new Keys(this.config);
|
|
2260
1154
|
this.groups = new Groups(this.config);
|
|
2261
|
-
this.signatures = new Signatures(this.config);
|
|
2262
1155
|
}
|
|
2263
1156
|
setNewHeaders(headers) {
|
|
2264
1157
|
if (!this.config) {
|
|
2265
1158
|
this.config = { pinataJwt: "", customHeaders: {} };
|
|
2266
1159
|
}
|
|
2267
1160
|
this.config.customHeaders = { ...this.config.customHeaders, ...headers };
|
|
1161
|
+
this.files.updateConfig(this.config);
|
|
2268
1162
|
this.upload.updateConfig(this.config);
|
|
2269
1163
|
this.gateways.updateConfig(this.config);
|
|
2270
|
-
this.usage.updateConfig(this.config);
|
|
2271
1164
|
this.keys.updateConfig(this.config);
|
|
2272
1165
|
this.groups.updateConfig(this.config);
|
|
2273
|
-
this.signatures.updateConfig(this.config);
|
|
2274
1166
|
}
|
|
2275
1167
|
testAuthentication() {
|
|
2276
1168
|
return testAuthentication(this.config);
|
|
2277
1169
|
}
|
|
2278
|
-
|
|
2279
|
-
|
|
1170
|
+
};
|
|
1171
|
+
var Files = class {
|
|
1172
|
+
constructor(config) {
|
|
1173
|
+
this.config = formatConfig(config);
|
|
1174
|
+
}
|
|
1175
|
+
updateConfig(newConfig) {
|
|
1176
|
+
this.config = newConfig;
|
|
2280
1177
|
}
|
|
2281
|
-
|
|
1178
|
+
list() {
|
|
2282
1179
|
return new FilterFiles(this.config);
|
|
2283
1180
|
}
|
|
2284
|
-
|
|
2285
|
-
return
|
|
1181
|
+
delete(files) {
|
|
1182
|
+
return deleteFile(this.config, files);
|
|
2286
1183
|
}
|
|
2287
|
-
|
|
2288
|
-
return
|
|
1184
|
+
update(options) {
|
|
1185
|
+
return updateFile(this.config, options);
|
|
2289
1186
|
}
|
|
2290
1187
|
};
|
|
2291
1188
|
var UploadBuilder = class {
|
|
@@ -2293,7 +1190,6 @@ var UploadBuilder = class {
|
|
|
2293
1190
|
this.config = config;
|
|
2294
1191
|
this.uploadFunction = uploadFunction;
|
|
2295
1192
|
this.args = args;
|
|
2296
|
-
this.version = 1;
|
|
2297
1193
|
}
|
|
2298
1194
|
addMetadata(metadata) {
|
|
2299
1195
|
this.metadata = metadata;
|
|
@@ -2303,18 +1199,14 @@ var UploadBuilder = class {
|
|
|
2303
1199
|
this.keys = jwt;
|
|
2304
1200
|
return this;
|
|
2305
1201
|
}
|
|
2306
|
-
cidVersion(v) {
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
}
|
|
1202
|
+
// cidVersion(v: 0 | 1): UploadBuilder<T> {
|
|
1203
|
+
// this.version = v;
|
|
1204
|
+
// return this;
|
|
1205
|
+
// }
|
|
2310
1206
|
group(groupId) {
|
|
2311
1207
|
this.groupId = groupId;
|
|
2312
1208
|
return this;
|
|
2313
1209
|
}
|
|
2314
|
-
peerAddress(peerAddresses) {
|
|
2315
|
-
this.peerAddresses = peerAddresses;
|
|
2316
|
-
return this;
|
|
2317
|
-
}
|
|
2318
1210
|
then(onfulfilled, onrejected) {
|
|
2319
1211
|
const options = this.args[this.args.length - 1] || {};
|
|
2320
1212
|
if (this.metadata) {
|
|
@@ -2326,12 +1218,6 @@ var UploadBuilder = class {
|
|
|
2326
1218
|
if (this.groupId) {
|
|
2327
1219
|
options.groupId = this.groupId;
|
|
2328
1220
|
}
|
|
2329
|
-
if (this.version) {
|
|
2330
|
-
options.cidVersion = this.version;
|
|
2331
|
-
}
|
|
2332
|
-
if (this.peerAddresses && "peerAddresses" in options) {
|
|
2333
|
-
options.peerAddresses = this.peerAddresses;
|
|
2334
|
-
}
|
|
2335
1221
|
this.args[this.args.length - 1] = options;
|
|
2336
1222
|
return this.uploadFunction(this.config, ...this.args).then(
|
|
2337
1223
|
onfulfilled,
|
|
@@ -2349,9 +1235,12 @@ var Upload = class {
|
|
|
2349
1235
|
file(file, options) {
|
|
2350
1236
|
return new UploadBuilder(this.config, uploadFile, file, options);
|
|
2351
1237
|
}
|
|
2352
|
-
fileArray(
|
|
2353
|
-
|
|
2354
|
-
|
|
1238
|
+
// fileArray(
|
|
1239
|
+
// files: FileObject[],
|
|
1240
|
+
// options?: UploadOptions,
|
|
1241
|
+
// ): UploadBuilder<UploadResponse> {
|
|
1242
|
+
// return new UploadBuilder(this.config, uploadFileArray, files, options);
|
|
1243
|
+
// }
|
|
2355
1244
|
base64(base64String, options) {
|
|
2356
1245
|
return new UploadBuilder(this.config, uploadBase64, base64String, options);
|
|
2357
1246
|
}
|
|
@@ -2361,97 +1250,58 @@ var Upload = class {
|
|
|
2361
1250
|
json(data, options) {
|
|
2362
1251
|
return new UploadBuilder(this.config, uploadJson, data, options);
|
|
2363
1252
|
}
|
|
2364
|
-
cid(cid, options) {
|
|
2365
|
-
return new UploadBuilder(this.config, uploadCid, cid, options);
|
|
2366
|
-
}
|
|
2367
1253
|
};
|
|
2368
1254
|
var FilterFiles = class {
|
|
1255
|
+
// rate limit vars
|
|
1256
|
+
// private requestCount = 0;
|
|
1257
|
+
// private lastRequestTime = 0;
|
|
1258
|
+
// private readonly MAX_REQUESTS_PER_MINUTE = 30;
|
|
1259
|
+
// private readonly MINUTE_IN_MS = 60000;
|
|
2369
1260
|
constructor(config) {
|
|
2370
1261
|
this.query = {};
|
|
2371
|
-
// rate limit vars
|
|
2372
|
-
this.requestCount = 0;
|
|
2373
|
-
this.lastRequestTime = 0;
|
|
2374
|
-
this.MAX_REQUESTS_PER_MINUTE = 30;
|
|
2375
|
-
this.MINUTE_IN_MS = 6e4;
|
|
2376
1262
|
this.config = config;
|
|
2377
1263
|
}
|
|
2378
|
-
|
|
2379
|
-
this.query.
|
|
2380
|
-
return this;
|
|
2381
|
-
}
|
|
2382
|
-
pinStart(date) {
|
|
2383
|
-
this.query.pinStart = date;
|
|
2384
|
-
return this;
|
|
2385
|
-
}
|
|
2386
|
-
pinEnd(date) {
|
|
2387
|
-
this.query.pinEnd = date;
|
|
2388
|
-
return this;
|
|
2389
|
-
}
|
|
2390
|
-
pinSizeMin(size) {
|
|
2391
|
-
this.query.pinSizeMin = size;
|
|
2392
|
-
return this;
|
|
2393
|
-
}
|
|
2394
|
-
pinSizeMax(size) {
|
|
2395
|
-
this.query.pinSizeMax = size;
|
|
2396
|
-
return this;
|
|
2397
|
-
}
|
|
2398
|
-
pageLimit(limit) {
|
|
2399
|
-
this.query.pageLimit = limit;
|
|
2400
|
-
return this;
|
|
2401
|
-
}
|
|
2402
|
-
pageOffset(offset) {
|
|
2403
|
-
this.query.pageOffset = offset;
|
|
2404
|
-
return this;
|
|
2405
|
-
}
|
|
2406
|
-
name(name) {
|
|
2407
|
-
this.query.name = name;
|
|
2408
|
-
return this;
|
|
2409
|
-
}
|
|
2410
|
-
group(groupId) {
|
|
2411
|
-
this.query.groupId = groupId;
|
|
1264
|
+
limit(limit) {
|
|
1265
|
+
this.query.limit = limit;
|
|
2412
1266
|
return this;
|
|
2413
1267
|
}
|
|
2414
|
-
|
|
2415
|
-
this.query.
|
|
2416
|
-
this.query.value = value;
|
|
2417
|
-
if (operator) {
|
|
2418
|
-
this.query.operator = operator;
|
|
2419
|
-
}
|
|
1268
|
+
cidPending(cidPending) {
|
|
1269
|
+
this.query.cidPending = cidPending;
|
|
2420
1270
|
return this;
|
|
2421
1271
|
}
|
|
2422
1272
|
then(onfulfilled) {
|
|
2423
|
-
return
|
|
2424
|
-
}
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
1273
|
+
return this.fetchPage().then(onfulfilled);
|
|
1274
|
+
}
|
|
1275
|
+
async fetchPage() {
|
|
1276
|
+
if (this.currentPageToken) {
|
|
1277
|
+
this.query.pageToken = this.currentPageToken;
|
|
1278
|
+
}
|
|
1279
|
+
const response = await listFiles(this.config, this.query);
|
|
1280
|
+
this.currentPageToken = response.next_page_token;
|
|
1281
|
+
return response.files;
|
|
1282
|
+
}
|
|
1283
|
+
// // rate limit, hopefully temporary?
|
|
1284
|
+
// private async rateLimit(): Promise<void> {
|
|
1285
|
+
// this.requestCount++;
|
|
1286
|
+
// const now = Date.now();
|
|
1287
|
+
// if (this.requestCount >= this.MAX_REQUESTS_PER_MINUTE) {
|
|
1288
|
+
// const timePassedSinceLastRequest = now - this.lastRequestTime;
|
|
1289
|
+
// if (timePassedSinceLastRequest < this.MINUTE_IN_MS) {
|
|
1290
|
+
// const delayTime = this.MINUTE_IN_MS - timePassedSinceLastRequest;
|
|
1291
|
+
// await new Promise((resolve) => setTimeout(resolve, delayTime));
|
|
1292
|
+
// }
|
|
1293
|
+
// this.requestCount = 0;
|
|
1294
|
+
// }
|
|
1295
|
+
// this.lastRequestTime = Date.now();
|
|
1296
|
+
// }
|
|
2439
1297
|
async *[Symbol.asyncIterator]() {
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
const limit = this.query.pageLimit || 10;
|
|
2443
|
-
while (hasMore) {
|
|
2444
|
-
await this.rateLimit();
|
|
2445
|
-
this.query.pageOffset = offset;
|
|
2446
|
-
this.query.pageLimit = limit;
|
|
2447
|
-
const items = await listFiles(this.config, this.query);
|
|
1298
|
+
while (true) {
|
|
1299
|
+
const items = await this.fetchPage();
|
|
2448
1300
|
for (const item of items) {
|
|
2449
1301
|
yield item;
|
|
2450
1302
|
}
|
|
2451
|
-
if (
|
|
2452
|
-
|
|
2453
|
-
} else {
|
|
2454
|
-
offset += items.length;
|
|
1303
|
+
if (!this.currentPageToken) {
|
|
1304
|
+
break;
|
|
2455
1305
|
}
|
|
2456
1306
|
}
|
|
2457
1307
|
}
|
|
@@ -2473,125 +1323,63 @@ var Gateways = class {
|
|
|
2473
1323
|
get(cid) {
|
|
2474
1324
|
return getCid(this.config, cid);
|
|
2475
1325
|
}
|
|
2476
|
-
|
|
2477
|
-
return
|
|
2478
|
-
}
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
}
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
}
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
}
|
|
2534
|
-
sort(sort) {
|
|
2535
|
-
this.query.sort = sort;
|
|
2536
|
-
return this;
|
|
2537
|
-
}
|
|
2538
|
-
then(onfulfilled) {
|
|
2539
|
-
return pinJobs(this.config, this.query).then(onfulfilled);
|
|
2540
|
-
}
|
|
2541
|
-
// rate limit, hopefully temporary?
|
|
2542
|
-
async rateLimit() {
|
|
2543
|
-
this.requestCount++;
|
|
2544
|
-
const now = Date.now();
|
|
2545
|
-
if (this.requestCount >= this.MAX_REQUESTS_PER_MINUTE) {
|
|
2546
|
-
const timePassedSinceLastRequest = now - this.lastRequestTime;
|
|
2547
|
-
if (timePassedSinceLastRequest < this.MINUTE_IN_MS) {
|
|
2548
|
-
const delayTime = this.MINUTE_IN_MS - timePassedSinceLastRequest;
|
|
2549
|
-
await new Promise((resolve) => setTimeout(resolve, delayTime));
|
|
2550
|
-
}
|
|
2551
|
-
this.requestCount = 0;
|
|
2552
|
-
}
|
|
2553
|
-
this.lastRequestTime = Date.now();
|
|
2554
|
-
}
|
|
2555
|
-
async *[Symbol.asyncIterator]() {
|
|
2556
|
-
let hasMore = true;
|
|
2557
|
-
let offset = 0;
|
|
2558
|
-
const limit = this.query.limit || 10;
|
|
2559
|
-
while (hasMore) {
|
|
2560
|
-
await this.rateLimit();
|
|
2561
|
-
this.query.offset = offset;
|
|
2562
|
-
this.query.limit = limit;
|
|
2563
|
-
const items = await pinJobs(this.config, this.query);
|
|
2564
|
-
for (const item of items) {
|
|
2565
|
-
yield item;
|
|
2566
|
-
}
|
|
2567
|
-
if (items.length === 0) {
|
|
2568
|
-
hasMore = false;
|
|
2569
|
-
} else {
|
|
2570
|
-
offset += items.length;
|
|
2571
|
-
}
|
|
2572
|
-
}
|
|
2573
|
-
}
|
|
2574
|
-
async all() {
|
|
2575
|
-
const allItems = [];
|
|
2576
|
-
for await (const item of this) {
|
|
2577
|
-
allItems.push(item);
|
|
2578
|
-
}
|
|
2579
|
-
return allItems;
|
|
2580
|
-
}
|
|
2581
|
-
};
|
|
2582
|
-
var Usage = class {
|
|
2583
|
-
constructor(config) {
|
|
2584
|
-
this.config = formatConfig(config);
|
|
2585
|
-
}
|
|
2586
|
-
updateConfig(newConfig) {
|
|
2587
|
-
this.config = newConfig;
|
|
2588
|
-
}
|
|
2589
|
-
pinnedFileCount() {
|
|
2590
|
-
return pinnedFileCount(this.config);
|
|
2591
|
-
}
|
|
2592
|
-
totalStorageSize() {
|
|
2593
|
-
return totalStorageUsage(this.config);
|
|
2594
|
-
}
|
|
1326
|
+
createSignedURL(options) {
|
|
1327
|
+
return createSignedURL(this.config, options);
|
|
1328
|
+
}
|
|
1329
|
+
// get(cid: string): OptimizeImage {
|
|
1330
|
+
// return new OptimizeImage(this.config, cid);
|
|
1331
|
+
// }
|
|
1332
|
+
// convert(url: string, gatewayPrefix?: string): Promise<string> {
|
|
1333
|
+
// return convertIPFSUrl(this.config, url, gatewayPrefix);
|
|
1334
|
+
// }
|
|
1335
|
+
// containsCID(cid: string): Promise<ContainsCIDResponse> {
|
|
1336
|
+
// return containsCID(cid);
|
|
1337
|
+
// }
|
|
1338
|
+
// topUsageAnalytics(options: {
|
|
1339
|
+
// domain: string;
|
|
1340
|
+
// start: string;
|
|
1341
|
+
// end: string;
|
|
1342
|
+
// sortBy: "requests" | "bandwidth";
|
|
1343
|
+
// attribute:
|
|
1344
|
+
// | "cid"
|
|
1345
|
+
// | "country"
|
|
1346
|
+
// | "region"
|
|
1347
|
+
// | "user_agent"
|
|
1348
|
+
// | "referer"
|
|
1349
|
+
// | "file_name";
|
|
1350
|
+
// }): TopGatewayAnalyticsBuilder {
|
|
1351
|
+
// return new TopGatewayAnalyticsBuilder(
|
|
1352
|
+
// this.config,
|
|
1353
|
+
// options.domain,
|
|
1354
|
+
// options.start,
|
|
1355
|
+
// options.end,
|
|
1356
|
+
// options.sortBy,
|
|
1357
|
+
// options.attribute,
|
|
1358
|
+
// );
|
|
1359
|
+
// }
|
|
1360
|
+
// dateIntervalAnalytics(options: {
|
|
1361
|
+
// domain: string;
|
|
1362
|
+
// start: string;
|
|
1363
|
+
// end: string;
|
|
1364
|
+
// interval: "day" | "week";
|
|
1365
|
+
// }): TimeIntervalGatewayAnalyticsBuilder {
|
|
1366
|
+
// return new TimeIntervalGatewayAnalyticsBuilder(
|
|
1367
|
+
// this.config,
|
|
1368
|
+
// options.domain,
|
|
1369
|
+
// options.start,
|
|
1370
|
+
// options.end,
|
|
1371
|
+
// options.interval,
|
|
1372
|
+
// );
|
|
1373
|
+
// }
|
|
1374
|
+
// swapCid(options: SwapCidOptions): Promise<SwapCidResponse> {
|
|
1375
|
+
// return swapCid(this.config, options);
|
|
1376
|
+
// }
|
|
1377
|
+
// swapHistory(options: SwapHistoryOptions): Promise<SwapCidResponse[]> {
|
|
1378
|
+
// return swapHistory(this.config, options);
|
|
1379
|
+
// }
|
|
1380
|
+
// deleteSwap(cid: string): Promise<string> {
|
|
1381
|
+
// return deleteSwap(this.config, cid);
|
|
1382
|
+
// }
|
|
2595
1383
|
};
|
|
2596
1384
|
var Keys = class {
|
|
2597
1385
|
constructor(config) {
|
|
@@ -2611,13 +1399,13 @@ var Keys = class {
|
|
|
2611
1399
|
}
|
|
2612
1400
|
};
|
|
2613
1401
|
var FilterKeys = class {
|
|
1402
|
+
// rate limit vars
|
|
1403
|
+
// private requestCount = 0;
|
|
1404
|
+
// private lastRequestTime = 0;
|
|
1405
|
+
// private readonly MAX_REQUESTS_PER_MINUTE = 30;
|
|
1406
|
+
// private readonly MINUTE_IN_MS = 60000;
|
|
2614
1407
|
constructor(config) {
|
|
2615
1408
|
this.query = {};
|
|
2616
|
-
// rate limit vars
|
|
2617
|
-
this.requestCount = 0;
|
|
2618
|
-
this.lastRequestTime = 0;
|
|
2619
|
-
this.MAX_REQUESTS_PER_MINUTE = 30;
|
|
2620
|
-
this.MINUTE_IN_MS = 6e4;
|
|
2621
1409
|
this.config = config;
|
|
2622
1410
|
}
|
|
2623
1411
|
offset(offset) {
|
|
@@ -2643,25 +1431,23 @@ var FilterKeys = class {
|
|
|
2643
1431
|
then(onfulfilled) {
|
|
2644
1432
|
return listKeys(this.config, this.query).then(onfulfilled);
|
|
2645
1433
|
}
|
|
2646
|
-
//
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
}
|
|
1434
|
+
// private async rateLimit(): Promise<void> {
|
|
1435
|
+
// this.requestCount++;
|
|
1436
|
+
// const now = Date.now();
|
|
1437
|
+
// if (this.requestCount >= this.MAX_REQUESTS_PER_MINUTE) {
|
|
1438
|
+
// const timePassedSinceLastRequest = now - this.lastRequestTime;
|
|
1439
|
+
// if (timePassedSinceLastRequest < this.MINUTE_IN_MS) {
|
|
1440
|
+
// const delayTime = this.MINUTE_IN_MS - timePassedSinceLastRequest;
|
|
1441
|
+
// await new Promise((resolve) => setTimeout(resolve, delayTime));
|
|
1442
|
+
// }
|
|
1443
|
+
// this.requestCount = 0;
|
|
1444
|
+
// }
|
|
1445
|
+
// this.lastRequestTime = Date.now();
|
|
1446
|
+
// }
|
|
2660
1447
|
async *[Symbol.asyncIterator]() {
|
|
2661
1448
|
let hasMore = true;
|
|
2662
1449
|
let offset = 0;
|
|
2663
1450
|
while (hasMore) {
|
|
2664
|
-
await this.rateLimit();
|
|
2665
1451
|
this.query.offset = offset;
|
|
2666
1452
|
const items = await listKeys(this.config, this.query);
|
|
2667
1453
|
for (const item of items) {
|
|
@@ -2698,12 +1484,12 @@ var Groups = class {
|
|
|
2698
1484
|
get(options) {
|
|
2699
1485
|
return getGroup(this.config, options);
|
|
2700
1486
|
}
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
}
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
}
|
|
1487
|
+
// addFiles(options: GroupCIDOptions): Promise<string> {
|
|
1488
|
+
// return addToGroup(this.config, options);
|
|
1489
|
+
// }
|
|
1490
|
+
// removeFiles(options: GroupCIDOptions): Promise<string> {
|
|
1491
|
+
// return removeFromGroup(this.config, options);
|
|
1492
|
+
// }
|
|
2707
1493
|
update(options) {
|
|
2708
1494
|
return updateGroup(this.config, options);
|
|
2709
1495
|
}
|
|
@@ -2714,57 +1500,56 @@ var Groups = class {
|
|
|
2714
1500
|
var FilterGroups = class {
|
|
2715
1501
|
constructor(config) {
|
|
2716
1502
|
this.query = {};
|
|
2717
|
-
// rate limit vars
|
|
2718
|
-
this.requestCount = 0;
|
|
2719
|
-
this.lastRequestTime = 0;
|
|
2720
|
-
this.MAX_REQUESTS_PER_MINUTE = 30;
|
|
2721
|
-
this.MINUTE_IN_MS = 6e4;
|
|
2722
1503
|
this.config = config;
|
|
2723
1504
|
}
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
}
|
|
2728
|
-
name(nameContains) {
|
|
2729
|
-
this.query.nameContains = nameContains;
|
|
2730
|
-
return this;
|
|
2731
|
-
}
|
|
1505
|
+
// name(nameContains: string): FilterGroups {
|
|
1506
|
+
// this.query.nameContains = nameContains;
|
|
1507
|
+
// return this;
|
|
1508
|
+
// }
|
|
2732
1509
|
limit(limit) {
|
|
2733
1510
|
this.query.limit = limit;
|
|
2734
1511
|
return this;
|
|
2735
1512
|
}
|
|
1513
|
+
isPublic(isPublic) {
|
|
1514
|
+
this.query.isPublic = isPublic;
|
|
1515
|
+
return this;
|
|
1516
|
+
}
|
|
2736
1517
|
then(onfulfilled) {
|
|
2737
|
-
return
|
|
1518
|
+
return this.fetchPage().then((response) => {
|
|
1519
|
+
this.nextPageToken = response.next_page_token;
|
|
1520
|
+
return response.groups;
|
|
1521
|
+
}).then(onfulfilled);
|
|
2738
1522
|
}
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
const now = Date.now();
|
|
2743
|
-
if (this.requestCount >= this.MAX_REQUESTS_PER_MINUTE) {
|
|
2744
|
-
const timePassedSinceLastRequest = now - this.lastRequestTime;
|
|
2745
|
-
if (timePassedSinceLastRequest < this.MINUTE_IN_MS) {
|
|
2746
|
-
const delayTime = this.MINUTE_IN_MS - timePassedSinceLastRequest;
|
|
2747
|
-
await new Promise((resolve) => setTimeout(resolve, delayTime));
|
|
2748
|
-
}
|
|
2749
|
-
this.requestCount = 0;
|
|
1523
|
+
async fetchPage() {
|
|
1524
|
+
if (this.nextPageToken) {
|
|
1525
|
+
this.query.pageToken = this.nextPageToken;
|
|
2750
1526
|
}
|
|
2751
|
-
this.
|
|
1527
|
+
return listGroups(this.config, this.query);
|
|
2752
1528
|
}
|
|
1529
|
+
// rate limit, hopefully temporary?
|
|
1530
|
+
// private async rateLimit(): Promise<void> {
|
|
1531
|
+
// this.requestCount++;
|
|
1532
|
+
// const now = Date.now();
|
|
1533
|
+
// if (this.requestCount >= this.MAX_REQUESTS_PER_MINUTE) {
|
|
1534
|
+
// const timePassedSinceLastRequest = now - this.lastRequestTime;
|
|
1535
|
+
// if (timePassedSinceLastRequest < this.MINUTE_IN_MS) {
|
|
1536
|
+
// const delayTime = this.MINUTE_IN_MS - timePassedSinceLastRequest;
|
|
1537
|
+
// await new Promise((resolve) => setTimeout(resolve, delayTime));
|
|
1538
|
+
// }
|
|
1539
|
+
// this.requestCount = 0;
|
|
1540
|
+
// }
|
|
1541
|
+
// this.lastRequestTime = Date.now();
|
|
1542
|
+
// }
|
|
2753
1543
|
async *[Symbol.asyncIterator]() {
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
await this.rateLimit();
|
|
2758
|
-
this.query.offset = offset;
|
|
2759
|
-
const items = await listGroups(this.config, this.query);
|
|
2760
|
-
for (const item of items) {
|
|
1544
|
+
while (true) {
|
|
1545
|
+
const response = await this.fetchPage();
|
|
1546
|
+
for (const item of response.groups) {
|
|
2761
1547
|
yield item;
|
|
2762
1548
|
}
|
|
2763
|
-
if (
|
|
2764
|
-
|
|
2765
|
-
} else {
|
|
2766
|
-
offset += items.length;
|
|
1549
|
+
if (!response.next_page_token) {
|
|
1550
|
+
break;
|
|
2767
1551
|
}
|
|
1552
|
+
this.nextPageToken = response.next_page_token;
|
|
2768
1553
|
}
|
|
2769
1554
|
}
|
|
2770
1555
|
async all() {
|
|
@@ -2775,122 +1560,6 @@ var FilterGroups = class {
|
|
|
2775
1560
|
return allItems;
|
|
2776
1561
|
}
|
|
2777
1562
|
};
|
|
2778
|
-
var Signatures = class {
|
|
2779
|
-
constructor(config) {
|
|
2780
|
-
this.config = formatConfig(config);
|
|
2781
|
-
}
|
|
2782
|
-
updateConfig(newConfig) {
|
|
2783
|
-
this.config = newConfig;
|
|
2784
|
-
}
|
|
2785
|
-
add(options) {
|
|
2786
|
-
return addSignature(this.config, options);
|
|
2787
|
-
}
|
|
2788
|
-
get(cid) {
|
|
2789
|
-
return getSignature(this.config, cid);
|
|
2790
|
-
}
|
|
2791
|
-
delete(cid) {
|
|
2792
|
-
return removeSignature(this.config, cid);
|
|
2793
|
-
}
|
|
2794
|
-
};
|
|
2795
|
-
var GatewayAnalyticsBuilder = class {
|
|
2796
|
-
constructor(config, query) {
|
|
2797
|
-
this.requestCount = 0;
|
|
2798
|
-
this.lastRequestTime = 0;
|
|
2799
|
-
this.MAX_REQUESTS_PER_MINUTE = 30;
|
|
2800
|
-
this.MINUTE_IN_MS = 6e4;
|
|
2801
|
-
this.config = config;
|
|
2802
|
-
this.query = query;
|
|
2803
|
-
}
|
|
2804
|
-
cid(cid) {
|
|
2805
|
-
this.query.cid = cid;
|
|
2806
|
-
return this;
|
|
2807
|
-
}
|
|
2808
|
-
fileName(fileName) {
|
|
2809
|
-
this.query.file_name = fileName;
|
|
2810
|
-
return this;
|
|
2811
|
-
}
|
|
2812
|
-
userAgent(userAgent) {
|
|
2813
|
-
this.query.user_agent = userAgent;
|
|
2814
|
-
return this;
|
|
2815
|
-
}
|
|
2816
|
-
country(country) {
|
|
2817
|
-
this.query.country = country;
|
|
2818
|
-
return this;
|
|
2819
|
-
}
|
|
2820
|
-
region(region) {
|
|
2821
|
-
this.query.region = region;
|
|
2822
|
-
return this;
|
|
2823
|
-
}
|
|
2824
|
-
referer(referer) {
|
|
2825
|
-
this.query.referer = referer;
|
|
2826
|
-
return this;
|
|
2827
|
-
}
|
|
2828
|
-
limit(limit) {
|
|
2829
|
-
this.query.limit = limit;
|
|
2830
|
-
return this;
|
|
2831
|
-
}
|
|
2832
|
-
sort(order) {
|
|
2833
|
-
this.query.sort_order = order;
|
|
2834
|
-
return this;
|
|
2835
|
-
}
|
|
2836
|
-
async rateLimit() {
|
|
2837
|
-
this.requestCount++;
|
|
2838
|
-
const now = Date.now();
|
|
2839
|
-
if (this.requestCount >= this.MAX_REQUESTS_PER_MINUTE) {
|
|
2840
|
-
const timePassedSinceLastRequest = now - this.lastRequestTime;
|
|
2841
|
-
if (timePassedSinceLastRequest < this.MINUTE_IN_MS) {
|
|
2842
|
-
const delayTime = this.MINUTE_IN_MS - timePassedSinceLastRequest;
|
|
2843
|
-
await new Promise((resolve) => setTimeout(resolve, delayTime));
|
|
2844
|
-
}
|
|
2845
|
-
this.requestCount = 0;
|
|
2846
|
-
}
|
|
2847
|
-
this.lastRequestTime = Date.now();
|
|
2848
|
-
}
|
|
2849
|
-
async getAnalytics() {
|
|
2850
|
-
await this.rateLimit();
|
|
2851
|
-
throw new Error("getAnalytics method must be implemented in derived class");
|
|
2852
|
-
}
|
|
2853
|
-
then(onfulfilled) {
|
|
2854
|
-
return this.getAnalytics().then(onfulfilled);
|
|
2855
|
-
}
|
|
2856
|
-
};
|
|
2857
|
-
var TopGatewayAnalyticsBuilder = class extends GatewayAnalyticsBuilder {
|
|
2858
|
-
constructor(config, domain, start, end, sortBy, attribute) {
|
|
2859
|
-
super(config, {
|
|
2860
|
-
gateway_domain: domain,
|
|
2861
|
-
start_date: start,
|
|
2862
|
-
end_date: end,
|
|
2863
|
-
sort_by: sortBy,
|
|
2864
|
-
attribute
|
|
2865
|
-
});
|
|
2866
|
-
}
|
|
2867
|
-
async getAnalytics() {
|
|
2868
|
-
return analyticsTopUsage(this.config, this.query);
|
|
2869
|
-
}
|
|
2870
|
-
async all() {
|
|
2871
|
-
return this.getAnalytics();
|
|
2872
|
-
}
|
|
2873
|
-
};
|
|
2874
|
-
var TimeIntervalGatewayAnalyticsBuilder = class extends GatewayAnalyticsBuilder {
|
|
2875
|
-
constructor(config, domain, start, end, dateInterval) {
|
|
2876
|
-
super(config, {
|
|
2877
|
-
gateway_domain: domain,
|
|
2878
|
-
start_date: start,
|
|
2879
|
-
end_date: end,
|
|
2880
|
-
date_interval: dateInterval
|
|
2881
|
-
});
|
|
2882
|
-
}
|
|
2883
|
-
sortBy(sortBy) {
|
|
2884
|
-
this.query.sort_by = sortBy;
|
|
2885
|
-
return this;
|
|
2886
|
-
}
|
|
2887
|
-
async getAnalytics() {
|
|
2888
|
-
return analyticsDateInterval(this.config, this.query);
|
|
2889
|
-
}
|
|
2890
|
-
async all() {
|
|
2891
|
-
return this.getAnalytics();
|
|
2892
|
-
}
|
|
2893
|
-
};
|
|
2894
1563
|
export {
|
|
2895
1564
|
PinataSDK
|
|
2896
1565
|
};
|