@deverjak/tenantkit-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 Chytré Digital
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.
@@ -0,0 +1,8 @@
1
+ import type { EmailProvider } from '@deverjak/tenantkit-kernel';
2
+ export interface ResendEmailOptions {
3
+ /** Default From, e.g. "Termínář <no-reply@terminar.cz>". A message's own `from` overrides it. */
4
+ from: string;
5
+ /** Defaults to `process.env.RESEND_API_KEY`. Missing key → every send is cleanly `skipped`. */
6
+ apiKey?: string;
7
+ }
8
+ export declare function createResendEmail(opts: ResendEmailOptions): EmailProvider;
package/dist/index.js ADDED
@@ -0,0 +1,39 @@
1
+ /**
2
+ * `EmailProvider` port → Resend. The transactional transport the kernel's `sendEmail(runtime, …)` delegates to
3
+ * (docs/14 §4; the Resend `import` used to live in the kernel — it now lives here, behind the port).
4
+ *
5
+ * Four load-bearing behaviors, each a legacy lesson made structural (docs/10 §1):
6
+ * • IDEMPOTENT — `idempotencyKey` forwarded so a retried outbox tick can't double-send.
7
+ * • GRACEFUL — no API key → `skipped`; a provider error → `error` RETURNED, never thrown (must not break enrollment).
8
+ */
9
+ import { Resend } from 'resend';
10
+ export function createResendEmail(opts) {
11
+ const key = opts.apiKey ?? process.env.RESEND_API_KEY;
12
+ const client = key ? new Resend(key) : null;
13
+ return {
14
+ async send(msg) {
15
+ if (!client)
16
+ return { status: 'skipped', reason: 'no_api_key' };
17
+ try {
18
+ const { data, error } = await client.emails.send({
19
+ from: msg.from || opts.from,
20
+ to: msg.to,
21
+ replyTo: msg.replyTo,
22
+ subject: msg.subject,
23
+ html: msg.html,
24
+ text: msg.text,
25
+ tags: toResendTags(msg.tags),
26
+ }, msg.idempotencyKey ? { idempotencyKey: msg.idempotencyKey } : undefined);
27
+ if (error)
28
+ return { status: 'error', error: error.message };
29
+ return { status: 'ok', id: data?.id ?? 'unknown' };
30
+ }
31
+ catch (e) {
32
+ return { status: 'error', error: e instanceof Error ? e.message : String(e) };
33
+ }
34
+ },
35
+ };
36
+ }
37
+ function toResendTags(tags) {
38
+ return tags ? Object.entries(tags).map(([name, value]) => ({ name, value })) : undefined;
39
+ }
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@deverjak/tenantkit-email-resend",
3
+ "version": "0.1.0",
4
+ "description": "Resend EmailProvider adapter for the @deverjak/tenantkit-kernel ports. The transport the kernel's sendEmail() delegates to.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js"
11
+ }
12
+ },
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "peerDependencies": {
20
+ "@deverjak/tenantkit-kernel": "0.2.0"
21
+ },
22
+ "dependencies": {
23
+ "resend": "^6.14.0"
24
+ },
25
+ "devDependencies": {
26
+ "typescript": "^5.9.3"
27
+ },
28
+ "scripts": {
29
+ "typecheck": "tsc --noEmit",
30
+ "build": "tsc -p tsconfig.json --outDir dist --declaration"
31
+ }
32
+ }