UNPKG

@mbc-cqrs-serverless/core

Version:
58 lines (57 loc) 2.74 kB
import { ConfigService } from '@nestjs/config'; import { DynamoDbService } from './dynamodb.service'; import { SessionItem } from './session.interface'; export declare class SessionService { private readonly dynamoDbService; private readonly config; private readonly logger; private readonly sessionTableName; private readonly ttlSeconds; /** When unset or invalid, session rows are not written (RYW read path still works on empty). */ private readonly sessionWritesEnabled; constructor(dynamoDbService: DynamoDbService, config: ConfigService); /** * Build session pk: {userId}#{tenantCode} */ private buildPk; /** * Build session sk: {moduleTableName}#{itemId} */ private buildSk; private calculateTtl; /** * Write a session entry after a successful async command publish. * Called by CommandService after publishAsync only. * No-ops when RYW session TTL is not configured (`sessionWritesEnabled` is false). */ put(userId: string, tenantCode: string, moduleTableName: string, itemId: string, version: number): Promise<void>; /** * Get a single session entry for a specific item. * Returns `null` without querying DynamoDB when session writes are disabled. */ get(userId: string, tenantCode: string, moduleTableName: string, itemId: string): Promise<SessionItem | null>; /** * Delete a session entry. * Used to clean up the session once the data table has caught up to the command version. */ delete(userId: string, tenantCode: string, moduleTableName: string, itemId: string): Promise<void>; /** * List session entries for a user scoped to a command module. * * Queries the session table by `{userId}#{tenantCode}` and filters to entries * whose sort key begins with `{moduleTableName}#`, returning only sessions * that belong to the given module. * * @param userId - The ID of the requesting user (from JWT `sub` claim). * @param tenantCode - The tenant the user is operating under. * @param moduleTableName - The `tableName` from `CommandModuleOptions` — used * as the sort key prefix to scope results to a single command module. * @param limit - Maximum number of session entries to fetch. Defaults to * `MAX_SESSION_ENTRIES` to prevent silent truncation from the underlying * DynamoDB query's default limit of 10. Callers should rarely need to * override this. * @returns The matching session entries, or an empty array if none exist or * session writes are disabled. */ listByUser(userId: string, tenantCode: string, moduleTableName: string, limit?: number): Promise<SessionItem[]>; }