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
@@ -2184,6 +2184,31 @@ let NoAuthGuard = (() => {
2184
2184
  return _classThis;
2185
2185
  })();
2186
2186
 
2187
+ /**
2188
+ * Normalize a provider constructor argument into a full {@link BaseProviderConfig}.
2189
+ *
2190
+ * The standalone providers are public (exported from `capacitor-auth-manager/providers/web`) and
2191
+ * get constructed two ways: the factory/registry pass a full {@link BaseProviderConfig}, while
2192
+ * tests and direct consumers pass the provider's own bare options object. This helper accepts
2193
+ * either — a bare object is wrapped with an in-memory storage (`AuthPersistence.NONE`, so it never
2194
+ * touches `window` and stays safe under SSR / Node test environments) plus the shared
2195
+ * {@link defaultLogger}. Callers that pass a full config keep their injected storage/logger.
2196
+ */
2197
+ function resolveProviderConfig(provider, input) {
2198
+ if (typeof input === 'object' &&
2199
+ input !== null &&
2200
+ 'storage' in input &&
2201
+ 'logger' in input &&
2202
+ 'options' in input) {
2203
+ return input;
2204
+ }
2205
+ return {
2206
+ provider,
2207
+ options: (input !== null && input !== void 0 ? input : {}),
2208
+ storage: new WebStorage(AuthPersistence.NONE),
2209
+ logger: defaultLogger,
2210
+ };
2211
+ }
2187
2212
  class BaseAuthProvider {
2188
2213
  get name() {
2189
2214
  return this.provider;
@@ -2203,13 +2228,13 @@ class BaseAuthProvider {
2203
2228
  // across every provider (see AuthProviderInterface, where they are optional). Marking them
2204
2229
  // abstract previously forced every subclass to re-implement them just to throw.
2205
2230
  async linkAccount(_options) {
2206
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, `Provider ${this.provider} does not support account linking`, this.provider);
2231
+ throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, `Account linking is not supported by provider ${this.provider}`, this.provider);
2207
2232
  }
2208
2233
  async unlinkAccount(_options) {
2209
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, `Provider ${this.provider} does not support account unlinking`, this.provider);
2234
+ throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, `Account unlinking is not supported by provider ${this.provider}`, this.provider);
2210
2235
  }
2211
2236
  async revokeAccess(_token) {
2212
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, `Provider ${this.provider} does not support access revocation`, this.provider);
2237
+ throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, `Access revocation is not supported by provider ${this.provider}`, this.provider);
2213
2238
  }
