create-ailk 0.43.0 → 0.45.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.
@@ -3,24 +3,25 @@
3
3
  *
4
4
  * Reads a site's default-locale MDX pages through the site's own MDX adapter
5
5
  * and writes each one as a `text/page` Artifact through the tenant-guarded
6
- * workspace content routes. Per page (D3): read the draft; create on 404;
7
- * PATCH under `X-Draft-Version` (#10264) when the content differs; write nothing when it is
8
- * the same — so a second run over the same files creates nothing and reports
9
- * every page `unchanged`. A file the adapter rejects is `failed` with its path
6
+ * workspace content routes. Per page (D3, #11843 D1): read the draft, then
7
+ * save once — `save_page` (`PUT …/content/:type/:slug`) for a page and
8
+ * `save_document` (`POST …/documents/save`) for a `Document`, with
9
+ * `version: null` on a 404 and the read's version and layout token otherwise
10
+ * — or write nothing when the read already holds what the save would store,
11
+ * so a second run over the same files creates nothing and reports every page
12
+ * `unchanged` (#11843 D4). A file the adapter rejects is `failed` with its path
10
13
  * and reason and the run goes on. The seed step (U6b) and `migrate-content`
11
14
  * (U6c) both call it; this module adds no command.
12
15
  *
13
- * A page whose frontmatter carries `sections` is converted (#10534): its
14
- * words move into the Markdown body through the words codec
15
- * (`sectionsToMarkdown`, ADR 0038), after the body it already had, and the
16
- * sections — layout and data — go to the structure layer through
17
- * `PUT …/structure` under the draft's structure token (#10643), never into the
18
- * stored content. An unchanged layout writes nothing, so a re-run still
19
- * reports `unchanged`. A changed layout on a page whose words did not change
20
- * and whose draft is its live version is refused `draft_is_live`; the
21
- * importer then saves a draft with the same words under the version it read
22
- * and sends the layout once more (#11749 D2), so the live page does not change
23
- * until it is published. A second refusal fails the page with that reason.
16
+ * A page whose frontmatter carries `sections` is saved in the section form
17
+ * (#10534, #11843 D1): the sections are `save_page`'s words, and the hub
18
+ * builds the body from them, so the text before the first section — which
19
+ * nothing renders — is not sent (D3). Any other page's words are its body.
20
+ * The importer compares the read with what the save would store, its words
21
+ * as the codec (`sectionsToMarkdown`, ADR 0038) writes them, so a page the
22
+ * earlier importer stored after a lead is still `unchanged`. An edit to a
23
+ * live page appends a draft, so the live page does not change until it is
24
+ * published.
24
25
  *
25
26
  * A section string that holds inline HTML is converted first (#10804) — a
26
27
  * link to `[label](href)`, a line break to a newline, a block to a blank
@@ -28,7 +29,9 @@
28
29
  * carry no tag, which the hub's structure write refuses. The layout is then
29
30
  * checked against the hub's section-string rules before any write, so a page
30
31
  * the hub would refuse fails with the rule and the path, and a page whose
31
- * draft holds no layout yet is never reported `unchanged`.
32
+ * draft holds no layout yet is never reported `unchanged`. A page that fails
33
+ * its type's checks is refused `422 invalid` by the save, and nothing is
34
+ * stored (#11843 D2).
32
35
  *
33
36
  * create-ailk ships one runtime dependency, so the adapter is never imported:
34
37
  * the caller injects it, and `loadSiteMdxAdapter` resolves the SITE's
@@ -44,11 +47,9 @@
44
47
  * vocabulary does not name rides in `siteFields`, and a blog post's tags are
45
48
  * sent (#10806); a key the store cannot keep is named with its reason.
46
49
  *
47
- * Given `liveSource` (#10898 D5), each page carries the hub's live-source
48
- * mark — the SHA-256 of the body it sends — so the hub lists the template's
49
- * missing headings as advisory, not blocking; a file never supplies one. With
50
- * the site's contract members (`publishCheck`), each written page's outcome
51
- * carries the verdict the hub's publish gate will give it (D6).
50
+ * No page carries the hub's live-source mark: no save keeps it (#11843 D7).
51
+ * With the site's contract members (`publishCheck`), each written page's
52
+ * outcome carries the verdict the hub's publish gate will give it (#10898 D6).
52
53
  *
53
54
  * Given `publish` (#10659 D2), each page with no Live version is set Live
54
55
  * after it is written (`POST …/publish`, the draft tip); a page already Live
@@ -61,9 +62,9 @@
61
62
  *
62
63
  * Spec: docs/specs/10203-import-mdx-one-mdx-artifact-spec.md; the editorial
63
64
  * walk docs/specs/10701-import-mdx-walks-the-editorial-spec.md; its site
64
- * fields docs/specs/10806-the-editorial-import-drops-blog-spec.md.
65
+ * fields docs/specs/10806-the-editorial-import-drops-blog-spec.md; the saves
66
+ * docs/specs/11843-the-scaffold-s-importer-saves-spec.md.
65
67
  */
66
- import { createHash } from "node:crypto";
67
68
  import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
68
69
  import { createRequire } from "node:module";
69
70
  import { dirname, join, resolve } from "node:path";
@@ -80,10 +81,18 @@ const VALIDATION_PACKAGE = "@working-theory/validation";
80
81
  const FRONTMATTER_PACKAGE = "gray-matter";
81
82
  /** The page-type registry: a dependency of the adapter package (#10898 D6). */
82
83
  const PAGE_TYPES_PACKAGE = "@working-theory/schema/page-types";
83
- /** The hub's live-source content key (`LIVE_SOURCE_KEY`, api-content-write `content.ts`), restated: no runtime dep. */
84
+ /** The hub's live-source content key (`LIVE_SOURCE_KEY`, api-content-write `content.ts`), restated: never sent (#11843 D7). */
84
85
  const LIVE_SOURCE_KEY = "liveSource";
85
86
  /** The hub's written-from record (`WRITTEN_FROM_KEY`, same file), restated: never taken from a file (#11707 D9). */
86
87
  const WRITTEN_FROM_KEY = "writtenFrom";
88
+ /** `DOCUMENT_TYPE` (the validation package's `content-draft.ts`), restated: saved with `save_document` (#11843 D10). */
89
+ const DOCUMENT_TYPE = "Document";
90
+ /**
91
+ * The frontmatter keys never sent in `fields` (#11843 D2): the ones the save
92
+ * takes from the address and the words, and the two hub records a file never
93
+ * supplies (#10898 D5, #11707 D9).
94
+ */
95
+ const NOT_FIELDS = new Set(["sections", "type", "slug", "locale", LIVE_SOURCE_KEY, WRITTEN_FROM_KEY]);
87
96
  /** `EDITORIAL_FIELDS` (api-content-write `derive-publish.ts`): the editorial structure publish's repair builds. */
88
97
  const EDITORIAL_STRUCTURE_FIELDS = ["author", "tags", "order", "parent"];
89
98
  /** The adapter's locale shape (`BCP47_RE` in its `mdx/adapter.ts`). */
@@ -532,7 +541,7 @@ function retryAfterSeconds(header) {
532
541
  ? seconds
533
542
  : RATE_LIMIT_WAIT_MAX_S;
534
543
  }
535
- async function call(t, method, url, body, ifMatch) {
544
+ async function call(t, method, url, body) {
536
545
  for (let retry = 0;; retry++) {
537
546
  let response;
538
547
  try {
@@ -541,10 +550,6 @@ async function call(t, method, url, body, ifMatch) {
541
550
  headers: {
542
551
  authorization: `Bearer ${t.key}`,
543
552
  ...(body !== undefined && { "content-type": "application/json" }),
544
- // #10264 — the version rides `x-draft-version`; `if-match` rides
545
- // beside it for one release so this importer still saves against an
546
- // API that predates the new header (the route prefers the new one).
547
- ...(ifMatch !== undefined && { "x-draft-version": ifMatch, "if-match": ifMatch }),
548
553
  },
549
554
  ...(body !== undefined && { body: JSON.stringify(body) }),
550
555
  // A redirect would re-send the key and the body to another URL.
@@ -596,126 +601,121 @@ function refusedAnswer(at, answer) {
596
601
  }
597
602
  /**
598
603
  * A success answered for another locale: the API does not serve `locale`. A
599
- * success with no locale at all is not the API's answer shape: that page fails.
604
+ * success with no locale at all is not the API's answer shape: that page
605
+ * fails. A read names its locale at `data.locale`, a save at
606
+ * `data.address.locale` (#11843 D1).
600
607
  */
601
- function wrongLocale(at, answer, locale) {
602
- if ("network" in answer || answer.data["locale"] === locale)
608
+ function wrongLocale(at, answer, locale, of) {
609
+ if ("network" in answer)
610
+ return undefined;
611
+ const address = answer.data["address"];
612
+ const answered = of === "read"
613
+ ? answer.data["locale"]
614
+ : address !== null && typeof address === "object"
615
+ ? address["locale"]
616
+ : undefined;
617
+ if (answered === locale)
603
618
  return undefined;
604
- if (typeof answer.data["locale"] !== "string") {
619
+ if (typeof answered !== "string") {
605
620
  return failed(at, `${answer.status} unknown`);
606
621
  }
607
622
  return failed(at, `the API does not serve locale ${locale}`, `not sent: the API does not serve locale ${locale}`);
608
623
  }
609
- /** `value` without the hub's own records: the live-source mark and the written-from record. */
610
- function withoutHubRecords(value) {
611
- if (value === null || typeof value !== "object" || Array.isArray(value))
612
- return value;
613
- const { [LIVE_SOURCE_KEY]: _mark, [WRITTEN_FROM_KEY]: _record, ...rest } = value;
624
+ /**
625
+ * Records a save carries forward when the file sends none (#11843 D4): never
626
+ * compared unless the file sends it, or every run would save again. The
627
+ * live-source mark is never kept, so never compared.
628
+ */
629
+ const CARRIED_RECORDS = [WRITTEN_FROM_KEY, "pageChange", "reader", "narrator"];
630
+ /** The stored content's fields, as compared with the fields a save sends. */
631
+ function storedFields(stored, fields) {
632
+ if (stored === null || typeof stored !== "object" || Array.isArray(stored))
633
+ return {};
634
+ const { type: _t, slug: _s, body: _b, locale: _l, [LIVE_SOURCE_KEY]: _m, ...rest } = stored;
635
+ for (const key of CARRIED_RECORDS)
636
+ if (!Object.hasOwn(fields, key))
637
+ delete rest[key];
614
638
  return rest;
615
639
  }
616
- async function writePage(t, page, locale, content, layout, publicTags) {
640
+ /**
641
+ * Whether the stored body holds the page's words (#11843 D4): exactly, or —
642
+ * for a layout — after a lead, as the earlier importer stored it.
643
+ */
644
+ function sameWords(storedBody, save) {
645
+ if (typeof storedBody !== "string")
646
+ return false;
647
+ return (storedBody === save.body ||
648
+ (save.layout !== undefined && storedBody.endsWith(`\n\n${save.body}`)));
649
+ }
650
+ async function writePage(t, page, locale, save, publicTags) {
617
651
  const { root, path, type, slug } = page;
618
- const pagePath = `${t.base}/content/${encodeURIComponent(type)}/${encodeURIComponent(slug)}`;
619
652
  const query = `?locale=${encodeURIComponent(locale)}`;
620
- const address = `${pagePath}${query}`;
653
+ const address = `${t.base}/content/${encodeURIComponent(type)}/${encodeURIComponent(slug)}${query}`;
654
+ const document = type === DOCUMENT_TYPE;
621
655
  // The route's `statusOf`: anything but `draft` has a Live version.
622
656
  let live = false;
623
- let stored;
624
- let sent = false;
625
- const outcome = (result, layoutOnly = false) => ({
657
+ const sent = { ...save.fields, type };
658
+ const outcome = (result, stored, layoutOnly = false) => ({
626
659
  outcome: { root, path, result, type, slug, ...(layoutOnly && { layoutOnly: true }) },
627
660
  live,
628
- stored,
629
- sent,
661
+ ...(stored !== undefined && { stored }),
630
662
  });
631
- // The words are written; now the layout, under the token the draft holds
632
- // (`null` for a page that has none yet). `version` is the read's, given
633
- // only when the words compared equal and were not saved (#11749 D2).
634
- const done = async (result, structureToken = null, version) => {
635
- if (layout === undefined)
636
- return outcome(result);
637
- const writeLayout = () => call(t, "PUT", `${pagePath}/structure${query}`, {
663
+ // #11843 D1 — one save: `save_document` for a Document, else `save_page`,
664
+ // with the sections as a layout's words and `{ body }` for the rest.
665
+ const write = (version, structureToken) => document
666
+ ? call(t, "POST", `${t.base}/documents/save`, {
667
+ address: { type, slug, locale },
668
+ version,
669
+ fields: save.fields,
670
+ words: { body: save.body },
671
+ })
672
+ : call(t, "PUT", address, {
673
+ version,
638
674
  structureToken,
639
- structure: layout,
675
+ fields: save.fields,
676
+ words: save.layout === undefined ? { body: save.body } : save.layout.sections,
640
677
  });
641
- let put = await writeLayout();
642
- // #11749 D2 — the hub refuses a layout on a live tip and names the remedy:
643
- // save a draft (the same words, under the version read), then write the
644
- // layout once more. A save carries the structure token forward (§1).
645
- const redraft = version !== undefined &&
646
- !("network" in put) &&
647
- put.status === 409 &&
648
- put.code === "draft_is_live";
649
- if (redraft) {
650
- const saved = await call(t, "PATCH", address, content, version);
651
- if ("network" in saved || saved.status !== 200)
652
- return refusedAnswer(page, saved);
653
- stored = saved.data["content"];
654
- sent = true;
655
- const mismatch = wrongLocale(page, saved, locale);
656
- if (mismatch !== undefined)
657
- return mismatch;
658
- put = await writeLayout();
659
- }
660
- if ("network" in put || put.status !== 200)
661
- return refusedAnswer(page, put);
662
- // #10804 D6 — with no token the hub writes the layout (or refuses a
663
- // live tip), so a dry run's `written: false` never makes it unchanged.
664
- const layoutOnly = result === "unchanged" &&
665
- (redraft || structureToken === null || put.data["written"] === true);
666
- return (wrongLocale(page, put, locale) ??
667
- outcome(layoutOnly ? "updated" : result, layoutOnly));
668
- };
669
678
  for (let reread = false;; reread = true) {
670
679
  const read = await call(t, "GET", address);
671
680
  if ("network" in read)
672
681
  return refusedAnswer(page, read);
682
+ let version = null;
683
+ let structureToken = null;
684
+ let layoutOnly = false;
673
685
  if (read.status === 200) {
674
- const mismatch = wrongLocale(page, read, locale);
686
+ const mismatch = wrongLocale(page, read, locale, "read");
675
687
  if (mismatch !== undefined)
676
688
  return mismatch;
677
- const version = read.data["version"];
678
- if (typeof version !== "string")
689
+ const readVersion = read.data["version"];
690
+ if (typeof readVersion !== "string")
679
691
  return failed(page, "200 unknown");
692
+ version = readVersion;
680
693
  live = read.data["status"] !== "draft";
681
694
  const token = read.data["structureToken"];
682
- const structureToken = typeof token === "string" ? token : null;
683
- stored = read.data["content"];
684
- // #10898 D5 — a live tip is never re-drafted for the mark alone.
685
- const liveTip = read.data["status"] === "published";
686
- if (canonical(compared(liveTip ? withoutHubRecords(stored) : stored, content, publicTags)) ===
687
- canonical(compared(liveTip ? withoutHubRecords(content) : content, content, publicTags))) {
688
- return done("unchanged", structureToken, version);
689
- }
690
- // The token is the version just compared against, so a draft saved
691
- // since the read is a 409, never a silent overwrite.
692
- const saved = await call(t, "PATCH", address, content, version);
693
- if ("network" in saved || saved.status !== 200)
694
- return refusedAnswer(page, saved);
695
- stored = saved.data["content"];
696
- sent = true;
697
- // A save carries the structure token forward (#10330 D5).
698
- return (wrongLocale(page, saved, locale) ?? done("updated", structureToken));
695
+ structureToken = typeof token === "string" ? token : null;
696
+ const stored = read.data["content"];
697
+ // #11843 D4 — one comparison, before any write.
698
+ const sameFields = canonical(compared(storedFields(stored, save.fields), sent, publicTags)) ===
699
+ canonical(compared(save.fields, sent, publicTags));
700
+ const sameBody = sameWords(stored?.["body"], save);
701
+ const sameLayout = save.layout === undefined || canonical(read.data["structure"]) === canonical(save.layout);
702
+ if (sameFields && sameBody && sameLayout)
703
+ return outcome("unchanged");
704
+ layoutOnly = sameFields && sameBody;
699
705
  }
700
- if (read.status !== 404 || reread)
706
+ else if (read.status !== 404 || reread) {
701
707
  return refusedAnswer(page, read);
702
- const created = await call(t, "POST", `${t.base}/content`, {
703
- ...content,
704
- locale,
705
- });
706
- if ("network" in created)
707
- return refusedAnswer(page, created);
708
- if (created.status === 201) {
709
- stored = created.data["content"];
710
- sent = true;
711
- return wrongLocale(page, created, locale) ?? done("created");
712
- }
713
- // 409 slug_taken: another page holds this page's registry link (#10268
714
- // D5) — reported as it is, since a re-read at this address finds nothing.
715
- // Any other 409: created by someone else since the read — read it once more.
716
- if (created.status !== 409 || created.code === "slug_taken") {
717
- return refusedAnswer(page, created);
718
708
  }
709
+ const saved = await write(version, structureToken);
710
+ if ("network" in saved)
711
+ return refusedAnswer(page, saved);
712
+ // #11843 D5 — created by someone else since the read: read it once more.
713
+ if (version === null && saved.status === 409 && saved.code === "stale" && !reread)
714
+ continue;
715
+ if (saved.status !== (version === null ? 201 : 200))
716
+ return refusedAnswer(page, saved);
717
+ return (wrongLocale(page, saved, locale, "save") ??
718
+ outcome(version === null ? "created" : "updated", saved.data["fields"], layoutOnly));
719
719
  }
720
720
  }
721
721
  // ── The report (D6) ─────────────────────────────────────────────────────────
@@ -1060,19 +1060,19 @@ function adapterReason(err, stage = "adapter") {
1060
1060
  return `${stage}: ${message.replace(/\s+/g, " ").trim().slice(0, ADAPTER_REASON_MAX)}`;
1061
1061
  }
1062
1062
  /**
1063
- * What the page stores (#10534): with `sections` and a codec, its words after
1064
- * the body's own text and its sections as the layout; else the page as read.
1065
- * Both come from one array, its inline HTML converted (#10804 D2).
1063
+ * What the page saves (#10534, #11843 D1–D3): its fields — the frontmatter
1064
+ * less the keys the address and the words own, and the two hub records a file
1065
+ * never supplies (#10898 D5, #11707 D9) — and, with `sections` and a codec,
1066
+ * the sections as its layout and the codec's words as the body the hub will
1067
+ * build from them; else the file's body. The text before a page's first
1068
+ * section is not sent: nothing renders it (D3). Both come from one array, its
1069
+ * inline HTML converted (#10804 D2).
1066
1070
  */
1067
1071
  function convert(source, codec) {
1068
- const { sections: authored, ...frontmatter } = source.frontmatter;
1069
- if (!Array.isArray(authored) ||
1070
- authored.length === 0 ||
1071
- codec === undefined) {
1072
- return {
1073
- content: { ...source.frontmatter, body: source.body },
1074
- notCarried: [],
1075
- };
1072
+ const fields = Object.fromEntries(Object.entries(source.frontmatter).filter(([key]) => !NOT_FIELDS.has(key)));
1073
+ const authored = source.frontmatter["sections"];
1074
+ if (!Array.isArray(authored) || authored.length === 0 || codec === undefined) {
1075
+ return { fields, body: source.body, notCarried: [] };
1076
1076
  }
1077
1077
  const { sections, notCarried } = sectionsWithoutHtml(authored);
1078
1078
  let words;
@@ -1082,15 +1082,7 @@ function convert(source, codec) {
1082
1082
  catch (err) {
1083
1083
  return { reason: adapterReason(err, "codec") };
1084
1084
  }
1085
- const lead = source.body.trimEnd();
1086
- return {
1087
- content: {
1088
- ...frontmatter,
1089
- body: lead === "" ? words : `${lead}\n\n${words}`,
1090
- },
1091
- layout: { kind: "sections", sections },
1092
- notCarried,
1093
- };
1085
+ return { fields, body: words, layout: { kind: "sections", sections }, notCarried };
1094
1086
  }
1095
1087
  export async function importMdx(opts) {
1096
1088
  const defaultLocale = opts.defaultLocale ?? "en";
@@ -1114,7 +1106,7 @@ export async function importMdx(opts) {
1114
1106
  const rules = opts.adapters.siteFields;
1115
1107
  // #10701 D3 — one route path holds one page, so an editorial index the run
1116
1108
  // will write supersedes the content page of its type at the surface's own
1117
- // slug (the scaffold's teaser), which the create would refuse `slug_taken`.
1109
+ // slug (the scaffold's teaser), which the save would refuse at `address.slug`.
1118
1110
  // Any other slug of the type has a link of its own (#10805 D5).
1119
1111
  const indexTypes = new Set(parseFrontmatter === undefined
1120
1112
  ? []
@@ -1149,10 +1141,11 @@ export async function importMdx(opts) {
1149
1141
  // first in processing order wins and the rest fail. Two pages of different
1150
1142
  // types may share a slug (#10268 D7): the store addresses by type too.
1151
1143
  const addresses = new Map();
1152
- // #11793 D7 (Q7) — an older site's packages cannot say which types are laid
1153
- // out in sections, so its pages without sections are written as read.
1144
+ // #11793 D7 (Q7), #11843 D6 — an older site's packages cannot say which
1145
+ // types are laid out in sections, so its pages without sections are sent
1146
+ // as their body, and the hub refuses one of a sections type.
1154
1147
  if (opts.adapters.laidOutInSections === undefined) {
1155
- onLine("import-mdx: the site's packages cannot say which page types are laid out in sections; pages without sections were written as read");
1148
+ onLine("import-mdx: the site's packages cannot say which page types are laid out in sections; pages without sections are sent as their body; the hub refuses one of a type laid out in sections");
1156
1149
  }
1157
1150
  let halt;
1158
1151
  let publishRefused;
@@ -1216,36 +1209,29 @@ export async function importMdx(opts) {
1216
1209
  }
1217
1210
  const authored = source.frontmatter["sections"];
1218
1211
  const hasSections = Array.isArray(authored) && authored.length > 0;
1219
- // #11793 D7 — a page laid out in sections is never stored with no layout:
1220
- // it fails here, naming why, before anything is sent for it.
1221
- if (converted.layout === undefined &&
1222
- opts.adapters.laidOutInSections?.(page.type) === true) {
1212
+ const sectionsRule = opts.adapters.laidOutInSections?.(page.type);
1213
+ // #11843 D6, D10 — an editorial page's words, and a document's, are its
1214
+ // body: a file of either with sections is never stored as markers with no layout.
1215
+ if (hasSections && (page.type === DOCUMENT_TYPE || sectionsRule === false)) {
1216
+ fail(page.type === DOCUMENT_TYPE
1217
+ ? "sections: a Document's words are its body (save_document takes { body }), and this file has sections; move their words into the body"
1218
+ : `sections: a ${page.type} page's words are its body, and this file has sections; move their words into the body`);
1219
+ continue;
1220
+ }
1221
+ // #11793 D7 — a page laid out in sections is never stored with no layout,
1222
+ // and (#11843) a file's sections are never dropped: each fails here,
1223
+ // naming why, before anything is sent for it.
1224
+ if (converted.layout === undefined && (hasSections || sectionsRule === true)) {
1223
1225
  fail(hasSections
1224
1226
  ? `sections: the site's ${VALIDATION_PACKAGE} has no words codec — update its dependencies and re-run`
1225
1227
  : `sections: a ${page.type} page is laid out in sections, and this file has none — move its words into frontmatter sections`);
1226
1228
  continue;
1227
1229
  }
1228
- // #10898 D5 — a file never supplies the mark; the importer computes it.
1229
- // #11707 D9 — nor the written-from record: a file is never its source.
1230
- const { [LIVE_SOURCE_KEY]: _fileMark, [WRITTEN_FROM_KEY]: _fileRecord, ...words } = converted.content;
1231
- const body = words["body"];
1232
- converted.content =
1233
- opts.liveSource === true && typeof body === "string"
1234
- ? {
1235
- ...words,
1236
- [LIVE_SOURCE_KEY]: {
1237
- bodySha256: createHash("sha256").update(body, "utf8").digest("hex"),
1238
- },
1239
- }
1240
- : words;
1241
1230
  if (converted.notCarried.length > 0) {
1242
1231
  onLine(`${outcomePath(page)}: inline HTML not carried — ${converted.notCarried.join(", ")} (the layout holds no HTML; their text is kept)`);
1243
1232
  }
1244
- if (converted.layout === undefined && hasSections) {
1245
- onLine(`${page.path}: keeps its words in sections — the site's ${VALIDATION_PACKAGE} has no words codec; update its dependencies and re-run`);
1246
- }
1247
1233
  // #10804 D5 — a layout the hub would refuse fails here, in a dry run and
1248
- // under --apply alike, before its words are saved.
1234
+ // under --apply alike, before anything is saved.
1249
1235
  const refusal = converted.layout === undefined
1250
1236
  ? undefined
1251
1237
  : layoutRefusal(converted.layout);
@@ -1253,34 +1239,25 @@ export async function importMdx(opts) {
1253
1239
  fail(`layout: ${refusal}`);
1254
1240
  continue;
1255
1241
  }
1256
- const result = await writePage(t, page, defaultLocale, converted.content, converted.layout, rules?.publicPageTags);
1242
+ const result = await writePage(t, page, defaultLocale, converted, rules?.publicPageTags);
1257
1243
  halt = result.halt;
1258
- // #10898 D5 — a hub that predates the mark strips it, so every re-run
1259
- // would save the page again; say so. An answer that carries no content
1260
- // says nothing about what was kept.
1261
- if (opts.liveSource === true &&
1262
- result.sent === true &&
1263
- result.stored !== null &&
1264
- typeof result.stored === "object" &&
1265
- !Object.hasOwn(result.stored, LIVE_SOURCE_KEY)) {
1266
- onLine(`${outcomePath(page)}: not kept by the hub: ${LIVE_SOURCE_KEY} (the hub predates the live-source mark; update it and re-run)`);
1267
- }
1268
- // #10898 D6 — what the hub's publish gate will answer for these words.
1269
- const check = opts.liveSource === true ? opts.adapters.publishCheck : undefined;
1244
+ // #10898 D6, #11843 D7 — what the hub's publish gate will answer for the
1245
+ // page as it is now stored, with no live-source mark.
1246
+ const check = opts.adapters.publishCheck;
1270
1247
  if (check !== undefined && !("reason" in result.outcome)) {
1271
- const verdict = check(page.type, converted.content, converted.layout);
1248
+ const verdict = check(page.type, { ...converted.fields, type: page.type, slug: page.slug, body: converted.body }, converted.layout);
1272
1249
  if (verdict !== undefined)
1273
1250
  result.outcome = { ...result.outcome, publishVerdict: verdict };
1274
1251
  }
1275
1252
  // #10806 D4 — an older hub strips what it has no member for; say so.
1276
- // An answer that carries no content says nothing about what was kept.
1253
+ // An answer that carries no fields says nothing about what was kept.
1277
1254
  const dropped = rules === undefined ||
1278
1255
  page.root !== "editorial" ||
1279
1256
  "reason" in result.outcome ||
1280
1257
  result.stored === null ||
1281
1258
  typeof result.stored !== "object"
1282
1259
  ? []
1283
- : notKept(converted.content, result.stored, rules);
1260
+ : notKept({ ...converted.fields, type: page.type }, result.stored, rules);
1284
1261
  if (dropped.length > 0) {
1285
1262
  onLine(`${page.path}: not kept by the hub: ${dropped.join(", ")} (the hub predates site fields; update it and re-run)`);
1286
1263
  }
@@ -1328,12 +1305,12 @@ export async function importMdx(opts) {
1328
1305
  };
1329
1306
  }
1330
1307
  /**
1331
- * The hub's publish gate over a live-source page, as the site's contract
1332
- * reads it: the page's words checked against its type's template and the
1333
- * structure publish's repair would build — the layout when the page converts,
1334
- * an editorial template's frontmatter quartet, else none — with the
1335
- * required-heading findings advisory. Publish repairs every `script` finding,
1336
- * so only the rest block.
1308
+ * The hub's publish gate over a page, as the site's contract reads it: the
1309
+ * page's words checked against its type's template and the structure
1310
+ * publish's repair would build — the layout when the page converts, an
1311
+ * editorial template's frontmatter quartet, else none. No live-source split
1312
+ * is applied: no save keeps the mark (#11843 D7). Publish repairs every
1313
+ * `script` finding, so only the rest block.
1337
1314
  */
1338
1315
  export function publishCheckOf(members) {
1339
1316
  return (type, content, layout) => {
@@ -1351,13 +1328,13 @@ export function publishCheckOf(members) {
1351
1328
  frontmatter: Object.fromEntries(EDITORIAL_STRUCTURE_FIELDS.filter((field) => content[field] !== undefined).map((field) => [field, content[field]])),
1352
1329
  }
1353
1330
  : null);
1354
- const report = members.liveSourceReport(members.checkPage({
1331
+ const report = members.checkPage({
1355
1332
  template,
1356
1333
  title: text("title"),
1357
1334
  description: text("description"),
1358
1335
  slug: text("slug"),
1359
1336
  body: text("body"),
1360
- }, structure));
1337
+ }, structure);
1361
1338
  const blocking = report.issues.filter((issue) => issue.fixer !== "script");
1362
1339
  return blocking.length === 0
1363
1340
  ? { publishable: true, advisory: report.advisory ?? [] }
@@ -1447,8 +1424,8 @@ export async function loadSiteMdxAdapter(siteRoot) {
1447
1424
  // Not resolvable from the adapter: no parser.
1448
1425
  }
1449
1426
  // #10898 D6 — the site's own page-type registry, beside its contract; a
1450
- // validation package that predates the live-source report, or no registry,
1451
- // leaves the dry run's publish verdict unchecked, and the run says so.
1427
+ // validation package with no content check, or no registry, leaves the dry
1428
+ // run's publish verdict unchecked, and the run says so.
1452
1429
  let registry;
1453
1430
  try {
1454
1431
  const path = createRequire(entry).resolve(PAGE_TYPES_PACKAGE);
@@ -1457,7 +1434,7 @@ export async function loadSiteMdxAdapter(siteRoot) {
1457
1434
  catch {
1458
1435
  // Not resolvable from the adapter: no registry.
1459
1436
  }
1460
- const { checkPage, liveSourceReport, PAGE_TEMPLATES: templates } = validation;
1437
+ const { checkPage, PAGE_TEMPLATES: templates } = validation;
1461
1438
  return {
1462
1439
  ...mod,
1463
1440
  ...(typeof codec === "function" && {
@@ -1475,13 +1452,11 @@ export async function loadSiteMdxAdapter(siteRoot) {
1475
1452
  },
1476
1453
  }),
1477
1454
  ...(typeof checkPage === "function" &&
1478
- typeof liveSourceReport === "function" &&
1479
1455
  templates !== null &&
1480
1456
  typeof templates === "object" &&
1481
1457
  Array.isArray(registry) && {
1482
1458
  publishCheck: publishCheckOf({
1483
1459
  checkPage: checkPage,
1484
- liveSourceReport: liveSourceReport,
1485
1460
  templates: templates,
1486
1461
  registry: registry,
1487
1462
  }),
@@ -1,6 +1,8 @@
1
1
  export declare const LICENSE_KEY_FILE = "ailk.key";
2
2
  export declare const LICENSE_ENV_FILE: string;
3
3
  export declare const LICENSE_ENV_VAR = "AILK_LICENSE_KEY";
4
+ /** The site's own key (D6): `<target>/ailk.key`, else `AILK_LICENSE_KEY`, else none. */
5
+ export declare function readSiteKey(targetAbs: string, env: NodeJS.ProcessEnv): string | undefined;
4
6
  /**
5
7
  * Throws unless `key` is 1–4096 characters of `[A-Za-z0-9._-]`. The message
6
8
  * describes the rule, never the value.
@@ -21,6 +21,17 @@ import { dirname, join } from "node:path";
21
21
  export const LICENSE_KEY_FILE = "ailk.key";
22
22
  export const LICENSE_ENV_FILE = join("apps", "api", ".env");
23
23
  export const LICENSE_ENV_VAR = "AILK_LICENSE_KEY";
24
+ /** The site's own key (D6): `<target>/ailk.key`, else `AILK_LICENSE_KEY`, else none. */
25
+ export function readSiteKey(targetAbs, env) {
26
+ const keyPath = join(targetAbs, LICENSE_KEY_FILE);
27
+ if (existsSync(keyPath)) {
28
+ const key = readFileSync(keyPath, "utf8").trim();
29
+ if (key.length > 0)
30
+ return key;
31
+ }
32
+ const fromEnv = env["AILK_LICENSE_KEY"];
33
+ return fromEnv !== undefined && fromEnv.length > 0 ? fromEnv : undefined;
34
+ }
24
35
  const KEY_SHAPE = /^[A-Za-z0-9._-]{1,4096}$/;
25
36
  /** `.gitignore` lines that already ignore a root `ailk.key`. */
26
37
  const KEY_IGNORE_LINES = new Set([