create-ailk 0.46.2 → 0.46.3

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.
@@ -10,6 +10,7 @@
10
10
  import {
11
11
  PageSectionsSchema,
12
12
  workspaceShownSetSchema,
13
+ type OfferingsContactProduct,
13
14
  type OfferingsPrice,
14
15
  type OfferingsProduct,
15
16
  type PageSection,
@@ -27,6 +28,8 @@ import {
27
28
  pagePlans,
28
29
  PRICING_HUB_SLUG,
29
30
  pricingPageCard,
31
+ pricingPagesHeading,
32
+ pricingPagesSectionEnabled,
30
33
  pricingSections,
31
34
  withContactFallback,
32
35
  withOfferings,
@@ -114,6 +117,26 @@ describe("pagePlans (#10044 D1)", () => {
114
117
  });
115
118
  });
116
119
 
120
+ describe("pricingPagesHeading (#12213 AC-1)", () => {
121
+ it("reads the hub's heading override, or undefined when unset", () => {
122
+ expect(pricingPagesHeading({ pricingPagesHeading: "Pick your plan" })).toBe(
123
+ "Pick your plan",
124
+ );
125
+ expect(pricingPagesHeading({})).toBeUndefined();
126
+ expect(pricingPagesHeading(null)).toBeUndefined();
127
+ expect(pricingPagesHeading({ pricingPagesHeading: 1 })).toBeUndefined();
128
+ });
129
+ });
130
+
131
+ describe("pricingPagesSectionEnabled (#12213 AC-2, AC-3)", () => {
132
+ it("is on by default and off only when the frontmatter sets it false", () => {
133
+ expect(pricingPagesSectionEnabled({})).toBe(true);
134
+ expect(pricingPagesSectionEnabled(null)).toBe(true);
135
+ expect(pricingPagesSectionEnabled({ pricingPagesSection: true })).toBe(true);
136
+ expect(pricingPagesSectionEnabled({ pricingPagesSection: false })).toBe(false);
137
+ });
138
+ });
139
+
117
140
  describe("pricingSections (#10044 AC-4)", () => {
118
141
  const declared: PageSection[] = PageSectionsSchema.parse([
119
142
  {
@@ -169,6 +192,7 @@ const LABELS: OfferingsPricingLabels = {
169
192
  withRequired: (plan, required) => "W⟪" + plan + "⟫" + required,
170
193
  depositNote: (deposit) => "D⟪" + deposit,
171
194
  billedYearly: (amount) => "B⟪" + amount,
195
+ custom: "C⟪",
172
196
  };
173
197
  const RECOMMENDED_LABEL = "FOR-YOU⟪";
174
198
  const ADDONS_HEADLINE = "ADDONS⟪";
@@ -922,3 +946,255 @@ describe("a bound section's offeringGroups and writtenPlans (#12174 AC-5, AC-7)"
922
946
  expect(p?.type === "pricing" && p.data.plans.map((c) => c.key)).toEqual(["fallback"]);
923
947
  });
924
948
  });
949
+
950
+ // ─── #12193 — cards built from Stripe ───────────────────────────────────────
951
+
952
+ /** `stripeSet()` with `edit` applied to its offerings and these contacts. */
953
+ function stripeSetWith(
954
+ edit: (offerings: OfferingsProduct[]) => void,
955
+ contacts: OfferingsContactProduct[] = [],
956
+ ): WorkspaceShownSet {
957
+ const set = structuredClone(stripeSet());
958
+ edit(set.offerings);
959
+ set.productIds = set.offerings.map((o) => o.productId);
960
+ if (contacts.length > 0) set.contacts = contacts;
961
+ return workspaceShownSetSchema.parse(set);
962
+ }
963
+
964
+ const COMMERCE: OfferingsContactProduct = {
965
+ productId: "prod_commerce",
966
+ plan: "commerce",
967
+ ailkGroup: "addon",
968
+ name: "Growth Hub Commerce",
969
+ description: null,
970
+ marketingFeatures: [],
971
+ ailkOrder: null,
972
+ url: "https://example.com/contact",
973
+ ctaLabel: "Talk to us",
974
+ priceText: "From 179 USD a month",
975
+ shortName: "Commerce",
976
+ collection: "growth-hub",
977
+ };
978
+
979
+ describe("a selecting bound section builds its cards from Stripe (#12193 D5, AC-2, AC-4, AC-7)", () => {
980
+ it("a collection section's tier card takes nothing from the page", () => {
981
+ const set = stripeSetWith((o) => {
982
+ for (const p of o) if (p.plan === "growth" || p.plan === "writing") Object.assign(p, { collection: "c", tier: "Individual" });
983
+ });
984
+ const section = pricingSection("p", {
985
+ source: "offerings",
986
+ offeringCollection: "c",
987
+ plans: [{ name: "Page name", description: "Page desc", price: {}, features: [], cta: { label: "x", href: "/x" } }],
988
+ });
989
+ const { placed } = render([section], { set });
990
+ const card = dataOf(placed, "p").plans[0]!;
991
+ expect(card.name).toBe("Individual");
992
+ expect(card.description).not.toBe("Page desc");
993
+ expect(card.levels!.map((l) => l.key)).toEqual(["growth", "writing"]);
994
+ });
995
+
996
+ it("a collection section shows its collection, matched lowercased; the unbound slot leaves those plans out", () => {
997
+ const tagged = (extra?: OfferingsProduct) =>
998
+ stripeSetWith((o) => {
999
+ for (const p of o) if (p.plan === "growth" || p.plan === "writing") p.collection = "Growth-Platform";
1000
+ if (extra) o.push(extra);
1001
+ });
1002
+ const sections = [
1003
+ HERO,
1004
+ pricingSection("c", { source: "offerings", offeringCollection: "growth-platform" }),
1005
+ pricingSection("rest"),
1006
+ ];
1007
+ const { placed } = render(sections, { set: tagged(), plans: ["essentials"] });
1008
+ expect(keysOf(placed, "c")).toEqual(["growth", "writing"]);
1009
+ expect(keysOf(placed, "rest")).toEqual(["essentials"]);
1010
+ const pro = stripeProduct("pro", "plan", [stripePrice("pro", "monthly", 5000)], { collection: "growth-platform" });
1011
+ expect(keysOf(render(sections, { set: tagged(pro), plans: ["essentials"] }).placed, "c")).toEqual(["growth", "pro", "writing"]);
1012
+ });
1013
+
1014
+ it("an add-ons section selects its collection, the contact tile included", () => {
1015
+ const set = stripeSetWith((o) => {
1016
+ o.find((p) => p.plan === "seo")!.collection = "growth-hub";
1017
+ }, [COMMERCE]);
1018
+ const { placed } = render(
1019
+ [pricingSection("p"), pricingSection("a", { source: "offerings", variant: "addons", offeringCollection: "growth-hub" })],
1020
+ { set },
1021
+ );
1022
+ expect(dataOf(placed, "a").addons!.map((t) => (t as { key?: string }).key)).toEqual(["seo", "commerce"]);
1023
+ });
1024
+
1025
+ it("a section with offeringPlans keeps one card per plan though the plans carry a tier (AC-17)", () => {
1026
+ const set = stripeSetWith((o) => {
1027
+ for (const p of o) if (p.ailkGroup === "plan") p.tier = "T";
1028
+ });
1029
+ const { placed } = render([pricingSection("p", { source: "offerings", offeringPlans: ["growth", "writing"] })], { set });
1030
+ expect(keysOf(placed, "p")).toEqual(["growth", "writing"]);
1031
+ for (const card of dataOf(placed, "p").plans) expect(card).not.toHaveProperty("levels");
1032
+ });
1033
+
1034
+ it("a contact appears in no unbound slot (AC-17)", () => {
1035
+ const set = stripeSetWith(() => {}, [{ ...COMMERCE, ailkGroup: "plan", plan: "enterprise", productId: "prod_e" }]);
1036
+ expect(allKeys(render([pricingSection("p")], { set }).placed)).not.toContain("enterprise");
1037
+ });
1038
+ });
1039
+
1040
+ describe("pricingSections — the toggle field, ?plan= and ?billing=, and the render-time strip (#12193 D7, D9, D11)", () => {
1041
+ // Past every earlier suite's mocked clock, so no shared read of theirs is reused.
1042
+ let now = Date.now() + 10 ** 12;
1043
+ const unconnected = fetchMock.getMockImplementation();
1044
+ beforeEach(() => {
1045
+ jest.spyOn(Date, "now").mockReturnValue(now);
1046
+ });
1047
+ afterEach(() => {
1048
+ jest.restoreAllMocks();
1049
+ fetchMock.mockReset();
1050
+ fetchMock.mockImplementation(unconnected);
1051
+ });
1052
+
1053
+ /** Answer every read with `data`, past the shared read's window. */
1054
+ const answer = (data: unknown) => {
1055
+ now += 16_000;
1056
+ jest.spyOn(Date, "now").mockReturnValue(now);
1057
+ fetchMock.mockReset();
1058
+ fetchMock.mockImplementation(async () => ({
1059
+ ok: true,
1060
+ status: 200,
1061
+ json: async () => ({ ok: true, data }),
1062
+ }));
1063
+ };
1064
+
1065
+ it("a stored billingToggle: false hides nothing on a bound section; hideBillingToggle is kept (AC-11)", async () => {
1066
+ answer({ status: "shown", shownSet: stripeSet() });
1067
+ const off = await pricingSections([pricingSection("p", { source: "offerings", billingToggle: false })], {
1068
+ plans: undefined,
1069
+ plan: undefined,
1070
+ locale: "en",
1071
+ });
1072
+ expect(dataOf(off, "p").billingToggle).toBe(true);
1073
+ const hidden = await pricingSections(
1074
+ [pricingSection("p", { source: "offerings", billingToggle: false, hideBillingToggle: true })],
1075
+ { plans: undefined, plan: undefined, locale: "en" },
1076
+ );
1077
+ expect(dataOf(hidden, "p").hideBillingToggle).toBe(true);
1078
+ });
1079
+
1080
+ it("sets selectedPlan and billingPeriod on every pricing section, on the shown and unconnected reads (AC-15)", async () => {
1081
+ answer({ status: "shown", shownSet: stripeSet() });
1082
+ const shown = await pricingSections([pricingSection("p")], { plans: undefined, plan: "ind-pb", period: "monthly", locale: "en" });
1083
+ expect(dataOf(shown, "p")).toMatchObject({ selectedPlan: "ind-pb", billingPeriod: "monthly" });
1084
+ const yearly = await pricingSections([pricingSection("p")], { plans: undefined, plan: "ind-pb", period: "yearly", locale: "en" });
1085
+ expect(dataOf(yearly, "p")).not.toHaveProperty("billingPeriod");
1086
+ answer({ status: "unconnected" });
1087
+ const unconnected = await pricingSections([pricingSection("p")], {
1088
+ plans: undefined,
1089
+ plan: "ind-pb",
1090
+ period: "annual",
1091
+ locale: "en",
1092
+ });
1093
+ expect(dataOf(unconnected, "p")).toMatchObject({ selectedPlan: "ind-pb", billingPeriod: "annual" });
1094
+ const badPlan = await pricingSections([pricingSection("p")], { plans: undefined, plan: "IND PB", period: undefined, locale: "en" });
1095
+ expect(dataOf(badPlan, "p")).not.toHaveProperty("selectedPlan");
1096
+ });
1097
+
1098
+ it("strips an authored offerPrices, selectedPlan and billingPeriod on every path (AC-13, security)", async () => {
1099
+ answer({ status: "unconnected" });
1100
+ const offerPrices = [{ amount: "1", currency: "USD", period: "month" }];
1101
+ const plan = { key: "a", name: "A", price: { monthly: "$9" }, features: [], cta: { label: "Go", href: "/go" }, offerPrices };
1102
+ const section = pricingSection("w", {
1103
+ source: "written",
1104
+ selectedPlan: "a",
1105
+ billingPeriod: "annual",
1106
+ plans: [{ ...plan, levels: [{ ...plan, label: "L1" }, { ...plan, label: "L2" }] }],
1107
+ extraTier: plan,
1108
+ });
1109
+ for (const options of [
1110
+ { plans: undefined, plan: undefined, locale: "en" },
1111
+ { plans: [] as string[], plan: undefined, locale: "en" },
1112
+ ]) {
1113
+ const [out] = await pricingSections([section], options);
1114
+ const data = out!.data as Record<string, unknown> & { plans: Array<Record<string, unknown> & { levels: Record<string, unknown>[] }> };
1115
+ expect(data).not.toHaveProperty("selectedPlan");
1116
+ expect(data).not.toHaveProperty("billingPeriod");
1117
+ expect(data.plans[0]).not.toHaveProperty("offerPrices");
1118
+ for (const level of data.plans[0]!.levels) expect(level).not.toHaveProperty("offerPrices");
1119
+ expect(data.extraTier).not.toHaveProperty("offerPrices");
1120
+ }
1121
+ const bound = pricingSection("b", { source: "offerings", writtenPlans: [plan] });
1122
+ answer({ status: "shown", shownSet: stripeSet() });
1123
+ const [placed] = await pricingSections([bound], { plans: undefined, plan: undefined, locale: "en" });
1124
+ const written = (placed!.data as { plans: Array<Record<string, unknown>> }).plans.find((c) => c.key === "a")!;
1125
+ expect(written).not.toHaveProperty("offerPrices");
1126
+ });
1127
+ });
1128
+
1129
+ // ─── #12209 — the level card's settings on a Stripe section ─────────────────
1130
+
1131
+ describe("a bound section keeps the level card's settings (#12209 D2, D8, D11, D12)", () => {
1132
+ const tiered = (n = 2) =>
1133
+ stripeSetWith((o) => {
1134
+ for (const p of o) if (p.plan === "growth" || p.plan === "writing") p.tier = "Individual";
1135
+ for (let i = 1; i <= n - 2; i++) {
1136
+ o.push(stripeProduct(`more-${i}`, "plan", [stripePrice(`more-${i}`, "monthly", 4000 + i)], { tier: "Individual" }));
1137
+ }
1138
+ });
1139
+ const levelOf = (label: string, plan: string) => ({ label, plan });
1140
+
1141
+ it("carries the control, the derived detail and the level heading onto the placed section (AC-1)", () => {
1142
+ const section = pricingSection("p", {
1143
+ source: "offerings",
1144
+ levelSwitchControl: "select",
1145
+ levelSwitchDetail: "price",
1146
+ showLevelHeading: true,
1147
+ });
1148
+ const data = dataOf(render([section], { set: tiered() }).placed, "p");
1149
+ expect(data.levelSwitchControl).toBe("select");
1150
+ expect(data.levelSwitchDetail).toBe("price");
1151
+ expect(data.showLevelHeading).toBe(true);
1152
+ });
1153
+
1154
+ it("an offeringGroups entry's control reaches its placed card, and none when it sets none (AC-1)", () => {
1155
+ const group = { key: "team", name: "Team", levels: [levelOf("Lite", "essentials"), levelOf("Full", "writing")] };
1156
+ const withControl = render([pricingSection("p", { source: "offerings", offeringGroups: [{ ...group, levelSwitchControl: "select" }] })]);
1157
+ expect(dataOf(withControl.placed, "p").plans[0]!.levelSwitchControl).toBe("select");
1158
+ const without = render([pricingSection("p", { source: "offerings", offeringGroups: [group] })]);
1159
+ expect(dataOf(without.placed, "p").plans[0]!).not.toHaveProperty("levelSwitchControl");
1160
+ });
1161
+
1162
+ it("no authored level detail survives onto a bound section's cards (AC-3, SEC-12209-1)", () => {
1163
+ const authored = {
1164
+ name: "Page",
1165
+ price: { monthly: "$1/mo" },
1166
+ features: [],
1167
+ cta: { label: "Go", href: "/go" },
1168
+ levels: [
1169
+ { label: "A", detail: "$1/mo", price: { monthly: "$1/mo" }, features: [], cta: { label: "Go", href: "/a" } },
1170
+ { label: "B", detail: "$1/mo", price: { monthly: "$1/mo" }, features: [], cta: { label: "Go", href: "/b" } },
1171
+ ],
1172
+ };
1173
+ const { placed } = render([pricingSection("p", { source: "offerings", plans: [authored] })], { set: tiered() });
1174
+ for (const card of dataOf(placed, "p").plans) for (const level of card.levels ?? []) expect(level).not.toHaveProperty("detail");
1175
+ expect(JSON.stringify(dataOf(placed, "p").plans)).not.toContain('"detail"');
1176
+ });
1177
+
1178
+ it("a select section places a tier card with up to twenty levels; segments keep four (AC-8)", () => {
1179
+ const set = tiered(22);
1180
+ const select = render([pricingSection("p", { source: "offerings", levelSwitchControl: "select" })], { set });
1181
+ expect(dataOf(select.placed, "p").plans.find((c) => c.name === "Individual")!.levels).toHaveLength(20);
1182
+ const segments = render([pricingSection("p", { source: "offerings" })], { set });
1183
+ expect(dataOf(segments.placed, "p").plans.find((c) => c.name === "Individual")!.levels).toHaveLength(4);
1184
+ });
1185
+
1186
+ it("separateTiers shows the same tier as separate cards, and is not carried into the placed section (AC-9)", () => {
1187
+ const set = tiered();
1188
+ const { placed } = render(
1189
+ [pricingSection("one", { source: "offerings" }), pricingSection("two", { source: "offerings", separateTiers: true })],
1190
+ { set },
1191
+ );
1192
+ const one = dataOf(placed, "one").plans;
1193
+ const two = dataOf(placed, "two").plans;
1194
+ expect(one.filter((c) => (c.levels?.length ?? 0) >= 2).map((c) => c.levels!.map((l) => l.key))).toEqual([["growth", "writing"]]);
1195
+ expect(two.map((c) => c.key)).toEqual(expect.arrayContaining(["growth", "writing"]));
1196
+ for (const c of two) expect(c).not.toHaveProperty("levels");
1197
+ expect(dataOf(placed, "one")).not.toHaveProperty("separateTiers");
1198
+ expect(dataOf(placed, "two")).not.toHaveProperty("separateTiers");
1199
+ });
1200
+ });
@@ -27,6 +27,18 @@ jest.mock("@working-theory/page-renderer", () => ({
27
27
  },
28
28
  }));
29
29
 
30
+ // #12204 D8 — the magnet addresses the site serves (`lib/magnet-addresses`).
31
+ // None by default; the third-source cases set them.
32
+ let mockServedAddresses: { path: string; title: string }[] = [];
33
+ let mockAddressesThrow = false;
34
+ // eslint-disable-next-line no-restricted-syntax -- #507: the address table's one reader; mocked so no case reads a hub or loads the paid package (#12204)
35
+ jest.mock("../magnet-addresses", () => ({
36
+ servedAddresses: async () => {
37
+ if (mockAddressesThrow) throw new Error("no table");
38
+ return mockServedAddresses;
39
+ },
40
+ }));
41
+
30
42
  function page(type: string, slug: string, title: string) {
31
43
  return { type, slug, title };
32
44
  }
@@ -70,6 +82,8 @@ beforeEach(() => {
70
82
  root = mkdtempSync(join(tmpdir(), "served-pages-"));
71
83
  jest.spyOn(process, "cwd").mockReturnValue(root);
72
84
  mockAdapterThrows = false;
85
+ mockServedAddresses = [];
86
+ mockAddressesThrow = false;
73
87
  mockListPages.mockReset();
74
88
  mockListPages.mockImplementation((type: string) => {
75
89
  if (type === "AboutPage")
@@ -218,3 +232,33 @@ describe("servedPages — what still falls through", () => {
218
232
  expect(warn).toHaveBeenCalledWith(expect.stringContaining("[served-pages]"));
219
233
  });
220
234
  });
235
+
236
+ describe("servedPages — magnet addresses (#12204 D8)", () => {
237
+ it("serves an address with its magnet's title, so a page under it walks up to it", async () => {
238
+ mockServedAddresses = [{ path: "/agencies/apply", title: "Agency application" }];
239
+ const pages = await loadServed("en");
240
+ expect(pages.get("/agencies/apply")).toBe("Agency application");
241
+ await expect(arrowParent("/agencies/apply/start")).resolves.toBe("/agencies/apply");
242
+ });
243
+
244
+ it("keeps the other sources when the address table cannot be read", async () => {
245
+ mockAddressesThrow = true;
246
+ const pages = await loadServed("en");
247
+ expect(pages.get("/about")).toBe("About us");
248
+ });
249
+ });
250
+
251
+ describe("staticFirstSegments (#12204 D5 a)", () => {
252
+ it("names every static first segment the app builds, from both sources, and no dynamic one", () => {
253
+ appPages("about", "faq", "flows/[slug]/start", "[slug]", "[slug]/[detail]", "(auth)/sign-in");
254
+ site({
255
+ ".next/app-path-routes-manifest.json": JSON.stringify({
256
+ "/[locale]/diagnostic/page": "/[locale]/diagnostic",
257
+ "/_not-found/page": "/_not-found",
258
+ }),
259
+ });
260
+ expect(new Set(loadModule().staticFirstSegments())).toEqual(
261
+ new Set(["about", "faq", "flows", "sign-in", "diagnostic"]),
262
+ );
263
+ });
264
+ });
@@ -23,14 +23,24 @@
23
23
  * section the `<h1>` and `renderPageMetadata` gives `<title>` the same text.
24
24
  * - `renderInPageMagnet` is the slotted surface for a slug (D15): the form
25
25
  * bound to its action, or `ContactFallback` when capture is off.
26
+ * - `renderMagnetSection` is the site's renderer for a page's `magnet`
27
+ * section (#12205 D4), registered with `@working-theory/page-renderer` at
28
+ * module load: the magnet's title card and walk from the signal-collectors
29
+ * package, or `null` — the section is then removed from the page.
26
30
  *
27
31
  * Pure apart from the two reads; no React state.
28
32
  */
29
33
  import { flows, leads } from "@working-theory/api-client";
30
- import type {
31
- getMdxSource as defaultGetMdxSource,
32
- getPageSections as defaultGetPageSections,
34
+ import {
35
+ type getMdxSource as defaultGetMdxSource,
36
+ type getPageSections as defaultGetPageSections,
37
+ setMagnetSectionRenderer,
33
38
  } from "@working-theory/page-renderer";
39
+ import {
40
+ contactFormFromConfig,
41
+ type ContactFormView,
42
+ } from "@working-theory/site-pages/pages/contact/contact-form-magnet";
43
+ import { captureLeadAction } from "@working-theory/site-pages/pages/contact/contact.actions";
34
44
  import {
35
45
  ContactFallback,
36
46
  LeadCaptureForm,
@@ -38,22 +48,21 @@ import {
38
48
  localeHref,
39
49
  NewsletterFormInline,
40
50
  } from "@working-theory/ui";
51
+ import { Image } from "@working-theory/ui/primitives";
41
52
  import {
42
53
  flowLeadSource,
43
54
  flowSitePathSchema,
44
55
  resolveLocalizedString,
45
56
  type FlowConfig,
46
57
  } from "@working-theory/validation";
58
+ import { unstable_rethrow } from "next/navigation";
47
59
  import { createElement, type ReactElement } from "react";
48
60
 
49
- import {
50
- contactFormFromConfig,
51
- type ContactFormView,
52
- } from "@working-theory/site-pages/pages/contact/contact-form-magnet";
53
- import { captureLeadAction } from "@working-theory/site-pages/pages/contact/contact.actions";
54
-
55
61
  import { consentPoliciesFor } from "./consent-policies";
56
62
  import { subscribeNewsletterAction } from "./newsletter.actions";
63
+ import type { UiSignalCollectorsContract } from "./paid-section-contracts";
64
+ import { loadUiSignalCollectors } from "./paid-sections.generated";
65
+ import { siteLogo, siteWordmarkAsset } from "./site-logo";
57
66
 
58
67
 
59
68
  export { fillEndingName } from "@working-theory/validation";
@@ -417,3 +426,71 @@ export function renderInPageMagnet({
417
426
  consentGate: "on-submit",
418
427
  });
419
428
  }
429
+
430
+ // ─── The magnet section (#12205 D4) ────────────────────────────────────────────
431
+
432
+ type MagnetSectionUi = Pick<UiSignalCollectorsContract, "MagnetSectionClient"> &
433
+ Partial<Pick<UiSignalCollectorsContract, "bookingStepElement">>;
434
+
435
+ let magnetSectionUi: Promise<MagnetSectionUi | null> | undefined;
436
+
437
+ /**
438
+ * The package's launcher, or `null` when this site does not carry the package
439
+ * or its package has no `MagnetSectionClient`. Once per process, as
440
+ * `listings.tsx`'s `loadListingUi`.
441
+ */
442
+ function loadMagnetSectionUi(): Promise<MagnetSectionUi | null> {
443
+ magnetSectionUi ??= loadUiSignalCollectors().then((mod) => {
444
+ const ui = mod as Partial<MagnetSectionUi> | null;
445
+ return typeof ui?.MagnetSectionClient === "function" ? (ui as MagnetSectionUi) : null;
446
+ });
447
+ return magnetSectionUi;
448
+ }
449
+
450
+ /**
451
+ * The node a page's `magnet` section shows, or `null` to remove the section
452
+ * (D7): a failed read (absent, a draft, the hub down or late), a body that is
453
+ * not a served flow (a string `slug` and a non-empty `steps`, `served-flow.ts`'s
454
+ * `isServedFlow` rule restated — base code cannot import the package), a
455
+ * deliverable magnet (its one route is `/reports/<slug>`), or a site without
456
+ * the package. Otherwise the package's `MagnetSectionClient` with the inputs
457
+ * `renderMagnetStart` builds — the whole served config, its slug, the
458
+ * locale's policy links, the site's marks — plus the booking step's calendar
459
+ * the magnet's own walk would show (#12202 D7). A throw other than Next's
460
+ * control flow answers `null` with one warning that names nothing read.
461
+ */
462
+ export async function renderMagnetSection({
463
+ slug,
464
+ locale,
465
+ }: {
466
+ slug: string;
467
+ locale: string;
468
+ }): Promise<ReactElement | null> {
469
+ const config = await readServedMagnet(slug);
470
+ if (config === null) return null;
471
+ const served = config as Partial<FlowConfig>;
472
+ if (typeof served.slug !== "string" || !Array.isArray(served.steps) || served.steps.length === 0) {
473
+ return null;
474
+ }
475
+ if (config.deliverable !== undefined) return null;
476
+ try {
477
+ const ui = await loadMagnetSectionUi();
478
+ if (ui === null) return null;
479
+ const bookingStep =
480
+ typeof ui.bookingStepElement === "function" ? await ui.bookingStepElement(config) : undefined;
481
+ return createElement(ui.MagnetSectionClient, {
482
+ config,
483
+ slug: config.slug,
484
+ locale,
485
+ consentPolicies: consentPoliciesFor(locale),
486
+ brand: { logomark: siteLogo(), wordmark: createElement(Image, siteWordmarkAsset()) },
487
+ ...(bookingStep !== undefined ? { bookingStep } : {}),
488
+ });
489
+ } catch (err) {
490
+ unstable_rethrow(err);
491
+ console.warn("[magnet-section] render failed; the section is removed");
492
+ return null;
493
+ }
494
+ }
495
+
496
+ setMagnetSectionRenderer(renderMagnetSection);