@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.
- package/amplify/data/resource.js +23 -3
- package/amplify/data/resource.ts +25 -3
- package/amplify/data/schema.js +2028 -1979
- package/amplify/data/schema.ts +72 -14
- package/amplify/functions/assignment-action/data-access.js +90 -0
- package/amplify/functions/assignment-action/data-access.ts +89 -0
- package/amplify/functions/assignment-action/handler.ts +1 -1
- package/amplify/functions/content-actions/handler.py +61 -2
- package/amplify/functions/content-actions/requirements.txt +1 -0
- package/amplify/functions/content-actions/resource.js +1 -1
- package/amplify/functions/content-actions/resource.ts +1 -1
- package/amplify/functions/editorial-checks/handler.py +14 -0
- package/amplify/functions/editorial-checks/requirements.txt +1 -0
- package/amplify/{plugins/editorial-checks/function → functions/editorial-checks}/resource.js +7 -7
- package/amplify/{plugins/editorial-checks/function → functions/editorial-checks}/resource.ts +7 -7
- package/amplify/functions/editorial-checks/schema.js +121 -0
- package/amplify/{plugins → functions}/editorial-checks/schema.ts +33 -6
- package/amplify/functions/editorial-checks/wire.js +53 -0
- package/amplify/functions/editorial-checks/wire.ts +61 -0
- package/amplify/functions/monitoring-view/handler.py +11 -0
- package/amplify/functions/monitoring-view/resource.js +24 -0
- package/amplify/functions/monitoring-view/resource.ts +34 -0
- package/amplify/functions/monitoring-view/schema.js +16 -0
- package/amplify/functions/monitoring-view/schema.ts +18 -0
- package/amplify/functions/monitoring-view/wire.js +37 -0
- package/amplify/functions/monitoring-view/wire.ts +47 -0
- package/amplify/functions/public-forms/core.js +247 -0
- package/amplify/functions/public-forms/core.ts +310 -0
- package/amplify/functions/public-forms/handler.ts +41 -0
- package/amplify/functions/public-forms/origins.js +35 -0
- package/amplify/functions/public-forms/origins.ts +43 -0
- package/amplify/functions/public-forms/resource.js +9 -0
- package/amplify/functions/public-forms/resource.ts +10 -0
- package/amplify/functions/public-forms/wire.js +25 -0
- package/amplify/functions/public-forms/wire.ts +32 -0
- package/amplify/functions/shared/editorial-context.ts +63 -4
- package/amplify/functions/shared/python-bundle.js +20 -14
- package/amplify/functions/shared/python-bundle.ts +25 -18
- package/amplify/plugins/newsletter/config.js +245 -0
- package/amplify/plugins/newsletter/config.ts +305 -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 +263 -0
- package/amplify/plugins/newsletter/papyrus.plugin.ts +311 -0
- package/amplify/plugins/newsletter/schema.js +56 -0
- package/amplify/plugins/newsletter/schema.ts +61 -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 +140 -0
- package/amplify/plugins/newsletter/sending.ts +186 -0
- package/amplify/plugins/reader-steering/config.js +173 -0
- package/amplify/plugins/reader-steering/config.ts +268 -0
- package/amplify/plugins/reader-steering/function/ai_moderation.py +246 -0
- package/amplify/plugins/reader-steering/function/handler.py +1363 -0
- 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 +27 -0
- package/amplify/plugins/reader-steering/function/resource.ts +35 -0
- package/amplify/plugins/reader-steering/papyrus.plugin.js +176 -0
- package/amplify/plugins/reader-steering/papyrus.plugin.ts +202 -0
- package/amplify/plugins/reader-steering/schema.js +140 -0
- package/amplify/plugins/reader-steering/schema.ts +142 -0
- package/amplify/plugins/registry.js +4 -2
- package/amplify/plugins/registry.ts +4 -2
- package/amplify/plugins/types.ts +5 -0
- package/amplify/plugins/wire.js +1 -0
- package/amplify/plugins/wire.ts +1 -0
- package/amplify/publication/projection-lease.js +30 -0
- package/amplify/publication/projection-lease.ts +39 -0
- package/amplify/publication/redirect-and-index.js +105 -0
- package/amplify/publication/redirect-rules.js +73 -0
- package/amplify/publication/redirect-rules.ts +93 -0
- package/amplify/publication/s3-projection.js +7 -1
- package/amplify/publication/s3-projection.ts +9 -1
- package/amplify/site-backend-config.ts +17 -0
- package/amplify/site-backend.js +38 -1
- package/amplify/site-backend.ts +46 -1
- package/app/api/auth/prospectus/sign-in/route.ts +4 -0
- package/app/api/newsletter/confirm/route.ts +13 -0
- package/app/api/newsletter/preferences/route.ts +13 -0
- package/app/api/newsletter/state/route.ts +9 -0
- package/app/api/newsletter/subscribe/route.ts +9 -0
- package/app/api/newsletter/unsubscribe/route.ts +13 -0
- package/app/api/newsroom/curation/context/route.ts +9 -0
- package/app/api/newsroom/curation/priming/route.ts +9 -0
- package/app/api/newsroom/curation/publication/route.ts +9 -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/handle/route.ts +9 -0
- package/app/api/reader/me/route.ts +9 -0
- package/app/api/reader/rating/route.ts +9 -0
- package/app/api/reader/report/route.ts +9 -0
- package/app/api/reader/retired/route.ts +9 -0
- package/app/api/reader/submit/route.ts +9 -0
- package/app/api/reader/vote/route.ts +9 -0
- package/bin/papyrus-infra.mjs +20 -1
- package/components/editorial-checks-admin-panel.tsx +36 -11
- package/components/moderation-panel.tsx +248 -0
- package/components/monitoring-overview-view.tsx +241 -0
- package/components/monitoring-panel.tsx +40 -0
- package/components/newsletter-panel.tsx +474 -0
- package/components/newsletter-sections.tsx +163 -0
- package/components/newsroom-article-editor.tsx +2 -4
- package/components/newsroom-curation-bootstrap.tsx +45 -0
- package/components/newsroom-organizer.css +31 -0
- package/components/newsroom-references-view.tsx +14 -14
- package/components/publication-cyclotron-panel.tsx +15 -10
- package/components/reference-add-entry.tsx +75 -0
- package/components/reference-curation-controls.tsx +31 -22
- package/components/reference-cyclotron-priming.tsx +58 -19
- package/components/reference-cyclotron-suggestion.tsx +1 -1
- package/components/reference-priming.tsx +14 -10
- package/components/reference-section-suggestion.tsx +1 -1
- package/components/topic-steering-workspace.tsx +64 -20
- package/components/use-editorial-checks.ts +12 -10
- package/infra/amplify-app-shell.js +90 -16
- package/infra/amplify-app-shell.ts +102 -18
- package/infra/index.js +1 -0
- package/infra/secure-string-parameter-handler.js +41 -0
- package/infra/secure-string-parameter-handler.ts +41 -0
- package/infra/secure-string-parameter.js +79 -0
- package/infra/secure-string-parameter.ts +91 -0
- package/infra/site-config.js +86 -6
- package/infra/site-config.ts +129 -6
- package/lib/category-repository.ts +11 -9
- package/lib/curation-routes.ts +345 -0
- package/lib/editorial-checks-backend.ts +1 -1
- package/lib/editorial-checks-client.ts +19 -1
- package/lib/editorial-checks-demo.ts +2 -2
- package/lib/editorial-checks-settings.ts +3 -0
- package/lib/editorial-checks.ts +8 -11
- package/lib/editorial-preview.ts +5 -5
- package/lib/monitoring-client.ts +29 -0
- package/lib/monitoring-overview-fixture.ts +51 -0
- package/lib/monitoring-overview.ts +145 -0
- package/lib/newsletter-api.ts +418 -0
- package/lib/newsletter-client.ts +46 -0
- package/lib/newsletter-fixture.ts +184 -0
- package/lib/newsletter-model.ts +202 -0
- package/lib/prospectus-session.ts +15 -14
- package/lib/prospectus-sign-in-routes.ts +84 -19
- package/lib/prospectus-site-identity.ts +24 -1
- package/lib/reader-api.ts +145 -0
- package/lib/reader-moderation.ts +220 -0
- package/lib/reader-retirement-route.ts +89 -0
- package/lib/reader-subject.md +29 -0
- package/lib/reader-subject.ts +53 -0
- package/lib/relevance-status.ts +2 -2
- package/lib/semantic-graph.ts +2 -0
- package/lib/site-brand-tenant.ts +11 -6
- package/lib/site-brand.ts +6 -3
- package/lib/site-origin.ts +67 -0
- package/middleware.ts +14 -3
- package/package.json +41 -3
- package/routes.manifest.json +204 -2
- package/amplify/plugins/editorial-checks/function/handler.py +0 -11
- package/amplify/plugins/editorial-checks/function/requirements.txt +0 -1
- package/amplify/plugins/editorial-checks/papyrus.plugin.js +0 -50
- package/amplify/plugins/editorial-checks/papyrus.plugin.ts +0 -63
- package/amplify/plugins/editorial-checks/schema.js +0 -94
|
@@ -12,6 +12,9 @@ async function lookUpRedirectTarget(uri) {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
function rewriteToIndexDocument(uri) {
|
|
15
|
+
if (uri === "/404") {
|
|
16
|
+
return "/404.html";
|
|
17
|
+
}
|
|
15
18
|
if (uri.endsWith("/")) {
|
|
16
19
|
return uri + "index.html";
|
|
17
20
|
}
|
|
@@ -22,6 +25,88 @@ function rewriteToIndexDocument(uri) {
|
|
|
22
25
|
return uri;
|
|
23
26
|
}
|
|
24
27
|
|
|
28
|
+
// Pattern redirects: data from the site's projection.json, spliced between the markers at deploy
|
|
29
|
+
// time by redirect-rules.ts. Each rule is {p: regex, t: target with $1..$9, s: status, x: excluded paths}.
|
|
30
|
+
const patternRules = /*PAPYRUS_PATTERN_RULES*/[]/*END_PAPYRUS_PATTERN_RULES*/;
|
|
31
|
+
|
|
32
|
+
function lookUpPatternRedirect(uri) {
|
|
33
|
+
for (let index = 0; index < patternRules.length; index += 1) {
|
|
34
|
+
const rule = patternRules[index];
|
|
35
|
+
if (rule.x.indexOf(uri) !== -1) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
const match = new RegExp(rule.p).exec(uri);
|
|
39
|
+
if (match !== null) {
|
|
40
|
+
return {
|
|
41
|
+
status: rule.s,
|
|
42
|
+
target: rule.t.replace(/\$([0-9])/g, function (whole, group) {
|
|
43
|
+
return match[Number(group)] || "";
|
|
44
|
+
}),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Content negotiation for agents: when the site publishes Markdown twins (standard front end, agents.markdown), a request
|
|
52
|
+
// whose Accept header prefers text/markdown over text/html is rewritten to the .md object before the cache lookup. The
|
|
53
|
+
// flag is spliced in by redirect-rules.ts at deploy time.
|
|
54
|
+
const negotiateMarkdown = /*PAPYRUS_NEGOTIATE_MARKDOWN*/false/*END_PAPYRUS_NEGOTIATE_MARKDOWN*/;
|
|
55
|
+
|
|
56
|
+
function qualityOf(accept, mediaType) {
|
|
57
|
+
let quality = 0;
|
|
58
|
+
const parts = accept.toLowerCase().split(",");
|
|
59
|
+
for (let index = 0; index < parts.length; index += 1) {
|
|
60
|
+
const fields = parts[index].split(";");
|
|
61
|
+
if (fields[0].trim() !== mediaType) {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
quality = 1;
|
|
65
|
+
for (let field = 1; field < fields.length; field += 1) {
|
|
66
|
+
const pair = fields[field].trim();
|
|
67
|
+
if (pair.indexOf("q=") === 0) {
|
|
68
|
+
quality = Number(pair.substring(2));
|
|
69
|
+
if (isNaN(quality)) {
|
|
70
|
+
quality = 0;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return quality;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function prefersMarkdown(request) {
|
|
79
|
+
const header = request.headers && request.headers.accept;
|
|
80
|
+
if (!header || !header.value) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
const markdown = qualityOf(header.value, "text/markdown");
|
|
84
|
+
return markdown > 0 && markdown > qualityOf(header.value, "text/html");
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function markdownTwin(uri) {
|
|
88
|
+
if (uri === "/404.html" || uri.length < 6 || uri.substring(uri.length - 5) !== ".html") {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
return uri.substring(0, uri.length - 5) + ".md";
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Directory-style sites keep a page's twin at /x/index.md, so a bare /x.md is rewritten there. The edge cannot test for
|
|
95
|
+
// existence, hence the rule: a last segment <name>.md with a name other than index. A path prefix (a base path) is just
|
|
96
|
+
// part of <path>. The flag is spliced in by redirect-rules.ts at deploy time from urls.style.
|
|
97
|
+
const directoryTwins = /*PAPYRUS_DIRECTORY_TWINS*/false/*END_PAPYRUS_DIRECTORY_TWINS*/;
|
|
98
|
+
|
|
99
|
+
function directoryTwin(uri) {
|
|
100
|
+
if (uri.length < 5 || uri.substring(uri.length - 3) !== ".md") {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
const lastSegment = uri.substring(uri.lastIndexOf("/") + 1);
|
|
104
|
+
if (lastSegment === "index.md" || lastSegment === ".md") {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
return uri.substring(0, uri.length - 3) + "/index.md";
|
|
108
|
+
}
|
|
109
|
+
|
|
25
110
|
async function handler(event) {
|
|
26
111
|
const request = event.request;
|
|
27
112
|
const redirectTarget = await lookUpRedirectTarget(request.uri);
|
|
@@ -32,6 +117,26 @@ async function handler(event) {
|
|
|
32
117
|
headers: { location: { value: redirectTarget } },
|
|
33
118
|
};
|
|
34
119
|
}
|
|
120
|
+
const patternRedirect = lookUpPatternRedirect(request.uri);
|
|
121
|
+
if (patternRedirect !== null) {
|
|
122
|
+
return {
|
|
123
|
+
statusCode: patternRedirect.status,
|
|
124
|
+
statusDescription: "Moved",
|
|
125
|
+
headers: { location: { value: patternRedirect.target } },
|
|
126
|
+
};
|
|
127
|
+
}
|
|
35
128
|
request.uri = rewriteToIndexDocument(request.uri);
|
|
129
|
+
if (directoryTwins) {
|
|
130
|
+
const bareTwin = directoryTwin(request.uri);
|
|
131
|
+
if (bareTwin !== null) {
|
|
132
|
+
request.uri = bareTwin;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (negotiateMarkdown && prefersMarkdown(request)) {
|
|
136
|
+
const twin = markdownTwin(request.uri);
|
|
137
|
+
if (twin !== null) {
|
|
138
|
+
request.uri = twin;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
36
141
|
return request;
|
|
37
142
|
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
/** Mirrors DIRECTORY_HTML_PATTERN and DIRECTORY_SLASH_PATTERN in standard/config.py. */
|
|
4
|
+
const DIRECTORY_HTML_PATTERN = "^/(?!(?:.*/)?index\\.html$)(.+)\\.html$";
|
|
5
|
+
const DIRECTORY_SLASH_PATTERN = "^/((?:[^/]+/)*[^/.]+)$";
|
|
6
|
+
const START_MARKER = "/*PAPYRUS_PATTERN_RULES*/";
|
|
7
|
+
const END_MARKER = "/*END_PAPYRUS_PATTERN_RULES*/";
|
|
8
|
+
/**
|
|
9
|
+
* The pattern rules a site declares in projection.json: its `redirects.patterns`, plus, for
|
|
10
|
+
* `urls.style: "directory"`, `/x.html` to `/x/`. Mirrors `StandardSettings.edge_rules` in Python.
|
|
11
|
+
*/
|
|
12
|
+
export function edgeRulesFromSettings(settings) {
|
|
13
|
+
const rules = (settings.redirects?.patterns ?? []).map((rule) => ({
|
|
14
|
+
p: rule.pattern,
|
|
15
|
+
t: rule.to,
|
|
16
|
+
s: rule.status ?? 301,
|
|
17
|
+
x: rule.except ?? [],
|
|
18
|
+
}));
|
|
19
|
+
if (settings.urls?.style === "directory") {
|
|
20
|
+
// /x.html to /x/ (a directory index file such as /x/index.html is served as it is), then /x to /x/.
|
|
21
|
+
rules.push({ p: DIRECTORY_HTML_PATTERN, t: "/$1/", s: 301, x: ["/404.html"] });
|
|
22
|
+
rules.push({ p: DIRECTORY_SLASH_PATTERN, t: "/$1/", s: 301, x: ["/404"] });
|
|
23
|
+
}
|
|
24
|
+
return rules;
|
|
25
|
+
}
|
|
26
|
+
/** A standard-front-end site publishes Markdown twins unless it turns `agents.markdown` off. */
|
|
27
|
+
export function negotiatesMarkdown(settings) {
|
|
28
|
+
return settings.site !== undefined && settings.agents?.markdown !== false;
|
|
29
|
+
}
|
|
30
|
+
/** A directory-style site keeps a page's Markdown twin at `/x/index.md`; the edge then serves a bare `/x.md` from there. */
|
|
31
|
+
export function usesDirectoryTwins(settings) {
|
|
32
|
+
return negotiatesMarkdown(settings) && settings.urls?.style === "directory";
|
|
33
|
+
}
|
|
34
|
+
export function readEdgeConfig(staticDir, baseDirectory = process.cwd()) {
|
|
35
|
+
if (staticDir === undefined)
|
|
36
|
+
return { rules: [], negotiateMarkdown: false, directoryTwins: false };
|
|
37
|
+
const settingsPath = resolve(baseDirectory, staticDir, "projection.json");
|
|
38
|
+
if (!existsSync(settingsPath))
|
|
39
|
+
return { rules: [], negotiateMarkdown: false, directoryTwins: false };
|
|
40
|
+
const settings = JSON.parse(readFileSync(settingsPath, "utf8"));
|
|
41
|
+
return { rules: edgeRulesFromSettings(settings), negotiateMarkdown: negotiatesMarkdown(settings), directoryTwins: usesDirectoryTwins(settings) };
|
|
42
|
+
}
|
|
43
|
+
export function readEdgeRules(staticDir, baseDirectory = process.cwd()) {
|
|
44
|
+
return readEdgeConfig(staticDir, baseDirectory).rules;
|
|
45
|
+
}
|
|
46
|
+
const NEGOTIATE_START = "/*PAPYRUS_NEGOTIATE_MARKDOWN*/";
|
|
47
|
+
const NEGOTIATE_END = "/*END_PAPYRUS_NEGOTIATE_MARKDOWN*/";
|
|
48
|
+
const TWINS_START = "/*PAPYRUS_DIRECTORY_TWINS*/";
|
|
49
|
+
const TWINS_END = "/*END_PAPYRUS_DIRECTORY_TWINS*/";
|
|
50
|
+
function spliceFlag(source, start, end, label) {
|
|
51
|
+
const from = source.indexOf(start);
|
|
52
|
+
const to = source.indexOf(end);
|
|
53
|
+
if (from === -1 || to === -1 || to < from) {
|
|
54
|
+
throw new Error(`redirect function source has no ${label} markers`);
|
|
55
|
+
}
|
|
56
|
+
return source.slice(0, from + start.length) + "true" + source.slice(to);
|
|
57
|
+
}
|
|
58
|
+
/** The CloudFront Function source with the site's pattern rules and Markdown negotiation flag spliced in. */
|
|
59
|
+
export function compileRedirectFunctionSource(source, rules, options = {}) {
|
|
60
|
+
const start = source.indexOf(START_MARKER);
|
|
61
|
+
const end = source.indexOf(END_MARKER);
|
|
62
|
+
if (start === -1 || end === -1 || end < start) {
|
|
63
|
+
throw new Error("redirect function source has no pattern-rule markers");
|
|
64
|
+
}
|
|
65
|
+
let compiled = rules.length === 0 ? source : source.slice(0, start + START_MARKER.length) + JSON.stringify(rules) + source.slice(end);
|
|
66
|
+
if (options.negotiateMarkdown === true) {
|
|
67
|
+
compiled = spliceFlag(compiled, NEGOTIATE_START, NEGOTIATE_END, "markdown negotiation");
|
|
68
|
+
}
|
|
69
|
+
if (options.directoryTwins === true) {
|
|
70
|
+
compiled = spliceFlag(compiled, TWINS_START, TWINS_END, "directory twin");
|
|
71
|
+
}
|
|
72
|
+
return compiled;
|
|
73
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
|
|
4
|
+
/** One pattern redirect as the edge function reads it: regex, target with $1..$9, status, excluded paths. */
|
|
5
|
+
export type EdgeRedirectRule = { p: string; t: string; s: number; x: string[] };
|
|
6
|
+
|
|
7
|
+
/** Mirrors DIRECTORY_HTML_PATTERN and DIRECTORY_SLASH_PATTERN in standard/config.py. */
|
|
8
|
+
const DIRECTORY_HTML_PATTERN = "^/(?!(?:.*/)?index\\.html$)(.+)\\.html$";
|
|
9
|
+
const DIRECTORY_SLASH_PATTERN = "^/((?:[^/]+/)*[^/.]+)$";
|
|
10
|
+
|
|
11
|
+
const START_MARKER = "/*PAPYRUS_PATTERN_RULES*/";
|
|
12
|
+
const END_MARKER = "/*END_PAPYRUS_PATTERN_RULES*/";
|
|
13
|
+
|
|
14
|
+
type ProjectionRedirects = { patterns?: { pattern: string; to: string; status?: number; except?: string[] }[] };
|
|
15
|
+
type ProjectionSettings = { site?: unknown; urls?: { style?: string }; redirects?: ProjectionRedirects; agents?: { markdown?: boolean } };
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The pattern rules a site declares in projection.json: its `redirects.patterns`, plus, for
|
|
19
|
+
* `urls.style: "directory"`, `/x.html` to `/x/`. Mirrors `StandardSettings.edge_rules` in Python.
|
|
20
|
+
*/
|
|
21
|
+
export function edgeRulesFromSettings(settings: ProjectionSettings): EdgeRedirectRule[] {
|
|
22
|
+
const rules = (settings.redirects?.patterns ?? []).map((rule) => ({
|
|
23
|
+
p: rule.pattern,
|
|
24
|
+
t: rule.to,
|
|
25
|
+
s: rule.status ?? 301,
|
|
26
|
+
x: rule.except ?? [],
|
|
27
|
+
}));
|
|
28
|
+
if (settings.urls?.style === "directory") {
|
|
29
|
+
// /x.html to /x/ (a directory index file such as /x/index.html is served as it is), then /x to /x/.
|
|
30
|
+
rules.push({ p: DIRECTORY_HTML_PATTERN, t: "/$1/", s: 301, x: ["/404.html"] });
|
|
31
|
+
rules.push({ p: DIRECTORY_SLASH_PATTERN, t: "/$1/", s: 301, x: ["/404"] });
|
|
32
|
+
}
|
|
33
|
+
return rules;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** A standard-front-end site publishes Markdown twins unless it turns `agents.markdown` off. */
|
|
37
|
+
export function negotiatesMarkdown(settings: ProjectionSettings): boolean {
|
|
38
|
+
return settings.site !== undefined && settings.agents?.markdown !== false;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** A directory-style site keeps a page's Markdown twin at `/x/index.md`; the edge then serves a bare `/x.md` from there. */
|
|
42
|
+
export function usesDirectoryTwins(settings: ProjectionSettings): boolean {
|
|
43
|
+
return negotiatesMarkdown(settings) && settings.urls?.style === "directory";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export type EdgeConfig = { rules: EdgeRedirectRule[]; negotiateMarkdown: boolean; directoryTwins: boolean };
|
|
47
|
+
|
|
48
|
+
export function readEdgeConfig(staticDir: string | undefined, baseDirectory: string = process.cwd()): EdgeConfig {
|
|
49
|
+
if (staticDir === undefined) return { rules: [], negotiateMarkdown: false, directoryTwins: false };
|
|
50
|
+
const settingsPath = resolve(baseDirectory, staticDir, "projection.json");
|
|
51
|
+
if (!existsSync(settingsPath)) return { rules: [], negotiateMarkdown: false, directoryTwins: false };
|
|
52
|
+
const settings = JSON.parse(readFileSync(settingsPath, "utf8")) as ProjectionSettings;
|
|
53
|
+
return { rules: edgeRulesFromSettings(settings), negotiateMarkdown: negotiatesMarkdown(settings), directoryTwins: usesDirectoryTwins(settings) };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function readEdgeRules(staticDir: string | undefined, baseDirectory: string = process.cwd()): EdgeRedirectRule[] {
|
|
57
|
+
return readEdgeConfig(staticDir, baseDirectory).rules;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const NEGOTIATE_START = "/*PAPYRUS_NEGOTIATE_MARKDOWN*/";
|
|
61
|
+
const NEGOTIATE_END = "/*END_PAPYRUS_NEGOTIATE_MARKDOWN*/";
|
|
62
|
+
const TWINS_START = "/*PAPYRUS_DIRECTORY_TWINS*/";
|
|
63
|
+
const TWINS_END = "/*END_PAPYRUS_DIRECTORY_TWINS*/";
|
|
64
|
+
|
|
65
|
+
function spliceFlag(source: string, start: string, end: string, label: string): string {
|
|
66
|
+
const from = source.indexOf(start);
|
|
67
|
+
const to = source.indexOf(end);
|
|
68
|
+
if (from === -1 || to === -1 || to < from) {
|
|
69
|
+
throw new Error(`redirect function source has no ${label} markers`);
|
|
70
|
+
}
|
|
71
|
+
return source.slice(0, from + start.length) + "true" + source.slice(to);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** The CloudFront Function source with the site's pattern rules and Markdown negotiation flag spliced in. */
|
|
75
|
+
export function compileRedirectFunctionSource(
|
|
76
|
+
source: string,
|
|
77
|
+
rules: EdgeRedirectRule[],
|
|
78
|
+
options: { negotiateMarkdown?: boolean; directoryTwins?: boolean } = {},
|
|
79
|
+
): string {
|
|
80
|
+
const start = source.indexOf(START_MARKER);
|
|
81
|
+
const end = source.indexOf(END_MARKER);
|
|
82
|
+
if (start === -1 || end === -1 || end < start) {
|
|
83
|
+
throw new Error("redirect function source has no pattern-rule markers");
|
|
84
|
+
}
|
|
85
|
+
let compiled = rules.length === 0 ? source : source.slice(0, start + START_MARKER.length) + JSON.stringify(rules) + source.slice(end);
|
|
86
|
+
if (options.negotiateMarkdown === true) {
|
|
87
|
+
compiled = spliceFlag(compiled, NEGOTIATE_START, NEGOTIATE_END, "markdown negotiation");
|
|
88
|
+
}
|
|
89
|
+
if (options.directoryTwins === true) {
|
|
90
|
+
compiled = spliceFlag(compiled, TWINS_START, TWINS_END, "directory twin");
|
|
91
|
+
}
|
|
92
|
+
return compiled;
|
|
93
|
+
}
|
|
@@ -7,11 +7,13 @@ import { SqsDestination } from "aws-cdk-lib/aws-lambda-destinations";
|
|
|
7
7
|
import * as route53 from "aws-cdk-lib/aws-route53";
|
|
8
8
|
import * as s3 from "aws-cdk-lib/aws-s3";
|
|
9
9
|
import * as sqs from "aws-cdk-lib/aws-sqs";
|
|
10
|
+
import { readFileSync } from "node:fs";
|
|
10
11
|
import { dirname, resolve } from "node:path";
|
|
11
12
|
import { fileURLToPath } from "node:url";
|
|
12
13
|
import { assertValidPublicationConfig } from "../site-backend-config.js";
|
|
13
14
|
import { addRenditionsFunction } from "./renditions-function.js";
|
|
14
15
|
import { RENDITIONS_FUNCTION_NAME_ENV } from "./renditions-settings.js";
|
|
16
|
+
import { compileRedirectFunctionSource, readEdgeConfig } from "./redirect-rules.js";
|
|
15
17
|
import { addInvalidationPathAlarm } from "./invalidation-alarm.js";
|
|
16
18
|
import { distributionIdFromArn, s3ProjectionEnvironment, s3ProjectionPolicyStatements } from "./s3-projection-settings.js";
|
|
17
19
|
const redirectFunctionSourcePath = resolve(dirname(fileURLToPath(import.meta.url)), "redirect-and-index.js");
|
|
@@ -68,9 +70,13 @@ export function addS3ProjectionPublication(scope, props, media) {
|
|
|
68
70
|
assertValidPublicationConfig({ kind: "s3-projection", ...props });
|
|
69
71
|
const bucket = createSiteBucket(scope, props.retainBucketOnDelete !== false);
|
|
70
72
|
const keyValueStore = new cloudfront.KeyValueStore(scope, "RedirectsKeyValueStore");
|
|
73
|
+
const edgeConfig = readEdgeConfig(props.staticDir);
|
|
71
74
|
const redirectFunction = new cloudfront.Function(scope, "RedirectAndIndexFunction", {
|
|
72
75
|
runtime: cloudfront.FunctionRuntime.JS_2_0,
|
|
73
|
-
code: cloudfront.FunctionCode.
|
|
76
|
+
code: cloudfront.FunctionCode.fromInline(compileRedirectFunctionSource(readFileSync(redirectFunctionSourcePath, "utf8"), edgeConfig.rules, {
|
|
77
|
+
negotiateMarkdown: edgeConfig.negotiateMarkdown,
|
|
78
|
+
directoryTwins: edgeConfig.directoryTwins,
|
|
79
|
+
})),
|
|
74
80
|
keyValueStore,
|
|
75
81
|
});
|
|
76
82
|
const deadLetterQueue = new sqs.Queue(scope, "ProjectionDeadLetterQueue", {
|
|
@@ -10,11 +10,13 @@ import * as route53 from "aws-cdk-lib/aws-route53";
|
|
|
10
10
|
import * as s3 from "aws-cdk-lib/aws-s3";
|
|
11
11
|
import * as sqs from "aws-cdk-lib/aws-sqs";
|
|
12
12
|
import type { Construct } from "constructs";
|
|
13
|
+
import { readFileSync } from "node:fs";
|
|
13
14
|
import { dirname, resolve } from "node:path";
|
|
14
15
|
import { fileURLToPath } from "node:url";
|
|
15
16
|
import { assertValidPublicationConfig, type PapyrusPublicationConfig } from "../site-backend-config";
|
|
16
17
|
import { addRenditionsFunction, type RenditionsFunction } from "./renditions-function";
|
|
17
18
|
import { RENDITIONS_FUNCTION_NAME_ENV, type RenditionsPlan } from "./renditions-settings";
|
|
19
|
+
import { compileRedirectFunctionSource, readEdgeConfig } from "./redirect-rules";
|
|
18
20
|
import { addInvalidationPathAlarm } from "./invalidation-alarm";
|
|
19
21
|
import { distributionIdFromArn, s3ProjectionEnvironment, s3ProjectionPolicyStatements } from "./s3-projection-settings";
|
|
20
22
|
|
|
@@ -110,9 +112,15 @@ export function addS3ProjectionPublication(
|
|
|
110
112
|
const bucket = createSiteBucket(scope, props.retainBucketOnDelete !== false);
|
|
111
113
|
|
|
112
114
|
const keyValueStore = new cloudfront.KeyValueStore(scope, "RedirectsKeyValueStore");
|
|
115
|
+
const edgeConfig = readEdgeConfig(props.staticDir);
|
|
113
116
|
const redirectFunction = new cloudfront.Function(scope, "RedirectAndIndexFunction", {
|
|
114
117
|
runtime: cloudfront.FunctionRuntime.JS_2_0,
|
|
115
|
-
code: cloudfront.FunctionCode.
|
|
118
|
+
code: cloudfront.FunctionCode.fromInline(
|
|
119
|
+
compileRedirectFunctionSource(readFileSync(redirectFunctionSourcePath, "utf8"), edgeConfig.rules, {
|
|
120
|
+
negotiateMarkdown: edgeConfig.negotiateMarkdown,
|
|
121
|
+
directoryTwins: edgeConfig.directoryTwins,
|
|
122
|
+
}),
|
|
123
|
+
),
|
|
116
124
|
keyValueStore,
|
|
117
125
|
});
|
|
118
126
|
const deadLetterQueue = new sqs.Queue(scope, "ProjectionDeadLetterQueue", {
|
|
@@ -145,6 +145,13 @@ export type PapyrusSiteBackendConfig = {
|
|
|
145
145
|
* DependsOn ordering; no resource changes. Default 12; 0 turns it off.
|
|
146
146
|
*/
|
|
147
147
|
resolverWaveSize?: number;
|
|
148
|
+
/**
|
|
149
|
+
* Optional model groups to leave out of the data API (see `OPTIONAL_MODEL_GROUPS`; today `editions`).
|
|
150
|
+
* CloudFormation allows 2,500 resources per stack operation, nested stacks included, and a fresh create of the full
|
|
151
|
+
* model set exceeds it. Deploy a new site once with a group excluded, then remove the exclusion and deploy again:
|
|
152
|
+
* the second deploy is an ordinary update that adds the models.
|
|
153
|
+
*/
|
|
154
|
+
excludeModelGroups?: string[];
|
|
148
155
|
/** Static reader app (Markus-static sites) that a publish rebuilds through IAM `amplify:StartJob`. */
|
|
149
156
|
reader?: { amplifyAppId: string; branchName?: string };
|
|
150
157
|
/** Lets the newsroom start the `staging` branch build of this CMS app. */
|
|
@@ -178,6 +185,16 @@ export type PapyrusSiteBackendConfig = {
|
|
|
178
185
|
* Unset: no plugin, and the synthesized backend is exactly what it was before plugins existed.
|
|
179
186
|
*/
|
|
180
187
|
plugins?: PluginRequest[];
|
|
188
|
+
/**
|
|
189
|
+
* The public form receiving endpoint every site gets (docs/public-forms.md). It accepts posts only from the site's
|
|
190
|
+
* own public hosts (distribution aliases, reader domain, revalidate URL, sign-in redirect URLs) plus these.
|
|
191
|
+
*/
|
|
192
|
+
publicForms?: {
|
|
193
|
+
/** Extra https origins (or http://localhost) allowed to post, for example `https://www.example.org`. */
|
|
194
|
+
allowedOrigins?: string[];
|
|
195
|
+
/** Extra honeypot field names besides `website`. */
|
|
196
|
+
honeypotFields?: string[];
|
|
197
|
+
};
|
|
181
198
|
features?: {
|
|
182
199
|
consoleResponder?: boolean;
|
|
183
200
|
inboundEmail?: boolean;
|
package/amplify/site-backend.js
CHANGED
|
@@ -11,6 +11,7 @@ import { resolveSitePublication } from "./publication/default-publication.js";
|
|
|
11
11
|
import { REPROJECT_ON_DEPLOY_TIMEOUT_SECONDS, addReprojectOnDeploy, reprojectDeployToken } from "./publication/reproject-on-deploy.js";
|
|
12
12
|
import { addProjectionRetries, addS3ProjectionPublication } from "./publication/s3-projection.js";
|
|
13
13
|
import { planRenditions } from "./publication/renditions-settings.js";
|
|
14
|
+
import { addProjectionLeaseAccess } from "./publication/projection-lease.js";
|
|
14
15
|
import { contentActionsPublicationWiring, planS3ProjectionBackend } from "./publication/s3-projection-settings.js";
|
|
15
16
|
import { rebuildTriggerSettings } from "./rebuild-trigger-settings.js";
|
|
16
17
|
import { assertValidPublicationConfig } from "./site-backend-config.js";
|
|
@@ -20,9 +21,14 @@ import { addInvalidationPathAlarm } from "./publication/invalidation-alarm.js";
|
|
|
20
21
|
import { applyCognitoDomainPrefix, authConfigFromEnv, defineSiteAuth, siteAuthRedirectUrls } from "./auth/resource.js";
|
|
21
22
|
import { PROSPECTUS_SIGN_IN_CALLBACK_PATH, addProspectusGoogleOnlyClient } from "./auth/prospectus-google-client.js";
|
|
22
23
|
import { defineSiteData } from "./data/resource.js";
|
|
24
|
+
import { editorialChecks } from "./functions/editorial-checks/resource.js";
|
|
25
|
+
import { monitoringView } from "./functions/monitoring-view/resource.js";
|
|
26
|
+
import { wireMonitoringView } from "./functions/monitoring-view/wire.js";
|
|
27
|
+
import { wireEditorialChecks } from "./functions/editorial-checks/wire.js";
|
|
23
28
|
import { resolvePlugins } from "./plugins/registry.js";
|
|
24
29
|
import { wirePlugins } from "./plugins/wire.js";
|
|
25
30
|
import { assignmentAction } from "./functions/assignment-action/resource.js";
|
|
31
|
+
import { scopeAssignmentDataAccess } from "./functions/assignment-action/data-access.js";
|
|
26
32
|
import { categoryAction } from "./functions/category-action/resource.js";
|
|
27
33
|
import { ConsoleChatResponderStack } from "./functions/console-chat-responder/resource.js";
|
|
28
34
|
import { contentActions, setSiteFilesForContentActionsBundle } from "./functions/content-actions/resource.js";
|
|
@@ -30,6 +36,9 @@ import { knowledgeQuery } from "./functions/knowledge-query/resource.js";
|
|
|
30
36
|
import { manageUserRole } from "./functions/manage-user-role/resource.js";
|
|
31
37
|
import { modelAttachmentUpload } from "./functions/model-attachment-upload/resource.js";
|
|
32
38
|
import { newsroomSummary } from "./functions/newsroom-summary/resource.js";
|
|
39
|
+
import { derivePublicFormOrigins } from "./functions/public-forms/origins.js";
|
|
40
|
+
import { publicForms } from "./functions/public-forms/resource.js";
|
|
41
|
+
import { wirePublicForms } from "./functions/public-forms/wire.js";
|
|
33
42
|
import { procedureAction } from "./functions/procedure-action/resource.js";
|
|
34
43
|
import { readerSettings } from "./functions/reader-settings/resource.js";
|
|
35
44
|
import { emailSubmissionProcessor } from "./functions/email-submission-processor/resource.js";
|
|
@@ -88,12 +97,15 @@ export function defineSiteBackend(papyrusSite) {
|
|
|
88
97
|
auth: defineSiteAuth(authConfig),
|
|
89
98
|
categoryAction,
|
|
90
99
|
contentActions,
|
|
91
|
-
|
|
100
|
+
editorialChecks,
|
|
101
|
+
data: defineSiteData(pluginDefinitions, site.excludeModelGroups ?? []),
|
|
92
102
|
knowledgeQuery,
|
|
93
103
|
manageUserRole,
|
|
104
|
+
monitoringView,
|
|
94
105
|
modelAttachmentUpload,
|
|
95
106
|
newsroomSummary,
|
|
96
107
|
procedureAction,
|
|
108
|
+
publicForms,
|
|
97
109
|
readerSettings,
|
|
98
110
|
emailSubmissionProcessor,
|
|
99
111
|
sesInboundReceive,
|
|
@@ -304,10 +316,19 @@ export function defineSiteBackend(papyrusSite) {
|
|
|
304
316
|
}
|
|
305
317
|
grantCorporaRead(backend.knowledgeQuery.resources.lambda);
|
|
306
318
|
grantNewsroomReadWrite(backend.assignmentAction.resources.lambda);
|
|
319
|
+
scopeAssignmentDataAccess(backend.assignmentAction.resources.lambda, backend.data.resources.graphqlApi.arn);
|
|
307
320
|
grantNewsroomReadWrite(backend.categoryAction.resources.lambda);
|
|
308
321
|
grantNewsroomReadWrite(backend.newsroomSummary.resources.lambda);
|
|
309
322
|
const contentActionsLambda = backend.contentActions.resources.lambda;
|
|
310
323
|
grantNewsroomReadWriteDelete(contentActionsLambda);
|
|
324
|
+
if ((activeBrand?.corpusKey ?? "").trim() !== "") {
|
|
325
|
+
// A deploy creates the publication's canonical corpus from the brand when the backend has none.
|
|
326
|
+
contentActionsLambda.addEnvironment("PAPYRUS_PUBLICATION_CORPUS_KEY", (activeBrand?.corpusKey ?? "").trim());
|
|
327
|
+
contentActionsLambda.addEnvironment("PAPYRUS_PUBLICATION_NAME", (activeBrand?.publicationName ?? activeBrand?.corpusKey ?? "").trim());
|
|
328
|
+
}
|
|
329
|
+
// AppSync validates the token; pending intake additionally binds its actor
|
|
330
|
+
// and publication to this deployment's pool and existing API endpoint.
|
|
331
|
+
contentActionsLambda.addEnvironment("PAPYRUS_USER_POOL_ISSUER", `https://cognito-idp.${Stack.of(contentActionsLambda).region}.amazonaws.com/${backend.auth.resources.userPool.userPoolId}`);
|
|
311
332
|
contentActionsLambda.addEnvironment("PAPYRUS_GRAPHQL_ENDPOINT", backend.data.resources.cfnResources.cfnGraphqlApi.attrGraphQlUrl);
|
|
312
333
|
contentActionsLambda.addToRolePolicy(new PolicyStatement({
|
|
313
334
|
actions: ["appsync:GraphQL"],
|
|
@@ -340,6 +361,7 @@ export function defineSiteBackend(papyrusSite) {
|
|
|
340
361
|
}
|
|
341
362
|
if (s3ProjectionPublication !== undefined) {
|
|
342
363
|
addProjectionRetries(contentActionsLambda, s3ProjectionPublication.deadLetterQueue);
|
|
364
|
+
addProjectionLeaseAccess(contentActionsLambda);
|
|
343
365
|
}
|
|
344
366
|
const publicationWiring = contentActionsPublicationWiring(s3ProjectionPublication);
|
|
345
367
|
for (const [name, value] of Object.entries(publicationWiring.environment)) {
|
|
@@ -548,8 +570,21 @@ export function defineSiteBackend(papyrusSite) {
|
|
|
548
570
|
: []),
|
|
549
571
|
],
|
|
550
572
|
}));
|
|
573
|
+
const publicFormsEndpoint = wirePublicForms(backend, {
|
|
574
|
+
allowedOrigins: derivePublicFormOrigins({
|
|
575
|
+
explicit: site.publicForms?.allowedOrigins,
|
|
576
|
+
hosts: [activeBrand?.readerDeployment?.domain, ...(publication?.distribution?.aliases ?? [])],
|
|
577
|
+
urls: [site.revalidateBaseUrl, ...siteAuthRedirectUrls(authConfig)],
|
|
578
|
+
}),
|
|
579
|
+
honeypotFields: site.publicForms?.honeypotFields,
|
|
580
|
+
});
|
|
551
581
|
backend.addOutput({
|
|
552
582
|
custom: {
|
|
583
|
+
publicForms: { endpoint: publicFormsEndpoint },
|
|
584
|
+
// Lets the operator CLI re-project on publish without PAPYRUS_PUBLICATION_KIND / PAPYRUS_CONTENT_ACTIONS_FUNCTION (PPY-0c0b75).
|
|
585
|
+
publication: s3ProjectionPublication !== undefined
|
|
586
|
+
? { kind: "s3-projection", contentActionsFunction: contentActionsLambda.functionName }
|
|
587
|
+
: null,
|
|
553
588
|
prospectusSignIn: prospectusGoogleOnlyClient
|
|
554
589
|
? { clientId: prospectusGoogleOnlyClient.ref, callbackPath: PROSPECTUS_SIGN_IN_CALLBACK_PATH }
|
|
555
590
|
: null,
|
|
@@ -584,6 +619,8 @@ export function defineSiteBackend(papyrusSite) {
|
|
|
584
619
|
: null,
|
|
585
620
|
},
|
|
586
621
|
});
|
|
622
|
+
wireEditorialChecks(backend);
|
|
623
|
+
wireMonitoringView(backend);
|
|
587
624
|
wirePlugins(backend, plugins, contentActionsLambda);
|
|
588
625
|
return backend;
|
|
589
626
|
}
|
package/amplify/site-backend.ts
CHANGED
|
@@ -14,6 +14,7 @@ import { resolveSitePublication } from "./publication/default-publication";
|
|
|
14
14
|
import { REPROJECT_ON_DEPLOY_TIMEOUT_SECONDS, addReprojectOnDeploy, reprojectDeployToken } from "./publication/reproject-on-deploy";
|
|
15
15
|
import { addProjectionRetries, addS3ProjectionPublication, type S3ProjectionPublication } from "./publication/s3-projection";
|
|
16
16
|
import { planRenditions } from "./publication/renditions-settings";
|
|
17
|
+
import { addProjectionLeaseAccess } from "./publication/projection-lease";
|
|
17
18
|
import { contentActionsPublicationWiring, planS3ProjectionBackend } from "./publication/s3-projection-settings";
|
|
18
19
|
import { rebuildTriggerSettings } from "./rebuild-trigger-settings";
|
|
19
20
|
import { assertValidPublicationConfig } from "./site-backend-config";
|
|
@@ -27,9 +28,14 @@ import { addInvalidationPathAlarm } from "./publication/invalidation-alarm";
|
|
|
27
28
|
import { applyCognitoDomainPrefix, authConfigFromEnv, defineSiteAuth, siteAuthRedirectUrls } from "./auth/resource";
|
|
28
29
|
import { PROSPECTUS_SIGN_IN_CALLBACK_PATH, addProspectusGoogleOnlyClient } from "./auth/prospectus-google-client";
|
|
29
30
|
import { defineSiteData } from "./data/resource";
|
|
31
|
+
import { editorialChecks } from "./functions/editorial-checks/resource";
|
|
32
|
+
import { monitoringView } from "./functions/monitoring-view/resource";
|
|
33
|
+
import { wireMonitoringView } from "./functions/monitoring-view/wire";
|
|
34
|
+
import { wireEditorialChecks } from "./functions/editorial-checks/wire";
|
|
30
35
|
import { resolvePlugins } from "./plugins/registry";
|
|
31
36
|
import { wirePlugins } from "./plugins/wire";
|
|
32
37
|
import { assignmentAction } from "./functions/assignment-action/resource";
|
|
38
|
+
import { scopeAssignmentDataAccess } from "./functions/assignment-action/data-access";
|
|
33
39
|
import { categoryAction } from "./functions/category-action/resource";
|
|
34
40
|
import { ConsoleChatResponderStack } from "./functions/console-chat-responder/resource";
|
|
35
41
|
import { contentActions, setSiteFilesForContentActionsBundle } from "./functions/content-actions/resource";
|
|
@@ -37,6 +43,9 @@ import { knowledgeQuery } from "./functions/knowledge-query/resource";
|
|
|
37
43
|
import { manageUserRole } from "./functions/manage-user-role/resource";
|
|
38
44
|
import { modelAttachmentUpload } from "./functions/model-attachment-upload/resource";
|
|
39
45
|
import { newsroomSummary } from "./functions/newsroom-summary/resource";
|
|
46
|
+
import { derivePublicFormOrigins } from "./functions/public-forms/origins";
|
|
47
|
+
import { publicForms } from "./functions/public-forms/resource";
|
|
48
|
+
import { wirePublicForms } from "./functions/public-forms/wire";
|
|
40
49
|
import { procedureAction } from "./functions/procedure-action/resource";
|
|
41
50
|
import { readerSettings } from "./functions/reader-settings/resource";
|
|
42
51
|
import { emailSubmissionProcessor } from "./functions/email-submission-processor/resource";
|
|
@@ -109,12 +118,15 @@ export function defineSiteBackend(papyrusSite: PapyrusSite) {
|
|
|
109
118
|
auth: defineSiteAuth(authConfig),
|
|
110
119
|
categoryAction,
|
|
111
120
|
contentActions,
|
|
112
|
-
|
|
121
|
+
editorialChecks,
|
|
122
|
+
data: defineSiteData(pluginDefinitions, site.excludeModelGroups ?? []),
|
|
113
123
|
knowledgeQuery,
|
|
114
124
|
manageUserRole,
|
|
125
|
+
monitoringView,
|
|
115
126
|
modelAttachmentUpload,
|
|
116
127
|
newsroomSummary,
|
|
117
128
|
procedureAction,
|
|
129
|
+
publicForms,
|
|
118
130
|
readerSettings,
|
|
119
131
|
emailSubmissionProcessor,
|
|
120
132
|
sesInboundReceive,
|
|
@@ -387,10 +399,25 @@ export function defineSiteBackend(papyrusSite: PapyrusSite) {
|
|
|
387
399
|
}
|
|
388
400
|
grantCorporaRead(backend.knowledgeQuery.resources.lambda as LambdaFunction);
|
|
389
401
|
grantNewsroomReadWrite(backend.assignmentAction.resources.lambda as LambdaFunction);
|
|
402
|
+
scopeAssignmentDataAccess(
|
|
403
|
+
backend.assignmentAction.resources.lambda as LambdaFunction,
|
|
404
|
+
backend.data.resources.graphqlApi.arn,
|
|
405
|
+
);
|
|
390
406
|
grantNewsroomReadWrite(backend.categoryAction.resources.lambda as LambdaFunction);
|
|
391
407
|
grantNewsroomReadWrite(backend.newsroomSummary.resources.lambda as LambdaFunction);
|
|
392
408
|
const contentActionsLambda = backend.contentActions.resources.lambda as LambdaFunction;
|
|
393
409
|
grantNewsroomReadWriteDelete(contentActionsLambda);
|
|
410
|
+
if ((activeBrand?.corpusKey ?? "").trim() !== "") {
|
|
411
|
+
// A deploy creates the publication's canonical corpus from the brand when the backend has none.
|
|
412
|
+
contentActionsLambda.addEnvironment("PAPYRUS_PUBLICATION_CORPUS_KEY", (activeBrand?.corpusKey ?? "").trim());
|
|
413
|
+
contentActionsLambda.addEnvironment("PAPYRUS_PUBLICATION_NAME", (activeBrand?.publicationName ?? activeBrand?.corpusKey ?? "").trim());
|
|
414
|
+
}
|
|
415
|
+
// AppSync validates the token; pending intake additionally binds its actor
|
|
416
|
+
// and publication to this deployment's pool and existing API endpoint.
|
|
417
|
+
contentActionsLambda.addEnvironment(
|
|
418
|
+
"PAPYRUS_USER_POOL_ISSUER",
|
|
419
|
+
`https://cognito-idp.${Stack.of(contentActionsLambda).region}.amazonaws.com/${backend.auth.resources.userPool.userPoolId}`,
|
|
420
|
+
);
|
|
394
421
|
contentActionsLambda.addEnvironment(
|
|
395
422
|
"PAPYRUS_GRAPHQL_ENDPOINT",
|
|
396
423
|
backend.data.resources.cfnResources.cfnGraphqlApi.attrGraphQlUrl,
|
|
@@ -430,6 +457,7 @@ export function defineSiteBackend(papyrusSite: PapyrusSite) {
|
|
|
430
457
|
}
|
|
431
458
|
if (s3ProjectionPublication !== undefined) {
|
|
432
459
|
addProjectionRetries(contentActionsLambda, s3ProjectionPublication.deadLetterQueue);
|
|
460
|
+
addProjectionLeaseAccess(contentActionsLambda);
|
|
433
461
|
}
|
|
434
462
|
const publicationWiring = contentActionsPublicationWiring(s3ProjectionPublication);
|
|
435
463
|
for (const [name, value] of Object.entries(publicationWiring.environment)) {
|
|
@@ -685,8 +713,23 @@ export function defineSiteBackend(papyrusSite: PapyrusSite) {
|
|
|
685
713
|
}),
|
|
686
714
|
);
|
|
687
715
|
|
|
716
|
+
const publicFormsEndpoint = wirePublicForms(backend, {
|
|
717
|
+
allowedOrigins: derivePublicFormOrigins({
|
|
718
|
+
explicit: site.publicForms?.allowedOrigins,
|
|
719
|
+
hosts: [activeBrand?.readerDeployment?.domain, ...(publication?.distribution?.aliases ?? [])],
|
|
720
|
+
urls: [site.revalidateBaseUrl, ...siteAuthRedirectUrls(authConfig)],
|
|
721
|
+
}),
|
|
722
|
+
honeypotFields: site.publicForms?.honeypotFields,
|
|
723
|
+
});
|
|
724
|
+
|
|
688
725
|
backend.addOutput({
|
|
689
726
|
custom: {
|
|
727
|
+
publicForms: { endpoint: publicFormsEndpoint },
|
|
728
|
+
// Lets the operator CLI re-project on publish without PAPYRUS_PUBLICATION_KIND / PAPYRUS_CONTENT_ACTIONS_FUNCTION (PPY-0c0b75).
|
|
729
|
+
publication:
|
|
730
|
+
s3ProjectionPublication !== undefined
|
|
731
|
+
? { kind: "s3-projection", contentActionsFunction: contentActionsLambda.functionName }
|
|
732
|
+
: null,
|
|
690
733
|
prospectusSignIn: prospectusGoogleOnlyClient
|
|
691
734
|
? { clientId: prospectusGoogleOnlyClient.ref, callbackPath: PROSPECTUS_SIGN_IN_CALLBACK_PATH }
|
|
692
735
|
: null,
|
|
@@ -721,6 +764,8 @@ export function defineSiteBackend(papyrusSite: PapyrusSite) {
|
|
|
721
764
|
: null,
|
|
722
765
|
},
|
|
723
766
|
});
|
|
767
|
+
wireEditorialChecks(backend);
|
|
768
|
+
wireMonitoringView(backend);
|
|
724
769
|
wirePlugins(backend, plugins, contentActionsLambda);
|
|
725
770
|
|
|
726
771
|
return backend;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { NextRequest } from "next/server";
|
|
2
|
+
import { handleNewsletterConfirm } from "../../../../lib/newsletter-api";
|
|
3
|
+
|
|
4
|
+
export const dynamic = "force-dynamic";
|
|
5
|
+
export const runtime = "nodejs";
|
|
6
|
+
|
|
7
|
+
export function GET(request: NextRequest) {
|
|
8
|
+
return handleNewsletterConfirm(request);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function POST(request: NextRequest) {
|
|
12
|
+
return handleNewsletterConfirm(request);
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { NextRequest } from "next/server";
|
|
2
|
+
import { handleNewsletterPreferences } from "../../../../lib/newsletter-api";
|
|
3
|
+
|
|
4
|
+
export const dynamic = "force-dynamic";
|
|
5
|
+
export const runtime = "nodejs";
|
|
6
|
+
|
|
7
|
+
export function GET(request: NextRequest) {
|
|
8
|
+
return handleNewsletterPreferences(request);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function POST(request: NextRequest) {
|
|
12
|
+
return handleNewsletterPreferences(request);
|
|
13
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { NextRequest } from "next/server";
|
|
2
|
+
import { handleNewsletterState } from "../../../../lib/newsletter-api";
|
|
3
|
+
|
|
4
|
+
export const dynamic = "force-dynamic";
|
|
5
|
+
export const runtime = "nodejs";
|
|
6
|
+
|
|
7
|
+
export function GET(request: NextRequest) {
|
|
8
|
+
return handleNewsletterState(request);
|
|
9
|
+
}
|