@rdlabo/ionic-angular-kit 22.0.3 → 22.0.5

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/docs/auth-http.md CHANGED
@@ -45,6 +45,14 @@ export const routes: Routes = [
45
45
 
46
46
  Use `kitRequiredUnauthorizedGuard`, `kitRequireConfirmingGuard`, and `kitRequireAuthorizedGuard` in route definitions. A protected asynchronous decision suspends previously published remote capability until the current authorization lease succeeds.
47
47
 
48
+ ## Share startup login requests
49
+
50
+ `KitAuthLoginExchange<Identity, Result>` shares a pending backend login request. A preloaded result (including failure) can be consumed once by authorization while the originating navigation is current, for up to 30 seconds after completion. Later authorization calls make a fresh request; this is not a permissions cache.
51
+
52
+ Keep one instance in the application authentication service. Capture the Firebase user when constructing the request, reject responses for a replaced user, and call `clear()` on sign-out. Provider eligibility, deletion recovery, terms acceptance, and response handling remain application-owned.
53
+
54
+ For applications that initialize a local runtime before authorization, call `kitPreloadAuthLoginForNavigation(router, isCurrent => auth.preloadTokenLogin(isCurrent))` after Firebase readiness and required account recovery, before awaiting runtime initialization. Invoke its returned cleanup if initialization fails. It discards unconsumed work when that navigation ends or is canceled. Applications without useful startup work to overlap can use `run(identity, request)` alone.
55
+
48
56
  ## HTTP policy
49
57
 
50
58
  `provideKitHttp()` configures `kitAuthInterceptor` for credential injection, bypass rules, transient failure handling, and application error hooks. Register the interceptor separately with `provideHttpClient`. Only `getAuthHeaders` is required; every other hook is optional and application-owned.
@@ -10,8 +10,8 @@ import { Keyboard } from '@capacitor/keyboard';
10
10
  import { ImpactStyle, Haptics } from '@capacitor/haptics';
11
11
  import { LoadingController } from '@ionic/angular/loading-controller';
12
12
  import { FORM_FIELD } from '@angular/forms/signals';
13
- import { BehaviorSubject, Subscription, throwError, of, from, retry, timer, Subject, Observable, startWith } from 'rxjs';
14
- import { Router } from '@angular/router';
13
+ import { BehaviorSubject, Subscription, throwError, of, filter, take, from, retry, timer, Subject, Observable, startWith } from 'rxjs';
14
+ import { Router, NavigationEnd, NavigationCancel, NavigationError } from '@angular/router';
15
15
  import { NavController } from '@ionic/angular/common';
16
16
  import { catchError, map, mergeMap, timeout, tap } from 'rxjs/operators';
17
17
  import { HttpContextToken, HttpErrorResponse, HttpResponse } from '@angular/common/http';
@@ -1691,6 +1691,71 @@ function isRemoteAccessActivation(value) {
1691
1691
  typeof value.resume === 'function');
1692
1692
  }
1693
1693
 
