@aparajita/capacitor-biometric-auth 3.0.2 → 3.1.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/README.md CHANGED
@@ -90,7 +90,7 @@ Check to see what biometry type (if any) is available.
90
90
  ### setBiometryType(...)
91
91
 
92
92
  ```typescript
93
- setBiometryType(type: BiometryType | string | undefined) => void
93
+ setBiometryType(type: BiometryType | string | undefined) => Promise<void>
94
94
  ```
95
95
 
96
96
  web only<br><br>On the web, this method allows you to dynamically simulate different types of biometry. You may either pass a <a href="#biometrytype">`BiometryType`</a> enum or the string name of a <a href="#biometrytype">`BiometryType`</a>. If a string is passed and it isn't a valid value, nothing happens.
@@ -32,12 +32,12 @@ public class AuthActivity extends AppCompatActivity {
32
32
 
33
33
  BiometricPrompt.PromptInfo.Builder builder = new BiometricPrompt.PromptInfo.Builder();
34
34
  Intent intent = getIntent();
35
- String title = intent.getStringExtra(BiometricAuth.TITLE);
36
- String subtitle = intent.getStringExtra(BiometricAuth.SUBTITLE);
37
- String description = intent.getStringExtra(BiometricAuth.REASON);
35
+ String title = intent.getStringExtra(BiometricAuthNative.TITLE);
36
+ String subtitle = intent.getStringExtra(BiometricAuthNative.SUBTITLE);
37
+ String description = intent.getStringExtra(BiometricAuthNative.REASON);
38
38
  final int maxAttempts = intent.getIntExtra(
39
- BiometricAuth.MAX_ATTEMPTS,
40
- BiometricAuth.DEFAULT_MAX_ATTEMPTS
39
+ BiometricAuthNative.MAX_ATTEMPTS,
40
+ BiometricAuthNative.DEFAULT_MAX_ATTEMPTS
41
41
  );
42
42
  allowDeviceCredential = false;
43
43
 
@@ -49,7 +49,7 @@ public class AuthActivity extends AppCompatActivity {
49
49
 
50
50
  if (manager.isDeviceSecure()) {
51
51
  allowDeviceCredential =
52
- intent.getBooleanExtra(BiometricAuth.DEVICE_CREDENTIAL, false);
52
+ intent.getBooleanExtra(BiometricAuthNative.DEVICE_CREDENTIAL, false);
53
53
  }
54
54
  }
55
55
 
@@ -77,7 +77,7 @@ public class AuthActivity extends AppCompatActivity {
77
77
  // Android docs say that negative button text should not be set if device credential is allowed
78
78
  if (!allowDeviceCredential) {
79
79
  String negativeButtonText = intent.getStringExtra(
80
- BiometricAuth.CANCEL_TITLE
80
+ BiometricAuthNative.CANCEL_TITLE
81
81
  );
82
82
  builder.setNegativeButtonText(
83
83
  negativeButtonText == null || negativeButtonText.isEmpty()
@@ -127,12 +127,12 @@ public class AuthActivity extends AppCompatActivity {
127
127
  String errorMessage
128
128
  ) {
129
129
  Intent intent = new Intent();
130
- String prefix = BiometricAuth.RESULT_EXTRA_PREFIX;
130
+ String prefix = BiometricAuthNative.RESULT_EXTRA_PREFIX;
131
131
 
132
132
  intent
133
- .putExtra(prefix + BiometricAuth.RESULT_TYPE, resultType.toString())
134
- .putExtra(prefix + BiometricAuth.RESULT_ERROR_CODE, errorCode)
135
- .putExtra(prefix + BiometricAuth.RESULT_ERROR_MESSAGE, errorMessage);
133
+ .putExtra(prefix + BiometricAuthNative.RESULT_TYPE, resultType.toString())
134
+ .putExtra(prefix + BiometricAuthNative.RESULT_ERROR_CODE, errorCode)
135
+ .putExtra(prefix + BiometricAuthNative.RESULT_ERROR_MESSAGE, errorMessage);
136
136
 
137
137
  setResult(RESULT_OK, intent);
138
138
  finish();
@@ -17,8 +17,8 @@ import com.getcapacitor.annotation.CapacitorPlugin;
17
17
  import java.util.HashMap;
18
18
 
19
19
  @SuppressLint("RestrictedApi")
20
- @CapacitorPlugin(name = "BiometricAuth")
21
- public class BiometricAuth extends Plugin {
20
+ @CapacitorPlugin(name = "BiometricAuthNative")
21
+ public class BiometricAuthNative extends Plugin {
22
22
 
23
23
  public static final String RESULT_TYPE = "type";
24
24
  public static final String RESULT_ERROR_CODE = "errorCode";
@@ -206,7 +206,7 @@ public class BiometricAuth extends Plugin {
206
206
 
207
207
  if (data != null) {
208
208
  resultTypeName =
209
- data.getStringExtra(RESULT_EXTRA_PREFIX + BiometricAuth.RESULT_TYPE);
209
+ data.getStringExtra(RESULT_EXTRA_PREFIX + BiometricAuthNative.RESULT_TYPE);
210
210
  }
211
211
 
212
212
  if (resultTypeName == null) {
@@ -230,11 +230,11 @@ public class BiometricAuth extends Plugin {
230
230
  }
231
231
 
232
232
  int errorCode = data.getIntExtra(
233
- RESULT_EXTRA_PREFIX + BiometricAuth.RESULT_ERROR_CODE,
233
+ RESULT_EXTRA_PREFIX + BiometricAuthNative.RESULT_ERROR_CODE,
234
234
  0
235
235
  );
236
236
  String errorMessage = data.getStringExtra(
237
- RESULT_EXTRA_PREFIX + BiometricAuth.RESULT_ERROR_MESSAGE
237
+ RESULT_EXTRA_PREFIX + BiometricAuthNative.RESULT_ERROR_MESSAGE
238
238
  );
239
239
 
240
240
  switch (resultType) {
@@ -0,0 +1,9 @@
1
+ import { WebPlugin } from '@capacitor/core';
2
+ import type { PluginListenerHandle } from '@capacitor/core';
3
+ import type { AuthenticateOptions, BiometricAuthPlugin, CheckBiometryResult, ResumeListener, BiometryType } from './definitions';
4
+ export declare abstract class BiometricAuthBase extends WebPlugin implements BiometricAuthPlugin {
5
+ abstract setBiometryType(type: BiometryType | string | undefined): Promise<void>;
6
+ abstract checkBiometry(): Promise<CheckBiometryResult>;
7
+ abstract authenticate(options?: AuthenticateOptions): Promise<void>;
8
+ addResumeListener(listener: ResumeListener): Promise<PluginListenerHandle> & PluginListenerHandle;
9
+ }
@@ -0,0 +1,16 @@
1
+ import { App } from '@capacitor/app';
2
+ import { WebPlugin } from '@capacitor/core';
3
+ // eslint-disable-next-line import/prefer-default-export
4
+ export class BiometricAuthBase extends WebPlugin {
5
+ addResumeListener(listener) {
6
+ return App.addListener('appStateChange', ({ isActive }) => {
7
+ if (isActive) {
8
+ this.checkBiometry()
9
+ .then((info) => {
10
+ listener(info);
11
+ })
12
+ .catch(console.error);
13
+ }
14
+ });
15
+ }
16
+ }
@@ -1,5 +1,4 @@
1
- import type { DecoratedNativePlugin } from '@aparajita/capacitor-native-decorator';
2
- import type { PluginListenerHandle, PluginResultError } from '@capacitor/core';
1
+ import type { PluginListenerHandle, PluginResultError, WebPlugin } from '@capacitor/core';
3
2
  export declare enum BiometryType {
4
3
  /**
5
4
  * No biometry is available
@@ -152,7 +151,7 @@ export interface CheckBiometryResult {
152
151
  * The signature of the callback passed to `addResumeListener()`.
153
152
  */
154
153
  export declare type ResumeListener = (info: CheckBiometryResult) => void;
155
- export interface BiometricAuthPlugin extends DecoratedNativePlugin {
154
+ export interface BiometricAuthPlugin extends WebPlugin {
156
155
  /**
157
156
  * Check to see what biometry type (if any) is available.
158
157
  */
@@ -165,7 +164,7 @@ export interface BiometricAuthPlugin extends DecoratedNativePlugin {
165
164
  * or the string name of a `BiometryType`. If a string is passed and
166
165
  * it isn't a valid value, nothing happens.
167
166
  */
168
- setBiometryType: (type: BiometryType | string | undefined) => void;
167
+ setBiometryType: (type: BiometryType | string | undefined) => Promise<void>;
169
168
  /**
170
169
  * Prompt the user for authentication. If authorization fails for any reason,
171
170
  * the promise is rejected with a `BiometryError`.
@@ -189,4 +188,3 @@ export interface BiometricAuthPlugin extends DecoratedNativePlugin {
189
188
  */
190
189
  addResumeListener: (listener: ResumeListener) => Promise<PluginListenerHandle>;
191
190
  }
192
- export declare const kPluginName = "BiometricAuth";
@@ -54,4 +54,3 @@ export class BiometryError {
54
54
  this.code = BiometryErrorType[code];
55
55
  }
56
56
  }
57
- export const kPluginName = 'BiometricAuth';
@@ -1,5 +1,5 @@
1
- import { BiometricAuth } from './web';
2
- declare const plugin: BiometricAuth;
1
+ import type { BiometricAuthPlugin } from './definitions';
2
+ declare const proxy: BiometricAuthPlugin;
3
3
  export * from './definitions';
4
- export { plugin as BiometricAuth };
5
- export { getBiometryName } from './web';
4
+ export * from './web-utils';
5
+ export { proxy as BiometricAuth };
package/dist/esm/index.js CHANGED
@@ -1,17 +1,11 @@
1
1
  import { registerPlugin } from '@capacitor/core';
2
- import { kPluginName } from './definitions';
3
2
  import info from './info.json';
4
- import { BiometricAuth } from './web';
5
3
  console.log(`loaded ${info.name} v${info.version}`);
6
- // Because we are using @aparajita/capacitor-native-decorator,
7
- // we have one version of the TS code to rule them all, and there
8
- // is no need to lazy load. 😁
9
- const plugin = new BiometricAuth();
10
- registerPlugin(kPluginName, {
11
- web: plugin,
12
- ios: plugin,
13
- android: plugin
4
+ const proxy = registerPlugin('BiometricAuthNative', {
5
+ web: async () => import('./web').then((module) => new module.BiometricAuthWeb()),
6
+ ios: async () => import('./native').then((module) => new module.BiometricAuthNative(proxy)),
7
+ android: async () => import('./native').then((module) => new module.BiometricAuthNative(proxy))
14
8
  });
15
9
  export * from './definitions';
16
- export { plugin as BiometricAuth };
17
- export { getBiometryName } from './web';
10
+ export * from './web-utils';
11
+ export { proxy as BiometricAuth };
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "@aparajita/capacitor-biometric-auth",
3
- "version": "3.0.2"
3
+ "version": "3.1.2"
4
4
  }
@@ -0,0 +1,9 @@
1
+ import { BiometricAuthBase } from './base';
2
+ import type { AuthenticateOptions, BiometricAuthPlugin, CheckBiometryResult } from './definitions';
3
+ import { BiometryType } from './definitions';
4
+ export declare class BiometricAuthNative extends BiometricAuthBase {
5
+ constructor(capProxy: BiometricAuthPlugin);
6
+ checkBiometry(): Promise<CheckBiometryResult>;
7
+ authenticate(options?: AuthenticateOptions): Promise<void>;
8
+ setBiometryType(type: BiometryType | string | undefined): Promise<void>;
9
+ }
@@ -0,0 +1,26 @@
1
+ import { BiometricAuthBase } from './base';
2
+ import { BiometryType } from './definitions';
3
+ // eslint-disable-next-line import/prefer-default-export
4
+ export class BiometricAuthNative extends BiometricAuthBase {
5
+ constructor(capProxy) {
6
+ super();
7
+ this.checkBiometry = capProxy.checkBiometry;
8
+ this.authenticate = capProxy.authenticate;
9
+ }
10
+ async checkBiometry() {
11
+ // Never used, satisfy the compiler
12
+ return Promise.resolve({
13
+ isAvailable: true,
14
+ biometryType: BiometryType.none,
15
+ reason: ''
16
+ });
17
+ }
18
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/no-empty-function
19
+ async authenticate(options) { }
20
+ // eslint-disable-next-line @typescript-eslint/require-await
21
+ async setBiometryType(
22
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
23
+ type) {
24
+ throw this.unimplemented('setBiometryType is web only');
25
+ }
26
+ }
@@ -0,0 +1,5 @@
1
+ import { BiometryType } from './definitions';
2
+ /**
3
+ * Return a human-readable name for a BiometryType.
4
+ */
5
+ export declare function getBiometryName(type: BiometryType): string;
@@ -0,0 +1,16 @@
1
+ import { BiometryType } from './definitions';
2
+ const kBiometryTypeNameMap = {
3
+ [BiometryType.none]: '',
4
+ [BiometryType.touchId]: 'Touch ID',
5
+ [BiometryType.faceId]: 'Face ID',
6
+ [BiometryType.fingerprintAuthentication]: 'Fingerprint Authentication',
7
+ [BiometryType.faceAuthentication]: 'Face Authentication',
8
+ [BiometryType.irisAuthentication]: 'Iris Authentication'
9
+ };
10
+ /**
11
+ * Return a human-readable name for a BiometryType.
12
+ */
13
+ // eslint-disable-next-line import/prefer-default-export
14
+ export function getBiometryName(type) {
15
+ return kBiometryTypeNameMap[type] || '';
16
+ }
package/dist/esm/web.d.ts CHANGED
@@ -1,19 +1,9 @@
1
- import { WebPlugin } from '@capacitor/core';
2
- import type { PluginListenerHandle } from '@capacitor/core';
3
- import type { AuthenticateOptions, BiometricAuthPlugin, CheckBiometryResult, ResumeListener } from './definitions';
1
+ import { BiometricAuthBase } from './base';
2
+ import type { AuthenticateOptions, CheckBiometryResult } from './definitions';
4
3
  import { BiometryType } from './definitions';
5
- export declare class BiometricAuth extends WebPlugin implements BiometricAuthPlugin {
4
+ export declare class BiometricAuthWeb extends BiometricAuthBase {
6
5
  private biometryType;
7
- getRegisteredPluginName(): string;
8
- setBiometryType(type: BiometryType | string | undefined): void;
9
6
  checkBiometry(): Promise<CheckBiometryResult>;
10
7
  authenticate(options?: AuthenticateOptions): Promise<void>;
11
- addResumeListener(listener: ResumeListener): Promise<PluginListenerHandle> & PluginListenerHandle;
8
+ setBiometryType(type: BiometryType | string | undefined): Promise<void>;
12
9
  }
13
- /**
14
- * Return a human-readable name for a BiometryType.
15
- *
16
- * @param {BiometryType} type
17
- * @returns {string}
18
- */
19
- export declare function getBiometryName(type: BiometryType): string;
package/dist/esm/web.js CHANGED
@@ -1,39 +1,12 @@
1
- import { __decorate } from "tslib";
2
- import { native } from '@aparajita/capacitor-native-decorator';
3
- import { App } from '@capacitor/app';
4
- import { WebPlugin } from '@capacitor/core';
5
- import { BiometryError, BiometryErrorType, BiometryType, kPluginName } from './definitions';
6
- const kBiometryTypeNameMap = {
7
- [BiometryType.none]: '',
8
- [BiometryType.touchId]: 'Touch ID',
9
- [BiometryType.faceId]: 'Face ID',
10
- [BiometryType.fingerprintAuthentication]: 'Fingerprint Authentication',
11
- [BiometryType.faceAuthentication]: 'Face Authentication',
12
- [BiometryType.irisAuthentication]: 'Iris Authentication'
13
- };
14
- export class BiometricAuth extends WebPlugin {
1
+ import { BiometricAuthBase } from './base';
2
+ import { BiometryError, BiometryErrorType, BiometryType } from './definitions';
3
+ import { getBiometryName } from './web-utils';
4
+ // eslint-disable-next-line import/prefer-default-export
5
+ export class BiometricAuthWeb extends BiometricAuthBase {
15
6
  constructor() {
16
7
  super(...arguments);
17
8
  this.biometryType = BiometryType.none;
18
9
  }
19
- getRegisteredPluginName() {
20
- return kPluginName;
21
- }
22
- setBiometryType(type) {
23
- if (typeof type === 'undefined') {
24
- return;
25
- }
26
- if (typeof type === 'string') {
27
- // eslint-disable-next-line no-prototype-builtins
28
- if (BiometryType.hasOwnProperty(type)) {
29
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
30
- this.biometryType = BiometryType[type];
31
- }
32
- }
33
- else {
34
- this.biometryType = type;
35
- }
36
- }
37
10
  async checkBiometry() {
38
11
  return Promise.resolve({
39
12
  isAvailable: this.biometryType !== BiometryType.none,
@@ -47,7 +20,7 @@ export class BiometricAuth extends WebPlugin {
47
20
  if (
48
21
  // eslint-disable-next-line no-alert
49
22
  confirm((options === null || options === void 0 ? void 0 : options.reason) ||
50
- `Authenticate with ${kBiometryTypeNameMap[biometryType]}?`)) {
23
+ `Authenticate with ${getBiometryName(biometryType)}?`)) {
51
24
  return;
52
25
  }
53
26
  throw new BiometryError('User cancelled', BiometryErrorType.userCancel);
@@ -55,32 +28,20 @@ export class BiometricAuth extends WebPlugin {
55
28
  throw new BiometryError('Biometry not available', BiometryErrorType.biometryNotAvailable);
56
29
  });
57
30
  }
58
- addResumeListener(listener) {
59
- return App.addListener('appStateChange', ({ isActive }) => {
60
- if (isActive) {
61
- this.checkBiometry()
62
- .then((info) => {
63
- listener(info);
64
- })
65
- .catch((error) => {
66
- console.error(error.message);
67
- });
31
+ async setBiometryType(type) {
32
+ if (typeof type === 'undefined') {
33
+ return Promise.resolve();
34
+ }
35
+ if (typeof type === 'string') {
36
+ // eslint-disable-next-line no-prototype-builtins
37
+ if (BiometryType.hasOwnProperty(type)) {
38
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
39
+ this.biometryType = BiometryType[type];
68
40
  }
69
- });
41
+ }
42
+ else {
43
+ this.biometryType = type;
44
+ }
45
+ return Promise.resolve();
70
46
  }
71
47
  }
72
- __decorate([
73
- native()
74
- ], BiometricAuth.prototype, "checkBiometry", null);
75
- __decorate([
76
- native()
77
- ], BiometricAuth.prototype, "authenticate", null);
78
- /**
79
- * Return a human-readable name for a BiometryType.
80
- *
81
- * @param {BiometryType} type
82
- * @returns {string}
83
- */
84
- export function getBiometryName(type) {
85
- return kBiometryTypeNameMap[type] || '';
86
- }
@@ -3,10 +3,13 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var core = require('@capacitor/core');
6
- var tslib = require('tslib');
7
- var capacitorNativeDecorator = require('@aparajita/capacitor-native-decorator');
8
6
  var app = require('@capacitor/app');
9
7
 
8
+ var info = {
9
+ name: "@aparajita/capacitor-biometric-auth",
10
+ version: "3.1.2"
11
+ };
12
+
10
13
  exports.BiometryType = void 0;
11
14
  (function (BiometryType) {
12
15
  /**
@@ -63,12 +66,6 @@ class BiometryError {
63
66
  this.code = exports.BiometryErrorType[code];
64
67
  }
65
68
  }
66
- const kPluginName = 'BiometricAuth';
67
-
68
- var info = {
69
- name: "@aparajita/capacitor-biometric-auth",
70
- version: "3.0.2"
71
- };
72
69
 
73
70
  const kBiometryTypeNameMap = {
74
71
  [exports.BiometryType.none]: '',
@@ -78,29 +75,42 @@ const kBiometryTypeNameMap = {
78
75
  [exports.BiometryType.faceAuthentication]: 'Face Authentication',
79
76
  [exports.BiometryType.irisAuthentication]: 'Iris Authentication'
80
77
  };
81
- class BiometricAuth extends core.WebPlugin {
78
+ /**
79
+ * Return a human-readable name for a BiometryType.
80
+ */
81
+ // eslint-disable-next-line import/prefer-default-export
82
+ function getBiometryName(type) {
83
+ return kBiometryTypeNameMap[type] || '';
84
+ }
85
+
86
+ console.log(`loaded ${info.name} v${info.version}`);
87
+ const proxy = core.registerPlugin('BiometricAuthNative', {
88
+ web: async () => Promise.resolve().then(function () { return web; }).then((module) => new module.BiometricAuthWeb()),
89
+ ios: async () => Promise.resolve().then(function () { return native; }).then((module) => new module.BiometricAuthNative(proxy)),
90
+ android: async () => Promise.resolve().then(function () { return native; }).then((module) => new module.BiometricAuthNative(proxy))
91
+ });
92
+
93
+ // eslint-disable-next-line import/prefer-default-export
94
+ class BiometricAuthBase extends core.WebPlugin {
95
+ addResumeListener(listener) {
96
+ return app.App.addListener('appStateChange', ({ isActive }) => {
97
+ if (isActive) {
98
+ this.checkBiometry()
99
+ .then((info) => {
100
+ listener(info);
101
+ })
102
+ .catch(console.error);
103
+ }
104
+ });
105
+ }
106
+ }
107
+
108
+ // eslint-disable-next-line import/prefer-default-export
109
+ class BiometricAuthWeb extends BiometricAuthBase {
82
110
  constructor() {
83
111
  super(...arguments);
84
112
  this.biometryType = exports.BiometryType.none;
85
113
  }
86
- getRegisteredPluginName() {
87
- return kPluginName;
88
- }
89
- setBiometryType(type) {
90
- if (typeof type === 'undefined') {
91
- return;
92
- }
93
- if (typeof type === 'string') {
94
- // eslint-disable-next-line no-prototype-builtins
95
- if (exports.BiometryType.hasOwnProperty(type)) {
96
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
97
- this.biometryType = exports.BiometryType[type];
98
- }
99
- }
100
- else {
101
- this.biometryType = type;
102
- }
103
- }
104
114
  async checkBiometry() {
105
115
  return Promise.resolve({
106
116
  isAvailable: this.biometryType !== exports.BiometryType.none,
@@ -114,7 +124,7 @@ class BiometricAuth extends core.WebPlugin {
114
124
  if (
115
125
  // eslint-disable-next-line no-alert
116
126
  confirm((options === null || options === void 0 ? void 0 : options.reason) ||
117
- `Authenticate with ${kBiometryTypeNameMap[biometryType]}?`)) {
127
+ `Authenticate with ${getBiometryName(biometryType)}?`)) {
118
128
  return;
119
129
  }
120
130
  throw new BiometryError('User cancelled', exports.BiometryErrorType.userCancel);
@@ -122,48 +132,59 @@ class BiometricAuth extends core.WebPlugin {
122
132
  throw new BiometryError('Biometry not available', exports.BiometryErrorType.biometryNotAvailable);
123
133
  });
124
134
  }
125
- addResumeListener(listener) {
126
- return app.App.addListener('appStateChange', ({ isActive }) => {
127
- if (isActive) {
128
- this.checkBiometry()
129
- .then((info) => {
130
- listener(info);
131
- })
132
- .catch((error) => {
133
- console.error(error.message);
134
- });
135
+ async setBiometryType(type) {
136
+ if (typeof type === 'undefined') {
137
+ return Promise.resolve();
138
+ }
139
+ if (typeof type === 'string') {
140
+ // eslint-disable-next-line no-prototype-builtins
141
+ if (exports.BiometryType.hasOwnProperty(type)) {
142
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
143
+ this.biometryType = exports.BiometryType[type];
135
144
  }
136
- });
145
+ }
146
+ else {
147
+ this.biometryType = type;
148
+ }
149
+ return Promise.resolve();
137
150
  }
138
151
  }
139
- tslib.__decorate([
140
- capacitorNativeDecorator.native()
141
- ], BiometricAuth.prototype, "checkBiometry", null);
142
- tslib.__decorate([
143
- capacitorNativeDecorator.native()
144
- ], BiometricAuth.prototype, "authenticate", null);
145
- /**
146
- * Return a human-readable name for a BiometryType.
147
- *
148
- * @param {BiometryType} type
149
- * @returns {string}
150
- */
151
- function getBiometryName(type) {
152
- return kBiometryTypeNameMap[type] || '';
152
+
153
+ var web = /*#__PURE__*/Object.freeze({
154
+ __proto__: null,
155
+ BiometricAuthWeb: BiometricAuthWeb
156
+ });
157
+
158
+ // eslint-disable-next-line import/prefer-default-export
159
+ class BiometricAuthNative extends BiometricAuthBase {
160
+ constructor(capProxy) {
161
+ super();
162
+ this.checkBiometry = capProxy.checkBiometry;
163
+ this.authenticate = capProxy.authenticate;
164
+ }
165
+ async checkBiometry() {
166
+ // Never used, satisfy the compiler
167
+ return Promise.resolve({
168
+ isAvailable: true,
169
+ biometryType: exports.BiometryType.none,
170
+ reason: ''
171
+ });
172
+ }
173
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/no-empty-function
174
+ async authenticate(options) { }
175
+ // eslint-disable-next-line @typescript-eslint/require-await
176
+ async setBiometryType(
177
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
178
+ type) {
179
+ throw this.unimplemented('setBiometryType is web only');
180
+ }
153
181
  }
154
182
 
155
- console.log(`loaded ${info.name} v${info.version}`);
156
- // Because we are using @aparajita/capacitor-native-decorator,
157
- // we have one version of the TS code to rule them all, and there
158
- // is no need to lazy load. 😁
159
- const plugin = new BiometricAuth();
160
- core.registerPlugin(kPluginName, {
161
- web: plugin,
162
- ios: plugin,
163
- android: plugin
183
+ var native = /*#__PURE__*/Object.freeze({
184
+ __proto__: null,
185
+ BiometricAuthNative: BiometricAuthNative
164
186
  });
165
187
 
166
- exports.BiometricAuth = plugin;
188
+ exports.BiometricAuth = proxy;
167
189
  exports.BiometryError = BiometryError;
168
190
  exports.getBiometryName = getBiometryName;
169
- exports.kPluginName = kPluginName;
package/dist/plugin.js CHANGED
@@ -1,6 +1,11 @@
1
- var capacitorBiometricAuth = (function (exports, core, tslib, capacitorNativeDecorator, app) {
1
+ var capacitorBiometricAuth = (function (exports, core, app) {
2
2
  'use strict';
3
3
 
4
+ var info = {
5
+ name: "@aparajita/capacitor-biometric-auth",
6
+ version: "3.1.2"
7
+ };
8
+
4
9
  exports.BiometryType = void 0;
5
10
  (function (BiometryType) {
6
11
  /**
@@ -57,12 +62,6 @@ var capacitorBiometricAuth = (function (exports, core, tslib, capacitorNativeDec
57
62
  this.code = exports.BiometryErrorType[code];
58
63
  }
59
64
  }
60
- const kPluginName = 'BiometricAuth';
61
-
62
- var info = {
63
- name: "@aparajita/capacitor-biometric-auth",
64
- version: "3.0.2"
65
- };
66
65
 
67
66
  const kBiometryTypeNameMap = {
68
67
  [exports.BiometryType.none]: '',
@@ -72,29 +71,42 @@ var capacitorBiometricAuth = (function (exports, core, tslib, capacitorNativeDec
72
71
  [exports.BiometryType.faceAuthentication]: 'Face Authentication',
73
72
  [exports.BiometryType.irisAuthentication]: 'Iris Authentication'
74
73
  };
75
- class BiometricAuth extends core.WebPlugin {
74
+ /**
75
+ * Return a human-readable name for a BiometryType.
76
+ */
77
+ // eslint-disable-next-line import/prefer-default-export
78
+ function getBiometryName(type) {
79
+ return kBiometryTypeNameMap[type] || '';
80
+ }
81
+
82
+ console.log(`loaded ${info.name} v${info.version}`);
83
+ const proxy = core.registerPlugin('BiometricAuthNative', {
84
+ web: async () => Promise.resolve().then(function () { return web; }).then((module) => new module.BiometricAuthWeb()),
85
+ ios: async () => Promise.resolve().then(function () { return native; }).then((module) => new module.BiometricAuthNative(proxy)),
86
+ android: async () => Promise.resolve().then(function () { return native; }).then((module) => new module.BiometricAuthNative(proxy))
87
+ });
88
+
89
+ // eslint-disable-next-line import/prefer-default-export
90
+ class BiometricAuthBase extends core.WebPlugin {
91
+ addResumeListener(listener) {
92
+ return app.App.addListener('appStateChange', ({ isActive }) => {
93
+ if (isActive) {
94
+ this.checkBiometry()
95
+ .then((info) => {
96
+ listener(info);
97
+ })
98
+ .catch(console.error);
99
+ }
100
+ });
101
+ }
102
+ }
103
+
104
+ // eslint-disable-next-line import/prefer-default-export
105
+ class BiometricAuthWeb extends BiometricAuthBase {
76
106
  constructor() {
77
107
  super(...arguments);
78
108
  this.biometryType = exports.BiometryType.none;
79
109
  }
80
- getRegisteredPluginName() {
81
- return kPluginName;
82
- }
83
- setBiometryType(type) {
84
- if (typeof type === 'undefined') {
85
- return;
86
- }
87
- if (typeof type === 'string') {
88
- // eslint-disable-next-line no-prototype-builtins
89
- if (exports.BiometryType.hasOwnProperty(type)) {
90
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
91
- this.biometryType = exports.BiometryType[type];
92
- }
93
- }
94
- else {
95
- this.biometryType = type;
96
- }
97
- }
98
110
  async checkBiometry() {
99
111
  return Promise.resolve({
100
112
  isAvailable: this.biometryType !== exports.BiometryType.none,
@@ -108,7 +120,7 @@ var capacitorBiometricAuth = (function (exports, core, tslib, capacitorNativeDec
108
120
  if (
109
121
  // eslint-disable-next-line no-alert
110
122
  confirm((options === null || options === void 0 ? void 0 : options.reason) ||
111
- `Authenticate with ${kBiometryTypeNameMap[biometryType]}?`)) {
123
+ `Authenticate with ${getBiometryName(biometryType)}?`)) {
112
124
  return;
113
125
  }
114
126
  throw new BiometryError('User cancelled', exports.BiometryErrorType.userCancel);
@@ -116,54 +128,65 @@ var capacitorBiometricAuth = (function (exports, core, tslib, capacitorNativeDec
116
128
  throw new BiometryError('Biometry not available', exports.BiometryErrorType.biometryNotAvailable);
117
129
  });
118
130
  }
119
- addResumeListener(listener) {
120
- return app.App.addListener('appStateChange', ({ isActive }) => {
121
- if (isActive) {
122
- this.checkBiometry()
123
- .then((info) => {
124
- listener(info);
125
- })
126
- .catch((error) => {
127
- console.error(error.message);
128
- });
131
+ async setBiometryType(type) {
132
+ if (typeof type === 'undefined') {
133
+ return Promise.resolve();
134
+ }
135
+ if (typeof type === 'string') {
136
+ // eslint-disable-next-line no-prototype-builtins
137
+ if (exports.BiometryType.hasOwnProperty(type)) {
138
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
139
+ this.biometryType = exports.BiometryType[type];
129
140
  }
130
- });
141
+ }
142
+ else {
143
+ this.biometryType = type;
144
+ }
145
+ return Promise.resolve();
131
146
  }
132
147
  }
133
- tslib.__decorate([
134
- capacitorNativeDecorator.native()
135
- ], BiometricAuth.prototype, "checkBiometry", null);
136
- tslib.__decorate([
137
- capacitorNativeDecorator.native()
138
- ], BiometricAuth.prototype, "authenticate", null);
139
- /**
140
- * Return a human-readable name for a BiometryType.
141
- *
142
- * @param {BiometryType} type
143
- * @returns {string}
144
- */
145
- function getBiometryName(type) {
146
- return kBiometryTypeNameMap[type] || '';
148
+
149
+ var web = /*#__PURE__*/Object.freeze({
150
+ __proto__: null,
151
+ BiometricAuthWeb: BiometricAuthWeb
152
+ });
153
+
154
+ // eslint-disable-next-line import/prefer-default-export
155
+ class BiometricAuthNative extends BiometricAuthBase {
156
+ constructor(capProxy) {
157
+ super();
158
+ this.checkBiometry = capProxy.checkBiometry;
159
+ this.authenticate = capProxy.authenticate;
160
+ }
161
+ async checkBiometry() {
162
+ // Never used, satisfy the compiler
163
+ return Promise.resolve({
164
+ isAvailable: true,
165
+ biometryType: exports.BiometryType.none,
166
+ reason: ''
167
+ });
168
+ }
169
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/no-empty-function
170
+ async authenticate(options) { }
171
+ // eslint-disable-next-line @typescript-eslint/require-await
172
+ async setBiometryType(
173
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
174
+ type) {
175
+ throw this.unimplemented('setBiometryType is web only');
176
+ }
147
177
  }
148
178
 
149
- console.log(`loaded ${info.name} v${info.version}`);
150
- // Because we are using @aparajita/capacitor-native-decorator,
151
- // we have one version of the TS code to rule them all, and there
152
- // is no need to lazy load. 😁
153
- const plugin = new BiometricAuth();
154
- core.registerPlugin(kPluginName, {
155
- web: plugin,
156
- ios: plugin,
157
- android: plugin
179
+ var native = /*#__PURE__*/Object.freeze({
180
+ __proto__: null,
181
+ BiometricAuthNative: BiometricAuthNative
158
182
  });
159
183
 
160
- exports.BiometricAuth = plugin;
184
+ exports.BiometricAuth = proxy;
161
185
  exports.BiometryError = BiometryError;
162
186
  exports.getBiometryName = getBiometryName;
163
- exports.kPluginName = kPluginName;
164
187
 
165
188
  Object.defineProperty(exports, '__esModule', { value: true });
166
189
 
167
190
  return exports;
168
191
 
169
- })({}, capacitorExports, tslib, capacitorNativeDecorator, app);
192
+ })({}, capacitorExports, app);
@@ -3,7 +3,7 @@
3
3
 
4
4
  // Generated by @aparajita/capacitor-native-decorator/make-ios-plugin
5
5
 
6
- CAP_PLUGIN(BiometricAuth, "BiometricAuth",
6
+ CAP_PLUGIN(BiometricAuthNative, "BiometricAuthNative",
7
7
  CAP_PLUGIN_METHOD(checkBiometry, CAPPluginReturnPromise);
8
8
  CAP_PLUGIN_METHOD(authenticate, CAPPluginReturnPromise);
9
9
  )
@@ -5,8 +5,8 @@ import LocalAuthentication
5
5
  private let kReason = "reason"
6
6
  private let kMissingFaceIDUsageEntry = "The device supports Face ID, but NSFaceIDUsageDescription is not in Info.plist."
7
7
 
8
- @objc(BiometricAuth)
9
- public class BiometricAuth: CAPPlugin {
8
+ @objc(BiometricAuthNative)
9
+ public class BiometricAuthNative: CAPPlugin {
10
10
  let biometryErrorCodeMap: [LAError.Code: String] = [
11
11
  .appCancel: "appCancel",
12
12
  .authenticationFailed: "authenticationFailed",
@@ -22,6 +22,7 @@ public class BiometricAuth: CAPPlugin {
22
22
  ]
23
23
 
24
24
  var canEvaluatePolicy = true
25
+ var count = 0
25
26
 
26
27
  /**
27
28
  * Check the device's availability and type of biometric authentication.
@@ -60,6 +61,11 @@ public class BiometricAuth: CAPPlugin {
60
61
  ])
61
62
  }
62
63
 
64
+ @objc func test(_ call: CAPPluginCall) {
65
+ call.resolve(["count": count])
66
+ count += 1
67
+ }
68
+
63
69
  /**
64
70
  * Prompt the user for authentication.
65
71
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aparajita/capacitor-biometric-auth",
3
- "version": "3.0.2",
3
+ "version": "3.1.2",
4
4
  "description": "Provides access to the native biometric auth APIs for Capacitor apps",
5
5
  "author": "Aparajita Fishman",
6
6
  "license": "MIT",
@@ -21,14 +21,9 @@
21
21
  ],
22
22
  "commit-and-tag-version": {
23
23
  "scripts": {
24
- "postbump": "pnpm -s builder"
24
+ "postbump": "pnpm builder"
25
25
  }
26
26
  },
27
- "ultra": {
28
- "concurrent": [
29
- "verify"
30
- ]
31
- },
32
27
  "keywords": [
33
28
  "capacitor",
34
29
  "plugin",
@@ -66,9 +61,9 @@
66
61
  "@commitlint/config-conventional": "^17.0.3",
67
62
  "@ionic/swiftlint-config": "^1.1.2",
68
63
  "@rollup/plugin-json": "^4.1.0",
69
- "@types/node": "^18.6.3",
70
- "@typescript-eslint/eslint-plugin": "^5.32.0",
71
- "@typescript-eslint/parser": "^5.32.0",
64
+ "@types/node": "^18.6.5",
65
+ "@typescript-eslint/eslint-plugin": "^5.33.0",
66
+ "@typescript-eslint/parser": "^5.33.0",
72
67
  "commit-and-tag-version": "^10.0.1",
73
68
  "eslint": "^8.21.0",
74
69
  "eslint-config-prettier": "^8.5.0",
@@ -85,16 +80,13 @@
85
80
  "rimraf": "^3.0.2",
86
81
  "rollup": "^2.77.2",
87
82
  "swiftlint": "^1.0.1",
88
- "typescript": "~4.7.4",
89
- "ultra-runner": "^3.10.5"
83
+ "typescript": "~4.7.4"
90
84
  },
91
85
  "dependencies": {
92
- "@aparajita/capacitor-native-decorator": "^3.0.0",
93
86
  "@capacitor/android": "^4.0.1",
94
87
  "@capacitor/app": "^4.0.1",
95
88
  "@capacitor/core": "^4.0.1",
96
- "@capacitor/ios": "^4.0.1",
97
- "tslib": "^2.4.0"
89
+ "@capacitor/ios": "^4.0.1"
98
90
  },
99
91
  "scripts": {
100
92
  "clean": "rimraf dist",
@@ -102,19 +94,20 @@
102
94
  "lint.eslint": "eslint --fix --cache --ext .js,.cjs,.mjs,.ts --max-warnings 0",
103
95
  "lint.prettier": "prettier --write --cache --list-different",
104
96
  "lint.tsc": "tsc --noEmit",
105
- "lint": "pnpm -s extract-info && pnpm -s lint.eslint . && pnpm -s lint.prettier . && pnpm -s lint.tsc",
106
- "tsc": "tsc ${SOURCE_MAP}",
107
- "builder": "pnpm -s extract-info && pnpm -s clean && pnpm -s tsc && rollup -c rollup.config.mjs",
108
- "build": "pnpm -s builder",
109
- "build.dev": "SOURCE_MAP=--sourceMap pnpm -s builder",
110
- "watch": "nodemon --exec 'pnpm -s build.dev'",
111
- "docgen": "docgen --api BiometricAuthPlugin --output-readme README.md && docgen-format && pnpm -s lint.prettier README.md",
97
+ "lint": "pnpm lint.eslint . && pnpm lint.prettier . && pnpm lint.tsc",
98
+ "prebuilder": "pnpm clean && pnpm extract-info",
99
+ "builder": "tsc ${SOURCE_MAP:-} && rollup -c rollup.config.mjs",
100
+ "prebuild": "pnpm lint",
101
+ "build": "pnpm builder",
102
+ "build.dev": "SOURCE_MAP=--sourceMap pnpm build",
103
+ "watch": "nodemon --exec 'pnpm build.dev'",
104
+ "docgen": "docgen --api BiometricAuthPlugin --output-readme README.md && docgen-format && pnpm lint.prettier README.md",
112
105
  "open.ios": "open ios/Plugin.xcworkspace",
113
106
  "open.android": "open -b com.google.android.studio android",
114
107
  "verify.ios": "cd ios && pod install && xcodebuild -workspace Plugin.xcworkspace -scheme Plugin -quiet && cd ..",
115
108
  "verify.android": "cd android && ./gradlew clean build test && cd ..",
116
109
  "verify": "pnpm verify.ios && pnpm verify.android",
117
- "release.pre": "scripts/ensure-clean.sh && pnpm -s lint && pnpm -s docgen && git add README.md",
118
- "release": "pnpm -s release.pre && commit-and-tag-version --commit-all && git push --follow-tags && pnpm publish"
110
+ "prerelease": "scripts/ensure-clean.sh && pnpm build && pnpm docgen && git add README.md",
111
+ "release": "commit-and-tag-version --commit-all && git push --follow-tags && pnpm publish"
119
112
  }
120
113
  }