@ossy/email 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/package.json +23 -0
- package/src/email-layout.jsx +67 -0
- package/src/email-renderer.js +10 -0
- package/src/email.integration.js +50 -0
- package/src/index.js +3 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
# 1.1.0 (2026-05-30)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **api:** implement new API endpoints for resource and user management ([cd565c0](https://github.com/ossy-se/ossy/commit/cd565c01170ac111f8fc55d8c26e6d5487d9fe08))
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ossy/email",
|
|
3
|
+
"private": false,
|
|
4
|
+
"version": "1.1.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./src/index.js",
|
|
7
|
+
"module": "./src/index.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./src/index.js"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"ossy": {
|
|
15
|
+
"src": "./src"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@aws-sdk/client-ses": "^3",
|
|
19
|
+
"react": "*",
|
|
20
|
+
"react-dom": "*"
|
|
21
|
+
},
|
|
22
|
+
"gitHead": "c6697078268867d88553ca0bac08faad5cea1546"
|
|
23
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const DEFAULT_THEME = {
|
|
2
|
+
primaryColor: '#111111',
|
|
3
|
+
backgroundColor: '#f5f5f5',
|
|
4
|
+
fontFamily: 'sans-serif',
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function EmailLayout({ children, theme = {} }) {
|
|
8
|
+
const t = { ...DEFAULT_THEME, ...theme }
|
|
9
|
+
|
|
10
|
+
return (
|
|
11
|
+
<html>
|
|
12
|
+
<head>
|
|
13
|
+
<meta charSet="utf-8" />
|
|
14
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
15
|
+
</head>
|
|
16
|
+
<body style={{ fontFamily: t.fontFamily, background: t.backgroundColor, margin: 0, padding: 0 }}>
|
|
17
|
+
<table width="100%" cellPadding={0} cellSpacing={0} style={{ padding: '40px 20px' }}>
|
|
18
|
+
<tbody>
|
|
19
|
+
<tr>
|
|
20
|
+
<td align="center">
|
|
21
|
+
<table width="600" cellPadding={0} cellSpacing={0} style={{ background: '#ffffff', borderRadius: 8, padding: 40 }}>
|
|
22
|
+
<tbody>
|
|
23
|
+
<tr>
|
|
24
|
+
<td>
|
|
25
|
+
{children}
|
|
26
|
+
</td>
|
|
27
|
+
</tr>
|
|
28
|
+
</tbody>
|
|
29
|
+
</table>
|
|
30
|
+
</td>
|
|
31
|
+
</tr>
|
|
32
|
+
</tbody>
|
|
33
|
+
</table>
|
|
34
|
+
</body>
|
|
35
|
+
</html>
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function EmailButton({ href, children, theme = {} }) {
|
|
40
|
+
const t = { ...DEFAULT_THEME, ...theme }
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<a
|
|
44
|
+
href={href}
|
|
45
|
+
style={{
|
|
46
|
+
display: 'inline-block',
|
|
47
|
+
background: t.primaryColor,
|
|
48
|
+
color: '#ffffff',
|
|
49
|
+
textDecoration: 'none',
|
|
50
|
+
padding: '12px 24px',
|
|
51
|
+
borderRadius: 6,
|
|
52
|
+
fontSize: 16,
|
|
53
|
+
fontFamily: t.fontFamily,
|
|
54
|
+
}}
|
|
55
|
+
>
|
|
56
|
+
{children}
|
|
57
|
+
</a>
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function EmailText({ children, style = {} }) {
|
|
62
|
+
return (
|
|
63
|
+
<p style={{ color: '#444444', fontSize: 16, lineHeight: 1.5, margin: '0 0 32px', ...style }}>
|
|
64
|
+
{children}
|
|
65
|
+
</p>
|
|
66
|
+
)
|
|
67
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { renderToStaticMarkup } from 'react-dom/server'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
|
|
4
|
+
export const EmailRenderer = {
|
|
5
|
+
render(Component, props) {
|
|
6
|
+
const html = renderToStaticMarkup(React.createElement(Component, props))
|
|
7
|
+
const text = html.replace(/<[^>]+>/g, ' ').replace(/\s+/g, ' ').trim()
|
|
8
|
+
return { html, text }
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { SESClient, SendEmailCommand } from '@aws-sdk/client-ses'
|
|
2
|
+
import { EmailRenderer } from './email-renderer.js'
|
|
3
|
+
|
|
4
|
+
export const id = 'email'
|
|
5
|
+
|
|
6
|
+
export const credentials = [
|
|
7
|
+
'SES_REGION',
|
|
8
|
+
'AWS_ACCESS_KEY_ID',
|
|
9
|
+
'AWS_SECRET_ACCESS_KEY',
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Returns an email client configured from env vars.
|
|
14
|
+
* Exposes `send({ to, from, subject, html, text })` and
|
|
15
|
+
* `sendTemplate(TemplateComponent, props, { to, from, subject })`.
|
|
16
|
+
*
|
|
17
|
+
* @param {{ env: NodeJS.ProcessEnv }} opts
|
|
18
|
+
*/
|
|
19
|
+
export async function connect({ env }) {
|
|
20
|
+
const ses = new SESClient({
|
|
21
|
+
region: env.SES_REGION,
|
|
22
|
+
credentials: {
|
|
23
|
+
accessKeyId: env.AWS_ACCESS_KEY_ID,
|
|
24
|
+
secretAccessKey: env.AWS_SECRET_ACCESS_KEY,
|
|
25
|
+
},
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
function send({ to, from, subject, html, text }) {
|
|
29
|
+
return ses.send(new SendEmailCommand({
|
|
30
|
+
Destination: { ToAddresses: [to] },
|
|
31
|
+
Message: {
|
|
32
|
+
Subject: { Data: subject },
|
|
33
|
+
Body: {
|
|
34
|
+
Html: { Data: html },
|
|
35
|
+
Text: { Data: text },
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
Source: from,
|
|
39
|
+
}))
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function sendTemplate(TemplateComponent, props, { to, from, subject }) {
|
|
43
|
+
const { html, text } = EmailRenderer.render(TemplateComponent, props)
|
|
44
|
+
return send({ to, from, subject, html, text })
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return { send, sendTemplate }
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const emailIntegration = { id, credentials, connect }
|
package/src/index.js
ADDED