diff --git a/src/api.ts b/src/api.ts index 946826b..6f7db38 100644 --- a/src/api.ts +++ b/src/api.ts @@ -1,6 +1,6 @@ import { perform } from "./email"; import { redactJob, type EmailJob } from "./job"; -import { ConsoleLogger } from "./logger"; +import { ConsoleLogger, type Logger } from "./logger"; export const main = (port: number) => { const server = Bun.serve({ @@ -14,27 +14,32 @@ export const main = (port: number) => { const jobInsensitive = redactJob(job); const uuid = crypto.randomUUID(); - ConsoleLogger.info( - `[${uuid}] Received email job: ${JSON.stringify(jobInsensitive)}`, + const logger: Logger = { + info: (message) => ConsoleLogger.info(`[${uuid}] ${message}`), + warn: (message) => ConsoleLogger.warn(`[${uuid}] ${message}`), + error: (message) => ConsoleLogger.error(`[${uuid}] ${message}`), + } + logger.info( + `Received email job: ${JSON.stringify(jobInsensitive)}`, )(); - const performEmailTest = perform(job)(); + const performEmailTest = perform(job, undefined, logger)(); return performEmailTest .then((result) => { if (result._tag === "Left") { const error = result.left; - ConsoleLogger.warn( - `[${uuid}] job failure due to ${error.message}`, + logger.warn( + `job failure due to ${error.message}`, )(); return new Response(error.message, { status: 400, }); } - ConsoleLogger.info(`[${uuid}] success`)(); + logger.info('success')(); return Response.json({ success: true }); }) .catch((e) => { - ConsoleLogger.error(`[${uuid}] internal failure due to ${e}`)(); + logger.error(`internal failure due to ${e}`)(); return new Response(e.message, { status: 500, }); diff --git a/src/email.ts b/src/email.ts index b822cd9..328afab 100644 --- a/src/email.ts +++ b/src/email.ts @@ -3,7 +3,7 @@ import * as TE from "fp-ts/lib/TaskEither"; import * as O from "fp-ts/lib/Option"; import { createTransport } from "nodemailer"; import { toError } from "fp-ts/lib/Either"; -import { flow, pipe } from "fp-ts/lib/function"; +import { pipe } from "fp-ts/lib/function"; import { ImapFlow, type FetchMessageObject,