pinata 2.4.9 → 2.5.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/LICENSE +0 -0
- package/README.md +0 -0
- package/dist/{gateway-tools-l9hk7kz4.d.mts → gateway-tools-Cd7xutmh.d.mts} +2 -0
- package/dist/{gateway-tools-l9hk7kz4.d.ts → gateway-tools-Cd7xutmh.d.ts} +2 -0
- package/dist/index.d.mts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +66 -37
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +66 -37
- package/dist/index.mjs.map +1 -1
- package/dist/react/index.d.mts +2 -2
- package/dist/react/index.d.ts +2 -2
- package/package.json +68 -68
package/dist/index.mjs
CHANGED
|
@@ -2457,49 +2457,65 @@ var createSignedUploadURL = async (config, options, network) => {
|
|
|
2457
2457
|
Source: "sdk/createSignURL"
|
|
2458
2458
|
};
|
|
2459
2459
|
}
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
if (request.
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2460
|
+
const maxRetries = 3;
|
|
2461
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
2462
|
+
try {
|
|
2463
|
+
const request = await fetch(`${endpoint}/files/sign`, {
|
|
2464
|
+
method: "POST",
|
|
2465
|
+
headers,
|
|
2466
|
+
cache: "no-store",
|
|
2467
|
+
body: JSON.stringify(payload)
|
|
2468
|
+
});
|
|
2469
|
+
if (!request.ok) {
|
|
2470
|
+
const errorData = await request.text();
|
|
2471
|
+
if (request.status === 401 || request.status === 403) {
|
|
2472
|
+
throw new AuthenticationError(
|
|
2473
|
+
`Authentication Failed: ${errorData}`,
|
|
2474
|
+
request.status,
|
|
2475
|
+
{
|
|
2476
|
+
error: errorData,
|
|
2477
|
+
code: "AUTH_ERROR",
|
|
2478
|
+
metadata: {
|
|
2479
|
+
requestUrl: request.url
|
|
2480
|
+
}
|
|
2478
2481
|
}
|
|
2482
|
+
);
|
|
2483
|
+
}
|
|
2484
|
+
throw new NetworkError(`HTTP error: ${errorData}`, request.status, {
|
|
2485
|
+
error: errorData,
|
|
2486
|
+
code: "HTTP_ERROR",
|
|
2487
|
+
metadata: {
|
|
2488
|
+
requestUrl: request.url
|
|
2479
2489
|
}
|
|
2480
|
-
);
|
|
2490
|
+
});
|
|
2481
2491
|
}
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2492
|
+
const res = await request.json();
|
|
2493
|
+
return res.data;
|
|
2494
|
+
} catch (error) {
|
|
2495
|
+
if (error instanceof AuthenticationError) {
|
|
2496
|
+
throw error;
|
|
2497
|
+
}
|
|
2498
|
+
if (error instanceof NetworkError && error.statusCode && error.statusCode >= 400 && error.statusCode < 500 && error.statusCode !== 429) {
|
|
2499
|
+
throw error;
|
|
2500
|
+
}
|
|
2501
|
+
if (attempt === maxRetries) {
|
|
2502
|
+
if (error instanceof PinataError) {
|
|
2503
|
+
throw error;
|
|
2487
2504
|
}
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
);
|
|
2505
|
+
if (error instanceof Error) {
|
|
2506
|
+
throw new PinataError(
|
|
2507
|
+
`Error processing createSignedURL: ${error.message}`
|
|
2508
|
+
);
|
|
2509
|
+
}
|
|
2510
|
+
throw new PinataError(
|
|
2511
|
+
"An unknown error occurred while getting signed url"
|
|
2512
|
+
);
|
|
2513
|
+
}
|
|
2514
|
+
const delay = Math.min(1e3 * Math.pow(2, attempt), 4e3);
|
|
2515
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
2500
2516
|
}
|
|
2501
|
-
throw new PinataError("An unknown error occurred while getting signed url");
|
|
2502
2517
|
}
|
|
2518
|
+
throw new PinataError("An unknown error occurred while getting signed url");
|
|
2503
2519
|
};
|
|
2504
2520
|
|
|
2505
2521
|
// src/core/functions/uploads/file.ts
|
|
@@ -2536,6 +2552,9 @@ var uploadFile = async (config, file, network, options) => {
|
|
|
2536
2552
|
if (options?.streamable) {
|
|
2537
2553
|
metadata += `,streamable ${btoa("true")}`;
|
|
2538
2554
|
}
|
|
2555
|
+
if (options?.car) {
|
|
2556
|
+
metadata += `,car ${btoa("true")}`;
|
|
2557
|
+
}
|
|
2539
2558
|
let updatedEndpoint = `${endpoint}/files`;
|
|
2540
2559
|
if (options?.url) {
|
|
2541
2560
|
updatedEndpoint = options.url;
|
|
@@ -2699,6 +2718,9 @@ var uploadFile = async (config, file, network, options) => {
|
|
|
2699
2718
|
if (options?.streamable) {
|
|
2700
2719
|
data.append("streamable", "true");
|
|
2701
2720
|
}
|
|
2721
|
+
if (options?.car) {
|
|
2722
|
+
data.append("car", "true");
|
|
2723
|
+
}
|
|
2702
2724
|
if (options?.url) {
|
|
2703
2725
|
try {
|
|
2704
2726
|
const request = await fetch(options.url, {
|
|
@@ -4233,6 +4255,10 @@ var UploadBuilder = class {
|
|
|
4233
4255
|
this.isStreamable = true;
|
|
4234
4256
|
return this;
|
|
4235
4257
|
}
|
|
4258
|
+
car() {
|
|
4259
|
+
this.carFormat = true;
|
|
4260
|
+
return this;
|
|
4261
|
+
}
|
|
4236
4262
|
peerAddress(peerAddresses) {
|
|
4237
4263
|
this.peerAddresses = peerAddresses;
|
|
4238
4264
|
return this;
|
|
@@ -4260,6 +4286,9 @@ var UploadBuilder = class {
|
|
|
4260
4286
|
if (this.peerAddresses) {
|
|
4261
4287
|
options.peerAddresses = this.peerAddresses;
|
|
4262
4288
|
}
|
|
4289
|
+
if (this.carFormat) {
|
|
4290
|
+
options.car = this.carFormat;
|
|
4291
|
+
}
|
|
4263
4292
|
this.args[this.args.length - 1] = options;
|
|
4264
4293
|
return this.uploadFunction(this.config, ...this.args).then(
|
|
4265
4294
|
onfulfilled,
|