pinata 2.5.2 → 2.5.3
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/index.d.mts +99 -1
- package/dist/index.d.ts +99 -1
- package/dist/index.js +639 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +632 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +69 -69
package/dist/index.mjs
CHANGED
|
@@ -3351,6 +3351,600 @@ var uploadCid = async (config, cid, options) => {
|
|
|
3351
3351
|
}
|
|
3352
3352
|
};
|
|
3353
3353
|
|
|
3354
|
+
// src/core/functions/x402/listPaymentInstructions.ts
|
|
3355
|
+
var listPaymentInstructions = async (config, options) => {
|
|
3356
|
+
if (!config) {
|
|
3357
|
+
throw new ValidationError("Pinata configuration is missing");
|
|
3358
|
+
}
|
|
3359
|
+
let headers;
|
|
3360
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
3361
|
+
headers = {
|
|
3362
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
3363
|
+
"Content-Type": "application/json",
|
|
3364
|
+
...config.customHeaders
|
|
3365
|
+
};
|
|
3366
|
+
} else {
|
|
3367
|
+
headers = {
|
|
3368
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
3369
|
+
"Content-Type": "application/json",
|
|
3370
|
+
Source: "sdk/listPaymentInstructions"
|
|
3371
|
+
};
|
|
3372
|
+
}
|
|
3373
|
+
const params = new URLSearchParams();
|
|
3374
|
+
if (options) {
|
|
3375
|
+
const { pageToken, limit, cid, name, id } = options;
|
|
3376
|
+
if (pageToken) params.append("pageToken", pageToken);
|
|
3377
|
+
if (limit !== void 0) params.append("limit", limit.toString());
|
|
3378
|
+
if (cid) params.append("cid", cid);
|
|
3379
|
+
if (name) params.append("name", name);
|
|
3380
|
+
if (id) params.append("id", id);
|
|
3381
|
+
}
|
|
3382
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
3383
|
+
if (config.endpointUrl) {
|
|
3384
|
+
endpoint = config.endpointUrl;
|
|
3385
|
+
}
|
|
3386
|
+
try {
|
|
3387
|
+
const request = await fetch(
|
|
3388
|
+
`${endpoint}/x402/payment_instructions?${params.toString()}`,
|
|
3389
|
+
{
|
|
3390
|
+
method: "GET",
|
|
3391
|
+
headers
|
|
3392
|
+
}
|
|
3393
|
+
);
|
|
3394
|
+
if (!request.ok) {
|
|
3395
|
+
const errorData = await request.text();
|
|
3396
|
+
if (request.status === 401 || request.status === 403) {
|
|
3397
|
+
throw new AuthenticationError(
|
|
3398
|
+
`Authentication failed: ${errorData}`,
|
|
3399
|
+
request.status,
|
|
3400
|
+
{
|
|
3401
|
+
error: errorData,
|
|
3402
|
+
code: "AUTH_ERROR",
|
|
3403
|
+
metadata: {
|
|
3404
|
+
requestUrl: request.url
|
|
3405
|
+
}
|
|
3406
|
+
}
|
|
3407
|
+
);
|
|
3408
|
+
}
|
|
3409
|
+
throw new NetworkError(`HTTP error: ${errorData}`, request.status, {
|
|
3410
|
+
error: errorData,
|
|
3411
|
+
code: "HTTP_ERROR",
|
|
3412
|
+
metadata: {
|
|
3413
|
+
requestUrl: request.url
|
|
3414
|
+
}
|
|
3415
|
+
});
|
|
3416
|
+
}
|
|
3417
|
+
const res = await request.json();
|
|
3418
|
+
return res;
|
|
3419
|
+
} catch (error) {
|
|
3420
|
+
if (error instanceof PinataError) {
|
|
3421
|
+
throw error;
|
|
3422
|
+
}
|
|
3423
|
+
if (error instanceof Error) {
|
|
3424
|
+
throw new PinataError(
|
|
3425
|
+
`Error processing listPaymentInstructions: ${error.message}`
|
|
3426
|
+
);
|
|
3427
|
+
}
|
|
3428
|
+
throw new PinataError(
|
|
3429
|
+
"An unknown error occurred while listing payment instructions"
|
|
3430
|
+
);
|
|
3431
|
+
}
|
|
3432
|
+
};
|
|
3433
|
+
|
|
3434
|
+
// src/core/functions/x402/createPaymentInstruction.ts
|
|
3435
|
+
var createPaymentInstruction = async (config, request) => {
|
|
3436
|
+
if (!config) {
|
|
3437
|
+
throw new ValidationError("Pinata configuration is missing");
|
|
3438
|
+
}
|
|
3439
|
+
if (!request.name) {
|
|
3440
|
+
throw new ValidationError("Payment instruction name is required");
|
|
3441
|
+
}
|
|
3442
|
+
if (!request.payment_requirements || request.payment_requirements.length === 0) {
|
|
3443
|
+
throw new ValidationError("At least one payment requirement is required");
|
|
3444
|
+
}
|
|
3445
|
+
let headers;
|
|
3446
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
3447
|
+
headers = {
|
|
3448
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
3449
|
+
"Content-Type": "application/json",
|
|
3450
|
+
...config.customHeaders
|
|
3451
|
+
};
|
|
3452
|
+
} else {
|
|
3453
|
+
headers = {
|
|
3454
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
3455
|
+
"Content-Type": "application/json",
|
|
3456
|
+
Source: "sdk/createPaymentInstruction"
|
|
3457
|
+
};
|
|
3458
|
+
}
|
|
3459
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
3460
|
+
if (config.endpointUrl) {
|
|
3461
|
+
endpoint = config.endpointUrl;
|
|
3462
|
+
}
|
|
3463
|
+
try {
|
|
3464
|
+
const requestObj = await fetch(`${endpoint}/x402/payment_instructions`, {
|
|
3465
|
+
method: "POST",
|
|
3466
|
+
headers,
|
|
3467
|
+
body: JSON.stringify(request)
|
|
3468
|
+
});
|
|
3469
|
+
if (!requestObj.ok) {
|
|
3470
|
+
const errorData = await requestObj.text();
|
|
3471
|
+
if (requestObj.status === 401 || requestObj.status === 403) {
|
|
3472
|
+
throw new AuthenticationError(
|
|
3473
|
+
`Authentication failed: ${errorData}`,
|
|
3474
|
+
requestObj.status,
|
|
3475
|
+
{
|
|
3476
|
+
error: errorData,
|
|
3477
|
+
code: "AUTH_ERROR",
|
|
3478
|
+
metadata: {
|
|
3479
|
+
requestUrl: requestObj.url
|
|
3480
|
+
}
|
|
3481
|
+
}
|
|
3482
|
+
);
|
|
3483
|
+
}
|
|
3484
|
+
throw new NetworkError(`HTTP error: ${errorData}`, requestObj.status, {
|
|
3485
|
+
error: errorData,
|
|
3486
|
+
code: "HTTP_ERROR",
|
|
3487
|
+
metadata: {
|
|
3488
|
+
requestUrl: requestObj.url
|
|
3489
|
+
}
|
|
3490
|
+
});
|
|
3491
|
+
}
|
|
3492
|
+
const res = await requestObj.json();
|
|
3493
|
+
return res;
|
|
3494
|
+
} catch (error) {
|
|
3495
|
+
if (error instanceof PinataError) {
|
|
3496
|
+
throw error;
|
|
3497
|
+
}
|
|
3498
|
+
if (error instanceof Error) {
|
|
3499
|
+
throw new PinataError(
|
|
3500
|
+
`Error processing createPaymentInstruction: ${error.message}`
|
|
3501
|
+
);
|
|
3502
|
+
}
|
|
3503
|
+
throw new PinataError(
|
|
3504
|
+
"An unknown error occurred while creating payment instruction"
|
|
3505
|
+
);
|
|
3506
|
+
}
|
|
3507
|
+
};
|
|
3508
|
+
|
|
3509
|
+
// src/core/functions/x402/getPaymentInstruction.ts
|
|
3510
|
+
var getPaymentInstruction = async (config, id) => {
|
|
3511
|
+
if (!config) {
|
|
3512
|
+
throw new ValidationError("Pinata configuration is missing");
|
|
3513
|
+
}
|
|
3514
|
+
if (!id) {
|
|
3515
|
+
throw new ValidationError("Payment instruction ID is required");
|
|
3516
|
+
}
|
|
3517
|
+
let headers;
|
|
3518
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
3519
|
+
headers = {
|
|
3520
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
3521
|
+
"Content-Type": "application/json",
|
|
3522
|
+
...config.customHeaders
|
|
3523
|
+
};
|
|
3524
|
+
} else {
|
|
3525
|
+
headers = {
|
|
3526
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
3527
|
+
"Content-Type": "application/json",
|
|
3528
|
+
Source: "sdk/getPaymentInstruction"
|
|
3529
|
+
};
|
|
3530
|
+
}
|
|
3531
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
3532
|
+
if (config.endpointUrl) {
|
|
3533
|
+
endpoint = config.endpointUrl;
|
|
3534
|
+
}
|
|
3535
|
+
try {
|
|
3536
|
+
const request = await fetch(`${endpoint}/x402/payment_instructions/${id}`, {
|
|
3537
|
+
method: "GET",
|
|
3538
|
+
headers
|
|
3539
|
+
});
|
|
3540
|
+
if (!request.ok) {
|
|
3541
|
+
const errorData = await request.text();
|
|
3542
|
+
if (request.status === 401 || request.status === 403) {
|
|
3543
|
+
throw new AuthenticationError(
|
|
3544
|
+
`Authentication failed: ${errorData}`,
|
|
3545
|
+
request.status,
|
|
3546
|
+
{
|
|
3547
|
+
error: errorData,
|
|
3548
|
+
code: "AUTH_ERROR",
|
|
3549
|
+
metadata: {
|
|
3550
|
+
requestUrl: request.url
|
|
3551
|
+
}
|
|
3552
|
+
}
|
|
3553
|
+
);
|
|
3554
|
+
}
|
|
3555
|
+
throw new NetworkError(`HTTP error: ${errorData}`, request.status, {
|
|
3556
|
+
error: errorData,
|
|
3557
|
+
code: "HTTP_ERROR",
|
|
3558
|
+
metadata: {
|
|
3559
|
+
requestUrl: request.url
|
|
3560
|
+
}
|
|
3561
|
+
});
|
|
3562
|
+
}
|
|
3563
|
+
const res = await request.json();
|
|
3564
|
+
return res;
|
|
3565
|
+
} catch (error) {
|
|
3566
|
+
if (error instanceof PinataError) {
|
|
3567
|
+
throw error;
|
|
3568
|
+
}
|
|
3569
|
+
if (error instanceof Error) {
|
|
3570
|
+
throw new PinataError(
|
|
3571
|
+
`Error processing getPaymentInstruction: ${error.message}`
|
|
3572
|
+
);
|
|
3573
|
+
}
|
|
3574
|
+
throw new PinataError(
|
|
3575
|
+
"An unknown error occurred while getting payment instruction"
|
|
3576
|
+
);
|
|
3577
|
+
}
|
|
3578
|
+
};
|
|
3579
|
+
|
|
3580
|
+
// src/core/functions/x402/updatePaymentInstruction.ts
|
|
3581
|
+
var updatePaymentInstruction = async (config, id, request) => {
|
|
3582
|
+
if (!config) {
|
|
3583
|
+
throw new ValidationError("Pinata configuration is missing");
|
|
3584
|
+
}
|
|
3585
|
+
if (!id) {
|
|
3586
|
+
throw new ValidationError("Payment instruction ID is required");
|
|
3587
|
+
}
|
|
3588
|
+
let headers;
|
|
3589
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
3590
|
+
headers = {
|
|
3591
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
3592
|
+
"Content-Type": "application/json",
|
|
3593
|
+
...config.customHeaders
|
|
3594
|
+
};
|
|
3595
|
+
} else {
|
|
3596
|
+
headers = {
|
|
3597
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
3598
|
+
"Content-Type": "application/json",
|
|
3599
|
+
Source: "sdk/updatePaymentInstruction"
|
|
3600
|
+
};
|
|
3601
|
+
}
|
|
3602
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
3603
|
+
if (config.endpointUrl) {
|
|
3604
|
+
endpoint = config.endpointUrl;
|
|
3605
|
+
}
|
|
3606
|
+
try {
|
|
3607
|
+
const requestObj = await fetch(
|
|
3608
|
+
`${endpoint}/x402/payment_instructions/${id}`,
|
|
3609
|
+
{
|
|
3610
|
+
method: "PATCH",
|
|
3611
|
+
headers,
|
|
3612
|
+
body: JSON.stringify(request)
|
|
3613
|
+
}
|
|
3614
|
+
);
|
|
3615
|
+
if (!requestObj.ok) {
|
|
3616
|
+
const errorData = await requestObj.text();
|
|
3617
|
+
if (requestObj.status === 401 || requestObj.status === 403) {
|
|
3618
|
+
throw new AuthenticationError(
|
|
3619
|
+
`Authentication failed: ${errorData}`,
|
|
3620
|
+
requestObj.status,
|
|
3621
|
+
{
|
|
3622
|
+
error: errorData,
|
|
3623
|
+
code: "AUTH_ERROR",
|
|
3624
|
+
metadata: {
|
|
3625
|
+
requestUrl: requestObj.url
|
|
3626
|
+
}
|
|
3627
|
+
}
|
|
3628
|
+
);
|
|
3629
|
+
}
|
|
3630
|
+
throw new NetworkError(`HTTP error: ${errorData}`, requestObj.status, {
|
|
3631
|
+
error: errorData,
|
|
3632
|
+
code: "HTTP_ERROR",
|
|
3633
|
+
metadata: {
|
|
3634
|
+
requestUrl: requestObj.url
|
|
3635
|
+
}
|
|
3636
|
+
});
|
|
3637
|
+
}
|
|
3638
|
+
const res = await requestObj.json();
|
|
3639
|
+
return res;
|
|
3640
|
+
} catch (error) {
|
|
3641
|
+
if (error instanceof PinataError) {
|
|
3642
|
+
throw error;
|
|
3643
|
+
}
|
|
3644
|
+
if (error instanceof Error) {
|
|
3645
|
+
throw new PinataError(
|
|
3646
|
+
`Error processing updatePaymentInstruction: ${error.message}`
|
|
3647
|
+
);
|
|
3648
|
+
}
|
|
3649
|
+
throw new PinataError(
|
|
3650
|
+
"An unknown error occurred while updating payment instruction"
|
|
3651
|
+
);
|
|
3652
|
+
}
|
|
3653
|
+
};
|
|
3654
|
+
|
|
3655
|
+
// src/core/functions/x402/deletePaymentInstruction.ts
|
|
3656
|
+
var deletePaymentInstruction = async (config, id) => {
|
|
3657
|
+
if (!config) {
|
|
3658
|
+
throw new ValidationError("Pinata configuration is missing");
|
|
3659
|
+
}
|
|
3660
|
+
if (!id) {
|
|
3661
|
+
throw new ValidationError("Payment instruction ID is required");
|
|
3662
|
+
}
|
|
3663
|
+
let headers;
|
|
3664
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
3665
|
+
headers = {
|
|
3666
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
3667
|
+
"Content-Type": "application/json",
|
|
3668
|
+
...config.customHeaders
|
|
3669
|
+
};
|
|
3670
|
+
} else {
|
|
3671
|
+
headers = {
|
|
3672
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
3673
|
+
"Content-Type": "application/json",
|
|
3674
|
+
Source: "sdk/deletePaymentInstruction"
|
|
3675
|
+
};
|
|
3676
|
+
}
|
|
3677
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
3678
|
+
if (config.endpointUrl) {
|
|
3679
|
+
endpoint = config.endpointUrl;
|
|
3680
|
+
}
|
|
3681
|
+
try {
|
|
3682
|
+
const request = await fetch(`${endpoint}/x402/payment_instructions/${id}`, {
|
|
3683
|
+
method: "DELETE",
|
|
3684
|
+
headers
|
|
3685
|
+
});
|
|
3686
|
+
if (!request.ok) {
|
|
3687
|
+
const errorData = await request.text();
|
|
3688
|
+
if (request.status === 401 || request.status === 403) {
|
|
3689
|
+
throw new AuthenticationError(
|
|
3690
|
+
`Authentication failed: ${errorData}`,
|
|
3691
|
+
request.status,
|
|
3692
|
+
{
|
|
3693
|
+
error: errorData,
|
|
3694
|
+
code: "AUTH_ERROR",
|
|
3695
|
+
metadata: {
|
|
3696
|
+
requestUrl: request.url
|
|
3697
|
+
}
|
|
3698
|
+
}
|
|
3699
|
+
);
|
|
3700
|
+
}
|
|
3701
|
+
throw new NetworkError(`HTTP error: ${errorData}`, request.status, {
|
|
3702
|
+
error: errorData,
|
|
3703
|
+
code: "HTTP_ERROR",
|
|
3704
|
+
metadata: {
|
|
3705
|
+
requestUrl: request.url
|
|
3706
|
+
}
|
|
3707
|
+
});
|
|
3708
|
+
}
|
|
3709
|
+
const res = await request.json();
|
|
3710
|
+
return res;
|
|
3711
|
+
} catch (error) {
|
|
3712
|
+
if (error instanceof PinataError) {
|
|
3713
|
+
throw error;
|
|
3714
|
+
}
|
|
3715
|
+
if (error instanceof Error) {
|
|
3716
|
+
throw new PinataError(
|
|
3717
|
+
`Error processing deletePaymentInstruction: ${error.message}`
|
|
3718
|
+
);
|
|
3719
|
+
}
|
|
3720
|
+
throw new PinataError(
|
|
3721
|
+
"An unknown error occurred while deleting payment instruction"
|
|
3722
|
+
);
|
|
3723
|
+
}
|
|
3724
|
+
};
|
|
3725
|
+
|
|
3726
|
+
// src/core/functions/x402/listCids.ts
|
|
3727
|
+
var listCids = async (config, paymentInstructionId, options) => {
|
|
3728
|
+
if (!config) {
|
|
3729
|
+
throw new ValidationError("Pinata configuration is missing");
|
|
3730
|
+
}
|
|
3731
|
+
if (!paymentInstructionId) {
|
|
3732
|
+
throw new ValidationError("Payment instruction ID is required");
|
|
3733
|
+
}
|
|
3734
|
+
let headers;
|
|
3735
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
3736
|
+
headers = {
|
|
3737
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
3738
|
+
"Content-Type": "application/json",
|
|
3739
|
+
...config.customHeaders
|
|
3740
|
+
};
|
|
3741
|
+
} else {
|
|
3742
|
+
headers = {
|
|
3743
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
3744
|
+
"Content-Type": "application/json",
|
|
3745
|
+
Source: "sdk/listCids"
|
|
3746
|
+
};
|
|
3747
|
+
}
|
|
3748
|
+
const params = new URLSearchParams();
|
|
3749
|
+
if (options) {
|
|
3750
|
+
const { pageToken, limit } = options;
|
|
3751
|
+
if (pageToken) params.append("pageToken", pageToken);
|
|
3752
|
+
if (limit !== void 0) params.append("limit", limit.toString());
|
|
3753
|
+
}
|
|
3754
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
3755
|
+
if (config.endpointUrl) {
|
|
3756
|
+
endpoint = config.endpointUrl;
|
|
3757
|
+
}
|
|
3758
|
+
try {
|
|
3759
|
+
const request = await fetch(
|
|
3760
|
+
`${endpoint}/x402/payment_instructions/${paymentInstructionId}/cids?${params.toString()}`,
|
|
3761
|
+
{
|
|
3762
|
+
method: "GET",
|
|
3763
|
+
headers
|
|
3764
|
+
}
|
|
3765
|
+
);
|
|
3766
|
+
if (!request.ok) {
|
|
3767
|
+
const errorData = await request.text();
|
|
3768
|
+
if (request.status === 401 || request.status === 403) {
|
|
3769
|
+
throw new AuthenticationError(
|
|
3770
|
+
`Authentication failed: ${errorData}`,
|
|
3771
|
+
request.status,
|
|
3772
|
+
{
|
|
3773
|
+
error: errorData,
|
|
3774
|
+
code: "AUTH_ERROR",
|
|
3775
|
+
metadata: {
|
|
3776
|
+
requestUrl: request.url
|
|
3777
|
+
}
|
|
3778
|
+
}
|
|
3779
|
+
);
|
|
3780
|
+
}
|
|
3781
|
+
throw new NetworkError(`HTTP error: ${errorData}`, request.status, {
|
|
3782
|
+
error: errorData,
|
|
3783
|
+
code: "HTTP_ERROR",
|
|
3784
|
+
metadata: {
|
|
3785
|
+
requestUrl: request.url
|
|
3786
|
+
}
|
|
3787
|
+
});
|
|
3788
|
+
}
|
|
3789
|
+
const res = await request.json();
|
|
3790
|
+
return res;
|
|
3791
|
+
} catch (error) {
|
|
3792
|
+
if (error instanceof PinataError) {
|
|
3793
|
+
throw error;
|
|
3794
|
+
}
|
|
3795
|
+
if (error instanceof Error) {
|
|
3796
|
+
throw new PinataError(`Error processing listCids: ${error.message}`);
|
|
3797
|
+
}
|
|
3798
|
+
throw new PinataError("An unknown error occurred while listing CIDs");
|
|
3799
|
+
}
|
|
3800
|
+
};
|
|
3801
|
+
|
|
3802
|
+
// src/core/functions/x402/addCid.ts
|
|
3803
|
+
var addCid = async (config, paymentInstructionId, cid) => {
|
|
3804
|
+
if (!config) {
|
|
3805
|
+
throw new ValidationError("Pinata configuration is missing");
|
|
3806
|
+
}
|
|
3807
|
+
if (!paymentInstructionId) {
|
|
3808
|
+
throw new ValidationError("Payment instruction ID is required");
|
|
3809
|
+
}
|
|
3810
|
+
if (!cid) {
|
|
3811
|
+
throw new ValidationError("CID is required");
|
|
3812
|
+
}
|
|
3813
|
+
let headers;
|
|
3814
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
3815
|
+
headers = {
|
|
3816
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
3817
|
+
"Content-Type": "application/json",
|
|
3818
|
+
...config.customHeaders
|
|
3819
|
+
};
|
|
3820
|
+
} else {
|
|
3821
|
+
headers = {
|
|
3822
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
3823
|
+
"Content-Type": "application/json",
|
|
3824
|
+
Source: "sdk/addCid"
|
|
3825
|
+
};
|
|
3826
|
+
}
|
|
3827
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
3828
|
+
if (config.endpointUrl) {
|
|
3829
|
+
endpoint = config.endpointUrl;
|
|
3830
|
+
}
|
|
3831
|
+
try {
|
|
3832
|
+
const request = await fetch(
|
|
3833
|
+
`${endpoint}/x402/payment_instructions/${paymentInstructionId}/cids/${cid}`,
|
|
3834
|
+
{
|
|
3835
|
+
method: "PUT",
|
|
3836
|
+
headers
|
|
3837
|
+
}
|
|
3838
|
+
);
|
|
3839
|
+
if (!request.ok) {
|
|
3840
|
+
const errorData = await request.text();
|
|
3841
|
+
if (request.status === 401 || request.status === 403) {
|
|
3842
|
+
throw new AuthenticationError(
|
|
3843
|
+
`Authentication failed: ${errorData}`,
|
|
3844
|
+
request.status,
|
|
3845
|
+
{
|
|
3846
|
+
error: errorData,
|
|
3847
|
+
code: "AUTH_ERROR",
|
|
3848
|
+
metadata: {
|
|
3849
|
+
requestUrl: request.url
|
|
3850
|
+
}
|
|
3851
|
+
}
|
|
3852
|
+
);
|
|
3853
|
+
}
|
|
3854
|
+
throw new NetworkError(`HTTP error: ${errorData}`, request.status, {
|
|
3855
|
+
error: errorData,
|
|
3856
|
+
code: "HTTP_ERROR",
|
|
3857
|
+
metadata: {
|
|
3858
|
+
requestUrl: request.url
|
|
3859
|
+
}
|
|
3860
|
+
});
|
|
3861
|
+
}
|
|
3862
|
+
const res = await request.json();
|
|
3863
|
+
return res;
|
|
3864
|
+
} catch (error) {
|
|
3865
|
+
if (error instanceof PinataError) {
|
|
3866
|
+
throw error;
|
|
3867
|
+
}
|
|
3868
|
+
if (error instanceof Error) {
|
|
3869
|
+
throw new PinataError(`Error processing addCid: ${error.message}`);
|
|
3870
|
+
}
|
|
3871
|
+
throw new PinataError("An unknown error occurred while adding CID");
|
|
3872
|
+
}
|
|
3873
|
+
};
|
|
3874
|
+
|
|
3875
|
+
// src/core/functions/x402/removeCid.ts
|
|
3876
|
+
var removeCid = async (config, paymentInstructionId, cid) => {
|
|
3877
|
+
if (!config) {
|
|
3878
|
+
throw new ValidationError("Pinata configuration is missing");
|
|
3879
|
+
}
|
|
3880
|
+
if (!paymentInstructionId) {
|
|
3881
|
+
throw new ValidationError("Payment instruction ID is required");
|
|
3882
|
+
}
|
|
3883
|
+
if (!cid) {
|
|
3884
|
+
throw new ValidationError("CID is required");
|
|
3885
|
+
}
|
|
3886
|
+
let headers;
|
|
3887
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
3888
|
+
headers = {
|
|
3889
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
3890
|
+
"Content-Type": "application/json",
|
|
3891
|
+
...config.customHeaders
|
|
3892
|
+
};
|
|
3893
|
+
} else {
|
|
3894
|
+
headers = {
|
|
3895
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
3896
|
+
"Content-Type": "application/json",
|
|
3897
|
+
Source: "sdk/removeCid"
|
|
3898
|
+
};
|
|
3899
|
+
}
|
|
3900
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
3901
|
+
if (config.endpointUrl) {
|
|
3902
|
+
endpoint = config.endpointUrl;
|
|
3903
|
+
}
|
|
3904
|
+
try {
|
|
3905
|
+
const request = await fetch(
|
|
3906
|
+
`${endpoint}/x402/payment_instructions/${paymentInstructionId}/cids/${cid}`,
|
|
3907
|
+
{
|
|
3908
|
+
method: "DELETE",
|
|
3909
|
+
headers
|
|
3910
|
+
}
|
|
3911
|
+
);
|
|
3912
|
+
if (!request.ok) {
|
|
3913
|
+
const errorData = await request.text();
|
|
3914
|
+
if (request.status === 401 || request.status === 403) {
|
|
3915
|
+
throw new AuthenticationError(
|
|
3916
|
+
`Authentication failed: ${errorData}`,
|
|
3917
|
+
request.status,
|
|
3918
|
+
{
|
|
3919
|
+
error: errorData,
|
|
3920
|
+
code: "AUTH_ERROR",
|
|
3921
|
+
metadata: {
|
|
3922
|
+
requestUrl: request.url
|
|
3923
|
+
}
|
|
3924
|
+
}
|
|
3925
|
+
);
|
|
3926
|
+
}
|
|
3927
|
+
throw new NetworkError(`HTTP error: ${errorData}`, request.status, {
|
|
3928
|
+
error: errorData,
|
|
3929
|
+
code: "HTTP_ERROR",
|
|
3930
|
+
metadata: {
|
|
3931
|
+
requestUrl: request.url
|
|
3932
|
+
}
|
|
3933
|
+
});
|
|
3934
|
+
}
|
|
3935
|
+
const res = await request.json();
|
|
3936
|
+
return res;
|
|
3937
|
+
} catch (error) {
|
|
3938
|
+
if (error instanceof PinataError) {
|
|
3939
|
+
throw error;
|
|
3940
|
+
}
|
|
3941
|
+
if (error instanceof Error) {
|
|
3942
|
+
throw new PinataError(`Error processing removeCid: ${error.message}`);
|
|
3943
|
+
}
|
|
3944
|
+
throw new PinataError("An unknown error occurred while removing CID");
|
|
3945
|
+
}
|
|
3946
|
+
};
|
|
3947
|
+
|
|
3354
3948
|
// src/core/classes/analytics/Analytics.ts
|
|
3355
3949
|
var Analytics = class {
|
|
3356
3950
|
constructor(config) {
|
|
@@ -4688,6 +5282,40 @@ var Signatures = class {
|
|
|
4688
5282
|
}
|
|
4689
5283
|
};
|
|
4690
5284
|
|
|
5285
|
+
// src/core/classes/x402/X402.ts
|
|
5286
|
+
var X402 = class {
|
|
5287
|
+
constructor(config) {
|
|
5288
|
+
this.config = formatConfig(config);
|
|
5289
|
+
}
|
|
5290
|
+
updateConfig(newConfig) {
|
|
5291
|
+
this.config = newConfig;
|
|
5292
|
+
}
|
|
5293
|
+
listPaymentInstructions(options) {
|
|
5294
|
+
return listPaymentInstructions(this.config, options);
|
|
5295
|
+
}
|
|
5296
|
+
createPaymentInstruction(request) {
|
|
5297
|
+
return createPaymentInstruction(this.config, request);
|
|
5298
|
+
}
|
|
5299
|
+
getPaymentInstruction(id) {
|
|
5300
|
+
return getPaymentInstruction(this.config, id);
|
|
5301
|
+
}
|
|
5302
|
+
updatePaymentInstruction(id, request) {
|
|
5303
|
+
return updatePaymentInstruction(this.config, id, request);
|
|
5304
|
+
}
|
|
5305
|
+
deletePaymentInstruction(id) {
|
|
5306
|
+
return deletePaymentInstruction(this.config, id);
|
|
5307
|
+
}
|
|
5308
|
+
listCids(paymentInstructionId, options) {
|
|
5309
|
+
return listCids(this.config, paymentInstructionId, options);
|
|
5310
|
+
}
|
|
5311
|
+
addCid(paymentInstructionId, cid) {
|
|
5312
|
+
return addCid(this.config, paymentInstructionId, cid);
|
|
5313
|
+
}
|
|
5314
|
+
removeCid(paymentInstructionId, cid) {
|
|
5315
|
+
return removeCid(this.config, paymentInstructionId, cid);
|
|
5316
|
+
}
|
|
5317
|
+
};
|
|
5318
|
+
|
|
4691
5319
|
// src/core/pinataSDK.ts
|
|
4692
5320
|
var PinataSDK = class {
|
|
4693
5321
|
constructor(config) {
|
|
@@ -4699,6 +5327,7 @@ var PinataSDK = class {
|
|
|
4699
5327
|
this.groups = new Groups(this.config);
|
|
4700
5328
|
this.analytics = new Analytics(this.config);
|
|
4701
5329
|
this.signatures = new Signatures(this.config);
|
|
5330
|
+
this.x402 = new X402(this.config);
|
|
4702
5331
|
}
|
|
4703
5332
|
setNewHeaders(headers) {
|
|
4704
5333
|
if (!this.config) {
|
|
@@ -4712,6 +5341,7 @@ var PinataSDK = class {
|
|
|
4712
5341
|
this.groups.updateConfig(this.config);
|
|
4713
5342
|
this.analytics.updateConfig(this.config);
|
|
4714
5343
|
this.signatures.updateConfig(this.config);
|
|
5344
|
+
this.x402.updateConfig(this.config);
|
|
4715
5345
|
}
|
|
4716
5346
|
setNewJwt(jwt) {
|
|
4717
5347
|
if (!this.config) {
|
|
@@ -4725,12 +5355,13 @@ var PinataSDK = class {
|
|
|
4725
5355
|
this.groups.updateConfig(this.config);
|
|
4726
5356
|
this.analytics.updateConfig(this.config);
|
|
4727
5357
|
this.signatures.updateConfig(this.config);
|
|
5358
|
+
this.x402.updateConfig(this.config);
|
|
4728
5359
|
}
|
|
4729
5360
|
testAuthentication() {
|
|
4730
5361
|
return testAuthentication(this.config);
|
|
4731
5362
|
}
|
|
4732
5363
|
};
|
|
4733
5364
|
|
|
4734
|
-
export { PinataSDK, addToGroup, analyticsDateInterval, analyticsTopUsage, convertIPFSUrl, createAccessLink, createGroup, createKey, createSignedUploadURL, deleteFile, deleteFileVectors, deleteGroup, deletePinRequest, deleteSwap, getCid, getGroup, listFiles, listGroups, listKeys, pinnedFileCount, queue, removeFromGroup, revokeKeys, swapCid, swapHistory, testAuthentication, totalStorageUsage, updateFile, updateGroup, uploadBase64, uploadCid, uploadFile, uploadFileArray, uploadJson, uploadUrl, vectorizeFile, vectorizeQuery };
|
|
5365
|
+
export { PinataSDK, addCid, addToGroup, analyticsDateInterval, analyticsTopUsage, convertIPFSUrl, createAccessLink, createGroup, createKey, createPaymentInstruction, createSignedUploadURL, deleteFile, deleteFileVectors, deleteGroup, deletePaymentInstruction, deletePinRequest, deleteSwap, getCid, getGroup, getPaymentInstruction, listCids, listFiles, listGroups, listKeys, listPaymentInstructions, pinnedFileCount, queue, removeCid, removeFromGroup, revokeKeys, swapCid, swapHistory, testAuthentication, totalStorageUsage, updateFile, updateGroup, updatePaymentInstruction, uploadBase64, uploadCid, uploadFile, uploadFileArray, uploadJson, uploadUrl, vectorizeFile, vectorizeQuery };
|
|
4735
5366
|
//# sourceMappingURL=index.mjs.map
|
|
4736
5367
|
//# sourceMappingURL=index.mjs.map
|