@taprootio/site-authoring 0.62.0 → 0.64.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 (69) hide show
  1. package/README.md +63 -23
  2. package/package.json +2 -2
  3. package/src/api.js +149 -21
  4. package/src/appearance-contract.js +9 -0
  5. package/src/article-end-settings.js +295 -0
  6. package/src/changelog.json +39 -0
  7. package/src/chrome-input.js +1 -1
  8. package/src/cli.js +110 -26
  9. package/src/constants.js +7 -0
  10. package/src/content/components.js +130 -14
  11. package/src/content/cta-decoration-paint.js +321 -0
  12. package/src/content/form-placement-presentation.js +91 -0
  13. package/src/content/form-placement-presentation.json +6 -0
  14. package/src/content/free-form-section-registry.json +19 -1
  15. package/src/content/free-form-sections.js +64 -55
  16. package/src/content/markdown.js +13 -0
  17. package/src/content/tiptap-prosemirror.ts +72 -59
  18. package/src/content/validate-document.js +2 -0
  19. package/src/cta-artwork-warnings.js +164 -0
  20. package/src/errors.js +6 -0
  21. package/src/field-schema.json +6 -2
  22. package/src/field-validation.js +14 -5
  23. package/src/footer-workspace.js +7 -3
  24. package/src/form-references.js +71 -9
  25. package/src/forms-contract.js +3 -5
  26. package/src/heading-outline.js +7 -0
  27. package/src/output.js +2 -0
  28. package/src/page-article-end.js +66 -0
  29. package/src/page-block-catalog.js +54 -0
  30. package/src/page-form-presentation.js +104 -0
  31. package/src/page-structure-checks.js +7 -1
  32. package/src/placed-image-ids.js +15 -18
  33. package/src/presentation-reference.js +30 -52
  34. package/src/reference-help.js +97 -27
  35. package/src/reusable-blocks.js +429 -0
  36. package/src/reusable-placements.js +271 -0
  37. package/src/setting-reference.js +25 -1
  38. package/src/settings-catalog.js +1 -0
  39. package/src/site-check-findings.js +30 -2
  40. package/src/site-check-rules.json +1 -0
  41. package/src/site-checks.js +26 -2
  42. package/src/site-health-findings.js +25 -3
  43. package/src/site-health-image-checks.js +1 -1
  44. package/src/staging-check.js +108 -21
  45. package/src/staging-served.js +5 -49
  46. package/src/status-warning-paints.js +17 -0
  47. package/src/template-token-reach.json +14 -2
  48. package/src/theme-resolve.js +27 -0
  49. package/src/transport.js +41 -5
  50. package/src/typed-page-reference.js +55 -5
  51. package/src/typed-pages.js +27 -4
  52. package/src/verbs/approve.js +2 -1
  53. package/src/verbs/deploy.js +93 -15
  54. package/src/verbs/footer-push.js +4 -2
  55. package/src/verbs/forms-push.js +9 -0
  56. package/src/verbs/health.js +11 -6
  57. package/src/verbs/index.js +3 -0
  58. package/src/verbs/pages-blocks-pull.js +22 -0
  59. package/src/verbs/pages-push.js +89 -34
  60. package/src/verbs/plan.js +34 -5
  61. package/src/verbs/pull.js +213 -124
  62. package/src/verbs/status.js +20 -2
  63. package/src/verbs/theme-push.js +164 -14
  64. package/src/verbs/theme-resolve.js +114 -40
  65. package/src/verbs/validate.js +49 -18
  66. package/src/workspace-check.js +42 -5
  67. package/src/workspace-context-usage.js +54 -1
  68. package/src/workspace.js +37 -7
  69. package/test/fixtures/default-site-theme.json +1 -1
@@ -1,11 +1,57 @@
1
- import { getSiteRedirectMap, mintStagingPreviewHandoff } from "./api.js";
2
- import { CLI_BINARY_NAME } from "./constants.js";
3
- import { sanitizeDiagnostic, SiteAuthoringError } from "./errors.js";
1
+ import { getStagedSiteRedirectMap, mintStagingPreviewHandoff } from "./api.js";
2
+ import { boundedByBytes } from "./session.js";
3
+ import { CLI_BINARY_NAME, LIMITS } from "./constants.js";
4
+ import { isCanonicalUuid, sanitizeDiagnostic, SiteAuthoringError } from "./errors.js";
4
5
 
5
6
  const COOKIE = "__Host-taproot_staging_preview";
6
7
  const CHECK = "__taproot_preview_check";
7
8
  const TIMEOUT = 5_000;
8
9
  const REPORT_BYTES = 28_000;
