@taprootio/site-authoring 0.38.1 → 0.40.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.
Files changed (39) hide show
  1. package/README.md +73 -17
  2. package/examples/riverbend-wellness/manifest.fixture.json +1 -1
  3. package/examples/riverbend-wellness/settings/site-publishing-preferences.json +29 -14
  4. package/package.json +2 -2
  5. package/src/api.js +4 -5
  6. package/src/appearance-contract.js +64 -55
  7. package/src/atomic-file.js +2 -1
  8. package/src/changelog.json +37 -0
  9. package/src/cli.js +2 -2
  10. package/src/content/free-form-sections.js +2 -3
  11. package/src/display-scale.js +17 -0
  12. package/src/footer-alignment.js +97 -0
  13. package/src/footer-brand-inputs.js +33 -0
  14. package/src/footer-branding.js +44 -0
  15. package/src/footer-content.js +10 -0
  16. package/src/footer-contract.js +167 -43
  17. package/src/footer-draft-hash.js +26 -27
  18. package/src/footer-fit-widths.js +10 -0
  19. package/src/footer-fit.js +328 -0
  20. package/src/footer-font-metrics.js +8345 -0
  21. package/src/footer-workspace.js +4 -6
  22. package/src/header-presentation.js +17 -15
  23. package/src/logo-inputs.js +38 -0
  24. package/src/logo-surface-checks.js +67 -0
  25. package/src/presentation-reference.js +119 -46
  26. package/src/reference-help.js +3 -3
  27. package/src/setting-reference.js +15 -4
  28. package/src/settings-catalog.js +10 -3
  29. package/src/site-check-findings.js +73 -11
  30. package/src/site-check-rules.json +4 -2
  31. package/src/theme-contexts.js +82 -0
  32. package/src/theme-resolve.js +2 -2
  33. package/src/theme-validation.js +30 -13
  34. package/src/verbs/footer-push.js +20 -9
  35. package/src/verbs/plan.js +2 -2
  36. package/src/verbs/theme-push.js +46 -41
  37. package/src/verbs/validate.js +33 -17
  38. package/src/workspace-check.js +1 -1
  39. package/src/workspace.js +1 -1
@@ -1,15 +1,14 @@
1
1
  import { getSitePresentation, saveSitePresentation, withRefusalGuidance } from "../api.js";
2
2
  import {
3
- APPEARANCE_FOOTER_COLOR_FIELDS,
3
+ APPEARANCE_FOOTER_FIELDS,
4
4
  APPEARANCE_SCALAR_FIELDS,
5
5
  appearanceScalarInput,
6
6
  buildAppearanceScalarOperations,
7
- footerColorOverlay,
7
+ footerPresentationOverlay,
8
8
  } from "../appearance-contract.js";
9
9
  import { REFUSAL_UNCLASSIFIED, VERB_THEME_PUSH } from "../constants.js";
10
10
  import { MISSING_SETTING_MESSAGE, SiteAuthoringError } from "../errors.js";
11
11
  import { projectFooterSettingsForWorkspace } from "../footer-contract.js";
