@anthusai/papyrus 5.135.0-next.6 → 5.135.0-next.7
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.
|
@@ -2,9 +2,9 @@ import { COMPUTE_ROLE_ARN_ENVIRONMENT_VARIABLE, environmentOrConfigured } from "
|
|
|
2
2
|
import { COMPUTE_ROLE_ARN, HOSTNAME, LOCAL_PART, NEWSLETTER_LIST_ID, NEWSLETTER_SITE_ID, SES_NAME, basePath, itemUrlStyle, matching, origin, record, resolveRule, resolveTheme, text, } from "../newsletter/config.js";
|
|
3
3
|
const KNOWN_KEYS = [
|
|
4
4
|
"name", "siteId", "siteOrigin", "basePath", "computeRoleArn", "sendingDomain", "fromAddress", "fromName", "theme", "lists",
|
|
5
|
-
"itemUrlStyle", "configurationSet", "consent", "confirmWindowHours",
|
|
5
|
+
"itemUrlStyle", "configurationSet", "consent", "confirmWindowHours", "legacyNewsletterLinks",
|
|
6
6
|
];
|
|
7
|
-
const LIST_KEYS = ["id", "name", "description", "rule", "approval", "family", "cadence", "sendAt", "timeZone"];
|
|
7
|
+
const LIST_KEYS = ["id", "name", "description", "rule", "approval", "kind", "family", "cadence", "sendAt", "timeZone"];
|
|
8
8
|
const CADENCES = ["each", "daily", "weekly"];
|
|
9
9
|
const WEEKDAYS = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"];
|
|
10
10
|
/** The helpers shared with the newsletter word their errors for it; this plugin says its own name. */
|
|
@@ -27,6 +27,11 @@ function resolveList(raw, index) {
|
|
|
27
27
|
const approval = list.approval === undefined ? "admin" : list.approval;
|
|
28
28
|
if (approval !== "admin" && approval !== "none")
|
|
29
29
|
fail(`${label}.approval must be "admin" or "none"`);
|
|
30
|
+
const kind = list.kind === undefined ? undefined : list.kind;
|
|
31
|
+
if (kind !== undefined && kind !== "story.published" && kind !== "roundup")
|
|
32
|
+
fail(`${label}.kind must be "story.published" or "roundup"`);
|
|
33
|
+
if (kind === "roundup" && list.rule !== undefined)
|
|
34
|
+
fail(`${label} is a roundup list, which is never sent each story, so it names no rule`);
|
|
30
35
|
const family = list.family === undefined ? undefined : matching(list.family, `${label}.family`, NEWSLETTER_LIST_ID, "lowercase letters, digits and hyphens, starting with a letter");
|
|
31
36
|
const cadence = list.cadence === undefined ? undefined : list.cadence;
|
|
32
37
|
if (cadence !== undefined && !CADENCES.includes(cadence))
|
|
@@ -50,6 +55,7 @@ function resolveList(raw, index) {
|
|
|
50
55
|
description: text(list.description, `${label}.description`, 300, { optional: true, fallback: "" }),
|
|
51
56
|
rule: resolveRule(list.rule, `${label}.rule`),
|
|
52
57
|
approval,
|
|
58
|
+
...(kind === undefined ? {} : { kind: kind }),
|
|
53
59
|
...(family === undefined ? {} : { family }),
|
|
54
60
|
...(cadence === undefined ? {} : { cadence: cadence }),
|
|
55
61
|
...(periodic ? { sendAt: list.sendAt, timeZone: list.timeZone } : {}),
|
|
@@ -63,6 +69,13 @@ function confirmWindowHours(raw) {
|
|
|
63
69
|
fail("confirmWindowHours must be a whole number of hours, at least 1");
|
|
64
70
|
return raw;
|
|
65
71
|
}
|
|
72
|
+
function legacyNewsletterLinks(raw) {
|
|
73
|
+
if (raw === undefined)
|
|
74
|
+
return false;
|
|
75
|
+
if (typeof raw !== "boolean")
|
|
76
|
+
fail("legacyNewsletterLinks must be true or false");
|
|
77
|
+
return raw;
|
|
78
|
+
}
|
|
66
79
|
export function resolveNotificationsConfig(request) {
|
|
67
80
|
return inThisPlugin(() => {
|
|
68
81
|
const raw = record(typeof request === "string" ? { name: request } : request, "settings", KNOWN_KEYS);
|
|
@@ -97,6 +110,7 @@ export function resolveNotificationsConfig(request) {
|
|
|
97
110
|
confirmWindowHours: confirmWindowHours(raw.confirmWindowHours),
|
|
98
111
|
itemUrlStyle: itemUrlStyle(raw.itemUrlStyle),
|
|
99
112
|
configurationSet: matching(raw.configurationSet, "configurationSet", SES_NAME, "an SES configuration set name", `papyrus-${siteId}`),
|
|
113
|
+
legacyNewsletterLinks: legacyNewsletterLinks(raw.legacyNewsletterLinks),
|
|
100
114
|
};
|
|
101
115
|
});
|
|
102
116
|
}
|
|
@@ -29,6 +29,11 @@ export type NotificationsList = {
|
|
|
29
29
|
description: string;
|
|
30
30
|
rule: NewsletterRule;
|
|
31
31
|
approval: "admin" | "none";
|
|
32
|
+
/**
|
|
33
|
+
* What the list is for. `story.published` (the default) sends each matching story. `roundup` is a periodic issue's list: it is never
|
|
34
|
+
* sent each story, so it carries no rule. A newsletter roundup list keeps its id and becomes a `roundup` list when its subscribers move (PPY-6b2d35).
|
|
35
|
+
*/
|
|
36
|
+
kind?: "story.published" | "roundup";
|
|
32
37
|
/** 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
38
|
family?: string;
|
|
34
39
|
/** `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. */
|
|
@@ -59,13 +64,18 @@ export type NotificationsConfig = {
|
|
|
59
64
|
itemUrlStyle: ItemUrlStyle;
|
|
60
65
|
/** `papyrus-<siteId>` unless overridden: the sending stack's configuration set, shared with the newsletter. */
|
|
61
66
|
configurationSet: string;
|
|
67
|
+
/**
|
|
68
|
+
* Honour the old newsletter's manage and unsubscribe links (they were mailed with the newsletter's tokens) until the date the migration
|
|
69
|
+
* gave them. Dated: set only while that period runs, and removed with `src/papyrus_content/notifications/legacy_links.py` (see that file).
|
|
70
|
+
*/
|
|
71
|
+
legacyNewsletterLinks: boolean;
|
|
62
72
|
};
|
|
63
73
|
|
|
64
74
|
const KNOWN_KEYS = [
|
|
65
75
|
"name", "siteId", "siteOrigin", "basePath", "computeRoleArn", "sendingDomain", "fromAddress", "fromName", "theme", "lists",
|
|
66
|
-
"itemUrlStyle", "configurationSet", "consent", "confirmWindowHours",
|
|
76
|
+
"itemUrlStyle", "configurationSet", "consent", "confirmWindowHours", "legacyNewsletterLinks",
|
|
67
77
|
];
|
|
68
|
-
const LIST_KEYS = ["id", "name", "description", "rule", "approval", "family", "cadence", "sendAt", "timeZone"];
|
|
78
|
+
const LIST_KEYS = ["id", "name", "description", "rule", "approval", "kind", "family", "cadence", "sendAt", "timeZone"];
|
|
69
79
|
const CADENCES = ["each", "daily", "weekly"];
|
|
70
80
|
const WEEKDAYS = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"];
|
|
71
81
|
|
|
@@ -88,6 +98,9 @@ function resolveList(raw: unknown, index: number): NotificationsList {
|
|
|
88
98
|
const list = record(raw, label, LIST_KEYS);
|
|
89
99
|
const approval = list.approval === undefined ? "admin" : list.approval;
|
|
90
100
|
if (approval !== "admin" && approval !== "none") fail(`${label}.approval must be "admin" or "none"`);
|
|
101
|
+
const kind = list.kind === undefined ? undefined : list.kind;
|
|
102
|
+
if (kind !== undefined && kind !== "story.published" && kind !== "roundup") fail(`${label}.kind must be "story.published" or "roundup"`);
|
|
103
|
+
if (kind === "roundup" && list.rule !== undefined) fail(`${label} is a roundup list, which is never sent each story, so it names no rule`);
|
|
91
104
|
const family = list.family === undefined ? undefined : matching(list.family, `${label}.family`, NEWSLETTER_LIST_ID, "lowercase letters, digits and hyphens, starting with a letter");
|
|
92
105
|
const cadence = list.cadence === undefined ? undefined : list.cadence;
|
|
93
106
|
if (cadence !== undefined && !CADENCES.includes(cadence as string)) fail(`${label}.cadence must be one of: ${CADENCES.join(", ")}`);
|
|
@@ -107,6 +120,7 @@ function resolveList(raw: unknown, index: number): NotificationsList {
|
|
|
107
120
|
description: text(list.description, `${label}.description`, 300, { optional: true, fallback: "" }),
|
|
108
121
|
rule: resolveRule(list.rule, `${label}.rule`),
|
|
109
122
|
approval,
|
|
123
|
+
...(kind === undefined ? {} : { kind: kind as NotificationsList["kind"] }),
|
|
110
124
|
...(family === undefined ? {} : { family }),
|
|
111
125
|
...(cadence === undefined ? {} : { cadence: cadence as NotificationsList["cadence"] }),
|
|
112
126
|
...(periodic ? { sendAt: list.sendAt as NotificationsList["sendAt"], timeZone: list.timeZone as string } : {}),
|
|
@@ -120,6 +134,12 @@ function confirmWindowHours(raw: unknown): number {
|
|
|
120
134
|
return raw;
|
|
121
135
|
}
|
|
122
136
|
|
|
137
|
+
function legacyNewsletterLinks(raw: unknown): boolean {
|
|
138
|
+
if (raw === undefined) return false;
|
|
139
|
+
if (typeof raw !== "boolean") fail("legacyNewsletterLinks must be true or false");
|
|
140
|
+
return raw;
|
|
141
|
+
}
|
|
142
|
+
|
|
123
143
|
export function resolveNotificationsConfig(request: PluginRequest): NotificationsConfig {
|
|
124
144
|
return inThisPlugin(() => {
|
|
125
145
|
const raw = record(typeof request === "string" ? { name: request } : request, "settings", KNOWN_KEYS);
|
|
@@ -152,6 +172,7 @@ export function resolveNotificationsConfig(request: PluginRequest): Notification
|
|
|
152
172
|
confirmWindowHours: confirmWindowHours(raw.confirmWindowHours),
|
|
153
173
|
itemUrlStyle: itemUrlStyle(raw.itemUrlStyle),
|
|
154
174
|
configurationSet: matching(raw.configurationSet, "configurationSet", SES_NAME, "an SES configuration set name", `papyrus-${siteId}`),
|
|
175
|
+
legacyNewsletterLinks: legacyNewsletterLinks(raw.legacyNewsletterLinks),
|
|
155
176
|
};
|
|
156
177
|
});
|
|
157
178
|
}
|
|
@@ -58,6 +58,8 @@ export const notificationsTableName = (siteId) => `papyrus-notifications-${siteI
|
|
|
58
58
|
export const notificationsOperatorsParameterName = (siteId) => `/papyrus/${siteId}/notifications/operators`;
|
|
59
59
|
/** Generated once by the stack; the addresses' recipient keys are derived from it. */
|
|
60
60
|
export const notificationsKeyParameterName = (siteId) => `/papyrus/${siteId}/notifications/recipient-key`;
|
|
61
|
+
/** Where the newsletter plugin generated its key (it is retained when that plugin is removed): read only while old newsletter links are honoured. */
|
|
62
|
+
export const legacyNewsletterKeyParameterName = (siteId) => `/papyrus/${siteId}/newsletter-key`;
|
|
61
63
|
export const notificationsAlarmNames = (siteId) => ({
|
|
62
64
|
emailDeadLetters: `papyrus-notifications-${siteId}-email-dlq`,
|
|
63
65
|
routerDeadLetters: `papyrus-notifications-${siteId}-router-dlq`,
|
|
@@ -87,11 +89,12 @@ export function notificationsEnvironment(config, names) {
|
|
|
87
89
|
FROM_NAME: config.fromName,
|
|
88
90
|
CONFIGURATION_SET: config.configurationSet,
|
|
89
91
|
ITEM_URL_STYLE: config.itemUrlStyle,
|
|
90
|
-
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 }))),
|
|
92
|
+
LISTS_JSON: JSON.stringify(config.lists.map((list) => ({ id: list.id, name: list.name, description: list.description, rule: list.rule, approval: list.approval, kind: list.kind, family: list.family, cadence: list.cadence, sendAt: list.sendAt, timeZone: list.timeZone }))),
|
|
91
93
|
THEME_JSON: JSON.stringify(config.theme),
|
|
92
94
|
CONSENT: config.consent,
|
|
93
95
|
CONFIRM_WINDOW_SECONDS: String(config.confirmWindowHours * 3600),
|
|
94
96
|
METRIC_NAMESPACE: `Caducus/papyrus-${config.siteId}`,
|
|
97
|
+
...(config.legacyNewsletterLinks ? { LEGACY_NEWSLETTER_KEY_PARAMETER: legacyNewsletterKeyParameterName(config.siteId) } : {}),
|
|
95
98
|
};
|
|
96
99
|
}
|
|
97
100
|
export const notificationsPlugin = {
|
|
@@ -247,6 +250,10 @@ export const notificationsPlugin = {
|
|
|
247
250
|
`arn:${stack.partition}:ssm:${stack.region}:${stack.account}:parameter${operatorsParameter}`,
|
|
248
251
|
keyParameter.parameterArn,
|
|
249
252
|
];
|
|
253
|
+
// Old newsletter links (dated; legacy_links.py): every function builds the same runtime, so each may read the old key.
|
|
254
|
+
if (config.legacyNewsletterLinks) {
|
|
255
|
+
parameterArns.push(`arn:${stack.partition}:ssm:${stack.region}:${stack.account}:parameter${legacyNewsletterKeyParameterName(config.siteId)}`);
|
|
256
|
+
}
|
|
250
257
|
// Every function builds the same runtime (the audience needs the recipient key), and the SES events suppress readers.
|
|
251
258
|
for (const fn of [router, email, flush, sesEvents]) {
|
|
252
259
|
table.grantReadWriteData(fn); // includes the table key's encrypt and decrypt
|
|
@@ -66,6 +66,8 @@ export const notificationsTableName = (siteId: string) => `papyrus-notifications
|
|
|
66
66
|
export const notificationsOperatorsParameterName = (siteId: string) => `/papyrus/${siteId}/notifications/operators`;
|
|
67
67
|
/** Generated once by the stack; the addresses' recipient keys are derived from it. */
|
|
68
68
|
export const notificationsKeyParameterName = (siteId: string) => `/papyrus/${siteId}/notifications/recipient-key`;
|
|
69
|
+
/** Where the newsletter plugin generated its key (it is retained when that plugin is removed): read only while old newsletter links are honoured. */
|
|
70
|
+
export const legacyNewsletterKeyParameterName = (siteId: string) => `/papyrus/${siteId}/newsletter-key`;
|
|
69
71
|
export const notificationsAlarmNames = (siteId: string) => ({
|
|
70
72
|
emailDeadLetters: `papyrus-notifications-${siteId}-email-dlq`,
|
|
71
73
|
routerDeadLetters: `papyrus-notifications-${siteId}-router-dlq`,
|
|
@@ -98,11 +100,12 @@ export function notificationsEnvironment(config: NotificationsConfig, names: { t
|
|
|
98
100
|
FROM_NAME: config.fromName,
|
|
99
101
|
CONFIGURATION_SET: config.configurationSet,
|
|
100
102
|
ITEM_URL_STYLE: config.itemUrlStyle,
|
|
101
|
-
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 }))),
|
|
103
|
+
LISTS_JSON: JSON.stringify(config.lists.map((list) => ({ id: list.id, name: list.name, description: list.description, rule: list.rule, approval: list.approval, kind: list.kind, family: list.family, cadence: list.cadence, sendAt: list.sendAt, timeZone: list.timeZone }))),
|
|
102
104
|
THEME_JSON: JSON.stringify(config.theme),
|
|
103
105
|
CONSENT: config.consent,
|
|
104
106
|
CONFIRM_WINDOW_SECONDS: String(config.confirmWindowHours * 3600),
|
|
105
107
|
METRIC_NAMESPACE: `Caducus/papyrus-${config.siteId}`,
|
|
108
|
+
...(config.legacyNewsletterLinks ? { LEGACY_NEWSLETTER_KEY_PARAMETER: legacyNewsletterKeyParameterName(config.siteId) } : {}),
|
|
106
109
|
};
|
|
107
110
|
}
|
|
108
111
|
|
|
@@ -268,6 +271,10 @@ export const notificationsPlugin: PapyrusPlugin<NotificationsConfig, Record<stri
|
|
|
268
271
|
`arn:${stack.partition}:ssm:${stack.region}:${stack.account}:parameter${operatorsParameter}`,
|
|
269
272
|
keyParameter.parameterArn,
|
|
270
273
|
];
|
|
274
|
+
// Old newsletter links (dated; legacy_links.py): every function builds the same runtime, so each may read the old key.
|
|
275
|
+
if (config.legacyNewsletterLinks) {
|
|
276
|
+
parameterArns.push(`arn:${stack.partition}:ssm:${stack.region}:${stack.account}:parameter${legacyNewsletterKeyParameterName(config.siteId)}`);
|
|
277
|
+
}
|
|
271
278
|
// Every function builds the same runtime (the audience needs the recipient key), and the SES events suppress readers.
|
|
272
279
|
for (const fn of [router, email, flush, sesEvents]) {
|
|
273
280
|
table.grantReadWriteData(fn); // includes the table key's encrypt and decrypt
|
package/package.json
CHANGED
package/routes.manifest.json
CHANGED