@passkeyme/auth 2.0.1 → 2.0.3

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
@@ -267,10 +267,11 @@ class PasskeymeApiClient {
267
267
  this.appId = appId;
268
268
  this.baseUrl = baseUrl.replace(/\/$/, ""); // Remove trailing slash
269
269
  this.debug = debug;
270
+ this.log("API Client initialized with baseUrl:", this.baseUrl);
270
271
  }
271
272
  log(...args) {
272
273
  if (this.debug) {
273
- logger.debug("[PasskeymeAuth]", ...args);
274
+ logger.debug("[PasskeymeApiClient]", ...args);
274
275
  }
275
276
  }
276
277
  async request(endpoint, options = {}) {
@@ -453,6 +454,179 @@ class PasskeymeApiClient {
453
454
  }
454
455
  }
455
456
 
457
+ /**
458
+ * Platform SDK Interface for Passkeyme
459
+ *
460
+ * This interface abstracts platform-specific passkey operations,
461
+ * allowing the core SDK to work across web, React Native, and other platforms.
462
+ */
463
+ /**
464
+ * No-op implementation for platforms without passkey support
465
+ */
466
+ class NoOpPasskeySDK {
467
+ async register(_options) {
468
+ return {
469
+ success: false,
470
+ error: "Passkeys not supported on this platform",
471
+ };
472
+ }
473
+ async authenticate(_options) {
474
+ return {
475
+ success: false,
476
+ error: "Passkeys not supported on this platform",
477
+ };
478
+ }
479
+ isSupported() {
480
+ return false;
481
+ }
482
+ canUseDiscoverableCredentials() {
483
+ return false;
484
+ }
485
+ supportsBiometrics() {
486
+ return false;
487
+ }
488
+ }
489
+
490
+ /**
491
+ * Web Platform SDK Implementation
492
+ *
493
+ * Wraps the passkeyme-web-sdk to implement the PasskeySDK interface
494
+ */
495
+ /**
496
+ * Web implementation of PasskeySDK using passkeyme-web-sdk
497
+ *
498
+ * This implementation should be used for web browsers that support WebAuthn.
499
+ * The actual passkeyme-web-sdk dependency should be provided by the consuming package.
500
+ */
501
+ class WebPasskeySDK {
502
+ constructor(webSDK) {
503
+ this.webSDK = webSDK;
504
+ }
505
+ async register(options) {
506
+ try {
507
+ if (!this.webSDK) {
508
+ return {
509
+ success: false,
510
+ error: "Web SDK not available",
511
+ };
512
+ }
513
+ // Extract the challenge from the options
514
+ // The options object contains: { username, displayName, challenge, ...otherChallengeData }
515
+ const { username, displayName, challenge, ...otherData } = options;
516
+ // Pass the challenge data directly to the web SDK
517
+ const challengeData = challenge || otherData;
518
+ // Call the web SDK register method with the challenge
519
+ const result = await this.webSDK.passkeyRegister(challengeData);
520
+ return {
521
+ success: true,
522
+ credentialId: result.credentialId || result.id,
523
+ data: result,
524
+ };
525
+ }
526
+ catch (error) {
527
+ return {
528
+ success: false,
529
+ error: error.message || "Registration failed",
530
+ };
531
+ }
532
+ }
533
+ async authenticate(options) {
534
+ try {
535
+ if (!this.webSDK) {
536
+ return {
537
+ success: false,
538
+ error: "Web SDK not available",
539
+ };
540
+ }
541
+ // Extract the challenge from the options
542
+ // The options object contains: { username, challenge, ...otherChallengeData }
543
+ const { username, challenge, ...otherData } = options;
544
+ // Pass the challenge data directly to the web SDK
545
+ const challengeData = challenge || otherData;
546
+ // Call the web SDK authenticate method with the challenge
547
+ const result = await this.webSDK.passkeyAuthenticate(challengeData);
548
+ return {
549
+ success: true,
550
+ assertion: result,
551
+ data: result,
552
+ };
553
+ }
554
+ catch (error) {
555
+ return {
556
+ success: false,
557
+ error: error.message || "Authentication failed",
558
+ };
559
+ }
560
+ }
561
+ isSupported() {
562
+ // Check if we're in a browser environment with WebAuthn support
563
+ return (typeof window !== "undefined" &&
564
+ typeof navigator !== "undefined" &&
565
+ "credentials" in navigator &&
566
+ typeof navigator.credentials.create === "function");
567
+ }
568
+ async getAvailableAuthenticators() {
569
+ // This is a basic implementation - the web SDK might provide more detailed info
570
+ const authenticators = [];
571
+ if (this.isSupported()) {
572
+ // Basic platform authenticator info
573
+ authenticators.push({
574
+ type: "platform",
575
+ supportsBiometrics: true, // Assume platform authenticators support biometrics
576
+ supportsUserVerification: true,
577
+ });
578
+ // Basic cross-platform authenticator info
579
+ authenticators.push({
580
+ type: "cross-platform",
581
+ supportsBiometrics: false,
582
+ supportsUserVerification: true,
583
+ });
584
+ }
585
+ return authenticators;
586
+ }
587
+ canUseDiscoverableCredentials() {
588
+ // Check if the platform supports discoverable credentials (resident keys)
589
+ return this.isSupported();
590
+ }
591
+ supportsBiometrics() {
592
+ // On web, this depends on the platform authenticator availability
593
+ // This is a simplified check - a more sophisticated implementation
594
+ // would actually test for platform authenticator support
595
+ return (this.isSupported() &&
596
+ typeof window !== "undefined" &&
597
+ /Mac|Win|Linux/.test(navigator.platform));
598
+ }
599
+ async initialize(config) {
600
+ // Initialize the web SDK if it has an init method
601
+ if (this.webSDK && typeof this.webSDK.init === "function") {
602
+ await this.webSDK.init(config);
603
+ }
604
+ }
605
+ async cleanup() {
606
+ // Cleanup if the web SDK has a cleanup method
607
+ if (this.webSDK && typeof this.webSDK.cleanup === "function") {
608
+ await this.webSDK.cleanup();
609
+ }
610
+ }
611
+ }
612
+
613
+ /**
614
+ * Platform SDK exports
615
+ */
616
+ // Conditionally export React Native SDK only in React Native environments
617
+ exports.ReactNativePasskeySDK = null;
618
+ try {
619
+ // Only try to load React Native SDK if we're actually in a React Native environment
620
+ if (typeof navigator !== "undefined" && navigator.product === "ReactNative") {
621
+ const { ReactNativePasskeySDK: RNPasskeySDK, } = require("./ReactNativePasskeySDK");
622
+ exports.ReactNativePasskeySDK = RNPasskeySDK;
623
+ }
624
+ }
625
+ catch (error) {
626
+ // React Native SDK not available or not in React Native environment
627
+ exports.ReactNativePasskeySDK = null;
628
+ }
629
+
456
630
  /**
457
631
  * Browser storage implementation using localStorage or sessionStorage
458
632
  */
