diff --git a/packages/scout/src/parsers.ts b/packages/scout/src/parsers.ts index 364512b..6537d1a 100644 --- a/packages/scout/src/parsers.ts +++ b/packages/scout/src/parsers.ts @@ -26,7 +26,7 @@ const definitions = [ } ] -function render(template: string, values: ) { +function render(template: string, values: any) { // console.log(`values=${values}`) // console.log(values) return template.replace(/:([a-zA-Z0-9_]+)/g, (match, key) => { @@ -57,14 +57,19 @@ function render(template: string, values: ) { export async function checkEmail (body: string): Promise { const mail = await simpleParser(body) + if (!mail) throw new Error('mail object was unable to be gathered from simpleParser'); + if (!mail.from) throw new Error('mail.from was empty'); + if (!mail.from.value) throw new Error('mail.from.value was empty'); + if (!mail.from.value[0]) throw new Error('mail.from.value[0] was empty'); + if (!mail.date) throw new Error('mail.date was empty'); if (!mail?.html) { console.log(`mail.html was not truthy. This means the e-mail was text-only mode. This also means the e-mail is not a go-live notification.`); return { isMatch: false } } - let res = {} - let def = definitions.find((def) => def.from === mail.from.value[0].address) - if (!def) return { isMatch: false, channel: null, platform: null, url: null }; + let res: Record = {} + let def: any = definitions.find((def) => def.from === mail.from!.value[0]!.address) + if (!def) return { isMatch: false, channel: null, platform: undefined, url: undefined }; res.isMatch = true // Step 0, get values from e-mail metadata @@ -85,8 +90,8 @@ export async function checkEmail (body: string): Promise { if (def.regex && res.url) return def.regex.exec(res.url).at(1); })() - res.userId = res.userId || null - res.avatar = res.avatar || null + res.userId = res.userId || undefined + res.avatar = res.avatar || undefined res.url = res.url || render(def.template, { channel: res.channel })