1import fs from 'fs'2import nodemailer from 'nodemailer'3import { getEnvConfOpt } from '../envConfF.mts'4import { calcReqHash } from '../calcHashF.mts'5import { withTimeout } from '../../sharedF/sleepF.mts'6import { ensureTmpDirExists, ptTmpDir } from '../ptDiskF/ptDiskF.mts'7import { readJsonIfExist } from '../libFs/readJsonIfExistF.mts'8import { pathDownJoin } from '../pathF.mts'10export const getAppName = () => getEnvConfOpt()?.appname ?? 'unknown'12const getEtherealJsonPath = () => pathDownJoin(ptTmpDir, `${calcReqHash(getAppName() as string)}-ethereal.json`)14export const clearEtherealCreds = () => {15 fs.rmSync(getEtherealJsonPath())16}18export const getCachedEtherealCreds = async () => {19 const path = getEtherealJsonPath()21 const readJson = await readJsonIfExist(path)22 if (readJson) return readJson24 const newCreds = await withTimeout(nodemailer.createTestAccount(), 15_000)26 await ensureTmpDirExists()27 fs.writeFileSync(path, JSON.stringify(newCreds))29 return newCreds30}