@anthusai/papyrus 5.112.1-next.3 → 5.113.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.
@@ -44,6 +44,7 @@ from papyrus_content.story_schedule import TASK_NAME as PUBLISH_SCHEDULED_TASK,
44
44
  from papyrus_content.live_schema import wait_for_live_schema
45
45
  from papyrus_content.publication import ensure_publication_from_environment
46
46
  from papyrus_content.editorial_checks import GraphQLEditorialStore, ensure_default_policies
47
+ from papyrus_content.item_deck_backfill import ensure_item_decks
47
48
  from papyrus_content.item_language_backfill import ensure_item_languages
48
49
  from papyrus_content.reference_intake import IntakeError, intake_email_submission_references, intake_references
49
50
  from papyrus_content.publish_alerts import PUBLISHED_TASK_KEY, announce_published
@@ -392,6 +393,8 @@ def run_deploy_render_task(client) -> dict:
392
393
  context = projection_context(client)
393
394
  # Before anything reads a language (the render, the editorial policies' checks): rows written before the fields get them, once per site.
394
395
  print(json.dumps(ensure_item_languages(client, context.writer, now=utc_now_iso, echo=lambda line: None)))
396
+ # Decks next: a row's deck column is the dek its front matter holds, which older writers did not keep (item_deck_backfill.py).
397
+ print(json.dumps(ensure_item_decks(client, context.writer, now=utc_now_iso, echo=lambda line: None)))
395
398
  ensure_default_editorial_policies(client)
396
399
  if targeted_invalidation(os.environ):
397
400
  context.invalidate = None # the default, "targeted": a deploy never purges; pages age out with the HTML lifetime (PPY-2745c1)
