@anthusai/papyrus 2.0.0-next.6 → 2.0.0-next.60

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 (164) hide show
  1. package/amplify/data/resource.js +23 -3
  2. package/amplify/data/resource.ts +25 -3
  3. package/amplify/data/schema.js +2028 -1979
  4. package/amplify/data/schema.ts +72 -14
  5. package/amplify/functions/assignment-action/data-access.js +90 -0
  6. package/amplify/functions/assignment-action/data-access.ts +89 -0
  7. package/amplify/functions/assignment-action/handler.ts +1 -1
  8. package/amplify/functions/content-actions/handler.py +61 -2
  9. package/amplify/functions/content-actions/requirements.txt +1 -0
  10. package/amplify/functions/content-actions/resource.js +1 -1
  11. package/amplify/functions/content-actions/resource.ts +1 -1
  12. package/amplify/functions/editorial-checks/handler.py +14 -0
  13. package/amplify/functions/editorial-checks/requirements.txt +1 -0
  14. package/amplify/{plugins/editorial-checks/function → functions/editorial-checks}/resource.js +7 -7
  15. package/amplify/{plugins/editorial-checks/function → functions/editorial-checks}/resource.ts +7 -7
  16. package/amplify/functions/editorial-checks/schema.js +121 -0
  17. package/amplify/{plugins → functions}/editorial-checks/schema.ts +33 -6
  18. package/amplify/functions/editorial-checks/wire.js +53 -0
  19. package/amplify/functions/editorial-checks/wire.ts +61 -0
  20. package/amplify/functions/monitoring-view/handler.py +11 -0
  21. package/amplify/functions/monitoring-view/resource.js +24 -0
  22. package/amplify/functions/monitoring-view/resource.ts +34 -0
  23. package/amplify/functions/monitoring-view/schema.js +16 -0
  24. package/amplify/functions/monitoring-view/schema.ts +18 -0
  25. package/amplify/functions/monitoring-view/wire.js +37 -0
  26. package/amplify/functions/monitoring-view/wire.ts +47 -0
  27. package/amplify/functions/public-forms/core.js +247 -0
  28. package/amplify/functions/public-forms/core.ts +310 -0
  29. package/amplify/functions/public-forms/handler.ts +41 -0
  30. package/amplify/functions/public-forms/origins.js +35 -0
  31. package/amplify/functions/public-forms/origins.ts +43 -0
  32. package/amplify/functions/public-forms/resource.js +9 -0
  33. package/amplify/functions/public-forms/resource.ts +10 -0
  34. package/amplify/functions/public-forms/wire.js +25 -0
  35. package/amplify/functions/public-forms/wire.ts +32 -0
  36. package/amplify/functions/shared/editorial-context.ts +63 -4
  37. package/amplify/functions/shared/python-bundle.js +20 -14
  38. package/amplify/functions/shared/python-bundle.ts +25 -18
  39. package/amplify/plugins/newsletter/config.js +235 -0
  40. package/amplify/plugins/newsletter/config.ts +294 -0
  41. package/amplify/plugins/newsletter/function/handler.py +6 -0
  42. package/amplify/plugins/newsletter/function/requirements.txt +5 -0
  43. package/amplify/plugins/newsletter/ops/handler.py +12 -0
  44. package/amplify/plugins/newsletter/ops/resource.js +27 -0
  45. package/amplify/plugins/newsletter/ops/resource.ts +37 -0
  46. package/amplify/plugins/newsletter/papyrus.plugin.js +263 -0
  47. package/amplify/plugins/newsletter/papyrus.plugin.ts +311 -0
  48. package/amplify/plugins/newsletter/schema.js +56 -0
  49. package/amplify/plugins/newsletter/schema.ts +61 -0
  50. package/amplify/plugins/newsletter/secure-string-parameter.js +107 -0
  51. package/amplify/plugins/newsletter/secure-string-parameter.ts +120 -0
  52. package/amplify/plugins/newsletter/sending.js +140 -0
  53. package/amplify/plugins/newsletter/sending.ts +186 -0
  54. package/amplify/plugins/reader-steering/config.js +173 -0
  55. package/amplify/plugins/reader-steering/config.ts +268 -0
  56. package/amplify/plugins/reader-steering/function/ai_moderation.py +246 -0
  57. package/amplify/plugins/reader-steering/function/handler.py +1363 -0
  58. package/amplify/plugins/reader-steering/function/moderation-prompt.md +27 -0
  59. package/amplify/plugins/reader-steering/function/moderation.py +316 -0
  60. package/amplify/plugins/reader-steering/function/resource.js +27 -0
  61. package/amplify/plugins/reader-steering/function/resource.ts +35 -0
  62. package/amplify/plugins/reader-steering/papyrus.plugin.js +176 -0
  63. package/amplify/plugins/reader-steering/papyrus.plugin.ts +202 -0
  64. package/amplify/plugins/reader-steering/schema.js +140 -0
  65. package/amplify/plugins/reader-steering/schema.ts +142 -0
  66. package/amplify/plugins/registry.js +4 -2
  67. package/amplify/plugins/registry.ts +4 -2
  68. package/amplify/plugins/types.ts +5 -0
  69. package/amplify/plugins/wire.js +1 -0
  70. package/amplify/plugins/wire.ts +1 -0
  71. package/amplify/publication/projection-lease.js +30 -0
  72. package/amplify/publication/projection-lease.ts +39 -0
  73. package/amplify/publication/redirect-and-index.js +105 -0
  74. package/amplify/publication/redirect-rules.js +73 -0
  75. package/amplify/publication/redirect-rules.ts +93 -0
  76. package/amplify/publication/s3-projection.js +7 -1
  77. package/amplify/publication/s3-projection.ts +9 -1
  78. package/amplify/site-backend-config.ts +17 -0
  79. package/amplify/site-backend.js +38 -1
  80. package/amplify/site-backend.ts +46 -1
  81. package/app/api/auth/prospectus/sign-in/route.ts +4 -0
  82. package/app/api/newsletter/confirm/route.ts +13 -0
  83. package/app/api/newsletter/preferences/route.ts +13 -0
  84. package/app/api/newsletter/state/route.ts +9 -0
  85. package/app/api/newsletter/subscribe/route.ts +9 -0
  86. package/app/api/newsletter/unsubscribe/route.ts +13 -0
  87. package/app/api/newsroom/curation/context/route.ts +9 -0
  88. package/app/api/newsroom/curation/priming/route.ts +9 -0
  89. package/app/api/newsroom/curation/publication/route.ts +9 -0
  90. package/app/api/reader/comment/delete/route.ts +9 -0
  91. package/app/api/reader/comment/edit/route.ts +9 -0
  92. package/app/api/reader/comment/route.ts +9 -0
  93. package/app/api/reader/handle/route.ts +9 -0
  94. package/app/api/reader/me/route.ts +9 -0
  95. package/app/api/reader/rating/route.ts +9 -0
  96. package/app/api/reader/report/route.ts +9 -0
  97. package/app/api/reader/retired/route.ts +9 -0
  98. package/app/api/reader/submit/route.ts +9 -0
  99. package/app/api/reader/vote/route.ts +9 -0
  100. package/bin/papyrus-infra.mjs +20 -1
  101. package/components/editorial-checks-admin-panel.tsx +36 -11
  102. package/components/moderation-panel.tsx +248 -0
  103. package/components/monitoring-overview-view.tsx +241 -0
  104. package/components/monitoring-panel.tsx +40 -0
  105. package/components/newsletter-panel.tsx +474 -0
  106. package/components/newsletter-sections.tsx +163 -0
  107. package/components/newsroom-article-editor.tsx +2 -4
  108. package/components/newsroom-curation-bootstrap.tsx +45 -0
  109. package/components/newsroom-organizer.css +31 -0
  110. package/components/newsroom-references-view.tsx +14 -14
  111. package/components/publication-cyclotron-panel.tsx +15 -10
  112. package/components/reference-add-entry.tsx +75 -0
  113. package/components/reference-curation-controls.tsx +31 -22
  114. package/components/reference-cyclotron-priming.tsx +58 -19
  115. package/components/reference-cyclotron-suggestion.tsx +1 -1
  116. package/components/reference-priming.tsx +14 -10
  117. package/components/reference-section-suggestion.tsx +1 -1
  118. package/components/topic-steering-workspace.tsx +64 -20
  119. package/components/use-editorial-checks.ts +12 -10
  120. package/infra/amplify-app-shell.js +90 -16
  121. package/infra/amplify-app-shell.ts +102 -18
  122. package/infra/index.js +1 -0
  123. package/infra/secure-string-parameter-handler.js +41 -0
  124. package/infra/secure-string-parameter-handler.ts +41 -0
  125. package/infra/secure-string-parameter.js +79 -0
  126. package/infra/secure-string-parameter.ts +91 -0
  127. package/infra/site-config.js +86 -6
  128. package/infra/site-config.ts +129 -6
  129. package/lib/category-repository.ts +11 -9
  130. package/lib/curation-routes.ts +345 -0
  131. package/lib/editorial-checks-backend.ts +1 -1
  132. package/lib/editorial-checks-client.ts +19 -1
  133. package/lib/editorial-checks-demo.ts +2 -2
  134. package/lib/editorial-checks-settings.ts +3 -0
  135. package/lib/editorial-checks.ts +8 -11
  136. package/lib/editorial-preview.ts +5 -5
  137. package/lib/monitoring-client.ts +29 -0
  138. package/lib/monitoring-overview-fixture.ts +51 -0
  139. package/lib/monitoring-overview.ts +145 -0
  140. package/lib/newsletter-api.ts +410 -0
  141. package/lib/newsletter-client.ts +46 -0
  142. package/lib/newsletter-fixture.ts +184 -0
  143. package/lib/newsletter-model.ts +202 -0
  144. package/lib/prospectus-session.ts +15 -14
  145. package/lib/prospectus-sign-in-routes.ts +84 -19
  146. package/lib/prospectus-site-identity.ts +24 -1
  147. package/lib/reader-api.ts +145 -0
  148. package/lib/reader-moderation.ts +220 -0
  149. package/lib/reader-retirement-route.ts +89 -0
  150. package/lib/reader-subject.md +29 -0
  151. package/lib/reader-subject.ts +53 -0
  152. package/lib/relevance-status.ts +2 -2
  153. package/lib/semantic-graph.ts +2 -0
  154. package/lib/site-brand-tenant.ts +11 -6
  155. package/lib/site-brand.ts +6 -3
  156. package/lib/site-origin.ts +67 -0
  157. package/middleware.ts +14 -3
  158. package/package.json +41 -3
  159. package/routes.manifest.json +204 -2
  160. package/amplify/plugins/editorial-checks/function/handler.py +0 -11
  161. package/amplify/plugins/editorial-checks/function/requirements.txt +0 -1
  162. package/amplify/plugins/editorial-checks/papyrus.plugin.js +0 -50
  163. package/amplify/plugins/editorial-checks/papyrus.plugin.ts +0 -63
  164. package/amplify/plugins/editorial-checks/schema.js +0 -94
