@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.
Files changed (140) hide show
  1. package/amplify/auth/resource.js +17 -4
  2. package/amplify/auth/resource.ts +21 -4
  3. package/amplify/data/resource.js +52 -70
  4. package/amplify/data/resource.ts +57 -70
  5. package/amplify/data/schema.js +52 -58
  6. package/amplify/data/schema.ts +57 -58
  7. package/amplify/functions/console-chat-responder/py/execute_tactus_runner.py +0 -10
  8. package/amplify/functions/console-chat-responder/resource.js +0 -7
  9. package/amplify/functions/console-chat-responder/resource.ts +0 -8
  10. package/amplify/functions/console-chat-responder/src/main.rs +0 -9
  11. package/amplify/functions/content-actions/handler.py +149 -0
  12. package/amplify/functions/content-actions/requirements.txt +4 -0
  13. package/amplify/functions/content-actions/resource.js +40 -0
  14. package/amplify/functions/content-actions/resource.ts +54 -0
  15. package/amplify/functions/shared/python-bundle.js +17 -2
  16. package/amplify/functions/shared/python-bundle.ts +23 -2
  17. package/amplify/rebuild-trigger-settings.js +22 -0
  18. package/amplify/rebuild-trigger-settings.ts +42 -0
  19. package/amplify/site-backend-config.ts +12 -1
  20. package/amplify/site-backend.js +51 -27
  21. package/amplify/site-backend.ts +66 -34
  22. package/amplify/storage/resource.js +3 -0
  23. package/amplify/storage/resource.ts +3 -0
  24. package/app/%5F_preview/[[...path]]/route.ts +8 -0
  25. package/app/[year]/[month]/[day]/[articleSlug]/page.tsx +4 -2
  26. package/app/[year]/[month]/[day]/edition-route-page.tsx +2 -0
  27. package/app/api/revalidate/route.ts +8 -7
  28. package/app/articles/[slug]/page.tsx +6 -4
  29. package/app/blog-rhythm.css +278 -0
  30. package/app/globals.css +22 -4
  31. package/app/layout.tsx +24 -12
  32. package/app/newsroom/articles/[id]/page.tsx +15 -0
  33. package/app/newsroom/articles/page.tsx +13 -0
  34. package/app/page.tsx +12 -4
  35. package/app/robots.ts +11 -0
  36. package/bin/papyrus-app.mjs +12 -2
  37. package/bin/papyrus-infra.mjs +74 -18
  38. package/components/archive-shell.tsx +2 -22
  39. package/components/article-video.tsx +247 -3
  40. package/components/blog-page-background.tsx +23 -6
  41. package/components/markus-ir-preview.tsx +300 -0
  42. package/components/news-desk-page.tsx +1 -4
  43. package/components/newspaper.tsx +6 -2
  44. package/components/newsroom-access-gate.tsx +66 -0
  45. package/components/newsroom-article-editor.tsx +741 -0
  46. package/components/newsroom-articles-view.tsx +129 -0
  47. package/components/newsroom-ops-overview.tsx +28 -11
  48. package/components/newsroom-ops-shell.tsx +3 -1
  49. package/components/pictogram-figure.tsx +9 -2
  50. package/components/presentation-header.tsx +135 -0
  51. package/components/presentation-rhythm-hrule.tsx +17 -0
  52. package/components/settings-page.tsx +2 -1
  53. package/components/staging-banner.tsx +11 -0
  54. package/components/topic-steering-workspace.tsx +1 -59
  55. package/components/use-blog-header-obstacles.ts +81 -0
  56. package/components/use-brand-fonts-ready.ts +28 -0
  57. package/components/use-rhythm-overlay.ts +29 -0
  58. package/infra/amplify-app-shell.js +285 -80
  59. package/infra/amplify-app-shell.ts +326 -113
  60. package/infra/build-specs.js +94 -0
  61. package/infra/build-specs.ts +141 -0
  62. package/infra/github-oidc-provider.js +24 -0
  63. package/infra/github-oidc-provider.ts +30 -0
  64. package/infra/index.js +3 -0
  65. package/infra/site-config.js +273 -0
  66. package/infra/site-config.ts +336 -0
  67. package/lib/blog-feature-solver.ts +459 -0
  68. package/lib/blog-rhythm.ts +134 -0
  69. package/lib/brand-fonts-watch.ts +43 -0
  70. package/lib/brand-fonts.ts +112 -0
  71. package/lib/cached-content-repository.ts +14 -1
  72. package/lib/category-repository.ts +1 -93
  73. package/lib/content-actions-client.ts +98 -0
  74. package/lib/content-actions-demo.ts +190 -0
  75. package/lib/content-repository.ts +6 -0
  76. package/lib/content-source-context.ts +26 -0
  77. package/lib/content-types.ts +4 -0
  78. package/lib/edition-routes.ts +31 -29
  79. package/lib/empty-theme.css +1 -0
  80. package/lib/graphql-content-repository.ts +239 -43
  81. package/lib/layout-scenarios.ts +8 -8
  82. package/lib/newspaper-layout.ts +3 -2
  83. package/lib/newsroom-articles.ts +325 -0
  84. package/lib/newsroom-demo-articles.ts +90 -0
  85. package/lib/newsroom-media-backend.ts +142 -0
  86. package/lib/newsroom-media.ts +182 -0
  87. package/lib/newsroom-nav.ts +3 -0
  88. package/lib/papyrus-web-locations.ts +7 -6
  89. package/lib/presentation-footer.ts +3 -2
  90. package/lib/pretext-layout.ts +12 -3
  91. package/lib/reader-base-path.ts +24 -0
  92. package/lib/reader-static-params.ts +8 -0
  93. package/lib/renderer.ts +7 -0
  94. package/lib/revalidate-secret.ts +59 -0
  95. package/lib/root-route-redirect.ts +16 -0
  96. package/lib/site-brand-tenant.ts +3 -22
  97. package/lib/site-brand.ts +95 -42
  98. package/lib/site-env.ts +52 -0
  99. package/lib/staging-gate.ts +37 -0
  100. package/lib/staging-gated-path.ts +22 -0
  101. package/lib/staging-preview-object.ts +98 -0
  102. package/lib/video-mode.ts +42 -0
  103. package/lib/video-script.ts +77 -0
  104. package/middleware.ts +56 -42
  105. package/package.json +40 -1
  106. package/renderers/pretext/article-page.tsx +40 -9
  107. package/renderers/pretext/presentation-shared.tsx +113 -0
  108. package/renderers/pretext/presentation-shell.tsx +18 -112
  109. package/renderers/pretext/rhythm-article-page.tsx +165 -0
  110. package/renderers/pretext/rhythm-blog-presentation.tsx +279 -0
  111. package/renderers/pretext/rhythm-shell-style.ts +35 -0
  112. package/routes.manifest.json +37 -2
  113. package/scripts/videoml/build-browser-bundle.mjs +22 -0
  114. package/scripts/videoml/build-preview-bundle.mjs +50 -0
  115. package/scripts/videoml/bundle-common.mjs +129 -0
  116. package/scripts/videoml/preview/preview-entry.tsx +381 -0
  117. package/scripts/videoml/preview/preview-stage-fit.ts +28 -0
  118. package/scripts/videoml/preview/preview-timing.ts +42 -0
  119. package/scripts/videoml/preview.html +77 -0
  120. package/scripts/videoml/standard-entry.tsx +46 -0
  121. package/src/sync.mjs +30 -6
  122. package/src/with-papyrus.mjs +15 -2
  123. package/amplify/functions/graphql-jwt-authorizer/handler.ts +0 -193
  124. package/amplify/functions/graphql-jwt-authorizer/resource.js +0 -14
  125. package/amplify/functions/graphql-jwt-authorizer/resource.ts +0 -15
  126. package/publications/anth_us/brand.ts +0 -68
  127. package/publications/anth_us/theme.css +0 -66
  128. package/publications/pilobol_us/brand.ts +0 -37
  129. package/publications/pilobol_us/theme.css +0 -140
  130. package/publications/threat_intelligence/blog-defense/graph.ts +0 -636
  131. package/publications/threat_intelligence/blog-defense/layout.ts +0 -934
  132. package/publications/threat_intelligence/blog-defense/page-background.tsx +0 -590
  133. package/publications/threat_intelligence/brand.ts +0 -40
  134. package/publications/threat_intelligence/pictograms/art.tsx +0 -608
  135. package/publications/threat_intelligence/pictograms/figure.tsx +0 -82
  136. package/publications/threat_intelligence/pictograms/registry.ts +0 -30
  137. package/publications/threat_intelligence/pictograms/system.tsx +0 -305
  138. package/publications/threat_intelligence/seed/seed-edition-content.json +0 -629
  139. package/publications/threat_intelligence/theme.css +0 -1440
  140. /package/{publications/papyrus/theme.css → app/papyrus-theme.css} +0 -0
