@anthusai/papyrus 1.0.0-next.9 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/amplify/auth/prospectus-google-client.js +66 -0
- package/amplify/auth/prospectus-google-client.ts +71 -0
- package/amplify/auth/redirect-urls.js +54 -0
- package/amplify/auth/redirect-urls.ts +66 -0
- package/amplify/auth/resource.js +23 -5
- package/amplify/auth/resource.ts +31 -5
- package/amplify/data/resource.js +42 -80
- package/amplify/data/resource.ts +42 -80
- package/amplify/data/schema.js +45 -62
- package/amplify/data/schema.ts +47 -62
- package/amplify/functions/category-action/handler.ts +5 -3
- package/amplify/functions/console-chat-responder/py/execute_tactus_runner.py +0 -10
- package/amplify/functions/console-chat-responder/resource.js +0 -7
- package/amplify/functions/console-chat-responder/resource.ts +0 -8
- package/amplify/functions/console-chat-responder/src/main.rs +0 -9
- package/amplify/functions/content-actions/handler.py +143 -1
- package/amplify/functions/content-actions/requirements.txt +2 -1
- package/amplify/functions/content-actions/resource.js +6 -1
- package/amplify/functions/content-actions/resource.ts +9 -2
- package/amplify/functions/email-submission-processor/handler.py +3 -1
- package/amplify/functions/renditions/handler.py +120 -0
- package/amplify/functions/renditions/requirements.txt +4 -0
- package/amplify/functions/ses-inbound-receive/handler.ts +32 -4
- package/amplify/functions/shared/email-submission.ts +109 -1
- package/amplify/functions/shared/python-bundle.js +42 -2
- package/amplify/functions/shared/python-bundle.ts +47 -2
- package/amplify/functions/shared/reference-curation-metadata.ts +29 -0
- package/amplify/inbound-email/ses-intake.js +86 -0
- package/amplify/inbound-email/ses-intake.ts +110 -0
- package/amplify/plugins/registry.js +19 -0
- package/amplify/plugins/registry.ts +23 -0
- package/amplify/plugins/signup/function/handler.py +200 -0
- package/amplify/plugins/signup/function/resource.js +27 -0
- package/amplify/plugins/signup/function/resource.ts +35 -0
- package/amplify/plugins/signup/papyrus.plugin.js +59 -0
- package/amplify/plugins/signup/papyrus.plugin.ts +74 -0
- package/amplify/plugins/signup/schema.js +40 -0
- package/amplify/plugins/signup/schema.ts +41 -0
- package/amplify/plugins/signup/waf.js +48 -0
- package/amplify/plugins/signup/waf.ts +51 -0
- package/amplify/plugins/types.js +1 -0
- package/amplify/plugins/types.ts +39 -0
- package/amplify/plugins/wire.js +24 -0
- package/amplify/plugins/wire.ts +26 -0
- package/amplify/publication/default-publication.js +18 -0
- package/amplify/publication/default-publication.ts +20 -0
- package/amplify/publication/invalidation-alarm.js +26 -0
- package/amplify/publication/invalidation-alarm.ts +30 -0
- package/amplify/publication/redirect-and-index.js +37 -0
- package/amplify/publication/renditions-function.js +74 -0
- package/amplify/publication/renditions-function.ts +112 -0
- package/amplify/publication/renditions-settings.js +51 -0
- package/amplify/publication/renditions-settings.ts +58 -0
- package/amplify/publication/reproject-on-deploy.js +73 -0
- package/amplify/publication/reproject-on-deploy.ts +78 -0
- package/amplify/publication/s3-projection-settings.js +67 -0
- package/amplify/publication/s3-projection-settings.ts +101 -0
- package/amplify/publication/s3-projection.js +151 -0
- package/amplify/publication/s3-projection.ts +201 -0
- package/amplify/resolver-waves.js +26 -0
- package/amplify/resolver-waves.ts +34 -0
- package/amplify/revalidate-invalidation-settings.js +30 -0
- package/amplify/revalidate-invalidation-settings.ts +35 -0
- package/amplify/revalidate-secret-policy.js +13 -0
- package/amplify/revalidate-secret-policy.ts +19 -0
- package/amplify/site-backend-config.js +65 -1
- package/amplify/site-backend-config.ts +153 -2
- package/amplify/site-backend-names.js +103 -0
- package/amplify/site-backend-names.ts +166 -0
- package/amplify/site-backend.js +150 -176
- package/amplify/site-backend.ts +189 -201
- package/amplify/storage-backups/construct.js +31 -0
- package/amplify/storage-backups/construct.ts +47 -0
- package/app/[year]/[month]/[day]/[articleSlug]/page.tsx +8 -1
- package/app/[year]/[month]/[day]/edition-route-page.tsx +2 -0
- package/app/[year]/[month]/[day]/page/[pageNumber]/page.tsx +6 -1
- package/app/[year]/[month]/[day]/page.tsx +1 -1
- package/app/[year]/[month]/[day]/section/[sectionKey]/page.tsx +6 -1
- package/app/api/archive/editions/route.ts +1 -1
- package/app/api/auth/prospectus/callback/route.ts +9 -0
- package/app/api/auth/prospectus/selection/route.ts +9 -0
- package/app/api/auth/prospectus/session/route.ts +9 -0
- package/app/api/auth/prospectus/sign-in/route.ts +9 -0
- package/app/api/auth/prospectus/sign-out/route.ts +9 -0
- package/app/api/cyclotron/priming-proof/route.ts +11 -0
- package/app/api/media/[...path]/route.ts +5 -16
- package/app/api/revalidate/route.ts +15 -7
- package/app/archive/page.tsx +1 -1
- package/app/articles/[slug]/page.tsx +7 -5
- package/app/blog-rhythm.css +278 -0
- package/app/cyclotron/page.tsx +13 -0
- package/app/globals.css +2 -0
- package/app/layout.tsx +16 -0
- package/app/newsroom/[section]/[...selection]/page.tsx +9 -6
- package/app/newsroom/[section]/page.tsx +6 -3
- package/app/newsroom/layout.tsx +4 -9
- package/app/newsroom/settings/page.tsx +6 -0
- package/app/newsroom/work/page.tsx +10 -0
- package/app/page.tsx +22 -8
- package/app/robots.ts +2 -5
- package/app/tailwind.css +1 -6
- package/components/amplify-client-provider.tsx +5 -22
- package/components/archive-shell.tsx +2 -22
- package/components/article-video.tsx +152 -5
- package/components/blog-page-background.tsx +23 -6
- package/components/news-desk-page.tsx +4 -15
- package/components/news-desk-taxonomy-client.ts +90 -3
- package/components/newspaper.tsx +6 -2
- package/components/newsroom-access-gate.tsx +2 -1
- package/components/newsroom-board-view.tsx +99 -0
- package/components/newsroom-client-shell.tsx +12 -0
- package/components/newsroom-curation-provider.tsx +17 -0
- package/components/newsroom-fonts/playfair-display-700.ttf +0 -0
- package/components/newsroom-fonts/playfair-display-900.ttf +0 -0
- package/components/newsroom-fonts/playfair-display-OFL.txt +93 -0
- package/components/newsroom-fonts/plus-jakarta-sans-400.ttf +0 -0
- package/components/newsroom-fonts/plus-jakarta-sans-600.ttf +0 -0
- package/components/newsroom-fonts/plus-jakarta-sans-OFL.txt +93 -0
- package/components/newsroom-newsprint-board.css +48 -0
- package/components/newsroom-ops-overview.tsx +28 -11
- package/components/newsroom-ops-shell.tsx +7 -1
- package/components/newsroom-organizer-shell.tsx +130 -0
- package/components/newsroom-organizer.css +63 -0
- package/components/newsroom-references-view.tsx +92 -8
- package/components/papyrus-console-shell.tsx +4 -2
- package/components/pictogram-figure.tsx +9 -2
- package/components/presentation-header.tsx +135 -0
- package/components/presentation-rhythm-hrule.tsx +17 -0
- package/components/priming-proof-page.tsx +94 -0
- package/components/publication-cyclotron-panel.tsx +57 -0
- package/components/reader-auth-control.tsx +8 -5
- package/components/reference-curation-controls.tsx +77 -0
- package/components/reference-cyclotron-status.tsx +109 -0
- package/components/reference-priming.tsx +18 -0
- package/components/reference-relevance-review.tsx +75 -0
- package/components/settings-page.tsx +2 -1
- package/components/signup-entries-panel.tsx +94 -0
- package/components/topic-steering-workspace.tsx +78 -8
- package/components/use-blog-header-obstacles.ts +81 -0
- package/components/use-brand-fonts-ready.ts +28 -0
- package/components/use-near-viewport.ts +30 -0
- package/components/use-rhythm-overlay.ts +29 -0
- package/infra/amplify-app-shell.js +166 -27
- package/infra/amplify-app-shell.ts +180 -31
- package/infra/build-specs.js +23 -7
- package/infra/build-specs.ts +27 -10
- package/infra/site-config.js +248 -36
- package/infra/site-config.ts +313 -51
- package/lib/amplify-outputs-path.ts +5 -1
- package/lib/amplify-server-runtime.ts +36 -1
- package/lib/approved-priming-proof-reports.ts +6 -0
- package/lib/blog-feature-solver.ts +459 -0
- package/lib/blog-rhythm.ts +134 -0
- package/lib/brand-fonts-watch.ts +43 -0
- package/lib/brand-fonts.ts +112 -0
- package/lib/cached-content-repository.ts +12 -0
- package/lib/category-repository.ts +43 -93
- package/lib/content-item-lifecycle.ts +55 -0
- package/lib/content-repository.ts +3 -0
- package/lib/content-types.ts +4 -0
- package/lib/curation-client.ts +61 -0
- package/lib/edition-routes.ts +31 -29
- package/lib/graphql-content-repository.ts +56 -22
- package/lib/media-route-response.ts +45 -0
- package/lib/newspaper-layout.ts +3 -2
- package/lib/newsroom-base-path.ts +12 -3
- package/lib/newsroom-board.ts +99 -0
- package/lib/newsroom-category-drilldown.ts +3 -2
- package/lib/newsroom-forum-routes.ts +6 -4
- package/lib/newsroom-index-filters.ts +14 -10
- package/lib/newsroom-nav.ts +3 -1
- package/lib/newsroom-organizer-nav.ts +37 -0
- package/lib/newsroom-section-routing.ts +20 -0
- package/lib/oauth-redirect-priority.ts +40 -0
- package/lib/papyrus-web-locations.ts +7 -6
- package/lib/plugin-settings.ts +11 -0
- package/lib/presentation-footer.ts +3 -2
- package/lib/pretext-layout.ts +12 -3
- package/lib/priming-proof-report.ts +90 -0
- package/lib/prospectus-publication-access.ts +53 -0
- package/lib/prospectus-session.ts +196 -0
- package/lib/prospectus-sign-in-routes.ts +284 -0
- package/lib/prospectus-site-identity.ts +303 -0
- package/lib/publication-cyclotron.ts +74 -0
- package/lib/rate-limit-retry.ts +55 -0
- package/lib/reader-base-path.ts +24 -0
- package/lib/reader-cache-lifetime.ts +5 -0
- package/lib/reader-static-params.ts +85 -4
- package/lib/reader-storage-url.ts +9 -12
- package/lib/reference-policy.ts +5 -0
- package/lib/relevance-decisions.ts +103 -0
- package/lib/relevance-status.ts +63 -0
- package/lib/renderer.ts +7 -0
- package/lib/revalidate-prewarm.ts +53 -0
- package/lib/revalidate-secret.ts +59 -0
- package/lib/robots-policy.ts +14 -0
- package/lib/root-route-redirect.ts +16 -0
- package/lib/semantic-graph.ts +7 -0
- package/lib/shared-credentials-provider.ts +61 -0
- package/lib/signup-csv.ts +24 -0
- package/lib/site-brand.ts +59 -0
- package/lib/staging-gated-path.ts +23 -0
- package/lib/staging-preview-object.ts +21 -5
- package/lib/test-editor-override.ts +4 -0
- package/lib/video-loading.ts +22 -0
- package/lib/video-script.ts +14 -0
- package/middleware.ts +11 -19
- package/package.json +73 -8
- package/renderers/pretext/article-page.tsx +39 -3
- package/renderers/pretext/presentation-shared.tsx +113 -0
- package/renderers/pretext/presentation-shell.tsx +15 -102
- package/renderers/pretext/rhythm-article-page.tsx +165 -0
- package/renderers/pretext/rhythm-blog-presentation.tsx +279 -0
- package/renderers/pretext/rhythm-shell-style.ts +35 -0
- package/routes.manifest.json +123 -12
- package/src/sync.mjs +30 -6
- package/src/with-papyrus.d.mts +9 -0
- package/src/with-papyrus.mjs +48 -3
- package/amplify/functions/graphql-jwt-authorizer/handler.ts +0 -193
- package/amplify/functions/graphql-jwt-authorizer/resource.js +0 -14
- package/amplify/functions/graphql-jwt-authorizer/resource.ts +0 -15
- package/components/ai-elements/message.tsx +0 -360
package/infra/site-config.js
CHANGED
|
@@ -1,14 +1,50 @@
|
|
|
1
|
+
export const READER_REDIRECT_STATUSES = ["301", "302", "200", "404", "404-200"];
|
|
2
|
+
export function hasCmsApp(config) {
|
|
3
|
+
return config.cms !== undefined;
|
|
4
|
+
}
|
|
1
5
|
export const DEFAULT_CI_BRANCHES = ["main", "staging"];
|
|
2
6
|
const SITE_ID_PATTERN = /^[a-z][a-z0-9]*(-[a-z0-9]+)*$/;
|
|
3
7
|
const REPOSITORY_PATTERN = /^https:\/\/github\.com\/[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/;
|
|
4
8
|
const HOSTED_ZONE_ID_PATTERN = /^Z[A-Z0-9]+$/;
|
|
5
9
|
const HOST_NAME_PATTERN = /^([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,}$/;
|
|
10
|
+
const DOMAIN_PREFIX_PATTERN = /^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/;
|
|
6
11
|
const APP_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9 _.-]*$/;
|
|
7
12
|
const STACK_NAME_PATTERN = /^[A-Za-z][A-Za-z0-9-]{0,127}$/;
|
|
8
13
|
const BRANCH_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9/_.-]*$/;
|
|
9
14
|
const PAPYRUS_VERSION_PATTERN = /^\d+\.\d+\.\d+(-[0-9A-Za-z-]+\.\d+)?$/;
|
|
10
15
|
const GITHUB_OWNER_PATTERN = /^[A-Za-z0-9](?:[A-Za-z0-9]|-(?=[A-Za-z0-9])){0,38}$/;
|
|
11
16
|
const GITHUB_REPO_PATTERN = /^[A-Za-z0-9_.-]+$/;
|
|
17
|
+
const COGNITO_DOMAIN_PREFIX_PATTERN = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
|
|
18
|
+
const COGNITO_RESERVED_WORDS = ["aws", "amazon", "cognito"];
|
|
19
|
+
const PROSPECTUS_ACCOUNTS_API_STAGE_ARN_PATTERN = /^arn:aws:execute-api:[a-z0-9-]+:\d{12}:[a-z0-9]+\/api$/;
|
|
20
|
+
const TEMPLATE_MANAGED_ENVIRONMENT_KEYS = ["PAPYRUS_COGNITO_DOMAIN_PREFIX", "PAPYRUS_APPLY_COGNITO_DOMAIN_PREFIX", "PAPYRUS_DISABLE_GOOGLE_OAUTH", "PAPYRUS_REVALIDATE_SECRET_PARAMETER", "PAPYRUS_PROSPECTUS_ACCOUNTS_ENDPOINT", "PAPYRUS_PROSPECTUS_SESSION_SECRET_ARN", "PAPYRUS_PROSPECTUS_SITE_PRODUCT"];
|
|
21
|
+
/** Routes Prospectus admits for a registered Papyrus site (Prospectus accounts/papyrus-sites.ts). */
|
|
22
|
+
export const PROSPECTUS_PAPYRUS_SITE_ROUTES = [
|
|
23
|
+
"GET/v1/identities/me",
|
|
24
|
+
"POST/v1/identities/google/challenge",
|
|
25
|
+
"POST/v1/identities/google/resolve",
|
|
26
|
+
"GET/v1/accounts",
|
|
27
|
+
"GET/v1/accounts/*",
|
|
28
|
+
"POST/v1/accounts/*/authorize",
|
|
29
|
+
"GET/v1/account-directory",
|
|
30
|
+
"GET/v1/account-directory/*",
|
|
31
|
+
];
|
|
32
|
+
export function resolveProspectusAccountsEndpoint(prospectusAccountsApiStageArn) {
|
|
33
|
+
const [, , , region, , apiPath] = prospectusAccountsApiStageArn.split(":");
|
|
34
|
+
const [apiId, stageName] = apiPath.split("/");
|
|
35
|
+
return `https://${apiId}.execute-api.${region}.amazonaws.com/${stageName}/`;
|
|
36
|
+
}
|
|
37
|
+
function originOfRedirectUrl(value) {
|
|
38
|
+
try {
|
|
39
|
+
return new URL(value).origin;
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export function resolveRevalidateSecretParameterName(config) {
|
|
46
|
+
return `/papyrus/${config.siteId}/revalidate-secret`;
|
|
47
|
+
}
|
|
12
48
|
const LOCAL_DEVELOPMENT_ORIGIN = "http://localhost:3001/";
|
|
13
49
|
function fail(field, problem) {
|
|
14
50
|
throw new Error(`site.json: ${field} ${problem}`);
|
|
@@ -47,12 +83,96 @@ function rejectUnknownKeys(record, allowed, field) {
|
|
|
47
83
|
fail(`${field}.${key}`, `is not a known field (known: ${allowed.join(", ")})`);
|
|
48
84
|
}
|
|
49
85
|
}
|
|
86
|
+
function parseRedirects(value) {
|
|
87
|
+
if (value === undefined)
|
|
88
|
+
return undefined;
|
|
89
|
+
if (!Array.isArray(value) || value.length === 0)
|
|
90
|
+
fail("cms.redirects", "must be a non-empty array");
|
|
91
|
+
return value.map((entry, index) => {
|
|
92
|
+
const field = `cms.redirects[${index}]`;
|
|
93
|
+
const record = requireObject(entry, field);
|
|
94
|
+
rejectUnknownKeys(record, ["source", "status"], field);
|
|
95
|
+
const source = requireString(record.source, `${field}.source`, HOST_NAME_PATTERN, "host name without scheme or path");
|
|
96
|
+
const status = record.status ?? 301;
|
|
97
|
+
if (status !== 301 && status !== 302)
|
|
98
|
+
fail(`${field}.status`, `must be 301 or 302, got ${JSON.stringify(status)}`);
|
|
99
|
+
return { source, status };
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
function parseReaderDomainPrefixes(value) {
|
|
103
|
+
if (value === undefined)
|
|
104
|
+
return undefined;
|
|
105
|
+
if (!Array.isArray(value) || value.length === 0)
|
|
106
|
+
fail("reader.domainPrefixes", "must be a non-empty array");
|
|
107
|
+
const prefixes = value.map((entry, index) => {
|
|
108
|
+
const field = `reader.domainPrefixes[${index}]`;
|
|
109
|
+
if (entry === "")
|
|
110
|
+
return "";
|
|
111
|
+
return requireString(entry, field, DOMAIN_PREFIX_PATTERN, 'single DNS label, or "" for the apex');
|
|
112
|
+
});
|
|
113
|
+
if (new Set(prefixes).size !== prefixes.length)
|
|
114
|
+
fail("reader.domainPrefixes", "must not repeat a prefix");
|
|
115
|
+
return prefixes;
|
|
116
|
+
}
|
|
117
|
+
function parseReaderRedirects(value) {
|
|
118
|
+
if (value === undefined)
|
|
119
|
+
return undefined;
|
|
120
|
+
if (!Array.isArray(value) || value.length === 0)
|
|
121
|
+
fail("reader.redirects", "must be a non-empty array");
|
|
122
|
+
return value.map((entry, index) => {
|
|
123
|
+
const field = `reader.redirects[${index}]`;
|
|
124
|
+
const record = requireObject(entry, field);
|
|
125
|
+
rejectUnknownKeys(record, ["source", "target", "status"], field);
|
|
126
|
+
const status = record.status ?? "301";
|
|
127
|
+
if (typeof status !== "string" || !READER_REDIRECT_STATUSES.includes(status)) {
|
|
128
|
+
fail(`${field}.status`, `must be one of ${READER_REDIRECT_STATUSES.join(", ")}, got ${JSON.stringify(status)}`);
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
source: requireString(record.source, `${field}.source`),
|
|
132
|
+
target: requireString(record.target, `${field}.target`),
|
|
133
|
+
status: status,
|
|
134
|
+
};
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
function parseReaderCustomHeaders(value) {
|
|
138
|
+
if (value === undefined)
|
|
139
|
+
return undefined;
|
|
140
|
+
if (!Array.isArray(value) || value.length === 0)
|
|
141
|
+
fail("reader.customHeaders", "must be a non-empty array");
|
|
142
|
+
return value.map((entry, index) => {
|
|
143
|
+
const field = `reader.customHeaders[${index}]`;
|
|
144
|
+
const record = requireObject(entry, field);
|
|
145
|
+
rejectUnknownKeys(record, ["pattern", "headers"], field);
|
|
146
|
+
const headers = requireStringRecord(record.headers, `${field}.headers`);
|
|
147
|
+
if (Object.keys(headers).length === 0)
|
|
148
|
+
fail(`${field}.headers`, "must not be empty");
|
|
149
|
+
return { pattern: requireString(record.pattern, `${field}.pattern`), headers };
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
function parseReaderPreBuildCommands(value) {
|
|
153
|
+
if (value === undefined)
|
|
154
|
+
return undefined;
|
|
155
|
+
if (!Array.isArray(value) || value.length === 0)
|
|
156
|
+
fail("reader.preBuildCommands", "must be a non-empty array of commands");
|
|
157
|
+
return value.map((command, index) => requireString(command, `reader.preBuildCommands[${index}]`));
|
|
158
|
+
}
|
|
159
|
+
export function resolveRedirectSubDomainPrefix(rootDomain, source) {
|
|
160
|
+
return source === rootDomain ? "" : source.slice(0, -rootDomain.length - 1);
|
|
161
|
+
}
|
|
50
162
|
export function isStagingEnabled(config) {
|
|
51
163
|
return config.cms.staging !== false;
|
|
52
164
|
}
|
|
165
|
+
export function resolveCmsHostName(config) {
|
|
166
|
+
if (!config.cms.domainName)
|
|
167
|
+
return undefined;
|
|
168
|
+
return config.cms.domainPrefix ? `${config.cms.domainPrefix}.${config.cms.domainName}` : config.cms.domainName;
|
|
169
|
+
}
|
|
53
170
|
export function resolveStagingDomainName(config) {
|
|
54
171
|
if (!isStagingEnabled(config))
|
|
55
172
|
return undefined;
|
|
173
|
+
if (config.cms.domainPrefix) {
|
|
174
|
+
return config.cms.stagingDomainPrefix ? `${config.cms.stagingDomainPrefix}.${config.cms.domainName}` : undefined;
|
|
175
|
+
}
|
|
56
176
|
if (config.cms.stagingDomainName)
|
|
57
177
|
return config.cms.stagingDomainName;
|
|
58
178
|
if (!config.cms.domainName)
|
|
@@ -66,22 +186,19 @@ export function resolveStackName(config) {
|
|
|
66
186
|
export function resolveStoragePreviewPrefix(config) {
|
|
67
187
|
return config.storagePreviewPrefix ?? "preview/";
|
|
68
188
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
const storagePreviewPrefix = optionalString(record.storagePreviewPrefix, "storagePreviewPrefix", /^[A-Za-z0-9._-]+\/$/, "must end with /");
|
|
83
|
-
const cmsRecord = requireObject(record.cms, "cms");
|
|
84
|
-
rejectUnknownKeys(cmsRecord, ["appName", "domainName", "staging", "buildComputeType", "environment", "stagingDomainName"], "cms");
|
|
189
|
+
function parseStagingPreview(value) {
|
|
190
|
+
if (value === undefined)
|
|
191
|
+
return undefined;
|
|
192
|
+
const record = requireObject(value, "cms.stagingPreview");
|
|
193
|
+
rejectUnknownKeys(record, ["buildCommand", "baseDirectory"], "cms.stagingPreview");
|
|
194
|
+
return {
|
|
195
|
+
buildCommand: requireString(record.buildCommand, "cms.stagingPreview.buildCommand"),
|
|
196
|
+
baseDirectory: requireString(record.baseDirectory, "cms.stagingPreview.baseDirectory"),
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
function parseCms(value) {
|
|
200
|
+
const cmsRecord = requireObject(value, "cms");
|
|
201
|
+
rejectUnknownKeys(cmsRecord, ["appName", "domainName", "staging", "cognitoDomainPrefix", "applyCognitoDomainPrefix", "buildComputeType", "environment", "stagingDomainName", "domainPrefix", "stagingDomainPrefix", "redirects", "stagingPreview", "prospectusAccountsApiStageArn"], "cms");
|
|
85
202
|
const buildComputeType = cmsRecord.buildComputeType;
|
|
86
203
|
if (buildComputeType !== undefined && buildComputeType !== "STANDARD" && buildComputeType !== "STANDARD_8GB") {
|
|
87
204
|
fail("cms.buildComputeType", `must be "STANDARD" or "STANDARD_8GB", got ${JSON.stringify(buildComputeType)}`);
|
|
@@ -89,26 +206,119 @@ export function parseSiteConfig(raw) {
|
|
|
89
206
|
if (cmsRecord.staging !== undefined && typeof cmsRecord.staging !== "boolean") {
|
|
90
207
|
fail("cms.staging", `must be a boolean, got ${JSON.stringify(cmsRecord.staging)}`);
|
|
91
208
|
}
|
|
209
|
+
if (cmsRecord.applyCognitoDomainPrefix !== undefined && typeof cmsRecord.applyCognitoDomainPrefix !== "boolean") {
|
|
210
|
+
fail("cms.applyCognitoDomainPrefix", `must be a boolean, got ${JSON.stringify(cmsRecord.applyCognitoDomainPrefix)}`);
|
|
211
|
+
}
|
|
92
212
|
const cms = {
|
|
93
213
|
appName: optionalString(cmsRecord.appName, "cms.appName", APP_NAME_PATTERN),
|
|
94
214
|
domainName: optionalString(cmsRecord.domainName, "cms.domainName", HOST_NAME_PATTERN, "host name"),
|
|
215
|
+
domainPrefix: optionalString(cmsRecord.domainPrefix, "cms.domainPrefix", DOMAIN_PREFIX_PATTERN, "single DNS label"),
|
|
95
216
|
staging: cmsRecord.staging,
|
|
217
|
+
cognitoDomainPrefix: requireString(cmsRecord.cognitoDomainPrefix, "cms.cognitoDomainPrefix", COGNITO_DOMAIN_PREFIX_PATTERN, "lowercase letters, digits and hyphens; globally unique per region"),
|
|
218
|
+
applyCognitoDomainPrefix: cmsRecord.applyCognitoDomainPrefix,
|
|
96
219
|
buildComputeType: buildComputeType,
|
|
97
220
|
environment: requireStringRecord(cmsRecord.environment, "cms.environment"),
|
|
98
221
|
stagingDomainName: optionalString(cmsRecord.stagingDomainName, "cms.stagingDomainName", HOST_NAME_PATTERN, "host name"),
|
|
222
|
+
stagingDomainPrefix: optionalString(cmsRecord.stagingDomainPrefix, "cms.stagingDomainPrefix", DOMAIN_PREFIX_PATTERN, "single DNS label"),
|
|
223
|
+
redirects: parseRedirects(cmsRecord.redirects),
|
|
224
|
+
stagingPreview: parseStagingPreview(cmsRecord.stagingPreview),
|
|
225
|
+
prospectusAccountsApiStageArn: optionalString(cmsRecord.prospectusAccountsApiStageArn, "cms.prospectusAccountsApiStageArn", PROSPECTUS_ACCOUNTS_API_STAGE_ARN_PATTERN, "arn:aws:execute-api:<region>:<account>:<api id>/api"),
|
|
99
226
|
};
|
|
227
|
+
const reservedWord = COGNITO_RESERVED_WORDS.find((word) => cms.cognitoDomainPrefix.includes(word));
|
|
228
|
+
if (reservedWord) {
|
|
229
|
+
fail("cms.cognitoDomainPrefix", `must not contain "${reservedWord}" (Cognito reserves it): ${JSON.stringify(cms.cognitoDomainPrefix)}`);
|
|
230
|
+
}
|
|
231
|
+
for (const key of TEMPLATE_MANAGED_ENVIRONMENT_KEYS) {
|
|
232
|
+
if (key in cms.environment) {
|
|
233
|
+
fail(`cms.environment.${key}`, "is managed by the template: Google sign-in is always on, the Cognito domain comes from cms.cognitoDomainPrefix, the revalidation secret parameter is derived from siteId and the Prospectus endpoint comes from cms.prospectusAccountsApiStageArn");
|
|
234
|
+
}
|
|
235
|
+
}
|
|
100
236
|
if (cms.staging === false && cms.stagingDomainName) {
|
|
101
237
|
fail("cms.stagingDomainName", "must not be set when cms.staging is false");
|
|
102
238
|
}
|
|
103
239
|
if (cms.stagingDomainName && !cms.domainName) {
|
|
104
240
|
fail("cms.stagingDomainName", "requires cms.domainName");
|
|
105
241
|
}
|
|
242
|
+
if (cms.domainPrefix && !cms.domainName) {
|
|
243
|
+
fail("cms.domainPrefix", "requires cms.domainName (the root domain)");
|
|
244
|
+
}
|
|
245
|
+
if (cms.stagingDomainPrefix && !cms.domainPrefix) {
|
|
246
|
+
fail("cms.stagingDomainPrefix", "requires cms.domainPrefix");
|
|
247
|
+
}
|
|
248
|
+
if (cms.domainPrefix && cms.stagingDomainName) {
|
|
249
|
+
fail("cms.stagingDomainName", "must not be set with cms.domainPrefix: use cms.stagingDomainPrefix");
|
|
250
|
+
}
|
|
251
|
+
if (cms.staging === false && cms.stagingDomainPrefix) {
|
|
252
|
+
fail("cms.stagingDomainPrefix", "must not be set when cms.staging is false");
|
|
253
|
+
}
|
|
254
|
+
if (cms.domainPrefix && cms.staging !== false && !cms.stagingDomainPrefix) {
|
|
255
|
+
fail("cms.stagingDomainPrefix", "is required when cms.domainPrefix is set and staging is enabled: the staging host is never derived under a shared root domain");
|
|
256
|
+
}
|
|
257
|
+
if (cms.domainPrefix && cms.stagingDomainPrefix === cms.domainPrefix) {
|
|
258
|
+
fail("cms.stagingDomainPrefix", "must differ from cms.domainPrefix");
|
|
259
|
+
}
|
|
260
|
+
if (cms.redirects) {
|
|
261
|
+
if (!cms.domainPrefix)
|
|
262
|
+
fail("cms.redirects", "requires cms.domainPrefix (redirects target the primary host under a shared root domain)");
|
|
263
|
+
cms.redirects.forEach((redirect, index) => {
|
|
264
|
+
const field = `cms.redirects[${index}].source`;
|
|
265
|
+
const root = cms.domainName;
|
|
266
|
+
if (redirect.source !== root && !(redirect.source.endsWith(`.${root}`) && DOMAIN_PREFIX_PATTERN.test(redirect.source.slice(0, -root.length - 1)))) {
|
|
267
|
+
fail(field, `must be the root domain ${root} or a single label under it: ${JSON.stringify(redirect.source)}`);
|
|
268
|
+
}
|
|
269
|
+
if (redirect.source === resolveCmsHostName({ cms }))
|
|
270
|
+
fail(field, "must differ from the primary host");
|
|
271
|
+
if (redirect.source === resolveStagingDomainName({ cms }))
|
|
272
|
+
fail(field, "must differ from the staging host");
|
|
273
|
+
});
|
|
274
|
+
if (new Set(cms.redirects.map((redirect) => redirect.source)).size !== cms.redirects.length) {
|
|
275
|
+
fail("cms.redirects", "must not repeat a source");
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return cms;
|
|
279
|
+
}
|
|
280
|
+
function validateOauthRedirectUrls(config) {
|
|
281
|
+
const redirectValue = config.cms.environment.PAPYRUS_OAUTH_REDIRECT_URLS;
|
|
282
|
+
if (redirectValue === undefined)
|
|
283
|
+
fail("config.cms.environment.PAPYRUS_OAUTH_REDIRECT_URLS", "is required");
|
|
284
|
+
const redirectUrls = redirectValue.split(",").map((url) => url.trim());
|
|
285
|
+
const stagingDomainName = resolveStagingDomainName(config);
|
|
286
|
+
const listedOrigins = new Set(redirectUrls.map(originOfRedirectUrl));
|
|
287
|
+
const requiredOrigins = [
|
|
288
|
+
...(resolveCmsHostName(config) ? [`https://${resolveCmsHostName(config)}`] : []),
|
|
289
|
+
...(stagingDomainName ? [`https://${stagingDomainName}`] : []),
|
|
290
|
+
originOfRedirectUrl(LOCAL_DEVELOPMENT_ORIGIN),
|
|
291
|
+
];
|
|
292
|
+
for (const origin of requiredOrigins) {
|
|
293
|
+
if (!listedOrigins.has(origin)) {
|
|
294
|
+
fail("config.cms.environment.PAPYRUS_OAUTH_REDIRECT_URLS", `must include ${origin}/ (or just the origin: the backend also registers its newsroom path)`);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
export function parseSiteConfig(raw) {
|
|
299
|
+
const record = requireObject(raw, "site");
|
|
300
|
+
rejectUnknownKeys(record, ["siteId", "repository", "brand", "frontend", "hostedZoneId", "stackName", "cms", "reader", "papyrusVersion", "storagePreviewPrefix", "github"], "site");
|
|
301
|
+
const siteId = requireString(record.siteId, "siteId", SITE_ID_PATTERN, "kebab-case");
|
|
302
|
+
const repository = requireString(record.repository, "repository", REPOSITORY_PATTERN, "https://github.com/<org>/<repo>");
|
|
303
|
+
const brand = requireString(record.brand, "brand");
|
|
304
|
+
const frontend = requireString(record.frontend, "frontend");
|
|
305
|
+
if (frontend !== "pretext" && frontend !== "markus-static") {
|
|
306
|
+
fail("frontend", `must be "pretext" or "markus-static", got ${JSON.stringify(frontend)}`);
|
|
307
|
+
}
|
|
308
|
+
const hostedZoneId = optionalString(record.hostedZoneId, "hostedZoneId", HOSTED_ZONE_ID_PATTERN, "Route 53 zone id");
|
|
309
|
+
const stackName = optionalString(record.stackName, "stackName", STACK_NAME_PATTERN, "CloudFormation stack name");
|
|
310
|
+
const papyrusVersion = requireString(record.papyrusVersion, "papyrusVersion", PAPYRUS_VERSION_PATTERN, "exact version such as 1.0.0 or 1.0.0-next.1");
|
|
311
|
+
const storagePreviewPrefix = optionalString(record.storagePreviewPrefix, "storagePreviewPrefix", /^[A-Za-z0-9._-]+\/$/, "must end with /");
|
|
312
|
+
const cms = record.cms === undefined && frontend === "markus-static" ? undefined : parseCms(record.cms);
|
|
106
313
|
let reader;
|
|
107
314
|
if (record.reader !== undefined) {
|
|
108
315
|
if (frontend !== "markus-static")
|
|
109
316
|
fail("reader", `is only allowed when frontend is "markus-static"`);
|
|
110
317
|
const readerRecord = requireObject(record.reader, "reader");
|
|
111
|
-
rejectUnknownKeys(readerRecord, ["appName", "domainName", "branchName", "buildCommand", "baseDirectory", "environment"], "reader");
|
|
318
|
+
rejectUnknownKeys(readerRecord, ["appName", "domainName", "domainPrefixes", "branchName", "buildCommand", "baseDirectory", "environment", "redirects", "customHeaders", "preBuildCommands", "skipContentExport"], "reader");
|
|
319
|
+
if (readerRecord.skipContentExport !== undefined && typeof readerRecord.skipContentExport !== "boolean") {
|
|
320
|
+
fail("reader.skipContentExport", `must be a boolean, got ${JSON.stringify(readerRecord.skipContentExport)}`);
|
|
321
|
+
}
|
|
112
322
|
reader = {
|
|
113
323
|
appName: optionalString(readerRecord.appName, "reader.appName", APP_NAME_PATTERN),
|
|
114
324
|
domainName: optionalString(readerRecord.domainName, "reader.domainName", HOST_NAME_PATTERN, "host name"),
|
|
@@ -116,13 +326,28 @@ export function parseSiteConfig(raw) {
|
|
|
116
326
|
buildCommand: requireString(readerRecord.buildCommand, "reader.buildCommand"),
|
|
117
327
|
baseDirectory: requireString(readerRecord.baseDirectory, "reader.baseDirectory"),
|
|
118
328
|
environment: readerRecord.environment === undefined ? undefined : requireStringRecord(readerRecord.environment, "reader.environment"),
|
|
329
|
+
domainPrefixes: parseReaderDomainPrefixes(readerRecord.domainPrefixes),
|
|
330
|
+
redirects: parseReaderRedirects(readerRecord.redirects),
|
|
331
|
+
customHeaders: parseReaderCustomHeaders(readerRecord.customHeaders),
|
|
332
|
+
preBuildCommands: parseReaderPreBuildCommands(readerRecord.preBuildCommands),
|
|
333
|
+
skipContentExport: readerRecord.skipContentExport,
|
|
119
334
|
};
|
|
335
|
+
if (reader.domainPrefixes && !reader.domainName)
|
|
336
|
+
fail("reader.domainPrefixes", "requires reader.domainName");
|
|
337
|
+
}
|
|
338
|
+
else if (frontend === "markus-static" && cms === undefined) {
|
|
339
|
+
fail("reader", `is required when frontend is "markus-static" and there is no cms section`);
|
|
340
|
+
}
|
|
341
|
+
if (cms?.stagingPreview !== undefined && frontend !== "markus-static") {
|
|
342
|
+
fail("cms.stagingPreview", `is only allowed when frontend is "markus-static"`);
|
|
120
343
|
}
|
|
121
|
-
|
|
122
|
-
fail("
|
|
344
|
+
if (cms?.stagingPreview !== undefined && cms.staging === false) {
|
|
345
|
+
fail("cms.stagingPreview", "must not be set when cms.staging is false");
|
|
123
346
|
}
|
|
124
347
|
let github;
|
|
125
348
|
if (record.github !== undefined) {
|
|
349
|
+
if (cms === undefined)
|
|
350
|
+
fail("github", "requires cms (the CI role is scoped to the CMS app)");
|
|
126
351
|
const githubRecord = requireObject(record.github, "github");
|
|
127
352
|
rejectUnknownKeys(githubRecord, ["owner", "repo", "branches", "ciCanDeployInfra"], "github");
|
|
128
353
|
const owner = requireString(githubRecord.owner, "github.owner", GITHUB_OWNER_PATTERN, "plain GitHub login");
|
|
@@ -130,7 +355,7 @@ export function parseSiteConfig(raw) {
|
|
|
130
355
|
if (repository !== `https://github.com/${owner}/${repo}`) {
|
|
131
356
|
fail("github", `owner/repo must match repository ${repository}`);
|
|
132
357
|
}
|
|
133
|
-
let branches = cms
|
|
358
|
+
let branches = cms?.staging === false ? DEFAULT_CI_BRANCHES.filter((branch) => branch !== "staging") : DEFAULT_CI_BRANCHES;
|
|
134
359
|
if (githubRecord.branches !== undefined) {
|
|
135
360
|
if (!Array.isArray(githubRecord.branches) || githubRecord.branches.length === 0) {
|
|
136
361
|
fail("github.branches", "must be a non-empty array of branch names");
|
|
@@ -147,7 +372,7 @@ export function parseSiteConfig(raw) {
|
|
|
147
372
|
fail("github.ciCanDeployInfra", "must be a boolean");
|
|
148
373
|
github = { owner, repo, branches, ciCanDeployInfra: ciCanDeployInfra };
|
|
149
374
|
}
|
|
150
|
-
const hasDomain = cms
|
|
375
|
+
const hasDomain = cms?.domainName !== undefined || reader?.domainName !== undefined;
|
|
151
376
|
if (hasDomain && hostedZoneId === undefined) {
|
|
152
377
|
fail("hostedZoneId", "is required when cms.domainName or reader.domainName is set");
|
|
153
378
|
}
|
|
@@ -167,20 +392,7 @@ export function parseSiteConfig(raw) {
|
|
|
167
392
|
storagePreviewPrefix,
|
|
168
393
|
github,
|
|
169
394
|
};
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
fail("cms.environment.PAPYRUS_OAUTH_REDIRECT_URLS", "is required");
|
|
173
|
-
const redirectUrls = redirectValue.split(",").map((url) => url.trim());
|
|
174
|
-
const stagingDomainName = resolveStagingDomainName(config);
|
|
175
|
-
const requiredOrigins = [
|
|
176
|
-
...(cms.domainName ? [`https://${cms.domainName}/`] : []),
|
|
177
|
-
...(stagingDomainName ? [`https://${stagingDomainName}/`] : []),
|
|
178
|
-
LOCAL_DEVELOPMENT_ORIGIN,
|
|
179
|
-
];
|
|
180
|
-
for (const origin of requiredOrigins) {
|
|
181
|
-
if (!redirectUrls.includes(origin)) {
|
|
182
|
-
fail("cms.environment.PAPYRUS_OAUTH_REDIRECT_URLS", `must include ${origin}`);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
395
|
+
if (hasCmsApp(config))
|
|
396
|
+
validateOauthRedirectUrls(config);
|
|
185
397
|
return config;
|
|
186
398
|
}
|