@infuro/cms-core 1.0.61 → 1.0.63

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.
Files changed (50) hide show
  1. package/dist/admin.cjs +3624 -2642
  2. package/dist/admin.js +2415 -1433
  3. package/dist/api.cjs +41 -37
  4. package/dist/api.js +9 -5
  5. package/dist/chunk-3VZAAQUV.js +106 -0
  6. package/dist/{chunk-UHT4INVW.js → chunk-77YWLP4X.js} +625 -252
  7. package/dist/{chunk-BXYZDMTZ.cjs → chunk-7L556RGL.cjs} +3 -94
  8. package/dist/{chunk-T3HPSF7K.js → chunk-AYWDQFJZ.js} +3 -0
  9. package/dist/{chunk-URN7GS23.js → chunk-BWOITUNI.js} +203 -1062
  10. package/dist/{chunk-CNAHVRRU.cjs → chunk-CJEOH6QC.cjs} +676 -312
  11. package/dist/{chunk-O2642WVS.js → chunk-DTUL3Q5L.js} +17 -3
  12. package/dist/{chunk-YSYX4GUD.cjs → chunk-EWXG4E74.cjs} +213 -1082
  13. package/dist/chunk-GWDI752Q.js +83 -0
  14. package/dist/chunk-H3IVLIPR.cjs +86 -0
  15. package/dist/chunk-JLDHK2QE.cjs +109 -0
  16. package/dist/chunk-KAOHOHCA.js +901 -0
  17. package/dist/{chunk-2KUCQVAQ.js → chunk-MWEK7N3F.js} +2 -91
  18. package/dist/{chunk-V25RDUOU.cjs → chunk-MXABMVF7.cjs} +38 -4
  19. package/dist/chunk-OVTOP42W.js +199 -0
  20. package/dist/{chunk-73WVHINE.cjs → chunk-RHYVNRYG.cjs} +18 -4
  21. package/dist/{chunk-L3525VXI.js → chunk-RXTUSF3R.js} +36 -2
  22. package/dist/{chunk-77I3KS7V.cjs → chunk-UEE4PTTB.cjs} +3 -0
  23. package/dist/chunk-WFMVD567.cjs +209 -0
  24. package/dist/chunk-YVP4NQII.cjs +914 -0
  25. package/dist/{email-queue-6NJY6HNM.cjs → email-queue-VTYL2KFA.cjs} +7 -6
  26. package/dist/{email-queue-OI2HSCGE.js → email-queue-YPRSVG56.js} +3 -2
  27. package/dist/email-service-ATCPJFWG.cjs +28 -0
  28. package/dist/email-service-DPKVQOKP.js +3 -0
  29. package/dist/{emit-order-notification-trigger-TNEZOYEE.cjs → emit-order-notification-trigger-WI4HGMKH.cjs} +4 -4
  30. package/dist/{emit-order-notification-trigger-CZU3V2WE.js → emit-order-notification-trigger-XVG2B5ZF.js} +2 -2
  31. package/dist/{erp-order-invoice-3GXDE443.js → erp-order-invoice-3UGWLICU.js} +2 -1
  32. package/dist/{erp-order-invoice-EYYNR526.cjs → erp-order-invoice-KJYJNWMG.cjs} +6 -5
  33. package/dist/index.cjs +366 -316
  34. package/dist/index.d.cts +61 -21
  35. package/dist/index.d.ts +61 -21
  36. package/dist/index.js +79 -29
  37. package/dist/migrations/1783000000000-AddOrderPendingProcessingCompletedTriggers.ts +56 -0
  38. package/dist/migrations/1783100000000-AddSmsToOrderNotificationBindingsChannelEnum.ts +17 -0
  39. package/dist/migrations/1783200000000-AddOrderAssigneeColumns.ts +30 -0
  40. package/dist/order-assignees-handlers-LKMAGLG6.js +150 -0
  41. package/dist/order-assignees-handlers-NPKD64P6.cjs +152 -0
  42. package/dist/order-completion-otp-handlers-IMMQGHDR.cjs +363 -0
  43. package/dist/order-completion-otp-handlers-WGM7HWG4.js +361 -0
  44. package/dist/order-notification-dispatcher-5TUFCDU7.cjs +35 -0
  45. package/dist/order-notification-dispatcher-JKFQJYGG.js +10 -0
  46. package/dist/sms-notification-templates-handlers-SJLO7JGZ.js +47 -0
  47. package/dist/sms-notification-templates-handlers-YSB3L2PK.cjs +49 -0
  48. package/package.json +1 -1
  49. package/dist/order-notification-dispatcher-KJVGLK5E.cjs +0 -24
  50. package/dist/order-notification-dispatcher-ZSFKEYMP.js +0 -7
