@ultimat3/mail 31.47.0 → 31.48.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +7 -7
- package/src/driver-env.ts +24 -0
- package/src/smtp-client.ts +1 -1
- package/src/smtp-socket.ts +1 -1
package/README.md
CHANGED
|
@@ -101,7 +101,7 @@ the app changes between environments; the credential does.
|
|
|
101
101
|
|---|---|
|
|
102
102
|
| *(nothing set)*, `development` / `test` | `memoryMailDriver()` — caught, never sent |
|
|
103
103
|
| *(nothing set)*, `staging` / `production` | `unconfiguredMailDriver(...)` — every send is `X_MAIL_CREDENTIAL_MISSING` |
|
|
104
|
-
| `SMTP_URL` + `MAIL_FROM` | `smtpMailDriver(...)`, `MAIL_POOL_SIZE` optional |
|
|
104
|
+
| `SMTP_URL` + `MAIL_FROM` | `smtpMailDriver(...)`, `MAIL_POOL_SIZE` and `MAIL_TIMEOUT_MS` (read/write deadline, default `30000`) optional |
|
|
105
105
|
| `RESEND_API_KEY` + `MAIL_FROM` | `resendMailDriver(...)` |
|
|
106
106
|
| `SES_REGION` + `SES_ACCESS_KEY_ID` + `SES_SECRET_ACCESS_KEY` + `MAIL_FROM` | `sesMailDriver(...)`; `SES_SESSION_TOKEN`, `SES_ENDPOINT`, `SES_CONFIGURATION_SET` optional |
|
|
107
107
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/mail",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.48.0",
|
|
4
4
|
"description": "Transactional email as data: one template renders HTML and text, sent through a job.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ultimate",
|
|
@@ -44,11 +44,11 @@
|
|
|
44
44
|
"test": "bun test"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@ultimat3/core": "31.
|
|
48
|
-
"@ultimat3/i18n": "31.
|
|
49
|
-
"@ultimat3/jobs": "31.
|
|
50
|
-
"@ultimat3/schema": "31.
|
|
51
|
-
"@ultimat3/storage": "31.
|
|
52
|
-
"@ultimat3/time": "31.
|
|
47
|
+
"@ultimat3/core": "31.48.0",
|
|
48
|
+
"@ultimat3/i18n": "31.48.0",
|
|
49
|
+
"@ultimat3/jobs": "31.48.0",
|
|
50
|
+
"@ultimat3/schema": "31.48.0",
|
|
51
|
+
"@ultimat3/storage": "31.48.0",
|
|
52
|
+
"@ultimat3/time": "31.48.0"
|
|
53
53
|
}
|
|
54
54
|
}
|
package/src/driver-env.ts
CHANGED
|
@@ -22,6 +22,7 @@ export const MAIL_ENV_KEYS = [
|
|
|
22
22
|
'RESEND_API_KEY',
|
|
23
23
|
'MAIL_FROM',
|
|
24
24
|
'MAIL_POOL_SIZE',
|
|
25
|
+
'MAIL_TIMEOUT_MS',
|
|
25
26
|
'SES_REGION',
|
|
26
27
|
'SES_ACCESS_KEY_ID',
|
|
27
28
|
'SES_SECRET_ACCESS_KEY',
|
|
@@ -97,6 +98,27 @@ function poolSizeFrom(env: MailEnvironment): number | undefined {
|
|
|
97
98
|
return parsed;
|
|
98
99
|
}
|
|
99
100
|
|
|
101
|
+
/** The longest delay `setTimeout` holds: one past it overflows to 1 ms and fires at once. */
|
|
102
|
+
const MAX_TIMER_MS = 2_147_483_647;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* `MAIL_POOL_SIZE`'s rule, plus a ceiling: the deadline reaches `setTimeout`, so a value past
|
|
106
|
+
* `MAX_TIMER_MS` — written to wait LONGER — would expire every read on the next tick.
|
|
107
|
+
*/
|
|
108
|
+
function timeoutMsFrom(env: MailEnvironment): number | undefined {
|
|
109
|
+
const raw = nonEmpty(env['MAIL_TIMEOUT_MS']);
|
|
110
|
+
if (raw === undefined) return undefined;
|
|
111
|
+
const parsed = Number(raw);
|
|
112
|
+
if (!Number.isInteger(parsed) || parsed < 1 || parsed > MAX_TIMER_MS) {
|
|
113
|
+
throw new ConfigInvalidError({
|
|
114
|
+
cause: `MAIL_TIMEOUT_MS is "${raw}", which is not a whole number of milliseconds from 1 to ${MAX_TIMER_MS}`,
|
|
115
|
+
fix: 'MAIL_TIMEOUT_MS=60000 — in .env.production, or unset it to keep the 30000 default',
|
|
116
|
+
meta: { MAIL_TIMEOUT_MS: raw },
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
return parsed;
|
|
120
|
+
}
|
|
121
|
+
|
|
100
122
|
/**
|
|
101
123
|
* A credential selects its transport. Two credentials is the one case that cannot be answered by
|
|
102
124
|
* picking a winner — whichever this chose would be the one an operator did not mean half the time,
|
|
@@ -130,11 +152,13 @@ export function selectMailDriver(
|
|
|
130
152
|
const smtpUrl = nonEmpty(env['SMTP_URL']);
|
|
131
153
|
if (smtpUrl !== undefined) {
|
|
132
154
|
const poolSize = poolSizeFrom(env);
|
|
155
|
+
const timeoutMs = timeoutMsFrom(env);
|
|
133
156
|
return {
|
|
134
157
|
driver: smtpMailDriver({
|
|
135
158
|
url: smtpUrl,
|
|
136
159
|
from: requireFrom(env, 'SMTP_URL'),
|
|
137
160
|
...(poolSize === undefined ? {} : { poolSize }),
|
|
161
|
+
...(timeoutMs === undefined ? {} : { timeoutMs }),
|
|
138
162
|
retainMime: options.retainMime,
|
|
139
163
|
}),
|
|
140
164
|
detail: 'SMTP_URL',
|
package/src/smtp-client.ts
CHANGED
|
@@ -164,7 +164,7 @@ class Conversation {
|
|
|
164
164
|
stage,
|
|
165
165
|
detail: `the server sent nothing for ${timeoutMs}ms, so the read deadline expired`,
|
|
166
166
|
retryable: true,
|
|
167
|
-
fix: 'smtpMailDriver({ url, from, timeoutMs: 60_000 })
|
|
167
|
+
fix: 'MAIL_TIMEOUT_MS=60000 # in .env.production — or smtpMailDriver({ url, from, timeoutMs: 60_000 })',
|
|
168
168
|
}),
|
|
169
169
|
);
|
|
170
170
|
}, timeoutMs);
|
package/src/smtp-socket.ts
CHANGED
|
@@ -233,7 +233,7 @@ export function smtpStreamOver(runtime: BunConnect, target: SmtpTarget): Promise
|
|
|
233
233
|
stage: 'data',
|
|
234
234
|
detail: `the socket stopped accepting bytes for ${target.timeoutMs}ms`,
|
|
235
235
|
retryable: true,
|
|
236
|
-
fix: 'smtpMailDriver({ url, from, timeoutMs: 60_000 })
|
|
236
|
+
fix: 'MAIL_TIMEOUT_MS=60000 # in .env.production — or smtpMailDriver({ url, from, timeoutMs: 60_000 })',
|
|
237
237
|
}),
|
|
238
238
|
);
|
|
239
239
|
}, target.timeoutMs);
|