capacitor-auth-manager 2.2.0 → 2.3.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.
Files changed (37) hide show
  1. package/dist/angular.cjs.js +99 -80
  2. package/dist/angular.cjs.js.map +1 -1
  3. package/dist/core.cjs.js +99 -80
  4. package/dist/core.cjs.js.map +1 -1
  5. package/dist/esm/providers/base-provider.d.ts +11 -0
  6. package/dist/esm/providers/base-provider.js +30 -3
  7. package/dist/esm/providers/base-provider.js.map +1 -1
  8. package/dist/esm/providers/web/biometric-provider.d.ts +6 -7
  9. package/dist/esm/providers/web/biometric-provider.js +10 -7
  10. package/dist/esm/providers/web/biometric-provider.js.map +1 -1
  11. package/dist/esm/providers/web/email-code-provider.d.ts +5 -7
  12. package/dist/esm/providers/web/email-code-provider.js +10 -11
  13. package/dist/esm/providers/web/email-code-provider.js.map +1 -1
  14. package/dist/esm/providers/web/email-password-provider.d.ts +4 -7
  15. package/dist/esm/providers/web/email-password-provider.js +12 -13
  16. package/dist/esm/providers/web/email-password-provider.js.map +1 -1
  17. package/dist/esm/providers/web/magic-link-provider.d.ts +5 -7
  18. package/dist/esm/providers/web/magic-link-provider.js +12 -13
  19. package/dist/esm/providers/web/magic-link-provider.js.map +1 -1
  20. package/dist/esm/providers/web/phone-password-provider.d.ts +5 -8
  21. package/dist/esm/providers/web/phone-password-provider.js +18 -16
  22. package/dist/esm/providers/web/phone-password-provider.js.map +1 -1
  23. package/dist/esm/providers/web/sms-provider.d.ts +5 -7
  24. package/dist/esm/providers/web/sms-provider.js +11 -13
  25. package/dist/esm/providers/web/sms-provider.js.map +1 -1
  26. package/dist/esm/providers/web/username-password-provider.d.ts +4 -7
  27. package/dist/esm/providers/web/username-password-provider.js +12 -11
  28. package/dist/esm/providers/web/username-password-provider.js.map +1 -1
  29. package/dist/plugin.cjs.js +99 -80
  30. package/dist/plugin.cjs.js.map +1 -1
  31. package/dist/plugin.js +99 -80
  32. package/dist/plugin.js.map +1 -1
  33. package/dist/react.cjs.js +99 -80
  34. package/dist/react.cjs.js.map +1 -1
  35. package/dist/vue.cjs.js +99 -80
  36. package/dist/vue.cjs.js.map +1 -1
  37. package/package.json +2 -2
package/dist/react.cjs.js CHANGED
@@ -2141,6 +2141,31 @@ function useIsAuthenticated() {
2141
2141
  return isAuthenticated;
2142
2142
  }
2143
2143
 
2144
+ /**
2145
+ * Normalize a provider constructor argument into a full {@link BaseProviderConfig}.
2146
+ *
2147
+ * The standalone providers are public (exported from `capacitor-auth-manager/providers/web`) and
2148
+ * get constructed two ways: the factory/registry pass a full {@link BaseProviderConfig}, while
2149
+ * tests and direct consumers pass the provider's own bare options object. This helper accepts
2150
+ * either — a bare object is wrapped with an in-memory storage (`AuthPersistence.NONE`, so it never
2151
+ * touches `window` and stays safe under SSR / Node test environments) plus the shared
2152
+ * {@link defaultLogger}. Callers that pass a full config keep their injected storage/logger.
2153
+ */
2154
+ function resolveProviderConfig(provider, input) {
2155
+ if (typeof input === 'object' &&
2156
+ input !== null &&
2157
+ 'storage' in input &&
2158
+ 'logger' in input &&
2159
+ 'options' in input) {
2160
+ return input;
2161
+ }
2162
+ return {
2163
+ provider,
2164
+ options: (input !== null && input !== void 0 ? input : {}),
2165
+ storage: new WebStorage(AuthPersistence.NONE),
2166
+ logger: defaultLogger,
2167
+ };
2168
+ }
2144
2169
  class BaseAuthProvider {
2145
2170
  get name() {
2146
2171
  return this.provider;
@@ -2160,13 +2185,13 @@ class BaseAuthProvider {
2160
2185
  // across every provider (see AuthProviderInterface, where they are optional). Marking them
2161
2186
  // abstract previously forced every subclass to re-implement them just to throw.
2162
2187
  async linkAccount(_options) {
2163
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, `Provider ${this.provider} does not support account linking`, this.provider);
2188
+ throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, `Account linking is not supported by provider ${this.provider}`, this.provider);
2164
2189
  }
2165
2190
  async unlinkAccount(_options) {
2166
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, `Provider ${this.provider} does not support account unlinking`, this.provider);
2191
+ throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, `Account unlinking is not supported by provider ${this.provider}`, this.provider);
2167
2192
  }
