@joelincc/mailroom 0.1.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/README.md +54 -8
  2. package/SECURITY.md +1 -1
  3. package/bin/mailroom.mjs +26 -0
  4. package/dist/broadcast/config.js +79 -0
  5. package/dist/broadcast/explain.js +50 -0
  6. package/dist/cli/args.js +29 -0
  7. package/dist/cli/errors.js +37 -0
  8. package/dist/cli/main.js +533 -0
  9. package/dist/compose/clicks.js +29 -0
  10. package/dist/compose/compose.js +275 -0
  11. package/dist/compose/index.js +8 -0
  12. package/dist/compose/markdown.js +1197 -0
  13. package/dist/compose/personalize.js +123 -0
  14. package/dist/compose/preflight.js +251 -0
  15. package/dist/compose/preview.js +41 -0
  16. package/dist/compose/render.js +141 -0
  17. package/dist/compose/template.js +118 -0
  18. package/docs/broadcast.md +199 -0
  19. package/docs/composing.md +156 -0
  20. package/docs/desk-commands.md +52 -0
  21. package/docs/export.md +52 -0
  22. package/docs/lists.md +68 -0
  23. package/docs/security-model.md +6 -4
  24. package/docs/ses.md +116 -0
  25. package/docs/tracking.md +102 -0
  26. package/docs/unsubscribe.md +124 -0
  27. package/docs/welcome.md +72 -0
  28. package/migrations/0004_last_error.sql +2 -0
  29. package/migrations/0005_lists.sql +41 -0
  30. package/migrations/0006_broadcast.sql +154 -0
  31. package/migrations/0007_unsubscribe.sql +12 -0
  32. package/migrations/0008_tracking.sql +5 -0
  33. package/migrations/0009_welcome.sql +17 -0
  34. package/package.json +21 -3
  35. package/src/alert.ts +123 -0
  36. package/src/aws-sigv4.ts +100 -0
  37. package/src/broadcast/audience.ts +96 -0
  38. package/src/broadcast/campaigns.ts +352 -0
  39. package/src/broadcast/config.ts +136 -0
  40. package/src/broadcast/dispatch.ts +779 -0
  41. package/src/broadcast/events.ts +110 -0
  42. package/src/broadcast/explain.ts +73 -0
  43. package/src/broadcast/freeze.ts +93 -0
  44. package/src/broadcast/index.ts +21 -0
  45. package/src/broadcast/postman.ts +229 -0
  46. package/src/broadcast/reconcile.ts +120 -0
  47. package/src/broadcast/routes.ts +181 -0
  48. package/src/broadcast/ses.ts +181 -0
  49. package/src/broadcast/stats.ts +59 -0
  50. package/src/broadcast/status.ts +60 -0
  51. package/src/broadcast/test-send.ts +88 -0
  52. package/src/broadcast/warmup.ts +150 -0
  53. package/src/broadcast/worker.ts +218 -0
  54. package/src/cf-events.ts +4 -3
  55. package/src/cli/args.ts +27 -0
  56. package/src/cli/errors.ts +39 -0
  57. package/src/cli/main.ts +515 -0
  58. package/src/compose/clicks.ts +45 -0
  59. package/src/compose/compose.ts +297 -0
  60. package/src/compose/index.ts +8 -0
  61. package/src/compose/markdown.ts +1173 -0
  62. package/src/compose/personalize.ts +130 -0
  63. package/src/compose/preflight.ts +250 -0
  64. package/src/compose/preview.ts +58 -0
  65. package/src/compose/render.ts +158 -0
  66. package/src/compose/template.ts +197 -0
  67. package/src/core.ts +45 -2
  68. package/src/export.ts +184 -0
  69. package/src/feedback.ts +128 -0
  70. package/src/http.ts +17 -0
  71. package/src/index.ts +146 -32
  72. package/src/list-routes.ts +55 -0
  73. package/src/lists.ts +381 -0
  74. package/src/ses-events.ts +426 -0
  75. package/src/track.ts +409 -0
  76. package/src/unsub-wiring.ts +64 -0
  77. package/src/unsub.ts +499 -0
  78. package/src/webhook.ts +5 -3
  79. package/src/welcome.ts +257 -0
  80. package/wrangler.example.jsonc +16 -2
