@headless-lms/adapter-email-resend 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 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,21 @@
1
+ # @headless-lms/adapter-email-resend
2
+
3
+ Resend 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 `ResendEmailConfig` and injects the constructed adapter:
7
+
8
+ ```ts
9
+ import { ResendEmailAdapter } from "@headless-lms/adapter-email-resend";
10
+
11
+ const container = await createContainer(config, {
12
+ adapters: { email: new ResendEmailAdapter({ apiKey, from }) },
13
+ });
14
+ ```
15
+
16
+ ## Environment variables (reference installation)
17
+
18
+ | Variable | Required | Maps to | Notes |
19
+ | ---------------- | -------- | -------- | -------------------------------------------------------- |
20
+ | `RESEND_API_KEY` | yes | `apiKey` | Unset → no adapter injected; email sends fail loudly. |
21
+ | `EMAIL_FROM` | no | `from` | e.g. `Acme LMS <noreply@acme.com>`, on a verified Resend domain. Defaults to `onboarding@resend.dev`. |
@@ -0,0 +1,17 @@
1
+ import { EmailMessage, EmailSender, Logger } from "@headless-lms/core/types";
2
+ //#region src/index.d.ts
3
+ interface ResendEmailConfig {
4
+ apiKey: string;
5
+ /** Sender, e.g. "Acme LMS <noreply@acme.com>". Must be on a verified Resend domain. */
6
+ from: string;
7
+ }
8
+ declare class ResendEmailAdapter implements EmailSender {
9
+ private readonly config;
10
+ private readonly logger?;
11
+ private readonly fetchFn;
12
+ constructor(config: ResendEmailConfig, logger?: Logger | undefined, fetchFn?: typeof fetch);
13
+ send(message: EmailMessage): Promise<void>;
14
+ }
15
+ //#endregion
16
+ export { ResendEmailAdapter, ResendEmailConfig };
17
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,41 @@
1
+ //#region src/index.ts
2
+ const RESEND_ENDPOINT = "https://api.resend.com/emails";
3
+ var ResendEmailAdapter = class {
4
+ config;
5
+ logger;
6
+ fetchFn;
7
+ constructor(config, logger, fetchFn = fetch) {
8
+ this.config = config;
9
+ this.logger = logger;
10
+ this.fetchFn = fetchFn;
11
+ }
12
+ async send(message) {
13
+ const response = await this.fetchFn(RESEND_ENDPOINT, {
14
+ method: "POST",
15
+ headers: {
16
+ authorization: `Bearer ${this.config.apiKey}`,
17
+ "content-type": "application/json"
18
+ },
19
+ body: JSON.stringify({
20
+ from: this.config.from,
21
+ to: message.to,
22
+ subject: message.subject,
23
+ text: message.text,
24
+ ...message.html !== void 0 && { html: message.html }
25
+ })
26
+ });
27
+ if (!response.ok) {
28
+ const detail = await response.json().then((body) => body && typeof body === "object" && "message" in body ? String(body.message) : "").catch(() => "");
29
+ this.logger?.error("email send failed", {
30
+ to: message.to,
31
+ status: response.status,
32
+ detail
33
+ });
34
+ throw new Error(`resend responded ${response.status}${detail ? `: ${detail}` : ""}`);
35
+ }
36
+ }
37
+ };
38
+ //#endregion
39
+ export { ResendEmailAdapter };
40
+
41
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["// Resend implementation of the EmailSender port.\nimport type { EmailSender, EmailMessage, Logger } from \"@headless-lms/core/types\";\n\nconst RESEND_ENDPOINT = \"https://api.resend.com/emails\";\n\nexport interface ResendEmailConfig {\n apiKey: string;\n /** Sender, e.g. \"Acme LMS <noreply@acme.com>\". Must be on a verified Resend domain. */\n from: string;\n}\n\nexport class ResendEmailAdapter implements EmailSender {\n constructor(\n private readonly config: ResendEmailConfig,\n private readonly logger?: Logger,\n private readonly fetchFn: typeof fetch = fetch,\n ) {}\n\n async send(message: EmailMessage): Promise<void> {\n const response = await this.fetchFn(RESEND_ENDPOINT, {\n method: \"POST\",\n headers: {\n authorization: `Bearer ${this.config.apiKey}`,\n \"content-type\": \"application/json\",\n },\n body: JSON.stringify({\n from: this.config.from,\n to: message.to,\n subject: message.subject,\n text: message.text,\n ...(message.html !== undefined && { html: message.html }),\n }),\n });\n if (!response.ok) {\n const detail = await response\n .json()\n .then((body: unknown) =>\n body && typeof body === \"object\" && \"message\" in body ? String(body.message) : \"\",\n )\n .catch(() => \"\");\n this.logger?.error(\"email send failed\", { to: message.to, status: response.status, detail });\n throw new Error(`resend responded ${response.status}${detail ? `: ${detail}` : \"\"}`);\n }\n }\n}\n"],"mappings":";AAGA,MAAM,kBAAkB;AAQxB,IAAa,qBAAb,MAAuD;CAElC;CACA;CACA;CAHnB,YACE,QACA,QACA,UAAyC,OACzC;EAHiB,KAAA,SAAA;EACA,KAAA,SAAA;EACA,KAAA,UAAA;CAChB;CAEH,MAAM,KAAK,SAAsC;EAC/C,MAAM,WAAW,MAAM,KAAK,QAAQ,iBAAiB;GACnD,QAAQ;GACR,SAAS;IACP,eAAe,UAAU,KAAK,OAAO;IACrC,gBAAgB;GAClB;GACA,MAAM,KAAK,UAAU;IACnB,MAAM,KAAK,OAAO;IAClB,IAAI,QAAQ;IACZ,SAAS,QAAQ;IACjB,MAAM,QAAQ;IACd,GAAI,QAAQ,SAAS,KAAA,KAAa,EAAE,MAAM,QAAQ,KAAK;GACzD,CAAC;EACH,CAAC;EACD,IAAI,CAAC,SAAS,IAAI;GAChB,MAAM,SAAS,MAAM,SAClB,KAAK,CAAC,CACN,MAAM,SACL,QAAQ,OAAO,SAAS,YAAY,aAAa,OAAO,OAAO,KAAK,OAAO,IAAI,EACjF,CAAC,CACA,YAAY,EAAE;GACjB,KAAK,QAAQ,MAAM,qBAAqB;IAAE,IAAI,QAAQ;IAAI,QAAQ,SAAS;IAAQ;GAAO,CAAC;GAC3F,MAAM,IAAI,MAAM,oBAAoB,SAAS,SAAS,SAAS,KAAK,WAAW,IAAI;EACrF;CACF;AACF"}
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@headless-lms/adapter-email-resend",
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
+ "@headless-lms/core": "0.1.0"
15
+ },
16
+ "devDependencies": {
17
+ "@types/node": "^22.10.2",
18
+ "tsdown": "^0.22.9",
19
+ "typescript": "^5.7.2",
20
+ "vitest": "^2.1.8"
21
+ },
22
+ "description": "Resend email adapter for the headless LMS",
23
+ "license": "MIT",
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://github.com/mdwt/headless-lms.git",
27
+ "directory": "adapters/email-resend"
28
+ },
29
+ "homepage": "https://github.com/mdwt/headless-lms#readme",
30
+ "bugs": {
31
+ "url": "https://github.com/mdwt/headless-lms/issues"
32
+ },
33
+ "files": [
34
+ "dist"
35
+ ],
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "scripts": {
40
+ "build": "tsdown",
41
+ "typecheck": "tsc --noEmit",
42
+ "test": "vitest run"
43
+ }
44
+ }