feat(#89): implement COMMAND message type for federation
Implements federated command messages following TDD principles and mirroring the QueryService pattern for consistency. ## Implementation ### Schema Changes - Added commandType and payload fields to FederationMessage model - Supports COMMAND message type (already defined in enum) - Applied schema changes with prisma db push ### Type Definitions - CommandMessage: Request structure with commandType and payload - CommandResponse: Response structure with correlation - CommandMessageDetails: Full message details for API responses ### CommandService - sendCommand(): Send command to remote instance with signature - handleIncomingCommand(): Process incoming commands with verification - processCommandResponse(): Handle command responses - getCommandMessages(): List commands for workspace - getCommandMessage(): Get single command details - Full signature verification and timestamp validation - Error handling and status tracking ### CommandController - POST /api/v1/federation/command - Send command (authenticated) - POST /api/v1/federation/incoming/command - Handle incoming (public) - GET /api/v1/federation/commands - List commands (authenticated) - GET /api/v1/federation/commands/:id - Get command (authenticated) ## Testing - CommandService: 15 tests, 90.21% coverage - CommandController: 8 tests, 100% coverage - All 23 tests passing - Exceeds 85% coverage requirement - Total 47 tests passing (includes command tests) ## Security - RSA signature verification for all incoming commands - Timestamp validation to prevent replay attacks - Connection status validation - Authorization checks on command types ## Quality Checks - TypeScript compilation: PASSED - All tests: 47 PASSED - Code coverage: >85% (90.21% for CommandService, 100% for CommandController) - Linting: PASSED Fixes #89 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
54
apps/api/src/federation/dto/command.dto.ts
Normal file
54
apps/api/src/federation/dto/command.dto.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* Command DTOs
|
||||
*
|
||||
* Data Transfer Objects for command message operations.
|
||||
*/
|
||||
|
||||
import { IsString, IsObject, IsNotEmpty, IsNumber } from "class-validator";
|
||||
import type { CommandMessage } from "../types/message.types";
|
||||
|
||||
/**
|
||||
* DTO for sending a command to a remote instance
|
||||
*/
|
||||
export class SendCommandDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
connectionId!: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
commandType!: string;
|
||||
|
||||
@IsObject()
|
||||
@IsNotEmpty()
|
||||
payload!: Record<string, unknown>;
|
||||
}
|
||||
|
||||
/**
|
||||
* DTO for incoming command request from remote instance
|
||||
*/
|
||||
export class IncomingCommandDto implements CommandMessage {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
messageId!: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
instanceId!: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
commandType!: string;
|
||||
|
||||
@IsObject()
|
||||
@IsNotEmpty()
|
||||
payload!: Record<string, unknown>;
|
||||
|
||||
@IsNumber()
|
||||
@IsNotEmpty()
|
||||
timestamp!: number;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
signature!: string;
|
||||
}
|
||||
Reference in New Issue
Block a user