2168
2193
  async revokeAccess(_token) {
2169
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, `Provider ${this.provider} does not support access revocation`, this.provider);
2194
+ throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, `Access revocation is not supported by provider ${this.provider}`, this.provider);
2170
2195
  }
2171
2196
  async getCurrentUser() {
2172
2197
  if (!this.isInitialized) {
@@ -4481,16 +4506,19 @@ class PendingVerificationStore {
4481
4506
  }
4482
4507
  }
4483
4508
 
4484
- class MagicLinkProvider {
4485
- constructor(config) {
4486
- this.name = 'magic-link';
4509
+ class MagicLinkProvider extends BaseAuthProvider {
4510
+ get name() {
4511
+ return 'magic-link';
4512
+ }
4513
+ constructor(input) {
4514
+ super(resolveProviderConfig(AuthProvider.EMAIL_MAGIC_LINK, input));
4487
4515
  // Persisted (SSR-guarded localStorage) so a magic link clicked from an email — which opens a
4488
4516
  // FRESH page load with empty in-memory state — can still find its pending entry to verify
4489
4517
  // against. Keyed by the link token (already present in the callback URL); we store only the
4490
4518
  // email + expiry, never any additional secret (see PendingVerificationStore + F-11).
4491
4519
  this.pendingVerification = new PendingVerificationStore('magic-link');
4492
- // Initialize with config
4493
- this.config = config;
4520
+ // Magic link uses its config as-is (no defaults to merge).
4521
+ this.config = this.options;
4494
4522
  // Check for magic link callback on initialization
4495
4523
  this.checkForMagicLinkCallback();
4496
4524
  }
@@ -4740,14 +4768,9 @@ class MagicLinkProvider {
4740
4768
  // Magic link auth is supported if we have the required config
4741
4769
  return !!this.config.sendLinkUrl;
4742
4770
  }
4743
- async linkAccount(_options) {
4744
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for magic link authentication');
4745
- }
4746
- async unlinkAccount(_options) {
4747
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for magic link authentication');
4748
- }
4771
+ // linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
4749
4772
  async revokeAccess(_token) {
4750
- // Magic link doesn't have persistent access to revoke
4773
+ // Magic link doesn't have persistent access to revoke; clear any pending verification.
4751
4774
  this.pendingVerification.clear();
4752
4775
  }
4753
4776
  }
@@ -4757,16 +4780,18 @@ var magicLinkProvider = /*#__PURE__*/Object.freeze({
4757
4780
  MagicLinkProvider: MagicLinkProvider
4758
4781
  });
4759
4782
 
4760
- class SMSProvider {
4761
- constructor(config) {
4762
- this.name = 'sms';
4783
+ class SMSProvider extends BaseAuthProvider {
4784
+ get name() {
4785
+ return 'sms';
4786
+ }
4787
+ constructor(input) {
4788
+ super(resolveProviderConfig(AuthProvider.SMS, input));
4763
4789
  // Pending verifications are persisted (SSR-guarded localStorage) so they survive a reload /
4764
4790
  // page change between sending and verifying the code. Only non-secret metadata is stored —
4765
4791
  // never the SMS code itself (see PendingVerificationStore + F-11).
4766
4792
  this.pendingVerifications = new PendingVerificationStore('sms');
4767
4793
  this.MAX_ATTEMPTS = 3;
4768
- // Initialize with config
4769
- this.config = Object.assign({ countryCode: '+1', codeLength: 6, resendDelay: 60000 }, config);
4794
+ this.config = Object.assign({ countryCode: '+1', codeLength: 6, resendDelay: 60000 }, this.options);
4770
4795
  }
4771
4796
  async signIn(options) {
4772
4797
  if (!(options === null || options === void 0 ? void 0 : options.phoneNumber)) {
@@ -5004,14 +5029,9 @@ class SMSProvider {
5004
5029
  // SMS auth is supported if we have the required config
5005
5030
  return !!(this.config.sendCodeUrl && this.config.verifyCodeUrl);
5006
5031
  }
5007
- async linkAccount(_options) {
5008
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for SMS authentication');
5009
- }
5010
- async unlinkAccount(_options) {
5011
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for SMS authentication');
5012
- }
5032
+ // linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
5013
5033
  async revokeAccess(_token) {
5014
- // SMS auth doesn't have persistent access to revoke
5034
+ // SMS auth doesn't have persistent access to revoke; clear any pending verification.
5015
5035
  this.pendingVerifications.clear();
5016
5036
  }
5017
5037
  }
@@ -5021,20 +5041,23 @@ var smsProvider = /*#__PURE__*/Object.freeze({
5021
5041
  SMSProvider: SMSProvider
5022
5042
  });
5023
5043
 
5024
- class EmailPasswordProvider {
5025
- constructor(config) {
5026
- this.name = 'email-password';
5027
- this.currentUser = null;
5044
+ class EmailPasswordProvider extends BaseAuthProvider {
5045
+ get name() {
5046
+ return 'email-password';
5047
+ }
5048
+ constructor(input) {
5049
+ super(resolveProviderConfig(AuthProvider.EMAIL_PASSWORD, input));
5050
+ // currentUser is the inherited (in-memory) field from BaseAuthProvider; assigned directly here
5051
+ // so email/password sessions stay in-memory exactly as before (no new storage persistence).
5028
5052
  this.authToken = null;
5029
5053
  this.refreshTokenValue = null;
5030
- // Initialize with config
5031
5054
  this.config = Object.assign({ allowSignUp: true, passwordRequirements: {
5032
5055
  minLength: 8,
5033
5056
  requireUppercase: true,
5034
5057
  requireLowercase: true,
5035
5058
  requireNumbers: true,
5036
5059
  requireSpecialChars: false,
5037
- } }, config);
5060
+ } }, this.options);
5038
5061
  }
5039
5062
  async signIn(options) {
5040
5063
  if (!(options === null || options === void 0 ? void 0 : options.email) || !(options === null || options === void 0 ? void 0 : options.password)) {
@@ -5380,12 +5403,7 @@ class EmailPasswordProvider {
5380
5403
  // Email/Password auth is supported if we have the required config
5381
5404
  return !!this.config.apiUrl;
5382
5405
  }
5383
- async linkAccount(_options) {
5384
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for email/password authentication');
5385
- }
5386
- async unlinkAccount(_options) {
5387
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for email/password authentication');
5388
- }
5406
+ // linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
5389
5407
  async revokeAccess(_token) {
5390
5408
  // For email/password auth, revoking access means signing out
5391
5409
  await this.signOut();
@@ -5397,11 +5415,15 @@ var emailPasswordProvider = /*#__PURE__*/Object.freeze({
5397
5415
  EmailPasswordProvider: EmailPasswordProvider
5398
5416
  });
5399
5417
 
5400
- class BiometricProvider {
5401
- constructor(config = {}) {
5402
- this.name = 'biometric';
5418
+ class BiometricProvider extends BaseAuthProvider {
5419
+ get name() {
5420
+ return 'biometric';
5421
+ }
5422
+ constructor(input = {}) {
5423
+ super(resolveProviderConfig(AuthProvider.BIOMETRIC, input));
5403
5424
  this.biometricAuth = null;
5404
5425
  this.cryptoKeyPromise = null;
5426
+ const config = this.options;
5405
5427
  this.config = Object.assign({ reason: 'Authenticate to access your account', title: 'Authentication Required', subtitle: 'Access your account securely', fallbackTitle: 'Use Passcode', requireRecentAuth: true, recentAuthTimeout: 5 * 60 * 1000 }, config);
5406
5428
  this.storageKey =
5407
5429
  config.storageKey || 'capacitor-auth-biometric-credentials';
@@ -5685,9 +5707,7 @@ class BiometricProvider {
5685
5707
  const result = await this.isAvailable();
5686
5708
  return result.available;
5687
5709
  }
5688
- async linkAccount(_options) {
5689
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for biometric authentication');
5690
- }
5710
+ // linkAccount inherits BaseAuthProvider's OPERATION_NOT_ALLOWED default (F-44).
5691
5711
  async unlinkAccount(_options) {
5692
5712
  // Unlinking biometric auth means clearing stored credentials
5693
5713
  await this.clearStoredCredentials();
@@ -5964,12 +5984,17 @@ var linkedinProvider = /*#__PURE__*/Object.freeze({
5964
5984
  LinkedInProvider: LinkedInProvider
5965
5985
  });
5966
5986
 
5967
- class UsernamePasswordProvider {
5968
- constructor(config) {
5969
- this.name = 'username-password';
5970
- this.currentUser = null;
5987
+ class UsernamePasswordProvider extends BaseAuthProvider {
5988
+ get name() {
5989
+ return 'username-password';
5990
+ }
5991
+ constructor(input) {
5992
+ super(resolveProviderConfig(AuthProvider.USERNAME_PASSWORD, input));
5993
+ // currentUser is the inherited (in-memory) field from BaseAuthProvider; assigned directly here
5994
+ // so username/password sessions stay in-memory exactly as before (no new storage persistence).
5971
5995
  this.authToken = null;
5972
5996
  this.refreshTokenValue = null;
5997
+ const config = this.options;
5973
5998
  this.config = Object.assign({ allowSignUp: true, usernameRequirements: Object.assign({ minLength: 3, maxLength: 20, allowedCharacters: /^[a-zA-Z0-9_-]+$/, reservedUsernames: ['admin', 'root', 'system', 'user'] }, config.usernameRequirements), passwordRequirements: Object.assign({ minLength: 8, requireUppercase: true, requireLowercase: true, requireNumbers: true, requireSpecialChars: false }, config.passwordRequirements) }, config);
5974
5999
  }
5975
6000
  async signIn(options) {
@@ -6314,12 +6339,7 @@ class UsernamePasswordProvider {
6314
6339
  // Username/Password auth is supported if we have the required config
6315
6340
  return !!this.config.apiUrl;
6316
6341
  }
6317
- async linkAccount(_options) {
6318
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for username/password authentication');
6319
- }
6320
- async unlinkAccount(_options) {
6321
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for username/password authentication');
6322
- }
6342
+ // linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
6323
6343
  async revokeAccess(_token) {
6324
6344
  // For username/password auth, revoking access means signing out
6325
6345
  await this.signOut();
@@ -6331,15 +6351,18 @@ var usernamePasswordProvider = /*#__PURE__*/Object.freeze({
6331
6351
  UsernamePasswordProvider: UsernamePasswordProvider
6332
6352
  });
6333
6353
 
6334
- class EmailCodeProvider {
6335
- constructor(config) {
6336
- this.name = 'email-code';
6354
+ class EmailCodeProvider extends BaseAuthProvider {
6355
+ get name() {
6356
+ return 'email-code';
6357
+ }
6358
+ constructor(input) {
6359
+ super(resolveProviderConfig(AuthProvider.EMAIL_CODE, input));
6337
6360
  // Pending verifications are persisted (SSR-guarded localStorage) so they survive a reload /
6338
6361
  // page change between sending and verifying the code. Only non-secret metadata is stored —
6339
6362
  // never the verification code itself (see PendingVerificationStore + F-11).
6340
6363
  this.pendingVerifications = new PendingVerificationStore('email-code');
6341
6364
  this.MAX_ATTEMPTS = 3;
6342
- this.config = Object.assign({ codeLength: 6, resendDelay: 60000, codeExpiration: 10 * 60 * 1000 }, config);
6365
+ this.config = Object.assign({ codeLength: 6, resendDelay: 60000, codeExpiration: 10 * 60 * 1000 }, this.options);
6343
6366
  }
6344
6367
  async signIn(options) {
6345
6368
  if (!(options === null || options === void 0 ? void 0 : options.email)) {
@@ -6534,12 +6557,7 @@ class EmailCodeProvider {
6534
6557
  async isSupported() {
6535
6558
  return !!(this.config.sendCodeUrl && this.config.verifyCodeUrl);
6536
6559
  }
6537
- async linkAccount(_options) {
6538
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for email code authentication');
6539
- }
6540
- async unlinkAccount(_options) {
6541
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for email code authentication');
6542
- }
6560
+ // linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
6543
6561
  async revokeAccess(_token) {
6544
6562
  this.pendingVerifications.clear();
6545
6563
  }
@@ -6584,11 +6602,15 @@ var emailCodeProvider = /*#__PURE__*/Object.freeze({
6584
6602
  EmailCodeProvider: EmailCodeProvider
6585
6603
  });
6586
6604
 
6587
- class PhonePasswordProvider {
6588
- constructor(config) {
6589
- this.name = 'phone-password';
6605
+ class PhonePasswordProvider extends BaseAuthProvider {
6606
+ get name() {
6607
+ return 'phone-password';
6608
+ }
6609
+ constructor(input) {
6610
+ super(resolveProviderConfig(AuthProvider.PHONE_PASSWORD, input));
6590
6611
  this.pendingVerifications = new Map();
6591
- this.currentUser = null;
6612
+ // currentUser is the inherited (in-memory) field from BaseAuthProvider; assigned directly here
6613
+ // so phone/password sessions stay in-memory exactly as before (no new storage persistence).
6592
6614
  this.storedAccessToken = null;
6593
6615
  this.storedRefreshToken = null;
6594
6616
  this.config = Object.assign({ countryCode: '+1', requirePhoneVerification: false, passwordStrength: {
@@ -6597,7 +6619,7 @@ class PhonePasswordProvider {
6597
6619
  requireLowercase: true,
6598
6620
  requireNumbers: true,
6599
6621
  requireSpecialChars: false,
6600
- } }, config);
6622
+ } }, this.options);
6601
6623
  }
6602
6624
  async signIn(options) {
6603
6625
  const credentials = options === null || options === void 0 ? void 0 : options.credentials;
@@ -6640,7 +6662,7 @@ class PhonePasswordProvider {
6640
6662
  throw new AuthError(AuthErrorCode.SIGN_IN_FAILED, error.message || 'Sign in failed');
6641
6663
  }
6642
6664
  const data = await response.json();
6643
- return this.createAuthResult(data, phoneNumber);
6665
+ return this.buildAuthResult(data, phoneNumber);
6644
6666
  }
6645
6667
  catch (error) {
6646
6668
  if (error instanceof AuthError)
@@ -6704,7 +6726,7 @@ class PhonePasswordProvider {
6704
6726
  },
6705
6727
  };
6706
6728
  }
6707
- return this.createAuthResult(data, phoneNumber, true);
6729
+ return this.buildAuthResult(data, phoneNumber, true);
6708
6730
  }
6709
6731
  catch (error) {
6710
6732
  if (error instanceof AuthError)
@@ -6772,7 +6794,7 @@ class PhonePasswordProvider {
6772
6794
  }
6773
6795
  const data = await response.json();
6774
6796
  this.pendingVerifications.delete(phoneNumber);
6775
- return this.createAuthResult(data, phoneNumber);
6797
+ return this.buildAuthResult(data, phoneNumber);
6776
6798
  }
6777
6799
  catch (error) {
6778
6800
  if (error instanceof AuthError)
@@ -6842,12 +6864,7 @@ class PhonePasswordProvider {
6842
6864
  async isSupported() {
6843
6865
  return !!(this.config.signInUrl && this.config.signUpUrl);
6844
6866
  }
6845
- async linkAccount(_options) {
6846
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for phone/password authentication');
6847
- }
6848
- async unlinkAccount(_options) {
6849
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for phone/password authentication');
6850
- }
6867
+ // linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
6851
6868
  async revokeAccess(_token) {
6852
6869
  await this.signOut();
6853
6870
  }
@@ -6874,7 +6891,9 @@ class PhonePasswordProvider {
6874
6891
  throw new AuthError(AuthErrorCode.SERVER_ERROR, error.message || 'Failed to send password reset');
6875
6892
  }
6876
6893
  }
6877
- createAuthResult(data, phoneNumber, isNewUser = false) {
6894
+ // Renamed from createAuthResult to avoid colliding with BaseAuthProvider.createAuthResult,
6895
+ // which has a different signature (this builds a phone-specific result from a backend payload).
6896
+ buildAuthResult(data, phoneNumber, isNewUser = false) {
6878
6897
  const user = {
6879
6898
  uid: data.uid || this.generateUid(phoneNumber),
6880
6899
  email: data.email || null,