@porulle/adapter-ses 0.64.0 → 0.65.1

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,iBAAiB;IAChC,sCAAsC;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,8FAA8F;IAC9F,IAAI,EAAE,MAAM,CAAC;IACb,iGAAiG;IACjG,WAAW,CAAC,EAAE;QACZ,WAAW,EAAE,MAAM,CAAC;QACpB,eAAe,EAAE,MAAM,CAAC;KACzB,CAAC;IACF;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,CAAC,CAAC;IACrE;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,CAAC,CAAC;CACvE;AAgCD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG;IACtD,IAAI,CAAC,KAAK,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9F,CAyCA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,iBAAiB;IAChC,sCAAsC;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,8FAA8F;IAC9F,IAAI,EAAE,MAAM,CAAC;IACb,iGAAiG;IACjG,WAAW,CAAC,EAAE;QACZ,WAAW,EAAE,MAAM,CAAC;QACpB,eAAe,EAAE,MAAM,CAAC;KACzB,CAAC;IACF;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,CAAC,CAAC;IACrE;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,CAAC,CAAC;CACvE;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG;IACtD,IAAI,CAAC,KAAK,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9F,CAmCA"}
package/dist/index.js CHANGED
@@ -1,24 +1,5 @@
1
+ import { renderEmail } from "@porulle/core";
1
2
  import { SESv2Client, SendEmailCommand } from "@aws-sdk/client-sesv2";
