@anthusai/papyrus 5.135.0-next.7 → 5.135.0

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.
@@ -213,7 +213,7 @@ export async function handleNotificationsUnsubscribe(request: NextRequest, optio
213
213
  }
214
214
  }
215
215
 
216
- const PREFERENCE_MESSAGES = new Set(["saved", "unsubscribed"]);
216
+ const PREFERENCE_MESSAGES = new Set(["saved", "unsubscribed", "check_email"]);
217
217
 
218
218
  /** /api/notifications/preferences. POST (same-origin form) saves, unsubscribes from everything, or deletes after a confirm step; GET redirects. */
219
219
  export async function handleNotificationsPreferences(request: NextRequest, options: NotificationsApiOptions = {}): Promise<NextResponse> {
@@ -233,9 +233,21 @@ export async function handleNotificationsPreferences(request: NextRequest, optio
233
233
  if (!token || !plugin.functionName) return to.go("expired");
234
234
  const action = form.get("action");
235
235
  if (action === "delete" && form.get("confirm") !== "1") return to.go("preferences", { token, step: "delete" });
236
+ // Joining a family the reader does not hold needs their consent: the page shows the site's wording and posts it back with the form, the page and the network as
237
+ // evidence, as the subscribe form does. The function uses them only for a new family; a cadence change inside a family the reader holds ignores them.
236
238
  const operation =
237
239
  action === "save"
238
- ? { action: "update_preferences", token, lists: form.getAll("l").slice(0, MAXIMUM_LISTS).filter((id) => LIST_ID.test(id)) }
240
+ ? {
241
+ action: "update_preferences",
242
+ token,
243
+ lists: form.getAll("l").slice(0, MAXIMUM_LISTS).filter((id) => LIST_ID.test(id)),
244
+ consent: limited(form.get("consent"), 500),
245
+ formId: "notifications-preferences",
246
+ page: `${to.origin}${basePathOf(plugin)}/notifications/preferences/`,
247
+ origin: to.origin,
248
+ ip: clientAddress(request.headers),
249
+ userAgent: limited(request.headers.get("user-agent"), NEWSLETTER_USER_AGENT_CHARACTERS),
250
+ }
239
251
  : action === "unsubscribe_all"
240
252
  ? { action: "unsubscribe", token }
241
253
  : action === "delete"
@@ -243,10 +255,11 @@ export async function handleNotificationsPreferences(request: NextRequest, optio
243
255
  : null;
244
256
  if (!operation) return failure(400, "invalid_action", "Choose save, unsubscribe from everything, or delete.");
245
257
  try {
246
- const status = (await call(options, plugin.functionName, operation)).body.status;
258
+ const { body: answer } = await call(options, plugin.functionName, operation);
259
+ const status = answer.status;
247
260
  if (status === "deleted") return to.go("preferences", { msg: "deleted" });
248
261
  if (typeof status !== "string" || !PREFERENCE_MESSAGES.has(status)) return to.go("expired");
249
- return to.go("preferences", { token, msg: status });
262
+ return to.go("preferences", { token, msg: status, ...(status === "check_email" ? { confirming: (Array.isArray(answer.confirming) ? answer.confirming : []).filter((id): id is string => typeof id === "string" && LIST_ID.test(id)).join(",") } : {}) });
250
263
  } catch (error) {
251
264
  console.error(`Notifications preferences save failed (${error instanceof Error ? error.name : "error"}).`);
252
265
  return to.go("expired");
@@ -261,6 +274,17 @@ function configuredLists(plugin: Enabled, ids: string[]): Array<{ id: string; na
261
274
  });
262
275
  }
263
276
 
277
+ /** What the preferences page needs to group lists into families: the site's public settings, nothing about any reader. A list that names no family is its own. */
278
+ function familiesOf(plugin: Enabled): Record<string, { family: string; cadence: string }> {
279
+ const known = Array.isArray(plugin.settings.lists) ? (plugin.settings.lists as Array<{ id?: unknown; family?: unknown; cadence?: unknown }>) : [];
280
+ const result: Record<string, { family: string; cadence: string }> = {};
281
+ for (const entry of known) {
282
+ if (typeof entry.id !== "string") continue;
283
+ result[entry.id] = { family: typeof entry.family === "string" ? entry.family : entry.id, cadence: typeof entry.cadence === "string" ? entry.cadence : "" };
284
+ }
285
+ return result;
286
+ }
287
+
264
288
  function offeredLists(plugin: Enabled): Array<{ id: string; name: string; description: string }> {
265
289
  const known = Array.isArray(plugin.settings.lists) ? (plugin.settings.lists as Array<{ id?: unknown; name?: unknown; description?: unknown }>) : [];
266
290
  return known.flatMap((entry) =>
@@ -294,10 +318,24 @@ export async function handleNotificationsState(request: NextRequest, options: No
294
318
  if (result.body.status !== "ready") return json(400, { status: "invalid" });
295
319
  const lists = Array.isArray(result.body.lists) ? (result.body.lists as Array<Record<string, unknown>>) : [];
296
320
  if (kind === "confirm") return json(200, { status: "ready", lists: lists.flatMap((entry) => (typeof entry.name === "string" ? [{ name: entry.name }] : [])) });
321
+ const known = familiesOf(plugin);
322
+ // The wording the page shows, and posts back, when the reader chooses a family they do not hold: the same sentence as the subscribe form.
323
+ const consent = typeof plugin.settings.consent === "string" ? plugin.settings.consent : "";
297
324
  return json(200, {
298
325
  status: "ready",
299
326
  email: typeof result.body.email === "string" ? result.body.email : "",
300
- lists: lists.map((entry) => ({ id: entry.id, name: entry.name, description: entry.description ?? "", subscribed: entry.subscribed === true })),
327
+ consent,
328
+ lists: lists.map((entry) => {
329
+ const own = typeof entry.id === "string" ? known[entry.id] : undefined;
330
+ return {
331
+ id: entry.id,
332
+ name: entry.name,
333
+ description: entry.description ?? "",
334
+ subscribed: entry.subscribed === true,
335
+ family: own?.family ?? entry.id,
336
+ cadence: own?.cadence ?? "",
337
+ };
338
+ }),
301
339
  });
302
340
  } catch (error) {
303
341
  console.error(`Notifications state failed (${error instanceof Error ? error.name : "error"}).`);
package/package.json CHANGED
@@ -650,7 +650,7 @@
650
650
  "optional": true
651
651
  }
652
652
  },
653
- "version": "5.135.0-next.7",
653
+ "version": "5.135.0",
654
654
  "dependencies": {
655
655
  "@aws-amplify/adapter-nextjs": "^1.7.3",
656
656
  "@aws-crypto/sha256-js": "5.2.0",
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "5.135.0-next.7",
2
+ "version": "5.135.0",
3
3
  "routes": [
4
4
  {
5
5
  "file": "app/%5F_preview/[[...path]]/route.ts",