@joelincc/mailroom 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +165 -2
- package/SECURITY.md +11 -0
- package/docs/security-model.md +82 -0
- package/migrations/0001_init.sql +42 -0
- package/migrations/0002_tier.sql +4 -0
- package/migrations/0003_rate.sql +9 -0
- package/package.json +48 -4
- package/src/cf-events.ts +83 -0
- package/src/core.ts +287 -0
- package/src/index.ts +289 -0
- package/src/transport.ts +193 -0
- package/src/webhook.ts +99 -0
- package/wrangler.example.jsonc +42 -0
package/src/core.ts
ADDED
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
// 郵務室的帳本邏輯:拒收名單 → 去重 → 交郵差 → 記帳。
|
|
2
|
+
// 不 import cloudflare:*,測試用 Node 內建 SQLite 跑同一份 SQL(tests/helpers.ts)。
|
|
3
|
+
|
|
4
|
+
import { deliver, idempotencyKeyFor, MAIL_ROUTES, type MailRoute, type TransportKeys } from './transport.ts';
|
|
5
|
+
|
|
6
|
+
/** D1 用得到的那一小塊介面(D1Database 本身就符合)。 */
|
|
7
|
+
export interface Stmt {
|
|
8
|
+
bind(...values: unknown[]): Stmt;
|
|
9
|
+
first<T = Record<string, unknown>>(): Promise<T | null>;
|
|
10
|
+
run(): Promise<{ meta: { changes?: number } }>;
|
|
11
|
+
all<T = Record<string, unknown>>(): Promise<{ results: T[] }>;
|
|
12
|
+
}
|
|
13
|
+
export interface Db {
|
|
14
|
+
prepare(sql: string): Stmt;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type Stream = 'transactional' | 'marketing';
|
|
18
|
+
/**
|
|
19
|
+
* 掛號櫃台裡的兩層:notify=第一層「一定要到」(登入、邀請、付款…);
|
|
20
|
+
* remind=第二層「服務提醒」(待簽核、到期提醒、彙整…)。各用自己的寄件網域與郵差順序。
|
|
21
|
+
*/
|
|
22
|
+
export type Tier = 'notify' | 'remind';
|
|
23
|
+
export const TIERS: readonly Tier[] = ['notify', 'remind'];
|
|
24
|
+
/** 郵差順序表:鍵=`站:層`、`*:層`;查不到用 DEFAULT_ROUTES。 */
|
|
25
|
+
export type RouteTable = Record<string, readonly MailRoute[]>;
|
|
26
|
+
export const DEFAULT_ROUTES: readonly MailRoute[] = ['resend', 'smtp2go'];
|
|
27
|
+
export type SuppressionReason = 'hard_bounce' | 'complaint' | 'unsubscribe';
|
|
28
|
+
export const SUPPRESSION_REASONS: readonly SuppressionReason[] = ['hard_bounce', 'complaint', 'unsubscribe'];
|
|
29
|
+
|
|
30
|
+
export interface SendRequest {
|
|
31
|
+
site: string;
|
|
32
|
+
/** 去重鍵:同一站同一把只寄一次(失敗的可以拿同一把重試)。 */
|
|
33
|
+
key: string;
|
|
34
|
+
/** 現在只開掛號櫃台,省略=transactional。 */
|
|
35
|
+
stream?: Stream;
|
|
36
|
+
/** 第幾層;省略=notify(第一層)。寄件地址必須是這一層的網域。 */
|
|
37
|
+
tier?: Tier;
|
|
38
|
+
kind?: string;
|
|
39
|
+
from: string;
|
|
40
|
+
to: string;
|
|
41
|
+
subject: string;
|
|
42
|
+
html: string;
|
|
43
|
+
text: string;
|
|
44
|
+
replyTo?: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* sent=這次寄出 duplicate=這把鑰匙早就寄過了(不重寄) in_flight=同一把鑰匙正在寄,稍後再問
|
|
49
|
+
* suppressed=收件人在拒收名單 failed=兩個郵差都失敗 rejected=請求本身不合格(不要重試)
|
|
50
|
+
*/
|
|
51
|
+
export type SendStatus = 'sent' | 'duplicate' | 'in_flight' | 'suppressed' | 'failed' | 'rejected';
|
|
52
|
+
|
|
53
|
+
export interface SendResult {
|
|
54
|
+
status: SendStatus;
|
|
55
|
+
/** true=站上應記「待寄」,稍後拿同一把鑰匙再送。 */
|
|
56
|
+
retryable: boolean;
|
|
57
|
+
route?: MailRoute;
|
|
58
|
+
id?: number;
|
|
59
|
+
reason?: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface MessageRow {
|
|
63
|
+
id: number; stream: Stream; tier: Tier | null; site: string; dedupe_key: string; kind: string | null; to_email: string; from_addr: string;
|
|
64
|
+
subject: string; status: string; route: string | null; provider_id: string | null; error: string | null; attempts: number;
|
|
65
|
+
last_event: string | null; created_at: string; updated_at: string; sent_at: string | null;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface CoreDeps {
|
|
69
|
+
db: Db;
|
|
70
|
+
/** 第一層(notify)的郵差鑰匙;其他層沒給 tierKeys 就沿用這組。 */
|
|
71
|
+
keys: TransportKeys;
|
|
72
|
+
tierKeys?: Partial<Record<Tier, TransportKeys>>;
|
|
73
|
+
/** 第一層的寄件網域(例 notify.example.com)。 */
|
|
74
|
+
fromDomain: string;
|
|
75
|
+
/** 其他層的寄件網域(例 { remind: 'remind.example.com' });沒設的層一律拒收。 */
|
|
76
|
+
tierDomains?: Partial<Record<Tier, string>>;
|
|
77
|
+
routes?: RouteTable;
|
|
78
|
+
fetcher?: typeof fetch;
|
|
79
|
+
now?: () => Date;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const EMAIL = /^[^\s,;<>"'@]+@[^\s,;<>"'@]+\.[^\s,;<>"'@]+$/;
|
|
83
|
+
const SITE = /^[a-z0-9][a-z0-9-]{0,39}$/;
|
|
84
|
+
/** 「正在寄」超過這麼久沒結果(Worker 中途被砍)就當失敗,可以重寄。 */
|
|
85
|
+
const STALE_SENDING_MS = 2 * 60_000;
|
|
86
|
+
const LIMITS = { key: 300, subject: 300, html: 400_000, text: 200_000, to: 254, kind: 64 };
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* 寄件人只收兩種寫法:`a@b` 或 `顯示名稱 <a@b>`(名稱可加雙引號)。名稱不准有控制字元、<>"@,;\\;
|
|
90
|
+
* 通過後由郵務室重組成 `名稱 <a@b>` 交郵差,原字串不往外送(防標頭注入、防騙過寄件網域檢查)。
|
|
91
|
+
*/
|
|
92
|
+
export function parseAddress(raw: string): { name: string | null; addr: string } | null {
|
|
93
|
+
if (typeof raw !== 'string' || raw.length > 320 || /[\u0000-\u001f\u007f]/.test(raw)) return null;
|
|
94
|
+
const s = raw.trim();
|
|
95
|
+
const m = /^(?:"([^"]*)"|([^<>"]*?))\s*<([^<>\s]+)>$/.exec(s);
|
|
96
|
+
const name = m ? (m[1] ?? m[2] ?? '').trim() : null;
|
|
97
|
+
const addr = (m ? m[3] : s).toLowerCase();
|
|
98
|
+
if (!EMAIL.test(addr)) return null;
|
|
99
|
+
if (name !== null && /[<>"@,;\\]/.test(name)) return null;
|
|
100
|
+
// 顯示名稱不准有文字方向控制字元(可把名稱在收件匣裡倒著顯示,用來冒充別的寄件人)。
|
|
101
|
+
if (name !== null && /[\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069]/.test(name)) return null;
|
|
102
|
+
return { name: name || null, addr };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const formatAddress = (a: { name: string | null; addr: string }) => (a.name ? `${a.name} <${a.addr}>` : a.addr);
|
|
106
|
+
|
|
107
|
+
/** 這一層的寄件網域;沒設=這層沒開。 */
|
|
108
|
+
export function domainFor(deps: Pick<CoreDeps, 'fromDomain' | 'tierDomains'>, tier: Tier): string | null {
|
|
109
|
+
return tier === 'notify' ? deps.fromDomain : deps.tierDomains?.[tier] ?? null;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** 郵差順序:先找 `站:層`,再找 `*:層`,都沒有用預設(Resend → SMTP2GO)。表裡寫錯的郵差名字略過。 */
|
|
113
|
+
export function routeFor(table: RouteTable | undefined, site: string, tier: Tier): readonly MailRoute[] {
|
|
114
|
+
const raw = table?.[`${site}:${tier}`] ?? table?.[`*:${tier}`];
|
|
115
|
+
const clean = Array.isArray(raw) ? raw.filter((r): r is MailRoute => MAIL_ROUTES.includes(r as MailRoute)) : [];
|
|
116
|
+
return clean.length > 0 ? clean : DEFAULT_ROUTES;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function validate(req: SendRequest, fromDomain: string | null): string | null {
|
|
120
|
+
if (!req || typeof req !== 'object') return 'bad_request';
|
|
121
|
+
if (!SITE.test(String(req.site ?? ''))) return 'bad_site';
|
|
122
|
+
if (typeof req.key !== 'string' || !req.key || req.key.length > LIMITS.key || /[\u0000-\u001f\u007f]/.test(req.key)) return 'bad_key';
|
|
123
|
+
if ((req.stream ?? 'transactional') !== 'transactional') return 'stream_closed'; // 印刷品櫃台還沒開
|
|
124
|
+
if (!fromDomain) return 'bad_tier';
|
|
125
|
+
if (typeof req.to !== 'string' || req.to.length > LIMITS.to || /[\u0000-\u001f\u007f]/.test(req.to) || !EMAIL.test(req.to)) return 'bad_to';
|
|
126
|
+
if (req.kind !== undefined && req.kind !== null && (typeof req.kind !== 'string' || req.kind.length > LIMITS.kind || /[\u0000-\u001f\u007f]/.test(req.kind))) return 'bad_kind';
|
|
127
|
+
const from = parseAddress(String(req.from ?? ''));
|
|
128
|
+
if (!from || !from.addr.endsWith(`@${fromDomain}`)) return 'bad_from';
|
|
129
|
+
if (typeof req.subject !== 'string' || !req.subject || req.subject.length > LIMITS.subject || /[\u0000-\u001f\u007f]/.test(req.subject)) return 'bad_subject';
|
|
130
|
+
if (typeof req.html !== 'string' || typeof req.text !== 'string' || req.html.length > LIMITS.html || req.text.length > LIMITS.text) return 'bad_body';
|
|
131
|
+
if (req.replyTo !== undefined && !parseAddress(req.replyTo)) return 'bad_reply_to';
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** 這個信箱在這個櫃台會不會被擋;擋的話回原因。 */
|
|
136
|
+
export async function suppressedReason(db: Db, email: string, stream: Stream): Promise<SuppressionReason | null> {
|
|
137
|
+
const reasons: SuppressionReason[] = stream === 'marketing' ? ['hard_bounce', 'complaint', 'unsubscribe'] : ['hard_bounce', 'complaint'];
|
|
138
|
+
const row = await db
|
|
139
|
+
.prepare(`SELECT reason FROM suppressions WHERE email = ? AND reason IN (${reasons.map(() => '?').join(',')}) LIMIT 1`)
|
|
140
|
+
.bind(email.toLowerCase(), ...reasons)
|
|
141
|
+
.first<{ reason: SuppressionReason }>();
|
|
142
|
+
return row?.reason ?? null;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export async function addSuppression(db: Db, email: string, reason: SuppressionReason, source: string, detail: string | null, now = new Date()): Promise<boolean> {
|
|
146
|
+
const r = await db
|
|
147
|
+
.prepare('INSERT INTO suppressions (email, reason, source, detail, created_at) VALUES (?, ?, ?, ?, ?) ON CONFLICT (email, reason) DO NOTHING')
|
|
148
|
+
.bind(email.trim().toLowerCase(), reason, source, detail ? detail.slice(0, 300) : null, now.toISOString())
|
|
149
|
+
.run();
|
|
150
|
+
return (r.meta.changes ?? 0) > 0;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* 人工解除拒收:把這個信箱的指定原因從拒收名單拿掉(例:對方換了信箱主機、誤判的退信)。
|
|
155
|
+
* 原因一定要明講(不給預設),避免一次把檢舉也解掉。回傳實際拿掉的原因。
|
|
156
|
+
* 郵差自己的拒收名單(例 Resend 後台)不在這裡,要另外去郵差那邊解。
|
|
157
|
+
*/
|
|
158
|
+
export async function removeSuppression(db: Db, email: string, reasons: SuppressionReason[]): Promise<SuppressionReason[]> {
|
|
159
|
+
const addr = email.trim().toLowerCase();
|
|
160
|
+
const removed: SuppressionReason[] = [];
|
|
161
|
+
for (const reason of reasons) {
|
|
162
|
+
const r = await db.prepare('DELETE FROM suppressions WHERE email = ? AND reason = ?').bind(addr, reason).run();
|
|
163
|
+
if ((r.meta.changes ?? 0) > 0) removed.push(reason);
|
|
164
|
+
}
|
|
165
|
+
return removed;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* 走公開網址(帶鑰匙)的站的速度上限:每分鐘 perMinute、每天 perDay 次請求。
|
|
170
|
+
* 用意=鑰匙外洩時,別人拿它也寄不了多少。計數用一條 SQL 加一並讀回(原子),同時打進 N 個請求也擋得住。
|
|
171
|
+
* 算的是「請求次數」不是寄出封數(被拒的也算),寧可保守。內線(同帳號)不受限。0 或不合法=該窗不限。
|
|
172
|
+
* 回傳超過的那個窗('minute'/'day'),沒超過回 null。
|
|
173
|
+
*/
|
|
174
|
+
export async function takeRate(db: Db, site: string, limits: { perMinute: number; perDay: number }, now = new Date()): Promise<'minute' | 'day' | null> {
|
|
175
|
+
const iso = now.toISOString();
|
|
176
|
+
const windows: Array<['minute' | 'day', string, number]> = [
|
|
177
|
+
['minute', `m:${iso.slice(0, 16)}`, limits.perMinute],
|
|
178
|
+
['day', `d:${iso.slice(0, 10)}`, limits.perDay],
|
|
179
|
+
];
|
|
180
|
+
for (const [name, win, limit] of windows) {
|
|
181
|
+
if (!Number.isFinite(limit) || limit <= 0) continue;
|
|
182
|
+
const row = await db
|
|
183
|
+
.prepare('INSERT INTO rate_counters (site, win, n) VALUES (?, ?, 1) ON CONFLICT (site, win) DO UPDATE SET n = n + 1 RETURNING n')
|
|
184
|
+
.bind(site, win)
|
|
185
|
+
.first<{ n: number }>();
|
|
186
|
+
if (Number(row?.n ?? 0) > limit) return name;
|
|
187
|
+
}
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** 速度上限設定:沒設、空白或不合法=預設;只接受 ≥0 的整數,明寫 0=不限。 */
|
|
192
|
+
export function limitVar(v: unknown, fallback: number): number {
|
|
193
|
+
if (typeof v === 'number') return Number.isInteger(v) && v >= 0 ? v : fallback;
|
|
194
|
+
if (typeof v !== 'string' || !/^\d+$/.test(v.trim())) return fallback;
|
|
195
|
+
return Number(v.trim());
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* 請求內文大小檢查(看 content-length 標頭):沒帶、亂碼或超過上限都不收。
|
|
200
|
+
* 回 'missing'(應回 411)、'too_large'(應回 413)或 null(可以讀)。
|
|
201
|
+
*/
|
|
202
|
+
export function bodySizeProblem(contentLength: string | null, max: number): 'missing' | 'too_large' | null {
|
|
203
|
+
if (contentLength === null || !/^\d+$/.test(contentLength.trim())) return 'missing';
|
|
204
|
+
return Number(contentLength.trim()) > max ? 'too_large' : null;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** 指定時差的日期 YYYY-MM-DD(預設 UTC;時差夾在 ±14 小時內)。 */
|
|
208
|
+
export function localDay(d: Date, offsetHours: unknown = 0): string {
|
|
209
|
+
const n = typeof offsetHours === 'string' && /^\s*-?\d+(\.\d+)?\s*$/.test(offsetHours) ? Number(offsetHours) : offsetHours;
|
|
210
|
+
const h = typeof n === 'number' && Number.isFinite(n) ? Math.max(-14, Math.min(14, n)) : 0;
|
|
211
|
+
return new Date(d.getTime() + h * 3_600_000).toISOString().slice(0, 10);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** 舊的計數窗清掉(兩天前以前);由 /v1/send(約每 100 次)與管理入口(約每 20 次)順手呼叫。 */
|
|
215
|
+
export async function pruneRate(db: Db, now = new Date()): Promise<void> {
|
|
216
|
+
const cutoff = new Date(now.getTime() - 2 * 86_400_000).toISOString();
|
|
217
|
+
await db.prepare("DELETE FROM rate_counters WHERE (win LIKE 'm:%' AND win < ?) OR (win LIKE 'd:%' AND win < ?)").bind(`m:${cutoff.slice(0, 16)}`, `d:${cutoff.slice(0, 10)}`).run();
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export async function lookup(db: Db, site: string, key: string): Promise<MessageRow | null> {
|
|
221
|
+
return db.prepare('SELECT * FROM messages WHERE site = ? AND dedupe_key = ?').bind(site, key).first<MessageRow>();
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export async function send(deps: CoreDeps, req: SendRequest, opts: { forceInvalidResend?: boolean; routes?: readonly MailRoute[] } = {}): Promise<SendResult> {
|
|
225
|
+
const tier: Tier = req && typeof req === 'object' && req.tier !== undefined ? req.tier : 'notify';
|
|
226
|
+
if (!TIERS.includes(tier)) return { status: 'rejected', retryable: false, reason: 'bad_tier' };
|
|
227
|
+
const bad = validate(req, domainFor(deps, tier));
|
|
228
|
+
if (bad) return { status: 'rejected', retryable: false, reason: bad };
|
|
229
|
+
const { db } = deps;
|
|
230
|
+
const now = (deps.now ?? (() => new Date()))();
|
|
231
|
+
const iso = now.toISOString();
|
|
232
|
+
const stream: Stream = req.stream ?? 'transactional';
|
|
233
|
+
const to = req.to.trim().toLowerCase();
|
|
234
|
+
// 驗過才重組,原字串不往外送。
|
|
235
|
+
const from = formatAddress(parseAddress(req.from)!);
|
|
236
|
+
const replyTo = req.replyTo === undefined ? undefined : formatAddress(parseAddress(req.replyTo)!);
|
|
237
|
+
|
|
238
|
+
// 1. 拒收名單:照樣記一列(查得到「為什麼沒寄」),不交郵差。
|
|
239
|
+
const blocked = await suppressedReason(db, to, stream);
|
|
240
|
+
|
|
241
|
+
// 2. 搶這把去重鍵:沒寄過、上次失敗/被擋、或「正在寄」已經放太久,才輪得到這次。
|
|
242
|
+
const staleBefore = new Date(now.getTime() - STALE_SENDING_MS).toISOString();
|
|
243
|
+
const status = blocked ? 'suppressed' : 'sending';
|
|
244
|
+
const claimed = await db
|
|
245
|
+
.prepare(
|
|
246
|
+
`INSERT INTO messages (stream, tier, site, dedupe_key, kind, to_email, from_addr, subject, status, error, attempts, created_at, updated_at)
|
|
247
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1, ?, ?)
|
|
248
|
+
ON CONFLICT (site, dedupe_key) DO UPDATE SET
|
|
249
|
+
status = excluded.status, error = excluded.error, attempts = messages.attempts + 1, updated_at = excluded.updated_at,
|
|
250
|
+
to_email = excluded.to_email, from_addr = excluded.from_addr, subject = excluded.subject, tier = excluded.tier
|
|
251
|
+
WHERE messages.status IN ('failed', 'suppressed') OR (messages.status = 'sending' AND messages.updated_at < ?)
|
|
252
|
+
RETURNING id`,
|
|
253
|
+
)
|
|
254
|
+
.bind(stream, tier, req.site, req.key, req.kind ?? null, to, from, req.subject, status, blocked ? `suppressed:${blocked}` : null, iso, iso, staleBefore)
|
|
255
|
+
.first<{ id: number }>();
|
|
256
|
+
|
|
257
|
+
if (!claimed) {
|
|
258
|
+
const existing = await lookup(db, req.site, req.key);
|
|
259
|
+
if (existing?.status === 'sent') return { status: 'duplicate', retryable: false, route: (existing.route as MailRoute) ?? undefined, id: existing.id };
|
|
260
|
+
return { status: 'in_flight', retryable: true, id: existing?.id };
|
|
261
|
+
}
|
|
262
|
+
if (blocked) return { status: 'suppressed', retryable: false, id: claimed.id, reason: blocked };
|
|
263
|
+
|
|
264
|
+
// 3. 交郵差。
|
|
265
|
+
const tierKeys = deps.tierKeys?.[tier] ?? deps.keys;
|
|
266
|
+
const keys: TransportKeys = opts.forceInvalidResend ? { ...tierKeys, resend: 're_invalid_drill_key' } : tierKeys;
|
|
267
|
+
const routes = opts.routes ?? routeFor(deps.routes, req.site, tier);
|
|
268
|
+
const out = await deliver(keys, { from, to, subject: req.subject, html: req.html, text: req.text, replyTo }, await idempotencyKeyFor(req.site, req.key), deps.fetcher, routes);
|
|
269
|
+
|
|
270
|
+
// 4. 記帳。
|
|
271
|
+
const done = (deps.now ?? (() => new Date()))().toISOString();
|
|
272
|
+
if (out.ok) {
|
|
273
|
+
await db
|
|
274
|
+
.prepare("UPDATE messages SET status = 'sent', route = ?, provider_id = ?, error = NULL, updated_at = ?, sent_at = ? WHERE id = ?")
|
|
275
|
+
.bind(out.route, out.providerId ?? null, done, done, claimed.id)
|
|
276
|
+
.run();
|
|
277
|
+
return { status: 'sent', retryable: false, route: out.route, id: claimed.id };
|
|
278
|
+
}
|
|
279
|
+
if (out.suppressed) {
|
|
280
|
+
// 郵差(Cloudflare)自己的拒收名單擋下:不換郵差、不重試;原因不明,不寫進我們的拒收名單。
|
|
281
|
+
await db.prepare("UPDATE messages SET status = 'suppressed', error = ?, updated_at = ? WHERE id = ?").bind(out.error ?? 'provider_suppressed', done, claimed.id).run();
|
|
282
|
+
return { status: 'suppressed', retryable: false, id: claimed.id, reason: 'provider_suppressed' };
|
|
283
|
+
}
|
|
284
|
+
await db.prepare("UPDATE messages SET status = 'failed', error = ?, updated_at = ? WHERE id = ?").bind(out.error ?? 'unknown', done, claimed.id).run();
|
|
285
|
+
console.error('mail failed', req.site, req.kind ?? '-', out.error);
|
|
286
|
+
return { status: 'failed', retryable: true, id: claimed.id, reason: out.error };
|
|
287
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
// 郵務室(mailroom):多個站共用的寄信 Worker。運作說明見 README。
|
|
2
|
+
//
|
|
3
|
+
// 兩個入口:
|
|
4
|
+
// - 內線(service binding):同一個 Cloudflare 帳號的站在 wrangler.jsonc 加
|
|
5
|
+
// { "binding": "MAILROOM", "service": "mailroom", "entrypoint": "Mailroom" },呼叫 env.MAILROOM.send({...})。
|
|
6
|
+
// - 公開網址(workers.dev):Resend 事後回報 POST /webhooks/resend;
|
|
7
|
+
// 別的 Cloudflare 帳號的站帶自己的鑰匙 POST /v1/send;演習 POST /v1/drill;寄信統計 GET /v1/report;
|
|
8
|
+
// 人工解除拒收 POST /v1/unsuppress。
|
|
9
|
+
// - Queue:Cloudflare 寄信的事後回報(cf-events.ts)。
|
|
10
|
+
// - 排程:有設 cron 與 DAILY_DRILL 時,每天最多寄一輪演習信(過了 until 自動停)。
|
|
11
|
+
|
|
12
|
+
import { WorkerEntrypoint } from 'cloudflare:workers';
|
|
13
|
+
import { bodySizeProblem, limitVar, localDay, lookup, parseAddress, pruneRate, removeSuppression, send, SUPPRESSION_REASONS, takeRate, TIERS, type SuppressionReason, type CoreDeps, type MessageRow, type RouteTable, type SendRequest, type SendResult, type Tier } from './core.ts';
|
|
14
|
+
import { handleCfEvent } from './cf-events.ts';
|
|
15
|
+
import { MAIL_ROUTES, type CloudflareSender, type MailRoute } from './transport.ts';
|
|
16
|
+
import { handleEvent, verifySignature } from './webhook.ts';
|
|
17
|
+
|
|
18
|
+
export interface Env {
|
|
19
|
+
DB: D1Database;
|
|
20
|
+
/** 第一層(一定要到)的寄件網域,例 notify.example.com。 */
|
|
21
|
+
FROM_DOMAIN: string;
|
|
22
|
+
/** 第二層(服務提醒)的寄件網域,例 remind.example.com。沒設=第二層不收。 */
|
|
23
|
+
REMIND_DOMAIN?: string;
|
|
24
|
+
/** 郵差順序表(JSON 物件,鍵=`站:層`/`*:層`)。改這裡+部署=換郵差順序/退回原狀。 */
|
|
25
|
+
ROUTES?: RouteTable | string;
|
|
26
|
+
/** Cloudflare 寄信綁定(send_email),只准第二層的寄件地址。 */
|
|
27
|
+
EMAIL?: SendEmail;
|
|
28
|
+
/** 第二層專用的 Resend 鑰匙(只能從第二層網域寄);沒放=第二層備援跳過 Resend。 */
|
|
29
|
+
RESEND_API_KEY_REMIND?: string;
|
|
30
|
+
/** 每日演習:{ until: 'YYYY-MM-DD'(含當天;日期照 utcOffsetHours,預設 UTC), to: [...], site, tier, routes?, utcOffsetHours? }。 */
|
|
31
|
+
DAILY_DRILL?: DailyDrill | string;
|
|
32
|
+
/** 走公開網址寄信的站(逗號分隔,例 "shop");每站一把 Secret:HTTP_KEY_<站名大寫>。 */
|
|
33
|
+
HTTP_CLIENTS?: string;
|
|
34
|
+
/** 走公開網址的站每分鐘最多幾次請求(預設 60;鑰匙外洩時的上限)。 */
|
|
35
|
+
HTTP_RATE_PER_MIN?: string | number;
|
|
36
|
+
/** 走公開網址的站每天最多幾次請求(預設 2000,UTC 日)。 */
|
|
37
|
+
HTTP_DAILY_LIMIT?: string | number;
|
|
38
|
+
/** 走公開網址的站准用的寄件地址(JSON:{ "站": ["app@notify.example.com"] })。沒列的站=該層網域內任一地址(並記警告)。 */
|
|
39
|
+
HTTP_FROM?: Record<string, string[]> | string;
|
|
40
|
+
RESEND_API_KEY?: string;
|
|
41
|
+
SMTP2GO_API_KEY?: string;
|
|
42
|
+
RESEND_WEBHOOK_SECRET?: string;
|
|
43
|
+
/** 管理口令(演習、查帳、統計、解除拒收);沒設=這些路徑一律 404。 */
|
|
44
|
+
DRILL_TOKEN?: string;
|
|
45
|
+
[key: `HTTP_KEY_${string}`]: string | undefined;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** 公開網址入口每站每分鐘預設上限。 */
|
|
49
|
+
const DEFAULT_HTTP_RATE_PER_MIN = 60;
|
|
50
|
+
/** 公開網址入口每站每天預設上限。 */
|
|
51
|
+
const DEFAULT_HTTP_DAILY_LIMIT = 2000;
|
|
52
|
+
/** 管理口令入口(演習、查帳、統計、解除拒收)合計上限:口令外洩時,別人拿它也寄不了多少演習信。 */
|
|
53
|
+
const ADMIN_LIMITS = { perMinute: 20, perDay: 200 };
|
|
54
|
+
/** 請求內文上限(位元組,一定要帶 content-length):寄信 3 MB(內文上限 html 40 萬+text 20 萬字元,中文 UTF-8 一字 3 bytes)、webhook 256 KB。 */
|
|
55
|
+
const MAX_SEND_BYTES = 3_000_000;
|
|
56
|
+
const MAX_WEBHOOK_BYTES = 256_000;
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
interface DailyDrill { until: string; to: string[]; site?: string; tier?: Tier; routes?: MailRoute[]; utcOffsetHours?: number }
|
|
60
|
+
|
|
61
|
+
function jsonVar<T>(v: T | string | undefined): T | undefined {
|
|
62
|
+
if (typeof v !== 'string') return v;
|
|
63
|
+
try {
|
|
64
|
+
return JSON.parse(v) as T;
|
|
65
|
+
} catch {
|
|
66
|
+
console.error('bad json var');
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function deps(env: Env): CoreDeps {
|
|
72
|
+
const base = { resend: env.RESEND_API_KEY, smtp2go: env.SMTP2GO_API_KEY };
|
|
73
|
+
return {
|
|
74
|
+
db: env.DB,
|
|
75
|
+
keys: base,
|
|
76
|
+
fromDomain: env.FROM_DOMAIN,
|
|
77
|
+
tierDomains: env.REMIND_DOMAIN ? { remind: env.REMIND_DOMAIN } : {},
|
|
78
|
+
// 第二層:Resend 用自己的鑰匙(Resend 鑰匙綁網域);Cloudflare 綁定只給第二層。
|
|
79
|
+
tierKeys: { remind: { resend: env.RESEND_API_KEY_REMIND, smtp2go: env.SMTP2GO_API_KEY, cloudflare: env.EMAIL as unknown as CloudflareSender | undefined } },
|
|
80
|
+
routes: jsonVar<RouteTable>(env.ROUTES),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export type DrillMode = 'fallback' | 'normal';
|
|
85
|
+
export interface DrillInput { to: string; mode?: DrillMode; key?: string; tier?: Tier; only?: MailRoute }
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* 演習信:fallback 故意給錯的 Resend 鑰匙(Resend 真的回 401)→ 應改走下一個郵差;normal 走正式路徑。
|
|
89
|
+
* tier=哪一層(寄件網域跟著換);only=只走這一個郵差(看單一郵差能不能寄、簽章對不對)。
|
|
90
|
+
*/
|
|
91
|
+
async function drill(env: Env, site: string, input: DrillInput): Promise<SendResult & { row: MessageRow | null }> {
|
|
92
|
+
const mode: DrillMode = input.mode === 'normal' ? 'normal' : 'fallback';
|
|
93
|
+
const tier: Tier = input.tier && TIERS.includes(input.tier) ? input.tier : 'notify';
|
|
94
|
+
const only = input.only && MAIL_ROUTES.includes(input.only) ? input.only : undefined;
|
|
95
|
+
const domain = tier === 'remind' ? env.REMIND_DOMAIN : env.FROM_DOMAIN;
|
|
96
|
+
const stamp = new Date().toISOString();
|
|
97
|
+
const label = [site, tier, only ? `only-${only}` : mode].join(' / ');
|
|
98
|
+
// 演習的去重鍵一律加 drill: 前綴:不能拿演習去搶真信的去重鍵(否則那封真信會被當成已寄)。
|
|
99
|
+
const raw = input.key || `${tier}:${only ?? mode}:${stamp}`;
|
|
100
|
+
const key = raw.startsWith('drill:') ? raw : `drill:${raw}`;
|
|
101
|
+
const result = await send(
|
|
102
|
+
deps(env),
|
|
103
|
+
{
|
|
104
|
+
site, key, tier, kind: 'drill', to: input.to,
|
|
105
|
+
from: `Mailroom drill <mailroom@${domain ?? 'unset.invalid'}>`,
|
|
106
|
+
subject: `[mailroom drill] ${label} ${stamp}`,
|
|
107
|
+
text: `This is a mailroom delivery drill (${label}). No reply needed.\n${stamp}`,
|
|
108
|
+
html: `<p>This is a mailroom delivery drill (${label}). No reply needed.</p><p>${stamp}</p>`,
|
|
109
|
+
},
|
|
110
|
+
{ forceInvalidResend: !only && mode === 'fallback', routes: only ? [only] : undefined },
|
|
111
|
+
);
|
|
112
|
+
return { ...result, row: await lookup(env.DB, site, key) };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
/** 試跑期每日演習:每個收件人一封,同一天同一人只寄一次(去重鍵含日期)。 */
|
|
117
|
+
async function dailyDrill(env: Env, now = new Date()): Promise<string[]> {
|
|
118
|
+
const cfg = jsonVar<DailyDrill>(env.DAILY_DRILL);
|
|
119
|
+
if (!cfg || !Array.isArray(cfg.to) || !/^\d{4}-\d{2}-\d{2}$/.test(cfg.until ?? '')) return [];
|
|
120
|
+
const day = localDay(now, cfg.utcOffsetHours);
|
|
121
|
+
if (day > cfg.until) return [];
|
|
122
|
+
const out: string[] = [];
|
|
123
|
+
for (const to of cfg.to) {
|
|
124
|
+
const only = cfg.routes && cfg.routes.length === 1 ? cfg.routes[0] : undefined;
|
|
125
|
+
const r = await drill(env, cfg.site || 'drill', { to, mode: 'normal', tier: cfg.tier, only, key: `daily:${day}:${to.toLowerCase()}` });
|
|
126
|
+
out.push(`${r.status}:${r.route ?? '-'}`);
|
|
127
|
+
}
|
|
128
|
+
return out;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** 最近 N 天的寄信統計(試跑驗收用):依站、層、郵差、結果、事後回報分組。不含收件人。 */
|
|
132
|
+
async function report(env: Env, days: number) {
|
|
133
|
+
const since = new Date(Date.now() - days * 86_400_000).toISOString();
|
|
134
|
+
const rows = await env.DB.prepare(
|
|
135
|
+
`SELECT site, tier, route, status, COALESCE(last_event, '-') AS last_event, COUNT(*) AS n,
|
|
136
|
+
SUBSTR(to_email, INSTR(to_email, '@') + 1) AS to_domain
|
|
137
|
+
FROM messages WHERE created_at >= ? GROUP BY site, tier, route, status, last_event, to_domain ORDER BY site, tier, n DESC`,
|
|
138
|
+
).bind(since).all();
|
|
139
|
+
const suppressions = await env.DB.prepare('SELECT reason, source, COUNT(*) AS n FROM suppressions WHERE created_at >= ? GROUP BY reason, source').bind(since).all();
|
|
140
|
+
return { since, rows: rows.results, suppressions: suppressions.results };
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** 內線入口(RPC)。 */
|
|
144
|
+
export class Mailroom extends WorkerEntrypoint<Env> {
|
|
145
|
+
send(req: SendRequest): Promise<SendResult> {
|
|
146
|
+
return send(deps(this.env), req);
|
|
147
|
+
}
|
|
148
|
+
lookup(site: string, key: string): Promise<MessageRow | null> {
|
|
149
|
+
return lookup(this.env.DB, site, key);
|
|
150
|
+
}
|
|
151
|
+
drill(site: string, input: DrillInput) {
|
|
152
|
+
return drill(this.env, site, input);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function sameToken(a: string, b: string): boolean {
|
|
157
|
+
if (!a || !b || a.length !== b.length) return false;
|
|
158
|
+
let diff = 0;
|
|
159
|
+
for (let i = 0; i < a.length; i++) diff |= a.charCodeAt(i) ^ b.charCodeAt(i);
|
|
160
|
+
return diff === 0;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function bearer(request: Request): string {
|
|
164
|
+
const m = /^Bearer\s+(.+)$/i.exec(request.headers.get('authorization') ?? '');
|
|
165
|
+
return m ? m[1].trim() : '';
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** 帶鑰匙的站:鑰匙決定是哪個站,站名不聽請求本身的。 */
|
|
169
|
+
function clientSite(env: Env, token: string): string | null {
|
|
170
|
+
for (const site of (env.HTTP_CLIENTS ?? '').split(',').map((s) => s.trim()).filter(Boolean)) {
|
|
171
|
+
if (sameToken(token, env[`HTTP_KEY_${site.toUpperCase().replace(/-/g, '_')}`] ?? '')) return site;
|
|
172
|
+
}
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const json = (body: unknown, status = 200) =>
|
|
177
|
+
new Response(JSON.stringify(body), { status, headers: { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' } });
|
|
178
|
+
const notFound = () => new Response('Not found', { status: 404 });
|
|
179
|
+
|
|
180
|
+
/** 公開網址查帳只回狀態欄位,不回收件人、寄件人、主旨(口令外洩時不會變成查收件人的工具)。 */
|
|
181
|
+
function publicRow(row: MessageRow | null) {
|
|
182
|
+
if (!row) return null;
|
|
183
|
+
const { id, stream, tier, site, dedupe_key, kind, status, route, attempts, last_event, error, created_at, updated_at, sent_at } = row;
|
|
184
|
+
return { id, stream, tier, site, dedupe_key, kind, status, route, attempts, last_event, error, created_at, updated_at, sent_at };
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export default {
|
|
188
|
+
async fetch(request: Request, env: Env): Promise<Response> {
|
|
189
|
+
const url = new URL(request.url);
|
|
190
|
+
|
|
191
|
+
if (url.pathname === '/webhooks/resend' && request.method === 'POST') {
|
|
192
|
+
const size = bodySizeProblem(request.headers.get('content-length'), MAX_WEBHOOK_BYTES);
|
|
193
|
+
if (size) return new Response(size, { status: size === 'missing' ? 411 : 413 });
|
|
194
|
+
const body = await request.text();
|
|
195
|
+
const h = request.headers;
|
|
196
|
+
const ok = await verifySignature(env.RESEND_WEBHOOK_SECRET ?? '', h.get('svix-id') ?? '', h.get('svix-timestamp') ?? '', h.get('svix-signature') ?? '', body);
|
|
197
|
+
if (!ok) return new Response('bad signature', { status: 401 });
|
|
198
|
+
const outcome = await handleEvent(env.DB, h.get('svix-id') ?? '', body);
|
|
199
|
+
console.log('resend webhook', outcome);
|
|
200
|
+
return json({ ok: true });
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (url.pathname === '/v1/send' && request.method === 'POST') {
|
|
204
|
+
const site = clientSite(env, bearer(request));
|
|
205
|
+
if (!site) return notFound();
|
|
206
|
+
const limits = {
|
|
207
|
+
perMinute: limitVar(env.HTTP_RATE_PER_MIN, DEFAULT_HTTP_RATE_PER_MIN),
|
|
208
|
+
perDay: limitVar(env.HTTP_DAILY_LIMIT, DEFAULT_HTTP_DAILY_LIMIT),
|
|
209
|
+
};
|
|
210
|
+
const over = await takeRate(env.DB, site, limits);
|
|
211
|
+
// 舊計數窗順手清(約每 100 次請求一次),不另開排程。
|
|
212
|
+
if (Math.random() < 0.01) await pruneRate(env.DB).catch((e) => console.error('prune rate failed', e instanceof Error ? e.message : 'unknown'));
|
|
213
|
+
if (over) {
|
|
214
|
+
console.warn('http client rate limited', site, over);
|
|
215
|
+
return new Response(JSON.stringify({ status: 'failed', retryable: true, reason: `rate_limited_${over}` }), {
|
|
216
|
+
status: 429,
|
|
217
|
+
headers: { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store', 'retry-after': over === 'day' ? '3600' : '60' },
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
const size = bodySizeProblem(request.headers.get('content-length'), MAX_SEND_BYTES);
|
|
221
|
+
if (size) return json({ status: 'rejected', retryable: false, reason: size === 'missing' ? 'length_required' : 'too_large' }, size === 'missing' ? 411 : 413);
|
|
222
|
+
const req = (await request.json().catch(() => null)) as SendRequest | null;
|
|
223
|
+
if (!req || typeof req !== 'object') return json({ status: 'rejected', retryable: false, reason: 'bad_json' }, 400);
|
|
224
|
+
// 白名單有設但讀不懂(JSON 寫壞)=設定錯誤,整個入口先不收;不能當成「沒設」放行。
|
|
225
|
+
const fromTable = jsonVar<Record<string, string[]>>(env.HTTP_FROM);
|
|
226
|
+
if (env.HTTP_FROM !== undefined && env.HTTP_FROM !== '' && (!fromTable || typeof fromTable !== 'object' || Array.isArray(fromTable))) {
|
|
227
|
+
console.error('HTTP_FROM unreadable, refusing http sends');
|
|
228
|
+
return json({ status: 'failed', retryable: true, reason: 'config_error' }, 500);
|
|
229
|
+
}
|
|
230
|
+
const allowed = fromTable?.[site];
|
|
231
|
+
if (allowed) {
|
|
232
|
+
const from = parseAddress(String(req.from ?? ''));
|
|
233
|
+
if (!from || !allowed.map((a) => a.toLowerCase()).includes(from.addr)) return json({ status: 'rejected', retryable: false, reason: 'from_not_allowed' }, 400);
|
|
234
|
+
} else {
|
|
235
|
+
console.warn('http client without HTTP_FROM allowlist', site);
|
|
236
|
+
}
|
|
237
|
+
const result = await send(deps(env), { ...req, site });
|
|
238
|
+
return json(result, result.status === 'rejected' ? 400 : result.status === 'failed' ? 502 : 200);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const postPaths = ['/v1/drill', '/v1/unsuppress'];
|
|
242
|
+
const tokenPaths = [...postPaths, '/v1/lookup', '/v1/report'];
|
|
243
|
+
if (tokenPaths.includes(url.pathname) && (request.method === 'POST') === postPaths.includes(url.pathname)) {
|
|
244
|
+
if (!sameToken(bearer(request), env.DRILL_TOKEN ?? '')) return notFound();
|
|
245
|
+
// 管理入口也有速度上限(站名用 _admin,不會跟真站撞:站名規則不准底線開頭)。
|
|
246
|
+
const adminOver = await takeRate(env.DB, '_admin', ADMIN_LIMITS);
|
|
247
|
+
if (adminOver) return new Response('rate limited', { status: 429, headers: { 'retry-after': adminOver === 'day' ? '3600' : '60' } });
|
|
248
|
+
if (Math.random() < 0.05) await pruneRate(env.DB).catch((e) => console.error('prune rate failed', e instanceof Error ? e.message : 'unknown'));
|
|
249
|
+
if (url.pathname === '/v1/unsuppress') {
|
|
250
|
+
const body = (await request.json().catch(() => null)) as { email?: unknown; reasons?: unknown } | null;
|
|
251
|
+
const email = typeof body?.email === 'string' ? body.email.trim() : '';
|
|
252
|
+
const reasons = Array.isArray(body?.reasons) ? body.reasons : [];
|
|
253
|
+
if (!/^[^\s@]+@[^\s@]+$/.test(email) || email.length > 320) return json({ ok: false, reason: 'bad_email' }, 400);
|
|
254
|
+
if (!reasons.length || !reasons.every((r) => SUPPRESSION_REASONS.includes(r as SuppressionReason))) return json({ ok: false, reason: 'bad_reasons' }, 400);
|
|
255
|
+
const removed = await removeSuppression(env.DB, email, [...new Set(reasons as SuppressionReason[])]);
|
|
256
|
+
console.log('manual unsuppress', removed.join(',') || 'none');
|
|
257
|
+
return json({ ok: true, removed });
|
|
258
|
+
}
|
|
259
|
+
if (url.pathname === '/v1/lookup') return json(publicRow(await lookup(env.DB, url.searchParams.get('site') ?? '', url.searchParams.get('key') ?? '')));
|
|
260
|
+
if (url.pathname === '/v1/report') return json(await report(env, Math.min(Math.max(Number(url.searchParams.get('days')) || 7, 1), 90)));
|
|
261
|
+
const body = (await request.json().catch(() => ({}))) as DrillInput & { site?: string };
|
|
262
|
+
const result = await drill(env, body.site || 'drill', { to: String(body.to ?? ''), mode: body.mode, key: body.key, tier: body.tier, only: body.only });
|
|
263
|
+
return json({ ...result, row: publicRow(result.row) }, result.status === 'failed' ? 502 : 200);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (url.pathname === '/' && request.method === 'GET') return new Response('mailroom', { status: 200 });
|
|
267
|
+
return notFound();
|
|
268
|
+
},
|
|
269
|
+
|
|
270
|
+
/** Cloudflare 寄信的事後回報(wrangler.jsonc 的 queues.consumers)。處理失敗的那則讓 Queue 重送。 */
|
|
271
|
+
async queue(batch: MessageBatch<unknown>, env: Env): Promise<void> {
|
|
272
|
+
for (const msg of batch.messages) {
|
|
273
|
+
try {
|
|
274
|
+
const outcome = await handleCfEvent(env.DB, msg.body);
|
|
275
|
+
if (outcome !== 'event:delivered' && outcome !== 'repeat') console.log('cloudflare email event', outcome);
|
|
276
|
+
msg.ack();
|
|
277
|
+
} catch (error) {
|
|
278
|
+
console.error('cloudflare email event failed', error instanceof Error ? error.message : 'unknown');
|
|
279
|
+
msg.retry();
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
},
|
|
283
|
+
|
|
284
|
+
/** 試跑期每日演習(DAILY_DRILL)。 */
|
|
285
|
+
async scheduled(_controller: ScheduledController, env: Env): Promise<void> {
|
|
286
|
+
const out = await dailyDrill(env);
|
|
287
|
+
if (out.length) console.log('daily drill', out.join(','));
|
|
288
|
+
},
|
|
289
|
+
} satisfies ExportedHandler<Env>;
|