package/src/welcome.ts ADDED
@@ -0,0 +1,257 @@
1
+ // 歡迎信:讀者「第一次」加入某份名單時,郵務室寄一封歡迎信。走電子報那一路(電子報郵差、電子報寄件網域、退訂兩個標頭、帳本)。
2
+ //
3
+ // 什麼時候會寄(全部都要成立):
4
+ // 1. 群發總開關開著(MARKETING_DOMAIN+NEWSLETTER_POSTMAN+BROADCAST Queue 都有,郵差設得起來)。關著=一封都不寄,也不排。
5
+ // 2. 這份名單有歡迎信、而且明確打開(welcome_mails.enabled = 1)。預設關。
6
+ // 3. 這次加入是讀者本人的加入動作(listSubscribe),而且他以前從來不是這份名單的成員(firstTime)。
7
+ // 退訂後再訂回、搬家匯入、分群寫入都不寄。
8
+ // 4. 寄的當下他還訂閱中、不在拒收名單、寄件網域沒有停寄、郵差健康、今天額度還有。
9
+ // 5. 帳本去重鍵 welcome:{名單}:{聯絡人} 沒寄過(同一人最多一封,兩個加入同時進來也只寄一封)。
10
+ //
11
+ // 內容是設定:在 Worker 外面用 compose 產好(品牌樣板在自己的設定裡),用管理入口存進 welcome_mails。引擎只附範例(docs/welcome.md)。
12
+
13
+ import { parseAddress, suppressedReason, type Db } from './core.ts';
14
+ import { scanPlaceholders, personalize } from './compose/personalize.ts';
15
+ import { unsubscribeLinks } from './unsub.ts';
16
+ import type { Postman, PostmanOutcome } from './broadcast/postman.ts';
17
+ import { localDay } from './core.ts';
18
+ import { subscribeMember, type ListDb, type SubscribeInput, type SubscribeResult } from './lists.ts';
19
+
20
+ export interface WelcomeInput {
21
+ subject: string;
22
+ from: string;
23
+ replyTo?: string;
24
+ html: string;
25
+ text: string;
26
+ /** {{web_url}} 的值(https),例如電子報的過刊頁。 */
27
+ webUrl: string;
28
+ /** 一定要明講:true=開始對新訂閱者寄、false=存著但不寄。 */
29
+ enabled: boolean;
30
+ }
31
+
32
+ export interface WelcomeRow {
33
+ list_id: string; subject: string; from_addr: string; reply_to: string | null; html: string; text: string;
34
+ web_url: string; content_hash: string; enabled: number; updated_at: string;
35
+ }
36
+
37
+ export type WelcomeMessage = { kind: 'welcome'; list: string; contact: number; queuedAt: string };
38
+
39
+ const LIST_ID = /^[a-z0-9][a-z0-9-]{0,39}$/;
40
+ const ctl = (s: string) => /[\u0000-\u001f\u007f]/.test(s);
41
+ /** 寄的當下暫時寄不了(網域停寄、郵差不健康、額度用完)最多等多久,過了就放棄(不補寄很舊的歡迎信)。 */
42
+ export const WELCOME_MAX_AGE_MS = 48 * 3600_000;
43
+ /** 暫時寄不了時多久後再試。 */
44
+ export const WELCOME_RETRY_SECONDS = 900;
45
+
46
+ async function sha256(s: string): Promise<string> {
47
+ const d = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(s));
48
+ return [...new Uint8Array(d)].map((b) => b.toString(16).padStart(2, '0')).join('');
49
+ }
50
+
51
+ /** 檢查歡迎信內容。回錯誤代碼或 null。 */
52
+ export function checkWelcome(input: WelcomeInput, marketingDomain: string): string | null {
53
+ if (!input || typeof input !== 'object') return 'bad_request';
54
+ if (typeof input.enabled !== 'boolean') return 'enabled_required';
55
+ if (typeof input.subject !== 'string' || !input.subject.trim() || Array.from(input.subject).length > 80 || ctl(input.subject)) return 'bad_subject';
56
+ const from = parseAddress(String(input.from ?? ''));
57
+ if (!from || !marketingDomain || !from.addr.endsWith(`@${marketingDomain.toLowerCase()}`)) return 'bad_from';
58
+ if (input.replyTo !== undefined && !parseAddress(input.replyTo)) return 'bad_reply_to';
59
+ if (typeof input.html !== 'string' || !input.html || input.html.length > 200_000) return 'bad_html';
60
+ if (typeof input.text !== 'string' || !input.text || input.text.length > 100_000) return 'bad_text';
61
+ if (typeof input.webUrl !== 'string' || input.webUrl.length > 2000 || !/^https:\/\/[^\s<>"]+$/i.test(input.webUrl)) return 'bad_web_url';
62
+ for (const s of [input.html, input.text]) {
63
+ const p = scanPlaceholders(s);
64
+ if (p.unknown.length || p.unbalanced.length) return 'unknown_placeholder';
65
+ // 歡迎信不追蹤(沒有期別的連結表):compose 時不要給 trackBase。
66
+ if (p.used.has('c') || p.used.has('o')) return 'tracking_not_supported';
67
+ if (!p.used.has('unsubscribe_url')) return 'unsubscribe_link_missing';
68
+ if (p.used.has('unsubscribe_mailto')) return 'unknown_placeholder';
69
+ }
70
+ return null;
71
+ }
72
+
73
+ /** 存(或改)一份名單的歡迎信。enabled 每次都要明講。 */
74
+ export async function saveWelcome(db: Db, list: string, input: WelcomeInput, opts: { marketingDomain: string; now?: () => Date }): Promise<{ ok: true; enabled: boolean; changed: boolean } | { ok: false; reason: string }> {
75
+ if (typeof list !== 'string' || !LIST_ID.test(list)) return { ok: false, reason: 'bad_list' };
76
+ const bad = checkWelcome(input, opts.marketingDomain);
77
+ if (bad) return { ok: false, reason: bad };
78
+ if (!(await db.prepare('SELECT id FROM lists WHERE id = ?').bind(list).first())) return { ok: false, reason: 'unknown_list' };
79
+ const hash = await sha256(JSON.stringify([input.subject, input.from, input.replyTo ?? '', input.html, input.text, input.webUrl]));
80
+ const before = await db.prepare('SELECT content_hash, enabled FROM welcome_mails WHERE list_id = ?').bind(list).first<{ content_hash: string; enabled: number }>();
81
+ const t = (opts.now ?? (() => new Date()))().toISOString();
82
+ await db
83
+ .prepare(
84
+ `INSERT INTO welcome_mails (list_id, subject, from_addr, reply_to, html, text, web_url, content_hash, enabled, updated_at)
85
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
86
+ ON CONFLICT (list_id) DO UPDATE SET subject = excluded.subject, from_addr = excluded.from_addr, reply_to = excluded.reply_to, html = excluded.html,
87
+ text = excluded.text, web_url = excluded.web_url, content_hash = excluded.content_hash, enabled = excluded.enabled, updated_at = excluded.updated_at`,
88
+ )
89
+ .bind(list, input.subject, input.from, input.replyTo ?? null, input.html, input.text, input.webUrl, hash, input.enabled ? 1 : 0, t)
90
+ .run();
91
+ return { ok: true, enabled: input.enabled, changed: !before || before.content_hash !== hash || Boolean(before.enabled) !== input.enabled };
92
+ }
93
+
94
+ export async function getWelcome(db: Db, list: string): Promise<WelcomeRow | null> {
95
+ if (typeof list !== 'string' || !LIST_ID.test(list)) return null;
96
+ return db.prepare('SELECT * FROM welcome_mails WHERE list_id = ?').bind(list).first<WelcomeRow>();
97
+ }
98
+
99
+ // ---------- 排信(加入時)----------
100
+
101
+ export interface WelcomeQueue { send(body: WelcomeMessage, opts?: { delaySeconds?: number }): Promise<unknown> }
102
+
103
+ /**
104
+ * 加入成功、而且是第一次加入時呼叫。只排進 Queue(不在讀者的加入請求裡寄信);任何失敗都只記 log,不影響加入結果。
105
+ * @param enabled 群發總開關(呼叫端判斷);false=什麼都不做。
106
+ */
107
+ export async function queueWelcome(db: Db, queue: WelcomeQueue | undefined, enabled: boolean, list: string, contact: number, now = new Date()): Promise<'queued' | 'off' | 'no_welcome' | 'error'> {
108
+ if (!enabled || !queue) return 'off';
109
+ try {
110
+ const w = await db.prepare('SELECT enabled FROM welcome_mails WHERE list_id = ?').bind(list).first<{ enabled: number }>();
111
+ if (!w || !w.enabled) return 'no_welcome';
112
+ await queue.send({ kind: 'welcome', list, contact, queuedAt: now.toISOString() }, { delaySeconds: 5 });
113
+ return 'queued';
114
+ } catch (e) {
115
+ console.error('welcome queue failed', e instanceof Error ? e.message.slice(0, 200) : 'unknown');
116
+ return 'error';
117
+ }
118
+ }
119
+
120
+ /**
121
+ * 內線 listSubscribe 的實作:加入名單;第一次加入時照上面的條件排歡迎信。回給呼叫端的只有加入結果(不含聯絡人編號)。
122
+ * @param switchOn 群發總開關(呼叫端判斷)。
123
+ */
124
+ export async function subscribeWithWelcome(db: ListDb, input: SubscribeInput, opts: { queue?: WelcomeQueue; switchOn: boolean; now?: () => Date }): Promise<SubscribeResult> {
125
+ const r = await subscribeMember(db, input, opts.now);
126
+ if (r.status !== 'subscribed') return r;
127
+ if ('contactId' in r && r.firstTime) {
128
+ const outcome = await queueWelcome(db as unknown as Db, opts.queue, opts.switchOn, input.list, r.contactId, (opts.now ?? (() => new Date()))());
129
+ if (outcome === 'error') console.warn('welcome not queued', input.list);
130
+ }
131
+ return { status: 'subscribed', firstTime: r.firstTime };
132
+ }
133
+
134
+ // ---------- 寄信(Queue 消化時)----------
135
+
136
+ export interface WelcomeDeps {
137
+ db: ListDb;
138
+ postman: Postman;
139
+ /** 電子報寄件網域(小寫)。 */
140
+ domain: string;
141
+ /** 帳本站名(群發設定的 site)。 */
142
+ site: string;
143
+ utcOffsetHours: number;
144
+ unsub: { secrets: readonly string[]; baseUrl?: string; mailto?: string };
145
+ now?: () => Date;
146
+ }
147
+
148
+ export type WelcomeResult = { action: 'ack'; outcome: string } | { action: 'retry'; delaySeconds: number; outcome: string };
149
+ const ack = (outcome: string): WelcomeResult => ({ action: 'ack', outcome });
150
+
151
+ function fmt(a: { name: string | null; addr: string }): string {
152
+ return a.name ? `${a.name} <${a.addr}>` : a.addr;
153
+ }
154
+
155
+ /**
156
+ * 名字是加入的人自己填的;歡迎信是加入一發生就寄出的自動信,名字欄可以被拿來夾帶網址或網域(「請到 evil.example 領獎」)。
157
+ * 名字只收允許清單裡的字元(見下);其他一律當作沒有名字(整段問候拿掉)。
158
+ */
159
+ export function safeName(name: string | null): string | null {
160
+ if (typeof name !== 'string') return null;
161
+ // 允許清單(先 NFKC,全形句點等會變成「.」):字母、組合記號、空白、撇號、連字號;句點只准跟在單一字母後面(縮寫 J. R.)。最多 40 字。
162
+ const n = name.normalize('NFKC').trim();
163
+ if (!n || Array.from(n).length > 40) return null;
164
+ if (!/^[\p{L}\p{M}\s'\u2019.-]+$/u.test(n)) return null;
165
+ if (/(?:^|[^\p{L}])\.|\p{L}{2}\.|\.(?!\s|$)/u.test(n)) return null;
166
+ return n;
167
+ }
168
+
169
+ export async function consumeWelcome(deps: WelcomeDeps, msg: WelcomeMessage): Promise<WelcomeResult> {
170
+ const { db } = deps;
171
+ const now = (deps.now ?? (() => new Date()))();
172
+ if (!msg || typeof msg.list !== 'string' || !LIST_ID.test(msg.list) || !Number.isInteger(msg.contact) || msg.contact < 1) return ack('welcome_bad_message');
173
+ const queuedAt = Date.parse(String(msg.queuedAt));
174
+ const tooOld = Number.isNaN(queuedAt) || now.getTime() - queuedAt > WELCOME_MAX_AGE_MS;
175
+ const later = (outcome: string): WelcomeResult => (tooOld ? ack(`welcome_expired:${outcome}`) : { action: 'retry', delaySeconds: WELCOME_RETRY_SECONDS, outcome });
176
+
177
+ const w = await getWelcome(db as unknown as Db, msg.list);
178
+ if (!w || !w.enabled) return ack('welcome_disabled');
179
+ const member = await db
180
+ .prepare('SELECT m.status AS status, c.email AS email, c.name AS name FROM list_members m JOIN contacts c ON c.id = m.contact_id WHERE m.list_id = ? AND m.contact_id = ?')
181
+ .bind(msg.list, msg.contact)
182
+ .first<{ status: string; email: string; name: string | null }>();
183
+ if (!member || member.status !== 'subscribed') return ack('welcome_not_subscribed');
184
+ if (await suppressedReason(db as unknown as Db, member.email, 'marketing')) return ack('welcome_suppressed');
185
+ const key = `welcome:${msg.list}:${msg.contact}`;
186
+ const done = await db.prepare("SELECT status FROM messages WHERE site = ? AND dedupe_key = ?").bind(deps.site, key).first<{ status: string }>();
187
+ if (done && done.status !== 'failed') return ack(done.status === 'sent' ? 'welcome_duplicate' : `welcome_${done.status}`);
188
+ const hold = await db.prepare('SELECT id FROM domain_holds WHERE domain = ? AND released_at IS NULL LIMIT 1').bind(deps.domain).first();
189
+ if (hold) return later('welcome_domain_hold');
190
+ const day = localDay(now, deps.utcOffsetHours);
191
+ const health = await db.prepare('SELECT enforcement FROM throttle_days WHERE domain = ? AND day = ?').bind(deps.domain, day).first<{ enforcement: string | null }>();
192
+ if (health?.enforcement && health.enforcement !== 'HEALTHY' && health.enforcement !== 'UNKNOWN') return later('welcome_provider_unhealthy');
193
+
194
+ const from = parseAddress(w.from_addr);
195
+ if (!from || !from.addr.endsWith(`@${deps.domain}`)) return ack('welcome_bad_from');
196
+ const replyTo = w.reply_to ? parseAddress(w.reply_to) : null;
197
+
198
+ // 內容先組好(缺退訂設定就不寄:沒有退訂連結的信一封都不出去)。
199
+ let content: { html: string; text: string; headers: Record<string, string> };
200
+ try {
201
+ if (!deps.unsub.secrets.length || !deps.unsub.baseUrl) throw new Error('unsubscribe not configured');
202
+ const links = await unsubscribeLinks(deps.unsub.secrets, { baseUrl: deps.unsub.baseUrl, mailtoAddress: deps.unsub.mailto }, { list: msg.list, contactId: msg.contact, campaign: null });
203
+ content = personalize(
204
+ { html: w.html, text: w.text, headers: { ...links.headers } },
205
+ { name: safeName(member.name), email: member.email, web_url: w.web_url, unsubscribe_url: links.url },
206
+ );
207
+ } catch (e) {
208
+ console.error('welcome render failed', e instanceof Error ? e.message.slice(0, 200) : 'unknown');
209
+ return ack('welcome_render_error');
210
+ }
211
+
212
+ // 今天的額度:跟群發共用同一個寄件網域的每日上限(先佔一格,沒寄出再還)。今天的列還沒建=群發今天還沒讀過郵差上限,晚點再試。
213
+ const reserved = await db.prepare('UPDATE throttle_days SET sent = sent + 1 WHERE domain = ? AND day = ? AND sent < "limit" RETURNING sent').bind(deps.domain, day).first<{ sent: number }>();
214
+ if (!reserved) return later('welcome_no_quota');
215
+ const refund = () => db.prepare('UPDATE throttle_days SET sent = MAX(sent - 1, 0) WHERE domain = ? AND day = ?').bind(deps.domain, day).run();
216
+
217
+ const iso = now.toISOString();
218
+ const claimed = await db
219
+ .prepare(
220
+ `INSERT INTO messages (stream, tier, site, dedupe_key, kind, to_email, from_addr, subject, status, attempts, created_at, updated_at)
221
+ VALUES ('marketing', 'marketing', ?, ?, 'welcome', ?, ?, ?, 'sending', 1, ?, ?)
222
+ ON CONFLICT (site, dedupe_key) DO UPDATE SET status = 'sending', last_error = COALESCE(messages.error, messages.last_error), error = NULL,
223
+ attempts = messages.attempts + 1, updated_at = excluded.updated_at
224
+ WHERE messages.status = 'failed'
225
+ RETURNING id, attempts`,
226
+ )
227
+ .bind(deps.site, key, member.email, fmt(from), w.subject, iso, iso)
228
+ .first<{ id: number; attempts: number }>();
229
+ if (!claimed) {
230
+ await refund();
231
+ return ack('welcome_duplicate');
232
+ }
233
+ let out: PostmanOutcome;
234
+ try {
235
+ out = await deps.postman.send({
236
+ from: fmt(from), to: member.email, subject: w.subject, html: content.html, text: content.text,
237
+ ...(replyTo ? { replyTo: fmt(replyTo) } : {}),
238
+ headers: content.headers,
239
+ tags: { campaign: `_welcome-${msg.list}`, contact: String(msg.contact) },
240
+ idempotencyKey: `${deps.site}/${key}`,
241
+ });
242
+ } catch (e) {
243
+ // 不知道寄出沒有:帳本列留在 sending,不再自動重寄(寧可少一封也不寄兩封)。
244
+ console.error('welcome postman threw', e instanceof Error ? e.message.slice(0, 200) : 'unknown');
245
+ return ack('welcome_uncertain');
246
+ }
247
+ const t = (deps.now ?? (() => new Date()))().toISOString();
248
+ if (out.ok) {
249
+ await db.prepare("UPDATE messages SET status = 'sent', route = ?, provider_id = ?, updated_at = ?, sent_at = ? WHERE id = ?").bind(deps.postman.name, out.providerId, t, t, claimed.id).run();
250
+ return ack('welcome_sent');
251
+ }
252
+ await refund();
253
+ await db.prepare("UPDATE messages SET status = 'failed', route = ?, error = ?, updated_at = ? WHERE id = ?").bind(deps.postman.name, `${deps.postman.name} ${out.kind} ${out.error}`.slice(0, 200), t, claimed.id).run();
254
+ if (out.kind === 'permanent' || claimed.attempts >= 5) return ack(`welcome_failed_${out.kind}`);
255
+ return later(`welcome_${out.kind}`);
256
+ }
257
+
@@ -29,14 +29,28 @@
29
29
  // Missing or invalid -> default; an explicit 0 means unlimited.
30
30
  "HTTP_RATE_PER_MIN": 60,
31
31
  "HTTP_DAILY_LIMIT": 2000
32
- // Per-client sender allowlist for the public HTTP endpoint (strongly recommended):
33
- // "HTTP_FROM": { "shop": ["orders@notify.example.com"] }
32
+ // Per-client sender allowlist for the public HTTP endpoint (REQUIRED for every client in HTTP_CLIENTS; a client without an entry is refused):
33
+ // "HTTP_FROM": { "shop": ["orders@notify.example.com"] },
34
+ // Delete ledger rows older than this many days (needs the cron trigger below). Unset = never delete automatically.
35
+ // "LEDGER_RETENTION_DAYS": 180
34
36
  },
35
37
  // Only needed if you send through Cloudflare Email Sending. List every allowed sender address.
36
38
  // "send_email": [{ "name": "EMAIL", "remote": true, "allowed_sender_addresses": ["app@remind.example.com"] }],
37
39
  // Delivery / bounce / complaint events from Cloudflare Email Sending (only if you use it).
38
40
  // "queues": { "consumers": [{ "queue": "mailroom-email-events", "max_batch_size": 50, "max_batch_timeout": 30, "max_retries": 5 }] },
41
+ // Newsletter broadcasting (preview, see docs/broadcast.md). Off unless MARKETING_DOMAIN, NEWSLETTER_POSTMAN and the BROADCAST queue are all set.
42
+ // Add to "vars": "MARKETING_DOMAIN": "mail.example.com", "NEWSLETTER_POSTMAN": "fake", "NEWSLETTER_MAX_PER_DAY": 3000
43
+ // Amazon SES instead of the fake postman (docs/ses.md): "NEWSLETTER_POSTMAN": "ses", "SES_REGION": "us-east-1",
44
+ // "SES_CONFIGURATION_SET": "newsletter-events", "SES_SNS_TOPIC_ARNS": "arn:aws:sns:us-east-1:123456789012:newsletter-events"
45
+ // and Secrets SES_ACCESS_KEY_ID, SES_SECRET_ACCESS_KEY.
46
+ // "queues": {
47
+ // "producers": [{ "binding": "BROADCAST", "queue": "mailroom-broadcast" }],
48
+ // "consumers": [{ "queue": "mailroom-broadcast", "max_batch_size": 10, "max_concurrency": 1, "max_retries": 10, "dead_letter_queue": "mailroom-broadcast-dlq" }]
49
+ // },
50
+ // and a cron that runs every minute: "triggers": { "crons": ["* * * * *"] }
39
51
  // Secrets (always add as Secret, never as a plain variable):
40
52
  // RESEND_API_KEY, SMTP2GO_API_KEY, RESEND_WEBHOOK_SECRET, DRILL_TOKEN, HTTP_KEY_*, RESEND_API_KEY_REMIND (optional)
53
+ // Needed for LEDGER_RETENTION_DAYS and DAILY_DRILL: the Worker's scheduled handler runs on this trigger.
54
+ // "triggers": { "crons": ["17 3 * * *"] },
41
55
  "observability": { "enabled": true }
42
56
  }