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