10
+ const IDENTITY_ATTRIBUTE = /\sdata-review-identity="([^"]{1,200})"/u;
11
+
12
+ /** The release a staged HTML document says it came from, or null when it names none. */
13
+ export function parseServedStagingRelease(html) {
14
+ const attribute = IDENTITY_ATTRIBUTE.exec(html)?.[1];
15
+ if (attribute === undefined) return null;
16
+ try {
17
+ const identity = JSON.parse(attribute.replaceAll(""", "\""));
18
+ if (Array.isArray(identity) && identity.length === 2 && identity[0] === "staging" && isCanonicalUuid(identity[1])) {
19
+ return identity[1];
20
+ }
21
+ } catch {
22
+ // An unreadable stamp is the same as no stamp.
23
+ }
24
+ return null;
25
+ }
26
+
27
+ /**
28
+ * The release a staged response names, reading at most `maximumBytes` of its body and
29
+ * stopping at the first stamp. A body past the bound is cut, which loses the stamp rather
30
+ * than memory.
31
+ */
32
+ export async function readServedStagingRelease(response, maximumBytes = LIMITS.stagingServedPageBytes) {
33
+ return parseServedStagingRelease(await readBoundedText(response, maximumBytes));
34
+ }
35
+
36
+ async function readBoundedText(response, maximumBytes) {
37
+ if (!response.body) return "";
38
+ const reader = response.body.getReader();
39
+ const decoder = new TextDecoder();
40
+ let text = "";
41
+ let bytes = 0;
42
+ try {
43
+ for (;;) {
44
+ const { done, value } = await reader.read();
45
+ if (done) break;
46
+ bytes += value.byteLength;
47
+ text += decoder.decode(value, { stream: true });
48
+ if (bytes >= maximumBytes || IDENTITY_ATTRIBUTE.test(text)) break;
49
+ }
50
+ } finally {
51
+ await reader.cancel().catch(() => {});
52
+ }
53
+ return text;
54
+ }
9
55
 
10
56
  async function send(client, url, cookie, signal, userAgent) {
11
57
  return await client.fetch(url, {
@@ -79,28 +125,51 @@ function safeLocation(value) {
79
125
  return sanitizeDiagnostic(value, "");
80
126
  }
81
127
 
82
- /** Check the current redirect-map revision at the real edge from the Node CLI. */
83
- export async function checkStagingRedirects(client, siteId, onProgress, now) {
84
- const map = await getSiteRedirectMap(client, siteId);
128
+ function stagingRoute(origin, route) {
129
+ if (
130
+ !route.startsWith("/") || route.startsWith("//") || route.includes("\\")
131
+ || /[?#\u0000-\u001f\u007f]/u.test(route)
132
+ ) throw unavailable();
133
+ const url = new URL(route, `${origin}/`);
134
+ if (
135
+ url.origin !== origin || url.pathname !== route || url.username || url.password || url.hash
136
+ || [...url.searchParams.keys()].some((key) => key.startsWith("__taproot_preview_"))
137
+ ) throw unavailable();
138
+ return url;
139
+ }
140
+
141
+ async function readRedirectCheckRelease(client, origin, path, cookie, signal, allowNotFound) {
142
+ const response = await send(client, stagingRoute(origin, path).href, cookie, signal, "taproot-site/staging-redirect-release-check");
143
+ if (response.status === 200 || (allowNotFound && response.status === 404)) return await readServedStagingRelease(response);
144
+ await response.body?.cancel().catch(() => {});
145
+ return null;
146
+ }
147
+
148
+ /** Check the acknowledged staging redirect map at the edge. */
149
+ export async function checkStagingRedirects(client, siteId, onProgress, now, expectedDeploymentId) {
150
+ const map = await getStagedSiteRedirectMap(client, siteId);
151
+ if (expectedDeploymentId !== undefined && expectedDeploymentId !== map.deploymentId) {
152
+ throw new SiteAuthoringError("staging.release_changed", "A different staging deployment is acknowledged now. Review the current stage.");
153
+ }
85
154
  const handoff = await mintStagingPreviewHandoff(client, siteId, { now });
86
155
  const signal = client.timeoutSignal(90_000);
87
156
  const cookie = await authorize(client, handoff, signal);
88
157
  const origin = new URL(handoff.stagingUrl).origin;
158
+ const waitingPath = map.pathsWaitingForMove[0];
159
+ const allowNotFound = waitingPath === undefined;
160
+ let releasePath = waitingPath ?? "/";
161
+ let servedBefore = await readRedirectCheckRelease(client, origin, releasePath, cookie, signal, allowNotFound);
162
+ if (servedBefore === null && allowNotFound) {
163
+ releasePath = "/404.html";
164
+ servedBefore = await readRedirectCheckRelease(client, origin, releasePath, cookie, signal, allowNotFound);
165
+ }
89
166
  const rows = new Array(map.entries.length);
90
167
  let next = 0;
91
168
  await Promise.all(Array.from({ length: Math.min(8, map.entries.length) }, async () => {
92
169
  while (next < map.entries.length) {
93
170
  const index = next++;
94
171
  const entry = map.entries[index];
95
- if (
96
- !entry.path.startsWith("/") || entry.path.startsWith("//") || entry.path.includes("\\")
97
- || /[?#\u0000-\u001f\u007f]/u.test(entry.path)
98
- ) throw unavailable();
99
- const url = new URL(entry.path, `${origin}/`);
100
- if (
101
- url.origin !== origin || url.pathname !== entry.path || url.username || url.password || url.hash
102
- || [...url.searchParams.keys()].some((key) => key.startsWith("__taproot_preview_"))
103
- ) throw unavailable();
172
+ const url = stagingRoute(origin, entry.path);
104
173
  let row;
105
174
  try {
106
175
  const response = await request(client, url.href, cookie, signal);
@@ -134,11 +203,19 @@ export async function checkStagingRedirects(client, siteId, onProgress, now) {
134
203
  );
135
204
  }
136
205
  }));
137
- const latest = await getSiteRedirectMap(client, siteId);
138
- const revisionUnchanged = latest.revision === map.revision;
206
+ const servedAfter = await readRedirectCheckRelease(client, origin, releasePath, cookie, signal, allowNotFound);
207
+ const stagingReleaseVerified = servedBefore === map.outputReleaseId && servedAfter === map.outputReleaseId;
208
+ const latest = await getStagedSiteRedirectMap(client, siteId);
209
+ const revisionUnchanged = latest.deploymentId === map.deploymentId && latest.outputReleaseId === map.outputReleaseId
210
+ && latest.revision === map.revision;
211
+ const waitingPaths = boundedByBytes(map.pathsWaitingForMove.map((path) => sanitizeDiagnostic(path, "")), 4096);
212
+ const waitingForMove = map.pathsWaitingForMove.length === 0 ? undefined : {
213
+ total: map.pathsWaitingForMove.length,
214
+ ...waitingPaths,
215
+ };
139
216
  const failed = rows.filter((row) => !row.matches).length;
140
217
  const items = [];
141
- let bytes = 2;
218
+ let bytes = 2 + (waitingForMove === undefined ? 0 : Buffer.byteLength(JSON.stringify(waitingForMove), "utf8"));
142
219
  // Include failures first when a large map exceeds the JSON output budget.
143
220
  for (const row of [...rows.filter((row) => !row.matches), ...rows.filter((row) => row.matches)]) {
144
221
  const size = Buffer.byteLength(JSON.stringify(row), "utf8") + 1;
@@ -152,11 +229,13 @@ export async function checkStagingRedirects(client, siteId, onProgress, now) {
152
229
  redirects: {
153
230
  revision: map.revision,
154
231
  revisionUnchanged,
232
+ stagingReleaseVerified,
233
+ ...(waitingForMove === undefined ? {} : { waitingForMove }),
155
234
  total: rows.length,
156
235
  checked: rows.length,
157
236
  matched: rows.length - failed,
158
237
  failed,
159
- verified: revisionUnchanged && failed === 0,
238
+ verified: stagingReleaseVerified && revisionUnchanged && failed === 0,
160
239
  items,
161
240
  ...(items.length < rows.length ? { itemsTruncated: true } : {}),
162
241
  },
@@ -192,13 +271,21 @@ export async function inspectStagingPreview(
192
271
  siteId,
193
272
  onProgress,
194
273
  now,
195
- { handoff = false, returnPath = "/" } = {},
274
+ { handoff = false, returnPath = "/", expectedDeploymentId } = {},
196
275
  ) {
197
276
  let routeCheck;
198
277
  let redirects;
199
278
  let stagingUrl;
200
279
  try {
201
- ({ routeCheck, redirects, stagingUrl } = await checkStagingRedirects(client, siteId, onProgress, now));
280
+ ({ routeCheck, redirects, stagingUrl } = await checkStagingRedirects(client, siteId, onProgress, now, expectedDeploymentId));
281
+ if (!redirects.stagingReleaseVerified) {
282
+ onProgress("Warning: staging did not show the acknowledged release. Run 'taproot-site redirects check' once the new release is served.");
283
+ }
284
+ if (redirects.waitingForMove !== undefined) {
285
+ onProgress(
286
+ `${redirects.waitingForMove.total} redirect source(s) still serve a folder index. Stage the page moves to activate them.`,
287
+ );
288
+ }
202
289
  if (!redirects.verified) {
203
290
  onProgress(
204
291
  "Warning: staging redirects are not all verified. Check the reported mismatches against the staged release; run 'taproot-site redirects check' again once the deployment has completed.",
@@ -8,8 +8,9 @@ import {
8
8
  poll,
9
9
  } from "./api.js";
10
10
  import { LIMITS } from "./constants.js";
11
- import { isCanonicalUuid, SiteAuthoringError } from "./errors.js";
12
- import { authorizeStagingHandoff, fetchStagingPage } from "./staging-check.js";
11
+ import { SiteAuthoringError } from "./errors.js";
12
+ import { authorizeStagingHandoff, fetchStagingPage, readServedStagingRelease } from "./staging-check.js";
13
+ export { parseServedStagingRelease, readServedStagingRelease } from "./staging-check.js";
13
14
  import { ApiError } from "./transport.js";
14
15
 
15
16
  /**
@@ -24,62 +25,17 @@ import { ApiError } from "./transport.js";
24
25
  * that stamp and waits until it changes, instead of letting a reviewer open the
25
26
  * previous version.
26
27
  *
27
- * The CLI cannot learn the new deployment's release id (the public deployment
28
- * record does not carry a Standard site's), so it compares against what staging
28
+ * The deployment record does not carry the new output's release id, so this
29
+ * wait compares against what staging
29
30
  * served before the deployment was sent. That comparison is only sound when the
30
31
  * edge had settled on the previous release, which the caller checks.
31
32
  */
32
33
 
33
- const IDENTITY_ATTRIBUTE = /\sdata-review-identity="([^"]{1,200})"/u;
34
34
  // The read before the deploy is bounded so a slow host cannot hold up sending it.
35
35
  const BEFORE_READ_MILLISECONDS = 15_000;
36
36
  // The deployments listing that tells whether the previous deployment has settled has its own budget.
37
37
  const PREVIOUS_DEPLOYMENT_MILLISECONDS = 10_000;
38
38
 
39
- /** The release a staged HTML document says it came from, or null when it names none. */
40
- export function parseServedStagingRelease(html) {
41
- const attribute = IDENTITY_ATTRIBUTE.exec(html)?.[1];
42
- if (attribute === undefined) return null;
43
- try {
44
- const identity = JSON.parse(attribute.replaceAll("&quot;", "\""));
45
- if (Array.isArray(identity) && identity.length === 2 && identity[0] === "staging" && isCanonicalUuid(identity[1])) {
46
- return identity[1];
47
- }
48
- } catch {
49
- // An unreadable stamp is the same as no stamp.
50
- }
51
- return null;
52
- }
53
-
54
- /**
55
- * The release a staged response names, reading at most `maximumBytes` of its body and
56
- * stopping at the first stamp. A body past the bound is cut, which loses the stamp rather
57
- * than memory.
58
- */
59
- export async function readServedStagingRelease(response, maximumBytes = LIMITS.stagingServedPageBytes) {
60
- return parseServedStagingRelease(await readBoundedText(response, maximumBytes));
61
- }
62
-
63
- async function readBoundedText(response, maximumBytes) {
64
- if (!response.body) return "";
65
- const reader = response.body.getReader();
66
- const decoder = new TextDecoder();
67
- let text = "";
68
- let bytes = 0;
69
- try {
70
- for (;;) {
71
- const { done, value } = await reader.read();
72
- if (done) break;
73
- bytes += value.byteLength;
74
- text += decoder.decode(value, { stream: true });
75
- if (bytes >= maximumBytes || IDENTITY_ATTRIBUTE.test(text)) break;
76
- }
77
- } finally {
78
- await reader.cancel().catch(() => {});
79
- }
80
- return text;
81
- }
82
-
83
39
  // Every network step of a read ends by the read's deadline, not only the API call.
84
40
  function deadlineSignal(client, now, deadline) {
85
41
  return deadline === undefined ? undefined : client.timeoutSignal(Math.max(1, deadline - now()));
@@ -30,6 +30,23 @@ function familiesIn(warning) {
30
30
  const CONTEXT_SCOPE = /^(?:light|dark): contexts\.([^:]+): /u;
31
31
  export const UNUSED_CONTEXT_NOTE = "no use found in this workspace";
32
32
 
33
+ const longestUsageCounts = {
34
+ header: false,
35
+ footer: false,
36
+ listingCards: false,
37
+ sections: Number.MAX_SAFE_INTEGER,
38
+ ctas: Number.MAX_SAFE_INTEGER,
39
+ };
40
+ const warningUsageBytes = Math.max(
41
+ Buffer.byteLength(JSON.stringify({ usedBy: longestUsageCounts })),
42
+ Buffer.byteLength(JSON.stringify({ usedBy: null, usedByNote: UNUSED_CONTEXT_NOTE })),
43
+ ) - 1;
44
+
45
+ /** Hold the same room for counts before fitting a theme report with or without page evidence. */
46
+ export function warningUsageByteReserve(records) {
47
+ return records.filter(({ warning }) => CONTEXT_SCOPE.test(warning)).length * warningUsageBytes;
48
+ }
49
+
33
50
  /**
34
51
  * The warnings whose record groups fit the bound, each with its families. A warning keeps all of its records or
35
52
  * none: once a group would pass the bound, it and every later one are left out.
@@ -21,6 +21,15 @@
21
21
  {"token": "--esp-color-layer-2", "file": "generator/client/pages/card-grid/taproot-card-grid.ts", "markup": ":host(:not([interaction=\"none\"])) ::slotted(a.card-item:focus-visible)", "part": "background", "label": "card item fill", "topics": ["free-form", "article", "album", "recipe", "place-review", "legal", "generated"]},
22
22
  {"token": "intent:danger", "file": "generator/client/pages/cta/taproot-cta.ts", "markup": "esp-button[class=\"cta__button\"]", "part": "intent", "label": "destructive call-to-action button", "topics": ["free-form", "article", "album", "recipe", "place-review", "legal", "generated"]},
23
23
  {"token": "--esp-color-background", "file": "generator/client/pages/cta/taproot-cta.ts", "markup": ":host([context]:not([context=\"\"])) .cta", "part": "background", "label": "cta panel fill from its context", "topics": ["free-form", "article", "album", "recipe", "place-review", "legal", "generated"]},
24
+ {"token": "--esp-color-background", "file": "generator/client/pages/cta/taproot-cta.ts", "markup": ":host([data-cta-art]) .cta", "part": "background", "label": "cta panel fill behind artwork", "topics": ["free-form", "article", "album", "recipe", "place-review", "legal", "generated"]},
25
+ {"token": "--esp-color-background", "file": "generator/src/cta-decoration-paint.ts", "markup": ".cta-art::after", "part": "background", "label": "cta artwork scrim", "topics": ["free-form", "article", "album", "recipe", "place-review", "legal", "generated"]},
26
+ {"token": "--esp-color-background", "file": "generator/src/cta-decoration-paint.ts", "markup": "taproot-cta:not(:defined)[data-cta-art]", "part": "background", "label": "cta artwork panel fill before upgrade", "topics": ["free-form", "article", "album", "recipe", "place-review", "legal", "generated"]},
27
+ {"token": "--esp-color-border", "file": "generator/src/cta-decoration-paint.ts", "markup": "taproot-cta:not(:defined)[data-cta-art]", "part": "border", "label": "cta artwork panel border before upgrade", "topics": ["free-form", "article", "album", "recipe", "place-review", "legal", "generated"]},
28
+ {"token": "--esp-color-link", "file": "generator/src/cta-decoration-paint.ts", "markup": "styles", "part": "--taproot-cta-art-tint", "label": "cta artwork accent tint", "topics": ["free-form", "article", "album", "recipe", "place-review", "legal", "generated"]},
29
+ {"token": "--esp-color-headings", "file": "generator/src/cta-decoration-paint.ts", "markup": "styles", "part": "--taproot-cta-art-tint", "label": "cta artwork heading tint", "topics": ["free-form", "article", "album", "recipe", "place-review", "legal", "generated"]},
30
+ {"token": "--esp-color-text", "file": "generator/src/cta-decoration-paint.ts", "markup": "styles", "part": "--taproot-cta-art-tint", "label": "cta artwork text tint", "topics": ["free-form", "article", "album", "recipe", "place-review", "legal", "generated"]},
31
+ {"token": "--esp-color-action-background", "file": "generator/src/cta-decoration-paint.ts", "markup": "styles", "part": "--taproot-cta-art-tint", "label": "cta artwork action tint", "topics": ["free-form", "article", "album", "recipe", "place-review", "legal", "generated"]},
32
+ {"token": "--esp-color-border", "file": "generator/src/cta-decoration-paint.ts", "markup": "styles", "part": "--taproot-cta-art-tint", "label": "cta artwork border tint", "topics": ["free-form", "article", "album", "recipe", "place-review", "legal", "generated"]},
24
33
  {"token": "--esp-color-border", "file": "generator/client/pages/cta/taproot-cta.ts", "markup": ".cta--bordered", "part": "border", "label": "cta bordered border", "topics": ["free-form", "article", "album", "recipe", "place-review", "legal", "generated"]},
25
34
  {"token": "--esp-color-link","file": "generator/src/article-appearance-css.ts","markup": "subtle","part": "CSS value","label": "article inline code tint","topics": ["article"]},
26
35
  {"token": "--esp-color-layer-1","file": "generator/src/article-appearance-css.ts","markup": "layer1","part": "CSS value","label": "article inline code layer 1 background","topics": ["article"]},
@@ -203,8 +212,10 @@
203
212
  {"token": "--esp-color-link", "file": "generator/src/templates/page-shell.css", "markup": ".taproot-table-scroll a", "part": "color", "label": "table scroll ink", "topics": ["free-form", "article", "album", "recipe", "place-review", "legal", "generated"]},
204
213
  {"token": "--esp-color-layer-1", "file": "generator/src/templates/page-shell.css", "markup": ".taproot-comments-section", "part": "--esp-section-background", "label": "comments section fill", "topics": []},
205
214
  {"token": "--esp-color-border", "file": "generator/src/templates/page-shell.css", "markup": ".taproot-comments-section:has(taproot-comments)", "part": "border-block-start", "label": "comments section top border", "topics": []},
206
- {"token": "--esp-color-shadow", "file": "generator/src/templates/page-shell.css", "markup": "div.taproot-form__surface, esp-box.taproot-form__surface:not(:defined)", "part": "box-shadow via --esp-shadow-1", "label": "form surface shadow", "topics": ["free-form", "article", "album", "recipe", "place-review", "legal", "generated"]},
207
- {"token": "--esp-color-border", "file": "generator/src/templates/page-shell.css", "markup": ".taproot-form__surface--border", "part": "border", "label": "form surface border border", "topics": ["free-form", "article", "album", "recipe", "place-review", "legal", "generated"]},
215
+ {"token": "--esp-color-shadow", "file": "generator/src/templates/page-shell.css", "markup": "esp-box.taproot-form__surface:not(:defined)", "part": "box-shadow via --esp-shadow-1", "label": "form surface shadow", "topics": ["free-form", "article", "album", "recipe", "place-review", "legal", "generated"]},
216
+ {"token": "--esp-color-layer-2", "file": "generator/src/templates/page-shell.css", "markup": "esp-box[data-surface=\"elevated\"]", "part": "--taproot-form-fallback-background", "label": "form fill within elevated section", "topics": ["free-form", "article", "album", "recipe", "place-review", "legal", "generated"]},
217
+ {"token": "--esp-color-layer-1", "file": "generator/src/templates/page-shell.css", "markup": "esp-box.taproot-form__surface:not(:defined):not([transparent])", "part": "background-color", "label": "form surface fill", "topics": ["free-form", "article", "album", "recipe", "place-review", "legal", "generated"]},
218
+ {"token": "--esp-color-border", "file": "generator/src/templates/page-shell.css", "markup": "esp-box.taproot-form__surface--border", "part": "border", "label": "form surface border", "topics": ["free-form", "article", "album", "recipe", "place-review", "legal", "generated"]},
208
219
  {"token": "--esp-color-text", "file": "generator/src/templates/page-shell.css", "markup": ".taproot-form__legend, .taproot-form__staging", "part": "color", "label": "form staging ink", "topics": ["free-form", "article", "album", "recipe", "place-review", "legal", "generated"]},
209
220
  {"token": "--esp-color-danger-text", "file": "generator/src/templates/page-shell.css", "markup": ".taproot-form__form-error", "part": "color", "label": "form form error ink", "topics": ["free-form", "article", "album", "recipe", "place-review", "legal", "generated"]},
210
221
  {"token": "--esp-color-link", "file": "generator/src/templates/page-shell.css", "markup": ":where(.taproot-social-links) .taproot-social-links__link", "part": "color", "label": "social links link ink", "topics": ["free-form", "article", "album", "recipe", "place-review", "legal", "generated"]},
@@ -235,6 +246,7 @@
235
246
  {"token": "--esp-color-text", "file": "generator/src/templates/recipe/recipe.vto", "markup": ".recipe-card-description", "part": "color", "label": "recipe card description ink", "topics": ["recipe"]},
236
247
  {"token": "intent:neutral", "file": "generator/src/site-footer.ts", "markup": "esp-button", "part": "intent", "label": "footer button", "topics": ["free-form", "article", "album", "recipe", "place-review", "legal", "generated"]},
237
248
  {"token": "--esp-color-background", "file": "generator/src/tiptap-prosemirror.ts", "markup": "renderSection", "part": "--esp-section-background", "label": "section background", "topics": ["free-form"]},
249
+ {"token": "--esp-color-border", "file": "generator/src/tiptap-prosemirror.ts", "markup": "renderSection", "part": "border-block-start", "label": "section top border", "topics": ["free-form"]},
238
250
  {"token": "--esp-color-layer-2", "file": "generator/src/tiptap-prosemirror.ts", "markup": "style", "part": "--esp-color-box-background", "label": "section card fill", "topics": ["free-form"]},
239
251
  {"token": "--esp-color-shadow", "file": "generator/src/tiptap-prosemirror.ts", "markup": "style", "part": "--esp-box-shadow via --esp-shadow-2", "label": "section card shadow", "topics": ["free-form"]},
240
252
  {"token": "--esp-color-link", "file": "generator/src/tiptap-prosemirror.ts", "markup": "normalizedSectionDecorationStyle", "part": "--esp-section-decoration-color", "label": "section decoration color", "topics": ["free-form"]},
@@ -392,6 +392,31 @@ function surfaceName(context) {
392
392
  return context === null ? "page (root)" : `context ${context}`;
393
393
  }
394
394
 
395
+ export const TEXT_CONTEXT_USAGE = Symbol("theme-resolve.textContextUsage");
396
+ export const CONTEXT_USAGE_OMITTED_LINE = "Context usage was omitted from the JSON output.";
397
+
398
+ function contextUsageLines(result) {
399
+ const report = result[TEXT_CONTEXT_USAGE] ?? result.contextUsage;
400
+ if (report === undefined) return result.contextUsageOmitted ? [CONTEXT_USAGE_OMITTED_LINE] : [];
401
+ const { scope, status, contexts, reason, omitted, narrowWith } = report;
402
+ const setting = (value) => value === null ? "unknown" : value ? "yes" : "no";
403
+ const lines = [`Context usage (${scope}, page evidence ${status}${reason === undefined ? "" : `: ${reason}`})`];
404
+ if (scope === "site") lines.push("Page sources were not read in site mode.");
405
+ if (status === "partial") lines.push("Counts cover the page sources that were read and validated.");
406
+ for (const { context, usedBy } of contexts) {
407
+ const { header, footer, listingCards, sections, ctas } = usedBy;
408
+ lines.push(` ${context}: header ${setting(header)}, footer ${setting(footer)}, listing cards ${setting(listingCards)}, `
409
+ + `sections ${sections ?? "unknown"}, calls to action ${ctas ?? "unknown"}`);
410
+ }
411
+ if (omitted > 0) {
412
+ lines.push(result.contextUsage === undefined
413
+ ? CONTEXT_USAGE_OMITTED_LINE
414
+ : `${omitted} context usage row(s) omitted from the JSON output.`);
415
+ if (narrowWith !== undefined) lines.push(`Use '${narrowWith}' to request one context.`);
416
+ }
417
+ return lines;
418
+ }
419
+
395
420
  /**
396
421
  * The human table for a result. Tokens keep Espalier's own order, so a
397
422
  * background and its layers read together; a pinned or inherited value is
@@ -487,6 +512,8 @@ export function formatThemeResolve(result) {
487
512
  }
488
513
  }
489
514
  if (result.contextUsageSkipped !== undefined) lines.push("", ...notCountedLine(result.contextUsageSkipped));
515
+ const usage = contextUsageLines(result);
516
+ if (usage.length > 0) lines.push("", ...usage);
490
517
  if (result.chromeUnavailable) lines.push("", CHROME_UNAVAILABLE_MESSAGE);
491
518
  if (result.chromeNavigationUnavailable) lines.push("", CHROME_NAVIGATION_UNAVAILABLE_MESSAGE);
492
519
  if (result.skippedNavigationLinks !== undefined) lines.push("", describeSkippedLinks(result.skippedNavigationLinks));
package/src/transport.js CHANGED
@@ -24,6 +24,8 @@ import {
24
24
  REFUSAL_UNCLASSIFIED,
25
25
  ROLLOUT_REFUSAL_FIELD,
26
26
  SITE_DEPLOYMENT_REFUSAL_DOMAIN,
27
+ STAGED_RELEASE_STAGE_AGAIN_REFUSAL_REASON,
28
+ STAGED_RELEASE_UPDATING_REFUSAL_REASON,
27
29
  } from "./constants.js";
28
30
  import { Readable } from "node:stream";
29
31
 
@@ -184,7 +186,7 @@ const REPLACEABLE_POST_PATHS = Object.freeze([
184
186
  "u",
185
187
  ),
186
188
  /^v1\/site-authoring\/cli-authorizations\/claim$/u,
187
- new RegExp(`^v1/sites/${UUID_PATH}/presentation$`, "u"),
189
+ new RegExp(`^v1/sites/${UUID_PATH}/(?:structured-)?presentation$`, "u"),
188
190
  ]);
189
191
 
190
192
  /**
@@ -470,6 +472,30 @@ export function planLimitRefusal(value) {
470
472
  });
471
473
  }
472
474
 
475
+ function stagedReleasePromotionRefusal(value) {
476
+ return findErrorInfo(value, (detail) => {
477
+ const stageAgain = detail.reason === STAGED_RELEASE_STAGE_AGAIN_REFUSAL_REASON;
478
+ if (detail.domain !== SITE_DEPLOYMENT_REFUSAL_DOMAIN
479
+ || (!stageAgain && detail.reason !== STAGED_RELEASE_UPDATING_REFUSAL_REASON)) return undefined;
480
+
481
+ return { stageAgain, stageAgainReason: stageAgain ? detail.metadata?.stage_again_reason : undefined };
482
+ });
483
+ }
484
+
485
+ const STAGING_RESET_REFUSALS = Object.freeze({
486
+ STAGING_RESET_UNSUPPORTED: "deploy.reset_unsupported",
487
+ STAGING_RESET_NO_PRODUCTION: "deploy.reset_no_production",
488
+ STAGING_RESET_NOT_PROMOTABLE: "deploy.reset_not_promotable",
489
+ STAGING_RESET_ROLLOUT: "deploy.reset_unavailable",
490
+ });
491
+
492
+ function stagingResetRefusal(value) {
493
+ return findErrorInfo(value, (detail) => detail.domain === SITE_DEPLOYMENT_REFUSAL_DOMAIN
494
+ && Object.hasOwn(STAGING_RESET_REFUSALS, detail.reason)
495
+ ? STAGING_RESET_REFUSALS[detail.reason]
496
+ : undefined);
497
+ }
498
+
473
499
  /** A page count the server reported as a decimal string, or undefined. */
474
500
  function pageCount(value) {
475
501
  const count = typeof value === "string" && /^[0-9]{1,9}$/u.test(value) ? Number(value) : undefined;
@@ -515,6 +541,12 @@ function parseRetryAfterHeader(headers) {
515
541
  // A site authoring key, or a URL with a query string (which is how a presigned URL carries its signature).
516
542
  const CREDENTIAL_SHAPED = /\btr_[a-z]+_|[a-z][a-z0-9+.-]*:\/\/[^\s]*\?/iu;
517
543
 
544
+ function readableFieldReason(description) {
545
+ return typeof description === "string" && !CREDENTIAL_SHAPED.test(description)
546
+ ? sanitizeDiagnostic(description, "")
547
+ : "";
548
+ }
549
+
518
550
  export class ApiError extends SiteAuthoringError {
519
551
  constructor(httpStatus, body, headers) {
520
552
  const grpcCode = Number.isSafeInteger(body?.code) ? body.code : undefined;
@@ -533,10 +565,7 @@ export class ApiError extends SiteAuthoringError {
533
565
  const descriptions = fieldDescriptions(body);
534
566
  // The site's own reason for the first refused field, already length-capped and control-free (TR01433). A reason
535
567
  // that looks like it carries a key or a signed URL is withheld, since results reach logs and Actions output.
536
- const described = fields.length > 0 ? descriptions.get(fields[0]) : undefined;
537
- const reason = typeof described === "string" && !CREDENTIAL_SHAPED.test(described)
538
- ? sanitizeDiagnostic(described, "")
539
- : "";
568
+ const reason = readableFieldReason(descriptions.get(fields[0]));
540
569
  super(
541
570
  "api.request_rejected",
542
571
  upgradeMessage || (fields.length > 0
@@ -568,6 +597,8 @@ export class ApiError extends SiteAuthoringError {
568
597
  if (reason !== "") this.reason = reason;
569
598
  this.capability = capability;
570
599
  this.planLimit = planLimit;
600
+ this.stagedReleasePromotion = stagedReleasePromotionRefusal(body);
601
+ this.stagingResetRefusal = stagingResetRefusal(body);
571
602
  // The `retry-after` trailer (TR00839's deployment throttle, or any other
572
603
  // ResourceExhausted refusal that sets it) transcodes to an ordinary
573
604
  // response header. Undefined when absent or unparseable — callers must
@@ -592,6 +623,11 @@ export class ApiError extends SiteAuthoringError {
592
623
  return undefined;
593
624
  }
594
625
 
626
+ /** Bounded field text that can safely reach logs and machine-readable results. */
627
+ readableReasonFor(field) {
628
+ return readableFieldReason(this.descriptionFor(field));
629
+ }
630
+
595
631
  /**
596
632
  * The latest published release a `cli_outdated` refusal names, or undefined.
597
633
  * Taproot states it only inside the refusal's sentence, so it is read from
@@ -83,6 +83,13 @@ const FIELD_HELP = Object.freeze({
83
83
  + "the site's setting alone. Only true and false are accepted (pages.show_on_profile_invalid). The profile "
84
84
  + "changes after the page is published and its release goes live. A displayAuthor keeps a page apart entirely.",
85
85
  },
86
+ articleEnd: {
87
+ type: "true or false",
88
+ required: false,
89
+ description:
90
+ "Use false to hide the site's article-end call to action for this page. Omit the value or use true to follow the site rules. "
91
+ + "If the page already exists, pull its current preference before changing it.",
92
+ },
86
93
  coverImage: {
87
94
  type: "media reference",
88
95
  required: false,
@@ -127,6 +134,16 @@ const FIELD_HELP = Object.freeze({
127
134
  },
128
135
  });
129
136
 
137
+ const ARTICLE_INTRO = "We parked at the end of the gravel road and walked the last mile.";
138
+ const ARTICLE_TRANSITION = "The path forks just past the first footbridge.";
139
+ const ARTICLE_CLOSE = "We reached the trailhead just as the sun cleared the ridge.";
140
+ const ARTICLE_FORM = JSON.stringify({ formKey: "newsletter", layout: "compact" });
141
+ const ARTICLE_CTA = JSON.stringify({
142
+ heading: "Plan your hike",
143
+ buttonText: "See the trail guide",
144
+ buttonUrl: "/trail-guide",
145
+ });
146
+
130
147
  const ARTICLE_EXAMPLE = `---
131
148
  title: How we found the trailhead
132
149
  path: journal/how-we-found-the-trailhead
@@ -136,7 +153,19 @@ displayDate: 2023-06-18
136
153
  coverImage: media/trailhead.jpg
137
154
  ---
138
155
 
139
- We parked at the end of the gravel road and walked the last mile.
156
+ ${ARTICLE_INTRO}
157
+
158
+ \`\`\`component:form
159
+ ${ARTICLE_FORM}
160
+ \`\`\`
161
+
162
+ ${ARTICLE_TRANSITION}
163
+
164
+ \`\`\`component:cta
165
+ ${ARTICLE_CTA}
166
+ \`\`\`
167
+
168
+ ${ARTICLE_CLOSE}
140
169
 
141
170
  ![The trailhead at dawn](media/trailhead.jpg)
142
171
  `;
@@ -209,7 +238,8 @@ The espresso is excellent and the pastries sell out by ten.
209
238
  // The id `media upload` records for a file, shown here as a stand-in.
210
239
  const EXAMPLE_IMAGE_ID = "c1c1c1c1-c1c1-4c1c-8c1c-c1c1c1c1c1c1";
211
240
 
212
- const PARAGRAPH = (text) => ({ type: "doc", content: [{ type: "paragraph", content: [{ type: "text", text }] }] });
241
+ const paragraphNode = (text) => ({ type: "paragraph", content: [{ type: "text", text }] });
242
+ const PARAGRAPH = (text) => ({ type: "doc", content: [paragraphNode(text)] });
213
243
 
214
244
  function documentExample(template, extra, data) {
215
245
  return { template, ...extra, data };
@@ -219,12 +249,32 @@ const TYPE_DETAILS = Object.freeze({
219
249
  [TEMPLATE_ARTICLE]: {
220
250
  displayName: "Article",
221
251
  summary: "A dated post: a title, an optional cover image, and a rich-text body. The template for blog posts.",
222
- body: "Everything after the front matter is the article body, in the same Markdown subset as a free-form page.",
252
+ body: "Everything after the front matter is the article body, in the same Markdown subset as a free-form page. "
253
+ + "Between paragraphs, open a Markdown fence with component:form and put {\"formKey\":\"newsletter\",\"layout\":\"compact\"} inside it. "
254
+ + "Use component:cta the same way for a call to action. Either component renders as a block at that position. "
255
+ + "See 'help component form', 'help component cta' and 'help forms'.",
256
+ note: "In .pm.json, put a componentBlock node in data.body.content between paragraphs. Set attrs.componentType "
257
+ + "to form or cta and attrs.componentData to the JSON string for its component fields. A compact Form block needs a required email and one consent field.",
223
258
  markdownExample: ARTICLE_EXAMPLE,
224
259
  documentExample: documentExample(
225
260
  TEMPLATE_ARTICLE,
226
261
  { displayDate: "2023-06-18", coverImageId: EXAMPLE_IMAGE_ID },
227
- { body: PARAGRAPH("We parked at the end of the gravel road and walked the last mile.") },
262
+ {
263
+ body: {
264
+ type: "doc",
265
+ content: [
266
+ paragraphNode(ARTICLE_INTRO),
267
+ { type: "componentBlock", attrs: { componentType: "form", componentData: ARTICLE_FORM } },
268
+ paragraphNode(ARTICLE_TRANSITION),
269
+ { type: "componentBlock", attrs: { componentType: "cta", componentData: ARTICLE_CTA } },
270
+ paragraphNode(ARTICLE_CLOSE),
271
+ {
272
+ type: "taprootImage",
273
+ attrs: { imageId: EXAMPLE_IMAGE_ID, src: "", urls: [], alt: "The trailhead at dawn", width: 1600, height: 900 },
274
+ },
275
+ ],
276
+ },
277
+ },
228
278
  ),
229
279
  dataFields: ["body: ProseMirror document (required, not empty)", "place: UUID of a Taproot place (optional; \"\" clears it)"],
230
280
  },
@@ -542,7 +592,7 @@ function typedReference(type) {
542
592
  purpose: generated
543
593
  ? "The pulled form, and the only one: { template, data }. Path comes from the manifest; title and description "
544
594
  + "are the custom ones in data."
545
- : "The pulled form: { template, displayDate?, displayAuthor?, showOnProfile?, coverImageId?, tags?, data }. tags is "
595
+ : "The pulled form: { template, displayDate?, displayAuthor?, showOnProfile?, articleEnd?, coverImageId?, tags?, data }. tags is "
546
596
  + "the page's authored tag names, where the template takes them; 'status' reports whether Taproot accepts tag "
547
597
  + "writes now. Title, path and description come from the manifest.",
548
598
  dataFields: Object.freeze(details.dataFields),