@djangocfg/api 2.1.618 → 2.1.621

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/dist/auth.d.cts CHANGED
@@ -17,6 +17,48 @@ declare const AUTH_CONSTANTS: {
17
17
  readonly RESEND_COOLDOWN_SECONDS: 30;
18
18
  };
19
19
 
20
+ /**
21
+ * Auth trace: a persisted record of what the auth layer did, readable after any reload or redirect.
22
+ *
23
+ * Why storage and not `window`: a sign-in problem usually ends in a reload or a redirect, which throws away
24
+ * everything held in memory and in the console. The events live in `localStorage` (falling back to
25
+ * `sessionStorage`, then memory), so the next page can still print them. `window.__cfgAuth` is only the reader.
26
+ *
27
+ * Read it in the browser console, on any page of the origin, even after the redirect:
28
+ *
29
+ * __cfgAuth.dump() // copy-ready text with a header; paste it into the report
30
+ * __cfgAuth.trace() // the raw array
31
+ * __cfgAuth.clear() // empty it before reproducing
32
+ *
33
+ * What is recorded is the decision, never the secret: no token, code, address, cookie value or password.
34
+ * Values are primitives, strings are cut, and keys that look sensitive are dropped (`SENSITIVE`).
35
+ */
36
+ type Primitive = string | number | boolean | null;
37
+ type TraceFields = Record<string, Primitive>;
38
+ interface TraceEntry {
39
+ /** Wall clock, ms since epoch. */
40
+ t: number;
41
+ /** ms since this page started (`performance.now()`), so a reload shows as the counter restarting. */
42
+ p: number;
43
+ /** Short random id of this page load: one sequence, several loads, told apart by this. */
44
+ tab: string;
45
+ ev: string;
46
+ f?: TraceFields;
47
+ }
48
+ /** Record one auth event. Safe anywhere: it never throws and does nothing on the server. */
49
+ declare function authTrace(ev: string, fields?: TraceFields): void;
50
+ /** The recorded events, oldest first. */
51
+ declare function readAuthTrace(): TraceEntry[];
52
+ /** Empty the trace. */
53
+ declare function clearAuthTrace(): void;
54
+ /** Copy-ready text: a short header, then one line per event. Reloads show as a new `[tab]`. */
55
+ declare function dumpAuthTrace(): string;
56
+ /**
57
+ * Install the reader. Called once from the package entry; idempotent across copies of this module.
58
+ * The generated auth store forwards through `globalThis.__cfgAuthTrace` and queues until this runs.
59
+ */
60
+ declare function installAuthTrace(): void;
61
+
20
62
  type SessionStatus = 'authenticated' | 'anonymous';
