webssh2-server
Version:
A Websocket to SSH2 gateway using xterm.js, socket.io, ssh2
65 lines (64 loc) • 2.76 kB
JavaScript
// server
// app/utils.ts
/**
* Central barrel export for utility functions and validators.
*
* Organized by category:
* - Cryptography utilities
* - Object manipulation utilities
* - SSH validation utilities
* - Credential validation utilities
* - Environment variable utilities
* - Helper functions
*/
// ============================================================================
// Cryptography Utilities
// ============================================================================
/**
* Generate cryptographically secure random secrets.
*/
export { generateSecureSecret } from './utils/crypto.js';
// ============================================================================
// Object Manipulation Utilities
// ============================================================================
/**
* Deep merge objects without mutation (pure function).
*/
export { deepMergePure as deepMerge } from './utils/object-merger.js';
// ============================================================================
// SSH Validation Utilities
// ============================================================================
/**
* Validate and normalize SSH connection parameters.
* - getValidatedHost: Validate SSH host
* - getValidatedPort: Validate SSH port
* - validateSshTerm: Validate terminal type
*/
export { validateHost as getValidatedHost, validatePort as getValidatedPort, validateTerm as validateSshTerm } from './validation/ssh.js';
// ============================================================================
// Credential Validation Utilities
// ============================================================================
/**
* Validate SSH credentials structure and completeness.
*/
export { isValidCredentials } from './validation/credentials.js';
// ============================================================================
// Environment Variable Utilities
// ============================================================================
/**
* Validate and parse environment variables.
* - isValidEnvKey: Check if environment key is valid
* - isValidEnvValue: Check if environment value is valid
* - parseEnvVars: Parse environment variables from string
*/
export { isValidEnvKey, isValidEnvValue, parseEnvVars } from './validation/environment.js';
// ============================================================================
// Helper Functions
// ============================================================================
/**
* Pick first non-empty field, treating empty string as missing.
* Falls back to second value if first is null, undefined, or empty string.
*/
export function pickField(primary, fallback) {
return primary != null && primary !== '' ? primary : (fallback ?? undefined);
}