pinata 1.9.1 → 1.10.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/dist/index.d.mts +13 -1
- package/dist/index.d.ts +13 -1
- package/dist/index.js +233 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +233 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -124,7 +124,11 @@ var uploadFile = async (config, file, options) => {
|
|
|
124
124
|
if (options?.metadata?.keyvalues) {
|
|
125
125
|
metadata + `,keyvalues ${btoa(JSON.stringify(options.metadata.keyvalues))}`;
|
|
126
126
|
}
|
|
127
|
-
|
|
127
|
+
let updatedEndpoint = `${endpoint}/files`;
|
|
128
|
+
if (options?.url) {
|
|
129
|
+
updatedEndpoint = options.url;
|
|
130
|
+
}
|
|
131
|
+
const urlReq = await fetch(updatedEndpoint, {
|
|
128
132
|
method: "POST",
|
|
129
133
|
headers: {
|
|
130
134
|
"Upload-Length": `${file.size}`,
|
|
@@ -216,6 +220,43 @@ var uploadFile = async (config, file, options) => {
|
|
|
216
220
|
}
|
|
217
221
|
const data = new FormData();
|
|
218
222
|
data.append("file", file, file.name);
|
|
223
|
+
if (options?.url) {
|
|
224
|
+
try {
|
|
225
|
+
const request = await fetch(options.url, {
|
|
226
|
+
method: "POST",
|
|
227
|
+
headers,
|
|
228
|
+
body: data
|
|
229
|
+
});
|
|
230
|
+
if (!request.ok) {
|
|
231
|
+
const errorData = await request.text();
|
|
232
|
+
if (request.status === 401 || request.status === 403) {
|
|
233
|
+
throw new AuthenticationError(
|
|
234
|
+
`Authentication failed: ${errorData}`,
|
|
235
|
+
request.status,
|
|
236
|
+
errorData
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
throw new NetworkError(
|
|
240
|
+
`HTTP error: ${errorData}`,
|
|
241
|
+
request.status,
|
|
242
|
+
errorData
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
const res = await request.json();
|
|
246
|
+
const resData = res.data;
|
|
247
|
+
return resData;
|
|
248
|
+
} catch (error) {
|
|
249
|
+
if (error instanceof PinataError) {
|
|
250
|
+
throw error;
|
|
251
|
+
}
|
|
252
|
+
if (error instanceof Error) {
|
|
253
|
+
throw new PinataError(`Error processing base64: ${error.message}`);
|
|
254
|
+
}
|
|
255
|
+
throw new PinataError(
|
|
256
|
+
"An unknown error occurred while trying to upload base64"
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
219
260
|
data.append("name", options?.metadata?.name || file.name || "File from SDK");
|
|
220
261
|
if (options?.groupId) {
|
|
221
262
|
data.append("group_id", options.groupId);
|
|
@@ -314,6 +355,42 @@ var uploadBase64 = async (config, base64String, options) => {
|
|
|
314
355
|
if (config.uploadUrl) {
|
|
315
356
|
endpoint = config.uploadUrl;
|
|
316
357
|
}
|
|
358
|
+
if (options?.url) {
|
|
359
|
+
try {
|
|
360
|
+
const request = await fetch(options.url, {
|
|
361
|
+
method: "POST",
|
|
362
|
+
body: data
|
|
363
|
+
});
|
|
364
|
+
if (!request.ok) {
|
|
365
|
+
const errorData = await request.text();
|
|
366
|
+
if (request.status === 401 || request.status === 403) {
|
|
367
|
+
throw new AuthenticationError(
|
|
368
|
+
`Authentication failed: ${errorData}`,
|
|
369
|
+
request.status,
|
|
370
|
+
errorData
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
throw new NetworkError(
|
|
374
|
+
`HTTP error: ${errorData}`,
|
|
375
|
+
request.status,
|
|
376
|
+
errorData
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
const res = await request.json();
|
|
380
|
+
const resData = res.data;
|
|
381
|
+
return resData;
|
|
382
|
+
} catch (error) {
|
|
383
|
+
if (error instanceof PinataError) {
|
|
384
|
+
throw error;
|
|
385
|
+
}
|
|
386
|
+
if (error instanceof Error) {
|
|
387
|
+
throw new PinataError(`Error processing base64: ${error.message}`);
|
|
388
|
+
}
|
|
389
|
+
throw new PinataError(
|
|
390
|
+
"An unknown error occurred while trying to upload base64"
|
|
391
|
+
);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
317
394
|
try {
|
|
318
395
|
const request = await fetch(`${endpoint}/files`, {
|
|
319
396
|
method: "POST",
|
|
@@ -417,6 +494,42 @@ var uploadUrl = async (config, url, options) => {
|
|
|
417
494
|
if (config.uploadUrl) {
|
|
418
495
|
endpoint = config.uploadUrl;
|
|
419
496
|
}
|
|
497
|
+
if (options?.url) {
|
|
498
|
+
try {
|
|
499
|
+
const request = await fetch(options.url, {
|
|
500
|
+
method: "POST",
|
|
501
|
+
body: data
|
|
502
|
+
});
|
|
503
|
+
if (!request.ok) {
|
|
504
|
+
const errorData = await request.text();
|
|
505
|
+
if (request.status === 401 || request.status === 403) {
|
|
506
|
+
throw new AuthenticationError(
|
|
507
|
+
`Authentication failed: ${errorData}`,
|
|
508
|
+
request.status,
|
|
509
|
+
errorData
|
|
510
|
+
);
|
|
511
|
+
}
|
|
512
|
+
throw new NetworkError(
|
|
513
|
+
`HTTP error: ${errorData}`,
|
|
514
|
+
request.status,
|
|
515
|
+
errorData
|
|
516
|
+
);
|
|
517
|
+
}
|
|
518
|
+
const res = await request.json();
|
|
519
|
+
const resData = res.data;
|
|
520
|
+
return resData;
|
|
521
|
+
} catch (error) {
|
|
522
|
+
if (error instanceof PinataError) {
|
|
523
|
+
throw error;
|
|
524
|
+
}
|
|
525
|
+
if (error instanceof Error) {
|
|
526
|
+
throw new PinataError(`Error processing base64: ${error.message}`);
|
|
527
|
+
}
|
|
528
|
+
throw new PinataError(
|
|
529
|
+
"An unknown error occurred while trying to upload base64"
|
|
530
|
+
);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
420
533
|
try {
|
|
421
534
|
const request = await fetch(`${endpoint}/files`, {
|
|
422
535
|
method: "POST",
|
|
@@ -508,6 +621,42 @@ var uploadJson = async (config, jsonData, options) => {
|
|
|
508
621
|
if (config.uploadUrl) {
|
|
509
622
|
endpoint = config.uploadUrl;
|
|
510
623
|
}
|
|
624
|
+
if (options?.url) {
|
|
625
|
+
try {
|
|
626
|
+
const request = await fetch(options.url, {
|
|
627
|
+
method: "POST",
|
|
628
|
+
body: data
|
|
629
|
+
});
|
|
630
|
+
if (!request.ok) {
|
|
631
|
+
const errorData = await request.text();
|
|
632
|
+
if (request.status === 401 || request.status === 403) {
|
|
633
|
+
throw new AuthenticationError(
|
|
634
|
+
`Authentication failed: ${errorData}`,
|
|
635
|
+
request.status,
|
|
636
|
+
errorData
|
|
637
|
+
);
|
|
638
|
+
}
|
|
639
|
+
throw new NetworkError(
|
|
640
|
+
`HTTP error: ${errorData}`,
|
|
641
|
+
request.status,
|
|
642
|
+
errorData
|
|
643
|
+
);
|
|
644
|
+
}
|
|
645
|
+
const res = await request.json();
|
|
646
|
+
const resData = res.data;
|
|
647
|
+
return resData;
|
|
648
|
+
} catch (error) {
|
|
649
|
+
if (error instanceof PinataError) {
|
|
650
|
+
throw error;
|
|
651
|
+
}
|
|
652
|
+
if (error instanceof Error) {
|
|
653
|
+
throw new PinataError(`Error processing base64: ${error.message}`);
|
|
654
|
+
}
|
|
655
|
+
throw new PinataError(
|
|
656
|
+
"An unknown error occurred while trying to upload base64"
|
|
657
|
+
);
|
|
658
|
+
}
|
|
659
|
+
}
|
|
511
660
|
try {
|
|
512
661
|
const request = await fetch(`${endpoint}/files`, {
|
|
513
662
|
method: "POST",
|
|
@@ -2284,6 +2433,79 @@ var deleteFileVectors = async (config, fileId) => {
|
|
|
2284
2433
|
}
|
|
2285
2434
|
};
|
|
2286
2435
|
|
|
2436
|
+
// src/core/uploads/createSignedUploadURL.ts
|
|
2437
|
+
var createSignedUploadURL = async (config, options) => {
|
|
2438
|
+
if (!config) {
|
|
2439
|
+
throw new ValidationError("Pinata configuration is missing");
|
|
2440
|
+
}
|
|
2441
|
+
const date = options?.date || Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3);
|
|
2442
|
+
const payload = {
|
|
2443
|
+
date,
|
|
2444
|
+
expires: options.expires
|
|
2445
|
+
};
|
|
2446
|
+
if (options.groupId) {
|
|
2447
|
+
payload.group_id = options.groupId;
|
|
2448
|
+
}
|
|
2449
|
+
if (options.name) {
|
|
2450
|
+
payload.filename = options.name;
|
|
2451
|
+
}
|
|
2452
|
+
if (options.keyvalues) {
|
|
2453
|
+
payload.keyvalues = options.keyvalues;
|
|
2454
|
+
}
|
|
2455
|
+
let endpoint = "https://uploads.pinata.cloud/v3";
|
|
2456
|
+
if (config.uploadUrl) {
|
|
2457
|
+
endpoint = config.uploadUrl;
|
|
2458
|
+
}
|
|
2459
|
+
let headers;
|
|
2460
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
2461
|
+
headers = {
|
|
2462
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
2463
|
+
"Content-Type": "application/json",
|
|
2464
|
+
...config.customHeaders
|
|
2465
|
+
};
|
|
2466
|
+
} else {
|
|
2467
|
+
headers = {
|
|
2468
|
+
"Content-Type": "application/json",
|
|
2469
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
2470
|
+
Source: "sdk/createSignURL"
|
|
2471
|
+
};
|
|
2472
|
+
}
|
|
2473
|
+
try {
|
|
2474
|
+
const request = await fetch(`${endpoint}/files/sign`, {
|
|
2475
|
+
method: "POST",
|
|
2476
|
+
headers,
|
|
2477
|
+
body: JSON.stringify(payload)
|
|
2478
|
+
});
|
|
2479
|
+
if (!request.ok) {
|
|
2480
|
+
const errorData = await request.text();
|
|
2481
|
+
if (request.status === 401 || request.status === 403) {
|
|
2482
|
+
throw new AuthenticationError(
|
|
2483
|
+
`Authentication Failed: ${errorData}`,
|
|
2484
|
+
request.status,
|
|
2485
|
+
errorData
|
|
2486
|
+
);
|
|
2487
|
+
}
|
|
2488
|
+
throw new NetworkError(
|
|
2489
|
+
`HTTP error: ${errorData}`,
|
|
2490
|
+
request.status,
|
|
2491
|
+
errorData
|
|
2492
|
+
);
|
|
2493
|
+
}
|
|
2494
|
+
const res = await request.json();
|
|
2495
|
+
return res.data;
|
|
2496
|
+
} catch (error) {
|
|
2497
|
+
if (error instanceof PinataError) {
|
|
2498
|
+
throw error;
|
|
2499
|
+
}
|
|
2500
|
+
if (error instanceof Error) {
|
|
2501
|
+
throw new PinataError(
|
|
2502
|
+
`Error processing createSignedURL: ${error.message}`
|
|
2503
|
+
);
|
|
2504
|
+
}
|
|
2505
|
+
throw new PinataError("An unknown error occurred while getting signed url");
|
|
2506
|
+
}
|
|
2507
|
+
};
|
|
2508
|
+
|
|
2287
2509
|
// src/core/pinataSDK.ts
|
|
2288
2510
|
var formatConfig = (config) => {
|
|
2289
2511
|
let gateway = config?.pinataGateway;
|
|
@@ -2387,6 +2609,10 @@ var UploadBuilder = class {
|
|
|
2387
2609
|
this.vector = true;
|
|
2388
2610
|
return this;
|
|
2389
2611
|
}
|
|
2612
|
+
url(url) {
|
|
2613
|
+
this.uploadUrl = url;
|
|
2614
|
+
return this;
|
|
2615
|
+
}
|
|
2390
2616
|
// cidVersion(v: 0 | 1): UploadBuilder<T> {
|
|
2391
2617
|
// this.version = v;
|
|
2392
2618
|
// return this;
|
|
@@ -2409,6 +2635,9 @@ var UploadBuilder = class {
|
|
|
2409
2635
|
if (this.vector) {
|
|
2410
2636
|
options.vectorize = this.vector;
|
|
2411
2637
|
}
|
|
2638
|
+
if (this.uploadUrl) {
|
|
2639
|
+
options.url = this.uploadUrl;
|
|
2640
|
+
}
|
|
2412
2641
|
this.args[this.args.length - 1] = options;
|
|
2413
2642
|
return this.uploadFunction(this.config, ...this.args).then(
|
|
2414
2643
|
onfulfilled,
|
|
@@ -2441,6 +2670,9 @@ var Upload = class {
|
|
|
2441
2670
|
json(data, options) {
|
|
2442
2671
|
return new UploadBuilder(this.config, uploadJson, data, options);
|
|
2443
2672
|
}
|
|
2673
|
+
createSignedURL(options) {
|
|
2674
|
+
return createSignedUploadURL(this.config, options);
|
|
2675
|
+
}
|
|
2444
2676
|
};
|
|
2445
2677
|
var FilterFiles = class {
|
|
2446
2678
|
// rate limit vars
|