12
- import { computeFooterDraftHash } from "../footer-draft-hash.js";
13
12
  import {
14
13
  advanceFooterManifest,
15
14
  clearPendingPresentationSave,
@@ -30,7 +29,7 @@ import {
30
29
  SETTINGS_TYPE_SITE_PUBLISHING_PREFERENCES,
31
30
  SETTINGS_TYPE_TAPROOT_STYLES,
32
31
  } from "../settings-catalog.js";
33
- import { missingThemeFields, validateAndLintThemePair } from "../theme-validation.js";
32
+ import { missingThemeFields, requireSurfaceContexts, validateAndLintThemePair } from "../theme-validation.js";
34
33
  import { ApiError } from "../transport.js";
35
34
  import {
36
35
  readWorkspaceJson,
@@ -112,8 +111,14 @@ export function requireNoMissingSettings(missing) {
112
111
  );
113
112
  }
114
113
 
115
- /** The complete local validation phase shared by live push and offline fixtures. */
116
- export async function validateThemeWorkspace(workspaceDir, siteId, knownImageIds, expectedEntityIds) {
114
+ /** Offline callers validate context names here; push waits for the current state to classify removals. */
115
+ export async function validateThemeWorkspace(
116
+ workspaceDir,
117
+ siteId,
118
+ knownImageIds,
119
+ expectedEntityIds,
120
+ { deferContextValidation = false } = {},
121
+ ) {
117
122
  const [style, brand, header, publishing] = await Promise.all([
118
123
  readSettingsDocument(
119
124
  workspaceDir,
@@ -146,8 +151,8 @@ export async function validateThemeWorkspace(workspaceDir, siteId, knownImageIds
146
151
  [SETTINGS_TYPE_SITE_HEADER]: header,
147
152
  };
148
153
  // Preflight the complete required-key inventory before any value validator
149
- // can stop at a malformed value in an earlier group. Optional footer color
150
- // leaves retain their existing empty-color fallback.
154
+ // can stop at a malformed value in an earlier group. Optional presentation
155
+ // fields retain their empty default.
151
156
  const missing = missingThemeSettings(style);
152
157
  for (const definition of APPEARANCE_SCALAR_FIELDS) {
153
158
  if (!definition.optional && !Object.hasOwn(documents[definition.settingsType], definition.name)) {
@@ -162,18 +167,26 @@ export async function validateThemeWorkspace(workspaceDir, siteId, knownImageIds
162
167
  }
163
168
  }
164
169
  requireNoMissingSettings(missing);
170
+ const footerPresentation = footerPresentationOverlay(publishing.footerSettings);
171
+ if (!deferContextValidation) {
172
+ requireSurfaceContexts({
173
+ lightTheme: style.lightTheme,
174
+ darkTheme: style.darkTheme,
175
+ headerContext: header.context,
176
+ footerContext: footerPresentation.context,
177
+ });
178
+ }
165
179
  const themes = await validateAndLintThemePair(style.lightTheme, style.darkTheme);
166
180
  const scalarOperations = buildAppearanceScalarOperations(
167
181
  documents,
168
182
  knownImageIds,
169
183
  );
170
- const footerColors = footerColorOverlay(publishing.footerSettings);
171
- return { style, brand, header, publishing, themes, scalarOperations, footerColors };
184
+ return { style, brand, header, publishing, themes, scalarOperations, footerPresentation };
172
185
  }
173
186
 
174
187
  /**
175
188
  * The change set the atomic save receives: every appearance scalar in
176
- * registry order, then the two encoded themes, plus the ten footer colours.
189
+ * registry order, then the two encoded themes, plus the footer presentation fields.
177
190
  */
178
191
  function buildChangeSet(validated) {
179
192
  return {
@@ -189,7 +202,8 @@ function buildChangeSet(validated) {
189
202
  value: setting === "lightTheme" ? validated.themes.light : validated.themes.dark,
190
203
  })),
191
204
  ],
192
- footerColors: validated.footerColors,
205
+ footerContext: validated.footerPresentation.context,
206
+ footerLogoVariant: validated.footerPresentation.logoVariant,
193
207
  };
194
208
  }
195
209
 
@@ -226,14 +240,6 @@ function translateSaveRefusal(error) {
226
240
  { field: "revision", status: error.status },
227
241
  );
228
242
  }
229
- if (error instanceof ApiError && error.hasField("ExpectedFooterDraftHash")) {
230
- return new SiteAuthoringError(
231
- "theme.footer_concurrent_modification",
232
- "The footer document changed between this push's read and its save, so the push was refused and nothing was "
233
- + "written. Run 'taproot-site theme push' again; it re-reads the footer before saving.",
234
- { field: "expectedFooterDraftHash", status: error.status },
235
- );
236
- }
237
243
  return translateServerSupport(error, "save");
238
244
  }
239
245
 
@@ -261,15 +267,11 @@ function ownedDocuments(validated, presentation) {
261
267
  });
