@zubari/sdk 0.2.3 → 0.2.5

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.
@@ -296,6 +296,294 @@ function getWdkApiClient(baseUrl) {
296
296
  return wdkApiClient;
297
297
  }
298
298
 
299
+ // src/services/ZubariApiClient.ts
300
+ var ZubariApiClient = class {
301
+ config;
302
+ constructor(config) {
303
+ this.config = {
304
+ baseUrl: config.baseUrl.replace(/\/$/, ""),
305
+ // Remove trailing slash
306
+ timeout: config.timeout || 3e4,
307
+ authToken: config.authToken
308
+ };
309
+ }
310
+ /**
311
+ * Set the authentication token
312
+ */
313
+ setAuthToken(token) {
314
+ this.config.authToken = token;
315
+ }
316
+ /**
317
+ * Clear the authentication token
318
+ */
319
+ clearAuthToken() {
320
+ this.config.authToken = void 0;
321
+ }
322
+ /**
323
+ * Make an authenticated request to the API
324
+ */
325
+ async request(method, path, body) {
326
+ const headers = {
327
+ "Content-Type": "application/json"
328
+ };
329
+ if (this.config.authToken) {
330
+ headers["Authorization"] = `Bearer ${this.config.authToken}`;
331
+ }
332
+ const response = await fetch(`${this.config.baseUrl}${path}`, {
333
+ method,
334
+ headers,
335
+ body: body ? JSON.stringify(body) : void 0
336
+ });
337
+ if (!response.ok) {
338
+ const errorData = await response.json().catch(() => ({}));
339
+ throw new Error(errorData.error || `HTTP ${response.status}: ${response.statusText}`);
340
+ }
341
+ return response.json();
342
+ }
343
+ // ============ NFT Methods ============
344
+ /**
345
+ * Get all NFTs with optional filters
346
+ */
347
+ async getNFTs(filters) {
348
+ try {
349
+ const params = new URLSearchParams();
350
+ if (filters) {
351
+ Object.entries(filters).forEach(([key, value]) => {
352
+ if (value !== void 0) {
353
+ params.append(key, String(value));
354
+ }
355
+ });
356
+ }
357
+ const queryString = params.toString();
358
+ const path = `/api/nfts${queryString ? `?${queryString}` : ""}`;
359
+ return await this.request("GET", path);
360
+ } catch (error) {
361
+ return {
362
+ success: false,
363
+ error: error instanceof Error ? error.message : "Failed to get NFTs"
364
+ };
365
+ }
366
+ }
367
+ /**
368
+ * Get a single NFT by ID
369
+ */
370
+ async getNFT(nftId) {
371
+ try {
372
+ const nft = await this.request("GET", `/api/nfts/${nftId}`);
373
+ return { success: true, nft };
374
+ } catch (error) {
375
+ return {
376
+ success: false,
377
+ error: error instanceof Error ? error.message : "Failed to get NFT"
378
+ };
379
+ }
380
+ }
381
+ /**
382
+ * Create a new NFT (lazy minted)
383
+ */
384
+ async createNFT(data, image) {
385
+ try {
386
+ const formData = new FormData();
387
+ formData.append("image", image);
388
+ formData.append("name", data.name);
389
+ if (data.description) formData.append("description", data.description);
390
+ formData.append("price", data.price);
391
+ formData.append("currency", data.currency);
392
+ if (data.royaltyBps !== void 0) formData.append("royaltyBps", String(data.royaltyBps));
393
+ if (data.attributes) formData.append("attributes", JSON.stringify(data.attributes));
394
+ if (data.externalUrl) formData.append("externalUrl", data.externalUrl);
395
+ const headers = {};
396
+ if (this.config.authToken) {
397
+ headers["Authorization"] = `Bearer ${this.config.authToken}`;
398
+ }
399
+ const response = await fetch(`${this.config.baseUrl}/api/nfts`, {
400
+ method: "POST",
401
+ headers,
402
+ body: formData
403
+ });
404
+ if (!response.ok) {
405
+ const errorData = await response.json().catch(() => ({}));
406
+ throw new Error(errorData.error || `HTTP ${response.status}`);
407
+ }
408
+ const nft = await response.json();
409
+ return { success: true, nft };
410
+ } catch (error) {
411
+ return {
412
+ success: false,
413
+ error: error instanceof Error ? error.message : "Failed to create NFT"
414
+ };
415
+ }
416
+ }
417
+ /**
418
+ * Create a voucher for an NFT (EIP-712 signed)
419
+ */
420
+ async createVoucher(nftId, params) {
421
+ try {
422
+ return await this.request("POST", `/api/nfts/${nftId}/voucher`, params);
423
+ } catch (error) {
424
+ return {
425
+ success: false,
426
+ error: error instanceof Error ? error.message : "Failed to create voucher"
427
+ };
428
+ }
429
+ }
430
+ /**
431
+ * Redeem an NFT voucher (buy/mint)
432
+ */
433
+ async redeemVoucher(nftId, params) {
434
+ try {
435
+ return await this.request("POST", `/api/nfts/${nftId}/redeem`, params);
436
+ } catch (error) {
437
+ return {
438
+ success: false,
439
+ error: error instanceof Error ? error.message : "Failed to redeem voucher"
440
+ };
441
+ }
442
+ }
443
+ /**
444
+ * Get voucher status for an NFT
445
+ */
446
+ async getVoucherStatus(nftId) {
447
+ try {
448
+ return await this.request("GET", `/api/nfts/${nftId}/voucher/status`);
449
+ } catch (error) {
450
+ return {
451
+ success: false,
452
+ error: error instanceof Error ? error.message : "Failed to get voucher status"
453
+ };
454
+ }
455
+ }
456
+ // ============ Marketplace Methods ============
457
+ /**
458
+ * Get all active listings
459
+ */
460
+ async getListings(filters) {
461
+ try {
462
+ const params = new URLSearchParams();
463
+ if (filters) {
464
+ Object.entries(filters).forEach(([key, value]) => {
465
+ if (value !== void 0) {
466
+ params.append(key, String(value));
467
+ }
468
+ });
469
+ }
470
+ const queryString = params.toString();
471
+ const path = `/api/market/listings${queryString ? `?${queryString}` : ""}`;
472
+ return await this.request("GET", path);
473
+ } catch (error) {
474
+ return {
475
+ success: false,
476
+ error: error instanceof Error ? error.message : "Failed to get listings"
477
+ };
478
+ }
479
+ }
480
+ /**
481
+ * List an NFT for sale
482
+ */
483
+ async listItem(params) {
484
+ try {
485
+ return await this.request("POST", "/api/market/list", params);
486
+ } catch (error) {
487
+ return {
488
+ success: false,
489
+ error: error instanceof Error ? error.message : "Failed to list item"
490
+ };
491
+ }
492
+ }
493
+ /**
494
+ * Buy a listed NFT
495
+ */
496
+ async buyItem(params) {
497
+ try {
498
+ return await this.request("POST", "/api/market/buy", params);
499
+ } catch (error) {
500
+ return {
501
+ success: false,
502
+ error: error instanceof Error ? error.message : "Failed to buy item"
503
+ };
504
+ }
505
+ }
506
+ /**
507
+ * Cancel a listing
508
+ */
509
+ async cancelListing(params) {
510
+ try {
511
+ return await this.request("POST", "/api/market/cancel", params);
512
+ } catch (error) {
513
+ return {
514
+ success: false,
515
+ error: error instanceof Error ? error.message : "Failed to cancel listing"
516
+ };
517
+ }
518
+ }
519
+ /**
520
+ * Update listing price
521
+ */
522
+ async updateListingPrice(params) {
523
+ try {
524
+ return await this.request("PATCH", "/api/market/price", params);
525
+ } catch (error) {
526
+ return {
527
+ success: false,
528
+ error: error instanceof Error ? error.message : "Failed to update price"
529
+ };
530
+ }
531
+ }
532
+ /**
533
+ * Get current user's listings
534
+ */
535
+ async getMyListings(filters) {
536
+ try {
537
+ const params = new URLSearchParams();
538
+ if (filters) {
539
+ Object.entries(filters).forEach(([key, value]) => {
540
+ if (value !== void 0) {
541
+ params.append(key, String(value));
542
+ }
543
+ });
544
+ }
545
+ const queryString = params.toString();
546
+ const path = `/api/market/my/listings${queryString ? `?${queryString}` : ""}`;
547
+ return await this.request("GET", path);
548
+ } catch (error) {
549
+ return {
550
+ success: false,
551
+ error: error instanceof Error ? error.message : "Failed to get my listings"
552
+ };
553
+ }
554
+ }
555
+ /**
556
+ * Get marketplace statistics
557
+ */
558
+ async getMarketStats() {
559
+ try {
560
+ return await this.request("GET", "/api/market/stats");
561
+ } catch (error) {
562
+ return {
563
+ success: false,
564
+ error: error instanceof Error ? error.message : "Failed to get market stats"
565
+ };
566
+ }
567
+ }
568
+ };
569
+ var DEFAULT_API_URL2 = process.env.NEXT_PUBLIC_API_URL || "https://ckgwifsxka.us-east-2.awsapprunner.com";
570
+ var zubariApiClient = null;
571
+ function getZubariApiClient(config) {
572
+ if (!zubariApiClient || config?.baseUrl && zubariApiClient["config"].baseUrl !== config.baseUrl) {
573
+ zubariApiClient = new ZubariApiClient({
574
+ baseUrl: config?.baseUrl || DEFAULT_API_URL2,
575
+ timeout: config?.timeout,
576
+ authToken: config?.authToken
577
+ });
578
+ } else if (config?.authToken) {
579
+ zubariApiClient.setAuthToken(config.authToken);
580
+ }
581
+ return zubariApiClient;
582
+ }
583
+ function createZubariApiClient(config) {
584
+ return new ZubariApiClient(config);
585
+ }
586
+
299
587
  // src/services/BrowserAddressDerivation.ts