2
- const DEFAULT_SUBJECTS = {
3
- "order-confirmation": (d) => `Order Confirmed${d.orderId ? ` - #${String(d.orderId).slice(0, 8)}` : ""}`,
4
- "order-status-change": (d) => `Order Update - ${d.newStatus ?? "Status Changed"}`,
5
- "password-reset": () => "Reset Your Password",
6
- "email-verification": () => "Verify Your Email Address",
7
- "appointment:reminder": (d) => `Appointment Reminder${d.reminderType === "1h" ? " - Starting Soon" : ""}`,
8
- "appointment:confirmation-notice": () => "Appointment Confirmed",
9
- "appointment:cancellation-notice": () => "Appointment Cancelled",
10
- "appointment:no-show-notice": () => "Missed Appointment",
11
- };
12
- const DEFAULT_TEMPLATES = {
13
- "order-confirmation": (d) => `<h2>Order Confirmed</h2><p>Thank you for your order${d.orderId ? ` <strong>#${String(d.orderId).slice(0, 8)}</strong>` : ""}.</p>${d.total ? `<p>Total: ${d.currency ?? "USD"} ${String(d.total)}</p>` : ""}`,
14
- "order-status-change": (d) => `<h2>Order Update</h2><p>Your order${d.orderId ? ` <strong>#${String(d.orderId).slice(0, 8)}</strong>` : ""} status has been updated to <strong>${d.newStatus ?? "unknown"}</strong>.</p>`,
15
- "password-reset": (d) => `<h2>Reset Your Password</h2><p>Click the link below to reset your password:</p><p><a href="${d.url ?? "#"}">Reset Password</a></p>`,
16
- "email-verification": (d) => `<h2>Verify Your Email</h2><p>Click the link below to verify your email address:</p><p><a href="${d.url ?? "#"}">Verify Email</a></p>`,
17
- "appointment:reminder": (d) => `<h2>Appointment Reminder</h2><p>This is a${d.reminderType === "1h" ? " 1-hour" : " 24-hour"} reminder for your upcoming appointment.</p><p>Booking ID: ${d.bookingId ?? "N/A"}</p>`,
18
- "appointment:confirmation-notice": (d) => `<h2>Appointment Confirmed</h2><p>Your appointment has been confirmed.</p><p>Booking ID: ${d.bookingId ?? "N/A"}</p>`,
19
- "appointment:cancellation-notice": (d) => `<h2>Appointment Cancelled</h2><p>Your appointment has been cancelled.</p><p>Booking ID: ${d.bookingId ?? "N/A"}</p>`,
20
- "appointment:no-show-notice": (d) => `<h2>Missed Appointment</h2><p>You missed your appointment. Please contact us to rebook.</p><p>Booking ID: ${d.bookingId ?? "N/A"}</p>`,
21
- };
22
3
  /**
23
4
  * Creates an email adapter backed by AWS SES v2.
24
5
  *
@@ -45,17 +26,13 @@ export function sesAdapter(options) {
45
26
  region: options.region,
46
27
  ...(options.credentials ? { credentials: options.credentials } : {}),
47
28
  });
48
- const subjects = { ...DEFAULT_SUBJECTS, ...options.subjects };
49
- const templates = { ...DEFAULT_TEMPLATES, ...options.templates };
50
29
  return {
51
30
  async send(input) {
52
31
  const data = input.data ?? {};
53
- const subjectFn = subjects[input.template];
54
- const subject = subjectFn ? subjectFn(data) : input.template;
55
- const templateFn = templates[input.template];
56
- const html = templateFn
57
- ? templateFn(data)
58
- : `<p>Notification: ${input.template}</p><pre>${JSON.stringify(data, null, 2)}</pre>`;
32
+ const rendered = renderEmail(input.template, data, {
33
+ ...(options.subjects ? { subjects: options.subjects } : {}),
34
+ ...(options.templates ? { templates: options.templates } : {}),
35
+ });
59
36
  const command = new SendEmailCommand({
60
37
  FromEmailAddress: options.from,
61
38
  Destination: {
@@ -63,9 +40,9 @@ export function sesAdapter(options) {
63
40
  },
64
41
  Content: {
65
42
  Simple: {
66
- Subject: { Data: subject, Charset: "UTF-8" },
43
+ Subject: { Data: rendered.subject, Charset: "UTF-8" },
67
44
  Body: {
68
- Html: { Data: html, Charset: "UTF-8" },
45
+ Html: { Data: rendered.html, Charset: "UTF-8" },
69
46
  },
70
47
  },
71
48
  },
package/package.json CHANGED
@@ -1,17 +1,22 @@
1
1
  {
2
2
  "name": "@porulle/adapter-ses",
3
- "version": "0.64.0",
3
+ "version": "0.65.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {
8
- "bun": "./src/index.ts",
9
- "import": "./dist/index.js",
10
- "types": "./src/index.ts"
11
- }
8
+ "@porulle/source": "./src/index.ts",
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ },
12
+ "./package.json": "./package.json"
13
+ },
14
+ "engines": {
15
+ "node": ">=20.19.0"
12
16
  },
13
17
  "dependencies": {
14
- "@aws-sdk/client-sesv2": "^3.700.0"
18
+ "@aws-sdk/client-sesv2": "^3.700.0",
19
+ "@porulle/core": "0.65.1"
15
20
  },
16
21
  "devDependencies": {
17
22
  "@types/node": "^24.5.2",
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { renderEmail } from "@porulle/core";
1
2
  import { SESv2Client, SendEmailCommand } from "@aws-sdk/client-sesv2";
2
3
 
3
4
  export interface SESAdapterOptions {
@@ -22,36 +23,6 @@ export interface SESAdapterOptions {
22
23
  templates?: Record<string, (data: Record<string, unknown>) => string>;
23
24
  }
24
25
 
25
- const DEFAULT_SUBJECTS: Record<string, (data: Record<string, unknown>) => string> = {
26
- "order-confirmation": (d) => `Order Confirmed${d.orderId ? ` - #${String(d.orderId).slice(0, 8)}` : ""}`,
27
- "order-status-change": (d) => `Order Update - ${d.newStatus ?? "Status Changed"}`,
28
- "password-reset": () => "Reset Your Password",
29
- "email-verification": () => "Verify Your Email Address",
30
- "appointment:reminder": (d) => `Appointment Reminder${d.reminderType === "1h" ? " - Starting Soon" : ""}`,
31
- "appointment:confirmation-notice": () => "Appointment Confirmed",
32
- "appointment:cancellation-notice": () => "Appointment Cancelled",
33
- "appointment:no-show-notice": () => "Missed Appointment",
34
- };
35
-
36
- const DEFAULT_TEMPLATES: Record<string, (data: Record<string, unknown>) => string> = {
37
- "order-confirmation": (d) =>
38
- `<h2>Order Confirmed</h2><p>Thank you for your order${d.orderId ? ` <strong>#${String(d.orderId).slice(0, 8)}</strong>` : ""}.</p>${d.total ? `<p>Total: ${d.currency ?? "USD"} ${String(d.total)}</p>` : ""}`,
39
- "order-status-change": (d) =>
40
- `<h2>Order Update</h2><p>Your order${d.orderId ? ` <strong>#${String(d.orderId).slice(0, 8)}</strong>` : ""} status has been updated to <strong>${d.newStatus ?? "unknown"}</strong>.</p>`,
41
- "password-reset": (d) =>
42
- `<h2>Reset Your Password</h2><p>Click the link below to reset your password:</p><p><a href="${d.url ?? "#"}">Reset Password</a></p>`,
43
- "email-verification": (d) =>
44
- `<h2>Verify Your Email</h2><p>Click the link below to verify your email address:</p><p><a href="${d.url ?? "#"}">Verify Email</a></p>`,
45
- "appointment:reminder": (d) =>
46
- `<h2>Appointment Reminder</h2><p>This is a${d.reminderType === "1h" ? " 1-hour" : " 24-hour"} reminder for your upcoming appointment.</p><p>Booking ID: ${d.bookingId ?? "N/A"}</p>`,
47
- "appointment:confirmation-notice": (d) =>
48
- `<h2>Appointment Confirmed</h2><p>Your appointment has been confirmed.</p><p>Booking ID: ${d.bookingId ?? "N/A"}</p>`,
49
- "appointment:cancellation-notice": (d) =>
50
- `<h2>Appointment Cancelled</h2><p>Your appointment has been cancelled.</p><p>Booking ID: ${d.bookingId ?? "N/A"}</p>`,
51
- "appointment:no-show-notice": (d) =>
52
- `<h2>Missed Appointment</h2><p>You missed your appointment. Please contact us to rebook.</p><p>Booking ID: ${d.bookingId ?? "N/A"}</p>`,
53
- };
54
-
55
26
  /**
56
27
  * Creates an email adapter backed by AWS SES v2.
57
28
  *
@@ -81,19 +52,13 @@ export function sesAdapter(options: SESAdapterOptions): {
81
52
  ...(options.credentials ? { credentials: options.credentials } : {}),
82
53
  });
83
54
 
84
- const subjects = { ...DEFAULT_SUBJECTS, ...options.subjects };
85
- const templates = { ...DEFAULT_TEMPLATES, ...options.templates };
86
-
87
55
  return {
88
56
  async send(input) {
89
57
  const data = input.data ?? {};
90
- const subjectFn = subjects[input.template];
91
- const subject = subjectFn ? subjectFn(data) : input.template;
92
-
93
- const templateFn = templates[input.template];
94
- const html = templateFn
95
- ? templateFn(data)
96
- : `<p>Notification: ${input.template}</p><pre>${JSON.stringify(data, null, 2)}</pre>`;
58
+ const rendered = renderEmail(input.template, data, {
59
+ ...(options.subjects ? { subjects: options.subjects } : {}),
60
+ ...(options.templates ? { templates: options.templates } : {}),
61
+ });
97
62
 
98
63
  const command = new SendEmailCommand({
99
64
  FromEmailAddress: options.from,
@@ -102,9 +67,9 @@ export function sesAdapter(options: SESAdapterOptions): {
102
67
  },
103
68
  Content: {
104
69
  Simple: {
105
- Subject: { Data: subject, Charset: "UTF-8" },
70
+ Subject: { Data: rendered.subject, Charset: "UTF-8" },
106
71
  Body: {
107
- Html: { Data: html, Charset: "UTF-8" },
72
+ Html: { Data: rendered.html, Charset: "UTF-8" },
108
73
  },
109
74
  },
110
75
  },