create-ailk 0.32.0 → 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -3
- package/component-catalog.json +12 -1
- package/component-catalog.md +6 -5
- package/dist/export-content.d.ts +6 -3
- package/dist/export-content.js +82 -11
- package/dist/lib/env-catalog.js +4 -0
- package/dist/lib/import-mdx.d.ts +111 -0
- package/dist/lib/import-mdx.js +648 -46
- package/dist/migrate-content.d.ts +3 -1
- package/dist/migrate-content.js +52 -1
- package/dist/seed-flows.d.ts +1 -1
- package/dist/seed-flows.js +9 -4
- package/dist/surfaces.js +1 -0
- package/package.json +3 -3
- package/templates/apps/api/.env.example +11 -0
- package/templates/apps/api/CLAUDE.md +7 -5
- package/templates/apps/api/src/lib/__mocks__/prisma.ts +13 -0
- package/templates/apps/mcp/CLAUDE.md +4 -2
- package/templates/apps/web/CLAUDE.md +4 -1
- package/templates/apps/web/app/[locale]/(auth)/__tests__/password-reset.test.tsx +28 -0
- package/templates/apps/web/app/[locale]/(auth)/verify-email/__tests__/actions.test.ts +94 -0
- package/templates/apps/web/app/[locale]/(auth)/verify-email/actions.ts +77 -0
- package/templates/apps/web/app/[locale]/(auth)/verify-email/page.tsx +79 -14
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/hub-mode.test.tsx +7 -0
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-menu.test.tsx +7 -0
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/page.test.tsx +7 -0
- package/templates/apps/web/app/[locale]/contact/__tests__/contact.actions.test.ts +21 -0
- package/templates/apps/web/app/[locale]/contact/contact.actions.ts +15 -9
- package/templates/apps/web/app/[locale]/flows/[slug]/FlowStepperClient.tsx +38 -105
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.invite.test.tsx +72 -58
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/verify.test.tsx +249 -0
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsClient.tsx +164 -20
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/by-result.test.tsx +269 -0
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/score.test.tsx +179 -0
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/page.tsx +108 -40
- package/templates/apps/web/app/[locale]/flows/[slug]/verify/page.tsx +153 -0
- package/templates/apps/web/app/[locale]/flows/[slug]/verify.actions.ts +151 -0
- package/templates/apps/web/app/[locale]/meet/confirmed/BookingHandOff.tsx +1 -1
- package/templates/apps/web/app/[locale]/thanks/[slug]/__tests__/page.test.tsx +3 -20
- package/templates/apps/web/app/[locale]/thanks/[slug]/page.tsx +2 -9
- package/templates/apps/web/auth.ts +22 -6
- package/templates/apps/web/lib/__tests__/account-config.test.ts +69 -0
- package/templates/apps/web/lib/__tests__/auth-email.test.ts +99 -1
- package/templates/apps/web/lib/__tests__/telemetry-scrub.test.ts +20 -0
- package/templates/apps/web/lib/account-config.ts +52 -14
- package/templates/apps/web/lib/auth-email.ts +87 -5
- package/templates/apps/web/lib/mcp-oauth.ts +49 -6
- package/templates/apps/web/lib/telemetry-scrub.ts +6 -0
- package/templates/apps/web/messages/en.json +26 -1
- package/templates/database/seed.ts +7 -7
- package/versions.json +48 -48
- package/templates/apps/web/app/[locale]/thanks/[slug]/AccountInviteLink.tsx +0 -89
- package/templates/apps/web/app/[locale]/thanks/[slug]/__tests__/AccountInviteLink.test.tsx +0 -104
|
@@ -88,6 +88,17 @@ jest.mock("node:crypto", () => {
|
|
|
88
88
|
};
|
|
89
89
|
});
|
|
90
90
|
|
|
91
|
+
/**
|
|
92
|
+
* #10820 D7 — the confirm page's server action. Rendering `?verify=` must
|
|
93
|
+
* spend nothing: the action is the only path to the confirm hop, so a GET that
|
|
94
|
+
* called it is the mail-scanner hole this page exists to close.
|
|
95
|
+
*/
|
|
96
|
+
const mockConfirmEmailAction = jest.fn();
|
|
97
|
+
// eslint-disable-next-line no-restricted-syntax -- the "use server" action is the page's network boundary (it reaches apps/api over HTTP); its own suite, verify-email/__tests__/actions.test.ts, exercises it.
|
|
98
|
+
jest.mock("../verify-email/actions", () => ({
|
|
99
|
+
confirmEmailAction: (...args: unknown[]) => mockConfirmEmailAction(...args),
|
|
100
|
+
}));
|
|
101
|
+
|
|
91
102
|
import en from "../../../../messages/en.json";
|
|
92
103
|
import { createAuth } from "../../../../auth";
|
|
93
104
|
import ForgotPasswordPage from "../forgot-password/page";
|
|
@@ -218,6 +229,23 @@ describe("/verify-email", () => {
|
|
|
218
229
|
expect(screen.getByTestId("verify-token-error")).toBeInTheDocument();
|
|
219
230
|
expect(screen.queryByTestId("auth-sent-body")).not.toBeInTheDocument();
|
|
220
231
|
});
|
|
232
|
+
|
|
233
|
+
it("renders a confirm button on ?verify= and spends nothing while rendering (#10820)", async () => {
|
|
234
|
+
await renderVerify({ verify: "N".repeat(43) });
|
|
235
|
+
expect(screen.getByTestId("verify-email-confirm")).toBeInTheDocument();
|
|
236
|
+
expect(screen.getByTestId("verify-email-confirm-button")).toHaveTextContent(
|
|
237
|
+
en.auth.confirmButton,
|
|
238
|
+
);
|
|
239
|
+
expect(mockConfirmEmailAction).not.toHaveBeenCalled();
|
|
240
|
+
expect(document.body.innerHTML).not.toContain("N".repeat(43));
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it("renders the verified card on ?confirmed=1 (#10820)", async () => {
|
|
244
|
+
await renderVerify({ confirmed: "1" });
|
|
245
|
+
expect(screen.getByTestId("verify-email-confirmed")).toHaveTextContent(
|
|
246
|
+
en.auth.verifiedHeading,
|
|
247
|
+
);
|
|
248
|
+
});
|
|
221
249
|
});
|
|
222
250
|
|
|
223
251
|
// ── The flag-alone configuration: intent set, send impossible ──────────────
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment node
|
|
3
|
+
*
|
|
4
|
+
* `confirmEmailAction` (#10820 D7) — the one place a sign-up link's nonce is
|
|
5
|
+
* spent. The per-visitor limit and the bot check run before any API call; the
|
|
6
|
+
* signed hop's answer picks the redirect; the nonce is in no redirect URL.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const mockRedirect = jest.fn((url: string) => {
|
|
10
|
+
throw new Error(`REDIRECT ${url}`);
|
|
11
|
+
});
|
|
12
|
+
jest.mock("next/navigation", () => ({
|
|
13
|
+
redirect: (url: string) => mockRedirect(url),
|
|
14
|
+
}));
|
|
15
|
+
jest.mock("next/headers", () => ({
|
|
16
|
+
headers: async () => new Headers(),
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
const mockRunBotCheck = jest.fn();
|
|
20
|
+
// eslint-disable-next-line no-restricted-syntax -- BotID is an external service boundary; lib/bot-check.ts is its one wrapper.
|
|
21
|
+
jest.mock("../../../../../lib/bot-check", () => ({
|
|
22
|
+
runBotCheck: (...args: unknown[]) => mockRunBotCheck(...args),
|
|
23
|
+
}));
|
|
24
|
+
|
|
25
|
+
const mockConfirmSignUpEmail = jest.fn();
|
|
26
|
+
// eslint-disable-next-line no-restricted-syntax -- the signed hop to apps/api is the HTTP boundary; lib/auth-email.ts's own suite pins its signing.
|
|
27
|
+
jest.mock("../../../../../lib/auth-email", () => ({
|
|
28
|
+
confirmSignUpEmail: (...args: unknown[]) => mockConfirmSignUpEmail(...args),
|
|
29
|
+
}));
|
|
30
|
+
|
|
31
|
+
import { __resetRateLimit } from "../../../../../src/lib/rate-limit";
|
|
32
|
+
import { confirmEmailAction } from "../actions";
|
|
33
|
+
|
|
34
|
+
const NONCE = "N".repeat(43);
|
|
35
|
+
|
|
36
|
+
async function redirectOf(nonce = NONCE): Promise<string> {
|
|
37
|
+
await expect(confirmEmailAction(nonce, "en")).rejects.toThrow(/^REDIRECT /);
|
|
38
|
+
const url = mockRedirect.mock.calls.at(-1)![0];
|
|
39
|
+
expect(url).not.toContain(nonce);
|
|
40
|
+
return url;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
beforeEach(() => {
|
|
44
|
+
jest.clearAllMocks();
|
|
45
|
+
__resetRateLimit();
|
|
46
|
+
mockRunBotCheck.mockResolvedValue("pass");
|
|
47
|
+
mockConfirmSignUpEmail.mockResolvedValue("verified");
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe("confirmEmailAction (#10820 D7)", () => {
|
|
51
|
+
it.each(["verified", "already_verified"])(
|
|
52
|
+
"redirects to the verified card on %s",
|
|
53
|
+
async (outcome) => {
|
|
54
|
+
mockConfirmSignUpEmail.mockResolvedValue(outcome);
|
|
55
|
+
expect(await redirectOf()).toBe("/verify-email?confirmed=1");
|
|
56
|
+
expect(mockConfirmSignUpEmail).toHaveBeenCalledWith(NONCE);
|
|
57
|
+
},
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
it.each(["expired", "invalid", "failed"])(
|
|
61
|
+
"redirects to the expired-link card on %s",
|
|
62
|
+
async (outcome) => {
|
|
63
|
+
mockConfirmSignUpEmail.mockResolvedValue(outcome);
|
|
64
|
+
expect(await redirectOf()).toBe("/verify-email?error=invalid");
|
|
65
|
+
},
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
it("redirects to the expired-link card when the hop throws", async () => {
|
|
69
|
+
mockConfirmSignUpEmail.mockRejectedValue(new Error("boom"));
|
|
70
|
+
expect(await redirectOf()).toBe("/verify-email?error=invalid");
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it.each(["bot", "unavailable"])(
|
|
74
|
+
"makes no API call when the bot check answers %s",
|
|
75
|
+
async (verdict) => {
|
|
76
|
+
mockRunBotCheck.mockResolvedValue(verdict);
|
|
77
|
+
expect(await redirectOf()).toBe("/verify-email?error=invalid");
|
|
78
|
+
expect(mockConfirmSignUpEmail).not.toHaveBeenCalled();
|
|
79
|
+
},
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
it("makes no API call once the visitor limit is spent", async () => {
|
|
83
|
+
// An unreadable address shares the unknown bucket, 10x the per-visitor 5.
|
|
84
|
+
for (let i = 0; i < 50; i += 1) await redirectOf();
|
|
85
|
+
mockConfirmSignUpEmail.mockClear();
|
|
86
|
+
expect(await redirectOf()).toBe("/verify-email?error=invalid");
|
|
87
|
+
expect(mockConfirmSignUpEmail).not.toHaveBeenCalled();
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("redirects on the default locale for a locale outside the enabled set", async () => {
|
|
91
|
+
await expect(confirmEmailAction(NONCE, "/evil.example")).rejects.toThrow(/^REDIRECT /);
|
|
92
|
+
expect(mockRedirect).toHaveBeenLastCalledWith("/verify-email?confirmed=1");
|
|
93
|
+
});
|
|
94
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use server";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The sign-up confirm click (#10820 D7) — the one place a `/verify-email`
|
|
5
|
+
* link's nonce is spent.
|
|
6
|
+
*
|
|
7
|
+
* The page's GET renders a button and writes nothing, so a mail scanner or a
|
|
8
|
+
* link preview that fetches the link verifies nothing; only a person's POST
|
|
9
|
+
* reaches here. Before any API call it takes the per-visitor limit (5 per
|
|
10
|
+
* 10 minutes) and the bot check, because the API sees only this site's server
|
|
11
|
+
* address. Then the signed hop, `confirmSignUpEmail`, and a redirect: the
|
|
12
|
+
* verified card for `verified` and `already_verified`, the expired-link card
|
|
13
|
+
* for everything else. The nonce is never in either redirect URL, and never
|
|
14
|
+
* logged here.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { localeHref } from "@working-theory/ui";
|
|
18
|
+
import { headers } from "next/headers";
|
|
19
|
+
import { redirect } from "next/navigation";
|
|
20
|
+
|
|
21
|
+
import { confirmSignUpEmail } from "../../../../lib/auth-email";
|
|
22
|
+
import { runBotCheck } from "../../../../lib/bot-check";
|
|
23
|
+
import { takeVisitorLimit } from "../../../../src/lib/rate-limit";
|
|
24
|
+
|
|
25
|
+
const CONFIRM_LIMIT = 5;
|
|
26
|
+
const CONFIRM_WINDOW_MS = 10 * 60 * 1000;
|
|
27
|
+
const NO_HEADERS = { get: () => null };
|
|
28
|
+
|
|
29
|
+
async function confirmed(nonce: string): Promise<boolean> {
|
|
30
|
+
let requestHeaders: Awaited<ReturnType<typeof headers>> | undefined;
|
|
31
|
+
try {
|
|
32
|
+
requestHeaders = await headers();
|
|
33
|
+
} catch {
|
|
34
|
+
// No request scope to read — the shared unknown-visitor bucket.
|
|
35
|
+
}
|
|
36
|
+
const limit = takeVisitorLimit(
|
|
37
|
+
"verifyemail",
|
|
38
|
+
requestHeaders ?? NO_HEADERS,
|
|
39
|
+
CONFIRM_LIMIT,
|
|
40
|
+
CONFIRM_WINDOW_MS,
|
|
41
|
+
);
|
|
42
|
+
if (!limit.allowed) return false;
|
|
43
|
+
|
|
44
|
+
const bot = await runBotCheck({
|
|
45
|
+
source: "verify-email",
|
|
46
|
+
target: "confirmEmailAction",
|
|
47
|
+
scope: "write",
|
|
48
|
+
});
|
|
49
|
+
if (bot !== "pass") return false;
|
|
50
|
+
|
|
51
|
+
// `confirmSignUpEmail` never throws by contract; this guard keeps the
|
|
52
|
+
// action's own promise (a redirect, never a 500) if that ever changes.
|
|
53
|
+
try {
|
|
54
|
+
const outcome = await confirmSignUpEmail(nonce);
|
|
55
|
+
return outcome === "verified" || outcome === "already_verified";
|
|
56
|
+
} catch {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// The locale is a bound argument a direct call could set to anything, so the
|
|
62
|
+
// redirect's segment is checked against the build-time allowlist, never
|
|
63
|
+
// interpolated raw (the `checkout.actions.ts` idiom).
|
|
64
|
+
const DEFAULT_LOCALE = "en";
|
|
65
|
+
const ENABLED_LOCALES = (process.env.NEXT_PUBLIC_ENABLED_LOCALES ?? DEFAULT_LOCALE).split(",");
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Bound by the page — `confirmEmailAction.bind(null, nonce, locale)` — so no
|
|
69
|
+
* hidden input carries the nonce; the form's own data is ignored.
|
|
70
|
+
*/
|
|
71
|
+
export async function confirmEmailAction(nonce: string, locale = "en"): Promise<never> {
|
|
72
|
+
const ok = await confirmed(nonce);
|
|
73
|
+
const safeLocale = ENABLED_LOCALES.includes(locale) ? locale : DEFAULT_LOCALE;
|
|
74
|
+
redirect(
|
|
75
|
+
localeHref(safeLocale, ok ? "/verify-email?confirmed=1" : "/verify-email?error=invalid"),
|
|
76
|
+
);
|
|
77
|
+
}
|
|
@@ -1,31 +1,41 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `/[locale]/verify-email` — the check-your-email terminus (#5963, wired by
|
|
2
|
+
* `/[locale]/verify-email` — the check-your-email terminus (#5963, wired by
|
|
3
|
+
* #5962) and the sign-up confirm page (#10820 D7).
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
* -
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
5
|
+
* Four states, in this precedence:
|
|
6
|
+
* - `?verify=<nonce>` → a confirm card holding ONE button. The GET writes
|
|
7
|
+
* nothing: the button posts to `confirmEmailAction`, bound
|
|
8
|
+
* to the nonce (no hidden input carries it), so a mail
|
|
9
|
+
* scanner or a link preview that fetches the link verifies
|
|
10
|
+
* nothing — only a person's click does.
|
|
11
|
+
* - `?confirmed=1` → the verified card, with the Sign in link.
|
|
12
|
+
* - `?error=…` → the same expired/invalid-link state `/reset-password`
|
|
13
|
+
* renders: the action's answer for an expired, unknown or
|
|
14
|
+
* refused confirm.
|
|
15
|
+
* - no query → the `sent` intent: this page states what just happened.
|
|
11
16
|
*
|
|
12
|
-
* The
|
|
13
|
-
*
|
|
14
|
-
* neither single-use nor revocable — the same link keeps working until it
|
|
15
|
-
* expires. That asymmetry is acceptable precisely because its blast radius is
|
|
16
|
-
* `emailVerified: true` on one row rather than a credential.
|
|
17
|
+
* The link is the API's single-use nonce (`services/email-verification.ts`):
|
|
18
|
+
* one confirm spends it, and it expires after 24 hours.
|
|
17
19
|
*/
|
|
18
20
|
|
|
19
21
|
import { localeHref } from "@working-theory/ui";
|
|
20
22
|
import { AuthCard, type AuthCardLabels } from "@working-theory/ui/blocks";
|
|
23
|
+
import { Button, Text } from "@working-theory/ui/primitives";
|
|
21
24
|
import type { Metadata } from "next";
|
|
22
25
|
import { getTranslations } from "next-intl/server";
|
|
23
26
|
import type { ReactElement } from "react";
|
|
27
|
+
|
|
24
28
|
import { siteLogo } from "../../../../lib/site-logo";
|
|
25
29
|
|
|
30
|
+
import { confirmEmailAction } from "./actions";
|
|
31
|
+
|
|
26
32
|
interface Props {
|
|
27
33
|
params: Promise<{ locale: string }>;
|
|
28
|
-
searchParams?: Promise<{
|
|
34
|
+
searchParams?: Promise<{
|
|
35
|
+
error?: string | string[];
|
|
36
|
+
verify?: string | string[];
|
|
37
|
+
confirmed?: string | string[];
|
|
38
|
+
}>;
|
|
29
39
|
}
|
|
30
40
|
|
|
31
41
|
function firstValue(raw: string | string[] | undefined): string {
|
|
@@ -52,6 +62,61 @@ export default async function VerifyEmailPage({
|
|
|
52
62
|
|
|
53
63
|
const query = searchParams ? await searchParams : {};
|
|
54
64
|
const error = firstValue(query.error);
|
|
65
|
+
const nonce = firstValue(query.verify);
|
|
66
|
+
|
|
67
|
+
if (nonce.length >= 1 && nonce.length <= 256) {
|
|
68
|
+
const labels: AuthCardLabels = {
|
|
69
|
+
sentHeading: t("confirmHeading"),
|
|
70
|
+
sentSubhead: t("confirmSubhead"),
|
|
71
|
+
backToSignIn: t("backToSignIn"),
|
|
72
|
+
};
|
|
73
|
+
return (
|
|
74
|
+
<div className="flex flex-col gap-4" data-testid="verify-email-page">
|
|
75
|
+
<div data-testid="verify-email-confirm">
|
|
76
|
+
<AuthCard
|
|
77
|
+
logo={siteLogo()}
|
|
78
|
+
intent="sent"
|
|
79
|
+
signInHref={signInHref}
|
|
80
|
+
labels={labels}
|
|
81
|
+
body={
|
|
82
|
+
<form
|
|
83
|
+
action={confirmEmailAction.bind(null, nonce, locale)}
|
|
84
|
+
className="flex flex-col gap-5 text-center"
|
|
85
|
+
>
|
|
86
|
+
<Text variant="body-sm" tone="muted">
|
|
87
|
+
{t("confirmBody")}
|
|
88
|
+
</Text>
|
|
89
|
+
<Button
|
|
90
|
+
type="submit"
|
|
91
|
+
size="big"
|
|
92
|
+
className="w-full"
|
|
93
|
+
data-testid="verify-email-confirm-button"
|
|
94
|
+
>
|
|
95
|
+
{t("confirmButton")}
|
|
96
|
+
</Button>
|
|
97
|
+
</form>
|
|
98
|
+
}
|
|
99
|
+
/>
|
|
100
|
+
</div>
|
|
101
|
+
</div>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (firstValue(query.confirmed) === "1") {
|
|
106
|
+
const labels: AuthCardLabels = {
|
|
107
|
+
sentHeading: t("verifiedHeading"),
|
|
108
|
+
sentSubhead: t("verifiedSubhead"),
|
|
109
|
+
sentBody: t("verifiedBody"),
|
|
110
|
+
backToSignIn: t("backToSignIn"),
|
|
111
|
+
};
|
|
112
|
+
return (
|
|
113
|
+
<div className="flex flex-col gap-4" data-testid="verify-email-page">
|
|
114
|
+
<div data-testid="verify-email-confirmed">
|
|
115
|
+
<AuthCard logo={siteLogo()} intent="sent" signInHref={signInHref} labels={labels} />
|
|
116
|
+
</div>
|
|
117
|
+
</div>
|
|
118
|
+
);
|
|
119
|
+
}
|
|
55
120
|
|
|
56
121
|
if (error) {
|
|
57
122
|
const labels: AuthCardLabels = {
|
|
@@ -124,6 +124,13 @@ jest.mock("@working-theory/api-client", () => ({
|
|
|
124
124
|
messages: (...args: unknown[]) => mockMemberRead(...args),
|
|
125
125
|
purchases: (...args: unknown[]) => mockMemberPurchases(...args),
|
|
126
126
|
appointments: (...args: unknown[]) => mockMemberAppointments(...args),
|
|
127
|
+
// #10826 D7 — the user-magnet results read; 404 here (no workspace module).
|
|
128
|
+
results: () =>
|
|
129
|
+
Promise.resolve({
|
|
130
|
+
ok: false,
|
|
131
|
+
status: 404,
|
|
132
|
+
body: { ok: false, error: { code: "not_found", message: "Not found" } },
|
|
133
|
+
}),
|
|
127
134
|
updateProfile: (...args: unknown[]) => mockUpdateProfile(...args),
|
|
128
135
|
requestDeletion: (...args: unknown[]) => mockRequestDeletion(...args),
|
|
129
136
|
// #8217 — only the rendered billing action reads it; billing-source.ts never does.
|
|
@@ -72,6 +72,13 @@ jest.mock("@working-theory/api-client", () => ({
|
|
|
72
72
|
messages: (...args: unknown[]) => mockMemberMessages(...args),
|
|
73
73
|
purchases: (...args: unknown[]) => mockMemberPurchases(...args),
|
|
74
74
|
appointments: (...args: unknown[]) => mockMemberAppointments(...args),
|
|
75
|
+
// #10826 D7 — the user-magnet results read; 404 here (no workspace module).
|
|
76
|
+
results: () =>
|
|
77
|
+
Promise.resolve({
|
|
78
|
+
ok: false,
|
|
79
|
+
status: 404,
|
|
80
|
+
body: { ok: false, error: { code: "not_found", message: "Not found" } },
|
|
81
|
+
}),
|
|
75
82
|
meetingTypes: (...args: unknown[]) => mockMemberMeetingTypes(...args),
|
|
76
83
|
requestForm: (...args: unknown[]) => mockMemberRequestForm(...args),
|
|
77
84
|
},
|
|
@@ -100,6 +100,13 @@ jest.mock("@working-theory/api-client", () => ({
|
|
|
100
100
|
messages: (...args: unknown[]) => mockMemberMessages(...args),
|
|
101
101
|
purchases: (...args: unknown[]) => mockMemberPurchases(...args),
|
|
102
102
|
appointments: (...args: unknown[]) => mockMemberAppointments(...args),
|
|
103
|
+
// #10826 D7 — the user-magnet results read; 404 here (no workspace module).
|
|
104
|
+
results: () =>
|
|
105
|
+
Promise.resolve({
|
|
106
|
+
ok: false,
|
|
107
|
+
status: 404,
|
|
108
|
+
body: { ok: false, error: { code: "not_found", message: "Not found" } },
|
|
109
|
+
}),
|
|
103
110
|
// #8765 D8 — the retired card's read; the page must not depend on it.
|
|
104
111
|
consents: (...args: unknown[]) => mockMemberConsents(...args),
|
|
105
112
|
// #8233 C4 — the New menu's availability reads; 404 here, so the Inbox
|
|
@@ -935,6 +935,27 @@ describe("captureLeadAction — a checkout magnet answers the Offerings buy rout
|
|
|
935
935
|
},
|
|
936
936
|
);
|
|
937
937
|
|
|
938
|
+
it("a stored lookup key is the key itself, never `<key>_monthly` (#10823)", async () => {
|
|
939
|
+
answers({ completion: "checkout", checkoutOffering: "growth-ops-growth_yearly" });
|
|
940
|
+
shows({ status: "shown", shownSet: shownSet(["monthly", "yearly"], "growth-ops-growth") });
|
|
941
|
+
|
|
942
|
+
expect(await captureLeadAction(INITIAL_STATE, makeFormData(VALID_FIELDS))).toStrictEqual({
|
|
943
|
+
kind: "success",
|
|
944
|
+
name: "Jane Smith",
|
|
945
|
+
redirect: "/api/offerings/checkout/growth-ops-growth_yearly",
|
|
946
|
+
});
|
|
947
|
+
});
|
|
948
|
+
|
|
949
|
+
it("a stored lookup key the shown set does not show → exactly { kind: success } (#10823)", async () => {
|
|
950
|
+
answers({ completion: "checkout", checkoutOffering: "growth-ops-growth_once" });
|
|
951
|
+
shows({ status: "shown", shownSet: shownSet(["monthly", "yearly"], "growth-ops-growth") });
|
|
952
|
+
|
|
953
|
+
expect(await captureLeadAction(INITIAL_STATE, makeFormData(VALID_FIELDS))).toStrictEqual({
|
|
954
|
+
kind: "success",
|
|
955
|
+
name: expect.any(String),
|
|
956
|
+
});
|
|
957
|
+
});
|
|
958
|
+
|
|
938
959
|
it.each([
|
|
939
960
|
["a plan the shown set does not show", () => shows({ status: "shown", shownSet: shownSet(["monthly"], "growth") })],
|
|
940
961
|
["an unconnected site", () => shows({ status: "unconnected" })],
|
|
@@ -100,13 +100,15 @@
|
|
|
100
100
|
* (#9142). The form hard-navigates there (`LeadCaptureForm`'s `redirect`),
|
|
101
101
|
* because the route starts a session only for a top-level navigation and a
|
|
102
102
|
* Server Action `redirect()` is fetched as RSC, which it sends to `/pricing`.
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
103
|
+
* A stored value `parseLookupKey` accepts (`growth-ops-growth_monthly`,
|
|
104
|
+
* #10823) is the key itself. Otherwise it is a `{plan}`, and the key is the
|
|
105
|
+
* one that plan's `/pricing` card links first: the first of `<plan>_monthly`,
|
|
106
|
+
* `<plan>_yearly` and `<plan>_once` the shown set shows. Either way the key
|
|
107
|
+
* must be in the shown set, read through
|
|
106
108
|
* `offerings.shown()` within 5 seconds and shared per instance for 15, as
|
|
107
109
|
* the buy route reads it. It runs only after the write resolved `ok`. The
|
|
108
110
|
* value is re-checked with `flowCheckoutOfferingSchema` first; one that
|
|
109
|
-
* fails, a plan the shown set does not show, or a read that fails or times
|
|
111
|
+
* fails, a key or plan the shown set does not show, or a read that fails or times
|
|
110
112
|
* out answers `{ kind: "success" }`, as `lead` does.
|
|
111
113
|
* A failed write never answers the buy route.
|
|
112
114
|
*/
|
|
@@ -118,6 +120,7 @@ import {
|
|
|
118
120
|
flowCheckoutOfferingSchema,
|
|
119
121
|
leadSubmitNextSchema,
|
|
120
122
|
LOOKUP_KEY_PERIODS,
|
|
123
|
+
parseLookupKey,
|
|
121
124
|
} from "@working-theory/validation";
|
|
122
125
|
import { cookies, headers } from "next/headers";
|
|
123
126
|
import { getLocale, getTranslations } from "next-intl/server";
|
|
@@ -247,8 +250,9 @@ function sharedShownSet(): Promise<unknown> {
|
|
|
247
250
|
}
|
|
248
251
|
|
|
249
252
|
/**
|
|
250
|
-
* #8757 D11, #9171 — the Offerings buy route for the
|
|
251
|
-
* names:
|
|
253
|
+
* #8757 D11, #9171 — the Offerings buy route for the offering a `checkout`
|
|
254
|
+
* answer names: the stored lookup key when it is one and shown (#10823), else
|
|
255
|
+
* the plan's first shown key in `/pricing`'s card order; else `null`.
|
|
252
256
|
*/
|
|
253
257
|
async function checkoutHrefOf(next: unknown): Promise<string | null> {
|
|
254
258
|
const parsed = leadSubmitNextSchema.safeParse(next);
|
|
@@ -256,9 +260,11 @@ async function checkoutHrefOf(next: unknown): Promise<string | null> {
|
|
|
256
260
|
const plan = flowCheckoutOfferingSchema.safeParse(parsed.data.checkoutOffering);
|
|
257
261
|
if (!plan.success) return null;
|
|
258
262
|
const shownSet = await sharedShownSet();
|
|
259
|
-
const
|
|
260
|
-
|
|
261
|
-
|
|
263
|
+
const candidates =
|
|
264
|
+
parseLookupKey(plan.data) === null
|
|
265
|
+
? LOOKUP_KEY_PERIODS.map((period) => `${plan.data}_${period}`)
|
|
266
|
+
: [plan.data];
|
|
267
|
+
const key = candidates.find((k) => isShownLookupKey(shownSet, k));
|
|
262
268
|
return key === undefined ? null : offeringsCheckoutHref(key);
|
|
263
269
|
}
|
|
264
270
|
|