Coves frontend - a photon fork
at main 131 lines 4.1 kB view raw
1// See https://kit.svelte.dev/docs/types#app 2 3import type { Component } from 'svelte' 4import type { AccountSession, SealedToken } from '$lib/server/session' 5 6// for information about these interfaces 7declare global { 8 namespace App { 9 // interface Error {} 10 11 /** 12 * Unauthenticated auth state - no valid session. 13 */ 14 interface UnauthenticatedAuth { 15 readonly authenticated: false 16 } 17 18 /** 19 * Authenticated auth state - valid session with active account. 20 * All fields are guaranteed to be present when authenticated is true. 21 */ 22 interface AuthenticatedAuth { 23 readonly authenticated: true 24 /** The authenticated account */ 25 readonly account: AccountSession 26 /** 27 * Convenience alias for `account.sealedToken`. 28 * Duplicated at the top level so the proxy layer (`/api/proxy/[...path]`) 29 * can read the token directly from `locals.auth.authToken` without 30 * reaching into the nested account object on every proxied request. 31 */ 32 readonly authToken: SealedToken 33 } 34 35 /** 36 * Discriminated union for authentication state. 37 * Use `locals.auth.authenticated` to narrow the type. 38 * 39 * @example 40 * ```typescript 41 * if (locals.auth.authenticated) { 42 * // TypeScript knows account and authToken exist 43 * console.log(locals.auth.account.did) 44 * } 45 * ``` 46 */ 47 type AuthState = UnauthenticatedAuth | AuthenticatedAuth 48 49 /** 50 * Categories of authentication errors that can occur during session validation. 51 * These allow downstream code (layouts, pages) to show appropriate user feedback. 52 * 53 * - 'network_error': Infrastructure failure (DNS, TLS, timeout, connection refused). 54 * The session cookie is preserved because the error may be temporary. 55 * - 'validation_error': The /api/me response was received but contained invalid data. 56 * Indicates a server-side bug or protocol mismatch. 57 */ 58 type AuthErrorKind = 'network_error' | 'validation_error' 59 60 /** 61 * Server-side request-local state populated by hooks.server.ts. 62 * 63 * Uses a discriminated union to make invalid states unrepresentable: 64 * - When authenticated, all auth fields are guaranteed present 65 * - When unauthenticated, no auth fields are present 66 */ 67 interface Locals { 68 auth: AuthState 69 /** 70 * Set when authentication failed due to an infrastructure or validation error 71 * (as opposed to simply not having a session cookie). 72 * The layout can use this to show a warning banner to the user. 73 */ 74 authError?: AuthErrorKind 75 /** Set to true when a 401 from /api/me indicates the session has expired or been revoked */ 76 sessionExpired?: boolean 77 } 78 interface PageData { 79 slots?: { 80 sidebar?: { 81 /** 82 * A Svelte component to render in the sidebar slot. 83 * Uses `Component` with `Record<string, unknown>` because different pages 84 * pass different components (CommunityCard, etc.) with varying prop shapes. 85 */ 86 component?: Component<Record<string, unknown>> 87 /** 88 * Props to spread onto the sidebar component. 89 * Typed as `Record<string, unknown>` because this is a dynamic slot system 90 * where different components receive different props at runtime. 91 */ 92 props?: Record<string, unknown> 93 } 94 } 95 contextual?: { 96 actions?: Action[] 97 } 98 } 99 interface PageState { 100 openImage?: string 101 openModals?: string[] 102 } 103 // interface Platform {} 104 } 105 declare const __VERSION__: string 106} 107 108export {} 109// eslint-disable-next-line 110declare const __VERSION__: string 111 112declare module 'markdown-it-sub' 113declare module 'markdown-it-sup' 114 115declare module '@xylightdev/svelte-hero-icons' { 116 interface IconProps { 117 'aria-label'?: string 118 'aria-hidden'?: boolean 119 title?: string 120 } 121} 122 123declare module '*.svg?raw' { 124 const content: string 125 export default content 126} 127 128declare module '*.md?raw' { 129 const content: string 130 export default content 131}