@@ -0,0 +1,901 @@
1
+ import { __name } from './chunk-SHUYVCID.js';
2
+ import { SESClient, SendRawEmailCommand, SendEmailCommand } from '@aws-sdk/client-ses';
3
+ import { createRequire } from 'module';
4
+ import nodemailer from 'nodemailer';
5
+
6
+ // src/plugins/email/templates/layout.ts
7
+ function escapeHtml(s) {
8
+ return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
9
+ }
10
+ __name(escapeHtml, "escapeHtml");
11
+ function socialLinkInnerHtml(s) {
12
+ if (s.iconUrl?.trim()) {
13
+ return `<img src="${escapeHtml(s.iconUrl.trim())}" alt="" width="20" height="20" style="display:inline-block;vertical-align:middle;border:0;" />`;
14
+ }
15
+ const label = s.icon && s.icon.trim() || "\u{1F517}";
16
+ return escapeHtml(label);
17
+ }
18
+ __name(socialLinkInnerHtml, "socialLinkInnerHtml");
19
+ function supportLinesHtml(supportEmail, supportPhone) {
20
+ const parts = [];
21
+ if (supportEmail) {
22
+ parts.push(`<a href="mailto:${escapeHtml(supportEmail)}" style="color:#6b7280;text-decoration:none;font-size:13px;">${escapeHtml(supportEmail)}</a>`);
23
+ }
24
+ if (supportPhone) {
25
+ parts.push(`<span style="color:#6b7280;font-size:13px;">${escapeHtml(supportPhone)}</span>`);
26
+ }
27
+ return parts.join('<span style="color:#d1d5db;padding:0 8px;">\xB7</span>');
28
+ }
29
+ __name(supportLinesHtml, "supportLinesHtml");
30
+ function renderLayout(options) {
31
+ const { bodyHtml, companyDetails } = options;
32
+ const { logoUrl, companyName, supportEmail, supportPhone, socialLinks, footerDisclaimer, followUsTitle = "Follow Us" } = companyDetails;
33
+ const brand = (companyName || "Store").trim();
34
+ const accent = "#ea580c";
35
+ const logoHtml = logoUrl ? `<img src="${escapeHtml(logoUrl)}" alt="${escapeHtml(brand)}" width="160" style="max-height:56px;max-width:180px;height:auto;width:auto;display:block;border:0;margin:0 auto;" />` : `<div style="font-size:22px;font-weight:700;letter-spacing:-0.02em;color:#111827;">${escapeHtml(brand)}</div>`;
36
+ const hasSocial = Boolean(socialLinks?.length);
37
+ const socialRowHtml = hasSocial && socialLinks ? `<div style="margin-top:12px;text-align:center;font-size:0;line-height:0;">${socialLinks.map((s) => `<a href="${escapeHtml(s.url)}" style="display:inline-block;margin:0 8px;text-decoration:none;color:#374151;font-size:18px;line-height:1;vertical-align:middle;">${socialLinkInnerHtml(s)}</a>`).join("")}</div>` : "";
38
+ const followTitleHtml = hasSocial && followUsTitle ? `<div style="font-size:12px;font-weight:600;color:#9ca3af;text-transform:uppercase;letter-spacing:0.06em;margin:0 0 4px 0;">${escapeHtml(followUsTitle)}</div>` : "";
39
+ const supportHtml = supportLinesHtml(supportEmail, supportPhone);
40
+ const disclaimerBlock = footerDisclaimer ? `<div style="margin-top:16px;font-size:11px;line-height:1.5;color:#9ca3af;">${escapeHtml(footerDisclaimer).replace(/\n/g, "<br/>")}</div>` : "";
41
+ const responsiveCss = `
42
+ @media only screen and (max-width: 620px) {
43
+ .email-shell { padding: 16px 10px !important; }
44
+ .email-card { border-radius: 12px !important; }
45
+ .email-body { padding: 24px 18px !important; }
46
+ .email-header { padding: 20px 18px !important; }
47
+ }
48
+ `;
49
+ return `<!DOCTYPE html>
50
+ <html lang="en">
51
+ <head>
52
+ <meta charset="utf-8">
53
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
54
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
55
+ <title>${escapeHtml(brand)}</title>
56
+ <style type="text/css">${responsiveCss}</style>
57
+ </head>
58
+ <body style="margin:0;padding:0;background:#f3f4f6;-webkit-font-smoothing:antialiased;">
59
+ <table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background:#f3f4f6;border-collapse:collapse;">
60
+ <tr>
61
+ <td class="email-shell" align="center" style="padding:32px 16px;">
62
+ <table role="presentation" class="email-card" width="100%" cellpadding="0" cellspacing="0" style="max-width:600px;background:#ffffff;border-radius:16px;overflow:hidden;border:1px solid #e5e7eb;border-collapse:collapse;">
63
+ <tr>
64
+ <td class="email-header" align="center" style="padding:28px 32px 20px 32px;background:#ffffff;">
65
+ ${logoHtml}
66
+ ${logoUrl && companyName ? `<div style="margin-top:10px;font-size:13px;color:#6b7280;">${escapeHtml(companyName)}</div>` : ""}
67
+ </td>
68
+ </tr>
69
+ <tr>
70
+ <td style="height:4px;line-height:4px;font-size:0;background:${accent};">&nbsp;</td>
71
+ </tr>
72
+ <tr>
73
+ <td class="email-body" style="padding:28px 32px;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif;font-size:15px;line-height:1.65;color:#1f2937;">
74
+ ${bodyHtml}
75
+ </td>
76
+ </tr>
77
+ <tr>
78
+ <td style="padding:0 32px;">
79
+ <div style="border-top:1px solid #e5e7eb;line-height:0;font-size:0;">&nbsp;</div>
80
+ </td>
81
+ </tr>
82
+ <tr>
83
+ <td align="center" style="padding:20px 32px 28px 32px;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif;">
84
+ ${followTitleHtml}
85
+ ${socialRowHtml}
86
+ ${supportHtml ? `<div style="margin-top:14px;">${supportHtml}</div>` : ""}
87
+ <div style="margin-top:12px;font-size:12px;color:#9ca3af;">\xA9 ${(/* @__PURE__ */ new Date()).getFullYear()} ${escapeHtml(brand)}</div>
88
+ ${disclaimerBlock}
89
+ </td>
90
+ </tr>
91
+ </table>
92
+ </td>
93
+ </tr>
94
+ </table>
95
+ </body>
96
+ </html>`;
97
+ }
98
+ __name(renderLayout, "renderLayout");
99
+
100
+ // src/plugins/email/templates/inline-cta.ts
101
+ function escapeHtml2(s) {
102
+ return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
103
+ }
104
+ __name(escapeHtml2, "escapeHtml");
105
+ function escapeAttr(s) {
106
+ return escapeHtml2(s);
107
+ }
108
+ __name(escapeAttr, "escapeAttr");
109
+ function primaryCtaButton(href, label) {
110
+ return `<table role="presentation" cellpadding="0" cellspacing="0" style="margin:20px 0;">
111
+ <tr><td style="border-radius:6px;background:#1a1a1a;">
112
+ <a href="${escapeAttr(href)}" style="display:inline-block;padding:12px 22px;font-size:14px;font-weight:600;color:#ffffff;text-decoration:none;">${escapeHtml2(label)}</a>
113
+ </td></tr>
114
+ </table>`;
115
+ }
116
+ __name(primaryCtaButton, "primaryCtaButton");
117
+
118
+ // src/plugins/email/templates/signup.ts
119
+ function render(ctx) {
120
+ const { name, loginUrl, verifyEmailUrl, companyDetails } = ctx;
121
+ if (verifyEmailUrl) {
122
+ const subject2 = "Confirm your email";
123
+ const greeting = name && name.trim() ? `Hi ${escapeHtml2(name.trim())},` : "Hi,";
124
+ const bodyHtml2 = `<p style="margin:0 0 12px 0;font-size:15px;line-height:1.5;color:#333;">${greeting}</p>
125
+ <p style="margin:0 0 12px 0;font-size:15px;line-height:1.5;color:#333;">Thanks for signing up. Please confirm your email address to activate your account. Until you confirm, you won\u2019t be able to sign in.</p>
126
+ ${primaryCtaButton(verifyEmailUrl, "Confirm email address")}
127
+ <p style="margin:16px 0 0 0;font-size:12px;line-height:1.5;color:#888;">This link expires in a few days. If you didn\u2019t create an account, you can ignore this message.<br/><span style="word-break:break-all;">${escapeHtml2(verifyEmailUrl)}</span></p>`;
128
+ const text2 = [
129
+ greeting,
130
+ "",
131
+ "Confirm your email to activate your account:",
132
+ verifyEmailUrl,
133
+ "",
134
+ "You cannot sign in until your email is confirmed."
135
+ ].join("\n");
136
+ const html2 = renderLayout({
137
+ bodyHtml: bodyHtml2,
138
+ companyDetails
139
+ });
140
+ return {
141
+ subject: subject2,
142
+ html: html2,
143
+ text: text2
144
+ };
145
+ }
146
+ const subject = "Welcome";
147
+ const bodyHtml = `<p style="margin:0 0 12px 0;font-size:15px;line-height:1.5;color:#333;">Welcome${name ? `, ${escapeHtml2(name)}` : ""}.</p><p style="margin:0 0 12px 0;font-size:15px;line-height:1.5;color:#333;">Your account has been created.</p>${loginUrl ? `${primaryCtaButton(loginUrl, "Sign in")}` : ""}`;
148
+ const text = `Welcome${name ? `, ${name}` : ""}. Your account has been created.${loginUrl ? ` Sign in: ${loginUrl}` : ""}`;
149
+ const html = renderLayout({
150
+ bodyHtml,
151
+ companyDetails
152
+ });
153
+ return {
154
+ subject,
155
+ html,
156
+ text
157
+ };
158
+ }
159
+ __name(render, "render");
160
+
161
+ // src/plugins/email/templates/passwordReset.ts
162
+ function render2(ctx) {
163
+ const { resetLink, companyDetails } = ctx;
164
+ const subject = "Reset your password";
165
+ const bodyHtml = `<p style="margin:0 0 12px 0;font-size:15px;line-height:1.5;color:#333;">Hello,</p>
166
+ <p style="margin:0 0 12px 0;font-size:15px;line-height:1.5;color:#333;">We received a request to reset the password for your account. If you made this request, use the button below to choose a new password.</p>
167
+ <p style="margin:0 0 8px 0;font-size:14px;line-height:1.5;color:#555;">For your security, this link will stop working after a short time. If it expires, request a new reset from the sign-in page.</p>
168
+ ${primaryCtaButton(resetLink, "Reset password")}
169
+ <p style="margin:16px 0 0 0;font-size:12px;line-height:1.5;color:#888;">If you did not request a password reset, you can safely ignore this email\u2014your password will stay the same.</p>
170
+ <p style="margin:12px 0 0 0;font-size:12px;line-height:1.5;color:#888;">If the button does not work, copy and paste this URL into your browser:<br/><span style="word-break:break-all;">${escapeHtml2(resetLink)}</span></p>`;
171
+ const text = [
172
+ "Hello,",
173
+ "",
174
+ "We received a request to reset your password. Open the link below to set a new password:",
175
+ resetLink,
176
+ "",
177
+ "This link expires after a limited time.",
178
+ "",
179
+ "If you did not request this, you can ignore this email."
180
+ ].join("\n");
181
+ const html = renderLayout({
182
+ bodyHtml,
183
+ companyDetails
184
+ });
185
+ return {
186
+ subject,
187
+ html,
188
+ text
189
+ };
190
+ }
191
+ __name(render2, "render");
192
+
193
+ // src/plugins/email/templates/passwordChange.ts
194
+ function render3(ctx) {
195
+ const { name, companyDetails } = ctx;
196
+ const subject = "Password changed";
197
+ const bodyHtml = `<h2>Password changed</h2><p>Your password has been updated successfully${name ? `, ${escapeHtml3(name)}` : ""}.</p>`;
198
+ const text = `Your password has been updated successfully${name ? `, ${name}` : ""}.`;
199
+ const html = renderLayout({
200
+ bodyHtml,
201
+ companyDetails
202
+ });
203
+ return {
204
+ subject,
205
+ html,
206
+ text
207
+ };
208
+ }
209
+ __name(render3, "render");
210
+ function escapeHtml3(s) {
211
+ return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
212
+ }
213
+ __name(escapeHtml3, "escapeHtml");
214
+
215
+ // src/plugins/email/templates/orderPlaced.ts
216
+ function formatMoney(amount, currency) {
217
+ const v = typeof amount === "string" ? parseFloat(amount) : amount;
218
+ const num = Number.isFinite(v) ? Number(v).toFixed(2) : String(amount);
219
+ return currency ? `${num} ${currency}` : num;
220
+ }
221
+ __name(formatMoney, "formatMoney");
222
+ function renderLineItemsHtml(items, currency) {
223
+ if (!items.length) {
224
+ return '<p style="margin:12px 0 0 0;font-size:14px;color:#666;">No line items.</p>';
225
+ }
226
+ const rows = items.map((it) => {
227
+ const name = escapeHtml2(it.productName);
228
+ const sku = it.sku && String(it.sku).trim() ? `<span style="font-size:12px;color:#888;"> (${escapeHtml2(String(it.sku).trim())})</span>` : "";
229
+ const hsn = it.hsn && String(it.hsn).trim() ? `<br/><span style="font-size:11px;color:#888;">HSN: ${escapeHtml2(String(it.hsn).trim())}</span>` : "";
230
+ const taxNote = it.tax != null && String(it.tax).trim() && Number(it.tax) !== 0 ? `<br/><span style="font-size:11px;color:#888;">Tax: ${escapeHtml2(formatMoney(it.tax, currency))}</span>` : "";
231
+ return `<tr>
232
+ <td style="padding:10px 8px 10px 0;border-bottom:1px solid #eee;vertical-align:top;font-size:14px;color:#333;">${name}${sku}${hsn}${taxNote}</td>
233
+ <td align="right" style="padding:10px 8px;border-bottom:1px solid #eee;vertical-align:top;font-size:14px;color:#333;white-space:nowrap;">${escapeHtml2(String(it.quantity))}</td>
234
+ <td align="right" style="padding:10px 8px;border-bottom:1px solid #eee;vertical-align:top;font-size:14px;color:#333;white-space:nowrap;">${escapeHtml2(formatMoney(it.unitPrice, currency))}</td>
235
+ <td align="right" style="padding:10px 0 10px 8px;border-bottom:1px solid #eee;vertical-align:top;font-size:14px;color:#333;white-space:nowrap;">${escapeHtml2(formatMoney(it.lineTotal, currency))}</td>
236
+ </tr>`;
237
+ }).join("");
238
+ return `<p style="margin:16px 0 8px 0;font-size:14px;font-weight:600;color:#111;">Order items</p>
239
+ <table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="border-collapse:collapse;">
240
+ <tr>
241
+ <td style="padding:0 8px 8px 0;font-size:12px;font-weight:600;color:#555;text-transform:uppercase;letter-spacing:0.02em;">Item</td>
242
+ <td align="right" style="padding:0 8px 8px 8px;font-size:12px;font-weight:600;color:#555;text-transform:uppercase;">Qty</td>
243
+ <td align="right" style="padding:0 8px 8px 8px;font-size:12px;font-weight:600;color:#555;text-transform:uppercase;">Price</td>
244
+ <td align="right" style="padding:0 0 8px 8px;font-size:12px;font-weight:600;color:#555;text-transform:uppercase;">Total</td>
245
+ </tr>
246
+ ${rows}
247
+ </table>`;
248
+ }
249
+ __name(renderLineItemsHtml, "renderLineItemsHtml");
250
+ function renderLineItemsText(items, currency) {
251
+ if (!items.length) return "";
252
+ const lines = items.map((it) => {
253
+ let s = `- ${it.productName} \xD7 ${it.quantity} @ ${formatMoney(it.unitPrice, currency)} = ${formatMoney(it.lineTotal, currency)}`;
254
+ if (it.sku) s += ` [${it.sku}]`;
255
+ if (it.hsn && String(it.hsn).trim()) s += ` HSN:${it.hsn}`;
256
+ if (it.tax != null && Number(it.tax) !== 0) s += ` tax:${formatMoney(it.tax, currency)}`;
257
+ return s;
258
+ });
259
+ return [
260
+ "Items:",
261
+ ...lines
262
+ ].join("\n");
263
+ }
264
+ __name(renderLineItemsText, "renderLineItemsText");
265
+ function formatAddressLines(addr) {
266
+ if (!addr || typeof addr !== "object") return [];
267
+ const parts = [
268
+ addr.line1,
269
+ addr.line2,
270
+ [
271
+ addr.city,
272
+ addr.state
273
+ ].filter(Boolean).join(", "),
274
+ addr.postalCode,
275
+ addr.country
276
+ ].filter((x) => x != null && String(x).trim() !== "");
277
+ return parts.map((p) => String(p).trim()).filter(Boolean);
278
+ }
279
+ __name(formatAddressLines, "formatAddressLines");
280
+ function renderAddressesHtml(billing, shipping) {
281
+ const bLines = formatAddressLines(billing);
282
+ const sLines = formatAddressLines(shipping);
283
+ if (!bLines.length && !sLines.length) return "";
284
+ let html = '<p style="margin:16px 0 8px 0;font-size:14px;font-weight:600;color:#111;">Addresses</p>';
285
+ if (bLines.length) {
286
+ html += `<p style="margin:0 0 4px 0;font-size:12px;font-weight:600;color:#555;">Billing</p><p style="margin:0 0 12px 0;font-size:14px;line-height:1.5;color:#333;">${bLines.map((l) => escapeHtml2(l)).join("<br/>")}</p>`;
287
+ }
288
+ if (sLines.length) {
289
+ html += `<p style="margin:0 0 4px 0;font-size:12px;font-weight:600;color:#555;">Shipping</p><p style="margin:0 0 0 0;font-size:14px;line-height:1.5;color:#333;">${sLines.map((l) => escapeHtml2(l)).join("<br/>")}</p>`;
290
+ }
291
+ return html;
292
+ }
293
+ __name(renderAddressesHtml, "renderAddressesHtml");
294
+ function renderAddressesText(billing, shipping) {
295
+ const bLines = formatAddressLines(billing);
296
+ const sLines = formatAddressLines(shipping);
297
+ const out = [];
298
+ if (bLines.length) out.push("Billing:", ...bLines.map((l) => ` ${l}`));
299
+ if (sLines.length) out.push("Shipping:", ...sLines.map((l) => ` ${l}`));
300
+ return out.length ? out.join("\n") : "";
301
+ }
302
+ __name(renderAddressesText, "renderAddressesText");
303
+ function render4(ctx) {
304
+ const { orderNumber, total, subtotal, tax, currency, customerName, companyDetails, audience = "customer", internalCustomerEmail, lineItems = [], billingAddress, shippingAddress, invoiceAttached = false } = ctx;
305
+ const itemsHtml = renderLineItemsHtml(lineItems, currency);
306
+ const itemsText = renderLineItemsText(lineItems, currency);
307
+ const addrHtml = renderAddressesHtml(billingAddress, shippingAddress);
308
+ const addrText = renderAddressesText(billingAddress, shippingAddress);
309
+ const subtotalLine = subtotal != null && String(subtotal).trim() !== "" ? `<p style="margin:8px 0 0 0;font-size:14px;line-height:1.5;color:#333;"><strong>Subtotal:</strong> ${escapeHtml2(String(subtotal))}${currency ? ` ${escapeHtml2(currency)}` : ""}</p>` : "";
310
+ const taxLine = tax != null && String(tax).trim() !== "" && Number(tax) !== 0 ? `<p style="margin:4px 0 0 0;font-size:14px;line-height:1.5;color:#333;"><strong>Tax:</strong> ${escapeHtml2(String(tax))}${currency ? ` ${escapeHtml2(currency)}` : ""}</p>` : "";
311
+ const totalLine = total != null && String(total).trim() !== "" ? `<p style="margin:12px 0 0 0;font-size:15px;line-height:1.5;color:#333;"><strong>Order total:</strong> ${escapeHtml2(String(total))}${currency ? ` ${escapeHtml2(currency)}` : ""}</p>` : "";
312
+ let subject;
313
+ let bodyHtml;
314
+ let text;
315
+ if (audience === "sales") {
316
+ subject = `New order #${orderNumber}`;
317
+ const who = customerName || internalCustomerEmail ? `<p style="margin:0 0 12px 0;font-size:15px;line-height:1.5;color:#333;"><strong>Customer:</strong> ${escapeHtml2(customerName || "\u2014")}${internalCustomerEmail ? ` <span style="color:#555;">(${escapeHtml2(internalCustomerEmail)})</span>` : ""}</p>` : "";
318
+ bodyHtml = `<p style="margin:0 0 12px 0;font-size:15px;line-height:1.5;color:#333;">A new order has been placed and payment completed.</p>
319
+ <p style="margin:0 0 8px 0;font-size:15px;line-height:1.5;color:#333;"><strong>Order number:</strong> ${escapeHtml2(orderNumber)}</p>
320
+ ${who}
321
+ ${addrHtml}
322
+ ${itemsHtml}
323
+ ${subtotalLine}${taxLine}${totalLine}`;
324
+ text = [
325
+ `New order #${orderNumber}`,
326
+ customerName ? `Customer: ${customerName}` : "",
327
+ internalCustomerEmail ? `Email: ${internalCustomerEmail}` : "",
328
+ addrText,
329
+ itemsText,
330
+ subtotal != null ? `Subtotal: ${subtotal}${currency ? ` ${currency}` : ""}` : "",
331
+ tax != null && Number(tax) !== 0 ? `Tax: ${tax}${currency ? ` ${currency}` : ""}` : "",
332
+ total != null ? `Order total: ${total}${currency ? ` ${currency}` : ""}` : ""
333
+ ].filter(Boolean).join("\n\n");
334
+ } else {
335
+ subject = `Order confirmed #${orderNumber}`;
336
+ const thanksPlain = customerName && customerName.trim() ? `Thank you, ${customerName.trim()}.` : "Thank you for your order.";
337
+ const thanksHtml = `${escapeHtml2(thanksPlain)} We\u2019ve received your order and will process it shortly.`;
338
+ bodyHtml = `<p style="margin:0 0 12px 0;font-size:15px;line-height:1.5;color:#333;">${thanksHtml}</p>
339
+ <p style="margin:0 0 8px 0;font-size:15px;line-height:1.5;color:#333;"><strong>Order number:</strong> ${escapeHtml2(orderNumber)}</p>
340
+ ${addrHtml}
341
+ ${itemsHtml}
342
+ ${subtotalLine}${taxLine}${totalLine}
343
+ ${invoiceAttached ? `<p style="margin:16px 0 0 0;font-size:14px;line-height:1.5;color:#333;">Your order invoice is attached as a PDF.</p>` : ""}
344
+ <p style="margin:16px 0 0 0;font-size:13px;line-height:1.5;color:#666;">If you have questions, reply to this email or contact us using the details below.</p>`;
345
+ text = [
346
+ `Order confirmed #${orderNumber}`,
347
+ `${thanksPlain} We\u2019ve received your order and will process it shortly.`,
348
+ "",
349
+ addrText,
350
+ itemsText,
351
+ subtotal != null ? `Subtotal: ${subtotal}${currency ? ` ${currency}` : ""}` : "",
352
+ tax != null && Number(tax) !== 0 ? `Tax: ${tax}${currency ? ` ${currency}` : ""}` : "",
353
+ total != null ? `Order total: ${total}${currency ? ` ${currency}` : ""}` : "",
354
+ invoiceAttached ? "Your order invoice is attached as a PDF." : "",
355
+ "",
356
+ "We will process your order shortly."
357
+ ].filter((line, i, arr) => !(line === "" && arr[i - 1] === "")).join("\n");
358
+ }
359
+ const html = renderLayout({
360
+ bodyHtml,
361
+ companyDetails
362
+ });
363
+ return {
364
+ subject,
365
+ html,
366
+ text
367
+ };
368
+ }
369
+ __name(render4, "render");
370
+
371
+ // src/plugins/email/templates/returnInitiated.ts
372
+ function render5(ctx) {
373
+ const { returnId, orderNumber, companyDetails } = ctx;
374
+ const subject = "Return initiated";
375
+ const bodyHtml = `<h2>Return initiated</h2><p>Your return request has been received.</p>${orderNumber ? `<p><strong>Order:</strong> ${escapeHtml4(orderNumber)}</p>` : ""}${returnId ? `<p><strong>Return ID:</strong> ${escapeHtml4(returnId)}</p>` : ""}`;
376
+ const text = `Return initiated.${orderNumber ? ` Order: ${orderNumber}` : ""}${returnId ? ` Return ID: ${returnId}` : ""}`;
377
+ const html = renderLayout({
378
+ bodyHtml,
379
+ companyDetails
380
+ });
381
+ return {
382
+ subject,
383
+ html,
384
+ text
385
+ };
386
+ }
387
+ __name(render5, "render");
388
+ function escapeHtml4(s) {
389
+ return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
390
+ }
391
+ __name(escapeHtml4, "escapeHtml");
392
+
393
+ // src/plugins/email/templates/shippingUpdate.ts
394
+ function render6(ctx) {
395
+ const { orderNumber, status, trackingUrl, companyDetails } = ctx;
396
+ const subject = status ? `Shipping update: ${status}` : "Shipping update";
397
+ const bodyHtml = `<h2>Shipping update</h2>${status ? `<p><strong>Status:</strong> ${escapeHtml5(status)}</p>` : ""}${orderNumber ? `<p><strong>Order:</strong> ${escapeHtml5(orderNumber)}</p>` : ""}${trackingUrl ? `<p><a href="${escapeHtml5(trackingUrl)}">Track your order</a></p>` : ""}`;
398
+ const text = `Shipping update.${status ? ` Status: ${status}` : ""}${orderNumber ? ` Order: ${orderNumber}` : ""}${trackingUrl ? ` Track: ${trackingUrl}` : ""}`;
399
+ const html = renderLayout({
400
+ bodyHtml,
401
+ companyDetails
402
+ });
403
+ return {
404
+ subject,
405
+ html,
406
+ text
407
+ };
408
+ }
409
+ __name(render6, "render");
410
+ function escapeHtml5(s) {
411
+ return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
412
+ }
413
+ __name(escapeHtml5, "escapeHtml");
414
+
415
+ // src/plugins/email/templates/invite.ts
416
+ function render7(ctx) {
417
+ const { inviteLink, email, inviteeName, companyDetails } = ctx;
418
+ const subject = "You're invited";
419
+ const greeting = inviteeName && inviteeName.trim() ? `Hello ${escapeHtml2(inviteeName.trim())},` : "Hello,";
420
+ const bodyHtml = `<p style="margin:0 0 12px 0;font-size:15px;line-height:1.5;color:#333;">${greeting}</p>
421
+ <p style="margin:0 0 12px 0;font-size:15px;line-height:1.5;color:#333;">You have been invited to create your account for <strong>${escapeHtml2(email)}</strong>. Use the secure link below to choose your password and activate access.</p>
422
+ <p style="margin:0 0 8px 0;font-size:14px;line-height:1.5;color:#555;">This link is personal to you. If you did not expect this invitation, you can ignore this message.</p>
423
+ ${primaryCtaButton(inviteLink, "Accept invitation & set password")}
424
+ <p style="margin:16px 0 0 0;font-size:12px;line-height:1.5;color:#888;">If the button does not work, copy and paste this URL into your browser:<br/><span style="word-break:break-all;">${escapeHtml2(inviteLink)}</span></p>`;
425
+ const text = [
426
+ inviteeName?.trim() ? `Hello ${inviteeName.trim()},` : "Hello,",
427
+ "",
428
+ `You have been invited to create your account (${email}).`,
429
+ "Open this link to set your password:",
430
+ inviteLink,
431
+ "",
432
+ "If you did not expect this invitation, you can ignore this email."
433
+ ].join("\n");
434
+ const html = renderLayout({
435
+ bodyHtml,
436
+ companyDetails
437
+ });
438
+ return {
439
+ subject,
440
+ html,
441
+ text
442
+ };
443
+ }
444
+ __name(render7, "render");
445
+
446
+ // src/plugins/email/templates/formSubmission.ts
447
+ function render8(ctx) {
448
+ const { formName, contactName, contactEmail, formData, formFieldRows, companyDetails } = ctx;
449
+ const subject = `New Form Submission: ${formName}`;
450
+ const fieldsBlock = formFieldRows && formFieldRows.length > 0 ? formFieldRows.map((r) => `<p style="margin:10px 0 0 0;line-height:1.5;"><strong>${escapeHtml6(r.label)}</strong><br/>${escapeHtml6(r.value)}</p>`).join("") : `<p style="margin:10px 0 0 0;font-size:13px;white-space:pre-wrap;">${escapeHtml6(JSON.stringify(formData, null, 2))}</p>`;
451
+ const bodyHtml = `<p style="margin:0 0 6px 0;font-size:18px;font-weight:600;color:#111;">New Form Submission</p>
452
+ <p style="margin:0 0 4px 0;"><strong>Form:</strong> ${escapeHtml6(formName)}</p>
453
+ <p style="margin:0 0 8px 0;"><strong>Contact:</strong> ${escapeHtml6(contactName)}${contactEmail ? ` (${escapeHtml6(contactEmail)})` : ""}</p>
454
+ ${fieldsBlock}`;
455
+ const textLines = [
456
+ "New Form Submission",
457
+ `Form: ${formName}`,
458
+ `Contact: ${contactName}${contactEmail ? ` (${contactEmail})` : ""}`,
459
+ "",
460
+ ...formFieldRows?.length ? formFieldRows.map((r) => `${r.label}: ${r.value}`) : [
461
+ JSON.stringify(formData, null, 2)
462
+ ]
463
+ ];
464
+ const text = textLines.join("\n");
465
+ const html = renderLayout({
466
+ bodyHtml,
467
+ companyDetails
468
+ });
469
+ return {
470
+ subject,
471
+ html,
472
+ text
473
+ };
474
+ }
475
+ __name(render8, "render");
476
+ function escapeHtml6(s) {
477
+ return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
478
+ }
479
+ __name(escapeHtml6, "escapeHtml");
480
+
481
+ // src/plugins/email/templates/otp.ts
482
+ function render9(ctx) {
483
+ const { code, companyDetails } = ctx;
484
+ const name = companyDetails.companyName?.trim() || "Our store";
485
+ const bodyHtml = `
486
+ <p>Your verification code is:</p>
487
+ <p style="font-size:24px;font-weight:bold;letter-spacing:4px;">${escapeHtml7(code)}</p>
488
+ <p style="color:#666;font-size:14px;">This code expires in 10 minutes. If you did not request it, you can ignore this email.</p>
489
+ `;
490
+ const html = renderLayout({
491
+ bodyHtml,
492
+ companyDetails
493
+ });
494
+ return {
495
+ subject: `${name}: your sign-in code`,
496
+ html,
497
+ text: `Your code is ${code}. It expires in 10 minutes.`
498
+ };
499
+ }
500
+ __name(render9, "render");
501
+ function escapeHtml7(s) {
502
+ return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
503
+ }
504
+ __name(escapeHtml7, "escapeHtml");
505
+
506
+ // src/plugins/email/templates/chatLead.ts
507
+ function render10(ctx) {
508
+ const { contactName, contactEmail, contactPhone, conversationId, latestMessage, intentCode, intentReason, transcript, companyDetails } = ctx;
509
+ const intentDisplay = intentCode?.trim() ? `${intentCode.trim()}${intentReason?.trim() ? ` \u2014 ${intentReason.trim()}` : ""}` : intentReason;
510
+ const subject = `Chat lead${intentCode?.trim() ? ` [${intentCode.trim()}]` : ""}: ${contactName || contactEmail || "Visitor"}`;
511
+ const transcriptBlock = transcript?.trim() ? `<div style="margin-top:16px;padding:12px;background:#f9fafb;border-radius:6px;border:1px solid #e5e7eb;">
512
+ <p style="margin:0 0 8px 0;font-size:13px;font-weight:600;color:#374151;">Recent conversation</p>
513
+ <pre style="margin:0;font-size:12px;white-space:pre-wrap;font-family:inherit;color:#4b5563;">${escapeHtml8(transcript.trim())}</pre>
514
+ </div>` : "";
515
+ const bodyHtml = `<p style="margin:0 0 6px 0;font-size:18px;font-weight:600;color:#111;">New chat lead</p>
516
+ <p style="margin:0 0 12px 0;font-size:14px;color:#374151;">A visitor showed interest based on your intent rules.</p>
517
+ <table style="width:100%;border-collapse:collapse;font-size:14px;">
518
+ <tr><td style="padding:4px 8px 4px 0;color:#6b7280;vertical-align:top;">Name</td><td>${escapeHtml8(contactName || "\u2014")}</td></tr>
519
+ <tr><td style="padding:4px 8px 4px 0;color:#6b7280;vertical-align:top;">Email</td><td><a href="mailto:${escapeHtml8(contactEmail)}">${escapeHtml8(contactEmail)}</a></td></tr>
520
+ <tr><td style="padding:4px 8px 4px 0;color:#6b7280;vertical-align:top;">Phone</td><td>${escapeHtml8(contactPhone?.trim() || "\u2014")}</td></tr>
521
+ <tr><td style="padding:4px 8px 4px 0;color:#6b7280;vertical-align:top;">Conversation</td><td>#${conversationId}</td></tr>
522
+ <tr><td style="padding:4px 8px 4px 0;color:#6b7280;vertical-align:top;">Intent</td><td>${escapeHtml8(intentReason)}</td></tr>
523
+ </table>
524
+ <p style="margin:16px 0 6px 0;font-size:13px;font-weight:600;color:#374151;">Latest message</p>
525
+ <p style="margin:0;font-size:14px;white-space:pre-wrap;">${escapeHtml8(latestMessage)}</p>
526
+ ${transcriptBlock}`;
527
+ const text = [
528
+ "New chat lead",
529
+ `Name: ${contactName || "\u2014"}`,
530
+ `Email: ${contactEmail}`,
531
+ `Phone: ${contactPhone?.trim() || "\u2014"}`,
532
+ `Conversation: #${conversationId}`,
533
+ `Intent: ${intentDisplay}`,
534
+ "",
535
+ "Latest message:",
536
+ latestMessage,
537
+ transcript?.trim() ? `
538
+ Recent conversation:
539
+ ${transcript.trim()}` : ""
540
+ ].join("\n");
541
+ const html = renderLayout({
542
+ bodyHtml,
543
+ companyDetails
544
+ });
545
+ return {
546
+ subject,
547
+ html,
548
+ text
549
+ };
550
+ }
551
+ __name(render10, "render");
552
+ function escapeHtml8(s) {
553
+ return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
554
+ }
555
+ __name(escapeHtml8, "escapeHtml");
556
+
557
+ // src/plugins/email/templates/vendorOnboarded.ts
558
+ function render11(ctx) {
559
+ const { audience, activation, kind = "vendor_onboard", vendorName, vendorSlug, ownerName, ownerEmail, inviteLink, signInLink, companyDetails } = ctx;
560
+ const storeLabel = vendorName.trim() || "your store";
561
+ const greeting = ownerName && ownerName.trim() ? `Hello ${escapeHtml2(ownerName.trim())},` : "Hello,";
562
+ const slugNote = vendorSlug && vendorSlug.trim() ? `<p style="margin:0 0 8px 0;font-size:14px;line-height:1.5;color:#555;"><strong>Store URL slug:</strong> ${escapeHtml2(vendorSlug.trim())}</p>` : "";
563
+ let subject;
564
+ let bodyHtml;
565
+ let text;
566
+ if (audience === "internal") {
567
+ const action = kind === "team_invite" ? "A team member was invited to a vendor store." : activation === "invite" ? "A new vendor store was created and the owner was invited." : "A new vendor store was created with an active owner account.";
568
+ subject = kind === "team_invite" ? `Team invite: ${storeLabel}` : `New vendor: ${storeLabel}`;
569
+ bodyHtml = `<p style="margin:0 0 12px 0;font-size:15px;line-height:1.5;color:#333;">${action}</p>
570
+ <p style="margin:0 0 8px 0;font-size:15px;line-height:1.5;color:#333;"><strong>Store:</strong> ${escapeHtml2(storeLabel)}</p>
571
+ ${slugNote}
572
+ <p style="margin:0 0 8px 0;font-size:15px;line-height:1.5;color:#333;"><strong>Owner / invitee:</strong> ${escapeHtml2(ownerName?.trim() || "\u2014")} <span style="color:#555;">(${escapeHtml2(ownerEmail)})</span></p>
573
+ <p style="margin:0 0 0 0;font-size:14px;line-height:1.5;color:#555;"><strong>Activation:</strong> ${escapeHtml2(activation === "invite" ? "Invitation" : "Password set")}</p>`;
574
+ text = [
575
+ subject,
576
+ "",
577
+ action,
578
+ `Store: ${storeLabel}`,
579
+ vendorSlug ? `Slug: ${vendorSlug}` : "",
580
+ `Owner / invitee: ${ownerName?.trim() || "\u2014"} (${ownerEmail})`,
581
+ `Activation: ${activation === "invite" ? "Invitation" : "Password set"}`
582
+ ].filter(Boolean).join("\n");
583
+ } else if (kind === "team_invite" && activation === "membership" && inviteLink) {
584
+ subject = `You're invited to ${storeLabel}`;
585
+ bodyHtml = `<p style="margin:0 0 12px 0;font-size:15px;line-height:1.5;color:#333;">${greeting}</p>
586
+ <p style="margin:0 0 12px 0;font-size:15px;line-height:1.5;color:#333;">You have been invited to join the vendor team for <strong>${escapeHtml2(storeLabel)}</strong>. You already have an account \u2014 accept below to join this store. You will not need to set a new password.</p>
587
+ ${primaryCtaButton(inviteLink, "Accept invitation")}
588
+ <p style="margin:16px 0 0 0;font-size:12px;line-height:1.5;color:#888;">If the button does not work, copy and paste this URL into your browser:<br/><span style="word-break:break-all;">${escapeHtml2(inviteLink)}</span></p>`;
589
+ text = [
590
+ ownerName?.trim() ? `Hello ${ownerName.trim()},` : "Hello,",
591
+ "",
592
+ `You have been invited to join ${storeLabel}.`,
593
+ "Open this link to accept (no new password required):",
594
+ inviteLink
595
+ ].join("\n");
596
+ } else if (kind === "team_invite" && activation === "invite" && inviteLink) {
597
+ subject = `You're invited to ${storeLabel}`;
598
+ bodyHtml = `<p style="margin:0 0 12px 0;font-size:15px;line-height:1.5;color:#333;">${greeting}</p>
599
+ <p style="margin:0 0 12px 0;font-size:15px;line-height:1.5;color:#333;">You have been invited to join the vendor team for <strong>${escapeHtml2(storeLabel)}</strong>. Use the secure link below to set your password and activate your account.</p>
600
+ ${primaryCtaButton(inviteLink, "Accept invitation & set password")}
601
+ <p style="margin:16px 0 0 0;font-size:12px;line-height:1.5;color:#888;">If the button does not work, copy and paste this URL into your browser:<br/><span style="word-break:break-all;">${escapeHtml2(inviteLink)}</span></p>`;
602
+ text = [
603
+ ownerName?.trim() ? `Hello ${ownerName.trim()},` : "Hello,",
604
+ "",
605
+ `You have been invited to join ${storeLabel}.`,
606
+ "Open this link to set your password:",
607
+ inviteLink
608
+ ].join("\n");
609
+ } else if (activation === "invite" && inviteLink) {
610
+ subject = `Your vendor store "${storeLabel}" is ready`;
611
+ bodyHtml = `<p style="margin:0 0 12px 0;font-size:15px;line-height:1.5;color:#333;">${greeting}</p>
612
+ <p style="margin:0 0 12px 0;font-size:15px;line-height:1.5;color:#333;">Your vendor store <strong>${escapeHtml2(storeLabel)}</strong> has been created. Accept the invitation below to set your password and access the admin dashboard.</p>
613
+ ${slugNote}
614
+ ${primaryCtaButton(inviteLink, "Accept invitation & set password")}
615
+ <p style="margin:16px 0 0 0;font-size:12px;line-height:1.5;color:#888;">If the button does not work, copy and paste this URL into your browser:<br/><span style="word-break:break-all;">${escapeHtml2(inviteLink)}</span></p>`;
616
+ text = [
617
+ ownerName?.trim() ? `Hello ${ownerName.trim()},` : "Hello,",
618
+ "",
619
+ `Your vendor store "${storeLabel}" has been created.`,
620
+ "Open this link to set your password:",
621
+ inviteLink
622
+ ].join("\n");
623
+ } else {
624
+ subject = `Welcome to ${storeLabel}`;
625
+ const loginUrl = signInLink?.trim() || inviteLink?.trim() || "";
626
+ bodyHtml = `<p style="margin:0 0 12px 0;font-size:15px;line-height:1.5;color:#333;">${greeting}</p>
627
+ <p style="margin:0 0 12px 0;font-size:15px;line-height:1.5;color:#333;">Your vendor store <strong>${escapeHtml2(storeLabel)}</strong> has been created and your owner account is ready. Sign in to the admin dashboard to manage your store.</p>
628
+ ${slugNote}
629
+ ${loginUrl ? primaryCtaButton(loginUrl, "Sign in to admin") : ""}
630
+ ${loginUrl ? `<p style="margin:16px 0 0 0;font-size:12px;line-height:1.5;color:#888;">Sign-in URL:<br/><span style="word-break:break-all;">${escapeHtml2(loginUrl)}</span></p>` : ""}`;
631
+ text = [
632
+ ownerName?.trim() ? `Hello ${ownerName.trim()},` : "Hello,",
633
+ "",
634
+ `Your vendor store "${storeLabel}" has been created.`,
635
+ loginUrl ? `Sign in: ${loginUrl}` : ""
636
+ ].filter(Boolean).join("\n");
637
+ }
638
+ const html = renderLayout({
639
+ bodyHtml,
640
+ companyDetails
641
+ });
642
+ return {
643
+ subject,
644
+ html,
645
+ text
646
+ };
647
+ }
648
+ __name(render11, "render");
649
+
650
+ // src/plugins/email/templates/index.ts
651
+ var templateRenderMap = {
652
+ signup: render,
653
+ passwordReset: render2,
654
+ passwordChange: render3,
655
+ orderPlaced: render4,
656
+ returnInitiated: render5,
657
+ shippingUpdate: render6,
658
+ invite: render7,
659
+ formSubmission: render8,
660
+ otp: render9,
661
+ chatLead: render10,
662
+ vendorOnboarded: render11
663
+ };
664
+ function getTemplateRenderer(name) {
665
+ return templateRenderMap[name];
666
+ }
667
+ __name(getTemplateRenderer, "getTemplateRenderer");
668
+
669
+ // src/plugins/email/renderer.ts
670
+ function renderEmail(templateName, ctx, options) {
671
+ const layoutFn = options?.renderLayout ?? renderLayout;
672
+ const getBody = options?.getBody;
673
+ if (getBody) {
674
+ const custom = getBody(templateName, ctx);
675
+ if (custom != null) {
676
+ const html = layoutFn({
677
+ bodyHtml: custom.bodyHtml,
678
+ companyDetails: ctx.companyDetails
679
+ });
680
+ return {
681
+ subject: custom.subject,
682
+ html,
683
+ text: custom.text
684
+ };
685
+ }
686
+ }
687
+ const render12 = getTemplateRenderer(templateName);
688
+ if (!render12) {
689
+ throw new Error(`Unknown email template: ${templateName}`);
690
+ }
691
+ return render12(ctx);
692
+ }
693
+ __name(renderEmail, "renderEmail");
694
+
695
+ // src/plugins/email/email-service.ts
696
+ var require2 = createRequire(import.meta.url);
697
+ var MailComposer = require2("nodemailer/lib/mail-composer");
698
+ var SES_REGIONS_WITHOUT_SMTP = /* @__PURE__ */ new Set([
699
+ "af-south-1",
700
+ "ap-south-2",
701
+ "ap-southeast-3",
702
+ "ap-southeast-5",
703
+ "ca-west-1",
704
+ "eu-central-2",
705
+ "eu-south-1",
706
+ "il-central-1",
707
+ "me-central-1",
708
+ "me-south-1"
709
+ ]);
710
+ function sesSmtpHost(region) {
711
+ return `email-smtp.${region}.amazonaws.com`;
712
+ }
713
+ __name(sesSmtpHost, "sesSmtpHost");
714
+ function sesRegionSupportsSmtp(region) {
715
+ return !SES_REGIONS_WITHOUT_SMTP.has(region.trim());
716
+ }
717
+ __name(sesRegionSupportsSmtp, "sesRegionSupportsSmtp");
718
+ function toBuffer(content) {
719
+ return Buffer.isBuffer(content) ? content : Buffer.from(content);
720
+ }
721
+ __name(toBuffer, "toBuffer");
722
+ var EmailService = class {
723
+ static {
724
+ __name(this, "EmailService");
725
+ }
726
+ config;
727
+ templateOptions;
728
+ sesClient;
729
+ transporter;
730
+ /** AWS via SMTP (nodemailer) vs SES API SDK. */
731
+ awsViaSmtp = false;
732
+ constructor(config) {
733
+ this.config = config;
734
+ this.templateOptions = config.templateOptions;
735
+ if (config.type === "AWS") {
736
+ if (!config.region) {
737
+ throw new Error("AWS SES configuration incomplete: AWS_REGION is required");
738
+ }
739
+ if (config.user && config.password) {
740
+ this.awsViaSmtp = true;
741
+ const host = config.host || sesSmtpHost(config.region);
742
+ const port = config.port ?? 587;
743
+ const secure = config.secure ?? false;
744
+ this.transporter = nodemailer.createTransport({
745
+ host,
746
+ port,
747
+ secure,
748
+ auth: {
749
+ user: config.user,
750
+ pass: config.password
751
+ }
752
+ });
753
+ } else if (config.accessKeyId && config.secretAccessKey) {
754
+ this.sesClient = new SESClient({
755
+ region: config.region,
756
+ credentials: {
757
+ accessKeyId: config.accessKeyId,
758
+ secretAccessKey: config.secretAccessKey
759
+ }
760
+ });
761
+ } else {
762
+ throw new Error("AWS SES configuration incomplete: set SMTP_USER and SMTP_PASSWORD (SES SMTP) or AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY (SES API)");
763
+ }
764
+ } else if (config.type === "SMTP" || config.type === "GMAIL") {
765
+ if (!config.user || !config.password) throw new Error("SMTP configuration incomplete");
766
+ const host = config.type === "GMAIL" ? "smtp.gmail.com" : config.host;
767
+ if (!host) {
768
+ throw new Error("SMTP configuration incomplete: SMTP_HOST is required when SMTP_TYPE=SMTP (nodemailer otherwise connects to 127.0.0.1)");
769
+ }
770
+ const port = config.port ?? 587;
771
+ const secure = config.secure ?? false;
772
+ this.transporter = nodemailer.createTransport({
773
+ host,
774
+ port,
775
+ secure,
776
+ auth: {
777
+ user: config.user,
778
+ pass: config.password
779
+ }
780
+ });
781
+ } else {
782
+ throw new Error(`Unsupported email type: ${config.type}`);
783
+ }
784
+ }
785
+ nodemailerAttachments(attachments) {
786
+ if (!attachments?.length) return void 0;
787
+ return attachments.map((a) => ({
788
+ filename: a.filename,
789
+ content: toBuffer(a.content),
790
+ contentType: a.contentType || "application/octet-stream"
791
+ }));
792
+ }
793
+ async send(emailData) {
794
+ try {
795
+ const from = emailData.from || this.config.from;
796
+ const to = emailData.to || this.config.to;
797
+ const attachments = this.nodemailerAttachments(emailData.attachments);
798
+ if (this.config.type === "AWS" && this.sesClient) {
799
+ if (attachments?.length) {
800
+ const composer = new MailComposer({
801
+ from,
802
+ to,
803
+ subject: emailData.subject,
804
+ html: emailData.html,
805
+ text: emailData.text,
806
+ attachments
807
+ });
808
+ const raw = await new Promise((resolve, reject) => {
809
+ composer.compile().build((err, message) => {
810
+ if (err) reject(err);
811
+ else resolve(message);
812
+ });
813
+ });
814
+ await this.sesClient.send(new SendRawEmailCommand({
815
+ RawMessage: {
816
+ Data: raw
817
+ }
818
+ }));
819
+ return true;
820
+ }
821
+ await this.sesClient.send(new SendEmailCommand({
822
+ Source: from,
823
+ Destination: {
824
+ ToAddresses: [
825
+ to
826
+ ]
827
+ },
828
+ Message: {
829
+ Subject: {
830
+ Data: emailData.subject,
831
+ Charset: "UTF-8"
832
+ },
833
+ Body: {
834
+ Html: {
835
+ Data: emailData.html,
836
+ Charset: "UTF-8"
837
+ },
838
+ ...emailData.text && {
839
+ Text: {
840
+ Data: emailData.text,
841
+ Charset: "UTF-8"
842
+ }
843
+ }
844
+ }
845
+ }
846
+ }));
847
+ return true;
848
+ }
849
+ if (this.transporter && (this.config.type === "SMTP" || this.config.type === "GMAIL" || this.config.type === "AWS" && this.awsViaSmtp)) {
850
+ await this.transporter.sendMail({
851
+ from,
852
+ to,
853
+ subject: emailData.subject,
854
+ html: emailData.html,
855
+ text: emailData.text,
856
+ attachments
857
+ });
858
+ return true;
859
+ }
860
+ return false;
861
+ } catch (error) {
862
+ console.error("Email sending failed:", error);
863
+ return false;
864
+ }
865
+ }
866
+ renderTemplate(templateName, ctx) {
867
+ return renderEmail(templateName, ctx, this.templateOptions);
868
+ }
869
+ /** Default notification recipient from plugin config (SMTP_TO / plugin `to`). */
870
+ getDefaultTo() {
871
+ return this.config.to;
872
+ }
873
+ };
874
+ var emailTemplates = {
875
+ formSubmission: /* @__PURE__ */ __name((data) => ({
876
+ subject: `New Form Submission: ${data.formName}`,
877
+ html: `<h2>New Form Submission</h2><p><strong>Form:</strong> ${data.formName}</p><p><strong>Contact:</strong> ${data.contactName} (${data.contactEmail})</p><pre>${JSON.stringify(data.formData, null, 2)}</pre>`,
878
+ text: `New Form Submission
879
+ Form: ${data.formName}
880
+ Contact: ${data.contactName} (${data.contactEmail})
881
+ ${JSON.stringify(data.formData, null, 2)}`
882
+ }), "formSubmission"),
883
+ contactSubmission: /* @__PURE__ */ __name((data) => ({
884
+ subject: `New Contact Form Submission from ${data.name}`,
885
+ html: `<h2>New Contact Form Submission</h2><p><strong>Name:</strong> ${data.name}</p><p><strong>Email:</strong> ${data.email}</p>${data.phone ? `<p><strong>Phone:</strong> ${data.phone}</p>` : ""}${data.message ? `<p><strong>Message:</strong></p><p>${data.message}</p>` : ""}`,
886
+ text: `New Contact Form Submission
887
+ Name: ${data.name}
888
+ Email: ${data.email}
889
+ ${data.phone ? `Phone: ${data.phone}
890
+ ` : ""}${data.message ? `Message: ${data.message}` : ""}`
891
+ }), "contactSubmission"),
892
+ passwordReset: /* @__PURE__ */ __name((data) => ({
893
+ subject: "Reset your password",
894
+ html: `<h2>Reset your password</h2><p>Click the link below to set a new password. This link expires in 1 hour.</p><p><a href="${data.resetLink}">${data.resetLink}</a></p>`,
895
+ text: `Reset your password: ${data.resetLink}
896
+
897
+ This link expires in 1 hour.`
898
+ }), "passwordReset")
899
+ };
900
+
901
+ export { EmailService, SES_REGIONS_WITHOUT_SMTP, emailTemplates, renderEmail, renderLayout, sesRegionSupportsSmtp, sesSmtpHost };