ras-stack 5.5.0 → 5.5.2
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/dist/email/index.d.ts +1 -1
- package/dist/email/index.js +24 -7
- package/dist/email/index.js.map +1 -1
- package/package.json +8 -8
package/dist/email/index.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ export type SmtpConfig = {
|
|
|
24
24
|
password?: string;
|
|
25
25
|
/** The name TLS presents and verifies when `host` is an address the application already resolved. */
|
|
26
26
|
servername?: string;
|
|
27
|
-
/** Fails a send or verify that runs longer than this, and bounds each wait on the server to the same limit. */
|
|
27
|
+
/** Fails and disconnects a send or verify that runs longer than this, and bounds each wait on the server to the same limit. */
|
|
28
28
|
timeoutMs?: number;
|
|
29
29
|
};
|
|
30
30
|
export type SmtpEnvironmentOptions = {
|
package/dist/email/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import net from 'node:net';
|
|
1
2
|
import { createTransport } from 'nodemailer';
|
|
2
3
|
export function smtpConfigFromEnvironment(environment = process.env, keys = {}) {
|
|
3
4
|
const host = environment[keys.host ?? 'SMTP_HOST']?.trim();
|
|
@@ -28,26 +29,42 @@ export function smtpConfigFromEnvironment(environment = process.env, keys = {})
|
|
|
28
29
|
}
|
|
29
30
|
export function createSmtpDelivery(config) {
|
|
30
31
|
const timeout = config.timeoutMs;
|
|
31
|
-
const
|
|
32
|
+
const options = {
|
|
32
33
|
host: config.host,
|
|
33
34
|
port: config.port,
|
|
34
35
|
secure: config.secure,
|
|
35
36
|
servername: config.servername,
|
|
36
37
|
auth: config.user ? { user: config.user, pass: config.password } : undefined,
|
|
37
38
|
...(timeout === undefined ? {} : { connectionTimeout: timeout, greetingTimeout: timeout, socketTimeout: timeout }),
|
|
39
|
+
};
|
|
40
|
+
if (timeout === undefined) {
|
|
41
|
+
const transport = createTransport(options);
|
|
42
|
+
return smtpDelivery(config.from, async (work) => void (await work(transport)));
|
|
43
|
+
}
|
|
44
|
+
return smtpDelivery(config.from, async (work) => {
|
|
45
|
+
// nodemailer cannot abort an exchange, so each one gets its own socket for the deadline to destroy.
|
|
46
|
+
const socket = new net.Socket();
|
|
47
|
+
await withinDeadline(work(createTransport({ ...options, socket })), timeout, () => {
|
|
48
|
+
socket.destroy();
|
|
49
|
+
// Connecting revives a destroyed socket, so one the deadline beat to connecting closes as soon as it opens.
|
|
50
|
+
socket.once('connect', () => socket.destroy());
|
|
51
|
+
});
|
|
38
52
|
});
|
|
53
|
+
}
|
|
54
|
+
function smtpDelivery(from, exchange) {
|
|
39
55
|
return {
|
|
40
|
-
send:
|
|
41
|
-
verify:
|
|
56
|
+
send: ({ fromName, ...message }) => exchange((transport) => transport.sendMail({ from: fromName ? { name: fromName, address: senderAddress(from) } : from, ...message })),
|
|
57
|
+
verify: () => exchange((transport) => transport.verify()),
|
|
42
58
|
};
|
|
43
59
|
}
|
|
44
60
|
// A server that trickles bytes keeps each socket wait short of its timeout, so the whole exchange needs its own deadline.
|
|
45
|
-
async function withinDeadline(work, timeoutMs) {
|
|
46
|
-
if (timeoutMs === undefined)
|
|
47
|
-
return void (await work);
|
|
61
|
+
async function withinDeadline(work, timeoutMs, abort) {
|
|
48
62
|
let timer;
|
|
49
63
|
const deadline = new Promise((_resolve, reject) => {
|
|
50
|
-
timer = setTimeout(() =>
|
|
64
|
+
timer = setTimeout(() => {
|
|
65
|
+
abort();
|
|
66
|
+
reject(new Error(`SMTP server did not finish within ${timeoutMs} ms`));
|
|
67
|
+
}, timeoutMs);
|
|
51
68
|
});
|
|
52
69
|
try {
|
|
53
70
|
await Promise.race([work, deadline]);
|
package/dist/email/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/email/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAiD5C,MAAM,UAAU,yBAAyB,CACvC,WAAW,GAAsB,OAAO,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,UAAU,CAAC,OAAO,CAAC,yCAAyC,UAAU,CAAC,GAAG,CAAC,KAAK,KAAK,cAAc,MAAM,MAAM;KAC5H,CAAC,CAAA;IACN,OAAO;QACL,iBAAiB,EAAE,IAAI,CAAC,cAAc,OAAO,CAAC,WAAW,WAAW,EAAE,gBAAgB,CAAC;QACvF,qBAAqB,EAAE,IAAI,CAAC,eAAe,OAAO,CAAC,WAAW,gBAAgB,EAAE,sBAAsB,CAAC;KACxG,CAAA;AACH,CAAC;AAED,SAAS,UAAU,CAAC,KAAa;IAC/B,OAAO,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAA;AACjH,CAAC","sourcesContent":["import { createTransport } from 'nodemailer'\n\n/** `cid` lets the HTML body reference the attachment inline as `cid:<value>`. */\nexport type EmailAttachment = { filename: string; content: Buffer; contentType: string; cid?: string }\n\nexport type EmailMessage = {\n to: string\n subject: string\n text: string\n html?: string\n attachments?: EmailAttachment[]\n /** Replaces the display name of the configured sender; the address stays the configured one so SPF and DKIM still pass. */\n fromName?: string\n replyTo?: string\n}\n\nexport type SmtpConfig = {\n from: string\n host: string\n port: number\n secure: boolean\n user?: string\n password?: string\n /** The name TLS presents and verifies when `host` is an address the application already resolved. */\n servername?: string\n /** Fails a send or verify that runs longer than this, and bounds each wait on the server to the same limit. */\n timeoutMs?: number\n}\n\nexport type SmtpEnvironmentOptions = {\n host?: string\n port?: string\n secure?: string\n user?: string\n password?: string\n from?: string\n}\n\nexport type EmailDelivery = {\n send(message: EmailMessage): Promise<void>\n verify(): Promise<void>\n}\n\nexport type AuthEmailInput<User extends { email: string } = { email: string }> = {\n user: User\n url: string\n token: string\n}\n\nexport function smtpConfigFromEnvironment(\n environment: NodeJS.ProcessEnv = process.env,\n keys: SmtpEnvironmentOptions = {},\n): SmtpConfig | undefined {\n const host = environment[keys.host ?? 'SMTP_HOST']?.trim()\n const from = environment[keys.from ?? 'EMAIL_FROM']?.trim()\n if (!host && !from) return undefined\n if (!host) throw new Error(`${keys.host ?? 'SMTP_HOST'} is required for SMTP email`)\n if (!from) throw new Error(`${keys.from ?? 'EMAIL_FROM'} is required for SMTP email`)\n\n const portKey = keys.port ?? 'SMTP_PORT'\n const port = Number(environment[portKey] ?? 587)\n if (!Number.isInteger(port) || port < 1 || port > 65_535) throw new Error(`${portKey} must be a valid TCP port`)\n\n const userKey = keys.user ?? 'SMTP_USER'\n const passwordKey = keys.password ?? 'SMTP_PASSWORD'\n const user = environment[userKey]?.trim()\n const password = environment[passwordKey]\n if (Boolean(user) !== Boolean(password)) throw new Error(`${userKey} and ${passwordKey} must be configured together`)\n\n return {\n from,\n host,\n port,\n secure: environment[keys.secure ?? 'SMTP_SECURE']?.trim().toLowerCase() === 'true',\n ...(user && password ? { user, password } : {}),\n }\n}\n\nexport function createSmtpDelivery(config: SmtpConfig): EmailDelivery {\n const timeout = config.timeoutMs\n const transport = createTransport({\n host: config.host,\n port: config.port,\n secure: config.secure,\n servername: config.servername,\n auth: config.user ? { user: config.user, pass: config.password } : undefined,\n ...(timeout === undefined ? {} : { connectionTimeout: timeout, greetingTimeout: timeout, socketTimeout: timeout }),\n })\n return {\n send: async ({ fromName, ...message }) =>\n withinDeadline(\n transport.sendMail({ from: fromName ? { name: fromName, address: senderAddress(config.from) } : config.from, ...message }),\n timeout,\n ),\n verify: async () => withinDeadline(transport.verify(), timeout),\n }\n}\n\n// A server that trickles bytes keeps each socket wait short of its timeout, so the whole exchange needs its own deadline.\nasync function withinDeadline(work: Promise<unknown>, timeoutMs: number | undefined) {\n if (timeoutMs === undefined) return void (await work)\n let timer: ReturnType<typeof setTimeout> | undefined\n const deadline = new Promise<never>((_resolve, reject) => {\n timer = setTimeout(() => reject(new Error(`SMTP server did not finish within ${timeoutMs} ms`)), timeoutMs)\n })\n try {\n await Promise.race([work, deadline])\n } finally {\n clearTimeout(timer)\n }\n}\n\nfunction senderAddress(from: string) {\n return /<([^<>]+)>\\s*$/.exec(from)?.[1] ?? from\n}\n\nexport type StandardAuthEmailOptions = { productName: string }\n\nexport function standardAuthEmails<User extends { email: string } = { email: string }>(\n delivery: EmailDelivery,\n options: StandardAuthEmailOptions,\n) {\n const expiry = 'This link expires in one hour.'\n const send =\n (subject: string, label: string) =>\n async ({ user, url }: AuthEmailInput<User>) =>\n delivery.send({\n to: user.email,\n subject,\n text: `${subject} using this link: ${url}\\n\\n${expiry}`,\n html: `<p>${escapeHtml(subject)} using the link below.</p><p><a href=\"${escapeHtml(url)}\">${label}</a></p><p>${expiry}</p>`,\n })\n return {\n sendResetPassword: send(`Reset your ${options.productName} password`, 'Reset password'),\n sendVerificationEmail: send(`Verify your ${options.productName} email address`, 'Verify email address'),\n }\n}\n\nfunction escapeHtml(value: string) {\n return value.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>').replaceAll('\"', '"')\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/email/index.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,UAAU,CAAA;AAC1B,OAAO,EAAE,eAAe,EAAoB,MAAM,YAAY,CAAA;AAiD9D,MAAM,UAAU,yBAAyB,CACvC,WAAW,GAAsB,OAAO,CAAC,GAAG,EAC5C,IAAI,GAA2B,EAAE;IAEjC,MAAM,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,IAAI,WAAW,CAAC,EAAE,IAAI,EAAE,CAAA;IAC1D,MAAM,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,IAAI,YAAY,CAAC,EAAE,IAAI,EAAE,CAAA;IAC3D,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI;QAAE,OAAO,SAAS,CAAA;IACpC,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,CAAC,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MAAM,UAAU,kBAAkB,CAChC,QAAuB,EACvB,OAAiC;IAEjC,MAAM,MAAM,GAAG,gCAAgC,CAAA;IAC/C,MAAM,IAAI,GACR,CAAC,OAAe,EAAE,KAAa,EAAE,EAAE,CACnC,KAAK,EAAE,EAAE,IAAI,EAAE,GAAG,EAAwB,EAAE,EAAE,CAC5C,QAAQ,CAAC,IAAI,CAAC;QACZ,EAAE,EAAE,IAAI,CAAC,KAAK;QACd,OAAO;QACP,IAAI,EAAE,GAAG,OAAO,qBAAqB,GAAG,OAAO,MAAM,EAAE;QACvD,IAAI,EAAE,MAAM,UAAU,CAAC,OAAO,CAAC,yCAAyC,UAAU,CAAC,GAAG,CAAC,KAAK,KAAK,cAAc,MAAM,MAAM;KAC5H,CAAC,CAAA;IACN,OAAO;QACL,iBAAiB,EAAE,IAAI,CAAC,cAAc,OAAO,CAAC,WAAW,WAAW,EAAE,gBAAgB,CAAC;QACvF,qBAAqB,EAAE,IAAI,CAAC,eAAe,OAAO,CAAC,WAAW,gBAAgB,EAAE,sBAAsB,CAAC;KACxG,CAAA;AACH,CAAC;AAED,SAAS,UAAU,CAAC,KAAa;IAC/B,OAAO,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAA;AACjH,CAAC","sourcesContent":["import net from 'node:net'\nimport { createTransport, type Transporter } from 'nodemailer'\n\n/** `cid` lets the HTML body reference the attachment inline as `cid:<value>`. */\nexport type EmailAttachment = { filename: string; content: Buffer; contentType: string; cid?: string }\n\nexport type EmailMessage = {\n to: string\n subject: string\n text: string\n html?: string\n attachments?: EmailAttachment[]\n /** Replaces the display name of the configured sender; the address stays the configured one so SPF and DKIM still pass. */\n fromName?: string\n replyTo?: string\n}\n\nexport type SmtpConfig = {\n from: string\n host: string\n port: number\n secure: boolean\n user?: string\n password?: string\n /** The name TLS presents and verifies when `host` is an address the application already resolved. */\n servername?: string\n /** Fails and disconnects a send or verify that runs longer than this, and bounds each wait on the server to the same limit. */\n timeoutMs?: number\n}\n\nexport type SmtpEnvironmentOptions = {\n host?: string\n port?: string\n secure?: string\n user?: string\n password?: string\n from?: string\n}\n\nexport type EmailDelivery = {\n send(message: EmailMessage): Promise<void>\n verify(): Promise<void>\n}\n\nexport type AuthEmailInput<User extends { email: string } = { email: string }> = {\n user: User\n url: string\n token: string\n}\n\nexport function smtpConfigFromEnvironment(\n environment: NodeJS.ProcessEnv = process.env,\n keys: SmtpEnvironmentOptions = {},\n): SmtpConfig | undefined {\n const host = environment[keys.host ?? 'SMTP_HOST']?.trim()\n const from = environment[keys.from ?? 'EMAIL_FROM']?.trim()\n if (!host && !from) return undefined\n if (!host) throw new Error(`${keys.host ?? 'SMTP_HOST'} is required for SMTP email`)\n if (!from) throw new Error(`${keys.from ?? 'EMAIL_FROM'} is required for SMTP email`)\n\n const portKey = keys.port ?? 'SMTP_PORT'\n const port = Number(environment[portKey] ?? 587)\n if (!Number.isInteger(port) || port < 1 || port > 65_535) throw new Error(`${portKey} must be a valid TCP port`)\n\n const userKey = keys.user ?? 'SMTP_USER'\n const passwordKey = keys.password ?? 'SMTP_PASSWORD'\n const user = environment[userKey]?.trim()\n const password = environment[passwordKey]\n if (Boolean(user) !== Boolean(password)) throw new Error(`${userKey} and ${passwordKey} must be configured together`)\n\n return {\n from,\n host,\n port,\n secure: environment[keys.secure ?? 'SMTP_SECURE']?.trim().toLowerCase() === 'true',\n ...(user && password ? { user, password } : {}),\n }\n}\n\nexport function createSmtpDelivery(config: SmtpConfig): EmailDelivery {\n const timeout = config.timeoutMs\n const options = {\n host: config.host,\n port: config.port,\n secure: config.secure,\n servername: config.servername,\n auth: config.user ? { user: config.user, pass: config.password } : undefined,\n ...(timeout === undefined ? {} : { connectionTimeout: timeout, greetingTimeout: timeout, socketTimeout: timeout }),\n }\n if (timeout === undefined) {\n const transport = createTransport(options)\n return smtpDelivery(config.from, async (work) => void (await work(transport)))\n }\n return smtpDelivery(config.from, async (work) => {\n // nodemailer cannot abort an exchange, so each one gets its own socket for the deadline to destroy.\n const socket = new net.Socket()\n await withinDeadline(work(createTransport({ ...options, socket })), timeout, () => {\n socket.destroy()\n // Connecting revives a destroyed socket, so one the deadline beat to connecting closes as soon as it opens.\n socket.once('connect', () => socket.destroy())\n })\n })\n}\n\nfunction smtpDelivery(from: string, exchange: (work: (transport: Transporter) => Promise<unknown>) => Promise<void>): EmailDelivery {\n return {\n send: ({ fromName, ...message }) =>\n exchange((transport) => transport.sendMail({ from: fromName ? { name: fromName, address: senderAddress(from) } : from, ...message })),\n verify: () => exchange((transport) => transport.verify()),\n }\n}\n\n// A server that trickles bytes keeps each socket wait short of its timeout, so the whole exchange needs its own deadline.\nasync function withinDeadline(work: Promise<unknown>, timeoutMs: number, abort: () => void) {\n let timer: ReturnType<typeof setTimeout> | undefined\n const deadline = new Promise<never>((_resolve, reject) => {\n timer = setTimeout(() => {\n abort()\n reject(new Error(`SMTP server did not finish within ${timeoutMs} ms`))\n }, timeoutMs)\n })\n try {\n await Promise.race([work, deadline])\n } finally {\n clearTimeout(timer)\n }\n}\n\nfunction senderAddress(from: string) {\n return /<([^<>]+)>\\s*$/.exec(from)?.[1] ?? from\n}\n\nexport type StandardAuthEmailOptions = { productName: string }\n\nexport function standardAuthEmails<User extends { email: string } = { email: string }>(\n delivery: EmailDelivery,\n options: StandardAuthEmailOptions,\n) {\n const expiry = 'This link expires in one hour.'\n const send =\n (subject: string, label: string) =>\n async ({ user, url }: AuthEmailInput<User>) =>\n delivery.send({\n to: user.email,\n subject,\n text: `${subject} using this link: ${url}\\n\\n${expiry}`,\n html: `<p>${escapeHtml(subject)} using the link below.</p><p><a href=\"${escapeHtml(url)}\">${label}</a></p><p>${expiry}</p>`,\n })\n return {\n sendResetPassword: send(`Reset your ${options.productName} password`, 'Reset password'),\n sendVerificationEmail: send(`Verify your ${options.productName} email address`, 'Verify email address'),\n }\n}\n\nfunction escapeHtml(value: string) {\n return value.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>').replaceAll('\"', '"')\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ras-stack",
|
|
3
|
-
"version": "5.5.
|
|
3
|
+
"version": "5.5.2",
|
|
4
4
|
"description": "Composable full-stack primitives shared across Richard Solomou's applications.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"authentication",
|
|
@@ -154,10 +154,10 @@
|
|
|
154
154
|
"@opentelemetry/sdk-logs": "^0.223.0",
|
|
155
155
|
"@pnpm/parse-overrides": "1001.0.4",
|
|
156
156
|
"@posthog/react": "1.11.3",
|
|
157
|
-
"@posthog/rollup-plugin": "1.6.
|
|
157
|
+
"@posthog/rollup-plugin": "1.6.2",
|
|
158
158
|
"@tailwindcss/vite": "4.3.3",
|
|
159
|
-
"@tanstack/react-query": "5.104.
|
|
160
|
-
"@tanstack/react-start": "^1.169.
|
|
159
|
+
"@tanstack/react-query": "5.104.5",
|
|
160
|
+
"@tanstack/react-start": "^1.169.4",
|
|
161
161
|
"@types/better-sqlite3": "9.6.0",
|
|
162
162
|
"@types/node": "^26.6.5",
|
|
163
163
|
"@types/nodemailer": "^8.0.1",
|
|
@@ -174,16 +174,16 @@
|
|
|
174
174
|
"nodemailer": "^10.1.7",
|
|
175
175
|
"oxfmt": "^0.73.0",
|
|
176
176
|
"oxlint": "^1.88.0",
|
|
177
|
-
"oxlint-tsgolint": "^7.0.
|
|
177
|
+
"oxlint-tsgolint": "^7.0.2005",
|
|
178
178
|
"postgres": "3.4.9",
|
|
179
|
-
"posthog-js": "1.438.
|
|
179
|
+
"posthog-js": "1.438.21",
|
|
180
180
|
"posthog-node": "5.56.2",
|
|
181
181
|
"react": "19.3.1",
|
|
182
182
|
"react-test-renderer": "19.3.1",
|
|
183
183
|
"semver": "7.8.5",
|
|
184
184
|
"tus-js-client": "^4.3.1",
|
|
185
185
|
"typescript": "^7.0.2",
|
|
186
|
-
"vite": "8.3.
|
|
186
|
+
"vite": "8.3.5",
|
|
187
187
|
"vitest": "^4.1.12"
|
|
188
188
|
},
|
|
189
189
|
"peerDependencies": {
|
|
@@ -198,7 +198,7 @@
|
|
|
198
198
|
"better-sqlite3": ">=12 <14",
|
|
199
199
|
"centrifuge": ">=5 <6",
|
|
200
200
|
"drizzle-orm": ">=0.45 <1",
|
|
201
|
-
"nodemailer": ">=9 <11",
|
|
201
|
+
"nodemailer": ">=9.0.3 <11",
|
|
202
202
|
"postgres": ">=3.4 <4",
|
|
203
203
|
"posthog-js": ">=1.430.3 <2",
|
|
204
204
|
"posthog-node": ">=5.52 <6",
|