Skip to content

Commit

Permalink
Add extra types
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewheberle committed Jan 8, 2024
1 parent 8dfb3e1 commit 4c5f7c4
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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<Response> {
const org = config.org
const to = user ? `${formData.get('name')} <${formData.get('email')}>` : config.admin_email
const from = `${config.org} <${config.from}>`
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit 4c5f7c4

Please sign in to comment.