@@ -0,0 +1,141 @@
1
+ import { AmplifyAppShellSiteConfig, resolveStoragePreviewPrefix } from "./site-config";
2
+
3
+ export type BuildSpecAppName = "cms-production" | "cms-staging" | "reader";
4
+
5
+ export function papyrusVersionToPep440(version: string): string {
6
+ const match = /^(\d+\.\d+\.\d+)(?:-[0-9A-Za-z-]+\.(\d+))?$/.exec(version);
7
+ if (!match) throw new Error(`cannot map ${version} to PEP 440`);
8
+ return match[2] === undefined ? match[1] : `${match[1]}.dev${match[2]}`;
9
+ }
10
+
11
+ function yamlScalar(command: string): string {
12
+ const needsQuoting = /: | #|^[-?:,\[\]{}#&*!|>'"%@`]|:$/.test(command);
13
+ return needsQuoting ? `'${command.replace(/'/g, "''")}'` : command;
14
+ }
15
+
16
+ function commandLines(commands: string[], indent: string): string[] {
17
+ return commands.map((command) => `${indent}- ${yamlScalar(command)}`);
18
+ }
19
+
20
+ const NPM_CLEAN_INSTALL = "npm ci --cache .npm --prefer-offline";
21
+
22
+ const FRONTEND_ENVIRONMENT_CAPTURE =
23
+ "env | grep -e '^PAPYRUS_' -e '^SITE_ENV=' -e '^NEXT_PUBLIC_' >> .env.production";
24
+
25
+ const CHECKOUT_AS_PAPYRUS_ROOT = "PAPYRUS_ROOT=\"$PWD\"";
26
+
27
+ const STAGING_RUNTIME_OUTPUTS_COMMANDS = [
28
+ "cp amplify_outputs.json .next/amplify_outputs.json",
29
+ "echo PAPYRUS_AMPLIFY_OUTPUTS=.next/amplify_outputs.json >> .env.production",
30
+ ];
31
+
32
+ function pythonProvisioningCommands(config: AmplifyAppShellSiteConfig): string[] {
33
+ return [
34
+ "export UV_CACHE_DIR=\"$PWD/.uv-cache\"",
35
+ "curl -LsSf https://astral.sh/uv/install.sh | sh",
36
+ "export PATH=\"$HOME/.local/bin:$PATH\"",
37
+ "uv python install 3.12",
38
+ "uv venv --python 3.12 .venv",
39
+ `uv pip install --python .venv "papyrus-newsroom[markus]==${papyrusVersionToPep440(config.papyrusVersion)}"`,
40
+ "export PATH=\"$PWD/.venv/bin:$PATH\"",
41
+ ];
42
+ }
43
+
44
+ function reader(config: AmplifyAppShellSiteConfig): NonNullable<AmplifyAppShellSiteConfig["reader"]> {
45
+ if (!config.reader) throw new Error(`site ${config.siteId} has no reader app (frontend ${config.frontend})`);
46
+ return config.reader;
47
+ }
48
+
49
+ function frontendSection(preBuildCommands: string[], buildCommands: string[], artifactsDirectory: string, cachePaths: string[]): string[] {
50
+ const lines = ["frontend:", " phases:"];
51
+ if (preBuildCommands.length > 0) {
52
+ lines.push(" preBuild:", " commands:", ...commandLines(preBuildCommands, " "));
53
+ }
54
+ lines.push(
55
+ " build:",
56
+ " commands:",
57
+ ...commandLines(buildCommands, " "),
58
+ " artifacts:",
59
+ ` baseDirectory: ${artifactsDirectory}`,
60
+ " files:",
61
+ " - '**/*'",
62
+ " cache:",
63
+ " paths:",
64
+ ...cachePaths.map((cachePath) => ` - ${cachePath}`),
65
+ );
66
+ return lines;
67
+ }
68
+
69
+ export function cmsProductionBuildSpec(config: AmplifyAppShellSiteConfig): string {
70
+ return [
71
+ "version: 1",
72
+ "backend:",
73
+ " phases:",
74
+ " build:",
75
+ " commands:",
76
+ ...commandLines(
77
+ [
78
+ NPM_CLEAN_INSTALL,
79
+ "if [ -z \"${PAPYRUS_CONSOLE_RESPONDER_IMAGE_URI:-}\" ]; then export PAPYRUS_CONSOLE_RESPONDER_ALLOW_LOCAL_BUILD=true; fi",
80
+ "npx ampx pipeline-deploy --branch $AWS_BRANCH --app-id $AWS_APP_ID",
81
+ ],
82
+ " ",
83
+ ),
84
+ ...frontendSection(
85
+ [],
86
+ [FRONTEND_ENVIRONMENT_CAPTURE, "npx papyrus-app sync && npm run build"],
87
+ ".next",
88
+ [".next/cache/**/*", ".npm/**/*"],
89
+ ),
90
+ ].join("\n") + "\n";
91
+ }
92
+
93
+ export function cmsStagingBuildSpec(config: AmplifyAppShellSiteConfig): string {
94
+ const preBuild = [NPM_CLEAN_INSTALL, "npx ampx generate outputs --branch main --app-id $AWS_APP_ID"];
95
+ const cachePaths = [".next/cache/**/*", ".npm/**/*"];
96
+ if (config.frontend === "markus-static") {
97
+ const readerConfig = reader(config);
98
+ preBuild.push(
99
+ ...pythonProvisioningCommands(config),
100
+ `${CHECKOUT_AS_PAPYRUS_ROOT} papyrus ops content export-published --drafts --out content-export --clean`,
101
+ readerConfig.buildCommand,
102
+ `${CHECKOUT_AS_PAPYRUS_ROOT} papyrus ops content upload-preview --dir ${readerConfig.baseDirectory} --prefix ${resolveStoragePreviewPrefix(config)}`,
103
+ );
104
+ cachePaths.push(".uv-cache/**/*");
105
+ }
106
+ return [
107
+ "version: 1",
108
+ ...frontendSection(
109
+ preBuild,
110
+ [
111
+ FRONTEND_ENVIRONMENT_CAPTURE,
112
+ "npx papyrus-app sync && npm run build",
113
+ ...STAGING_RUNTIME_OUTPUTS_COMMANDS,
114
+ ],
115
+ ".next",
116
+ cachePaths,
117
+ ),
118
+ ].join("\n") + "\n";
119
+ }
120
+
121
+ export function readerBuildSpec(config: AmplifyAppShellSiteConfig): string {
122
+ const readerConfig = reader(config);
123
+ return [
124
+ "version: 1",
125
+ ...frontendSection(
126
+ [
127
+ ...pythonProvisioningCommands(config),
128
+ "papyrus ops content export-published --auth guest --out content-export --clean",
129
+ ],
130
+ [readerConfig.buildCommand],
131
+ readerConfig.baseDirectory,
132
+ [".uv-cache/**/*"],
133
+ ),
134
+ ].join("\n") + "\n";
135
+ }
136
+
137
+ export function buildSpecFor(config: AmplifyAppShellSiteConfig, app: BuildSpecAppName): string {
138
+ if (app === "cms-production") return cmsProductionBuildSpec(config);
139
+ if (app === "cms-staging") return cmsStagingBuildSpec(config);
140
+ return readerBuildSpec(config);
141
+ }
@@ -0,0 +1,24 @@
1
+ import { CfnOutput, Stack } from "aws-cdk-lib";
2
+ import * as iam from "aws-cdk-lib/aws-iam";
3
+ export const GITHUB_OIDC_PROVIDER_HOST = "token.actions.githubusercontent.com";
4
+ /**
5
+ * Account-global singleton: AWS allows one IAM OIDC provider per issuer URL per
6
+ * account, so this never belongs in a per-site stack. Deploy it once per
7
+ * account, and only after `aws iam list-open-id-connect-providers` shows no
8
+ * provider for token.actions.githubusercontent.com. When one already exists,
9
+ * do not deploy this stack: per-site CI roles only reference the provider by
10
+ * its ARN (arn:aws:iam::<account>:oidc-provider/token.actions.githubusercontent.com)
11
+ * and work against an existing provider unchanged.
12
+ */
13
+ export class GithubOidcProviderStack extends Stack {
14
+ providerArn;
15
+ constructor(scope, id, props) {
16
+ super(scope, id, props);
17
+ const provider = new iam.OpenIdConnectProvider(this, "GithubOidc", {
18
+ url: `https://${GITHUB_OIDC_PROVIDER_HOST}`,
19
+ clientIds: ["sts.amazonaws.com"],
20
+ });
21
+ this.providerArn = provider.openIdConnectProviderArn;
22
+ new CfnOutput(this, "GithubOidcProviderArn", { value: provider.openIdConnectProviderArn });
23
+ }
24
+ }
@@ -0,0 +1,30 @@
1
+ import { Construct } from "constructs";
2
+ import { CfnOutput, Stack, StackProps } from "aws-cdk-lib";
3
+ import * as iam from "aws-cdk-lib/aws-iam";
4
+
5
+ export const GITHUB_OIDC_PROVIDER_HOST = "token.actions.githubusercontent.com";
6
+
7
+ /**
8
+ * Account-global singleton: AWS allows one IAM OIDC provider per issuer URL per
9
+ * account, so this never belongs in a per-site stack. Deploy it once per
10
+ * account, and only after `aws iam list-open-id-connect-providers` shows no
11
+ * provider for token.actions.githubusercontent.com. When one already exists,
12
+ * do not deploy this stack: per-site CI roles only reference the provider by
13
+ * its ARN (arn:aws:iam::<account>:oidc-provider/token.actions.githubusercontent.com)
14
+ * and work against an existing provider unchanged.
15
+ */
16
+ export class GithubOidcProviderStack extends Stack {
17
+ public readonly providerArn: string;
18
+
19
+ constructor(scope: Construct, id: string, props?: StackProps) {
20
+ super(scope, id, props);
21
+
22
+ const provider = new iam.OpenIdConnectProvider(this, "GithubOidc", {
23
+ url: `https://${GITHUB_OIDC_PROVIDER_HOST}`,
24
+ clientIds: ["sts.amazonaws.com"],
25
+ });
26
+
27
+ this.providerArn = provider.openIdConnectProviderArn;
28
+ new CfnOutput(this, "GithubOidcProviderArn", { value: provider.openIdConnectProviderArn });
29
+ }
30
+ }
package/infra/index.js CHANGED
@@ -10,3 +10,6 @@ try {
10
10
  );
