@passkeyme/auth 1.1.1 → 1.1.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.esm.js CHANGED
@@ -11,6 +11,19 @@ class Logger {
11
11
  ...config,
12
12
  };
13
13
  }
14
+ /**
15
+ * Update logger configuration
16
+ */
17
+ setConfig(config) {
18
+ this.config = { ...this.config, ...config };
19
+ }
20
+ /**
21
+ * Enable debug logging
22
+ */
23
+ enableDebug() {
24
+ this.config.enabled = true;
25
+ this.config.level = "debug";
26
+ }
14
27
  shouldLog(level) {
15
28
  if (!this.config.enabled)
16
29
  return false;
@@ -763,168 +776,21 @@ class WebPasskeySDK {
763
776
  }
764
777
 
765
778
  /**
766
- * React Native Platform SDK Implementation
767
- *
768
- * Bridges to native iOS (CocoaPods) and Android (Gradle) SDKs
769
- */
770
- /**
771
- * React Native implementation of PasskeySDK
772
- *
773
- * This implementation bridges to native iOS and Android SDKs:
774
- * - iOS: https://cocoapods.org/pods/PasskeymeSDK
775
- * - Android: https://maven.pkg.github.com/justincrosbie/passkeyme-android-sdk
779
+ * Platform SDK exports
776
780
  */
777
- class ReactNativePasskeySDK {
778
- constructor() {
779
- try {
780
- // Try to import React Native module
781
- const { NativeModules } = require("react-native");
782
- this.nativeModule = NativeModules.PasskeymeNativeModule;
783
- }
784
- catch (error) {
785
- console.warn("React Native environment not detected or PasskeymeNativeModule not available");
786
- this.nativeModule = null;
787
- }
788
- }
789
- async register(options) {
790
- try {
791
- if (!this.nativeModule) {
792
- return {
793
- success: false,
794
- error: "Native module not available",
795
- };
796
- }
797
- // Call the native module register method
798
- const result = await this.nativeModule.register({
799
- ...options,
800
- requireUserVerification: options.requireUserVerification || false,
801
- });
802
- return {
803
- success: result.success,
804
- credentialId: result.credentialId,
805
- error: result.error,
806
- data: result,
807
- };
808
- }
809
- catch (error) {
810
- return {
811
- success: false,
812
- error: error.message || "Registration failed",
813
- };
814
- }
815
- }
816
- async authenticate(options) {
817
- try {
818
- if (!this.nativeModule) {
819
- return {
820
- success: false,
821
- error: "Native module not available",
822
- };
823
- }
824
- // Call the native module authenticate method
825
- const result = await this.nativeModule.authenticate({
826
- ...options,
827
- requireUserVerification: options.requireUserVerification || false,
828
- });
829
- return {
830
- success: result.success,
831
- assertion: result.assertion,
832
- error: result.error,
833
- data: result,
834
- };
835
- }
836
- catch (error) {
837
- return {
838
- success: false,
839
- error: error.message || "Authentication failed",
840
- };
841
- }
842
- }
843
- isSupported() {
844
- return this.nativeModule != null;
845
- }
846
- async getAvailableAuthenticators() {
847
- try {
848
- if (!this.nativeModule) {
849
- return [];
850
- }
851
- // Call native method to get available authenticators
852
- const authenticators = await this.nativeModule.getAvailableAuthenticators();
853
- return authenticators || [];
854
- }
855
- catch (error) {
856
- console.warn("Failed to get available authenticators:", error);
857
- return [];
858
- }
859
- }
860
- canUseDiscoverableCredentials() {
861
- // Most modern mobile devices support discoverable credentials
862
- return this.isSupported();
863
- }
864
- supportsBiometrics() {
865
- // Mobile devices typically support biometric authentication
866
- return this.isSupported();
867
- }
868
- async initialize(config) {
869
- if (this.nativeModule &&
870
- typeof this.nativeModule.initialize === "function") {
871
- await this.nativeModule.initialize(config);
872
- }
873
- }
874
- async cleanup() {
875
- if (this.nativeModule && typeof this.nativeModule.cleanup === "function") {
876
- await this.nativeModule.cleanup();
877
- }
878
- }
879
- /**
880
- * Check if the device supports Face ID (iOS) or Face Unlock (Android)
881
- */
882
- async supportsFaceRecognition() {
883
- try {
884
- if (!this.nativeModule)
885
- return false;
886
- return await this.nativeModule.supportsFaceRecognition();
887
- }
888
- catch (_a) {
889
- return false;
890
- }
891
- }
892
- /**
893
- * Check if the device supports Touch ID (iOS) or Fingerprint (Android)
894
- */
895
- async supportsFingerprint() {
896
- try {
897
- if (!this.nativeModule)
898
- return false;
899
- return await this.nativeModule.supportsFingerprint();
900
- }
901
- catch (_a) {
902
- return false;
903
- }
904
- }
905
- /**
906
- * Get detailed biometric capabilities
907
- */
908
- async getBiometricCapabilities() {
909
- try {
910
- if (!this.nativeModule) {
911
- return {
912
- faceRecognition: false,
913
- fingerprint: false,
914
- voiceRecognition: false,
915
- };
916
- }
917
- return await this.nativeModule.getBiometricCapabilities();
918
- }
919
- catch (_a) {
920
- return {
921
- faceRecognition: false,
922
- fingerprint: false,
923
- voiceRecognition: false,
924
- };
925
- }
781
+ // Conditionally export React Native SDK only in React Native environments
782
+ let ReactNativePasskeySDK = null;
783
+ try {
784
+ // Only try to load React Native SDK if we're actually in a React Native environment
785
+ if (typeof navigator !== "undefined" && navigator.product === "ReactNative") {
786
+ const { ReactNativePasskeySDK: RNPasskeySDK, } = require("./ReactNativePasskeySDK");
787
+ ReactNativePasskeySDK = RNPasskeySDK;
926
788
  }
927
789
  }
790
+ catch (error) {
791
+ // React Native SDK not available or not in React Native environment
792
+ ReactNativePasskeySDK = null;
793
+ }
928
794
 
929
795
  /**
930
796
  * Main PasskeyMe Authentication SDK class
@@ -962,6 +828,10 @@ class PasskeymeAuth {
962
828
  this.tokenStorage = new TokenStorage(storage);
963
829
  // Use provided passkey SDK or create default one
964
830
  this.passkeySDK = config.passkeySDK || this.createDefaultPasskeySDK();
831
+ // Configure logger with debug setting from config
832
+ if (this.config.debug) {
833
+ logger.enableDebug();
834
+ }
965
835
  logger.debug("Initialized with config:", this.config);
966
836
  }
967
837
  /**
@@ -1626,11 +1496,22 @@ class PasskeymeAuth {
1626
1496
  }
1627
1497
  try {
1628
1498
  // Get app configuration to check discoverable credentials support
1629
- const appConfig = await this.getAppConfig();
1630
- logger.debug("App config loaded:", {
1631
- discoverableCredentialsEnabled: appConfig.discoverableCredentialsEnabled,
1632
- passkeyEnabled: appConfig.passkeyEnabled,
1633
- });
1499
+ let appConfig;
1500
+ try {
1501
+ appConfig = await this.getAppConfig();
1502
+ logger.debug("App config loaded:", {
1503
+ discoverableCredentialsEnabled: appConfig.discoverableCredentialsEnabled,
1504
+ passkeyEnabled: appConfig.passkeyEnabled,
1505
+ });
1506
+ }
1507
+ catch (configError) {
1508
+ logger.debug("Failed to load app config, assuming passkeys enabled:", configError);
1509
+ // If we can't load config, assume passkeys are enabled and no discoverable credentials
1510
+ appConfig = {
1511
+ passkeyEnabled: true,
1512
+ discoverableCredentialsEnabled: false,
1513
+ };
1514
+ }
1634
1515
  // If passkeys are disabled at the app level, fallback to hosted auth
1635
1516
  if (!appConfig.passkeyEnabled) {
1636
1517
  logger.debug("Passkeys disabled for this app, falling back to hosted auth");
@@ -1654,7 +1535,10 @@ class PasskeymeAuth {
1654
1535
  }
1655
1536
  }
1656
1537
  // Try to get stored username for fallback
1657
- const storedUsername = await this.storage.getItem(`last_username_${this.config.appId}`);
1538
+ const storageKey = `last_username_${this.config.appId}`;
1539
+ logger.debug("Looking for stored username with key:", storageKey);
1540
+ const storedUsername = await this.storage.getItem(storageKey);
1541
+ logger.debug("Found stored username:", storedUsername);
1658
1542
  if (storedUsername) {
1659
1543
  logger.debug("Using stored username for targeted authentication:", storedUsername);
1660
1544
  authUsername = storedUsername;