pinata 2.5.2 → 2.5.4

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.mjs CHANGED
@@ -884,9 +884,9 @@ var updateFile = async (config, options, privacy) => {
884
884
  if (!config) {
885
885
  throw new ValidationError("Pinata configuration is missing");
886
886
  }
887
- if (!options.name && (!options.keyvalues || Object.keys(options.keyvalues).length === 0)) {
887
+ if (!options.name && (!options.keyvalues || Object.keys(options.keyvalues).length === 0) && options.expires_at === void 0) {
888
888
  throw new ValidationError(
889
- "At least one of 'name' or 'keyvalues' must be provided"
889
+ "At least one of 'name', 'keyvalues', or 'expires_at' must be provided"
890
890
  );
891
891
  }
892
892
  const data = {};
@@ -896,6 +896,9 @@ var updateFile = async (config, options, privacy) => {
896
896
  if (options.keyvalues && Object.keys(options.keyvalues).length > 0) {
897
897
  data.keyvalues = options.keyvalues;
898
898
  }
899
+ if (options.expires_at !== void 0) {
900
+ data.expires_at = options.expires_at;
901
+ }
899
902
  const body = JSON.stringify(data);
900
903
  let headers;
901
904
  if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
@@ -2558,6 +2561,9 @@ var uploadFile = async (config, file, network, options) => {
2558
2561
  if (options?.cid_version !== void 0) {
2559
2562
  metadata += `,cid_version ${btoa(options.cid_version)}`;
2560
2563
  }
2564
+ if (options?.expires_at !== void 0) {
2565
+ metadata += `,expires_at ${btoa(options.expires_at.toString())}`;
2566
+ }
2561
2567
  let updatedEndpoint = `${endpoint}/files`;
2562
2568
  if (options?.url) {
2563
2569
  updatedEndpoint = options.url;
@@ -2734,6 +2740,9 @@ var uploadFile = async (config, file, network, options) => {
2734
2740
  if (options?.cid_version !== void 0) {
2735
2741
  data.append("cid_version", options.cid_version.toString());
2736
2742
  }
2743
+ if (options?.expires_at !== void 0) {
2744
+ data.append("expires_at", options.expires_at.toString());
2745
+ }
2737
2746
  if (options?.url) {
2738
2747
  try {
2739
2748
  const url = new URL(options.url);
@@ -3351,156 +3360,750 @@ var uploadCid = async (config, cid, options) => {
3351
3360
  }
3352
3361
  };
3353
3362
 
3354
- // src/core/classes/analytics/Analytics.ts
3355
- var Analytics = class {
3356
- constructor(config) {
3357
- this.config = formatConfig(config);
3358
- this.requests = new AnalyticsRequests(this.config);
3359
- this.bandwidth = new AnalyticsBandwidth(this.config);
3360
- }
3361
- updateConfig(newConfig) {
3362
- this.config = newConfig;
3363
- this.requests.updateConfig(newConfig);
3364
- this.bandwidth.updateConfig(newConfig);
3365
- }
3366
- summary(options) {
3367
- return new TimeIntervalAnalyticsBuilder(
3368
- this.config,
3369
- options.domain,
3370
- options.start,
3371
- options.end,
3372
- options.interval
3373
- );
3363
+ // src/core/functions/x402/listPaymentInstructions.ts
3364
+ var listPaymentInstructions = async (config, options) => {
3365
+ if (!config) {
3366
+ throw new ValidationError("Pinata configuration is missing");
3374
3367
  }
3375
- };
3376
-
3377
- // src/core/classes/analytics/utils.ts
3378
- var calculateDates = (days) => {
3379
- const end = /* @__PURE__ */ new Date();
3380
- const start = /* @__PURE__ */ new Date();
3381
- start.setDate(start.getDate() - days);
3382
- return {
3383
- start: start.toISOString().split("T")[0],
3384
- end: end.toISOString().split("T")[0]
3385
- };
3386
- };
3387
-
3388
- // src/core/classes/analytics/AnalyticsFilter.ts
3389
- var AnalyticsFilter = class {
3390
- constructor(config, domain, start, end) {
3391
- this.config = config;
3392
- this.query = {
3393
- gateway_domain: domain,
3394
- start_date: start,
3395
- end_date: end,
3396
- sort_by: "requests",
3397
- // Will be overridden in child classes
3398
- attribute: "cid"
3368
+ let headers;
3369
+ if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
3370
+ headers = {
3371
+ Authorization: `Bearer ${config.pinataJwt}`,
3372
+ "Content-Type": "application/json",
3373
+ ...config.customHeaders
3374
+ };
3375
+ } else {
3376
+ headers = {
3377
+ Authorization: `Bearer ${config.pinataJwt}`,
3378
+ "Content-Type": "application/json",
3379
+ Source: "sdk/listPaymentInstructions"
3399
3380
  };
3400
3381
  }
3401
- cid(cid) {
3402
- this.query.attribute = "cid";
3403
- if (cid) {
3404
- this.query.cid = cid;
3405
- }
3406
- return this;
3407
- }
3408
- fileName(fileName) {
3409
- this.query.attribute = "file_name";
3410
- if (fileName) {
3411
- this.query.file_name = fileName;
3412
- }
3413
- return this;
3382
+ const params = new URLSearchParams();
3383
+ if (options) {
3384
+ const { pageToken, limit, cid, name, id } = options;
3385
+ if (pageToken) params.append("pageToken", pageToken);
3386
+ if (limit !== void 0) params.append("limit", limit.toString());
3387
+ if (cid) params.append("cid", cid);
3388
+ if (name) params.append("name", name);
3389
+ if (id) params.append("id", id);
3414
3390
  }
3415
- userAgent(userAgent) {
3416
- this.query.attribute = "user_agent";
3417
- if (userAgent) {
3418
- this.query.user_agent = userAgent;
3419
- }
3420
- return this;
3391
+ let endpoint = "https://api.pinata.cloud/v3";
3392
+ if (config.endpointUrl) {
3393
+ endpoint = config.endpointUrl;
3421
3394
  }
3422
- country(country) {
3423
- this.query.attribute = "country";
3424
- if (country) {
3425
- this.query.country = country;
3395
+ try {
3396
+ const request = await fetch(
3397
+ `${endpoint}/x402/payment_instructions?${params.toString()}`,
3398
+ {
3399
+ method: "GET",
3400
+ headers
3401
+ }
3402
+ );
3403
+ if (!request.ok) {
3404
+ const errorData = await request.text();
3405
+ if (request.status === 401 || request.status === 403) {
3406
+ throw new AuthenticationError(
3407
+ `Authentication failed: ${errorData}`,
3408
+ request.status,
3409
+ {
3410
+ error: errorData,
3411
+ code: "AUTH_ERROR",
3412
+ metadata: {
3413
+ requestUrl: request.url
3414
+ }
3415
+ }
3416
+ );
3417
+ }
3418
+ throw new NetworkError(`HTTP error: ${errorData}`, request.status, {
3419
+ error: errorData,
3420
+ code: "HTTP_ERROR",
3421
+ metadata: {
3422
+ requestUrl: request.url
3423
+ }
3424
+ });
3426
3425
  }
3427
- return this;
3428
- }
3429
- region(region) {
3430
- this.query.attribute = "region";
3431
- if (region) {
3432
- this.query.region = region;
3426
+ const res = await request.json();
3427
+ return res;
3428
+ } catch (error) {
3429
+ if (error instanceof PinataError) {
3430
+ throw error;
3433
3431
  }
3434
- return this;
3435
- }
3436
- referer(referer) {
3437
- this.query.attribute = "referer";
3438
- if (referer) {
3439
- this.query.referer = referer;
3432
+ if (error instanceof Error) {
3433
+ throw new PinataError(
3434
+ `Error processing listPaymentInstructions: ${error.message}`
3435
+ );
3440
3436
  }
3441
- return this;
3442
- }
3443
- limit(limit) {
3444
- this.query.limit = limit;
3445
- return this;
3446
- }
3447
- sort(order) {
3448
- this.query.sort_order = order;
3449
- return this;
3450
- }
3451
- days(numberOfDays) {
3452
- const { start, end } = calculateDates(numberOfDays);
3453
- this.query.start_date = start;
3454
- this.query.end_date = end;
3455
- return this;
3456
- }
3457
- then(onfulfilled, onrejected) {
3458
- return analyticsTopUsage(this.config, this.query).then(
3459
- onfulfilled,
3460
- onrejected
3437
+ throw new PinataError(
3438
+ "An unknown error occurred while listing payment instructions"
3461
3439
  );
3462
3440
  }
3463
3441
  };
3464
3442
 
3465
- // src/core/classes/analytics/AnalyticsBandwidth.ts
3466
- var AnalyticsBandwidth = class extends AnalyticsFilter {
3467
- constructor(config) {
3468
- super(config, "", "", "");
3469
- this.query.sort_by = "bandwidth";
3443
+ // src/core/functions/x402/createPaymentInstruction.ts
3444
+ var createPaymentInstruction = async (config, request) => {
3445
+ if (!config) {
3446
+ throw new ValidationError("Pinata configuration is missing");
3470
3447
  }
3471
- updateConfig(newConfig) {
3472
- this.config = newConfig;
3448
+ if (!request.name) {
3449
+ throw new ValidationError("Payment instruction name is required");
3473
3450
  }
3474
- customDates(start, end) {
3475
- if (start) this.query.start_date = start;
3476
- if (end) this.query.end_date = end;
3477
- return this;
3451
+ if (!request.payment_requirements || request.payment_requirements.length === 0) {
3452
+ throw new ValidationError("At least one payment requirement is required");
3478
3453
  }
3479
- from(domain) {
3480
- this.query.gateway_domain = domain;
3481
- return this;
3454
+ let headers;
3455
+ if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
3456
+ headers = {
3457
+ Authorization: `Bearer ${config.pinataJwt}`,
3458
+ "Content-Type": "application/json",
3459
+ ...config.customHeaders
3460
+ };
3461
+ } else {
3462
+ headers = {
3463
+ Authorization: `Bearer ${config.pinataJwt}`,
3464
+ "Content-Type": "application/json",
3465
+ Source: "sdk/createPaymentInstruction"
3466
+ };
3467
+ }
3468
+ let endpoint = "https://api.pinata.cloud/v3";
3469
+ if (config.endpointUrl) {
3470
+ endpoint = config.endpointUrl;
3471
+ }
3472
+ try {
3473
+ const requestObj = await fetch(`${endpoint}/x402/payment_instructions`, {
3474
+ method: "POST",
3475
+ headers,
3476
+ body: JSON.stringify(request)
3477
+ });
3478
+ if (!requestObj.ok) {
3479
+ const errorData = await requestObj.text();
3480
+ if (requestObj.status === 401 || requestObj.status === 403) {
3481
+ throw new AuthenticationError(
3482
+ `Authentication failed: ${errorData}`,
3483
+ requestObj.status,
3484
+ {
3485
+ error: errorData,
3486
+ code: "AUTH_ERROR",
3487
+ metadata: {
3488
+ requestUrl: requestObj.url
3489
+ }
3490
+ }
3491
+ );
3492
+ }
3493
+ throw new NetworkError(`HTTP error: ${errorData}`, requestObj.status, {
3494
+ error: errorData,
3495
+ code: "HTTP_ERROR",
3496
+ metadata: {
3497
+ requestUrl: requestObj.url
3498
+ }
3499
+ });
3500
+ }
3501
+ const res = await requestObj.json();
3502
+ return res;
3503
+ } catch (error) {
3504
+ if (error instanceof PinataError) {
3505
+ throw error;
3506
+ }
3507
+ if (error instanceof Error) {
3508
+ throw new PinataError(
3509
+ `Error processing createPaymentInstruction: ${error.message}`
3510
+ );
3511
+ }
3512
+ throw new PinataError(
3513
+ "An unknown error occurred while creating payment instruction"
3514
+ );
3482
3515
  }
3483
3516
  };
3484
3517
 
3485
- // src/core/classes/analytics/AnalyticsBuilder.ts
3486
- var AnalyticsBuilder = class {
3487
- constructor(config, query) {
3488
- this.requestCount = 0;
3489
- this.lastRequestTime = 0;
3490
- this.MAX_REQUESTS_PER_MINUTE = 30;
3491
- this.MINUTE_IN_MS = 6e4;
3492
- this.config = config;
3493
- this.query = query;
3518
+ // src/core/functions/x402/getPaymentInstruction.ts
3519
+ var getPaymentInstruction = async (config, id) => {
3520
+ if (!config) {
3521
+ throw new ValidationError("Pinata configuration is missing");
3494
3522
  }
3495
- cid(cid) {
3496
- this.query.cid = cid;
3497
- return this;
3523
+ if (!id) {
3524
+ throw new ValidationError("Payment instruction ID is required");
3498
3525
  }
3499
- fileName(fileName) {
3500
- this.query.file_name = fileName;
3501
- return this;
3526
+ let headers;
3527
+ if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
3528
+ headers = {
3529
+ Authorization: `Bearer ${config.pinataJwt}`,
3530
+ "Content-Type": "application/json",
3531
+ ...config.customHeaders
3532
+ };
3533
+ } else {
3534
+ headers = {
3535
+ Authorization: `Bearer ${config.pinataJwt}`,
3536
+ "Content-Type": "application/json",
3537
+ Source: "sdk/getPaymentInstruction"
3538
+ };
3502
3539
  }
3503
- userAgent(userAgent) {
3540
+ let endpoint = "https://api.pinata.cloud/v3";
3541
+ if (config.endpointUrl) {
3542
+ endpoint = config.endpointUrl;
3543
+ }
3544
+ try {
3545
+ const request = await fetch(`${endpoint}/x402/payment_instructions/${id}`, {
3546
+ method: "GET",
3547
+ headers
3548
+ });
3549
+ if (!request.ok) {
3550
+ const errorData = await request.text();
3551
+ if (request.status === 401 || request.status === 403) {
3552
+ throw new AuthenticationError(
3553
+ `Authentication failed: ${errorData}`,
3554
+ request.status,
3555
+ {
3556
+ error: errorData,
3557
+ code: "AUTH_ERROR",
3558
+ metadata: {
3559
+ requestUrl: request.url
3560
+ }
3561
+ }
3562
+ );
3563
+ }
3564
+ throw new NetworkError(`HTTP error: ${errorData}`, request.status, {
3565
+ error: errorData,
3566
+ code: "HTTP_ERROR",
3567
+ metadata: {
3568
+ requestUrl: request.url
3569
+ }
3570
+ });
3571
+ }
3572
+ const res = await request.json();
3573
+ return res;
3574
+ } catch (error) {
3575
+ if (error instanceof PinataError) {
3576
+ throw error;
3577
+ }
3578
+ if (error instanceof Error) {
3579
+ throw new PinataError(
3580
+ `Error processing getPaymentInstruction: ${error.message}`
3581
+ );
3582
+ }
3583
+ throw new PinataError(
3584
+ "An unknown error occurred while getting payment instruction"
3585
+ );
3586
+ }
3587
+ };
3588
+
3589
+ // src/core/functions/x402/updatePaymentInstruction.ts
3590
+ var updatePaymentInstruction = async (config, id, request) => {
3591
+ if (!config) {
3592
+ throw new ValidationError("Pinata configuration is missing");
3593
+ }
3594
+ if (!id) {
3595
+ throw new ValidationError("Payment instruction ID is required");
3596
+ }
3597
+ let headers;
3598
+ if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
3599
+ headers = {
3600
+ Authorization: `Bearer ${config.pinataJwt}`,
3601
+ "Content-Type": "application/json",
3602
+ ...config.customHeaders
3603
+ };
3604
+ } else {
3605
+ headers = {
3606
+ Authorization: `Bearer ${config.pinataJwt}`,
3607
+ "Content-Type": "application/json",
3608
+ Source: "sdk/updatePaymentInstruction"
3609
+ };
3610
+ }
3611
+ let endpoint = "https://api.pinata.cloud/v3";
3612
+ if (config.endpointUrl) {
3613
+ endpoint = config.endpointUrl;
3614
+ }
3615
+ try {
3616
+ const requestObj = await fetch(
3617
+ `${endpoint}/x402/payment_instructions/${id}`,
3618
+ {
3619
+ method: "PATCH",
3620
+ headers,
3621
+ body: JSON.stringify(request)
3622
+ }
3623
+ );
3624
+ if (!requestObj.ok) {
3625
+ const errorData = await requestObj.text();
3626
+ if (requestObj.status === 401 || requestObj.status === 403) {
3627
+ throw new AuthenticationError(
3628
+ `Authentication failed: ${errorData}`,
3629
+ requestObj.status,
3630
+ {
3631
+ error: errorData,
3632
+ code: "AUTH_ERROR",
3633
+ metadata: {
3634
+ requestUrl: requestObj.url
3635
+ }
3636
+ }
3637
+ );
3638
+ }
3639
+ throw new NetworkError(`HTTP error: ${errorData}`, requestObj.status, {
3640
+ error: errorData,
3641
+ code: "HTTP_ERROR",
3642
+ metadata: {
3643
+ requestUrl: requestObj.url
3644
+ }
3645
+ });
3646
+ }
3647
+ const res = await requestObj.json();
3648
+ return res;
3649
+ } catch (error) {
3650
+ if (error instanceof PinataError) {
3651
+ throw error;
3652
+ }
3653
+ if (error instanceof Error) {
3654
+ throw new PinataError(
3655
+ `Error processing updatePaymentInstruction: ${error.message}`
3656
+ );
3657
+ }
3658
+ throw new PinataError(
3659
+ "An unknown error occurred while updating payment instruction"
3660
+ );
3661
+ }
3662
+ };
3663
+
3664
+ // src/core/functions/x402/deletePaymentInstruction.ts
3665
+ var deletePaymentInstruction = async (config, id) => {
3666
+ if (!config) {
3667
+ throw new ValidationError("Pinata configuration is missing");
3668
+ }
3669
+ if (!id) {
3670
+ throw new ValidationError("Payment instruction ID is required");
3671
+ }
3672
+ let headers;
3673
+ if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
3674
+ headers = {
3675
+ Authorization: `Bearer ${config.pinataJwt}`,
3676
+ "Content-Type": "application/json",
3677
+ ...config.customHeaders
3678
+ };
3679
+ } else {
3680
+ headers = {
3681
+ Authorization: `Bearer ${config.pinataJwt}`,
3682
+ "Content-Type": "application/json",
3683
+ Source: "sdk/deletePaymentInstruction"
3684
+ };
3685
+ }
3686
+ let endpoint = "https://api.pinata.cloud/v3";
3687
+ if (config.endpointUrl) {
3688
+ endpoint = config.endpointUrl;
3689
+ }
3690
+ try {
3691
+ const request = await fetch(`${endpoint}/x402/payment_instructions/${id}`, {
3692
+ method: "DELETE",
3693
+ headers
3694
+ });
3695
+ if (!request.ok) {
3696
+ const errorData = await request.text();
3697
+ if (request.status === 401 || request.status === 403) {
3698
+ throw new AuthenticationError(
3699
+ `Authentication failed: ${errorData}`,
3700
+ request.status,
3701
+ {
3702
+ error: errorData,
3703
+ code: "AUTH_ERROR",
3704
+ metadata: {
3705
+ requestUrl: request.url
3706
+ }
3707
+ }
3708
+ );
3709
+ }
3710
+ throw new NetworkError(`HTTP error: ${errorData}`, request.status, {
3711
+ error: errorData,
3712
+ code: "HTTP_ERROR",
3713
+ metadata: {
3714
+ requestUrl: request.url
3715
+ }
3716
+ });
3717
+ }
3718
+ const res = await request.json();
3719
+ return res;
3720
+ } catch (error) {
3721
+ if (error instanceof PinataError) {
3722
+ throw error;
3723
+ }
3724
+ if (error instanceof Error) {
3725
+ throw new PinataError(
3726
+ `Error processing deletePaymentInstruction: ${error.message}`
3727
+ );
3728
+ }
3729
+ throw new PinataError(
3730
+ "An unknown error occurred while deleting payment instruction"
3731
+ );
3732
+ }
3733
+ };
3734
+
3735
+ // src/core/functions/x402/listCids.ts
3736
+ var listCids = async (config, paymentInstructionId, options) => {
3737
+ if (!config) {
3738
+ throw new ValidationError("Pinata configuration is missing");
3739
+ }
3740
+ if (!paymentInstructionId) {
3741
+ throw new ValidationError("Payment instruction ID is required");
3742
+ }
3743
+ let headers;
3744
+ if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
3745
+ headers = {
3746
+ Authorization: `Bearer ${config.pinataJwt}`,
3747
+ "Content-Type": "application/json",
3748
+ ...config.customHeaders
3749
+ };
3750
+ } else {
3751
+ headers = {
3752
+ Authorization: `Bearer ${config.pinataJwt}`,
3753
+ "Content-Type": "application/json",
3754
+ Source: "sdk/listCids"
3755
+ };
3756
+ }
3757
+ const params = new URLSearchParams();
3758
+ if (options) {
3759
+ const { pageToken, limit } = options;
3760
+ if (pageToken) params.append("pageToken", pageToken);
3761
+ if (limit !== void 0) params.append("limit", limit.toString());
3762
+ }
3763
+ let endpoint = "https://api.pinata.cloud/v3";
3764
+ if (config.endpointUrl) {
3765
+ endpoint = config.endpointUrl;
3766
+ }
3767
+ try {
3768
+ const request = await fetch(
3769
+ `${endpoint}/x402/payment_instructions/${paymentInstructionId}/cids?${params.toString()}`,
3770
+ {
3771
+ method: "GET",
3772
+ headers
3773
+ }
3774
+ );
3775
+ if (!request.ok) {
3776
+ const errorData = await request.text();
3777
+ if (request.status === 401 || request.status === 403) {
3778
+ throw new AuthenticationError(
3779
+ `Authentication failed: ${errorData}`,
3780
+ request.status,
3781
+ {
3782
+ error: errorData,
3783
+ code: "AUTH_ERROR",
3784
+ metadata: {
3785
+ requestUrl: request.url
3786
+ }
3787
+ }
3788
+ );
3789
+ }
3790
+ throw new NetworkError(`HTTP error: ${errorData}`, request.status, {
3791
+ error: errorData,
3792
+ code: "HTTP_ERROR",
3793
+ metadata: {
3794
+ requestUrl: request.url
3795
+ }
3796
+ });
3797
+ }
3798
+ const res = await request.json();
3799
+ return res;
3800
+ } catch (error) {
3801
+ if (error instanceof PinataError) {
3802
+ throw error;
3803
+ }
3804
+ if (error instanceof Error) {
3805
+ throw new PinataError(`Error processing listCids: ${error.message}`);
3806
+ }
3807
+ throw new PinataError("An unknown error occurred while listing CIDs");
3808
+ }
3809
+ };
3810
+
3811
+ // src/core/functions/x402/addCid.ts
3812
+ var addCid = async (config, paymentInstructionId, cid) => {
3813
+ if (!config) {
3814
+ throw new ValidationError("Pinata configuration is missing");
3815
+ }
3816
+ if (!paymentInstructionId) {
3817
+ throw new ValidationError("Payment instruction ID is required");
3818
+ }
3819
+ if (!cid) {
3820
+ throw new ValidationError("CID is required");
3821
+ }
3822
+ let headers;
3823
+ if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
3824
+ headers = {
3825
+ Authorization: `Bearer ${config.pinataJwt}`,
3826
+ "Content-Type": "application/json",
3827
+ ...config.customHeaders
3828
+ };
3829
+ } else {
3830
+ headers = {
3831
+ Authorization: `Bearer ${config.pinataJwt}`,
3832
+ "Content-Type": "application/json",
3833
+ Source: "sdk/addCid"
3834
+ };
3835
+ }
3836
+ let endpoint = "https://api.pinata.cloud/v3";
3837
+ if (config.endpointUrl) {
3838
+ endpoint = config.endpointUrl;
3839
+ }
3840
+ try {
3841
+ const request = await fetch(
3842
+ `${endpoint}/x402/payment_instructions/${paymentInstructionId}/cids/${cid}`,
3843
+ {
3844
+ method: "PUT",
3845
+ headers
3846
+ }
3847
+ );
3848
+ if (!request.ok) {
3849
+ const errorData = await request.text();
3850
+ if (request.status === 401 || request.status === 403) {
3851
+ throw new AuthenticationError(
3852
+ `Authentication failed: ${errorData}`,
3853
+ request.status,
3854
+ {
3855
+ error: errorData,
3856
+ code: "AUTH_ERROR",
3857
+ metadata: {
3858
+ requestUrl: request.url
3859
+ }
3860
+ }
3861
+ );
3862
+ }
3863
+ throw new NetworkError(`HTTP error: ${errorData}`, request.status, {
3864
+ error: errorData,
3865
+ code: "HTTP_ERROR",
3866
+ metadata: {
3867
+ requestUrl: request.url
3868
+ }
3869
+ });
3870
+ }
3871
+ const res = await request.json();
3872
+ return res;
3873
+ } catch (error) {
3874
+ if (error instanceof PinataError) {
3875
+ throw error;
3876
+ }
3877
+ if (error instanceof Error) {
3878
+ throw new PinataError(`Error processing addCid: ${error.message}`);
3879
+ }
3880
+ throw new PinataError("An unknown error occurred while adding CID");
3881
+ }
3882
+ };
3883
+
3884
+ // src/core/functions/x402/removeCid.ts
3885
+ var removeCid = async (config, paymentInstructionId, cid) => {
3886
+ if (!config) {
3887
+ throw new ValidationError("Pinata configuration is missing");
3888
+ }
3889
+ if (!paymentInstructionId) {
3890
+ throw new ValidationError("Payment instruction ID is required");
3891
+ }
3892
+ if (!cid) {
3893
+ throw new ValidationError("CID is required");
3894
+ }
3895
+ let headers;
3896
+ if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
3897
+ headers = {
3898
+ Authorization: `Bearer ${config.pinataJwt}`,
3899
+ "Content-Type": "application/json",
3900
+ ...config.customHeaders
3901
+ };
3902
+ } else {
3903
+ headers = {
3904
+ Authorization: `Bearer ${config.pinataJwt}`,
3905
+ "Content-Type": "application/json",
3906
+ Source: "sdk/removeCid"
3907
+ };
3908
+ }
3909
+ let endpoint = "https://api.pinata.cloud/v3";
3910
+ if (config.endpointUrl) {
3911
+ endpoint = config.endpointUrl;
3912
+ }
3913
+ try {
3914
+ const request = await fetch(
3915
+ `${endpoint}/x402/payment_instructions/${paymentInstructionId}/cids/${cid}`,
3916
+ {
3917
+ method: "DELETE",
3918
+ headers
3919
+ }
3920
+ );
3921
+ if (!request.ok) {
3922
+ const errorData = await request.text();
3923
+ if (request.status === 401 || request.status === 403) {
3924
+ throw new AuthenticationError(
3925
+ `Authentication failed: ${errorData}`,
3926
+ request.status,
3927
+ {
3928
+ error: errorData,
3929
+ code: "AUTH_ERROR",
3930
+ metadata: {
3931
+ requestUrl: request.url
3932
+ }
3933
+ }
3934
+ );
3935
+ }
3936
+ throw new NetworkError(`HTTP error: ${errorData}`, request.status, {
3937
+ error: errorData,
3938
+ code: "HTTP_ERROR",
3939
+ metadata: {
3940
+ requestUrl: request.url
3941
+ }
3942
+ });
3943
+ }
3944
+ const res = await request.json();
3945
+ return res;
3946
+ } catch (error) {
3947
+ if (error instanceof PinataError) {
3948
+ throw error;
3949
+ }
3950
+ if (error instanceof Error) {
3951
+ throw new PinataError(`Error processing removeCid: ${error.message}`);
3952
+ }
3953
+ throw new PinataError("An unknown error occurred while removing CID");
3954
+ }
3955
+ };
3956
+
3957
+ // src/core/classes/analytics/Analytics.ts
3958
+ var Analytics = class {
3959
+ constructor(config) {
3960
+ this.config = formatConfig(config);
3961
+ this.requests = new AnalyticsRequests(this.config);
3962
+ this.bandwidth = new AnalyticsBandwidth(this.config);
3963
+ }
3964
+ updateConfig(newConfig) {
3965
+ this.config = newConfig;
3966
+ this.requests.updateConfig(newConfig);
3967
+ this.bandwidth.updateConfig(newConfig);
3968
+ }
3969
+ summary(options) {
3970
+ return new TimeIntervalAnalyticsBuilder(
3971
+ this.config,
3972
+ options.domain,
3973
+ options.start,
3974
+ options.end,
3975
+ options.interval
3976
+ );
3977
+ }
3978
+ };
3979
+
3980
+ // src/core/classes/analytics/utils.ts
3981
+ var calculateDates = (days) => {
3982
+ const end = /* @__PURE__ */ new Date();
3983
+ const start = /* @__PURE__ */ new Date();
3984
+ start.setDate(start.getDate() - days);
3985
+ return {
3986
+ start: start.toISOString().split("T")[0],
3987
+ end: end.toISOString().split("T")[0]
3988
+ };
3989
+ };
3990
+
3991
+ // src/core/classes/analytics/AnalyticsFilter.ts
3992
+ var AnalyticsFilter = class {
3993
+ constructor(config, domain, start, end) {
3994
+ this.config = config;
3995
+ this.query = {
3996
+ gateway_domain: domain,
3997
+ start_date: start,
3998
+ end_date: end,
3999
+ sort_by: "requests",
4000
+ // Will be overridden in child classes
4001
+ attribute: "cid"
4002
+ };
4003
+ }
4004
+ cid(cid) {
4005
+ this.query.attribute = "cid";
4006
+ if (cid) {
4007
+ this.query.cid = cid;
4008
+ }
4009
+ return this;
4010
+ }
4011
+ fileName(fileName) {
4012
+ this.query.attribute = "file_name";
4013
+ if (fileName) {
4014
+ this.query.file_name = fileName;
4015
+ }
4016
+ return this;
4017
+ }
4018
+ userAgent(userAgent) {
4019
+ this.query.attribute = "user_agent";
4020
+ if (userAgent) {
4021
+ this.query.user_agent = userAgent;
4022
+ }
4023
+ return this;
4024
+ }
4025
+ country(country) {
4026
+ this.query.attribute = "country";
4027
+ if (country) {
4028
+ this.query.country = country;
4029
+ }
4030
+ return this;
4031
+ }
4032
+ region(region) {
4033
+ this.query.attribute = "region";
4034
+ if (region) {
4035
+ this.query.region = region;
4036
+ }
4037
+ return this;
4038
+ }
4039
+ referer(referer) {
4040
+ this.query.attribute = "referer";
4041
+ if (referer) {
4042
+ this.query.referer = referer;
4043
+ }
4044
+ return this;
4045
+ }
4046
+ limit(limit) {
4047
+ this.query.limit = limit;
4048
+ return this;
4049
+ }
4050
+ sort(order) {
4051
+ this.query.sort_order = order;
4052
+ return this;
4053
+ }
4054
+ days(numberOfDays) {
4055
+ const { start, end } = calculateDates(numberOfDays);
4056
+ this.query.start_date = start;
4057
+ this.query.end_date = end;
4058
+ return this;
4059
+ }
4060
+ then(onfulfilled, onrejected) {
4061
+ return analyticsTopUsage(this.config, this.query).then(
4062
+ onfulfilled,
4063
+ onrejected
4064
+ );
4065
+ }
4066
+ };
4067
+
4068
+ // src/core/classes/analytics/AnalyticsBandwidth.ts
4069
+ var AnalyticsBandwidth = class extends AnalyticsFilter {
4070
+ constructor(config) {
4071
+ super(config, "", "", "");
4072
+ this.query.sort_by = "bandwidth";
4073
+ }
4074
+ updateConfig(newConfig) {
4075
+ this.config = newConfig;
4076
+ }
4077
+ customDates(start, end) {
4078
+ if (start) this.query.start_date = start;
4079
+ if (end) this.query.end_date = end;
4080
+ return this;
4081
+ }
4082
+ from(domain) {
4083
+ this.query.gateway_domain = domain;
4084
+ return this;
4085
+ }
4086
+ };
4087
+
4088
+ // src/core/classes/analytics/AnalyticsBuilder.ts
4089
+ var AnalyticsBuilder = class {
4090
+ constructor(config, query) {
4091
+ this.requestCount = 0;
4092
+ this.lastRequestTime = 0;
4093
+ this.MAX_REQUESTS_PER_MINUTE = 30;
4094
+ this.MINUTE_IN_MS = 6e4;
4095
+ this.config = config;
4096
+ this.query = query;
4097
+ }
4098
+ cid(cid) {
4099
+ this.query.cid = cid;
4100
+ return this;
4101
+ }
4102
+ fileName(fileName) {
4103
+ this.query.file_name = fileName;
4104
+ return this;
4105
+ }
4106
+ userAgent(userAgent) {
3504
4107
  this.query.user_agent = userAgent;
3505
4108
  return this;
3506
4109
  }
@@ -4688,6 +5291,40 @@ var Signatures = class {
4688
5291
  }
4689
5292
  };
4690
5293
 
5294
+ // src/core/classes/x402/X402.ts
5295
+ var X402 = class {
5296
+ constructor(config) {
5297
+ this.config = formatConfig(config);
5298
+ }
5299
+ updateConfig(newConfig) {
5300
+ this.config = newConfig;
5301
+ }
5302
+ listPaymentInstructions(options) {
5303
+ return listPaymentInstructions(this.config, options);
5304
+ }
5305
+ createPaymentInstruction(request) {
5306
+ return createPaymentInstruction(this.config, request);
5307
+ }
5308
+ getPaymentInstruction(id) {
5309
+ return getPaymentInstruction(this.config, id);
5310
+ }
5311
+ updatePaymentInstruction(id, request) {
5312
+ return updatePaymentInstruction(this.config, id, request);
5313
+ }
5314
+ deletePaymentInstruction(id) {
5315
+ return deletePaymentInstruction(this.config, id);
5316
+ }
5317
+ listCids(paymentInstructionId, options) {
5318
+ return listCids(this.config, paymentInstructionId, options);
5319
+ }
5320
+ addCid(paymentInstructionId, cid) {
5321
+ return addCid(this.config, paymentInstructionId, cid);
5322
+ }
5323
+ removeCid(paymentInstructionId, cid) {
5324
+ return removeCid(this.config, paymentInstructionId, cid);
5325
+ }
5326
+ };
5327
+
4691
5328
  // src/core/pinataSDK.ts
4692
5329
  var PinataSDK = class {
4693
5330
  constructor(config) {
@@ -4699,6 +5336,7 @@ var PinataSDK = class {
4699
5336
  this.groups = new Groups(this.config);
4700
5337
  this.analytics = new Analytics(this.config);
4701
5338
  this.signatures = new Signatures(this.config);
5339
+ this.x402 = new X402(this.config);
4702
5340
  }
4703
5341
  setNewHeaders(headers) {
4704
5342
  if (!this.config) {
@@ -4712,6 +5350,7 @@ var PinataSDK = class {
4712
5350
  this.groups.updateConfig(this.config);
4713
5351
  this.analytics.updateConfig(this.config);
4714
5352
  this.signatures.updateConfig(this.config);
5353
+ this.x402.updateConfig(this.config);
4715
5354
  }
4716
5355
  setNewJwt(jwt) {
4717
5356
  if (!this.config) {
@@ -4725,12 +5364,13 @@ var PinataSDK = class {
4725
5364
  this.groups.updateConfig(this.config);
4726
5365
  this.analytics.updateConfig(this.config);
4727
5366
  this.signatures.updateConfig(this.config);
5367
+ this.x402.updateConfig(this.config);
4728
5368
  }
4729
5369
  testAuthentication() {
4730
5370
  return testAuthentication(this.config);
4731
5371
  }
4732
5372
  };
4733
5373
 
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 };
5374
+ 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
5375
  //# sourceMappingURL=index.mjs.map
4736
5376
  //# sourceMappingURL=index.mjs.map