@webority/mobile-core 0.189.0 → 0.190.1

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/README.md CHANGED
@@ -405,13 +405,15 @@ JWT-shaped strings, and the values of keys named `token`, `accessToken`, `refres
405
405
  ```ts
406
406
  import { useAppLock } from '@webority/mobile-core/appLock';
407
407
 
408
- const { locked, enabled, biometricAvailable, availabilityKnown, ready, setEnabled, unlock, lock } = useAppLock({ active: isSignedIn });
408
+ const { locked, enabled, biometricAvailable, availabilityKnown, ready, setEnabled, unlock, lock, markUnlocked } = useAppLock({ active: isSignedIn });
409
409
  ```
410
410
 
411
411
  - `availabilityKnown` is false until the first biometric check settles. Until then `biometricAvailable` is not an answer yet, so a screen should wait before it shows the lock as unavailable or disables its switch.
412
412
  - `lock()` locks the app on demand; `ready` is false until the saved time is read, so render nothing until it is true.
413
413
  - `setEnabled(next)` and `unlock(reason)` return an `AppLockResult`: `{ ok: true }`, or `{ ok: false, reason }` with the reason `cancelled`, `lockout`, `not-enrolled`, `not-available` or `failed`.
414
414
  - `policy` overrides the delay and the two storage keys; the defaults are used for any key left out.
415
+ - `policy.enabledByDefault` sets whether the lock is on when the person has made no choice; without it the lock is on when the phone has a fingerprint or face enrolled. An app that unlocks with its own PIN passes `true`.
416
+ - `markUnlocked()` clears the lock after the app's own check, such as a PIN screen.
415
417
 
416
418
  ## Certificate pinning
417
419
 
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.authenticateBiometric=authenticateBiometric,exports.isBiometricAvailable=isBiometricAvailable,exports.useAppLock=useAppLock;var cache,LocalAuthentication=_interopRequireWildcard(require("expo-local-authentication")),_react=require("react"),_reactNative=require("react-native"),_index=require("../logger/index.js"),_index2=require("../storage/index.js");function _interopRequireWildcard(e,t){if(!t&&e&&e.__esModule)return e;var a,r,c=Object.defineProperty,n={__proto__:null,default:e};if(Object(e)!==e)return n;if(cache||"function"!=typeof WeakMap||(cache=new WeakMap),cache){if(cache.has(e))return cache.get(e);cache.set(e,n)}for(r in e)"default"!==r&&{}.hasOwnProperty.call(e,r)&&((a=c&&Object.getOwnPropertyDescriptor(e,r))&&(a.get||a.set)?c(n,r,a):n[r]=e[r]);return n}const DEFAULT_POLICY={lockAfterMs:3e5,enabledKey:"appLockEnabled",backgroundedAtKey:"appLockBackgroundedAt"};let pendingPrompt=null;async function isBiometricAvailable(){try{const[e,t]=await Promise.all([LocalAuthentication.hasHardwareAsync(),LocalAuthentication.isEnrolledAsync()]);return e&&t}catch(e){return _index.Logger.error("[AppLock] biometric availability check failed:",e),!1}}const failureFor=e=>{switch(e){case"user_cancel":case"app_cancel":case"system_cancel":case"user_fallback":return"cancelled";case"lockout":return"lockout";case"not_enrolled":case"passcode_not_set":return"not-enrolled";case"not_available":return"not-available";default:return"failed"}},prompt=async e=>{try{if(await LocalAuthentication.getEnrolledLevelAsync()===LocalAuthentication.SecurityLevel.NONE)return{ok:!1,reason:"not-enrolled"};const t=await LocalAuthentication.authenticateAsync({promptMessage:e,cancelLabel:"Cancel",fallbackLabel:"Use passcode",disableDeviceFallback:!1});return t.success?{ok:!0}:(_index.Logger.warn("[AppLock] check not passed:",t.error),{ok:!1,reason:failureFor(t.error)})}catch(e){return _index.Logger.error("[AppLock] check failed:",e),{ok:!1,reason:"failed"}}};function authenticateBiometric(e){return pendingPrompt||(pendingPrompt=prompt(e).finally(()=>{pendingPrompt=null})),pendingPrompt}function useAppLock({active:e,policy:t}){const a=t?.lockAfterMs??DEFAULT_POLICY.lockAfterMs,r=t?.enabledKey??DEFAULT_POLICY.enabledKey,c=t?.backgroundedAtKey??DEFAULT_POLICY.backgroundedAtKey,[n,o]=(0,_react.useState)(!1),[i,l]=(0,_react.useState)(!1),[s,u]=(0,_react.useState)(!1),[d,p]=(0,_react.useState)(!1),[_,k]=(0,_react.useState)(!1),f=(0,_react.useCallback)(async()=>{const e=await _index2.Storage.getItem(r);return"true"===e||"false"===e?"true"===e:isBiometricAvailable()},[r]),b=(0,_react.useCallback)(async()=>{const t=await _index2.Storage.getItem(c);if(null===t)return;await _index2.Storage.removeItem(c);const r=Date.now()-Number(t);e&&(r<0||r>=a)&&await f()&&o(!0)},[e,c,a,f]);(0,_react.useEffect)(()=>{let t=!1;return e||o(!1),k(!1),b().finally(()=>{t||k(!0)}),()=>{t=!0}},[e,b]),(0,_react.useEffect)(()=>{const t=_reactNative.AppState.addEventListener("change",t=>{"background"===t&&e?_index2.Storage.setItem(c,String(Date.now())):"active"===t&&b()});return()=>t.remove()},[e,c,b]),(0,_react.useEffect)(()=>{let e=!1;return isBiometricAvailable().then(t=>{e||(u(t),p(!0))}),f().then(t=>{e||l(t)}),()=>{e=!0}},[f]);const A=(0,_react.useCallback)(async e=>await _index2.Storage.setItem(r,e?"true":"false")?(l(e),{ok:!0}):{ok:!1,reason:"failed"},[r]),g=(0,_react.useCallback)(async e=>{const t=await authenticateBiometric(e);return t.ok&&o(!1),t},[]),h=(0,_react.useCallback)(()=>!(!e||!i)&&(o(!0),!0),[e,i]);return{locked:n,enabled:i,biometricAvailable:s,availabilityKnown:d,ready:_,setEnabled:A,unlock:g,lock:h}}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.authenticateBiometric=authenticateBiometric,exports.isBiometricAvailable=isBiometricAvailable,exports.useAppLock=useAppLock;var cache,LocalAuthentication=_interopRequireWildcard(require("expo-local-authentication")),_react=require("react"),_reactNative=require("react-native"),_index=require("../logger/index.js"),_index2=require("../storage/index.js");function _interopRequireWildcard(e,t){if(!t&&e&&e.__esModule)return e;var a,r,c=Object.defineProperty,n={__proto__:null,default:e};if(Object(e)!==e)return n;if(cache||"function"!=typeof WeakMap||(cache=new WeakMap),cache){if(cache.has(e))return cache.get(e);cache.set(e,n)}for(r in e)"default"!==r&&{}.hasOwnProperty.call(e,r)&&((a=c&&Object.getOwnPropertyDescriptor(e,r))&&(a.get||a.set)?c(n,r,a):n[r]=e[r]);return n}const DEFAULT_POLICY={lockAfterMs:3e5,enabledKey:"appLockEnabled",backgroundedAtKey:"appLockBackgroundedAt"};let pendingPrompt=null;async function isBiometricAvailable(){try{const[e,t]=await Promise.all([LocalAuthentication.hasHardwareAsync(),LocalAuthentication.isEnrolledAsync()]);return e&&t}catch(e){return _index.Logger.error("[AppLock] biometric availability check failed:",e),!1}}const failureFor=e=>{switch(e){case"user_cancel":case"app_cancel":case"system_cancel":case"user_fallback":return"cancelled";case"lockout":return"lockout";case"not_enrolled":case"passcode_not_set":return"not-enrolled";case"not_available":return"not-available";default:return"failed"}},prompt=async e=>{try{if(await LocalAuthentication.getEnrolledLevelAsync()===LocalAuthentication.SecurityLevel.NONE)return{ok:!1,reason:"not-enrolled"};const t=await LocalAuthentication.authenticateAsync({promptMessage:e,cancelLabel:"Cancel",fallbackLabel:"Use passcode",disableDeviceFallback:!1});return t.success?{ok:!0}:(_index.Logger.warn("[AppLock] check not passed:",t.error),{ok:!1,reason:failureFor(t.error)})}catch(e){return _index.Logger.error("[AppLock] check failed:",e),{ok:!1,reason:"failed"}}};function authenticateBiometric(e){return pendingPrompt||(pendingPrompt=prompt(e).finally(()=>{pendingPrompt=null})),pendingPrompt}function useAppLock({active:e,policy:t}){const a=t?.lockAfterMs??DEFAULT_POLICY.lockAfterMs,r=t?.enabledKey??DEFAULT_POLICY.enabledKey,c=t?.backgroundedAtKey??DEFAULT_POLICY.backgroundedAtKey,n=t?.enabledByDefault,[o,i]=(0,_react.useState)(!1),[l,s]=(0,_react.useState)(!1),[u,d]=(0,_react.useState)(!1),[p,_]=(0,_react.useState)(!1),[k,f]=(0,_react.useState)(!1),b=(0,_react.useCallback)(async()=>{const e=await _index2.Storage.getItem(r);return"true"===e||"false"===e?"true"===e:n??await isBiometricAvailable()},[r,n]),A=(0,_react.useCallback)(async()=>{const t=await _index2.Storage.getItem(c);if(null===t)return;await _index2.Storage.removeItem(c);const r=Date.now()-Number(t);e&&(r<0||r>=a)&&await b()&&i(!0)},[e,c,a,b]);(0,_react.useEffect)(()=>{let t=!1;return e||i(!1),f(!1),A().finally(()=>{t||f(!0)}),()=>{t=!0}},[e,A]),(0,_react.useEffect)(()=>{const t=_reactNative.AppState.addEventListener("change",t=>{"background"===t&&e?_index2.Storage.setItem(c,String(Date.now())):"active"===t&&A()});return()=>t.remove()},[e,c,A]),(0,_react.useEffect)(()=>{let e=!1;return isBiometricAvailable().then(t=>{e||(d(t),_(!0))}),b().then(t=>{e||s(t)}),()=>{e=!0}},[b]);const g=(0,_react.useCallback)(async e=>await _index2.Storage.setItem(r,e?"true":"false")?(s(e),{ok:!0}):{ok:!1,reason:"failed"},[r]),y=(0,_react.useCallback)(async e=>{const t=await authenticateBiometric(e);return t.ok&&i(!1),t},[]),h=(0,_react.useCallback)(()=>!(!e||!l)&&(i(!0),!0),[e,l]),m=(0,_react.useCallback)(()=>{i(!1)},[]);return{locked:o,enabled:l,biometricAvailable:u,availabilityKnown:p,ready:k,setEnabled:g,unlock:y,lock:h,markUnlocked:m}}
@@ -1 +1 @@
1
- "use strict";import*as LocalAuthentication from"expo-local-authentication";import{useCallback,useEffect,useState}from"react";import{AppState}from"react-native";import{Logger}from"../logger/index.js";import{Storage}from"../storage/index.js";const DEFAULT_POLICY={lockAfterMs:3e5,enabledKey:"appLockEnabled",backgroundedAtKey:"appLockBackgroundedAt"};let pendingPrompt=null;export async function isBiometricAvailable(){try{const[e,t]=await Promise.all([LocalAuthentication.hasHardwareAsync(),LocalAuthentication.isEnrolledAsync()]);return e&&t}catch(e){return Logger.error("[AppLock] biometric availability check failed:",e),!1}}const failureFor=e=>{switch(e){case"user_cancel":case"app_cancel":case"system_cancel":case"user_fallback":return"cancelled";case"lockout":return"lockout";case"not_enrolled":case"passcode_not_set":return"not-enrolled";case"not_available":return"not-available";default:return"failed"}},prompt=async e=>{try{if(await LocalAuthentication.getEnrolledLevelAsync()===LocalAuthentication.SecurityLevel.NONE)return{ok:!1,reason:"not-enrolled"};const t=await LocalAuthentication.authenticateAsync({promptMessage:e,cancelLabel:"Cancel",fallbackLabel:"Use passcode",disableDeviceFallback:!1});return t.success?{ok:!0}:(Logger.warn("[AppLock] check not passed:",t.error),{ok:!1,reason:failureFor(t.error)})}catch(e){return Logger.error("[AppLock] check failed:",e),{ok:!1,reason:"failed"}}};export function authenticateBiometric(e){return pendingPrompt||(pendingPrompt=prompt(e).finally(()=>{pendingPrompt=null})),pendingPrompt}export function useAppLock({active:e,policy:t}){const a=t?.lockAfterMs??DEFAULT_POLICY.lockAfterMs,r=t?.enabledKey??DEFAULT_POLICY.enabledKey,o=t?.backgroundedAtKey??DEFAULT_POLICY.backgroundedAtKey,[n,c]=useState(!1),[l,i]=useState(!1),[s,u]=useState(!1),[p,d]=useState(!1),[k,f]=useState(!1),m=useCallback(async()=>{const e=await Storage.getItem(r);return"true"===e||"false"===e?"true"===e:isBiometricAvailable()},[r]),b=useCallback(async()=>{const t=await Storage.getItem(o);if(null===t)return;await Storage.removeItem(o);const r=Date.now()-Number(t);e&&(r<0||r>=a)&&await m()&&c(!0)},[e,o,a,m]);useEffect(()=>{let t=!1;return e||c(!1),f(!1),b().finally(()=>{t||f(!0)}),()=>{t=!0}},[e,b]),useEffect(()=>{const t=AppState.addEventListener("change",t=>{"background"===t&&e?Storage.setItem(o,String(Date.now())):"active"===t&&b()});return()=>t.remove()},[e,o,b]),useEffect(()=>{let e=!1;return isBiometricAvailable().then(t=>{e||(u(t),d(!0))}),m().then(t=>{e||i(t)}),()=>{e=!0}},[m]);const g=useCallback(async e=>await Storage.setItem(r,e?"true":"false")?(i(e),{ok:!0}):{ok:!1,reason:"failed"},[r]),A=useCallback(async e=>{const t=await authenticateBiometric(e);return t.ok&&c(!1),t},[]),L=useCallback(()=>!(!e||!l)&&(c(!0),!0),[e,l]);return{locked:n,enabled:l,biometricAvailable:s,availabilityKnown:p,ready:k,setEnabled:g,unlock:A,lock:L}}
1
+ "use strict";import*as LocalAuthentication from"expo-local-authentication";import{useCallback,useEffect,useState}from"react";import{AppState}from"react-native";import{Logger}from"../logger/index.js";import{Storage}from"../storage/index.js";const DEFAULT_POLICY={lockAfterMs:3e5,enabledKey:"appLockEnabled",backgroundedAtKey:"appLockBackgroundedAt"};let pendingPrompt=null;export async function isBiometricAvailable(){try{const[e,t]=await Promise.all([LocalAuthentication.hasHardwareAsync(),LocalAuthentication.isEnrolledAsync()]);return e&&t}catch(e){return Logger.error("[AppLock] biometric availability check failed:",e),!1}}const failureFor=e=>{switch(e){case"user_cancel":case"app_cancel":case"system_cancel":case"user_fallback":return"cancelled";case"lockout":return"lockout";case"not_enrolled":case"passcode_not_set":return"not-enrolled";case"not_available":return"not-available";default:return"failed"}},prompt=async e=>{try{if(await LocalAuthentication.getEnrolledLevelAsync()===LocalAuthentication.SecurityLevel.NONE)return{ok:!1,reason:"not-enrolled"};const t=await LocalAuthentication.authenticateAsync({promptMessage:e,cancelLabel:"Cancel",fallbackLabel:"Use passcode",disableDeviceFallback:!1});return t.success?{ok:!0}:(Logger.warn("[AppLock] check not passed:",t.error),{ok:!1,reason:failureFor(t.error)})}catch(e){return Logger.error("[AppLock] check failed:",e),{ok:!1,reason:"failed"}}};export function authenticateBiometric(e){return pendingPrompt||(pendingPrompt=prompt(e).finally(()=>{pendingPrompt=null})),pendingPrompt}export function useAppLock({active:e,policy:t}){const a=t?.lockAfterMs??DEFAULT_POLICY.lockAfterMs,r=t?.enabledKey??DEFAULT_POLICY.enabledKey,o=t?.backgroundedAtKey??DEFAULT_POLICY.backgroundedAtKey,n=t?.enabledByDefault,[c,l]=useState(!1),[i,s]=useState(!1),[u,p]=useState(!1),[d,k]=useState(!1),[f,m]=useState(!1),b=useCallback(async()=>{const e=await Storage.getItem(r);return"true"===e||"false"===e?"true"===e:n??await isBiometricAvailable()},[r,n]),g=useCallback(async()=>{const t=await Storage.getItem(o);if(null===t)return;await Storage.removeItem(o);const r=Date.now()-Number(t);e&&(r<0||r>=a)&&await b()&&l(!0)},[e,o,a,b]);useEffect(()=>{let t=!1;return e||l(!1),m(!1),g().finally(()=>{t||m(!0)}),()=>{t=!0}},[e,g]),useEffect(()=>{const t=AppState.addEventListener("change",t=>{"background"===t&&e?Storage.setItem(o,String(Date.now())):"active"===t&&g()});return()=>t.remove()},[e,o,g]),useEffect(()=>{let e=!1;return isBiometricAvailable().then(t=>{e||(p(t),k(!0))}),b().then(t=>{e||s(t)}),()=>{e=!0}},[b]);const A=useCallback(async e=>await Storage.setItem(r,e?"true":"false")?(s(e),{ok:!0}):{ok:!1,reason:"failed"},[r]),L=useCallback(async e=>{const t=await authenticateBiometric(e);return t.ok&&l(!1),t},[]),y=useCallback(()=>!(!e||!i)&&(l(!0),!0),[e,i]),h=useCallback(()=>{l(!1)},[]);return{locked:c,enabled:i,biometricAvailable:u,availabilityKnown:d,ready:f,setEnabled:A,unlock:L,lock:y,markUnlocked:h}}
@@ -2,6 +2,7 @@ export interface AppLockPolicy {
2
2
  lockAfterMs: number;
3
3
  enabledKey: string;
4
4
  backgroundedAtKey: string;
5
+ enabledByDefault?: boolean;
5
6
  }
6
7
  export type AppLockFailure = "cancelled" | "lockout" | "not-enrolled" | "not-available" | "failed";
7
8
  export type AppLockResult = {
@@ -22,6 +23,8 @@ export interface AppLockState {
22
23
  unlock: (reason: string) => Promise<AppLockResult>;
23
24
  /** Locks now when signed in and the lock is enabled. Returns whether it locked. */
24
25
  lock: () => boolean;
26
+ /** Clears the lock after the app's own check, such as a PIN. */
27
+ markUnlocked: () => void;
25
28
  }
26
29
  export declare function isBiometricAvailable(): Promise<boolean>;
27
30
  /** A second call while a prompt is open shares that prompt. */
@@ -30,7 +33,8 @@ export declare function authenticateBiometric(reason: string): Promise<AppLockRe
30
33
  * Whether the app is locked. It locks when a signed-in person (`active`) comes back after `lockAfterMs` or more away.
31
34
  * The time it left the screen is saved, not held in memory, so a phone that closed the app in the background still
32
35
  * locks on the next launch. Only "background" counts as away: iOS reports "inactive" while the Face ID prompt is up.
33
- * The person's choice is stored under `enabledKey`; with none saved it is on when the phone has a fingerprint or face enrolled.
36
+ * The person's choice is stored under `enabledKey`; with none saved it is `enabledByDefault` when the policy sets it, and
37
+ * otherwise on when the phone has a fingerprint or face enrolled.
34
38
  * `availabilityKnown` stays false until the first availability check settles, so a screen can wait before it reads
35
39
  * `biometricAvailable` as "this phone has no biometrics".
36
40
  */
@@ -2,6 +2,7 @@ export interface AppLockPolicy {
2
2
  lockAfterMs: number;
3
3
  enabledKey: string;
4
4
  backgroundedAtKey: string;
5
+ enabledByDefault?: boolean;
5
6
  }
6
7
  export type AppLockFailure = "cancelled" | "lockout" | "not-enrolled" | "not-available" | "failed";
7
8
  export type AppLockResult = {
@@ -22,6 +23,8 @@ export interface AppLockState {
22
23
  unlock: (reason: string) => Promise<AppLockResult>;
23
24
  /** Locks now when signed in and the lock is enabled. Returns whether it locked. */
24
25
  lock: () => boolean;
26
+ /** Clears the lock after the app's own check, such as a PIN. */
27
+ markUnlocked: () => void;
25
28
  }
26
29
  export declare function isBiometricAvailable(): Promise<boolean>;
27
30
  /** A second call while a prompt is open shares that prompt. */
@@ -30,7 +33,8 @@ export declare function authenticateBiometric(reason: string): Promise<AppLockRe
30
33
  * Whether the app is locked. It locks when a signed-in person (`active`) comes back after `lockAfterMs` or more away.
31
34
  * The time it left the screen is saved, not held in memory, so a phone that closed the app in the background still
32
35
  * locks on the next launch. Only "background" counts as away: iOS reports "inactive" while the Face ID prompt is up.
33
- * The person's choice is stored under `enabledKey`; with none saved it is on when the phone has a fingerprint or face enrolled.
36
+ * The person's choice is stored under `enabledKey`; with none saved it is `enabledByDefault` when the policy sets it, and
37
+ * otherwise on when the phone has a fingerprint or face enrolled.
34
38
  * `availabilityKnown` stays false until the first availability check settles, so a screen can wait before it reads
35
39
  * `biometricAvailable` as "this phone has no biometrics".
36
40
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webority/mobile-core",
3
- "version": "0.189.0",
3
+ "version": "0.190.1",
4
4
  "description": "Platform layer for Webority React Native apps: HTTP clients, auth/token storage, config, logging, formatters, validators, network status, permissions, storage, version checks and over-the-air updates. No UI.",
5
5
  "keywords": [
6
6
  "react-native",
@@ -404,7 +404,7 @@
404
404
  }
405
405
  },
406
406
  "dependencies": {
407
- "@webority/api-contract": "0.189.0",
407
+ "@webority/api-contract": "0.190.1",
408
408
  "axios": "^1.19.0",
409
409
  "libphonenumber-js": "^1.12.41"
410
410
  },