@@ -86,6 +86,12 @@ export const editorialChecksSchemaDefinitions = {
86
86
  .returns(a.json())
87
87
  .authorization((allow) => [allow.groups(editors)])
88
88
  .handler(functionHandler("editorialChecks", editorialChecks)),
89
+ describeEditorialLanguages: a
90
+ .query()
91
+ .arguments({ languages: a.json().required() })
92
+ .returns(a.json())
93
+ .authorization((allow) => [allow.groups(editors)])
94
+ .handler(functionHandler("editorialChecks", editorialChecks)),
89
95
  checkItemVersion: a
90
96
  .mutation()
91
97
  .arguments({ itemId: a.id().required() })
@@ -88,6 +88,12 @@ export const editorialChecksSchemaDefinitions = {
88
88
  .returns(a.json())
89
89
  .authorization((allow) => [allow.groups(editors)])
90
90
  .handler(functionHandler("editorialChecks", editorialChecks)),
91
+ describeEditorialLanguages: a
92
+ .query()
93
+ .arguments({ languages: a.json().required() })
94
+ .returns(a.json())
95
+ .authorization((allow) => [allow.groups(editors)])
96
+ .handler(functionHandler("editorialChecks", editorialChecks)),
91
97
  checkItemVersion: a
92
98
  .mutation()
93
99
  .arguments({ itemId: a.id().required() })
@@ -5,10 +5,13 @@ import { Button } from "./ui/button";
5
5
  import { Input } from "./ui/input";
6
6
  import { Spinner } from "./ui/spinner";
7
7
  import { Textarea } from "./ui/textarea";
8
+ import { EditorialLanguagesControls, useLanguagesCheck } from "./editorial-languages-controls";
9
+ import { settleLanguages } from "../lib/editorial-languages-form";
8
10
  import { describeProbability, type EditorialCheckResult } from "../lib/editorial-checks";
9
11
  import {
10
12
  DEFAULT_EDITORIAL_SETTINGS,
11
13
  deletePolicy,
14
+ describeLanguages,
12
15
  draftQuestions,
13
16
  importStarterPack,
14
17
  listPolicies,
@@ -100,6 +103,7 @@ export function EditorialChecksAdminPanel() {
100
103
  const [working, setWorking] = useState<string | null>(null);
101
104
  const [tryText, setTryText] = useState("");
102
105
  const [tryResult, setTryResult] = useState<EditorialCheckResult | null>(null);
106
+ const languagesCheck = useLanguagesCheck(settings.languages);
103
107
 
104
108
  const refresh = useCallback(async () => {
105
109
  try {
@@ -350,7 +354,12 @@ export function EditorialChecksAdminPanel() {
350
354
  onSubmit={(event) => {
351
355
  event.preventDefault();
352
356
  void run("settings", async () => {
353
- await saveSettings(settings, settingsExist);
357
+ // The languages are saved as settled (a language taken out of the list takes its serving keys with it) and only when the server's rules accept them.
358
+ const languages = settleLanguages(settings.languages);
359
+ const verdict = await describeLanguages(languages);
360
+ if (!verdict.ok) throw new Error(verdict.message);
361
+ await saveSettings({ ...settings, languages }, settingsExist);
362
+ setSettings((current) => ({ ...current, languages }));
354
363
  setSettingsExist(true);
355
364
  return "Settings saved.";
356
365
  });
@@ -375,7 +384,12 @@ export function EditorialChecksAdminPanel() {
375
384
  value={settings.languages.enabled.join(", ")}
376
385
  />
377
386
  </label>
378
- <Button disabled={working !== null} type="submit">Save settings</Button>
387
+ <EditorialLanguagesControls
388
+ check={languagesCheck}
389
+ languages={settings.languages}
390
+ onChange={(languages) => setSettings((current) => ({ ...current, languages }))}
391
+ />
392
+ <Button disabled={working !== null || languagesCheck.status !== "ok"} type="submit">Save settings</Button>
379
393
  </form>
380
394
  </section>
381
395
  );
@@ -0,0 +1,97 @@
1
+ "use client";
2
+
3
+ import { useEffect, useState } from "react";
4
+ import { Input } from "./ui/input";
5
+ import { describeLanguages } from "../lib/editorial-checks-client";
6
+ import {
7
+ SLUG_POLICIES,
8
+ SLUG_POLICY_LABELS,
9
+ checkAfter,
10
+ setPrefix,
11
+ setPublic,
12
+ setSlugPolicy,
13
+ settleLanguages,
14
+ type LanguagesCheck,
15
+ type SiteLanguages,
16
+ } from "../lib/editorial-languages-form";
17
+
18
+ /**
19
+ * The languages setting, checked by the server as it is edited (the rules are `serving_languages` in src/papyrus_content/language_serving.py; this form holds
20
+ * none of them). `check` is `checking` from the first change until the answer arrives, so a save waits for it.
21
+ */
22
+ export function useLanguagesCheck(languages: SiteLanguages): LanguagesCheck {
23
+ const [check, setCheck] = useState<LanguagesCheck>({ status: "checking", rows: [] });
24
+ const key = JSON.stringify(settleLanguages(languages));
25
+ useEffect(() => {
26
+ let current = true;
27
+ setCheck((last) => ({ status: "checking", rows: last.rows }));
28
+ const timer = setTimeout(() => {
29
+ describeLanguages(JSON.parse(key) as SiteLanguages)
30
+ .then((description) => current && setCheck((last) => checkAfter(last, description)))
31
+ .catch((error: unknown) => current && setCheck((last) => ({ status: "refused", rows: last.rows, message: `Could not check the languages: ${error instanceof Error ? error.message : String(error)}` })));
32
+ }, 300);
33
+ return () => {
34
+ current = false;
35
+ clearTimeout(timer);
36
+ };
37
+ }, [key]);
38
+ return check;
39
+ }
40
+
41
+ type Props = { languages: SiteLanguages; check: LanguagesCheck; onChange: (languages: SiteLanguages) => void };
42
+
43
+ /** Which enabled languages are public, each one's URL prefix and slug policy. The primary language is the site's root and always public. */
44
+ export function EditorialLanguagesControls({ languages, check, onChange }: Props) {
45
+ const others = check.rows.filter((row) => !row.primary);
46
+ return (
47
+ <fieldset className="min-w-0 space-y-2" data-editorial-languages>
48
+ <legend>How the site serves its languages</legend>
49
+ <p className="text-sm text-muted-foreground">
50
+ An enabled language that is not public is written, translated and checked, but gets no page on the public site. The primary language is always public.
51
+ </p>
52
+ <p aria-live="polite" data-editorial-languages-status role="status">
53
+ {check.status === "refused" ? <span data-editorial-languages-refusal>{check.message}</span> : check.status === "checking" ? "Checking the languages…" : null}
54
+ </p>
55
+ {others.length === 0 && check.status === "ok" ? <p className="text-sm text-muted-foreground">Add a second language above to choose how it is served.</p> : null}
56
+ {others.map((row) => (
57
+ <div className="grid min-w-0 gap-3 rounded-md bg-muted/40 p-3 md:grid-cols-3" data-editorial-language={row.tag} key={row.tag}>
58
+ <strong className="md:col-span-3">{row.tag}</strong>
59
+ <label className="flex min-w-0 items-start gap-2">
60
+ <input
61
+ checked={(languages.public ?? []).includes(row.tag)}
62
+ data-language-public
63
+ onChange={(event) => onChange(setPublic(languages, row.tag, event.target.checked))}
64
+ type="checkbox"
65
+ />
66
+ Public: readers can visit its pages
67
+ </label>
68
+ <label className="flex min-w-0 flex-col gap-1">
69
+ <span>Web address prefix (default {row.defaultPrefix})</span>
70
+ <Input
71
+ data-language-prefix
72
+ onChange={(event) => onChange(setPrefix(languages, row.tag, event.target.value))}
73
+ placeholder={row.defaultPrefix}
74
+ value={languages.prefixes?.[row.tag] ?? ""}
75
+ />
76
+ <small className="text-muted-foreground">Its pages live under /{languages.prefixes?.[row.tag]?.trim() || row.defaultPrefix}/</small>
77
+ </label>
78
+ <label className="flex min-w-0 flex-col gap-1">
79
+ <span>Page addresses (slugs)</span>
80
+ <select
81
+ className="w-full min-w-0"
82
+ data-language-slug
83
+ onChange={(event) => onChange(setSlugPolicy(languages, row.tag, event.target.value))}
84
+ value={languages.slugs?.[row.tag] ?? ""}
85
+ >
86
+ <option value="">Default ({row.defaultSlugPolicy ? SLUG_POLICY_LABELS[row.defaultSlugPolicy].toLowerCase() : "translated"})</option>
87
+ {SLUG_POLICIES.map((policy) => (
88
+ <option key={policy} value={policy}>{SLUG_POLICY_LABELS[policy]}</option>
89
+ ))}
90
+ </select>
91
+ <small className="text-muted-foreground">How a translation&apos;s address is first made; it never changes after the first publish.</small>
92
+ </label>
93
+ </div>
94
+ ))}
95
+ </fieldset>
96
+ );
97
+ }
@@ -3,6 +3,7 @@
3
3
  import { generateClient } from "aws-amplify/data";
4
4
  import type { EditorialCheckResult, EditorialFeedbackInput, EditorialFinding, RewriteResult, Span } from "./editorial-checks";
5
5
  import type { EditorialChecksBackend } from "./editorial-checks-backend";
6
+ import type { LanguagesDescription } from "./editorial-languages-form";
6
7
  import { DEFAULT_EDITORIAL_SETTINGS, mergeEditorialSettings, type EditorialSettings } from "./editorial-checks-settings";
7
8
 
8
9
  export { DEFAULT_EDITORIAL_SETTINGS, type EditorialSettings };
@@ -161,6 +162,18 @@ export async function saveSettings(settings: EditorialSettings, exists: boolean)
161
162
  });
162
163
  }
163
164
 
165
+ /**
166
+ * The `languages` setting checked by the rules the projection applies (src/papyrus_content/language_serving.py), with each language's effective and default
167
+ * prefix, public flag and slug policy. Refusals come back as `{ ok: false, message }`, so the form can say them before saving.
168
+ */
169
+ export async function describeLanguages(languages: EditorialSettings["languages"]): Promise<LanguagesDescription> {
170
+ const data = await call<{ describeEditorialLanguages: unknown }>(
171
+ `query DescribeEditorialLanguages($languages: AWSJSON!) { describeEditorialLanguages(languages: $languages) }`,
172
+ { languages: JSON.stringify(languages) },
173
+ );
174
+ return parsed<LanguagesDescription>(data.describeEditorialLanguages);
175
+ }
176
+
164
177
  export async function importStarterPack(name: string): Promise<{ created: number; skipped: number }> {
165
178
  const data = await call<{ importEditorialStarterPack: unknown }>(
166
179
  `mutation ImportStarterPack($name: String!) { importEditorialStarterPack(name: $name) }`,
@@ -0,0 +1,89 @@
1
+ /**
2
+ * The editing side of the `languages` editorial setting (Administration > Editorial checks): which enabled languages are public, each language's URL
3
+ * prefix and each language's slug policy. The rules those keys must obey are not here. They live in one place, `serving_languages` in
4
+ * src/papyrus_content/language_serving.py, and the form asks the `describeEditorialLanguages` query, which runs them (docs/multilingual-serving.md).
5
+ *
6
+ * Every function returns a new object that keeps every key it was not asked to change, so a save never drops a key the form does not show.
7
+ */
8
+ import type { EditorialSettings } from "./editorial-checks-settings";
9
+
10
+ export type SiteLanguages = EditorialSettings["languages"];
11
+
12
+ export const SLUG_POLICIES = ["translated", "characters", "pinyin", "primary"] as const;
13
+
14
+ export const SLUG_POLICY_LABELS: Record<string, string> = {
15
+ translated: "Translated title, in plain letters",
16
+ characters: "Title in its own script (Chinese characters kept)",
17
+ pinyin: "Pinyin (Chinese written in Latin letters)",
18
+ primary: "Same as the original story's address",
19
+ };
20
+
21
+ /** One enabled language as the server describes it: its effective values and the defaults it would otherwise get. */
22
+ export type LanguageRow = {
23
+ tag: string;
24
+ primary: boolean;
25
+ public: boolean;
26
+ prefix: string;
27
+ defaultPrefix: string;
28
+ slugPolicy: string | null;
29
+ defaultSlugPolicy: string | null;
30
+ };
31
+
32
+ /** Where the check of the setting stands. `rows` are the last language list the server described, kept while a new check runs or refuses so the fields stay editable. */
33
+ export type LanguagesCheck = { status: "checking" | "ok" | "refused"; rows: LanguageRow[]; message?: string };
34
+
35
+ export type LanguagesDescription = { ok: true; primary: string; enabled: string[]; languages: LanguageRow[] } | { ok: false; message: string };
36
+
37
+ /** `edited` without the entries of a key that name a language no longer enabled (or the primary, which has no prefix or slug policy). */
38
+ function without<T>(entries: Record<string, T> | undefined, keep: (tag: string) => boolean): Record<string, T> | undefined {
39
+ if (!entries) return undefined;
40
+ const kept = Object.fromEntries(Object.entries(entries).filter(([tag]) => keep(tag)));
41
+ return Object.keys(kept).length > 0 ? kept : undefined;
42
+ }
43
+
44
+ function setKey<K extends keyof SiteLanguages>(languages: SiteLanguages, key: K, value: SiteLanguages[K] | undefined): SiteLanguages {
45
+ const { [key]: _removed, ...rest } = languages;
46
+ return (value === undefined ? rest : { ...rest, [key]: value }) as SiteLanguages;
47
+ }
48
+
49
+ /**
50
+ * The setting as it is saved and checked: entries for a language the site no longer writes in are dropped (taking a language out of the list takes its
51
+ * public flag, prefix and slug policy with it), and a public list always starts with the primary. Left as typed while the list is being edited, so
52
+ * retyping a language does not lose its settings.
53
+ */
54
+ export function settleLanguages(languages: SiteLanguages): SiteLanguages {
55
+ const others = (tag: string) => languages.enabled.includes(tag) && tag !== languages.primary;
56
+ let settled = setKey(languages, "prefixes", without(languages.prefixes, others));
57
+ settled = setKey(settled, "slugs", without(languages.slugs, others));
58
+ if (languages.public === undefined) return settled;
59
+ const listed = languages.public.filter((tag) => others(tag));
60
+ return setKey(settled, "public", listed.length > 0 ? [languages.primary, ...listed] : undefined);
61
+ }
62
+
63
+ /** Make one non-primary language public or not. Nothing public beyond the primary is no list at all (the default). */
64
+ export function setPublic(languages: SiteLanguages, tag: string, on: boolean): SiteLanguages {
65
+ const current = (languages.public ?? []).filter((listed) => listed !== languages.primary && listed !== tag);
66
+ const next = on ? [...current, tag] : current;
67
+ return setKey(languages, "public", next.length > 0 ? [languages.primary, ...next] : undefined);
68
+ }
69
+
70
+ /** Set one language's URL prefix; blank returns it to the default. */
71
+ export function setPrefix(languages: SiteLanguages, tag: string, prefix: string): SiteLanguages {
72
+ const { [tag]: _old, ...others } = languages.prefixes ?? {};
73
+ const next = prefix.trim() === "" ? others : { ...others, [tag]: prefix.trim() };
74
+ return setKey(languages, "prefixes", Object.keys(next).length > 0 ? next : undefined);
75
+ }
76
+
77
+ /** Set one language's slug policy; blank returns it to the default. */
78
+ export function setSlugPolicy(languages: SiteLanguages, tag: string, policy: string): SiteLanguages {
79
+ const { [tag]: _old, ...others } = languages.slugs ?? {};
80
+ const next = policy === "" ? others : { ...others, [tag]: policy };
81
+ return setKey(languages, "slugs", Object.keys(next).length > 0 ? next : undefined);
82
+ }
83
+
84
+ /** The check after the server's answer: refused keeps the rows of the last answer that was fine, so the fields that caused it can be corrected. */
85
+ export function checkAfter(last: LanguagesCheck, description: LanguagesDescription): LanguagesCheck {
86
+ return description.ok
87
+ ? { status: "ok", rows: description.languages }
88
+ : { status: "refused", rows: last.rows, message: description.message };
89
+ }
package/package.json CHANGED
@@ -103,6 +103,7 @@
103
103
  "./components/editorial-checks-admin-panel": "./components/editorial-checks-admin-panel.tsx",
104
104
  "./components/editorial-finding-card": "./components/editorial-finding-card.tsx",
105
105
  "./components/editorial-findings-panel": "./components/editorial-findings-panel.tsx",
106
+ "./components/editorial-languages-controls": "./components/editorial-languages-controls.tsx",
106
107
  "./components/editorial-preview-popover": "./components/editorial-preview-popover.tsx",
107
108
  "./components/home-cyclotron-panel": "./components/home-cyclotron-panel.tsx",
108
109
  "./components/idea-decision": "./components/idea-decision.tsx",
@@ -317,6 +318,7 @@
317
318
  "./lib/editorial-checks-demo": "./lib/editorial-checks-demo.ts",
318
319
  "./lib/editorial-checks-settings": "./lib/editorial-checks-settings.ts",
319
320
  "./lib/editorial-checks": "./lib/editorial-checks.ts",
321
+ "./lib/editorial-languages-form": "./lib/editorial-languages-form.ts",
320
322
  "./lib/editorial-preview": "./lib/editorial-preview.ts",
321
323
  "./lib/empty-edition-layout-plan": "./lib/empty-edition-layout-plan.ts",
322
324
  "./lib/excerpts": "./lib/excerpts.ts",
@@ -638,7 +640,7 @@
638
640
  "optional": true
639
641
  }
640
642
  },
641
- "version": "5.112.1-next.3",
643
+ "version": "5.113.0-next.1",
642
644
  "dependencies": {
643
645
  "@aws-amplify/adapter-nextjs": "^1.7.3",
644
646
  "@aws-crypto/sha256-js": "5.2.0",
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "5.112.1-next.3",
2
+ "version": "5.113.0-next.1",
3
3
  "routes": [
4
4
  {
5
5
  "file": "app/%5F_preview/[[...path]]/route.ts",