@passkeyme/auth 2.0.0 → 2.0.2

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
@@ -323,7 +323,7 @@ class PasskeymeApiClient {
323
323
  * Get authentication configuration for the app
324
324
  */
325
325
  async getConfig() {
326
- const backendConfig = await this.request(`${this.baseUrl}/api/auth/${this.appId}/config`);
326
+ const backendConfig = await this.request(`/api/auth/${this.appId}/config`);
327
327
  // Map backend response to SDK format
328
328
  return {
329
329
  appId: backendConfig.app_id,
@@ -399,7 +399,7 @@ class PasskeymeApiClient {
399
399
  token: token,
400
400
  app_id: this.appId,
401
401
  });
402
- const response = (await this.request(`${this.baseUrl}/api/auth/verify-token?${params.toString()}`, {
402
+ const response = (await this.request(`/api/auth/verify-token?${params.toString()}`, {
403
403
  method: "GET",
404
404
  }));
405
405
  if (!response.valid) {
@@ -453,6 +453,179 @@ class PasskeymeApiClient {
453
453
  }
454
454
  }
455
455
 
456
+ /**
457
+ * Platform SDK Interface for Passkeyme
458
+ *
459
+ * This interface abstracts platform-specific passkey operations,
460
+ * allowing the core SDK to work across web, React Native, and other platforms.
461
+ */
462
+ /**
463
+ * No-op implementation for platforms without passkey support
464
+ */
465
+ class NoOpPasskeySDK {
466
+ async register(_options) {
467
+ return {
468
+ success: false,
469
+ error: "Passkeys not supported on this platform",
470
+ };
471
+ }
472
+ async authenticate(_options) {
473
+ return {
474
+ success: false,
475
+ error: "Passkeys not supported on this platform",
476
+ };
477
+ }
478
+ isSupported() {
479
+ return false;
480
+ }
481
+ canUseDiscoverableCredentials() {
482
+ return false;
483
+ }
484
+ supportsBiometrics() {
485
+ return false;
486
+ }
487
+ }
488
+
489
+ /**
490
+ * Web Platform SDK Implementation
491
+ *
492
+ * Wraps the passkeyme-web-sdk to implement the PasskeySDK interface
493
+ */
494
+ /**
495
+ * Web implementation of PasskeySDK using passkeyme-web-sdk
496
+ *
497
+ * This implementation should be used for web browsers that support WebAuthn.
498
+ * The actual passkeyme-web-sdk dependency should be provided by the consuming package.
499
+ */
500
+ class WebPasskeySDK {
501
+ constructor(webSDK) {
502
+ this.webSDK = webSDK;
503
+ }
504
+ async register(options) {
505
+ try {
506
+ if (!this.webSDK) {
507
+ return {
508
+ success: false,
509
+ error: "Web SDK not available",
510
+ };
511
+ }
512
+ // Extract the challenge from the options
513
+ // The options object contains: { username, displayName, challenge, ...otherChallengeData }
514
+ const { username, displayName, challenge, ...otherData } = options;
515
+ // Pass the challenge data directly to the web SDK
516
+ const challengeData = challenge || otherData;
517
+ // Call the web SDK register method with the challenge
518
+ const result = await this.webSDK.passkeyRegister(challengeData);
519
+ return {
520
+ success: true,
521
+ credentialId: result.credentialId || result.id,
522
+ data: result,
523
+ };
524
+ }
525
+ catch (error) {
526
+ return {
527
+ success: false,
528
+ error: error.message || "Registration failed",
529
+ };
530
+ }
531
+ }
532
+ async authenticate(options) {
533
+ try {
534
+ if (!this.webSDK) {
535
+ return {
536
+ success: false,
537
+ error: "Web SDK not available",
538
+ };
539
+ }
540
+ // Extract the challenge from the options
541
+ // The options object contains: { username, challenge, ...otherChallengeData }
542
+ const { username, challenge, ...otherData } = options;
543
+ // Pass the challenge data directly to the web SDK
544
+ const challengeData = challenge || otherData;
545
+ // Call the web SDK authenticate method with the challenge
546
+ const result = await this.webSDK.passkeyAuthenticate(challengeData);
547
+ return {
548
+ success: true,
549
+ assertion: result,
550
+ data: result,
551
+ };
552
+ }
553
+ catch (error) {
554
+ return {
555
+ success: false,
556
+ error: error.message || "Authentication failed",
557
+ };
558
+ }
559
+ }
560
+ isSupported() {
561
+ // Check if we're in a browser environment with WebAuthn support
562
+ return (typeof window !== "undefined" &&
563
+ typeof navigator !== "undefined" &&
564
+ "credentials" in navigator &&
565
+ typeof navigator.credentials.create === "function");
566
+ }
567
+ async getAvailableAuthenticators() {
568
+ // This is a basic implementation - the web SDK might provide more detailed info
569
+ const authenticators = [];
570
+ if (this.isSupported()) {
571
+ // Basic platform authenticator info
572
+ authenticators.push({
573
+ type: "platform",
574
+ supportsBiometrics: true, // Assume platform authenticators support biometrics
575
+ supportsUserVerification: true,
576
+ });
577
+ // Basic cross-platform authenticator info
578
+ authenticators.push({
579
+ type: "cross-platform",
580
+ supportsBiometrics: false,
581
+ supportsUserVerification: true,
582
+ });
583
+ }
584
+ return authenticators;
585
+ }
586
+ canUseDiscoverableCredentials() {
587
+ // Check if the platform supports discoverable credentials (resident keys)
588
+ return this.isSupported();
589
+ }
590
+ supportsBiometrics() {
591
+ // On web, this depends on the platform authenticator availability
592
+ // This is a simplified check - a more sophisticated implementation
593
+ // would actually test for platform authenticator support
594
+ return (this.isSupported() &&
595
+ typeof window !== "undefined" &&
596
+ /Mac|Win|Linux/.test(navigator.platform));
597
+ }
598
+ async initialize(config) {
599
+ // Initialize the web SDK if it has an init method
600
+ if (this.webSDK && typeof this.webSDK.init === "function") {
601
+ await this.webSDK.init(config);
602
+ }
603
+ }
604
+ async cleanup() {
605
+ // Cleanup if the web SDK has a cleanup method
606
+ if (this.webSDK && typeof this.webSDK.cleanup === "function") {
607
+ await this.webSDK.cleanup();
608
+ }
609
+ }
610
+ }
611
+
612
+ /**
613
+ * Platform SDK exports
614
+ */
615
+ // Conditionally export React Native SDK only in React Native environments
616
+ exports.ReactNativePasskeySDK = null;
617
+ try {
618
+ // Only try to load React Native SDK if we're actually in a React Native environment
619
+ if (typeof navigator !== "undefined" && navigator.product === "ReactNative") {
620
+ const { ReactNativePasskeySDK: RNPasskeySDK, } = require("./ReactNativePasskeySDK");
621
+ exports.ReactNativePasskeySDK = RNPasskeySDK;
622
+ }
623
+ }
624
+ catch (error) {
625
+ // React Native SDK not available or not in React Native environment
626
+ exports.ReactNativePasskeySDK = null;
627
+ }
628
+
456
629
  /**
457
630
  * Browser storage implementation using localStorage or sessionStorage
458
631
  */
@@ -629,179 +802,6 @@ TokenStorage.REFRESH_TOKEN_KEY = "passkeyme_refresh_token";
629
802
  TokenStorage.EXPIRES_AT_KEY = "passkeyme_expires_at";
630
803
  TokenStorage.TOKEN_TYPE_KEY = "passkeyme_token_type";
631
804
 
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
805
  /**
806
806
  * Main Passkeyme Authentication SDK class
807
807
  */
@@ -822,7 +822,7 @@ class PasskeymeAuth {
822
822
  ? `${window.location.origin}/auth/callback`
823
823
  : "http://localhost:3000/auth/callback";
824
824
  // Support both baseUrl and apiUrl for flexibility
825
- const serverUrl = config.apiUrl || config.baseUrl || "https://auth.passkeyme.com";
825
+ const serverUrl = config.baseUrl || "https://auth.passkeyme.com";
826
826
  this.config = {
827
827
  appId: config.appId,
828
828
  baseUrl: serverUrl,