package/infra/index.js CHANGED
@@ -10,6 +10,7 @@ try {
10
10
  );
11
11
  }
12
12
  export const { AmplifyAppShellStack } = await import("./amplify-app-shell.js");
13
+ export const { SecureStringParameter } = await import("./secure-string-parameter.js");
13
14
  export const { GithubOidcProviderStack } = await import("./github-oidc-provider.js");
14
15
  export { parseSiteConfig } from "./site-config.js";
15
16
  export { cmsProductionBuildSpec, cmsStagingBuildSpec, readerBuildSpec, buildSpecFor } from "./build-specs.js";
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Source of the Lambda behind SecureStringParameter, as a string so the staged
3
+ * package (which ships only .ts under infra/) can inline it and tests can run it
4
+ * against a fake SSM client. CommonJS, under the 4096-character inline limit.
5
+ *
6
+ * It creates the parameter when it is missing and does nothing else: it never
7
+ * overwrites an existing value, never reads one back, never logs the value, and
8
+ * returns no data (only the parameter name as the physical id).
9
+ */
10
+ export const SECURE_STRING_PARAMETER_HANDLER_SOURCE = `
11
+ const { randomInt } = require("node:crypto");
12
+ const ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
13
+ function generate(length) {
14
+ let value = "";
15
+ for (let index = 0; index < length; index += 1) value += ALPHABET[randomInt(ALPHABET.length)];
16
+ return value;
17
+ }
18
+ exports.createHandler = (ssm, PutParameterCommand) => async (event) => {
19
+ const name = event.ResourceProperties.ParameterName;
20
+ if (event.RequestType === "Delete") return { PhysicalResourceId: event.PhysicalResourceId };
21
+ try {
22
+ await ssm.send(new PutParameterCommand({
23
+ Name: name,
24
+ Description: event.ResourceProperties.Description,
25
+ Type: "SecureString",
26
+ Tier: "Standard",
27
+ Overwrite: false,
28
+ Value: generate(Number(event.ResourceProperties.Length)),
29
+ }));
30
+ } catch (error) {
31
+ if (!error || error.name !== "ParameterAlreadyExists") {
32
+ throw new Error("PutParameter failed for " + name + " (" + (error && error.name ? error.name : "error") + ")");
33
+ }
34
+ }
35
+ return { PhysicalResourceId: name };
36
+ };
37
+ exports.handler = async (event) => {
38
+ const { SSMClient, PutParameterCommand } = require("@aws-sdk/client-ssm");
39
+ return exports.createHandler(new SSMClient({}), PutParameterCommand)(event);
40
+ };
41
+ `;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Source of the Lambda behind SecureStringParameter, as a string so the staged
3
+ * package (which ships only .ts under infra/) can inline it and tests can run it
4
+ * against a fake SSM client. CommonJS, under the 4096-character inline limit.
5
+ *
6
+ * It creates the parameter when it is missing and does nothing else: it never
7
+ * overwrites an existing value, never reads one back, never logs the value, and
8
+ * returns no data (only the parameter name as the physical id).
9
+ */
10
+ export const SECURE_STRING_PARAMETER_HANDLER_SOURCE = `
11
+ const { randomInt } = require("node:crypto");
12
+ const ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
13
+ function generate(length) {
14
+ let value = "";
15
+ for (let index = 0; index < length; index += 1) value += ALPHABET[randomInt(ALPHABET.length)];
16
+ return value;
17
+ }
18
+ exports.createHandler = (ssm, PutParameterCommand) => async (event) => {
19
+ const name = event.ResourceProperties.ParameterName;
20
+ if (event.RequestType === "Delete") return { PhysicalResourceId: event.PhysicalResourceId };
21
+ try {
22
+ await ssm.send(new PutParameterCommand({
23
+ Name: name,
24
+ Description: event.ResourceProperties.Description,
25
+ Type: "SecureString",
26
+ Tier: "Standard",
27
+ Overwrite: false,
28
+ Value: generate(Number(event.ResourceProperties.Length)),
29
+ }));
30
+ } catch (error) {
31
+ if (!error || error.name !== "ParameterAlreadyExists") {
32
+ throw new Error("PutParameter failed for " + name + " (" + (error && error.name ? error.name : "error") + ")");
33
+ }
34
+ }
35
+ return { PhysicalResourceId: name };
36
+ };
37
+ exports.handler = async (event) => {
38
+ const { SSMClient, PutParameterCommand } = require("@aws-sdk/client-ssm");
39
+ return exports.createHandler(new SSMClient({}), PutParameterCommand)(event);
40
+ };
41
+ `;
@@ -0,0 +1,79 @@
1
+ import { Construct } from "constructs";
2
+ import { ArnFormat, CustomResource, Duration, RemovalPolicy, Stack } from "aws-cdk-lib";
3
+ import * as iam from "aws-cdk-lib/aws-iam";
4
+ import * as lambda from "aws-cdk-lib/aws-lambda";
5
+ import * as customResources from "aws-cdk-lib/custom-resources";
6
+ import { SECURE_STRING_PARAMETER_HANDLER_SOURCE } from "./secure-string-parameter-handler.js";
7
+ /** One Lambda and role per stack, shared by every SecureStringParameter in it. */
8
+ class SecureStringParameterProvider extends Construct {
9
+ static ID = "SecureStringParameterProvider";
10
+ role;
11
+ provider;
12
+ static of(stack) {
13
+ return stack.node.tryFindChild(SecureStringParameterProvider.ID)
14
+ ?? new SecureStringParameterProvider(stack);
15
+ }
16
+ constructor(stack) {
17
+ super(stack, SecureStringParameterProvider.ID);
18
+ this.role = new iam.Role(this, "Role", {
19
+ assumedBy: new iam.ServicePrincipal("lambda.amazonaws.com"),
20
+ description: "Creates generated SecureString parameters: PutParameter per named parameter, never overwriting",
21
+ managedPolicies: [iam.ManagedPolicy.fromAwsManagedPolicyName("service-role/AWSLambdaBasicExecutionRole")],
22
+ });
23
+ const onEvent = new lambda.Function(this, "OnEvent", {
24
+ runtime: lambda.Runtime.NODEJS_22_X,
25
+ handler: "index.handler",
26
+ code: lambda.Code.fromInline(SECURE_STRING_PARAMETER_HANDLER_SOURCE),
27
+ role: this.role,
28
+ timeout: Duration.seconds(30),
29
+ description: "Creates a generated SecureString parameter once; never returns or logs the value",
30
+ });
31
+ this.provider = new customResources.Provider(this, "Provider", { onEventHandler: onEvent });
32
+ }
33
+ }
34
+ /**
35
+ * A generated secret in SSM Parameter Store as a standard SecureString (free,
36
+ * AWS-managed `aws/ssm` key), instead of a Secrets Manager secret ($0.40/month).
37
+ *
38
+ * CloudFormation cannot create a SecureString, so a custom resource Lambda puts
39
+ * it. The Lambda generates a random value at create time and never returns or
40
+ * logs it, so the value is in no template, output or stack event. It is
41
+ * create-only: an update never regenerates it and never overwrites a parameter
42
+ * that already exists (a hand-made one is adopted as it is), and delete retains
43
+ * it, so a stack teardown cannot sign anyone out. Rotate it with
44
+ * `aws ssm put-parameter --overwrite`. Readers get `ssm:GetParameter` on
45
+ * `parameterArn` only; decrypting with the AWS-managed key needs no KMS grant.
46
+ */
47
+ export class SecureStringParameter extends Construct {
48
+ parameterName;
49
+ parameterArn;
50
+ constructor(scope, id, props) {
51
+ super(scope, id);
52
+ if (!props.parameterName.startsWith("/"))
53
+ throw new Error(`SSM parameter name must be absolute: ${props.parameterName}`);
54
+ const length = props.length ?? 64;
55
+ if (!Number.isInteger(length) || length < 32)
56
+ throw new Error("A generated secret must be at least 32 characters.");
57
+ const stack = Stack.of(this);
58
+ this.parameterName = props.parameterName;
59
+ this.parameterArn = stack.formatArn({
60
+ service: "ssm",
61
+ resource: "parameter",
62
+ resourceName: props.parameterName.slice(1),
63
+ arnFormat: ArnFormat.SLASH_RESOURCE_NAME,
64
+ });
65
+ const shared = SecureStringParameterProvider.of(stack);
66
+ shared.role.addToPolicy(new iam.PolicyStatement({
67
+ sid: `Put${id.replace(/[^A-Za-z0-9]/g, "")}`,
68
+ actions: ["ssm:PutParameter"],
69
+ resources: [this.parameterArn],
70
+ }));
71
+ const resource = new CustomResource(this, "Resource", {
72
+ serviceToken: shared.provider.serviceToken,
73
+ resourceType: "Custom::SecureStringParameter",
74
+ properties: { ParameterName: props.parameterName, Description: props.description, Length: String(length) },
75
+ removalPolicy: RemovalPolicy.RETAIN,
76
+ });
77
+ resource.node.addDependency(shared.role);
78
+ }
79
+ }
@@ -0,0 +1,91 @@
1
+ import { Construct } from "constructs";
2
+ import { ArnFormat, CustomResource, Duration, RemovalPolicy, Stack } from "aws-cdk-lib";
3
+ import * as iam from "aws-cdk-lib/aws-iam";
4
+ import * as lambda from "aws-cdk-lib/aws-lambda";
5
+ import * as customResources from "aws-cdk-lib/custom-resources";
6
+ import { SECURE_STRING_PARAMETER_HANDLER_SOURCE } from "./secure-string-parameter-handler";
7
+
8
+ export interface SecureStringParameterProps {
9
+ /** Absolute parameter name, e.g. `/papyrus/<siteId>/prospectus-session-sealing`. */
10
+ parameterName: string;
11
+ description: string;
12
+ /** Length of the generated value. Default 64. */
13
+ length?: number;
14
+ }
15
+
16
+ /** One Lambda and role per stack, shared by every SecureStringParameter in it. */
17
+ class SecureStringParameterProvider extends Construct {
18
+ static readonly ID = "SecureStringParameterProvider";
19
+ public readonly role: iam.Role;
20
+ public readonly provider: customResources.Provider;
21
+
22
+ static of(stack: Stack): SecureStringParameterProvider {
23
+ return (stack.node.tryFindChild(SecureStringParameterProvider.ID) as SecureStringParameterProvider | undefined)
24
+ ?? new SecureStringParameterProvider(stack);
25
+ }
26
+
27
+ private constructor(stack: Stack) {
28
+ super(stack, SecureStringParameterProvider.ID);
29
+ this.role = new iam.Role(this, "Role", {
30
+ assumedBy: new iam.ServicePrincipal("lambda.amazonaws.com"),
31
+ description: "Creates generated SecureString parameters: PutParameter per named parameter, never overwriting",
32
+ managedPolicies: [iam.ManagedPolicy.fromAwsManagedPolicyName("service-role/AWSLambdaBasicExecutionRole")],
33
+ });
34
+ const onEvent = new lambda.Function(this, "OnEvent", {
35
+ runtime: lambda.Runtime.NODEJS_22_X,
36
+ handler: "index.handler",
37
+ code: lambda.Code.fromInline(SECURE_STRING_PARAMETER_HANDLER_SOURCE),
38
+ role: this.role,
39
+ timeout: Duration.seconds(30),
40
+ description: "Creates a generated SecureString parameter once; never returns or logs the value",
41
+ });
42
+ this.provider = new customResources.Provider(this, "Provider", { onEventHandler: onEvent });
43
+ }
44
+ }
45
+
46
+ /**
47
+ * A generated secret in SSM Parameter Store as a standard SecureString (free,
48
+ * AWS-managed `aws/ssm` key), instead of a Secrets Manager secret ($0.40/month).
49
+ *
50
+ * CloudFormation cannot create a SecureString, so a custom resource Lambda puts
51
+ * it. The Lambda generates a random value at create time and never returns or
52
+ * logs it, so the value is in no template, output or stack event. It is
53
+ * create-only: an update never regenerates it and never overwrites a parameter
54
+ * that already exists (a hand-made one is adopted as it is), and delete retains
55
+ * it, so a stack teardown cannot sign anyone out. Rotate it with
56
+ * `aws ssm put-parameter --overwrite`. Readers get `ssm:GetParameter` on
57
+ * `parameterArn` only; decrypting with the AWS-managed key needs no KMS grant.
58
+ */
59
+ export class SecureStringParameter extends Construct {
60
+ public readonly parameterName: string;
61
+ public readonly parameterArn: string;
62
+
63
+ constructor(scope: Construct, id: string, props: SecureStringParameterProps) {
64
+ super(scope, id);
65
+ if (!props.parameterName.startsWith("/")) throw new Error(`SSM parameter name must be absolute: ${props.parameterName}`);
66
+ const length = props.length ?? 64;
67
+ if (!Number.isInteger(length) || length < 32) throw new Error("A generated secret must be at least 32 characters.");
68
+ const stack = Stack.of(this);
69
+ this.parameterName = props.parameterName;
70
+ this.parameterArn = stack.formatArn({
71
+ service: "ssm",
72
+ resource: "parameter",
73
+ resourceName: props.parameterName.slice(1),
74
+ arnFormat: ArnFormat.SLASH_RESOURCE_NAME,
75
+ });
76
+
77
+ const shared = SecureStringParameterProvider.of(stack);
78
+ shared.role.addToPolicy(new iam.PolicyStatement({
79
+ sid: `Put${id.replace(/[^A-Za-z0-9]/g, "")}`,
80
+ actions: ["ssm:PutParameter"],
81
+ resources: [this.parameterArn],
82
+ }));
83
+ const resource = new CustomResource(this, "Resource", {
84
+ serviceToken: shared.provider.serviceToken,
85
+ resourceType: "Custom::SecureStringParameter",
86
+ properties: { ParameterName: props.parameterName, Description: props.description, Length: String(length) },
87
+ removalPolicy: RemovalPolicy.RETAIN,
88
+ });
89
+ resource.node.addDependency(shared.role);
90
+ }
91
+ }
@@ -2,12 +2,29 @@ export const READER_REDIRECT_STATUSES = ["301", "302", "200", "404", "404-200"];
2
2
  export function hasCmsApp(config) {
3
3
  return config.cms !== undefined;
4
4
  }
