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