@zubari/sdk 0.2.4 → 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.
@@ -294,6 +294,294 @@ 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
+ };
567
+ var DEFAULT_API_URL2 = process.env.NEXT_PUBLIC_API_URL || "https://ckgwifsxka.us-east-2.awsapprunner.com";
568
+ var zubariApiClient = null;
569
+ function getZubariApiClient(config) {
570
+ if (!zubariApiClient || config?.baseUrl && zubariApiClient["config"].baseUrl !== config.baseUrl) {
571
+ zubariApiClient = new ZubariApiClient({
572
+ baseUrl: config?.baseUrl || DEFAULT_API_URL2,
573
+ timeout: config?.timeout,
574
+ authToken: config?.authToken
575
+ });
576
+ } else if (config?.authToken) {
577
+ zubariApiClient.setAuthToken(config.authToken);
578
+ }
579
+ return zubariApiClient;
580
+ }
581
+ function createZubariApiClient(config) {
582
+ return new ZubariApiClient(config);
583
+ }
584
+
297
585
  // src/services/BrowserAddressDerivation.ts
298
586
  var BrowserAddressDerivation_exports = {};
299
587
  __export(BrowserAddressDerivation_exports, {
@@ -487,7 +775,7 @@ function generateSeedPhrase() {
487
775
  }
488
776
 
489
777
  // src/services/ZubariWdkService.ts
490
- var DEFAULT_API_URL2 = "https://ckgwifsxka.us-east-2.awsapprunner.com";
778
+ var DEFAULT_API_URL3 = "https://ckgwifsxka.us-east-2.awsapprunner.com";
491
779
  function isBrowser() {
492
780
  return typeof window !== "undefined" && typeof window.document !== "undefined";
493
781
  }
@@ -512,7 +800,7 @@ var ZubariWdkService = class {
512
800
  constructor(config = {}) {
513
801
  this.config = {
514
802
  network: config.network || "testnet",
515
- apiUrl: config.apiUrl || process.env.NEXT_PUBLIC_API_URL || DEFAULT_API_URL2,
803
+ apiUrl: config.apiUrl || process.env.NEXT_PUBLIC_API_URL || DEFAULT_API_URL3,
516
804
  forceApi: config.forceApi ?? false,
517
805
  timeout: config.timeout || 3e4
518
806
  };
@@ -1333,6 +1621,6 @@ function createTransactionService(config) {
1333
1621
  return new TransactionService(config);
1334
1622
  }
1335
1623
 
1336
- export { BrowserAddressDerivation_exports as BrowserAddressDerivation, SwapService, TransactionService, WdkApiClient, ZubariWdkService, createTransactionService, createZubariWdkService, getTransactionService, getWdkApiClient, getZubariWdkService, isBrowser };
1624
+ export { BrowserAddressDerivation_exports as BrowserAddressDerivation, SwapService, TransactionService, WdkApiClient, ZubariApiClient, ZubariWdkService, createTransactionService, createZubariApiClient, createZubariWdkService, getTransactionService, getWdkApiClient, getZubariApiClient, getZubariWdkService, isBrowser };
1337
1625
  //# sourceMappingURL=index.mjs.map
1338
1626
  //# sourceMappingURL=index.mjs.map