5
+ export function resolveGithubRepository(config) {
6
+ if (config.github)
7
+ return { owner: config.github.owner, repo: config.github.repo };
8
+ const [owner, repo] = config.repository.replace("https://github.com/", "").split("/");
9
+ return { owner, repo };
10
+ }
11
+ /** The OIDC `sub` values a GitHub Actions run on `ref` of the site's repository can present. */
12
+ export function githubOidcSubjects(config, ref) {
13
+ const { owner, repo } = resolveGithubRepository(config);
14
+ const subjects = [`repo:${owner}/${repo}:ref:refs/heads/${ref}`];
15
+ const { ownerId, repoId } = config.github ?? {};
16
+ if (ownerId !== undefined && repoId !== undefined) {
17
+ subjects.push(`repo:${owner}@${ownerId}/${repo}@${repoId}:ref:refs/heads/${ref}`);
18
+ }
19
+ return subjects;
20
+ }
5
21
  export const DEFAULT_CI_BRANCHES = ["main", "staging"];
6
22
  const SITE_ID_PATTERN = /^[a-z][a-z0-9]*(-[a-z0-9]+)*$/;
7
23
  const REPOSITORY_PATTERN = /^https:\/\/github\.com\/[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/;
8
24
  const SECRETS_MANAGER_SECRET_ARN_PATTERN = /^arn:aws:secretsmanager:[a-z0-9-]+:\d{12}:secret:[A-Za-z0-9/_+=.@-]+$/;
9
25
  const HOSTED_ZONE_ID_PATTERN = /^Z[A-Z0-9]+$/;
10
26
  const HOST_NAME_PATTERN = /^([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,}$/;
27
+ const SITE_ORIGIN_PATTERN = /^https:\/\/([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+[a-z]{2,}(:\d{1,5})?$/;
11
28
  const DOMAIN_PREFIX_PATTERN = /^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/;
12
29
  const APP_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9 _.-]*$/;
13
30
  const STACK_NAME_PATTERN = /^[A-Za-z][A-Za-z0-9-]{0,127}$/;
@@ -18,7 +35,7 @@ const GITHUB_REPO_PATTERN = /^[A-Za-z0-9_.-]+$/;
18
35
  const COGNITO_DOMAIN_PREFIX_PATTERN = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
19
36
  const COGNITO_RESERVED_WORDS = ["aws", "amazon", "cognito"];
20
37
  const PROSPECTUS_ACCOUNTS_API_STAGE_ARN_PATTERN = /^arn:aws:execute-api:[a-z0-9-]+:\d{12}:[a-z0-9]+\/api$/;
21
- const TEMPLATE_MANAGED_ENVIRONMENT_KEYS = ["PAPYRUS_COGNITO_DOMAIN_PREFIX", "PAPYRUS_APPLY_COGNITO_DOMAIN_PREFIX", "PAPYRUS_DISABLE_GOOGLE_OAUTH", "PAPYRUS_REVALIDATE_SECRET_PARAMETER", "PAPYRUS_PROSPECTUS_ACCOUNTS_ENDPOINT", "PAPYRUS_PROSPECTUS_SESSION_SECRET_ARN", "PAPYRUS_PROSPECTUS_SITE_PRODUCT"];
38
+ const TEMPLATE_MANAGED_ENVIRONMENT_KEYS = ["PAPYRUS_COGNITO_DOMAIN_PREFIX", "PAPYRUS_APPLY_COGNITO_DOMAIN_PREFIX", "PAPYRUS_DISABLE_GOOGLE_OAUTH", "PAPYRUS_REVALIDATE_SECRET_PARAMETER", "PAPYRUS_PROSPECTUS_ACCOUNTS_ENDPOINT", "PAPYRUS_PROSPECTUS_SESSION_SECRET_PARAMETER", "PAPYRUS_PROSPECTUS_SITE_PRODUCT", "PAPYRUS_READER_POLL_SECRET_PARAMETER", "PAPYRUS_SITE_ORIGIN"];
22
39
  /** Routes Prospectus admits for a registered Papyrus site (Prospectus accounts/papyrus-sites.ts). */
23
40
  export const PROSPECTUS_PAPYRUS_SITE_ROUTES = [
24
41
  "GET/v1/identities/me",
@@ -43,6 +60,12 @@ function originOfRedirectUrl(value) {
43
60
  return value;
44
61
  }
45
62
  }
63
+ export function resolveProspectusSessionSealingParameterName(config) {
64
+ return `/papyrus/${config.siteId}/prospectus-session-sealing`;
65
+ }
66
+ export function resolveReaderPollSecretParameterName(config) {
67
+ return `/papyrus/${config.siteId}/reader-poll-secret`;
68
+ }
46
69
  export function resolveRevalidateSecretParameterName(config) {
47
70
  return `/papyrus/${config.siteId}/revalidate-secret`;
48
71
  }
@@ -168,6 +191,9 @@ export function resolveCmsHostName(config) {
168
191
  return undefined;
169
192
  return config.cms.domainPrefix ? `${config.cms.domainPrefix}.${config.cms.domainName}` : config.cms.domainName;
170
193
  }
194
+ export function resolveSiteOrigin(config) {
195
+ return config.cms.siteOrigin;
196
+ }
171
197
  export function resolveStagingDomainName(config) {
172
198
  if (!isStagingEnabled(config))
173
199
  return undefined;
@@ -199,7 +225,7 @@ function parseStagingPreview(value) {
199
225
  }
200
226
  function parseCms(value) {
201
227
  const cmsRecord = requireObject(value, "cms");
202
- rejectUnknownKeys(cmsRecord, ["appName", "domainName", "staging", "cognitoDomainPrefix", "applyCognitoDomainPrefix", "buildComputeType", "environment", "stagingDomainName", "domainPrefix", "stagingDomainPrefix", "redirects", "stagingPreview", "prospectusAccountsApiStageArn", "deployStackInBuild"], "cms");
228
+ rejectUnknownKeys(cmsRecord, ["appName", "domainName", "staging", "cognitoDomainPrefix", "applyCognitoDomainPrefix", "buildComputeType", "environment", "stagingDomainName", "domainPrefix", "siteOrigin", "stagingDomainPrefix", "redirects", "stagingPreview", "prospectusAccountsApiStageArn", "readerRetirementPoll", "deployStackInBuild"], "cms");
203
229
  const buildComputeType = cmsRecord.buildComputeType;
204
230
  if (buildComputeType !== undefined && buildComputeType !== "STANDARD" && buildComputeType !== "STANDARD_8GB") {
205
231
  fail("cms.buildComputeType", `must be "STANDARD" or "STANDARD_8GB", got ${JSON.stringify(buildComputeType)}`);
@@ -210,6 +236,12 @@ function parseCms(value) {
210
236
  if (cmsRecord.applyCognitoDomainPrefix !== undefined && typeof cmsRecord.applyCognitoDomainPrefix !== "boolean") {
211
237
  fail("cms.applyCognitoDomainPrefix", `must be a boolean, got ${JSON.stringify(cmsRecord.applyCognitoDomainPrefix)}`);
212
238
  }
239
+ if (cmsRecord.readerRetirementPoll !== undefined && typeof cmsRecord.readerRetirementPoll !== "boolean") {
240
+ fail("cms.readerRetirementPoll", `must be a boolean, got ${JSON.stringify(cmsRecord.readerRetirementPoll)}`);
241
+ }
242
+ if (cmsRecord.readerRetirementPoll === true && cmsRecord.prospectusAccountsApiStageArn === undefined) {
243
+ fail("cms.readerRetirementPoll", "requires cms.prospectusAccountsApiStageArn: the poll calls Prospectus as the site");
244
+ }
213
245
  if (cmsRecord.deployStackInBuild !== undefined && typeof cmsRecord.deployStackInBuild !== "boolean") {
214
246
  fail("cms.deployStackInBuild", `must be a boolean, got ${JSON.stringify(cmsRecord.deployStackInBuild)}`);
215
247
  }
@@ -217,6 +249,7 @@ function parseCms(value) {
217
249
  appName: optionalString(cmsRecord.appName, "cms.appName", APP_NAME_PATTERN),
218
250
  domainName: optionalString(cmsRecord.domainName, "cms.domainName", HOST_NAME_PATTERN, "host name"),
219
251
  domainPrefix: optionalString(cmsRecord.domainPrefix, "cms.domainPrefix", DOMAIN_PREFIX_PATTERN, "single DNS label"),
252
+ siteOrigin: optionalString(cmsRecord.siteOrigin, "cms.siteOrigin", SITE_ORIGIN_PATTERN, "https origin with no path, query or trailing slash, such as https://shipped.anth.us"),
220
253
  staging: cmsRecord.staging,
221
254
  cognitoDomainPrefix: requireString(cmsRecord.cognitoDomainPrefix, "cms.cognitoDomainPrefix", COGNITO_DOMAIN_PREFIX_PATTERN, "lowercase letters, digits and hyphens; globally unique per region"),
222
255
  applyCognitoDomainPrefix: cmsRecord.applyCognitoDomainPrefix,
@@ -226,6 +259,7 @@ function parseCms(value) {
226
259
  stagingDomainPrefix: optionalString(cmsRecord.stagingDomainPrefix, "cms.stagingDomainPrefix", DOMAIN_PREFIX_PATTERN, "single DNS label"),
227
260
  redirects: parseRedirects(cmsRecord.redirects),
228
261
  deployStackInBuild: cmsRecord.deployStackInBuild,
262
+ readerRetirementPoll: cmsRecord.readerRetirementPoll,
229
263
  stagingPreview: parseStagingPreview(cmsRecord.stagingPreview),
230
264
  prospectusAccountsApiStageArn: optionalString(cmsRecord.prospectusAccountsApiStageArn, "cms.prospectusAccountsApiStageArn", PROSPECTUS_ACCOUNTS_API_STAGE_ARN_PATTERN, "arn:aws:execute-api:<region>:<account>:<api id>/api"),
231
265
  };
@@ -235,9 +269,12 @@ function parseCms(value) {
235
269
  }
236
270
  for (const key of TEMPLATE_MANAGED_ENVIRONMENT_KEYS) {
237
271
  if (key in cms.environment) {
238
- fail(`cms.environment.${key}`, "is managed by the template: Google sign-in is always on, the Cognito domain comes from cms.cognitoDomainPrefix, the revalidation secret parameter is derived from siteId and the Prospectus endpoint comes from cms.prospectusAccountsApiStageArn");
272
+ fail(`cms.environment.${key}`, "is managed by the template: Google sign-in is always on, the Cognito domain comes from cms.cognitoDomainPrefix, the revalidation secret parameter is derived from siteId and the Prospectus endpoint comes from cms.prospectusAccountsApiStageArn and the public site origin comes from the site host");
239
273
  }
240
274
  }
275
+ if (cms.siteOrigin && cms.domainName) {
276
+ fail("cms.siteOrigin", "is for sites whose host is served by their own edge; remove it when cms.domainName is set");
277
+ }
241
278
  if (cms.staging === false && cms.stagingDomainName) {
242
279
  fail("cms.stagingDomainName", "must not be set when cms.staging is false");
243
280
  }
@@ -300,9 +337,20 @@ function validateOauthRedirectUrls(config) {
300
337
  }
301
338
  }
302
339
  }
340
+ function parseAws(value) {
341
+ if (value === undefined)
342
+ return undefined;
343
+ const record = requireObject(value, "aws");
344
+ rejectUnknownKeys(record, ["profile", "accountId", "region"], "aws");
345
+ return {
346
+ profile: optionalString(record.profile, "aws.profile", /^[A-Za-z0-9_.-]+$/, "AWS CLI profile name"),
347
+ accountId: optionalString(record.accountId, "aws.accountId", /^\d{12}$/, "12-digit account id"),
348
+ region: optionalString(record.region, "aws.region", /^[a-z]{2}(-[a-z]+)+-\d$/, "AWS region such as us-east-1"),
349
+ };
350
+ }
303
351
  export function parseSiteConfig(raw) {
304
352
  const record = requireObject(raw, "site");
305
- rejectUnknownKeys(record, ["siteId", "repository", "repositoryAccessTokenSecretArn", "brand", "frontend", "hostedZoneId", "stackName", "cms", "reader", "papyrusVersion", "storagePreviewPrefix", "github"], "site");
353
+ rejectUnknownKeys(record, ["siteId", "repository", "repositoryAccessTokenSecretArn", "brand", "frontend", "hostedZoneId", "stackName", "aws", "cms", "reader", "papyrusVersion", "storagePreviewPrefix", "knowledgeRun", "autoDeploy", "github"], "site");
306
354
  const siteId = requireString(record.siteId, "siteId", SITE_ID_PATTERN, "kebab-case");
307
355
  const repository = requireString(record.repository, "repository", REPOSITORY_PATTERN, "https://github.com/<org>/<repo>");
308
356
  const repositoryAccessTokenSecretArn = record.repositoryAccessTokenSecretArn === undefined
@@ -315,6 +363,7 @@ export function parseSiteConfig(raw) {
315
363
  }
316
364
  const hostedZoneId = optionalString(record.hostedZoneId, "hostedZoneId", HOSTED_ZONE_ID_PATTERN, "Route 53 zone id");
317
365
  const stackName = optionalString(record.stackName, "stackName", STACK_NAME_PATTERN, "CloudFormation stack name");
366
+ const aws = parseAws(record.aws);
318
367
  const papyrusVersion = requireString(record.papyrusVersion, "papyrusVersion", PAPYRUS_VERSION_PATTERN, "exact version such as 1.0.0 or 1.0.0-next.1");
319
368
  const storagePreviewPrefix = optionalString(record.storagePreviewPrefix, "storagePreviewPrefix", /^[A-Za-z0-9._-]+\/$/, "must end with /");
320
369
  const cms = record.cms === undefined && frontend === "markus-static" ? undefined : parseCms(record.cms);
@@ -352,12 +401,15 @@ export function parseSiteConfig(raw) {
352
401
  if (cms?.stagingPreview !== undefined && cms.staging === false) {
353
402
  fail("cms.stagingPreview", "must not be set when cms.staging is false");
354
403
  }
404
+ const autoDeploy = record.autoDeploy ?? true;
405
+ if (typeof autoDeploy !== "boolean")
406
+ fail("autoDeploy", "must be a boolean");
355
407
  let github;
356
408
  if (record.github !== undefined) {
357
409
  if (cms === undefined)
358
410
  fail("github", "requires cms (the CI role is scoped to the CMS app)");
359
411
  const githubRecord = requireObject(record.github, "github");
360
- rejectUnknownKeys(githubRecord, ["owner", "repo", "branches", "ciCanDeployInfra"], "github");
412
+ rejectUnknownKeys(githubRecord, ["owner", "repo", "branches", "ciCanDeployInfra", "ownerId", "repoId"], "github");
361
413
  const owner = requireString(githubRecord.owner, "github.owner", GITHUB_OWNER_PATTERN, "plain GitHub login");
362
414
  const repo = requireString(githubRecord.repo, "github.repo", GITHUB_REPO_PATTERN);
363
415
  if (repository !== `https://github.com/${owner}/${repo}`) {
@@ -378,7 +430,18 @@ export function parseSiteConfig(raw) {
378
430
  const ciCanDeployInfra = githubRecord.ciCanDeployInfra ?? false;
379
431
  if (typeof ciCanDeployInfra !== "boolean")
380
432
  fail("github.ciCanDeployInfra", "must be a boolean");
381
- github = { owner, repo, branches, ciCanDeployInfra: ciCanDeployInfra };
433
+ const optionalId = (value, name) => {
434
+ if (value === undefined)
435
+ return undefined;
436
+ if (typeof value !== "number" || !Number.isSafeInteger(value) || value <= 0)
437
+ fail(name, "must be a positive integer (GitHub numeric id)");
438
+ return value;
439
+ };
440
+ const ownerId = optionalId(githubRecord.ownerId, "github.ownerId");
441
+ const repoId = optionalId(githubRecord.repoId, "github.repoId");
442
+ if ((ownerId === undefined) !== (repoId === undefined))
443
+ fail("github", "ownerId and repoId must be set together");
444
+ github = { owner, repo, branches, ciCanDeployInfra: ciCanDeployInfra, ...(ownerId !== undefined ? { ownerId, repoId } : {}) };
382
445
  }
383
446
  const hasDomain = cms?.domainName !== undefined || reader?.domainName !== undefined;
384
447
  if (hasDomain && hostedZoneId === undefined) {
@@ -395,13 +458,30 @@ export function parseSiteConfig(raw) {
395
458
  frontend,
396
459
  hostedZoneId,
397
460
  stackName,
461
+ aws,
398
462
  cms,
399
463
  reader,
400
464
  papyrusVersion,
401
465
  storagePreviewPrefix,
466
+ autoDeploy: autoDeploy,
402
467
  github,
468
+ ...(record.knowledgeRun !== undefined ? { knowledgeRun: record.knowledgeRun } : {}),
403
469
  };
404
470
  if (hasCmsApp(config))
405
471
  validateOauthRedirectUrls(config);
406
472
  return config;
407
473
  }
474
+ /**
475
+ * The CDK environment for a site's app-shell stack, taken only from the site's own `aws` block. There is
476
+ * deliberately no default account: a deploy that guesses an account can land in, or fail against, the wrong
477
+ * one.
478
+ */
479
+ export function resolveDeployEnvironment(config) {
480
+ const account = config.aws?.accountId;
481
+ const region = config.aws?.region;
482
+ const missing = [account ? "" : "aws.accountId", region ? "" : "aws.region"].filter(Boolean);
483
+ if (!account || !region) {
484
+ throw new Error(`site "${config.siteId}" does not say where it deploys: add ${missing.join(" and ")} to its site.json, e.g. "aws": { "accountId": "<12-digit account>", "region": "us-east-1" }. No account is assumed.`);
485
+ }
486
+ return { account, region };
487
+ }