import { ConsentState, IdentityPayload, PartnerSessionData } from '../models/types'; import { isTokenExpired } from '../utils/token'; /** * Thrown when the partner session is blocked because the doctor profile is * incomplete (server `422 PROFILE_INCOMPLETE`). Carries the missing field names * so the host page can react via the `eoBlocked` event. */ export declare class ProfileIncompleteError extends Error { readonly missing: string[]; constructor(missing: string[]); } export declare class AuthService { private apiUrl; private apiKey; private token; private sessionId; private identity; /** * Consent state from the last session response. Deliberately NOT cleared by * clearToken(): the state belongs to the doctor + terms version, not the * token, so reopening the drawer in the same page keeps gating until a new * session response (or markConsentAccepted) says otherwise. */ private consent; /** Shared promise while an auth round-trip is in flight — prevents duplicate session calls on concurrent callers. */ private inFlightAuth; constructor(apiUrl: string, apiKey: string); static isTokenExpired: typeof isTokenExpired; /** * Static pure method (Functional Core) — normalizes the optional `consent` * field of the session response. Absent or malformed (old server without * consent support) ⇒ `{ required: false }`, so the widget keeps working * against servers that predate the consent feature. */ static normalizeConsent(raw: unknown): ConsentState; /** Set the identity the next auth round-trip will use (doctor data or a partner token). */ setIdentity(identity: IdentityPayload): void; /** * Resolve a partner session in a single call to `POST /partner/session`. The * server resolves the identity (client-provided or via the partner gateway), * upserts the doctor, and returns a session JWT. The legacy `/partner/register` * step is folded in server-side. * * @throws ProfileIncompleteError on `422` (blocked — doctor must finish registration) * @throws Error on any other non-ok response */ createSession(payload: IdentityPayload): Promise; ensureValidToken(): Promise; private doAuth; getToken(): string | null; getSessionId(): string | null; /** Consent state from the last session response ({ required: false } before any). */ getConsent(): ConsentState; /** * Marks consent as satisfied in memory after a successful * `POST /partner/consent` — the session is NOT re-resolved (spec §2.3). */ markConsentAccepted(): void; /** * Flips consent back to required — used when chat enforcement reveals stale * local state (403 CONSENT_REQUIRED, spec §2.5), so the cached-token reopen * path keeps gating consistently with the server. */ markConsentRequired(): void; /** * Clears the cached token and session id. Next call to `ensureValidToken` * will re-resolve the session. Used by: * - the `newSession` prop / "Nova conversa" button * - silent re-auth on 401 responses from the chat endpoint */ clearToken(): void; }