capacitor-biometric-authentication
Version:
Framework-agnostic biometric authentication library. Works with React, Vue, Angular, or vanilla JS. No providers required!
86 lines • 3.76 kB
JavaScript
/**
* Unified error codes for biometric authentication
* Using UPPER_CASE convention for enum values (more conventional)
*/
export var BiometricErrorCode;
(function (BiometricErrorCode) {
/** Authentication attempt failed */
BiometricErrorCode["AUTHENTICATION_FAILED"] = "AUTHENTICATION_FAILED";
/** User cancelled the authentication */
BiometricErrorCode["USER_CANCELLED"] = "USER_CANCELLED";
/** System cancelled the authentication */
BiometricErrorCode["SYSTEM_CANCELLED"] = "SYSTEM_CANCELLED";
/** Biometric hardware not available */
BiometricErrorCode["NOT_AVAILABLE"] = "NOT_AVAILABLE";
/** Biometric hardware unavailable (legacy alias) */
BiometricErrorCode["BIOMETRIC_UNAVAILABLE"] = "BIOMETRIC_UNAVAILABLE";
/** Permission denied by user */
BiometricErrorCode["PERMISSION_DENIED"] = "PERMISSION_DENIED";
/** User is locked out due to too many failed attempts */
BiometricErrorCode["LOCKED_OUT"] = "LOCKED_OUT";
/** Lockout (legacy alias) */
BiometricErrorCode["LOCKOUT"] = "LOCKOUT";
/** Invalid context for authentication */
BiometricErrorCode["INVALID_CONTEXT"] = "INVALID_CONTEXT";
/** No biometrics enrolled on device */
BiometricErrorCode["NOT_ENROLLED"] = "NOT_ENROLLED";
/** Authentication timed out */
BiometricErrorCode["TIMEOUT"] = "TIMEOUT";
/** Platform not supported */
BiometricErrorCode["PLATFORM_NOT_SUPPORTED"] = "PLATFORM_NOT_SUPPORTED";
/** Unknown error occurred */
BiometricErrorCode["UNKNOWN"] = "UNKNOWN";
/** Unknown error (legacy alias) */
BiometricErrorCode["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
})(BiometricErrorCode || (BiometricErrorCode = {}));
/**
* Reasons why biometric authentication is unavailable
*/
export var BiometricUnavailableReason;
(function (BiometricUnavailableReason) {
/** Device doesn't have biometric hardware */
BiometricUnavailableReason["NO_HARDWARE"] = "noHardware";
/** Biometric hardware is unavailable */
BiometricUnavailableReason["HARDWARE_UNAVAILABLE"] = "hardwareUnavailable";
/** No biometrics enrolled on device */
BiometricUnavailableReason["NO_ENROLLED_BIOMETRICS"] = "noEnrolledBiometrics";
/** User denied permission */
BiometricUnavailableReason["PERMISSION_DENIED"] = "permissionDenied";
/** Biometric not supported on this platform */
BiometricUnavailableReason["NOT_SUPPORTED"] = "notSupported";
/** User locked out due to failed attempts */
BiometricUnavailableReason["LOCKED_OUT"] = "lockedOut";
/** User disabled biometrics */
BiometricUnavailableReason["USER_DISABLED"] = "userDisabled";
})(BiometricUnavailableReason || (BiometricUnavailableReason = {}));
/**
* Map legacy camelCase error codes to UPPER_CASE
* Used for backward compatibility
*/
export const errorCodeMapping = {
authenticationFailed: BiometricErrorCode.AUTHENTICATION_FAILED,
userCancelled: BiometricErrorCode.USER_CANCELLED,
systemCancelled: BiometricErrorCode.SYSTEM_CANCELLED,
notAvailable: BiometricErrorCode.NOT_AVAILABLE,
permissionDenied: BiometricErrorCode.PERMISSION_DENIED,
lockedOut: BiometricErrorCode.LOCKED_OUT,
invalidContext: BiometricErrorCode.INVALID_CONTEXT,
notEnrolled: BiometricErrorCode.NOT_ENROLLED,
timeout: BiometricErrorCode.TIMEOUT,
unknown: BiometricErrorCode.UNKNOWN,
};
/**
* Normalize error code to UPPER_CASE format
*/
export function normalizeErrorCode(code) {
// Already in correct format
if (Object.values(BiometricErrorCode).includes(code)) {
return code;
}
// Map legacy format
if (code in errorCodeMapping) {
return errorCodeMapping[code];
}
return BiometricErrorCode.UNKNOWN;
}
//# sourceMappingURL=errors.js.map