@octane-xplat/biometrics 0.17.0 → 0.18.0

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
@@ -13,30 +13,32 @@ a registered credential and an authentication ceremony.
13
13
  ```ts
14
14
  import { biometrics } from '@octane-xplat/biometrics'
15
15
 
16
- if ((await biometrics.ensure()) === 'granted') {
17
- const ok = await biometrics.impl!.verify('Unlock your saved trips')
16
+ if ((await biometrics.requestPermissions()).granted) {
17
+ const ok = await biometrics.verify('Unlock your saved trips')
18
18
  }
19
19
  ```
20
20
 
21
- The shared capability contract: `supported` reports whether an
21
+ The shared service contract: `supported` reports whether an
22
22
  implementation exists on this target — branch on it rather than catching —
23
- `ensure()` resolves `'granted' | 'denied' | 'unsupported'`, and `impl` is
24
- the service once usable. `verify(reason)` resolves `false` for a declined
23
+ `getPermissions()`/`requestPermissions()` resolve
24
+ `{status: 'granted' | 'denied' | 'unsupported', granted, canAskAgain}`.
25
+ `verify(reason)` resolves `false` for a declined
25
26
  or failed prompt rather than throwing.
26
27
 
27
28
  On macOS, availability checks do not open a prompt. Missing hardware,
28
29
  enrollment, pairing, or a connected sensor returns `unsupported`; lockout
29
30
  or an interaction restriction returns `denied`. A host without the Objective-C
30
- LocalAuthentication bridge reports `supported: false` and `impl: null`.
31
+ LocalAuthentication bridge reports `supported: false` and `verify()` rejects
32
+ `UnavailabilityError`.
31
33
  Verification uses biometrics only, hides password fallback, and returns
32
34
  `false` on cancellation, failure, or an overlapping prompt.
33
35
 
