@anthusai/papyrus 2.0.0-next.6 → 2.0.0-next.61

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 (164) hide show
  1. package/amplify/data/resource.js +23 -3
  2. package/amplify/data/resource.ts +25 -3
  3. package/amplify/data/schema.js +2028 -1979
  4. package/amplify/data/schema.ts +72 -14
  5. package/amplify/functions/assignment-action/data-access.js +90 -0
  6. package/amplify/functions/assignment-action/data-access.ts +89 -0
  7. package/amplify/functions/assignment-action/handler.ts +1 -1
  8. package/amplify/functions/content-actions/handler.py +61 -2
  9. package/amplify/functions/content-actions/requirements.txt +1 -0
  10. package/amplify/functions/content-actions/resource.js +1 -1
  11. package/amplify/functions/content-actions/resource.ts +1 -1
  12. package/amplify/functions/editorial-checks/handler.py +14 -0
  13. package/amplify/functions/editorial-checks/requirements.txt +1 -0
  14. package/amplify/{plugins/editorial-checks/function → functions/editorial-checks}/resource.js +7 -7
  15. package/amplify/{plugins/editorial-checks/function → functions/editorial-checks}/resource.ts +7 -7
  16. package/amplify/functions/editorial-checks/schema.js +121 -0
  17. package/amplify/{plugins → functions}/editorial-checks/schema.ts +33 -6
  18. package/amplify/functions/editorial-checks/wire.js +53 -0
  19. package/amplify/functions/editorial-checks/wire.ts +61 -0
  20. package/amplify/functions/monitoring-view/handler.py +11 -0
  21. package/amplify/functions/monitoring-view/resource.js +24 -0
  22. package/amplify/functions/monitoring-view/resource.ts +34 -0
  23. package/amplify/functions/monitoring-view/schema.js +16 -0
  24. package/amplify/functions/monitoring-view/schema.ts +18 -0
  25. package/amplify/functions/monitoring-view/wire.js +37 -0
  26. package/amplify/functions/monitoring-view/wire.ts +47 -0
  27. package/amplify/functions/public-forms/core.js +247 -0
  28. package/amplify/functions/public-forms/core.ts +310 -0
  29. package/amplify/functions/public-forms/handler.ts +41 -0
  30. package/amplify/functions/public-forms/origins.js +35 -0
  31. package/amplify/functions/public-forms/origins.ts +43 -0
  32. package/amplify/functions/public-forms/resource.js +9 -0
  33. package/amplify/functions/public-forms/resource.ts +10 -0
  34. package/amplify/functions/public-forms/wire.js +25 -0
  35. package/amplify/functions/public-forms/wire.ts +32 -0
  36. package/amplify/functions/shared/editorial-context.ts +63 -4
  37. package/amplify/functions/shared/python-bundle.js +20 -14
  38. package/amplify/functions/shared/python-bundle.ts +25 -18
  39. package/amplify/plugins/newsletter/config.js +245 -0
  40. package/amplify/plugins/newsletter/config.ts +305 -0
  41. package/amplify/plugins/newsletter/function/handler.py +6 -0
  42. package/amplify/plugins/newsletter/function/requirements.txt +5 -0
  43. package/amplify/plugins/newsletter/ops/handler.py +12 -0
  44. package/amplify/plugins/newsletter/ops/resource.js +27 -0
  45. package/amplify/plugins/newsletter/ops/resource.ts +37 -0
  46. package/amplify/plugins/newsletter/papyrus.plugin.js +263 -0
  47. package/amplify/plugins/newsletter/papyrus.plugin.ts +311 -0
  48. package/amplify/plugins/newsletter/schema.js +56 -0
  49. package/amplify/plugins/newsletter/schema.ts +61 -0
  50. package/amplify/plugins/newsletter/secure-string-parameter.js +107 -0
  51. package/amplify/plugins/newsletter/secure-string-parameter.ts +120 -0
  52. package/amplify/plugins/newsletter/sending.js +140 -0
  53. package/amplify/plugins/newsletter/sending.ts +186 -0
  54. package/amplify/plugins/reader-steering/config.js +173 -0
  55. package/amplify/plugins/reader-steering/config.ts +268 -0
  56. package/amplify/plugins/reader-steering/function/ai_moderation.py +246 -0
  57. package/amplify/plugins/reader-steering/function/handler.py +1363 -0
  58. package/amplify/plugins/reader-steering/function/moderation-prompt.md +27 -0
  59. package/amplify/plugins/reader-steering/function/moderation.py +316 -0
  60. package/amplify/plugins/reader-steering/function/resource.js +27 -0
  61. package/amplify/plugins/reader-steering/function/resource.ts +35 -0
  62. package/amplify/plugins/reader-steering/papyrus.plugin.js +176 -0
  63. package/amplify/plugins/reader-steering/papyrus.plugin.ts +202 -0
  64. package/amplify/plugins/reader-steering/schema.js +140 -0
  65. package/amplify/plugins/reader-steering/schema.ts +142 -0
  66. package/amplify/plugins/registry.js +4 -2
  67. package/amplify/plugins/registry.ts +4 -2
  68. package/amplify/plugins/types.ts +5 -0
  69. package/amplify/plugins/wire.js +1 -0
  70. package/amplify/plugins/wire.ts +1 -0
  71. package/amplify/publication/projection-lease.js +30 -0
  72. package/amplify/publication/projection-lease.ts +39 -0
  73. package/amplify/publication/redirect-and-index.js +105 -0
  74. package/amplify/publication/redirect-rules.js +73 -0
  75. package/amplify/publication/redirect-rules.ts +93 -0
  76. package/amplify/publication/s3-projection.js +7 -1
  77. package/amplify/publication/s3-projection.ts +9 -1
  78. package/amplify/site-backend-config.ts +17 -0
  79. package/amplify/site-backend.js +38 -1
  80. package/amplify/site-backend.ts +46 -1
  81. package/app/api/auth/prospectus/sign-in/route.ts +4 -0
  82. package/app/api/newsletter/confirm/route.ts +13 -0
  83. package/app/api/newsletter/preferences/route.ts +13 -0
  84. package/app/api/newsletter/state/route.ts +9 -0
  85. package/app/api/newsletter/subscribe/route.ts +9 -0
  86. package/app/api/newsletter/unsubscribe/route.ts +13 -0
  87. package/app/api/newsroom/curation/context/route.ts +9 -0
  88. package/app/api/newsroom/curation/priming/route.ts +9 -0
  89. package/app/api/newsroom/curation/publication/route.ts +9 -0
  90. package/app/api/reader/comment/delete/route.ts +9 -0
  91. package/app/api/reader/comment/edit/route.ts +9 -0
  92. package/app/api/reader/comment/route.ts +9 -0
  93. package/app/api/reader/handle/route.ts +9 -0
  94. package/app/api/reader/me/route.ts +9 -0
  95. package/app/api/reader/rating/route.ts +9 -0
  96. package/app/api/reader/report/route.ts +9 -0
  97. package/app/api/reader/retired/route.ts +9 -0
  98. package/app/api/reader/submit/route.ts +9 -0
  99. package/app/api/reader/vote/route.ts +9 -0
  100. package/bin/papyrus-infra.mjs +20 -1
  101. package/components/editorial-checks-admin-panel.tsx +36 -11
  102. package/components/moderation-panel.tsx +248 -0
  103. package/components/monitoring-overview-view.tsx +241 -0
  104. package/components/monitoring-panel.tsx +40 -0
  105. package/components/newsletter-panel.tsx +474 -0
  106. package/components/newsletter-sections.tsx +163 -0
  107. package/components/newsroom-article-editor.tsx +2 -4
  108. package/components/newsroom-curation-bootstrap.tsx +45 -0
  109. package/components/newsroom-organizer.css +31 -0
  110. package/components/newsroom-references-view.tsx +14 -14
  111. package/components/publication-cyclotron-panel.tsx +15 -10
  112. package/components/reference-add-entry.tsx +75 -0
  113. package/components/reference-curation-controls.tsx +31 -22
  114. package/components/reference-cyclotron-priming.tsx +58 -19
  115. package/components/reference-cyclotron-suggestion.tsx +1 -1
  116. package/components/reference-priming.tsx +14 -10
  117. package/components/reference-section-suggestion.tsx +1 -1
  118. package/components/topic-steering-workspace.tsx +64 -20
  119. package/components/use-editorial-checks.ts +12 -10
  120. package/infra/amplify-app-shell.js +90 -16
  121. package/infra/amplify-app-shell.ts +102 -18
  122. package/infra/index.js +1 -0
  123. package/infra/secure-string-parameter-handler.js +41 -0
  124. package/infra/secure-string-parameter-handler.ts +41 -0
  125. package/infra/secure-string-parameter.js +79 -0
  126. package/infra/secure-string-parameter.ts +91 -0
  127. package/infra/site-config.js +86 -6
  128. package/infra/site-config.ts +129 -6
  129. package/lib/category-repository.ts +11 -9
  130. package/lib/curation-routes.ts +345 -0
  131. package/lib/editorial-checks-backend.ts +1 -1
  132. package/lib/editorial-checks-client.ts +19 -1
  133. package/lib/editorial-checks-demo.ts +2 -2
  134. package/lib/editorial-checks-settings.ts +3 -0
  135. package/lib/editorial-checks.ts +8 -11
  136. package/lib/editorial-preview.ts +5 -5
  137. package/lib/monitoring-client.ts +29 -0
  138. package/lib/monitoring-overview-fixture.ts +51 -0
  139. package/lib/monitoring-overview.ts +145 -0
  140. package/lib/newsletter-api.ts +418 -0
  141. package/lib/newsletter-client.ts +46 -0
  142. package/lib/newsletter-fixture.ts +184 -0
  143. package/lib/newsletter-model.ts +202 -0
  144. package/lib/prospectus-session.ts +15 -14
  145. package/lib/prospectus-sign-in-routes.ts +84 -19
  146. package/lib/prospectus-site-identity.ts +24 -1
  147. package/lib/reader-api.ts +145 -0
  148. package/lib/reader-moderation.ts +220 -0
  149. package/lib/reader-retirement-route.ts +89 -0
  150. package/lib/reader-subject.md +29 -0
  151. package/lib/reader-subject.ts +53 -0
  152. package/lib/relevance-status.ts +2 -2
  153. package/lib/semantic-graph.ts +2 -0
  154. package/lib/site-brand-tenant.ts +11 -6
  155. package/lib/site-brand.ts +6 -3
  156. package/lib/site-origin.ts +67 -0
  157. package/middleware.ts +14 -3
  158. package/package.json +41 -3
  159. package/routes.manifest.json +204 -2
  160. package/amplify/plugins/editorial-checks/function/handler.py +0 -11
  161. package/amplify/plugins/editorial-checks/function/requirements.txt +0 -1
  162. package/amplify/plugins/editorial-checks/papyrus.plugin.js +0 -50
  163. package/amplify/plugins/editorial-checks/papyrus.plugin.ts +0 -63
  164. package/amplify/plugins/editorial-checks/schema.js +0 -94
