Add auth service, storage service, types, and logging middleware

- Auth service: hashPassword/verifyPassword via bcrypt
- Storage service: saveFile, getFilePath, deleteStoredFile with ENOENT handling
- Types: JwtPayload interface
- Logging middleware: createLogger writing AUTH_FAILURE, AUTH_SUCCESS, FILE_NOT_FOUND
- 27 tests passing

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-03 15:49:22 -08:00
parent b6aa6211a9
commit 157d1e8230
6 changed files with 178 additions and 0 deletions

21
src/services/storage.ts Normal file
View File

@@ -0,0 +1,21 @@
import { writeFile, unlink } from 'fs/promises';
import { join } from 'path';
export async function saveFile(uploadDir: string, storedName: string, data: Buffer): Promise<string> {
await writeFile(join(uploadDir, storedName), data);
return storedName;
}
export function getFilePath(uploadDir: string, storedName: string): string {
return join(uploadDir, storedName);
}
export async function deleteStoredFile(uploadDir: string, storedName: string): Promise<void> {
try {
await unlink(join(uploadDir, storedName));
} catch (err: unknown) {
if ((err as NodeJS.ErrnoException).code !== 'ENOENT') {
throw err;
}
}
}