create-ailk 0.46.3 → 0.46.5

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.
@@ -529,6 +529,15 @@ const NO_STRUCTURED_DATA_ROUTES: ReadonlyArray<{
529
529
  route: "how-to",
530
530
  reason: "hand-composed listing; no HowTo list type exists",
531
531
  },
532
+ // #12204 D6 — the three-or-more-segment catch-all serves only a magnet's
533
+ // children at an owner-chosen address (its walk, verify and results pages)
534
+ // through `site.magnetAddress`, and reads no content. Keyed on that call, so
535
+ // a page that renders content here is checked like any other.
536
+ {
537
+ route: "[slug]/[detail]/[...rest]",
538
+ reason: "a magnet's children at its owner-chosen address (#12204 D6), served through site.magnetAddress; no content page behind it",
539
+ requires: ["site.magnetAddress.pageAt"],
540
+ },
532
541
  {
533
542
  route: "careers/[slug]/[action]",
534
543
  reason: "the Free apply form for a posting; noindex, no JSON-LD (#8849 D7)",
@@ -1051,9 +1060,17 @@ describe("structured data — exemption(route, src) keys the generated checkout
1051
1060
  expect(exemption("about", GENERATED_SRC)).toBeUndefined();
1052
1061
  });
1053
1062
 
1063
+ it("exempts the magnet-address catch-all only while its page serves through site.magnetAddress (#12204 D6)", () => {
1064
+ const route = "[slug]/[detail]/[...rest]";
1065
+ const served = "const magnet = await site.magnetAddress.pageAt(\n [slug, detail, ...rest],";
1066
+ expect(exemption(route, served)).toContain("#12204 D6");
1067
+ expect(exemption(route, "")).toBeUndefined();
1068
+ expect(exemption(route, 'return renderPage({ type: "LandingPage", slug });')).toBeUndefined();
1069
+ });
1070
+
1054
1071
  it("every pre-existing entry still returns its reason for its own route with any src, subtree entries included", () => {
1055
1072
  for (const entry of NO_STRUCTURED_DATA_ROUTES) {
1056
- if (entry.requires !== undefined) continue; // the two conditional entries above, checked above
1073
+ if (entry.requires !== undefined) continue; // a conditional entry keys on its file; see its own case
1057
1074
  expect(exemption(entry.route, "")).toBe(entry.reason);
1058
1075
  if (entry.subtree === true) {
1059
1076
  expect(exemption(`${entry.route}/child`, "")).toBe(entry.reason);
@@ -0,0 +1,175 @@
1
+ /**
2
+ * in-page-blocks.ts — the site's renderer for a page body's block lines
3
+ * (#12222, spec docs/specs/12222-capabilities-and-alternatives-what-a-spec.md
4
+ * D13, D18; B4 #12293).
5
+ *
6
+ * `@working-theory/page-renderer` finds each `<Offer … />` or `<Grid … />`
7
+ * line in a prose or mdx-body page (`resolveBodyBlocks`, the one grammar
8
+ * `parseBlockLine`) and asks the renderer registered here, at module load,
9
+ * for its node. The locale layout imports this module, as it imports
10
+ * `in-page-magnet`, so every page render has it.
11
+ *
12
+ * - **Offer.** One `pricing` section bound to the shown set
13
+ * (`source: "offerings"`, `offeringPlans`, `billingToggle` from `yearly`),
14
+ * run through `pricingSections` with `recommended` as the page's `?plan=`,
15
+ * so the cards are today's Stripe cards. Anything but Stripe cards — an
16
+ * unconnected site, an expired set, plans not shown — renders nothing.
17
+ * - **Grid.** The public read, `GET /v1/content/grids/:kind/:slug`, through
18
+ * api-client `content.grid`, shared per instance for 15 s
19
+ * (`sharedHubRead`), parsed by `GridAnswerSchema` and worded by
20
+ * `gridSection` with the page locale's `grids` messages — no English
21
+ * default reaches a page (D18). With `price` or `button`, the table's plan
22
+ * columns take their price and button from the shown set through
23
+ * `pricingSections`' plan-column resolver. Drawn through `SectionRenderer`.
24
+ *
25
+ * A read that fails, an answer that does not parse, an empty grid or a throw
26
+ * renders nothing (`null`), so a page never breaks on a block; page-renderer
27
+ * adds its own 3,000 ms backstop. The grid's data is never written anywhere:
28
+ * every render reads the published facts and Stripe's features afresh.
29
+ */
30
+ import { content } from "@working-theory/api-client";
31
+ import { setBodyBlockRenderer, type BodyBlockRenderer } from "@working-theory/page-renderer";
32
+ import { SectionRenderer } from "@working-theory/ui";
33
+ import {
34
+ GridAnswerSchema,
35
+ gridSection,
36
+ writeBlockLine,
37
+ type GridAnswer,
38
+ type GridBlock,
39
+ type GridLabels,
40
+ type OfferBlock,
41
+ type PageSection,
42
+ } from "@working-theory/validation";
43
+ import { unstable_rethrow } from "next/navigation";
44
+ import { getTranslations } from "next-intl/server";
45
+ import { createElement, type ReactElement } from "react";
46
+
47
+ import { sharedHubRead } from "./in-page-magnet";
48
+ import { pricingSections } from "./pricing-page";
49
+
50
+ type Sections = PageSection[];
51
+
52
+ /** The section list as `SectionRenderer` draws it, or `null` when there is none. */
53
+ function drawn(sections: Sections, locale: string): ReactElement | null {
54
+ return sections.length === 0 ? null : createElement(SectionRenderer, { sections, locale });
55
+ }
56
+
57
+ /** A bound pricing section for `plans` (#12140 D1), the one shape both blocks hand `pricingSections`. */
58
+ function boundPlans(id: string, plans: readonly string[], billingToggle: boolean): PageSection {
59
+ return {
60
+ type: "pricing",
61
+ id,
62
+ data: {
63
+ plans: [],
64
+ source: "offerings",
65
+ offeringPlans: [...plans],
66
+ ...(billingToggle ? { billingToggle: true } : {}),
67
+ },
68
+ } as PageSection;
69
+ }
70
+
71
+ /** A pricing section that carries Stripe cards: bound, with plans placed. */
72
+ function carriesCards(section: PageSection): boolean {
73
+ if (section.type !== "pricing") return false;
74
+ const data = section.data as { plans?: unknown[] };
75
+ return Array.isArray(data.plans) && data.plans.length > 0;
76
+ }
77
+
78
+ // ── Offer ──────────────────────────────────────────────────────────
79
+
80
+ export async function renderOffer(block: OfferBlock, locale: string): Promise<ReactElement | null> {
81
+ // The grammar holds one of the two: a slug, or 2–6 plans.
82
+ const plans = block.plans ?? [block.slug!];
83
+ const sections = await pricingSections([boundPlans(`offer-${plans.join("-")}`, plans, block.yearly === true)], {
84
+ plans: undefined,
85
+ plan: block.recommended,
86
+ locale,
87
+ });
88
+ return drawn(sections.filter(carriesCards), locale);
89
+ }
90
+
91
+ // ── Grid ───────────────────────────────────────────────────────────
92
+
93
+ /** The grid read, or `null` for any failed read or an answer that does not parse. */
94
+ export function readGrid(block: GridBlock, locale: string): Promise<GridAnswer | null> {
95
+ const key = `grid:${locale}:${writeBlockLine({ tag: "Grid", block })}`;
96
+ return sharedHubRead(key, async () => {
97
+ try {
98
+ const res = await content.grid({
99
+ kind: block.kind,
100
+ slug: block.kind === "capabilities" ? block.products.join(" ") : block.category,
101
+ show: block.show,
102
+ ...(block.kind === "capabilities" && block.levels !== undefined ? { levels: block.levels.join(" ") } : {}),
103
+ ...(block.kind === "alternatives" && block.ours !== undefined ? { ours: block.ours } : {}),
104
+ ...(block.kind === "alternatives" && block.columns !== undefined ? { columns: block.columns.join(" ") } : {}),
105
+ locale,
106
+ });
107
+ if (!res.ok) return null;
108
+ const parsed = GridAnswerSchema.safeParse(res.body);
109
+ return parsed.success ? parsed.data : null;
110
+ } catch {
111
+ return null;
112
+ }
113
+ });
114
+ }
115
+
116
+ /** The page locale's `grids` words (D18): every fixed word a grid shows. */
117
+ export async function gridLabels(locale: string): Promise<GridLabels> {
118
+ const t = await getTranslations({ locale, namespace: "grids" });
119
+ const dates = new Intl.DateTimeFormat(locale, { dateStyle: "medium", timeZone: "UTC" });
120
+ return {
121
+ fromLevel: (level) => t("fromLevel", { level }),
122
+ addon: t("addon"),
123
+ ourAssessment: t("ourAssessment"),
124
+ checked: (date) => t("checked", { date }),
125
+ factsAsOf: (date) => t("factsAsOf", { date }),
126
+ countOf: (yes, of) => t("countOf", { yes, of }),
127
+ capabilities: t("capabilities"),
128
+ labelHeader: t("labelHeader"),
129
+ planPicker: t("planPicker"),
130
+ formatDate: (isoDate) => dates.format(new Date(`${isoDate}T00:00:00Z`)),
131
+ };
132
+ }
133
+
134
+ export async function renderGrid(block: GridBlock, locale: string): Promise<ReactElement | null> {
135
+ const answer = await readGrid(block, locale);
136
+ if (answer === null) return null;
137
+ const options =
138
+ block.kind === "capabilities" ? { price: block.price, button: block.button } : { source: block.source };
139
+ const data = gridSection(answer, await gridLabels(locale), options);
140
+ if (data === null) return null;
141
+ const table = {
142
+ type: "comparison-table",
143
+ id: `grid-${block.kind}-${block.kind === "capabilities" ? block.products.join("-") : block.category}`,
144
+ data,
145
+ } as PageSection;
146
+ const plans = answer.columns.flatMap((column) => (column.ours && column.plan !== undefined ? [column.plan] : []));
147
+ if (block.kind !== "capabilities" || (block.price !== true && block.button !== true) || plans.length === 0) {
148
+ return drawn([table], locale);
149
+ }
150
+ // The plan bar's price and button come from the shown set: `pricingSections`
151
+ // resolves a table's plan columns beside a bound pricing section, which is
152
+ // read for that and never drawn.
153
+ const resolved = await pricingSections([boundPlans(`${table.id}-plans`, plans, false), table], {
154
+ plans: undefined,
155
+ plan: undefined,
156
+ locale,
157
+ });
158
+ return drawn(
159
+ resolved.filter((section) => section.type === "comparison-table"),
160
+ locale,
161
+ );
162
+ }
163
+
164
+ /** The renderer page-renderer asks for each block line (D13). */
165
+ export const renderBodyBlock: BodyBlockRenderer = async ({ block, locale }) => {
166
+ try {
167
+ return block.tag === "Offer" ? await renderOffer(block.block, locale) : await renderGrid(block.block, locale);
168
+ } catch (err) {
169
+ unstable_rethrow(err);
170
+ console.warn("[body-blocks] render failed; the block is left out");
171
+ return null;
172
+ }
173
+ };
174
+
175
+ setBodyBlockRenderer(renderBodyBlock);