@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
|
@@ -1,155 +1,368 @@
|
|
|
1
|
-
export type AmplifyAppShellSiteConfig = {
|
|
2
|
-
/** CDK context selector and stack id suffix. */
|
|
3
|
-
siteId: string;
|
|
4
|
-
/** Amplify app name (also the CloudFormation stack-friendly id). */
|
|
5
|
-
appName: string;
|
|
6
|
-
/** Human description shown in the Amplify console. */
|
|
7
|
-
description: string;
|
|
8
|
-
/** GitHub repo URL the CMS deploys from. */
|
|
9
|
-
repository: string;
|
|
10
|
-
/** Amplify platform. Papyrus CMS is always WEB_COMPUTE (Next.js SSR). */
|
|
11
|
-
platform: "WEB_COMPUTE";
|
|
12
|
-
/** Deploy branch. */
|
|
13
|
-
branchName: string;
|
|
14
|
-
/** Branch environment variables (PAPYRUS_SITE_BRAND etc.). */
|
|
15
|
-
environment: Record<string, string>;
|
|
16
|
-
/**
|
|
17
|
-
* Secrets Manager secret name holding the GitHub access token used by
|
|
18
|
-
* Amplify to clone the repo. CDK reads it via a dynamic reference so the
|
|
19
|
-
* token never lands in the CloudFormation template. Populate the secret
|
|
20
|
-
* before deploying. Replace the initial token with a dedicated fine-grained
|
|
21
|
-
* PAT scoped to this repo.
|
|
22
|
-
*/
|
|
23
|
-
githubTokenSecretName: string;
|
|
24
|
-
/** Custom domain for the CMS (newsroom.<site>.us). Apex stays on the reader. */
|
|
25
|
-
domainName: string;
|
|
26
|
-
/** Route 53 hosted zone id for the domain. */
|
|
27
|
-
hostedZoneId: string;
|
|
28
|
-
/** Build compute type. */
|
|
29
|
-
buildComputeType?: "STANDARD" | "STANDARD_8GB";
|
|
30
|
-
/** Enable branch auto-build so pushes trigger deploys. */
|
|
31
|
-
enableAutoBuild?: boolean;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
1
|
import { Construct } from "constructs";
|
|
35
|
-
import { Stack, StackProps
|
|
2
|
+
import { ArnFormat, CfnOutput, Duration, Fn, Stack, StackProps } from "aws-cdk-lib";
|
|
36
3
|
import * as iam from "aws-cdk-lib/aws-iam";
|
|
37
4
|
import * as amplify from "aws-cdk-lib/aws-amplify";
|
|
5
|
+
import { GITHUB_OIDC_PROVIDER_HOST } from "./github-oidc-provider";
|
|
6
|
+
import { cmsProductionBuildSpec, cmsStagingBuildSpec, readerBuildSpec } from "./build-specs";
|
|
7
|
+
import { AmplifyAppShellSiteConfig, isStagingEnabled, resolveRedirectSubDomainPrefix, resolveCmsHostName, resolveRevalidateSecretParameterName, resolveStackName, resolveStagingDomainName, resolveStoragePreviewPrefix } from "./site-config";
|
|
38
8
|
|
|
9
|
+
function environmentVariables(variables: Record<string, string>): amplify.CfnBranch.EnvironmentVariableProperty[] {
|
|
10
|
+
return Object.entries(variables).map(([name, value]) => ({ name, value }));
|
|
11
|
+
}
|
|
39
12
|
|
|
40
13
|
/**
|
|
41
|
-
* Provisions the Amplify *app shell*
|
|
14
|
+
* Provisions the Amplify *app shell* of a Papyrus publication from its
|
|
15
|
+
* site.json:
|
|
42
16
|
*
|
|
43
|
-
* -
|
|
44
|
-
*
|
|
45
|
-
* -
|
|
46
|
-
* -
|
|
17
|
+
* - CMS app (WEB_COMPUTE) with branches `main` (production, owns the backend)
|
|
18
|
+
* and `staging` (frontend only, reads the production backend)
|
|
19
|
+
* - for `markus-static` sites, a reader app (WEB) with branch `main`
|
|
20
|
+
* - a domain association per branch/app when a domain is configured (without
|
|
21
|
+
* one, no AWS::Amplify::Domain is created and the default amplifyapp.com
|
|
22
|
+
* URL is used), IAM service and compute roles
|
|
23
|
+
* - `cms.staging: false` omits the staging branch and its domain
|
|
47
24
|
*
|
|
48
|
-
*
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
25
|
+
* Google sign-in is always on: the branches never set PAPYRUS_DISABLE_GOOGLE_OAUTH,
|
|
26
|
+
and `cms.cognitoDomainPrefix` becomes the hosted-UI domain
|
|
27
|
+
(PAPYRUS_COGNITO_DOMAIN_PREFIX) only when `cms.applyCognitoDomainPrefix` is true
|
|
28
|
+
(PAPYRUS_APPLY_COGNITO_DOMAIN_PREFIX); otherwise Amplify's generated domain is kept. The secrets GOOGLE_CLIENT_ID and
|
|
29
|
+
GOOGLE_CLIENT_SECRET are Amplify backend secrets set in the console, never here.
|
|
30
|
+
The stack also creates the `<siteId>-papyrus-authoring` role. The CLI signs
|
|
31
|
+
* AppSync requests (SigV4) with credentials for that role (SSO, OIDC or any
|
|
32
|
+
* principal in the account that may assume it); no token is stored anywhere.
|
|
52
33
|
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
34
|
+
* No repository and no access token are configured: the apps are manual-deploy
|
|
35
|
+
* until Amplify's GitHub App is connected once in the console
|
|
36
|
+
* (docs/site-hosting.md). The Papyrus backend itself is created inside the CMS
|
|
37
|
+
* app by `ampx pipeline-deploy` from the production build.
|
|
55
38
|
*/
|
|
56
39
|
export class AmplifyAppShellStack extends Stack {
|
|
57
|
-
public readonly
|
|
58
|
-
public readonly
|
|
40
|
+
public readonly cmsAppId: string;
|
|
41
|
+
public readonly readerAppId?: string;
|
|
59
42
|
|
|
60
43
|
constructor(scope: Construct, id: string, config: AmplifyAppShellSiteConfig, props?: StackProps) {
|
|
61
44
|
super(scope, id, props);
|
|
62
45
|
|
|
63
|
-
const
|
|
46
|
+
const cmsAppName = config.cms.appName ?? `${config.siteId}-cms`;
|
|
47
|
+
const stagingEnabled = isStagingEnabled(config);
|
|
48
|
+
const stagingDomainName = resolveStagingDomainName(config);
|
|
49
|
+
const cmsHostName = resolveCmsHostName(config);
|
|
64
50
|
|
|
65
|
-
|
|
66
|
-
// creates AppSync, Storage, Lambda, etc., so it needs broad permissions).
|
|
67
|
-
const serviceRole = new iam.Role(this, "AmplifyServiceRole", {
|
|
51
|
+
const cmsServiceRole = new iam.Role(this, "AmplifyServiceRole", {
|
|
68
52
|
assumedBy: new iam.ServicePrincipal("amplify.amazonaws.com"),
|
|
69
|
-
description: `Backend deploy service role for Amplify app ${
|
|
53
|
+
description: `Backend deploy and staging build service role for Amplify app ${cmsAppName} (AdministratorAccess: documented risk)`,
|
|
70
54
|
managedPolicies: [iam.ManagedPolicy.fromAwsManagedPolicyName("AdministratorAccess")],
|
|
71
55
|
});
|
|
72
56
|
|
|
73
|
-
// WEB_COMPUTE (Next.js SSR) requires a compute role for the rendering server.
|
|
74
57
|
const computeRole = new iam.Role(this, "AmplifyComputeRole", {
|
|
75
58
|
assumedBy: new iam.ServicePrincipal("amplify.amazonaws.com"),
|
|
76
|
-
description: `SSR compute role for Amplify app ${
|
|
59
|
+
description: `SSR compute role for Amplify app ${cmsAppName}`,
|
|
77
60
|
managedPolicies: [
|
|
78
61
|
iam.ManagedPolicy.fromAwsManagedPolicyName("service-role/AWSLambdaBasicExecutionRole"),
|
|
79
62
|
iam.ManagedPolicy.fromAwsManagedPolicyName("CloudWatchLogsFullAccess"),
|
|
80
63
|
],
|
|
81
64
|
});
|
|
82
65
|
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
66
|
+
const revalidateSecretParameterName = config.frontend === "pretext" ? resolveRevalidateSecretParameterName(config) : undefined;
|
|
67
|
+
if (revalidateSecretParameterName) {
|
|
68
|
+
computeRole.addToPolicy(
|
|
69
|
+
new iam.PolicyStatement({
|
|
70
|
+
sid: "ReadRevalidateSecret",
|
|
71
|
+
actions: ["ssm:GetParameter"],
|
|
72
|
+
resources: [
|
|
73
|
+
this.formatArn({ service: "ssm", resource: "parameter", resourceName: revalidateSecretParameterName.slice(1), arnFormat: ArnFormat.SLASH_RESOURCE_NAME }),
|
|
74
|
+
],
|
|
75
|
+
}),
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const cmsApp = new amplify.CfnApp(this, "App", {
|
|
80
|
+
name: cmsAppName,
|
|
81
|
+
description: `Papyrus newsroom CMS for ${config.siteId} (WEB_COMPUTE)`,
|
|
82
|
+
platform: "WEB_COMPUTE",
|
|
83
|
+
iamServiceRole: cmsServiceRole.roleArn,
|
|
90
84
|
computeRoleArn: computeRole.roleArn,
|
|
91
|
-
buildSpec:
|
|
92
|
-
|
|
85
|
+
buildSpec: cmsProductionBuildSpec(config),
|
|
86
|
+
jobConfig: config.cms.buildComputeType ? { buildComputeType: config.cms.buildComputeType } : undefined,
|
|
87
|
+
customRules: [
|
|
88
|
+
...(config.cms.redirects ?? []).map((redirect) => ({
|
|
89
|
+
source: `https://${redirect.source}`,
|
|
90
|
+
target: `https://${resolveCmsHostName(config)}`,
|
|
91
|
+
status: String(redirect.status),
|
|
92
|
+
})),
|
|
93
|
+
{ source: "/<*>", target: "/index.html", status: "404-200" },
|
|
94
|
+
],
|
|
93
95
|
});
|
|
94
96
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
+
const stagingMode: Record<string, string> = config.frontend === "markus-static"
|
|
98
|
+
? { PAPYRUS_STAGING_PREVIEW: "static" }
|
|
99
|
+
: { PAPYRUS_CONTENT_SOURCE: "drafts" };
|
|
100
|
+
|
|
101
|
+
const productionOrigin = cmsHostName
|
|
102
|
+
? `https://${cmsHostName}/`
|
|
103
|
+
: Fn.join("", ["https://main.", cmsApp.attrDefaultDomain, "/"]);
|
|
104
|
+
const stagingOrigin = stagingDomainName
|
|
105
|
+
? `https://${stagingDomainName}/`
|
|
106
|
+
: Fn.join("", ["https://staging.", cmsApp.attrDefaultDomain, "/"]);
|
|
107
|
+
const sharedRootDomain = config.cms.domainPrefix !== undefined;
|
|
108
|
+
const defaultOriginsToAllow = [
|
|
109
|
+
...(config.cms.domainName ? [] : [productionOrigin]),
|
|
110
|
+
...(stagingEnabled && !stagingDomainName ? [stagingOrigin] : []),
|
|
111
|
+
];
|
|
112
|
+
const oauthRedirectUrls = defaultOriginsToAllow.length === 0
|
|
113
|
+
? config.cms.environment.PAPYRUS_OAUTH_REDIRECT_URLS
|
|
114
|
+
: Fn.join(",", [config.cms.environment.PAPYRUS_OAUTH_REDIRECT_URLS, ...defaultOriginsToAllow]);
|
|
97
115
|
|
|
98
|
-
const
|
|
99
|
-
appId:
|
|
100
|
-
branchName:
|
|
116
|
+
const productionBranch = new amplify.CfnBranch(this, "Branch", {
|
|
117
|
+
appId: cmsApp.attrAppId,
|
|
118
|
+
branchName: "main",
|
|
101
119
|
stage: "PRODUCTION",
|
|
102
|
-
enableAutoBuild:
|
|
120
|
+
enableAutoBuild: true,
|
|
103
121
|
enablePerformanceMode: false,
|
|
104
|
-
environmentVariables:
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
122
|
+
environmentVariables: environmentVariables({
|
|
123
|
+
...config.cms.environment,
|
|
124
|
+
PAPYRUS_COGNITO_DOMAIN_PREFIX: config.cms.cognitoDomainPrefix,
|
|
125
|
+
...(config.cms.applyCognitoDomainPrefix ? { PAPYRUS_APPLY_COGNITO_DOMAIN_PREFIX: "true" } : {}),
|
|
126
|
+
PAPYRUS_OAUTH_REDIRECT_URLS: oauthRedirectUrls,
|
|
127
|
+
PAPYRUS_SITE_BRAND: config.brand,
|
|
128
|
+
SITE_ENV: "production",
|
|
129
|
+
PAPYRUS_CONTENT_SOURCE: "published",
|
|
130
|
+
...(revalidateSecretParameterName ? { PAPYRUS_REVALIDATE_SECRET_PARAMETER: revalidateSecretParameterName } : {}),
|
|
131
|
+
}),
|
|
108
132
|
});
|
|
109
|
-
branch.addResourceDependency(app);
|
|
110
133
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
134
|
+
let stagingBranch: amplify.CfnBranch | undefined;
|
|
135
|
+
if (stagingEnabled) {
|
|
136
|
+
stagingBranch = new amplify.CfnBranch(this, "StagingBranch", {
|
|
137
|
+
appId: cmsApp.attrAppId,
|
|
138
|
+
branchName: "staging",
|
|
139
|
+
stage: "BETA",
|
|
140
|
+
enableAutoBuild: true,
|
|
141
|
+
enablePerformanceMode: false,
|
|
142
|
+
buildSpec: cmsStagingBuildSpec(config),
|
|
143
|
+
environmentVariables: environmentVariables({
|
|
144
|
+
...config.cms.environment,
|
|
145
|
+
PAPYRUS_COGNITO_DOMAIN_PREFIX: config.cms.cognitoDomainPrefix,
|
|
146
|
+
...(config.cms.applyCognitoDomainPrefix ? { PAPYRUS_APPLY_COGNITO_DOMAIN_PREFIX: "true" } : {}),
|
|
147
|
+
PAPYRUS_OAUTH_REDIRECT_URLS: oauthRedirectUrls,
|
|
148
|
+
PAPYRUS_SITE_BRAND: config.brand,
|
|
149
|
+
SITE_ENV: "staging",
|
|
150
|
+
...stagingMode,
|
|
151
|
+
NEXT_PUBLIC_PAPYRUS_STAGING_URL: stagingDomainName
|
|
152
|
+
? `https://${stagingDomainName}`
|
|
153
|
+
: Fn.join("", ["https://staging.", cmsApp.attrDefaultDomain]),
|
|
154
|
+
}),
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
if (stagingDomainName && !sharedRootDomain) {
|
|
158
|
+
const stagingDomain = new amplify.CfnDomain(this, "StagingDomain", {
|
|
159
|
+
appId: cmsApp.attrAppId,
|
|
160
|
+
domainName: stagingDomainName,
|
|
161
|
+
subDomainSettings: [{ branchName: "staging", prefix: "" }],
|
|
162
|
+
});
|
|
163
|
+
stagingDomain.addResourceDependency(stagingBranch);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (config.cms.domainName) {
|
|
168
|
+
const subDomainSettings = sharedRootDomain
|
|
169
|
+
? [
|
|
170
|
+
{ branchName: "main", prefix: config.cms.domainPrefix as string },
|
|
171
|
+
...(config.cms.redirects ?? []).map((redirect) => ({
|
|
172
|
+
branchName: "main",
|
|
173
|
+
prefix: resolveRedirectSubDomainPrefix(config.cms.domainName as string, redirect.source),
|
|
174
|
+
})),
|
|
175
|
+
...(stagingBranch ? [{ branchName: "staging", prefix: config.cms.stagingDomainPrefix as string }] : []),
|
|
176
|
+
]
|
|
177
|
+
: [{ branchName: "main", prefix: "" }];
|
|
178
|
+
const productionDomain = new amplify.CfnDomain(this, "Domain", {
|
|
179
|
+
appId: cmsApp.attrAppId,
|
|
180
|
+
domainName: config.cms.domainName,
|
|
181
|
+
subDomainSettings,
|
|
182
|
+
});
|
|
183
|
+
productionDomain.addResourceDependency(productionBranch);
|
|
184
|
+
if (sharedRootDomain && stagingBranch) {
|
|
185
|
+
productionDomain.addResourceDependency(stagingBranch);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
this.cmsAppId = cmsApp.attrAppId;
|
|
190
|
+
new CfnOutput(this, "CmsAppId", { value: cmsApp.attrAppId, description: `Amplify app id for ${cmsAppName}` });
|
|
191
|
+
new CfnOutput(this, "CmsOrigin", { value: productionOrigin });
|
|
192
|
+
if (stagingEnabled) {
|
|
193
|
+
new CfnOutput(this, "StagingOrigin", { value: stagingOrigin });
|
|
194
|
+
}
|
|
117
195
|
|
|
118
|
-
|
|
196
|
+
if (config.reader) {
|
|
197
|
+
this.readerAppId = this.addReaderApp(config, config.reader);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const amplifyAppIds = [cmsApp.attrAppId, ...(this.readerAppId ? [this.readerAppId] : [])];
|
|
201
|
+
this.addAuthoringRole(config, cmsApp.attrAppId, amplifyAppIds);
|
|
202
|
+
|
|
203
|
+
if (config.github) {
|
|
204
|
+
this.addGithubCiRole(config, config.github, amplifyAppIds);
|
|
205
|
+
}
|
|
119
206
|
}
|
|
120
207
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
* Papyrus backend + Next.js frontend on every build. Inlined because Amplify
|
|
124
|
-
* needs a buildSpec on the app for the first deploy before the repo is cloned.
|
|
125
|
-
*/
|
|
126
|
-
private buildSpec(): string {
|
|
208
|
+
private authoringStatements(config: AmplifyAppShellSiteConfig, cmsAppId: string, amplifyAppIds: string[]): iam.PolicyStatement[] {
|
|
209
|
+
const mediaBucketArn = `arn:${this.partition}:s3:::amplify-${cmsAppId}-*`;
|
|
127
210
|
return [
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
211
|
+
new iam.PolicyStatement({
|
|
212
|
+
sid: "SignAppSyncAuthoringRequests",
|
|
213
|
+
actions: ["appsync:GraphQL"],
|
|
214
|
+
resources: ["Query", "Mutation"].map((typeName) =>
|
|
215
|
+
this.formatArn({ service: "appsync", resource: "apis", resourceName: `*/types/${typeName}/fields/*`, arnFormat: ArnFormat.SLASH_RESOURCE_NAME }),
|
|
216
|
+
),
|
|
217
|
+
}),
|
|
218
|
+
new iam.PolicyStatement({
|
|
219
|
+
sid: "ReadWriteMediaAndPreview",
|
|
220
|
+
actions: ["s3:GetObject", "s3:PutObject", "s3:DeleteObject"],
|
|
221
|
+
resources: [`${mediaBucketArn}/media/*`, `${mediaBucketArn}/${resolveStoragePreviewPrefix(config)}*`],
|
|
222
|
+
}),
|
|
223
|
+
new iam.PolicyStatement({
|
|
224
|
+
sid: "ListMediaAndPreview",
|
|
225
|
+
actions: ["s3:ListBucket"],
|
|
226
|
+
resources: [mediaBucketArn],
|
|
227
|
+
conditions: { StringLike: { "s3:prefix": ["media/*", `${resolveStoragePreviewPrefix(config)}*`] } },
|
|
228
|
+
}),
|
|
229
|
+
new iam.PolicyStatement({
|
|
230
|
+
sid: "StartAndInspectAmplifyJobs",
|
|
231
|
+
actions: ["amplify:StartJob", "amplify:ListJobs", "amplify:GetJob", "amplify:ListBranches"],
|
|
232
|
+
resources: amplifyAppIds.flatMap((appId) => [
|
|
233
|
+
this.formatArn({ service: "amplify", resource: "apps", resourceName: appId, arnFormat: ArnFormat.SLASH_RESOURCE_NAME }),
|
|
234
|
+
this.formatArn({ service: "amplify", resource: "apps", resourceName: `${appId}/*`, arnFormat: ArnFormat.SLASH_RESOURCE_NAME }),
|
|
235
|
+
]),
|
|
236
|
+
}),
|
|
237
|
+
];
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
private addAuthoringRole(config: AmplifyAppShellSiteConfig, cmsAppId: string, amplifyAppIds: string[]): void {
|
|
241
|
+
const authoringRole = new iam.Role(this, "PapyrusAuthoringRole", {
|
|
242
|
+
roleName: `${config.siteId}-papyrus-authoring`,
|
|
243
|
+
description: `Papyrus CLI authoring role for ${config.siteId}: AppSync (SigV4), media and preview storage, rebuild jobs. Assumable by principals in this account that are allowed sts:AssumeRole on it.`,
|
|
244
|
+
assumedBy: new iam.AccountRootPrincipal(),
|
|
245
|
+
});
|
|
246
|
+
for (const statement of this.authoringStatements(config, cmsAppId, amplifyAppIds)) {
|
|
247
|
+
authoringRole.addToPolicy(statement);
|
|
248
|
+
}
|
|
249
|
+
new CfnOutput(this, "PapyrusAuthoringRoleArn", {
|
|
250
|
+
value: authoringRole.roleArn,
|
|
251
|
+
description: `Role the Papyrus CLI assumes for ${config.siteId} (profile role_arn)`,
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
private addGithubCiRole(
|
|
256
|
+
config: AmplifyAppShellSiteConfig,
|
|
257
|
+
github: NonNullable<AmplifyAppShellSiteConfig["github"]>,
|
|
258
|
+
amplifyAppIds: string[],
|
|
259
|
+
): void {
|
|
260
|
+
const provider = iam.OpenIdConnectProvider.fromOpenIdConnectProviderArn(
|
|
261
|
+
this,
|
|
262
|
+
"GithubOidcProvider",
|
|
263
|
+
this.formatArn({
|
|
264
|
+
service: "iam",
|
|
265
|
+
region: "",
|
|
266
|
+
resource: "oidc-provider",
|
|
267
|
+
resourceName: GITHUB_OIDC_PROVIDER_HOST,
|
|
268
|
+
arnFormat: ArnFormat.SLASH_RESOURCE_NAME,
|
|
269
|
+
}),
|
|
270
|
+
);
|
|
271
|
+
|
|
272
|
+
const ciRole = new iam.Role(this, "GithubCiRole", {
|
|
273
|
+
roleName: `${config.siteId}-github-ci`,
|
|
274
|
+
description: `GitHub Actions role for ${github.owner}/${github.repo} (OIDC, least privilege, no admin policy)`,
|
|
275
|
+
maxSessionDuration: Duration.hours(1),
|
|
276
|
+
assumedBy: new iam.OpenIdConnectPrincipal(provider, {
|
|
277
|
+
StringEquals: { [`${GITHUB_OIDC_PROVIDER_HOST}:aud`]: "sts.amazonaws.com" },
|
|
278
|
+
StringLike: {
|
|
279
|
+
[`${GITHUB_OIDC_PROVIDER_HOST}:sub`]: github.branches.map(
|
|
280
|
+
(branch) => `repo:${github.owner}/${github.repo}:ref:refs/heads/${branch}`,
|
|
281
|
+
),
|
|
282
|
+
},
|
|
283
|
+
}),
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
for (const statement of this.authoringStatements(config, this.cmsAppId, amplifyAppIds)) {
|
|
287
|
+
ciRole.addToPolicy(statement);
|
|
288
|
+
}
|
|
289
|
+
ciRole.addToPolicy(
|
|
290
|
+
new iam.PolicyStatement({
|
|
291
|
+
sid: "WhoAmI",
|
|
292
|
+
actions: ["sts:GetCallerIdentity"],
|
|
293
|
+
resources: ["*"],
|
|
294
|
+
}),
|
|
295
|
+
);
|
|
296
|
+
if (github.ciCanDeployInfra) {
|
|
297
|
+
ciRole.addToPolicy(
|
|
298
|
+
new iam.PolicyStatement({
|
|
299
|
+
sid: "DeployThisSitesAppShellStack",
|
|
300
|
+
actions: ["cloudformation:*"],
|
|
301
|
+
resources: [
|
|
302
|
+
this.formatArn({ service: "cloudformation", resource: "stack", resourceName: `${resolveStackName(config)}/*`, arnFormat: ArnFormat.SLASH_RESOURCE_NAME }),
|
|
303
|
+
],
|
|
304
|
+
}),
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
new CfnOutput(this, "GithubCiRoleArn", { value: ciRole.roleArn, description: `Role for GitHub Actions in ${github.owner}/${github.repo}` });
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
private addReaderApp(
|
|
312
|
+
config: AmplifyAppShellSiteConfig,
|
|
313
|
+
reader: NonNullable<AmplifyAppShellSiteConfig["reader"]>,
|
|
314
|
+
): string {
|
|
315
|
+
const readerAppName = reader.appName ?? `${config.siteId}-reader`;
|
|
316
|
+
const readerBranchName = reader.branchName ?? "main";
|
|
317
|
+
|
|
318
|
+
const readerServiceRole = new iam.Role(this, "ReaderServiceRole", {
|
|
319
|
+
assumedBy: new iam.ServicePrincipal("amplify.amazonaws.com"),
|
|
320
|
+
description: `Static reader build role for Amplify app ${readerAppName} (reads published media only; content is read as a Cognito guest)`,
|
|
321
|
+
});
|
|
322
|
+
readerServiceRole.addToPolicy(
|
|
323
|
+
new iam.PolicyStatement({
|
|
324
|
+
sid: "ReadMediaForExport",
|
|
325
|
+
actions: ["s3:GetObject"],
|
|
326
|
+
resources: ["arn:aws:s3:::amplify-*/media/*"],
|
|
327
|
+
}),
|
|
328
|
+
);
|
|
329
|
+
|
|
330
|
+
const readerApp = new amplify.CfnApp(this, "ReaderApp", {
|
|
331
|
+
name: readerAppName,
|
|
332
|
+
description: `Papyrus static reader for ${config.siteId} (WEB)`,
|
|
333
|
+
platform: "WEB",
|
|
334
|
+
iamServiceRole: readerServiceRole.roleArn,
|
|
335
|
+
buildSpec: readerBuildSpec(config),
|
|
336
|
+
customRules: [{ source: "/<*>", target: "/404.html", status: "404-200" }],
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
const readerBranch = new amplify.CfnBranch(this, "ReaderBranch", {
|
|
340
|
+
appId: readerApp.attrAppId,
|
|
341
|
+
branchName: readerBranchName,
|
|
342
|
+
stage: "PRODUCTION",
|
|
343
|
+
enableAutoBuild: true,
|
|
344
|
+
environmentVariables: environmentVariables({
|
|
345
|
+
...(reader.environment ?? {}),
|
|
346
|
+
PAPYRUS_SITE_BRAND: config.brand,
|
|
347
|
+
SITE_ENV: "production",
|
|
348
|
+
}),
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
if (reader.domainName) {
|
|
352
|
+
const readerDomain = new amplify.CfnDomain(this, "ReaderDomain", {
|
|
353
|
+
appId: readerApp.attrAppId,
|
|
354
|
+
domainName: reader.domainName,
|
|
355
|
+
subDomainSettings: [{ branchName: readerBranchName, prefix: "" }],
|
|
356
|
+
});
|
|
357
|
+
readerDomain.addResourceDependency(readerBranch);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
new CfnOutput(this, "ReaderAppId", { value: readerApp.attrAppId, description: `Amplify app id for ${readerAppName}` });
|
|
361
|
+
new CfnOutput(this, "ReaderOrigin", {
|
|
362
|
+
value: reader.domainName
|
|
363
|
+
? `https://${reader.domainName}/`
|
|
364
|
+
: Fn.join("", [`https://${readerBranchName}.`, readerApp.attrDefaultDomain, "/"]),
|
|
365
|
+
});
|
|
366
|
+
return readerApp.attrAppId;
|
|
154
367
|
}
|
|
155
368
|
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { resolveStoragePreviewPrefix } from "./site-config.js";
|
|
2
|
+
export function papyrusVersionToPep440(version) {
|
|
3
|
+
const match = /^(\d+\.\d+\.\d+)(?:-[0-9A-Za-z-]+\.(\d+))?$/.exec(version);
|
|
4
|
+
if (!match)
|
|
5
|
+
throw new Error(`cannot map ${version} to PEP 440`);
|
|
6
|
+
return match[2] === undefined ? match[1] : `${match[1]}.dev${match[2]}`;
|
|
7
|
+
}
|
|
8
|
+
function yamlScalar(command) {
|
|
9
|
+
const needsQuoting = /: | #|^[-?:,\[\]{}#&*!|>'"%@`]|:$/.test(command);
|
|
10
|
+
return needsQuoting ? `'${command.replace(/'/g, "''")}'` : command;
|
|
11
|
+
}
|
|
12
|
+
function commandLines(commands, indent) {
|
|
13
|
+
return commands.map((command) => `${indent}- ${yamlScalar(command)}`);
|
|
14
|
+
}
|
|
15
|
+
const NPM_CLEAN_INSTALL = "npm ci --cache .npm --prefer-offline";
|
|
16
|
+
const FRONTEND_ENVIRONMENT_CAPTURE = "env | grep -e '^PAPYRUS_' -e '^SITE_ENV=' -e '^NEXT_PUBLIC_' >> .env.production";
|
|
17
|
+
const CHECKOUT_AS_PAPYRUS_ROOT = "PAPYRUS_ROOT=\"$PWD\"";
|
|
18
|
+
const STAGING_RUNTIME_OUTPUTS_COMMANDS = [
|
|
19
|
+
"cp amplify_outputs.json .next/amplify_outputs.json",
|
|
20
|
+
"echo PAPYRUS_AMPLIFY_OUTPUTS=.next/amplify_outputs.json >> .env.production",
|
|
21
|
+
];
|
|
22
|
+
function pythonProvisioningCommands(config) {
|
|
23
|
+
return [
|
|
24
|
+
"export UV_CACHE_DIR=\"$PWD/.uv-cache\"",
|
|
25
|
+
"curl -LsSf https://astral.sh/uv/install.sh | sh",
|
|
26
|
+
"export PATH=\"$HOME/.local/bin:$PATH\"",
|
|
27
|
+
"uv python install 3.12",
|
|
28
|
+
"uv venv --python 3.12 .venv",
|
|
29
|
+
`uv pip install --python .venv "papyrus-newsroom[markus]==${papyrusVersionToPep440(config.papyrusVersion)}"`,
|
|
30
|
+
"export PATH=\"$PWD/.venv/bin:$PATH\"",
|
|
31
|
+
];
|
|
32
|
+
}
|
|
33
|
+
function reader(config) {
|
|
34
|
+
if (!config.reader)
|
|
35
|
+
throw new Error(`site ${config.siteId} has no reader app (frontend ${config.frontend})`);
|
|
36
|
+
return config.reader;
|
|
37
|
+
}
|
|
38
|
+
function frontendSection(preBuildCommands, buildCommands, artifactsDirectory, cachePaths) {
|
|
39
|
+
const lines = ["frontend:", " phases:"];
|
|
40
|
+
if (preBuildCommands.length > 0) {
|
|
41
|
+
lines.push(" preBuild:", " commands:", ...commandLines(preBuildCommands, " "));
|
|
42
|
+
}
|
|
43
|
+
lines.push(" build:", " commands:", ...commandLines(buildCommands, " "), " artifacts:", ` baseDirectory: ${artifactsDirectory}`, " files:", " - '**/*'", " cache:", " paths:", ...cachePaths.map((cachePath) => ` - ${cachePath}`));
|
|
44
|
+
return lines;
|
|
45
|
+
}
|
|
46
|
+
export function cmsProductionBuildSpec(config) {
|
|
47
|
+
return [
|
|
48
|
+
"version: 1",
|
|
49
|
+
"backend:",
|
|
50
|
+
" phases:",
|
|
51
|
+
" build:",
|
|
52
|
+
" commands:",
|
|
53
|
+
...commandLines([
|
|
54
|
+
NPM_CLEAN_INSTALL,
|
|
55
|
+
"if [ -z \"${PAPYRUS_CONSOLE_RESPONDER_IMAGE_URI:-}\" ]; then export PAPYRUS_CONSOLE_RESPONDER_ALLOW_LOCAL_BUILD=true; fi",
|
|
56
|
+
"npx ampx pipeline-deploy --branch $AWS_BRANCH --app-id $AWS_APP_ID",
|
|
57
|
+
], " "),
|
|
58
|
+
...frontendSection([], [FRONTEND_ENVIRONMENT_CAPTURE, "npx papyrus-app sync && npm run build"], ".next", [".next/cache/**/*", ".npm/**/*"]),
|
|
59
|
+
].join("\n") + "\n";
|
|
60
|
+
}
|
|
61
|
+
export function cmsStagingBuildSpec(config) {
|
|
62
|
+
const preBuild = [NPM_CLEAN_INSTALL, "npx ampx generate outputs --branch main --app-id $AWS_APP_ID"];
|
|
63
|
+
const cachePaths = [".next/cache/**/*", ".npm/**/*"];
|
|
64
|
+
if (config.frontend === "markus-static") {
|
|
65
|
+
const readerConfig = reader(config);
|
|
66
|
+
preBuild.push(...pythonProvisioningCommands(config), `${CHECKOUT_AS_PAPYRUS_ROOT} papyrus ops content export-published --drafts --out content-export --clean`, readerConfig.buildCommand, `${CHECKOUT_AS_PAPYRUS_ROOT} papyrus ops content upload-preview --dir ${readerConfig.baseDirectory} --prefix ${resolveStoragePreviewPrefix(config)}`);
|
|
67
|
+
cachePaths.push(".uv-cache/**/*");
|
|
68
|
+
}
|
|
69
|
+
return [
|
|
70
|
+
"version: 1",
|
|
71
|
+
...frontendSection(preBuild, [
|
|
72
|
+
FRONTEND_ENVIRONMENT_CAPTURE,
|
|
73
|
+
"npx papyrus-app sync && npm run build",
|
|
74
|
+
...STAGING_RUNTIME_OUTPUTS_COMMANDS,
|
|
75
|
+
], ".next", cachePaths),
|
|
76
|
+
].join("\n") + "\n";
|
|
77
|
+
}
|
|
78
|
+
export function readerBuildSpec(config) {
|
|
79
|
+
const readerConfig = reader(config);
|
|
80
|
+
return [
|
|
81
|
+
"version: 1",
|
|
82
|
+
...frontendSection([
|
|
83
|
+
...pythonProvisioningCommands(config),
|
|
84
|
+
"papyrus ops content export-published --auth guest --out content-export --clean",
|
|
85
|
+
], [readerConfig.buildCommand], readerConfig.baseDirectory, [".uv-cache/**/*"]),
|
|
86
|
+
].join("\n") + "\n";
|
|
87
|
+
}
|
|
88
|
+
export function buildSpecFor(config, app) {
|
|
89
|
+
if (app === "cms-production")
|
|
90
|
+
return cmsProductionBuildSpec(config);
|
|
91
|
+
if (app === "cms-staging")
|
|
92
|
+
return cmsStagingBuildSpec(config);
|
|
93
|
+
return readerBuildSpec(config);
|
|
94
|
+
}
|