21
63
  type SessionSnapshot = {
22
64
  /** 'authenticated' = a live access token OR a live refresh token exists. */
@@ -691,6 +733,8 @@ interface ResolvedAuthRoutes {
691
733
  interface AuthContextType {
692
734
  user: UserProfile | null;
693
735
  isLoading: boolean;
736
+ /** The one linear auth state: 'resolving' until the client has read the session and its profile, then 'authenticated' or 'anonymous'. */
737
+ status: 'resolving' | 'authenticated' | 'anonymous';
694
738
  isAuthenticated: boolean;
695
739
  isAdminUser: boolean;
696
740
  /** Resolved route conventions (config override or framework default). */
@@ -1456,6 +1500,35 @@ declare const normalizePath: (path: string | null | undefined) => string;
1456
1500
  */
1457
1501
  declare const isAllowedAuthPath: (pathname: string | null | undefined, allowedPaths: string[]) => boolean;
1458
1502
 
1503
+ /**
1504
+ * The one auth state: a single value answers "may this page render?".
1505
+ *
1506
+ * resolving the client has not read the session yet, or a live session is still loading its profile
1507
+ * authenticated a live session and its profile settled
1508
+ * anonymous no session (store and React snapshot agree)
1509
+ *
1510
+ * Every consumer (the page guard, the "leave /auth" effect, the trace) reads this and nothing else. The
1511
+ * inputs are plain booleans so the whole table is unit-tested.
1512
+ *
1513
+ * Termination: `resolving` is left in finite time. `timedOut` is set by one timer in the provider, and
1514
+ * when it fires the React snapshot decides. There is no input combination that stays `resolving` with
1515
+ * `timedOut` true.
1516
+ */
1517
+ type AuthStatus = 'resolving' | 'authenticated' | 'anonymous';
1518
+ interface AuthStateInput {
1519
+ /** The first client effect has run (the hydration commit is over). */
1520
+ clientReady: boolean;
1521
+ /** `useSession()` says authenticated (the React snapshot; the server snapshot is always anonymous). */
1522
+ snapshotAuthenticated: boolean;
1523
+ /** `auth.isAuthenticated()` read straight from the store at this render. */
1524
+ storeAuthenticated: boolean;
1525
+ /** The profile for a live session has loaded, failed in a way that keeps the session, or was cached. */
1526
+ profileSettled: boolean;
1527
+ /** The provider's single safety timer fired. */
1528
+ timedOut: boolean;
1529
+ }
1530
+ declare function resolveAuthStatus(s: AuthStateInput): AuthStatus;
1531
+
1459
1532
  declare const logger: consola.ConsolaInstance;
1460
1533
  /**
1461
1534
  * Auth-specific logger
@@ -1531,5 +1604,5 @@ declare const Analytics: {
1531
1604
  setUser(userId: string | null): void;
1532
1605
  };
1533
1606
 
1534
- export { AUTH_CONSTANTS, AUTH_ERROR_KEYS, AccountsProvider, Analytics, AnalyticsCategory, AnalyticsEvent, AuthContext, AuthProvider, OAUTH_PROVIDER_IDS, authLogger, beginTwoFactorChallenge, clearOAuthAttempt, clearProfileCache, consumeSavedRedirect, decodeBase64, encodeBase64, endTwoFactorChallenge, formatAuthError, getCacheMetadata, getCachedProfile, hasValidCache, isAllowedAuthPath, isForbidden, isOAuthProviderId, logAuthFailure, logger, normalizePath, peekSavedRedirect, readOAuthFailure, resolveAuthError, resolveGuardIsAuthenticated, resolveGuardIsLoading, setAnalyticsSink, setCachedProfile, shouldRedirectToAuth, useAccountsContext, useAuth, useAuthForm, useAuthFormState, useAuthRedirectManager, useAuthValidation, useAutoAuth, useBase64, useCfgRouter, useDeleteAccount, useGithubAuth, useLocalStorage, useOAuthLogin, useOAuthProviders, useQueryParams, useSession, useSessionStorage, useTimezone, useTwoFactor, useTwoFactorChallenge, useTwoFactorSetup, useTwoFactorStatus, useTwoFactorVerify, validateEmail, validateIdentifier };
1535
- export type { AccountsContextValue, AnalyticsCategoryType, AnalyticsEventType, AnalyticsSink, AuthConfig, AuthContextType, AuthErrorCopy, AuthErrorKey, AuthFormAutoSubmit, AuthFormReturn, AuthFormState, AuthFormStateHandlers, AuthFormSubmitHandlers, AuthFormValidation, AuthProviderProps, AuthStep, DeleteAccountResult, GuardInput, OAuthClientErrorCode, OAuthErrorCode, OAuthFailure, OAuthFailureCode, OAuthProviderId, OAuthUser, OTPRequestConsent, OTPRequestResult, PasswordLoginOptions, PasswordLoginResult, PatchedCfgUserUpdateRequest, ProfileCacheOptions, SessionSnapshot, SessionStatus, TwoFactorChallenge, TwoFactorDevice, TwoFactorSetupData, UseAuthFormOptions, UseAuthFormStateReturn, UseAutoAuthOptions, UseDeleteAccountReturn, UseGithubAuthOptions, UseGithubAuthReturn, UseOAuthLoginOptions, UseOAuthLoginReturn, UseOAuthProvidersReturn, UseTimezoneReturn, UseTwoFactorOptions, UseTwoFactorReturn, UseTwoFactorSetupOptions, UseTwoFactorSetupReturn, UseTwoFactorStatusReturn, UseTwoFactorVerifyOptions, UseTwoFactorVerifyReturn, UserProfile, WebmailLink };
1607
+ export { AUTH_CONSTANTS, AUTH_ERROR_KEYS, AccountsProvider, Analytics, AnalyticsCategory, AnalyticsEvent, AuthContext, AuthProvider, OAUTH_PROVIDER_IDS, authLogger, authTrace, beginTwoFactorChallenge, clearAuthTrace, clearOAuthAttempt, clearProfileCache, consumeSavedRedirect, decodeBase64, dumpAuthTrace, encodeBase64, endTwoFactorChallenge, formatAuthError, getCacheMetadata, getCachedProfile, hasValidCache, installAuthTrace, isAllowedAuthPath, isForbidden, isOAuthProviderId, logAuthFailure, logger, normalizePath, peekSavedRedirect, readAuthTrace, readOAuthFailure, resolveAuthError, resolveAuthStatus, resolveGuardIsAuthenticated, resolveGuardIsLoading, setAnalyticsSink, setCachedProfile, shouldRedirectToAuth, useAccountsContext, useAuth, useAuthForm, useAuthFormState, useAuthRedirectManager, useAuthValidation, useAutoAuth, useBase64, useCfgRouter, useDeleteAccount, useGithubAuth, useLocalStorage, useOAuthLogin, useOAuthProviders, useQueryParams, useSession, useSessionStorage, useTimezone, useTwoFactor, useTwoFactorChallenge, useTwoFactorSetup, useTwoFactorStatus, useTwoFactorVerify, validateEmail, validateIdentifier };
1608
+ export type { AccountsContextValue, AnalyticsCategoryType, AnalyticsEventType, AnalyticsSink, AuthConfig, AuthContextType, AuthErrorCopy, AuthErrorKey, AuthFormAutoSubmit, AuthFormReturn, AuthFormState, AuthFormStateHandlers, AuthFormSubmitHandlers, AuthFormValidation, AuthProviderProps, AuthStateInput, AuthStatus, AuthStep, DeleteAccountResult, GuardInput, OAuthClientErrorCode, OAuthErrorCode, OAuthFailure, OAuthFailureCode, OAuthProviderId, OAuthUser, OTPRequestConsent, OTPRequestResult, PasswordLoginOptions, PasswordLoginResult, PatchedCfgUserUpdateRequest, ProfileCacheOptions, SessionSnapshot, SessionStatus, TraceEntry, TraceFields, TwoFactorChallenge, TwoFactorDevice, TwoFactorSetupData, UseAuthFormOptions, UseAuthFormStateReturn, UseAutoAuthOptions, UseDeleteAccountReturn, UseGithubAuthOptions, UseGithubAuthReturn, UseOAuthLoginOptions, UseOAuthLoginReturn, UseOAuthProvidersReturn, UseTimezoneReturn, UseTwoFactorOptions, UseTwoFactorReturn, UseTwoFactorSetupOptions, UseTwoFactorSetupReturn, UseTwoFactorStatusReturn, UseTwoFactorVerifyOptions, UseTwoFactorVerifyReturn, UserProfile, WebmailLink };
package/dist/auth.d.ts CHANGED
@@ -17,6 +17,48 @@ declare const AUTH_CONSTANTS: {
17
17
  readonly RESEND_COOLDOWN_SECONDS: 30;
18
18
  };
19
19
 
20
+ /**
21
+ * Auth trace: a persisted record of what the auth layer did, readable after any reload or redirect.
22
+ *
23
+ * Why storage and not `window`: a sign-in problem usually ends in a reload or a redirect, which throws away
24
+ * everything held in memory and in the console. The events live in `localStorage` (falling back to
25
+ * `sessionStorage`, then memory), so the next page can still print them. `window.__cfgAuth` is only the reader.
26
+ *
27
+ * Read it in the browser console, on any page of the origin, even after the redirect:
28
+ *
29
+ * __cfgAuth.dump() // copy-ready text with a header; paste it into the report
30
+ * __cfgAuth.trace() // the raw array
31
+ * __cfgAuth.clear() // empty it before reproducing
32
+ *
33
+ * What is recorded is the decision, never the secret: no token, code, address, cookie value or password.
34
+ * Values are primitives, strings are cut, and keys that look sensitive are dropped (`SENSITIVE`).
35
+ */
36
+ type Primitive = string | number | boolean | null;
37
+ type TraceFields = Record<string, Primitive>;
38
+ interface TraceEntry {
39
+ /** Wall clock, ms since epoch. */
40
+ t: number;
41
+ /** ms since this page started (`performance.now()`), so a reload shows as the counter restarting. */
42
+ p: number;
43
+ /** Short random id of this page load: one sequence, several loads, told apart by this. */
44
+ tab: string;
45
+ ev: string;
46
+ f?: TraceFields;
47
+ }
48
+ /** Record one auth event. Safe anywhere: it never throws and does nothing on the server. */
49
+ declare function authTrace(ev: string, fields?: TraceFields): void;
50
+ /** The recorded events, oldest first. */
51
+ declare function readAuthTrace(): TraceEntry[];
52
+ /** Empty the trace. */
53
+ declare function clearAuthTrace(): void;
54
+ /** Copy-ready text: a short header, then one line per event. Reloads show as a new `[tab]`. */
55
+ declare function dumpAuthTrace(): string;
56
+ /**
57
+ * Install the reader. Called once from the package entry; idempotent across copies of this module.
58
+ * The generated auth store forwards through `globalThis.__cfgAuthTrace` and queues until this runs.
59
+ */
60
+ declare function installAuthTrace(): void;
61
+
20
62
  type SessionStatus = 'authenticated' | 'anonymous';
21
63
  type SessionSnapshot = {
22
64
  /** 'authenticated' = a live access token OR a live refresh token exists. */
@@ -691,6 +733,8 @@ interface ResolvedAuthRoutes {
691
733
  interface AuthContextType {
692
734
  user: UserProfile | null;
693
735
  isLoading: boolean;
736
+ /** The one linear auth state: 'resolving' until the client has read the session and its profile, then 'authenticated' or 'anonymous'. */
737
+ status: 'resolving' | 'authenticated' | 'anonymous';
694
738
  isAuthenticated: boolean;
695
739
  isAdminUser: boolean;
696
740
  /** Resolved route conventions (config override or framework default). */
@@ -1456,6 +1500,35 @@ declare const normalizePath: (path: string | null | undefined) => string;
1456
1500
  */
1457
1501
  declare const isAllowedAuthPath: (pathname: string | null | undefined, allowedPaths: string[]) => boolean;
1458
1502
 
1503
+ /**
1504
+ * The one auth state: a single value answers "may this page render?".
1505
+ *
1506
+ * resolving the client has not read the session yet, or a live session is still loading its profile
1507
+ * authenticated a live session and its profile settled
1508
+ * anonymous no session (store and React snapshot agree)
1509
+ *
1510
+ * Every consumer (the page guard, the "leave /auth" effect, the trace) reads this and nothing else. The
1511
+ * inputs are plain booleans so the whole table is unit-tested.
1512
+ *
1513
+ * Termination: `resolving` is left in finite time. `timedOut` is set by one timer in the provider, and
1514
+ * when it fires the React snapshot decides. There is no input combination that stays `resolving` with
1515
+ * `timedOut` true.
1516
+ */
1517
+ type AuthStatus = 'resolving' | 'authenticated' | 'anonymous';
1518
+ interface AuthStateInput {
1519
+ /** The first client effect has run (the hydration commit is over). */
1520
+ clientReady: boolean;
1521
+ /** `useSession()` says authenticated (the React snapshot; the server snapshot is always anonymous). */
1522
+ snapshotAuthenticated: boolean;
1523
+ /** `auth.isAuthenticated()` read straight from the store at this render. */
1524
+ storeAuthenticated: boolean;
1525
+ /** The profile for a live session has loaded, failed in a way that keeps the session, or was cached. */
1526
+ profileSettled: boolean;
1527
+ /** The provider's single safety timer fired. */
1528
+ timedOut: boolean;
1529
+ }
1530
+ declare function resolveAuthStatus(s: AuthStateInput): AuthStatus;
1531
+
1459
1532
  declare const logger: consola.ConsolaInstance;
1460
1533
  /**
1461
1534
  * Auth-specific logger
@@ -1531,5 +1604,5 @@ declare const Analytics: {
1531
1604
  setUser(userId: string | null): void;
1532
1605
  };
1533
1606
 
1534
- export { AUTH_CONSTANTS, AUTH_ERROR_KEYS, AccountsProvider, Analytics, AnalyticsCategory, AnalyticsEvent, AuthContext, AuthProvider, OAUTH_PROVIDER_IDS, authLogger, beginTwoFactorChallenge, clearOAuthAttempt, clearProfileCache, consumeSavedRedirect, decodeBase64, encodeBase64, endTwoFactorChallenge, formatAuthError, getCacheMetadata, getCachedProfile, hasValidCache, isAllowedAuthPath, isForbidden, isOAuthProviderId, logAuthFailure, logger, normalizePath, peekSavedRedirect, readOAuthFailure, resolveAuthError, resolveGuardIsAuthenticated, resolveGuardIsLoading, setAnalyticsSink, setCachedProfile, shouldRedirectToAuth, useAccountsContext, useAuth, useAuthForm, useAuthFormState, useAuthRedirectManager, useAuthValidation, useAutoAuth, useBase64, useCfgRouter, useDeleteAccount, useGithubAuth, useLocalStorage, useOAuthLogin, useOAuthProviders, useQueryParams, useSession, useSessionStorage, useTimezone, useTwoFactor, useTwoFactorChallenge, useTwoFactorSetup, useTwoFactorStatus, useTwoFactorVerify, validateEmail, validateIdentifier };
1535
- export type { AccountsContextValue, AnalyticsCategoryType, AnalyticsEventType, AnalyticsSink, AuthConfig, AuthContextType, AuthErrorCopy, AuthErrorKey, AuthFormAutoSubmit, AuthFormReturn, AuthFormState, AuthFormStateHandlers, AuthFormSubmitHandlers, AuthFormValidation, AuthProviderProps, AuthStep, DeleteAccountResult, GuardInput, OAuthClientErrorCode, OAuthErrorCode, OAuthFailure, OAuthFailureCode, OAuthProviderId, OAuthUser, OTPRequestConsent, OTPRequestResult, PasswordLoginOptions, PasswordLoginResult, PatchedCfgUserUpdateRequest, ProfileCacheOptions, SessionSnapshot, SessionStatus, TwoFactorChallenge, TwoFactorDevice, TwoFactorSetupData, UseAuthFormOptions, UseAuthFormStateReturn, UseAutoAuthOptions, UseDeleteAccountReturn, UseGithubAuthOptions, UseGithubAuthReturn, UseOAuthLoginOptions, UseOAuthLoginReturn, UseOAuthProvidersReturn, UseTimezoneReturn, UseTwoFactorOptions, UseTwoFactorReturn, UseTwoFactorSetupOptions, UseTwoFactorSetupReturn, UseTwoFactorStatusReturn, UseTwoFactorVerifyOptions, UseTwoFactorVerifyReturn, UserProfile, WebmailLink };
1607
+ export { AUTH_CONSTANTS, AUTH_ERROR_KEYS, AccountsProvider, Analytics, AnalyticsCategory, AnalyticsEvent, AuthContext, AuthProvider, OAUTH_PROVIDER_IDS, authLogger, authTrace, beginTwoFactorChallenge, clearAuthTrace, clearOAuthAttempt, clearProfileCache, consumeSavedRedirect, decodeBase64, dumpAuthTrace, encodeBase64, endTwoFactorChallenge, formatAuthError, getCacheMetadata, getCachedProfile, hasValidCache, installAuthTrace, isAllowedAuthPath, isForbidden, isOAuthProviderId, logAuthFailure, logger, normalizePath, peekSavedRedirect, readAuthTrace, readOAuthFailure, resolveAuthError, resolveAuthStatus, resolveGuardIsAuthenticated, resolveGuardIsLoading, setAnalyticsSink, setCachedProfile, shouldRedirectToAuth, useAccountsContext, useAuth, useAuthForm, useAuthFormState, useAuthRedirectManager, useAuthValidation, useAutoAuth, useBase64, useCfgRouter, useDeleteAccount, useGithubAuth, useLocalStorage, useOAuthLogin, useOAuthProviders, useQueryParams, useSession, useSessionStorage, useTimezone, useTwoFactor, useTwoFactorChallenge, useTwoFactorSetup, useTwoFactorStatus, useTwoFactorVerify, validateEmail, validateIdentifier };
1608
+ export type { AccountsContextValue, AnalyticsCategoryType, AnalyticsEventType, AnalyticsSink, AuthConfig, AuthContextType, AuthErrorCopy, AuthErrorKey, AuthFormAutoSubmit, AuthFormReturn, AuthFormState, AuthFormStateHandlers, AuthFormSubmitHandlers, AuthFormValidation, AuthProviderProps, AuthStateInput, AuthStatus, AuthStep, DeleteAccountResult, GuardInput, OAuthClientErrorCode, OAuthErrorCode, OAuthFailure, OAuthFailureCode, OAuthProviderId, OAuthUser, OTPRequestConsent, OTPRequestResult, PasswordLoginOptions, PasswordLoginResult, PatchedCfgUserUpdateRequest, ProfileCacheOptions, SessionSnapshot, SessionStatus, TraceEntry, TraceFields, TwoFactorChallenge, TwoFactorDevice, TwoFactorSetupData, UseAuthFormOptions, UseAuthFormStateReturn, UseAutoAuthOptions, UseDeleteAccountReturn, UseGithubAuthOptions, UseGithubAuthReturn, UseOAuthLoginOptions, UseOAuthLoginReturn, UseOAuthProvidersReturn, UseTimezoneReturn, UseTwoFactorOptions, UseTwoFactorReturn, UseTwoFactorSetupOptions, UseTwoFactorSetupReturn, UseTwoFactorStatusReturn, UseTwoFactorVerifyOptions, UseTwoFactorVerifyReturn, UserProfile, WebmailLink };