300
588
  var BrowserAddressDerivation_exports = {};
301
589
  __export(BrowserAddressDerivation_exports, {
@@ -489,7 +777,7 @@ function generateSeedPhrase() {
489
777
  }
490
778
 
491
779
  // src/services/ZubariWdkService.ts
492
- var DEFAULT_API_URL2 = "https://ckgwifsxka.us-east-2.awsapprunner.com";
780
+ var DEFAULT_API_URL3 = "https://ckgwifsxka.us-east-2.awsapprunner.com";
493
781
  function isBrowser() {
494
782
  return typeof window !== "undefined" && typeof window.document !== "undefined";
495
783
  }
@@ -514,7 +802,7 @@ var ZubariWdkService = class {
514
802
  constructor(config = {}) {
515
803
  this.config = {
516
804
  network: config.network || "testnet",
517
- apiUrl: config.apiUrl || process.env.NEXT_PUBLIC_API_URL || DEFAULT_API_URL2,
805
+ apiUrl: config.apiUrl || process.env.NEXT_PUBLIC_API_URL || DEFAULT_API_URL3,
518
806
  forceApi: config.forceApi ?? false,
519
807
  timeout: config.timeout || 3e4
520
808
  };
@@ -1339,11 +1627,14 @@ exports.BrowserAddressDerivation = BrowserAddressDerivation_exports;
1339
1627
  exports.SwapService = SwapService;
1340
1628
  exports.TransactionService = TransactionService;
1341
1629
  exports.WdkApiClient = WdkApiClient;
1630
+ exports.ZubariApiClient = ZubariApiClient;
1342
1631
  exports.ZubariWdkService = ZubariWdkService;
1343
1632
  exports.createTransactionService = createTransactionService;
1633
+ exports.createZubariApiClient = createZubariApiClient;
1344
1634
  exports.createZubariWdkService = createZubariWdkService;
1345
1635
  exports.getTransactionService = getTransactionService;
1346
1636
  exports.getWdkApiClient = getWdkApiClient;
1637
+ exports.getZubariApiClient = getZubariApiClient;
1347
1638
  exports.getZubariWdkService = getZubariWdkService;
1348
1639
  exports.isBrowser = isBrowser;
1349
1640
  //# sourceMappingURL=index.js.map