From 4c5f7c45d39366a930e79c95cee0afd8f02f0e68 Mon Sep 17 00:00:00 2001 From: Andrew Heberle Date: Mon, 8 Jan 2024 12:18:41 +0800 Subject: [PATCH] Add extra types --- index.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/index.ts b/index.ts index efda83a..660eb11 100644 --- a/index.ts +++ b/index.ts @@ -22,6 +22,11 @@ type EmailFieldValidatons = { [index: string]: string | string[] } +type MailgunResponse = { + message: string + id: string +} + function dataValid(config: EmailConfig, country: string, formData: FormData) { // check country is valid if (config.allowed_countries !== undefined) { @@ -93,7 +98,7 @@ function fieldValid(value: string, validation: string | string[]) { return false } -async function mailgunSend(config: EmailConfig, formData: FormData, user: Boolean = false) { +async function mailgunSend(config: EmailConfig, formData: FormData, user: Boolean = false):Promise { const org = config.org const to = user ? `${formData.get('name')} <${formData.get('email')}>` : config.admin_email const from = `${config.org} <${config.from}>` @@ -258,7 +263,7 @@ export async function HandlePost(context) { const response = await mailgunSend(config, formData, true) if (!response.ok) { - const json = await response.json() + const json:MailgunResponse = await response.json() throw json.message ?? 'unknown mailgun api error' } } catch (err) { @@ -272,7 +277,7 @@ export async function HandlePost(context) { const response = await mailgunSend(config, formData, false) if (!response.ok) { - const json = await response.json() + const json:MailgunResponse = await response.json() throw json.message ?? 'unknown mailgun api error' } } catch (err) {