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
@@ -1899,6 +1899,31 @@ const CapacitorAuthManager = core.registerPlugin('CapacitorAuthManager', {
1899
1899
  web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.CapacitorAuthManagerWeb()),
1900
1900
  });
1901
1901
 
1902
+ /**
1903
+ * Normalize a provider constructor argument into a full {@link BaseProviderConfig}.
1904
+ *
1905
+ * The standalone providers are public (exported from `capacitor-auth-manager/providers/web`) and
1906
+ * get constructed two ways: the factory/registry pass a full {@link BaseProviderConfig}, while
1907
+ * tests and direct consumers pass the provider's own bare options object. This helper accepts
1908
+ * either — a bare object is wrapped with an in-memory storage (`AuthPersistence.NONE`, so it never
1909
+ * touches `window` and stays safe under SSR / Node test environments) plus the shared
1910
+ * {@link defaultLogger}. Callers that pass a full config keep their injected storage/logger.
1911
+ */
1912
+ function resolveProviderConfig(provider, input) {
1913
+ if (typeof input === 'object' &&
1914
+ input !== null &&
1915
+ 'storage' in input &&
1916
+ 'logger' in input &&
1917
+ 'options' in input) {
1918
+ return input;
1919
+ }
1920
+ return {
1921
+ provider,
1922
+ options: (input !== null && input !== void 0 ? input : {}),
1923
+ storage: new WebStorage(exports.AuthPersistence.NONE),
1924
+ logger: defaultLogger,
1925
+ };
1926
+ }
1902
1927
  class BaseAuthProvider {
1903
1928
  get name() {
1904
1929
  return this.provider;
@@ -1918,13 +1943,13 @@ class BaseAuthProvider {
1918
1943
  // across every provider (see AuthProviderInterface, where they are optional). Marking them
1919
1944
  // abstract previously forced every subclass to re-implement them just to throw.
1920
1945
  async linkAccount(_options) {
1921
- throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, `Provider ${this.provider} does not support account linking`, this.provider);
1946
+ throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, `Account linking is not supported by provider ${this.provider}`, this.provider);
1922
1947
  }
1923
1948
  async unlinkAccount(_options) {
1924
- throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, `Provider ${this.provider} does not support account unlinking`, this.provider);
1949
+ throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, `Account unlinking is not supported by provider ${this.provider}`, this.provider);
1925
1950
  }
1926
1951
  async revokeAccess(_token) {
1927
- throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, `Provider ${this.provider} does not support access revocation`, this.provider);
1952
+ throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, `Access revocation is not supported by provider ${this.provider}`, this.provider);
1928
1953
  }
