import type { SDKObserver } from './observer/index.js'; import type { AuthTokenResolver } from '@pellux/goodvibes-transport-http'; import type { OperatorSdk } from '@pellux/goodvibes-operator-sdk'; import { AutoRefreshCoordinator, PermissionResolver, SessionManager, TokenStore } from './client-auth/index.js'; import type { AutoRefreshOptions } from './client-auth/index.js'; import type { GoodVibesAuthLoginOptions, GoodVibesCurrentAuth, GoodVibesExpiringTokenStore, GoodVibesLoginInput, GoodVibesLoginOutput, GoodVibesTokenStore } from './client-auth/types.js'; export { PermissionResolver, SessionManager, TokenStore } from './client-auth/index.js'; export type { OAuthStartState, OAuthTokenPayload } from './client-auth/oauth-types.js'; export type { GoodVibesAuthLoginOptions, GoodVibesCurrentAuth, GoodVibesExpiringTokenStore, GoodVibesLoginInput, GoodVibesLoginOutput, GoodVibesTokenStore, } from './client-auth/types.js'; export interface BrowserTokenStoreOptions { readonly key?: string | undefined; readonly storage?: Pick | undefined; } /** * The combined auth client attached to an SDK instance. * * This interface aggregates token storage and session management behind a * single object for convenience. For focused single-responsibility access, * use the split classes exposed as readonly getters on this object: * - `sdk.auth.tokenStore`, Token persistence (`TokenStore`) * - `sdk.auth.sessionManager`, Login / session lifecycle (`SessionManager`) * - `sdk.auth.permissionResolver(snapshot)`, Role / scope checks (`PermissionResolver`) * - OAuth 2.0 flows: handle server-side (operator/daemon) and provide the acquired * token to the client via TokenStore. */ export interface GoodVibesAuthClient { readonly writable: boolean; /** The underlying `TokenStore`, or null when using a read-only `getAuthToken` resolver. */ readonly tokenStore: TokenStore | null; /** The underlying `SessionManager`, which owns login and current-auth delegation. */ readonly sessionManager: SessionManager; /** * Build a `PermissionResolver` from a live auth snapshot. * * @example * const snap = await sdk.auth.current(); * const perm = sdk.auth.permissionResolver(snap); * if (perm.hasRole('admin')) { ... } */ permissionResolver(snapshot: GoodVibesCurrentAuth): PermissionResolver; current(): Promise; login(input: GoodVibesLoginInput, options?: GoodVibesAuthLoginOptions): Promise; /** Retrieve the current token. Delegates to `TokenStore.getToken()`. */ getToken(): Promise; /** Persist a token. Delegates to `TokenStore.setToken()`. */ setToken(token: string | null): Promise; /** Clear the stored token. Delegates to `TokenStore.clearToken()`. */ clearToken(): Promise; } /** * Options for the auto-refresh feature on the auth client. * * @see AutoRefreshOptions */ export type { AutoRefreshOptions }; export type { AutoRefreshCoordinatorOptions } from './client-auth/index.js'; export type { ControlPlaneAuthMode, ControlPlaneAuthSnapshot } from './client-auth/control-plane-auth-snapshot.js'; /** * Create a simple in-memory token store. * * The token is held in a closure variable, it does not survive page * refreshes or process restarts. Suitable for server-side scripts and tests. * * @example * import { createMemoryTokenStore } from '@pellux/goodvibes-sdk'; * * const store = createMemoryTokenStore('initial-token'); * const sdk = createGoodVibesSdk({ baseUrl: '...', tokenStore: store }); * await sdk.auth.clearToken(); // clears only in-memory */ export declare function createMemoryTokenStore(initialToken?: string | null, initialExpiresAt?: number): GoodVibesExpiringTokenStore; /** * Create a token store backed by `localStorage` (or a custom `Storage`). * * The token is persisted across page refreshes under the key * `'goodvibes.token'` (overridable via `options.key`). * Pass `options.storage` to use `sessionStorage` or a custom adapter. * * @example * import { createBrowserTokenStore, createBrowserGoodVibesSdk } from '@pellux/goodvibes-sdk/browser'; * * const tokenStore = createBrowserTokenStore({ storage: sessionStorage }); * const sdk = createBrowserGoodVibesSdk({ tokenStore }); * await sdk.auth.login({ username: 'alice', password: 's3cr3t' }); * // token is now stored in sessionStorage */ export declare function createBrowserTokenStore(options?: BrowserTokenStoreOptions): GoodVibesExpiringTokenStore; /** * Create the auth client attached to an SDK instance. * * Normally called internally by `createGoodVibesSdk`. Access the result via * `sdk.auth`. * * @example * import { createGoodVibesSdk, createBrowserTokenStore } from '@pellux/goodvibes-sdk'; * * const sdk = createGoodVibesSdk({ * baseUrl: 'https://daemon.example.com', * tokenStore: createBrowserTokenStore(), * }); * * // Login and persist the token automatically: * const { token } = await sdk.auth.login({ username: 'alice', password: 's3cr3t' }); * console.log('logged in, token stored:', token.slice(0, 8) + '...'); * * // Later: clear the session * await sdk.auth.clearToken(); */ export declare function createGoodVibesAuthClient(operator: OperatorSdk, tokenStore: GoodVibesTokenStore | null, getAuthToken?: AuthTokenResolver, observer?: SDKObserver | undefined, autoRefreshOptions?: AutoRefreshOptions, /** * Optional pre-built `AutoRefreshCoordinator`. When provided, it is reused * directly (no new coordinator is constructed). This allows `createGoodVibesSdk` * to share a single coordinator instance between the transport middleware and * the auth client, avoiding duplicate refresh calls. */ existingCoordinator?: AutoRefreshCoordinator | null): GoodVibesAuthClient; //# sourceMappingURL=auth.d.ts.map