pinata 0.4.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -7
- package/dist/index.d.mts +64 -200
- package/dist/index.d.ts +64 -200
- package/dist/index.js +400 -1788
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +400 -1778
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -4
- package/postinstall.ts +82 -0
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,157 +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
|
-
var getCid = async (config, cid
|
|
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
|
-
newUrl = await convertToDesiredGateway(cid, config?.pinataGateway);
|
|
535
|
+
let newUrl = `${config?.pinataGateway}/files/${cid}`;
|
|
839
536
|
const params = new URLSearchParams();
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
params.append("img-anim", options.animation.toString());
|
|
860
|
-
if (options.sharpen)
|
|
861
|
-
params.append("img-sharpen", options.sharpen.toString());
|
|
862
|
-
if (options.onError === true)
|
|
863
|
-
params.append("img-onerror", "redirect");
|
|
864
|
-
if (options.metadata)
|
|
865
|
-
params.append("img-metadata", options.metadata);
|
|
866
|
-
}
|
|
867
|
-
const queryString = params.toString();
|
|
868
|
-
if (queryString) {
|
|
869
|
-
newUrl += `?${queryString}`;
|
|
870
|
-
}
|
|
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();
|
|
871
556
|
try {
|
|
872
|
-
const request = await fetch(
|
|
557
|
+
const request = await fetch(signedUrl.data);
|
|
873
558
|
if (!request.ok) {
|
|
874
559
|
const errorData = await request.text();
|
|
875
560
|
if (request.status === 401 || request.status === 403) {
|
|
@@ -911,56 +596,31 @@ var getCid = async (config, cid, options) => {
|
|
|
911
596
|
}
|
|
912
597
|
};
|
|
913
598
|
|
|
914
|
-
// src/core/
|
|
915
|
-
var
|
|
916
|
-
let newUrl;
|
|
917
|
-
let prefix = gatewayPrefix || config?.pinataGateway || "https://gateway.pinata.cloud";
|
|
918
|
-
newUrl = await convertToDesiredGateway(url, prefix);
|
|
919
|
-
if (config?.pinataGatewayKey) {
|
|
920
|
-
`${newUrl}?pinataGatewayToken=${config?.pinataGatewayKey}`;
|
|
921
|
-
}
|
|
922
|
-
return newUrl;
|
|
923
|
-
};
|
|
924
|
-
|
|
925
|
-
// src/core/data/pinJobs.ts
|
|
926
|
-
var pinJobs = async (config, options) => {
|
|
599
|
+
// src/core/keys/createKey.ts
|
|
600
|
+
var createKey = async (config, options) => {
|
|
927
601
|
if (!config) {
|
|
928
602
|
throw new ValidationError("Pinata configuration is missing");
|
|
929
603
|
}
|
|
930
|
-
const params = new URLSearchParams({
|
|
931
|
-
includesCount: "false"
|
|
932
|
-
});
|
|
933
|
-
if (options) {
|
|
934
|
-
const { ipfs_pin_hash: cid, status, sort, limit, offset } = options;
|
|
935
|
-
if (cid)
|
|
936
|
-
params.append("ipfs_pin_hash", cid.toString());
|
|
937
|
-
if (status)
|
|
938
|
-
params.append("status", status.toString());
|
|
939
|
-
if (sort)
|
|
940
|
-
params.append("sort", sort.toString());
|
|
941
|
-
if (limit)
|
|
942
|
-
params.append("limit", limit.toString());
|
|
943
|
-
if (offset)
|
|
944
|
-
params.append("offset", offset.toString());
|
|
945
|
-
}
|
|
946
|
-
let endpoint = "https://api.pinata.cloud";
|
|
947
|
-
if (config.endpointUrl) {
|
|
948
|
-
endpoint = config.endpointUrl;
|
|
949
|
-
}
|
|
950
|
-
const url = `${endpoint}/pinning/pinJobs?${params.toString()}`;
|
|
951
604
|
let headers;
|
|
952
605
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
953
606
|
headers = { ...config.customHeaders };
|
|
954
607
|
} else {
|
|
955
608
|
headers = {
|
|
956
609
|
Authorization: `Bearer ${config.pinataJwt}`,
|
|
957
|
-
|
|
610
|
+
"Content-Type": "application/json",
|
|
611
|
+
Source: "sdk/createKey"
|
|
958
612
|
};
|
|
959
613
|
}
|
|
614
|
+
const data = JSON.stringify(options);
|
|
615
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
616
|
+
if (config.endpointUrl) {
|
|
617
|
+
endpoint = config.endpointUrl;
|
|
618
|
+
}
|
|
960
619
|
try {
|
|
961
|
-
const request = await fetch(
|
|
962
|
-
method: "
|
|
963
|
-
headers
|
|
620
|
+
const request = await fetch(`${endpoint}/pinata/keys`, {
|
|
621
|
+
method: "POST",
|
|
622
|
+
headers,
|
|
623
|
+
body: data
|
|
964
624
|
});
|
|
965
625
|
if (!request.ok) {
|
|
966
626
|
const errorData = await request.text();
|
|
@@ -978,41 +638,59 @@ var pinJobs = async (config, options) => {
|
|
|
978
638
|
);
|
|
979
639
|
}
|
|
980
640
|
const res = await request.json();
|
|
981
|
-
return res
|
|
641
|
+
return res;
|
|
982
642
|
} catch (error) {
|
|
983
643
|
if (error instanceof PinataError) {
|
|
984
644
|
throw error;
|
|
985
645
|
}
|
|
986
646
|
if (error instanceof Error) {
|
|
987
|
-
throw new PinataError(`Error processing
|
|
647
|
+
throw new PinataError(`Error processing createKey: ${error.message}`);
|
|
988
648
|
}
|
|
989
|
-
throw new PinataError("An unknown error occurred while
|
|
649
|
+
throw new PinataError("An unknown error occurred while creating API key");
|
|
990
650
|
}
|
|
991
651
|
};
|
|
992
652
|
|
|
993
|
-
// src/core/
|
|
994
|
-
var
|
|
653
|
+
// src/core/keys/listKeys.ts
|
|
654
|
+
var listKeys = async (config, options) => {
|
|
995
655
|
if (!config) {
|
|
996
656
|
throw new ValidationError("Pinata configuration is missing");
|
|
997
657
|
}
|
|
998
|
-
let endpoint = "https://api.pinata.cloud";
|
|
999
|
-
if (config.endpointUrl) {
|
|
1000
|
-
endpoint = config.endpointUrl;
|
|
1001
|
-
}
|
|
1002
658
|
let headers;
|
|
1003
659
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1004
660
|
headers = { ...config.customHeaders };
|
|
1005
661
|
} else {
|
|
1006
662
|
headers = {
|
|
1007
663
|
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1008
|
-
|
|
664
|
+
"Content-Type": "application/json",
|
|
665
|
+
Source: "sdk/listKeys"
|
|
1009
666
|
};
|
|
1010
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
|
+
}
|
|
1011
686
|
try {
|
|
1012
|
-
const request = await fetch(
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
687
|
+
const request = await fetch(
|
|
688
|
+
`${endpoint}/pinata/keys?${params.toString()}`,
|
|
689
|
+
{
|
|
690
|
+
method: "GET",
|
|
691
|
+
headers
|
|
692
|
+
}
|
|
693
|
+
);
|
|
1016
694
|
if (!request.ok) {
|
|
1017
695
|
const errorData = await request.text();
|
|
1018
696
|
if (request.status === 401 || request.status === 403) {
|
|
@@ -1029,207 +707,25 @@ var pinnedFileCount = async (config) => {
|
|
|
1029
707
|
);
|
|
1030
708
|
}
|
|
1031
709
|
const res = await request.json();
|
|
1032
|
-
return res.
|
|
710
|
+
return res.keys;
|
|
1033
711
|
} catch (error) {
|
|
1034
712
|
if (error instanceof PinataError) {
|
|
1035
713
|
throw error;
|
|
1036
714
|
}
|
|
1037
715
|
if (error instanceof Error) {
|
|
1038
|
-
throw new PinataError(
|
|
1039
|
-
`Error processing pinnedFileUsage: ${error.message}`
|
|
1040
|
-
);
|
|
716
|
+
throw new PinataError(`Error processing listKeys: ${error.message}`);
|
|
1041
717
|
}
|
|
1042
|
-
throw new PinataError(
|
|
1043
|
-
"An unknown error occurred while getting pinned file usage"
|
|
1044
|
-
);
|
|
718
|
+
throw new PinataError("An unknown error occurred while listing API keys");
|
|
1045
719
|
}
|
|
1046
720
|
};
|
|
1047
721
|
|
|
1048
|
-
// src/core/
|
|
1049
|
-
var
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
}
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
endpoint = config.endpointUrl;
|
|
1056
|
-
}
|
|
1057
|
-
let headers;
|
|
1058
|
-
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1059
|
-
headers = { ...config.customHeaders };
|
|
1060
|
-
} else {
|
|
1061
|
-
headers = {
|
|
1062
|
-
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1063
|
-
Source: "sdk/totalStorageUsage"
|
|
1064
|
-
};
|
|
1065
|
-
}
|
|
1066
|
-
try {
|
|
1067
|
-
const request = await fetch(`${endpoint}/data/userPinnedDataTotal`, {
|
|
1068
|
-
method: "GET",
|
|
1069
|
-
headers
|
|
1070
|
-
});
|
|
1071
|
-
if (!request.ok) {
|
|
1072
|
-
const errorData = await request.text();
|
|
1073
|
-
if (request.status === 401 || request.status === 403) {
|
|
1074
|
-
throw new AuthenticationError(
|
|
1075
|
-
`Authentication failed: ${errorData}`,
|
|
1076
|
-
request.status,
|
|
1077
|
-
errorData
|
|
1078
|
-
);
|
|
1079
|
-
}
|
|
1080
|
-
throw new NetworkError(
|
|
1081
|
-
`HTTP error: ${errorData}`,
|
|
1082
|
-
request.status,
|
|
1083
|
-
errorData
|
|
1084
|
-
);
|
|
1085
|
-
}
|
|
1086
|
-
const res = await request.json();
|
|
1087
|
-
return res.pin_size_total;
|
|
1088
|
-
} catch (error) {
|
|
1089
|
-
if (error instanceof PinataError) {
|
|
1090
|
-
throw error;
|
|
1091
|
-
}
|
|
1092
|
-
if (error instanceof Error) {
|
|
1093
|
-
throw new PinataError(
|
|
1094
|
-
`Error processing totalStorageUsage: ${error.message}`
|
|
1095
|
-
);
|
|
1096
|
-
}
|
|
1097
|
-
throw new PinataError(
|
|
1098
|
-
"An unknown error occurred while getting total storage usage"
|
|
1099
|
-
);
|
|
1100
|
-
}
|
|
1101
|
-
};
|
|
1102
|
-
|
|
1103
|
-
// src/core/keys/createKey.ts
|
|
1104
|
-
var createKey = async (config, options) => {
|
|
1105
|
-
if (!config) {
|
|
1106
|
-
throw new ValidationError("Pinata configuration is missing");
|
|
1107
|
-
}
|
|
1108
|
-
let headers;
|
|
1109
|
-
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1110
|
-
headers = { ...config.customHeaders };
|
|
1111
|
-
} else {
|
|
1112
|
-
headers = {
|
|
1113
|
-
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1114
|
-
"Content-Type": "application/json",
|
|
1115
|
-
Source: "sdk/createKey"
|
|
1116
|
-
};
|
|
1117
|
-
}
|
|
1118
|
-
const data = JSON.stringify(options);
|
|
1119
|
-
let endpoint = "https://api.pinata.cloud";
|
|
1120
|
-
if (config.endpointUrl) {
|
|
1121
|
-
endpoint = config.endpointUrl;
|
|
1122
|
-
}
|
|
1123
|
-
try {
|
|
1124
|
-
const request = await fetch(`${endpoint}/v3/pinata/keys`, {
|
|
1125
|
-
method: "POST",
|
|
1126
|
-
headers,
|
|
1127
|
-
body: data
|
|
1128
|
-
});
|
|
1129
|
-
if (!request.ok) {
|
|
1130
|
-
const errorData = await request.text();
|
|
1131
|
-
if (request.status === 401 || request.status === 403) {
|
|
1132
|
-
throw new AuthenticationError(
|
|
1133
|
-
`Authentication failed: ${errorData}`,
|
|
1134
|
-
request.status,
|
|
1135
|
-
errorData
|
|
1136
|
-
);
|
|
1137
|
-
}
|
|
1138
|
-
throw new NetworkError(
|
|
1139
|
-
`HTTP error: ${errorData}`,
|
|
1140
|
-
request.status,
|
|
1141
|
-
errorData
|
|
1142
|
-
);
|
|
1143
|
-
}
|
|
1144
|
-
const res = await request.json();
|
|
1145
|
-
return res;
|
|
1146
|
-
} catch (error) {
|
|
1147
|
-
if (error instanceof PinataError) {
|
|
1148
|
-
throw error;
|
|
1149
|
-
}
|
|
1150
|
-
if (error instanceof Error) {
|
|
1151
|
-
throw new PinataError(`Error processing createKey: ${error.message}`);
|
|
1152
|
-
}
|
|
1153
|
-
throw new PinataError("An unknown error occurred while creating API key");
|
|
1154
|
-
}
|
|
1155
|
-
};
|
|
1156
|
-
|
|
1157
|
-
// src/core/keys/listKeys.ts
|
|
1158
|
-
var listKeys = async (config, options) => {
|
|
1159
|
-
if (!config) {
|
|
1160
|
-
throw new ValidationError("Pinata configuration is missing");
|
|
1161
|
-
}
|
|
1162
|
-
let headers;
|
|
1163
|
-
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1164
|
-
headers = { ...config.customHeaders };
|
|
1165
|
-
} else {
|
|
1166
|
-
headers = {
|
|
1167
|
-
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1168
|
-
"Content-Type": "application/json",
|
|
1169
|
-
Source: "sdk/listKeys"
|
|
1170
|
-
};
|
|
1171
|
-
}
|
|
1172
|
-
const params = new URLSearchParams();
|
|
1173
|
-
if (options) {
|
|
1174
|
-
const { offset, name, revoked, limitedUse, exhausted } = options;
|
|
1175
|
-
if (offset)
|
|
1176
|
-
params.append("offset", offset.toString());
|
|
1177
|
-
if (revoked !== void 0)
|
|
1178
|
-
params.append("revoked", revoked.toString());
|
|
1179
|
-
if (limitedUse !== void 0)
|
|
1180
|
-
params.append("limitedUse", limitedUse.toString());
|
|
1181
|
-
if (exhausted !== void 0)
|
|
1182
|
-
params.append("exhausted", exhausted.toString());
|
|
1183
|
-
if (name)
|
|
1184
|
-
params.append("name", name);
|
|
1185
|
-
}
|
|
1186
|
-
let endpoint = "https://api.pinata.cloud";
|
|
1187
|
-
if (config.endpointUrl) {
|
|
1188
|
-
endpoint = config.endpointUrl;
|
|
1189
|
-
}
|
|
1190
|
-
try {
|
|
1191
|
-
const request = await fetch(
|
|
1192
|
-
`${endpoint}/v3/pinata/keys?${params.toString()}`,
|
|
1193
|
-
{
|
|
1194
|
-
method: "GET",
|
|
1195
|
-
headers
|
|
1196
|
-
}
|
|
1197
|
-
);
|
|
1198
|
-
if (!request.ok) {
|
|
1199
|
-
const errorData = await request.text();
|
|
1200
|
-
if (request.status === 401 || request.status === 403) {
|
|
1201
|
-
throw new AuthenticationError(
|
|
1202
|
-
`Authentication failed: ${errorData}`,
|
|
1203
|
-
request.status,
|
|
1204
|
-
errorData
|
|
1205
|
-
);
|
|
1206
|
-
}
|
|
1207
|
-
throw new NetworkError(
|
|
1208
|
-
`HTTP error: ${errorData}`,
|
|
1209
|
-
request.status,
|
|
1210
|
-
errorData
|
|
1211
|
-
);
|
|
1212
|
-
}
|
|
1213
|
-
const res = await request.json();
|
|
1214
|
-
return res.keys;
|
|
1215
|
-
} catch (error) {
|
|
1216
|
-
if (error instanceof PinataError) {
|
|
1217
|
-
throw error;
|
|
1218
|
-
}
|
|
1219
|
-
if (error instanceof Error) {
|
|
1220
|
-
throw new PinataError(`Error processing listKeys: ${error.message}`);
|
|
1221
|
-
}
|
|
1222
|
-
throw new PinataError("An unknown error occurred while listing API keys");
|
|
1223
|
-
}
|
|
1224
|
-
};
|
|
1225
|
-
|
|
1226
|
-
// src/core/keys/revokeKeys.ts
|
|
1227
|
-
var wait2 = (milliseconds) => {
|
|
1228
|
-
return new Promise((resolve) => {
|
|
1229
|
-
setTimeout(resolve, milliseconds);
|
|
1230
|
-
});
|
|
1231
|
-
};
|
|
1232
|
-
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) => {
|
|
1233
729
|
if (!config) {
|
|
1234
730
|
throw new ValidationError("Pinata configuration is missing");
|
|
1235
731
|
}
|
|
@@ -1244,13 +740,13 @@ var revokeKeys = async (config, keys) => {
|
|
|
1244
740
|
};
|
|
1245
741
|
}
|
|
1246
742
|
const responses = [];
|
|
1247
|
-
let endpoint = "https://api.pinata.cloud";
|
|
743
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
1248
744
|
if (config.endpointUrl) {
|
|
1249
745
|
endpoint = config.endpointUrl;
|
|
1250
746
|
}
|
|
1251
747
|
for (const key of keys) {
|
|
1252
748
|
try {
|
|
1253
|
-
const request = await fetch(`${endpoint}/
|
|
749
|
+
const request = await fetch(`${endpoint}/pinata/keys/${key}`, {
|
|
1254
750
|
method: "PUT",
|
|
1255
751
|
headers
|
|
1256
752
|
});
|
|
@@ -1298,7 +794,10 @@ var createGroup = async (config, options) => {
|
|
|
1298
794
|
if (!config) {
|
|
1299
795
|
throw new ValidationError("Pinata configuration is missing");
|
|
1300
796
|
}
|
|
1301
|
-
const data = JSON.stringify(
|
|
797
|
+
const data = JSON.stringify({
|
|
798
|
+
name: options.name,
|
|
799
|
+
is_public: options.isPublic
|
|
800
|
+
});
|
|
1302
801
|
let headers;
|
|
1303
802
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1304
803
|
headers = { ...config.customHeaders };
|
|
@@ -1309,12 +808,12 @@ var createGroup = async (config, options) => {
|
|
|
1309
808
|
Source: "sdk/createGroup"
|
|
1310
809
|
};
|
|
1311
810
|
}
|
|
1312
|
-
let endpoint = "https://api.pinata.cloud";
|
|
811
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
1313
812
|
if (config.endpointUrl) {
|
|
1314
813
|
endpoint = config.endpointUrl;
|
|
1315
814
|
}
|
|
1316
815
|
try {
|
|
1317
|
-
const request = await fetch(`${endpoint}/groups`, {
|
|
816
|
+
const request = await fetch(`${endpoint}/files/groups`, {
|
|
1318
817
|
method: "POST",
|
|
1319
818
|
headers,
|
|
1320
819
|
body: data
|
|
@@ -1335,7 +834,8 @@ var createGroup = async (config, options) => {
|
|
|
1335
834
|
);
|
|
1336
835
|
}
|
|
1337
836
|
const res = await request.json();
|
|
1338
|
-
|
|
837
|
+
const resData = res.data;
|
|
838
|
+
return resData;
|
|
1339
839
|
} catch (error) {
|
|
1340
840
|
if (error instanceof PinataError) {
|
|
1341
841
|
throw error;
|
|
@@ -1364,23 +864,28 @@ var listGroups = async (config, options) => {
|
|
|
1364
864
|
}
|
|
1365
865
|
const params = new URLSearchParams();
|
|
1366
866
|
if (options) {
|
|
1367
|
-
const {
|
|
1368
|
-
if (
|
|
1369
|
-
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());
|
|
1370
872
|
if (nameContains !== void 0)
|
|
1371
873
|
params.append("nameContains", nameContains.toString());
|
|
1372
874
|
if (limit !== void 0)
|
|
1373
875
|
params.append("limit", limit.toString());
|
|
1374
876
|
}
|
|
1375
|
-
let endpoint = "https://api.pinata.cloud";
|
|
877
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
1376
878
|
if (config.endpointUrl) {
|
|
1377
879
|
endpoint = config.endpointUrl;
|
|
1378
880
|
}
|
|
1379
881
|
try {
|
|
1380
|
-
const request = await fetch(
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
882
|
+
const request = await fetch(
|
|
883
|
+
`${endpoint}/files/groups?${params.toString()}`,
|
|
884
|
+
{
|
|
885
|
+
method: "GET",
|
|
886
|
+
headers
|
|
887
|
+
}
|
|
888
|
+
);
|
|
1384
889
|
if (!request.ok) {
|
|
1385
890
|
const errorData = await request.text();
|
|
1386
891
|
if (request.status === 401 || request.status === 403) {
|
|
@@ -1397,7 +902,8 @@ var listGroups = async (config, options) => {
|
|
|
1397
902
|
);
|
|
1398
903
|
}
|
|
1399
904
|
const res = await request.json();
|
|
1400
|
-
|
|
905
|
+
const resData = res.data;
|
|
906
|
+
return resData;
|
|
1401
907
|
} catch (error) {
|
|
1402
908
|
if (error instanceof PinataError) {
|
|
1403
909
|
throw error;
|
|
@@ -1424,12 +930,12 @@ var getGroup = async (config, options) => {
|
|
|
1424
930
|
Source: "sdk/getGroup"
|
|
1425
931
|
};
|
|
1426
932
|
}
|
|
1427
|
-
let endpoint = "https://api.pinata.cloud";
|
|
933
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
1428
934
|
if (config.endpointUrl) {
|
|
1429
935
|
endpoint = config.endpointUrl;
|
|
1430
936
|
}
|
|
1431
937
|
try {
|
|
1432
|
-
const request = await fetch(`${endpoint}/groups/${options.groupId}`, {
|
|
938
|
+
const request = await fetch(`${endpoint}/files/groups/${options.groupId}`, {
|
|
1433
939
|
method: "GET",
|
|
1434
940
|
headers
|
|
1435
941
|
});
|
|
@@ -1449,7 +955,8 @@ var getGroup = async (config, options) => {
|
|
|
1449
955
|
);
|
|
1450
956
|
}
|
|
1451
957
|
const res = await request.json();
|
|
1452
|
-
|
|
958
|
+
const resData = res.data;
|
|
959
|
+
return resData;
|
|
1453
960
|
} catch (error) {
|
|
1454
961
|
if (error instanceof PinataError) {
|
|
1455
962
|
throw error;
|
|
@@ -1463,71 +970,14 @@ var getGroup = async (config, options) => {
|
|
|
1463
970
|
}
|
|
1464
971
|
};
|
|
1465
972
|
|
|
1466
|
-
// src/core/groups/addToGroup.ts
|
|
1467
|
-
var addToGroup = async (config, options) => {
|
|
1468
|
-
if (!config) {
|
|
1469
|
-
throw new ValidationError("Pinata configuration is missing");
|
|
1470
|
-
}
|
|
1471
|
-
const data = JSON.stringify({
|
|
1472
|
-
cids: options.cids
|
|
1473
|
-
});
|
|
1474
|
-
let headers;
|
|
1475
|
-
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1476
|
-
headers = { ...config.customHeaders };
|
|
1477
|
-
} else {
|
|
1478
|
-
headers = {
|
|
1479
|
-
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1480
|
-
"Content-Type": "application/json",
|
|
1481
|
-
Source: "sdk/addToGroup"
|
|
1482
|
-
};
|
|
1483
|
-
}
|
|
1484
|
-
let endpoint = "https://api.pinata.cloud";
|
|
1485
|
-
if (config.endpointUrl) {
|
|
1486
|
-
endpoint = config.endpointUrl;
|
|
1487
|
-
}
|
|
1488
|
-
try {
|
|
1489
|
-
const request = await fetch(`${endpoint}/groups/${options.groupId}/cids`, {
|
|
1490
|
-
method: "PUT",
|
|
1491
|
-
headers,
|
|
1492
|
-
body: data
|
|
1493
|
-
});
|
|
1494
|
-
if (!request.ok) {
|
|
1495
|
-
const errorData = await request.text();
|
|
1496
|
-
if (request.status === 401 || request.status === 403) {
|
|
1497
|
-
throw new AuthenticationError(
|
|
1498
|
-
`Authentication failed: ${errorData}`,
|
|
1499
|
-
request.status,
|
|
1500
|
-
errorData
|
|
1501
|
-
);
|
|
1502
|
-
}
|
|
1503
|
-
throw new NetworkError(
|
|
1504
|
-
`HTTP error: ${errorData}`,
|
|
1505
|
-
request.status,
|
|
1506
|
-
errorData
|
|
1507
|
-
);
|
|
1508
|
-
}
|
|
1509
|
-
const res = await request.text();
|
|
1510
|
-
return res;
|
|
1511
|
-
} catch (error) {
|
|
1512
|
-
if (error instanceof PinataError) {
|
|
1513
|
-
throw error;
|
|
1514
|
-
}
|
|
1515
|
-
if (error instanceof Error) {
|
|
1516
|
-
throw new PinataError(`Error processing addToGroup: ${error.message}`);
|
|
1517
|
-
}
|
|
1518
|
-
throw new PinataError(
|
|
1519
|
-
"An unknown error occurred while adding CIDs to group"
|
|
1520
|
-
);
|
|
1521
|
-
}
|
|
1522
|
-
};
|
|
1523
|
-
|
|
1524
973
|
// src/core/groups/updateGroup.ts
|
|
1525
974
|
var updateGroup = async (config, options) => {
|
|
1526
975
|
if (!config) {
|
|
1527
976
|
throw new ValidationError("Pinata configuration is missing");
|
|
1528
977
|
}
|
|
1529
978
|
const data = JSON.stringify({
|
|
1530
|
-
name: options.name
|
|
979
|
+
name: options.name,
|
|
980
|
+
is_public: options.isPublic
|
|
1531
981
|
});
|
|
1532
982
|
let headers;
|
|
1533
983
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
@@ -1539,12 +989,12 @@ var updateGroup = async (config, options) => {
|
|
|
1539
989
|
Source: "sdk/updateGroup"
|
|
1540
990
|
};
|
|
1541
991
|
}
|
|
1542
|
-
let endpoint = "https://api.pinata.cloud";
|
|
992
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
1543
993
|
if (config.endpointUrl) {
|
|
1544
994
|
endpoint = config.endpointUrl;
|
|
1545
995
|
}
|
|
1546
996
|
try {
|
|
1547
|
-
const request = await fetch(`${endpoint}/groups/${options.groupId}`, {
|
|
997
|
+
const request = await fetch(`${endpoint}/files/groups/${options.groupId}`, {
|
|
1548
998
|
method: "PUT",
|
|
1549
999
|
headers,
|
|
1550
1000
|
body: data
|
|
@@ -1552,569 +1002,8 @@ var updateGroup = async (config, options) => {
|
|
|
1552
1002
|
if (!request.ok) {
|
|
1553
1003
|
const errorData = await request.text();
|
|
1554
1004
|
if (request.status === 401 || request.status === 403) {
|
|
1555
|
-
throw new AuthenticationError(
|
|
1556
|
-
`Authentication failed: ${errorData}`,
|
|
1557
|
-
request.status,
|
|
1558
|
-
errorData
|
|
1559
|
-
);
|
|
1560
|
-
}
|
|
1561
|
-
throw new NetworkError(
|
|
1562
|
-
`HTTP error: ${errorData}`,
|
|
1563
|
-
request.status,
|
|
1564
|
-
errorData
|
|
1565
|
-
);
|
|
1566
|
-
}
|
|
1567
|
-
const res = await request.json();
|
|
1568
|
-
return res;
|
|
1569
|
-
} catch (error) {
|
|
1570
|
-
if (error instanceof PinataError) {
|
|
1571
|
-
throw error;
|
|
1572
|
-
}
|
|
1573
|
-
if (error instanceof Error) {
|
|
1574
|
-
throw new PinataError(`Error processing updateGroup: ${error.message}`);
|
|
1575
|
-
}
|
|
1576
|
-
throw new PinataError("An unknown error occurred while updating group");
|
|
1577
|
-
}
|
|
1578
|
-
};
|
|
1579
|
-
|
|
1580
|
-
// src/core/groups/removeFromGroup.ts
|
|
1581
|
-
var removeFromGroup = async (config, options) => {
|
|
1582
|
-
if (!config) {
|
|
1583
|
-
throw new ValidationError("Pinata configuration is missing");
|
|
1584
|
-
}
|
|
1585
|
-
let headers;
|
|
1586
|
-
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1587
|
-
headers = { ...config.customHeaders };
|
|
1588
|
-
} else {
|
|
1589
|
-
headers = {
|
|
1590
|
-
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1591
|
-
"Content-Type": "application/json",
|
|
1592
|
-
Source: "sdk/removeFromGroup"
|
|
1593
|
-
};
|
|
1594
|
-
}
|
|
1595
|
-
const data = JSON.stringify({
|
|
1596
|
-
cids: options.cids
|
|
1597
|
-
});
|
|
1598
|
-
let endpoint = "https://api.pinata.cloud";
|
|
1599
|
-
if (config.endpointUrl) {
|
|
1600
|
-
endpoint = config.endpointUrl;
|
|
1601
|
-
}
|
|
1602
|
-
try {
|
|
1603
|
-
const request = await fetch(`${endpoint}/groups/${options.groupId}/cids`, {
|
|
1604
|
-
method: "DELETE",
|
|
1605
|
-
headers,
|
|
1606
|
-
body: data
|
|
1607
|
-
});
|
|
1608
|
-
if (!request.ok) {
|
|
1609
|
-
const errorData = await request.text();
|
|
1610
|
-
if (request.status === 401 || request.status === 403) {
|
|
1611
|
-
throw new AuthenticationError(
|
|
1612
|
-
`Authentication failed: ${errorData}`,
|
|
1613
|
-
request.status,
|
|
1614
|
-
errorData
|
|
1615
|
-
);
|
|
1616
|
-
}
|
|
1617
|
-
throw new NetworkError(
|
|
1618
|
-
`HTTP error: ${errorData}`,
|
|
1619
|
-
request.status,
|
|
1620
|
-
errorData
|
|
1621
|
-
);
|
|
1622
|
-
}
|
|
1623
|
-
const res = await request.text();
|
|
1624
|
-
return res;
|
|
1625
|
-
} catch (error) {
|
|
1626
|
-
if (error instanceof PinataError) {
|
|
1627
|
-
throw error;
|
|
1628
|
-
}
|
|
1629
|
-
if (error instanceof Error) {
|
|
1630
|
-
throw new PinataError(
|
|
1631
|
-
`Error processing removeFromGroup: ${error.message}`
|
|
1632
|
-
);
|
|
1633
|
-
}
|
|
1634
|
-
throw new PinataError(
|
|
1635
|
-
"An unknown error occurred while removing CIDs from a group"
|
|
1636
|
-
);
|
|
1637
|
-
}
|
|
1638
|
-
};
|
|
1639
|
-
|
|
1640
|
-
// src/core/groups/deleteGroup.ts
|
|
1641
|
-
var deleteGroup = async (config, options) => {
|
|
1642
|
-
if (!config) {
|
|
1643
|
-
throw new ValidationError("Pinata configuration is missing");
|
|
1644
|
-
}
|
|
1645
|
-
let headers;
|
|
1646
|
-
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1647
|
-
headers = { ...config.customHeaders };
|
|
1648
|
-
} else {
|
|
1649
|
-
headers = {
|
|
1650
|
-
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1651
|
-
"Content-Type": "application/json",
|
|
1652
|
-
Source: "sdk/deleteGroup"
|
|
1653
|
-
};
|
|
1654
|
-
}
|
|
1655
|
-
let endpoint = "https://api.pinata.cloud";
|
|
1656
|
-
if (config.endpointUrl) {
|
|
1657
|
-
endpoint = config.endpointUrl;
|
|
1658
|
-
}
|
|
1659
|
-
try {
|
|
1660
|
-
const request = await fetch(`${endpoint}/groups/${options.groupId}`, {
|
|
1661
|
-
method: "DELETE",
|
|
1662
|
-
headers
|
|
1663
|
-
});
|
|
1664
|
-
if (!request.ok) {
|
|
1665
|
-
const errorData = await request.text();
|
|
1666
|
-
if (request.status === 401 || request.status === 403) {
|
|
1667
|
-
throw new AuthenticationError(
|
|
1668
|
-
`Authentication failed: ${errorData}`,
|
|
1669
|
-
request.status,
|
|
1670
|
-
errorData
|
|
1671
|
-
);
|
|
1672
|
-
}
|
|
1673
|
-
throw new NetworkError(
|
|
1674
|
-
`HTTP error: ${errorData}`,
|
|
1675
|
-
request.status,
|
|
1676
|
-
errorData
|
|
1677
|
-
);
|
|
1678
|
-
}
|
|
1679
|
-
const res = await request.text();
|
|
1680
|
-
return res;
|
|
1681
|
-
} catch (error) {
|
|
1682
|
-
if (error instanceof PinataError) {
|
|
1683
|
-
throw error;
|
|
1684
|
-
}
|
|
1685
|
-
if (error instanceof Error) {
|
|
1686
|
-
throw new PinataError(`Error processing deleteGroup: ${error.message}`);
|
|
1687
|
-
}
|
|
1688
|
-
throw new PinataError("An unknown error occurred while deleting a group");
|
|
1689
|
-
}
|
|
1690
|
-
};
|
|
1691
|
-
|
|
1692
|
-
// src/core/signatures/addSignature.ts
|
|
1693
|
-
var addSignature = async (config, options) => {
|
|
1694
|
-
if (!config) {
|
|
1695
|
-
throw new ValidationError("Pinata configuration is missing");
|
|
1696
|
-
}
|
|
1697
|
-
const data = JSON.stringify({
|
|
1698
|
-
signature: options.signature
|
|
1699
|
-
});
|
|
1700
|
-
let headers;
|
|
1701
|
-
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1702
|
-
headers = { ...config.customHeaders };
|
|
1703
|
-
} else {
|
|
1704
|
-
headers = {
|
|
1705
|
-
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1706
|
-
"Content-Type": "application/json",
|
|
1707
|
-
Source: "sdk/addSignature"
|
|
1708
|
-
};
|
|
1709
|
-
}
|
|
1710
|
-
let endpoint = "https://api.pinata.cloud";
|
|
1711
|
-
if (config.endpointUrl) {
|
|
1712
|
-
endpoint = config.endpointUrl;
|
|
1713
|
-
}
|
|
1714
|
-
try {
|
|
1715
|
-
const request = await fetch(
|
|
1716
|
-
`${endpoint}/v3/ipfs/signature/${options.cid}`,
|
|
1717
|
-
{
|
|
1718
|
-
method: "POST",
|
|
1719
|
-
headers,
|
|
1720
|
-
body: data
|
|
1721
|
-
}
|
|
1722
|
-
);
|
|
1723
|
-
if (!request.ok) {
|
|
1724
|
-
const errorData = await request.text();
|
|
1725
|
-
if (request.status === 401 || request.status === 403) {
|
|
1726
|
-
throw new AuthenticationError(
|
|
1727
|
-
`Authentication failed: ${errorData}`,
|
|
1728
|
-
request.status,
|
|
1729
|
-
errorData
|
|
1730
|
-
);
|
|
1731
|
-
}
|
|
1732
|
-
if (request.status === 403) {
|
|
1733
|
-
throw new PinataError(
|
|
1734
|
-
"Unauthorized signing, you must be the original owner of the file and it must not have a signature",
|
|
1735
|
-
request.status,
|
|
1736
|
-
errorData
|
|
1737
|
-
);
|
|
1738
|
-
}
|
|
1739
|
-
throw new NetworkError(
|
|
1740
|
-
`HTTP error: ${errorData}`,
|
|
1741
|
-
request.status,
|
|
1742
|
-
errorData
|
|
1743
|
-
);
|
|
1744
|
-
}
|
|
1745
|
-
const res = await request.json();
|
|
1746
|
-
return res.data;
|
|
1747
|
-
} catch (error) {
|
|
1748
|
-
if (error instanceof PinataError) {
|
|
1749
|
-
throw error;
|
|
1750
|
-
}
|
|
1751
|
-
if (error instanceof Error) {
|
|
1752
|
-
throw new PinataError(`Error processing addSignature: ${error.message}`);
|
|
1753
|
-
}
|
|
1754
|
-
throw new PinataError(
|
|
1755
|
-
"An unknown error occurred while adding signature to CID"
|
|
1756
|
-
);
|
|
1757
|
-
}
|
|
1758
|
-
};
|
|
1759
|
-
|
|
1760
|
-
// src/core/signatures/getSignature.ts
|
|
1761
|
-
var getSignature = async (config, cid) => {
|
|
1762
|
-
if (!config) {
|
|
1763
|
-
throw new ValidationError("Pinata configuration is missing");
|
|
1764
|
-
}
|
|
1765
|
-
let headers;
|
|
1766
|
-
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1767
|
-
headers = { ...config.customHeaders };
|
|
1768
|
-
} else {
|
|
1769
|
-
headers = {
|
|
1770
|
-
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1771
|
-
"Content-Type": "application/json",
|
|
1772
|
-
Source: "sdk/getSignature"
|
|
1773
|
-
};
|
|
1774
|
-
}
|
|
1775
|
-
let endpoint = "https://api.pinata.cloud";
|
|
1776
|
-
if (config.endpointUrl) {
|
|
1777
|
-
endpoint = config.endpointUrl;
|
|
1778
|
-
}
|
|
1779
|
-
try {
|
|
1780
|
-
const request = await fetch(`${endpoint}/v3/ipfs/signature/${cid}`, {
|
|
1781
|
-
method: "GET",
|
|
1782
|
-
headers
|
|
1783
|
-
});
|
|
1784
|
-
if (!request.ok) {
|
|
1785
|
-
const errorData = await request.text();
|
|
1786
|
-
if (request.status === 401 || request.status === 403) {
|
|
1787
|
-
throw new AuthenticationError(
|
|
1788
|
-
`Authentication failed: ${errorData}`,
|
|
1789
|
-
request.status,
|
|
1790
|
-
errorData
|
|
1791
|
-
);
|
|
1792
|
-
}
|
|
1793
|
-
throw new NetworkError(
|
|
1794
|
-
`HTTP error: ${errorData}`,
|
|
1795
|
-
request.status,
|
|
1796
|
-
errorData
|
|
1797
|
-
);
|
|
1798
|
-
}
|
|
1799
|
-
const res = await request.json();
|
|
1800
|
-
return res.data;
|
|
1801
|
-
} catch (error) {
|
|
1802
|
-
if (error instanceof PinataError) {
|
|
1803
|
-
throw error;
|
|
1804
|
-
}
|
|
1805
|
-
if (error instanceof Error) {
|
|
1806
|
-
throw new PinataError(`Error processing getSignature: ${error.message}`);
|
|
1807
|
-
}
|
|
1808
|
-
throw new PinataError(
|
|
1809
|
-
"An unknown error occurred while fetching signature for CID"
|
|
1810
|
-
);
|
|
1811
|
-
}
|
|
1812
|
-
};
|
|
1813
|
-
|
|
1814
|
-
// src/core/signatures/removeSignature.ts
|
|
1815
|
-
var removeSignature = async (config, cid) => {
|
|
1816
|
-
if (!config) {
|
|
1817
|
-
throw new ValidationError("Pinata configuration is missing");
|
|
1818
|
-
}
|
|
1819
|
-
let headers;
|
|
1820
|
-
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1821
|
-
headers = { ...config.customHeaders };
|
|
1822
|
-
} else {
|
|
1823
|
-
headers = {
|
|
1824
|
-
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1825
|
-
"Content-Type": "application/json",
|
|
1826
|
-
Source: "sdk/removeSignature"
|
|
1827
|
-
};
|
|
1828
|
-
}
|
|
1829
|
-
let endpoint = "https://api.pinata.cloud";
|
|
1830
|
-
if (config.endpointUrl) {
|
|
1831
|
-
endpoint = config.endpointUrl;
|
|
1832
|
-
}
|
|
1833
|
-
try {
|
|
1834
|
-
const request = await fetch(`${endpoint}/v3/ipfs/signature/${cid}`, {
|
|
1835
|
-
method: "DELETE",
|
|
1836
|
-
headers
|
|
1837
|
-
});
|
|
1838
|
-
if (!request.ok) {
|
|
1839
|
-
const errorData = await request.text();
|
|
1840
|
-
if (request.status === 401 || request.status === 403) {
|
|
1841
|
-
throw new AuthenticationError(
|
|
1842
|
-
`Authentication failed: ${errorData}`,
|
|
1843
|
-
request.status,
|
|
1844
|
-
errorData
|
|
1845
|
-
);
|
|
1846
|
-
}
|
|
1847
|
-
throw new NetworkError(
|
|
1848
|
-
`HTTP error: ${errorData}`,
|
|
1849
|
-
request.status,
|
|
1850
|
-
errorData
|
|
1851
|
-
);
|
|
1852
|
-
}
|
|
1853
|
-
return "OK";
|
|
1854
|
-
} catch (error) {
|
|
1855
|
-
if (error instanceof PinataError) {
|
|
1856
|
-
throw error;
|
|
1857
|
-
}
|
|
1858
|
-
if (error instanceof Error) {
|
|
1859
|
-
throw new PinataError(`Error processing addSignature: ${error.message}`);
|
|
1860
|
-
}
|
|
1861
|
-
throw new PinataError(
|
|
1862
|
-
"An unknown error occurred while adding signature to CID"
|
|
1863
|
-
);
|
|
1864
|
-
}
|
|
1865
|
-
};
|
|
1866
|
-
|
|
1867
|
-
// src/core/gateway/analyticsTopUsage.ts
|
|
1868
|
-
var analyticsTopUsage = async (config, options) => {
|
|
1869
|
-
if (!config) {
|
|
1870
|
-
throw new ValidationError("Pinata configuration is missing");
|
|
1871
|
-
}
|
|
1872
|
-
const params = new URLSearchParams({
|
|
1873
|
-
includesCount: "false"
|
|
1874
|
-
});
|
|
1875
|
-
if (options) {
|
|
1876
|
-
const {
|
|
1877
|
-
cid,
|
|
1878
|
-
gateway_domain,
|
|
1879
|
-
start_date,
|
|
1880
|
-
end_date,
|
|
1881
|
-
file_name,
|
|
1882
|
-
user_agent,
|
|
1883
|
-
country,
|
|
1884
|
-
region,
|
|
1885
|
-
referer,
|
|
1886
|
-
limit,
|
|
1887
|
-
sort_order,
|
|
1888
|
-
sort_by,
|
|
1889
|
-
attribute
|
|
1890
|
-
} = options;
|
|
1891
|
-
if (cid)
|
|
1892
|
-
params.append("cid", cid);
|
|
1893
|
-
if (gateway_domain)
|
|
1894
|
-
params.append("gateway_domain", gateway_domain);
|
|
1895
|
-
if (start_date)
|
|
1896
|
-
params.append("start_date", start_date);
|
|
1897
|
-
if (end_date)
|
|
1898
|
-
params.append("end_date", end_date);
|
|
1899
|
-
if (file_name)
|
|
1900
|
-
params.append("file_name", file_name);
|
|
1901
|
-
if (user_agent)
|
|
1902
|
-
params.append("user_agent", user_agent.toString());
|
|
1903
|
-
if (country)
|
|
1904
|
-
params.append("country", country.toString());
|
|
1905
|
-
if (region)
|
|
1906
|
-
params.append("region", region);
|
|
1907
|
-
if (referer)
|
|
1908
|
-
params.append("referer", referer.toString());
|
|
1909
|
-
if (limit)
|
|
1910
|
-
params.append("limit", limit.toString());
|
|
1911
|
-
if (sort_order)
|
|
1912
|
-
params.append("sort_order", sort_order);
|
|
1913
|
-
if (sort_by)
|
|
1914
|
-
params.append("sort_by", sort_by);
|
|
1915
|
-
if (attribute)
|
|
1916
|
-
params.append("by", attribute);
|
|
1917
|
-
}
|
|
1918
|
-
let endpoint = "https://api.pinata.cloud";
|
|
1919
|
-
if (config.endpointUrl) {
|
|
1920
|
-
endpoint = config.endpointUrl;
|
|
1921
|
-
}
|
|
1922
|
-
const url = `${endpoint}/v3/ipfs/gateway_analytics_top?${params.toString()}`;
|
|
1923
|
-
try {
|
|
1924
|
-
let headers;
|
|
1925
|
-
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1926
|
-
headers = { ...config.customHeaders };
|
|
1927
|
-
} else {
|
|
1928
|
-
headers = {
|
|
1929
|
-
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1930
|
-
Source: "sdk/analyticsTopUsage"
|
|
1931
|
-
};
|
|
1932
|
-
}
|
|
1933
|
-
const request = await fetch(url, {
|
|
1934
|
-
method: "GET",
|
|
1935
|
-
headers
|
|
1936
|
-
});
|
|
1937
|
-
if (!request.ok) {
|
|
1938
|
-
const errorData = await request.text();
|
|
1939
|
-
if (request.status === 401 || request.status === 403) {
|
|
1940
|
-
throw new AuthenticationError(
|
|
1941
|
-
`Authentication failed: ${errorData}`,
|
|
1942
|
-
request.status,
|
|
1943
|
-
errorData
|
|
1944
|
-
);
|
|
1945
|
-
}
|
|
1946
|
-
throw new NetworkError(
|
|
1947
|
-
`HTTP error: ${errorData}`,
|
|
1948
|
-
request.status,
|
|
1949
|
-
errorData
|
|
1950
|
-
);
|
|
1951
|
-
}
|
|
1952
|
-
const res = await request.json();
|
|
1953
|
-
const resData = res.data;
|
|
1954
|
-
return resData;
|
|
1955
|
-
} catch (error) {
|
|
1956
|
-
if (error instanceof PinataError) {
|
|
1957
|
-
throw error;
|
|
1958
|
-
}
|
|
1959
|
-
if (error instanceof Error) {
|
|
1960
|
-
throw new PinataError(
|
|
1961
|
-
`Error processing anaytics usage: ${error.message}`
|
|
1962
|
-
);
|
|
1963
|
-
}
|
|
1964
|
-
throw new PinataError(
|
|
1965
|
-
"An unknown error occurred while fetching gateway usage"
|
|
1966
|
-
);
|
|
1967
|
-
}
|
|
1968
|
-
};
|
|
1969
|
-
|
|
1970
|
-
// src/core/gateway/analyticsDateInterval.ts
|
|
1971
|
-
var analyticsDateInterval = async (config, options) => {
|
|
1972
|
-
if (!config) {
|
|
1973
|
-
throw new ValidationError("Pinata configuration is missing");
|
|
1974
|
-
}
|
|
1975
|
-
const params = new URLSearchParams();
|
|
1976
|
-
if (options) {
|
|
1977
|
-
const {
|
|
1978
|
-
cid,
|
|
1979
|
-
gateway_domain,
|
|
1980
|
-
start_date,
|
|
1981
|
-
end_date,
|
|
1982
|
-
file_name,
|
|
1983
|
-
user_agent,
|
|
1984
|
-
country,
|
|
1985
|
-
region,
|
|
1986
|
-
referer,
|
|
1987
|
-
limit,
|
|
1988
|
-
sort_order,
|
|
1989
|
-
date_interval,
|
|
1990
|
-
sort_by
|
|
1991
|
-
} = options;
|
|
1992
|
-
if (cid)
|
|
1993
|
-
params.append("cid", cid);
|
|
1994
|
-
if (gateway_domain)
|
|
1995
|
-
params.append("gateway_domain", gateway_domain);
|
|
1996
|
-
if (start_date)
|
|
1997
|
-
params.append("start_date", start_date);
|
|
1998
|
-
if (end_date)
|
|
1999
|
-
params.append("end_date", end_date);
|
|
2000
|
-
if (file_name)
|
|
2001
|
-
params.append("file_name", file_name);
|
|
2002
|
-
if (user_agent)
|
|
2003
|
-
params.append("user_agent", user_agent.toString());
|
|
2004
|
-
if (country)
|
|
2005
|
-
params.append("country", country.toString());
|
|
2006
|
-
if (region)
|
|
2007
|
-
params.append("region", region);
|
|
2008
|
-
if (referer)
|
|
2009
|
-
params.append("referer", referer.toString());
|
|
2010
|
-
if (limit)
|
|
2011
|
-
params.append("limit", limit.toString());
|
|
2012
|
-
if (sort_order)
|
|
2013
|
-
params.append("sort_order", sort_order);
|
|
2014
|
-
if (sort_by)
|
|
2015
|
-
params.append("sort_by", sort_by);
|
|
2016
|
-
if (date_interval)
|
|
2017
|
-
params.append("by", date_interval);
|
|
2018
|
-
}
|
|
2019
|
-
let endpoint = "https://api.pinata.cloud";
|
|
2020
|
-
if (config.endpointUrl) {
|
|
2021
|
-
endpoint = config.endpointUrl;
|
|
2022
|
-
}
|
|
2023
|
-
const url = `${endpoint}/v3/ipfs/gateway_analytics_time_series?${params.toString()}`;
|
|
2024
|
-
try {
|
|
2025
|
-
let headers;
|
|
2026
|
-
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
2027
|
-
headers = { ...config.customHeaders };
|
|
2028
|
-
} else {
|
|
2029
|
-
headers = {
|
|
2030
|
-
Authorization: `Bearer ${config.pinataJwt}`,
|
|
2031
|
-
Source: "sdk/analyticsDateInterval"
|
|
2032
|
-
};
|
|
2033
|
-
}
|
|
2034
|
-
const request = await fetch(url, {
|
|
2035
|
-
method: "GET",
|
|
2036
|
-
headers
|
|
2037
|
-
});
|
|
2038
|
-
if (!request.ok) {
|
|
2039
|
-
const errorData = await request.text();
|
|
2040
|
-
if (request.status === 401 || request.status === 403) {
|
|
2041
|
-
throw new AuthenticationError(
|
|
2042
|
-
`Authentication failed: ${errorData}`,
|
|
2043
|
-
request.status,
|
|
2044
|
-
errorData
|
|
2045
|
-
);
|
|
2046
|
-
}
|
|
2047
|
-
throw new NetworkError(
|
|
2048
|
-
`HTTP error: ${errorData}`,
|
|
2049
|
-
request.status,
|
|
2050
|
-
errorData
|
|
2051
|
-
);
|
|
2052
|
-
}
|
|
2053
|
-
const res = await request.json();
|
|
2054
|
-
const resData = res.data;
|
|
2055
|
-
return resData;
|
|
2056
|
-
} catch (error) {
|
|
2057
|
-
if (error instanceof PinataError) {
|
|
2058
|
-
throw error;
|
|
2059
|
-
}
|
|
2060
|
-
if (error instanceof Error) {
|
|
2061
|
-
throw new PinataError(
|
|
2062
|
-
`Error processing anaytics usage: ${error.message}`
|
|
2063
|
-
);
|
|
2064
|
-
}
|
|
2065
|
-
throw new PinataError(
|
|
2066
|
-
"An unknown error occurred while fetching gateway usage"
|
|
2067
|
-
);
|
|
2068
|
-
}
|
|
2069
|
-
};
|
|
2070
|
-
|
|
2071
|
-
// src/core/gateway/swapCid.ts
|
|
2072
|
-
var swapCid = async (config, options) => {
|
|
2073
|
-
if (!config) {
|
|
2074
|
-
throw new ValidationError("Pinata configuration is missing");
|
|
2075
|
-
}
|
|
2076
|
-
const data = JSON.stringify({
|
|
2077
|
-
swapCid: options.swapCid
|
|
2078
|
-
});
|
|
2079
|
-
let headers;
|
|
2080
|
-
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
2081
|
-
headers = { ...config.customHeaders };
|
|
2082
|
-
} else {
|
|
2083
|
-
headers = {
|
|
2084
|
-
Authorization: `Bearer ${config.pinataJwt}`,
|
|
2085
|
-
"Content-Type": "application/json",
|
|
2086
|
-
Source: "sdk/swapCid"
|
|
2087
|
-
};
|
|
2088
|
-
}
|
|
2089
|
-
let endpoint = "https://api.pinata.cloud";
|
|
2090
|
-
if (config.endpointUrl) {
|
|
2091
|
-
endpoint = config.endpointUrl;
|
|
2092
|
-
}
|
|
2093
|
-
try {
|
|
2094
|
-
const request = await fetch(`${endpoint}/v3/ipfs/swap/${options.cid}`, {
|
|
2095
|
-
method: "PUT",
|
|
2096
|
-
headers,
|
|
2097
|
-
body: data
|
|
2098
|
-
});
|
|
2099
|
-
if (!request.ok) {
|
|
2100
|
-
const errorData = await request.text();
|
|
2101
|
-
if (request.status === 401 || request.status === 403) {
|
|
2102
|
-
throw new AuthenticationError(
|
|
2103
|
-
`Authentication failed: ${errorData}`,
|
|
2104
|
-
request.status,
|
|
2105
|
-
errorData
|
|
2106
|
-
);
|
|
2107
|
-
}
|
|
2108
|
-
if (request.status === 403) {
|
|
2109
|
-
throw new PinataError(
|
|
2110
|
-
"Unauthorized CID Swap",
|
|
2111
|
-
request.status,
|
|
2112
|
-
errorData
|
|
2113
|
-
);
|
|
2114
|
-
}
|
|
2115
|
-
if (request.status === 404) {
|
|
2116
|
-
throw new PinataError(
|
|
2117
|
-
"CID not pinned to account",
|
|
1005
|
+
throw new AuthenticationError(
|
|
1006
|
+
`Authentication failed: ${errorData}`,
|
|
2118
1007
|
request.status,
|
|
2119
1008
|
errorData
|
|
2120
1009
|
);
|
|
@@ -2133,14 +1022,14 @@ var swapCid = async (config, options) => {
|
|
|
2133
1022
|
throw error;
|
|
2134
1023
|
}
|
|
2135
1024
|
if (error instanceof Error) {
|
|
2136
|
-
throw new PinataError(`Error processing
|
|
1025
|
+
throw new PinataError(`Error processing updateGroup: ${error.message}`);
|
|
2137
1026
|
}
|
|
2138
|
-
throw new PinataError("An unknown error occurred while
|
|
1027
|
+
throw new PinataError("An unknown error occurred while updating group");
|
|
2139
1028
|
}
|
|
2140
1029
|
};
|
|
2141
1030
|
|
|
2142
|
-
// src/core/
|
|
2143
|
-
var
|
|
1031
|
+
// src/core/groups/deleteGroup.ts
|
|
1032
|
+
var deleteGroup = async (config, options) => {
|
|
2144
1033
|
if (!config) {
|
|
2145
1034
|
throw new ValidationError("Pinata configuration is missing");
|
|
2146
1035
|
}
|
|
@@ -2151,21 +1040,18 @@ var swapHistory = async (config, options) => {
|
|
|
2151
1040
|
headers = {
|
|
2152
1041
|
Authorization: `Bearer ${config.pinataJwt}`,
|
|
2153
1042
|
"Content-Type": "application/json",
|
|
2154
|
-
Source: "sdk/
|
|
1043
|
+
Source: "sdk/deleteGroup"
|
|
2155
1044
|
};
|
|
2156
1045
|
}
|
|
2157
|
-
let endpoint = "https://api.pinata.cloud";
|
|
1046
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
2158
1047
|
if (config.endpointUrl) {
|
|
2159
1048
|
endpoint = config.endpointUrl;
|
|
2160
1049
|
}
|
|
2161
1050
|
try {
|
|
2162
|
-
const request = await fetch(
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
headers
|
|
2167
|
-
}
|
|
2168
|
-
);
|
|
1051
|
+
const request = await fetch(`${endpoint}/files/groups/${options.groupId}`, {
|
|
1052
|
+
method: "DELETE",
|
|
1053
|
+
headers
|
|
1054
|
+
});
|
|
2169
1055
|
if (!request.ok) {
|
|
2170
1056
|
const errorData = await request.text();
|
|
2171
1057
|
if (request.status === 401 || request.status === 403) {
|
|
@@ -2175,78 +1061,52 @@ var swapHistory = async (config, options) => {
|
|
|
2175
1061
|
errorData
|
|
2176
1062
|
);
|
|
2177
1063
|
}
|
|
2178
|
-
if (request.status === 404) {
|
|
2179
|
-
throw new PinataError(
|
|
2180
|
-
"CID does not have history",
|
|
2181
|
-
request.status,
|
|
2182
|
-
errorData
|
|
2183
|
-
);
|
|
2184
|
-
}
|
|
2185
1064
|
throw new NetworkError(
|
|
2186
1065
|
`HTTP error: ${errorData}`,
|
|
2187
1066
|
request.status,
|
|
2188
1067
|
errorData
|
|
2189
1068
|
);
|
|
2190
1069
|
}
|
|
2191
|
-
const res =
|
|
2192
|
-
|
|
2193
|
-
return resData;
|
|
1070
|
+
const res = request.statusText;
|
|
1071
|
+
return res;
|
|
2194
1072
|
} catch (error) {
|
|
2195
1073
|
if (error instanceof PinataError) {
|
|
2196
1074
|
throw error;
|
|
2197
1075
|
}
|
|
2198
1076
|
if (error instanceof Error) {
|
|
2199
|
-
throw new PinataError(`Error
|
|
1077
|
+
throw new PinataError(`Error processing deleteGroup: ${error.message}`);
|
|
2200
1078
|
}
|
|
2201
|
-
throw new PinataError(
|
|
2202
|
-
"An unknown error occurred while fetching swap history"
|
|
2203
|
-
);
|
|
1079
|
+
throw new PinataError("An unknown error occurred while deleting a group");
|
|
2204
1080
|
}
|
|
2205
1081
|
};
|
|
2206
1082
|
|
|
2207
|
-
// src/core/gateway/
|
|
2208
|
-
var
|
|
1083
|
+
// src/core/gateway/createSignedURL.ts
|
|
1084
|
+
var createSignedURL = async (config, options) => {
|
|
2209
1085
|
if (!config) {
|
|
2210
1086
|
throw new ValidationError("Pinata configuration is missing");
|
|
2211
1087
|
}
|
|
2212
|
-
let
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
};
|
|
2221
|
-
}
|
|
2222
|
-
let endpoint = "https://api.pinata.cloud";
|
|
2223
|
-
if (config.endpointUrl) {
|
|
2224
|
-
endpoint = config.endpointUrl;
|
|
2225
|
-
}
|
|
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
|
+
});
|
|
2226
1096
|
try {
|
|
2227
|
-
const request = await fetch(
|
|
2228
|
-
method: "
|
|
2229
|
-
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
|
|
2230
1104
|
});
|
|
2231
1105
|
if (!request.ok) {
|
|
2232
1106
|
const errorData = await request.text();
|
|
2233
1107
|
if (request.status === 401 || request.status === 403) {
|
|
2234
1108
|
throw new AuthenticationError(
|
|
2235
|
-
`Authentication
|
|
2236
|
-
request.status,
|
|
2237
|
-
errorData
|
|
2238
|
-
);
|
|
2239
|
-
}
|
|
2240
|
-
if (request.status === 403) {
|
|
2241
|
-
throw new PinataError(
|
|
2242
|
-
"Unauthorized CID Swap Deletion",
|
|
2243
|
-
request.status,
|
|
2244
|
-
errorData
|
|
2245
|
-
);
|
|
2246
|
-
}
|
|
2247
|
-
if (request.status === 404) {
|
|
2248
|
-
throw new PinataError(
|
|
2249
|
-
"CID not pinned to account",
|
|
1109
|
+
`Authentication Failed: ${errorData}`,
|
|
2250
1110
|
request.status,
|
|
2251
1111
|
errorData
|
|
2252
1112
|
);
|
|
@@ -2257,15 +1117,18 @@ var deleteSwap = async (config, cid) => {
|
|
|
2257
1117
|
errorData
|
|
2258
1118
|
);
|
|
2259
1119
|
}
|
|
2260
|
-
|
|
1120
|
+
const res = await request.json();
|
|
1121
|
+
return res.data;
|
|
2261
1122
|
} catch (error) {
|
|
2262
1123
|
if (error instanceof PinataError) {
|
|
2263
1124
|
throw error;
|
|
2264
1125
|
}
|
|
2265
1126
|
if (error instanceof Error) {
|
|
2266
|
-
throw new PinataError(
|
|
1127
|
+
throw new PinataError(
|
|
1128
|
+
`Error processing createSignedURL: ${error.message}`
|
|
1129
|
+
);
|
|
2267
1130
|
}
|
|
2268
|
-
throw new PinataError("An unknown error occurred while
|
|
1131
|
+
throw new PinataError("An unknown error occurred while getting signed url");
|
|
2269
1132
|
}
|
|
2270
1133
|
};
|
|
2271
1134
|
|
|
@@ -2281,41 +1144,45 @@ var formatConfig = (config) => {
|
|
|
2281
1144
|
return config;
|
|
2282
1145
|
};
|
|
2283
1146
|
var PinataSDK = class {
|
|
1147
|
+
//signatures: Signatures;
|
|
2284
1148
|
constructor(config) {
|
|
2285
1149
|
this.config = formatConfig(config);
|
|
1150
|
+
this.files = new Files(this.config);
|
|
2286
1151
|
this.upload = new Upload(this.config);
|
|
2287
1152
|
this.gateways = new Gateways(this.config);
|
|
2288
|
-
this.usage = new Usage(this.config);
|
|
2289
1153
|
this.keys = new Keys(this.config);
|
|
2290
1154
|
this.groups = new Groups(this.config);
|
|
2291
|
-
this.signatures = new Signatures(this.config);
|
|
2292
1155
|
}
|
|
2293
1156
|
setNewHeaders(headers) {
|
|
2294
1157
|
if (!this.config) {
|
|
2295
1158
|
this.config = { pinataJwt: "", customHeaders: {} };
|
|
2296
1159
|
}
|
|
2297
1160
|
this.config.customHeaders = { ...this.config.customHeaders, ...headers };
|
|
1161
|
+
this.files.updateConfig(this.config);
|
|
2298
1162
|
this.upload.updateConfig(this.config);
|
|
2299
1163
|
this.gateways.updateConfig(this.config);
|
|
2300
|
-
this.usage.updateConfig(this.config);
|
|
2301
1164
|
this.keys.updateConfig(this.config);
|
|
2302
1165
|
this.groups.updateConfig(this.config);
|
|
2303
|
-
this.signatures.updateConfig(this.config);
|
|
2304
1166
|
}
|
|
2305
1167
|
testAuthentication() {
|
|
2306
1168
|
return testAuthentication(this.config);
|
|
2307
1169
|
}
|
|
2308
|
-
|
|
2309
|
-
|
|
1170
|
+
};
|
|
1171
|
+
var Files = class {
|
|
1172
|
+
constructor(config) {
|
|
1173
|
+
this.config = formatConfig(config);
|
|
1174
|
+
}
|
|
1175
|
+
updateConfig(newConfig) {
|
|
1176
|
+
this.config = newConfig;
|
|
2310
1177
|
}
|
|
2311
|
-
|
|
1178
|
+
list() {
|
|
2312
1179
|
return new FilterFiles(this.config);
|
|
2313
1180
|
}
|
|
2314
|
-
|
|
2315
|
-
return
|
|
1181
|
+
delete(files) {
|
|
1182
|
+
return deleteFile(this.config, files);
|
|
2316
1183
|
}
|
|
2317
|
-
|
|
2318
|
-
return
|
|
1184
|
+
update(options) {
|
|
1185
|
+
return updateFile(this.config, options);
|
|
2319
1186
|
}
|
|
2320
1187
|
};
|
|
2321
1188
|
var UploadBuilder = class {
|
|
@@ -2323,7 +1190,6 @@ var UploadBuilder = class {
|
|
|
2323
1190
|
this.config = config;
|
|
2324
1191
|
this.uploadFunction = uploadFunction;
|
|
2325
1192
|
this.args = args;
|
|
2326
|
-
this.version = 1;
|
|
2327
1193
|
}
|
|
2328
1194
|
addMetadata(metadata) {
|
|
2329
1195
|
this.metadata = metadata;
|
|
@@ -2333,18 +1199,14 @@ var UploadBuilder = class {
|
|
|
2333
1199
|
this.keys = jwt;
|
|
2334
1200
|
return this;
|
|
2335
1201
|
}
|
|
2336
|
-
cidVersion(v) {
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
}
|
|
1202
|
+
// cidVersion(v: 0 | 1): UploadBuilder<T> {
|
|
1203
|
+
// this.version = v;
|
|
1204
|
+
// return this;
|
|
1205
|
+
// }
|
|
2340
1206
|
group(groupId) {
|
|
2341
1207
|
this.groupId = groupId;
|
|
2342
1208
|
return this;
|
|
2343
1209
|
}
|
|
2344
|
-
peerAddress(peerAddresses) {
|
|
2345
|
-
this.peerAddresses = peerAddresses;
|
|
2346
|
-
return this;
|
|
2347
|
-
}
|
|
2348
1210
|
then(onfulfilled, onrejected) {
|
|
2349
1211
|
const options = this.args[this.args.length - 1] || {};
|
|
2350
1212
|
if (this.metadata) {
|
|
@@ -2356,12 +1218,6 @@ var UploadBuilder = class {
|
|
|
2356
1218
|
if (this.groupId) {
|
|
2357
1219
|
options.groupId = this.groupId;
|
|
2358
1220
|
}
|
|
2359
|
-
if (this.version) {
|
|
2360
|
-
options.cidVersion = this.version;
|
|
2361
|
-
}
|
|
2362
|
-
if (this.peerAddresses && "peerAddresses" in options) {
|
|
2363
|
-
options.peerAddresses = this.peerAddresses;
|
|
2364
|
-
}
|
|
2365
1221
|
this.args[this.args.length - 1] = options;
|
|
2366
1222
|
return this.uploadFunction(this.config, ...this.args).then(
|
|
2367
1223
|
onfulfilled,
|
|
@@ -2379,9 +1235,12 @@ var Upload = class {
|
|
|
2379
1235
|
file(file, options) {
|
|
2380
1236
|
return new UploadBuilder(this.config, uploadFile, file, options);
|
|
2381
1237
|
}
|
|
2382
|
-
fileArray(
|
|
2383
|
-
|
|
2384
|
-
|
|
1238
|
+
// fileArray(
|
|
1239
|
+
// files: FileObject[],
|
|
1240
|
+
// options?: UploadOptions,
|
|
1241
|
+
// ): UploadBuilder<UploadResponse> {
|
|
1242
|
+
// return new UploadBuilder(this.config, uploadFileArray, files, options);
|
|
1243
|
+
// }
|
|
2385
1244
|
base64(base64String, options) {
|
|
2386
1245
|
return new UploadBuilder(this.config, uploadBase64, base64String, options);
|
|
2387
1246
|
}
|
|
@@ -2391,97 +1250,58 @@ var Upload = class {
|
|
|
2391
1250
|
json(data, options) {
|
|
2392
1251
|
return new UploadBuilder(this.config, uploadJson, data, options);
|
|
2393
1252
|
}
|
|
2394
|
-
cid(cid, options) {
|
|
2395
|
-
return new UploadBuilder(this.config, uploadCid, cid, options);
|
|
2396
|
-
}
|
|
2397
1253
|
};
|
|
2398
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;
|
|
2399
1260
|
constructor(config) {
|
|
2400
1261
|
this.query = {};
|
|
2401
|
-
// rate limit vars
|
|
2402
|
-
this.requestCount = 0;
|
|
2403
|
-
this.lastRequestTime = 0;
|
|
2404
|
-
this.MAX_REQUESTS_PER_MINUTE = 30;
|
|
2405
|
-
this.MINUTE_IN_MS = 6e4;
|
|
2406
1262
|
this.config = config;
|
|
2407
1263
|
}
|
|
2408
|
-
|
|
2409
|
-
this.query.
|
|
2410
|
-
return this;
|
|
2411
|
-
}
|
|
2412
|
-
pinStart(date) {
|
|
2413
|
-
this.query.pinStart = date;
|
|
2414
|
-
return this;
|
|
2415
|
-
}
|
|
2416
|
-
pinEnd(date) {
|
|
2417
|
-
this.query.pinEnd = date;
|
|
2418
|
-
return this;
|
|
2419
|
-
}
|
|
2420
|
-
pinSizeMin(size) {
|
|
2421
|
-
this.query.pinSizeMin = size;
|
|
2422
|
-
return this;
|
|
2423
|
-
}
|
|
2424
|
-
pinSizeMax(size) {
|
|
2425
|
-
this.query.pinSizeMax = size;
|
|
2426
|
-
return this;
|
|
2427
|
-
}
|
|
2428
|
-
pageLimit(limit) {
|
|
2429
|
-
this.query.pageLimit = limit;
|
|
2430
|
-
return this;
|
|
2431
|
-
}
|
|
2432
|
-
pageOffset(offset) {
|
|
2433
|
-
this.query.pageOffset = offset;
|
|
2434
|
-
return this;
|
|
2435
|
-
}
|
|
2436
|
-
name(name) {
|
|
2437
|
-
this.query.name = name;
|
|
2438
|
-
return this;
|
|
2439
|
-
}
|
|
2440
|
-
group(groupId) {
|
|
2441
|
-
this.query.groupId = groupId;
|
|
1264
|
+
limit(limit) {
|
|
1265
|
+
this.query.limit = limit;
|
|
2442
1266
|
return this;
|
|
2443
1267
|
}
|
|
2444
|
-
|
|
2445
|
-
this.query.
|
|
2446
|
-
this.query.value = value;
|
|
2447
|
-
if (operator) {
|
|
2448
|
-
this.query.operator = operator;
|
|
2449
|
-
}
|
|
1268
|
+
cidPending(cidPending) {
|
|
1269
|
+
this.query.cidPending = cidPending;
|
|
2450
1270
|
return this;
|
|
2451
1271
|
}
|
|
2452
1272
|
then(onfulfilled) {
|
|
2453
|
-
return
|
|
2454
|
-
}
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
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
|
+
// }
|
|
2469
1297
|
async *[Symbol.asyncIterator]() {
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
const limit = this.query.pageLimit || 10;
|
|
2473
|
-
while (hasMore) {
|
|
2474
|
-
await this.rateLimit();
|
|
2475
|
-
this.query.pageOffset = offset;
|
|
2476
|
-
this.query.pageLimit = limit;
|
|
2477
|
-
const items = await listFiles(this.config, this.query);
|
|
1298
|
+
while (true) {
|
|
1299
|
+
const items = await this.fetchPage();
|
|
2478
1300
|
for (const item of items) {
|
|
2479
1301
|
yield item;
|
|
2480
1302
|
}
|
|
2481
|
-
if (
|
|
2482
|
-
|
|
2483
|
-
} else {
|
|
2484
|
-
offset += items.length;
|
|
1303
|
+
if (!this.currentPageToken) {
|
|
1304
|
+
break;
|
|
2485
1305
|
}
|
|
2486
1306
|
}
|
|
2487
1307
|
}
|
|
@@ -2501,144 +1321,65 @@ var Gateways = class {
|
|
|
2501
1321
|
this.config = newConfig;
|
|
2502
1322
|
}
|
|
2503
1323
|
get(cid) {
|
|
2504
|
-
return
|
|
2505
|
-
}
|
|
2506
|
-
|
|
2507
|
-
return
|
|
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
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
}
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
}
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
this.config = config;
|
|
2564
|
-
}
|
|
2565
|
-
cid(cid) {
|
|
2566
|
-
this.query.ipfs_pin_hash = cid;
|
|
2567
|
-
return this;
|
|
2568
|
-
}
|
|
2569
|
-
status(status) {
|
|
2570
|
-
this.query.status = status;
|
|
2571
|
-
return this;
|
|
2572
|
-
}
|
|
2573
|
-
pageLimit(limit) {
|
|
2574
|
-
this.query.limit = limit;
|
|
2575
|
-
return this;
|
|
2576
|
-
}
|
|
2577
|
-
pageOffset(offset) {
|
|
2578
|
-
this.query.offset = offset;
|
|
2579
|
-
return this;
|
|
2580
|
-
}
|
|
2581
|
-
sort(sort) {
|
|
2582
|
-
this.query.sort = sort;
|
|
2583
|
-
return this;
|
|
2584
|
-
}
|
|
2585
|
-
then(onfulfilled) {
|
|
2586
|
-
return pinJobs(this.config, this.query).then(onfulfilled);
|
|
2587
|
-
}
|
|
2588
|
-
// rate limit, hopefully temporary?
|
|
2589
|
-
async rateLimit() {
|
|
2590
|
-
this.requestCount++;
|
|
2591
|
-
const now = Date.now();
|
|
2592
|
-
if (this.requestCount >= this.MAX_REQUESTS_PER_MINUTE) {
|
|
2593
|
-
const timePassedSinceLastRequest = now - this.lastRequestTime;
|
|
2594
|
-
if (timePassedSinceLastRequest < this.MINUTE_IN_MS) {
|
|
2595
|
-
const delayTime = this.MINUTE_IN_MS - timePassedSinceLastRequest;
|
|
2596
|
-
await new Promise((resolve) => setTimeout(resolve, delayTime));
|
|
2597
|
-
}
|
|
2598
|
-
this.requestCount = 0;
|
|
2599
|
-
}
|
|
2600
|
-
this.lastRequestTime = Date.now();
|
|
2601
|
-
}
|
|
2602
|
-
async *[Symbol.asyncIterator]() {
|
|
2603
|
-
let hasMore = true;
|
|
2604
|
-
let offset = 0;
|
|
2605
|
-
const limit = this.query.limit || 10;
|
|
2606
|
-
while (hasMore) {
|
|
2607
|
-
await this.rateLimit();
|
|
2608
|
-
this.query.offset = offset;
|
|
2609
|
-
this.query.limit = limit;
|
|
2610
|
-
const items = await pinJobs(this.config, this.query);
|
|
2611
|
-
for (const item of items) {
|
|
2612
|
-
yield item;
|
|
2613
|
-
}
|
|
2614
|
-
if (items.length === 0) {
|
|
2615
|
-
hasMore = false;
|
|
2616
|
-
} else {
|
|
2617
|
-
offset += items.length;
|
|
2618
|
-
}
|
|
2619
|
-
}
|
|
2620
|
-
}
|
|
2621
|
-
async all() {
|
|
2622
|
-
const allItems = [];
|
|
2623
|
-
for await (const item of this) {
|
|
2624
|
-
allItems.push(item);
|
|
2625
|
-
}
|
|
2626
|
-
return allItems;
|
|
2627
|
-
}
|
|
2628
|
-
};
|
|
2629
|
-
var Usage = class {
|
|
2630
|
-
constructor(config) {
|
|
2631
|
-
this.config = formatConfig(config);
|
|
2632
|
-
}
|
|
2633
|
-
updateConfig(newConfig) {
|
|
2634
|
-
this.config = newConfig;
|
|
2635
|
-
}
|
|
2636
|
-
pinnedFileCount() {
|
|
2637
|
-
return pinnedFileCount(this.config);
|
|
2638
|
-
}
|
|
2639
|
-
totalStorageSize() {
|
|
2640
|
-
return totalStorageUsage(this.config);
|
|
2641
|
-
}
|
|
1324
|
+
return getCid(this.config, cid);
|
|
1325
|
+
}
|
|
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
|
+
// }
|
|
2642
1383
|
};
|
|
2643
1384
|
var Keys = class {
|
|
2644
1385
|
constructor(config) {
|
|
@@ -2658,13 +1399,13 @@ var Keys = class {
|
|
|
2658
1399
|
}
|
|
2659
1400
|
};
|
|
2660
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;
|
|
2661
1407
|
constructor(config) {
|
|
2662
1408
|
this.query = {};
|
|
2663
|
-
// rate limit vars
|
|
2664
|
-
this.requestCount = 0;
|
|
2665
|
-
this.lastRequestTime = 0;
|
|
2666
|
-
this.MAX_REQUESTS_PER_MINUTE = 30;
|
|
2667
|
-
this.MINUTE_IN_MS = 6e4;
|
|
2668
1409
|
this.config = config;
|
|
2669
1410
|
}
|
|
2670
1411
|
offset(offset) {
|
|
@@ -2690,25 +1431,23 @@ var FilterKeys = class {
|
|
|
2690
1431
|
then(onfulfilled) {
|
|
2691
1432
|
return listKeys(this.config, this.query).then(onfulfilled);
|
|
2692
1433
|
}
|
|
2693
|
-
//
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
}
|
|
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
|
+
// }
|
|
2707
1447
|
async *[Symbol.asyncIterator]() {
|
|
2708
1448
|
let hasMore = true;
|
|
2709
1449
|
let offset = 0;
|
|
2710
1450
|
while (hasMore) {
|
|
2711
|
-
await this.rateLimit();
|
|
2712
1451
|
this.query.offset = offset;
|
|
2713
1452
|
const items = await listKeys(this.config, this.query);
|
|
2714
1453
|
for (const item of items) {
|
|
@@ -2745,12 +1484,12 @@ var Groups = class {
|
|
|
2745
1484
|
get(options) {
|
|
2746
1485
|
return getGroup(this.config, options);
|
|
2747
1486
|
}
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
}
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
}
|
|
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
|
+
// }
|
|
2754
1493
|
update(options) {
|
|
2755
1494
|
return updateGroup(this.config, options);
|
|
2756
1495
|
}
|
|
@@ -2761,57 +1500,56 @@ var Groups = class {
|
|
|
2761
1500
|
var FilterGroups = class {
|
|
2762
1501
|
constructor(config) {
|
|
2763
1502
|
this.query = {};
|
|
2764
|
-
// rate limit vars
|
|
2765
|
-
this.requestCount = 0;
|
|
2766
|
-
this.lastRequestTime = 0;
|
|
2767
|
-
this.MAX_REQUESTS_PER_MINUTE = 30;
|
|
2768
|
-
this.MINUTE_IN_MS = 6e4;
|
|
2769
1503
|
this.config = config;
|
|
2770
1504
|
}
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
}
|
|
2775
|
-
name(nameContains) {
|
|
2776
|
-
this.query.nameContains = nameContains;
|
|
2777
|
-
return this;
|
|
2778
|
-
}
|
|
1505
|
+
// name(nameContains: string): FilterGroups {
|
|
1506
|
+
// this.query.nameContains = nameContains;
|
|
1507
|
+
// return this;
|
|
1508
|
+
// }
|
|
2779
1509
|
limit(limit) {
|
|
2780
1510
|
this.query.limit = limit;
|
|
2781
1511
|
return this;
|
|
2782
1512
|
}
|
|
1513
|
+
isPublic(isPublic) {
|
|
1514
|
+
this.query.isPublic = isPublic;
|
|
1515
|
+
return this;
|
|
1516
|
+
}
|
|
2783
1517
|
then(onfulfilled) {
|
|
2784
|
-
return
|
|
1518
|
+
return this.fetchPage().then((response) => {
|
|
1519
|
+
this.nextPageToken = response.next_page_token;
|
|
1520
|
+
return response.groups;
|
|
1521
|
+
}).then(onfulfilled);
|
|
2785
1522
|
}
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
const now = Date.now();
|
|
2790
|
-
if (this.requestCount >= this.MAX_REQUESTS_PER_MINUTE) {
|
|
2791
|
-
const timePassedSinceLastRequest = now - this.lastRequestTime;
|
|
2792
|
-
if (timePassedSinceLastRequest < this.MINUTE_IN_MS) {
|
|
2793
|
-
const delayTime = this.MINUTE_IN_MS - timePassedSinceLastRequest;
|
|
2794
|
-
await new Promise((resolve) => setTimeout(resolve, delayTime));
|
|
2795
|
-
}
|
|
2796
|
-
this.requestCount = 0;
|
|
1523
|
+
async fetchPage() {
|
|
1524
|
+
if (this.nextPageToken) {
|
|
1525
|
+
this.query.pageToken = this.nextPageToken;
|
|
2797
1526
|
}
|
|
2798
|
-
this.
|
|
1527
|
+
return listGroups(this.config, this.query);
|
|
2799
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
|
+
// }
|
|
2800
1543
|
async *[Symbol.asyncIterator]() {
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
await this.rateLimit();
|
|
2805
|
-
this.query.offset = offset;
|
|
2806
|
-
const items = await listGroups(this.config, this.query);
|
|
2807
|
-
for (const item of items) {
|
|
1544
|
+
while (true) {
|
|
1545
|
+
const response = await this.fetchPage();
|
|
1546
|
+
for (const item of response.groups) {
|
|
2808
1547
|
yield item;
|
|
2809
1548
|
}
|
|
2810
|
-
if (
|
|
2811
|
-
|
|
2812
|
-
} else {
|
|
2813
|
-
offset += items.length;
|
|
1549
|
+
if (!response.next_page_token) {
|
|
1550
|
+
break;
|
|
2814
1551
|
}
|
|
1552
|
+
this.nextPageToken = response.next_page_token;
|
|
2815
1553
|
}
|
|
2816
1554
|
}
|
|
2817
1555
|
async all() {
|
|
@@ -2822,122 +1560,6 @@ var FilterGroups = class {
|
|
|
2822
1560
|
return allItems;
|
|
2823
1561
|
}
|
|
2824
1562
|
};
|
|
2825
|
-
var Signatures = class {
|
|
2826
|
-
constructor(config) {
|
|
2827
|
-
this.config = formatConfig(config);
|
|
2828
|
-
}
|
|
2829
|
-
updateConfig(newConfig) {
|
|
2830
|
-
this.config = newConfig;
|
|
2831
|
-
}
|
|
2832
|
-
add(options) {
|
|
2833
|
-
return addSignature(this.config, options);
|
|
2834
|
-
}
|
|
2835
|
-
get(cid) {
|
|
2836
|
-
return getSignature(this.config, cid);
|
|
2837
|
-
}
|
|
2838
|
-
delete(cid) {
|
|
2839
|
-
return removeSignature(this.config, cid);
|
|
2840
|
-
}
|
|
2841
|
-
};
|
|
2842
|
-
var GatewayAnalyticsBuilder = class {
|
|
2843
|
-
constructor(config, query) {
|
|
2844
|
-
this.requestCount = 0;
|
|
2845
|
-
this.lastRequestTime = 0;
|
|
2846
|
-
this.MAX_REQUESTS_PER_MINUTE = 30;
|
|
2847
|
-
this.MINUTE_IN_MS = 6e4;
|
|
2848
|
-
this.config = config;
|
|
2849
|
-
this.query = query;
|
|
2850
|
-
}
|
|
2851
|
-
cid(cid) {
|
|
2852
|
-
this.query.cid = cid;
|
|
2853
|
-
return this;
|
|
2854
|
-
}
|
|
2855
|
-
fileName(fileName) {
|
|
2856
|
-
this.query.file_name = fileName;
|
|
2857
|
-
return this;
|
|
2858
|
-
}
|
|
2859
|
-
userAgent(userAgent) {
|
|
2860
|
-
this.query.user_agent = userAgent;
|
|
2861
|
-
return this;
|
|
2862
|
-
}
|
|
2863
|
-
country(country) {
|
|
2864
|
-
this.query.country = country;
|
|
2865
|
-
return this;
|
|
2866
|
-
}
|
|
2867
|
-
region(region) {
|
|
2868
|
-
this.query.region = region;
|
|
2869
|
-
return this;
|
|
2870
|
-
}
|
|
2871
|
-
referer(referer) {
|
|
2872
|
-
this.query.referer = referer;
|
|
2873
|
-
return this;
|
|
2874
|
-
}
|
|
2875
|
-
limit(limit) {
|
|
2876
|
-
this.query.limit = limit;
|
|
2877
|
-
return this;
|
|
2878
|
-
}
|
|
2879
|
-
sort(order) {
|
|
2880
|
-
this.query.sort_order = order;
|
|
2881
|
-
return this;
|
|
2882
|
-
}
|
|
2883
|
-
async rateLimit() {
|
|
2884
|
-
this.requestCount++;
|
|
2885
|
-
const now = Date.now();
|
|
2886
|
-
if (this.requestCount >= this.MAX_REQUESTS_PER_MINUTE) {
|
|
2887
|
-
const timePassedSinceLastRequest = now - this.lastRequestTime;
|
|
2888
|
-
if (timePassedSinceLastRequest < this.MINUTE_IN_MS) {
|
|
2889
|
-
const delayTime = this.MINUTE_IN_MS - timePassedSinceLastRequest;
|
|
2890
|
-
await new Promise((resolve) => setTimeout(resolve, delayTime));
|
|
2891
|
-
}
|
|
2892
|
-
this.requestCount = 0;
|
|
2893
|
-
}
|
|
2894
|
-
this.lastRequestTime = Date.now();
|
|
2895
|
-
}
|
|
2896
|
-
async getAnalytics() {
|
|
2897
|
-
await this.rateLimit();
|
|
2898
|
-
throw new Error("getAnalytics method must be implemented in derived class");
|
|
2899
|
-
}
|
|
2900
|
-
then(onfulfilled) {
|
|
2901
|
-
return this.getAnalytics().then(onfulfilled);
|
|
2902
|
-
}
|
|
2903
|
-
};
|
|
2904
|
-
var TopGatewayAnalyticsBuilder = class extends GatewayAnalyticsBuilder {
|
|
2905
|
-
constructor(config, domain, start, end, sortBy, attribute) {
|
|
2906
|
-
super(config, {
|
|
2907
|
-
gateway_domain: domain,
|
|
2908
|
-
start_date: start,
|
|
2909
|
-
end_date: end,
|
|
2910
|
-
sort_by: sortBy,
|
|
2911
|
-
attribute
|
|
2912
|
-
});
|
|
2913
|
-
}
|
|
2914
|
-
async getAnalytics() {
|
|
2915
|
-
return analyticsTopUsage(this.config, this.query);
|
|
2916
|
-
}
|
|
2917
|
-
async all() {
|
|
2918
|
-
return this.getAnalytics();
|
|
2919
|
-
}
|
|
2920
|
-
};
|
|
2921
|
-
var TimeIntervalGatewayAnalyticsBuilder = class extends GatewayAnalyticsBuilder {
|
|
2922
|
-
constructor(config, domain, start, end, dateInterval) {
|
|
2923
|
-
super(config, {
|
|
2924
|
-
gateway_domain: domain,
|
|
2925
|
-
start_date: start,
|
|
2926
|
-
end_date: end,
|
|
2927
|
-
date_interval: dateInterval
|
|
2928
|
-
});
|
|
2929
|
-
}
|
|
2930
|
-
sortBy(sortBy) {
|
|
2931
|
-
this.query.sort_by = sortBy;
|
|
2932
|
-
return this;
|
|
2933
|
-
}
|
|
2934
|
-
async getAnalytics() {
|
|
2935
|
-
return analyticsDateInterval(this.config, this.query);
|
|
2936
|
-
}
|
|
2937
|
-
async all() {
|
|
2938
|
-
return this.getAnalytics();
|
|
2939
|
-
}
|
|
2940
|
-
};
|
|
2941
1563
|
export {
|
|
2942
1564
|
PinataSDK
|
|
2943
1565
|
};
|