-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add email package for email templating (#24)
- Loading branch information
1 parent
a055338
commit a762eaa
Showing
21 changed files
with
1,770 additions
and
93 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
auto-install-peers = true | ||
enable-pre-post-scripts=true | ||
public-hoist-pattern[]=*storybook* |
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,33 @@ | ||
import * as fs from 'fs-extra'; | ||
import * as path from 'path'; | ||
import * as url from 'node:url'; | ||
|
||
const __filename = url.fileURLToPath(import.meta.url); | ||
const __dirname = path.dirname(__filename); | ||
|
||
const rootDir = '../../..'; | ||
const emailDir = '/packages/email/src/templates/static'; | ||
const engineDir = '/apps/engine/public/static/email'; | ||
|
||
const staticSrcDir = path.join(__dirname, `${rootDir}${emailDir}`); | ||
const staticDestDir = path.join(__dirname, `${rootDir}${engineDir}`); | ||
|
||
async function copyStaticFiles() { | ||
try { | ||
await fs.ensureDir(staticDestDir); | ||
await fs.copy(staticSrcDir, staticDestDir); | ||
console.log(` | ||
✨ Email static files copied successfully. | ||
📄 Summary: | ||
${emailDir} ➡️ ${engineDir} | ||
`); | ||
} catch (err) { | ||
console.error('💥 Error copying email static files:', err); | ||
} | ||
} | ||
|
||
async function main() { | ||
await copyStaticFiles(); | ||
} | ||
|
||
main(); |
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,62 @@ | ||
import type { NextRequest } from 'next/server'; | ||
import { NextResponse } from 'next/server'; | ||
import { serverEnv } from '@/env/server-env'; | ||
import { SignUpEmail } from '@ds-project/email/src/templates/sign-up'; | ||
import { Resend } from '@ds-project/email/src/resend'; | ||
import { render } from '@ds-project/email/src/render'; | ||
import { config } from '@/config'; | ||
import { Webhook } from 'standardwebhooks'; | ||
|
||
const resend = new Resend(serverEnv.RESEND_API_KEY); | ||
|
||
export async function POST(request: NextRequest) { | ||
const wh = new Webhook(serverEnv.SEND_EMAIL_HOOK_SECRET); | ||
const payload = await request.text(); | ||
const headers = Object.fromEntries(request.headers); | ||
|
||
try { | ||
const { | ||
user, | ||
email_data: { token }, | ||
} = wh.verify(payload, headers) as { | ||
user: { | ||
email: string; | ||
}; | ||
email_data: { | ||
token: string; | ||
}; | ||
}; | ||
|
||
const html = await render( | ||
<SignUpEmail | ||
otpCode={token} | ||
staticPathUrl={`${config.pageUrl}/static/email`} | ||
/> | ||
); | ||
|
||
const { error } = await resend.emails.send({ | ||
from: 'DS Pro <[email protected]>', | ||
to: [user.email], | ||
subject: 'DS Pro - Confirmation Code', | ||
html, | ||
}); | ||
|
||
if (error) { | ||
throw error; | ||
} | ||
} catch (error) { | ||
return NextResponse.json( | ||
{ error }, | ||
{ | ||
status: 401, | ||
} | ||
); | ||
} | ||
|
||
return NextResponse.json( | ||
{}, | ||
{ | ||
status: 200, | ||
} | ||
); | ||
} |
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,11 @@ | ||
import baseConfig from '@ds-project/eslint/base'; | ||
import reactConfig from '@ds-project/eslint/react'; | ||
|
||
/** @type {import('typescript-eslint').Config} */ | ||
export default [ | ||
{ | ||
ignores: ['dist/**'], | ||
}, | ||
...baseConfig, | ||
...reactConfig, | ||
]; |
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,29 @@ | ||
{ | ||
"name": "@ds-project/email", | ||
"private": true, | ||
"keywords": [], | ||
"license": "ISC", | ||
"author": "", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "email dev --dir ./templates", | ||
"format": "prettier --check . --ignore-path ../../.gitignore --ignore-path ../../.prettierignore", | ||
"lint": "eslint", | ||
"type-check": "tsc --noEmit --emitDeclarationOnly false" | ||
}, | ||
"prettier": "@ds-project/prettier", | ||
"dependencies": { | ||
"@react-email/components": "0.0.24", | ||
"@react-email/render": "^1.0.1", | ||
"react": "catalog:", | ||
"resend": "^4.0.0" | ||
}, | ||
"devDependencies": { | ||
"@ds-project/eslint": "workspace:*", | ||
"@ds-project/prettier": "workspace:*", | ||
"@ds-project/typescript": "workspace:*", | ||
"@types/react": "catalog:", | ||
"eslint": "catalog:", | ||
"react-email": "3.0.1" | ||
} | ||
} |
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 @@ | ||
export { render } from '@react-email/components'; |
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 @@ | ||
export * from 'resend'; |
Oops, something went wrong.