1929
1954
  async getCurrentUser() {
1930
1955
  if (!this.isInitialized) {
@@ -4239,16 +4264,19 @@ class PendingVerificationStore {
4239
4264
  }
4240
4265
  }
4241
4266
 
4242
- class MagicLinkProvider {
4243
- constructor(config) {
4244
- this.name = 'magic-link';
4267
+ class MagicLinkProvider extends BaseAuthProvider {
4268
+ get name() {
4269
+ return 'magic-link';
4270
+ }
4271
+ constructor(input) {
4272
+ super(resolveProviderConfig(exports.AuthProvider.EMAIL_MAGIC_LINK, input));
4245
4273
  // Persisted (SSR-guarded localStorage) so a magic link clicked from an email — which opens a
4246
4274
  // FRESH page load with empty in-memory state — can still find its pending entry to verify
4247
4275
  // against. Keyed by the link token (already present in the callback URL); we store only the
4248
4276
  // email + expiry, never any additional secret (see PendingVerificationStore + F-11).
4249
4277
  this.pendingVerification = new PendingVerificationStore('magic-link');
4250
- // Initialize with config
4251
- this.config = config;
4278
+ // Magic link uses its config as-is (no defaults to merge).
4279
+ this.config = this.options;
4252
4280
  // Check for magic link callback on initialization
4253
4281
  this.checkForMagicLinkCallback();
4254
4282
  }
@@ -4498,14 +4526,9 @@ class MagicLinkProvider {
4498
4526
  // Magic link auth is supported if we have the required config
4499
4527
  return !!this.config.sendLinkUrl;
4500
4528
  }
4501
- async linkAccount(_options) {
4502
- throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for magic link authentication');
4503
- }
4504
- async unlinkAccount(_options) {
4505
- throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for magic link authentication');
4506
- }
4529
+ // linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
4507
4530
  async revokeAccess(_token) {
4508
- // Magic link doesn't have persistent access to revoke
4531
+ // Magic link doesn't have persistent access to revoke; clear any pending verification.
4509
4532
  this.pendingVerification.clear();
4510
4533
  }
4511
4534
  }
@@ -4515,16 +4538,18 @@ var magicLinkProvider = /*#__PURE__*/Object.freeze({
4515
4538
  MagicLinkProvider: MagicLinkProvider
4516
4539
  });
4517
4540
 
4518
- class SMSProvider {
4519
- constructor(config) {
4520
- this.name = 'sms';
4541
+ class SMSProvider extends BaseAuthProvider {
4542
+ get name() {
4543
+ return 'sms';
4544
+ }
4545
+ constructor(input) {
4546
+ super(resolveProviderConfig(exports.AuthProvider.SMS, input));
4521
4547
  // Pending verifications are persisted (SSR-guarded localStorage) so they survive a reload /
4522
4548
  // page change between sending and verifying the code. Only non-secret metadata is stored —
4523
4549
  // never the SMS code itself (see PendingVerificationStore + F-11).
4524
4550
  this.pendingVerifications = new PendingVerificationStore('sms');
4525
4551
  this.MAX_ATTEMPTS = 3;
4526
- // Initialize with config
4527
- this.config = Object.assign({ countryCode: '+1', codeLength: 6, resendDelay: 60000 }, config);
4552
+ this.config = Object.assign({ countryCode: '+1', codeLength: 6, resendDelay: 60000 }, this.options);
4528
4553
  }
4529
4554
  async signIn(options) {
4530
4555
  if (!(options === null || options === void 0 ? void 0 : options.phoneNumber)) {
@@ -4762,14 +4787,9 @@ class SMSProvider {
4762
4787
  // SMS auth is supported if we have the required config
4763
4788
  return !!(this.config.sendCodeUrl && this.config.verifyCodeUrl);
4764
4789
  }
4765
- async linkAccount(_options) {
4766
- throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for SMS authentication');
4767
- }
4768
- async unlinkAccount(_options) {
4769
- throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for SMS authentication');
4770
- }
4790
+ // linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
4771
4791
  async revokeAccess(_token) {
4772
- // SMS auth doesn't have persistent access to revoke
4792
+ // SMS auth doesn't have persistent access to revoke; clear any pending verification.
4773
4793
  this.pendingVerifications.clear();
4774
4794
  }
4775
4795
  }
@@ -4779,20 +4799,23 @@ var smsProvider = /*#__PURE__*/Object.freeze({
4779
4799
  SMSProvider: SMSProvider
4780
4800
  });
4781
4801
 
4782
- class EmailPasswordProvider {
4783
- constructor(config) {
4784
- this.name = 'email-password';
4785
- this.currentUser = null;
4802
+ class EmailPasswordProvider extends BaseAuthProvider {
4803
+ get name() {
4804
+ return 'email-password';
4805
+ }
4806
+ constructor(input) {
4807
+ super(resolveProviderConfig(exports.AuthProvider.EMAIL_PASSWORD, input));
4808
+ // currentUser is the inherited (in-memory) field from BaseAuthProvider; assigned directly here
4809
+ // so email/password sessions stay in-memory exactly as before (no new storage persistence).
4786
4810
  this.authToken = null;
4787
4811
  this.refreshTokenValue = null;
4788
- // Initialize with config
4789
4812
  this.config = Object.assign({ allowSignUp: true, passwordRequirements: {
4790
4813
  minLength: 8,
4791
4814
  requireUppercase: true,
4792
4815
  requireLowercase: true,
4793
4816
  requireNumbers: true,
4794
4817
  requireSpecialChars: false,
4795
- } }, config);
4818
+ } }, this.options);
4796
4819
  }
4797
4820
  async signIn(options) {
4798
4821
  if (!(options === null || options === void 0 ? void 0 : options.email) || !(options === null || options === void 0 ? void 0 : options.password)) {
@@ -5138,12 +5161,7 @@ class EmailPasswordProvider {
5138
5161
  // Email/Password auth is supported if we have the required config
5139
5162
  return !!this.config.apiUrl;
5140
5163
  }
5141
- async linkAccount(_options) {
5142
- throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for email/password authentication');
5143
- }
5144
- async unlinkAccount(_options) {
5145
- throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for email/password authentication');
5146
- }
5164
+ // linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
5147
5165
  async revokeAccess(_token) {
5148
5166
  // For email/password auth, revoking access means signing out
5149
5167
  await this.signOut();
@@ -5155,11 +5173,15 @@ var emailPasswordProvider = /*#__PURE__*/Object.freeze({
5155
5173
  EmailPasswordProvider: EmailPasswordProvider
5156
5174
  });
5157
5175
 
5158
- class BiometricProvider {
5159
- constructor(config = {}) {
5160
- this.name = 'biometric';
5176
+ class BiometricProvider extends BaseAuthProvider {
5177
+ get name() {
5178
+ return 'biometric';
5179
+ }
5180
+ constructor(input = {}) {
5181
+ super(resolveProviderConfig(exports.AuthProvider.BIOMETRIC, input));
5161
5182
  this.biometricAuth = null;
5162
5183
  this.cryptoKeyPromise = null;
5184
+ const config = this.options;
5163
5185
  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);
5164
5186
  this.storageKey =
5165
5187
  config.storageKey || 'capacitor-auth-biometric-credentials';
@@ -5443,9 +5465,7 @@ class BiometricProvider {
5443
5465
  const result = await this.isAvailable();
5444
5466
  return result.available;
5445
5467
  }
5446
- async linkAccount(_options) {
5447
- throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for biometric authentication');
5448
- }
5468
+ // linkAccount inherits BaseAuthProvider's OPERATION_NOT_ALLOWED default (F-44).
5449
5469
  async unlinkAccount(_options) {
5450
5470
  // Unlinking biometric auth means clearing stored credentials
5451
5471
  await this.clearStoredCredentials();
@@ -5722,12 +5742,17 @@ var linkedinProvider = /*#__PURE__*/Object.freeze({
5722
5742
  LinkedInProvider: LinkedInProvider
5723
5743
  });
5724
5744
 
5725
- class UsernamePasswordProvider {
5726
- constructor(config) {
5727
- this.name = 'username-password';
5728
- this.currentUser = null;
5745
+ class UsernamePasswordProvider extends BaseAuthProvider {
5746
+ get name() {
5747
+ return 'username-password';
5748
+ }
5749
+ constructor(input) {
5750
+ super(resolveProviderConfig(exports.AuthProvider.USERNAME_PASSWORD, input));
5751
+ // currentUser is the inherited (in-memory) field from BaseAuthProvider; assigned directly here
5752
+ // so username/password sessions stay in-memory exactly as before (no new storage persistence).
5729
5753
  this.authToken = null;
5730
5754
  this.refreshTokenValue = null;
5755
+ const config = this.options;
5731
5756
  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);
5732
5757
  }
5733
5758
  async signIn(options) {
@@ -6072,12 +6097,7 @@ class UsernamePasswordProvider {
6072
6097
  // Username/Password auth is supported if we have the required config
6073
6098
  return !!this.config.apiUrl;
6074
6099
  }
6075
- async linkAccount(_options) {
6076
- throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for username/password authentication');
6077
- }
6078
- async unlinkAccount(_options) {
6079
- throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for username/password authentication');
6080
- }
6100
+ // linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
6081
6101
  async revokeAccess(_token) {
6082
6102
  // For username/password auth, revoking access means signing out
6083
6103
  await this.signOut();
@@ -6089,15 +6109,18 @@ var usernamePasswordProvider = /*#__PURE__*/Object.freeze({
6089
6109
  UsernamePasswordProvider: UsernamePasswordProvider
6090
6110
  });
6091
6111
 
6092
- class EmailCodeProvider {
6093
- constructor(config) {
6094
- this.name = 'email-code';
6112
+ class EmailCodeProvider extends BaseAuthProvider {
6113
+ get name() {
6114
+ return 'email-code';
6115
+ }
6116
+ constructor(input) {
6117
+ super(resolveProviderConfig(exports.AuthProvider.EMAIL_CODE, input));
6095
6118
  // Pending verifications are persisted (SSR-guarded localStorage) so they survive a reload /
6096
6119
  // page change between sending and verifying the code. Only non-secret metadata is stored —
6097
6120
  // never the verification code itself (see PendingVerificationStore + F-11).
6098
6121
  this.pendingVerifications = new PendingVerificationStore('email-code');
6099
6122
  this.MAX_ATTEMPTS = 3;
6100
- this.config = Object.assign({ codeLength: 6, resendDelay: 60000, codeExpiration: 10 * 60 * 1000 }, config);
6123
+ this.config = Object.assign({ codeLength: 6, resendDelay: 60000, codeExpiration: 10 * 60 * 1000 }, this.options);
6101
6124
  }
6102
6125
  async signIn(options) {
6103
6126
  if (!(options === null || options === void 0 ? void 0 : options.email)) {
@@ -6292,12 +6315,7 @@ class EmailCodeProvider {
6292
6315
  async isSupported() {
6293
6316
  return !!(this.config.sendCodeUrl && this.config.verifyCodeUrl);
6294
6317
  }
6295
- async linkAccount(_options) {
6296
- throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for email code authentication');
6297
- }
6298
- async unlinkAccount(_options) {
6299
- throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for email code authentication');
6300
- }
6318
+ // linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
6301
6319
  async revokeAccess(_token) {
6302
6320
  this.pendingVerifications.clear();
6303
6321
  }
@@ -6342,11 +6360,15 @@ var emailCodeProvider = /*#__PURE__*/Object.freeze({
6342
6360
  EmailCodeProvider: EmailCodeProvider
6343
6361
  });
6344
6362
 
6345
- class PhonePasswordProvider {
6346
- constructor(config) {
6347
- this.name = 'phone-password';
6363
+ class PhonePasswordProvider extends BaseAuthProvider {
6364
+ get name() {
6365
+ return 'phone-password';
6366
+ }
6367
+ constructor(input) {
6368
+ super(resolveProviderConfig(exports.AuthProvider.PHONE_PASSWORD, input));
6348
6369
  this.pendingVerifications = new Map();
6349
- this.currentUser = null;
6370
+ // currentUser is the inherited (in-memory) field from BaseAuthProvider; assigned directly here
6371
+ // so phone/password sessions stay in-memory exactly as before (no new storage persistence).
6350
6372
  this.storedAccessToken = null;
6351
6373
  this.storedRefreshToken = null;
6352
6374
  this.config = Object.assign({ countryCode: '+1', requirePhoneVerification: false, passwordStrength: {
@@ -6355,7 +6377,7 @@ class PhonePasswordProvider {
6355
6377
  requireLowercase: true,
6356
6378
  requireNumbers: true,
6357
6379
  requireSpecialChars: false,
6358
- } }, config);
6380
+ } }, this.options);
6359
6381
  }
6360
6382
  async signIn(options) {
6361
6383
  const credentials = options === null || options === void 0 ? void 0 : options.credentials;
@@ -6398,7 +6420,7 @@ class PhonePasswordProvider {
6398
6420
  throw new AuthError(exports.AuthErrorCode.SIGN_IN_FAILED, error.message || 'Sign in failed');
6399
6421
  }
6400
6422
  const data = await response.json();
6401
- return this.createAuthResult(data, phoneNumber);
6423
+ return this.buildAuthResult(data, phoneNumber);
6402
6424
  }
6403
6425
  catch (error) {
6404
6426
  if (error instanceof AuthError)
@@ -6462,7 +6484,7 @@ class PhonePasswordProvider {
6462
6484
  },
6463
6485
  };
6464
6486
  }
6465
- return this.createAuthResult(data, phoneNumber, true);
6487
+ return this.buildAuthResult(data, phoneNumber, true);
6466
6488
  }
6467
6489
  catch (error) {
6468
6490
  if (error instanceof AuthError)
@@ -6530,7 +6552,7 @@ class PhonePasswordProvider {
6530
6552
  }
6531
6553
  const data = await response.json();
6532
6554
  this.pendingVerifications.delete(phoneNumber);
6533
- return this.createAuthResult(data, phoneNumber);
6555
+ return this.buildAuthResult(data, phoneNumber);
6534
6556
  }
6535
6557
  catch (error) {
6536
6558
  if (error instanceof AuthError)
@@ -6600,12 +6622,7 @@ class PhonePasswordProvider {
6600
6622
  async isSupported() {
6601
6623
  return !!(this.config.signInUrl && this.config.signUpUrl);
6602
6624
  }
6603
- async linkAccount(_options) {
6604
- throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account linking is not supported for phone/password authentication');
6605
- }
6606
- async unlinkAccount(_options) {
6607
- throw new AuthError(exports.AuthErrorCode.OPERATION_NOT_ALLOWED, 'Account unlinking is not supported for phone/password authentication');
6608
- }
6625
+ // linkAccount + unlinkAccount inherit BaseAuthProvider's OPERATION_NOT_ALLOWED defaults (F-44).
6609
6626
  async revokeAccess(_token) {
6610
6627
  await this.signOut();
6611
6628
  }
@@ -6632,7 +6649,9 @@ class PhonePasswordProvider {
6632
6649
  throw new AuthError(exports.AuthErrorCode.SERVER_ERROR, error.message || 'Failed to send password reset');
6633
6650
  }
6634
6651
  }
6635
- createAuthResult(data, phoneNumber, isNewUser = false) {
6652
+ // Renamed from createAuthResult to avoid colliding with BaseAuthProvider.createAuthResult,
6653
+ // which has a different signature (this builds a phone-specific result from a backend payload).
6654
+ buildAuthResult(data, phoneNumber, isNewUser = false) {
6636
6655
  const user = {
6637
6656
  uid: data.uid || this.generateUid(phoneNumber),
6638
6657
  email: data.email || null,