@zubari/sdk 0.2.4 → 0.2.6

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.
@@ -294,6 +294,691 @@ function getWdkApiClient(baseUrl) {
294
294
  return wdkApiClient;
295
295
  }
296
296
 
297
+ // src/services/ZubariApiClient.ts
298
+ var ZubariApiClient = class {
299
+ config;
300
+ constructor(config) {
301
+ this.config = {
302
+ baseUrl: config.baseUrl.replace(/\/$/, ""),
303
+ // Remove trailing slash
304
+ timeout: config.timeout || 3e4,
305
+ authToken: config.authToken
306
+ };
307
+ }
308
+ /**
309
+ * Set the authentication token
310
+ */
311
+ setAuthToken(token) {
312
+ this.config.authToken = token;
313
+ }
314
+ /**
315
+ * Clear the authentication token
316
+ */
317
+ clearAuthToken() {
318
+ this.config.authToken = void 0;
319
+ }
320
+ /**
321
+ * Make an authenticated request to the API
322
+ */
323
+ async request(method, path, body) {
324
+ const headers = {
325
+ "Content-Type": "application/json"
326
+ };
327
+ if (this.config.authToken) {
328
+ headers["Authorization"] = `Bearer ${this.config.authToken}`;
329
+ }
330
+ const response = await fetch(`${this.config.baseUrl}${path}`, {
331
+ method,
332
+ headers,
333
+ body: body ? JSON.stringify(body) : void 0
334
+ });
335
+ if (!response.ok) {
336
+ const errorData = await response.json().catch(() => ({}));
337
+ throw new Error(errorData.error || `HTTP ${response.status}: ${response.statusText}`);
338
+ }
339
+ return response.json();
340
+ }
341
+ // ============ NFT Methods ============
342
+ /**
343
+ * Get all NFTs with optional filters
344
+ */
345
+ async getNFTs(filters) {
346
+ try {
347
+ const params = new URLSearchParams();
348
+ if (filters) {
349
+ Object.entries(filters).forEach(([key, value]) => {
350
+ if (value !== void 0) {
351
+ params.append(key, String(value));
352
+ }
353
+ });
354
+ }
355
+ const queryString = params.toString();
356
+ const path = `/api/nfts${queryString ? `?${queryString}` : ""}`;
357
+ return await this.request("GET", path);
358
+ } catch (error) {
359
+ return {
360
+ success: false,
361
+ error: error instanceof Error ? error.message : "Failed to get NFTs"
362
+ };
363
+ }
364
+ }
365
+ /**
366
+ * Get a single NFT by ID
367
+ */
368
+ async getNFT(nftId) {
369
+ try {
370
+ const nft = await this.request("GET", `/api/nfts/${nftId}`);
371
+ return { success: true, nft };
372
+ } catch (error) {
373
+ return {
374
+ success: false,
375
+ error: error instanceof Error ? error.message : "Failed to get NFT"
376
+ };
377
+ }
378
+ }
379
+ /**
380
+ * Create a new NFT (lazy minted)
381
+ */
382
+ async createNFT(data, image) {
383
+ try {
384
+ const formData = new FormData();
385
+ formData.append("image", image);
386
+ formData.append("name", data.name);
387
+ if (data.description) formData.append("description", data.description);
388
+ formData.append("price", data.price);
389
+ formData.append("currency", data.currency);
390
+ if (data.royaltyBps !== void 0) formData.append("royaltyBps", String(data.royaltyBps));
391
+ if (data.attributes) formData.append("attributes", JSON.stringify(data.attributes));
392
+ if (data.externalUrl) formData.append("externalUrl", data.externalUrl);
393
+ const headers = {};
394
+ if (this.config.authToken) {
395
+ headers["Authorization"] = `Bearer ${this.config.authToken}`;
396
+ }
397
+ const response = await fetch(`${this.config.baseUrl}/api/nfts`, {
398
+ method: "POST",
399
+ headers,
400
+ body: formData
401
+ });
402
+ if (!response.ok) {
403
+ const errorData = await response.json().catch(() => ({}));
404
+ throw new Error(errorData.error || `HTTP ${response.status}`);
405
+ }
406
+ const nft = await response.json();
407
+ return { success: true, nft };
408
+ } catch (error) {
409
+ return {
410
+ success: false,
411
+ error: error instanceof Error ? error.message : "Failed to create NFT"
412
+ };
413
+ }
414
+ }
415
+ /**
416
+ * Create a voucher for an NFT (EIP-712 signed)
417
+ */
418
+ async createVoucher(nftId, params) {
419
+ try {
420
+ return await this.request("POST", `/api/nfts/${nftId}/voucher`, params);
421
+ } catch (error) {
422
+ return {
423
+ success: false,
424
+ error: error instanceof Error ? error.message : "Failed to create voucher"
425
+ };
426
+ }
427
+ }
428
+ /**
429
+ * Redeem an NFT voucher (buy/mint)
430
+ */
431
+ async redeemVoucher(nftId, params) {
432
+ try {
433
+ return await this.request("POST", `/api/nfts/${nftId}/redeem`, params);
434
+ } catch (error) {
435
+ return {
436
+ success: false,
437
+ error: error instanceof Error ? error.message : "Failed to redeem voucher"
438
+ };
439
+ }
440
+ }
441
+ /**
442
+ * Get voucher status for an NFT
443
+ */
444
+ async getVoucherStatus(nftId) {
445
+ try {
446
+ return await this.request("GET", `/api/nfts/${nftId}/voucher/status`);
447
+ } catch (error) {
448
+ return {
449
+ success: false,
450
+ error: error instanceof Error ? error.message : "Failed to get voucher status"
451
+ };
452
+ }
453
+ }
454
+ // ============ Marketplace Methods ============
455
+ /**
456
+ * Get all active listings
457
+ */
458
+ async getListings(filters) {
459
+ try {
460
+ const params = new URLSearchParams();
461
+ if (filters) {
462
+ Object.entries(filters).forEach(([key, value]) => {
463
+ if (value !== void 0) {
464
+ params.append(key, String(value));
465
+ }
466
+ });
467
+ }
468
+ const queryString = params.toString();
469
+ const path = `/api/market/listings${queryString ? `?${queryString}` : ""}`;
470
+ return await this.request("GET", path);
471
+ } catch (error) {
472
+ return {
473
+ success: false,
474
+ error: error instanceof Error ? error.message : "Failed to get listings"
475
+ };
476
+ }
477
+ }
478
+ /**
479
+ * List an NFT for sale
480
+ */
481
+ async listItem(params) {
482
+ try {
483
+ return await this.request("POST", "/api/market/list", params);
484
+ } catch (error) {
485
+ return {
486
+ success: false,
487
+ error: error instanceof Error ? error.message : "Failed to list item"
488
+ };
489
+ }
490
+ }
491
+ /**
492
+ * Buy a listed NFT
493
+ */
494
+ async buyItem(params) {
495
+ try {
496
+ return await this.request("POST", "/api/market/buy", params);
497
+ } catch (error) {
498
+ return {
499
+ success: false,
500
+ error: error instanceof Error ? error.message : "Failed to buy item"
501
+ };
502
+ }
503
+ }
504
+ /**
505
+ * Cancel a listing
506
+ */
507
+ async cancelListing(params) {
508
+ try {
509
+ return await this.request("POST", "/api/market/cancel", params);
510
+ } catch (error) {
511
+ return {
512
+ success: false,
513
+ error: error instanceof Error ? error.message : "Failed to cancel listing"
514
+ };
515
+ }
516
+ }
517
+ /**
518
+ * Update listing price
519
+ */
520
+ async updateListingPrice(params) {
521
+ try {
522
+ return await this.request("PATCH", "/api/market/price", params);
523
+ } catch (error) {
524
+ return {
525
+ success: false,
526
+ error: error instanceof Error ? error.message : "Failed to update price"
527
+ };
528
+ }
529
+ }
530
+ /**
531
+ * Get current user's listings
532
+ */
533
+ async getMyListings(filters) {
534
+ try {
535
+ const params = new URLSearchParams();
536
+ if (filters) {
537
+ Object.entries(filters).forEach(([key, value]) => {
538
+ if (value !== void 0) {
539
+ params.append(key, String(value));
540
+ }
541
+ });
542
+ }
543
+ const queryString = params.toString();
544
+ const path = `/api/market/my/listings${queryString ? `?${queryString}` : ""}`;
545
+ return await this.request("GET", path);
546
+ } catch (error) {
547
+ return {
548
+ success: false,
549
+ error: error instanceof Error ? error.message : "Failed to get my listings"
550
+ };
551
+ }
552
+ }
553
+ /**
554
+ * Get marketplace statistics
555
+ */
556
+ async getMarketStats() {
557
+ try {
558
+ return await this.request("GET", "/api/market/stats");
559
+ } catch (error) {
560
+ return {
561
+ success: false,
562
+ error: error instanceof Error ? error.message : "Failed to get market stats"
563
+ };
564
+ }
565
+ }
566
+ // ============ Tips Methods ============
567
+ /**
568
+ * Send a tip to a creator
569
+ */
570
+ async sendTip(params) {
571
+ try {
572
+ return await this.request("POST", "/api/tips", params);
573
+ } catch (error) {
574
+ return {
575
+ success: false,
576
+ error: error instanceof Error ? error.message : "Failed to send tip"
577
+ };
578
+ }
579
+ }
580
+ /**
581
+ * Get tip statistics for current user
582
+ */
583
+ async getTipStats() {
584
+ try {
585
+ const data = await this.request("GET", "/api/tips/my/stats");
586
+ return { success: true, ...data };
587
+ } catch (error) {
588
+ return {
589
+ success: false,
590
+ error: error instanceof Error ? error.message : "Failed to get tip stats"
591
+ };
592
+ }
593
+ }
594
+ /**
595
+ * Get tips sent by current user
596
+ */
597
+ async getSentTips(filters) {
598
+ try {
599
+ const params = new URLSearchParams();
600
+ if (filters) {
601
+ Object.entries(filters).forEach(([key, value]) => {
602
+ if (value !== void 0) {
603
+ params.append(key, String(value));
604
+ }
605
+ });
606
+ }
607
+ const queryString = params.toString();
608
+ const path = `/api/tips/sent${queryString ? `?${queryString}` : ""}`;
609
+ const data = await this.request("GET", path);
610
+ return { success: true, ...data };
611
+ } catch (error) {
612
+ return {
613
+ success: false,
614
+ error: error instanceof Error ? error.message : "Failed to get sent tips"
615
+ };
616
+ }
617
+ }
618
+ /**
619
+ * Get tips received by current user
620
+ */
621
+ async getReceivedTips(filters) {
622
+ try {
623
+ const params = new URLSearchParams();
624
+ if (filters) {
625
+ Object.entries(filters).forEach(([key, value]) => {
626
+ if (value !== void 0) {
627
+ params.append(key, String(value));
628
+ }
629
+ });
630
+ }
631
+ const queryString = params.toString();
632
+ const path = `/api/tips/received${queryString ? `?${queryString}` : ""}`;
633
+ const data = await this.request("GET", path);
634
+ return { success: true, ...data };
635
+ } catch (error) {
636
+ return {
637
+ success: false,
638
+ error: error instanceof Error ? error.message : "Failed to get received tips"
639
+ };
640
+ }
641
+ }
642
+ /**
643
+ * Get a single tip by ID
644
+ */
645
+ async getTip(tipId) {
646
+ try {
647
+ const data = await this.request("GET", `/api/tips/${tipId}`);
648
+ return { success: true, tip: data.tip };
649
+ } catch (error) {
650
+ return {
651
+ success: false,
652
+ error: error instanceof Error ? error.message : "Failed to get tip"
653
+ };
654
+ }
655
+ }
656
+ /**
657
+ * Update tip status (for transaction confirmation)
658
+ */
659
+ async updateTipStatus(tipId, params) {
660
+ try {
661
+ const data = await this.request(
662
+ "PATCH",
663
+ `/api/tips/${tipId}/status`,
664
+ params
665
+ );
666
+ return { success: true, ...data };
667
+ } catch (error) {
668
+ return {
669
+ success: false,
670
+ error: error instanceof Error ? error.message : "Failed to update tip status"
671
+ };
672
+ }
673
+ }
674
+ // ============ Subscription Methods ============
675
+ /**
676
+ * Create a new subscription plan (creator only)
677
+ */
678
+ async createSubscriptionPlan(params) {
679
+ try {
680
+ return await this.request("POST", "/api/subscriptions/plans", params);
681
+ } catch (error) {
682
+ return {
683
+ success: false,
684
+ error: error instanceof Error ? error.message : "Failed to create subscription plan"
685
+ };
686
+ }
687
+ }
688
+ /**
689
+ * Get current user's subscription plans
690
+ */
691
+ async getMySubscriptionPlans() {
692
+ try {
693
+ const data = await this.request("GET", "/api/subscriptions/plans");
694
+ return { success: true, plans: data.plans };
695
+ } catch (error) {
696
+ return {
697
+ success: false,
698
+ error: error instanceof Error ? error.message : "Failed to get subscription plans"
699
+ };
700
+ }
701
+ }
702
+ /**
703
+ * Get subscription plan by ID
704
+ */
705
+ async getSubscriptionPlan(planId) {
706
+ try {
707
+ const plan = await this.request(
708
+ "GET",
709
+ `/api/subscriptions/plans/${planId}`
710
+ );
711
+ return { success: true, plan };
712
+ } catch (error) {
713
+ return {
714
+ success: false,
715
+ error: error instanceof Error ? error.message : "Failed to get subscription plan"
716
+ };
717
+ }
718
+ }
719
+ /**
720
+ * Delete/deactivate subscription plan
721
+ */
722
+ async deleteSubscriptionPlan(planId) {
723
+ try {
724
+ const data = await this.request(
725
+ "DELETE",
726
+ `/api/subscriptions/plans/${planId}`
727
+ );
728
+ return { success: true, ...data };
729
+ } catch (error) {
730
+ return {
731
+ success: false,
732
+ error: error instanceof Error ? error.message : "Failed to delete subscription plan"
733
+ };
734
+ }
735
+ }
736
+ /**
737
+ * Subscribe to a plan
738
+ */
739
+ async subscribe(params) {
740
+ try {
741
+ return await this.request("POST", "/api/subscriptions/subscribe", params);
742
+ } catch (error) {
743
+ return {
744
+ success: false,
745
+ error: error instanceof Error ? error.message : "Failed to subscribe"
746
+ };
747
+ }
748
+ }
749
+ /**
750
+ * Get current user's subscriptions (as subscriber)
751
+ */
752
+ async getMySubscriptions(filters) {
753
+ try {
754
+ const params = new URLSearchParams();
755
+ if (filters) {
756
+ Object.entries(filters).forEach(([key, value]) => {
757
+ if (value !== void 0) {
758
+ params.append(key, String(value));
759
+ }
760
+ });
761
+ }
762
+ const queryString = params.toString();
763
+ const path = `/api/subscriptions${queryString ? `?${queryString}` : ""}`;
764
+ const data = await this.request("GET", path);
765
+ return { success: true, ...data };
766
+ } catch (error) {
767
+ return {
768
+ success: false,
769
+ error: error instanceof Error ? error.message : "Failed to get subscriptions"
770
+ };
771
+ }
772
+ }
773
+ /**
774
+ * Get subscribers to current user's plans (as creator)
775
+ */
776
+ async getMySubscribers(filters) {
777
+ try {
778
+ const params = new URLSearchParams();
779
+ if (filters) {
780
+ Object.entries(filters).forEach(([key, value]) => {
781
+ if (value !== void 0) {
782
+ params.append(key, String(value));
783
+ }
784
+ });
785
+ }
786
+ const queryString = params.toString();
787
+ const path = `/api/subscriptions/subscribers${queryString ? `?${queryString}` : ""}`;
788
+ const data = await this.request("GET", path);
789
+ return { success: true, ...data };
790
+ } catch (error) {
791
+ return {
792
+ success: false,
793
+ error: error instanceof Error ? error.message : "Failed to get subscribers"
794
+ };
795
+ }
796
+ }
797
+ /**
798
+ * Cancel subscription
799
+ */
800
+ async cancelSubscription(subscriptionId) {
801
+ try {
802
+ const data = await this.request("DELETE", `/api/subscriptions/${subscriptionId}`);
803
+ return { success: true, ...data };
804
+ } catch (error) {
805
+ return {
806
+ success: false,
807
+ error: error instanceof Error ? error.message : "Failed to cancel subscription"
808
+ };
809
+ }
810
+ }
811
+ /**
812
+ * Create a subscription plan on-chain
813
+ */
814
+ async createSubscriptionPlanOnChain(params) {
815
+ try {
816
+ return await this.request("POST", "/api/subscriptions/contract/plans", params);
817
+ } catch (error) {
818
+ return {
819
+ success: false,
820
+ error: error instanceof Error ? error.message : "Failed to create plan on-chain"
821
+ };
822
+ }
823
+ }
824
+ /**
825
+ * Subscribe to a plan on-chain
826
+ */
827
+ async subscribeOnChain(params) {
828
+ try {
829
+ return await this.request("POST", "/api/subscriptions/contract/subscribe", params);
830
+ } catch (error) {
831
+ return {
832
+ success: false,
833
+ error: error instanceof Error ? error.message : "Failed to subscribe on-chain"
834
+ };
835
+ }
836
+ }
837
+ /**
838
+ * Cancel subscription on-chain
839
+ */
840
+ async cancelSubscriptionOnChain(subscriptionId, seed) {
841
+ try {
842
+ return await this.request(
843
+ "POST",
844
+ "/api/subscriptions/contract/cancel",
845
+ { subscriptionId, seed }
846
+ );
847
+ } catch (error) {
848
+ return {
849
+ success: false,
850
+ error: error instanceof Error ? error.message : "Failed to cancel subscription on-chain"
851
+ };
852
+ }
853
+ }
854
+ /**
855
+ * Check if user is subscribed to a creator on-chain
856
+ */
857
+ async isSubscribed(subscriber, creator) {
858
+ try {
859
+ return await this.request(
860
+ "GET",
861
+ `/api/subscriptions/contract/is-subscribed?subscriber=${subscriber}&creator=${creator}`
862
+ );
863
+ } catch (error) {
864
+ return {
865
+ subscriber,
866
+ creator,
867
+ isSubscribed: false
868
+ };
869
+ }
870
+ }
871
+ /**
872
+ * Get subscription platform fee
873
+ */
874
+ async getSubscriptionPlatformFee() {
875
+ try {
876
+ return await this.request("GET", "/api/subscriptions/platform-fee");
877
+ } catch (error) {
878
+ return {
879
+ feeBps: 0,
880
+ feePercent: "0"
881
+ };
882
+ }
883
+ }
884
+ // ============ Payouts Methods ============
885
+ /**
886
+ * Get pending and claimed earnings for the authenticated user
887
+ */
888
+ async getEarnings() {
889
+ try {
890
+ const data = await this.request("GET", "/api/payouts/earnings");
891
+ return { success: true, ...data };
892
+ } catch (error) {
893
+ return {
894
+ success: false,
895
+ error: error instanceof Error ? error.message : "Failed to get earnings"
896
+ };
897
+ }
898
+ }
899
+ /**
900
+ * Claim pending earnings
901
+ */
902
+ async claimEarnings(params) {
903
+ try {
904
+ return await this.request("POST", "/api/payouts/claim", params);
905
+ } catch (error) {
906
+ return {
907
+ success: false,
908
+ error: error instanceof Error ? error.message : "Failed to claim earnings"
909
+ };
910
+ }
911
+ }
912
+ /**
913
+ * Get payout history for the authenticated user
914
+ */
915
+ async getPayoutHistory(filters) {
916
+ try {
917
+ const params = new URLSearchParams();
918
+ if (filters) {
919
+ Object.entries(filters).forEach(([key, value]) => {
920
+ if (value !== void 0) {
921
+ params.append(key, String(value));
922
+ }
923
+ });
924
+ }
925
+ const queryString = params.toString();
926
+ const path = `/api/payouts/history${queryString ? `?${queryString}` : ""}`;
927
+ const data = await this.request("GET", path);
928
+ return { success: true, ...data };
929
+ } catch (error) {
930
+ return {
931
+ success: false,
932
+ error: error instanceof Error ? error.message : "Failed to get payout history"
933
+ };
934
+ }
935
+ }
936
+ /**
937
+ * Get earnings breakdown by source
938
+ */
939
+ async getEarningsBreakdown() {
940
+ try {
941
+ const data = await this.request("GET", "/api/payouts/breakdown");
942
+ return { success: true, ...data };
943
+ } catch (error) {
944
+ return {
945
+ success: false,
946
+ error: error instanceof Error ? error.message : "Failed to get earnings breakdown"
947
+ };
948
+ }
949
+ }
950
+ /**
951
+ * Get current platform fee for payouts
952
+ */
953
+ async getPayoutsPlatformFee() {
954
+ try {
955
+ return await this.request("GET", "/api/payouts/platform-fee");
956
+ } catch (error) {
957
+ return {
958
+ feeBps: 0,
959
+ feePercent: "0"
960
+ };
961
+ }
962
+ }
963
+ };
964
+ var DEFAULT_API_URL2 = process.env.NEXT_PUBLIC_API_URL || "https://ckgwifsxka.us-east-2.awsapprunner.com";
965
+ var zubariApiClient = null;
966
+ function getZubariApiClient(config) {
967
+ if (!zubariApiClient || config?.baseUrl && zubariApiClient["config"].baseUrl !== config.baseUrl) {
968
+ zubariApiClient = new ZubariApiClient({
969
+ baseUrl: config?.baseUrl || DEFAULT_API_URL2,
970
+ timeout: config?.timeout,
971
+ authToken: config?.authToken
972
+ });
973
+ } else if (config?.authToken) {
974
+ zubariApiClient.setAuthToken(config.authToken);
975
+ }
976
+ return zubariApiClient;
977
+ }
978
+ function createZubariApiClient(config) {
979
+ return new ZubariApiClient(config);
980
+ }
981
+
297
982
  // src/services/BrowserAddressDerivation.ts
