@djangocfg/api 2.1.619 → 2.1.622

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,53 @@ 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
+ * __cfgAuth.copy() // dump to the clipboard; __cfgAuth.download() saves the raw JSON
33
+ *
34
+ * What is recorded is the decision, never the secret: no token, code, address, cookie value or password.
35
+ * Values are primitives, strings are cut, and keys that look sensitive are dropped (`SENSITIVE`).
36
+ */
37
+ type Primitive = string | number | boolean | null;
38
+ type TraceFields = Record<string, Primitive>;
39
+ interface TraceEntry {
40
+ /** Wall clock, ms since epoch. */
41
+ t: number;
42
+ /** ms since this page started (`performance.now()`), so a reload shows as the counter restarting. */
43
+ p: number;
44
+ /** Short random id of this page load: one sequence, several loads, told apart by this. */
45
+ tab: string;
46
+ ev: string;
47
+ f?: TraceFields;
48
+ /** Times this exact event repeated back to back (absent = once). A loop must not push the start of the chain out of the buffer. */
49
+ n?: number;
50
+ }
51
+ /** Record one auth event. Safe anywhere: it never throws and does nothing on the server. */
52
+ declare function authTrace(ev: string, fields?: TraceFields): void;
53
+ /** The recorded events, oldest first. */
54
+ /** @internal for tests */
55
+ declare function resetAuthTraceForTests(): void;
56
+ declare function readAuthTrace(): TraceEntry[];
57
+ /** Empty the trace. */
58
+ declare function clearAuthTrace(): void;
59
+ /** Copy-ready text: a short header, then one line per event. Reloads show as a new `[tab]`. */
60
+ declare function dumpAuthTrace(): string;
61
+ /**
62
+ * Install the reader. Called once from the package entry; idempotent across copies of this module.
63
+ * The generated auth store forwards through `globalThis.__cfgAuthTrace` and queues until this runs.
64
+ */
65
+ declare function installAuthTrace(): void;
66
+
20
67
  type SessionStatus = 'authenticated' | 'anonymous';
