@aparajita/capacitor-biometric-auth 3.0.1 → 3.1.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
@@ -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,11 @@
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
+ private readonly _plugin;
6
+ constructor(plugin: BiometricAuthPlugin);
7
+ abstract setBiometryType(type: BiometryType | string | undefined): Promise<void>;
8
+ abstract checkBiometry(): Promise<CheckBiometryResult>;
9
+ abstract authenticate(options?: AuthenticateOptions): Promise<void>;
10
+ addResumeListener(listener: ResumeListener): Promise<PluginListenerHandle> & PluginListenerHandle;
11
+ }
@@ -0,0 +1,23 @@
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
+ constructor(plugin) {
6
+ super();
7
+ this._plugin = plugin;
8
+ }
9
+ addResumeListener(listener) {
10
+ return App.addListener('appStateChange', ({ isActive }) => {
11
+ if (isActive) {
12
+ this._plugin
13
+ .checkBiometry()
14
+ .then((info) => {
15
+ listener(info);
16
+ })
17
+ .catch((error) => {
18
+ console.error(error.message);
19
+ });
20
+ }
21
+ });
22
+ }
23
+ }
@@ -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`.
@@ -186,9 +185,6 @@ export interface BiometricAuthPlugin extends DecoratedNativePlugin {
186
185
  /**
187
186
  * Register a function that will be called when the app resumes.
188
187
  * The function will be passed the result of `checkBiometry()`.
189
- *
190
- * @returns {boolean} true if the listener is successfully added
191
188
  */
192
189
  addResumeListener: (listener: ResumeListener) => Promise<PluginListenerHandle>;
193
190
  }
194
- 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
1
  import type { BiometricAuthPlugin } from './definitions';
2
- declare const biometricAuth: BiometricAuthPlugin;
2
+ declare const proxy: BiometricAuthPlugin;
3
3
  export * from './definitions';
4
- export { biometricAuth 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
- const biometricAuth = 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(proxy)),
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 { biometricAuth 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.1"
3
+ "version": "3.1.1"
4
4
  }
@@ -0,0 +1,8 @@
1
+ import { BiometricAuthBase } from './base';
2
+ import type { AuthenticateOptions, CheckBiometryResult } from './definitions';
3
+ import { BiometryType } from './definitions';
4
+ export declare class BiometricAuthNative extends BiometricAuthBase {
5
+ checkBiometry(): Promise<CheckBiometryResult>;
6
+ authenticate(options?: AuthenticateOptions): Promise<void>;
7
+ setBiometryType(type: BiometryType | string | undefined): Promise<void>;
8
+ }
@@ -0,0 +1,21 @@
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
+ async checkBiometry() {
6
+ // Never used, satisfy the compiler
7
+ return Promise.resolve({
8
+ isAvailable: true,
9
+ biometryType: BiometryType.none,
10
+ reason: ''
11
+ });
12
+ }
13
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/no-empty-function
14
+ async authenticate(options) { }
15
+ // eslint-disable-next-line @typescript-eslint/require-await
16
+ async setBiometryType(
17
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
18
+ type) {
19
+ throw this.unimplemented('setBiometryType is web only');
20
+ }
21
+ }
@@ -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.1"
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.1"
71
- };
72
69
 
73
70
  const kBiometryTypeNameMap = {
74
71
  [exports.BiometryType.none]: '',
@@ -78,29 +75,49 @@ 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(proxy)),
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
+ constructor(plugin) {
96
+ super();
97
+ this._plugin = plugin;
98
+ }
99
+ addResumeListener(listener) {
100
+ return app.App.addListener('appStateChange', ({ isActive }) => {
101
+ if (isActive) {
102
+ this._plugin
103
+ .checkBiometry()
104
+ .then((info) => {
105
+ listener(info);
106
+ })
107
+ .catch((error) => {
108
+ console.error(error.message);
109
+ });
110
+ }
111
+ });
112
+ }
113
+ }
114
+
115
+ // eslint-disable-next-line import/prefer-default-export
116
+ class BiometricAuthWeb extends BiometricAuthBase {
82
117
  constructor() {
83
118
  super(...arguments);
84
119
  this.biometryType = exports.BiometryType.none;
85
120
  }
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
121
  async checkBiometry() {
105
122
  return Promise.resolve({
106
123
  isAvailable: this.biometryType !== exports.BiometryType.none,
@@ -114,7 +131,7 @@ class BiometricAuth extends core.WebPlugin {
114
131
  if (
115
132
  // eslint-disable-next-line no-alert
116
133
  confirm((options === null || options === void 0 ? void 0 : options.reason) ||
117
- `Authenticate with ${kBiometryTypeNameMap[biometryType]}?`)) {
134
+ `Authenticate with ${getBiometryName(biometryType)}?`)) {
118
135
  return;
119
136
  }
120
137
  throw new BiometryError('User cancelled', exports.BiometryErrorType.userCancel);
@@ -122,48 +139,54 @@ class BiometricAuth extends core.WebPlugin {
122
139
  throw new BiometryError('Biometry not available', exports.BiometryErrorType.biometryNotAvailable);
123
140
  });
124
141
  }
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
- });
142
+ async setBiometryType(type) {
143
+ if (typeof type === 'undefined') {
144
+ return Promise.resolve();
145
+ }
146
+ if (typeof type === 'string') {
147
+ // eslint-disable-next-line no-prototype-builtins
148
+ if (exports.BiometryType.hasOwnProperty(type)) {
149
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
150
+ this.biometryType = exports.BiometryType[type];
135
151
  }
136
- });
152
+ }
153
+ else {
154
+ this.biometryType = type;
155
+ }
156
+ return Promise.resolve();
137
157
  }
138
158
  }
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] || '';
159
+
160
+ var web = /*#__PURE__*/Object.freeze({
161
+ __proto__: null,
162
+ BiometricAuthWeb: BiometricAuthWeb
163
+ });
164
+
165
+ // eslint-disable-next-line import/prefer-default-export
166
+ class BiometricAuthNative extends BiometricAuthBase {
167
+ async checkBiometry() {
168
+ // Never used, satisfy the compiler
169
+ return Promise.resolve({
170
+ isAvailable: true,
171
+ biometryType: exports.BiometryType.none,
172
+ reason: ''
173
+ });
174
+ }
175
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/no-empty-function
176
+ async authenticate(options) { }
177
+ // eslint-disable-next-line @typescript-eslint/require-await
178
+ async setBiometryType(
179
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
180
+ type) {
181
+ throw this.unimplemented('setBiometryType is web only');
182
+ }
153
183
  }
154
184
 
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
- const biometricAuth = core.registerPlugin(kPluginName, {
161
- web: plugin,
162
- ios: plugin,
163
- android: plugin
185
+ var native = /*#__PURE__*/Object.freeze({
186
+ __proto__: null,
187
+ BiometricAuthNative: BiometricAuthNative
164
188
  });
165
189
 
166
- exports.BiometricAuth = biometricAuth;
190
+ exports.BiometricAuth = proxy;
167
191
  exports.BiometryError = BiometryError;
168
192
  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.1"
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.1"
65
- };
66
65
 
67
66
  const kBiometryTypeNameMap = {
68
67
  [exports.BiometryType.none]: '',
@@ -72,29 +71,49 @@ 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(proxy)),
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
+ constructor(plugin) {
92
+ super();
93
+ this._plugin = plugin;
94
+ }
95
+ addResumeListener(listener) {
96
+ return app.App.addListener('appStateChange', ({ isActive }) => {
97
+ if (isActive) {
98
+ this._plugin
99
+ .checkBiometry()
100
+ .then((info) => {
101
+ listener(info);
102
+ })
103
+ .catch((error) => {
104
+ console.error(error.message);
105
+ });
106
+ }
107
+ });
108
+ }
109
+ }
110
+
111
+ // eslint-disable-next-line import/prefer-default-export
112
+ class BiometricAuthWeb extends BiometricAuthBase {
76
113
  constructor() {
77
114
  super(...arguments);
78
115
  this.biometryType = exports.BiometryType.none;
79
116
  }
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
117
  async checkBiometry() {
99
118
  return Promise.resolve({
100
119
  isAvailable: this.biometryType !== exports.BiometryType.none,
@@ -108,7 +127,7 @@ var capacitorBiometricAuth = (function (exports, core, tslib, capacitorNativeDec
108
127
  if (
109
128
  // eslint-disable-next-line no-alert
110
129
  confirm((options === null || options === void 0 ? void 0 : options.reason) ||
111
- `Authenticate with ${kBiometryTypeNameMap[biometryType]}?`)) {
130
+ `Authenticate with ${getBiometryName(biometryType)}?`)) {
112
131
  return;
113
132
  }
114
133
  throw new BiometryError('User cancelled', exports.BiometryErrorType.userCancel);
@@ -116,54 +135,60 @@ var capacitorBiometricAuth = (function (exports, core, tslib, capacitorNativeDec
116
135
  throw new BiometryError('Biometry not available', exports.BiometryErrorType.biometryNotAvailable);
117
136
  });
118
137
  }
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
- });
138
+ async setBiometryType(type) {
139
+ if (typeof type === 'undefined') {
140
+ return Promise.resolve();
141
+ }
142
+ if (typeof type === 'string') {
143
+ // eslint-disable-next-line no-prototype-builtins
144
+ if (exports.BiometryType.hasOwnProperty(type)) {
145
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
146
+ this.biometryType = exports.BiometryType[type];
129
147
  }
130
- });
148
+ }
149
+ else {
150
+ this.biometryType = type;
151
+ }
152
+ return Promise.resolve();
131
153
  }
132
154
  }
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] || '';
155
+
156
+ var web = /*#__PURE__*/Object.freeze({
157
+ __proto__: null,
158
+ BiometricAuthWeb: BiometricAuthWeb
159
+ });
160
+
161
+ // eslint-disable-next-line import/prefer-default-export
162
+ class BiometricAuthNative extends BiometricAuthBase {
163
+ async checkBiometry() {
164
+ // Never used, satisfy the compiler
165
+ return Promise.resolve({
166
+ isAvailable: true,
167
+ biometryType: exports.BiometryType.none,
168
+ reason: ''
169
+ });
170
+ }
171
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/no-empty-function
172
+ async authenticate(options) { }
173
+ // eslint-disable-next-line @typescript-eslint/require-await
174
+ async setBiometryType(
175
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
176
+ type) {
177
+ throw this.unimplemented('setBiometryType is web only');
178
+ }
147
179
  }
148
180
 
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
- const biometricAuth = core.registerPlugin(kPluginName, {
155
- web: plugin,
156
- ios: plugin,
157
- android: plugin
181
+ var native = /*#__PURE__*/Object.freeze({
182
+ __proto__: null,
183
+ BiometricAuthNative: BiometricAuthNative
158
184
  });
159
185
 
160
- exports.BiometricAuth = biometricAuth;
186
+ exports.BiometricAuth = proxy;
161
187
  exports.BiometryError = BiometryError;
162
188
  exports.getBiometryName = getBiometryName;
163
- exports.kPluginName = kPluginName;
164
189
 
165
190
  Object.defineProperty(exports, '__esModule', { value: true });
166
191
 
167
192
  return exports;
168
193
 
169
- })({}, capacitorExports, tslib, capacitorNativeDecorator, app);
194
+ })({}, 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.1",
3
+ "version": "3.1.1",
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,35 +80,34 @@
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": {
92
+ "clean": "rimraf dist",
100
93
  "extract-info": "node scripts/extractPackageInfo.js",
101
94
  "lint.eslint": "eslint --fix --cache --ext .js,.cjs,.mjs,.ts --max-warnings 0",
102
95
  "lint.prettier": "prettier --write --cache --list-different",
103
96
  "lint.tsc": "tsc --noEmit",
104
- "lint": "pnpm -s extract-info && pnpm -s lint.eslint . && pnpm -s lint.prettier . && pnpm -s lint.tsc",
105
- "tsc": "tsc ${SOURCE_MAP}",
106
- "builder": "pnpm -s extract-info && rimraf dist && pnpm -s tsc && rollup -c rollup.config.mjs && pnpm -s docgen",
107
- "build": "pnpm -s builder",
108
- "build.dev": "SOURCE_MAP=--sourceMap pnpm -s builder",
109
- "watch": "nodemon --exec 'pnpm -s build.dev'",
110
- "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",
111
105
  "open.ios": "open ios/Plugin.xcworkspace",
112
106
  "open.android": "open -b com.google.android.studio android",
113
107
  "verify.ios": "cd ios && pod install && xcodebuild -workspace Plugin.xcworkspace -scheme Plugin -quiet && cd ..",
114
108
  "verify.android": "cd android && ./gradlew clean build test && cd ..",
115
109
  "verify": "pnpm verify.ios && pnpm verify.android",
116
- "release.pre": "scripts/ensure-clean.sh && pnpm -s lint",
117
- "release": "pnpm -s release.pre && commit-and-tag-version && 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"
118
112
  }
119
113
  }