@anthusai/papyrus 2.0.0-next.7 → 2.0.0-next.70

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 (165) 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/{plugins/editorial-checks/function → functions/editorial-checks}/handler.py +3 -3
  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 +245 -0
  40. package/amplify/plugins/newsletter/config.ts +305 -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 +180 -0
  55. package/amplify/plugins/reader-steering/config.ts +280 -0
  56. package/amplify/plugins/reader-steering/function/ai_moderation.py +246 -0
  57. package/amplify/plugins/reader-steering/function/handler.py +1554 -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/proposals.py +255 -0
  61. package/amplify/plugins/reader-steering/function/resource.js +27 -0
  62. package/amplify/plugins/reader-steering/function/resource.ts +35 -0
  63. package/amplify/plugins/reader-steering/papyrus.plugin.js +184 -0
  64. package/amplify/plugins/reader-steering/papyrus.plugin.ts +210 -0
  65. package/amplify/plugins/reader-steering/schema.js +204 -0
  66. package/amplify/plugins/reader-steering/schema.ts +206 -0
  67. package/amplify/plugins/registry.js +4 -2
  68. package/amplify/plugins/registry.ts +4 -2
  69. package/amplify/plugins/types.ts +5 -0
  70. package/amplify/plugins/wire.js +1 -0
  71. package/amplify/plugins/wire.ts +1 -0
  72. package/amplify/publication/projection-lease.js +30 -0
  73. package/amplify/publication/projection-lease.ts +39 -0
  74. package/amplify/publication/redirect-and-index.js +105 -0
  75. package/amplify/publication/redirect-rules.js +73 -0
  76. package/amplify/publication/redirect-rules.ts +93 -0
  77. package/amplify/publication/s3-projection.js +7 -1
  78. package/amplify/publication/s3-projection.ts +9 -1
  79. package/amplify/site-backend-config.ts +17 -0
  80. package/amplify/site-backend.js +38 -1
  81. package/amplify/site-backend.ts +46 -1
  82. package/app/api/auth/prospectus/sign-in/route.ts +4 -0
  83. package/app/api/newsletter/confirm/route.ts +13 -0
  84. package/app/api/newsletter/preferences/route.ts +13 -0
  85. package/app/api/newsletter/state/route.ts +9 -0
  86. package/app/api/newsletter/subscribe/route.ts +9 -0
  87. package/app/api/newsletter/unsubscribe/route.ts +13 -0
  88. package/app/api/newsroom/curation/context/route.ts +9 -0
  89. package/app/api/newsroom/curation/priming/route.ts +9 -0
  90. package/app/api/newsroom/curation/publication/route.ts +9 -0
  91. package/app/api/reader/comment/delete/route.ts +9 -0
  92. package/app/api/reader/comment/edit/route.ts +9 -0
  93. package/app/api/reader/comment/route.ts +9 -0
  94. package/app/api/reader/flag/route.ts +9 -0
  95. package/app/api/reader/handle/route.ts +9 -0
  96. package/app/api/reader/me/route.ts +9 -0
  97. package/app/api/reader/rating/route.ts +9 -0
  98. package/app/api/reader/report/route.ts +9 -0
  99. package/app/api/reader/retired/route.ts +9 -0
  100. package/app/api/reader/submit/route.ts +9 -0
  101. package/app/api/reader/vote/route.ts +9 -0
  102. package/bin/papyrus-infra.mjs +20 -1
  103. package/components/editorial-checks-admin-panel.tsx +36 -11
  104. package/components/moderation-panel.tsx +248 -0
  105. package/components/monitoring-overview-view.tsx +241 -0
  106. package/components/monitoring-panel.tsx +40 -0
  107. package/components/newsletter-panel.tsx +474 -0
  108. package/components/newsletter-sections.tsx +163 -0
  109. package/components/newsroom-article-editor.tsx +2 -4
  110. package/components/newsroom-curation-bootstrap.tsx +45 -0
  111. package/components/newsroom-organizer.css +31 -0
  112. package/components/newsroom-references-view.tsx +14 -14
  113. package/components/publication-cyclotron-panel.tsx +15 -10
  114. package/components/reference-add-entry.tsx +75 -0
  115. package/components/reference-curation-controls.tsx +31 -22
  116. package/components/reference-cyclotron-priming.tsx +58 -19
  117. package/components/reference-cyclotron-suggestion.tsx +1 -1
  118. package/components/reference-priming.tsx +14 -10
  119. package/components/reference-section-suggestion.tsx +1 -1
  120. package/components/topic-steering-workspace.tsx +64 -20
  121. package/components/use-editorial-checks.ts +12 -10
  122. package/infra/amplify-app-shell.js +90 -16
  123. package/infra/amplify-app-shell.ts +102 -18
  124. package/infra/index.js +1 -0
  125. package/infra/secure-string-parameter-handler.js +41 -0
  126. package/infra/secure-string-parameter-handler.ts +41 -0
  127. package/infra/secure-string-parameter.js +79 -0
  128. package/infra/secure-string-parameter.ts +91 -0
  129. package/infra/site-config.js +86 -6
  130. package/infra/site-config.ts +129 -6
  131. package/lib/category-repository.ts +11 -9
  132. package/lib/curation-routes.ts +345 -0
  133. package/lib/editorial-checks-backend.ts +1 -1
  134. package/lib/editorial-checks-client.ts +19 -1
  135. package/lib/editorial-checks-demo.ts +2 -2
  136. package/lib/editorial-checks-settings.ts +3 -0
  137. package/lib/editorial-checks.ts +8 -11
  138. package/lib/editorial-preview.ts +5 -5
  139. package/lib/monitoring-client.ts +29 -0
  140. package/lib/monitoring-overview-fixture.ts +51 -0
  141. package/lib/monitoring-overview.ts +145 -0
  142. package/lib/newsletter-api.ts +418 -0
  143. package/lib/newsletter-client.ts +46 -0
  144. package/lib/newsletter-fixture.ts +184 -0
  145. package/lib/newsletter-model.ts +202 -0
  146. package/lib/prospectus-session.ts +15 -14
  147. package/lib/prospectus-sign-in-routes.ts +84 -19
  148. package/lib/prospectus-site-identity.ts +24 -1
  149. package/lib/reader-api.ts +145 -0
  150. package/lib/reader-moderation.ts +220 -0
  151. package/lib/reader-retirement-route.ts +89 -0
  152. package/lib/reader-subject.md +29 -0
  153. package/lib/reader-subject.ts +53 -0
  154. package/lib/relevance-status.ts +2 -2
  155. package/lib/semantic-graph.ts +2 -0
  156. package/lib/site-brand-tenant.ts +11 -6
  157. package/lib/site-brand.ts +6 -3
  158. package/lib/site-origin.ts +67 -0
  159. package/middleware.ts +14 -3
  160. package/package.json +42 -3
  161. package/routes.manifest.json +215 -2
  162. package/amplify/plugins/editorial-checks/function/requirements.txt +0 -1
  163. package/amplify/plugins/editorial-checks/papyrus.plugin.js +0 -69
  164. package/amplify/plugins/editorial-checks/papyrus.plugin.ts +0 -85
  165. package/amplify/plugins/editorial-checks/schema.js +0 -94
