analytica-frontend-lib
Version:
Repositório público dos componentes utilizados nas plataformas da Analytica Ensino
80 lines • 4.19 kB
TypeScript
/**
* Resolves the root hostname shared by all application subdomains.
* Mirrors the subdomain rules used by `getRootDomain` (Auth), without
* protocol or port. Useful for the cookie `Domain` attribute so that a
* cookie set on a subdomain is visible on the root domain and vice versa.
*
* @param hostname - The hostname to resolve (e.g. window.location.hostname)
* @returns The root hostname, or null for localhost / IP literals
* (callers should omit the cookie Domain attribute in that case)
*
* @example
* ```typescript
* resolveRootHostname('aluno.analyticaensino.com.br'); // 'analyticaensino.com.br'
* resolveRootHostname('aluno.hml.analyticaensino.com.br'); // 'hml.analyticaensino.com.br'
* resolveRootHostname('sub.example.com'); // 'example.com'
* resolveRootHostname('localhost'); // null
* resolveRootHostname('127.0.0.1'); // null
* ```
*/
export declare const resolveRootHostname: (hostname: string) => string | null;
/**
* Extracts the profile "slug" from a hostname's leading subdomain label,
* stripping the homolog prefix so it matches the bare profile name the backend
* returns (e.g. "aluno"). Used to compare the profile a shared link belongs to
* against the profile the user actually logged in as.
*
* @param hostname - The hostname to read (e.g. window.location.hostname)
* @returns The profile slug, or null for localhost / IP literals / hosts with
* no subdomain (a root-level host carries no profile identity)
*
* @example
* ```typescript
* extractSubdomainSlug('aluno.analyticaensino.com.br'); // 'aluno'
* extractSubdomainSlug('hml-aluno.hml.analyticaensino.com.br'); // 'aluno'
* extractSubdomainSlug('analyticaensino.com.br'); // null (no subdomain)
* extractSubdomainSlug('localhost'); // null
* ```
*/
export declare const extractSubdomainSlug: (hostname: string) => string | null;
/**
* Builds the login URL (root domain) with the current deep link preserved as a
* `returnTo` query param, so that after the user logs in they can be sent back
* to the page they originally tried to open.
*
* Deliberately a no-op in two cases, returning the bare `rootDomain`:
* - **localhost / IP literals**: the deep-link-return flow is skipped entirely
* in local development (no subdomain to validate against).
* - **no meaningful path**: the user was at the root already, so there is
* nothing worth remembering.
*
* The stored value is the full current URL (origin + path + query). The login
* app later validates that its host's profile matches the logged-in profile
* before honoring it, and only ever reuses the path — never the host — so a
* crafted `returnTo` cannot redirect to a foreign origin.
*
* Also a no-op right after an explicit logout (see `markExplicitLogout`): a
* user who chose to sign out should never be bounced back to the page they were
* on, and clearing the session synchronously can make ProtectedRoute redirect
* through here before the app's own clean logout navigation completes.
*
* @param rootDomain - The login/root domain to redirect to (from getRootDomain)
* @returns `rootDomain` with `?returnTo=<encoded current URL>` appended, or the
* bare `rootDomain` when the flow should be skipped
*/
export declare const buildLoginUrlWithReturnTo: (rootDomain: string) => string;
/**
* Marks that the user is intentionally logging out, so redirects to login
* during the logout do NOT preserve a `returnTo` deep link. Call this right
* before clearing the session in an explicit "Sair" handler.
*
* Stored as a timestamp (not a one-shot flag) because a single logout can
* trigger MORE THAN ONE redirect through buildLoginUrlWithReturnTo — e.g. the
* ProtectedRoute re-render after signOut() AND the 401 interceptor firing on an
* in-flight request whose token was just cleared. A one-shot flag would be
* eaten by the first redirect, letting the second re-append returnTo. A
* time-boxed marker covers every redirect in the logout window and then expires
* on its own, so it never suppresses a later, genuine session-expiry redirect.
*/
export declare const markExplicitLogout: () => void;
//# sourceMappingURL=domainUtils.d.ts.map