298
983
  var BrowserAddressDerivation_exports = {};
299
984
  __export(BrowserAddressDerivation_exports, {
@@ -487,7 +1172,7 @@ function generateSeedPhrase() {
487
1172
  }
488
1173
 
489
1174
  // src/services/ZubariWdkService.ts
490
- var DEFAULT_API_URL2 = "https://ckgwifsxka.us-east-2.awsapprunner.com";
1175
+ var DEFAULT_API_URL3 = "https://ckgwifsxka.us-east-2.awsapprunner.com";
491
1176
  function isBrowser() {
492
1177
  return typeof window !== "undefined" && typeof window.document !== "undefined";
493
1178
  }
@@ -512,7 +1197,7 @@ var ZubariWdkService = class {
512
1197
  constructor(config = {}) {
513
1198
  this.config = {
514
1199
  network: config.network || "testnet",
515
- apiUrl: config.apiUrl || process.env.NEXT_PUBLIC_API_URL || DEFAULT_API_URL2,
1200
+ apiUrl: config.apiUrl || process.env.NEXT_PUBLIC_API_URL || DEFAULT_API_URL3,
516
1201
  forceApi: config.forceApi ?? false,
517
1202
  timeout: config.timeout || 3e4
518
1203
  };
@@ -1333,6 +2018,6 @@ function createTransactionService(config) {
1333
2018
  return new TransactionService(config);
1334
2019
  }
1335
2020
 
1336
- export { BrowserAddressDerivation_exports as BrowserAddressDerivation, SwapService, TransactionService, WdkApiClient, ZubariWdkService, createTransactionService, createZubariWdkService, getTransactionService, getWdkApiClient, getZubariWdkService, isBrowser };
2021
+ export { BrowserAddressDerivation_exports as BrowserAddressDerivation, SwapService, TransactionService, WdkApiClient, ZubariApiClient, ZubariWdkService, createTransactionService, createZubariApiClient, createZubariWdkService, getTransactionService, getWdkApiClient, getZubariApiClient, getZubariWdkService, isBrowser };
1337
2022
  //# sourceMappingURL=index.mjs.map
1338
2023
  //# sourceMappingURL=index.mjs.map