@paroicms/send-mail-aws-ses-plugin 0.2.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/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # @paroicms/send-mail-aws-ses-plugin
2
+
3
+ AWS SES email sending plugin for ParoiCMS.
4
+
5
+ This package is part of [ParoiCMS](https://www.npmjs.com/package/@paroicms/server).
6
+
7
+ ## Configuration
8
+
9
+ Add the following to your site configuration:
10
+
11
+ ```json
12
+ {
13
+ "plugins": {
14
+ "@paroicms/send-mail-aws-ses-plugin": {
15
+ "disabled": false,
16
+ "from": "noreply@example.com",
17
+ "awsAccessKeyId": "your-aws-access-key-id",
18
+ "awsSecretAccessKey": "your-aws-secret-access-key",
19
+ "awsRegion": "us-east-1"
20
+ }
21
+ }
22
+ }
23
+ ```
24
+
25
+ ### Configuration Options
26
+
27
+ - `disabled` (boolean, optional): Whether to disable the plugin. Default: `false`
28
+ - `from` (string, required): The email address to send emails from
29
+ - `awsAccessKeyId` (string, required): AWS access key ID for SES
30
+ - `awsSecretAccessKey` (string, required): AWS secret access key for SES
31
+ - `awsRegion` (string, required): AWS region for SES service
32
+
33
+ ## License
34
+
35
+ Released under the [MIT license](https://gitlab.com/paroi/opensource/paroicms/-/blob/main/LICENSE.md).
@@ -0,0 +1,24 @@
1
+ import { esmDirName, extractPackageNameAndVersionSync } from "@paroicms/script-lib";
2
+ import { type } from "arktype";
3
+ import { dirname } from "node:path";
4
+ import { sendMailAwsSes } from "./send-mail-aws-ses.js";
5
+ const SendMailAwsSesConfigAT = type({
6
+ "disabled?": "boolean",
7
+ from: "string",
8
+ awsAccessKeyId: "string",
9
+ awsSecretAccessKey: "string",
10
+ awsRegion: "string",
11
+ });
12
+ const projectDir = dirname(esmDirName(import.meta.url));
13
+ const packageDir = dirname(projectDir);
14
+ const { version } = extractPackageNameAndVersionSync(packageDir);
15
+ const plugin = {
16
+ version,
17
+ siteInit(service) {
18
+ const config = SendMailAwsSesConfigAT.assert(service.configuration);
19
+ service.registerHook("sendMail", async ({ service, value }) => {
20
+ await sendMailAwsSes(service, value, config);
21
+ });
22
+ },
23
+ };
24
+ export default plugin;
@@ -0,0 +1,52 @@
1
+ import { SESClient, SendEmailCommand } from "@aws-sdk/client-ses";
2
+ import { escapeHtml, htmlToRawText, } from "@paroicms/public-server-lib";
3
+ export async function sendMailAwsSes(service, { subject, html, replyTo, to }, configuration) {
4
+ const { logger } = service;
5
+ const text = htmlToRawText(html);
6
+ const replyToAddr = replyTo
7
+ ? `"${escapeHtml(replyTo.name)}" <${escapeHtml(replyTo.email)}>`
8
+ : undefined;
9
+ logger.debug(`[sendMailAwsSes] ${JSON.stringify({
10
+ from: configuration.from,
11
+ to,
12
+ replyToAddr,
13
+ subject,
14
+ html,
15
+ text,
16
+ })}`);
17
+ if (configuration.disabled) {
18
+ logger.info("[sendMailAwsSes] Email sending is disabled");
19
+ return;
20
+ }
21
+ const sesClient = new SESClient({
22
+ region: configuration.awsRegion,
23
+ credentials: {
24
+ accessKeyId: configuration.awsAccessKeyId,
25
+ secretAccessKey: configuration.awsSecretAccessKey,
26
+ },
27
+ });
28
+ const command = new SendEmailCommand({
29
+ Source: configuration.from,
30
+ Destination: {
31
+ ToAddresses: [to],
32
+ },
33
+ ReplyToAddresses: replyToAddr ? [replyToAddr] : undefined,
34
+ Message: {
35
+ Subject: {
36
+ Charset: "UTF-8",
37
+ Data: subject,
38
+ },
39
+ Body: {
40
+ Html: {
41
+ Charset: "UTF-8",
42
+ Data: html,
43
+ },
44
+ Text: {
45
+ Charset: "UTF-8",
46
+ Data: text,
47
+ },
48
+ },
49
+ },
50
+ });
51
+ await sesClient.send(command);
52
+ }
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@paroicms/send-mail-aws-ses-plugin",
3
+ "version": "0.2.0",
4
+ "description": "AWS SES email sending plugin for ParoiCMS",
5
+ "keywords": [
6
+ "paroicms",
7
+ "plugin",
8
+ "email",
9
+ "aws",
10
+ "ses"
11
+ ],
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://gitlab.com/paroi/opensource/paroicms.git",
15
+ "directory": "plugins/send-mail-aws-ses-plugin"
16
+ },
17
+ "author": "Paroi Team",
18
+ "license": "MIT",
19
+ "type": "module",
20
+ "main": "backend/dist/index.js",
21
+ "scripts": {
22
+ "build": "npm run build:backend",
23
+ "build:backend": "(cd backend && tsc)",
24
+ "build:backend:watch": "(cd backend && tsc --watch --preserveWatchOutput)",
25
+ "clear": "rimraf backend/dist/*",
26
+ "test": "vitest run",
27
+ "test:watch": "vitest"
28
+ },
29
+ "dependencies": {
30
+ "@aws-sdk/client-ses": "~3.848.0",
31
+ "@paroicms/script-lib": "0.2.0",
32
+ "arktype": "~2.1.20"
33
+ },
34
+ "peerDependencies": {
35
+ "@paroicms/public-anywhere-lib": "0",
36
+ "@paroicms/public-server-lib": "0"
37
+ },
38
+ "devDependencies": {
39
+ "@paroicms/public-anywhere-lib": "0.34.0",
40
+ "@paroicms/public-server-lib": "0.43.0",
41
+ "@types/node": "~24.0.1",
42
+ "rimraf": "~6.0.1",
43
+ "typescript": "~5.8.3",
44
+ "vitest": "~3.2.3"
45
+ },
46
+ "files": [
47
+ "backend/dist"
48
+ ]
49
+ }