@portalshq/capability-email-notifications 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/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # @portalshq/capability-email-notifications
2
+
3
+ Delivers notification messages through Resend with a small `send(message)` interface.
@@ -0,0 +1,22 @@
1
+ export type NotificationMessage = {
2
+ to: string;
3
+ subject: string;
4
+ text: string;
5
+ html?: string;
6
+ scheduledAt?: string;
7
+ attachments?: readonly {
8
+ filename: string;
9
+ content: string | Buffer;
10
+ contentType?: string;
11
+ }[];
12
+ };
13
+ export type DeliveryResult = {
14
+ messageId?: string;
15
+ };
16
+ export type Notifications = {
17
+ send(message: NotificationMessage): Promise<DeliveryResult>;
18
+ };
19
+ export declare function createResendNotifications(options: {
20
+ apiKey: string;
21
+ from: string;
22
+ }): Notifications;
package/dist/index.js ADDED
@@ -0,0 +1,24 @@
1
+ import { Resend } from "resend";
2
+ export function createResendNotifications(options) {
3
+ if (!options.apiKey)
4
+ throw new Error("Resend requires an API key.");
5
+ if (!options.from)
6
+ throw new Error("Resend requires a sender address.");
7
+ const client = new Resend(options.apiKey);
8
+ return {
9
+ async send(message) {
10
+ const { data, error } = await client.emails.send({
11
+ from: options.from,
12
+ to: message.to,
13
+ subject: message.subject,
14
+ text: message.text,
15
+ html: message.html ?? message.text.replace(/\n/g, "<br>"),
16
+ scheduledAt: message.scheduledAt,
17
+ attachments: message.attachments?.map((attachment) => ({ ...attachment })),
18
+ });
19
+ if (error)
20
+ throw new Error(`Email delivery failed: ${error.message}`);
21
+ return { messageId: data?.id };
22
+ },
23
+ };
24
+ }
package/package.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "@portalshq/capability-email-notifications",
3
+ "version": "0.1.0",
4
+ "repository": { "type": "git", "url": "git+https://github.com/portalshq/portals-cloud.git", "directory": "packages/capability-email-notifications" },
5
+ "description": "Provider-backed email notification delivery.",
6
+ "type": "module",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": { ".": { "types": "./dist/index.d.ts", "default": "./dist/index.js" } },
10
+ "files": ["dist", "README.md"],
11
+ "scripts": { "build": "rm -rf dist && tsc -p tsconfig.json", "typecheck": "tsc -p tsconfig.json --noEmit", "prepack": "npm run build" },
12
+ "dependencies": { "resend": "^6.9.3" },
13
+ "devDependencies": { "@types/node": "^20.0.0", "typescript": "^5.6.3" },
14
+ "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org/" }
15
+ }