@rdlabo/ionic-angular-kit 21.5.1 → 21.5.3

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.
@@ -1861,10 +1861,10 @@ const dispatchError = (config, req, error) => {
1861
1861
  const retryAfterMs = parseRetryAfterMs(error);
1862
1862
  const retryAfterSeconds = retryAfterMs === null ? undefined : Math.round(retryAfterMs / 1000);
1863
1863
  if (status === 401) {
1864
- config.onUnauthorized?.(req);
1864
+ config.onUnauthorized?.(req, error);
1865
1865
  }
1866
1866
  else if (status === 403) {
1867
- config.onForbidden?.(req);
1867
+ config.onForbidden?.(req, error);
1868
1868
  }
1869
1869
  else if (status === 0) {
1870
1870
  // Genuine network/transport failure. Only surface it when the device is actually connected
@@ -1945,6 +1945,7 @@ const kitAuthInterceptor = (request, next) => {
1945
1945
  // getAuthHeaders failed → the request is never sent; classify it instead of failing silently.
1946
1946
  if (config.enforceAuthAccessMode && isExplicitAuthDenial(headerError) && shouldRevokeAuthAccess(config, request, headerError)) {
1947
1947
  access.clear();
1948
+ config.onAuthAccessDenial?.(request, headerError);
1948
1949
  }
1949
1950
  config.onAuthError?.(request, headerError);
1950
1951
  return throwError(() => headerError);
@@ -1984,8 +1985,10 @@ const kitAuthInterceptor = (request, next) => {
1984
1985
  }
1985
1986
  }), catchError((error) => {
1986
1987
  if (config.enforceAuthAccessMode && isExplicitAuthDenial(error)) {
1987
- if (shouldRevokeAuthAccess(config, req, error))
1988
+ if (shouldRevokeAuthAccess(config, req, error)) {
1988
1989
  access.clear();
1990
+ config.onAuthAccessDenial?.(req, error);
1991
+ }
1989
1992
  dispatchError(config, req, error);
1990
1993
  return throwError(() => error);
1991
1994
  }
@@ -2001,6 +2004,47 @@ const kitAuthInterceptor = (request, next) => {
2001
2004
  }));
2002
2005
  };
2003
2006
 
2007
+ /**
2008
+ * Shared lifecycle boundary carried by an authentication failure response.
2009
+ *
2010
+ * Only `identity` invalidates the application's global authenticated identity.
2011
+ * The other scopes retain it and let the owning feature handle recovery.
2012
+ */
2013
+ const AUTH_FAILURE_SCOPES = {
2014
+ identity: 'identity',
2015
+ reauthentication: 'reauthentication',
2016
+ credential: 'credential',
2017
+ };
2018
+ const AUTH_IDENTITY_INVALID_CODE = 'AUTH_IDENTITY_INVALID';
2019
+ const isRecord = (value) => typeof value === 'object' && value !== null;
2020
+ const isAuthFailureScope = (value) => Object.values(AUTH_FAILURE_SCOPES).some((scope) => scope === value);
2021
+ /**
2022
+ * Reads the explicit auth-failure scope from an Angular `HttpErrorResponse` or
2023
+ * from a body-like value. Tagged historical 403 identity responses are
2024
+ * supported for installed-client compatibility. Untagged 401/403 responses
2025
+ * intentionally return `null`.
2026
+ */
2027
+ const getAuthFailureScope = (error) => {
2028
+ if (!isRecord(error))
2029
+ return null;
2030
+ const body = isRecord(error['error']) ? error['error'] : error;
2031
+ const status = typeof error['status'] === 'number' ? error['status'] : body['statusCode'];
2032
+ if (status !== 401 && status !== 403)
2033
+ return null;
2034
+ if (body['statusCode'] !== status || typeof body['code'] !== 'string')
2035
+ return null;
2036
+ const scope = body['authFailureScope'];
2037
+ if (!isAuthFailureScope(scope))
2038
+ return null;
2039
+ if (status === 403 && scope !== AUTH_FAILURE_SCOPES.identity)
2040
+ return null;
2041
+ if (scope === AUTH_FAILURE_SCOPES.identity && body['code'] !== AUTH_IDENTITY_INVALID_CODE)
2042
+ return null;
2043
+ return scope;
2044
+ };
2045
+ /** True only for an explicitly tagged global identity failure. */
2046
+ const isIdentityAuthFailure = (error) => getAuthFailureScope(error) === AUTH_FAILURE_SCOPES.identity;
2047
+
2004
2048
  /** Stable per-tab/application-run ID shared by realtime connections and write headers. */
2005
2049
  const KIT_REALTIME_CLIENT_ID = crypto.randomUUID();
2006
2050
  /** Convert an HTTP(S) endpoint to its WebSocket equivalent. */
@@ -2722,5 +2766,5 @@ function mountViewModel(host, onMount) {
2722
2766
  * Generated bundle index. Do not edit.
2723
2767
  */
2724
2768
 
2725
- export { 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, isExplicitAuthDenial, isMaintenanceError, kitAuthInterceptor, kitChangeEventDisabled, kitClearStoragePreservingKeys, kitCreateDidEnter, kitForgetEmail, kitImpact, kitIsValidEmail, kitKeyboardInit, kitPresentAuthFailedAlert, kitPresentLanguageActionSheet, kitRealtimeProtocols, kitRecallEmail, kitRememberEmail, kitRequireAuthorizedGuard, kitRequireConfirmingGuard, kitRequiredUnauthorizedGuard, mountViewModel, objectEqual, provideKitAuth, provideKitHttp, provideKitOverlay, toKitWebSocketUrl };
2769
+ 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 };
2726
2770
  //# sourceMappingURL=rdlabo-ionic-angular-kit.mjs.map