262
268
  const scalarNames = (settingsType) =>
263
269
  APPEARANCE_SCALAR_FIELDS.filter((field) => field.settingsType === settingsType).map((field) => field.name);
264
- const footerColors = (footer) => {
265
- const colors = {};
266
- for (const definition of APPEARANCE_FOOTER_COLOR_FIELDS) {
267
- const scheme = isPlainObject(footer?.[definition.scheme]) ? footer[definition.scheme] : {};
268
- colors[definition.scheme] ??= {};
269
- colors[definition.scheme][definition.name] = scheme[definition.name] ?? "";
270
- }
271
- return { footerSettings: colors };
272
- };
270
+ const footerPresentation = footer => ({
271
+ footerSettings: Object.fromEntries(
272
+ APPEARANCE_FOOTER_FIELDS.map(field => [field.name, footer?.[field.name] ?? field.default]),
273
+ ),
274
+ });
273
275
  return [
274
276
  owned(
275
277
  SETTINGS_TYPE_TAPROOT_STYLES,
@@ -286,8 +288,8 @@ function ownedDocuments(validated, presentation) {
286
288
  ),
287
289
  {
288
290
  file: `${SETTINGS_DIRECTORY}/${SETTINGS_FILES[SETTINGS_TYPE_SITE_PUBLISHING_PREFERENCES]}`,
289
- local: footerColors(validated.publishing.footerSettings),
290
- remote: footerColors(projected[SETTINGS_TYPE_SITE_PUBLISHING_PREFERENCES].footerSettings),
291
+ local: footerPresentation(validated.publishing.footerSettings),
292
+ remote: footerPresentation(projected[SETTINGS_TYPE_SITE_PUBLISHING_PREFERENCES].footerSettings),
291
293
  },
292
294
  ];
293
295
  }
@@ -343,6 +345,12 @@ export async function comparePresentation(client, siteId, validated, manifest) {
343
345
  } catch (error) {
344
346
  throw translateServerSupport(error, "read");
345
347
  }
348
+ requireSurfaceContexts({
349
+ lightTheme: validated.style.lightTheme,
350
+ darkTheme: validated.style.darkTheme,
351
+ headerContext: validated.header.context,
352
+ footerContext: validated.footerPresentation.context,
353
+ }, current);
346
354
  const stale = baseline !== undefined && baseline.revision !== current.revision;
347
355
  // A save this workspace sent and never heard back from (TR00807). When the
348
356
  // change set about to go is the same one, a moved revision is not evidence
@@ -383,11 +391,13 @@ export async function themePush(invocation) {
383
391
  config.workspaceDir,
384
392
  siteId,
385
393
  appearanceContext.knownImageIds,
394
+ undefined,
395
+ { deferContextValidation: true },
386
396
  );
387
397
  const { publishing, themes, scalarOperations } = validated;
388
398
  // The save's response replaces the workspace footer document, so refuse
389
399
  // while it still carries footer-content edits that footer push has not
390
- // saved. Colour-only differences are theme push's own to write.
400
+ // saved. Context-only differences are theme push's own to write.
391
401
  requireFooterContentPushed(appearanceContext.footer, publishing.footerSettings);
392
402
  const baseline = readPresentationBaseline(appearanceContext.manifest);
393
403
  if (!dryRun && baseline === undefined) {
@@ -408,7 +418,7 @@ export async function themePush(invocation) {
408
418
  };
409
419
 
410
420
  // The fresh read serves both modes: the dry run compares against it, and
411
- // the push takes the footer document's draft token from it. Nothing before
421
+ // the push checks the complete post-save context state. Nothing before
412
422
  // this point, and nothing in a dry run after it, writes to the site.
413
423
  const comparison = await withRefusalGuidance(
414
424
  onProgress,
@@ -490,16 +500,11 @@ export async function themePush(invocation) {
490
500
  });
491
501
  }
492
502
 