@@ -0,0 +1,474 @@
1
+ "use client";
2
+
3
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
4
+ import { callNewsletter, type NewsletterApi } from "../lib/newsletter-client";
5
+ import { createFixtureApi } from "../lib/newsletter-fixture";
6
+ import {
7
+ ISSUE_STATUS_FILTERS,
8
+ canApprove,
9
+ canCancel,
10
+ canStop,
11
+ failureText,
12
+ formatInZone,
13
+ isoToZonedInput,
14
+ nextWholeHourInput,
15
+ statusLabel,
16
+ subscribersToCsv,
17
+ validTimeZone,
18
+ zonedInputToIso,
19
+ type NewsletterDelivery,
20
+ type NewsletterExportRow,
21
+ type NewsletterFailure,
22
+ type NewsletterIssue,
23
+ type NewsletterOverview,
24
+ type NewsletterPreview,
25
+ type NewsletterSubscriber,
26
+ } from "../lib/newsletter-model";
27
+ import { DeliveriesCard, IssueSummary, ListsCard, SiteStatusCard, SubscribersTable } from "./newsletter-sections";
28
+
29
+ type Message = { kind: "ok" | "problem"; text: string } | null;
30
+ type Drawer = { issueId: string; mode: "preview" | "approve" | "stop" | "cancel" } | null;
31
+ type Result<T> = ({ ok: true } & T) | NewsletterFailure;
32
+
33
+ const isFailure = (value: { ok: boolean }): value is NewsletterFailure => value.ok === false;
34
+
35
+ /**
36
+ * Administration, Newsletter: subscriber counts, issues with their actions, delivery history, the pause, and (for admins) the
37
+ * subscriber list, CSV export and erasure. It never subscribes to anything live: it refreshes after each action and on the Refresh button.
38
+ */
39
+ export function NewsletterPanel({ isAdmin, isDemo }: { isAdmin: boolean; isDemo: boolean }) {
40
+ const api: NewsletterApi = useMemo(() => (isDemo ? createFixtureApi({ admin: isAdmin }) : callNewsletter), [isDemo, isAdmin]);
41
+ const live = useRef(true);
42
+ useEffect(() => {
43
+ live.current = true;
44
+ return () => {
45
+ live.current = false;
46
+ };
47
+ }, []);
48
+
49
+ const [overview, setOverview] = useState<NewsletterOverview | null>(null);
50
+ const [issues, setIssues] = useState<NewsletterIssue[] | null>(null);
51
+ const [edited, setEdited] = useState<Record<string, boolean>>({});
52
+ const [problem, setProblem] = useState<string | null>(null);
53
+ const [statusFilter, setStatusFilter] = useState("");
54
+ const [message, setMessage] = useState<Message>(null);
55
+ const [busy, setBusy] = useState<string | null>(null);
56
+ const [drawer, setDrawer] = useState<Drawer>(null);
57
+ const [preview, setPreview] = useState<Result<NewsletterPreview> | null>(null);
58
+ const [approveAt, setApproveAt] = useState("");
59
+ const [deliveriesFor, setDeliveriesFor] = useState<string | null>(null);
60
+ const [deliveries, setDeliveries] = useState<NewsletterDelivery[]>([]);
61
+ const [deliveriesCursor, setDeliveriesCursor] = useState<string | null>(null);
62
+ const [deliveriesLoading, setDeliveriesLoading] = useState(false);
63
+ const [subscribers, setSubscribers] = useState<NewsletterSubscriber[] | null>(null);
64
+ const [subscribersCursor, setSubscribersCursor] = useState<string | null>(null);
65
+ const [listFilter, setListFilter] = useState("");
66
+ const [subscriberStatus, setSubscriberStatus] = useState("");
67
+ const [eraseEmail, setEraseEmail] = useState("");
68
+ const [eraseConfirm, setEraseConfirm] = useState(false);
69
+
70
+ const zone = useMemo(() => {
71
+ const roundup = overview?.lists.find((list) => list.timezone)?.timezone;
72
+ return validTimeZone(roundup) ?? validTimeZone(Intl.DateTimeFormat().resolvedOptions().timeZone) ?? "UTC";
73
+ }, [overview]);
74
+
75
+ const loadOverview = useCallback(async () => {
76
+ const result = (await api("newsletterOverview")) as Result<NewsletterOverview>;
77
+ if (!live.current) return;
78
+ if (isFailure(result)) {
79
+ setProblem(result.error === "forbidden" ? "forbidden" : failureText(result));
80
+ return;
81
+ }
82
+ setProblem(null);
83
+ setOverview(result);
84
+ }, [api]);
85
+
86
+ const loadIssues = useCallback(async () => {
87
+ const result = (await api("newsletterIssues", { limit: 100, ...(statusFilter ? { status: statusFilter } : {}) })) as Result<{ issues: NewsletterIssue[] }>;
88
+ if (!live.current) return;
89
+ if (isFailure(result)) {
90
+ setMessage({ kind: "problem", text: failureText(result) });
91
+ return;
92
+ }
93
+ setIssues(result.issues);
94
+ // The list does not say whether an approved issue was edited; the single-issue read does. Scheduled issues are few.
95
+ const scheduled = result.issues.filter((issue) => issue.status === "scheduled").slice(0, 10);
96
+ const checks = await Promise.all(scheduled.map(async (issue) => [issue.issueId, await api("newsletterIssue", { issueId: issue.issueId })] as const));
97
+ if (!live.current) return;
98
+ setEdited(Object.fromEntries(checks.map(([id, one]) => [id, !isFailure(one as Result<object>) && Boolean((one as { issue?: NewsletterIssue }).issue?.editedSinceApproval)])));
99
+ }, [api, statusFilter]);
100
+
101
+ const loadSubscribers = useCallback(
102
+ async (cursor?: string | null) => {
103
+ if (!isAdmin) return;
104
+ const result = (await api("newsletterSubscribers", {
105
+ ...(listFilter ? { listId: listFilter } : {}),
106
+ ...(subscriberStatus ? { status: subscriberStatus } : {}),
107
+ ...(cursor ? { cursor } : {}),
108
+ })) as Result<{ subscribers: NewsletterSubscriber[]; cursor?: string }>;
109
+ if (!live.current) return;
110
+ if (isFailure(result)) {
111
+ setMessage({ kind: "problem", text: failureText(result) });
112
+ return;
113
+ }
114
+ setSubscribers((current) => (cursor && current ? [...current, ...result.subscribers] : result.subscribers));
115
+ setSubscribersCursor(result.cursor ?? null);
116
+ },
117
+ [api, isAdmin, listFilter, subscriberStatus],
118
+ );
119
+
120
+ const loadDeliveries = useCallback(
121
+ async (issueId: string, cursor?: string | null) => {
122
+ setDeliveriesLoading(true);
123
+ const result = (await api("newsletterIssueDeliveries", { issueId, ...(cursor ? { cursor } : {}) })) as Result<{ deliveries: NewsletterDelivery[]; cursor?: string }>;
124
+ if (!live.current) return;
125
+ setDeliveriesLoading(false);
126
+ if (isFailure(result)) {
127
+ setMessage({ kind: "problem", text: failureText(result) });
128
+ return;
129
+ }
130
+ setDeliveries((current) => (cursor ? [...current, ...result.deliveries] : result.deliveries));
131
+ setDeliveriesCursor(result.cursor ?? null);
132
+ },
133
+ [api],
134
+ );
135
+
136
+ const refresh = useCallback(async () => {
137
+ await Promise.all([loadOverview(), loadIssues(), loadSubscribers()]);
138
+ if (deliveriesFor) await loadDeliveries(deliveriesFor);
139
+ }, [loadOverview, loadIssues, loadSubscribers, loadDeliveries, deliveriesFor]);
140
+
141
+ useEffect(() => {
142
+ void loadOverview();
143
+ }, [loadOverview]);
144
+ useEffect(() => {
145
+ void loadIssues();
146
+ }, [loadIssues]);
147
+ useEffect(() => {
148
+ setSubscribers(null);
149
+ void loadSubscribers();
150
+ }, [loadSubscribers]);
151
+
152
+ /** Runs an operation with the buttons disabled, says what happened, then reloads what it may have changed. */
153
+ const act = async (key: string, run: () => Promise<{ text: string } | NewsletterFailure>, reload: Array<"overview" | "issues" | "subscribers"> = ["overview", "issues"]) => {
154
+ setBusy(key);
155
+ setMessage(null);
156
+ try {
157
+ const outcome = await run();
158
+ if (!live.current) return;
159
+ if ("ok" in outcome) {
160
+ setMessage({ kind: "problem", text: failureText(outcome) });
161
+ } else {
162
+ setMessage({ kind: "ok", text: outcome.text });
163
+ await Promise.all([
164
+ reload.includes("overview") ? loadOverview() : null,
165
+ reload.includes("issues") ? loadIssues() : null,
166
+ reload.includes("subscribers") ? loadSubscribers() : null,
167
+ deliveriesFor ? loadDeliveries(deliveriesFor) : null,
168
+ ]);
169
+ }
170
+ } finally {
171
+ if (live.current) setBusy(null);
172
+ }
173
+ };
174
+
175
+ const openPreview = async (issue: NewsletterIssue) => {
176
+ if (drawer?.issueId === issue.issueId && drawer.mode === "preview") {
177
+ setDrawer(null);
178
+ return;
179
+ }
180
+ setDrawer({ issueId: issue.issueId, mode: "preview" });
181
+ setPreview(null);
182
+ const result = (await api("newsletterPreview", { issueId: issue.issueId })) as Result<NewsletterPreview>;
183
+ if (live.current) setPreview(result);
184
+ };
185
+
186
+ const openApprove = (issue: NewsletterIssue) => {
187
+ setApproveAt(issue.sendAt ? isoToZonedInput(issue.sendAt, zone) : nextWholeHourInput(new Date(), zone));
188
+ setDrawer({ issueId: issue.issueId, mode: "approve" });
189
+ };
190
+
191
+ const approve = (issue: NewsletterIssue) => {
192
+ const sendAt = zonedInputToIso(approveAt, zone);
193
+ if (!sendAt) {
194
+ setMessage({ kind: "problem", text: "Choose a date and time." });
195
+ return;
196
+ }
197
+ void act(`approve:${issue.issueId}`, async () => {
198
+ const result = (await api("newsletterApproveIssue", { issueId: issue.issueId, sendAt })) as Result<{ issue: NewsletterIssue; adjusted?: boolean; warnings?: string[] }>;
199
+ if (isFailure(result)) return result;
200
+ setDrawer(null);
201
+ const when = formatInZone(result.issue.sendAt, zone);
202
+ const extras = [result.adjusted ? "That was too soon, so it was moved a couple of minutes ahead." : "", ...(result.warnings ?? [])].filter(Boolean);
203
+ return { text: `Approved for ${when}.${extras.length ? ` ${extras.join(" ")}` : ""}` };
204
+ });
205
+ };
206
+
207
+ const simple = (issue: NewsletterIssue, operation: "newsletterCancelIssue" | "newsletterStopIssue", done: string) => {
208
+ void act(`${operation}:${issue.issueId}`, async () => {
209
+ const result = (await api(operation, { issueId: issue.issueId })) as Result<object>;
210
+ if (isFailure(result)) return result;
211
+ setDrawer(null);
212
+ return { text: done };
213
+ });
214
+ };
215
+
216
+ const testSend = (issue: NewsletterIssue) =>
217
+ void act(`test:${issue.issueId}`, async () => {
218
+ const result = (await api("newsletterTestSend", { issueId: issue.issueId })) as Result<object>;
219
+ return isFailure(result) ? result : { text: "Test sent to your address." };
220
+ }, []);
221
+
222
+ const newDraft = (listId: string) =>
223
+ void act(`draft:${listId}`, async () => {
224
+ const result = (await api("newsletterCreateDraft", { listId })) as Result<{ status?: string; items?: number }>;
225
+ if (isFailure(result)) return result;
226
+ if (result.status === "created") return { text: `Draft created with ${result.items ?? 0} ${result.items === 1 ? "item" : "items"}. Open it in the editor to write the introduction.` };
227
+ if (result.status === "exists") return { text: "This week already has a draft for that list." };
228
+ return { text: "Nothing has been published since the last issue, so no draft was made." };
229
+ });
230
+
231
+ const showDeliveries = (issue: NewsletterIssue) => {
232
+ setDeliveriesFor(issue.issueId);
233
+ setDeliveries([]);
234
+ setDeliveriesCursor(null);
235
+ void loadDeliveries(issue.issueId);
236
+ };
237
+
238
+ const resume = () =>
239
+ void act("resume", async () => {
240
+ const result = (await api("newsletterResume")) as Result<object>;
241
+ return isFailure(result) ? result : { text: "Sending resumed. Approve any blocked issue again." };
242
+ });
243
+
244
+ const exportCsv = () =>
245
+ void act("export", async () => {
246
+ const rows: NewsletterExportRow[] = [];
247
+ let cursor: string | undefined;
248
+ do {
249
+ const result = (await api("newsletterExport", cursor ? { cursor } : {})) as Result<{ rows: NewsletterExportRow[]; cursor?: string }>;
250
+ if (isFailure(result)) return result;
251
+ rows.push(...result.rows);
252
+ cursor = result.cursor;
253
+ } while (cursor);
254
+ const url = URL.createObjectURL(new Blob([subscribersToCsv(rows)], { type: "text/csv;charset=utf-8" }));
255
+ const link = document.createElement("a");
256
+ link.href = url;
257
+ link.download = "newsletter-subscribers.csv";
258
+ link.click();
259
+ URL.revokeObjectURL(url);
260
+ return { text: `Exported ${rows.length} confirmed and pending ${rows.length === 1 ? "subscriber" : "subscribers"}.` };
261
+ }, []);
262
+
263
+ const erase = () =>
264
+ void act("erase", async () => {
265
+ const email = eraseEmail.trim().toLowerCase();
266
+ const result = (await api("newsletterErase", { email })) as Result<{ removed: number }>;
267
+ if (isFailure(result)) return result;
268
+ setEraseEmail("");
269
+ setEraseConfirm(false);
270
+ return { text: `Erased ${email}: ${result.removed} ${result.removed === 1 ? "record" : "records"} removed.` };
271
+ }, ["overview", "subscribers"]);
272
+
273
+ if (problem === "forbidden") {
274
+ return (
275
+ <div data-news-desk-admin-panel="newsletter">
276
+ <div className="category-steering-empty" role="alert" data-newsletter-state="forbidden">
277
+ <strong>The newsletter is for editors and admins</strong>
278
+ <p>Your account does not have access to this page. Ask an admin for the editor role.</p>
279
+ </div>
280
+ </div>
281
+ );
282
+ }
283
+
284
+ const roundupLists = overview?.lists.filter((list) => list.kind === "roundup") ?? [];
285
+ const deliveriesIssue = issues?.find((issue) => issue.issueId === deliveriesFor) ?? null;
286
+ const loading = overview === null && !problem;
287
+
288
+ return (
289
+ <div data-news-desk-admin-panel="newsletter">
290
+ <article className="news-desk-doctrine-card">
291
+ <div className="news-desk-doctrine-card__header">
292
+ <div>
293
+ <h3>Newsletter</h3>
294
+ <span>Subscribers, issues and delivery for the site&apos;s email. {isAdmin ? "You are an admin: you can approve, stop and see addresses." : "You are an editor: you can preview and test, and see counts. An admin approves."}</span>
295
+ </div>
296
+ </div>
297
+ <div className="news-desk-doctrine-card__actions">
298
+ <button type="button" data-newsletter-refresh disabled={busy !== null} onClick={() => void refresh()}>Refresh</button>
299
+ </div>
300
+ <p role="status" aria-live="polite" data-newsletter-message data-kind={message?.kind ?? (loading ? "loading" : "idle")}>
301
+ {message ? (message.kind === "problem" ? `Problem: ${message.text}` : message.text) : loading ? "Loading..." : problem ?? ""}
302
+ </p>
303
+ </article>
304
+
305
+ {overview ? <ListsCard overview={overview} /> : null}
306
+ {overview ? <SiteStatusCard paused={overview.paused} isAdmin={isAdmin} busy={busy !== null} onResume={resume} /> : null}
307
+
308
+ <article className="news-desk-doctrine-card" data-newsletter-section="issues">
309
+ <div className="news-desk-doctrine-card__header">
310
+ <div><h3>Issues</h3><span>Newest first. Times are in {zone}; hover a time for UTC.</span></div>
311
+ </div>
312
+ <label className="news-desk-doctrine-card__field">
313
+ <span>Show</span>
314
+ <select value={statusFilter} data-newsletter-status-filter onChange={(event) => setStatusFilter(event.target.value)}>
315
+ <option value="">All issues</option>
316
+ {ISSUE_STATUS_FILTERS.map((status) => <option key={status} value={status}>{statusLabel(status)}</option>)}
317
+ </select>
318
+ </label>
319
+ {roundupLists.length ? (
320
+ <div className="news-desk-doctrine-card__actions">
321
+ {roundupLists.map((list) => (
322
+ <button key={list.id} type="button" data-newsletter-new-draft={list.id} disabled={busy !== null} onClick={() => newDraft(list.id)}>New draft: {list.name}</button>
323
+ ))}
324
+ </div>
325
+ ) : null}
326
+ {issues === null ? <p>Loading issues...</p> : issues.length === 0 ? (
327
+ <p data-newsletter-no-issues>{statusFilter ? `No ${statusLabel(statusFilter).toLowerCase()} issues.` : "No issues yet. A roundup draft appears on its schedule, or make one with New draft."}</p>
328
+ ) : (
329
+ <div className="news-desk-user-list">
330
+ {issues.map((issue) => {
331
+ const open = drawer?.issueId === issue.issueId ? drawer.mode : null;
332
+ const row = { ...issue, editedSinceApproval: edited[issue.issueId] };
333
+ return (
334
+ <div className="news-desk-user-row" key={issue.issueId} data-newsletter-issue={issue.issueId} data-status={issue.status}>
335
+ <div><IssueSummary issue={row} zone={zone} demo={isDemo} /></div>
336
+ <div className="news-desk-user-row__actions">
337
+ <button type="button" data-newsletter-action="preview" aria-expanded={open === "preview"} onClick={() => void openPreview(issue)}>Preview</button>
338
+ <button type="button" data-newsletter-action="test" disabled={busy !== null} onClick={() => testSend(issue)}>Test send</button>
339
+ <button type="button" data-newsletter-action="deliveries" onClick={() => showDeliveries(issue)}>Deliveries</button>
340
+ {isAdmin && canApprove(issue.status) ? (
341
+ <button type="button" data-newsletter-action="approve" aria-expanded={open === "approve"} disabled={busy !== null} onClick={() => openApprove(issue)}>
342
+ {issue.status === "scheduled" ? "Change time" : "Approve for a time"}
343
+ </button>
344
+ ) : null}
345
+ {isAdmin && canCancel(issue.status) ? (
346
+ <button type="button" data-newsletter-action="cancel" disabled={busy !== null} onClick={() => simple(issue, "newsletterCancelIssue", "Cancelled. The issue is a draft again.")}>Cancel</button>
347
+ ) : null}
348
+ {isAdmin && canStop(issue.status) ? (
349
+ <button type="button" data-newsletter-action="stop" disabled={busy !== null} onClick={() => setDrawer({ issueId: issue.issueId, mode: "stop" })}>Stop</button>
350
+ ) : null}
351
+ </div>
352
+ {open === "preview" ? (
353
+ <div className="news-desk-newsletter__drawer" data-newsletter-preview>
354
+ {preview === null ? <p>Loading preview...</p> : isFailure(preview) ? (
355
+ <p className="category-steering-alert" role="alert">{failureText(preview)}</p>
356
+ ) : (
357
+ <>
358
+ <p className="news-desk-delegation-note">
359
+ Subject: <strong>{preview.subject}</strong> &middot; {Math.ceil(preview.bytes / 1024)} KB of HTML
360
+ {preview.bytes > 100 * 1024 ? " (Gmail clips messages over 102 KB)" : ""}
361
+ </p>
362
+ {!preview.postalAddress ? (
363
+ <p className="category-steering-alert" role="alert" data-newsletter-postal>{failureText({ ok: false, error: "postal_address_missing" })} The preview shows a placeholder.</p>
364
+ ) : null}
365
+ <iframe title={`Preview of ${issue.subject}`} sandbox="" srcDoc={preview.html} className="news-desk-newsletter__frame" />
366
+ <h4>Plain text version</h4>
367
+ <pre className="news-desk-newsletter__text">{preview.text}</pre>
368
+ </>
369
+ )}
370
+ </div>
371
+ ) : null}
372
+ {open === "approve" ? (
373
+ <div className="news-desk-newsletter__drawer" data-newsletter-approve>
374
+ <label className="news-desk-doctrine-card__field">
375
+ <span>Send at ({zone})</span>
376
+ <input type="datetime-local" value={approveAt} data-newsletter-send-at-input onChange={(event) => setApproveAt(event.target.value)} />
377
+ </label>
378
+ <p className="news-desk-delegation-note">This sends the issue as it is now. If it is edited before this time, it goes back to draft and sends nothing. A time less than two minutes ahead is moved to two minutes from now.</p>
379
+ <div className="news-desk-doctrine-card__actions">
380
+ <button type="button" data-newsletter-confirm-approve disabled={busy !== null} onClick={() => approve(issue)}>Approve for this time</button>
381
+ <button type="button" onClick={() => setDrawer(null)}>Keep as is</button>
382
+ </div>
383
+ </div>
384
+ ) : null}
385
+ {open === "stop" ? (
386
+ <div className="news-desk-newsletter__drawer" data-newsletter-stop>
387
+ <p className="category-steering-alert">Stop sending this issue? The addresses already mailed stay mailed; the rest are not sent. This cannot be resumed.</p>
388
+ <div className="news-desk-doctrine-card__actions">
389
+ <button type="button" data-newsletter-confirm-stop disabled={busy !== null} onClick={() => simple(issue, "newsletterStopIssue", "Stopped. No more of this issue will be sent.")}>Stop sending</button>
390
+ <button type="button" onClick={() => setDrawer(null)}>Keep sending</button>
391
+ </div>
392
+ </div>
393
+ ) : null}
394
+ </div>
395
+ );
396
+ })}
397
+ </div>
398
+ )}
399
+ </article>
400
+
401
+ {deliveriesIssue ? (
402
+ <DeliveriesCard
403
+ issue={deliveriesIssue}
404
+ rows={deliveries}
405
+ events={(overview?.events ?? []).filter((event) => event.issue === deliveriesIssue.issueId)}
406
+ hasMore={deliveriesCursor !== null}
407
+ loading={deliveriesLoading}
408
+ isAdmin={isAdmin}
409
+ onMore={() => void loadDeliveries(deliveriesIssue.issueId, deliveriesCursor)}
410
+ />
411
+ ) : (
412
+ <article className="news-desk-doctrine-card" data-newsletter-section="deliveries">
413
+ <div className="news-desk-doctrine-card__header"><div><h3>Delivery history</h3><span>Choose Deliveries on an issue to see who it went to and what happened</span></div></div>
414
+ </article>
415
+ )}
416
+
417
+ <article className="news-desk-doctrine-card" data-newsletter-section="subscribers">
418
+ <div className="news-desk-doctrine-card__header">
419
+ <div><h3>Subscribers</h3><span>{isAdmin ? "Addresses are personal data. Only admins see them." : "Only admins see addresses."}</span></div>
420
+ </div>
421
+ {isAdmin ? (
422
+ <>
423
+ <div className="news-desk-newsletter__filters">
424
+ <label className="news-desk-doctrine-card__field">
425
+ <span>List</span>
426
+ <select value={listFilter} data-newsletter-list-filter onChange={(event) => setListFilter(event.target.value)}>
427
+ <option value="">All lists</option>
428
+ {(overview?.lists ?? []).map((list) => <option key={list.id} value={list.id}>{list.name}</option>)}
429
+ </select>
430
+ </label>
431
+ <label className="news-desk-doctrine-card__field">
432
+ <span>Status</span>
433
+ <select value={subscriberStatus} data-newsletter-subscriber-filter onChange={(event) => setSubscriberStatus(event.target.value)}>
434
+ <option value="">Any status</option>
435
+ <option value="confirmed">Confirmed</option>
436
+ <option value="pending">Waiting to confirm</option>
437
+ <option value="unsubscribed">Unsubscribed</option>
438
+ </select>
439
+ </label>
440
+ </div>
441
+ <div className="news-desk-doctrine-card__actions">
442
+ <button type="button" data-newsletter-export disabled={busy !== null} onClick={exportCsv}>Export CSV (confirmed and pending)</button>
443
+ </div>
444
+ {subscribers === null ? <p>Loading subscribers...</p> : subscribers.length ? <SubscribersTable rows={subscribers} zone={zone} /> : <p>No subscribers match.</p>}
445
+ {subscribersCursor ? (
446
+ <div className="news-desk-doctrine-card__actions"><button type="button" data-newsletter-more-subscribers onClick={() => void loadSubscribers(subscribersCursor)}>Load more</button></div>
447
+ ) : null}
448
+ <div className="news-desk-merge-panel" data-newsletter-erase>
449
+ <strong>Erase one subscriber</strong>
450
+ <p className="news-desk-delegation-note">Removes the address, its list memberships, any suppression and its delivery records. Use it for a request to be forgotten. It cannot be undone.</p>
451
+ <label className="news-desk-doctrine-card__field">
452
+ <span>Address to erase</span>
453
+ <input type="email" value={eraseEmail} autoComplete="off" data-newsletter-erase-input onChange={(event) => { setEraseEmail(event.target.value); setEraseConfirm(false); }} />
454
+ </label>
455
+ {eraseConfirm ? (
456
+ <div className="news-desk-doctrine-card__actions">
457
+ <span>Erase {eraseEmail.trim()} for good?</span>
458
+ <button type="button" data-newsletter-confirm-erase disabled={busy !== null} onClick={erase}>Erase permanently</button>
459
+ <button type="button" onClick={() => setEraseConfirm(false)}>Keep</button>
460
+ </div>
461
+ ) : (
462
+ <div className="news-desk-doctrine-card__actions">
463
+ <button type="button" data-newsletter-erase-button disabled={!eraseEmail.trim() || busy !== null} onClick={() => setEraseConfirm(true)}>Erase…</button>
464
+ </div>
465
+ )}
466
+ </div>
467
+ </>
468
+ ) : (
469
+ <p className="news-desk-delegation-note" data-newsletter-editor-note>You can see how many people are on each list above. The address list, export and erasure are for admins.</p>
470
+ )}
471
+ </article>
472
+ </div>
473
+ );
474
+ }
@@ -0,0 +1,163 @@
1
+ import {
2
+ countsText,
3
+ formatInZone,
4
+ formatUtc,
5
+ issueEditorHref,
6
+ statusLabel,
7
+ statusMark,
8
+ type NewsletterDelivery,
9
+ type NewsletterEvent,
10
+ type NewsletterIssue,
11
+ type NewsletterOverview,
12
+ type NewsletterSubscriber,
13
+ } from "../lib/newsletter-model";
14
+
15
+ /** Presentation only: the panel fetches and holds state, these render what they are given, so every state is testable from fixtures. */
16
+
17
+ export function ListsCard({ overview }: { overview: NewsletterOverview }) {
18
+ const { totals } = overview;
19
+ return (
20
+ <article className="news-desk-doctrine-card" data-newsletter-section="lists">
21
+ <div className="news-desk-doctrine-card__header">
22
+ <div><h3>Lists</h3><span>Subscribers per list. A person on two lists counts on each.</span></div>
23
+ </div>
24
+ {overview.lists.length ? (
25
+ <dl className="news-desk-monitoring__usage">
26
+ {overview.lists.map((list) => (
27
+ <div key={list.id} data-newsletter-list={list.id}>
28
+ <dt>{list.name} ({list.kind === "roundup" ? "roundup" : list.kind === "alert" ? "alerts" : list.kind})</dt>
29
+ <dd>{list.confirmed}</dd>
30
+ <span className="news-desk-newsletter__quiet">confirmed &middot; {list.pending} pending &middot; {list.unsubscribed} unsubscribed</span>
31
+ </div>
32
+ ))}
33
+ </dl>
34
+ ) : <p>No list is configured.</p>}
35
+ <p className="news-desk-delegation-note" data-newsletter-totals>
36
+ Across the site: {totals.confirmed} confirmed, {totals.pending} waiting to confirm, {totals.unsubscribed} unsubscribed.
37
+ {" "}{overview.suppressed} {overview.suppressed === 1 ? "address is" : "addresses are"} suppressed after a bounce or complaint.
38
+ </p>
39
+ </article>
40
+ );
41
+ }
42
+
43
+ export function SiteStatusCard({ paused, isAdmin, busy, onResume }: { paused: NewsletterOverview["paused"]; isAdmin: boolean; busy: boolean; onResume: () => void }) {
44
+ return (
45
+ <article className="news-desk-doctrine-card" data-newsletter-section="site-status">
46
+ <div className="news-desk-doctrine-card__header">
47
+ <div><h3>Site status</h3><span>Sending turns itself off when bounces or complaints run high</span></div>
48
+ </div>
49
+ {paused.paused ? (
50
+ <div className="category-steering-alert" role="alert" data-newsletter-paused>
51
+ <strong><span aria-hidden="true">■ </span>Sending is paused.</strong>{" "}
52
+ {paused.reason ? <>Reason: {paused.reason}. </> : null}
53
+ {paused.pausedAt ? <>Paused {formatUtc(paused.pausedAt)}. </> : null}
54
+ Issues due now are blocked until sending resumes; approve a blocked issue again afterwards.
55
+ <div className="news-desk-doctrine-card__actions">
56
+ {isAdmin ? (
57
+ <button type="button" disabled={busy} data-newsletter-resume onClick={onResume}>Resume sending</button>
58
+ ) : <span>An admin can resume sending.</span>}
59
+ </div>
60
+ </div>
61
+ ) : (
62
+ <p data-newsletter-running><span aria-hidden="true">✓ </span>Sending is on.{paused.resumedAt ? ` Resumed ${formatUtc(paused.resumedAt)}.` : ""}</p>
63
+ )}
64
+ </article>
65
+ );
66
+ }
67
+
68
+ /** What an issue row says about the issue; the buttons beside it belong to the panel. */
69
+ export function IssueSummary({ issue, zone, demo }: { issue: NewsletterIssue; zone: string; demo: boolean }) {
70
+ return (
71
+ <>
72
+ <header>
73
+ <strong>{issue.subject || "(no subject)"}</strong>
74
+ <span data-newsletter-status={issue.status}><span aria-hidden="true">{statusMark(issue.status)} </span>{statusLabel(issue.status)}</span>
75
+ </header>
76
+ <p>{issue.listName ?? issue.listId}{issue.kind ? ` · ${issue.kind}` : ""}</p>
77
+ {issue.sendAt ? (
78
+ <p data-newsletter-send-at>
79
+ {issue.status === "sent" || issue.status === "sending" ? "Scheduled for " : "Send at "}
80
+ <time dateTime={issue.sendAt} title={formatUtc(issue.sendAt)}>{formatInZone(issue.sendAt, zone)}</time>
81
+ {issue.approvedBy ? ` · approved by ${issue.approvedBy}` : ""}
82
+ </p>
83
+ ) : null}
84
+ <p data-newsletter-counts>{countsText(issue.counts ?? {})}</p>
85
+ {issue.status === "blocked" ? (
86
+ <p className="category-steering-alert" data-newsletter-blocked>
87
+ Blocked: {issue.note ?? "see the issue"}. Fix the cause, then approve it again.
88
+ </p>
89
+ ) : issue.note ? <p data-newsletter-note>Note: {issue.note}</p> : null}
90
+ {issue.editedSinceApproval ? (
91
+ <p className="category-steering-alert" data-newsletter-edited>
92
+ Edited since approval. When it comes due it will go back to draft and send nothing. Approve it again to send this version.
93
+ </p>
94
+ ) : null}
95
+ <p className="news-desk-newsletter__links">
96
+ {issue.itemId ? <a href={issueEditorHref(issue.itemId, demo)} data-newsletter-editor-link>Open in the editor</a> : <span>No item</span>}
97
+ {issue.archiveUrl ? <> &middot; <a href={issue.archiveUrl} target="_blank" rel="noreferrer noopener" data-newsletter-archive-link>Archive page</a></> : null}
98
+ </p>
99
+ </>
100
+ );
101
+ }
102
+
103
+ export function DeliveriesCard({
104
+ issue, rows, events, hasMore, loading, isAdmin, onMore,
105
+ }: {
106
+ issue: NewsletterIssue; rows: NewsletterDelivery[]; events: NewsletterEvent[]; hasMore: boolean; loading: boolean; isAdmin: boolean; onMore: () => void;
107
+ }) {
108
+ return (
109
+ <article className="news-desk-doctrine-card" data-newsletter-section="deliveries" data-newsletter-deliveries-for={issue.issueId}>
110
+ <div className="news-desk-doctrine-card__header">
111
+ <div><h3>Delivery history</h3><span>{issue.subject} &middot; {countsText(issue.counts ?? {})}</span></div>
112
+ </div>
113
+ {!isAdmin ? <p className="news-desk-delegation-note">Addresses are masked for editors.</p> : null}
114
+ {rows.length ? (
115
+ <table className="news-desk-newsletter__table">
116
+ <thead><tr><th scope="col">Address</th><th scope="col">Result</th><th scope="col">Queued (UTC)</th><th scope="col">Last event (UTC)</th></tr></thead>
117
+ <tbody>
118
+ {rows.map((row, index) => (
119
+ <tr key={`${row.address}-${index}`} data-newsletter-delivery={row.status}>
120
+ <td>{row.address}</td>
121
+ <td>{row.status}{row.error ? ` (${row.error})` : ""}</td>
122
+ <td>{formatUtc(row.at)}</td>
123
+ <td>{row.eventAt ? formatUtc(row.eventAt) : "none yet"}</td>
124
+ </tr>
125
+ ))}
126
+ </tbody>
127
+ </table>
128
+ ) : <p>{loading ? "Loading deliveries..." : "Nothing has been sent for this issue."}</p>}
129
+ {hasMore ? <div className="news-desk-doctrine-card__actions"><button type="button" disabled={loading} onClick={onMore}>Load more deliveries</button></div> : null}
130
+ <h4>Recent events for this issue</h4>
131
+ {events.length ? (
132
+ <ul className="news-desk-monitoring__list" data-newsletter-events>
133
+ {events.map((event, index) => (
134
+ <li key={`${event.at}-${index}`}>
135
+ <strong>{event.type}{event.detail ? ` (${event.detail})` : ""}</strong>
136
+ <span>{event.list ?? ""}</span>
137
+ <span>{formatUtc(event.at)}</span>
138
+ </li>
139
+ ))}
140
+ </ul>
141
+ ) : <p>No recent events for this issue. Events are kept for 90 days and the panel shows the latest 100 for the whole site.</p>}
142
+ </article>
143
+ );
144
+ }
145
+
146
+ export function SubscribersTable({ rows, zone }: { rows: NewsletterSubscriber[]; zone: string }) {
147
+ return (
148
+ <table className="news-desk-newsletter__table" data-newsletter-subscribers>
149
+ <thead><tr><th scope="col">Address</th><th scope="col">Status</th><th scope="col">Lists</th><th scope="col">Signed up</th><th scope="col">Confirmed</th></tr></thead>
150
+ <tbody>
151
+ {rows.map((row) => (
152
+ <tr key={row.email} data-newsletter-subscriber={row.status}>
153
+ <td>{row.email}</td>
154
+ <td>{row.status}</td>
155
+ <td>{row.lists.length ? row.lists.map((entry) => `${entry.id} (${entry.status})`).join(", ") : "none"}</td>
156
+ <td>{formatInZone(row.createdAt, zone)}</td>
157
+ <td>{row.confirmedAt ? formatInZone(row.confirmedAt, zone) : "not yet"}</td>
158
+ </tr>
159
+ ))}
160
+ </tbody>
161
+ </table>
162
+ );
163
+ }
@@ -48,11 +48,9 @@ import {
48
48
  import { getNewsroomNavHref } from "../lib/newsroom-nav";
49
49
  import { SITE_BRAND } from "../lib/site-brand";
50
50
  import { cn } from "../lib/utils";
51
- import amplifyOutputs from "papyrus-amplify-outputs";
52
- import { applyReplacement, editorialChecksEnabled, inlineFindings, visibleFindings } from "../lib/editorial-checks";
51
+ import { applyReplacement, inlineFindings, visibleFindings } from "../lib/editorial-checks";
53
52
  import { graphqlEditorialBackend } from "../lib/editorial-checks-client";
54
53
  import { demoEditorialBackend } from "../lib/editorial-checks-demo";
55
- import type { PluginOutputs } from "../lib/plugin-settings";
56
54
  import type { FindingActions } from "./editorial-finding-card";
57
55
  import { EditorialFindingsPanel } from "./editorial-findings-panel";
58
56
  import { EditorialPreviewPopover, type PreviewPopoverTarget } from "./editorial-preview-popover";
@@ -219,7 +217,7 @@ export function NewsroomArticleEditor({ articleId, demo, embedded = false }: { a
219
217
  const frontMatterYaml = editor?.frontMatterYaml ?? null;
220
218
  const bodyMarkus = editor?.bodyMarkus ?? null;
221
219
  const editorialBackend = useMemo(
222
- () => (demo ? demoEditorialBackend : !previewMode && editorialChecksEnabled(amplifyOutputs as PluginOutputs) ? graphqlEditorialBackend : null),
220
+ () => (demo ? demoEditorialBackend : !previewMode ? graphqlEditorialBackend : null),
223
221
  [demo, previewMode],
224
222
  );
225
223
  const editorial = useEditorialChecks({