@taprootio/site-authoring 0.2.0 → 0.3.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.
@@ -1,4 +1,19 @@
1
+ import { readFileSync } from "node:fs";
2
+
3
+ import { TEMPLATE_TYPE_FREE_FORM } from "./api.js";
1
4
  import { CLI_BINARY_NAME } from "./constants.js";
5
+ import {
6
+ FIXTURE_CONTRACT_VERSION,
7
+ FIXTURE_DELIVERY_ORIGIN_DOMAIN,
8
+ FIXTURE_MANIFEST_FILE_NAME,
9
+ FIXTURE_MAXIMUM_DELIVERY_ORIGINS,
10
+ FIXTURE_METADATA_FIELDS,
11
+ FIXTURE_OPTIONAL_ROOT_FIELDS,
12
+ FIXTURE_REQUIRED_ROOT_FIELDS,
13
+ SHIPPED_FIXTURE_NAME,
14
+ shippedFixtureDirectory,
15
+ } from "./fixture-contract.js";
16
+ import { SETTINGS_GROUPS } from "./settings-catalog.js";
2
17
  import {
3
18
  canonicalizeComponentData,
4
19
  COMPONENT_TYPES,
@@ -20,14 +35,21 @@ import {
20
35
  } from "./presentation-reference.js";
21
36
  import {
22
37
  INTERNAL_PAGE_BASELINE_DIRECTORY,
38
+ MANIFEST_VERSION,
39
+ NAVIGATION_FILE_NAME,
23
40
  PAGE_READ_ONLY_REASON_SYSTEM_404,
41
+ PAGE_SOURCE_EXTENSIONS,
42
+ PAGE_WORKSPACE_MODE_EDITABLE,
24
43
  PAGE_WORKSPACE_MODE_READ_ONLY,
44
+ pageSourceFormat,
45
+ PAGES_DIRECTORY,
46
+ SETTINGS_DIRECTORY,
25
47
  SYSTEM_PAGE_NOT_FOUND_PATH,
26
48
  } from "./workspace.js";
27
49
 
28
50
  export { getAppearanceReference, getFooterReference, getThemeReference };
29
51
 
30
- export const REFERENCE_VERSION = 15;
52
+ export const REFERENCE_VERSION = 16;
31
53
  export const PAGE_TYPES = Object.freeze(["free-form"]);
32
54
  export const REFERENCE_TOPICS = Object.freeze([
33
55
  Object.freeze({ name: "pages", usage: `${CLI_BINARY_NAME} help pages`, summary: "List authorable page types." }),
@@ -72,6 +94,11 @@ export const REFERENCE_TOPICS = Object.freeze([
72
94
  usage: `${CLI_BINARY_NAME} help footer`,
73
95
  summary: "Author and concurrency-safely push the complete footer document.",
74
96
  }),
97
+ Object.freeze({
98
+ name: "fixture",
99
+ usage: `${CLI_BINARY_NAME} help fixture`,
100
+ summary: "State the offline fixture manifest contract and locate the shipped example.",
101
+ }),
75
102
  ]);
76
103
 
77
104
  const WORKFLOW_REFERENCES = Object.freeze({
@@ -84,6 +111,8 @@ const WORKFLOW_REFERENCES = Object.freeze({
84
111
  "kind is NAV_ITEM_KIND_PAGE, NAV_ITEM_KIND_EXTERNAL_URL, or NAV_ITEM_KIND_GROUP_HEADER.",
85
112
  "PAGE uses resourceId from .taproot-site-manifest.json, never pageId or path.",
86
113
  "EXTERNAL_URL uses externalUrl; GROUP_HEADER has no target; every kind may carry children.",
114
+ "externalUrl is an absolute credential-free http/https URL, or a mailto:/tel: contact URL such as "
115
+ + "tel:+15555550123, published exactly as authored.",
87
116
  ]),
88
117
  example: Object.freeze({
89
118
  siteId: "<site-uuid>",
@@ -125,6 +154,7 @@ const WORKFLOW_REFERENCES = Object.freeze({
125
154
  details: Object.freeze([
126
155
  "A page path resolves through .taproot-site-manifest.json; a canonical page UUID works directly.",
127
156
  "The homepage's manifest path is empty; address it as '/', which resolves to that empty root path.",
157
+ "Preview before approving: approve consumes the draft, so an approved page has no draft left to render and answers preview.no_draft. Review it on staging after a deploy instead.",
128
158
  "Creation prints pageId, snapshotId, and expiresAt before the bounded render wait starts.",
129
159
  "The default stored-preview cap is 10 per authoring key and site; operators can tune it.",
130
160
  "Success returns READY with url, snapshotId, expiresAt, storedPreviewCap, storedPreviewCount, and evictedPreviews.",
@@ -134,10 +164,96 @@ const WORKFLOW_REFERENCES = Object.freeze({
134
164
  ]),
135
165
  example: Object.freeze({ command: `${CLI_BINARY_NAME} preview page classes` }),
136
166
  }),
167
+ fixture: Object.freeze({
168
+ title: "Offline fixture manifest contract",
169
+ summary:
170
+ `${FIXTURE_MANIFEST_FILE_NAME} binds a directory laid out like a pulled workspace to deterministic identities, `
171
+ + "so validate can prove it with no credential, no network, and no write.",
172
+ usage: `${CLI_BINARY_NAME} validate <fixture-directory>`,
173
+ details: Object.freeze([
174
+ `Required root fields: ${FIXTURE_REQUIRED_ROOT_FIELDS.join(", ")}.`,
175
+ `Accepted and not read: ${FIXTURE_OPTIONAL_ROOT_FIELDS.join(", ")} — pull writes them, and neither the snapshot `
176
+ + "time nor a recorded deployment can be checked offline. Any other root field is refused.",
177
+ `manifestVersion must be ${MANIFEST_VERSION}; fixture.contractVersion must be ${FIXTURE_CONTRACT_VERSION}.`,
178
+ "siteId, every pageId and resourceId, every settings entityId, and every fixture.imageIds entry is a canonical "
179
+ + "lowercase UUID. They are deterministic fixture identities, not identities from a live site.",
180
+ `Each pages[] entry binds one editable free-form source: pageId, resourceId, path, title, templateType `
181
+ + `${TEMPLATE_TYPE_FREE_FORM}, file, sourceFormat, and workspaceMode ${PAGE_WORKSPACE_MODE_EDITABLE}. `
182
+ + "status, hasDraft, isGenerated, and description are recorded by pull and not read: the page key set "
183
+ + "stays open so a fixture from a newer pull is not refused. The homepage's path is the empty string.",
184
+ `file lives under '${PAGES_DIRECTORY}/' and ends in ${PAGE_SOURCE_EXTENSIONS.join(" or ")}; sourceFormat must be `
185
+ + `the format that extension implies (${
186
+ PAGE_SOURCE_EXTENSIONS.map((extension) => `${extension} is '${pageSourceFormat(`page${extension}`)}'`).join(
187
+ ", ",
188
+ )
189
+ }).`,
190
+ "No two page entries share a pageId, resourceId, file, or path; every declared source must exist; every "
191
+ + `source under '${PAGES_DIRECTORY}/' must be declared; and each entry's path must equal the path its source `
192
+ + "declares — a Markdown source's front-matter 'path:' wins, and the entry's value applies only when the "
193
+ + "front matter omits it.",
194
+ "pages must declare at least one entry, pagesTruncated must be false, and settingsSkipped must be empty: a "
195
+ + "partial snapshot is not a fixture.",
196
+ `navigation binds { file: "${NAVIGATION_FILE_NAME}", items }, and items must equal the tree's own item count.`,
197
+ `settings binds all ${SETTINGS_GROUPS.length} authorable groups, each with settingsType, file, and entityId: ${
198
+ SETTINGS_GROUPS.map((group) => `${group.settingsType} to '${SETTINGS_DIRECTORY}/${group.file}'`).join("; ")
199
+ }.`,
200
+ `The fixture block carries ${FIXTURE_METADATA_FIELDS.join(", ")}. Every image a page references by imageId must `
201
+ + "be listed in fixture.imageIds, and every absolute delivery URL a page uses must sit on a declared origin.",
202
+ `Each deliveryOrigins entry is an origin-only HTTPS URL (no path, query, fragment, or credentials) on `
203
+ + `${FIXTURE_DELIVERY_ORIGIN_DOMAIN} or a subdomain of it, at most ${FIXTURE_MAXIMUM_DELIVERY_ORIGINS} of them, `
204
+ + "with no duplicates. Fixtures are copied and shipped, so a real delivery host in one would be a live "
205
+ + "reference in every copy.",
206
+ "validate reads the fixture and writes nothing to it. Copy the directory somewhere writable before editing it.",
207
+ ]),
208
+ }),
137
209
  });
138
210
 
211
+ // The box, rather than the value, is the cache: an absent fixture memoizes
212
+ // `undefined` instead of being re-read on every call.
213
+ let shippedFixtureManifestCache;
214
+
215
+ /**
216
+ * The shipped fixture's own manifest, read on demand and memoized, or
217
+ * `undefined` when this copy of the package has no readable `examples/`.
218
+ *
219
+ * The read is lazy because `examples/` ships but is not load-bearing. This
220
+ * module sits on the path of every verb (`bin/taproot-site.js` imports
221
+ * `src/cli.js`, which imports this) and of every library consumer through
222
+ * `src/index.js`, while `examples/` is exactly what a `node_modules` pruner or
223
+ * an image-slimming step drops. A static import would turn such a pruned
224
+ * install into an `ERR_MODULE_NOT_FOUND` at module load for `login`, `pull`,
225
+ * `push`, and every other verb; reading here degrades `help fixture` alone.
226
+ */
227
+ function shippedFixtureManifest() {
228
+ shippedFixtureManifestCache ??= { value: readShippedFixtureManifest() };
229
+ return shippedFixtureManifestCache.value;
230
+ }
231
+
232
+ function readShippedFixtureManifest() {
233
+ try {
234
+ return JSON.parse(readFileSync(
235
+ new URL(`../examples/${SHIPPED_FIXTURE_NAME}/${FIXTURE_MANIFEST_FILE_NAME}`, import.meta.url),
236
+ "utf8",
237
+ ));
238
+ } catch {
239
+ // Missing, unreadable, or not JSON. The contract the topic states is
240
+ // derived from constants and stays complete without an example, so
241
+ // `help fixture` answers rather than fails.
242
+ return undefined;
243
+ }
244
+ }
245
+
139
246
  export function getWorkflowReference(topic) {
140
- return WORKFLOW_REFERENCES[topic];
247
+ const reference = WORKFLOW_REFERENCES[topic];
248
+ if (topic !== "fixture") return reference;
249
+ const example = shippedFixtureManifest();
250
+ // The directory is resolved from this package rather than from the caller's
251
+ // directory, so the path is right for a global install as well as a
252
+ // checkout. Both it and the example are reported only when the fixture is
253
+ // actually present: a pruned install has nothing to locate or to validate.
254
+ return example === undefined
255
+ ? reference
256
+ : Object.freeze({ ...reference, fixtureDirectory: shippedFixtureDirectory(), example });
141
257
  }
142
258
 
143
259
  function componentSummary(type) {
@@ -324,6 +440,8 @@ function decorationReference() {
324
440
  }
325
441
 
326
442
  const INLINE_FACTS_DEFINITION = FREE_FORM_SECTION_REGISTRY.inlineFacts;
443
+ // The third fact carries no label on purpose: a phone number names itself, and
444
+ // the row is allowed to mix labelled and standalone facts.
327
445
  const INLINE_FACT_ITEMS_EXAMPLE = Object.freeze([
328
446
  Object.freeze({ value: "4.9 ★", label: "Community rating" }),
329
447
  Object.freeze({
@@ -331,7 +449,7 @@ const INLINE_FACT_ITEMS_EXAMPLE = Object.freeze([
331
449
  label: "Elm Harbor",
332
450
  url: "https://maps.example.test/?q=100%20Riverside%20Way%20Elm%20Harbor",
333
451
  }),
334
- Object.freeze({ value: "(555) 013-7788", label: "Call the studio", url: "tel:+15550137788" }),
452
+ Object.freeze({ value: "(555) 013-7788", url: "tel:+15550137788" }),
335
453
  Object.freeze({ value: "Open today until 8:30 PM", label: "Today's hours", url: "/classes" }),
336
454
  ]);
337
455
 
@@ -353,6 +471,12 @@ function inlineFactsReference() {
353
471
  }),
354
472
  }),
355
473
  placement: Object.freeze({ ...INLINE_FACTS_DEFINITION.placement }),
474
+ valuePolicy:
475
+ `Required non-whitespace plain text; maximum ${items.fields.value.maxScalars} Unicode scalar values.`,
476
+ labelPolicy:
477
+ `Optional non-whitespace plain text; maximum ${items.fields.label.maxScalars} Unicode scalar values. `
478
+ + "Omit it when the value already names itself, such as a rating, an address, or a phone number; a row may "
479
+ + "mix labelled and standalone facts. An empty string is rejected, so omitting a label stays explicit.",
356
480
  urlPolicy:
357
481
  "Optional safe HTTP(S), mailto, tel, non-protocol-relative root, fragment, query, or relative URL. Empty/whitespace-only values, other schemes, backslashes, and ASCII controls are rejected; tel: remains a native link.",
358
482
  markdown: Object.freeze({
@@ -897,7 +1021,7 @@ export function formatReferenceResult(result) {
897
1021
  page.sections.placementMatrix.map(formatPlacement).join("\n")
898
1022
  }\n\nSemantic tables:\n placement document root or directly inside a top-level section; wide/full-well measure\n rows exactly ${page.tables.structure.headerRows} header row, then ${page.tables.limits.dataRows.min} through ${page.tables.limits.dataRows.max} data rows\n columns ${page.tables.limits.columns.min} through ${page.tables.limits.columns.max}; delimiter and every row must match the header width\n caption optional non-empty plain text; maximum ${page.tables.limits.captionScalars.max} Unicode scalar values; syntax ${page.tables.markdown.captionSyntax}\n caption guidance ${page.tables.captionGuidance}\n cells exactly ${page.tables.structure.paragraphChildrenPerCell} paragraph; headers need non-whitespace text; data cells may be empty; maximum ${page.tables.limits.cellTextScalars.max} text scalars\n inline ${page.tables.structure.inlineNodes.join(", ")}; marks ${page.tables.structure.marks.join(", ")}\n pipes outer pipes ${page.tables.markdown.outerPipes}; write a literal pipe as ${page.tables.markdown.literalPipeEscape}\n spans unsupported: ${page.tables.structure.unsupportedSpanAttrs.join(", ")}\n alignment ${page.tables.markdown.alignment}; delimiter cells contain hyphens only\n termination a blank line ends the table before another block\n\nRate table example:\n${page.tables.examples.rateTable}\n\nComparison table example:\n${page.tables.examples.comparisonTable}\n\nRejected alignment example (${CONTENT_ERROR_CODES.markdownTableAlignment}):\n${page.tables.examples.rejectedAlignment}\nRemove the ':' characters from the delimiter row.\n\nDirect ProseMirror table example:\n${JSON.stringify(page.tables.examples.proseMirror, null, 2)}\n\nTable error corrections:\n${
899
1023
  page.tables.corrections.map((entry) => ` ${entry.code.padEnd(34)} ${entry.correction}`).join("\n")
900
- }\n\nInline facts:\n placement document root or directly inside a top-level section; ${page.inlineFacts.placement.measure} measure\n items ${page.inlineFacts.attrs.items.minItems} through ${page.inlineFacts.attrs.items.maxItems}; closed objects in value, label, url order\n value and label required non-whitespace plain text; maximum ${page.inlineFacts.attrs.items.fields[0].maxScalars} Unicode scalar values each\n url ${page.inlineFacts.urlPolicy}\n Markdown fenced ${page.inlineFacts.markdown.fence} block whose body is a JSON array\n\nInline-facts Markdown example:\n${page.inlineFacts.markdown.example}\n\nDirect ProseMirror inlineFacts example:\n${JSON.stringify(page.inlineFacts.examples.proseMirror, null, 2)}\n\nRaw HTML: ${page.document.rawHtml.default} by default. For a tracked ${page.document.rawHtml.trackedProseMirror.format} document only: ${page.document.rawHtml.trackedProseMirror.behavior} Opt in with ${page.document.rawHtml.trackedProseMirror.optIn}. For ${page.document.rawHtml.markdown.format}, ${page.document.rawHtml.markdown.behavior} ${page.document.rawHtml.warning}\n\nComponents:\n${
1024
+ }\n\nInline facts:\n placement document root or directly inside a top-level section; ${page.inlineFacts.placement.measure} measure\n items ${page.inlineFacts.attrs.items.minItems} through ${page.inlineFacts.attrs.items.maxItems}; closed objects in ${page.inlineFacts.attrs.items.itemFieldOrder.join(", ")} order\n value ${page.inlineFacts.valuePolicy}\n label ${page.inlineFacts.labelPolicy}\n url ${page.inlineFacts.urlPolicy}\n Markdown fenced ${page.inlineFacts.markdown.fence} block whose body is a JSON array\n\nInline-facts Markdown example:\n${page.inlineFacts.markdown.example}\n\nDirect ProseMirror inlineFacts example:\n${JSON.stringify(page.inlineFacts.examples.proseMirror, null, 2)}\n\nRaw HTML: ${page.document.rawHtml.default} by default. For a tracked ${page.document.rawHtml.trackedProseMirror.format} document only: ${page.document.rawHtml.trackedProseMirror.behavior} Opt in with ${page.document.rawHtml.trackedProseMirror.optIn}. For ${page.document.rawHtml.markdown.format}, ${page.document.rawHtml.markdown.behavior} ${page.document.rawHtml.warning}\n\nComponents:\n${
901
1025
  page.components.map((component) => ` ${component.type.padEnd(16)} ${component.summary}`).join("\n")
902
1026
  }\n\nWorkflow:\n${
903
1027
  page.workflow.map((step) => ` ${step.command}: ${step.result}`).join("\n")
@@ -915,9 +1039,20 @@ export function formatReferenceResult(result) {
915
1039
  }
916
1040
  case "workflow": {
917
1041
  const reference = result.reference;
918
- return `${reference.title}\n${reference.summary}\n\nUsage: ${reference.usage}\n\n${
1042
+ // Only the fixture reference carries a shipped directory; every other
1043
+ // workflow topic renders exactly as it did.
1044
+ const shipped = reference.fixtureDirectory === undefined
1045
+ ? ""
1046
+ : `\nShipped example: ${reference.fixtureDirectory}\nValidate it: ${CLI_BINARY_NAME} validate "${reference.fixtureDirectory}"\n`;
1047
+ // Every other topic's example is a literal in this module and is always
1048
+ // present; the fixture topic's is a shipped file, so it is omitted the
1049
+ // same way the shipped-directory lines are when the file is not there.
1050
+ const example = reference.example === undefined
1051
+ ? ""
1052
+ : `\n\nExample:\n${JSON.stringify(reference.example, null, 2)}`;
1053
+ return `${reference.title}\n${reference.summary}\n\nUsage: ${reference.usage}\n${shipped}\n${
919
1054
  reference.details.map((detail) => ` - ${detail}`).join("\n")
920
- }\n\nExample:\n${JSON.stringify(reference.example, null, 2)}\n`;
1055
+ }${example}\n`;
921
1056
  }
922
1057
  case "presentation":
923
1058
  return formatPresentationReference(result.reference);
package/src/transport.js CHANGED
@@ -1,4 +1,6 @@
1
1
  import {
2
+ CAPABILITY_REFUSAL_FIELD,
3
+ CAPABILITY_REFUSAL_REASON,
2
4
  CLI_NAME,
3
5
  CLI_VERSION,
4
6
  CREDENTIAL_REFUSAL_FIELD,
@@ -9,6 +11,7 @@ import {
9
11
  LIMITS,
10
12
  PLAN_LIMIT_REFUSAL_FIELD,
11
13
  PUBLISH_KEY_ENVIRONMENT_VARIABLE,
14
+ REFUSAL_CAPABILITY_MISSING,
12
15
  REFUSAL_CREDENTIAL_REJECTED,
13
16
  REFUSAL_PLAN_LIMIT,
14
17
  REFUSAL_PLATFORM_PAUSED,
@@ -330,21 +333,95 @@ function fieldDescriptions(value) {
330
333
  return descriptions;
331
334
  }
332
335
 
336
+ /**
337
+ * A delegation capability or permission key as the server spells it. Anything
338
+ * outside this shape is dropped rather than repaired: these values reach a
339
+ * terminal and a machine-readable result, and a name the CLI cannot vouch for
340
+ * is worse than a name it does not print.
341
+ */
342
+ const CAPABILITY_NAME = /^[a-z][a-z0-9_]*(?:\.[a-z][a-z0-9_]*)+$/u;
343
+ const MAXIMUM_CAPABILITY_NAMES = 16;
344
+
345
+ function capabilityNames(value) {
346
+ if (typeof value !== "string" || value === "") return [];
347
+ return value
348
+ .split(",")
349
+ .map((name) => name.trim())
350
+ .filter((name) => name.length <= 200 && CAPABILITY_NAME.test(name))
351
+ .slice(0, MAXIMUM_CAPABILITY_NAMES);
352
+ }
353
+
354
+ /**
355
+ * The key-mode capability denial the authoring API attaches as a
356
+ * `google.rpc.ErrorInfo` detail (TR00691), or undefined.
357
+ *
358
+ * The same bounded breadth-first walk the field extractors use, for the same
359
+ * reason: transcoded `details[]` entries are `Any`-packed, and pinning one path
360
+ * through them is how a contract change silently empties an extractor. The
361
+ * `reason` is the contract — a stable, namespaced classifier — so the walk
362
+ * keys on it rather than on `@type`, which a future packing could reshape.
363
+ */
364
+ export function capabilityRefusal(value) {
365
+ const queue = [{ value, depth: 0 }];
366
+ let work = 0;
367
+ while (queue.length > 0 && work < 1_000) {
368
+ const current = queue.shift();
369
+ work += 1;
370
+ if (!current || current.depth > 8 || current.value === null || typeof current.value !== "object") continue;
371
+ const metadata = current.value.metadata;
372
+ if (
373
+ current.value.reason === CAPABILITY_REFUSAL_REASON
374
+ && metadata !== null
375
+ && typeof metadata === "object"
376
+ && !Array.isArray(metadata)
377
+ ) {
378
+ const permission = capabilityNames(metadata.permission)[0];
379
+ // A detail naming no permission is not this refusal, whatever it says:
380
+ // the guidance is built entirely out of these three values, and half of
381
+ // one would be a message nobody could act on.
382
+ if (permission !== undefined) {
383
+ return Object.freeze({
384
+ permission,
385
+ granted: Object.freeze(capabilityNames(metadata.granted)),
386
+ required: Object.freeze(capabilityNames(metadata.required)),
387
+ });
388
+ }
389
+ }
390
+ for (const child of Object.values(current.value)) {
391
+ if (child !== null && typeof child === "object") queue.push({ value: child, depth: current.depth + 1 });
392
+ }
393
+ }
394
+ return undefined;
395
+ }
396
+
333
397
  export class ApiError extends SiteAuthoringError {
334
398
  constructor(httpStatus, body) {
335
399
  const grpcCode = Number.isSafeInteger(body?.code) ? body.code : undefined;
336
400
  const fields = fieldViolations(body);
401
+ const capability = capabilityRefusal(body);
337
402
  super(
338
403
  "api.request_rejected",
339
404
  fields.length > 0
340
405
  ? `Taproot rejected the request field '${fields[0]}'.`
406
+ : capability !== undefined
407
+ ? `Taproot refused the request: this credential does not carry a capability granting '${
408
+ capability.permission
409
+ }'.`
341
410
  : `Taproot rejected the request with HTTP ${httpStatus}.`,
342
- { field: fields[0], status: grpcCode === undefined ? `http:${httpStatus}` : `grpc:${grpcCode}` },
411
+ {
412
+ // `fields` stays exactly what the wire named. The capability field is
413
+ // the CLI's own label for a refusal that carries no field violation at
414
+ // all, so it lands on the error without joining the wire-derived set
415
+ // that `hasField()` classifies on.
416
+ field: fields[0] ?? (capability === undefined ? undefined : CAPABILITY_REFUSAL_FIELD),
417
+ status: grpcCode === undefined ? `http:${httpStatus}` : `grpc:${grpcCode}`,
418
+ },
343
419
  );
344
420
  this.httpStatus = httpStatus;
345
421
  this.grpcCode = grpcCode;
346
422
  this.fields = fields;
347
423
  this.violationDescriptions = fieldDescriptions(body);
424
+ this.capability = capability;
348
425
  }
349
426
 
350
427
  hasField(field) {
@@ -366,7 +443,7 @@ export class ApiError extends SiteAuthoringError {
366
443
 
367
444
  /**
368
445
  * Classifies a refusal into the one thing the caller should do next. The
369
- * four kinds are genuinely different behaviors, and collapsing them into
446
+ * five kinds are genuinely different behaviors, and collapsing them into
370
447
  * "the request failed" is what makes an agent retry a revoked credential
371
448
  * forever or treat a plan ceiling as a transient outage:
372
449
  *
@@ -393,6 +470,13 @@ export class ApiError extends SiteAuthoringError {
393
470
  * never invents the numeric limit.
394
471
  * - `throttled` (gRPC `ResourceExhausted` / HTTP 429) — the per-key
395
472
  * throttle. **Back off** and retry with delay.
473
+ * - `capability_missing` (`ErrorInfo` reason `SITE_AUTHORING_CAPABILITY_MISSING`)
474
+ * — the credential is valid and correctly scoped, and simply was not
475
+ * exchanged for a capability this request needs. **Fix the verb table**,
476
+ * not the credential: the exchange minted exactly what the verb asked for,
477
+ * so a verb whose declared set is short of the requests it makes is the
478
+ * defect. Distinguished from `credential_rejected` precisely because
479
+ * re-issuing the same credential cannot help (TR00691).
396
480
  *
397
481
  * Anything else is `unclassified`, which is a signal to surface the raw
398
482
  * status rather than to guess.
@@ -403,6 +487,9 @@ export class ApiError extends SiteAuthoringError {
403
487
  if (this.hasField(ROLLOUT_REFUSAL_FIELD)) return REFUSAL_PLATFORM_PAUSED;
404
488
  if (this.hasField(CREDENTIAL_REFUSAL_FIELD)) return REFUSAL_CREDENTIAL_REJECTED;
405
489
  if (this.hasField(PLAN_LIMIT_REFUSAL_FIELD)) return REFUSAL_PLAN_LIMIT;
490
+ // The named detail ranks with the fields and above the status mappings, for
491
+ // the same reason: it is the specific statement about this refusal.
492
+ if (this.capability !== undefined) return REFUSAL_CAPABILITY_MISSING;
406
493
  if (this.grpcCode === GRPC_RESOURCE_EXHAUSTED || this.httpStatus === HTTP_TOO_MANY_REQUESTS) {
407
494
  return REFUSAL_THROTTLED;
408
495
  }
@@ -9,6 +9,11 @@ import {
9
9
  withRefusalGuidance,
10
10
  } from "../api.js";
11
11
  import { VERB_NAV_PUSH } from "../constants.js";
12
+ import {
13
+ CONTACT_OR_WEB_URL_MAX_LENGTH,
14
+ CONTACT_OR_WEB_URL_REQUIREMENT,
15
+ isContactOrWebUrl,
16
+ } from "../contact-url.js";
12
17
  import { SiteAuthoringError } from "../errors.js";
13
18
  import { boundedList, openSession, successResult } from "../session.js";
14
19
  import {
@@ -44,7 +49,7 @@ import {
44
49
  const MAXIMUM_REPORTED = 100;
45
50
  const MAXIMUM_ITEMS = 1_000;
46
51
  const MAXIMUM_TITLE_LENGTH = 200;
47
- const MAXIMUM_URL_LENGTH = 2_048;
52
+ const MAXIMUM_URL_LENGTH = CONTACT_OR_WEB_URL_MAX_LENGTH;
48
53
  const ITEM_KEYS = new Set(["id", "kind", "title", "resourceId", "externalUrl", "children"]);
49
54
 
50
55
  // `SaveSiteNavigation` maps both `id` and `resourceId` through
@@ -141,14 +146,10 @@ function validateItem(item, itemPath, depth, seenIds, counters) {
141
146
  if (!isBoundedText(item.externalUrl, MAXIMUM_URL_LENGTH)) {
142
147
  throw navError("nav.external_url_missing", "an EXTERNAL_URL item needs a non-empty 'externalUrl'.", itemPath);
143
148
  }
144
- let url;
145
- try {
146
- url = new URL(item.externalUrl);
147
- } catch {
148
- url = undefined;
149
- }
150
- if (url === undefined || (url.protocol !== "https:" && url.protocol !== "http:")) {
151
- throw navError("nav.external_url_invalid", "'externalUrl' must be an absolute http or https URL.", itemPath);
149
+ // A header item may be a phone number or an email address, not just a web
150
+ // page; the value is stored verbatim so the number stays dialable.
151
+ if (!isContactOrWebUrl(item.externalUrl, MAXIMUM_URL_LENGTH)) {
152
+ throw navError("nav.external_url_invalid", `'externalUrl' ${CONTACT_OR_WEB_URL_REQUIREMENT}.`, itemPath);
152
153
  }
153
154
  if (!isEmpty(item.resourceId)) {
154
155
  throw navError("nav.resource_unexpected", "an EXTERNAL_URL item must not carry 'resourceId'.", itemPath);
package/src/verbs/pull.js CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  TEMPLATE_TYPE_FREE_FORM,
10
10
  withRefusalGuidance,
11
11
  } from "../api.js";
12
- import { REFUSAL_UNCLASSIFIED, VERB_PULL } from "../constants.js";
12
+ import { REFUSAL_CAPABILITY_MISSING, REFUSAL_UNCLASSIFIED, VERB_PULL } from "../constants.js";
13
13
  import { SiteAuthoringError } from "../errors.js";
14
14
  import { appearanceManifestEntry, footerManifestEntry } from "../footer-workspace.js";
15
15
  import { boundedList, openSession, successResult } from "../session.js";
@@ -94,8 +94,10 @@ import {
94
94
 
95
95
  const MAXIMUM_REPORTED = 200;
96
96
  // A settings group the credential's envelope does not reach is a narrower
97
- // snapshot, not a failed pull. Anything the transport classified as a refusal
98
- // is a different matter and always propagates.
97
+ // snapshot, not a failed pull. The server names that shortfall as a
98
+ // capability denial (TR00691), and an older server answers a bare 403; both
99
+ // mean the same thing here. Any other classified refusal — a rejected
100
+ // credential, the rollout switch, a plan ceiling — always propagates.
99
101
  const UNAVAILABLE_SETTINGS_STATUSES = new Set([403, 404]);
100
102
  const APPEARANCE_SETTINGS_TYPES = Object.freeze([
101
103
  SETTINGS_TYPE_TAPROOT_STYLES,
@@ -435,7 +437,8 @@ export async function pull(invocation) {
435
437
  } catch (error) {
436
438
  if (
437
439
  error instanceof ApiError
438
- && error.refusalKind() === REFUSAL_UNCLASSIFIED
440
+ && (error.refusalKind() === REFUSAL_UNCLASSIFIED
441
+ || error.refusalKind() === REFUSAL_CAPABILITY_MISSING)
439
442
  && UNAVAILABLE_SETTINGS_STATUSES.has(error.httpStatus)
440
443
  ) {
441
444
  onProgress(`Settings group ${group.settingsType} is not readable by this credential; skipping it.`);
@@ -5,6 +5,14 @@ import { NAVIGATION_MAXIMUM_DEPTH, TEMPLATE_TYPE_FREE_FORM } from "../api.js";
5
5
  import { freeFormRootPresentation, sharedThemeContextNames } from "../content/free-form-sections.js";
6
6
  import { VERB_VALIDATE } from "../constants.js";
7
7
  import { isCanonicalUuid, SiteAuthoringError } from "../errors.js";
8
+ import {
9
+ FIXTURE_CONTRACT_VERSION,
10
+ FIXTURE_DELIVERY_ORIGIN_DOMAIN,
11
+ FIXTURE_MANIFEST_FILE_NAME,
12
+ FIXTURE_MAXIMUM_DELIVERY_ORIGINS,
13
+ FIXTURE_METADATA_FIELDS,
14
+ FIXTURE_ROOT_FIELDS,
15
+ } from "../fixture-contract.js";
8
16
  import { FOOTER_SETTINGS_FILE } from "../footer-workspace.js";
9
17
  import { boundedList, successResult } from "../session.js";
10
18
  import { SETTINGS_GROUPS, SETTINGS_TYPE_SITE_PUBLISHING_PREFERENCES } from "../settings-catalog.js";
@@ -26,22 +34,9 @@ import {
26
34
  WORKSPACE_LIMITS,
27
35
  } from "../workspace.js";
28
36
 
29
- export const FIXTURE_MANIFEST_FILE_NAME = "manifest.fixture.json";
30
- export const FIXTURE_CONTRACT_VERSION = 1;
31
37
  const MAXIMUM_REPORTED = 200;
32
- const FIXTURE_ROOT_KEYS = new Set([
33
- "manifestVersion",
34
- "siteId",
35
- "pulledAt",
36
- "pages",
37
- "pagesTruncated",
38
- "navigation",
39
- "settings",
40
- "settingsSkipped",
41
- "deployments",
42
- "fixture",
43
- ]);
44
- const FIXTURE_METADATA_KEYS = new Set(["contractVersion", "imageIds", "deliveryOrigins"]);
38
+ const FIXTURE_ROOT_KEYS = new Set(FIXTURE_ROOT_FIELDS);
39
+ const FIXTURE_METADATA_KEYS = new Set(FIXTURE_METADATA_FIELDS);
45
40
 
46
41
  function fail(code, message, field, exitCode) {
47
42
  throw new SiteAuthoringError(code, message, { field, exitCode });
@@ -163,7 +158,10 @@ function validateFixtureManifest(manifest) {
163
158
  if (imageIds.size !== manifest.fixture.imageIds.length) {
164
159
  fail("fixture.image_ids_invalid", "fixture.imageIds must not contain duplicates.", "fixture.imageIds");
165
160
  }
166
- if (!Array.isArray(manifest.fixture.deliveryOrigins) || manifest.fixture.deliveryOrigins.length > 100) {
161
+ if (
162
+ !Array.isArray(manifest.fixture.deliveryOrigins)
163
+ || manifest.fixture.deliveryOrigins.length > FIXTURE_MAXIMUM_DELIVERY_ORIGINS
164
+ ) {
167
165
  fail(
168
166
  "fixture.delivery_origins_invalid",
169
167
  "fixture.deliveryOrigins must be a bounded list of reserved HTTPS example origins.",
@@ -186,11 +184,14 @@ function validateFixtureManifest(manifest) {
186
184
  || url.pathname !== "/"
187
185
  || url.search !== ""
188
186
  || url.hash !== ""
189
- || !(url.hostname === "example.test" || url.hostname.endsWith(".example.test"))
187
+ || !(
188
+ url.hostname === FIXTURE_DELIVERY_ORIGIN_DOMAIN
189
+ || url.hostname.endsWith(`.${FIXTURE_DELIVERY_ORIGIN_DOMAIN}`)
190
+ )
190
191
  ) {
191
192
  fail(
192
193
  "fixture.delivery_origins_invalid",
193
- "Every fixture delivery origin must be an origin-only HTTPS URL under the reserved example.test domain.",
194
+ `Every fixture delivery origin must be an origin-only HTTPS URL under the reserved ${FIXTURE_DELIVERY_ORIGIN_DOMAIN} domain.`,
194
195
  `fixture.deliveryOrigins[${index}]`,
195
196
  );
196
197
  }