@taprootio/site-authoring 0.55.0 → 0.56.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.
@@ -57,28 +57,30 @@ export function descriptionWarnings(pages, onProgress) {
57
57
  }
58
58
 
59
59
  export const PAGE_AUTHOR_UNVERIFIED = "pages.author_unverified";
60
+ export const PAGE_DISPLAY_AUTHOR_UNVERIFIED = "pages.display_author_unverified";
60
61
 
61
62
  /**
62
63
  * Warnings for authors an offline run could not confirm (TR01196). The only
63
64
  * evidence offline is `authors.json`, which is as old as the last `pull` or
64
65
  * `authors list`, so a name missing from it may simply be newer; it is flagged
65
- * rather than refused, and an online run settles it against the site.
66
+ * rather than refused, and an online run settles it against the site. A display
67
+ * author's handle (TR01402) is held to the same evidence and has its own code.
66
68
  */
67
69
  export function authorWarnings(pages, onProgress) {
68
70
  const items = [];
69
71
  for (const page of pages ?? []) {
70
- if (page.authorUnverified !== true) continue;
71
- const item = {
72
- code: PAGE_AUTHOR_UNVERIFIED,
73
- file: page.file,
74
- path: displayPagePath(page.pagePath ?? page.path),
75
- author: page.author,
76
- };
77
- onProgress(
78
- `Warning: ${item.file} names author '${item.author}', who is not in authors.json; it may have been added `
79
- + "since. 'taproot-site authors list' refreshes it, and 'pages push' checks the name against the site.",
80
- );
81
- items.push(item);
72
+ for (const [flag, code, label, name] of [
73
+ [page.authorUnverified, PAGE_AUTHOR_UNVERIFIED, "author", page.author],
74
+ [page.displayAuthorUnverified, PAGE_DISPLAY_AUTHOR_UNVERIFIED, "displayAuthor", page.document?.displayAuthor],
75
+ ]) {
76
+ if (flag !== true) continue;
77
+ const item = { code, file: page.file, path: displayPagePath(page.pagePath ?? page.path), author: name };
78
+ onProgress(
79
+ `Warning: ${item.file} names ${label} '${item.author}', who is not in authors.json; it may have been added `
80
+ + "since. 'taproot-site authors list' refreshes it, and 'pages push' checks the name against the site.",
81
+ );
82
+ items.push(item);
83
+ }
82
84
  }
83
85
  const reported = boundedByBytes(items, 8 * 1024);
84
86
  return items.length === 0
@@ -99,7 +99,7 @@ import {
99
99
 
100
100
  export { getAppearanceReference, getFooterReference, getSettingsReference, getThemeReference };
101
101
 
102
- export const REFERENCE_VERSION = 79;
102
+ export const REFERENCE_VERSION = 80;
103
103
 
104
104
  // The date-limit examples `help forms` prints; tests run them through the form validator.
105
105
  export const FORM_DATE_WINDOW_FIELD = Object.freeze({
@@ -1761,15 +1761,32 @@ const FREE_FORM_REFERENCE = Object.freeze({
1761
1761
  + "matter for any template or use pages meta set <path> --author for .pm.json. Use a site author's handle "
1762
1762
  + "(jane-doe) or the email of a member who can create pages. authors list refreshes authors.json. "
1763
1763
  + "authors add <handle> --name <name> [--email <address>] creates a site author with a private email, "
1764
- + "a byline and structured data. Site authors have no Taproot account, profile link or follow button. "
1765
- + "Reusing a handle and name returns existing: true. A different name triggers authors.handle_taken. "
1764
+ + "a byline and structured data. Site authors have no Taproot account or follow button. "
1765
+ + "A site author's byline can link to a page on the site (--link-page <path or resourceId>) or a web address "
1766
+ + "(--link-url <address>), never both (authors.link_conflict), and show an image from the media library "
1767
+ + "(--image <media path or image id>). authors set <handle> changes the name, email, link or image, sending "
1768
+ + "only what is passed; --no-link, --no-image and --no-email clear. It asks for the deployments capability "
1769
+ + "because changing the byline of an author on published pages queues a deployment (authors.deployment_refused "
1770
+ + "when that is not allowed). authors.json records each author's link and image. "
1771
+ + "Reusing a handle and name returns existing: true; a link or image is compared only when its option is "
1772
+ + "passed. A difference triggers authors.handle_taken and points at authors set. "
1766
1773
  + "Only the CLI assigns authors, and only to authorless pages. Repeating the assigned author is a no-op. "
1767
1774
  + "A different author triggers pages.author_conflict. Restore the site's author in front matter or with "
1768
1775
  + "pages meta set <path> --author. Use --author \"\" to clear an unsent assignment. "
1769
1776
  + "Offline validate and pages meta set warn pages.author_unverified on authors.json misses. pages push "
1770
1777
  + "and plan check the live list once on a miss. Unknown or ineligible authors trigger pages.author_unknown. "
1771
- + "Text that is neither a handle nor an address triggers pages.author_invalid.",
1772
- authorshipErrors: Object.freeze(["pages.author_invalid", "pages.author_unknown", "pages.author_conflict"]),
1778
+ + "Text that is neither a handle nor an address triggers pages.author_invalid. "
1779
+ // Kept to one sentence: every page type's help carries this rule, and the free-form help is near its
1780
+ // output bound. The typed page's field help holds the detail (TR01402).
1781
+ + "displayAuthor on a typed page names a site author for the byline instead of the member; that page "
1782
+ + "type's field help has the rules.",
1783
+ authorshipErrors: Object.freeze([
1784
+ "pages.author_invalid",
1785
+ "pages.author_unknown",
1786
+ "pages.author_conflict",
1787
+ "pages.display_author_invalid",
1788
+ "pages.display_author_unknown",
1789
+ ]),
1773
1790
  conflictDetail:
1774
1791
  "error.differences is absent when the workspace has no baseline document to compare. An empty list means "
1775
1792
  + "only title, path, description, cover image or display date changed. Otherwise it lists changed JSON body paths. "
@@ -61,6 +61,27 @@ const FIELD_HELP = Object.freeze({
61
61
  "The date the page is about or was originally published. Set it to preserve an imported date; omit it to use the "
62
62
  + "first publication date. An empty value clears it.",
63
63
  },
64
+ displayAuthor: {
65
+ type: "site author handle",
66
+ required: false,
67
+ description:
68
+ "The site author the byline shows instead of the member who wrote the page, such as jane-doe. Every handle "
69
+ + "names an author, including none; a member's email address is refused. A page with a display author carries no "
70
+ + "trace of the member and stays off their Taproot profile. Omit it to leave the site's value alone; a quoted "
71
+ + "empty value (\"\") clears it and a bare key is refused. It can be changed at any time, but a page that must be kept apart from the member needs it "
72
+ + "before the page is first published: a page already published under the member's name was public with it. "
73
+ + "An unknown handle is refused (pages.display_author_unknown); offline validate only warns "
74
+ + "(pages.display_author_unverified) about one authors.json lacks.",
75
+ },
76
+ showOnProfile: {
77
+ type: "true or false",
78
+ required: false,
79
+ description:
80
+ "false keeps a member's page (one with no display author) off that member's Taproot profile; it keeps its byline "
81
+ + "and profile link. Omit it to leave "
82
+ + "the site's setting alone. Only true and false are accepted (pages.show_on_profile_invalid). The profile "
83
+ + "changes after the page is published and its release goes live. A displayAuthor keeps a page apart entirely.",
84
+ },
64
85
  coverImage: {
65
86
  type: "media reference",
66
87
  required: false,
@@ -507,7 +528,7 @@ function typedReference(type) {
507
528
  purpose: generated
508
529
  ? "The pulled form, and the only one: { template, data }. Path comes from the manifest; title and description "
509
530
  + "are the custom ones in data."
510
- : "The pulled form: { template, displayDate?, coverImageId?, data }. Title, path and description come from the manifest.",
531
+ : "The pulled form: { template, displayDate?, displayAuthor?, showOnProfile?, coverImageId?, data }. Title, path and description come from the manifest.",
511
532
  dataFields: Object.freeze(details.dataFields),
512
533
  }),
513
534
  ]),
@@ -1,4 +1,5 @@
1
1
  import { FREE_FORM_TEMPLATE_VERSION, TEMPLATE_TYPE_FREE_FORM } from "./api.js";
2
+ import { normalizeAuthorHandle } from "./authors-contract.js";
2
3
  import { authoredTagSlug, validateAuthoredTagNames } from "./authored-tag-names.js";
3
4
  import { isVideoEmbedId } from "./content/video-embed-url.js";
4
5
  import { hasControlCharacter, SiteAuthoringError } from "./errors.js";
@@ -15,7 +16,7 @@ import { recipeStepProblems } from "./recipe-step-contract.js";
15
16
  * Free-form keeps its historical shape (the ProseMirror document itself). The
16
17
  * other templates use a small wrapper:
17
18
  *
18
- * { "template": "recipe", "displayDate": "2024-05-01", "coverImageId": "…", "data": { … } }
19
+ * { "template": "recipe", "displayDate": "2024-05-01", "displayAuthor": "jane-doe", "showOnProfile": false, "coverImageId": "…", "data": { … } }
19
20
  *
20
21
  * `pull` writes that wrapper, a Markdown source is converted into it, and
21
22
  * `pages push` turns it into the API's `PageTemplate`. Because all three meet
@@ -63,7 +64,7 @@ export const SHARED_FRONT_MATTER_KEYS = Object.freeze(["title", "path", "descrip
63
64
  * its bare document, which has nowhere to carry them, so it does not accept
64
65
  * them.
65
66
  */
66
- const TYPED_PAGE_FRONT_MATTER_KEYS = Object.freeze(["displayDate", "coverImage", "tags"]);
67
+ const TYPED_PAGE_FRONT_MATTER_KEYS = Object.freeze(["displayDate", "displayAuthor", "showOnProfile", "coverImage", "tags"]);
67
68
 
68
69
  /** Front-matter fields only one template accepts. Others are refused for it. */
69
70
  const TEMPLATE_FRONT_MATTER_KEYS = Object.freeze({
@@ -379,6 +380,43 @@ export function requireDisplayDate(value, file) {
379
380
  return value;
380
381
  }
381
382
 
383
+ /**
384
+ * A page's display author (TR01402): a site author's handle, folded, or ""
385
+ * to clear it. Every handle names an author, including `none`; a member's
386
+ * email address is not one, because only a site author can be a byline.
387
+ */
388
+ export function requireDisplayAuthor(value, file) {
389
+ if (value === "") return value;
390
+ const handle = normalizeAuthorHandle(value);
391
+ if (handle === undefined) {
392
+ throw fail(
393
+ "pages.display_author_invalid",
394
+ `'${file}' declares displayAuthor '${typeof value === "string" ? value.slice(0, 80) : ""}', which is not a `
395
+ + "site author's handle (lowercase letters, digits and single hyphens, such as jane-doe). Use '' to clear it.",
396
+ file,
397
+ );
398
+ }
399
+ return handle;
400
+ }
401
+
402
+ /**
403
+ * Whether the page may appear on its author's Taproot profile (TR01403): the
404
+ * literal `true` or `false`. A `.pm.json` document holds a JSON boolean; a
405
+ * Markdown front-matter line holds the text (`fromText`), which an unquoted or
406
+ * quoted literal both give. Anything else, a JSON string included, is refused
407
+ * so a typo never leaves a page on a profile its author meant to keep it off.
408
+ */
409
+ export function requireShowOnProfile(value, file, { fromText = false } = {}) {
410
+ if (typeof value === "boolean") return value;
411
+ if (fromText && (value === "true" || value === "false")) return value === "true";
412
+ throw fail(
413
+ "pages.show_on_profile_invalid",
414
+ `'${file}' declares showOnProfile ${typeof value === "string" ? `'${value.slice(0, 80)}'` : "with a value"}, which is `
415
+ + `not ${fromText ? "true or false" : "a JSON boolean (true or false)"}.`,
416
+ file,
417
+ );
418
+ }
419
+
382
420
  // ── Canonical data per template ──────────────────────────────────────────────
383
421
 
384
422
  const INGREDIENT_KEYS = ["rawText", "quantity", "unit", "name", "parsed"];
@@ -635,10 +673,12 @@ function canonicalSourceData(template, data, file) {
635
673
  * The canonical workspace document for a typed page, with keys in one fixed
636
674
  * order. The order is part of the byte-stability contract.
637
675
  */
638
- function typedDocument(template, { displayDate, coverImageId, tags, data }) {
676
+ function typedDocument(template, { displayDate, displayAuthor, showOnProfile, coverImageId, tags, data }) {
639
677
  return {
640
678
  template,
641
679
  ...(displayDate === undefined ? {} : { displayDate }),
680
+ ...(displayAuthor === undefined ? {} : { displayAuthor }),
681
+ ...(showOnProfile === undefined ? {} : { showOnProfile }),
642
682
  ...(coverImageId === undefined ? {} : { coverImageId }),
643
683
  ...(tags === undefined ? {} : { tags }),
644
684
  data,
@@ -647,7 +687,7 @@ function typedDocument(template, { displayDate, coverImageId, tags, data }) {
647
687
 
648
688
  /** Validates a parsed `.pm.json` that declares a template, and returns its canonical form. */
649
689
  export function typedDocumentFromJson(parsed, file) {
650
- requireKeys(parsed, ["template", "displayDate", "coverImageId", "tags", "data"], file, "document");
690
+ requireKeys(parsed, ["template", "displayDate", "displayAuthor", "showOnProfile", "coverImageId", "tags", "data"], file, "document");
651
691
  const template = requireTemplateName(parsed.template, file);
652
692
  const tags = Object.hasOwn(parsed, "tags") ? requireSourceTags(template, parsed.tags, file).names : undefined;
653
693
  if (template === TEMPLATE_FREE_FORM) {
@@ -658,21 +698,25 @@ export function typedDocumentFromJson(parsed, file) {
658
698
  file,
659
699
  );
660
700
  }
661
- if ((template === TEMPLATE_GENERATED || template === TEMPLATE_LEGAL) && (parsed.displayDate !== undefined || parsed.coverImageId !== undefined)) {
701
+ if ((template === TEMPLATE_GENERATED || template === TEMPLATE_LEGAL) && (parsed.displayDate !== undefined || parsed.displayAuthor !== undefined || parsed.showOnProfile !== undefined || parsed.coverImageId !== undefined)) {
662
702
  throw fail(
663
703
  "pages.document_shape",
664
- `'${file}' is a ${template} page, which has no displayDate or coverImageId of its own: its document is `
704
+ `'${file}' is a ${template} page, which has no displayDate, displayAuthor, showOnProfile or coverImageId of its own: its document is `
665
705
  + "{ template, data }.",
666
706
  file,
667
707
  );
668
708
  }
669
709
  const displayDate = parsed.displayDate === undefined ? undefined : requireDisplayDate(parsed.displayDate, file);
710
+ const displayAuthor = parsed.displayAuthor === undefined ? undefined : requireDisplayAuthor(parsed.displayAuthor, file);
711
+ const showOnProfile = parsed.showOnProfile === undefined ? undefined : requireShowOnProfile(parsed.showOnProfile, file);
670
712
  let coverImageId;
671
713
  if (parsed.coverImageId !== undefined) {
672
714
  coverImageId = parsed.coverImageId === "" ? "" : requireIdentifier(parsed.coverImageId, file, "coverImageId");
673
715
  }
674
716
  return typedDocument(template, {
675
717
  displayDate,
718
+ displayAuthor,
719
+ showOnProfile,
676
720
  coverImageId,
677
721
  tags,
678
722
  data: canonicalSourceData(template, parsed.data, file),
@@ -784,6 +828,11 @@ export function workspaceDocumentFromPage(page, listedTemplateType) {
784
828
  displayDate: !generated && typeof page.displayDate === "string" && page.displayDate !== ""
785
829
  ? page.displayDate
786
830
  : undefined,
831
+ displayAuthor: !generated && typeof page.displayAuthor === "string" && page.displayAuthor !== ""
832
+ ? normalizeAuthorHandle(page.displayAuthor)
833
+ : undefined,
834
+ // Written only when the page is kept off its author's profile, as the date is written only when there is one.
835
+ showOnProfile: !generated && page.showOnProfile === false ? false : undefined,
787
836
  coverImageId: !generated && typeof page.coverImageId === "string" && page.coverImageId !== ""
788
837
  ? page.coverImageId
789
838
  : undefined,
@@ -821,6 +870,10 @@ export function sentDisplayDate(wireType) {
821
870
  return name !== undefined && name !== TEMPLATE_FREE_FORM && name !== TEMPLATE_GENERATED && name !== TEMPLATE_LEGAL;
822
871
  }
823
872
 
873
+ /** `displayAuthor` and `showOnProfile` travel with the same four byline templates as `displayDate` (TR01402, TR01403). */
874
+ export const sentDisplayAuthor = sentDisplayDate;
875
+ export const sentShowOnProfile = sentDisplayDate;
876
+
824
877
  // The nodes the API accepts in an album or recipe introduction
825
878
  // (`MembershipTermsDocumentRules.AllowedNodeTypes`). A page body accepts
826
879
  // more, such as `section` and `inlineFacts`, so a document valid as a body can
@@ -1019,6 +1072,8 @@ export function wirePageFields(document_) {
1019
1072
  if ([TEMPLATE_FREE_FORM, TEMPLATE_LEGAL].includes(documentTemplate(document_))) return {};
1020
1073
  return definedEntries([
1021
1074
  ["displayDate", document_.displayDate],
1075
+ ["displayAuthor", document_.displayAuthor],
1076
+ ["showOnProfile", document_.showOnProfile],
1022
1077
  ["coverImageId", document_.coverImageId],
1023
1078
  ]);
1024
1079
  }
@@ -1281,6 +1336,10 @@ export async function typedDocumentFromMarkdown({
1281
1336
  if (template === TEMPLATE_LEGAL) throw legalMarkdownFault(file);
1282
1337
  const tags = fields.has("tags") ? parseMarkdownTags(fields.get("tags"), file) : undefined;
1283
1338
  const displayDate = fields.has("displayDate") ? requireDisplayDate(fields.get("displayDate"), file) : undefined;
1339
+ const displayAuthor = fields.has("displayAuthor") ? requireDisplayAuthor(fields.get("displayAuthor"), file) : undefined;
1340
+ const showOnProfile = fields.has("showOnProfile")
1341
+ ? requireShowOnProfile(fields.get("showOnProfile"), file, { fromText: true })
1342
+ : undefined;
1284
1343
  let coverImageId;
1285
1344
  if (fields.has("coverImage")) {
1286
1345
  const reference = fields.get("coverImage");
@@ -1324,7 +1383,7 @@ export async function typedDocumentFromMarkdown({
1324
1383
  return typedDocumentFromJson(
1325
1384
  {
1326
1385
  template,
1327
- ...definedEntries([["displayDate", displayDate], ["coverImageId", coverImageId], ["tags", tags]]),
1386
+ ...definedEntries([["displayDate", displayDate], ["displayAuthor", displayAuthor], ["showOnProfile", showOnProfile], ["coverImageId", coverImageId], ["tags", tags]]),
1328
1387
  data: withoutUndefined(data),
1329
1388
  },
1330
1389
  file,
@@ -1,17 +1,27 @@
1
- import { createSiteAuthor, listSiteAuthors, withRefusalGuidance } from "../api.js";
1
+ import { createSiteAuthor, listSiteAuthors, updateSiteAuthor, withRefusalGuidance } from "../api.js";
2
2
  import {
3
3
  AUTHOR_DISPLAY_NAME_MAXIMUM_LENGTH,
4
4
  AUTHOR_HANDLE_MAXIMUM_LENGTH,
5
5
  AUTHORS_FILE_NAME,
6
+ differingAuthorValues,
6
7
  normalizeAuthorEmail,
7
8
  normalizeAuthorHandle,
8
9
  projectAuthorsForWorkspace,
10
+ requireConsistentAuthorOptions,
9
11
  } from "../authors-contract.js";
10
- import { VERB_AUTHORS_ADD, VERB_AUTHORS_LIST } from "../constants.js";
11
- import { sanitizeDiagnostic, SiteAuthoringError } from "../errors.js";
12
- import { boundedList, openSession, successResult } from "../session.js";
12
+ import { VERB_AUTHORS_ADD, VERB_AUTHORS_LIST, VERB_AUTHORS_SET } from "../constants.js";
13
+ import { isCanonicalUuid, sanitizeDiagnostic, SiteAuthoringError } from "../errors.js";
14
+ import { boundedList, openSession, resolveSiteSession, successResult } from "../session.js";
15
+ import { trimSocialLinkInput } from "../social-link-url.js";
13
16
  import { ApiError } from "../transport.js";
14
- import { ensureWorkspaceRoot, writeWorkspaceJson } from "../workspace.js";
17
+ import {
18
+ ensureWorkspaceRoot,
19
+ mediaReferenceCandidates,
20
+ normalizePagePath,
21
+ readManifest,
22
+ readMediaManifest,
23
+ writeWorkspaceJson,
24
+ } from "../workspace.js";
15
25
 
16
26
  const MAXIMUM_REPORTED = 200;
17
27
 
@@ -57,58 +67,154 @@ export async function authorsList(invocation) {
57
67
  });
58
68
  }
59
69
 
60
- /**
61
- * `authors add` — creates a site author, someone a page can be credited to who
62
- * has no Taproot account, such as one of an imported blog's authors.
63
- */
64
- export async function authorsAdd(invocation) {
65
- const handle = normalizeAuthorHandle(invocation.authorHandle);
70
+ /** The name readers see, trimmed, or a usage refusal. */
71
+ function requireDisplayName(value) {
72
+ const displayName = typeof value === "string" ? value.trim() : "";
73
+ if (displayName === "" || [...displayName].length > AUTHOR_DISPLAY_NAME_MAXIMUM_LENGTH) {
74
+ throw new SiteAuthoringError(
75
+ "authors.name_invalid",
76
+ `--name must be the name readers see, 1 to ${AUTHOR_DISPLAY_NAME_MAXIMUM_LENGTH} characters.`,
77
+ { field: "name", exitCode: 2 },
78
+ );
79
+ }
80
+ return displayName;
81
+ }
82
+
83
+ function requireHandle(value) {
84
+ const handle = normalizeAuthorHandle(value);
66
85
  if (handle === undefined) {
67
86
  throw new SiteAuthoringError(
68
87
  "authors.handle_invalid",
69
- `'${String(invocation.authorHandle ?? "").slice(0, 80)}' is not a handle. Use lowercase letters and digits `
88
+ `'${String(value ?? "").slice(0, 80)}' is not a handle. Use lowercase letters and digits `
70
89
  + `with single hyphens between them, at most ${AUTHOR_HANDLE_MAXIMUM_LENGTH} characters, such as jane-doe.`,
71
90
  { field: "handle", exitCode: 2 },
72
91
  );
73
92
  }
74
- const displayName = typeof invocation.authorName === "string" ? invocation.authorName.trim() : "";
75
- if (displayName === "" || [...displayName].length > AUTHOR_DISPLAY_NAME_MAXIMUM_LENGTH) {
93
+ return handle;
94
+ }
95
+
96
+ function requireEmail(value) {
97
+ const email = normalizeAuthorEmail(value);
98
+ if (email === undefined) {
99
+ throw new SiteAuthoringError("authors.email_invalid", "--email must be an email address.", {
100
+ field: "email",
101
+ exitCode: 2,
102
+ });
103
+ }
104
+ return email;
105
+ }
106
+
107
+ /**
108
+ * The byline link and image the options name, as the ids and address the site
109
+ * takes. A page or image given by path is looked up in the workspace's
110
+ * manifests, so a path the workspace does not know is refused before any
111
+ * request (TR01401). An id is passed on, and the site decides whether it is
112
+ * this site's.
113
+ */
114
+ async function resolveBylineOptions(invocation, config, siteId) {
115
+ const resolved = {};
116
+ if (invocation.authorLinkUrl !== undefined) {
117
+ // The site stores the address trimmed, so it is sent and compared that way. A blank one names no
118
+ // address, and sending it would read as clearing the link.
119
+ const linkUrl = trimSocialLinkInput(invocation.authorLinkUrl);
120
+ if (linkUrl === "") {
121
+ throw new SiteAuthoringError(
122
+ "authors.link_url_invalid",
123
+ "--link-url needs an absolute http or https address. Use --no-link to remove the link.",
124
+ { field: "link-url", exitCode: 2 },
125
+ );
126
+ }
127
+ resolved.linkUrl = linkUrl;
128
+ }
129
+ if (invocation.authorLinkPage !== undefined) {
130
+ resolved.linkPageResourceId = await resolvePageResourceId(config, siteId, invocation.authorLinkPage);
131
+ }
132
+ if (invocation.authorImage !== undefined) {
133
+ resolved.imageId = await resolveImageId(config, siteId, invocation.authorImage);
134
+ }
135
+ return resolved;
136
+ }
137
+
138
+ async function resolvePageResourceId(config, siteId, reference) {
139
+ if (isCanonicalUuid(reference)) return reference;
140
+ const wanted = normalizePagePath(reference);
141
+ const manifest = await readManifest(config.workspaceDir, siteId, { required: false });
142
+ const entry = wanted === undefined
143
+ ? undefined
144
+ : manifest?.pages.find((page) => page !== null && normalizePagePath(page.path) === wanted);
145
+ if (typeof entry?.resourceId !== "string" || !isCanonicalUuid(entry.resourceId)) {
76
146
  throw new SiteAuthoringError(
77
- "authors.name_invalid",
78
- `--name must be the name readers see, 1 to ${AUTHOR_DISPLAY_NAME_MAXIMUM_LENGTH} characters.`,
79
- { field: "name", exitCode: 2 },
147
+ "authors.link_page_unknown",
148
+ `--link-page '${reference.slice(0, 80)}' is not a page the workspace's manifest records. Give the page's `
149
+ + "path as 'pull' recorded it ('/' for the home page), or its resourceId.",
150
+ { field: "link-page", exitCode: 2 },
80
151
  );
81
152
  }
82
- let email;
83
- if (invocation.authorEmail !== undefined) {
84
- email = normalizeAuthorEmail(invocation.authorEmail);
85
- if (email === undefined) {
86
- throw new SiteAuthoringError("authors.email_invalid", "--email must be an email address.", {
87
- field: "email",
88
- exitCode: 2,
89
- });
90
- }
153
+ return entry.resourceId;
154
+ }
155
+
156
+ async function resolveImageId(config, siteId, reference) {
157
+ if (isCanonicalUuid(reference)) return reference;
158
+ const { media } = await readMediaManifest(config.workspaceDir, siteId);
159
+ for (const candidate of mediaReferenceCandidates(reference)) {
160
+ const imageId = media[candidate]?.imageId;
161
+ if (isCanonicalUuid(imageId)) return imageId;
91
162
  }
163
+ throw new SiteAuthoringError(
164
+ "authors.image_unknown",
165
+ `--image '${reference.slice(0, 80)}' is not an image the workspace's media manifest records. Run 'media upload' `
166
+ + "for the file first, or give the image's id.",
167
+ { field: "image", exitCode: 2 },
168
+ );
169
+ }
92
170
 
93
- const { client, config, siteId, onProgress } = await openSession(invocation);
171
+ /** How an author reads in a result and a progress line: only what it has. */
172
+ function authorResult(author) {
173
+ const { handle, displayName, hasEmail, linkPageResourceId, linkUrl, imageId } = author;
174
+ return {
175
+ handle,
176
+ displayName,
177
+ hasEmail,
178
+ ...(linkPageResourceId === undefined ? {} : { linkPageResourceId }),
179
+ ...(linkUrl === undefined ? {} : { linkUrl }),
180
+ ...(imageId === undefined ? {} : { imageId }),
181
+ };
182
+ }
183
+
184
+ /**
185
+ * `authors add` — creates a site author, someone a page can be credited to who
186
+ * has no Taproot account, such as one of an imported blog's authors. The
187
+ * author may carry a byline link and an image (TR01401).
188
+ */
189
+ export async function authorsAdd(invocation) {
190
+ const handle = requireHandle(invocation.authorHandle);
191
+ const displayName = requireDisplayName(invocation.authorName);
192
+ const email = invocation.authorEmail === undefined ? undefined : requireEmail(invocation.authorEmail);
193
+ requireConsistentAuthorOptions(invocation, { set: false });
194
+
195
+ const session = await resolveSiteSession(invocation);
196
+ const byline = await resolveBylineOptions(invocation, session.config, session.siteId);
197
+ const { client, config, siteId, onProgress } = await session.open();
94
198
  // A handle that is already taken by the same person is a repeat of this
95
199
  // command, not a mistake: a script that adds its authors again succeeds.
96
200
  let existing = false;
97
201
  let known;
98
202
  const created = await withRefusalGuidance(onProgress, "authors add", async () => {
99
203
  try {
100
- return await createSiteAuthor(client, siteId, { handle, displayName, email });
204
+ return await createSiteAuthor(client, siteId, { handle, displayName, email, ...byline });
101
205
  } catch (error) {
102
206
  const refusal = translateAuthorsRefusal(error, handle);
103
207
  if (refusal?.code !== "authors.handle_taken") throw refusal;
104
208
  known = await listSiteAuthors(client, siteId);
105
209
  const held = known.authors.find((author) => author.handle === handle);
106
210
  if (held === undefined) throw refusal;
107
- if (held.displayName !== displayName) {
211
+ const differs = differingAuthorValues(held, { displayName, ...byline });
212
+ if (differs.length > 0) {
108
213
  throw new SiteAuthoringError(
109
214
  "authors.handle_taken",
110
- `A site author with the handle '${handle}' already exists, named '${held.displayName}', not `
111
- + `'${displayName}'. Use another handle, or the existing author.`,
215
+ `A site author with the handle '${handle}' already exists and differs in its ${differs.join(" and ")}: `
216
+ + `it is named '${held.displayName}'. Use another handle, the existing author, or `
217
+ + `'authors set ${handle}' to change it.`,
112
218
  { field: "handle" },
113
219
  );
114
220
  }
@@ -133,7 +239,7 @@ export async function authorsAdd(invocation) {
133
239
  onProgress(`The author was created, but ${AUTHORS_FILE_NAME} could not be refreshed: run 'authors list'.`);
134
240
  }
135
241
  return successResult(VERB_AUTHORS_ADD, siteId, {
136
- author: { handle: created.handle, displayName: created.displayName, hasEmail: created.hasEmail },
242
+ author: authorResult(created),
137
243
  existing,
138
244
  ...(refreshed ? { authorsFile: AUTHORS_FILE_NAME } : {}),
139
245
  nextStep: `Credit pages with 'author: ${created.handle}' in a page's front matter or `
@@ -141,12 +247,66 @@ export async function authorsAdd(invocation) {
141
247
  });
142
248
  }
143
249
 
250
+ /**
251
+ * `authors set` — changes a site author's name, private email, byline link or
252
+ * image. Only what was passed is sent, so the rest keeps its stored value.
253
+ * A change to the byline of an author on published pages queues a deployment
254
+ * (TR01401).
255
+ */
256
+ export async function authorsSet(invocation) {
257
+ const handle = requireHandle(invocation.authorHandle);
258
+ requireConsistentAuthorOptions(invocation, { set: true });
259
+ const displayName = invocation.authorName === undefined ? undefined : requireDisplayName(invocation.authorName);
260
+ const email = invocation.authorEmail === undefined ? undefined : requireEmail(invocation.authorEmail);
261
+
262
+ const session = await resolveSiteSession(invocation);
263
+ const byline = await resolveBylineOptions(invocation, session.config, session.siteId);
264
+ const { client, config, siteId, onProgress } = await session.open();
265
+ const changes = {
266
+ ...(displayName === undefined ? {} : { displayName }),
267
+ ...(email === undefined ? {} : { email }),
268
+ ...(invocation.authorNoEmail ? { email: "" } : {}),
269
+ ...byline,
270
+ ...(invocation.authorNoLink ? { linkPageResourceId: "", linkUrl: "" } : {}),
271
+ ...(invocation.authorNoImage ? { imageId: "" } : {}),
272
+ };
273
+ const author = await withRefusalGuidance(onProgress, "authors set", async () => {
274
+ try {
275
+ return await updateSiteAuthor(client, siteId, handle, changes);
276
+ } catch (error) {
277
+ if (error instanceof ApiError && error.httpStatus === 404) {
278
+ throw new SiteAuthoringError(
279
+ "authors.handle_unknown",
280
+ `This site has no site author with the handle '${handle}'. Run 'authors list' to see the handles, or `
281
+ + "'authors add' to create one.",
282
+ { field: "handle" },
283
+ );
284
+ }
285
+ throw translateAuthorsRefusal(error, handle);
286
+ }
287
+ });
288
+ onProgress(`Changed site author '${author.handle}' (${author.displayName}).`);
289
+
290
+ let refreshed = false;
291
+ try {
292
+ await writeAuthorsFile(config, siteId, await listSiteAuthors(client, siteId));
293
+ refreshed = true;
294
+ } catch (error) {
295
+ if (!(error instanceof SiteAuthoringError)) throw error;
296
+ onProgress(`The author was changed, but ${AUTHORS_FILE_NAME} could not be refreshed: run 'authors list'.`);
297
+ }
298
+ return successResult(VERB_AUTHORS_SET, siteId, {
299
+ author: authorResult(author),
300
+ ...(refreshed ? { authorsFile: AUTHORS_FILE_NAME } : {}),
301
+ });
302
+ }
303
+
144
304
  async function writeAuthorsFile(config, siteId, listing) {
145
305
  await ensureWorkspaceRoot(config);
146
306
  await writeWorkspaceJson(config.workspaceDir, AUTHORS_FILE_NAME, projectAuthorsForWorkspace(siteId, listing));
147
307
  }
148
308
 
149
- /** Gives the site's refusals of a new author the stable codes the CLI documents. */
309
+ /** Gives the site's refusals of a new or changed author the stable codes the CLI documents. */
150
310
  function translateAuthorsRefusal(error, handle) {
151
311
  if (!(error instanceof ApiError)) return error;
152
312
  for (const [field, code, fallback] of [
@@ -154,6 +314,11 @@ function translateAuthorsRefusal(error, handle) {
154
314
  ["Handle", "authors.handle_invalid", `'${handle}' cannot be used as a handle.`],
155
315
  ["DisplayName", "authors.name_invalid", "The name was refused."],
156
316
  ["Email", "authors.email_invalid", "The email address was refused."],
317
+ ["Link", "authors.link_conflict", "Give a page or a web address for the byline link, not both."],
318
+ ["LinkUrl", "authors.link_url_invalid", "The byline link must be an absolute http or https address."],
319
+ ["LinkPageResourceId", "authors.link_page_unknown", "The byline link is not a page on this site."],
320
+ ["ImageId", "authors.image_unknown", "The image is not in this site's media library."],
321
+ ["Deployment", "authors.deployment_refused", "The change could not queue the deployment it needs."],
157
322
  ]) {
158
323
  if (error.hasField(field)) {
159
324
  return new SiteAuthoringError(
@@ -3,6 +3,7 @@ import {
3
3
  VERB_APPROVE,
4
4
  VERB_AUTHORS_ADD,
5
5
  VERB_AUTHORS_LIST,
6
+ VERB_AUTHORS_SET,
6
7
  VERB_DELIVERY_CHECK,
7
8
  VERB_DEPLOY,
8
9
  VERB_CHANGELOG,
@@ -47,7 +48,7 @@ import {
47
48
  VERB_WHOAMI,
48
49
  } from "../constants.js";
49
50
  import { approve } from "./approve.js";
50
- import { authorsAdd, authorsList } from "./authors.js";
51
+ import { authorsAdd, authorsList, authorsSet } from "./authors.js";
51
52
  import { changelog } from "./changelog.js";
52
53
  import { deliveryCheck } from "./delivery-check.js";
53
54
  import { deploy } from "./deploy.js";
@@ -137,7 +138,7 @@ import { whoami } from "./whoami.js";
137
138
  * placeId, // places category clear: [placeId]
138
139
  * pagePaths, // approve: narrow to these page paths; with none, every
139
140
  * // draft the workspace manifest tracks is staged
140
- * authorHandle, // authors add: the handle of the site author to create
141
+ * authorHandle, // authors add / set: the handle of the site author to create or change
141
142
  * deletePagePath, // pages delete: the one tracked page to delete
142
143
  * pageId, // preview page: the one persisted draft UUID to render
143
144
  * previewIds, // preview revoke: [page UUID, snapshot UUID]
@@ -175,6 +176,7 @@ export const VERB_HANDLERS = Object.freeze({
175
176
  [VERB_PAGES_DELETE]: pagesDelete,
176
177
  [VERB_AUTHORS_LIST]: authorsList,
177
178
  [VERB_AUTHORS_ADD]: authorsAdd,
179
+ [VERB_AUTHORS_SET]: authorsSet,
178
180
  [VERB_NAV_PUSH]: navPush,
179
181
  [VERB_PLAN]: plan,
180
182
  [VERB_PLACES_SEARCH]: placesSearch,