create-ailk 0.34.0 → 0.35.1
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.
- package/component-catalog.json +25 -3
- package/component-catalog.md +9 -8
- package/dist/add-module.js +7 -2
- package/dist/derive-architecture.js +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/module-architecture.js +9 -0
- package/dist/programmatic.js +5 -2
- package/dist/site-listing-path.d.ts +8 -0
- package/dist/site-listing-path.js +8 -0
- package/dist/surfaces.d.ts +20 -0
- package/dist/surfaces.js +26 -0
- package/dist/template-record.js +2 -0
- package/dist/update.js +11 -0
- package/package.json +3 -3
- package/templates/apps/api/CLAUDE.md +6 -6
- package/templates/apps/mcp/CLAUDE.md +16 -7
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/item.test.tsx +43 -0
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/page.test.tsx +6 -5
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/[kind]/[id]/page.tsx +6 -1
- package/templates/apps/web/app/[locale]/flows/[slug]/FlowStepperClient.tsx +43 -4
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.deliverable.test.tsx +23 -9
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.invite.test.tsx +15 -0
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.permalink.test.tsx +74 -0
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.test.tsx +34 -1
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/magnet-page.test.tsx +257 -4
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/save.actions.test.ts +72 -92
- package/templates/apps/web/app/[locale]/flows/[slug]/email-moment.ts +2 -2
- package/templates/apps/web/app/[locale]/flows/[slug]/magnet-page.tsx +164 -65
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/LevelChart.tsx +100 -0
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsCard.tsx +99 -0
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsClient.tsx +415 -253
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsEmailStep.tsx +113 -32
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/ResultsClient.no-commerce.test.tsx +16 -17
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/ResultsClient.report.test.tsx +284 -0
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/by-result.test.tsx +52 -19
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/cards.test.tsx +402 -0
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/page.test.tsx +100 -12
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/score.test.tsx +153 -101
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/meeting-seam.ts +36 -0
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/page.tsx +121 -33
- package/templates/apps/web/app/[locale]/flows/[slug]/save.actions.ts +27 -17
- package/templates/apps/web/app/[locale]/flows/[slug]/served-flow.ts +91 -0
- package/templates/apps/web/app/[locale]/layout.tsx +18 -1
- package/templates/apps/web/app/api/auth/hub/authorize/__tests__/route.test.ts +24 -0
- package/templates/apps/web/app/api/auth/hub/authorize/route.ts +5 -1
- package/templates/apps/web/app/llms.txt/__tests__/site-listing.test.ts +122 -0
- package/templates/apps/web/app/llms.txt/route.ts +14 -2
- package/templates/apps/web/app/sitemap.xml/__tests__/site-listing.test.ts +98 -0
- package/templates/apps/web/app/sitemap.xml/route.ts +13 -2
- package/templates/apps/web/lib/account-config.ts +24 -9
- package/templates/apps/web/lib/hub-children.tsx +15 -11
- package/templates/apps/web/lib/site-listing.ts +7 -0
- package/templates/apps/web/messages/en.json +13 -1
- package/versions.json +47 -47
|
@@ -3,17 +3,20 @@
|
|
|
3
3
|
* /[locale]/flows/[slug]/results/[payload] — the cold-load results route
|
|
4
4
|
* (#4770).
|
|
5
5
|
*
|
|
6
|
-
* Server-fetches the flow config
|
|
7
|
-
*
|
|
8
|
-
* live data)
|
|
6
|
+
* Server-fetches the flow config through `served-flow.ts`'s
|
|
7
|
+
* `readServedFlow(slug)`, uncached (always dynamically rendered — the config
|
|
8
|
+
* is DB-backed live data); any failed read redirects to the landing (#10990
|
|
9
|
+
* D3).
|
|
9
10
|
* Decodes the versioned, answers-only permalink (`decodePermalink`,
|
|
10
11
|
* `@working-theory/validation`) and `redirect()`s to `/[locale]/flows/[slug]`
|
|
11
12
|
* — step 1, never an error page — on ANY of: an invalid payload (FR6), a
|
|
12
13
|
* stale-version payload (FR6), a payload whose own `flowSlug` does not match
|
|
13
14
|
* this route's `[slug]` (D2/FR6), or a served flow that is not a
|
|
14
15
|
* recommending register (D8 — `mode !== "recommending"`, or neither `offers`
|
|
15
|
-
* nor `recommendation.byResult` (#10827)
|
|
16
|
-
*
|
|
16
|
+
* nor `recommendation.byResult` (#10827) nor a results page — #11013 D-C:
|
|
17
|
+
* spec C's `hasResultsPage`, a recommending flow with no `ending`, widens the
|
|
18
|
+
* guard additively, so every flow the page rendered before still renders —
|
|
19
|
+
* checked against the field `recommend()` is about to be handed rather than
|
|
17
20
|
* inferring the compiler's five-keys-travel-together guarantee).
|
|
18
21
|
*
|
|
19
22
|
* On a valid payload against a recommending flow, renders `ResultsClient`,
|
|
@@ -44,13 +47,24 @@
|
|
|
44
47
|
* row — or a checkout row whose offering is not shown, a draft — renders
|
|
45
48
|
* the results page with one card named from the offering, priced only
|
|
46
49
|
* while the offering is shown.
|
|
50
|
+
*
|
|
51
|
+
* #11013 D-A, D-G — the page builds the frame's brand on the server (the
|
|
52
|
+
* site's logomark and wordmark, the landing title) and the exit to the
|
|
53
|
+
* flow's landing, and resolves the magnet's Email-links-to offering
|
|
54
|
+
* (`conversionLink.kind === "offering"`, spec C) from the same shown set as
|
|
55
|
+
* a Product card, only when no by-result card won (decision 15). The
|
|
56
|
+
* appointment card is the scheduling layout's (`../layout.tsx`, D-K); this
|
|
57
|
+
* file imports nothing from scheduling.
|
|
47
58
|
*/
|
|
48
|
-
import {
|
|
59
|
+
import { offerings } from "@working-theory/api-client";
|
|
60
|
+
import { Image } from "@working-theory/ui/primitives";
|
|
49
61
|
import {
|
|
50
62
|
decodePermalink,
|
|
51
63
|
type FlowConfig,
|
|
64
|
+
type FlowConversionLink,
|
|
52
65
|
type FlowResultRouteTo,
|
|
53
66
|
flowRecommendRegister,
|
|
67
|
+
hasResultsPage,
|
|
54
68
|
parseLookupKey,
|
|
55
69
|
recommend,
|
|
56
70
|
resolveLocalizedString,
|
|
@@ -62,10 +76,15 @@ import type { Metadata } from "next";
|
|
|
62
76
|
import { redirect } from "next/navigation";
|
|
63
77
|
import type { ReactElement } from "react";
|
|
64
78
|
|
|
65
|
-
import { browserApiOrigin } from "../../../../../../lib/api-origin.generated";
|
|
66
79
|
import { offeringsCheckoutHref } from "../../../../../../lib/offerings-pricing";
|
|
80
|
+
import { siteLogo, siteWordmarkAsset } from "../../../../../../lib/site-logo";
|
|
81
|
+
import { apiOriginConfigured, readServedFlow } from "../../served-flow";
|
|
67
82
|
|
|
68
|
-
import type {
|
|
83
|
+
import type {
|
|
84
|
+
ResultsConversionCard,
|
|
85
|
+
ResultsOfferingCard,
|
|
86
|
+
ResultsReturnState,
|
|
87
|
+
} from "./ResultsClient";
|
|
69
88
|
import { ResultsClient } from "./ResultsClient";
|
|
70
89
|
|
|
71
90
|
export const dynamic = "force-dynamic";
|
|
@@ -101,19 +120,6 @@ let shownRead:
|
|
|
101
120
|
| { at: number; read: Promise<WorkspaceShownSetWire | null> }
|
|
102
121
|
| undefined;
|
|
103
122
|
|
|
104
|
-
/**
|
|
105
|
-
* The three names `getApiBase()` reads, the browser-facing one through the
|
|
106
|
-
* topology seam (#7874 D12), which a spoke renders with no env read (#9480):
|
|
107
|
-
* the browser-facing name set on a spoke at runtime counts as no origin.
|
|
108
|
-
*/
|
|
109
|
-
function apiOriginConfigured(): boolean {
|
|
110
|
-
return Boolean(
|
|
111
|
-
process.env.AILK_API_URL ||
|
|
112
|
-
browserApiOrigin() ||
|
|
113
|
-
process.env.NEXT_PUBLIC_API_URL,
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
123
|
/**
|
|
118
124
|
* #9071 D3a — the current shown set, or `null` for "nothing shown": no API
|
|
119
125
|
* origin in production (no call), `unconnected`, `empty`, an expired set, a
|
|
@@ -171,6 +177,27 @@ function shownPricesOf(shown: WorkspaceShownSetWire | null, offeringKey: string)
|
|
|
171
177
|
};
|
|
172
178
|
}
|
|
173
179
|
|
|
180
|
+
/** `/pricing`'s last guard before markup: no format or control characters. */
|
|
181
|
+
function cleanProductText(value: string): string {
|
|
182
|
+
return value.replace(/[\p{Cc}\p{Cf}\p{Zl}\p{Zp}\p{Cs}]/gu, "");
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* The shown product's Stripe description and marketing features, for the
|
|
187
|
+
* Product card (#11013 D-G), cleaned as `/pricing`'s `features()` cleans them:
|
|
188
|
+
* a feature that is nothing but format characters is dropped.
|
|
189
|
+
*/
|
|
190
|
+
function productCopy(
|
|
191
|
+
product: WorkspaceShownSetWire["offerings"][number] | undefined,
|
|
192
|
+
): Pick<ResultsOfferingCard, "description" | "features"> {
|
|
193
|
+
if (product === undefined) return {};
|
|
194
|
+
const description = product.description !== null ? cleanProductText(product.description) : "";
|
|
195
|
+
return {
|
|
196
|
+
...(description.length > 0 ? { description } : {}),
|
|
197
|
+
features: product.marketingFeatures.map(cleanProductText).filter((feature) => feature.length > 0),
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
174
201
|
type ResultLanding =
|
|
175
202
|
| { kind: "redirect"; url: string }
|
|
176
203
|
| { kind: "render"; card?: ResultsOfferingCard };
|
|
@@ -236,9 +263,8 @@ async function resultLanding(
|
|
|
236
263
|
(o as { copy?: { name?: unknown } }).copy?.name !== undefined,
|
|
237
264
|
)
|
|
238
265
|
: undefined;
|
|
239
|
-
// `/pricing`'s last guard before markup: no format or control characters.
|
|
240
266
|
const title =
|
|
241
|
-
product
|
|
267
|
+
(product !== undefined ? cleanProductText(product.name) : undefined) ??
|
|
242
268
|
(legacy
|
|
243
269
|
? resolveLocalizedString(legacy.copy.name, locale, config.defaultLocale)
|
|
244
270
|
: plan.charAt(0).toUpperCase() + plan.slice(1).replace(/-/g, " "));
|
|
@@ -247,6 +273,7 @@ async function resultLanding(
|
|
|
247
273
|
card: {
|
|
248
274
|
offeringKey,
|
|
249
275
|
title,
|
|
276
|
+
...productCopy(product),
|
|
250
277
|
...(price !== undefined
|
|
251
278
|
? {
|
|
252
279
|
price: { amount: price.amount, currency: price.currency, period: price.period },
|
|
@@ -261,23 +288,60 @@ async function resultLanding(
|
|
|
261
288
|
}
|
|
262
289
|
}
|
|
263
290
|
|
|
291
|
+
/**
|
|
292
|
+
* #11013 D-G (3) — Email links to an offering: the shown product's Product
|
|
293
|
+
* card, with Get Started to its `/pricing?plan=` landing; a product not in
|
|
294
|
+
* the shown set (a draft) gives none. Resolved only when no by-result card
|
|
295
|
+
* won, so the link never costs a second read.
|
|
296
|
+
*/
|
|
297
|
+
async function offeringConversionCard(
|
|
298
|
+
link: FlowConversionLink,
|
|
299
|
+
locale: string,
|
|
300
|
+
): Promise<ResultsConversionCard | undefined> {
|
|
301
|
+
if (link.kind !== "offering") return undefined;
|
|
302
|
+
try {
|
|
303
|
+
const shown = await readCurrentShownSet();
|
|
304
|
+
const { plan, product, price } = shownPricesOf(shown, link.id);
|
|
305
|
+
if (product === undefined) return undefined;
|
|
306
|
+
const safeLocale = ENABLED_LOCALES.includes(locale) ? locale : DEFAULT_LOCALE;
|
|
307
|
+
return {
|
|
308
|
+
kind: "product",
|
|
309
|
+
name: cleanProductText(product.name),
|
|
310
|
+
...productCopy(product),
|
|
311
|
+
...(price !== undefined
|
|
312
|
+
? { price: { amount: price.amount, currency: price.currency, period: price.period } }
|
|
313
|
+
: {}),
|
|
314
|
+
href: `/${safeLocale}/pricing?plan=${price?.plan ?? plan}`,
|
|
315
|
+
};
|
|
316
|
+
} catch {
|
|
317
|
+
return undefined;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/** The landing title — the record's `landing.title`, else step 1's (`magnet-page.tsx`'s `landingCopy`). */
|
|
322
|
+
function landingTitle(config: FlowConfig, locale: string): string {
|
|
323
|
+
const pick = (value: Record<string, string> | undefined): string | undefined =>
|
|
324
|
+
value === undefined ? undefined : resolveLocalizedString(value, locale, config.defaultLocale);
|
|
325
|
+
return pick(config.landing?.title) ?? pick(config.steps[0]!.copy.title) ?? config.slug;
|
|
326
|
+
}
|
|
327
|
+
|
|
264
328
|
export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
|
265
329
|
const { locale, slug, payload } = await params;
|
|
266
330
|
|
|
267
331
|
const decoded = decodePermalink(payload);
|
|
268
332
|
if (!decoded.ok || decoded.value.flowSlug !== slug) return {};
|
|
269
333
|
|
|
270
|
-
const
|
|
271
|
-
if (
|
|
334
|
+
const read = await readServedFlow(slug);
|
|
335
|
+
if (read.kind !== "ok") return {};
|
|
272
336
|
|
|
273
|
-
const { recommendation } =
|
|
337
|
+
const { recommendation } = read.config;
|
|
274
338
|
if (!recommendation) return {};
|
|
275
339
|
|
|
276
340
|
return {
|
|
277
341
|
title: resolveLocalizedString(
|
|
278
342
|
recommendation.copy.title,
|
|
279
343
|
locale,
|
|
280
|
-
|
|
344
|
+
read.config.defaultLocale,
|
|
281
345
|
),
|
|
282
346
|
};
|
|
283
347
|
}
|
|
@@ -296,36 +360,60 @@ export default async function Page({
|
|
|
296
360
|
redirect(`/${locale}/flows/${slug}`);
|
|
297
361
|
}
|
|
298
362
|
|
|
299
|
-
|
|
300
|
-
|
|
363
|
+
// #10990 D3 — any failed read (refused, non-2xx, a 2xx that is not a
|
|
364
|
+
// flow, no answer within 5 s) lands on the flow's page, never a 500.
|
|
365
|
+
const read = await readServedFlow(slug);
|
|
366
|
+
if (read.kind !== "ok") {
|
|
301
367
|
redirect(`/${locale}/flows/${slug}`);
|
|
302
368
|
}
|
|
369
|
+
const config = read.config as FlowConfig & { conversionLink?: FlowConversionLink };
|
|
370
|
+
// #11013 D-C — today's condition, plus spec C's results-page predicate.
|
|
303
371
|
if (
|
|
304
|
-
|
|
305
|
-
(
|
|
372
|
+
config.mode !== "recommending" ||
|
|
373
|
+
(config.offers === undefined &&
|
|
374
|
+
config.recommendation?.byResult === undefined &&
|
|
375
|
+
!hasResultsPage(config))
|
|
306
376
|
) {
|
|
307
377
|
redirect(`/${locale}/flows/${slug}`);
|
|
308
378
|
}
|
|
309
379
|
|
|
310
380
|
const landing = await resultLanding(
|
|
311
|
-
|
|
381
|
+
config,
|
|
312
382
|
decoded.value.answers,
|
|
313
383
|
locale,
|
|
314
384
|
);
|
|
315
385
|
if (landing.kind === "redirect") redirect(landing.url);
|
|
316
386
|
|
|
387
|
+
// #11013 decision 15 — Email links to, after a by-result card.
|
|
388
|
+
const conversionCard =
|
|
389
|
+
landing.card === undefined && config.conversionLink !== undefined
|
|
390
|
+
? await offeringConversionCard(config.conversionLink, locale)
|
|
391
|
+
: undefined;
|
|
392
|
+
|
|
317
393
|
// FR7 — read AFTER every redirect guard above, so a return param never
|
|
318
394
|
// changes which guard fires or where it sends the visitor.
|
|
319
395
|
const returnState = resolveReturnState((await searchParams)?.checkout);
|
|
320
396
|
|
|
397
|
+
// #11013 D-A — the frame's brand, built here because `site-logo.tsx` reads
|
|
398
|
+
// site config on the server; the exit leaves for the flow's landing.
|
|
399
|
+
const safeLocale = ENABLED_LOCALES.includes(locale) ? locale : DEFAULT_LOCALE;
|
|
400
|
+
const brand = {
|
|
401
|
+
logomark: siteLogo(),
|
|
402
|
+
wordmark: <Image {...siteWordmarkAsset()} />,
|
|
403
|
+
title: landingTitle(config, locale),
|
|
404
|
+
};
|
|
405
|
+
|
|
321
406
|
return (
|
|
322
407
|
<ResultsClient
|
|
323
|
-
config={
|
|
408
|
+
config={config}
|
|
324
409
|
locale={locale}
|
|
325
410
|
answers={decoded.value.answers}
|
|
326
411
|
slug={slug}
|
|
327
412
|
payload={payload}
|
|
413
|
+
brand={brand}
|
|
414
|
+
exitHref={`/${safeLocale}/flows/${slug}`}
|
|
328
415
|
{...(landing.card !== undefined ? { offeringCard: landing.card } : {})}
|
|
416
|
+
{...(conversionCard !== undefined ? { conversionCard } : {})}
|
|
329
417
|
{...(returnState !== undefined ? { returnState } : {})}
|
|
330
418
|
/>
|
|
331
419
|
);
|
|
@@ -2,14 +2,25 @@
|
|
|
2
2
|
"use server";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* save.actions.ts —
|
|
6
|
-
* `flowSaveInputSchema`, calls `flows.
|
|
7
|
-
* `
|
|
5
|
+
* save.actions.ts — Get your full report (#11013 spec E, D-F): validates with
|
|
6
|
+
* `flowSaveInputSchema`, calls `flows.resultsEmail` — spec C's
|
|
7
|
+
* `POST /v1/flows/:slug/results-email`, which writes the Lead, records the
|
|
8
|
+
* form's consents and runs the magnet's conversion email — and answers
|
|
9
|
+
* `{ ok: true }`, never an id. It replaced "Email me this plan"
|
|
10
|
+
* (`saveRecommendationAction` → `flows.save`, #4842 D7), which wrote a Lead
|
|
11
|
+
* but ran no conversion. A sibling of `flow.actions.ts` (ADR 0013
|
|
12
|
+
* `*.actions.ts`).
|
|
8
13
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
14
|
+
* A thin forwarder (SEC-E-1): the controls on who may attach an email and
|
|
15
|
+
* how often mail is sent — session ownership, dedupe, consent, the
|
|
16
|
+
* per-recipient, per-workspace and per-IP limits — are the route's; this
|
|
17
|
+
* action adds the same slug and body parse, bot check and visitor-IP
|
|
18
|
+
* forwarding its predecessor had, and no trust boundary in the site.
|
|
19
|
+
*
|
|
20
|
+
* Split out of `checkout.actions.ts` by #6786: the results page's email
|
|
21
|
+
* moment ships with the page (the `flows` surface, signal-collectors), while
|
|
22
|
+
* `startCheckoutAction` stays commerce's. The shared validation,
|
|
23
|
+
* IP-forwarding and status → kind helpers are `email-moment.ts`.
|
|
13
24
|
*/
|
|
14
25
|
|
|
15
26
|
import { flows } from "@working-theory/api-client";
|
|
@@ -29,13 +40,12 @@ import {
|
|
|
29
40
|
resolveVisitorIpInit,
|
|
30
41
|
} from "./email-moment";
|
|
31
42
|
|
|
32
|
-
export type
|
|
33
|
-
{ ok: true; leadId: string } | EmailMomentFailure;
|
|
43
|
+
export type ResultsEmailActionResult = { ok: true } | EmailMomentFailure;
|
|
34
44
|
|
|
35
|
-
export async function
|
|
45
|
+
export async function sendResultsEmailAction(
|
|
36
46
|
slug: string,
|
|
37
47
|
body: FlowSaveInput,
|
|
38
|
-
): Promise<
|
|
48
|
+
): Promise<ResultsEmailActionResult> {
|
|
39
49
|
const parsedSlug = flowSlugSchema.safeParse(slug);
|
|
40
50
|
if (!parsedSlug.success) return { ok: false, kind: "invalid_input" };
|
|
41
51
|
|
|
@@ -48,7 +58,7 @@ export async function saveRecommendationAction(
|
|
|
48
58
|
// the write.
|
|
49
59
|
const botCheck = await runBotCheck({
|
|
50
60
|
source: "bot-check",
|
|
51
|
-
target: "
|
|
61
|
+
target: "sendResultsEmailAction",
|
|
52
62
|
scope: "write",
|
|
53
63
|
});
|
|
54
64
|
if (botCheck !== "pass") return { ok: false, kind: "unavailable" };
|
|
@@ -56,19 +66,19 @@ export async function saveRecommendationAction(
|
|
|
56
66
|
try {
|
|
57
67
|
const visitorIpInit = await resolveVisitorIpInit();
|
|
58
68
|
const res = visitorIpInit
|
|
59
|
-
? await flows.
|
|
60
|
-
: await flows.
|
|
69
|
+
? await flows.resultsEmail(parsedSlug.data, payload, visitorIpInit)
|
|
70
|
+
: await flows.resultsEmail(parsedSlug.data, payload);
|
|
61
71
|
if (!res.ok) {
|
|
62
72
|
const failure = failureFor(res);
|
|
63
73
|
console.error(
|
|
64
|
-
`[
|
|
74
|
+
`[sendResultsEmailAction] slug=${parsedSlug.data} kind=${failure.kind} status=${res.status}`,
|
|
65
75
|
);
|
|
66
76
|
return failure;
|
|
67
77
|
}
|
|
68
|
-
return { ok: true
|
|
78
|
+
return { ok: true };
|
|
69
79
|
} catch (err) {
|
|
70
80
|
console.error(
|
|
71
|
-
`[
|
|
81
|
+
`[sendResultsEmailAction] slug=${parsedSlug.data} kind=network errName=${errorName(err)}`,
|
|
72
82
|
);
|
|
73
83
|
return { ok: false, kind: "network" };
|
|
74
84
|
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// oss: false
|
|
2
|
+
/**
|
|
3
|
+
* served-flow.ts — the one read of a served flow config (#10990 D1).
|
|
4
|
+
*
|
|
5
|
+
* `readServedFlow(slug)` asks the hub (`flows.get`) and answers one of four
|
|
6
|
+
* kinds. It is shared by the magnet pages (`magnet-page.tsx`'s `readMagnet`,
|
|
7
|
+
* which adds a 15-second per-instance cache) and the results permalink
|
|
8
|
+
* (`results/[payload]/page.tsx`, uncached). It imports nothing of either
|
|
9
|
+
* page's render graph, so the results route can load it alone.
|
|
10
|
+
*
|
|
11
|
+
* - `ok` only for a 2xx whose body is a served flow (`isServedFlow`).
|
|
12
|
+
* - `absent` only for a 404 (the hub's `flow_not_found`: no such flow, or a
|
|
13
|
+
* draft).
|
|
14
|
+
* - `not-configured` for the hub's 503 `flows_not_configured`, or a failed
|
|
15
|
+
* read with no API origin configured (#9219).
|
|
16
|
+
* - `unavailable` for everything else: a refused connection, any other
|
|
17
|
+
* non-2xx (5xx, 401, 403, 429, …), a 2xx that is not a served flow, and no
|
|
18
|
+
* answer within 5 seconds. A firewall's 403 or a block page's 2xx therefore
|
|
19
|
+
* shows the site's contact email, never a 404 or a 500.
|
|
20
|
+
*/
|
|
21
|
+
import { flows } from "@working-theory/api-client";
|
|
22
|
+
import type { FlowConfig } from "@working-theory/validation";
|
|
23
|
+
|
|
24
|
+
import { browserApiOrigin } from "../../../../lib/api-origin.generated";
|
|
25
|
+
|
|
26
|
+
export type MagnetRead =
|
|
27
|
+
| { kind: "ok"; config: FlowConfig }
|
|
28
|
+
| { kind: "absent" }
|
|
29
|
+
| { kind: "unavailable" }
|
|
30
|
+
| { kind: "not-configured" };
|
|
31
|
+
|
|
32
|
+
/** No flow read holds a visitor longer than this (the results page's #9071 NFR-4 value). */
|
|
33
|
+
export const SERVED_FLOW_TIMEOUT_MS = 5_000;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Whether an API origin is configured: the three names `getApiBase()` in
|
|
37
|
+
* packages/api-client/src/http.ts reads, in step with it on a hub. Without one
|
|
38
|
+
* that function answers `localhost:3001`. The browser-facing origin comes from
|
|
39
|
+
* the topology seam (#7874 D12), which a spoke renders with no env read, so a
|
|
40
|
+
* spoke passes its own `env:check` (#9480). A spoke diverges on purpose: the
|
|
41
|
+
* browser-facing name set on one at runtime counts as no origin here.
|
|
42
|
+
*/
|
|
43
|
+
export function apiOriginConfigured(): boolean {
|
|
44
|
+
return Boolean(
|
|
45
|
+
process.env.AILK_API_URL ||
|
|
46
|
+
browserApiOrigin() ||
|
|
47
|
+
process.env.NEXT_PUBLIC_API_URL,
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The flows route's own answer when its hub has no database (apps/api `flows_not_configured`). */
|
|
52
|
+
function isFlowsNotConfigured(body: unknown): boolean {
|
|
53
|
+
const error = (body as { error?: { code?: unknown } } | null)?.error;
|
|
54
|
+
return error?.code === "flows_not_configured";
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** A read that failed: `not-configured` when there is no hub to ask, else `unavailable`. */
|
|
58
|
+
function failedRead(): MagnetRead {
|
|
59
|
+
return apiOriginConfigured() ? { kind: "unavailable" } : { kind: "not-configured" };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Whether a 2xx body is a served flow: only what the renderers dereference
|
|
64
|
+
* before any schema-checked path. Deliberately not `flowConfigSchema` — the
|
|
65
|
+
* hub parses the config before serving it, and a spoke's schema can be older
|
|
66
|
+
* than its hub's.
|
|
67
|
+
*/
|
|
68
|
+
export function isServedFlow(body: unknown): body is FlowConfig {
|
|
69
|
+
if (typeof body !== "object" || body === null) return false;
|
|
70
|
+
const { slug, steps } = body as { slug?: unknown; steps?: unknown };
|
|
71
|
+
return typeof slug === "string" && Array.isArray(steps) && steps.length > 0;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** The served flow config for `slug`, classified (D1). */
|
|
75
|
+
export async function readServedFlow(slug: string): Promise<MagnetRead> {
|
|
76
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
77
|
+
try {
|
|
78
|
+
const timeout = new Promise<null>((resolve) => {
|
|
79
|
+
timer = setTimeout(() => resolve(null), SERVED_FLOW_TIMEOUT_MS);
|
|
80
|
+
});
|
|
81
|
+
const res = await Promise.race([flows.get(slug), timeout]);
|
|
82
|
+
if (res === null) return failedRead();
|
|
83
|
+
if (res.ok) return isServedFlow(res.body) ? { kind: "ok", config: res.body } : failedRead();
|
|
84
|
+
if (res.status === 503 && isFlowsNotConfigured(res.body)) return { kind: "not-configured" };
|
|
85
|
+
return res.status === 404 ? { kind: "absent" } : failedRead();
|
|
86
|
+
} catch {
|
|
87
|
+
return failedRead();
|
|
88
|
+
} finally {
|
|
89
|
+
clearTimeout(timer);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -29,6 +29,7 @@ import { readFileSync } from "node:fs";
|
|
|
29
29
|
import { join } from "node:path";
|
|
30
30
|
|
|
31
31
|
import { Telemetry, VerificationMeta } from "@working-theory/analytics";
|
|
32
|
+
import { slugFormTarget } from "@working-theory/page-renderer";
|
|
32
33
|
import {
|
|
33
34
|
SiteConsentSchema,
|
|
34
35
|
type ConsentAppearance,
|
|
@@ -58,6 +59,7 @@ import {
|
|
|
58
59
|
import { BotIdClient } from "botid/client";
|
|
59
60
|
import type { Metadata, Viewport } from "next";
|
|
60
61
|
import { cookies, headers } from "next/headers";
|
|
62
|
+
import { permanentRedirect } from "next/navigation";
|
|
61
63
|
import { NextIntlClientProvider } from "next-intl";
|
|
62
64
|
import { getMessages, getTranslations } from "next-intl/server";
|
|
63
65
|
import type { ReactElement, ReactNode } from "react";
|
|
@@ -117,6 +119,7 @@ import {
|
|
|
117
119
|
readSiteHeader,
|
|
118
120
|
signedOutHeaderActions,
|
|
119
121
|
} from "../../lib/site-header";
|
|
122
|
+
import { SITE_LISTING } from "../../lib/site-listing";
|
|
120
123
|
import { siteLogo } from "../../lib/site-logo";
|
|
121
124
|
// Registers the `_site.mdx` identity with page-renderer at module load, so
|
|
122
125
|
// every page rendered under this layout carries the sitewide JSON-LD (#6597).
|
|
@@ -132,7 +135,7 @@ import {
|
|
|
132
135
|
SIGN_UP_PATH,
|
|
133
136
|
readSession,
|
|
134
137
|
} from "../../lib/topology.generated";
|
|
135
|
-
import { resolveBaseUrl } from "../../src/lib/routes";
|
|
138
|
+
import { pagePathFor, resolveBaseUrl } from "../../src/lib/routes";
|
|
136
139
|
|
|
137
140
|
import { ConsentBanner } from "./consent-banner";
|
|
138
141
|
import { readSiteContactLines } from "./contact/site-contact-lines";
|
|
@@ -371,6 +374,20 @@ export default async function LocaleLayout({
|
|
|
371
374
|
// #6107 — a segment that is not an enabled locale is a 404, before any
|
|
372
375
|
// message load or session read.
|
|
373
376
|
assertEnabledLocale(locale);
|
|
377
|
+
// #10940 D4 — a row the site's listing moves answers its convention URL
|
|
378
|
+
// with a 308 to the route that serves it, locale kept. A missing
|
|
379
|
+
// `x-pathname` skips the check.
|
|
380
|
+
const requested = (await headers()).get("x-pathname");
|
|
381
|
+
const moved =
|
|
382
|
+
requested === null
|
|
383
|
+
? null
|
|
384
|
+
: slugFormTarget(
|
|
385
|
+
SITE_LISTING,
|
|
386
|
+
{ pathname: requested, locale },
|
|
387
|
+
pagePathFor,
|
|
388
|
+
);
|
|
389
|
+
if (moved !== null)
|
|
390
|
+
permanentRedirect(localeHref(locale, moved, DEFAULT_LOCALE));
|
|
374
391
|
const messages = await getMessages();
|
|
375
392
|
// #7742 D2 — `colorMode: "light"` pins the mode: a saved dark cookie is
|
|
376
393
|
// ignored, no flash script runs and no theme switch renders.
|
|
@@ -687,6 +687,30 @@ describe("the consent step (#9966 D2, AC-4)", () => {
|
|
|
687
687
|
expect(init.headers["x-internal-auth"]).toBe("internal-secret");
|
|
688
688
|
});
|
|
689
689
|
|
|
690
|
+
it("POST: a hub that holds its own spoke key still carries x-internal-auth (#10941)", async () => {
|
|
691
|
+
process.env = {
|
|
692
|
+
...process.env,
|
|
693
|
+
OSS_API_INTERNAL_SECRET: "internal-secret",
|
|
694
|
+
AILK_API_URL: "https://api.example.com",
|
|
695
|
+
AILK_SPOKE_KEY: "ailk_spk_the_hubs_own_key",
|
|
696
|
+
};
|
|
697
|
+
mockGetSession.mockResolvedValue({ user: { id: "u1" } });
|
|
698
|
+
mockCreateCode.mockResolvedValue({
|
|
699
|
+
ok: true,
|
|
700
|
+
body: { code: CODE, redirectUri: SPOKE_CALLBACK },
|
|
701
|
+
});
|
|
702
|
+
|
|
703
|
+
const res = await POST(post([ref()]));
|
|
704
|
+
|
|
705
|
+
expect(res.status).toBe(303);
|
|
706
|
+
const [body, init] = mockCreateCode.mock.calls[0] as [
|
|
707
|
+
Record<string, unknown>,
|
|
708
|
+
{ headers: Record<string, string> },
|
|
709
|
+
];
|
|
710
|
+
expect(body.consent).toBe(true);
|
|
711
|
+
expect(init.headers["x-internal-auth"]).toBe("internal-secret");
|
|
712
|
+
});
|
|
713
|
+
|
|
690
714
|
it("POST: withholds x-internal-auth from a plain-http API", async () => {
|
|
691
715
|
process.env = {
|
|
692
716
|
...process.env,
|
|
@@ -161,7 +161,11 @@ function sealQuery(query: HubAuthorizeQuery): string | null {
|
|
|
161
161
|
*/
|
|
162
162
|
function internalAuthHeader(): Record<string, string> {
|
|
163
163
|
const secret = process.env.OSS_API_INTERNAL_SECRET;
|
|
164
|
-
|
|
164
|
+
// The topology alone says "spoke" (#10941). A hub also holds a spoke key —
|
|
165
|
+
// its own, for server-side reads — and reading that key as "this site is a
|
|
166
|
+
// spoke" dropped the header on the one site that mints codes, so no consent
|
|
167
|
+
// ever completed.
|
|
168
|
+
const spoke = TOPOLOGY === "spoke";
|
|
165
169
|
if (!secret || spoke) return {};
|
|
166
170
|
try {
|
|
167
171
|
const api = new URL(
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment node
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* #10940 D3 — both llms routes (the base route and the docs-blog variant)
|
|
7
|
+
* read the site listing and skip `ThankYouPage` rows.
|
|
8
|
+
*
|
|
9
|
+
* AC-1: on a database-backed site each public page is listed once, at the
|
|
10
|
+
* route that serves it. AC-3: with the empty listing (the default dep) the
|
|
11
|
+
* output is today's convention listing, apart from the ThankYouPage skip.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import type { ContentAdapter } from "@working-theory/content-adapters";
|
|
15
|
+
import type { SiteListing } from "@working-theory/page-renderer";
|
|
16
|
+
|
|
17
|
+
type Route = typeof import("../route");
|
|
18
|
+
|
|
19
|
+
const BASE = "https://example.com";
|
|
20
|
+
// The docs-blog variant is that module's ownedFile, so a scaffold without
|
|
21
|
+
// docs-blog carries no copy — only the routes that resolve here are run (#11085).
|
|
22
|
+
const ROUTES = ["../route", "../../../lib/slices/docs-blog/llms-route"].filter((path) => {
|
|
23
|
+
try {
|
|
24
|
+
require.resolve(path);
|
|
25
|
+
return true;
|
|
26
|
+
} catch {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const PUBLIC_ROWS: Record<string, Array<{ type: string; slug: string; title: string }>> = {
|
|
32
|
+
AboutPage: [{ type: "AboutPage", slug: "about", title: "About" }],
|
|
33
|
+
LandingPage: [
|
|
34
|
+
{ type: "LandingPage", slug: "private-convo", title: "Private" },
|
|
35
|
+
{ type: "LandingPage", slug: "projects-apply", title: "Apply" },
|
|
36
|
+
],
|
|
37
|
+
BookCall: [{ type: "BookCall", slug: "meet-discovery", title: "Discovery" }],
|
|
38
|
+
};
|
|
39
|
+
const THANKS = {
|
|
40
|
+
ThankYouPage: [{ type: "ThankYouPage", slug: "projects-approved", title: "Thanks" }],
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
function stubAdapter(rows: Record<string, unknown[]>): ContentAdapter {
|
|
44
|
+
// eslint-disable-next-line no-restricted-syntax -- partial stub; the routes read listPages only
|
|
45
|
+
return {
|
|
46
|
+
listPages: jest.fn(async (type: string) => rows[type] ?? []),
|
|
47
|
+
} as unknown as ContentAdapter;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const LISTING: SiteListing = {
|
|
51
|
+
"LandingPage/private-convo": { listed: false },
|
|
52
|
+
"LandingPage/projects-apply": { path: "/projects/apply" },
|
|
53
|
+
"BookCall/meet-discovery": { path: "/meet/discovery" },
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
function loadRoute(path: string): Route {
|
|
57
|
+
let route: Route | undefined;
|
|
58
|
+
jest.isolateModules(() => {
|
|
59
|
+
route = jest.requireActual<Route>(path);
|
|
60
|
+
});
|
|
61
|
+
return route!;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function llms(
|
|
65
|
+
path: string,
|
|
66
|
+
rows: Record<string, unknown[]>,
|
|
67
|
+
listing?: SiteListing,
|
|
68
|
+
): Promise<string> {
|
|
69
|
+
const { createLlmsHandler } = loadRoute(path);
|
|
70
|
+
const GET = createLlmsHandler({
|
|
71
|
+
getContentAdapter: () => stubAdapter(rows),
|
|
72
|
+
getBlogPages: () => [],
|
|
73
|
+
getDocsPages: () => [],
|
|
74
|
+
discoverable: async () => true,
|
|
75
|
+
...(listing === undefined ? {} : { getSiteListing: () => listing }),
|
|
76
|
+
});
|
|
77
|
+
return (await GET()).text();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const urls = (text: string): string[] =>
|
|
81
|
+
[...text.matchAll(/^ {2}URL: (.+)$/gm)].map((m) => m[1]!);
|
|
82
|
+
|
|
83
|
+
describe.each(ROUTES)("GET /llms.txt (%s) — the site listing (#10940)", (path) => {
|
|
84
|
+
beforeEach(() => {
|
|
85
|
+
process.env.CONTENT_ADAPTER = "database";
|
|
86
|
+
process.env.NEXT_PUBLIC_ENABLED_LOCALES = "en,es";
|
|
87
|
+
process.env.NEXT_PUBLIC_BASE_URL = BASE;
|
|
88
|
+
});
|
|
89
|
+
afterEach(() => {
|
|
90
|
+
delete process.env.CONTENT_ADAPTER;
|
|
91
|
+
delete process.env.NEXT_PUBLIC_ENABLED_LOCALES;
|
|
92
|
+
delete process.env.NEXT_PUBLIC_BASE_URL;
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it("AC-1: lists each public page once, at its served route", async () => {
|
|
96
|
+
const text = await llms(path, { ...PUBLIC_ROWS, ...THANKS }, LISTING);
|
|
97
|
+
expect(new Set(urls(text))).toEqual(
|
|
98
|
+
new Set(["/about", "/projects/apply", "/meet/discovery"].map((p) => `${BASE}${p}`)),
|
|
99
|
+
);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("AC-1: ignores an invalid listing path", async () => {
|
|
103
|
+
const text = await llms(path, PUBLIC_ROWS, {
|
|
104
|
+
"AboutPage/about": { path: "https://evil.example/x" },
|
|
105
|
+
});
|
|
106
|
+
expect(urls(text)).toContain(`${BASE}/about`);
|
|
107
|
+
expect(text).not.toContain("evil.example");
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("AC-3: the default listing is the empty one — today's convention listing", async () => {
|
|
111
|
+
const byDefault = await llms(path, PUBLIC_ROWS);
|
|
112
|
+
expect(byDefault).toBe(await llms(path, PUBLIC_ROWS, {}));
|
|
113
|
+
for (const p of ["/projects-apply", "/meet/meet-discovery", "/private-convo"]) {
|
|
114
|
+
expect(byDefault).toContain(`URL: ${BASE}${p}`);
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it("AC-3: never lists a ThankYouPage, even with an empty listing", async () => {
|
|
119
|
+
const text = await llms(path, { ...PUBLIC_ROWS, ...THANKS }, {});
|
|
120
|
+
expect(text).not.toContain("/thanks/projects-approved");
|
|
121
|
+
});
|
|
122
|
+
});
|