@@ -629,179 +803,6 @@ TokenStorage.REFRESH_TOKEN_KEY = "passkeyme_refresh_token";
629
803
  TokenStorage.EXPIRES_AT_KEY = "passkeyme_expires_at";
630
804
  TokenStorage.TOKEN_TYPE_KEY = "passkeyme_token_type";
631
805
 
632
- /**
633
- * Platform SDK Interface for Passkeyme
634
- *
635
- * This interface abstracts platform-specific passkey operations,
636
- * allowing the core SDK to work across web, React Native, and other platforms.
637
- */
638
- /**
639
- * No-op implementation for platforms without passkey support
640
- */
641
- class NoOpPasskeySDK {
642
- async register(_options) {
643
- return {
644
- success: false,
645
- error: "Passkeys not supported on this platform",
646
- };
647
- }
648
- async authenticate(_options) {
649
- return {
650
- success: false,
651
- error: "Passkeys not supported on this platform",
652
- };
653
- }
654
- isSupported() {
655
- return false;
656
- }
657
- canUseDiscoverableCredentials() {
658
- return false;
659
- }
660
- supportsBiometrics() {
661
- return false;
662
- }
663
- }
664
-
665
- /**
666
- * Web Platform SDK Implementation
667
- *
668
- * Wraps the passkeyme-web-sdk to implement the PasskeySDK interface
669
- */
670
- /**
671
- * Web implementation of PasskeySDK using passkeyme-web-sdk
672
- *
673
- * This implementation should be used for web browsers that support WebAuthn.
674
- * The actual passkeyme-web-sdk dependency should be provided by the consuming package.
675
- */
676
- class WebPasskeySDK {
677
- constructor(webSDK) {
678
- this.webSDK = webSDK;
679
- }
680
- async register(options) {
681
- try {
682
- if (!this.webSDK) {
683
- return {
684
- success: false,
685
- error: "Web SDK not available",
686
- };
687
- }
688
- // Extract the challenge from the options
689
- // The options object contains: { username, displayName, challenge, ...otherChallengeData }
690
- const { username, displayName, challenge, ...otherData } = options;
691
- // Pass the challenge data directly to the web SDK
692
- const challengeData = challenge || otherData;
693
- // Call the web SDK register method with the challenge
694
- const result = await this.webSDK.passkeyRegister(challengeData);
695
- return {
696
- success: true,
697
- credentialId: result.credentialId || result.id,
698
- data: result,
699
- };
700
- }
701
- catch (error) {
702
- return {
703
- success: false,
704
- error: error.message || "Registration failed",
705
- };
706
- }
707
- }
708
- async authenticate(options) {
709
- try {
710
- if (!this.webSDK) {
711
- return {
712
- success: false,
713
- error: "Web SDK not available",
714
- };
715
- }
716
- // Extract the challenge from the options
717
- // The options object contains: { username, challenge, ...otherChallengeData }
718
- const { username, challenge, ...otherData } = options;
719
- // Pass the challenge data directly to the web SDK
720
- const challengeData = challenge || otherData;
721
- // Call the web SDK authenticate method with the challenge
722
- const result = await this.webSDK.passkeyAuthenticate(challengeData);
723
- return {
724
- success: true,
725
- assertion: result,
726
- data: result,
727
- };
728
- }
729
- catch (error) {
730
- return {
731
- success: false,
732
- error: error.message || "Authentication failed",
733
- };
734
- }
735
- }
736
- isSupported() {
737
- // Check if we're in a browser environment with WebAuthn support
738
- return (typeof window !== "undefined" &&
739
- typeof navigator !== "undefined" &&
740
- "credentials" in navigator &&
741
- typeof navigator.credentials.create === "function");
742
- }
743
- async getAvailableAuthenticators() {
744
- // This is a basic implementation - the web SDK might provide more detailed info
745
- const authenticators = [];
746
- if (this.isSupported()) {
747
- // Basic platform authenticator info
748
- authenticators.push({
749
- type: "platform",
750
- supportsBiometrics: true, // Assume platform authenticators support biometrics
751
- supportsUserVerification: true,
752
- });
753
- // Basic cross-platform authenticator info
754
- authenticators.push({
755
- type: "cross-platform",
756
- supportsBiometrics: false,
757
- supportsUserVerification: true,
758
- });
759
- }
760
- return authenticators;
761
- }
762
- canUseDiscoverableCredentials() {
763
- // Check if the platform supports discoverable credentials (resident keys)
764
- return this.isSupported();
765
- }
766
- supportsBiometrics() {
767
- // On web, this depends on the platform authenticator availability
768
- // This is a simplified check - a more sophisticated implementation
769
- // would actually test for platform authenticator support
770
- return (this.isSupported() &&
771
- typeof window !== "undefined" &&
772
- /Mac|Win|Linux/.test(navigator.platform));
773
- }
774
- async initialize(config) {
775
- // Initialize the web SDK if it has an init method
776
- if (this.webSDK && typeof this.webSDK.init === "function") {
777
- await this.webSDK.init(config);
778
- }
779
- }
780
- async cleanup() {
781
- // Cleanup if the web SDK has a cleanup method
782
- if (this.webSDK && typeof this.webSDK.cleanup === "function") {
783
- await this.webSDK.cleanup();
784
- }
785
- }
786
- }
787
-
788
- /**
789
- * Platform SDK exports
790
- */
791
- // Conditionally export React Native SDK only in React Native environments
792
- exports.ReactNativePasskeySDK = null;
793
- try {
794
- // Only try to load React Native SDK if we're actually in a React Native environment
795
- if (typeof navigator !== "undefined" && navigator.product === "ReactNative") {
796
- const { ReactNativePasskeySDK: RNPasskeySDK, } = require("./ReactNativePasskeySDK");
797
- exports.ReactNativePasskeySDK = RNPasskeySDK;
798
- }
799
- }
800
- catch (error) {
801
- // React Native SDK not available or not in React Native environment
802
- exports.ReactNativePasskeySDK = null;
803
- }
804
-
805
806
  /**
806
807
  * Main Passkeyme Authentication SDK class
807
808
  */
@@ -822,7 +823,7 @@ class PasskeymeAuth {
822
823
  ? `${window.location.origin}/auth/callback`
823
824
  : "http://localhost:3000/auth/callback";
824
825
  // Support both baseUrl and apiUrl for flexibility
825
- const serverUrl = config.apiUrl || config.baseUrl || "https://auth.passkeyme.com";
826
+ const serverUrl = config.baseUrl || "https://auth.passkeyme.com";
826
827
  this.config = {
827
828
  appId: config.appId,
828
829
  baseUrl: serverUrl,
@@ -843,6 +844,7 @@ class PasskeymeAuth {
843
844
  logger.enableDebug();
844
845
  logger.debug("[DEBUG] Logger debug mode enabled, testing logger...");
845
846
  logger.debug("[DEBUG] Logger config after enableDebug:", logger.getConfig());
847
+ logger.debug("config.baseUrl:", this.config.baseUrl);
846
848
  logger.debug("Logger test message - if you see this, logger is working");
847
849
  }
848
850
  logger.debug("Initialized with config:", this.config);