@@ -0,0 +1,121 @@
1
+ import { a } from "@aws-amplify/backend";
2
+ import { editorialChecks } from "./resource.js";
3
+ const editors = ["editor", "admin"];
4
+ /**
5
+ * Core to every site's data API. Policies, settings and editors' decisions live in Papyrus; Humanus checks
6
+ * content against them. Editors read policies and record decisions; admins
7
+ * manage policies and settings. Only the function (IAM) calls Humanus.
8
+ */
9
+ export const editorialChecksSchemaDefinitions = {
10
+ EditorialPolicy: a
11
+ .model({
12
+ id: a.id().required(),
13
+ policyKey: a.string().required(),
14
+ scope: a.string().required(),
15
+ version: a.integer().required(),
16
+ title: a.string().required(),
17
+ guidance: a.string().required(),
18
+ severity: a.string().required(),
19
+ enabled: a.boolean().required(),
20
+ detectors: a.json().required(),
21
+ examples: a.json(),
22
+ rewriteGuidance: a.string(),
23
+ source: a.string().required(),
24
+ })
25
+ .disableOperations(["subscriptions"])
26
+ .authorization((allow) => [allow.group("editor").to(["read"]), allow.group("admin")]),
27
+ EditorialCheckSettings: a
28
+ .model({
29
+ id: a.id().required(),
30
+ settings: a.json().required(),
31
+ })
32
+ .disableOperations(["subscriptions"])
33
+ .authorization((allow) => [allow.group("editor").to(["read"]), allow.group("admin")]),
34
+ EditorialFeedback: a
35
+ .model({
36
+ id: a.id().required(),
37
+ itemId: a.string().required(),
38
+ findingId: a.string().required(),
39
+ policyId: a.string().required(),
40
+ detectorId: a.string().required(),
41
+ lane: a.string().required(),
42
+ probability: a.float(),
43
+ decision: a.string().required(),
44
+ reason: a.string(),
45
+ text: a.string(),
46
+ })
47
+ .disableOperations(["subscriptions"])
48
+ .secondaryIndexes((index) => [index("itemId").queryField("listEditorialFeedbackByItem")])
49
+ .authorization((allow) => [allow.group("editor").to(["create", "read"]), allow.group("admin")]),
50
+ EditorialCheckRun: a
51
+ .model({
52
+ id: a.id().required(),
53
+ itemId: a.string().required(),
54
+ lineageId: a.string().required(),
55
+ versionNumber: a.integer().required(),
56
+ section: a.string(),
57
+ contentHash: a.string(),
58
+ packVersion: a.string(),
59
+ violations: a.integer().required(),
60
+ reviews: a.integer().required(),
61
+ findings: a.json().required(),
62
+ lanes: a.json(),
63
+ checkedAt: a.datetime().required(),
64
+ })
65
+ .disableOperations(["subscriptions"])
66
+ .secondaryIndexes((index) => [index("lineageId").sortKeys(["versionNumber"]).queryField("listEditorialCheckRunsByLineage")])
67
+ .authorization((allow) => [allow.group("editor").to(["read"]), allow.group("admin")]),
68
+ listEditorialStarterPacks: a
69
+ .query()
70
+ .returns(a.json())
71
+ .authorization((allow) => [allow.groups(editors)])
72
+ .handler(a.handler.function(editorialChecks)),
73
+ checkItemVersion: a
74
+ .mutation()
75
+ .arguments({ itemId: a.id().required() })
76
+ .returns(a.json())
77
+ .authorization((allow) => [allow.groups(editors)])
78
+ .handler(a.handler.function(editorialChecks)),
79
+ checkEditorial: a
80
+ .query()
81
+ .arguments({ body: a.string().required(), format: a.string(), section: a.string() })
82
+ .returns(a.json())
83
+ .authorization((allow) => [allow.groups(editors)])
84
+ .handler(a.handler.function(editorialChecks)),
85
+ suggestEditorialRewrite: a
86
+ .query()
87
+ .arguments({
88
+ body: a.string().required(),
89
+ format: a.string(),
90
+ section: a.string(),
91
+ finding: a.json(),
92
+ selection: a.json(),
93
+ note: a.string(),
94
+ })
95
+ .returns(a.json())
96
+ .authorization((allow) => [allow.groups(editors)])
97
+ .handler(a.handler.function(editorialChecks)),
98
+ draftEditorialQuestions: a
99
+ .query()
100
+ .arguments({ title: a.string().required(), guidance: a.string().required(), examples: a.json() })
101
+ .returns(a.json())
102
+ .authorization((allow) => [allow.group("admin")])
103
+ .handler(a.handler.function(editorialChecks)),
104
+ tryEditorialPolicy: a
105
+ .query()
106
+ .arguments({ policy: a.json().required(), text: a.string().required(), format: a.string() })
107
+ .returns(a.json())
108
+ .authorization((allow) => [allow.group("admin")])
109
+ .handler(a.handler.function(editorialChecks)),
110
+ importEditorialStarterPack: a
111
+ .mutation()
112
+ .arguments({ name: a.string().required() })
113
+ .returns(a.json())
114
+ .authorization((allow) => [allow.group("admin")])
115
+ .handler(a.handler.function(editorialChecks)),
116
+ recalibrateEditorialPolicies: a
117
+ .mutation()
118
+ .returns(a.json())
119
+ .authorization((allow) => [allow.group("admin")])
120
+ .handler(a.handler.function(editorialChecks)),
121
+ };
@@ -1,15 +1,14 @@
1
1
  import { a } from "@aws-amplify/backend";
