/** * SessionsService - Main Sessions Service Class * * Provides a unified interface for JWT-based session management including * creating, refreshing, verifying, and revoking sessions. */ import { ISessionServiceConfig, ICreateSessionOptions, IRefreshSessionOptions, IVerifySessionOptions, IRevokeSessionOptions, IListSessionsOptions, ISessionResult, IVerifyResult, IListSessionsResult, IDefineSessionOptions, IDefinedSession, IFetchSessionUsersOptions, IFetchSessionUsersResult, IFetchSessionUserDetailsOptions, ISessionUserDetails, IFetchSessionActivityLogsOptions, IFetchSessionActivityLogsResult, IFetchSessionDashboardOptions, ISessionDashboardMetrics, IFetchUserDashboardOptions, IUserDashboardMetrics } from './types'; import { IBootstrapSessionResponse } from '../api/services/productsApi.service'; /** * Error class for session operations */ export declare class SessionError extends Error { code: string; details?: unknown; constructor(message: string, code: string, details?: unknown); } /** * SessionsService * * Unified API for JWT-based session management. * * @example * ```ts * import { SessionsService } from '@ductape/sdk'; * * const sessions = new SessionsService({ * workspace_id: 'your-workspace-id', * public_key: 'your-public-key', * user_id: 'your-user-id', * token: 'your-token', * env_type: 'prd', * }); * * // Create a session * const result = await sessions.create({ * product: 'my-product', * env: 'production', * tag: 'user-session', * data: { userId: '123', email: 'user@example.com' }, * }); * * // Verify a session * const verifyResult = await sessions.verify({ * product: 'my-product', * env: 'production', * tag: 'user-session', * token: result.token, * }); * * // Refresh a session * const refreshResult = await sessions.refresh({ * product: 'my-product', * env: 'production', * tag: 'user-session', * refreshToken: result.refreshToken, * }); * * // Revoke a session * await sessions.revoke({ * product: 'my-product', * env: 'production', * tag: 'user-session', * sessionId: verifyResult.sessionId, * }); * ``` */ export declare class SessionsService { private config; private productBuilderService; private processorApiService; private inputService; private logService; private productId; /** Cache manager for 3-tier caching */ private cacheManager; /** Private keys per product for cache encryption */ private privateKeys; /** Local cache for cache configurations to avoid repeated API calls */ private cacheConfigCache; private readonly productEnv; constructor(config: ISessionServiceConfig); private resolvePE; /** Activity/reporting APIs intentionally support cross-environment queries. */ private resolveActivityScope; /** * Get user access credentials */ private getUserAccess; /** * Initialize logging service */ private initializeLogService; /** * Validate cache tag exists in product and return cache configuration * Uses local in-memory cache to avoid repeated API calls (5 minute TTL) */ private validateCache; /** * Create a new session * * @param internal - For internal use by `refresh()`: lets it reuse the bootstrap it already * fetched (instead of fetching again) and tags the write as a token rotation so the backend * validates the previous refresh token atomically as part of the same write. */ create(options: ICreateSessionOptions, internal?: { bootstrap?: IBootstrapSessionResponse; previousRefreshToken?: string; }): Promise; /** * Refresh an existing session */ refresh(options: IRefreshSessionOptions): Promise; /** * Verify a session token */ verify(options: IVerifySessionOptions): Promise; /** * Revoke a session */ revoke(options: IRevokeSessionOptions): Promise; /** * List active sessions */ list(options: IListSessionsOptions): Promise; /** * Define a new session schema */ define(options: IDefineSessionOptions): Promise; /** * Register a defined session with a product */ register(product: string, session: IDefinedSession): Promise; /** * Fetch paginated session users * * @example * ```ts * const users = await sessions.fetchUsers({ * product: 'my-product', * session: 'user-session', * env: 'production', * page: 1, * limit: 20, * }); * ``` */ fetchUsers(options: IFetchSessionUsersOptions): Promise; /** * Fetch detailed information about a single session user * * @example * ```ts * const userDetails = await sessions.fetchUserDetails({ * product: 'my-product', * session: 'user-session', * identifier: 'user@example.com', * env: 'production', * }); * ``` */ fetchUserDetails(options: IFetchSessionUserDetailsOptions): Promise; /** * Fetch paginated session activity logs * * @example * ```ts * const logs = await sessions.fetchActivityLogs({ * product: 'my-product', * session: 'user-session', * env: 'production', * status: 'success', * page: 1, * limit: 20, * }); * ``` */ fetchActivityLogs(options: IFetchSessionActivityLogsOptions): Promise; /** * Fetch session dashboard metrics * * @example * ```ts * const dashboard = await sessions.fetchDashboard({ * product: 'my-product', * session: 'user-session', * env: 'production', * }); * ``` */ fetchDashboard(options: IFetchSessionDashboardOptions): Promise; /** * Fetch user-specific dashboard metrics * * @example * ```ts * const userDashboard = await sessions.fetchUserDashboard({ * product: 'my-product', * session: 'user-session', * identifier: 'user@example.com', * env: 'production', * }); * ``` */ fetchUserDashboard(options: IFetchUserDashboardOptions): Promise; } export default SessionsService;