@anthusai/papyrus 5.131.0-next.3 → 5.132.0-next.1
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/agents/schedule-group.js +26 -0
- package/amplify/agents/schedule-group.ts +33 -0
- package/amplify/plugins/notifications/config.js +23 -1
- package/amplify/plugins/notifications/config.ts +26 -1
- package/amplify/plugins/notifications/function/requirements.txt +1 -1
- package/amplify/plugins/notifications/papyrus.plugin.js +2 -2
- package/amplify/plugins/notifications/papyrus.plugin.ts +2 -2
- package/package.json +1 -1
- package/routes.manifest.json +1 -1
|
@@ -31,6 +31,32 @@ export function scheduleNames(brandId) {
|
|
|
31
31
|
role: assertLiteralResourceName("Scheduler role name", `${SCHEDULE_GROUP_NAME_PREFIX}${siteId}${SCHEDULER_ROLE_NAME_SUFFIX}`),
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* The follow-up timers' entries (slice C2, src/papyrus_content/follow_up_timers.py) are named `follow-up-` and a digest of the record. The reconciler's own
|
|
36
|
+
* entries are `agent-...`, so the two never meet.
|
|
37
|
+
*/
|
|
38
|
+
export const FOLLOW_UP_ENTRY_PREFIX = "follow-up-";
|
|
39
|
+
/**
|
|
40
|
+
* Lets a site function set and clear follow-up timers: it may create, update and delete entries named `follow-up-*` in this site's schedule group, and hand the
|
|
41
|
+
* scheduler role to the scheduler service, and nothing else. It may not touch the reconciler's `agent-*` entries, another site's group, the default group
|
|
42
|
+
* (scheduled publishing's), or read an entry. The group and the role are named by the site's brand id, so no reference to the `agents` stack is made and the
|
|
43
|
+
* function's stack does not depend on it. It adds no resource: two statements on the function's own role.
|
|
44
|
+
*/
|
|
45
|
+
export function allowFollowUpTimers(lambda, brandId) {
|
|
46
|
+
const stack = Stack.of(lambda);
|
|
47
|
+
const names = scheduleNames(brandId);
|
|
48
|
+
lambda.addToRolePolicy(new PolicyStatement({
|
|
49
|
+
effect: Effect.ALLOW,
|
|
50
|
+
actions: ["scheduler:CreateSchedule", "scheduler:UpdateSchedule", "scheduler:DeleteSchedule"],
|
|
51
|
+
resources: [`arn:${stack.partition}:scheduler:${stack.region}:${stack.account}:schedule/${names.group}/${FOLLOW_UP_ENTRY_PREFIX}*`],
|
|
52
|
+
}));
|
|
53
|
+
lambda.addToRolePolicy(new PolicyStatement({
|
|
54
|
+
effect: Effect.ALLOW,
|
|
55
|
+
actions: ["iam:PassRole"],
|
|
56
|
+
resources: [`arn:${stack.partition}:iam::${stack.account}:role/${names.role}`],
|
|
57
|
+
conditions: { StringEquals: { "iam:PassedToService": "scheduler.amazonaws.com" } },
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
34
60
|
/** The group, the role the scheduler assumes and the alarm on a tick that could not be delivered. */
|
|
35
61
|
export function scheduleGroupPiece(brandId) {
|
|
36
62
|
const names = scheduleNames(brandId);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Duration, Stack } from "aws-cdk-lib";
|
|
2
2
|
import { Alarm, ComparisonOperator, Metric, TreatMissingData } from "aws-cdk-lib/aws-cloudwatch";
|
|
3
3
|
import { Effect, PolicyDocument, PolicyStatement, Role, ServicePrincipal } from "aws-cdk-lib/aws-iam";
|
|
4
|
+
import type { Function as LambdaFunction } from "aws-cdk-lib/aws-lambda";
|
|
4
5
|
import { CfnScheduleGroup } from "aws-cdk-lib/aws-scheduler";
|
|
5
6
|
import type { Construct } from "constructs";
|
|
6
7
|
import { assertLiteralResourceName, sanitizeAwsName } from "../site-backend-names";
|
|
@@ -38,6 +39,38 @@ export function scheduleNames(brandId: string): ScheduleNames {
|
|
|
38
39
|
};
|
|
39
40
|
}
|
|
40
41
|
|
|
42
|
+
/**
|
|
43
|
+
* The follow-up timers' entries (slice C2, src/papyrus_content/follow_up_timers.py) are named `follow-up-` and a digest of the record. The reconciler's own
|
|
44
|
+
* entries are `agent-...`, so the two never meet.
|
|
45
|
+
*/
|
|
46
|
+
export const FOLLOW_UP_ENTRY_PREFIX = "follow-up-";
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Lets a site function set and clear follow-up timers: it may create, update and delete entries named `follow-up-*` in this site's schedule group, and hand the
|
|
50
|
+
* scheduler role to the scheduler service, and nothing else. It may not touch the reconciler's `agent-*` entries, another site's group, the default group
|
|
51
|
+
* (scheduled publishing's), or read an entry. The group and the role are named by the site's brand id, so no reference to the `agents` stack is made and the
|
|
52
|
+
* function's stack does not depend on it. It adds no resource: two statements on the function's own role.
|
|
53
|
+
*/
|
|
54
|
+
export function allowFollowUpTimers(lambda: LambdaFunction, brandId: string): void {
|
|
55
|
+
const stack = Stack.of(lambda);
|
|
56
|
+
const names = scheduleNames(brandId);
|
|
57
|
+
lambda.addToRolePolicy(
|
|
58
|
+
new PolicyStatement({
|
|
59
|
+
effect: Effect.ALLOW,
|
|
60
|
+
actions: ["scheduler:CreateSchedule", "scheduler:UpdateSchedule", "scheduler:DeleteSchedule"],
|
|
61
|
+
resources: [`arn:${stack.partition}:scheduler:${stack.region}:${stack.account}:schedule/${names.group}/${FOLLOW_UP_ENTRY_PREFIX}*`],
|
|
62
|
+
}),
|
|
63
|
+
);
|
|
64
|
+
lambda.addToRolePolicy(
|
|
65
|
+
new PolicyStatement({
|
|
66
|
+
effect: Effect.ALLOW,
|
|
67
|
+
actions: ["iam:PassRole"],
|
|
68
|
+
resources: [`arn:${stack.partition}:iam::${stack.account}:role/${names.role}`],
|
|
69
|
+
conditions: { StringEquals: { "iam:PassedToService": "scheduler.amazonaws.com" } },
|
|
70
|
+
}),
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
41
74
|
/** The group, the role the scheduler assumes and the alarm on a tick that could not be delivered. */
|
|
42
75
|
export function scheduleGroupPiece(brandId: string): AgentPiece {
|
|
43
76
|
const names = scheduleNames(brandId);
|
|
@@ -4,7 +4,9 @@ const KNOWN_KEYS = [
|
|
|
4
4
|
"name", "siteId", "siteOrigin", "basePath", "computeRoleArn", "sendingDomain", "fromAddress", "fromName", "theme", "lists",
|
|
5
5
|
"itemUrlStyle", "configurationSet", "consent", "confirmWindowHours",
|
|
6
6
|
];
|
|
7
|
-
const LIST_KEYS = ["id", "name", "description", "rule", "approval"];
|
|
7
|
+
const LIST_KEYS = ["id", "name", "description", "rule", "approval", "family", "cadence", "sendAt", "timeZone"];
|
|
8
|
+
const CADENCES = ["each", "daily", "weekly"];
|
|
9
|
+
const WEEKDAYS = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"];
|
|
8
10
|
/** The helpers shared with the newsletter word their errors for it; this plugin says its own name. */
|
|
9
11
|
function inThisPlugin(run) {
|
|
10
12
|
try {
|
|
@@ -25,12 +27,32 @@ function resolveList(raw, index) {
|
|
|
25
27
|
const approval = list.approval === undefined ? "admin" : list.approval;
|
|
26
28
|
if (approval !== "admin" && approval !== "none")
|
|
27
29
|
fail(`${label}.approval must be "admin" or "none"`);
|
|
30
|
+
const family = list.family === undefined ? undefined : matching(list.family, `${label}.family`, NEWSLETTER_LIST_ID, "lowercase letters, digits and hyphens, starting with a letter");
|
|
31
|
+
const cadence = list.cadence === undefined ? undefined : list.cadence;
|
|
32
|
+
if (cadence !== undefined && !CADENCES.includes(cadence))
|
|
33
|
+
fail(`${label}.cadence must be one of: ${CADENCES.join(", ")}`);
|
|
34
|
+
const periodic = cadence === "daily" || cadence === "weekly";
|
|
35
|
+
if (periodic) {
|
|
36
|
+
const sendAt = record(list.sendAt, `${label}.sendAt`, ["time", "day"]);
|
|
37
|
+
matching(sendAt.time, `${label}.sendAt.time`, /^([01]\d|2[0-3]):[0-5]\d$/, "a local time of day such as 06:00");
|
|
38
|
+
if (cadence === "weekly" && !WEEKDAYS.includes(sendAt.day))
|
|
39
|
+
fail(`${label}.sendAt.day must be a weekday name: ${WEEKDAYS.join(", ")}`);
|
|
40
|
+
if (cadence === "daily" && sendAt.day !== undefined)
|
|
41
|
+
fail(`${label}.sendAt.day is for a weekly list`);
|
|
42
|
+
text(list.timeZone, `${label}.timeZone`, 64);
|
|
43
|
+
}
|
|
44
|
+
else if (list.sendAt !== undefined || list.timeZone !== undefined) {
|
|
45
|
+
fail(`${label} is not a periodic list, so it names no sendAt or timeZone`);
|
|
46
|
+
}
|
|
28
47
|
return {
|
|
29
48
|
id: matching(list.id, `${label}.id`, NEWSLETTER_LIST_ID, "lowercase letters, digits and hyphens, starting with a letter (at most 40 characters)"),
|
|
30
49
|
name: text(list.name, `${label}.name`, 80),
|
|
31
50
|
description: text(list.description, `${label}.description`, 300, { optional: true, fallback: "" }),
|
|
32
51
|
rule: resolveRule(list.rule, `${label}.rule`),
|
|
33
52
|
approval,
|
|
53
|
+
...(family === undefined ? {} : { family }),
|
|
54
|
+
...(cadence === undefined ? {} : { cadence: cadence }),
|
|
55
|
+
...(periodic ? { sendAt: list.sendAt, timeZone: list.timeZone } : {}),
|
|
34
56
|
};
|
|
35
57
|
}
|
|
36
58
|
/** A whole, positive number of hours. 72 by default: how long the newsletter has always told readers a link works. */
|
|
@@ -29,6 +29,13 @@ export type NotificationsList = {
|
|
|
29
29
|
description: string;
|
|
30
30
|
rule: NewsletterRule;
|
|
31
31
|
approval: "admin" | "none";
|
|
32
|
+
/** The cadence family: lists that carry the same items at different cadences share one, and a reader holds one list of a family. None: its own family. */
|
|
33
|
+
family?: string;
|
|
34
|
+
/** `each`, `daily` or `weekly`, as in the site's `lists` document. A reader's switch between lists of a family waits for the next period start of its periodic list. */
|
|
35
|
+
cadence?: "each" | "daily" | "weekly";
|
|
36
|
+
/** A periodic list's local send time (`time`, and `day` for a weekly list) and IANA time zone. */
|
|
37
|
+
sendAt?: { time: string; day?: string };
|
|
38
|
+
timeZone?: string;
|
|
32
39
|
};
|
|
33
40
|
|
|
34
41
|
export type NotificationsConfig = {
|
|
@@ -58,7 +65,9 @@ const KNOWN_KEYS = [
|
|
|
58
65
|
"name", "siteId", "siteOrigin", "basePath", "computeRoleArn", "sendingDomain", "fromAddress", "fromName", "theme", "lists",
|
|
59
66
|
"itemUrlStyle", "configurationSet", "consent", "confirmWindowHours",
|
|
60
67
|
];
|
|
61
|
-
const LIST_KEYS = ["id", "name", "description", "rule", "approval"];
|
|
68
|
+
const LIST_KEYS = ["id", "name", "description", "rule", "approval", "family", "cadence", "sendAt", "timeZone"];
|
|
69
|
+
const CADENCES = ["each", "daily", "weekly"];
|
|
70
|
+
const WEEKDAYS = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"];
|
|
62
71
|
|
|
63
72
|
/** The helpers shared with the newsletter word their errors for it; this plugin says its own name. */
|
|
64
73
|
function inThisPlugin<T>(run: () => T): T {
|
|
@@ -79,12 +88,28 @@ function resolveList(raw: unknown, index: number): NotificationsList {
|
|
|
79
88
|
const list = record(raw, label, LIST_KEYS);
|
|
80
89
|
const approval = list.approval === undefined ? "admin" : list.approval;
|
|
81
90
|
if (approval !== "admin" && approval !== "none") fail(`${label}.approval must be "admin" or "none"`);
|
|
91
|
+
const family = list.family === undefined ? undefined : matching(list.family, `${label}.family`, NEWSLETTER_LIST_ID, "lowercase letters, digits and hyphens, starting with a letter");
|
|
92
|
+
const cadence = list.cadence === undefined ? undefined : list.cadence;
|
|
93
|
+
if (cadence !== undefined && !CADENCES.includes(cadence as string)) fail(`${label}.cadence must be one of: ${CADENCES.join(", ")}`);
|
|
94
|
+
const periodic = cadence === "daily" || cadence === "weekly";
|
|
95
|
+
if (periodic) {
|
|
96
|
+
const sendAt = record(list.sendAt, `${label}.sendAt`, ["time", "day"]);
|
|
97
|
+
matching(sendAt.time, `${label}.sendAt.time`, /^([01]\d|2[0-3]):[0-5]\d$/, "a local time of day such as 06:00");
|
|
98
|
+
if (cadence === "weekly" && !WEEKDAYS.includes(sendAt.day as string)) fail(`${label}.sendAt.day must be a weekday name: ${WEEKDAYS.join(", ")}`);
|
|
99
|
+
if (cadence === "daily" && sendAt.day !== undefined) fail(`${label}.sendAt.day is for a weekly list`);
|
|
100
|
+
text(list.timeZone, `${label}.timeZone`, 64);
|
|
101
|
+
} else if (list.sendAt !== undefined || list.timeZone !== undefined) {
|
|
102
|
+
fail(`${label} is not a periodic list, so it names no sendAt or timeZone`);
|
|
103
|
+
}
|
|
82
104
|
return {
|
|
83
105
|
id: matching(list.id, `${label}.id`, NEWSLETTER_LIST_ID, "lowercase letters, digits and hyphens, starting with a letter (at most 40 characters)"),
|
|
84
106
|
name: text(list.name, `${label}.name`, 80),
|
|
85
107
|
description: text(list.description, `${label}.description`, 300, { optional: true, fallback: "" }),
|
|
86
108
|
rule: resolveRule(list.rule, `${label}.rule`),
|
|
87
109
|
approval,
|
|
110
|
+
...(family === undefined ? {} : { family }),
|
|
111
|
+
...(cadence === undefined ? {} : { cadence: cadence as NotificationsList["cadence"] }),
|
|
112
|
+
...(periodic ? { sendAt: list.sendAt as NotificationsList["sendAt"], timeZone: list.timeZone as string } : {}),
|
|
88
113
|
};
|
|
89
114
|
}
|
|
90
115
|
|
|
@@ -29,7 +29,7 @@ export const HANDLERS = {
|
|
|
29
29
|
pause: "papyrus_content.notifications.handler.pause",
|
|
30
30
|
};
|
|
31
31
|
/** Caducus is pinned exactly, beside `papyrus_content`: a package change is a Caducus release, then a Papyrus release. */
|
|
32
|
-
export const CADUCUS_REQUIREMENT = "caducus[notify]==0.
|
|
32
|
+
export const CADUCUS_REQUIREMENT = "caducus[notify]==0.4.0";
|
|
33
33
|
export const NOTIFICATIONS_REQUIREMENTS = [CADUCUS_REQUIREMENT, "PyYAML>=6.0.2,<7", "citeproc-py>=0.8.2,<1", "anthus-markus==0.7.0", "Pillow>=11.3,<12"];
|
|
34
34
|
/** Relative to `amplify/functions/`, which is where the shared bundler looks for a function's `handler.py`. */
|
|
35
35
|
const FUNCTION_DIRECTORY = "../plugins/notifications/function";
|
|
@@ -89,7 +89,7 @@ export function notificationsEnvironment(config, names) {
|
|
|
89
89
|
FROM_NAME: config.fromName,
|
|
90
90
|
CONFIGURATION_SET: config.configurationSet,
|
|
91
91
|
ITEM_URL_STYLE: config.itemUrlStyle,
|
|
92
|
-
LISTS_JSON: JSON.stringify(config.lists.map((list) => ({ id: list.id, name: list.name, description: list.description, rule: list.rule, approval: list.approval }))),
|
|
92
|
+
LISTS_JSON: JSON.stringify(config.lists.map((list) => ({ id: list.id, name: list.name, description: list.description, rule: list.rule, approval: list.approval, family: list.family, cadence: list.cadence, sendAt: list.sendAt, timeZone: list.timeZone }))),
|
|
93
93
|
THEME_JSON: JSON.stringify(config.theme),
|
|
94
94
|
CONSENT: config.consent,
|
|
95
95
|
CONFIRM_WINDOW_SECONDS: String(config.confirmWindowHours * 3600),
|
|
@@ -33,7 +33,7 @@ export const HANDLERS = {
|
|
|
33
33
|
pause: "papyrus_content.notifications.handler.pause",
|
|
34
34
|
} as const;
|
|
35
35
|
/** Caducus is pinned exactly, beside `papyrus_content`: a package change is a Caducus release, then a Papyrus release. */
|
|
36
|
-
export const CADUCUS_REQUIREMENT = "caducus[notify]==0.
|
|
36
|
+
export const CADUCUS_REQUIREMENT = "caducus[notify]==0.4.0";
|
|
37
37
|
export const NOTIFICATIONS_REQUIREMENTS = [CADUCUS_REQUIREMENT, "PyYAML>=6.0.2,<7", "citeproc-py>=0.8.2,<1", "anthus-markus==0.7.0", "Pillow>=11.3,<12"];
|
|
38
38
|
/** Relative to `amplify/functions/`, which is where the shared bundler looks for a function's `handler.py`. */
|
|
39
39
|
const FUNCTION_DIRECTORY = "../plugins/notifications/function";
|
|
@@ -100,7 +100,7 @@ export function notificationsEnvironment(config: NotificationsConfig, names: { t
|
|
|
100
100
|
FROM_NAME: config.fromName,
|
|
101
101
|
CONFIGURATION_SET: config.configurationSet,
|
|
102
102
|
ITEM_URL_STYLE: config.itemUrlStyle,
|
|
103
|
-
LISTS_JSON: JSON.stringify(config.lists.map((list) => ({ id: list.id, name: list.name, description: list.description, rule: list.rule, approval: list.approval }))),
|
|
103
|
+
LISTS_JSON: JSON.stringify(config.lists.map((list) => ({ id: list.id, name: list.name, description: list.description, rule: list.rule, approval: list.approval, family: list.family, cadence: list.cadence, sendAt: list.sendAt, timeZone: list.timeZone }))),
|
|
104
104
|
THEME_JSON: JSON.stringify(config.theme),
|
|
105
105
|
CONSENT: config.consent,
|
|
106
106
|
CONFIRM_WINDOW_SECONDS: String(config.confirmWindowHours * 3600),
|
package/package.json
CHANGED
package/routes.manifest.json
CHANGED