1694
+ /** Shares an in-flight login and hands its startup result to authorization exactly once. */
1695
+ class KitAuthLoginExchange {
1696
+ #startedFor;
1697
+ #exchange = null;
1698
+ /** Start once per signed-in identity; discard an unconsumed result when its navigation ends. */
1699
+ preload(identity, request, isCurrent) {
1700
+ if (this.#startedFor === identity)
1701
+ return undefined;
1702
+ const exchange = this.#start(identity, request, isCurrent);
1703
+ void exchange.promise.catch(() => undefined);
1704
+ return () => {
1705
+ if (this.#exchange === exchange)
1706
+ this.clear();
1707
+ };
1708
+ }
1709
+ /** Consume a current startup result, share pending work, or perform a fresh login. */
1710
+ run(identity, request) {
1711
+ const exchange = this.#exchange;
1712
+ if (exchange &&
1713
+ exchange.identity === identity &&
1714
+ (!exchange.handoff || (exchange.handoff() && (exchange.settledAt === null || Date.now() - exchange.settledAt < 30_000)))) {
1715
+ exchange.handoff = null;
1716
+ if (exchange.settledAt !== null)
1717
+ this.#exchange = null;
1718
+ return exchange.promise;
1719
+ }
1720
+ return this.#start(identity, request, null).promise;
1721
+ }
1722
+ /** Forget startup state on sign-out; a later sign-in may preload again. */
1723
+ clear() {
1724
+ this.#exchange = null;
1725
+ this.#startedFor = undefined;
1726
+ }
1727
+ #start(identity, request, handoff) {
1728
+ const exchange = {
1729
+ identity,
1730
+ handoff,
1731
+ settledAt: null,
1732
+ promise: request().finally(() => {
1733
+ exchange.settledAt = Date.now();
1734
+ if (!exchange.handoff && this.#exchange === exchange)
1735
+ this.#exchange = null;
1736
+ }),
1737
+ };
1738
+ this.#startedFor = identity;
1739
+ this.#exchange = exchange;
1740
+ return exchange;
1741
+ }
1742
+ }
1743
+ /** Bind an optional login preload to the active navigation and return cleanup for initialization failure. */
1744
+ function kitPreloadAuthLoginForNavigation(router, preload) {
1745
+ const navigation = router.currentNavigation();
1746
+ const cancel = navigation ? preload(() => router.currentNavigation() === navigation) : undefined;
1747
+ const subscription = cancel
1748
+ ? router.events
1749
+ .pipe(filter((event) => (event instanceof NavigationEnd || event instanceof NavigationCancel || event instanceof NavigationError) &&
1750
+ event.id === navigation?.id), take(1))
1751
+ .subscribe(() => cancel())
1752
+ : undefined;
1753
+ return () => {
1754
+ subscription?.unsubscribe();
1755
+ cancel?.();
1756
+ };
1757
+ }
1758
+
1694
1759
  /**
1695
1760
  * Marks the narrowly scoped credential-exchange request that establishes remote access.
1696
1761
  *
@@ -2770,5 +2835,5 @@ function mountViewModel(host, onMount) {
2770
2835
  * Generated bundle index. Do not edit.
2771
2836
  */
2772
2837
 
2773
- export { AUTH_FAILURE_SCOPES, AUTH_IDENTITY_INVALID_CODE, KIT_AUTH_BOOTSTRAP_REQUEST, KIT_AUTH_CONFIG, KIT_AUTH_RECOVERY_CONFIG, KIT_HTTP_CONFIG, KIT_LAST_AUTH_EMAIL_KEY, KIT_OVERLAY_CONFIG, KIT_REALTIME_CLIENT_ID, KIT_THEME_STORAGE_KEY, KitAuthAccessService, KitAuthInputDirective, KitAuthRecoveryService, KitLoadingController, KitMaintenanceController, KitOverlayController, KitRealtimeConnection, KitRealtimeLivenessWatchdog, KitReloadAlertController, KitStorageService, arrayConcatById, disableHandler, getAuthFailureScope, isExplicitAuthDenial, isIdentityAuthFailure, isMaintenanceError, kitAuthInterceptor, kitChangeEventDisabled, kitClearStoragePreservingKeys, kitCreateDidEnter, kitForgetEmail, kitImpact, kitIsValidEmail, kitKeyboardInit, kitPresentAuthFailedAlert, kitPresentLanguageActionSheet, kitRealtimeProtocols, kitRecallEmail, kitRememberEmail, kitRequireAuthorizedGuard, kitRequireConfirmingGuard, kitRequiredUnauthorizedGuard, mountViewModel, objectEqual, provideKitAuth, provideKitHttp, provideKitOverlay, toKitWebSocketUrl };
2838
+ export { AUTH_FAILURE_SCOPES, AUTH_IDENTITY_INVALID_CODE, KIT_AUTH_BOOTSTRAP_REQUEST, KIT_AUTH_CONFIG, KIT_AUTH_RECOVERY_CONFIG, KIT_HTTP_CONFIG, KIT_LAST_AUTH_EMAIL_KEY, KIT_OVERLAY_CONFIG, KIT_REALTIME_CLIENT_ID, KIT_THEME_STORAGE_KEY, KitAuthAccessService, KitAuthInputDirective, KitAuthLoginExchange, KitAuthRecoveryService, KitLoadingController, KitMaintenanceController, KitOverlayController, KitRealtimeConnection, KitRealtimeLivenessWatchdog, KitReloadAlertController, KitStorageService, arrayConcatById, disableHandler, getAuthFailureScope, isExplicitAuthDenial, isIdentityAuthFailure, isMaintenanceError, kitAuthInterceptor, kitChangeEventDisabled, kitClearStoragePreservingKeys, kitCreateDidEnter, kitForgetEmail, kitImpact, kitIsValidEmail, kitKeyboardInit, kitPreloadAuthLoginForNavigation, kitPresentAuthFailedAlert, kitPresentLanguageActionSheet, kitRealtimeProtocols, kitRecallEmail, kitRememberEmail, kitRequireAuthorizedGuard, kitRequireConfirmingGuard, kitRequiredUnauthorizedGuard, mountViewModel, objectEqual, provideKitAuth, provideKitHttp, provideKitOverlay, toKitWebSocketUrl };
2774
2839
  //# sourceMappingURL=rdlabo-ionic-angular-kit.mjs.map