fix(mail): migrate filesystem helpers to fsUtils, update DKIM and mail APIs, harden SMTP client, and bump dependencies
This commit is contained in:
@@ -93,3 +93,71 @@ export {
|
||||
uuid,
|
||||
ip,
|
||||
}
|
||||
|
||||
// Filesystem utilities (compatibility helpers for smartfile v13+)
|
||||
export const fsUtils = {
|
||||
/**
|
||||
* Ensure a directory exists, creating it recursively if needed (sync)
|
||||
*/
|
||||
ensureDirSync: (dirPath: string): void => {
|
||||
fs.mkdirSync(dirPath, { recursive: true });
|
||||
},
|
||||
|
||||
/**
|
||||
* Ensure a directory exists, creating it recursively if needed (async)
|
||||
*/
|
||||
ensureDir: async (dirPath: string): Promise<void> => {
|
||||
await fs.promises.mkdir(dirPath, { recursive: true });
|
||||
},
|
||||
|
||||
/**
|
||||
* Write JSON content to a file synchronously
|
||||
*/
|
||||
toFsSync: (content: any, filePath: string): void => {
|
||||
const data = typeof content === 'string' ? content : JSON.stringify(content, null, 2);
|
||||
fs.writeFileSync(filePath, data);
|
||||
},
|
||||
|
||||
/**
|
||||
* Write JSON content to a file asynchronously
|
||||
*/
|
||||
toFs: async (content: any, filePath: string): Promise<void> => {
|
||||
const data = typeof content === 'string' ? content : JSON.stringify(content, null, 2);
|
||||
await fs.promises.writeFile(filePath, data);
|
||||
},
|
||||
|
||||
/**
|
||||
* Check if a file or directory exists
|
||||
*/
|
||||
fileExistsSync: (filePath: string): boolean => {
|
||||
return fs.existsSync(filePath);
|
||||
},
|
||||
|
||||
/**
|
||||
* Check if a file or directory exists (async)
|
||||
*/
|
||||
fileExists: async (filePath: string): Promise<boolean> => {
|
||||
try {
|
||||
await fs.promises.access(filePath);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Read a JSON file synchronously
|
||||
*/
|
||||
toObjectSync: <T = any>(filePath: string): T => {
|
||||
const content = fs.readFileSync(filePath, 'utf8');
|
||||
return JSON.parse(content) as T;
|
||||
},
|
||||
|
||||
/**
|
||||
* Read a JSON file asynchronously
|
||||
*/
|
||||
toObject: async <T = any>(filePath: string): Promise<T> => {
|
||||
const content = await fs.promises.readFile(filePath, 'utf8');
|
||||
return JSON.parse(content) as T;
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user