@headless-lms/adapter-email-ses 0.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/LICENSE +21 -0
- package/README.md +27 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +56 -0
- package/dist/index.js.map +1 -0
- package/package.json +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 mdwt
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# @headless-lms/adapter-email-ses
|
|
2
|
+
|
|
3
|
+
AWS SES (SESv2) implementation of the `EmailSender` port from `@headless-lms/core/types`.
|
|
4
|
+
|
|
5
|
+
The adapter reads no environment itself — the installation's `config.ts` parses
|
|
6
|
+
env into a `SesEmailConfig` and injects the constructed adapter:
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
import { SesEmailAdapter } from "@headless-lms/adapter-email-ses";
|
|
10
|
+
|
|
11
|
+
const container = await createContainer(config, {
|
|
12
|
+
adapters: { email: new SesEmailAdapter({ region, from }) },
|
|
13
|
+
});
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Omit `accessKeyId`/`secretAccessKey` to use the default AWS credential chain
|
|
17
|
+
(IAM role, env vars, shared profile).
|
|
18
|
+
|
|
19
|
+
## Environment variables (reference installation)
|
|
20
|
+
|
|
21
|
+
| Variable | Required | Maps to | Notes |
|
|
22
|
+
| ------------------------ | -------- | ---------------------- | ----------------------------------------------------------- |
|
|
23
|
+
| `SES_REGION` | yes | `region` | |
|
|
24
|
+
| `EMAIL_FROM` | yes | `from` | e.g. `Acme LMS <noreply@acme.com>`, a verified SES identity.|
|
|
25
|
+
| `SES_ACCESS_KEY` | no | `accessKeyId` | Omit for the default credential chain. |
|
|
26
|
+
| `SES_SECRET_KEY` | no | `secretAccessKey` | Omit for the default credential chain. |
|
|
27
|
+
| `SES_CONFIGURATION_SET` | no | `configurationSetName` | SES configuration set to send through. |
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { SendEmailCommand } from "@aws-sdk/client-sesv2";
|
|
2
|
+
import { EmailMessage, EmailSender, Logger } from "@headless-lms/core/types";
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
interface SesEmailConfig {
|
|
5
|
+
region: string;
|
|
6
|
+
/** Sender, e.g. "Acme LMS <noreply@acme.com>". Must be a verified SES identity. */
|
|
7
|
+
from: string;
|
|
8
|
+
/** Omit both keys to use the default AWS credential chain (IAM role, env, profile). */
|
|
9
|
+
accessKeyId?: string;
|
|
10
|
+
secretAccessKey?: string;
|
|
11
|
+
/** SES configuration set to send through. */
|
|
12
|
+
configurationSetName?: string;
|
|
13
|
+
}
|
|
14
|
+
interface SesClient {
|
|
15
|
+
send(command: SendEmailCommand): Promise<unknown>;
|
|
16
|
+
}
|
|
17
|
+
declare class SesEmailAdapter implements EmailSender {
|
|
18
|
+
private readonly config;
|
|
19
|
+
private readonly logger?;
|
|
20
|
+
private readonly client;
|
|
21
|
+
constructor(config: SesEmailConfig, logger?: Logger | undefined, client?: SesClient);
|
|
22
|
+
send(message: EmailMessage): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { SesEmailAdapter, SesEmailConfig };
|
|
26
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { SESv2Client, SendEmailCommand } from "@aws-sdk/client-sesv2";
|
|
2
|
+
//#region src/index.ts
|
|
3
|
+
var SesEmailAdapter = class {
|
|
4
|
+
config;
|
|
5
|
+
logger;
|
|
6
|
+
client;
|
|
7
|
+
constructor(config, logger, client) {
|
|
8
|
+
this.config = config;
|
|
9
|
+
this.logger = logger;
|
|
10
|
+
this.client = client ?? new SESv2Client({
|
|
11
|
+
region: config.region,
|
|
12
|
+
...config.accessKeyId && config.secretAccessKey ? { credentials: {
|
|
13
|
+
accessKeyId: config.accessKeyId,
|
|
14
|
+
secretAccessKey: config.secretAccessKey
|
|
15
|
+
} } : {}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
async send(message) {
|
|
19
|
+
const command = new SendEmailCommand({
|
|
20
|
+
FromEmailAddress: this.config.from,
|
|
21
|
+
Destination: { ToAddresses: [message.to] },
|
|
22
|
+
...this.config.configurationSetName ? { ConfigurationSetName: this.config.configurationSetName } : {},
|
|
23
|
+
Content: { Simple: {
|
|
24
|
+
Subject: {
|
|
25
|
+
Data: message.subject,
|
|
26
|
+
Charset: "UTF-8"
|
|
27
|
+
},
|
|
28
|
+
Body: {
|
|
29
|
+
Text: {
|
|
30
|
+
Data: message.text,
|
|
31
|
+
Charset: "UTF-8"
|
|
32
|
+
},
|
|
33
|
+
...message.html !== void 0 ? { Html: {
|
|
34
|
+
Data: message.html,
|
|
35
|
+
Charset: "UTF-8"
|
|
36
|
+
} } : {}
|
|
37
|
+
}
|
|
38
|
+
} }
|
|
39
|
+
});
|
|
40
|
+
try {
|
|
41
|
+
await this.client.send(command);
|
|
42
|
+
} catch (err) {
|
|
43
|
+
const e = err;
|
|
44
|
+
this.logger?.error("email send failed", {
|
|
45
|
+
to: message.to,
|
|
46
|
+
name: e?.name ?? "",
|
|
47
|
+
detail: e?.message ?? ""
|
|
48
|
+
});
|
|
49
|
+
throw err;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
//#endregion
|
|
54
|
+
export { SesEmailAdapter };
|
|
55
|
+
|
|
56
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["// AWS SES implementation of the EmailSender port.\nimport { SendEmailCommand, SESv2Client } from \"@aws-sdk/client-sesv2\";\nimport type { EmailSender, EmailMessage, Logger } from \"@headless-lms/core/types\";\n\nexport interface SesEmailConfig {\n region: string;\n /** Sender, e.g. \"Acme LMS <noreply@acme.com>\". Must be a verified SES identity. */\n from: string;\n /** Omit both keys to use the default AWS credential chain (IAM role, env, profile). */\n accessKeyId?: string;\n secretAccessKey?: string;\n /** SES configuration set to send through. */\n configurationSetName?: string;\n}\n\ninterface SesClient {\n send(command: SendEmailCommand): Promise<unknown>;\n}\n\nexport class SesEmailAdapter implements EmailSender {\n private readonly client: SesClient;\n\n constructor(\n private readonly config: SesEmailConfig,\n private readonly logger?: Logger,\n client?: SesClient,\n ) {\n this.client =\n client ??\n new SESv2Client({\n region: config.region,\n ...(config.accessKeyId && config.secretAccessKey\n ? {\n credentials: {\n accessKeyId: config.accessKeyId,\n secretAccessKey: config.secretAccessKey,\n },\n }\n : {}),\n });\n }\n\n async send(message: EmailMessage): Promise<void> {\n const command = new SendEmailCommand({\n FromEmailAddress: this.config.from,\n Destination: { ToAddresses: [message.to] },\n ...(this.config.configurationSetName\n ? { ConfigurationSetName: this.config.configurationSetName }\n : {}),\n Content: {\n Simple: {\n Subject: { Data: message.subject, Charset: \"UTF-8\" },\n Body: {\n Text: { Data: message.text, Charset: \"UTF-8\" },\n ...(message.html !== undefined\n ? { Html: { Data: message.html, Charset: \"UTF-8\" } }\n : {}),\n },\n },\n },\n });\n try {\n await this.client.send(command);\n } catch (err) {\n const e = err as { name?: string; message?: string };\n this.logger?.error(\"email send failed\", {\n to: message.to,\n name: e?.name ?? \"\",\n detail: e?.message ?? \"\",\n });\n throw err;\n }\n }\n}\n"],"mappings":";;AAmBA,IAAa,kBAAb,MAAoD;CAI/B;CACA;CAJnB;CAEA,YACE,QACA,QACA,QACA;EAHiB,KAAA,SAAA;EACA,KAAA,SAAA;EAGjB,KAAK,SACH,UACA,IAAI,YAAY;GACd,QAAQ,OAAO;GACf,GAAI,OAAO,eAAe,OAAO,kBAC7B,EACE,aAAa;IACX,aAAa,OAAO;IACpB,iBAAiB,OAAO;GAC1B,EACF,IACA,CAAC;EACP,CAAC;CACL;CAEA,MAAM,KAAK,SAAsC;EAC/C,MAAM,UAAU,IAAI,iBAAiB;GACnC,kBAAkB,KAAK,OAAO;GAC9B,aAAa,EAAE,aAAa,CAAC,QAAQ,EAAE,EAAE;GACzC,GAAI,KAAK,OAAO,uBACZ,EAAE,sBAAsB,KAAK,OAAO,qBAAqB,IACzD,CAAC;GACL,SAAS,EACP,QAAQ;IACN,SAAS;KAAE,MAAM,QAAQ;KAAS,SAAS;IAAQ;IACnD,MAAM;KACJ,MAAM;MAAE,MAAM,QAAQ;MAAM,SAAS;KAAQ;KAC7C,GAAI,QAAQ,SAAS,KAAA,IACjB,EAAE,MAAM;MAAE,MAAM,QAAQ;MAAM,SAAS;KAAQ,EAAE,IACjD,CAAC;IACP;GACF,EACF;EACF,CAAC;EACD,IAAI;GACF,MAAM,KAAK,OAAO,KAAK,OAAO;EAChC,SAAS,KAAK;GACZ,MAAM,IAAI;GACV,KAAK,QAAQ,MAAM,qBAAqB;IACtC,IAAI,QAAQ;IACZ,MAAM,GAAG,QAAQ;IACjB,QAAQ,GAAG,WAAW;GACxB,CAAC;GACD,MAAM;EACR;CACF;AACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@headless-lms/adapter-email-ses",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@aws-sdk/client-sesv2": "^3.712.0",
|
|
15
|
+
"@headless-lms/core": "0.1.0"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@types/node": "^22.10.2",
|
|
19
|
+
"tsdown": "^0.22.9",
|
|
20
|
+
"typescript": "^5.7.2",
|
|
21
|
+
"vitest": "^2.1.8"
|
|
22
|
+
},
|
|
23
|
+
"description": "AWS SES email adapter for the headless LMS",
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/mdwt/headless-lms.git",
|
|
28
|
+
"directory": "adapters/email-ses"
|
|
29
|
+
},
|
|
30
|
+
"homepage": "https://github.com/mdwt/headless-lms#readme",
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/mdwt/headless-lms/issues"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist"
|
|
36
|
+
],
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "tsdown",
|
|
42
|
+
"typecheck": "tsc --noEmit",
|
|
43
|
+
"test": "vitest run"
|
|
44
|
+
}
|
|
45
|
+
}
|