493
- // The footer token comes from the read just made: the server overlays the
494
- // colours onto the document it holds now. On a replay of a committed save
495
- // the site is already current and the token is not consulted.
496
- const currentFooter = current.sitePublishingPreferences?.footerSettings ?? {};
497
503
  let saved;
498
504
  try {
499
505
  saved = await withRefusalGuidance(onProgress, "theme push", async () =>
500
506
  await saveSitePresentation(client, siteId, {
501
507
  expectedRevision,
502
- expectedFooterDraftHash: computeFooterDraftHash(currentFooter),
503
508
  ...changeSet,
504
509
  }));
505
510
  } catch (error) {
@@ -519,7 +524,7 @@ export async function themePush(invocation) {
519
524
  // record is what lets the next run of the same change set be answered as
520
525
  // already current instead of refused as someone else's edit.
521
526
  if (
522
- error instanceof ApiError && (error.hasField("ExpectedRevision") || error.hasField("ExpectedFooterDraftHash"))
527
+ error instanceof ApiError && error.hasField("ExpectedRevision")
523
528
  ) {
524
529
  await clearPendingPresentationSave(config.workspaceDir, siteId);
525
530
  } else {
@@ -560,13 +565,13 @@ export async function themePush(invocation) {
560
565
  });
561
566
  onProgress(
562
567
  applied
563
- ? "Saved the complete presentation in one transaction: footer scheme colors, appearance settings, and both "
568
+ ? "Saved the complete presentation in one transaction: surface contexts and logo choices, appearance settings, and both "
564
569
  + "themes; Brand & Style now treats the color model as externally managed."
565
570
  : "The site already held this presentation; nothing was written and the baseline was refreshed.",
566
571
  );
567
572
 
568
573
  const written = [
569
- "footerSettings.light/dark colors",
574
+ ...APPEARANCE_FOOTER_FIELDS.map(field => `footerSettings.${field.name}`),
570
575
  ...scalarOperations.map((operation) => `${operation.settingsType}.${operation.setting}`),
571
576
  ...THEME_SETTINGS.map((setting) => `${SETTINGS_TYPE_TAPROOT_STYLES}.${setting}`),
572
577
  ];
@@ -16,6 +16,10 @@ import {
16
16
  FIXTURE_ROOT_FIELDS,
17
17
  } from "../fixture-contract.js";
18
18
  import { initializeFixture } from "../fixture-init.js";
19
+ import { evaluateLogoSurfaceChecks } from "../logo-surface-checks.js";
20
+ import { loadThemeEngines } from "../theme-resolve.js";
21
+ import { readFooterBrandInputs } from "../footer-brand-inputs.js";
22
+ import { buildFooterFitInput } from "../footer-fit.js";
19
23
  import { appearanceManifestEntry, footerManifestEntry } from "../footer-workspace.js";
20
24
  import { FORMS_DIRECTORY } from "../forms-contract.js";
21
25
  import { authorWarnings, descriptionWarnings } from "../page-metadata.js";
@@ -24,6 +28,7 @@ import { isRedirectMapRevision, REDIRECT_KIND_GONE, REDIRECTS_FILE_NAME } from "
24
28
  import { boundedList, openSession, successResult } from "../session.js";
25
29
  import {
26
30
  evaluateOfflineSiteChecks,
31
+ mergeOfflineSiteChecks,
27
32
  IMAGE_CHECK_DIRECTORY_ARGUMENT,
28
33
  IMAGE_CHECK_DOCS_SITE,
29
34
  IMAGE_CHECK_NOT_REQUESTED,
@@ -682,16 +687,27 @@ function pageHints(checked, onProgress) {
682
687
  * The offline site checks (TR01085) over the planned pages: the rules the shared
683
688
  * catalogue lists for `validate`, with the rest named as checked by the site.
684
689
  */
685
- function offlineSiteChecks(checked, manifest, onProgress, imageCheck) {
686
- if (checked.settingsOnly) return {};
687
- return evaluateOfflineSiteChecks({
688
- planned: checked.pages?.planned,
689
- pagePaths: manifest.pages.map((entry) => normalizePagePath(entry?.path)).filter((value) => value !== undefined),
690
+ async function offlineSiteChecks(checked, manifest, onProgress, imageCheck, workspaceDir, loadLogoEngines) {
691
+ const footerInput = checked.footer === undefined
692
+ ? undefined
693
+ : buildFooterFitInput(checked.footer.footerSettings, await readFooterBrandInputs(workspaceDir, checked.footer.footerSettings));
694
+ const evaluated = evaluateOfflineSiteChecks({
695
+ planned: checked.settingsOnly ? [] : checked.pages?.planned,
696
+ footerInput,
697
+ footerOnly: checked.settingsOnly,
698
+ pagePaths: checked.settingsOnly ? [] : manifest.pages.map((entry) => normalizePagePath(entry?.path)).filter((value) => value !== undefined),
690
699
  pagesComplete: manifest.pagesTruncated !== true,
691
700
  formKeysChecked: checked.formKeysChecked === true,
692
701
  imageCheck,
693
702
  onProgress,
694
703
  });
704
+ const logos = await evaluateLogoSurfaceChecks({
705
+ styles: checked.presentation?.style,
706
+ header: checked.presentation?.header,
707
+ footer: checked.footer?.footerSettings,
708
+ onProgress,
709
+ }, { loadEngines: loadLogoEngines });
710
+ return mergeOfflineSiteChecks(evaluated, logos);
695
711
  }
696
712
 
697
713
  /**
@@ -736,12 +752,12 @@ function emptyBlock(pages) {
736
752
  };
737
753
  }
738
754
 
739
- export async function validateFixture(invocation = {}) {
755
+ export async function validateFixture(invocation = {}, { loadLogoEngines = loadThemeEngines } = {}) {
740
756
  // Refused before any file is read: a directory, or a fixture to export, has no site to read.
741
757
  if (invocation.fromSite === true && (invocation.init || invocation.fixturePath !== undefined)) {
742
758
  throw siteNeedsWorkspaceError(Boolean(invocation.init));
743
759
  }
744
- if (invocation.init) return await initializeFixture(invocation, validateFixture);
760
+ if (invocation.init) return await initializeFixture(invocation, next => validateFixture(next, { loadLogoEngines }));
745
761
  const onProgress = typeof invocation.onProgress === "function" ? invocation.onProgress : () => {};
746
762
  const cwd = invocation.cwd ?? process.cwd();
747
763
  if (invocation.fixturePath === undefined) {
@@ -753,7 +769,7 @@ export async function validateFixture(invocation = {}) {
753
769
  "siteId",
754
770
  );
755
771
  }
756
- return await validatePulledWorkspace(config.workspaceDir, config.siteId, invocation, onProgress, { config });
772
+ return await validatePulledWorkspace(config.workspaceDir, config.siteId, invocation, onProgress, { config, loadLogoEngines });
757
773
  }
758
774
  const fixtureRoot = await resolveFixtureRoot(cwd, invocation.fixturePath);
759
775
  if (
@@ -764,7 +780,7 @@ export async function validateFixture(invocation = {}) {
764
780
  if (!isCanonicalUuid(siteId)) {
765
781
  fail("workspace.manifest_invalid", `${MANIFEST_FILE_NAME} does not record a canonical site id.`, "siteId");
766
782
  }
767
- return await validatePulledWorkspace(fixtureRoot, siteId, invocation, onProgress, { directoryArgument: true });
783
+ return await validatePulledWorkspace(fixtureRoot, siteId, invocation, onProgress, { directoryArgument: true, loadLogoEngines });
768
784
  }
769
785
 
770
786
  onProgress(`Reading ${FIXTURE_MANIFEST_FILE_NAME}.`);
@@ -828,7 +844,7 @@ export async function validateFixture(invocation = {}) {
828
844
  ...autolinkWarnings(checked.pages?.planned, onProgress),
829
845
  ...descriptionWarnings(checked.pages?.planned, onProgress),
830
846
  ...authorWarnings(checked.pages?.planned, onProgress),
831
- ...offlineSiteChecks(checked, manifest, onProgress, imageCheckSkipped(IMAGE_CHECK_DIRECTORY_ARGUMENT)),
847
+ ...await offlineSiteChecks(checked, manifest, onProgress, imageCheckSkipped(IMAGE_CHECK_DIRECTORY_ARGUMENT), fixtureRoot, loadLogoEngines),
832
848
  };
833
849
  onProgress(
834
850
  `Validated ${validatedPages.length} page(s), ${checked.navigation.items} navigation item(s), two themes, appearance, and footer without credentials or mutation.`,
@@ -870,7 +886,7 @@ export async function validateFixture(invocation = {}) {
870
886
  * runs before it sends anything, for every page and setting at once, against
871
887
  * what the manifests recorded at the pull — no credential and no request.
872
888
  */
873
- async function validatePulledWorkspace(workspaceDir, siteId, invocation, onProgress, { config, directoryArgument = false }) {
889
+ async function validatePulledWorkspace(workspaceDir, siteId, invocation, onProgress, { config, directoryArgument = false, loadLogoEngines }) {
874
890
  onProgress(`Reading ${MANIFEST_FILE_NAME}.`);
875
891
  const manifest = await readManifest(workspaceDir, siteId);
876
892
  const mediaManifest = await readMediaManifest(workspaceDir, siteId);
@@ -893,15 +909,15 @@ async function validatePulledWorkspace(workspaceDir, siteId, invocation, onProgr
893
909
  ? []
894
910
  : checked.pages.planned.map((page) => ({ file: page.file, path: displayPagePath(page.pagePath) }));
895
911
  const hints = pageHints(checked, onProgress);
896
- const warnings = checked.settingsOnly
897
- ? {}
898
- : {
912
+ const warnings = {
913
+ ...(checked.settingsOnly ? {} : {
899
914
  ...autolinkWarnings(checked.pages.planned, onProgress),
900
915
  ...descriptionWarnings(checked.pages.planned, onProgress),
901
916
  ...authorWarnings(checked.pages.planned, onProgress),
902
- ...offlineSiteChecks(checked, manifest, onProgress, site.imageCheck),
903
- };
904
- // A Docs workspace has no `siteChecks` to carry the reason, so it is said at the top level.
917
+ }),
918
+ ...await offlineSiteChecks(checked, manifest, onProgress, site.imageCheck, workspaceDir, loadLogoEngines),
919
+ };
920
+ // The Docs settings checks do not own the skipped image reason reported by --site.
905
921
  const docsReason = checked.settingsOnly && invocation.fromSite === true
906
922
  ? {
907
923
  imageCheckReason: {
@@ -68,7 +68,7 @@ export async function checkWorkspace({
68
68
  ?? await collectProblems(problems, { area: CHECK_AREA.presentation }, async () =>
69
69
  (await readAppearanceWorkspaceContext(workspaceDir, siteId)).knownImageIds);
70
70
 
71
- onProgress("Validating the complete light/dark theme, appearance, header, brand, and footer colors.");
71
+ onProgress("Validating the complete light/dark theme, appearance, header, brand, and surface contexts.");
72
72
  const presentation = knownImageIds === undefined
73
73
  ? undefined
74
74
  : await collectProblems(problems, { area: CHECK_AREA.presentation }, async () =>
package/src/workspace.js CHANGED
@@ -156,7 +156,7 @@ export function internalPageObservedRevisionFile(pageId) {
156
156
  // classified pulled files but recorded no registry. The package is in-repo and
157
157
  // its manifests are workspace state, so an older one is re-pulled rather than
158
158
  // migrated.
159
- export const MANIFEST_VERSION = 7;
159
+ export const MANIFEST_VERSION = 8;
160
160
 
161
161
  /**
162
162
  * The shape of a page body revision as the site reports it: a scheme name and