34
36
  ```ts
35
37
  import { biometrics } from '@octane-xplat/biometrics'
36
38
 
37
- const availability = await biometrics.ensure()
38
- if (availability === 'granted') {
39
- const verified = await biometrics.impl!.verify('Unlock your saved trips')
39
+ const availability = await biometrics.requestPermissions()
40
+ if (availability.granted) {
41
+ const verified = await biometrics.verify('Unlock your saved trips')
40
42
  console.log(verified ? 'Unlocked' : 'Still locked')
41
43
  }
42
44
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@octane-xplat/biometrics",
3
- "version": "0.17.0",
3
+ "version": "0.18.0",
4
4
  "description": "Biometric verification (FaceID/TouchID/fingerprint) for Octane xplat — matching web + NativeScript implementations",
5
5
  "keywords": [
6
6
  "android",
@@ -51,7 +51,8 @@
51
51
  "access": "public"
52
52
  },
53
53
  "dependencies": {
54
- "@nativescript/biometrics": "1.3.1"
54
+ "@nativescript/biometrics": "1.3.1",
55
+ "@octane-xplat/lib": "0.18.0"
55
56
  },
56
57
  "devDependencies": {
57
58
  "@nativescript-community/octane": "0.2.5",
@@ -1,5 +1,7 @@
1
1
  // LocalAuthentication through the AppKit host's existing Objective-C bridge.
2
- import type { BiometricsImpl, Capability } from './types'
2
+ import { UnavailabilityError } from '@octane-xplat/lib/capability'
3
+ import type { Permissioned, PermissionResponse } from '@octane-xplat/lib/capability'
4
+ import type { BiometricsImpl } from './types'
3
5
 
4
6
  declare const objc: { import(name: string): void }
5
7
  declare const interop: { Reference: new () => { value?: { domain: string; code: number } } }
@@ -115,26 +117,36 @@ const implementation: BiometricsImpl = {
115
117
  },
116
118
  }
117
119
 
118
- export const biometrics: Capability<BiometricsImpl> = {
119
- get supported() {
120
- return frameworkAvailable()
121
- },
122
- async ensure() {
123
- if (!frameworkAvailable()) {
124
- return 'unsupported'
125
- }
120
+ const ensure = async (): Promise<PermissionResponse> => {
121
+ if (!frameworkAvailable()) {
122
+ return { status: 'unsupported', granted: false, canAskAgain: false }
123
+ }
126
124
 
127
- let context: AuthenticationContext | null = null
128
- try {
129
- context = LAContext.new()
130
- return availability(context)
131
- } catch {
132
- return 'denied'
133
- } finally {
134
- invalidate(context)
125
+ let context: AuthenticationContext | null = null
126
+ try {
127
+ context = LAContext.new()
128
+ const status = availability(context)
129
+ return {
130
+ status,
131
+ granted: status === 'granted',
132
+ canAskAgain: status === 'granted',
135
133
  }
134
+ } catch {
135
+ return { status: 'denied', granted: false, canAskAgain: false }
136
+ } finally {
137
+ invalidate(context)
138
+ }
139
+ }
140
+
141
+ export const biometrics: Permissioned<BiometricsImpl> = {
142
+ get supported() {
143
+ return frameworkAvailable()
136
144
  },
137
- get impl() {
138
- return frameworkAvailable() ? implementation : null
139
- },
145
+ isAvailable: async () => frameworkAvailable(),
146
+ getPermissions: ensure,
147
+ requestPermissions: ensure,
148
+ verify: (reason) =>
149
+ frameworkAvailable()
150
+ ? implementation.verify(reason)
151
+ : Promise.reject(new UnavailabilityError('biometrics')),
140
152
  }
package/src/biometrics.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  import { BiometricAuth } from '@nativescript/biometrics'
3
3
  import type { VerifyBiometricOptions } from '@nativescript/biometrics'
4
4
  import { isIOS } from '@nativescript/core'
5
- import type { Capability } from './types'
5
+ import type { Permissioned, PermissionResponse } from '@octane-xplat/lib/capability'
6
6
  import type { BiometricsImpl } from './types'
7
7
 
8
8
  const bio = new BiometricAuth()
@@ -12,23 +12,31 @@ const bio = new BiometricAuth()
12
12
  // keychain entry on iOS.
13
13
  let verifying = false
14
14
 
15
- export const biometrics: Capability<BiometricsImpl> = {
16
- supported: true,
17
- async ensure() {
18
- try {
19
- const r = await bio.available()
20
- // Android reports `any` for a secure lockscreen without biometrics —
21
- // verify() requires BIOMETRIC_STRONG, so that state is not usable.
22
- return r.any && (isIOS || r.biometrics) ? 'granted' : 'unsupported'
23
- } catch {
24
- // Android rejects when the device lacks biometric hardware,
25
- // enrollment, or a secure lockscreen — absence, not an error.
26
- return 'unsupported'
15
+ const available = async (): Promise<PermissionResponse> => {
16
+ try {
17
+ const r = await bio.available()
18
+ // Android reports `any` for a secure lockscreen without biometrics —
19
+ // verify() requires BIOMETRIC_STRONG, so that state is not usable.
20
+ const usable = !!(r.any && (isIOS || r.biometrics))
21
+ return {
22
+ status: usable ? 'granted' : 'unsupported',
23
+ granted: usable,
24
+ canAskAgain: usable,
27
25
  }
28
- },
29
- impl: {
30
- async verify(reason) {
31
- if (verifying) {
26
+ } catch {
27
+ // Android rejects when the device lacks biometric hardware,
28
+ // enrollment, or a secure lockscreen — absence, not an error.
29
+ return { status: 'unsupported', granted: false, canAskAgain: false }
30
+ }
31
+ }
32
+
33
+ export const biometrics: Permissioned<BiometricsImpl> = {
34
+ supported: true,
35
+ isAvailable: async () => (await available()).granted,
36
+ getPermissions: available,
37
+ requestPermissions: available,
38
+ async verify(reason) {
39
+ if (verifying) {
32
40
  return false
33
41
  }
34
42
 
@@ -49,6 +57,5 @@ export const biometrics: Capability<BiometricsImpl> = {
49
57
  } finally {
50
58
  verifying = false
51
59
  }
52
- },
53
60
  },
54
61
  }
@@ -2,12 +2,20 @@
2
2
  // standalone local-presence API: it requires an RP challenge and a registered
3
3
  // credential, and may require a user gesture. Do not claim it implements the
4
4
  // native verify(reason) contract by creating an ephemeral passkey.
5
- import type { BiometricsImpl, Capability } from './types'
5
+ import { UnavailabilityError } from '@octane-xplat/lib/capability'
6
+ import type { Permissioned, PermissionResponse } from '@octane-xplat/lib/capability'
7
+ import type { BiometricsImpl } from './types'
6
8
 
7
- export const biometrics: Capability<BiometricsImpl> = {
9
+ const UNSUPPORTED: PermissionResponse = {
10
+ status: 'unsupported',
11
+ granted: false,
12
+ canAskAgain: false,
13
+ }
14
+
15
+ export const biometrics: Permissioned<BiometricsImpl> = {
8
16
  supported: false,
9
- async ensure() {
10
- return 'unsupported'
11
- },
12
- impl: null,
17
+ isAvailable: async () => false,
18
+ getPermissions: async () => UNSUPPORTED,
19
+ requestPermissions: async () => UNSUPPORTED,
20
+ verify: () => Promise.reject(new UnavailabilityError('biometrics')),
13
21
  }
package/src/types.ts CHANGED
@@ -1,11 +1,11 @@
1
- /** Optional capability — never throws for absence (docs/platform/platform-services.md). */
2
- export interface Capability<T> {
3
- supported: boolean
4
- ensure(): Promise<'granted' | 'denied' | 'unsupported'>
5
- /** usable iff supported && ensured */
6
- impl: T | null
7
- }
8
-
9
1
  export interface BiometricsImpl {
10
2
  verify(reason: string): Promise<boolean>
11
3
  }
4
+
5
+ export { UnavailabilityError } from '@octane-xplat/lib/capability'
6
+ export type {
7
+ Permissioned,
8
+ PermissionResponse,
9
+ PermissionStatus,
10
+ Service,
11
+ } from '@octane-xplat/lib/capability'
@@ -1,3 +1,3 @@
1
- import type { Capability } from './types.js';
1
+ import type { Permissioned } from '@octane-xplat/lib/capability';
2
2
  import type { BiometricsImpl } from './types.js';
3
- export declare const biometrics: Capability<BiometricsImpl>;
3
+ export declare const biometrics: Permissioned<BiometricsImpl>;
@@ -1,2 +1,3 @@
1
- import type { BiometricsImpl, Capability } from './types.js';
2
- export declare const biometrics: Capability<BiometricsImpl>;
1
+ import type { Permissioned } from '@octane-xplat/lib/capability';
2
+ import type { BiometricsImpl } from './types.js';
3
+ export declare const biometrics: Permissioned<BiometricsImpl>;
@@ -1,2 +1,3 @@
1
- import type { BiometricsImpl, Capability } from './types.js';
2
- export declare const biometrics: Capability<BiometricsImpl>;
1
+ import type { Permissioned } from '@octane-xplat/lib/capability';
2
+ import type { BiometricsImpl } from './types.js';
3
+ export declare const biometrics: Permissioned<BiometricsImpl>;
@@ -1,10 +1,5 @@
1
- /** Optional capability — never throws for absence (docs/platform/platform-services.md). */
2
- export interface Capability<T> {
3
- supported: boolean;
4
- ensure(): Promise<'granted' | 'denied' | 'unsupported'>;
5
- /** usable iff supported && ensured */
6
- impl: T | null;
7
- }
8
1
  export interface BiometricsImpl {
9
2
  verify(reason: string): Promise<boolean>;
10
3
  }
4
+ export { UnavailabilityError } from '@octane-xplat/lib/capability';
5
+ export type { Permissioned, PermissionResponse, PermissionStatus, Service, } from '@octane-xplat/lib/capability';