@anthusai/papyrus 2.0.0-next.41 → 2.0.0-next.43
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/amplify/functions/assignment-action/data-access.js +2 -0
- package/amplify/functions/assignment-action/data-access.ts +2 -0
- package/amplify/functions/content-actions/handler.py +1 -1
- package/amplify/functions/shared/editorial-context.ts +59 -6
- package/amplify/plugins/newsletter/config.js +195 -0
- package/amplify/plugins/newsletter/config.ts +240 -0
- package/amplify/plugins/newsletter/function/handler.py +6 -0
- package/amplify/plugins/newsletter/function/requirements.txt +5 -0
- package/amplify/plugins/newsletter/ops/handler.py +12 -0
- package/amplify/plugins/newsletter/ops/resource.js +27 -0
- package/amplify/plugins/newsletter/ops/resource.ts +37 -0
- package/amplify/plugins/newsletter/papyrus.plugin.js +246 -0
- package/amplify/plugins/newsletter/papyrus.plugin.ts +291 -0
- package/amplify/plugins/newsletter/schema.js +37 -0
- package/amplify/plugins/newsletter/schema.ts +42 -0
- package/amplify/plugins/newsletter/secure-string-parameter.js +107 -0
- package/amplify/plugins/newsletter/secure-string-parameter.ts +120 -0
- package/amplify/plugins/newsletter/sending.js +139 -0
- package/amplify/plugins/newsletter/sending.ts +185 -0
- package/amplify/plugins/reader-steering/config.js +55 -3
- package/amplify/plugins/reader-steering/config.ts +98 -3
- package/amplify/plugins/reader-steering/function/ai_moderation.py +230 -0
- package/amplify/plugins/reader-steering/function/handler.py +829 -10
- package/amplify/plugins/reader-steering/function/moderation-prompt.md +27 -0
- package/amplify/plugins/reader-steering/function/moderation.py +316 -0
- package/amplify/plugins/reader-steering/function/resource.js +1 -1
- package/amplify/plugins/reader-steering/function/resource.ts +1 -1
- package/amplify/plugins/reader-steering/papyrus.plugin.js +78 -6
- package/amplify/plugins/reader-steering/papyrus.plugin.ts +85 -6
- package/amplify/plugins/reader-steering/schema.js +101 -1
- package/amplify/plugins/reader-steering/schema.ts +101 -1
- package/amplify/plugins/registry.js +2 -0
- package/amplify/plugins/registry.ts +2 -0
- package/amplify/plugins/types.ts +2 -0
- package/app/api/newsletter/confirm/route.ts +13 -0
- package/app/api/newsletter/preferences/route.ts +13 -0
- package/app/api/newsletter/subscribe/route.ts +9 -0
- package/app/api/newsletter/unsubscribe/route.ts +13 -0
- package/app/api/reader/comment/delete/route.ts +9 -0
- package/app/api/reader/comment/edit/route.ts +9 -0
- package/app/api/reader/comment/route.ts +9 -0
- package/app/api/reader/report/route.ts +9 -0
- package/app/api/reader/submit/route.ts +9 -0
- package/components/moderation-panel.tsx +248 -0
- package/components/topic-steering-workspace.tsx +19 -1
- package/lib/editorial-checks.ts +3 -1
- package/lib/newsletter-api.ts +391 -0
- package/lib/newsletter-pages.ts +264 -0
- package/lib/reader-api.ts +7 -5
- package/lib/reader-moderation.ts +220 -0
- package/package.json +14 -1
- package/routes.manifest.json +103 -1
|
@@ -9,6 +9,8 @@ export const ASSIGNMENT_DATA_FIELDS = [
|
|
|
9
9
|
"Query/fields/getProcedureDefinition",
|
|
10
10
|
"Query/fields/getModelAttachment",
|
|
11
11
|
"Query/fields/getNewsroomSection",
|
|
12
|
+
"Query/fields/listNewsroomSections",
|
|
13
|
+
"Query/fields/listNewsroomSectionsByTenantAndSortOrder",
|
|
12
14
|
"Query/fields/getKnowledgeCorpus",
|
|
13
15
|
"Query/fields/getKnowledgeImportRun",
|
|
14
16
|
"Query/fields/getReference",
|
|
@@ -11,6 +11,8 @@ export const ASSIGNMENT_DATA_FIELDS = [
|
|
|
11
11
|
"Query/fields/getProcedureDefinition",
|
|
12
12
|
"Query/fields/getModelAttachment",
|
|
13
13
|
"Query/fields/getNewsroomSection",
|
|
14
|
+
"Query/fields/listNewsroomSections",
|
|
15
|
+
"Query/fields/listNewsroomSectionsByTenantAndSortOrder",
|
|
14
16
|
"Query/fields/getKnowledgeCorpus",
|
|
15
17
|
"Query/fields/getKnowledgeImportRun",
|
|
16
18
|
"Query/fields/getReference",
|
|
@@ -189,7 +189,7 @@ def run_projection_task(task: dict) -> dict:
|
|
|
189
189
|
elif task.get("task") == "deploy-render":
|
|
190
190
|
return run_deploy_render_task(client)
|
|
191
191
|
elif task.get("task") == READER_SNAPSHOT_TASK:
|
|
192
|
-
return run_reader_snapshot(projection_context(client), client).to_dict()
|
|
192
|
+
return run_reader_snapshot(projection_context(client), client, poll_retirements=task.get("retirementPoll") is True).to_dict()
|
|
193
193
|
elif task.get("task") == "invalidate":
|
|
194
194
|
invalidate = projection_context(client).invalidate
|
|
195
195
|
if invalidate is None:
|
|
@@ -13,8 +13,9 @@ export type EditorialOptions = {
|
|
|
13
13
|
storyLineageId?: string | null;
|
|
14
14
|
assignmentId?: string | null;
|
|
15
15
|
maxCharacters?: number | null;
|
|
16
|
-
/** A publication without a current mission or policy record yields missingPublicationDoctrine instead of an error
|
|
17
|
-
*
|
|
16
|
+
/** A publication without a current mission or policy record yields missingPublicationDoctrine instead of an error, and a
|
|
17
|
+
* section value that matches no NewsroomSection yields missingSectionConfiguration instead of an error.
|
|
18
|
+
* Only the editorial check asks for this (its rule lane needs neither); more than one current record is still an error. */
|
|
18
19
|
optionalPublicationDoctrine?: boolean | null;
|
|
19
20
|
readAttachment: (attachment: EditorialRecord) => Promise<string>;
|
|
20
21
|
};
|
|
@@ -41,6 +42,47 @@ async function get(client: EditorialClient, model: string, id: string) {
|
|
|
41
42
|
return row;
|
|
42
43
|
}
|
|
43
44
|
|
|
45
|
+
const slugOf = (value: string) => value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
46
|
+
const localPart = (id: string) => id.split("#").at(-1) ?? id;
|
|
47
|
+
|
|
48
|
+
async function allSections(client: EditorialClient) {
|
|
49
|
+
const rows: EditorialRecord[] = [];
|
|
50
|
+
let nextToken: string | null | undefined;
|
|
51
|
+
do {
|
|
52
|
+
const response = checked(await client.models.NewsroomSection.list({ limit: 100, nextToken }), "read NewsroomSection list");
|
|
53
|
+
rows.push(...(response.data as EditorialRecord[] ?? []));
|
|
54
|
+
nextToken = response.nextToken;
|
|
55
|
+
} while (nextToken);
|
|
56
|
+
return rows;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** An item stores its section as an id, a slug or a name; find the NewsroomSection of this publication it means.
|
|
60
|
+
* Order: id (as given, then tenant-scoped), then slug (the id's local part), then name (title or short title).
|
|
61
|
+
* Returns null when nothing matches; two sections matching at the same step is an error. */
|
|
62
|
+
async function findSection(client: EditorialClient, value: string, tenantId?: string) {
|
|
63
|
+
const direct = checked(await client.models.NewsroomSection.get({ id: value }), "read NewsroomSection").data as EditorialRecord | null;
|
|
64
|
+
if (direct) return direct;
|
|
65
|
+
if (tenantId) {
|
|
66
|
+
const scoped = checked(await client.models.NewsroomSection.get({ id: tenantScopedValue(tenantId, value) }), "read NewsroomSection").data as EditorialRecord | null;
|
|
67
|
+
if (scoped) return scoped;
|
|
68
|
+
}
|
|
69
|
+
const all = tenantId
|
|
70
|
+
? await pages(client, "NewsroomSection", "listNewsroomSectionsByTenantAndSortOrder", { tenantId })
|
|
71
|
+
: (await allSections(client)).filter(row => !row.tenantId);
|
|
72
|
+
const wanted = slugOf(value);
|
|
73
|
+
const steps: ((row: EditorialRecord) => boolean)[] = [
|
|
74
|
+
row => slugOf(localPart(String(row.id ?? ""))) === wanted,
|
|
75
|
+
row => [row.title, row.shortTitle].some(name => typeof name === "string" && name.trim().toLowerCase() === value.trim().toLowerCase()),
|
|
76
|
+
row => [row.title, row.shortTitle].some(name => typeof name === "string" && slugOf(name) === wanted),
|
|
77
|
+
];
|
|
78
|
+
for (const step of steps) {
|
|
79
|
+
const matches = all.filter(step);
|
|
80
|
+
if (matches.length > 1) throw new Error(`Section "${value}" is ambiguous: ${matches.map(row => row.id).join(", ")}.`);
|
|
81
|
+
if (matches.length === 1) return matches[0];
|
|
82
|
+
}
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
|
|
44
86
|
function tenant(row: EditorialRecord, tenantId?: string) {
|
|
45
87
|
if ((row.tenantId || null) !== (tenantId || null)) throw new Error("Editorial record tenant does not match the configured authoring scope.");
|
|
46
88
|
}
|
|
@@ -58,7 +100,7 @@ function entry(scope: string, kind: string, text: string, record: EditorialRecor
|
|
|
58
100
|
} };
|
|
59
101
|
}
|
|
60
102
|
|
|
61
|
-
export function buildEditorialContext(publication: EditorialRecord, scope: EditorialRecord, entries: EditorialRecord[], warnings: string[], maxCharacters = 0, missingPublicationDoctrine: string[] = []) {
|
|
103
|
+
export function buildEditorialContext(publication: EditorialRecord, scope: EditorialRecord, entries: EditorialRecord[], warnings: string[], maxCharacters = 0, missingPublicationDoctrine: string[] = [], missingSectionConfiguration: string[] = []) {
|
|
62
104
|
const lines = [`Editorial context: ${publication.key}`, "Source: cloud",
|
|
63
105
|
"Precedence: publication > section > assignment. Surface conflicts; narrower instructions do not silently override publication policy.",
|
|
64
106
|
"Private operating guidance; not evidence or reader-facing copy."];
|
|
@@ -69,7 +111,8 @@ export function buildEditorialContext(publication: EditorialRecord, scope: Edito
|
|
|
69
111
|
if (maxCharacters && totalCharacters > maxCharacters) throw new Error(`Editorial context budget ${maxCharacters} cannot hold ${totalCharacters} required characters; policy was not truncated.`);
|
|
70
112
|
const payload = { schemaVersion: 1, rendererVersion: "editorial-context/v1", publication, scope, sourceMode: "cloud",
|
|
71
113
|
precedence: ["publication", "section", "assignment"], entries, sources: entries.map(value => value.source), warnings, text, totalCharacters,
|
|
72
|
-
...(missingPublicationDoctrine.length ? { missingPublicationDoctrine } : {})
|
|
114
|
+
...(missingPublicationDoctrine.length ? { missingPublicationDoctrine } : {}),
|
|
115
|
+
...(missingSectionConfiguration.length ? { missingSectionConfiguration } : {}) };
|
|
73
116
|
return { ...payload, contextHash: digest(JSON.stringify(canonical(payload))), resolvedAt: new Date().toISOString() };
|
|
74
117
|
}
|
|
75
118
|
|
|
@@ -89,6 +132,8 @@ export async function resolveEditorialContext(client: EditorialClient, options:
|
|
|
89
132
|
const warnings: string[] = [];
|
|
90
133
|
const missingPublicationDoctrine: string[] = [];
|
|
91
134
|
let sectionId = options.sectionId || null;
|
|
135
|
+
let requestedSection: string | null = null;
|
|
136
|
+
const missingSectionConfiguration: string[] = [];
|
|
92
137
|
let storyLineageId = options.storyLineageId || null;
|
|
93
138
|
const assignmentId = options.assignmentId || null;
|
|
94
139
|
let assignment: EditorialRecord | undefined;
|
|
@@ -124,13 +169,19 @@ export async function resolveEditorialContext(client: EditorialClient, options:
|
|
|
124
169
|
entries.push(entry("publication", kind, text, record));
|
|
125
170
|
}
|
|
126
171
|
if (sectionId) {
|
|
127
|
-
const section = await
|
|
172
|
+
const section = await findSection(client, sectionId, options.tenantId);
|
|
173
|
+
if (!section && !options.optionalPublicationDoctrine) throw new Error(`NewsroomSection not found: ${sectionId}`);
|
|
174
|
+
if (!section) { missingSectionConfiguration.push(sectionId); requestedSection = sectionId; sectionId = null; }
|
|
175
|
+
else {
|
|
128
176
|
tenant(section, options.tenantId);
|
|
177
|
+
if (section.id !== sectionId) requestedSection = sectionId;
|
|
178
|
+
sectionId = section.id;
|
|
129
179
|
for (const [kind, key] of [["mission", "editorialMission"], ["policy", "editorialPolicy"], ["guidance", "assignmentGuidance"], ["kill criteria", "killCriteria"]]) {
|
|
130
180
|
const text = String(section[key] || "").trim();
|
|
131
181
|
if (text) entries.push(entry("section", kind, text, section));
|
|
132
182
|
else if (kind === "mission" || kind === "policy") warnings.push(`Section ${section.id} intentionally has an empty ${kind} slot; publication doctrine still applies.`);
|
|
133
183
|
}
|
|
184
|
+
}
|
|
134
185
|
}
|
|
135
186
|
if (assignment) {
|
|
136
187
|
if (options.tenantId && !storyLineageId && !sectionId) throw new Error("A tenant assignment needs a scoped story or section to establish its publication.");
|
|
@@ -153,7 +204,9 @@ export async function resolveEditorialContext(client: EditorialClient, options:
|
|
|
153
204
|
warnings.push("No assignment brief attachment exists; the Assignment summary is supplied as its brief.");
|
|
154
205
|
}
|
|
155
206
|
}
|
|
156
|
-
|
|
207
|
+
// requestedSection: the value the caller asked for when it was not the section's id (a slug or name, or nothing matched).
|
|
208
|
+
const scope = { sectionId, storyLineageId, assignmentId, ...(requestedSection ? { requestedSection } : {}) };
|
|
209
|
+
return buildEditorialContext(publication, scope, entries, warnings, options.maxCharacters ?? 0, missingPublicationDoctrine, missingSectionConfiguration);
|
|
157
210
|
}
|
|
158
211
|
|
|
159
212
|
export function assignmentDoctrine(pack: Awaited<ReturnType<typeof resolveEditorialContext>>) {
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
export const NEWSLETTER_SITE_ID = /^[a-z0-9][a-z0-9-]{0,39}$/;
|
|
2
|
+
export const NEWSLETTER_LIST_ID = /^[a-z][a-z0-9-]{0,39}$/;
|
|
3
|
+
export const COMPUTE_ROLE_ARN = /^arn:aws:iam::[0-9]{12}:role\/[A-Za-z0-9+=,.@_/-]{1,512}$/;
|
|
4
|
+
const HOSTNAME = /^(?=.{1,253}$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+$/;
|
|
5
|
+
const LOCAL_PART = /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*$/;
|
|
6
|
+
const SES_NAME = /^[A-Za-z0-9_-]{1,64}$/;
|
|
7
|
+
const ISSUE_TYPE = /^[a-z][a-z0-9_]{0,59}$/;
|
|
8
|
+
/** One path segment: it is the Item section of the archive and the `urls.sections` key of the site's projection.json. */
|
|
9
|
+
const ARCHIVE_PATH = /^\/[a-z0-9][a-z0-9_-]*\/$/;
|
|
10
|
+
const SCHEDULER_CRON = /^cron\(\S+ \S+ \S+ \S+ \S+ \S+\)$/;
|
|
11
|
+
const UNSAFE_CSS = /[<>{};"\\`]|url\(|expression\(|@import/i;
|
|
12
|
+
const CONTROL_CHARACTERS = /[\u0000-\u001f\u007f]/;
|
|
13
|
+
export const ITEM_URL_STYLES = ["html", "directory", "clean"];
|
|
14
|
+
const KNOWN_KEYS = new Set([
|
|
15
|
+
"name", "siteId", "siteOrigin", "computeRoleArn", "sendingDomain", "fromAddress", "fromName", "instantAlerts", "theme", "lists",
|
|
16
|
+
"configurationSet", "eventTopicName", "itemUrlStyle",
|
|
17
|
+
]);
|
|
18
|
+
const LIST_KEYS = {
|
|
19
|
+
roundup: ["id", "name", "description", "kind", "schedule", "issueType", "archivePath"],
|
|
20
|
+
alert: ["id", "name", "description", "kind", "rule", "approval"],
|
|
21
|
+
};
|
|
22
|
+
function fail(message) {
|
|
23
|
+
throw new Error(`newsletter plugin ${message}`);
|
|
24
|
+
}
|
|
25
|
+
function record(raw, label, known) {
|
|
26
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw))
|
|
27
|
+
fail(`${label} must be an object`);
|
|
28
|
+
const unknown = Object.keys(raw).filter((key) => !known.includes(key));
|
|
29
|
+
if (unknown.length > 0)
|
|
30
|
+
fail(`${label} has unknown settings: ${unknown.join(", ")}`);
|
|
31
|
+
return raw;
|
|
32
|
+
}
|
|
33
|
+
function text(raw, label, maximum, options = {}) {
|
|
34
|
+
const value = raw === undefined ? options.fallback : raw;
|
|
35
|
+
if (value === undefined)
|
|
36
|
+
fail(`${label} is required`);
|
|
37
|
+
if (typeof value !== "string" || CONTROL_CHARACTERS.test(value) || value.trim() !== value) {
|
|
38
|
+
fail(`${label} must be text on one line with no leading or trailing spaces`);
|
|
39
|
+
}
|
|
40
|
+
if (value.length === 0 && !options.optional)
|
|
41
|
+
fail(`${label} is required`);
|
|
42
|
+
if (value.length > maximum)
|
|
43
|
+
fail(`${label} must be at most ${maximum} characters`);
|
|
44
|
+
return value;
|
|
45
|
+
}
|
|
46
|
+
function matching(raw, label, pattern, description, fallback) {
|
|
47
|
+
const value = raw === undefined ? fallback : raw;
|
|
48
|
+
if (typeof value !== "string" || !pattern.test(value))
|
|
49
|
+
fail(`${label} must be ${description}`);
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
function timeZone(raw, label) {
|
|
53
|
+
const value = text(raw, label, 64);
|
|
54
|
+
try {
|
|
55
|
+
new Intl.DateTimeFormat("en-US", { timeZone: value });
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
fail(`${label} must be an IANA time zone such as America/New_York`);
|
|
59
|
+
}
|
|
60
|
+
return value;
|
|
61
|
+
}
|
|
62
|
+
function origin(raw) {
|
|
63
|
+
const value = text(raw, "siteOrigin", 200);
|
|
64
|
+
let parsed;
|
|
65
|
+
try {
|
|
66
|
+
parsed = new URL(value);
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
parsed = undefined;
|
|
70
|
+
}
|
|
71
|
+
if (!parsed || parsed.protocol !== "https:" || parsed.origin !== value)
|
|
72
|
+
fail("siteOrigin must be an https origin such as https://example.com with no path");
|
|
73
|
+
return value;
|
|
74
|
+
}
|
|
75
|
+
function stringList(raw, label) {
|
|
76
|
+
if (raw === undefined)
|
|
77
|
+
return undefined;
|
|
78
|
+
if (!Array.isArray(raw) || raw.length === 0 || raw.length > 50)
|
|
79
|
+
fail(`${label} must be a list of 1 to 50 names`);
|
|
80
|
+
return [...new Set(raw.map((entry, index) => text(entry, `${label}[${index}]`, 80)))];
|
|
81
|
+
}
|
|
82
|
+
function itemUrlStyle(raw) {
|
|
83
|
+
if (raw === undefined)
|
|
84
|
+
return "html";
|
|
85
|
+
if (typeof raw !== "string" || !ITEM_URL_STYLES.includes(raw))
|
|
86
|
+
fail(`itemUrlStyle must be one of ${ITEM_URL_STYLES.join(", ")}`);
|
|
87
|
+
return raw;
|
|
88
|
+
}
|
|
89
|
+
function resolveTheme(raw) {
|
|
90
|
+
const theme = record(raw, "theme", ["accent", "text", "background", "surface", "muted", "fontFamily", "logoUrl"]);
|
|
91
|
+
const resolved = {
|
|
92
|
+
accent: text(theme.accent, "theme.accent", 80),
|
|
93
|
+
text: text(theme.text, "theme.text", 80),
|
|
94
|
+
background: text(theme.background, "theme.background", 80),
|
|
95
|
+
};
|
|
96
|
+
for (const key of ["surface", "muted", "fontFamily"]) {
|
|
97
|
+
if (theme[key] !== undefined)
|
|
98
|
+
resolved[key] = text(theme[key], `theme.${key}`, 200);
|
|
99
|
+
}
|
|
100
|
+
for (const [key, value] of Object.entries(resolved)) {
|
|
101
|
+
if (UNSAFE_CSS.test(value))
|
|
102
|
+
fail(`theme.${key} contains characters that are not allowed in a style value`);
|
|
103
|
+
}
|
|
104
|
+
if (theme.logoUrl !== undefined) {
|
|
105
|
+
const logoUrl = text(theme.logoUrl, "theme.logoUrl", 500);
|
|
106
|
+
if (!/^https:\/\//.test(logoUrl))
|
|
107
|
+
fail("theme.logoUrl must be an https URL");
|
|
108
|
+
resolved.logoUrl = logoUrl;
|
|
109
|
+
}
|
|
110
|
+
return resolved;
|
|
111
|
+
}
|
|
112
|
+
function resolveRule(raw, label) {
|
|
113
|
+
if (raw === undefined)
|
|
114
|
+
return {};
|
|
115
|
+
const rule = record(raw, label, ["sections", "tags", "types"]);
|
|
116
|
+
return {
|
|
117
|
+
...(rule.sections === undefined ? {} : { sections: stringList(rule.sections, `${label}.sections`) }),
|
|
118
|
+
...(rule.tags === undefined ? {} : { tags: stringList(rule.tags, `${label}.tags`) }),
|
|
119
|
+
...(rule.types === undefined ? {} : { types: stringList(rule.types, `${label}.types`) }),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function resolveList(raw, index, instantAlerts) {
|
|
123
|
+
const label = `lists[${index}]`;
|
|
124
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw))
|
|
125
|
+
fail(`${label} must be an object`);
|
|
126
|
+
const kind = raw.kind;
|
|
127
|
+
if (kind !== "roundup" && kind !== "alert")
|
|
128
|
+
fail(`${label}.kind must be "roundup" or "alert"`);
|
|
129
|
+
const list = record(raw, label, LIST_KEYS[kind]);
|
|
130
|
+
const base = {
|
|
131
|
+
id: matching(list.id, `${label}.id`, NEWSLETTER_LIST_ID, "lowercase letters, digits and hyphens, starting with a letter (at most 40 characters)"),
|
|
132
|
+
name: text(list.name, `${label}.name`, 80),
|
|
133
|
+
description: text(list.description, `${label}.description`, 300, { optional: true, fallback: "" }),
|
|
134
|
+
};
|
|
135
|
+
if (kind === "roundup") {
|
|
136
|
+
const schedule = record(list.schedule, `${label}.schedule`, ["draft", "timezone"]);
|
|
137
|
+
return {
|
|
138
|
+
...base,
|
|
139
|
+
kind,
|
|
140
|
+
schedule: {
|
|
141
|
+
draft: matching(schedule.draft, `${label}.schedule.draft`, SCHEDULER_CRON, 'an EventBridge Scheduler cron such as "cron(0 13 ? * FRI *)"'),
|
|
142
|
+
timezone: timeZone(schedule.timezone, `${label}.schedule.timezone`),
|
|
143
|
+
},
|
|
144
|
+
issueType: matching(list.issueType, `${label}.issueType`, ISSUE_TYPE, "a lowercase item type name", "newsletter_issue"),
|
|
145
|
+
archivePath: matching(list.archivePath, `${label}.archivePath`, ARCHIVE_PATH, 'a path that starts and ends with "/", such as /roundup/'),
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
const approval = list.approval === undefined ? "admin" : list.approval;
|
|
149
|
+
if (approval !== "admin" && approval !== "none")
|
|
150
|
+
fail(`${label}.approval must be "admin" or "none"`);
|
|
151
|
+
if (approval === "none" && !instantAlerts) {
|
|
152
|
+
fail(`${label}.approval "none" sends alerts without an admin approving them: set instantAlerts: true on the plugin first`);
|
|
153
|
+
}
|
|
154
|
+
return { ...base, kind, rule: resolveRule(list.rule, `${label}.rule`), approval };
|
|
155
|
+
}
|
|
156
|
+
export function resolveNewsletterConfig(request) {
|
|
157
|
+
const raw = record(typeof request === "string" ? { name: request } : request, "settings", [...KNOWN_KEYS]);
|
|
158
|
+
const siteId = matching(raw.siteId, "siteId", NEWSLETTER_SITE_ID, "a lowercase site id (letters, digits, hyphens), the SiteId of the sending stack");
|
|
159
|
+
const computeRoleArn = raw.computeRoleArn;
|
|
160
|
+
if (typeof computeRoleArn !== "string" || !COMPUTE_ROLE_ARN.test(computeRoleArn)) {
|
|
161
|
+
fail("computeRoleArn must be the IAM role ARN of the CMS app's compute role (the CmsComputeRoleArn output)");
|
|
162
|
+
}
|
|
163
|
+
const sendingDomain = matching(raw.sendingDomain, "sendingDomain", HOSTNAME, "a lowercase domain name such as news.example.com");
|
|
164
|
+
const fromAddress = text(raw.fromAddress, "fromAddress", 254);
|
|
165
|
+
const [local, domain, ...extra] = fromAddress.split("@");
|
|
166
|
+
if (extra.length > 0 || !local || local.length > 64 || !LOCAL_PART.test(local) || domain !== sendingDomain) {
|
|
167
|
+
fail(`fromAddress must be an address on ${sendingDomain} (lowercase, such as newsletter@${sendingDomain})`);
|
|
168
|
+
}
|
|
169
|
+
if (raw.instantAlerts !== undefined && typeof raw.instantAlerts !== "boolean")
|
|
170
|
+
fail("instantAlerts must be a boolean");
|
|
171
|
+
const instantAlerts = raw.instantAlerts === true;
|
|
172
|
+
if (!Array.isArray(raw.lists) || raw.lists.length === 0 || raw.lists.length > 20)
|
|
173
|
+
fail("lists must be a list of 1 to 20 lists");
|
|
174
|
+
const lists = raw.lists.map((entry, index) => resolveList(entry, index, instantAlerts));
|
|
175
|
+
const duplicates = lists.map((list) => list.id).filter((id, index, ids) => ids.indexOf(id) !== index);
|
|
176
|
+
if (duplicates.length > 0)
|
|
177
|
+
fail(`lists has duplicate ids: ${[...new Set(duplicates)].join(", ")}`);
|
|
178
|
+
const roundups = lists.filter((list) => list.kind === "roundup");
|
|
179
|
+
if (new Set(roundups.map((list) => list.archivePath)).size !== roundups.length)
|
|
180
|
+
fail("roundup lists need different archivePath values");
|
|
181
|
+
return {
|
|
182
|
+
siteId,
|
|
183
|
+
siteOrigin: origin(raw.siteOrigin),
|
|
184
|
+
computeRoleArn,
|
|
185
|
+
sendingDomain,
|
|
186
|
+
fromAddress,
|
|
187
|
+
fromName: text(raw.fromName, "fromName", 80),
|
|
188
|
+
instantAlerts,
|
|
189
|
+
theme: resolveTheme(raw.theme),
|
|
190
|
+
lists,
|
|
191
|
+
itemUrlStyle: itemUrlStyle(raw.itemUrlStyle),
|
|
192
|
+
configurationSet: matching(raw.configurationSet, "configurationSet", SES_NAME, "an SES configuration set name", `papyrus-${siteId}`),
|
|
193
|
+
eventTopicName: matching(raw.eventTopicName, "eventTopicName", SES_NAME, "an SNS topic name", `papyrus-newsletter-events-${siteId}`),
|
|
194
|
+
};
|
|
195
|
+
}
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import type { PluginRequest } from "../types";
|
|
2
|
+
|
|
3
|
+
export const NEWSLETTER_SITE_ID = /^[a-z0-9][a-z0-9-]{0,39}$/;
|
|
4
|
+
export const NEWSLETTER_LIST_ID = /^[a-z][a-z0-9-]{0,39}$/;
|
|
5
|
+
export const COMPUTE_ROLE_ARN = /^arn:aws:iam::[0-9]{12}:role\/[A-Za-z0-9+=,.@_/-]{1,512}$/;
|
|
6
|
+
const HOSTNAME = /^(?=.{1,253}$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+$/;
|
|
7
|
+
const LOCAL_PART = /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*$/;
|
|
8
|
+
const SES_NAME = /^[A-Za-z0-9_-]{1,64}$/;
|
|
9
|
+
const ISSUE_TYPE = /^[a-z][a-z0-9_]{0,59}$/;
|
|
10
|
+
/** One path segment: it is the Item section of the archive and the `urls.sections` key of the site's projection.json. */
|
|
11
|
+
const ARCHIVE_PATH = /^\/[a-z0-9][a-z0-9_-]*\/$/;
|
|
12
|
+
const SCHEDULER_CRON = /^cron\(\S+ \S+ \S+ \S+ \S+ \S+\)$/;
|
|
13
|
+
const UNSAFE_CSS = /[<>{};"\\`]|url\(|expression\(|@import/i;
|
|
14
|
+
const CONTROL_CHARACTERS = /[\u0000-\u001f\u007f]/;
|
|
15
|
+
|
|
16
|
+
export const ITEM_URL_STYLES = ["html", "directory", "clean"] as const;
|
|
17
|
+
export type ItemUrlStyle = (typeof ITEM_URL_STYLES)[number];
|
|
18
|
+
|
|
19
|
+
export type NewsletterTheme = {
|
|
20
|
+
accent: string;
|
|
21
|
+
text: string;
|
|
22
|
+
background: string;
|
|
23
|
+
surface?: string;
|
|
24
|
+
muted?: string;
|
|
25
|
+
fontFamily?: string;
|
|
26
|
+
logoUrl?: string;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export type NewsletterRule = { sections?: string[]; tags?: string[]; types?: string[] };
|
|
30
|
+
|
|
31
|
+
type ListBase = { id: string; name: string; description: string };
|
|
32
|
+
export type RoundupList = ListBase & {
|
|
33
|
+
kind: "roundup";
|
|
34
|
+
/** EventBridge Scheduler cron for assembling the draft, and the IANA time zone it runs in. */
|
|
35
|
+
schedule: { draft: string; timezone: string };
|
|
36
|
+
/** The CMS item type of an issue. */
|
|
37
|
+
issueType: string;
|
|
38
|
+
/** Where the sent issue is archived, such as `/roundup/`: one path segment, also the section the issue Items are filed under. */
|
|
39
|
+
archivePath: string;
|
|
40
|
+
};
|
|
41
|
+
export type AlertList = ListBase & {
|
|
42
|
+
kind: "alert";
|
|
43
|
+
/** Which published items raise an alert. Absent or empty: every published item (an admin still approves it). */
|
|
44
|
+
rule: NewsletterRule;
|
|
45
|
+
approval: "admin" | "none";
|
|
46
|
+
};
|
|
47
|
+
export type NewsletterList = RoundupList | AlertList;
|
|
48
|
+
|
|
49
|
+
export type NewsletterConfig = {
|
|
50
|
+
/** The site id: names the key parameter, the configuration set and the event topic. Must match the sending stack's SiteId. */
|
|
51
|
+
siteId: string;
|
|
52
|
+
/** The site's public https origin: confirmation links point at `<siteOrigin>/api/newsletter/confirm`. */
|
|
53
|
+
siteOrigin: string;
|
|
54
|
+
/** The IAM role of the CMS app's server runtime (the `CmsComputeRoleArn` output of the app-shell stack): the only caller of the function. */
|
|
55
|
+
computeRoleArn: string;
|
|
56
|
+
sendingDomain: string;
|
|
57
|
+
fromAddress: string;
|
|
58
|
+
fromName: string;
|
|
59
|
+
/** A site must set this to true before any list may send without approval. */
|
|
60
|
+
instantAlerts: boolean;
|
|
61
|
+
theme: NewsletterTheme;
|
|
62
|
+
lists: NewsletterList[];
|
|
63
|
+
/** How the site addresses its item pages (`urls.style` in projection.json): roundup drafts link to published items with it. */
|
|
64
|
+
itemUrlStyle: ItemUrlStyle;
|
|
65
|
+
/** `papyrus-<siteId>` unless overridden. */
|
|
66
|
+
configurationSet: string;
|
|
67
|
+
/** `papyrus-newsletter-events-<siteId>` unless overridden. */
|
|
68
|
+
eventTopicName: string;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const KNOWN_KEYS = new Set([
|
|
72
|
+
"name", "siteId", "siteOrigin", "computeRoleArn", "sendingDomain", "fromAddress", "fromName", "instantAlerts", "theme", "lists",
|
|
73
|
+
"configurationSet", "eventTopicName", "itemUrlStyle",
|
|
74
|
+
]);
|
|
75
|
+
const LIST_KEYS = {
|
|
76
|
+
roundup: ["id", "name", "description", "kind", "schedule", "issueType", "archivePath"],
|
|
77
|
+
alert: ["id", "name", "description", "kind", "rule", "approval"],
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
function fail(message: string): never {
|
|
81
|
+
throw new Error(`newsletter plugin ${message}`);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function record(raw: unknown, label: string, known: string[]): Record<string, unknown> {
|
|
85
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) fail(`${label} must be an object`);
|
|
86
|
+
const unknown = Object.keys(raw).filter((key) => !known.includes(key));
|
|
87
|
+
if (unknown.length > 0) fail(`${label} has unknown settings: ${unknown.join(", ")}`);
|
|
88
|
+
return raw as Record<string, unknown>;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function text(raw: unknown, label: string, maximum: number, options: { optional?: boolean; fallback?: string } = {}): string {
|
|
92
|
+
const value = raw === undefined ? options.fallback : raw;
|
|
93
|
+
if (value === undefined) fail(`${label} is required`);
|
|
94
|
+
if (typeof value !== "string" || CONTROL_CHARACTERS.test(value) || value.trim() !== value) {
|
|
95
|
+
fail(`${label} must be text on one line with no leading or trailing spaces`);
|
|
96
|
+
}
|
|
97
|
+
if (value.length === 0 && !options.optional) fail(`${label} is required`);
|
|
98
|
+
if (value.length > maximum) fail(`${label} must be at most ${maximum} characters`);
|
|
99
|
+
return value;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function matching(raw: unknown, label: string, pattern: RegExp, description: string, fallback?: string): string {
|
|
103
|
+
const value = raw === undefined ? fallback : raw;
|
|
104
|
+
if (typeof value !== "string" || !pattern.test(value)) fail(`${label} must be ${description}`);
|
|
105
|
+
return value;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function timeZone(raw: unknown, label: string): string {
|
|
109
|
+
const value = text(raw, label, 64);
|
|
110
|
+
try {
|
|
111
|
+
new Intl.DateTimeFormat("en-US", { timeZone: value });
|
|
112
|
+
} catch {
|
|
113
|
+
fail(`${label} must be an IANA time zone such as America/New_York`);
|
|
114
|
+
}
|
|
115
|
+
return value;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function origin(raw: unknown): string {
|
|
119
|
+
const value = text(raw, "siteOrigin", 200);
|
|
120
|
+
let parsed: URL | undefined;
|
|
121
|
+
try {
|
|
122
|
+
parsed = new URL(value);
|
|
123
|
+
} catch {
|
|
124
|
+
parsed = undefined;
|
|
125
|
+
}
|
|
126
|
+
if (!parsed || parsed.protocol !== "https:" || parsed.origin !== value) fail("siteOrigin must be an https origin such as https://example.com with no path");
|
|
127
|
+
return value;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function stringList(raw: unknown, label: string): string[] | undefined {
|
|
131
|
+
if (raw === undefined) return undefined;
|
|
132
|
+
if (!Array.isArray(raw) || raw.length === 0 || raw.length > 50) fail(`${label} must be a list of 1 to 50 names`);
|
|
133
|
+
return [...new Set(raw.map((entry, index) => text(entry, `${label}[${index}]`, 80)))];
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function itemUrlStyle(raw: unknown): ItemUrlStyle {
|
|
137
|
+
if (raw === undefined) return "html";
|
|
138
|
+
if (typeof raw !== "string" || !(ITEM_URL_STYLES as readonly string[]).includes(raw)) fail(`itemUrlStyle must be one of ${ITEM_URL_STYLES.join(", ")}`);
|
|
139
|
+
return raw as ItemUrlStyle;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function resolveTheme(raw: unknown): NewsletterTheme {
|
|
143
|
+
const theme = record(raw, "theme", ["accent", "text", "background", "surface", "muted", "fontFamily", "logoUrl"]);
|
|
144
|
+
const resolved: NewsletterTheme = {
|
|
145
|
+
accent: text(theme.accent, "theme.accent", 80),
|
|
146
|
+
text: text(theme.text, "theme.text", 80),
|
|
147
|
+
background: text(theme.background, "theme.background", 80),
|
|
148
|
+
};
|
|
149
|
+
for (const key of ["surface", "muted", "fontFamily"] as const) {
|
|
150
|
+
if (theme[key] !== undefined) resolved[key] = text(theme[key], `theme.${key}`, 200);
|
|
151
|
+
}
|
|
152
|
+
for (const [key, value] of Object.entries(resolved)) {
|
|
153
|
+
if (UNSAFE_CSS.test(value)) fail(`theme.${key} contains characters that are not allowed in a style value`);
|
|
154
|
+
}
|
|
155
|
+
if (theme.logoUrl !== undefined) {
|
|
156
|
+
const logoUrl = text(theme.logoUrl, "theme.logoUrl", 500);
|
|
157
|
+
if (!/^https:\/\//.test(logoUrl)) fail("theme.logoUrl must be an https URL");
|
|
158
|
+
resolved.logoUrl = logoUrl;
|
|
159
|
+
}
|
|
160
|
+
return resolved;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function resolveRule(raw: unknown, label: string): NewsletterRule {
|
|
164
|
+
if (raw === undefined) return {};
|
|
165
|
+
const rule = record(raw, label, ["sections", "tags", "types"]);
|
|
166
|
+
return {
|
|
167
|
+
...(rule.sections === undefined ? {} : { sections: stringList(rule.sections, `${label}.sections`) }),
|
|
168
|
+
...(rule.tags === undefined ? {} : { tags: stringList(rule.tags, `${label}.tags`) }),
|
|
169
|
+
...(rule.types === undefined ? {} : { types: stringList(rule.types, `${label}.types`) }),
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function resolveList(raw: unknown, index: number, instantAlerts: boolean): NewsletterList {
|
|
174
|
+
const label = `lists[${index}]`;
|
|
175
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) fail(`${label} must be an object`);
|
|
176
|
+
const kind = (raw as Record<string, unknown>).kind;
|
|
177
|
+
if (kind !== "roundup" && kind !== "alert") fail(`${label}.kind must be "roundup" or "alert"`);
|
|
178
|
+
const list = record(raw, label, LIST_KEYS[kind]);
|
|
179
|
+
const base = {
|
|
180
|
+
id: matching(list.id, `${label}.id`, NEWSLETTER_LIST_ID, "lowercase letters, digits and hyphens, starting with a letter (at most 40 characters)"),
|
|
181
|
+
name: text(list.name, `${label}.name`, 80),
|
|
182
|
+
description: text(list.description, `${label}.description`, 300, { optional: true, fallback: "" }),
|
|
183
|
+
};
|
|
184
|
+
if (kind === "roundup") {
|
|
185
|
+
const schedule = record(list.schedule, `${label}.schedule`, ["draft", "timezone"]);
|
|
186
|
+
return {
|
|
187
|
+
...base,
|
|
188
|
+
kind,
|
|
189
|
+
schedule: {
|
|
190
|
+
draft: matching(schedule.draft, `${label}.schedule.draft`, SCHEDULER_CRON, 'an EventBridge Scheduler cron such as "cron(0 13 ? * FRI *)"'),
|
|
191
|
+
timezone: timeZone(schedule.timezone, `${label}.schedule.timezone`),
|
|
192
|
+
},
|
|
193
|
+
issueType: matching(list.issueType, `${label}.issueType`, ISSUE_TYPE, "a lowercase item type name", "newsletter_issue"),
|
|
194
|
+
archivePath: matching(list.archivePath, `${label}.archivePath`, ARCHIVE_PATH, 'a path that starts and ends with "/", such as /roundup/'),
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
const approval = list.approval === undefined ? "admin" : list.approval;
|
|
198
|
+
if (approval !== "admin" && approval !== "none") fail(`${label}.approval must be "admin" or "none"`);
|
|
199
|
+
if (approval === "none" && !instantAlerts) {
|
|
200
|
+
fail(`${label}.approval "none" sends alerts without an admin approving them: set instantAlerts: true on the plugin first`);
|
|
201
|
+
}
|
|
202
|
+
return { ...base, kind, rule: resolveRule(list.rule, `${label}.rule`), approval };
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export function resolveNewsletterConfig(request: PluginRequest): NewsletterConfig {
|
|
206
|
+
const raw = record(typeof request === "string" ? { name: request } : request, "settings", [...KNOWN_KEYS]);
|
|
207
|
+
const siteId = matching(raw.siteId, "siteId", NEWSLETTER_SITE_ID, "a lowercase site id (letters, digits, hyphens), the SiteId of the sending stack");
|
|
208
|
+
const computeRoleArn = raw.computeRoleArn;
|
|
209
|
+
if (typeof computeRoleArn !== "string" || !COMPUTE_ROLE_ARN.test(computeRoleArn)) {
|
|
210
|
+
fail("computeRoleArn must be the IAM role ARN of the CMS app's compute role (the CmsComputeRoleArn output)");
|
|
211
|
+
}
|
|
212
|
+
const sendingDomain = matching(raw.sendingDomain, "sendingDomain", HOSTNAME, "a lowercase domain name such as news.example.com");
|
|
213
|
+
const fromAddress = text(raw.fromAddress, "fromAddress", 254);
|
|
214
|
+
const [local, domain, ...extra] = fromAddress.split("@");
|
|
215
|
+
if (extra.length > 0 || !local || local.length > 64 || !LOCAL_PART.test(local) || domain !== sendingDomain) {
|
|
216
|
+
fail(`fromAddress must be an address on ${sendingDomain} (lowercase, such as newsletter@${sendingDomain})`);
|
|
217
|
+
}
|
|
218
|
+
if (raw.instantAlerts !== undefined && typeof raw.instantAlerts !== "boolean") fail("instantAlerts must be a boolean");
|
|
219
|
+
const instantAlerts = raw.instantAlerts === true;
|
|
220
|
+
if (!Array.isArray(raw.lists) || raw.lists.length === 0 || raw.lists.length > 20) fail("lists must be a list of 1 to 20 lists");
|
|
221
|
+
const lists = raw.lists.map((entry, index) => resolveList(entry, index, instantAlerts));
|
|
222
|
+
const duplicates = lists.map((list) => list.id).filter((id, index, ids) => ids.indexOf(id) !== index);
|
|
223
|
+
if (duplicates.length > 0) fail(`lists has duplicate ids: ${[...new Set(duplicates)].join(", ")}`);
|
|
224
|
+
const roundups = lists.filter((list) => list.kind === "roundup");
|
|
225
|
+
if (new Set(roundups.map((list) => (list as RoundupList).archivePath)).size !== roundups.length) fail("roundup lists need different archivePath values");
|
|
226
|
+
return {
|
|
227
|
+
siteId,
|
|
228
|
+
siteOrigin: origin(raw.siteOrigin),
|
|
229
|
+
computeRoleArn,
|
|
230
|
+
sendingDomain,
|
|
231
|
+
fromAddress,
|
|
232
|
+
fromName: text(raw.fromName, "fromName", 80),
|
|
233
|
+
instantAlerts,
|
|
234
|
+
theme: resolveTheme(raw.theme),
|
|
235
|
+
lists,
|
|
236
|
+
itemUrlStyle: itemUrlStyle(raw.itemUrlStyle),
|
|
237
|
+
configurationSet: matching(raw.configurationSet, "configurationSet", SES_NAME, "an SES configuration set name", `papyrus-${siteId}`),
|
|
238
|
+
eventTopicName: matching(raw.eventTopicName, "eventTopicName", SES_NAME, "an SNS topic name", `papyrus-newsletter-events-${siteId}`),
|
|
239
|
+
};
|
|
240
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"""Bundle entry kept for the shared Python bundler, which copies ``handler.py`` to the asset root.
|
|
2
|
+
|
|
3
|
+
The Lambda's handler is ``papyrus_content.newsletter.handler.handler`` (src/papyrus_content/newsletter/handler.py).
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from papyrus_content.newsletter.handler import handler # noqa: F401
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"""Bundle entry for the newsroom's newsletter operations (AppSync): forwards to the ``newsletter`` function.
|
|
2
|
+
|
|
3
|
+
The logic is ``papyrus_content.newsletter.ops_proxy`` (src/papyrus_content/newsletter/ops_proxy.py).
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from papyrus_content.newsletter.ops_proxy import handle
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def handler(event: dict[str, Any], _context: Any = None) -> Any:
|
|
12
|
+
return handle(event)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { defineFunction } from "@aws-amplify/backend";
|
|
2
|
+
import { Duration } from "aws-cdk-lib";
|
|
3
|
+
import { Architecture, Function, Runtime } from "aws-cdk-lib/aws-lambda";
|
|
4
|
+
import { pythonLambdaCode } from "../../../functions/shared/python-bundle.js";
|
|
5
|
+
/** AppSync gives a resolver 30 seconds; this function only forwards to `newsletter`, which answers in a few. */
|
|
6
|
+
export const NEWSLETTER_OPS_TIMEOUT_SECONDS = 25;
|
|
7
|
+
/**
|
|
8
|
+
* The newsroom's newsletter operations enter here because an Amplify custom operation needs an Amplify-defined function and
|
|
9
|
+
* the `newsletter` function itself lives in the plugin stack. It holds no data access: it may invoke that one function.
|
|
10
|
+
*/
|
|
11
|
+
export const newsletterOps = defineFunction((scope) => new Function(scope, "papyrus-newsletter-ops", {
|
|
12
|
+
runtime: Runtime.PYTHON_3_12,
|
|
13
|
+
architecture: Architecture.ARM_64,
|
|
14
|
+
handler: "handler.handler",
|
|
15
|
+
timeout: Duration.seconds(NEWSLETTER_OPS_TIMEOUT_SECONDS),
|
|
16
|
+
memorySize: 256,
|
|
17
|
+
code: pythonLambdaCode({ functionDir: "../plugins/newsletter/ops", modules: ["papyrus_content"], noDeps: true }, [
|
|
18
|
+
"bash",
|
|
19
|
+
"-c",
|
|
20
|
+
[
|
|
21
|
+
"set -euo pipefail",
|
|
22
|
+
"mkdir -p /asset-output/papyrus_content",
|
|
23
|
+
"cp amplify/plugins/newsletter/ops/handler.py /asset-output/handler.py",
|
|
24
|
+
"cp -R src/papyrus_content/. /asset-output/papyrus_content/",
|
|
25
|
+
].join(" && "),
|
|
26
|
+
]),
|
|
27
|
+
}), { resourceGroupName: "data" });
|