2
- import { editorialChecks } from "./function/resource";
2
+ import { editorialChecks } from "./resource";
3
3
 
4
4
  const editors = ["editor", "admin"];
5
5
 
6
6
  /**
7
- * Policies, settings and editors' decisions live in Papyrus; Limatus checks
7
+ * Core to every site's data API. Policies, settings and editors' decisions live in Papyrus; Humanus checks
8
8
  * content against them. Editors read policies and record decisions; admins
9
- * manage policies and settings. Only the function (IAM) calls Limatus.
9
+ * manage policies and settings. Only the function (IAM) calls Humanus.
10
10
  */
11
- export function editorialChecksSchemaDefinitions() {
12
- return {
11
+ export const editorialChecksSchemaDefinitions = {
13
12
  EditorialPolicy: a
14
13
  .model({
15
14
  id: a.id().required(),
@@ -50,6 +49,35 @@ export function editorialChecksSchemaDefinitions() {
50
49
  .disableOperations(["subscriptions"])
51
50
  .secondaryIndexes((index) => [index("itemId").queryField("listEditorialFeedbackByItem")])
52
51
  .authorization((allow) => [allow.group("editor").to(["create", "read"]), allow.group("admin")]),
52
+ EditorialCheckRun: a
53
+ .model({
54
+ id: a.id().required(),
55
+ itemId: a.string().required(),
56
+ lineageId: a.string().required(),
57
+ versionNumber: a.integer().required(),
58
+ section: a.string(),
59
+ contentHash: a.string(),
60
+ packVersion: a.string(),
61
+ violations: a.integer().required(),
62
+ reviews: a.integer().required(),
63
+ findings: a.json().required(),
64
+ lanes: a.json(),
65
+ checkedAt: a.datetime().required(),
66
+ })
67
+ .disableOperations(["subscriptions"])
68
+ .secondaryIndexes((index) => [index("lineageId").sortKeys(["versionNumber"]).queryField("listEditorialCheckRunsByLineage")])
69
+ .authorization((allow) => [allow.group("editor").to(["read"]), allow.group("admin")]),
70
+ listEditorialStarterPacks: a
71
+ .query()
72
+ .returns(a.json())
73
+ .authorization((allow) => [allow.groups(editors)])
74
+ .handler(a.handler.function(editorialChecks)),
75
+ checkItemVersion: a
76
+ .mutation()
77
+ .arguments({ itemId: a.id().required() })
78
+ .returns(a.json())
79
+ .authorization((allow) => [allow.groups(editors)])
80
+ .handler(a.handler.function(editorialChecks)),
53
81
  checkEditorial: a
54
82
  .query()
55
83
  .arguments({ body: a.string().required(), format: a.string(), section: a.string() })
@@ -93,4 +121,3 @@ export function editorialChecksSchemaDefinitions() {
93
121
  .authorization((allow) => [allow.group("admin")])
94
122
  .handler(a.handler.function(editorialChecks)),
95
123
  };
96
- }
@@ -0,0 +1,53 @@
1
+ import { secret } from "@aws-amplify/backend";
2
+ import { Stack } from "aws-cdk-lib";
3
+ import { Effect, PolicyStatement } from "aws-cdk-lib/aws-iam";
4
+ /** The model operations the function performs with its own role. The two context reads are its least-privilege access to private policy. */
5
+ export const EDITORIAL_CHECKS_FUNCTION_FIELDS = [
6
+ "Query/fields/listKnowledgeCorporaByRoleAndName",
7
+ "Query/fields/getEditorialContext",
8
+ "Query/fields/listEditorialPolicies",
9
+ "Query/fields/getEditorialCheckSettings",
10
+ "Query/fields/listEditorialFeedbacks",
11
+ "Mutation/fields/createEditorialPolicy",
12
+ "Mutation/fields/updateEditorialPolicy",
13
+ "Query/fields/getItem",
14
+ "Query/fields/getEditorialCheckRun",
15
+ "Mutation/fields/createEditorialCheckRun",
16
+ "Mutation/fields/updateEditorialCheckRun",
17
+ ];
18
+ export const EDITORIAL_CHECKS_SECRETS = ["TYPESAFE_API_KEY", "OPENAI_API_KEY"];
19
+ /**
20
+ * SSM parameters holding the provider keys. A Python function reads its secret()
21
+ * values itself (Amplify only resolves them for Node functions), so it needs read
22
+ * access to the app's branch and shared secret paths, and to the sandbox paths.
23
+ */
24
+ export function editorialChecksSecretParameters(region, account, appId) {
25
+ const arn = (path) => `arn:aws:ssm:${region}:${account}:parameter/amplify/${path}`;
26
+ return EDITORIAL_CHECKS_SECRETS.flatMap((name) => [
27
+ arn(`papyrus/*/${name}`),
28
+ arn(`shared/papyrus/${name}`),
29
+ ...(appId ? [arn(`${appId}/*/${name}`), arn(`shared/${appId}/${name}`)] : []),
30
+ ]);
31
+ }
32
+ /**
33
+ * Environment, secrets and least-privilege IAM for the editorial-checks function. Every site gets
34
+ * these; whether checks run is a stored setting (EditorialCheckSettings.enabled), not a deploy flag.
35
+ */
36
+ export function wireEditorialChecks(backend) {
37
+ const lambda = backend.editorialChecks.resources.lambda;
38
+ const stack = Stack.of(lambda);
39
+ lambda.addEnvironment("PAPYRUS_GRAPHQL_ENDPOINT", backend.data.resources.cfnResources.cfnGraphqlApi.attrGraphQlUrl);
40
+ for (const name of EDITORIAL_CHECKS_SECRETS)
41
+ backend.editorialChecks.addEnvironment(name, secret(name));
42
+ lambda.addToRolePolicy(new PolicyStatement({
43
+ effect: Effect.ALLOW,
44
+ actions: ["ssm:GetParameter", "ssm:GetParameters"],
45
+ resources: editorialChecksSecretParameters(stack.region, stack.account, (process.env.AWS_APP_ID ?? "").trim()),
46
+ }));
47
+ const apiId = backend.data.resources.graphqlApi.apiId;
48
+ lambda.addToRolePolicy(new PolicyStatement({
49
+ effect: Effect.ALLOW,
50
+ actions: ["appsync:GraphQL"],
51
+ resources: EDITORIAL_CHECKS_FUNCTION_FIELDS.map((field) => `arn:aws:appsync:${stack.region}:${stack.account}:apis/${apiId}/types/${field}`),
52
+ }));
53
+ }
@@ -0,0 +1,61 @@
1
+ import { secret } from "@aws-amplify/backend";
2
+ import { Stack } from "aws-cdk-lib";
3
+ import { Effect, PolicyStatement } from "aws-cdk-lib/aws-iam";
4
+ import type { Function as LambdaFunction } from "aws-cdk-lib/aws-lambda";
5
+
6
+ /** The model operations the function performs with its own role. The two context reads are its least-privilege access to private policy. */
7
+ export const EDITORIAL_CHECKS_FUNCTION_FIELDS = [
8
+ "Query/fields/listKnowledgeCorporaByRoleAndName",
9
+ "Query/fields/getEditorialContext",
10
+ "Query/fields/listEditorialPolicies",
11
+ "Query/fields/getEditorialCheckSettings",
12
+ "Query/fields/listEditorialFeedbacks",
13
+ "Mutation/fields/createEditorialPolicy",
14
+ "Mutation/fields/updateEditorialPolicy",
15
+ "Query/fields/getItem",
16
+ "Query/fields/getEditorialCheckRun",
17
+ "Mutation/fields/createEditorialCheckRun",
18
+ "Mutation/fields/updateEditorialCheckRun",
19
+ ];
20
+
21
+ export const EDITORIAL_CHECKS_SECRETS = ["TYPESAFE_API_KEY", "OPENAI_API_KEY"];
22
+
23
+ /**
24
+ * SSM parameters holding the provider keys. A Python function reads its secret()
25
+ * values itself (Amplify only resolves them for Node functions), so it needs read
26
+ * access to the app's branch and shared secret paths, and to the sandbox paths.
27
+ */
28
+ export function editorialChecksSecretParameters(region: string, account: string, appId: string): string[] {
29
+ const arn = (path: string) => `arn:aws:ssm:${region}:${account}:parameter/amplify/${path}`;
30
+ return EDITORIAL_CHECKS_SECRETS.flatMap((name) => [
31
+ arn(`papyrus/*/${name}`),
32
+ arn(`shared/papyrus/${name}`),
33
+ ...(appId ? [arn(`${appId}/*/${name}`), arn(`shared/${appId}/${name}`)] : []),
34
+ ]);
35
+ }
36
+
37
+ /**
38
+ * Environment, secrets and least-privilege IAM for the editorial-checks function. Every site gets
39
+ * these; whether checks run is a stored setting (EditorialCheckSettings.enabled), not a deploy flag.
40
+ */
41
+ export function wireEditorialChecks(backend: any): void {
42
+ const lambda = backend.editorialChecks.resources.lambda as LambdaFunction;
43
+ const stack = Stack.of(lambda);
44
+ lambda.addEnvironment("PAPYRUS_GRAPHQL_ENDPOINT", backend.data.resources.cfnResources.cfnGraphqlApi.attrGraphQlUrl as string);
45
+ for (const name of EDITORIAL_CHECKS_SECRETS) backend.editorialChecks.addEnvironment(name, secret(name));
46
+ lambda.addToRolePolicy(
47
+ new PolicyStatement({
48
+ effect: Effect.ALLOW,
49
+ actions: ["ssm:GetParameter", "ssm:GetParameters"],
50
+ resources: editorialChecksSecretParameters(stack.region, stack.account, (process.env.AWS_APP_ID ?? "").trim()),
51
+ }),
52
+ );
53
+ const apiId = backend.data.resources.graphqlApi.apiId as string;
54
+ lambda.addToRolePolicy(
55
+ new PolicyStatement({
56
+ effect: Effect.ALLOW,
57
+ actions: ["appsync:GraphQL"],
58
+ resources: EDITORIAL_CHECKS_FUNCTION_FIELDS.map((field) => `arn:aws:appsync:${stack.region}:${stack.account}:apis/${apiId}/types/${field}`),
59
+ }),
60
+ );
61
+ }
@@ -0,0 +1,11 @@
1
+ """The monitoring-view function: `monitoringOverview` for editors and admins, read-only."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any
6
+
7
+ from papyrus_content.monitoring_view import handle
8
+
9
+
10
+ def handler(event: dict[str, Any], _context: Any = None) -> dict[str, Any]:
11
+ return handle(event)
@@ -0,0 +1,24 @@
1
+ import { defineFunction } from "@aws-amplify/backend";
2
+ import { Duration } from "aws-cdk-lib";
3
+ import { Architecture, Function, Runtime } from "aws-cdk-lib/aws-lambda";
4
+ import { pythonLambdaCode } from "../shared/python-bundle.js";
5
+ /** AppSync gives a resolver 30 seconds; a read of one small table needs a few. */
6
+ export const MONITORING_VIEW_TIMEOUT_SECONDS = 15;
7
+ /** stdlib plus the runtime's boto3: the bundle is `papyrus_content` and nothing else. */
8
+ export const monitoringView = defineFunction((scope) => new Function(scope, "papyrus-monitoring-view", {
9
+ runtime: Runtime.PYTHON_3_12,
10
+ architecture: Architecture.ARM_64,
11
+ handler: "handler.handler",
12
+ timeout: Duration.seconds(MONITORING_VIEW_TIMEOUT_SECONDS),
13
+ memorySize: 256,
14
+ code: pythonLambdaCode({ functionDir: "monitoring-view", modules: ["papyrus_content"], noDeps: true }, [
15
+ "bash",
16
+ "-c",
17
+ [
18
+ "set -euo pipefail",
19
+ "mkdir -p /asset-output/papyrus_content",
20
+ "cp amplify/functions/monitoring-view/handler.py /asset-output/handler.py",
21
+ "cp -R src/papyrus_content/. /asset-output/papyrus_content/",
22
+ ].join(" && "),
23
+ ]),
24
+ }), { resourceGroupName: "data" });
@@ -0,0 +1,34 @@
1
+ import { defineFunction } from "@aws-amplify/backend";
2
+ import { Duration } from "aws-cdk-lib";
3
+ import { Architecture, Function, Runtime } from "aws-cdk-lib/aws-lambda";
4
+ import type { Construct } from "constructs";
5
+ import { pythonLambdaCode } from "../shared/python-bundle";
6
+
7
+ /** AppSync gives a resolver 30 seconds; a read of one small table needs a few. */
8
+ export const MONITORING_VIEW_TIMEOUT_SECONDS = 15;
9
+
10
+ /** stdlib plus the runtime's boto3: the bundle is `papyrus_content` and nothing else. */
11
+ export const monitoringView = defineFunction(
12
+ (scope: Construct) =>
13
+ new Function(scope, "papyrus-monitoring-view", {
14
+ runtime: Runtime.PYTHON_3_12,
15
+ architecture: Architecture.ARM_64,
16
+ handler: "handler.handler",
17
+ timeout: Duration.seconds(MONITORING_VIEW_TIMEOUT_SECONDS),
18
+ memorySize: 256,
19
+ code: pythonLambdaCode(
20
+ { functionDir: "monitoring-view", modules: ["papyrus_content"], noDeps: true },
21
+ [
22
+ "bash",
23
+ "-c",
24
+ [
25
+ "set -euo pipefail",
26
+ "mkdir -p /asset-output/papyrus_content",
27
+ "cp amplify/functions/monitoring-view/handler.py /asset-output/handler.py",
28
+ "cp -R src/papyrus_content/. /asset-output/papyrus_content/",
29
+ ].join(" && "),
30
+ ],
31
+ ),
32
+ }),
33
+ { resourceGroupName: "data" },
34
+ );
@@ -0,0 +1,16 @@
1
+ import { a } from "@aws-amplify/backend";
2
+ import { monitoringView } from "./resource.js";
3
+ const editors = ["editor", "admin"];
4
+ /**
5
+ * Core to every site's data API. The Monitoring page reads the shared monitoring pipeline through
6
+ * this one query. AppSync admits editors and admins only; the function checks the groups again,
7
+ * and returns the whole shared pipeline to admins alone.
8
+ */
9
+ export const monitoringViewSchemaDefinitions = {
10
+ monitoringOverview: a
11
+ .query()
12
+ .arguments({ scope: a.string() })
13
+ .returns(a.json())
14
+ .authorization((allow) => [allow.groups(editors)])
15
+ .handler(a.handler.function(monitoringView)),
16
+ };
@@ -0,0 +1,18 @@
1
+ import { a } from "@aws-amplify/backend";
2
+ import { monitoringView } from "./resource";
3
+
4
+ const editors = ["editor", "admin"];
5
+
6
+ /**
7
+ * Core to every site's data API. The Monitoring page reads the shared monitoring pipeline through
8
+ * this one query. AppSync admits editors and admins only; the function checks the groups again,
9
+ * and returns the whole shared pipeline to admins alone.
10
+ */
11
+ export const monitoringViewSchemaDefinitions = {
12
+ monitoringOverview: a
13
+ .query()
14
+ .arguments({ scope: a.string() })
15
+ .returns(a.json())
16
+ .authorization((allow) => [allow.groups(editors)])
17
+ .handler(a.handler.function(monitoringView)),
18
+ };
@@ -0,0 +1,37 @@
1
+ import { Stack } from "aws-cdk-lib";
2
+ import { Effect, PolicyStatement } from "aws-cdk-lib/aws-iam";
3
+ /** The monitoring stack writes the table's name here (infra/monitoring/papyrus-monitoring.yaml). */
4
+ export const MONITORING_TABLE_PARAMETER = "/papyrus/monitoring/table-name";
5
+ /** Reads only: a single item or a key-range query. No Scan, no writes, no other table. */
6
+ export const MONITORING_VIEW_TABLE_ACTIONS = ["dynamodb:GetItem", "dynamodb:Query"];
7
+ /**
8
+ * The monitoring table is auto-named by CloudFormation (`papyrus-monitoring-MonitoringTable-<id>`), so
9
+ * the grant is the stack's table name prefix, not a wildcard on the account.
10
+ */
11
+ export function monitoringViewTableArns(region, account) {
12
+ const table = `arn:aws:dynamodb:${region}:${account}:table/papyrus-monitoring-MonitoringTable-*`;
13
+ return [table, `${table}/index/routing`];
14
+ }
15
+ export function monitoringViewParameterArn(region, account) {
16
+ return `arn:aws:ssm:${region}:${account}:parameter${MONITORING_TABLE_PARAMETER}`;
17
+ }
18
+ /**
19
+ * Environment and least-privilege IAM for the monitoring-view function. A site outside the monitoring
20
+ * account simply finds no parameter and the page says monitoring is not configured.
21
+ */
22
+ export function wireMonitoringView(backend) {
23
+ const lambda = backend.monitoringView.resources.lambda;
24
+ const stack = Stack.of(lambda);
25
+ lambda.addEnvironment("PAPYRUS_GRAPHQL_ENDPOINT", backend.data.resources.cfnResources.cfnGraphqlApi.attrGraphQlUrl);
26
+ lambda.addEnvironment("PAPYRUS_MONITORING_TABLE_PARAMETER", MONITORING_TABLE_PARAMETER);
27
+ lambda.addToRolePolicy(new PolicyStatement({
28
+ effect: Effect.ALLOW,
29
+ actions: ["ssm:GetParameter"],
30
+ resources: [monitoringViewParameterArn(stack.region, stack.account)],
31
+ }));
32
+ lambda.addToRolePolicy(new PolicyStatement({
33
+ effect: Effect.ALLOW,
34
+ actions: MONITORING_VIEW_TABLE_ACTIONS,
35
+ resources: monitoringViewTableArns(stack.region, stack.account),
36
+ }));
37
+ }
@@ -0,0 +1,47 @@
1
+ import { Stack } from "aws-cdk-lib";
2
+ import { Effect, PolicyStatement } from "aws-cdk-lib/aws-iam";
3
+ import type { Function as LambdaFunction } from "aws-cdk-lib/aws-lambda";
4
+
5
+ /** The monitoring stack writes the table's name here (infra/monitoring/papyrus-monitoring.yaml). */
6
+ export const MONITORING_TABLE_PARAMETER = "/papyrus/monitoring/table-name";
7
+
8
+ /** Reads only: a single item or a key-range query. No Scan, no writes, no other table. */
9
+ export const MONITORING_VIEW_TABLE_ACTIONS = ["dynamodb:GetItem", "dynamodb:Query"];
10
+
11
+ /**
12
+ * The monitoring table is auto-named by CloudFormation (`papyrus-monitoring-MonitoringTable-<id>`), so
13
+ * the grant is the stack's table name prefix, not a wildcard on the account.
14
+ */
15
+ export function monitoringViewTableArns(region: string, account: string): string[] {
16
+ const table = `arn:aws:dynamodb:${region}:${account}:table/papyrus-monitoring-MonitoringTable-*`;
17
+ return [table, `${table}/index/routing`];
18
+ }
19
+
20
+ export function monitoringViewParameterArn(region: string, account: string): string {
21
+ return `arn:aws:ssm:${region}:${account}:parameter${MONITORING_TABLE_PARAMETER}`;
22
+ }
23
+
24
+ /**
25
+ * Environment and least-privilege IAM for the monitoring-view function. A site outside the monitoring
26
+ * account simply finds no parameter and the page says monitoring is not configured.
27
+ */
28
+ export function wireMonitoringView(backend: any): void {
29
+ const lambda = backend.monitoringView.resources.lambda as LambdaFunction;
30
+ const stack = Stack.of(lambda);
31
+ lambda.addEnvironment("PAPYRUS_GRAPHQL_ENDPOINT", backend.data.resources.cfnResources.cfnGraphqlApi.attrGraphQlUrl as string);
32
+ lambda.addEnvironment("PAPYRUS_MONITORING_TABLE_PARAMETER", MONITORING_TABLE_PARAMETER);
33
+ lambda.addToRolePolicy(
34
+ new PolicyStatement({
35
+ effect: Effect.ALLOW,
36
+ actions: ["ssm:GetParameter"],
37
+ resources: [monitoringViewParameterArn(stack.region, stack.account)],
38
+ }),
39
+ );
40
+ lambda.addToRolePolicy(
41
+ new PolicyStatement({
42
+ effect: Effect.ALLOW,
43
+ actions: MONITORING_VIEW_TABLE_ACTIONS,
44
+ resources: monitoringViewTableArns(stack.region, stack.account),
45
+ }),
46
+ );
47
+ }