API Reference
MeroJs class, property accessors, instance methods, static utilities, and types
MeroJs Constructor
new MeroJs(config: MeroJsConfig)
baseUrl
Required. Base URL of the Calimero node, e.g. 'http://localhost:2428'.
timeoutMs
Request timeout in milliseconds. Default: 10000.
credentials
Optional { username, password } — auto-authenticate on first call if set.
requestCredentials
Fetch credentials mode ('omit', 'same-origin', 'include'). Defaults to 'omit' in Tauri environments.
tokenStore
Optional TokenStore for persisting tokens across sessions.
Property Accessors
Read-only getters on MeroJs. rpc, events, and ws are lazily initialised on first access.
sdk.auth
AuthApiClient — access the raw auth API (login, refresh, key management).
sdk.admin
AdminApiClient — access the admin API (contexts, apps, namespaces, groups).
sdk.rpc
RpcClient — execute WASM contract methods via JSON-RPC. Lazy.
sdk.events
SseClient — subscribe to real-time events via SSE. Lazy.
sdk.ws
WsClient — experimental WebSocket client. Lazy. Logs a warning on first access.
Instance Methods
authenticate(credentials?)
Exchange username + password for tokens. Accepts optional { username, password } override (falls back to config.credentials). Returns Promise<TokenData>.
setTokenData(data)
Set tokens directly — used for SSO flows where tokens arrive via URL hash. If expires_at is 0, parses the JWT exp claim automatically.
getTokenData()
Returns the current TokenData | null. Useful for debugging.
isAuthenticated()
Returns boolean — true if token data is present.
clearToken()
Remove the current token data and clear the token store.
close()
Close all open SSE/WebSocket connections and release resources.
Static Methods
MeroJs.parseAuthCallback(url)
Parse the hash fragment from a Calimero SSO callback URL. Returns AuthCallbackResult | null.
MeroJs.buildAuthLoginUrl(nodeUrl, opts)
Build a redirect URL for the Calimero auth login flow. Returns the URL string.
Both are also exported as standalone functions: parseAuthCallback, buildAuthLoginUrl.
TokenData
interface TokenData {
access_token: string; // JWT access token
refresh_token: string; // refresh token
expires_at: number; // ms timestamp; 0 = parse from JWT exp
}
access_token: string; // JWT access token
refresh_token: string; // refresh token
expires_at: number; // ms timestamp; 0 = parse from JWT exp
}
AuthCallbackResult
interface AuthCallbackResult {
accessToken: string;
refreshToken: string;
nodeUrl: string;
applicationId: string;
contextId: string;
contextIdentity: string;
}
accessToken: string;
refreshToken: string;
nodeUrl: string;
applicationId: string;
contextId: string;
contextIdentity: string;
}
RpcClient
class RpcClient {
execute<T = unknown>(params: ExecuteParams): Promise<T>;
}
interface ExecuteParams {
contextId: string;
method: string;
argsJson?: Record<string, unknown>; // method arguments
}
execute<T = unknown>(params: ExecuteParams): Promise<T>;
}
interface ExecuteParams {
contextId: string;
method: string;
argsJson?: Record<string, unknown>; // method arguments
}
Access via sdk.rpc. Throws RpcError on JSON-RPC errors. See Error Model.
TokenStore
interface TokenStore {
getTokens(): TokenData | null;
setTokens(data: TokenData): void;
clear(): void;
}
// Built-in implementations:
class MemoryTokenStore implements TokenStore { }
class LocalStorageTokenStore implements TokenStore {
constructor(key?: string); // default key: 'mero-tokens'
}
getTokens(): TokenData | null;
setTokens(data: TokenData): void;
clear(): void;
}
// Built-in implementations:
class MemoryTokenStore implements TokenStore { }
class LocalStorageTokenStore implements TokenStore {
constructor(key?: string); // default key: 'mero-tokens'
}