@anthusai/papyrus 2.0.0-next.7 → 2.0.0-next.71
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/data/resource.js +23 -3
- package/amplify/data/resource.ts +25 -3
- package/amplify/data/schema.js +2028 -1979
- package/amplify/data/schema.ts +72 -14
- package/amplify/functions/assignment-action/data-access.js +90 -0
- package/amplify/functions/assignment-action/data-access.ts +89 -0
- package/amplify/functions/assignment-action/handler.ts +1 -1
- package/amplify/functions/content-actions/handler.py +61 -2
- package/amplify/functions/content-actions/requirements.txt +1 -0
- package/amplify/functions/content-actions/resource.js +1 -1
- package/amplify/functions/content-actions/resource.ts +1 -1
- package/amplify/{plugins/editorial-checks/function → functions/editorial-checks}/handler.py +3 -3
- package/amplify/functions/editorial-checks/requirements.txt +1 -0
- package/amplify/{plugins/editorial-checks/function → functions/editorial-checks}/resource.js +7 -7
- package/amplify/{plugins/editorial-checks/function → functions/editorial-checks}/resource.ts +7 -7
- package/amplify/functions/editorial-checks/schema.js +121 -0
- package/amplify/{plugins → functions}/editorial-checks/schema.ts +33 -6
- package/amplify/functions/editorial-checks/wire.js +53 -0
- package/amplify/functions/editorial-checks/wire.ts +61 -0
- package/amplify/functions/monitoring-view/handler.py +11 -0
- package/amplify/functions/monitoring-view/resource.js +24 -0
- package/amplify/functions/monitoring-view/resource.ts +34 -0
- package/amplify/functions/monitoring-view/schema.js +16 -0
- package/amplify/functions/monitoring-view/schema.ts +18 -0
- package/amplify/functions/monitoring-view/wire.js +37 -0
- package/amplify/functions/monitoring-view/wire.ts +47 -0
- package/amplify/functions/public-forms/core.js +247 -0
- package/amplify/functions/public-forms/core.ts +310 -0
- package/amplify/functions/public-forms/handler.ts +41 -0
- package/amplify/functions/public-forms/origins.js +35 -0
- package/amplify/functions/public-forms/origins.ts +43 -0
- package/amplify/functions/public-forms/resource.js +9 -0
- package/amplify/functions/public-forms/resource.ts +10 -0
- package/amplify/functions/public-forms/wire.js +25 -0
- package/amplify/functions/public-forms/wire.ts +32 -0
- package/amplify/functions/shared/editorial-context.ts +63 -4
- package/amplify/functions/shared/python-bundle.js +20 -14
- package/amplify/functions/shared/python-bundle.ts +25 -18
- package/amplify/plugins/newsletter/config.js +245 -0
- package/amplify/plugins/newsletter/config.ts +305 -0
- package/amplify/plugins/newsletter/function/handler.py +6 -0
- package/amplify/plugins/newsletter/function/requirements.txt +5 -0
- package/amplify/plugins/newsletter/ops/handler.py +12 -0
- package/amplify/plugins/newsletter/ops/resource.js +27 -0
- package/amplify/plugins/newsletter/ops/resource.ts +37 -0
- package/amplify/plugins/newsletter/papyrus.plugin.js +263 -0
- package/amplify/plugins/newsletter/papyrus.plugin.ts +311 -0
- package/amplify/plugins/newsletter/schema.js +56 -0
- package/amplify/plugins/newsletter/schema.ts +61 -0
- package/amplify/plugins/newsletter/secure-string-parameter.js +107 -0
- package/amplify/plugins/newsletter/secure-string-parameter.ts +120 -0
- package/amplify/plugins/newsletter/sending.js +140 -0
- package/amplify/plugins/newsletter/sending.ts +186 -0
- package/amplify/plugins/reader-steering/config.js +180 -0
- package/amplify/plugins/reader-steering/config.ts +280 -0
- package/amplify/plugins/reader-steering/function/ai_moderation.py +246 -0
- package/amplify/plugins/reader-steering/function/handler.py +1554 -0
- package/amplify/plugins/reader-steering/function/moderation-prompt.md +27 -0
- package/amplify/plugins/reader-steering/function/moderation.py +316 -0
- package/amplify/plugins/reader-steering/function/proposals.py +255 -0
- package/amplify/plugins/reader-steering/function/resource.js +27 -0
- package/amplify/plugins/reader-steering/function/resource.ts +35 -0
- package/amplify/plugins/reader-steering/papyrus.plugin.js +184 -0
- package/amplify/plugins/reader-steering/papyrus.plugin.ts +210 -0
- package/amplify/plugins/reader-steering/schema.js +204 -0
- package/amplify/plugins/reader-steering/schema.ts +206 -0
- package/amplify/plugins/registry.js +4 -2
- package/amplify/plugins/registry.ts +4 -2
- package/amplify/plugins/types.ts +5 -0
- package/amplify/plugins/wire.js +1 -0
- package/amplify/plugins/wire.ts +1 -0
- package/amplify/publication/projection-lease.js +30 -0
- package/amplify/publication/projection-lease.ts +39 -0
- package/amplify/publication/redirect-and-index.js +105 -0
- package/amplify/publication/redirect-rules.js +73 -0
- package/amplify/publication/redirect-rules.ts +93 -0
- package/amplify/publication/s3-projection.js +7 -1
- package/amplify/publication/s3-projection.ts +9 -1
- package/amplify/site-backend-config.ts +17 -0
- package/amplify/site-backend.js +38 -1
- package/amplify/site-backend.ts +46 -1
- package/app/api/auth/prospectus/sign-in/route.ts +4 -0
- package/app/api/newsletter/confirm/route.ts +13 -0
- package/app/api/newsletter/preferences/route.ts +13 -0
- package/app/api/newsletter/state/route.ts +9 -0
- package/app/api/newsletter/subscribe/route.ts +9 -0
- package/app/api/newsletter/unsubscribe/route.ts +13 -0
- package/app/api/newsroom/curation/context/route.ts +9 -0
- package/app/api/newsroom/curation/priming/route.ts +9 -0
- package/app/api/newsroom/curation/publication/route.ts +9 -0
- package/app/api/reader/comment/delete/route.ts +9 -0
- package/app/api/reader/comment/edit/route.ts +9 -0
- package/app/api/reader/comment/route.ts +9 -0
- package/app/api/reader/flag/route.ts +9 -0
- package/app/api/reader/handle/route.ts +9 -0
- package/app/api/reader/me/route.ts +9 -0
- package/app/api/reader/rating/route.ts +9 -0
- package/app/api/reader/report/route.ts +9 -0
- package/app/api/reader/retired/route.ts +9 -0
- package/app/api/reader/submit/route.ts +9 -0
- package/app/api/reader/vote/route.ts +9 -0
- package/bin/papyrus-infra.mjs +20 -1
- package/components/editorial-checks-admin-panel.tsx +36 -11
- package/components/moderation-panel.tsx +248 -0
- package/components/monitoring-overview-view.tsx +241 -0
- package/components/monitoring-panel.tsx +40 -0
- package/components/newsletter-panel.tsx +474 -0
- package/components/newsletter-sections.tsx +163 -0
- package/components/newsroom-article-editor.tsx +2 -4
- package/components/newsroom-curation-bootstrap.tsx +45 -0
- package/components/newsroom-organizer.css +31 -0
- package/components/newsroom-references-view.tsx +14 -14
- package/components/publication-cyclotron-panel.tsx +15 -10
- package/components/reference-add-entry.tsx +75 -0
- package/components/reference-curation-controls.tsx +31 -22
- package/components/reference-cyclotron-priming.tsx +58 -19
- package/components/reference-cyclotron-suggestion.tsx +1 -1
- package/components/reference-priming.tsx +14 -10
- package/components/reference-section-suggestion.tsx +1 -1
- package/components/topic-steering-workspace.tsx +64 -20
- package/components/use-editorial-checks.ts +12 -10
- package/infra/amplify-app-shell.js +90 -16
- package/infra/amplify-app-shell.ts +102 -18
- package/infra/index.js +1 -0
- package/infra/secure-string-parameter-handler.js +41 -0
- package/infra/secure-string-parameter-handler.ts +41 -0
- package/infra/secure-string-parameter.js +79 -0
- package/infra/secure-string-parameter.ts +91 -0
- package/infra/site-config.js +86 -6
- package/infra/site-config.ts +129 -6
- package/lib/category-repository.ts +11 -9
- package/lib/curation-routes.ts +345 -0
- package/lib/editorial-checks-backend.ts +1 -1
- package/lib/editorial-checks-client.ts +19 -1
- package/lib/editorial-checks-demo.ts +2 -2
- package/lib/editorial-checks-settings.ts +3 -0
- package/lib/editorial-checks.ts +8 -11
- package/lib/editorial-preview.ts +5 -5
- package/lib/monitoring-client.ts +29 -0
- package/lib/monitoring-overview-fixture.ts +51 -0
- package/lib/monitoring-overview.ts +145 -0
- package/lib/newsletter-api.ts +418 -0
- package/lib/newsletter-client.ts +46 -0
- package/lib/newsletter-fixture.ts +184 -0
- package/lib/newsletter-model.ts +202 -0
- package/lib/prospectus-session.ts +15 -14
- package/lib/prospectus-sign-in-routes.ts +84 -19
- package/lib/prospectus-site-identity.ts +24 -1
- package/lib/reader-api.ts +145 -0
- package/lib/reader-moderation.ts +220 -0
- package/lib/reader-retirement-route.ts +89 -0
- package/lib/reader-subject.md +29 -0
- package/lib/reader-subject.ts +53 -0
- package/lib/relevance-status.ts +2 -2
- package/lib/semantic-graph.ts +2 -0
- package/lib/site-brand-tenant.ts +11 -6
- package/lib/site-brand.ts +6 -3
- package/lib/site-origin.ts +67 -0
- package/middleware.ts +14 -3
- package/package.json +42 -3
- package/routes.manifest.json +215 -2
- package/amplify/plugins/editorial-checks/function/requirements.txt +0 -1
- package/amplify/plugins/editorial-checks/papyrus.plugin.js +0 -69
- package/amplify/plugins/editorial-checks/papyrus.plugin.ts +0 -85
- package/amplify/plugins/editorial-checks/schema.js +0 -94
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { ArnPrincipal, Effect, PolicyStatement, Role, ServicePrincipal } from "aws-cdk-lib/aws-iam";
|
|
2
|
+
import { Duration, Stack } from "aws-cdk-lib";
|
|
3
|
+
import { Rule, RuleTargetInput, Schedule } from "aws-cdk-lib/aws-events";
|
|
4
|
+
import { LambdaFunction as LambdaFunctionTarget } from "aws-cdk-lib/aws-events-targets";
|
|
5
|
+
import { resolveReaderSteeringConfig } from "./config.js";
|
|
6
|
+
import { readerActions } from "./function/resource.js";
|
|
7
|
+
import { readerSteeringSchemaDefinitions } from "./schema.js";
|
|
8
|
+
export { resolveReaderSteeringConfig };
|
|
9
|
+
export const READER_STEERING_OUTPUT_KEY = "readerSteering";
|
|
10
|
+
export const SNAPSHOT_SCHEDULE_PREFIX = "papyrus-reader-snapshot-";
|
|
11
|
+
export const READER_SNAPSHOT_TASK = { projectionTask: { task: "reader-snapshot" } };
|
|
12
|
+
export const READER_SCHEDULED_SNAPSHOT_TASK = { projectionTask: { task: "reader-snapshot", retirementPoll: true } };
|
|
13
|
+
export const READER_POLL_SECRET_PARAMETER_ENV = "PAPYRUS_READER_POLL_SECRET_PARAMETER";
|
|
14
|
+
export const readerSteeringManifest = {
|
|
15
|
+
name: "reader-steering",
|
|
16
|
+
contract: 1,
|
|
17
|
+
models: ["ReaderProfile", "ReaderHandle", "ReaderVote", "ReaderFlag", "ReaderSubmission", "ReaderComment", "ReaderReport", "ModerationAction", "Proposal"],
|
|
18
|
+
mutations: ["moderateReader", "fileProposal", "transitionProposal"],
|
|
19
|
+
guest: { mutations: [] },
|
|
20
|
+
newsroomPanels: [{ id: "moderation", label: "Moderation" }],
|
|
21
|
+
staticAssets: ["_plugins/papyrus-reader@1.js", "_plugins/papyrus-reader@1.css"],
|
|
22
|
+
};
|
|
23
|
+
/** What the reader-actions function reads from `PAPYRUS_READER_SETTINGS`. */
|
|
24
|
+
export function readerActionsSettings(config, allowInterimSubjects) {
|
|
25
|
+
return {
|
|
26
|
+
dimensions: config.dimensions,
|
|
27
|
+
limits: config.limits,
|
|
28
|
+
submissions: config.submissions,
|
|
29
|
+
subjects: config.subjects,
|
|
30
|
+
comments: config.comments,
|
|
31
|
+
moderation: config.moderation,
|
|
32
|
+
reservedHandles: config.reservedHandles,
|
|
33
|
+
allowInterimSubjects,
|
|
34
|
+
snapshotDebounceSeconds: 60,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/** What the `reader-snapshot` projection task reads from `PAPYRUS_READER_SNAPSHOT_SETTINGS`. */
|
|
38
|
+
export function readerSnapshotSettings(config) {
|
|
39
|
+
return {
|
|
40
|
+
dimensions: config.dimensions,
|
|
41
|
+
submissions: config.submissions,
|
|
42
|
+
subjects: config.subjects,
|
|
43
|
+
karma: config.karma,
|
|
44
|
+
ranking: config.ranking,
|
|
45
|
+
limits: { newAccountHours: config.limits.newAccountHours },
|
|
46
|
+
hypeMinimum: config.snapshot.hypeMinimum,
|
|
47
|
+
...(config.hypeGap ? { hypeGap: config.hypeGap } : {}),
|
|
48
|
+
retirementPoll: config.retirementPoll,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export function interimSubjectsAllowedAtSynth(environment = process.env) {
|
|
52
|
+
return ["development", "test"].includes((environment.SITE_ENV ?? "").trim()) && environment.NODE_ENV !== "production";
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The scheduled run polls Prospectus through the CMS route /api/reader/retired (docs/reader-steering.md), so it needs the
|
|
56
|
+
* site origin and the poll secret parameter that the app-shell stack generates (`cms.readerRetirementPoll`); both reach the
|
|
57
|
+
* backend build as branch variables. It also deletes and re-keys rows, and keeps its cursor in the rate table.
|
|
58
|
+
*/
|
|
59
|
+
function wireRetirementPoll(readerLambda, contentActions, tables) {
|
|
60
|
+
const origin = (process.env.PAPYRUS_SITE_ORIGIN ?? "").trim();
|
|
61
|
+
const parameterName = (process.env[READER_POLL_SECRET_PARAMETER_ENV] ?? "").trim();
|
|
62
|
+
if (!origin.startsWith("https://") || !parameterName.startsWith("/")) {
|
|
63
|
+
throw new Error("reader-steering retirementPoll needs PAPYRUS_SITE_ORIGIN (an https origin) and PAPYRUS_READER_POLL_SECRET_PARAMETER (an SSM parameter name). The app-shell template sets both on the production branch when site.json has cms.readerRetirementPoll: true; see docs/reader-steering.md.");
|
|
64
|
+
}
|
|
65
|
+
const rateTable = readerLambda.node.scope?.node.tryFindChild("PapyrusReaderRateWindows");
|
|
66
|
+
if (!rateTable)
|
|
67
|
+
throw new Error("reader-steering retirementPoll could not find the reader-actions rate table to keep its cursor in");
|
|
68
|
+
tables.ReaderVote.grantReadWriteData(contentActions);
|
|
69
|
+
tables.ReaderHandle.grantReadWriteData(contentActions);
|
|
70
|
+
rateTable.grantReadWriteData(contentActions);
|
|
71
|
+
contentActions.addEnvironment("PAPYRUS_READER_RATE_TABLE", rateTable.tableName);
|
|
72
|
+
contentActions.addEnvironment("PAPYRUS_READER_POLL_URL", origin);
|
|
73
|
+
contentActions.addEnvironment(READER_POLL_SECRET_PARAMETER_ENV, parameterName);
|
|
74
|
+
const stack = Stack.of(contentActions);
|
|
75
|
+
contentActions.addToRolePolicy(new PolicyStatement({
|
|
76
|
+
effect: Effect.ALLOW,
|
|
77
|
+
actions: ["ssm:GetParameter"],
|
|
78
|
+
resources: [`arn:${stack.partition}:ssm:${stack.region}:${stack.account}:parameter${parameterName}`],
|
|
79
|
+
}));
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* AI moderation (`moderation.mode: ai`). The debounced run becomes a run of reader-actions itself (a one-off schedule that
|
|
83
|
+
* invokes this function), which judges the new items and then asks content-actions for the snapshot. So the scheduler role may
|
|
84
|
+
* invoke reader-actions, reader-actions may invoke content-actions (its ARN is already in the environment) and may read exactly
|
|
85
|
+
* one SSM SecureString: the API key, which the plugin never creates and never receives.
|
|
86
|
+
*/
|
|
87
|
+
function wireAiModeration(readerLambda, contentActions, schedulerRole, apiKeyParameter) {
|
|
88
|
+
const stack = Stack.of(readerLambda);
|
|
89
|
+
readerLambda.grantInvoke(schedulerRole);
|
|
90
|
+
contentActions.grantInvoke(readerLambda);
|
|
91
|
+
readerLambda.addToRolePolicy(new PolicyStatement({
|
|
92
|
+
effect: Effect.ALLOW,
|
|
93
|
+
actions: ["ssm:GetParameter"],
|
|
94
|
+
resources: [`arn:${stack.partition}:ssm:${stack.region}:${stack.account}:parameter${apiKeyParameter}`],
|
|
95
|
+
}));
|
|
96
|
+
}
|
|
97
|
+
export const readerSteeringPlugin = {
|
|
98
|
+
manifest: readerSteeringManifest,
|
|
99
|
+
resolveConfig: resolveReaderSteeringConfig,
|
|
100
|
+
functions: () => ({ readerActions }),
|
|
101
|
+
schemaDefinitions: readerSteeringSchemaDefinitions,
|
|
102
|
+
publicSettings: (config) => ({
|
|
103
|
+
contract: readerSteeringManifest.contract,
|
|
104
|
+
dimensions: config.dimensions,
|
|
105
|
+
subjects: { types: config.subjects.types },
|
|
106
|
+
moderation: { mode: config.moderation.mode },
|
|
107
|
+
}),
|
|
108
|
+
wire(backend, config, context) {
|
|
109
|
+
const lambda = backend.readerActions.resources.lambda;
|
|
110
|
+
const tables = backend.data.resources.tables;
|
|
111
|
+
const contentActions = context.contentActionsLambda;
|
|
112
|
+
for (const [variable, model] of [
|
|
113
|
+
["PAPYRUS_READER_PROFILE_TABLE", "ReaderProfile"],
|
|
114
|
+
["PAPYRUS_READER_HANDLE_TABLE", "ReaderHandle"],
|
|
115
|
+
["PAPYRUS_READER_VOTE_TABLE", "ReaderVote"],
|
|
116
|
+
["PAPYRUS_READER_FLAG_TABLE", "ReaderFlag"],
|
|
117
|
+
["PAPYRUS_READER_SUBMISSION_TABLE", "ReaderSubmission"],
|
|
118
|
+
["PAPYRUS_READER_COMMENT_TABLE", "ReaderComment"],
|
|
119
|
+
["PAPYRUS_READER_REPORT_TABLE", "ReaderReport"],
|
|
120
|
+
["PAPYRUS_READER_ACTION_TABLE", "ModerationAction"],
|
|
121
|
+
["PAPYRUS_READER_PROPOSAL_TABLE", "Proposal"],
|
|
122
|
+
]) {
|
|
123
|
+
tables[model].grantReadWriteData(lambda);
|
|
124
|
+
lambda.addEnvironment(variable, tables[model].tableName);
|
|
125
|
+
contentActions.addEnvironment(variable, tables[model].tableName);
|
|
126
|
+
}
|
|
127
|
+
// Promoting a submission writes one draft Item (a version 1 draft; nothing is published by this function).
|
|
128
|
+
tables.Item.grantWriteData(lambda);
|
|
129
|
+
lambda.addEnvironment("PAPYRUS_READER_ITEM_TABLE", tables.Item.tableName);
|
|
130
|
+
tables.PublishedItem.grantReadData(lambda);
|
|
131
|
+
lambda.addEnvironment("PAPYRUS_READER_PUBLISHED_ITEM_TABLE", tables.PublishedItem.tableName);
|
|
132
|
+
tables.ReaderVote.grantReadData(contentActions);
|
|
133
|
+
tables.ReaderFlag.grantReadData(contentActions);
|
|
134
|
+
tables.ReaderProfile.grantReadWriteData(contentActions);
|
|
135
|
+
// The snapshot reads submissions, and the review step writes their signals and moderation state.
|
|
136
|
+
tables.ReaderSubmission.grantReadWriteData(contentActions);
|
|
137
|
+
tables.ReaderComment.grantReadWriteData(contentActions);
|
|
138
|
+
// The snapshot reads proposals and freezes the community result of one that reaches editor review.
|
|
139
|
+
tables.Proposal.grantReadWriteData(contentActions);
|
|
140
|
+
lambda.addEnvironment("PAPYRUS_READER_SETTINGS", JSON.stringify(readerActionsSettings(config, interimSubjectsAllowedAtSynth())));
|
|
141
|
+
if (config.reservedConcurrency !== undefined) {
|
|
142
|
+
lambda.node.defaultChild.addPropertyOverride("ReservedConcurrentExecutions", config.reservedConcurrency);
|
|
143
|
+
}
|
|
144
|
+
// Trailing-edge debounce: the first write in a window creates a one-off EventBridge Scheduler schedule at the end of
|
|
145
|
+
// the window (docs/reader-steering.md). The schedule invokes content-actions as this role; reader-actions may create
|
|
146
|
+
// schedules named for this feature, and pass exactly this role.
|
|
147
|
+
const schedulerRole = new Role(Stack.of(lambda), "ReaderSnapshotSchedulerRole", {
|
|
148
|
+
assumedBy: new ServicePrincipal("scheduler.amazonaws.com"),
|
|
149
|
+
description: "Lets one-off schedules created by reader-actions invoke the reader-snapshot run.",
|
|
150
|
+
});
|
|
151
|
+
contentActions.grantInvoke(schedulerRole);
|
|
152
|
+
const stack = Stack.of(lambda); // the role lives with the function, so the stacks keep their existing one-way dependency
|
|
153
|
+
lambda.addToRolePolicy(new PolicyStatement({
|
|
154
|
+
effect: Effect.ALLOW,
|
|
155
|
+
actions: ["scheduler:CreateSchedule"],
|
|
156
|
+
resources: [`arn:${stack.partition}:scheduler:${stack.region}:${stack.account}:schedule/default/${SNAPSHOT_SCHEDULE_PREFIX}*`],
|
|
157
|
+
}));
|
|
158
|
+
lambda.addToRolePolicy(new PolicyStatement({ effect: Effect.ALLOW, actions: ["iam:PassRole"], resources: [schedulerRole.roleArn] }));
|
|
159
|
+
lambda.addEnvironment("PAPYRUS_READER_SNAPSHOT_FUNCTION_ARN", contentActions.functionArn);
|
|
160
|
+
lambda.addEnvironment("PAPYRUS_READER_SCHEDULER_ROLE_ARN", schedulerRole.roleArn);
|
|
161
|
+
contentActions.addEnvironment("PAPYRUS_READER_SNAPSHOT_SETTINGS", JSON.stringify(readerSnapshotSettings(config)));
|
|
162
|
+
if (config.moderation.ai)
|
|
163
|
+
wireAiModeration(lambda, contentActions, schedulerRole, config.moderation.ai.apiKeyParameter);
|
|
164
|
+
lambda.addPermission("InvokeFromCmsCompute", {
|
|
165
|
+
principal: new ArnPrincipal(config.computeRoleArn),
|
|
166
|
+
action: "lambda:InvokeFunction",
|
|
167
|
+
});
|
|
168
|
+
if (config.retirementPoll)
|
|
169
|
+
wireRetirementPoll(lambda, contentActions, tables);
|
|
170
|
+
if (config.snapshot.schedule) {
|
|
171
|
+
new Rule(context.createStack("reader-steering-schedule"), "ReaderSnapshotSchedule", {
|
|
172
|
+
description: "Rebuilds the reader snapshot (time decay, Rising) and, when enabled, applies Prospectus subject retirements.",
|
|
173
|
+
schedule: Schedule.rate(Duration.hours(config.snapshot.intervalHours)),
|
|
174
|
+
targets: [
|
|
175
|
+
new LambdaFunctionTarget(contentActions, {
|
|
176
|
+
event: RuleTargetInput.fromObject(config.retirementPoll ? READER_SCHEDULED_SNAPSHOT_TASK : READER_SNAPSHOT_TASK),
|
|
177
|
+
retryAttempts: 0,
|
|
178
|
+
}),
|
|
179
|
+
],
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
backend.addOutput({ custom: { [READER_STEERING_OUTPUT_KEY]: { actionsFunction: lambda.functionName } } });
|
|
183
|
+
},
|
|
184
|
+
};
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { ArnPrincipal, Effect, PolicyStatement, Role, ServicePrincipal } from "aws-cdk-lib/aws-iam";
|
|
2
|
+
import { Duration, Stack } from "aws-cdk-lib";
|
|
3
|
+
import type { ITable } from "aws-cdk-lib/aws-dynamodb";
|
|
4
|
+
import { Rule, RuleTargetInput, Schedule } from "aws-cdk-lib/aws-events";
|
|
5
|
+
import { LambdaFunction as LambdaFunctionTarget } from "aws-cdk-lib/aws-events-targets";
|
|
6
|
+
import { CfnFunction, type Function as LambdaFunction } from "aws-cdk-lib/aws-lambda";
|
|
7
|
+
import type { PapyrusPlugin, PluginManifest, PluginWiringContext } from "../types";
|
|
8
|
+
import { resolveReaderSteeringConfig, type ReaderSteeringConfig } from "./config";
|
|
9
|
+
import { readerActions } from "./function/resource";
|
|
10
|
+
import { readerSteeringSchemaDefinitions } from "./schema";
|
|
11
|
+
|
|
12
|
+
export { resolveReaderSteeringConfig };
|
|
13
|
+
export type { ReaderSteeringConfig };
|
|
14
|
+
|
|
15
|
+
export const READER_STEERING_OUTPUT_KEY = "readerSteering";
|
|
16
|
+
export const SNAPSHOT_SCHEDULE_PREFIX = "papyrus-reader-snapshot-";
|
|
17
|
+
export const READER_SNAPSHOT_TASK = { projectionTask: { task: "reader-snapshot" } };
|
|
18
|
+
export const READER_SCHEDULED_SNAPSHOT_TASK = { projectionTask: { task: "reader-snapshot", retirementPoll: true } };
|
|
19
|
+
export const READER_POLL_SECRET_PARAMETER_ENV = "PAPYRUS_READER_POLL_SECRET_PARAMETER";
|
|
20
|
+
|
|
21
|
+
export const readerSteeringManifest: PluginManifest = {
|
|
22
|
+
name: "reader-steering",
|
|
23
|
+
contract: 1,
|
|
24
|
+
models: ["ReaderProfile", "ReaderHandle", "ReaderVote", "ReaderFlag", "ReaderSubmission", "ReaderComment", "ReaderReport", "ModerationAction", "Proposal"],
|
|
25
|
+
mutations: ["moderateReader", "fileProposal", "transitionProposal"],
|
|
26
|
+
guest: { mutations: [] },
|
|
27
|
+
newsroomPanels: [{ id: "moderation", label: "Moderation" }],
|
|
28
|
+
staticAssets: ["_plugins/papyrus-reader@1.js", "_plugins/papyrus-reader@1.css"],
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/** What the reader-actions function reads from `PAPYRUS_READER_SETTINGS`. */
|
|
32
|
+
export function readerActionsSettings(config: ReaderSteeringConfig, allowInterimSubjects: boolean) {
|
|
33
|
+
return {
|
|
34
|
+
dimensions: config.dimensions,
|
|
35
|
+
limits: config.limits,
|
|
36
|
+
submissions: config.submissions,
|
|
37
|
+
subjects: config.subjects,
|
|
38
|
+
comments: config.comments,
|
|
39
|
+
moderation: config.moderation,
|
|
40
|
+
reservedHandles: config.reservedHandles,
|
|
41
|
+
allowInterimSubjects,
|
|
42
|
+
snapshotDebounceSeconds: 60,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** What the `reader-snapshot` projection task reads from `PAPYRUS_READER_SNAPSHOT_SETTINGS`. */
|
|
47
|
+
export function readerSnapshotSettings(config: ReaderSteeringConfig) {
|
|
48
|
+
return {
|
|
49
|
+
dimensions: config.dimensions,
|
|
50
|
+
submissions: config.submissions,
|
|
51
|
+
subjects: config.subjects,
|
|
52
|
+
karma: config.karma,
|
|
53
|
+
ranking: config.ranking,
|
|
54
|
+
limits: { newAccountHours: config.limits.newAccountHours },
|
|
55
|
+
hypeMinimum: config.snapshot.hypeMinimum,
|
|
56
|
+
...(config.hypeGap ? { hypeGap: config.hypeGap } : {}),
|
|
57
|
+
retirementPoll: config.retirementPoll,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function interimSubjectsAllowedAtSynth(environment: Record<string, string | undefined> = process.env): boolean {
|
|
62
|
+
return ["development", "test"].includes((environment.SITE_ENV ?? "").trim()) && environment.NODE_ENV !== "production";
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The scheduled run polls Prospectus through the CMS route /api/reader/retired (docs/reader-steering.md), so it needs the
|
|
67
|
+
* site origin and the poll secret parameter that the app-shell stack generates (`cms.readerRetirementPoll`); both reach the
|
|
68
|
+
* backend build as branch variables. It also deletes and re-keys rows, and keeps its cursor in the rate table.
|
|
69
|
+
*/
|
|
70
|
+
function wireRetirementPoll(readerLambda: LambdaFunction, contentActions: LambdaFunction, tables: Record<string, ITable>) {
|
|
71
|
+
const origin = (process.env.PAPYRUS_SITE_ORIGIN ?? "").trim();
|
|
72
|
+
const parameterName = (process.env[READER_POLL_SECRET_PARAMETER_ENV] ?? "").trim();
|
|
73
|
+
if (!origin.startsWith("https://") || !parameterName.startsWith("/")) {
|
|
74
|
+
throw new Error(
|
|
75
|
+
"reader-steering retirementPoll needs PAPYRUS_SITE_ORIGIN (an https origin) and PAPYRUS_READER_POLL_SECRET_PARAMETER (an SSM parameter name). The app-shell template sets both on the production branch when site.json has cms.readerRetirementPoll: true; see docs/reader-steering.md.",
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
const rateTable = readerLambda.node.scope?.node.tryFindChild("PapyrusReaderRateWindows") as ITable | undefined;
|
|
79
|
+
if (!rateTable) throw new Error("reader-steering retirementPoll could not find the reader-actions rate table to keep its cursor in");
|
|
80
|
+
tables.ReaderVote.grantReadWriteData(contentActions);
|
|
81
|
+
tables.ReaderHandle.grantReadWriteData(contentActions);
|
|
82
|
+
rateTable.grantReadWriteData(contentActions);
|
|
83
|
+
contentActions.addEnvironment("PAPYRUS_READER_RATE_TABLE", rateTable.tableName);
|
|
84
|
+
contentActions.addEnvironment("PAPYRUS_READER_POLL_URL", origin);
|
|
85
|
+
contentActions.addEnvironment(READER_POLL_SECRET_PARAMETER_ENV, parameterName);
|
|
86
|
+
const stack = Stack.of(contentActions);
|
|
87
|
+
contentActions.addToRolePolicy(
|
|
88
|
+
new PolicyStatement({
|
|
89
|
+
effect: Effect.ALLOW,
|
|
90
|
+
actions: ["ssm:GetParameter"],
|
|
91
|
+
resources: [`arn:${stack.partition}:ssm:${stack.region}:${stack.account}:parameter${parameterName}`],
|
|
92
|
+
}),
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* AI moderation (`moderation.mode: ai`). The debounced run becomes a run of reader-actions itself (a one-off schedule that
|
|
98
|
+
* invokes this function), which judges the new items and then asks content-actions for the snapshot. So the scheduler role may
|
|
99
|
+
* invoke reader-actions, reader-actions may invoke content-actions (its ARN is already in the environment) and may read exactly
|
|
100
|
+
* one SSM SecureString: the API key, which the plugin never creates and never receives.
|
|
101
|
+
*/
|
|
102
|
+
function wireAiModeration(readerLambda: LambdaFunction, contentActions: LambdaFunction, schedulerRole: Role, apiKeyParameter: string) {
|
|
103
|
+
const stack = Stack.of(readerLambda);
|
|
104
|
+
readerLambda.grantInvoke(schedulerRole);
|
|
105
|
+
contentActions.grantInvoke(readerLambda);
|
|
106
|
+
readerLambda.addToRolePolicy(
|
|
107
|
+
new PolicyStatement({
|
|
108
|
+
effect: Effect.ALLOW,
|
|
109
|
+
actions: ["ssm:GetParameter"],
|
|
110
|
+
resources: [`arn:${stack.partition}:ssm:${stack.region}:${stack.account}:parameter${apiKeyParameter}`],
|
|
111
|
+
}),
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export const readerSteeringPlugin: PapyrusPlugin<ReaderSteeringConfig, { readerActions: typeof readerActions }> = {
|
|
116
|
+
manifest: readerSteeringManifest,
|
|
117
|
+
resolveConfig: resolveReaderSteeringConfig,
|
|
118
|
+
functions: () => ({ readerActions }),
|
|
119
|
+
schemaDefinitions: readerSteeringSchemaDefinitions,
|
|
120
|
+
publicSettings: (config) => ({
|
|
121
|
+
contract: readerSteeringManifest.contract,
|
|
122
|
+
dimensions: config.dimensions,
|
|
123
|
+
subjects: { types: config.subjects.types },
|
|
124
|
+
moderation: { mode: config.moderation.mode },
|
|
125
|
+
}),
|
|
126
|
+
wire(backend, config, context: PluginWiringContext) {
|
|
127
|
+
const lambda = backend.readerActions.resources.lambda as LambdaFunction;
|
|
128
|
+
const tables = backend.data.resources.tables as Record<string, ITable>;
|
|
129
|
+
const contentActions = context.contentActionsLambda;
|
|
130
|
+
|
|
131
|
+
for (const [variable, model] of [
|
|
132
|
+
["PAPYRUS_READER_PROFILE_TABLE", "ReaderProfile"],
|
|
133
|
+
["PAPYRUS_READER_HANDLE_TABLE", "ReaderHandle"],
|
|
134
|
+
["PAPYRUS_READER_VOTE_TABLE", "ReaderVote"],
|
|
135
|
+
["PAPYRUS_READER_FLAG_TABLE", "ReaderFlag"],
|
|
136
|
+
["PAPYRUS_READER_SUBMISSION_TABLE", "ReaderSubmission"],
|
|
137
|
+
["PAPYRUS_READER_COMMENT_TABLE", "ReaderComment"],
|
|
138
|
+
["PAPYRUS_READER_REPORT_TABLE", "ReaderReport"],
|
|
139
|
+
["PAPYRUS_READER_ACTION_TABLE", "ModerationAction"],
|
|
140
|
+
["PAPYRUS_READER_PROPOSAL_TABLE", "Proposal"],
|
|
141
|
+
] as const) {
|
|
142
|
+
tables[model].grantReadWriteData(lambda);
|
|
143
|
+
lambda.addEnvironment(variable, tables[model].tableName);
|
|
144
|
+
contentActions.addEnvironment(variable, tables[model].tableName);
|
|
145
|
+
}
|
|
146
|
+
// Promoting a submission writes one draft Item (a version 1 draft; nothing is published by this function).
|
|
147
|
+
tables.Item.grantWriteData(lambda);
|
|
148
|
+
lambda.addEnvironment("PAPYRUS_READER_ITEM_TABLE", tables.Item.tableName);
|
|
149
|
+
tables.PublishedItem.grantReadData(lambda);
|
|
150
|
+
lambda.addEnvironment("PAPYRUS_READER_PUBLISHED_ITEM_TABLE", tables.PublishedItem.tableName);
|
|
151
|
+
tables.ReaderVote.grantReadData(contentActions);
|
|
152
|
+
tables.ReaderFlag.grantReadData(contentActions);
|
|
153
|
+
tables.ReaderProfile.grantReadWriteData(contentActions);
|
|
154
|
+
// The snapshot reads submissions, and the review step writes their signals and moderation state.
|
|
155
|
+
tables.ReaderSubmission.grantReadWriteData(contentActions);
|
|
156
|
+
tables.ReaderComment.grantReadWriteData(contentActions);
|
|
157
|
+
// The snapshot reads proposals and freezes the community result of one that reaches editor review.
|
|
158
|
+
tables.Proposal.grantReadWriteData(contentActions);
|
|
159
|
+
|
|
160
|
+
lambda.addEnvironment("PAPYRUS_READER_SETTINGS", JSON.stringify(readerActionsSettings(config, interimSubjectsAllowedAtSynth())));
|
|
161
|
+
if (config.reservedConcurrency !== undefined) {
|
|
162
|
+
(lambda.node.defaultChild as CfnFunction).addPropertyOverride("ReservedConcurrentExecutions", config.reservedConcurrency);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Trailing-edge debounce: the first write in a window creates a one-off EventBridge Scheduler schedule at the end of
|
|
166
|
+
// the window (docs/reader-steering.md). The schedule invokes content-actions as this role; reader-actions may create
|
|
167
|
+
// schedules named for this feature, and pass exactly this role.
|
|
168
|
+
const schedulerRole = new Role(Stack.of(lambda), "ReaderSnapshotSchedulerRole", {
|
|
169
|
+
assumedBy: new ServicePrincipal("scheduler.amazonaws.com"),
|
|
170
|
+
description: "Lets one-off schedules created by reader-actions invoke the reader-snapshot run.",
|
|
171
|
+
});
|
|
172
|
+
contentActions.grantInvoke(schedulerRole);
|
|
173
|
+
const stack = Stack.of(lambda); // the role lives with the function, so the stacks keep their existing one-way dependency
|
|
174
|
+
lambda.addToRolePolicy(
|
|
175
|
+
new PolicyStatement({
|
|
176
|
+
effect: Effect.ALLOW,
|
|
177
|
+
actions: ["scheduler:CreateSchedule"],
|
|
178
|
+
resources: [`arn:${stack.partition}:scheduler:${stack.region}:${stack.account}:schedule/default/${SNAPSHOT_SCHEDULE_PREFIX}*`],
|
|
179
|
+
}),
|
|
180
|
+
);
|
|
181
|
+
lambda.addToRolePolicy(new PolicyStatement({ effect: Effect.ALLOW, actions: ["iam:PassRole"], resources: [schedulerRole.roleArn] }));
|
|
182
|
+
lambda.addEnvironment("PAPYRUS_READER_SNAPSHOT_FUNCTION_ARN", contentActions.functionArn);
|
|
183
|
+
lambda.addEnvironment("PAPYRUS_READER_SCHEDULER_ROLE_ARN", schedulerRole.roleArn);
|
|
184
|
+
contentActions.addEnvironment("PAPYRUS_READER_SNAPSHOT_SETTINGS", JSON.stringify(readerSnapshotSettings(config)));
|
|
185
|
+
|
|
186
|
+
if (config.moderation.ai) wireAiModeration(lambda, contentActions, schedulerRole, config.moderation.ai.apiKeyParameter);
|
|
187
|
+
|
|
188
|
+
lambda.addPermission("InvokeFromCmsCompute", {
|
|
189
|
+
principal: new ArnPrincipal(config.computeRoleArn),
|
|
190
|
+
action: "lambda:InvokeFunction",
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
if (config.retirementPoll) wireRetirementPoll(lambda, contentActions, tables);
|
|
194
|
+
|
|
195
|
+
if (config.snapshot.schedule) {
|
|
196
|
+
new Rule(context.createStack("reader-steering-schedule"), "ReaderSnapshotSchedule", {
|
|
197
|
+
description: "Rebuilds the reader snapshot (time decay, Rising) and, when enabled, applies Prospectus subject retirements.",
|
|
198
|
+
schedule: Schedule.rate(Duration.hours(config.snapshot.intervalHours)),
|
|
199
|
+
targets: [
|
|
200
|
+
new LambdaFunctionTarget(contentActions, {
|
|
201
|
+
event: RuleTargetInput.fromObject(config.retirementPoll ? READER_SCHEDULED_SNAPSHOT_TASK : READER_SNAPSHOT_TASK),
|
|
202
|
+
retryAttempts: 0,
|
|
203
|
+
}),
|
|
204
|
+
],
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
backend.addOutput({ custom: { [READER_STEERING_OUTPUT_KEY]: { actionsFunction: lambda.functionName } } });
|
|
209
|
+
},
|
|
210
|
+
};
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { a } from "@aws-amplify/backend";
|
|
2
|
+
import { readerActions } from "./function/resource.js";
|
|
3
|
+
/**
|
|
4
|
+
* Staff and IAM only: no guest, API key or reader rule on any model. The reader-actions function writes the
|
|
5
|
+
* tables directly with its own role, and editors may list them; admins may delete. `id` is the lookup key:
|
|
6
|
+
* the siteSubject for a profile, the lowercase handle for a claim, `subjectKey#readerId#dimension` for a vote (`subjectKey#readerId#kind` for a flag; the key is the bare id for items and submissions and `type:id` for the rest) and
|
|
7
|
+
* `sub-<sha256 of the canonical URL>` for a submission (so a canonical URL is one submission).
|
|
8
|
+
*/
|
|
9
|
+
const staffOnly = (allow) => [allow.group("editor").to(["read"]), allow.group("admin").to(["read", "delete"])];
|
|
10
|
+
export function readerSteeringSchemaDefinitions() {
|
|
11
|
+
return {
|
|
12
|
+
ReaderProfile: a
|
|
13
|
+
.model({
|
|
14
|
+
id: a.id().required(),
|
|
15
|
+
siteSubject: a.string().required(),
|
|
16
|
+
readerId: a.string().required(),
|
|
17
|
+
handle: a.string(),
|
|
18
|
+
state: a.string().required(),
|
|
19
|
+
karma: a.integer(),
|
|
20
|
+
})
|
|
21
|
+
.disableOperations(["subscriptions"])
|
|
22
|
+
.secondaryIndexes((index) => [index("readerId").name("profilesByReader").queryField("listReaderProfilesByReader")])
|
|
23
|
+
.authorization(staffOnly),
|
|
24
|
+
ReaderHandle: a
|
|
25
|
+
.model({
|
|
26
|
+
id: a.id().required(),
|
|
27
|
+
readerId: a.string().required(),
|
|
28
|
+
})
|
|
29
|
+
.disableOperations(["subscriptions"])
|
|
30
|
+
.authorization(staffOnly),
|
|
31
|
+
ReaderVote: a
|
|
32
|
+
.model({
|
|
33
|
+
id: a.id().required(),
|
|
34
|
+
subjectKey: a.string().required(),
|
|
35
|
+
subjectType: a.string(),
|
|
36
|
+
readerId: a.string().required(),
|
|
37
|
+
dimension: a.string().required(),
|
|
38
|
+
value: a.integer().required(),
|
|
39
|
+
voterRole: a.string().required(),
|
|
40
|
+
})
|
|
41
|
+
.disableOperations(["subscriptions"])
|
|
42
|
+
.authorization(staffOnly),
|
|
43
|
+
ReaderFlag: a
|
|
44
|
+
.model({
|
|
45
|
+
id: a.id().required(),
|
|
46
|
+
subjectKey: a.string().required(),
|
|
47
|
+
subjectType: a.string().required(),
|
|
48
|
+
readerId: a.string().required(),
|
|
49
|
+
kind: a.string().required(),
|
|
50
|
+
reason: a.string().required(),
|
|
51
|
+
targetKey: a.string(),
|
|
52
|
+
suggestedName: a.string(),
|
|
53
|
+
voterRole: a.string().required(),
|
|
54
|
+
createdAt: a.datetime().required(),
|
|
55
|
+
})
|
|
56
|
+
.disableOperations(["subscriptions"])
|
|
57
|
+
.authorization(staffOnly),
|
|
58
|
+
ReaderComment: a
|
|
59
|
+
.model({
|
|
60
|
+
id: a.id().required(),
|
|
61
|
+
subjectKey: a.string().required(),
|
|
62
|
+
readerId: a.string().required(),
|
|
63
|
+
body: a.string().required(),
|
|
64
|
+
parentId: a.string(),
|
|
65
|
+
ratingContext: a.json(),
|
|
66
|
+
state: a.string().required(),
|
|
67
|
+
signals: a.json(),
|
|
68
|
+
moderation: a.string().required(),
|
|
69
|
+
reportCount: a.integer(),
|
|
70
|
+
reviewedAt: a.datetime(),
|
|
71
|
+
editedAt: a.datetime(),
|
|
72
|
+
deletedAt: a.datetime(),
|
|
73
|
+
createdAt: a.datetime().required(),
|
|
74
|
+
})
|
|
75
|
+
.disableOperations(["subscriptions"])
|
|
76
|
+
.secondaryIndexes((index) => [index("moderation").sortKeys(["createdAt"]).name("commentsByModeration").queryField("listReaderCommentsByModerationAndCreatedAt")])
|
|
77
|
+
.authorization(staffOnly),
|
|
78
|
+
ReaderSubmission: a
|
|
79
|
+
.model({
|
|
80
|
+
id: a.id().required(),
|
|
81
|
+
canonicalUrl: a.string().required(),
|
|
82
|
+
domain: a.string().required(),
|
|
83
|
+
title: a.string().required(),
|
|
84
|
+
kind: a.string().required(),
|
|
85
|
+
note: a.string(),
|
|
86
|
+
readerId: a.string().required(),
|
|
87
|
+
state: a.string().required(),
|
|
88
|
+
similar: a.string().array(),
|
|
89
|
+
signals: a.json(),
|
|
90
|
+
extractionState: a.string().required(),
|
|
91
|
+
itemId: a.string(),
|
|
92
|
+
moderation: a.string().required(),
|
|
93
|
+
reportCount: a.integer(),
|
|
94
|
+
reviewedAt: a.datetime(),
|
|
95
|
+
createdAt: a.datetime().required(),
|
|
96
|
+
})
|
|
97
|
+
.disableOperations(["subscriptions"])
|
|
98
|
+
.secondaryIndexes((index) => [
|
|
99
|
+
index("domain").sortKeys(["createdAt"]).name("submissionsByDomain").queryField("listReaderSubmissionsByDomainAndCreatedAt"),
|
|
100
|
+
index("moderation").sortKeys(["createdAt"]).name("submissionsByModeration").queryField("listReaderSubmissionsByModerationAndCreatedAt"),
|
|
101
|
+
])
|
|
102
|
+
.authorization(staffOnly),
|
|
103
|
+
ReaderReport: a
|
|
104
|
+
.model({
|
|
105
|
+
id: a.id().required(),
|
|
106
|
+
targetType: a.string().required(),
|
|
107
|
+
target: a.string().required(),
|
|
108
|
+
reporterReaderId: a.string().required(),
|
|
109
|
+
reason: a.string().required(),
|
|
110
|
+
state: a.string().required(),
|
|
111
|
+
closedAt: a.datetime(),
|
|
112
|
+
createdAt: a.datetime().required(),
|
|
113
|
+
})
|
|
114
|
+
.disableOperations(["subscriptions"])
|
|
115
|
+
.secondaryIndexes((index) => [index("target").sortKeys(["createdAt"]).name("reportsByTarget").queryField("listReaderReportsByTargetAndCreatedAt")])
|
|
116
|
+
.authorization(staffOnly),
|
|
117
|
+
ModerationAction: a
|
|
118
|
+
.model({
|
|
119
|
+
id: a.id().required(),
|
|
120
|
+
by: a.string().required(),
|
|
121
|
+
actorSub: a.string().required(),
|
|
122
|
+
action: a.string().required(),
|
|
123
|
+
targetType: a.string().required(),
|
|
124
|
+
target: a.string().required(),
|
|
125
|
+
reason: a.string(),
|
|
126
|
+
fromState: a.string().required(),
|
|
127
|
+
toState: a.string().required(),
|
|
128
|
+
fromModeration: a.string(),
|
|
129
|
+
toModeration: a.string(),
|
|
130
|
+
undoOf: a.string(),
|
|
131
|
+
undoneBy: a.string(),
|
|
132
|
+
at: a.datetime().required(),
|
|
133
|
+
})
|
|
134
|
+
.disableOperations(["subscriptions"])
|
|
135
|
+
.secondaryIndexes((index) => [index("target").sortKeys(["at"]).name("actionsByTarget").queryField("listModerationActionsByTargetAndAt")])
|
|
136
|
+
.authorization(staffOnly),
|
|
137
|
+
Proposal: a
|
|
138
|
+
.model({
|
|
139
|
+
id: a.id().required(),
|
|
140
|
+
kind: a.string().required(),
|
|
141
|
+
title: a.string().required(),
|
|
142
|
+
summary: a.string(),
|
|
143
|
+
body: a.string().required(),
|
|
144
|
+
targets: a.json().required(),
|
|
145
|
+
evidence: a.json(),
|
|
146
|
+
proposer: a.string().required(),
|
|
147
|
+
state: a.string().required(),
|
|
148
|
+
history: a.json().required(),
|
|
149
|
+
communityResult: a.json(),
|
|
150
|
+
createdAt: a.datetime().required(),
|
|
151
|
+
})
|
|
152
|
+
.disableOperations(["subscriptions"])
|
|
153
|
+
.secondaryIndexes((index) => [index("state").sortKeys(["createdAt"]).name("proposalsByState").queryField("listProposalsByStateAndCreatedAt")])
|
|
154
|
+
.authorization(staffOnly),
|
|
155
|
+
ProposalReceipt: a.customType({
|
|
156
|
+
status: a.string().required(),
|
|
157
|
+
id: a.string(),
|
|
158
|
+
error: a.string(),
|
|
159
|
+
message: a.string(),
|
|
160
|
+
}),
|
|
161
|
+
fileProposal: a
|
|
162
|
+
.mutation()
|
|
163
|
+
.arguments({
|
|
164
|
+
kind: a.string().required(),
|
|
165
|
+
title: a.string().required(),
|
|
166
|
+
body: a.string().required(),
|
|
167
|
+
summary: a.string(),
|
|
168
|
+
targets: a.json(),
|
|
169
|
+
evidence: a.json(),
|
|
170
|
+
})
|
|
171
|
+
.returns(a.ref("ProposalReceipt"))
|
|
172
|
+
.authorization((allow) => [allow.group("editor"), allow.group("admin")])
|
|
173
|
+
.handler(a.handler.function(readerActions)),
|
|
174
|
+
transitionProposal: a
|
|
175
|
+
.mutation()
|
|
176
|
+
.arguments({
|
|
177
|
+
proposalId: a.string().required(),
|
|
178
|
+
state: a.string().required(),
|
|
179
|
+
reason: a.string(),
|
|
180
|
+
result: a.string(),
|
|
181
|
+
})
|
|
182
|
+
.returns(a.ref("ProposalReceipt"))
|
|
183
|
+
.authorization((allow) => [allow.group("editor"), allow.group("admin")])
|
|
184
|
+
.handler(a.handler.function(readerActions)),
|
|
185
|
+
ModerationReceipt: a.customType({
|
|
186
|
+
status: a.string().required(),
|
|
187
|
+
id: a.string(),
|
|
188
|
+
error: a.string(),
|
|
189
|
+
message: a.string(),
|
|
190
|
+
}),
|
|
191
|
+
moderateReader: a
|
|
192
|
+
.mutation()
|
|
193
|
+
.arguments({
|
|
194
|
+
action: a.string().required(),
|
|
195
|
+
targetType: a.string().required(),
|
|
196
|
+
target: a.string().required(),
|
|
197
|
+
reason: a.string(),
|
|
198
|
+
undoOf: a.string(),
|
|
199
|
+
})
|
|
200
|
+
.returns(a.ref("ModerationReceipt"))
|
|
201
|
+
.authorization((allow) => [allow.group("editor"), allow.group("admin")])
|
|
202
|
+
.handler(a.handler.function(readerActions)),
|
|
203
|
+
};
|
|
204
|
+
}
|