11
11
  }
12
12
  export const { AmplifyAppShellStack } = await import("./amplify-app-shell.js");
13
+ export const { GithubOidcProviderStack } = await import("./github-oidc-provider.js");
14
+ export { parseSiteConfig } from "./site-config.js";
15
+ export { cmsProductionBuildSpec, cmsStagingBuildSpec, readerBuildSpec, buildSpecFor } from "./build-specs.js";
@@ -0,0 +1,273 @@
1
+ export const DEFAULT_CI_BRANCHES = ["main", "staging"];
2
+ const SITE_ID_PATTERN = /^[a-z][a-z0-9]*(-[a-z0-9]+)*$/;
3
+ const REPOSITORY_PATTERN = /^https:\/\/github\.com\/[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/;
4
+ const HOSTED_ZONE_ID_PATTERN = /^Z[A-Z0-9]+$/;
5
+ const HOST_NAME_PATTERN = /^([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,}$/;
6
+ const DOMAIN_PREFIX_PATTERN = /^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/;
7
+ const APP_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9 _.-]*$/;
8
+ const STACK_NAME_PATTERN = /^[A-Za-z][A-Za-z0-9-]{0,127}$/;
9
+ const BRANCH_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9/_.-]*$/;
10
+ const PAPYRUS_VERSION_PATTERN = /^\d+\.\d+\.\d+(-[0-9A-Za-z-]+\.\d+)?$/;
11
+ const GITHUB_OWNER_PATTERN = /^[A-Za-z0-9](?:[A-Za-z0-9]|-(?=[A-Za-z0-9])){0,38}$/;
12
+ const GITHUB_REPO_PATTERN = /^[A-Za-z0-9_.-]+$/;
13
+ const COGNITO_DOMAIN_PREFIX_PATTERN = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
14
+ const COGNITO_RESERVED_WORDS = ["aws", "amazon", "cognito"];
15
+ const TEMPLATE_MANAGED_ENVIRONMENT_KEYS = ["PAPYRUS_COGNITO_DOMAIN_PREFIX", "PAPYRUS_APPLY_COGNITO_DOMAIN_PREFIX", "PAPYRUS_DISABLE_GOOGLE_OAUTH", "PAPYRUS_REVALIDATE_SECRET_PARAMETER"];
16
+ export function resolveRevalidateSecretParameterName(config) {
17
+ return `/papyrus/${config.siteId}/revalidate-secret`;
18
+ }
19
+ const LOCAL_DEVELOPMENT_ORIGIN = "http://localhost:3001/";
20
+ function fail(field, problem) {
21
+ throw new Error(`site.json: ${field} ${problem}`);
22
+ }
23
+ function requireObject(value, field) {
24
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
25
+ fail(field, "must be an object");
26
+ }
27
+ return value;
28
+ }
29
+ function requireString(value, field, pattern, patternHint) {
30
+ if (typeof value !== "string" || value.trim() === "") {
31
+ fail(field, "must be a non-empty string");
32
+ }
33
+ if (pattern && !pattern.test(value)) {
34
+ fail(field, `is invalid${patternHint ? ` (${patternHint})` : ""}: ${JSON.stringify(value)}`);
35
+ }
36
+ return value;
37
+ }
38
+ function optionalString(value, field, pattern, patternHint) {
39
+ return value === undefined ? undefined : requireString(value, field, pattern, patternHint);
40
+ }
41
+ function requireStringRecord(value, field) {
42
+ const record = requireObject(value, field);
43
+ const result = {};
44
+ for (const [key, entry] of Object.entries(record)) {
45
+ if (typeof entry !== "string")
46
+ fail(`${field}.${key}`, "must be a string");
47
+ result[key] = entry;
48
+ }
49
+ return result;
50
+ }
51
+ function rejectUnknownKeys(record, allowed, field) {
52
+ for (const key of Object.keys(record)) {
53
+ if (!allowed.includes(key))
54
+ fail(`${field}.${key}`, `is not a known field (known: ${allowed.join(", ")})`);
55
+ }
56
+ }
57
+ function parseRedirects(value) {
58
+ if (value === undefined)
59
+ return undefined;
60
+ if (!Array.isArray(value) || value.length === 0)
61
+ fail("cms.redirects", "must be a non-empty array");
62
+ return value.map((entry, index) => {
63
+ const field = `cms.redirects[${index}]`;
64
+ const record = requireObject(entry, field);
65
+ rejectUnknownKeys(record, ["source", "status"], field);
66
+ const source = requireString(record.source, `${field}.source`, HOST_NAME_PATTERN, "host name without scheme or path");
67
+ const status = record.status ?? 301;
68
+ if (status !== 301 && status !== 302)
69
+ fail(`${field}.status`, `must be 301 or 302, got ${JSON.stringify(status)}`);
70
+ return { source, status };
71
+ });
72
+ }
73
+ export function resolveRedirectSubDomainPrefix(rootDomain, source) {
74
+ return source === rootDomain ? "" : source.slice(0, -rootDomain.length - 1);
75
+ }
76
+ export function isStagingEnabled(config) {
77
+ return config.cms.staging !== false;
78
+ }
79
+ export function resolveCmsHostName(config) {
80
+ if (!config.cms.domainName)
81
+ return undefined;
82
+ return config.cms.domainPrefix ? `${config.cms.domainPrefix}.${config.cms.domainName}` : config.cms.domainName;
83
+ }
84
+ export function resolveStagingDomainName(config) {
85
+ if (!isStagingEnabled(config))
86
+ return undefined;
87
+ if (config.cms.domainPrefix) {
88
+ return config.cms.stagingDomainPrefix ? `${config.cms.stagingDomainPrefix}.${config.cms.domainName}` : undefined;
89
+ }
90
+ if (config.cms.stagingDomainName)
91
+ return config.cms.stagingDomainName;
92
+ if (!config.cms.domainName)
93
+ return undefined;
94
+ const [, ...rest] = config.cms.domainName.split(".");
95
+ return ["staging", ...rest].join(".");
96
+ }
97
+ export function resolveStackName(config) {
98
+ return config.stackName ?? `amplify-app-shell-${config.siteId}`;
99
+ }
100
+ export function resolveStoragePreviewPrefix(config) {
101
+ return config.storagePreviewPrefix ?? "preview/";
102
+ }
103
+ export function parseSiteConfig(raw) {
104
+ const record = requireObject(raw, "site");
105
+ rejectUnknownKeys(record, ["siteId", "repository", "brand", "frontend", "hostedZoneId", "stackName", "cms", "reader", "papyrusVersion", "storagePreviewPrefix", "github"], "site");
106
+ const siteId = requireString(record.siteId, "siteId", SITE_ID_PATTERN, "kebab-case");
107
+ const repository = requireString(record.repository, "repository", REPOSITORY_PATTERN, "https://github.com/<org>/<repo>");
108
+ const brand = requireString(record.brand, "brand");
109
+ const frontend = requireString(record.frontend, "frontend");
110
+ if (frontend !== "pretext" && frontend !== "markus-static") {
111
+ fail("frontend", `must be "pretext" or "markus-static", got ${JSON.stringify(frontend)}`);
112
+ }
113
+ const hostedZoneId = optionalString(record.hostedZoneId, "hostedZoneId", HOSTED_ZONE_ID_PATTERN, "Route 53 zone id");
114
+ const stackName = optionalString(record.stackName, "stackName", STACK_NAME_PATTERN, "CloudFormation stack name");
115
+ const papyrusVersion = requireString(record.papyrusVersion, "papyrusVersion", PAPYRUS_VERSION_PATTERN, "exact version such as 1.0.0 or 1.0.0-next.1");
116
+ const storagePreviewPrefix = optionalString(record.storagePreviewPrefix, "storagePreviewPrefix", /^[A-Za-z0-9._-]+\/$/, "must end with /");
117
+ const cmsRecord = requireObject(record.cms, "cms");
118
+ rejectUnknownKeys(cmsRecord, ["appName", "domainName", "staging", "cognitoDomainPrefix", "applyCognitoDomainPrefix", "buildComputeType", "environment", "stagingDomainName", "domainPrefix", "stagingDomainPrefix", "redirects"], "cms");
119
+ const buildComputeType = cmsRecord.buildComputeType;
120
+ if (buildComputeType !== undefined && buildComputeType !== "STANDARD" && buildComputeType !== "STANDARD_8GB") {
121
+ fail("cms.buildComputeType", `must be "STANDARD" or "STANDARD_8GB", got ${JSON.stringify(buildComputeType)}`);
122
+ }
123
+ if (cmsRecord.staging !== undefined && typeof cmsRecord.staging !== "boolean") {
124
+ fail("cms.staging", `must be a boolean, got ${JSON.stringify(cmsRecord.staging)}`);
125
+ }
126
+ if (cmsRecord.applyCognitoDomainPrefix !== undefined && typeof cmsRecord.applyCognitoDomainPrefix !== "boolean") {
127
+ fail("cms.applyCognitoDomainPrefix", `must be a boolean, got ${JSON.stringify(cmsRecord.applyCognitoDomainPrefix)}`);
128
+ }
129
+ const cms = {
130
+ appName: optionalString(cmsRecord.appName, "cms.appName", APP_NAME_PATTERN),
131
+ domainName: optionalString(cmsRecord.domainName, "cms.domainName", HOST_NAME_PATTERN, "host name"),
132
+ domainPrefix: optionalString(cmsRecord.domainPrefix, "cms.domainPrefix", DOMAIN_PREFIX_PATTERN, "single DNS label"),
133
+ staging: cmsRecord.staging,
134
+ cognitoDomainPrefix: requireString(cmsRecord.cognitoDomainPrefix, "cms.cognitoDomainPrefix", COGNITO_DOMAIN_PREFIX_PATTERN, "lowercase letters, digits and hyphens; globally unique per region"),
135
+ applyCognitoDomainPrefix: cmsRecord.applyCognitoDomainPrefix,
136
+ buildComputeType: buildComputeType,
137
+ environment: requireStringRecord(cmsRecord.environment, "cms.environment"),
138
+ stagingDomainName: optionalString(cmsRecord.stagingDomainName, "cms.stagingDomainName", HOST_NAME_PATTERN, "host name"),
139
+ stagingDomainPrefix: optionalString(cmsRecord.stagingDomainPrefix, "cms.stagingDomainPrefix", DOMAIN_PREFIX_PATTERN, "single DNS label"),
140
+ redirects: parseRedirects(cmsRecord.redirects),
141
+ };
142
+ const reservedWord = COGNITO_RESERVED_WORDS.find((word) => cms.cognitoDomainPrefix.includes(word));
143
+ if (reservedWord) {
144
+ fail("cms.cognitoDomainPrefix", `must not contain "${reservedWord}" (Cognito reserves it): ${JSON.stringify(cms.cognitoDomainPrefix)}`);
145
+ }
146
+ for (const key of TEMPLATE_MANAGED_ENVIRONMENT_KEYS) {
147
+ if (key in cms.environment) {
148
+ 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");
149
+ }
150
+ }
151
+ if (cms.staging === false && cms.stagingDomainName) {
152
+ fail("cms.stagingDomainName", "must not be set when cms.staging is false");
153
+ }
154
+ if (cms.stagingDomainName && !cms.domainName) {
155
+ fail("cms.stagingDomainName", "requires cms.domainName");
156
+ }
157
+ if (cms.domainPrefix && !cms.domainName) {
158
+ fail("cms.domainPrefix", "requires cms.domainName (the root domain)");
159
+ }
160
+ if (cms.stagingDomainPrefix && !cms.domainPrefix) {
161
+ fail("cms.stagingDomainPrefix", "requires cms.domainPrefix");
162
+ }
163
+ if (cms.domainPrefix && cms.stagingDomainName) {
164
+ fail("cms.stagingDomainName", "must not be set with cms.domainPrefix: use cms.stagingDomainPrefix");
165
+ }
166
+ if (cms.staging === false && cms.stagingDomainPrefix) {
167
+ fail("cms.stagingDomainPrefix", "must not be set when cms.staging is false");
168
+ }
169
+ if (cms.domainPrefix && cms.staging !== false && !cms.stagingDomainPrefix) {
170
+ 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");
171
+ }
172
+ if (cms.domainPrefix && cms.stagingDomainPrefix === cms.domainPrefix) {
173
+ fail("cms.stagingDomainPrefix", "must differ from cms.domainPrefix");
174
+ }
175
+ if (cms.redirects) {
176
+ if (!cms.domainPrefix)
177
+ fail("cms.redirects", "requires cms.domainPrefix (redirects target the primary host under a shared root domain)");
178
+ cms.redirects.forEach((redirect, index) => {
179
+ const field = `cms.redirects[${index}].source`;
180
+ const root = cms.domainName;
181
+ if (redirect.source !== root && !(redirect.source.endsWith(`.${root}`) && DOMAIN_PREFIX_PATTERN.test(redirect.source.slice(0, -root.length - 1)))) {
182
+ fail(field, `must be the root domain ${root} or a single label under it: ${JSON.stringify(redirect.source)}`);
183
+ }
184
+ if (redirect.source === resolveCmsHostName({ cms }))
185
+ fail(field, "must differ from the primary host");
186
+ if (redirect.source === resolveStagingDomainName({ cms }))
187
+ fail(field, "must differ from the staging host");
188
+ });
189
+ if (new Set(cms.redirects.map((redirect) => redirect.source)).size !== cms.redirects.length) {
190
+ fail("cms.redirects", "must not repeat a source");
191
+ }
192
+ }
193
+ let reader;
194
+ if (record.reader !== undefined) {
195
+ if (frontend !== "markus-static")
196
+ fail("reader", `is only allowed when frontend is "markus-static"`);
197
+ const readerRecord = requireObject(record.reader, "reader");
198
+ rejectUnknownKeys(readerRecord, ["appName", "domainName", "branchName", "buildCommand", "baseDirectory", "environment"], "reader");
199
+ reader = {
200
+ appName: optionalString(readerRecord.appName, "reader.appName", APP_NAME_PATTERN),
201
+ domainName: optionalString(readerRecord.domainName, "reader.domainName", HOST_NAME_PATTERN, "host name"),
202
+ branchName: optionalString(readerRecord.branchName, "reader.branchName", BRANCH_NAME_PATTERN),
203
+ buildCommand: requireString(readerRecord.buildCommand, "reader.buildCommand"),
204
+ baseDirectory: requireString(readerRecord.baseDirectory, "reader.baseDirectory"),
205
+ environment: readerRecord.environment === undefined ? undefined : requireStringRecord(readerRecord.environment, "reader.environment"),
206
+ };
207
+ }
208
+ else if (frontend === "markus-static") {
209
+ fail("reader", `is required when frontend is "markus-static"`);
210
+ }
211
+ let github;
212
+ if (record.github !== undefined) {
213
+ const githubRecord = requireObject(record.github, "github");
214
+ rejectUnknownKeys(githubRecord, ["owner", "repo", "branches", "ciCanDeployInfra"], "github");
215
+ const owner = requireString(githubRecord.owner, "github.owner", GITHUB_OWNER_PATTERN, "plain GitHub login");
216
+ const repo = requireString(githubRecord.repo, "github.repo", GITHUB_REPO_PATTERN);
217
+ if (repository !== `https://github.com/${owner}/${repo}`) {
218
+ fail("github", `owner/repo must match repository ${repository}`);
219
+ }
220
+ let branches = cms.staging === false ? DEFAULT_CI_BRANCHES.filter((branch) => branch !== "staging") : DEFAULT_CI_BRANCHES;
221
+ if (githubRecord.branches !== undefined) {
222
+ if (!Array.isArray(githubRecord.branches) || githubRecord.branches.length === 0) {
223
+ fail("github.branches", "must be a non-empty array of branch names");
224
+ }
225
+ branches = githubRecord.branches.map((branch, index) => {
226
+ if (typeof branch === "string" && /[*?]/.test(branch)) {
227
+ fail(`github.branches[${index}]`, `must not contain wildcards: ${JSON.stringify(branch)}`);
228
+ }
229
+ return requireString(branch, `github.branches[${index}]`, BRANCH_NAME_PATTERN);
230
+ });
231
+ }
232
+ const ciCanDeployInfra = githubRecord.ciCanDeployInfra ?? false;
233
+ if (typeof ciCanDeployInfra !== "boolean")
234
+ fail("github.ciCanDeployInfra", "must be a boolean");
235
+ github = { owner, repo, branches, ciCanDeployInfra: ciCanDeployInfra };
236
+ }
237
+ const hasDomain = cms.domainName !== undefined || reader?.domainName !== undefined;
238
+ if (hasDomain && hostedZoneId === undefined) {
239
+ fail("hostedZoneId", "is required when cms.domainName or reader.domainName is set");
240
+ }
241
+ if (!hasDomain && hostedZoneId !== undefined) {
242
+ fail("hostedZoneId", "is only allowed when cms.domainName or reader.domainName is set");
243
+ }
244
+ const config = {
245
+ siteId,
246
+ repository,
247
+ brand,
248
+ frontend,
249
+ hostedZoneId,
250
+ stackName,
251
+ cms,
252
+ reader,
253
+ papyrusVersion,
254
+ storagePreviewPrefix,
255
+ github,
256
+ };
257
+ const redirectValue = cms.environment.PAPYRUS_OAUTH_REDIRECT_URLS;
258
+ if (redirectValue === undefined)
259
+ fail("cms.environment.PAPYRUS_OAUTH_REDIRECT_URLS", "is required");
260
+ const redirectUrls = redirectValue.split(",").map((url) => url.trim());
261
+ const stagingDomainName = resolveStagingDomainName(config);
262
+ const requiredOrigins = [
263
+ ...(resolveCmsHostName(config) ? [`https://${resolveCmsHostName(config)}/`] : []),
264
+ ...(stagingDomainName ? [`https://${stagingDomainName}/`] : []),
265
+ LOCAL_DEVELOPMENT_ORIGIN,
266
+ ];
267
+ for (const origin of requiredOrigins) {
268
+ if (!redirectUrls.includes(origin)) {
269
+ fail("cms.environment.PAPYRUS_OAUTH_REDIRECT_URLS", `must include ${origin}`);
270
+ }
271
+ }
272
+ return config;
273
+ }