import { isObject } from '@emprespresso/pengueno'; export interface Email { from: string; to: string; subject: string; text: string; } export interface EmailCredentials { email: string; username: string; password: string; } export const isCreds = (u: unknown): u is EmailCredentials => !!( isObject(u) && ['email', 'username', 'password'].every((key) => key in u && typeof u[key as keyof typeof u] === 'string') ); export interface EmailSendInstruction extends EmailCredentials { send_host: string; send_port: number; } export const isSend = (u: unknown): u is EmailSendInstruction => !!( isCreds(u) && 'send_host' in u && typeof u.send_host === 'string' && 'send_port' in u && typeof u.send_port === 'number' ); export interface EmailRecvInstruction extends EmailCredentials { read_host: string; read_port: number; } export const isRecv = (u: unknown): u is EmailSendInstruction => !!( isCreds(u) && 'read_host' in u && typeof u.read_host === 'string' && 'read_port' in u && typeof u.read_port === 'number' ); export interface EmailJob { from: EmailSendInstruction; to: EmailRecvInstruction; readRetry: Retry; } export const isEmailJob = (u: unknown): u is EmailJob => !!( isObject(u) && 'from' in u && isSend(u.from) && 'to' in u && isRecv(u.to) && 'readRetry' in u && isRetry(u.readRetry) ); export interface Retry { attempts: number; interval: number; } export const isRetry = (u: unknown): u is Retry => !!( isObject(u) && ['attempts', 'interval'].every((key) => key in u && typeof u[key as keyof typeof u] === 'number') ); export const redact = (instruction: T): T => ({ ...instruction, password: 'REDACTED', username: 'REDACTED', }); export const redactJob = (job: EmailJob): EmailJob => ({ ...job, from: redact(job.from), to: redact(job.to), });