-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #611 from desci-labs/develop
promote main
- Loading branch information
Showing
11 changed files
with
291 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import sgMail from '@sendgrid/mail'; | ||
|
||
import { logger as parentLogger } from '../logger.js'; | ||
import { DoiMintedEmailHtml } from '../templates/emails/utils/emailRenderer.js'; | ||
|
||
export enum EmailTypes { | ||
DoiMinted, | ||
DOI_REGISTRATION_REQUESTED, | ||
} | ||
|
||
type DoiRegisteredPayload = { | ||
type: EmailTypes.DoiMinted; | ||
payload: { to: string; name: string; title: string; dpid: string; doi: string }; | ||
}; | ||
|
||
type DoiRequestedPayload = { | ||
type: EmailTypes.DOI_REGISTRATION_REQUESTED; | ||
payload: { to: string; subject: string; name: string }; | ||
}; | ||
|
||
export type EmailProps = DoiRegisteredPayload | DoiRequestedPayload; | ||
|
||
const logger = parentLogger.child({ module: 'EmailService' }); | ||
|
||
export function assertNever(value: never) { | ||
console.error('Unknown value', value); | ||
throw Error('Not Possible'); | ||
} | ||
|
||
async function sendDoiRegisteredEmail({ to, name, title, dpid, doi }: DoiRegisteredPayload['payload']) { | ||
const message = { | ||
to, | ||
from: 'no-reply@desci.com', | ||
subject: 'DOI Registration successful 🎉', | ||
text: `Hello ${name}, You DOI registration for the research object ${title} has been completed. Here is your DOI: ${process.env.CROSSREF_DOI_URL}/${doi}`, | ||
html: DoiMintedEmailHtml({ | ||
dpid, | ||
doi, | ||
nodeTitle: title, | ||
userName: name.split(' ')?.[0] ?? '', | ||
dpidPath: `${process.env.DAPP_URL}/dpid/${dpid}`, | ||
doiLink: `${process.env.CROSSREF_DOI_URL}/${doi}`, | ||
}), | ||
}; | ||
|
||
try { | ||
if (process.env.NODE_ENV === 'production') { | ||
const response = await sgMail.send(message); | ||
logger.trace(response, '[EMAIL]:: Response'); | ||
} else { | ||
logger.info({ nodeEnv: process.env.NODE_ENV }, message.subject); | ||
} | ||
} catch (err) { | ||
logger.error({ err }, '[ERROR]:: DOI MINTED EMAIL'); | ||
} | ||
} | ||
|
||
async function sendDoiRequested(payload: DoiRequestedPayload['payload']) { | ||
// | ||
} | ||
|
||
export const sendEmail = async (props: EmailProps) => { | ||
switch (props.type) { | ||
case EmailTypes.DoiMinted: | ||
return sendDoiRegisteredEmail(props.payload); | ||
case EmailTypes.DOI_REGISTRATION_REQUESTED: | ||
return sendDoiRequested(props.payload); | ||
default: | ||
assertNever(props); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Nodes Lib Tests", | ||
"type": "node", | ||
"request": "attach", | ||
"restart": true, | ||
"port": 9229, | ||
"address": "localhost", | ||
"localRoot": "${workspaceFolder}" | ||
} | ||
] | ||
} |
Oops, something went wrong.