21
68
  type SessionSnapshot = {
22
69
  /** 'authenticated' = a live access token OR a live refresh token exists. */
@@ -691,6 +738,8 @@ interface ResolvedAuthRoutes {
691
738
  interface AuthContextType {
692
739
  user: UserProfile | null;
693
740
  isLoading: boolean;
741
+ /** The one linear auth state: 'resolving' until the client has read the session and its profile, then 'authenticated' or 'anonymous'. */
742
+ status: 'resolving' | 'authenticated' | 'anonymous';
694
743
  isAuthenticated: boolean;
695
744
  isAdminUser: boolean;
696
745
  /** Resolved route conventions (config override or framework default). */
@@ -1456,6 +1505,35 @@ declare const normalizePath: (path: string | null | undefined) => string;
1456
1505
  */
1457
1506
  declare const isAllowedAuthPath: (pathname: string | null | undefined, allowedPaths: string[]) => boolean;
1458
1507
 
1508
+ /**
1509
+ * The one auth state: a single value answers "may this page render?".
1510
+ *
1511
+ * resolving the client has not read the session yet, or a live session is still loading its profile
1512
+ * authenticated a live session and its profile settled
1513
+ * anonymous no session (store and React snapshot agree)
1514
+ *
1515
+ * Every consumer (the page guard, the "leave /auth" effect, the trace) reads this and nothing else. The
1516
+ * inputs are plain booleans so the whole table is unit-tested.
1517
+ *
1518
+ * Termination: `resolving` is left in finite time. `timedOut` is set by one timer in the provider, and
1519
+ * when it fires the React snapshot decides. There is no input combination that stays `resolving` with
1520
+ * `timedOut` true.
1521
+ */
1522
+ type AuthStatus = 'resolving' | 'authenticated' | 'anonymous';
1523
+ interface AuthStateInput {
1524
+ /** The first client effect has run (the hydration commit is over). */
1525
+ clientReady: boolean;
1526
+ /** `useSession()` says authenticated (the React snapshot; the server snapshot is always anonymous). */
1527
+ snapshotAuthenticated: boolean;
1528
+ /** `auth.isAuthenticated()` read straight from the store at this render. */
1529
+ storeAuthenticated: boolean;
1530
+ /** The profile for a live session has loaded, failed in a way that keeps the session, or was cached. */
1531
+ profileSettled: boolean;
1532
+ /** The provider's single safety timer fired. */
1533
+ timedOut: boolean;
1534
+ }
1535
+ declare function resolveAuthStatus(s: AuthStateInput): AuthStatus;
1536
+
1459
1537
  declare const logger: consola.ConsolaInstance;
1460
1538
  /**
1461
1539
  * Auth-specific logger
@@ -1531,5 +1609,5 @@ declare const Analytics: {
1531
1609
  setUser(userId: string | null): void;
1532
1610
  };
1533
1611
 
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 };
1612
+ 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, resetAuthTraceForTests, 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 };
1613
+ 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,53 @@ 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
+ * __cfgAuth.copy() // dump to the clipboard; __cfgAuth.download() saves the raw JSON
33
+ *
34
+ * What is recorded is the decision, never the secret: no token, code, address, cookie value or password.
35
+ * Values are primitives, strings are cut, and keys that look sensitive are dropped (`SENSITIVE`).
36
+ */
37
+ type Primitive = string | number | boolean | null;
38
+ type TraceFields = Record<string, Primitive>;
39
+ interface TraceEntry {
40
+ /** Wall clock, ms since epoch. */
41
+ t: number;
42
+ /** ms since this page started (`performance.now()`), so a reload shows as the counter restarting. */
43
+ p: number;
44
+ /** Short random id of this page load: one sequence, several loads, told apart by this. */
45
+ tab: string;
46
+ ev: string;
47
+ f?: TraceFields;
48
+ /** Times this exact event repeated back to back (absent = once). A loop must not push the start of the chain out of the buffer. */
49
+ n?: number;
50
+ }
51
+ /** Record one auth event. Safe anywhere: it never throws and does nothing on the server. */
52
+ declare function authTrace(ev: string, fields?: TraceFields): void;
53
+ /** The recorded events, oldest first. */
54
+ /** @internal for tests */
55
+ declare function resetAuthTraceForTests(): void;
56
+ declare function readAuthTrace(): TraceEntry[];
57
+ /** Empty the trace. */
58
+ declare function clearAuthTrace(): void;
59
+ /** Copy-ready text: a short header, then one line per event. Reloads show as a new `[tab]`. */
60
+ declare function dumpAuthTrace(): string;
61
+ /**
62
+ * Install the reader. Called once from the package entry; idempotent across copies of this module.
63
+ * The generated auth store forwards through `globalThis.__cfgAuthTrace` and queues until this runs.
64
+ */
65
+ declare function installAuthTrace(): void;
66
+
20
67
  type SessionStatus = 'authenticated' | 'anonymous';
21
68
  type SessionSnapshot = {
22
69
  /** 'authenticated' = a live access token OR a live refresh token exists. */
@@ -691,6 +738,8 @@ interface ResolvedAuthRoutes {
691
738
  interface AuthContextType {
692
739
  user: UserProfile | null;
693
740
  isLoading: boolean;
741
+ /** The one linear auth state: 'resolving' until the client has read the session and its profile, then 'authenticated' or 'anonymous'. */
742
+ status: 'resolving' | 'authenticated' | 'anonymous';
694
743
  isAuthenticated: boolean;
695
744
  isAdminUser: boolean;
696
745
  /** Resolved route conventions (config override or framework default). */
@@ -1456,6 +1505,35 @@ declare const normalizePath: (path: string | null | undefined) => string;
1456
1505
  */
1457
1506
  declare const isAllowedAuthPath: (pathname: string | null | undefined, allowedPaths: string[]) => boolean;
1458
1507
 
1508
+ /**
1509
+ * The one auth state: a single value answers "may this page render?".
1510
+ *
1511
+ * resolving the client has not read the session yet, or a live session is still loading its profile
1512
+ * authenticated a live session and its profile settled
1513
+ * anonymous no session (store and React snapshot agree)
1514
+ *
1515
+ * Every consumer (the page guard, the "leave /auth" effect, the trace) reads this and nothing else. The
1516
+ * inputs are plain booleans so the whole table is unit-tested.
1517
+ *
1518
+ * Termination: `resolving` is left in finite time. `timedOut` is set by one timer in the provider, and
1519
+ * when it fires the React snapshot decides. There is no input combination that stays `resolving` with
1520
+ * `timedOut` true.
1521
+ */
1522
+ type AuthStatus = 'resolving' | 'authenticated' | 'anonymous';
1523
+ interface AuthStateInput {
1524
+ /** The first client effect has run (the hydration commit is over). */
1525
+ clientReady: boolean;
1526
+ /** `useSession()` says authenticated (the React snapshot; the server snapshot is always anonymous). */
1527
+ snapshotAuthenticated: boolean;
1528
+ /** `auth.isAuthenticated()` read straight from the store at this render. */
1529
+ storeAuthenticated: boolean;
1530
+ /** The profile for a live session has loaded, failed in a way that keeps the session, or was cached. */
1531
+ profileSettled: boolean;
1532
+ /** The provider's single safety timer fired. */
1533
+ timedOut: boolean;
1534
+ }
1535
+ declare function resolveAuthStatus(s: AuthStateInput): AuthStatus;
1536
+
1459
1537
  declare const logger: consola.ConsolaInstance;
1460
1538
  /**
1461
1539
  * Auth-specific logger
@@ -1531,5 +1609,5 @@ declare const Analytics: {
1531
1609
  setUser(userId: string | null): void;
1532
1610
  };
1533
1611
 
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 };
1612
+ 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, resetAuthTraceForTests, 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 };
1613
+ 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 };