From 80d77c37cee28ebb5c713618469b436971001f3e Mon Sep 17 00:00:00 2001 From: tngzixiang Date: Wed, 3 Jan 2024 18:32:42 +0800 Subject: [PATCH] chore: use esm export --- .eslintrc | 4 +++- src/email/index.js | 14 ++++++-------- src/storage/create.js | 6 +----- src/storage/createAtId.js | 6 +----- src/storage/get.js | 6 +----- src/storage/queueNumber.js | 6 +----- src/verify/index.js | 17 ++++++----------- 7 files changed, 19 insertions(+), 40 deletions(-) diff --git a/.eslintrc b/.eslintrc index 8f8c05d..6ca7e84 100644 --- a/.eslintrc +++ b/.eslintrc @@ -15,6 +15,8 @@ "func-names": ["error", "as-needed"], "prettier/prettier": "error", "no-unused-expressions": "off", - "import/no-import-module-exports": "off" + "import/no-import-module-exports": "off", + "import/prefer-default-export": "off" + } } diff --git a/src/email/index.js b/src/email/index.js index 522bb83..3e45053 100644 --- a/src/email/index.js +++ b/src/email/index.js @@ -18,7 +18,7 @@ const validateApiKey = (key) => { throw new Error("Invalid API key"); }; -const handleEmail = async (event, _context, callback) => { +const handleEmail = async (event) => { try { const { to, data, captcha } = JSON.parse(event.body); @@ -50,18 +50,16 @@ const handleEmail = async (event, _context, callback) => { // Send certificate out await certificateMailer({ to, certificate: data }); - callback(null, { + return { statusCode: 200, body: JSON.stringify({ success: true }) - }); + }; } catch (e) { - callback(null, { + return { statusCode: 400, body: JSON.stringify({ error: e.message }) - }); + }; } }; -const handler = middy().use(cors()).handler(handleEmail); - -module.exports = { handler }; +export const handler = middy().use(cors()).handler(handleEmail); diff --git a/src/storage/create.js b/src/storage/create.js index 6298dee..0295fb3 100644 --- a/src/storage/create.js +++ b/src/storage/create.js @@ -28,8 +28,4 @@ const handleCreate = async (event) => { } }; -const handler = middy().use(cors()).handler(handleCreate); - -module.exports = { - handler -}; +export const handler = middy().use(cors()).handler(handleCreate); diff --git a/src/storage/createAtId.js b/src/storage/createAtId.js index dd1258d..89f24d7 100644 --- a/src/storage/createAtId.js +++ b/src/storage/createAtId.js @@ -31,8 +31,4 @@ const handleCreateAtId = async (event) => { } }; -const handler = middy().use(cors()).handler(handleCreateAtId); - -module.exports = { - handler -}; +export const handler = middy().use(cors()).handler(handleCreateAtId); diff --git a/src/storage/get.js b/src/storage/get.js index a6d7335..04eff7d 100644 --- a/src/storage/get.js +++ b/src/storage/get.js @@ -22,8 +22,4 @@ const handleGet = async (event) => { } }; -const handler = middy().use(cors()).handler(handleGet); - -module.exports = { - handler -}; +export const handler = middy().use(cors()).handler(handleGet); diff --git a/src/storage/queueNumber.js b/src/storage/queueNumber.js index 57f2ef5..bf335e8 100644 --- a/src/storage/queueNumber.js +++ b/src/storage/queueNumber.js @@ -18,8 +18,4 @@ const handleQueueNumber = async () => { } }; -const handler = middy().use(cors()).handler(handleQueueNumber); - -module.exports = { - handler -}; +export const handler = middy().use(cors()).handler(handleQueueNumber); diff --git a/src/verify/index.js b/src/verify/index.js index f813dcc..0c6a86d 100644 --- a/src/verify/index.js +++ b/src/verify/index.js @@ -4,12 +4,11 @@ import cors from "@middy/http-cors"; const { verify, isValid } = require("@govtechsg/opencerts-verify"); const config = require("./config"); -// adding a comment to trigger a deploy -const handleVerify = async (event, _context, callback) => { +const handleVerify = async (event) => { const { document } = JSON.parse(event.body); try { const fragments = await verify({ network: config.network })(document); - callback(null, { + return { statusCode: 200, headers: { "Content-Type": "application/json" }, body: JSON.stringify({ @@ -21,17 +20,13 @@ const handleVerify = async (event, _context, callback) => { }, data: fragments }) - }); + }; } catch (e) { - callback(null, { + return { statusCode: 400, body: e.message - }); + }; } }; -const handler = middy().use(cors()).handler(handleVerify); - -module.exports = { - handler -}; +export const handler = middy().use(cors()).handler(handleVerify);