Add input validation to connectToService()

Validation: Add checks for empty strings in connectToService()
- Validates serviceFqn is not empty string
- Validates service is not empty string
- Validates username is not empty string
- Prevents silent failures from whitespace-only inputs

Impact: Better error messages for invalid inputs
This commit is contained in:
2025-12-12 22:51:58 +01:00
parent a9a0127ccf
commit c662161cd9

View File

@@ -548,6 +548,17 @@ export class Rondevu {
async connectToService(options: ConnectToServiceOptions): Promise<ConnectionContext> {
const { serviceFqn, service, username, onConnection, rtcConfig } = options
// Validate inputs
if (serviceFqn !== undefined && typeof serviceFqn === 'string' && !serviceFqn.trim()) {
throw new Error('serviceFqn cannot be empty')
}
if (service !== undefined && typeof service === 'string' && !service.trim()) {
throw new Error('service cannot be empty')
}
if (username !== undefined && typeof username === 'string' && !username.trim()) {
throw new Error('username cannot be empty')
}
// Determine the full service FQN
let fqn: string
if (serviceFqn) {