@prenta/plugin-email 0.4.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/CHANGELOG.md +254 -0
- package/LICENSE +21 -0
- package/README.md +29 -0
- package/dist/__tests__/index.test.d.ts +2 -0
- package/dist/__tests__/index.test.d.ts.map +1 -0
- package/dist/__tests__/index.test.js +306 -0
- package/dist/__tests__/index.test.js.map +1 -0
- package/dist/__tests__/provider-factory.test.d.ts +2 -0
- package/dist/__tests__/provider-factory.test.d.ts.map +1 -0
- package/dist/__tests__/provider-factory.test.js +64 -0
- package/dist/__tests__/provider-factory.test.js.map +1 -0
- package/dist/__tests__/providers.test.d.ts +2 -0
- package/dist/__tests__/providers.test.d.ts.map +1 -0
- package/dist/__tests__/providers.test.js +186 -0
- package/dist/__tests__/providers.test.js.map +1 -0
- package/dist/__tests__/smtp-missing-nodemailer.test.d.ts +2 -0
- package/dist/__tests__/smtp-missing-nodemailer.test.d.ts.map +1 -0
- package/dist/__tests__/smtp-missing-nodemailer.test.js +35 -0
- package/dist/__tests__/smtp-missing-nodemailer.test.js.map +1 -0
- package/dist/__tests__/smtp.test.d.ts +2 -0
- package/dist/__tests__/smtp.test.d.ts.map +1 -0
- package/dist/__tests__/smtp.test.js +70 -0
- package/dist/__tests__/smtp.test.js.map +1 -0
- package/dist/__tests__/templates.test.d.ts +2 -0
- package/dist/__tests__/templates.test.d.ts.map +1 -0
- package/dist/__tests__/templates.test.js +55 -0
- package/dist/__tests__/templates.test.js.map +1 -0
- package/dist/collections.d.ts +3 -0
- package/dist/collections.d.ts.map +1 -0
- package/dist/collections.js +2 -0
- package/dist/collections.js.map +1 -0
- package/dist/fields.d.ts +3 -0
- package/dist/fields.d.ts.map +1 -0
- package/dist/fields.js +2 -0
- package/dist/fields.js.map +1 -0
- package/dist/hooks.d.ts +3 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +2 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index.d.ts +65 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +181 -0
- package/dist/index.js.map +1 -0
- package/dist/providers/resend.d.ts +21 -0
- package/dist/providers/resend.d.ts.map +1 -0
- package/dist/providers/resend.js +31 -0
- package/dist/providers/resend.js.map +1 -0
- package/dist/providers/ses.d.ts +7 -0
- package/dist/providers/ses.d.ts.map +1 -0
- package/dist/providers/ses.js +44 -0
- package/dist/providers/ses.js.map +1 -0
- package/dist/providers/smtp.d.ts +38 -0
- package/dist/providers/smtp.d.ts.map +1 -0
- package/dist/providers/smtp.js +60 -0
- package/dist/providers/smtp.js.map +1 -0
- package/dist/providers/smtpcom.d.ts +14 -0
- package/dist/providers/smtpcom.d.ts.map +1 -0
- package/dist/providers/smtpcom.js +65 -0
- package/dist/providers/smtpcom.js.map +1 -0
- package/dist/templates/index.d.ts +22 -0
- package/dist/templates/index.d.ts.map +1 -0
- package/dist/templates/index.js +101 -0
- package/dist/templates/index.js.map +1 -0
- package/package.json +49 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { definePlugin } from '@prenta/core/config';
|
|
2
|
+
// Import from the lightweight subpath, not the full barrel: pulling the entire
|
|
3
|
+
// cms-core barrel (handlers, middleware, etc.) here made plugin-email's tests —
|
|
4
|
+
// which re-import this module on every `vi.resetModules()` — blow past the 5s
|
|
5
|
+
// timeout in CI. The registry module only depends on the config runtime.
|
|
6
|
+
import { setEmailSender, setEmailProviderFactory } from '@prenta/core/email-sender';
|
|
7
|
+
import { emailFields } from './fields.js';
|
|
8
|
+
import { emailCollections } from './collections.js';
|
|
9
|
+
import { emailHooks } from './hooks.js';
|
|
10
|
+
import { createResendProvider } from './providers/resend.js';
|
|
11
|
+
import { createSESProvider } from './providers/ses.js';
|
|
12
|
+
import { createSmtpComProvider } from './providers/smtpcom.js';
|
|
13
|
+
import { createSmtpProvider } from './providers/smtp.js';
|
|
14
|
+
let _emailProvider = null;
|
|
15
|
+
/** Get the configured email provider instance. */
|
|
16
|
+
export function getEmailProvider() {
|
|
17
|
+
return _emailProvider;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Resolve an {@link EmailPluginConfig} from environment variables. Returns
|
|
21
|
+
* `undefined` when no email provider can be determined, so callers fall back
|
|
22
|
+
* to "no provider configured" rather than registering a broken one.
|
|
23
|
+
*
|
|
24
|
+
* Selection order:
|
|
25
|
+
* 1. `EMAIL_PROVIDER` (explicit: `resend` | `ses` | `smtpcom` | `smtp`).
|
|
26
|
+
* 2. Inference when `EMAIL_PROVIDER` is unset: `SMTP_HOST` → smtp,
|
|
27
|
+
* an SMTP.com API key → smtpcom, otherwise `RESEND_API_KEY` → resend.
|
|
28
|
+
*
|
|
29
|
+
* Recognised vars: `EMAIL_FROM`, `RESEND_API_KEY`, `SES_REGION`/`AWS_REGION`,
|
|
30
|
+
* the generic relay (`SMTP_HOST`/`SMTP_PORT`/`SMTP_SECURE`/`SMTP_USER`/
|
|
31
|
+
* `SMTP_PASS`), and SMTP.com's v4 API
|
|
32
|
+
* (`SMTPCOM_API_KEY`/`SMTPCOM_CHANNEL`, or the shorter `SMTP_KEY`/
|
|
33
|
+
* `SMTP_CHANNEL`/`SMTP_EMAIL` aliases that SMTP.com's own dashboard uses).
|
|
34
|
+
*/
|
|
35
|
+
export function resolveEmailConfigFromEnv(env) {
|
|
36
|
+
const from = env.EMAIL_FROM ?? env.SMTP_EMAIL;
|
|
37
|
+
const explicit = env.EMAIL_PROVIDER;
|
|
38
|
+
// SMTP.com (v4 REST API) credentials. Accept the canonical `SMTPCOM_*` names
|
|
39
|
+
// and the shorter `SMTP_KEY` / `SMTP_CHANNEL` aliases (SMTP.com's dashboard
|
|
40
|
+
// surfaces those). These suffixes are distinct from the generic relay's
|
|
41
|
+
// `SMTP_HOST` / `SMTP_USER` / `SMTP_PASS`, so there's no collision.
|
|
42
|
+
const smtpComKey = env.SMTPCOM_API_KEY ?? env.SMTP_KEY;
|
|
43
|
+
const smtpComChannel = env.SMTPCOM_CHANNEL ?? env.SMTP_CHANNEL;
|
|
44
|
+
const provider = explicit ??
|
|
45
|
+
(env.SMTP_HOST ? 'smtp' : smtpComKey ? 'smtpcom' : env.RESEND_API_KEY ? 'resend' : undefined);
|
|
46
|
+
switch (provider) {
|
|
47
|
+
case 'smtp': {
|
|
48
|
+
if (!env.SMTP_HOST)
|
|
49
|
+
return undefined;
|
|
50
|
+
const auth = env.SMTP_USER || env.SMTP_PASS
|
|
51
|
+
? { user: env.SMTP_USER ?? '', pass: env.SMTP_PASS ?? '' }
|
|
52
|
+
: undefined;
|
|
53
|
+
return {
|
|
54
|
+
provider: 'smtp',
|
|
55
|
+
host: env.SMTP_HOST,
|
|
56
|
+
port: env.SMTP_PORT ? Number(env.SMTP_PORT) : undefined,
|
|
57
|
+
// Only treat an explicit "true" as secure; otherwise let the provider
|
|
58
|
+
// default by port (465 → implicit TLS, else STARTTLS).
|
|
59
|
+
secure: env.SMTP_SECURE === undefined ? undefined : env.SMTP_SECURE === 'true',
|
|
60
|
+
auth,
|
|
61
|
+
from,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
case 'resend':
|
|
65
|
+
return env.RESEND_API_KEY
|
|
66
|
+
? { provider: 'resend', apiKey: env.RESEND_API_KEY, from }
|
|
67
|
+
: undefined;
|
|
68
|
+
case 'ses': {
|
|
69
|
+
const region = env.SES_REGION ?? env.AWS_REGION;
|
|
70
|
+
return region ? { provider: 'ses', region, from } : undefined;
|
|
71
|
+
}
|
|
72
|
+
case 'smtpcom':
|
|
73
|
+
return smtpComKey
|
|
74
|
+
? { provider: 'smtpcom', apiKey: smtpComKey, channel: smtpComChannel, from }
|
|
75
|
+
: undefined;
|
|
76
|
+
default:
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Build a concrete provider from decrypted Settings > Email values. Exposed
|
|
82
|
+
* for tests; registered with cms-core via `setEmailProviderFactory` so admin-
|
|
83
|
+
* configured (DB-stored) email settings can send without env vars.
|
|
84
|
+
*/
|
|
85
|
+
export const providerFromSettings = (settings) => {
|
|
86
|
+
const from = settings.from;
|
|
87
|
+
let provider = null;
|
|
88
|
+
switch (settings.provider) {
|
|
89
|
+
case 'resend':
|
|
90
|
+
provider = settings.apiKey ? createResendProvider({ apiKey: settings.apiKey, from }) : null;
|
|
91
|
+
break;
|
|
92
|
+
case 'smtpcom':
|
|
93
|
+
provider = settings.apiKey
|
|
94
|
+
? createSmtpComProvider({ apiKey: settings.apiKey, from, channel: settings.channel })
|
|
95
|
+
: null;
|
|
96
|
+
break;
|
|
97
|
+
case 'ses':
|
|
98
|
+
provider = settings.region ? createSESProvider({ region: settings.region, from }) : null;
|
|
99
|
+
break;
|
|
100
|
+
case 'smtp':
|
|
101
|
+
provider = settings.host
|
|
102
|
+
? createSmtpProvider({
|
|
103
|
+
host: settings.host,
|
|
104
|
+
port: settings.port,
|
|
105
|
+
secure: settings.secure,
|
|
106
|
+
auth: settings.auth,
|
|
107
|
+
from,
|
|
108
|
+
})
|
|
109
|
+
: null;
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
if (!provider)
|
|
113
|
+
return null;
|
|
114
|
+
const p = provider;
|
|
115
|
+
return {
|
|
116
|
+
async send(options) {
|
|
117
|
+
await p.send(options);
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
/** Factory that creates the email plugin with a configured provider. */
|
|
122
|
+
export function emailPlugin(config) {
|
|
123
|
+
// When no explicit config is supplied, fall back to env-var resolution so
|
|
124
|
+
// deployments can configure email purely through environment variables.
|
|
125
|
+
const resolved = config ??
|
|
126
|
+
(typeof process !== 'undefined' && process.env
|
|
127
|
+
? resolveEmailConfigFromEnv(process.env)
|
|
128
|
+
: undefined);
|
|
129
|
+
const from = resolved?.defaultFrom ?? resolved?.from ?? 'noreply@example.com';
|
|
130
|
+
if (resolved?.provider === 'smtp' && resolved.host) {
|
|
131
|
+
_emailProvider = createSmtpProvider({
|
|
132
|
+
host: resolved.host,
|
|
133
|
+
port: resolved.port,
|
|
134
|
+
secure: resolved.secure,
|
|
135
|
+
auth: resolved.auth,
|
|
136
|
+
from,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
else if (resolved?.provider === 'smtpcom' && resolved.apiKey) {
|
|
140
|
+
_emailProvider = createSmtpComProvider({
|
|
141
|
+
apiKey: resolved.apiKey,
|
|
142
|
+
from,
|
|
143
|
+
channel: resolved.channel,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
else if (resolved?.provider === 'resend' && resolved.apiKey) {
|
|
147
|
+
_emailProvider = createResendProvider({ apiKey: resolved.apiKey, from });
|
|
148
|
+
}
|
|
149
|
+
else if (resolved?.provider === 'ses' && resolved.region) {
|
|
150
|
+
_emailProvider = createSESProvider({ region: resolved.region, from });
|
|
151
|
+
}
|
|
152
|
+
// Register the resolved provider with cms-core's transactional email registry
|
|
153
|
+
// so password-reset and form-notification email (which live in core and read
|
|
154
|
+
// the registry) can actually send. Without this, configuring email purely via
|
|
155
|
+
// `emailPlugin()` would only power plugin-local sends. A wrapper adapts the
|
|
156
|
+
// provider's richer return type to the core `EmailAdapter` (send → void).
|
|
157
|
+
const provider = _emailProvider;
|
|
158
|
+
setEmailSender(provider
|
|
159
|
+
? {
|
|
160
|
+
async send(options) {
|
|
161
|
+
await provider.send(options);
|
|
162
|
+
},
|
|
163
|
+
}
|
|
164
|
+
: null);
|
|
165
|
+
// Register the settings factory so providers configured through the admin
|
|
166
|
+
// UI (Settings > Email, stored encrypted in the DB) can send too. DB
|
|
167
|
+
// settings take precedence over the env-resolved sender above.
|
|
168
|
+
setEmailProviderFactory(providerFromSettings);
|
|
169
|
+
return definePlugin({
|
|
170
|
+
name: 'plugin-email',
|
|
171
|
+
fields: emailFields,
|
|
172
|
+
collections: emailCollections,
|
|
173
|
+
hooks: emailHooks,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
export { createResendProvider } from './providers/resend.js';
|
|
177
|
+
export { createSESProvider } from './providers/ses.js';
|
|
178
|
+
export { createSmtpComProvider } from './providers/smtpcom.js';
|
|
179
|
+
export { createSmtpProvider } from './providers/smtp.js';
|
|
180
|
+
export { passwordResetTemplate, userInvitationTemplate, formNotificationTemplate, } from './templates/index.js';
|
|
181
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAyB,MAAM,qBAAqB,CAAA;AACzE,+EAA+E;AAC/E,gFAAgF;AAChF,8EAA8E;AAC9E,yEAAyE;AACzE,OAAO,EAAE,cAAc,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAA;AAEnF,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAA;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAA;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAsBxD,IAAI,cAAc,GAAyB,IAAI,CAAA;AAE/C,kDAAkD;AAClD,MAAM,UAAU,gBAAgB;IAC9B,OAAO,cAAc,CAAA;AACvB,CAAC;AAOD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,yBAAyB,CAAC,GAAmB;IAC3D,MAAM,IAAI,GAAG,GAAG,CAAC,UAAU,IAAI,GAAG,CAAC,UAAU,CAAA;IAC7C,MAAM,QAAQ,GAAG,GAAG,CAAC,cAA2D,CAAA;IAEhF,6EAA6E;IAC7E,4EAA4E;IAC5E,wEAAwE;IACxE,o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7B,KAAK,EAAE,UAAU;KAClB,CAAC,CAAA;AACJ,CAAC;AAED,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAA;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAA;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAIxD,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,wBAAwB,GACzB,MAAM,sBAAsB,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface EmailOptions {
|
|
2
|
+
to: string | string[];
|
|
3
|
+
subject: string;
|
|
4
|
+
html: string;
|
|
5
|
+
text?: string;
|
|
6
|
+
replyTo?: string;
|
|
7
|
+
cc?: string | string[];
|
|
8
|
+
bcc?: string | string[];
|
|
9
|
+
}
|
|
10
|
+
export interface EmailProvider {
|
|
11
|
+
send(options: EmailOptions): Promise<{
|
|
12
|
+
id: string;
|
|
13
|
+
success: boolean;
|
|
14
|
+
}>;
|
|
15
|
+
}
|
|
16
|
+
/** Creates an email provider backed by the Resend API. */
|
|
17
|
+
export declare function createResendProvider(config: {
|
|
18
|
+
apiKey: string;
|
|
19
|
+
from: string;
|
|
20
|
+
}): EmailProvider;
|
|
21
|
+
//# sourceMappingURL=resend.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resend.d.ts","sourceRoot":"","sources":["../../src/providers/resend.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IACrB,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IACtB,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;CACxB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,CAAA;CACvE;AAED,0DAA0D;AAC1D,wBAAgB,oBAAoB,CAAC,MAAM,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,aAAa,CA8B5F"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** Creates an email provider backed by the Resend API. */
|
|
2
|
+
export function createResendProvider(config) {
|
|
3
|
+
return {
|
|
4
|
+
async send(options) {
|
|
5
|
+
const response = await fetch('https://api.resend.com/emails', {
|
|
6
|
+
method: 'POST',
|
|
7
|
+
headers: {
|
|
8
|
+
Authorization: `Bearer ${config.apiKey}`,
|
|
9
|
+
'Content-Type': 'application/json',
|
|
10
|
+
},
|
|
11
|
+
body: JSON.stringify({
|
|
12
|
+
from: config.from,
|
|
13
|
+
to: Array.isArray(options.to) ? options.to : [options.to],
|
|
14
|
+
subject: options.subject,
|
|
15
|
+
html: options.html,
|
|
16
|
+
text: options.text,
|
|
17
|
+
reply_to: options.replyTo,
|
|
18
|
+
cc: options.cc,
|
|
19
|
+
bcc: options.bcc,
|
|
20
|
+
}),
|
|
21
|
+
});
|
|
22
|
+
if (!response.ok) {
|
|
23
|
+
const body = await response.text();
|
|
24
|
+
throw new Error(`Resend API error (${response.status}): ${body}`);
|
|
25
|
+
}
|
|
26
|
+
const result = (await response.json());
|
|
27
|
+
return { id: result.id, success: true };
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=resend.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resend.js","sourceRoot":"","sources":["../../src/providers/resend.ts"],"names":[],"mappings":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ses.d.ts","sourceRoot":"","sources":["../../src/providers/ses.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAgB,MAAM,aAAa,CAAA;AAG9D,mDAAmD;AACnD,wBAAgB,iBAAiB,CAAC,MAAM,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,aAAa,CAiDzF"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// AWS: Primary email provider
|
|
2
|
+
/** Creates an email provider backed by AWS SES. */
|
|
3
|
+
export function createSESProvider(config) {
|
|
4
|
+
return {
|
|
5
|
+
async send(options) {
|
|
6
|
+
const to = Array.isArray(options.to) ? options.to : [options.to];
|
|
7
|
+
const endpoint = `https://email.${config.region}.amazonaws.com`;
|
|
8
|
+
const params = new URLSearchParams({
|
|
9
|
+
Action: 'SendEmail',
|
|
10
|
+
Source: config.from,
|
|
11
|
+
'Message.Subject.Data': options.subject,
|
|
12
|
+
'Message.Body.Html.Data': options.html,
|
|
13
|
+
});
|
|
14
|
+
to.forEach((addr, i) => {
|
|
15
|
+
params.set(`Destination.ToAddresses.member.${i + 1}`, addr);
|
|
16
|
+
});
|
|
17
|
+
if (options.text) {
|
|
18
|
+
params.set('Message.Body.Text.Data', options.text);
|
|
19
|
+
}
|
|
20
|
+
if (options.replyTo) {
|
|
21
|
+
const replyAddrs = Array.isArray(options.replyTo) ? options.replyTo : [options.replyTo];
|
|
22
|
+
replyAddrs.forEach((addr, i) => {
|
|
23
|
+
params.set(`ReplyToAddresses.member.${i + 1}`, addr);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
const response = await fetch(endpoint, {
|
|
27
|
+
method: 'POST',
|
|
28
|
+
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
29
|
+
body: params.toString(),
|
|
30
|
+
});
|
|
31
|
+
if (!response.ok) {
|
|
32
|
+
const body = await response.text();
|
|
33
|
+
throw new Error(`SES API error (${response.status}): ${body}`);
|
|
34
|
+
}
|
|
35
|
+
const xml = await response.text();
|
|
36
|
+
const messageIdMatch = xml.match(/<MessageId>(.+?)<\/MessageId>/);
|
|
37
|
+
return {
|
|
38
|
+
id: messageIdMatch?.[1] ?? crypto.randomUUID(),
|
|
39
|
+
success: true,
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=ses.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ses.js","sourceRoot":"","sources":["../../src/providers/ses.ts"],"names":[],"mappings":"AAEA,8BAA8B;AAC9B,mDAAmD;AACnD,MAAM,UAAU,iBAAiB,CAAC,MAAwC;IACxE,OAAO;QACL,KAAK,CAAC,IAAI,CAAC,OAAqB;YAC9B,MAAM,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;YAEhE,MAAM,QAAQ,GAAG,iBAAiB,MAAM,CAAC,MAAM,gBAAgB,CAAA;YAE/D,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC;gBACjC,MAAM,EAAE,WAAW;gBACnB,MAAM,EAAE,MAAM,CAAC,IAAI;gBACnB,sBAAsB,EAAE,OAAO,CAAC,OAAO;gBACvC,wBAAwB,EAAE,OAAO,CAAC,IAAI;aACvC,CAAC,CAAA;YAEF,EAAE,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE;gBACrB,MAAM,CAAC,GAAG,CAAC,kCAAkC,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,CAAA;YAC7D,CAAC,CAAC,CAAA;YAEF,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;gBACjB,MAAM,CAAC,GAAG,CAAC,wBAAwB,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;YACpD,C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. */
|
|
4
|
+
host: string;
|
|
5
|
+
/** SMTP port. 465 = implicit TLS, 587 = STARTTLS (the common default). */
|
|
6
|
+
port?: number;
|
|
7
|
+
/**
|
|
8
|
+
* Use implicit TLS. When omitted, defaults to `true` for port 465 and
|
|
9
|
+
* `false` (STARTTLS) otherwise — matching nodemailer's own convention.
|
|
10
|
+
*/
|
|
11
|
+
secure?: boolean;
|
|
12
|
+
/** Optional SMTP auth. Omit for relays that authenticate by IP. */
|
|
13
|
+
auth?: {
|
|
14
|
+
user: string;
|
|
15
|
+
pass: string;
|
|
16
|
+
};
|
|
17
|
+
/** Default sender address. */
|
|
18
|
+
from: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Creates an email provider backed by a generic SMTP server via `nodemailer`.
|
|
22
|
+
*
|
|
23
|
+
* Unlike the Resend / SES / SMTP.com providers (which speak vendor HTTP APIs),
|
|
24
|
+
* this works with ANY SMTP service — your own mail server, Gmail, Office 365,
|
|
25
|
+
* SendGrid / Mailgun / Postmark SMTP endpoints, etc. — using standard
|
|
26
|
+
* host/port/credentials. That makes a single provider cover every SMTP option.
|
|
27
|
+
*
|
|
28
|
+
* `nodemailer` is an optional peer dependency: it is imported lazily so apps
|
|
29
|
+
* that only use an HTTP provider never need it. If SMTP is selected without
|
|
30
|
+
* `nodemailer` installed, `send()` throws a clear, actionable error.
|
|
31
|
+
*
|
|
32
|
+
* Serverless note: SMTP opens a TCP connection per send and is not pooled
|
|
33
|
+
* across function invocations, so it is marginally slower than an HTTP API
|
|
34
|
+
* provider. For transactional volume (password resets, lead notifications)
|
|
35
|
+
* this is not a concern; prefer an HTTP provider for high-volume sending.
|
|
36
|
+
*/
|
|
37
|
+
export declare function createSmtpProvider(config: SmtpConfig): EmailProvider;
|
|
38
|
+
//# sourceMappingURL=smtp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"smtp.d.ts","sourceRoot":"","sources":["../../src/providers/smtp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAgB,MAAM,aAAa,CAAA;AAE9D,MAAM,WAAW,UAAU;IACzB,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAA;IACZ,0EAA0E;IAC1E,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,mEAAmE;IACnE,IAAI,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAA;IACrC,8BAA8B;IAC9B,IAAI,EAAE,MAAM,CAAA;CACb;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,UAAU,GAAG,aAAa,CAiDpE"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates an email provider backed by a generic SMTP server via `nodemailer`.
|
|
3
|
+
*
|
|
4
|
+
* Unlike the Resend / SES / SMTP.com providers (which speak vendor HTTP APIs),
|
|
5
|
+
* this works with ANY SMTP service — your own mail server, Gmail, Office 365,
|
|
6
|
+
* SendGrid / Mailgun / Postmark SMTP endpoints, etc. — using standard
|
|
7
|
+
* host/port/credentials. That makes a single provider cover every SMTP option.
|
|
8
|
+
*
|
|
9
|
+
* `nodemailer` is an optional peer dependency: it is imported lazily so apps
|
|
10
|
+
* that only use an HTTP provider never need it. If SMTP is selected without
|
|
11
|
+
* `nodemailer` installed, `send()` throws a clear, actionable error.
|
|
12
|
+
*
|
|
13
|
+
* Serverless note: SMTP opens a TCP connection per send and is not pooled
|
|
14
|
+
* across function invocations, so it is marginally slower than an HTTP API
|
|
15
|
+
* provider. For transactional volume (password resets, lead notifications)
|
|
16
|
+
* this is not a concern; prefer an HTTP provider for high-volume sending.
|
|
17
|
+
*/
|
|
18
|
+
export function createSmtpProvider(config) {
|
|
19
|
+
const port = config.port ?? 587;
|
|
20
|
+
const secure = config.secure ?? port === 465;
|
|
21
|
+
return {
|
|
22
|
+
async send(options) {
|
|
23
|
+
let nodemailer;
|
|
24
|
+
try {
|
|
25
|
+
nodemailer = await import('nodemailer');
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
throw new Error('The SMTP email provider requires `nodemailer`. ' +
|
|
29
|
+
'Install it with: pnpm add nodemailer');
|
|
30
|
+
}
|
|
31
|
+
// Some bundlers expose the module on `.default`; normalise both shapes.
|
|
32
|
+
const createTransport = nodemailer.createTransport ??
|
|
33
|
+
nodemailer.default?.createTransport;
|
|
34
|
+
if (typeof createTransport !== 'function') {
|
|
35
|
+
throw new Error('Failed to load nodemailer.createTransport from `nodemailer`.');
|
|
36
|
+
}
|
|
37
|
+
const transporter = createTransport({
|
|
38
|
+
host: config.host,
|
|
39
|
+
port,
|
|
40
|
+
secure,
|
|
41
|
+
auth: config.auth,
|
|
42
|
+
});
|
|
43
|
+
const info = await transporter.sendMail({
|
|
44
|
+
from: config.from,
|
|
45
|
+
to: options.to,
|
|
46
|
+
subject: options.subject,
|
|
47
|
+
html: options.html,
|
|
48
|
+
text: options.text,
|
|
49
|
+
replyTo: options.replyTo,
|
|
50
|
+
cc: options.cc,
|
|
51
|
+
bcc: options.bcc,
|
|
52
|
+
});
|
|
53
|
+
return {
|
|
54
|
+
id: info.messageId ?? crypto.randomUUID(),
|
|
55
|
+
success: true,
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=smtp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"smtp.js","sourceRoot":"","sources":["../../src/providers/smtp.ts"],"names":[],"mappings":"AAkBA;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,kBAAkB,CAAC,MAAkB;IACnD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,GAAG,CAAA;IAC/B,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,IAAI,KAA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face SmtpComConfig {
|
|
3
|
+
apiKey: string;
|
|
4
|
+
from: string;
|
|
5
|
+
channel?: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Creates an email provider backed by the SMTP.com v4 API.
|
|
9
|
+
*
|
|
10
|
+
* Requires an SMTP.com API key and a configured sender channel.
|
|
11
|
+
* API docs: https://api.smtp.com/
|
|
12
|
+
*/
|
|
13
|
+
export declare function createSmtpComProvider(config: SmtpComConfig): EmailProvider;
|
|
14
|
+
//# sourceMappingURL=smtpcom.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"smtpcom.d.ts","sourceRoot":"","sources":["../../src/providers/smtpcom.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAgB,MAAM,aAAa,CAAA;AAE9D,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,aAAa,GAAG,aAAa,CAuE1E"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates an email provider backed by the SMTP.com v4 API.
|
|
3
|
+
*
|
|
4
|
+
* Requires an SMTP.com API key and a configured sender channel.
|
|
5
|
+
* API docs: https://api.smtp.com/
|
|
6
|
+
*/
|
|
7
|
+
export function createSmtpComProvider(config) {
|
|
8
|
+
const channel = config.channel ?? 'default';
|
|
9
|
+
return {
|
|
10
|
+
async send(options) {
|
|
11
|
+
const toArray = Array.isArray(options.to) ? options.to : [options.to];
|
|
12
|
+
const recipients = {
|
|
13
|
+
to: toArray.map((addr) => ({ address: addr })),
|
|
14
|
+
};
|
|
15
|
+
if (options.cc) {
|
|
16
|
+
const ccArray = Array.isArray(options.cc) ? options.cc : [options.cc];
|
|
17
|
+
recipients.cc = ccArray.map((addr) => ({ address: addr }));
|
|
18
|
+
}
|
|
19
|
+
if (options.bcc) {
|
|
20
|
+
const bccArray = Array.isArray(options.bcc) ? options.bcc : [options.bcc];
|
|
21
|
+
recipients.bcc = bccArray.map((addr) => ({ address: addr }));
|
|
22
|
+
}
|
|
23
|
+
const bodyParts = [];
|
|
24
|
+
if (options.html) {
|
|
25
|
+
bodyParts.push({ content: options.html, type: 'text/html' });
|
|
26
|
+
}
|
|
27
|
+
if (options.text) {
|
|
28
|
+
bodyParts.push({ content: options.text, type: 'text/plain' });
|
|
29
|
+
}
|
|
30
|
+
const requestBody = {
|
|
31
|
+
channel,
|
|
32
|
+
recipients,
|
|
33
|
+
originator: {
|
|
34
|
+
from: { address: config.from },
|
|
35
|
+
},
|
|
36
|
+
subject: options.subject,
|
|
37
|
+
body: {
|
|
38
|
+
parts: bodyParts,
|
|
39
|
+
},
|
|
40
|
+
...(options.replyTo
|
|
41
|
+
? { custom_headers: [{ header: 'Reply-To', value: options.replyTo }] }
|
|
42
|
+
: {}),
|
|
43
|
+
};
|
|
44
|
+
const response = await fetch('https://api.smtp.com/v4/messages', {
|
|
45
|
+
method: 'POST',
|
|
46
|
+
headers: {
|
|
47
|
+
Authorization: `Bearer ${config.apiKey}`,
|
|
48
|
+
'Content-Type': 'application/json',
|
|
49
|
+
Accept: 'application/json',
|
|
50
|
+
},
|
|
51
|
+
body: JSON.stringify(requestBody),
|
|
52
|
+
});
|
|
53
|
+
if (!response.ok) {
|
|
54
|
+
const errorText = await response.text().catch(() => 'Unknown error');
|
|
55
|
+
throw new Error(`SMTP.com API error (${response.status}): ${errorText}`);
|
|
56
|
+
}
|
|
57
|
+
const result = (await response.json());
|
|
58
|
+
return {
|
|
59
|
+
id: result.data?.message_id ?? crypto.randomUUID(),
|
|
60
|
+
success: result.status === 'success',
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=smtpcom.js.map
|
|
@@ -0,0 +1 @@
|
|
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CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,eAAe,CAAC,CAAA;gBACpE,MAAM,IAAI,KAAK,CAAC,uBAAuB,QAAQ,CAAC,MAAM,MAAM,SAAS,EAAE,CAAC,CAAA;YAC1E,CAAC;YAED,MAAM,MAAM,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAGpC,CAAA;YAED,OAAO;gBACL,EAAE,EAAE,MAAM,CAAC,IAAI,EAAE,UAAU,IAAI,MAAM,CAAC,UAAU,EAAE;gBAClD,OAAO,EAAE,MAAM,CAAC,MAAM,KAAK,SAAS;aACrC,CAAA;QACH,CAAC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface EmailTemplate {
|
|
2
|
+
subject: string;
|
|
3
|
+
html: string;
|
|
4
|
+
text: string;
|
|
5
|
+
}
|
|
6
|
+
/** Generates a password reset email with a one-click reset link. */
|
|
7
|
+
export declare function passwordResetTemplate(args: {
|
|
8
|
+
resetUrl: string;
|
|
9
|
+
userName: string;
|
|
10
|
+
}): EmailTemplate;
|
|
11
|
+
/** Generates an invitation email for a new user joining an organization. */
|
|
12
|
+
export declare function userInvitationTemplate(args: {
|
|
13
|
+
inviteUrl: string;
|
|
14
|
+
inviterName: string;
|
|
15
|
+
orgName: string;
|
|
16
|
+
}): EmailTemplate;
|
|
17
|
+
/** Generates a notification email when a form submission is received. */
|
|
18
|
+
export declare function formNotificationTemplate(args: {
|
|
19
|
+
formName: string;
|
|
20
|
+
fields: Record<string, string>;
|
|
21
|
+
}): EmailTemplate;
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/templates/index.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;CACb;AAED,oEAAoE;AACpE,wBAAgB,qBAAqB,CAAC,IAAI,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,aAAa,CA2BjG;AAED,4EAA4E;AAC5E,wBAAgB,sBAAsB,CAAC,IAAI,EAAE;IAC3C,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,MAAM,CAAA;IACnB,OAAO,EAAE,MAAM,CAAA;CAChB,GAAG,aAAa,CA2BhB;AAED,yEAAyE;AACzE,wBAAgB,wBAAwB,CAAC,IAAI,EAAE;IAC7C,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAC/B,GAAG,aAAa,CA8ChB"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/** Generates a password reset email with a one-click reset link. */
|
|
2
|
+
export function passwordResetTemplate(args) {
|
|
3
|
+
return {
|
|
4
|
+
subject: 'Reset your password',
|
|
5
|
+
html: `<!DOCTYPE html>
|
|
6
|
+
<html>
|
|
7
|
+
<head><meta charset="utf-8"></head>
|
|
8
|
+
<body style="margin:0;padding:0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;background:#f9fafb;">
|
|
9
|
+
<table width="100%" cellpadding="0" cellspacing="0" style="max-width:560px;margin:40px auto;background:#fff;border-radius:8px;border:1px solid #e5e7eb;">
|
|
10
|
+
<tr>
|
|
11
|
+
<td style="padding:32px;">
|
|
12
|
+
<h1 style="margin:0 0 16px;font-size:20px;color:#111827;">Reset your password</h1>
|
|
13
|
+
<p style="margin:0 0 24px;font-size:15px;line-height:1.6;color:#374151;">
|
|
14
|
+
Hi ${args.userName}, we received a request to reset your password. Click the button below to choose a new one.
|
|
15
|
+
</p>
|
|
16
|
+
<a href="${args.resetUrl}" style="display:inline-block;padding:12px 24px;background:#3b82f6;color:#fff;text-decoration:none;border-radius:6px;font-weight:600;font-size:14px;">
|
|
17
|
+
Reset Password
|
|
18
|
+
</a>
|
|
19
|
+
<p style="margin:24px 0 0;font-size:13px;color:#9ca3af;">
|
|
20
|
+
If you didn't request this, you can safely ignore this email. This link expires in 1 hour.
|
|
21
|
+
</p>
|
|
22
|
+
</td>
|
|
23
|
+
</tr>
|
|
24
|
+
</table>
|
|
25
|
+
</body>
|
|
26
|
+
</html>`,
|
|
27
|
+
text: `Hi ${args.userName},\n\nWe received a request to reset your password. Visit the link below to choose a new one:\n\n${args.resetUrl}\n\nIf you didn't request this, you can safely ignore this email. This link expires in 1 hour.`,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/** Generates an invitation email for a new user joining an organization. */
|
|
31
|
+
export function userInvitationTemplate(args) {
|
|
32
|
+
return {
|
|
33
|
+
subject: `You've been invited to ${args.orgName}`,
|
|
34
|
+
html: `<!DOCTYPE html>
|
|
35
|
+
<html>
|
|
36
|
+
<head><meta charset="utf-8"></head>
|
|
37
|
+
<body style="margin:0;padding:0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;background:#f9fafb;">
|
|
38
|
+
<table width="100%" cellpadding="0" cellspacing="0" style="max-width:560px;margin:40px auto;background:#fff;border-radius:8px;border:1px solid #e5e7eb;">
|
|
39
|
+
<tr>
|
|
40
|
+
<td style="padding:32px;">
|
|
41
|
+
<h1 style="margin:0 0 16px;font-size:20px;color:#111827;">You're invited!</h1>
|
|
42
|
+
<p style="margin:0 0 24px;font-size:15px;line-height:1.6;color:#374151;">
|
|
43
|
+
${args.inviterName} has invited you to join <strong>${args.orgName}</strong>. Click below to accept the invitation and set up your account.
|
|
44
|
+
</p>
|
|
45
|
+
<a href="${args.inviteUrl}" style="display:inline-block;padding:12px 24px;background:#3b82f6;color:#fff;text-decoration:none;border-radius:6px;font-weight:600;font-size:14px;">
|
|
46
|
+
Accept Invitation
|
|
47
|
+
</a>
|
|
48
|
+
<p style="margin:24px 0 0;font-size:13px;color:#9ca3af;">
|
|
49
|
+
This invitation expires in 7 days. If you weren't expecting this, no action is needed.
|
|
50
|
+
</p>
|
|
51
|
+
</td>
|
|
52
|
+
</tr>
|
|
53
|
+
</table>
|
|
54
|
+
</body>
|
|
55
|
+
</html>`,
|
|
56
|
+
text: `${args.inviterName} has invited you to join ${args.orgName}.\n\nAccept the invitation here:\n${args.inviteUrl}\n\nThis invitation expires in 7 days. If you weren't expecting this, no action is needed.`,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/** Generates a notification email when a form submission is received. */
|
|
60
|
+
export function formNotificationTemplate(args) {
|
|
61
|
+
const fieldEntries = Object.entries(args.fields);
|
|
62
|
+
const htmlRows = fieldEntries
|
|
63
|
+
.map(([key, value]) => `<tr>
|
|
64
|
+
<td style="padding:8px 12px;border-bottom:1px solid #f3f4f6;font-weight:600;color:#374151;font-size:14px;white-space:nowrap;">${key}</td>
|
|
65
|
+
<td style="padding:8px 12px;border-bottom:1px solid #f3f4f6;color:#111827;font-size:14px;">${value}</td>
|
|
66
|
+
</tr>`)
|
|
67
|
+
.join('\n');
|
|
68
|
+
const textRows = fieldEntries.map(([key, value]) => `${key}: ${value}`).join('\n');
|
|
69
|
+
return {
|
|
70
|
+
subject: `New submission: ${args.formName}`,
|
|
71
|
+
html: `<!DOCTYPE html>
|
|
72
|
+
<html>
|
|
73
|
+
<head><meta charset="utf-8"></head>
|
|
74
|
+
<body style="margin:0;padding:0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;background:#f9fafb;">
|
|
75
|
+
<table width="100%" cellpadding="0" cellspacing="0" style="max-width:560px;margin:40px auto;background:#fff;border-radius:8px;border:1px solid #e5e7eb;">
|
|
76
|
+
<tr>
|
|
77
|
+
<td style="padding:32px;">
|
|
78
|
+
<h1 style="margin:0 0 8px;font-size:20px;color:#111827;">New Form Submission</h1>
|
|
79
|
+
<p style="margin:0 0 24px;font-size:15px;color:#6b7280;">
|
|
80
|
+
A new response was submitted to <strong>${args.formName}</strong>.
|
|
81
|
+
</p>
|
|
82
|
+
<table width="100%" cellpadding="0" cellspacing="0" style="border:1px solid #e5e7eb;border-radius:6px;overflow:hidden;">
|
|
83
|
+
<thead>
|
|
84
|
+
<tr style="background:#f9fafb;">
|
|
85
|
+
<th style="padding:8px 12px;text-align:left;font-size:12px;text-transform:uppercase;letter-spacing:0.05em;color:#6b7280;">Field</th>
|
|
86
|
+
<th style="padding:8px 12px;text-align:left;font-size:12px;text-transform:uppercase;letter-spacing:0.05em;color:#6b7280;">Value</th>
|
|
87
|
+
</tr>
|
|
88
|
+
</thead>
|
|
89
|
+
<tbody>
|
|
90
|
+
${htmlRows}
|
|
91
|
+
</tbody>
|
|
92
|
+
</table>
|
|
93
|
+
</td>
|
|
94
|
+
</tr>
|
|
95
|
+
</table>
|
|
96
|
+
</body>
|
|
97
|
+
</html>`,
|
|
98
|
+
text: `New Form Submission\n\nForm: ${args.formName}\n\n${textRows}`,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=index.js.map
|