module Types exposing ( BasicTheme , BlobRef , Config , Document , ExamplePhase(..) , Flags , Model , Page(..) , PendingOAuth , Preferences , Publication , RgbColor , Session ) import Browser.Navigation as Nav import Dict exposing (Dict) import File import Json.Decode as Decode -- Config (from flags, 12-factor) type alias Config = { clientName : String , appUrl : String , basePath : String , plcDirectoryUrl : String , dohUrl : String , bskyAppviewUrl : String } -- Flags from JS bootstrap {-| Raw flags from JS. `session` and `pendingOAuth` are kept as opaque JSON values so that schema mismatches in stored data don't crash the app at boot — they're decoded leniently in `init` and dropped on failure. -} type alias Flags = { clientName : String , appUrl : String , plcDirectoryUrl : String , dohUrl : String , bskyAppviewUrl : String , jkt : String , now : Int , session : Decode.Value , pendingOAuth : Decode.Value } -- Session (persisted across reloads) type alias Session = { did : String , handle : String , pdsEndpoint : String , tokenEndpoint : String , accessToken : String , refreshToken : Maybe String } -- Pending OAuth (persisted between authorize redirect and callback) type alias PendingOAuth = { state : String , codeVerifier : String , tokenEndpoint : String , pdsEndpoint : String , did : String , handle : String } -- Page type Page = LoginView | Dashboard Session type ExamplePhase = Idle | FadingOut | FadingIn -- Model type alias Model = { config : Config , jkt : String , page : Page , navKey : Nav.Key , clientId : String , redirectUri : String , handleInput : String , error : Maybe String , notification : Maybe String , isLoading : Bool , pendingRequests : Int -- Login animation , exampleIndex : Int , examplePhase : ExamplePhase -- Lexicon state , publications : List Publication , selectedPubRkey : Maybe String , draftPublication : Maybe Publication , documents : List Document , publicationsCursor : Maybe String , documentsCursor : Maybe String , pendingIconFile : Maybe File.File , pendingActionId : Maybe String -- OAuth flow (transient, cleared on success) , oauthCode : String , oauthCodeVerifier : String , oauthCodeChallenge : String , oauthState : String , oauthDid : String , oauthHandle : String , oauthPdsEndpoint : String , oauthAuthorizationEndpoint : String , oauthTokenEndpoint : String , oauthParEndpoint : String , oauthIssuer : String -- DPoP nonces per origin , nonces : Dict String String } -- Lexicon types type alias Publication = { rkey : String , url : String , name : String , description : Maybe String , icon : Maybe BlobRef , basicTheme : Maybe BasicTheme , preferences : Maybe Preferences , createdAt : Maybe String } type alias BasicTheme = { background : RgbColor , foreground : RgbColor , accent : RgbColor , accentForeground : RgbColor } type alias RgbColor = { r : Int, g : Int, b : Int } type alias BlobRef = { link : String , mimeType : String , size : Int } type alias Preferences = { showInDiscover : Maybe Bool } type alias Document = { title : String , path : Maybe String , site : String , publishedAt : String , url : Maybe String , description : Maybe String }