2214
2239
  async getCurrentUser() {
2215
2240
  if (!this.isInitialized) {
@@ -4524,16 +4549,19 @@ class PendingVerificationStore {
4524
4549
  }
4525
4550
  }
4526
4551
 
4527
- class MagicLinkProvider {
4528
- constructor(config) {
4529
- this.name = 'magic-link';
4552
+ class MagicLinkProvider extends BaseAuthProvider {
4553
+ get name() {
4554
+ return 'magic-link';
4555
+ }
4556
+ constructor(input) {
4557
+ super(resolveProviderConfig(AuthProvider.EMAIL_MAGIC_LINK, input));
4530
4558
  // Persisted (SSR-guarded localStorage) so a magic link clicked from an email — which opens a
4531
4559
  // FRESH page load with empty in-memory state — can still find its pending entry to verify
4532
4560
  // against. Keyed by the link token (already present in the callback URL); we store only the
4533
4561
  // email + expiry, never any additional secret (see PendingVerificationStore + F-11).
4534
4562
  this.pendingVerification = new PendingVerificationStore('magic-link');
4535
- // Initialize with config
4536
- this.config = config;
4563
+ // Magic link uses its config as-is (no defaults to merge).
4564
+ this.config = this.options;
4537
4565
  // Check for magic link callback on initialization
4538
4566
  this.checkForMagicLinkCallback();
4539
4567
  }
@@ -4783,14 +4811,9 @@ class MagicLinkProvider {
4783
4811
  // Magic link auth is supported if we have the required config
4784
4812
  return !!this.config.sendLinkUrl;
4785
4813
  }
4786
- async linkAccount(_options) {
4787
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for magic link authentication');
4788
- }
4789
- async unlinkAccount(_options) {
4790
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for magic link authentication');
4791
- }
4814
+ // linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
4792
4815
  async revokeAccess(_token) {
4793
- // Magic link doesn't have persistent access to revoke
4816
+ // Magic link doesn't have persistent access to revoke; clear any pending verification.
4794
4817
  this.pendingVerification.clear();
4795
4818
  }
4796
4819
  }
@@ -4800,16 +4823,18 @@ var magicLinkProvider = /*#__PURE__*/Object.freeze({
4800
4823
  MagicLinkProvider: MagicLinkProvider
4801
4824
  });
4802
4825
 
4803
- class SMSProvider {
4804
- constructor(config) {
4805
- this.name = 'sms';
4826
+ class SMSProvider extends BaseAuthProvider {
4827
+ get name() {
4828
+ return 'sms';
4829
+ }
4830
+ constructor(input) {
4831
+ super(resolveProviderConfig(AuthProvider.SMS, input));
4806
4832
  // Pending verifications are persisted (SSR-guarded localStorage) so they survive a reload /
4807
4833
  // page change between sending and verifying the code. Only non-secret metadata is stored —
4808
4834
  // never the SMS code itself (see PendingVerificationStore + F-11).
4809
4835
  this.pendingVerifications = new PendingVerificationStore('sms');
4810
4836
  this.MAX_ATTEMPTS = 3;
4811
- // Initialize with config
4812
- this.config = Object.assign({ countryCode: '+1', codeLength: 6, resendDelay: 60000 }, config);
4837
+ this.config = Object.assign({ countryCode: '+1', codeLength: 6, resendDelay: 60000 }, this.options);
4813
4838
  }
4814
4839
  async signIn(options) {
4815
4840
  if (!(options === null || options === void 0 ? void 0 : options.phoneNumber)) {
@@ -5047,14 +5072,9 @@ class SMSProvider {
5047
5072
  // SMS auth is supported if we have the required config
5048
5073
  return !!(this.config.sendCodeUrl && this.config.verifyCodeUrl);
5049
5074
  }
5050
- async linkAccount(_options) {
5051
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for SMS authentication');
5052
- }
5053
- async unlinkAccount(_options) {
5054
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for SMS authentication');
5055
- }
5075
+ // linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
5056
5076
  async revokeAccess(_token) {
5057
- // SMS auth doesn't have persistent access to revoke
5077
+ // SMS auth doesn't have persistent access to revoke; clear any pending verification.
5058
5078
  this.pendingVerifications.clear();
5059
5079
  }
5060
5080
  }
@@ -5064,20 +5084,23 @@ var smsProvider = /*#__PURE__*/Object.freeze({
5064
5084
  SMSProvider: SMSProvider
5065
5085
  });
5066
5086
 
5067
- class EmailPasswordProvider {
5068
- constructor(config) {
5069
- this.name = 'email-password';
5070
- this.currentUser = null;
5087
+ class EmailPasswordProvider extends BaseAuthProvider {
5088
+ get name() {
5089
+ return 'email-password';
5090
+ }
5091
+ constructor(input) {
5092
+ super(resolveProviderConfig(AuthProvider.EMAIL_PASSWORD, input));
5093
+ // currentUser is the inherited (in-memory) field from BaseAuthProvider; assigned directly here
5094
+ // so email/password sessions stay in-memory exactly as before (no new storage persistence).
5071
5095
  this.authToken = null;
5072
5096
  this.refreshTokenValue = null;
5073
- // Initialize with config
5074
5097
  this.config = Object.assign({ allowSignUp: true, passwordRequirements: {
5075
5098
  minLength: 8,
5076
5099
  requireUppercase: true,
5077
5100
  requireLowercase: true,
5078
5101
  requireNumbers: true,
5079
5102
  requireSpecialChars: false,
5080
- } }, config);
5103
+ } }, this.options);
5081
5104
  }
5082
5105
  async signIn(options) {
5083
5106
  if (!(options === null || options === void 0 ? void 0 : options.email) || !(options === null || options === void 0 ? void 0 : options.password)) {
@@ -5423,12 +5446,7 @@ class EmailPasswordProvider {
5423
5446
  // Email/Password auth is supported if we have the required config
5424
5447
  return !!this.config.apiUrl;
5425
5448
  }
5426
- async linkAccount(_options) {
5427
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for email/password authentication');
5428
- }
5429
- async unlinkAccount(_options) {
5430
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for email/password authentication');
5431
- }
5449
+ // linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
5432
5450
  async revokeAccess(_token) {
5433
5451
  // For email/password auth, revoking access means signing out
5434
5452
  await this.signOut();
@@ -5440,11 +5458,15 @@ var emailPasswordProvider = /*#__PURE__*/Object.freeze({
5440
5458
  EmailPasswordProvider: EmailPasswordProvider
5441
5459
  });
5442
5460
 
5443
- class BiometricProvider {
5444
- constructor(config = {}) {
5445
- this.name = 'biometric';
5461
+ class BiometricProvider extends BaseAuthProvider {
5462
+ get name() {
5463
+ return 'biometric';
5464
+ }
5465
+ constructor(input = {}) {
5466
+ super(resolveProviderConfig(AuthProvider.BIOMETRIC, input));
5446
5467
  this.biometricAuth = null;
5447
5468
  this.cryptoKeyPromise = null;
5469
+ const config = this.options;
5448
5470
  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);
5449
5471
  this.storageKey =
5450
5472
  config.storageKey || 'capacitor-auth-biometric-credentials';
@@ -5728,9 +5750,7 @@ class BiometricProvider {
5728
5750
  const result = await this.isAvailable();
5729
5751
  return result.available;
5730
5752
  }
5731
- async linkAccount(_options) {
5732
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for biometric authentication');
5733
- }
5753
+ // linkAccount inherits BaseAuthProvider's OPERATION_NOT_ALLOWED default (F-44).
5734
5754
  async unlinkAccount(_options) {
5735
5755
  // Unlinking biometric auth means clearing stored credentials
5736
5756
  await this.clearStoredCredentials();
@@ -6007,12 +6027,17 @@ var linkedinProvider = /*#__PURE__*/Object.freeze({
6007
6027
  LinkedInProvider: LinkedInProvider
6008
6028
  });
6009
6029
 
6010
- class UsernamePasswordProvider {
6011
- constructor(config) {
6012
- this.name = 'username-password';
6013
- this.currentUser = null;
6030
+ class UsernamePasswordProvider extends BaseAuthProvider {
6031
+ get name() {
6032
+ return 'username-password';
6033
+ }
6034
+ constructor(input) {
6035
+ super(resolveProviderConfig(AuthProvider.USERNAME_PASSWORD, input));
6036
+ // currentUser is the inherited (in-memory) field from BaseAuthProvider; assigned directly here
6037
+ // so username/password sessions stay in-memory exactly as before (no new storage persistence).
6014
6038
  this.authToken = null;
6015
6039
  this.refreshTokenValue = null;
6040
+ const config = this.options;
6016
6041
  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);
6017
6042
  }
6018
6043
  async signIn(options) {
@@ -6357,12 +6382,7 @@ class UsernamePasswordProvider {
6357
6382
  // Username/Password auth is supported if we have the required config
6358
6383
  return !!this.config.apiUrl;
6359
6384
  }
6360
- async linkAccount(_options) {
6361
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for username/password authentication');
6362
- }
6363
- async unlinkAccount(_options) {
6364
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for username/password authentication');
6365
- }
6385
+ // linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
6366
6386
  async revokeAccess(_token) {
6367
6387
  // For username/password auth, revoking access means signing out
6368
6388
  await this.signOut();
@@ -6374,15 +6394,18 @@ var usernamePasswordProvider = /*#__PURE__*/Object.freeze({
6374
6394
  UsernamePasswordProvider: UsernamePasswordProvider
6375
6395
  });
6376
6396
 
6377
- class EmailCodeProvider {
6378
- constructor(config) {
6379
- this.name = 'email-code';
6397
+ class EmailCodeProvider extends BaseAuthProvider {
6398
+ get name() {
6399
+ return 'email-code';
6400
+ }
6401
+ constructor(input) {
6402
+ super(resolveProviderConfig(AuthProvider.EMAIL_CODE, input));
6380
6403
  // Pending verifications are persisted (SSR-guarded localStorage) so they survive a reload /
6381
6404
  // page change between sending and verifying the code. Only non-secret metadata is stored —
6382
6405
  // never the verification code itself (see PendingVerificationStore + F-11).
6383
6406
  this.pendingVerifications = new PendingVerificationStore('email-code');
6384
6407
  this.MAX_ATTEMPTS = 3;
6385
- this.config = Object.assign({ codeLength: 6, resendDelay: 60000, codeExpiration: 10 * 60 * 1000 }, config);
6408
+ this.config = Object.assign({ codeLength: 6, resendDelay: 60000, codeExpiration: 10 * 60 * 1000 }, this.options);
6386
6409
  }
6387
6410
  async signIn(options) {
6388
6411
  if (!(options === null || options === void 0 ? void 0 : options.email)) {
@@ -6577,12 +6600,7 @@ class EmailCodeProvider {
6577
6600
  async isSupported() {
6578
6601
  return !!(this.config.sendCodeUrl && this.config.verifyCodeUrl);
6579
6602
  }
6580
- async linkAccount(_options) {
6581
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for email code authentication');
6582
- }
6583
- async unlinkAccount(_options) {
6584
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for email code authentication');
6585
- }
6603
+ // linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
6586
6604
  async revokeAccess(_token) {
6587
6605
  this.pendingVerifications.clear();
6588
6606
  }
@@ -6627,11 +6645,15 @@ var emailCodeProvider = /*#__PURE__*/Object.freeze({
6627
6645
  EmailCodeProvider: EmailCodeProvider
6628
6646
  });
6629
6647
 
6630
- class PhonePasswordProvider {
6631
- constructor(config) {
6632
- this.name = 'phone-password';
6648
+ class PhonePasswordProvider extends BaseAuthProvider {
6649
+ get name() {
6650
+ return 'phone-password';
6651
+ }
6652
+ constructor(input) {
6653
+ super(resolveProviderConfig(AuthProvider.PHONE_PASSWORD, input));
6633
6654
  this.pendingVerifications = new Map();
6634
- this.currentUser = null;
6655
+ // currentUser is the inherited (in-memory) field from BaseAuthProvider; assigned directly here
6656
+ // so phone/password sessions stay in-memory exactly as before (no new storage persistence).
6635
6657
  this.storedAccessToken = null;
6636
6658
  this.storedRefreshToken = null;
6637
6659
  this.config = Object.assign({ countryCode: '+1', requirePhoneVerification: false, passwordStrength: {
@@ -6640,7 +6662,7 @@ class PhonePasswordProvider {
6640
6662
  requireLowercase: true,
6641
6663
  requireNumbers: true,
6642
6664
  requireSpecialChars: false,
6643
- } }, config);
6665
+ } }, this.options);
6644
6666
  }
6645
6667
  async signIn(options) {
6646
6668
  const credentials = options === null || options === void 0 ? void 0 : options.credentials;
@@ -6683,7 +6705,7 @@ class PhonePasswordProvider {
6683
6705
  throw new AuthError(AuthErrorCode.SIGN_IN_FAILED, error.message || 'Sign in failed');
6684
6706
  }
6685
6707
  const data = await response.json();
6686
- return this.createAuthResult(data, phoneNumber);
6708
+ return this.buildAuthResult(data, phoneNumber);
6687
6709
  }
6688
6710
  catch (error) {
6689
6711
  if (error instanceof AuthError)
@@ -6747,7 +6769,7 @@ class PhonePasswordProvider {
6747
6769
  },
6748
6770
  };
6749
6771
  }
6750
- return this.createAuthResult(data, phoneNumber, true);
6772
+ return this.buildAuthResult(data, phoneNumber, true);
6751
6773
  }
6752
6774
  catch (error) {
6753
6775
  if (error instanceof AuthError)
@@ -6815,7 +6837,7 @@ class PhonePasswordProvider {
6815
6837
  }
6816
6838
  const data = await response.json();
6817
6839
  this.pendingVerifications.delete(phoneNumber);
6818
- return this.createAuthResult(data, phoneNumber);
6840
+ return this.buildAuthResult(data, phoneNumber);
6819
6841
  }
6820
6842
  catch (error) {
6821
6843
  if (error instanceof AuthError)
@@ -6885,12 +6907,7 @@ class PhonePasswordProvider {
6885
6907
  async isSupported() {
6886
6908
  return !!(this.config.signInUrl && this.config.signUpUrl);
6887
6909
  }
6888
- async linkAccount(_options) {
6889
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for phone/password authentication');
6890
- }
6891
- async unlinkAccount(_options) {
6892
- throw new AuthError(AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for phone/password authentication');
6893
- }
6910
+ // linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
6894
6911
  async revokeAccess(_token) {
6895
6912
  await this.signOut();
6896
6913
  }
@@ -6917,7 +6934,9 @@ class PhonePasswordProvider {
6917
6934
  throw new AuthError(AuthErrorCode.SERVER_ERROR, error.message || 'Failed to send password reset');
6918
6935
  }
6919
6936
  }
6920
- createAuthResult(data, phoneNumber, isNewUser = false) {
6937
+ // Renamed from createAuthResult to avoid colliding with BaseAuthProvider.createAuthResult,
6938
+ // which has a different signature (this builds a phone-specific result from a backend payload).
6939
+ buildAuthResult(data, phoneNumber, isNewUser = false) {
6921
6940
  const user = {
6922
6941
  uid: data.uid || this.generateUid(phoneNumber),
6923
6942
  email: data.email || null,