@anthusai/papyrus 1.0.0-next.2 → 1.0.0-next.21
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/resource.js +17 -4
- package/amplify/auth/resource.ts +21 -4
- package/amplify/data/resource.js +52 -70
- package/amplify/data/resource.ts +57 -70
- package/amplify/data/schema.js +52 -58
- package/amplify/data/schema.ts +57 -58
- 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 +149 -0
- package/amplify/functions/content-actions/requirements.txt +4 -0
- package/amplify/functions/content-actions/resource.js +40 -0
- package/amplify/functions/content-actions/resource.ts +54 -0
- package/amplify/functions/shared/python-bundle.js +17 -2
- package/amplify/functions/shared/python-bundle.ts +23 -2
- package/amplify/rebuild-trigger-settings.js +22 -0
- package/amplify/rebuild-trigger-settings.ts +42 -0
- package/amplify/site-backend-config.ts +12 -1
- package/amplify/site-backend.js +51 -27
- package/amplify/site-backend.ts +66 -34
- package/amplify/storage/resource.js +3 -0
- package/amplify/storage/resource.ts +3 -0
- package/app/%5F_preview/[[...path]]/route.ts +8 -0
- package/app/[year]/[month]/[day]/[articleSlug]/page.tsx +4 -2
- package/app/[year]/[month]/[day]/edition-route-page.tsx +2 -0
- package/app/api/revalidate/route.ts +8 -7
- package/app/articles/[slug]/page.tsx +6 -4
- package/app/blog-rhythm.css +278 -0
- package/app/globals.css +22 -4
- package/app/layout.tsx +24 -12
- package/app/newsroom/articles/[id]/page.tsx +15 -0
- package/app/newsroom/articles/page.tsx +13 -0
- package/app/page.tsx +12 -4
- package/app/robots.ts +11 -0
- package/bin/papyrus-app.mjs +12 -2
- package/bin/papyrus-infra.mjs +74 -18
- package/components/archive-shell.tsx +2 -22
- package/components/article-video.tsx +247 -3
- package/components/blog-page-background.tsx +23 -6
- package/components/markus-ir-preview.tsx +300 -0
- package/components/news-desk-page.tsx +1 -4
- package/components/newspaper.tsx +6 -2
- package/components/newsroom-access-gate.tsx +66 -0
- package/components/newsroom-article-editor.tsx +741 -0
- package/components/newsroom-articles-view.tsx +129 -0
- package/components/newsroom-ops-overview.tsx +28 -11
- package/components/newsroom-ops-shell.tsx +3 -1
- package/components/pictogram-figure.tsx +9 -2
- package/components/presentation-header.tsx +135 -0
- package/components/presentation-rhythm-hrule.tsx +17 -0
- package/components/settings-page.tsx +2 -1
- package/components/staging-banner.tsx +11 -0
- package/components/topic-steering-workspace.tsx +1 -59
- package/components/use-blog-header-obstacles.ts +81 -0
- package/components/use-brand-fonts-ready.ts +28 -0
- package/components/use-rhythm-overlay.ts +29 -0
- package/infra/amplify-app-shell.js +285 -80
- package/infra/amplify-app-shell.ts +326 -113
- package/infra/build-specs.js +94 -0
- package/infra/build-specs.ts +141 -0
- package/infra/github-oidc-provider.js +24 -0
- package/infra/github-oidc-provider.ts +30 -0
- package/infra/index.js +3 -0
- package/infra/site-config.js +273 -0
- package/infra/site-config.ts +336 -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 +14 -1
- package/lib/category-repository.ts +1 -93
- package/lib/content-actions-client.ts +98 -0
- package/lib/content-actions-demo.ts +190 -0
- package/lib/content-repository.ts +6 -0
- package/lib/content-source-context.ts +26 -0
- package/lib/content-types.ts +4 -0
- package/lib/edition-routes.ts +31 -29
- package/lib/empty-theme.css +1 -0
- package/lib/graphql-content-repository.ts +239 -43
- package/lib/layout-scenarios.ts +8 -8
- package/lib/newspaper-layout.ts +3 -2
- package/lib/newsroom-articles.ts +325 -0
- package/lib/newsroom-demo-articles.ts +90 -0
- package/lib/newsroom-media-backend.ts +142 -0
- package/lib/newsroom-media.ts +182 -0
- package/lib/newsroom-nav.ts +3 -0
- package/lib/papyrus-web-locations.ts +7 -6
- package/lib/presentation-footer.ts +3 -2
- package/lib/pretext-layout.ts +12 -3
- package/lib/reader-base-path.ts +24 -0
- package/lib/reader-static-params.ts +8 -0
- package/lib/renderer.ts +7 -0
- package/lib/revalidate-secret.ts +59 -0
- package/lib/root-route-redirect.ts +16 -0
- package/lib/site-brand-tenant.ts +3 -22
- package/lib/site-brand.ts +95 -42
- package/lib/site-env.ts +52 -0
- package/lib/staging-gate.ts +37 -0
- package/lib/staging-gated-path.ts +22 -0
- package/lib/staging-preview-object.ts +98 -0
- package/lib/video-mode.ts +42 -0
- package/lib/video-script.ts +77 -0
- package/middleware.ts +56 -42
- package/package.json +40 -1
- package/renderers/pretext/article-page.tsx +40 -9
- package/renderers/pretext/presentation-shared.tsx +113 -0
- package/renderers/pretext/presentation-shell.tsx +18 -112
- 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 +37 -2
- package/scripts/videoml/build-browser-bundle.mjs +22 -0
- package/scripts/videoml/build-preview-bundle.mjs +50 -0
- package/scripts/videoml/bundle-common.mjs +129 -0
- package/scripts/videoml/preview/preview-entry.tsx +381 -0
- package/scripts/videoml/preview/preview-stage-fit.ts +28 -0
- package/scripts/videoml/preview/preview-timing.ts +42 -0
- package/scripts/videoml/preview.html +77 -0
- package/scripts/videoml/standard-entry.tsx +46 -0
- package/src/sync.mjs +30 -6
- package/src/with-papyrus.mjs +15 -2
- 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/publications/anth_us/brand.ts +0 -68
- package/publications/anth_us/theme.css +0 -66
- package/publications/pilobol_us/brand.ts +0 -37
- package/publications/pilobol_us/theme.css +0 -140
- package/publications/threat_intelligence/blog-defense/graph.ts +0 -636
- package/publications/threat_intelligence/blog-defense/layout.ts +0 -934
- package/publications/threat_intelligence/blog-defense/page-background.tsx +0 -590
- package/publications/threat_intelligence/brand.ts +0 -40
- package/publications/threat_intelligence/pictograms/art.tsx +0 -608
- package/publications/threat_intelligence/pictograms/figure.tsx +0 -82
- package/publications/threat_intelligence/pictograms/registry.ts +0 -30
- package/publications/threat_intelligence/pictograms/system.tsx +0 -305
- package/publications/threat_intelligence/seed/seed-edition-content.json +0 -629
- package/publications/threat_intelligence/theme.css +0 -1440
- /package/{publications/papyrus/theme.css → app/papyrus-theme.css} +0 -0
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
export type CmsRedirect = {
|
|
2
|
+
source: string;
|
|
3
|
+
status: 301 | 302;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
export type AmplifyAppShellSiteConfig = {
|
|
7
|
+
siteId: string;
|
|
8
|
+
repository: string;
|
|
9
|
+
brand: string;
|
|
10
|
+
frontend: "pretext" | "markus-static";
|
|
11
|
+
hostedZoneId?: string;
|
|
12
|
+
stackName?: string;
|
|
13
|
+
cms: {
|
|
14
|
+
appName?: string;
|
|
15
|
+
domainName?: string;
|
|
16
|
+
domainPrefix?: string;
|
|
17
|
+
staging?: boolean;
|
|
18
|
+
cognitoDomainPrefix: string;
|
|
19
|
+
applyCognitoDomainPrefix?: boolean;
|
|
20
|
+
buildComputeType?: "STANDARD" | "STANDARD_8GB";
|
|
21
|
+
environment: Record<string, string>;
|
|
22
|
+
stagingDomainName?: string;
|
|
23
|
+
stagingDomainPrefix?: string;
|
|
24
|
+
redirects?: CmsRedirect[];
|
|
25
|
+
};
|
|
26
|
+
reader?: {
|
|
27
|
+
appName?: string;
|
|
28
|
+
domainName?: string;
|
|
29
|
+
branchName?: string;
|
|
30
|
+
buildCommand: string;
|
|
31
|
+
baseDirectory: string;
|
|
32
|
+
environment?: Record<string, string>;
|
|
33
|
+
};
|
|
34
|
+
papyrusVersion: string;
|
|
35
|
+
storagePreviewPrefix?: string;
|
|
36
|
+
github?: {
|
|
37
|
+
owner: string;
|
|
38
|
+
repo: string;
|
|
39
|
+
branches: string[];
|
|
40
|
+
ciCanDeployInfra: boolean;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const DEFAULT_CI_BRANCHES = ["main", "staging"];
|
|
45
|
+
|
|
46
|
+
const SITE_ID_PATTERN = /^[a-z][a-z0-9]*(-[a-z0-9]+)*$/;
|
|
47
|
+
const REPOSITORY_PATTERN = /^https:\/\/github\.com\/[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/;
|
|
48
|
+
const HOSTED_ZONE_ID_PATTERN = /^Z[A-Z0-9]+$/;
|
|
49
|
+
const HOST_NAME_PATTERN = /^([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,}$/;
|
|
50
|
+
const DOMAIN_PREFIX_PATTERN = /^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/;
|
|
51
|
+
const APP_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9 _.-]*$/;
|
|
52
|
+
const STACK_NAME_PATTERN = /^[A-Za-z][A-Za-z0-9-]{0,127}$/;
|
|
53
|
+
const BRANCH_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9/_.-]*$/;
|
|
54
|
+
const PAPYRUS_VERSION_PATTERN = /^\d+\.\d+\.\d+(-[0-9A-Za-z-]+\.\d+)?$/;
|
|
55
|
+
const GITHUB_OWNER_PATTERN = /^[A-Za-z0-9](?:[A-Za-z0-9]|-(?=[A-Za-z0-9])){0,38}$/;
|
|
56
|
+
const GITHUB_REPO_PATTERN = /^[A-Za-z0-9_.-]+$/;
|
|
57
|
+
const COGNITO_DOMAIN_PREFIX_PATTERN = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
|
|
58
|
+
const COGNITO_RESERVED_WORDS = ["aws", "amazon", "cognito"];
|
|
59
|
+
const TEMPLATE_MANAGED_ENVIRONMENT_KEYS = ["PAPYRUS_COGNITO_DOMAIN_PREFIX", "PAPYRUS_APPLY_COGNITO_DOMAIN_PREFIX", "PAPYRUS_DISABLE_GOOGLE_OAUTH", "PAPYRUS_REVALIDATE_SECRET_PARAMETER"];
|
|
60
|
+
export function resolveRevalidateSecretParameterName(config: Pick<AmplifyAppShellSiteConfig, "siteId">): string {
|
|
61
|
+
return `/papyrus/${config.siteId}/revalidate-secret`;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const LOCAL_DEVELOPMENT_ORIGIN = "http://localhost:3001/";
|
|
65
|
+
|
|
66
|
+
function fail(field: string, problem: string): never {
|
|
67
|
+
throw new Error(`site.json: ${field} ${problem}`);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function requireObject(value: unknown, field: string): Record<string, unknown> {
|
|
71
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
72
|
+
fail(field, "must be an object");
|
|
73
|
+
}
|
|
74
|
+
return value as Record<string, unknown>;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function requireString(value: unknown, field: string, pattern?: RegExp, patternHint?: string): string {
|
|
78
|
+
if (typeof value !== "string" || value.trim() === "") {
|
|
79
|
+
fail(field, "must be a non-empty string");
|
|
80
|
+
}
|
|
81
|
+
if (pattern && !pattern.test(value as string)) {
|
|
82
|
+
fail(field, `is invalid${patternHint ? ` (${patternHint})` : ""}: ${JSON.stringify(value)}`);
|
|
83
|
+
}
|
|
84
|
+
return value as string;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function optionalString(value: unknown, field: string, pattern?: RegExp, patternHint?: string): string | undefined {
|
|
88
|
+
return value === undefined ? undefined : requireString(value, field, pattern, patternHint);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function requireStringRecord(value: unknown, field: string): Record<string, string> {
|
|
92
|
+
const record = requireObject(value, field);
|
|
93
|
+
const result: Record<string, string> = {};
|
|
94
|
+
for (const [key, entry] of Object.entries(record)) {
|
|
95
|
+
if (typeof entry !== "string") fail(`${field}.${key}`, "must be a string");
|
|
96
|
+
result[key] = entry as string;
|
|
97
|
+
}
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function rejectUnknownKeys(record: Record<string, unknown>, allowed: string[], field: string): void {
|
|
102
|
+
for (const key of Object.keys(record)) {
|
|
103
|
+
if (!allowed.includes(key)) fail(`${field}.${key}`, `is not a known field (known: ${allowed.join(", ")})`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function parseRedirects(value: unknown): CmsRedirect[] | undefined {
|
|
108
|
+
if (value === undefined) return undefined;
|
|
109
|
+
if (!Array.isArray(value) || value.length === 0) fail("cms.redirects", "must be a non-empty array");
|
|
110
|
+
return (value as unknown[]).map((entry, index) => {
|
|
111
|
+
const field = `cms.redirects[${index}]`;
|
|
112
|
+
const record = requireObject(entry, field);
|
|
113
|
+
rejectUnknownKeys(record, ["source", "status"], field);
|
|
114
|
+
const source = requireString(record.source, `${field}.source`, HOST_NAME_PATTERN, "host name without scheme or path");
|
|
115
|
+
const status = record.status ?? 301;
|
|
116
|
+
if (status !== 301 && status !== 302) fail(`${field}.status`, `must be 301 or 302, got ${JSON.stringify(status)}`);
|
|
117
|
+
return { source, status };
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function resolveRedirectSubDomainPrefix(rootDomain: string, source: string): string {
|
|
122
|
+
return source === rootDomain ? "" : source.slice(0, -rootDomain.length - 1);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function isStagingEnabled(config: Pick<AmplifyAppShellSiteConfig, "cms">): boolean {
|
|
126
|
+
return config.cms.staging !== false;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function resolveCmsHostName(config: Pick<AmplifyAppShellSiteConfig, "cms">): string | undefined {
|
|
130
|
+
if (!config.cms.domainName) return undefined;
|
|
131
|
+
return config.cms.domainPrefix ? `${config.cms.domainPrefix}.${config.cms.domainName}` : config.cms.domainName;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export function resolveStagingDomainName(config: Pick<AmplifyAppShellSiteConfig, "cms">): string | undefined {
|
|
135
|
+
if (!isStagingEnabled(config)) return undefined;
|
|
136
|
+
if (config.cms.domainPrefix) {
|
|
137
|
+
return config.cms.stagingDomainPrefix ? `${config.cms.stagingDomainPrefix}.${config.cms.domainName}` : undefined;
|
|
138
|
+
}
|
|
139
|
+
if (config.cms.stagingDomainName) return config.cms.stagingDomainName;
|
|
140
|
+
if (!config.cms.domainName) return undefined;
|
|
141
|
+
const [, ...rest] = config.cms.domainName.split(".");
|
|
142
|
+
return ["staging", ...rest].join(".");
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export function resolveStackName(config: Pick<AmplifyAppShellSiteConfig, "siteId" | "stackName">): string {
|
|
146
|
+
return config.stackName ?? `amplify-app-shell-${config.siteId}`;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export function resolveStoragePreviewPrefix(config: Pick<AmplifyAppShellSiteConfig, "storagePreviewPrefix">): string {
|
|
150
|
+
return config.storagePreviewPrefix ?? "preview/";
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export function parseSiteConfig(raw: unknown): AmplifyAppShellSiteConfig {
|
|
154
|
+
const record = requireObject(raw, "site");
|
|
155
|
+
rejectUnknownKeys(
|
|
156
|
+
record,
|
|
157
|
+
["siteId", "repository", "brand", "frontend", "hostedZoneId", "stackName", "cms", "reader", "papyrusVersion", "storagePreviewPrefix", "github"],
|
|
158
|
+
"site",
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
const siteId = requireString(record.siteId, "siteId", SITE_ID_PATTERN, "kebab-case");
|
|
162
|
+
const repository = requireString(record.repository, "repository", REPOSITORY_PATTERN, "https://github.com/<org>/<repo>");
|
|
163
|
+
const brand = requireString(record.brand, "brand");
|
|
164
|
+
const frontend = requireString(record.frontend, "frontend");
|
|
165
|
+
if (frontend !== "pretext" && frontend !== "markus-static") {
|
|
166
|
+
fail("frontend", `must be "pretext" or "markus-static", got ${JSON.stringify(frontend)}`);
|
|
167
|
+
}
|
|
168
|
+
const hostedZoneId = optionalString(record.hostedZoneId, "hostedZoneId", HOSTED_ZONE_ID_PATTERN, "Route 53 zone id");
|
|
169
|
+
const stackName = optionalString(record.stackName, "stackName", STACK_NAME_PATTERN, "CloudFormation stack name");
|
|
170
|
+
const papyrusVersion = requireString(record.papyrusVersion, "papyrusVersion", PAPYRUS_VERSION_PATTERN, "exact version such as 1.0.0 or 1.0.0-next.1");
|
|
171
|
+
const storagePreviewPrefix = optionalString(record.storagePreviewPrefix, "storagePreviewPrefix", /^[A-Za-z0-9._-]+\/$/, "must end with /");
|
|
172
|
+
|
|
173
|
+
const cmsRecord = requireObject(record.cms, "cms");
|
|
174
|
+
rejectUnknownKeys(cmsRecord, ["appName", "domainName", "staging", "cognitoDomainPrefix", "applyCognitoDomainPrefix", "buildComputeType", "environment", "stagingDomainName", "domainPrefix", "stagingDomainPrefix", "redirects"], "cms");
|
|
175
|
+
const buildComputeType = cmsRecord.buildComputeType;
|
|
176
|
+
if (buildComputeType !== undefined && buildComputeType !== "STANDARD" && buildComputeType !== "STANDARD_8GB") {
|
|
177
|
+
fail("cms.buildComputeType", `must be "STANDARD" or "STANDARD_8GB", got ${JSON.stringify(buildComputeType)}`);
|
|
178
|
+
}
|
|
179
|
+
if (cmsRecord.staging !== undefined && typeof cmsRecord.staging !== "boolean") {
|
|
180
|
+
fail("cms.staging", `must be a boolean, got ${JSON.stringify(cmsRecord.staging)}`);
|
|
181
|
+
}
|
|
182
|
+
if (cmsRecord.applyCognitoDomainPrefix !== undefined && typeof cmsRecord.applyCognitoDomainPrefix !== "boolean") {
|
|
183
|
+
fail("cms.applyCognitoDomainPrefix", `must be a boolean, got ${JSON.stringify(cmsRecord.applyCognitoDomainPrefix)}`);
|
|
184
|
+
}
|
|
185
|
+
const cms: AmplifyAppShellSiteConfig["cms"] = {
|
|
186
|
+
appName: optionalString(cmsRecord.appName, "cms.appName", APP_NAME_PATTERN),
|
|
187
|
+
domainName: optionalString(cmsRecord.domainName, "cms.domainName", HOST_NAME_PATTERN, "host name"),
|
|
188
|
+
domainPrefix: optionalString(cmsRecord.domainPrefix, "cms.domainPrefix", DOMAIN_PREFIX_PATTERN, "single DNS label"),
|
|
189
|
+
staging: cmsRecord.staging as boolean | undefined,
|
|
190
|
+
cognitoDomainPrefix: requireString(
|
|
191
|
+
cmsRecord.cognitoDomainPrefix,
|
|
192
|
+
"cms.cognitoDomainPrefix",
|
|
193
|
+
COGNITO_DOMAIN_PREFIX_PATTERN,
|
|
194
|
+
"lowercase letters, digits and hyphens; globally unique per region",
|
|
195
|
+
),
|
|
196
|
+
applyCognitoDomainPrefix: cmsRecord.applyCognitoDomainPrefix as boolean | undefined,
|
|
197
|
+
buildComputeType: buildComputeType as "STANDARD" | "STANDARD_8GB" | undefined,
|
|
198
|
+
environment: requireStringRecord(cmsRecord.environment, "cms.environment"),
|
|
199
|
+
stagingDomainName: optionalString(cmsRecord.stagingDomainName, "cms.stagingDomainName", HOST_NAME_PATTERN, "host name"),
|
|
200
|
+
stagingDomainPrefix: optionalString(cmsRecord.stagingDomainPrefix, "cms.stagingDomainPrefix", DOMAIN_PREFIX_PATTERN, "single DNS label"),
|
|
201
|
+
redirects: parseRedirects(cmsRecord.redirects),
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
const reservedWord = COGNITO_RESERVED_WORDS.find((word) => cms.cognitoDomainPrefix.includes(word));
|
|
205
|
+
if (reservedWord) {
|
|
206
|
+
fail("cms.cognitoDomainPrefix", `must not contain "${reservedWord}" (Cognito reserves it): ${JSON.stringify(cms.cognitoDomainPrefix)}`);
|
|
207
|
+
}
|
|
208
|
+
for (const key of TEMPLATE_MANAGED_ENVIRONMENT_KEYS) {
|
|
209
|
+
if (key in cms.environment) {
|
|
210
|
+
fail(`cms.environment.${key}`, "is managed by the template: Google sign-in is always on, the Cognito domain comes from cms.cognitoDomainPrefix and the revalidation secret parameter is derived from siteId");
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (cms.staging === false && cms.stagingDomainName) {
|
|
215
|
+
fail("cms.stagingDomainName", "must not be set when cms.staging is false");
|
|
216
|
+
}
|
|
217
|
+
if (cms.stagingDomainName && !cms.domainName) {
|
|
218
|
+
fail("cms.stagingDomainName", "requires cms.domainName");
|
|
219
|
+
}
|
|
220
|
+
if (cms.domainPrefix && !cms.domainName) {
|
|
221
|
+
fail("cms.domainPrefix", "requires cms.domainName (the root domain)");
|
|
222
|
+
}
|
|
223
|
+
if (cms.stagingDomainPrefix && !cms.domainPrefix) {
|
|
224
|
+
fail("cms.stagingDomainPrefix", "requires cms.domainPrefix");
|
|
225
|
+
}
|
|
226
|
+
if (cms.domainPrefix && cms.stagingDomainName) {
|
|
227
|
+
fail("cms.stagingDomainName", "must not be set with cms.domainPrefix: use cms.stagingDomainPrefix");
|
|
228
|
+
}
|
|
229
|
+
if (cms.staging === false && cms.stagingDomainPrefix) {
|
|
230
|
+
fail("cms.stagingDomainPrefix", "must not be set when cms.staging is false");
|
|
231
|
+
}
|
|
232
|
+
if (cms.domainPrefix && cms.staging !== false && !cms.stagingDomainPrefix) {
|
|
233
|
+
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");
|
|
234
|
+
}
|
|
235
|
+
if (cms.domainPrefix && cms.stagingDomainPrefix === cms.domainPrefix) {
|
|
236
|
+
fail("cms.stagingDomainPrefix", "must differ from cms.domainPrefix");
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
if (cms.redirects) {
|
|
240
|
+
if (!cms.domainPrefix) fail("cms.redirects", "requires cms.domainPrefix (redirects target the primary host under a shared root domain)");
|
|
241
|
+
cms.redirects.forEach((redirect, index) => {
|
|
242
|
+
const field = `cms.redirects[${index}].source`;
|
|
243
|
+
const root = cms.domainName as string;
|
|
244
|
+
if (redirect.source !== root && !(redirect.source.endsWith(`.${root}`) && DOMAIN_PREFIX_PATTERN.test(redirect.source.slice(0, -root.length - 1)))) {
|
|
245
|
+
fail(field, `must be the root domain ${root} or a single label under it: ${JSON.stringify(redirect.source)}`);
|
|
246
|
+
}
|
|
247
|
+
if (redirect.source === resolveCmsHostName({ cms })) fail(field, "must differ from the primary host");
|
|
248
|
+
if (redirect.source === resolveStagingDomainName({ cms })) fail(field, "must differ from the staging host");
|
|
249
|
+
});
|
|
250
|
+
if (new Set(cms.redirects.map((redirect) => redirect.source)).size !== cms.redirects.length) {
|
|
251
|
+
fail("cms.redirects", "must not repeat a source");
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
let reader: AmplifyAppShellSiteConfig["reader"];
|
|
256
|
+
if (record.reader !== undefined) {
|
|
257
|
+
if (frontend !== "markus-static") fail("reader", `is only allowed when frontend is "markus-static"`);
|
|
258
|
+
const readerRecord = requireObject(record.reader, "reader");
|
|
259
|
+
rejectUnknownKeys(readerRecord, ["appName", "domainName", "branchName", "buildCommand", "baseDirectory", "environment"], "reader");
|
|
260
|
+
reader = {
|
|
261
|
+
appName: optionalString(readerRecord.appName, "reader.appName", APP_NAME_PATTERN),
|
|
262
|
+
domainName: optionalString(readerRecord.domainName, "reader.domainName", HOST_NAME_PATTERN, "host name"),
|
|
263
|
+
branchName: optionalString(readerRecord.branchName, "reader.branchName", BRANCH_NAME_PATTERN),
|
|
264
|
+
buildCommand: requireString(readerRecord.buildCommand, "reader.buildCommand"),
|
|
265
|
+
baseDirectory: requireString(readerRecord.baseDirectory, "reader.baseDirectory"),
|
|
266
|
+
environment: readerRecord.environment === undefined ? undefined : requireStringRecord(readerRecord.environment, "reader.environment"),
|
|
267
|
+
};
|
|
268
|
+
} else if (frontend === "markus-static") {
|
|
269
|
+
fail("reader", `is required when frontend is "markus-static"`);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
let github: AmplifyAppShellSiteConfig["github"];
|
|
273
|
+
if (record.github !== undefined) {
|
|
274
|
+
const githubRecord = requireObject(record.github, "github");
|
|
275
|
+
rejectUnknownKeys(githubRecord, ["owner", "repo", "branches", "ciCanDeployInfra"], "github");
|
|
276
|
+
const owner = requireString(githubRecord.owner, "github.owner", GITHUB_OWNER_PATTERN, "plain GitHub login");
|
|
277
|
+
const repo = requireString(githubRecord.repo, "github.repo", GITHUB_REPO_PATTERN);
|
|
278
|
+
if (repository !== `https://github.com/${owner}/${repo}`) {
|
|
279
|
+
fail("github", `owner/repo must match repository ${repository}`);
|
|
280
|
+
}
|
|
281
|
+
let branches = cms.staging === false ? DEFAULT_CI_BRANCHES.filter((branch) => branch !== "staging") : DEFAULT_CI_BRANCHES;
|
|
282
|
+
if (githubRecord.branches !== undefined) {
|
|
283
|
+
if (!Array.isArray(githubRecord.branches) || githubRecord.branches.length === 0) {
|
|
284
|
+
fail("github.branches", "must be a non-empty array of branch names");
|
|
285
|
+
}
|
|
286
|
+
branches = (githubRecord.branches as unknown[]).map((branch, index) => {
|
|
287
|
+
if (typeof branch === "string" && /[*?]/.test(branch)) {
|
|
288
|
+
fail(`github.branches[${index}]`, `must not contain wildcards: ${JSON.stringify(branch)}`);
|
|
289
|
+
}
|
|
290
|
+
return requireString(branch, `github.branches[${index}]`, BRANCH_NAME_PATTERN);
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
const ciCanDeployInfra = githubRecord.ciCanDeployInfra ?? false;
|
|
294
|
+
if (typeof ciCanDeployInfra !== "boolean") fail("github.ciCanDeployInfra", "must be a boolean");
|
|
295
|
+
github = { owner, repo, branches, ciCanDeployInfra: ciCanDeployInfra as boolean };
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const hasDomain = cms.domainName !== undefined || reader?.domainName !== undefined;
|
|
299
|
+
if (hasDomain && hostedZoneId === undefined) {
|
|
300
|
+
fail("hostedZoneId", "is required when cms.domainName or reader.domainName is set");
|
|
301
|
+
}
|
|
302
|
+
if (!hasDomain && hostedZoneId !== undefined) {
|
|
303
|
+
fail("hostedZoneId", "is only allowed when cms.domainName or reader.domainName is set");
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const config: AmplifyAppShellSiteConfig = {
|
|
307
|
+
siteId,
|
|
308
|
+
repository,
|
|
309
|
+
brand,
|
|
310
|
+
frontend,
|
|
311
|
+
hostedZoneId,
|
|
312
|
+
stackName,
|
|
313
|
+
cms,
|
|
314
|
+
reader,
|
|
315
|
+
papyrusVersion,
|
|
316
|
+
storagePreviewPrefix,
|
|
317
|
+
github,
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
const redirectValue = cms.environment.PAPYRUS_OAUTH_REDIRECT_URLS;
|
|
321
|
+
if (redirectValue === undefined) fail("cms.environment.PAPYRUS_OAUTH_REDIRECT_URLS", "is required");
|
|
322
|
+
const redirectUrls = redirectValue.split(",").map((url) => url.trim());
|
|
323
|
+
const stagingDomainName = resolveStagingDomainName(config);
|
|
324
|
+
const requiredOrigins = [
|
|
325
|
+
...(resolveCmsHostName(config) ? [`https://${resolveCmsHostName(config)}/`] : []),
|
|
326
|
+
...(stagingDomainName ? [`https://${stagingDomainName}/`] : []),
|
|
327
|
+
LOCAL_DEVELOPMENT_ORIGIN,
|
|
328
|
+
];
|
|
329
|
+
for (const origin of requiredOrigins) {
|
|
330
|
+
if (!redirectUrls.includes(origin)) {
|
|
331
|
+
fail("cms.environment.PAPYRUS_OAUTH_REDIRECT_URLS", `must include ${origin}`);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
return config;
|
|
336
|
+
}
|