create-ailk 0.45.0 → 0.46.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/README.md +6 -3
- package/component-catalog.json +217 -4
- package/component-catalog.md +10 -7
- package/dist/lib/env-catalog.js +1 -1
- package/dist/lib/import-mdx.js +10 -2
- package/dist/seed-workspace.d.ts +1 -1
- package/dist/seed-workspace.js +10 -3
- package/dist/surfaces.js +1 -1
- package/package.json +3 -3
- package/templates/apps/api/.env.example +23 -0
- package/templates/apps/api/CLAUDE.md +13 -6
- package/templates/apps/api/src/lib/__mocks__/prisma.ts +11 -0
- package/templates/apps/mcp/.env.example +8 -0
- package/templates/apps/mcp/CLAUDE.md +22 -6
- package/templates/apps/web/.env.example +1 -1
- package/templates/apps/web/CLAUDE.md +80 -16
- package/templates/apps/web/app/.well-known/mcp.json/route.ts +6 -7
- package/templates/apps/web/app/[locale]/layout.tsx +10 -7
- package/templates/apps/web/app/api/site-status/__tests__/route.test.ts +120 -0
- package/templates/apps/web/app/api/site-status/route.ts +62 -0
- package/templates/apps/web/app/llms.txt/route.ts +3 -3
- package/templates/apps/web/app/openapi.json/__tests__/route.test.ts +21 -4
- package/templates/apps/web/app/openapi.json/route.ts +10 -9
- package/templates/apps/web/app/sitemap.xml/route.ts +3 -3
- package/templates/apps/web/auth.ts +25 -1
- package/templates/apps/web/lib/__tests__/fixtures/mcp-stub-server.ts +10 -3
- package/templates/apps/web/lib/__tests__/mcp-served-tools.test.ts +61 -0
- package/templates/apps/web/lib/__tests__/offerings-pricing.test.ts +384 -1
- package/templates/apps/web/lib/__tests__/pricing-page.test.ts +675 -0
- package/templates/apps/web/lib/__tests__/site-brand.test.ts +5 -6
- package/templates/apps/web/lib/__tests__/site-visibility.test.ts +64 -0
- package/templates/apps/web/lib/mcp-oauth.ts +64 -0
- package/templates/apps/web/lib/mcp-served-tools.ts +51 -9
- package/templates/apps/web/lib/offerings-pricing.ts +173 -20
- package/templates/apps/web/lib/pricing-page.ts +382 -43
- package/templates/apps/web/lib/site-brand.tsx +1 -7
- package/templates/apps/web/lib/site-visibility.ts +45 -0
- package/templates/apps/web/messages/en.json +9 -0
- package/templates/apps/web/middleware.ts +16 -1
- package/templates/apps/web/src/lib/routes.ts +3 -3
- package/versions.json +51 -51
- package/templates/apps/web/app/.well-known/ai-plugin.json/route.ts +0 -93
|
@@ -310,14 +310,13 @@ describe("resolveSiteBrand() (#11456 D4)", () => {
|
|
|
310
310
|
const hub = (identity: unknown, seo: unknown = null) =>
|
|
311
311
|
mockReadHubSite.mockResolvedValue({ identity, seo });
|
|
312
312
|
|
|
313
|
-
it("with no hub site, answers the module's constants
|
|
313
|
+
it("with no hub site, answers the module's constants", async () => {
|
|
314
314
|
mockReadHubSite.mockResolvedValue(undefined);
|
|
315
315
|
const brand = await loadSiteBrand();
|
|
316
316
|
await expect(brand.resolveSiteBrand()).resolves.toEqual({
|
|
317
317
|
siteName: brand.SITE_NAME,
|
|
318
318
|
description: brand.SITE_DESCRIPTION,
|
|
319
319
|
copyrightHolder: brand.COPYRIGHT_HOLDER,
|
|
320
|
-
indexable: true,
|
|
321
320
|
});
|
|
322
321
|
});
|
|
323
322
|
|
|
@@ -331,7 +330,6 @@ describe("resolveSiteBrand() (#11456 D4)", () => {
|
|
|
331
330
|
siteName: "Hub Co",
|
|
332
331
|
description: "Seo description.",
|
|
333
332
|
copyrightHolder: "Hub Co",
|
|
334
|
-
indexable: true,
|
|
335
333
|
});
|
|
336
334
|
});
|
|
337
335
|
|
|
@@ -358,12 +356,13 @@ describe("resolveSiteBrand() (#11456 D4)", () => {
|
|
|
358
356
|
await expect(resolveSiteBrand()).resolves.toMatchObject({ siteName: "Env Name" });
|
|
359
357
|
});
|
|
360
358
|
|
|
361
|
-
it("
|
|
359
|
+
it("a stored seo robots.index false gives a brand with no indexing field (#11978 D7)", async () => {
|
|
362
360
|
hub(null, { version: "1", robots: { index: false } });
|
|
363
361
|
const brand = await loadSiteBrand();
|
|
364
|
-
await expect(brand.resolveSiteBrand()).resolves.
|
|
362
|
+
await expect(brand.resolveSiteBrand()).resolves.toEqual({
|
|
365
363
|
siteName: brand.SITE_NAME,
|
|
366
|
-
|
|
364
|
+
description: brand.SITE_DESCRIPTION,
|
|
365
|
+
copyrightHolder: brand.COPYRIGHT_HOLDER,
|
|
367
366
|
});
|
|
368
367
|
});
|
|
369
368
|
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #11978 D2 — the site's one rule for Hidden (AC-2 (d), AC-3 (a)).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { StealthValueError } from "@working-theory/web-i18n/stealth";
|
|
6
|
+
|
|
7
|
+
const mockSiteDiscoverable = jest.fn();
|
|
8
|
+
jest.mock("@working-theory/api-client", () => ({
|
|
9
|
+
siteDiscoverable: () => mockSiteDiscoverable(),
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
import { HIDDEN_ROBOTS_HEADER, siteHidden, siteLock } from "../site-visibility";
|
|
13
|
+
|
|
14
|
+
const saved = process.env["STEALTH"];
|
|
15
|
+
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
mockSiteDiscoverable.mockReset().mockResolvedValue(true);
|
|
18
|
+
delete process.env["STEALTH"];
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
afterAll(() => {
|
|
22
|
+
if (saved === undefined) delete process.env["STEALTH"];
|
|
23
|
+
else process.env["STEALTH"] = saved;
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe("siteHidden() (#11978 D2)", () => {
|
|
27
|
+
it("is true under STEALTH, with no hub read", async () => {
|
|
28
|
+
process.env["STEALTH"] = "true";
|
|
29
|
+
await expect(siteHidden()).resolves.toBe(true);
|
|
30
|
+
expect(mockSiteDiscoverable).not.toHaveBeenCalled();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("is true with STEALTH unset and the switch off", async () => {
|
|
34
|
+
mockSiteDiscoverable.mockResolvedValue(false);
|
|
35
|
+
await expect(siteHidden()).resolves.toBe(true);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("is false with both off", async () => {
|
|
39
|
+
process.env["STEALTH"] = "false";
|
|
40
|
+
await expect(siteHidden()).resolves.toBe(false);
|
|
41
|
+
expect(mockSiteDiscoverable).toHaveBeenCalledTimes(1);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("throws StealthValueError on a bogus STEALTH", async () => {
|
|
45
|
+
process.env["STEALTH"] = "maybe";
|
|
46
|
+
await expect(siteHidden()).rejects.toBeInstanceOf(StealthValueError);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe("siteLock() (#11978 D2)", () => {
|
|
51
|
+
it.each([
|
|
52
|
+
["true", "hosting"],
|
|
53
|
+
["1", "hosting"],
|
|
54
|
+
["off", null],
|
|
55
|
+
[undefined, null],
|
|
56
|
+
])("STEALTH=%s → %s", (raw, lock) => {
|
|
57
|
+
if (raw !== undefined) process.env["STEALTH"] = raw;
|
|
58
|
+
expect(siteLock()).toBe(lock);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("is STEALTH's own header value", () => {
|
|
62
|
+
expect(HIDDEN_ROBOTS_HEADER).toBe("noindex, nofollow, noarchive");
|
|
63
|
+
});
|
|
64
|
+
});
|
|
@@ -89,6 +89,16 @@ export interface McpOAuthDeps {
|
|
|
89
89
|
* carrying the entry is not this server's. Requires `issuerTag`.
|
|
90
90
|
*/
|
|
91
91
|
allWorkspaces?: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* #12063 FR7 — clear outside-send switches, in every workspace: one
|
|
94
|
+
* person's for one client, or (no `applicationId`) every client of theirs.
|
|
95
|
+
* A switch never outlives the connection it was given to, so this runs when
|
|
96
|
+
* the person's line for a client ends (`/mcp/revoke`, `/mcp/revoke-client`,
|
|
97
|
+
* a changed password) and when a client and person with no live token
|
|
98
|
+
* consent again, which also covers a lapsed refresh and a disabled client.
|
|
99
|
+
* Absent: nothing is cleared.
|
|
100
|
+
*/
|
|
101
|
+
clearOutsideSendSwitches?(target: { userId: string; applicationId?: string }): Promise<void>;
|
|
92
102
|
}
|
|
93
103
|
|
|
94
104
|
/** The scopes `/mcp/authorize` accepts a request for. */
|
|
@@ -234,6 +244,7 @@ interface AuthorizationValue {
|
|
|
234
244
|
}
|
|
235
245
|
|
|
236
246
|
interface OAuthApplicationRow {
|
|
247
|
+
id: string;
|
|
237
248
|
clientId: string;
|
|
238
249
|
clientSecret?: string | null;
|
|
239
250
|
type?: string | null;
|
|
@@ -572,6 +583,14 @@ export function mcpOAuthPlugin(deps: McpOAuthDeps) {
|
|
|
572
583
|
`[auth-email] ${JSON.stringify({ userId, kind: "password-change", reason: "mcp_token_revocation_failed" })}`,
|
|
573
584
|
);
|
|
574
585
|
}
|
|
586
|
+
// #12063 FR7 — and their outside-send switches with them.
|
|
587
|
+
try {
|
|
588
|
+
await deps.clearOutsideSendSwitches?.({ userId });
|
|
589
|
+
} catch {
|
|
590
|
+
console.warn(
|
|
591
|
+
`[auth-email] ${JSON.stringify({ userId, kind: "password-change", reason: "outside_send_clear_failed" })}`,
|
|
592
|
+
);
|
|
593
|
+
}
|
|
575
594
|
}),
|
|
576
595
|
},
|
|
577
596
|
],
|
|
@@ -691,6 +710,22 @@ export function mcpOAuthPlugin(deps: McpOAuthDeps) {
|
|
|
691
710
|
});
|
|
692
711
|
}
|
|
693
712
|
|
|
713
|
+
// #12063 FR7 — a client and person with no live token are a new
|
|
714
|
+
// connection, so it starts off: whatever ended the last one (a
|
|
715
|
+
// lapsed refresh, a disabled client, a revoke elsewhere), an owner
|
|
716
|
+
// who let that one send did not let this one.
|
|
717
|
+
if (deps.clearOutsideSendSwitches) {
|
|
718
|
+
const live = await ctx.context.adapter.findOne({
|
|
719
|
+
model: "oauthAccessToken",
|
|
720
|
+
where: [
|
|
721
|
+
{ field: "clientId", value: value.clientId },
|
|
722
|
+
{ field: "userId", value: userId },
|
|
723
|
+
{ field: "refreshTokenExpiresAt", value: new Date(), operator: "gt" },
|
|
724
|
+
],
|
|
725
|
+
});
|
|
726
|
+
if (!live) await deps.clearOutsideSendSwitches({ applicationId: client.id, userId });
|
|
727
|
+
}
|
|
728
|
+
|
|
694
729
|
// `openid`, `profile` and `email` are never bound: no id_token.
|
|
695
730
|
const scope = [
|
|
696
731
|
// Always bound: the plugin issues and refreshes only for it, and
|
|
@@ -773,6 +808,22 @@ export function mcpOAuthPlugin(deps: McpOAuthDeps) {
|
|
|
773
808
|
throw refuse("UNAUTHORIZED", "invalid_client");
|
|
774
809
|
}
|
|
775
810
|
if (!token) throw refuse("BAD_REQUEST", "invalid_request");
|
|
811
|
+
// #12063 FR7 — whose line this token is, read before it goes.
|
|
812
|
+
const held =
|
|
813
|
+
(await ctx.context.adapter.findOne<{ userId?: string | null }>({
|
|
814
|
+
model: "oauthAccessToken",
|
|
815
|
+
where: [
|
|
816
|
+
{ field: "clientId", value: clientId },
|
|
817
|
+
{ field: "accessToken", value: token },
|
|
818
|
+
],
|
|
819
|
+
})) ??
|
|
820
|
+
(await ctx.context.adapter.findOne<{ userId?: string | null }>({
|
|
821
|
+
model: "oauthAccessToken",
|
|
822
|
+
where: [
|
|
823
|
+
{ field: "clientId", value: clientId },
|
|
824
|
+
{ field: "refreshToken", value: token },
|
|
825
|
+
],
|
|
826
|
+
}));
|
|
776
827
|
await deleteTokensOf(ctx, [
|
|
777
828
|
{ field: "clientId", value: clientId },
|
|
778
829
|
{ field: "accessToken", value: token },
|
|
@@ -781,6 +832,9 @@ export function mcpOAuthPlugin(deps: McpOAuthDeps) {
|
|
|
781
832
|
{ field: "clientId", value: clientId },
|
|
782
833
|
{ field: "refreshToken", value: token },
|
|
783
834
|
]);
|
|
835
|
+
if (held?.userId && deps.clearOutsideSendSwitches) {
|
|
836
|
+
await deps.clearOutsideSendSwitches({ applicationId: client.id, userId: held.userId });
|
|
837
|
+
}
|
|
784
838
|
return ctx.json({});
|
|
785
839
|
},
|
|
786
840
|
),
|
|
@@ -794,6 +848,16 @@ export function mcpOAuthPlugin(deps: McpOAuthDeps) {
|
|
|
794
848
|
{ field: "clientId", value: ctx.body.client_id },
|
|
795
849
|
{ field: "userId", value: ctx.context.session.user.id },
|
|
796
850
|
]);
|
|
851
|
+
// #12063 FR7 — the person's switches for this client go with it.
|
|
852
|
+
if (deps.clearOutsideSendSwitches) {
|
|
853
|
+
const app = await ctx.context.adapter.findOne<OAuthApplicationRow>({
|
|
854
|
+
model: "oauthApplication",
|
|
855
|
+
where: [{ field: "clientId", value: ctx.body.client_id }],
|
|
856
|
+
});
|
|
857
|
+
if (app) {
|
|
858
|
+
await deps.clearOutsideSendSwitches({ applicationId: app.id, userId: ctx.context.session.user.id });
|
|
859
|
+
}
|
|
860
|
+
}
|
|
797
861
|
return ctx.json({ revoked });
|
|
798
862
|
},
|
|
799
863
|
),
|
|
@@ -21,6 +21,15 @@
|
|
|
21
21
|
* inside the window share it, a failure included, so an outage never adds the
|
|
22
22
|
* deadline to every manifest request.
|
|
23
23
|
*
|
|
24
|
+
* #11978 D3 — `readMcpServer(url)` is the same one exchange and the same
|
|
25
|
+
* shared answer, told apart for the site's status report: `answering` (with
|
|
26
|
+
* the tools, and the loaded packs' tool names the server reports in its
|
|
27
|
+
* `initialize` answer under `capabilities.experimental["ailk/installed"]`, or
|
|
28
|
+
* `null` from a server that reports none), `refused` when `initialize`
|
|
29
|
+
* answered HTTP 404 (the server is hidden, #10510), and `unreachable` for
|
|
30
|
+
* every other failure below. `readServedMcpTools(url)` is its tools when
|
|
31
|
+
* answering, else `null`, so mcp.json's answers are unchanged.
|
|
32
|
+
*
|
|
24
33
|
* A failed read is `null` — a throw, the deadline, a non-2xx `initialize` or
|
|
25
34
|
* `tools/list`, no JSON-RPC answer with the request's `id`, an `error`
|
|
26
35
|
* answer, a `result.tools` that is not an array, an entry with no string
|
|
@@ -30,6 +39,8 @@
|
|
|
30
39
|
* It never rejects.
|
|
31
40
|
*/
|
|
32
41
|
|
|
42
|
+
import { MCP_INSTALLED_CAPABILITY } from "@working-theory/validation";
|
|
43
|
+
|
|
33
44
|
/** Names this caller and its purpose to the server's user-agent guard. */
|
|
34
45
|
export const MCP_DISCOVERY_USER_AGENT = "ailk-web/mcp-discovery";
|
|
35
46
|
/** The MCP protocol version this site speaks and its manifest advertises. */
|
|
@@ -48,6 +59,15 @@ export interface ServedMcpTool {
|
|
|
48
59
|
inputSchema: Record<string, unknown>;
|
|
49
60
|
}
|
|
50
61
|
|
|
62
|
+
/** #11978 D3 — what the MCP server at a URL answered. */
|
|
63
|
+
export type McpServerAnswer =
|
|
64
|
+
| { state: "answering"; tools: ServedMcpTool[]; installed: string[] | null }
|
|
65
|
+
| { state: "refused" }
|
|
66
|
+
| { state: "unreachable" };
|
|
67
|
+
|
|
68
|
+
const REFUSED: McpServerAnswer = { state: "refused" };
|
|
69
|
+
const UNREACHABLE: McpServerAnswer = { state: "unreachable" };
|
|
70
|
+
|
|
51
71
|
type JsonRpcMessage = { id?: unknown; result?: unknown; error?: unknown };
|
|
52
72
|
|
|
53
73
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
@@ -94,13 +114,25 @@ function toServedTool(entry: unknown): ServedMcpTool | null {
|
|
|
94
114
|
};
|
|
95
115
|
}
|
|
96
116
|
|
|
97
|
-
|
|
117
|
+
/** #11978 D4 — the loaded packs' tool names from an `initialize` result, or `null`. */
|
|
118
|
+
function installedOf(result: Record<string, unknown>): string[] | null {
|
|
119
|
+
const capabilities = result["capabilities"];
|
|
120
|
+
const experimental = isRecord(capabilities) ? capabilities["experimental"] : undefined;
|
|
121
|
+
const entry = isRecord(experimental) ? experimental[MCP_INSTALLED_CAPABILITY] : undefined;
|
|
122
|
+
const tools = isRecord(entry) ? entry["tools"] : undefined;
|
|
123
|
+
return Array.isArray(tools) && tools.every((name) => typeof name === "string")
|
|
124
|
+
? (tools as string[])
|
|
125
|
+
: null;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async function exchange(url: string): Promise<McpServerAnswer> {
|
|
98
129
|
const signal = AbortSignal.timeout(MCP_TOOLS_TIMEOUT_MS);
|
|
99
130
|
const headers: Record<string, string> = {
|
|
100
131
|
"user-agent": MCP_DISCOVERY_USER_AGENT,
|
|
101
132
|
accept: "application/json, text/event-stream",
|
|
102
133
|
};
|
|
103
134
|
let nextId = 1;
|
|
135
|
+
let lastStatus = 0;
|
|
104
136
|
|
|
105
137
|
const post = (body: Record<string, unknown>): Promise<Response> =>
|
|
106
138
|
fetch(url, {
|
|
@@ -119,6 +151,7 @@ async function exchange(url: string): Promise<ServedMcpTool[] | null> {
|
|
|
119
151
|
): Promise<{ result: Record<string, unknown>; res: Response } | null> => {
|
|
120
152
|
const id = nextId++;
|
|
121
153
|
const res = await post({ id, method, params });
|
|
154
|
+
lastStatus = res.status;
|
|
122
155
|
if (!res.ok) {
|
|
123
156
|
await res.body?.cancel();
|
|
124
157
|
return null;
|
|
@@ -133,7 +166,8 @@ async function exchange(url: string): Promise<ServedMcpTool[] | null> {
|
|
|
133
166
|
capabilities: {},
|
|
134
167
|
clientInfo: { name: "ailk-web", version: "1" },
|
|
135
168
|
});
|
|
136
|
-
|
|
169
|
+
// #11978 D3 — a hidden server answers `initialize` with Fastify's 404.
|
|
170
|
+
if (init === null) return lastStatus === 404 ? REFUSED : UNREACHABLE;
|
|
137
171
|
const sessionId = init.res.headers.get("mcp-session-id");
|
|
138
172
|
const version = init.result["protocolVersion"];
|
|
139
173
|
headers["mcp-protocol-version"] =
|
|
@@ -148,17 +182,19 @@ async function exchange(url: string): Promise<ServedMcpTool[] | null> {
|
|
|
148
182
|
let cursor: string | undefined;
|
|
149
183
|
for (let page = 0; page < MAX_PAGES; page++) {
|
|
150
184
|
const listed = await call("tools/list", cursor === undefined ? {} : { cursor });
|
|
151
|
-
if (listed === null || !Array.isArray(listed.result["tools"])) return
|
|
185
|
+
if (listed === null || !Array.isArray(listed.result["tools"])) return UNREACHABLE;
|
|
152
186
|
for (const entry of listed.result["tools"] as unknown[]) {
|
|
153
187
|
const tool = toServedTool(entry);
|
|
154
|
-
if (tool === null) return
|
|
188
|
+
if (tool === null) return UNREACHABLE;
|
|
155
189
|
tools.push(tool);
|
|
156
190
|
}
|
|
157
191
|
const next = listed.result["nextCursor"];
|
|
158
192
|
cursor = typeof next === "string" ? next : undefined;
|
|
159
193
|
if (cursor === undefined) break;
|
|
160
194
|
}
|
|
161
|
-
return cursor === undefined
|
|
195
|
+
return cursor === undefined
|
|
196
|
+
? { state: "answering", tools, installed: installedOf(init.result) }
|
|
197
|
+
: UNREACHABLE;
|
|
162
198
|
} finally {
|
|
163
199
|
if (sessionId) {
|
|
164
200
|
// End the stateful session, whatever the list's outcome. No
|
|
@@ -171,18 +207,24 @@ async function exchange(url: string): Promise<ServedMcpTool[] | null> {
|
|
|
171
207
|
}
|
|
172
208
|
}
|
|
173
209
|
|
|
174
|
-
const held = new Map<string, { at: number; answer: Promise<
|
|
210
|
+
const held = new Map<string, { at: number; answer: Promise<McpServerAnswer> }>();
|
|
175
211
|
|
|
176
|
-
/** #
|
|
177
|
-
export function
|
|
212
|
+
/** #11978 D3 — what the MCP server at `url` answered. Never rejects. */
|
|
213
|
+
export function readMcpServer(url: string): Promise<McpServerAnswer> {
|
|
178
214
|
const now = Date.now();
|
|
179
215
|
const hit = held.get(url);
|
|
180
216
|
if (hit !== undefined && now - hit.at < MCP_TOOLS_TTL_MS) return hit.answer;
|
|
181
|
-
const answer = exchange(url).catch(() =>
|
|
217
|
+
const answer = exchange(url).catch(() => UNREACHABLE);
|
|
182
218
|
held.set(url, { at: now, answer });
|
|
183
219
|
return answer;
|
|
184
220
|
}
|
|
185
221
|
|
|
222
|
+
/** #11951 D2 — the tools the MCP server at `url` serves, or `null`. Never rejects. */
|
|
223
|
+
export async function readServedMcpTools(url: string): Promise<ServedMcpTool[] | null> {
|
|
224
|
+
const answer = await readMcpServer(url);
|
|
225
|
+
return answer.state === "answering" ? answer.tools : null;
|
|
226
|
+
}
|
|
227
|
+
|
|
186
228
|
/** Test seam: forget every held answer. */
|
|
187
229
|
export function __resetServedMcpToolsForTests(): void {
|
|
188
230
|
held.clear();
|
|
@@ -22,7 +22,10 @@
|
|
|
22
22
|
* in the key (D2).
|
|
23
23
|
*
|
|
24
24
|
* The module holds no user-visible copy: the CTA label, the recommended label
|
|
25
|
-
* and the period phrasings arrive in `labels` (D9, customer-facing-i18n).
|
|
25
|
+
* and the period phrasings arrive in `labels` (D9, customer-facing-i18n). A
|
|
26
|
+
* seller's own button label (`ctaLabel`, Stripe `ailk_cta`) and an add-on's
|
|
27
|
+
* eyebrow (`ailk_eyebrow`) are seller-authored text shown as written, as the
|
|
28
|
+
* product name is (#12103 D1, D5).
|
|
26
29
|
*/
|
|
27
30
|
import {
|
|
28
31
|
parseLookupKey,
|
|
@@ -45,7 +48,7 @@ type PricingAddonTile = NonNullable<PricingSectionData["addons"]>[number] & {
|
|
|
45
48
|
};
|
|
46
49
|
|
|
47
50
|
export interface OfferingsPricingLabels {
|
|
48
|
-
/** The CTA label on every card and tile. */
|
|
51
|
+
/** The CTA label on every card and tile whose product sets none of its own. */
|
|
49
52
|
cta: string;
|
|
50
53
|
/** The recommended plan's pill and the recommended add-on's eyebrow. */
|
|
51
54
|
recommended: string;
|
|
@@ -57,6 +60,8 @@ export interface OfferingsPricingLabels {
|
|
|
57
60
|
withRequired(plan: string, required: string): string;
|
|
58
61
|
/** A deposit plan's footnote, from the formatted deposit (#10030 D10). */
|
|
59
62
|
depositNote(deposit: string): string;
|
|
63
|
+
/** The yearly total under a per-month annual price (#12139 D1). */
|
|
64
|
+
billedYearly(amount: string): string;
|
|
60
65
|
}
|
|
61
66
|
|
|
62
67
|
export interface OfferingsPricing {
|
|
@@ -64,6 +69,12 @@ export interface OfferingsPricing {
|
|
|
64
69
|
addons: PricingSectionData | null;
|
|
65
70
|
}
|
|
66
71
|
|
|
72
|
+
/** The layouts a plans fragment takes (#12140 D3): every variant but `addons`. */
|
|
73
|
+
export type OfferingsLayout = Exclude<
|
|
74
|
+
NonNullable<PricingSectionData["variant"]>,
|
|
75
|
+
"addons"
|
|
76
|
+
>;
|
|
77
|
+
|
|
67
78
|
/** The route every Offerings CTA links to, followed by a grammar key. */
|
|
68
79
|
export const OFFERINGS_CHECKOUT_PATH = "/api/offerings/checkout";
|
|
69
80
|
|
|
@@ -175,6 +186,12 @@ function stripFormatCharacters(text: string, keepNewlines = false): string {
|
|
|
175
186
|
);
|
|
176
187
|
}
|
|
177
188
|
|
|
189
|
+
/** The product's own button label (#12103 D1), else the translated default. */
|
|
190
|
+
function ctaLabel(product: OfferingsProduct, labels: OfferingsPricingLabels): string {
|
|
191
|
+
const own = product.ctaLabel && stripFormatCharacters(product.ctaLabel);
|
|
192
|
+
return own || labels.cta;
|
|
193
|
+
}
|
|
194
|
+
|
|
178
195
|
function features(product: OfferingsProduct): string[] {
|
|
179
196
|
return product.marketingFeatures
|
|
180
197
|
.map((feature) => stripFormatCharacters(feature))
|
|
@@ -255,14 +272,17 @@ function bundleCard(
|
|
|
255
272
|
name: stripFormatCharacters(product.name),
|
|
256
273
|
price,
|
|
257
274
|
features: features(product),
|
|
258
|
-
cta: { label: labels
|
|
275
|
+
cta: { label: ctaLabel(product, labels), href },
|
|
259
276
|
};
|
|
260
277
|
// The deposit note wins the footnote; the terms note shows only without one.
|
|
261
278
|
// NO_HAND_IMPLEMENT_OK: builder-assessors run for #10030 — the builder is the implementer.
|
|
262
279
|
if (product.deposit !== undefined)
|
|
263
280
|
card.priceFootnote = labels.depositNote(formatMinorUnits(product.deposit, once.currency, locale));
|
|
264
|
-
else if (product.termsNote)
|
|
281
|
+
else if (product.termsNote) {
|
|
265
282
|
card.priceFootnote = stripFormatCharacters(product.termsNote);
|
|
283
|
+
// Beside both prices, the terms note describes the annual one (#12139 D2).
|
|
284
|
+
if (monthly && yearly) card.priceFootnoteAnnualOnly = true;
|
|
285
|
+
}
|
|
266
286
|
const annualHref =
|
|
267
287
|
monthly && yearly && offeringsBundleHref(once.lookupKey, yearly.lookupKey);
|
|
268
288
|
if (annualHref) card.annualCtaHref = annualHref;
|
|
@@ -289,7 +309,18 @@ function planCard(
|
|
|
289
309
|
const once = priceFor(product, PERIOD.once);
|
|
290
310
|
const price: PricingPlanCard["price"] = {};
|
|
291
311
|
if (monthly) price.monthly = phrase(monthly, locale, labels);
|
|
292
|
-
|
|
312
|
+
// Beside a monthly Price, annual mode shows the yearly Price per month, so
|
|
313
|
+
// the two modes compare in one unit (#12139 D1); its total goes in a note.
|
|
314
|
+
if (yearly)
|
|
315
|
+
price.annual = monthly
|
|
316
|
+
? labels.monthly(
|
|
317
|
+
formatMinorUnits(
|
|
318
|
+
Math.round(yearly.amount / 12),
|
|
319
|
+
yearly.currency,
|
|
320
|
+
locale,
|
|
321
|
+
),
|
|
322
|
+
)
|
|
323
|
+
: phrase(yearly, locale, labels);
|
|
293
324
|
if (once && !monthly && !yearly) price.custom = phrase(once, locale, labels);
|
|
294
325
|
|
|
295
326
|
const card: PricingPlanCard = {
|
|
@@ -297,7 +328,7 @@ function planCard(
|
|
|
297
328
|
name: stripFormatCharacters(product.name),
|
|
298
329
|
price,
|
|
299
330
|
features: features(product),
|
|
300
|
-
cta: { label: labels
|
|
331
|
+
cta: { label: ctaLabel(product, labels), href },
|
|
301
332
|
};
|
|
302
333
|
const description =
|
|
303
334
|
product.description && stripFormatCharacters(product.description, true);
|
|
@@ -305,12 +336,19 @@ function planCard(
|
|
|
305
336
|
if (product.unitLabel)
|
|
306
337
|
card.priceUnit = stripFormatCharacters(product.unitLabel);
|
|
307
338
|
if (product.note) card.priceSubhead = stripFormatCharacters(product.note);
|
|
308
|
-
if (
|
|
309
|
-
card.
|
|
339
|
+
if (monthly && yearly)
|
|
340
|
+
card.annualPriceNote = labels.billedYearly(
|
|
341
|
+
formatMinorUnits(yearly.amount, yearly.currency, locale),
|
|
342
|
+
);
|
|
310
343
|
// A deposit plan's footnote (#10030 D10), in its one-time Price's currency;
|
|
311
344
|
// it takes the footnote over a terms note (the rarer field).
|
|
312
345
|
if (product.deposit !== undefined && once)
|
|
313
346
|
card.priceFootnote = labels.depositNote(formatMinorUnits(product.deposit, once.currency, locale));
|
|
347
|
+
else if (product.termsNote) {
|
|
348
|
+
card.priceFootnote = stripFormatCharacters(product.termsNote);
|
|
349
|
+
// Beside both prices, the terms note describes the annual one (#12139 D2).
|
|
350
|
+
if (monthly && yearly) card.priceFootnoteAnnualOnly = true;
|
|
351
|
+
}
|
|
314
352
|
// Annual mode shows the yearly Price only when a monthly one is beside it,
|
|
315
353
|
// so only then does the card need a second link (D5, D6).
|
|
316
354
|
const annualHref =
|
|
@@ -324,6 +362,105 @@ function planCard(
|
|
|
324
362
|
return card;
|
|
325
363
|
}
|
|
326
364
|
|
|
365
|
+
/**
|
|
366
|
+
* `features-and-plans` for one product with a monthly and a yearly Price
|
|
367
|
+
* (#12140 D4): two blocks, each selling its own Price, built from the
|
|
368
|
+
* product's card as `planCard` made it. The yearly block is keyed by its
|
|
369
|
+
* lookup key, which the plan-slug grammar refuses, so it never collides with a
|
|
370
|
+
* card's key or matches `?plan=`; the terms note sits on it alone (#12139 D2).
|
|
371
|
+
* `null` when the product is not that shape or either key is outside the
|
|
372
|
+
* grammar — the caller then keeps the card as built.
|
|
373
|
+
*/
|
|
374
|
+
function splitBlocks(
|
|
375
|
+
product: OfferingsProduct,
|
|
376
|
+
card: PricingPlanCard,
|
|
377
|
+
locale: string,
|
|
378
|
+
labels: OfferingsPricingLabels,
|
|
379
|
+
): PricingPlanCard[] | null {
|
|
380
|
+
const monthly = priceFor(product, PERIOD.monthly);
|
|
381
|
+
const yearly = priceFor(product, PERIOD.yearly);
|
|
382
|
+
if (product.requires !== undefined || !monthly || !yearly) return null;
|
|
383
|
+
const monthlyHref = offeringsCheckoutHref(monthly.lookupKey);
|
|
384
|
+
const yearlyHref = offeringsCheckoutHref(yearly.lookupKey);
|
|
385
|
+
if (!monthlyHref || !yearlyHref) return null;
|
|
386
|
+
const {
|
|
387
|
+
price: _price,
|
|
388
|
+
annualCtaHref: _annualCtaHref,
|
|
389
|
+
annualPriceNote: _annualPriceNote,
|
|
390
|
+
priceFootnote: _priceFootnote,
|
|
391
|
+
priceFootnoteAnnualOnly: _priceFootnoteAnnualOnly,
|
|
392
|
+
...shared
|
|
393
|
+
} = card;
|
|
394
|
+
const yearlyBlock: PricingPlanCard = {
|
|
395
|
+
key: yearly.lookupKey,
|
|
396
|
+
name: card.name,
|
|
397
|
+
price: { annual: phrase(yearly, locale, labels) },
|
|
398
|
+
features: card.features,
|
|
399
|
+
cta: { label: card.cta.label, href: yearlyHref },
|
|
400
|
+
};
|
|
401
|
+
if (card.priceUnit !== undefined) yearlyBlock.priceUnit = card.priceUnit;
|
|
402
|
+
if (card.priceSubhead !== undefined)
|
|
403
|
+
yearlyBlock.priceSubhead = card.priceSubhead;
|
|
404
|
+
if (product.termsNote)
|
|
405
|
+
yearlyBlock.priceFootnote = stripFormatCharacters(product.termsNote);
|
|
406
|
+
return [
|
|
407
|
+
{
|
|
408
|
+
...shared,
|
|
409
|
+
price: { monthly: phrase(monthly, locale, labels) },
|
|
410
|
+
cta: { label: card.cta.label, href: monthlyHref },
|
|
411
|
+
},
|
|
412
|
+
yearlyBlock,
|
|
413
|
+
];
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* The plans fragment in `layout` (#12140 D3): the cards as built, framed for
|
|
418
|
+
* the layout that renders them. Absent, today's toggle fragment. `product` is
|
|
419
|
+
* the one plan product behind `cards`, when there is exactly one.
|
|
420
|
+
*/
|
|
421
|
+
function plansFragment(
|
|
422
|
+
cards: PricingPlanCard[],
|
|
423
|
+
layout: OfferingsLayout | undefined,
|
|
424
|
+
product: OfferingsProduct | undefined,
|
|
425
|
+
locale: string,
|
|
426
|
+
labels: OfferingsPricingLabels,
|
|
427
|
+
): PricingSectionData {
|
|
428
|
+
switch (layout) {
|
|
429
|
+
case undefined:
|
|
430
|
+
case "three-tiers-with-toggle":
|
|
431
|
+
return {
|
|
432
|
+
variant: "three-tiers-with-toggle",
|
|
433
|
+
cardLayout: "centered",
|
|
434
|
+
billingToggle: cards.some(
|
|
435
|
+
(card) =>
|
|
436
|
+
card.price.monthly !== undefined &&
|
|
437
|
+
card.price.annual !== undefined,
|
|
438
|
+
),
|
|
439
|
+
plans: cards,
|
|
440
|
+
};
|
|
441
|
+
// These variants show monthly prices only, so they take no toggle.
|
|
442
|
+
case "with-comparison-table":
|
|
443
|
+
case "two-tiers-with-extra-tier":
|
|
444
|
+
case "band-hero":
|
|
445
|
+
return { variant: layout, cardLayout: "centered", plans: cards };
|
|
446
|
+
// The variant renders one plan and has no card layout.
|
|
447
|
+
case "single-price-with-details":
|
|
448
|
+
return { variant: layout, plans: cards.slice(0, 1) };
|
|
449
|
+
case "features-and-plans": {
|
|
450
|
+
const split =
|
|
451
|
+
product && splitBlocks(product, cards[0]!, locale, labels);
|
|
452
|
+
const rows = product ? features(product) : [];
|
|
453
|
+
return {
|
|
454
|
+
variant: layout,
|
|
455
|
+
plans: split ?? cards,
|
|
456
|
+
...(rows.length > 0
|
|
457
|
+
? { features: rows.map((title) => ({ title })) }
|
|
458
|
+
: {}),
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
|
|
327
464
|
function addonTile(
|
|
328
465
|
product: OfferingsProduct,
|
|
329
466
|
highlighted: boolean,
|
|
@@ -339,10 +476,16 @@ function addonTile(
|
|
|
339
476
|
name: stripFormatCharacters(product.name),
|
|
340
477
|
price: phrase(shown, locale, labels),
|
|
341
478
|
features: features(product),
|
|
342
|
-
cta: { label: labels
|
|
479
|
+
cta: { label: ctaLabel(product, labels), href },
|
|
343
480
|
};
|
|
344
481
|
if (product.unitLabel)
|
|
345
482
|
tile.qualifier = stripFormatCharacters(product.unitLabel);
|
|
483
|
+
// #12103 D5 — the seller's eyebrow and note; the recommended add-on's
|
|
484
|
+
// eyebrow stays the Recommended label, the one place a tile shows it.
|
|
485
|
+
const eyebrow = product.eyebrow && stripFormatCharacters(product.eyebrow);
|
|
486
|
+
if (eyebrow) tile.eyebrow = eyebrow;
|
|
487
|
+
const note = product.note && stripFormatCharacters(product.note);
|
|
488
|
+
if (note) tile.note = note;
|
|
346
489
|
if (highlighted) {
|
|
347
490
|
tile.eyebrow = labels.recommended;
|
|
348
491
|
tile.checkTone = "primary";
|
|
@@ -393,6 +536,14 @@ function narrowToPlans(
|
|
|
393
536
|
* `plans` (#10044 D4) narrows the set to an offering page's own products:
|
|
394
537
|
* those whose `{plan}` it lists, plus every product a kept one `requires`, in
|
|
395
538
|
* the snapshot's order. Absent, every shown product is mapped, as before.
|
|
539
|
+
*
|
|
540
|
+
* `exclude` (#12103 D2) drops the plan cards of the plans it lists — the ones
|
|
541
|
+
* a section's own `offeringPlans` already shows — so the page's unlisted
|
|
542
|
+
* plans section does not show them twice. Add-on tiles are unaffected.
|
|
543
|
+
*
|
|
544
|
+
* `layout` (#12140 D3) frames the plans fragment for the variant a bound
|
|
545
|
+
* section names; the cards are built the same either way. Absent, the plans
|
|
546
|
+
* fragment is the toggle layout, exactly as before. Add-ons are unaffected.
|
|
396
547
|
*/
|
|
397
548
|
export function offeringsPricing(
|
|
398
549
|
shownSet: unknown,
|
|
@@ -400,6 +551,8 @@ export function offeringsPricing(
|
|
|
400
551
|
locale: string;
|
|
401
552
|
labels: OfferingsPricingLabels;
|
|
402
553
|
plans?: readonly string[] | undefined;
|
|
554
|
+
exclude?: readonly string[] | undefined;
|
|
555
|
+
layout?: OfferingsLayout | undefined;
|
|
403
556
|
},
|
|
404
557
|
): OfferingsPricing | null {
|
|
405
558
|
const parsed = shownSetSchema.safeParse(shownSet);
|
|
@@ -415,9 +568,13 @@ export function offeringsPricing(
|
|
|
415
568
|
shown.map((o) => o.requires).filter((plan) => plan !== undefined),
|
|
416
569
|
);
|
|
417
570
|
const offerings = narrowToPlans(shown, options.plans);
|
|
571
|
+
const excluded = new Set(options.exclude);
|
|
418
572
|
// #11166 — the two group reads are exact, so an `offer` falls into neither.
|
|
419
573
|
const planProducts = offerings.filter(
|
|
420
|
-
(o) =>
|
|
574
|
+
(o) =>
|
|
575
|
+
o.ailkGroup === "plan" &&
|
|
576
|
+
!requiredPlans.has(o.plan) &&
|
|
577
|
+
!excluded.has(o.plan),
|
|
421
578
|
);
|
|
422
579
|
const addonProducts = offerings.filter((o) => o.ailkGroup === "addon");
|
|
423
580
|
const recommendedPlan = firstRecommended(planProducts);
|
|
@@ -439,19 +596,15 @@ export function offeringsPricing(
|
|
|
439
596
|
.map((p) => addonTile(p, p.plan === recommendedAddon, locale, labels))
|
|
440
597
|
.filter(isPresent);
|
|
441
598
|
|
|
599
|
+
// Each card is keyed by its product's `{plan}`, so a lone card names its product.
|
|
600
|
+
const product =
|
|
601
|
+
plans.length === 1
|
|
602
|
+
? planProducts.find((p) => p.plan === plans[0]!.key)
|
|
603
|
+
: undefined;
|
|
442
604
|
return {
|
|
443
605
|
plans:
|
|
444
606
|
plans.length > 0
|
|
445
|
-
?
|
|
446
|
-
variant: "three-tiers-with-toggle",
|
|
447
|
-
cardLayout: "centered",
|
|
448
|
-
billingToggle: plans.some(
|
|
449
|
-
(card) =>
|
|
450
|
-
card.price.monthly !== undefined &&
|
|
451
|
-
card.price.annual !== undefined,
|
|
452
|
-
),
|
|
453
|
-
plans,
|
|
454
|
-
}
|
|
607
|
+
? plansFragment(plans, options.layout, product, locale, labels)
|
|
455
608
|
: null,
|
|
456
609
|
addons: addons.length > 0 ? { variant: "addons", plans: [], addons } : null,
|
|
457
610
|
};
|