Skip to content

MantleClient

Defined in: client.ts:26

new MantleClient(options): MantleClient

Defined in: client.ts:41

ClientOptions

MantleClient

get url(): string

Defined in: client.ts:104

The server’s base URL, trailing slashes removed — handy for building links to non-service routes.

string

authenticate(credentials): Promise<AuthResult>

Defined in: client.ts:67

AuthCredentials

Promise<AuthResult>


getAccessToken(): string | undefined

Defined in: client.ts:108

string | undefined


isAuthenticated(): Promise<boolean>

Defined in: client.ts:120

Whether a persisted session exists, hydrating the in-memory access token from storage first if nothing has triggered that yet. Use this on app startup instead of getAccessToken() — that one is synchronous and returns undefined until hydration has happened (normally the side effect of an authenticated REST call), even when a valid token is sitting in storage from a previous session. A UI that checks getAccessToken() on first render will show its logged-out state on every page load/refresh regardless of a persisted session.

Promise<boolean>


logout(): Promise<void>

Defined in: client.ts:92

Promise<void>


off(event, handler): this

Defined in: client.ts:129

ClientEvent

() => void

this


on(event, handler): this

Defined in: client.ts:124

ClientEvent

() => void

this


request<R>(method, path, data, params?): Promise<R>

Defined in: client.ts:135

REST dispatch used by every ServiceClient method: bearer auth, one refresh-retry on 401, typed errors.

R

string

string

unknown

ClientParams

Promise<R>


service<T>(path): ServiceClient<T>

Defined in: client.ts:57

T = unknown

string

ServiceClient<T>


setTokens(tokens): Promise<void>

Defined in: client.ts:86

Hydrate the client from a token pair obtained outside authenticate() — e.g. an OAuth provider’s redirect-back callback landing tokens in the URL fragment. Stores them and emits 'authenticated', same as a successful authenticate() call.

string

string

Promise<void>


upload<R>(method, path, body, options?): Promise<R>

Defined in: client.ts:152

multipart/form-data dispatch used by ServiceClient.upload(): bearer auth, one refresh-retry on 401, typed errors — the same guarantees as request(). The body is rebuilt for the retry, since a consumed FormData stream can’t be replayed by every transport.

R

string

string

() => FormData

UploadTransportOptions = {}

Promise<R>