/** * Sessions Types */ /** * Session service configuration */ export interface ISessionServiceConfig { workspace_id: string; public_key: string; user_id: string; token: string; env_type: string; redis_client?: any; access_key?: string; /** Workspace private key for encrypting log data. When set, LogsService encrypts log payloads. */ workspace_private_key?: string; /** From Ductape constructor — inherited when product/env omitted on calls */ default_product?: string; default_env?: string; } /** * Create session options */ export interface ICreateSessionOptions { product: string; env: string; tag: string; data: Record; /** Optional cache tag for caching the result */ cache?: string; } /** * Refresh session options */ export interface IRefreshSessionOptions { product: string; env: string; tag: string; refreshToken: string; /** Optional cache tag for caching the result */ cache?: string; } /** * Verify session options */ export interface IVerifySessionOptions { product: string; env: string; tag: string; token: string; /** Optional cache tag for caching the result */ cache?: string; } /** * Revoke session options */ export interface IRevokeSessionOptions { product: string; env: string; tag: string; sessionId?: string; identifier?: string; } /** * List sessions options */ export interface IListSessionsOptions { product: string; env: string; tag: string; identifier?: string; page?: number; limit?: number; /** Optional cache tag for caching the result */ cache?: string; } /** * Session result */ export interface ISessionResult { token: string; refreshToken: string; expiresAt?: Date; sessionId?: string; } /** * Verify session result */ export interface IVerifyResult { valid: boolean; data?: Record; sessionId?: string; expiresAt?: Date; } /** * Session info */ export interface ISessionInfo { sessionId: string; identifier: string; startAt: Date; endAt: Date; sessionTag: string; active: boolean; } /** * List sessions result */ export interface IListSessionsResult { sessions: ISessionInfo[]; total: number; page: number; limit: number; } /** * Session schema definition */ export interface ISessionSchema { tag: string; name?: string; description?: string; selector: string; expiry: number; period: 'seconds' | 'minutes' | 'hours' | 'days'; schemaData: Record; } /** * Session schema field */ export interface ISessionSchemaField { type: 'string' | 'number' | 'boolean' | 'object' | 'array'; required?: boolean; description?: string; } /** * Define session options */ export interface IDefineSessionOptions { product: string; tag: string; name?: string; description?: string; handler: (ctx: ISessionContext) => void | Promise; } /** * Session context for defining sessions */ export interface ISessionContext { selector(path: string): ISessionContext; expiry(value: number, period: 'seconds' | 'minutes' | 'hours' | 'days'): ISessionContext; schema(fields: Record): ISessionContext; } /** * Defined session result */ export interface IDefinedSession { tag: string; name?: string; description?: string; selector: string; expiry: number; period: 'seconds' | 'minutes' | 'hours' | 'days'; schemaData: Record; } /** * Session user information */ export interface ISessionUser { _id: string; ductape_user_id: string; product_tag: string; session_tag?: string; identifier: string; last_seen?: Date | null; env: string; first_seen?: Date | null; createdAt?: Date; updatedAt?: Date; } /** * Options for fetching paginated session users */ export interface IFetchSessionUsersOptions { product: string; session: string; env?: string; page?: number; limit?: number; } /** * Result for paginated session users */ export interface IFetchSessionUsersResult { users: ISessionUser[]; total: number; page: number; limit: number; totalPages: number; } /** * Options for fetching a single session user's details */ export interface IFetchSessionUserDetailsOptions { product: string; session: string; identifier: string; env?: string; } /** * Detailed session user result including session history */ export interface ISessionUserDetails extends ISessionUser { sessions: IUserSessionInfo[]; totalSessions: number; activeSessionsCount: number; } /** * User session info */ export interface IUserSessionInfo { session_id: string; start_at: Date; end_at?: Date; active: boolean; } /** * Session activity log entry */ export interface ISessionActivityLog { _id: string; process_id: string; product_tag: string; session_tag: string; parent_tag: string; env: string; type: string; message: string; status: 'success' | 'fail' | 'processing'; successful_execution: boolean; failed_execution: boolean; data?: string; start?: number; end?: number; timestamp: Date; } /** * Options for fetching paginated session activity logs */ export interface IFetchSessionActivityLogsOptions { product: string; session: string; env?: string; status?: 'success' | 'fail' | 'processing'; start?: string; end?: string; page?: number; limit?: number; } /** * Result for paginated session activity logs */ export interface IFetchSessionActivityLogsResult { logs: ISessionActivityLog[]; total: number; page: number; limit: number; totalPages: number; } /** * Session dashboard metrics */ export interface ISessionDashboardMetrics { totalUsers: number; activeUsers: number; inactiveUsers: number; expiredUsers: number; newUsersToday: number; newUsersThisWeek: number; totalSessions: number; activeSessions: number; averageSessionsPerUser: number; dau: { current: number; previous: number; change: number; }; wau: { current: number; previous: number; change: number; }; mau: { current: number; previous: number; change: number; }; activityTimeline: Array<{ date: string; sessions: number; }>; peakHours: Array<{ hour: string; count: number; }>; environmentBreakdown: Array<{ env: string; count: number; percentage: number; }>; avgSessionDuration: { current: string; previous: string; change: number; }; } /** * Options for fetching session dashboard data */ export interface IFetchSessionDashboardOptions { product: string; session: string; env?: string; } /** * Options for fetching user-specific dashboard data */ export interface IFetchUserDashboardOptions { product: string; session: string; identifier: string; env?: string; } /** * User-specific dashboard metrics */ export interface IUserDashboardMetrics { totalLogs: number; successRate: number; activityTimeline: Array<{ day: string; count: number; }>; peakHours: Array<{ hour: string; count: number; }>; }