create-ailk 0.34.1 → 0.36.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 +1 -1
- package/component-catalog.json +37 -4
- package/component-catalog.md +11 -9
- 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/lib/env-catalog.js +8 -0
- 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 +32 -3
- package/dist/template-record.js +2 -0
- package/dist/topology.d.ts +4 -4
- package/dist/topology.js +104 -60
- package/dist/update.js +11 -0
- package/package.json +3 -3
- package/templates/.env.example +21 -0
- package/templates/apps/api/.env.example +7 -0
- package/templates/apps/api/CLAUDE.md +14 -9
- package/templates/apps/mcp/CLAUDE.md +18 -7
- package/templates/apps/web/.env.example +16 -0
- package/templates/apps/web/CLAUDE.md +46 -5
- package/templates/apps/web/app/[locale]/(auth)/__tests__/password-reset.test.tsx +2 -0
- package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/page.test.tsx +52 -1
- package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/remembered-method.test.ts +43 -0
- package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/sign-in-card.test.tsx +108 -1
- package/templates/apps/web/app/[locale]/(auth)/sign-in/page.tsx +36 -3
- package/templates/apps/web/app/[locale]/(auth)/sign-in/remembered-method.ts +37 -0
- package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-card.tsx +90 -33
- package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-text.ts +9 -4
- package/templates/apps/web/app/[locale]/(authed)/__tests__/gate.test.tsx +79 -348
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/billing.test.tsx +12 -1
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/hub-mode.test.tsx +55 -2
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/item.test.tsx +43 -0
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout-sign-out.test.tsx +10 -5
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/page.test.tsx +6 -5
- package/templates/apps/web/app/[locale]/(authed)/account/account-frame.tsx +1 -1
- package/templates/apps/web/app/[locale]/(authed)/account/billing/page.tsx +60 -6
- package/templates/apps/web/app/[locale]/(authed)/account/billing-source.ts +32 -3
- package/templates/apps/web/app/[locale]/(authed)/account/connect/__tests__/page.test.tsx +8 -1
- package/templates/apps/web/app/[locale]/(authed)/account/connect/page.tsx +7 -3
- package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/phone-verification.test.tsx +215 -0
- package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/seam-imports.test.ts +65 -0
- package/templates/apps/web/app/[locale]/(authed)/account/general/page.tsx +47 -0
- package/templates/apps/web/app/[locale]/(authed)/account/general/phone-actions.ts +122 -0
- package/templates/apps/web/app/[locale]/(authed)/account/general/phone-verification.tsx +214 -0
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/[kind]/[id]/page.tsx +6 -1
- package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/invitation-id.test.ts +35 -0
- package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/page.test.tsx +266 -0
- package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/actions.ts +116 -0
- package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/invitation-id.ts +12 -0
- package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/page.tsx +154 -0
- package/templates/apps/web/app/[locale]/(authed)/account/layout.tsx +6 -4
- package/templates/apps/web/app/[locale]/(authed)/account/security/page.tsx +3 -1
- package/templates/apps/web/app/[locale]/(authed)/layout.tsx +15 -13
- package/templates/apps/web/app/[locale]/(authed)/signed-out-gate.generated.tsx +20 -52
- 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 +42 -76
- package/templates/apps/web/app/[locale]/purchase/__tests__/success.test.tsx +50 -0
- package/templates/apps/web/app/[locale]/purchase/success/page.tsx +48 -7
- package/templates/apps/web/app/api/auth/hub/__tests__/entry-routes.test.ts +749 -0
- package/templates/apps/web/app/api/auth/hub/authorize/__tests__/route.test.ts +189 -6
- package/templates/apps/web/app/api/auth/hub/authorize/route.ts +101 -31
- package/templates/apps/web/app/api/auth/hub/continuation.ts +51 -2
- package/templates/apps/web/app/api/auth/hub/email/route.ts +111 -0
- package/templates/apps/web/app/api/auth/hub/entry-shared.ts +163 -0
- package/templates/apps/web/app/api/auth/hub/purchase/route.ts +230 -0
- package/templates/apps/web/app/api/auth/hub/purchase-link/route.ts +174 -0
- package/templates/apps/web/app/api/auth/hub/sign-up/route.ts +60 -0
- package/templates/apps/web/app/api/auth/hub/sign-up-evidence.ts +97 -0
- package/templates/apps/web/app/api/hub-session/__tests__/routes.test.ts +475 -7
- package/templates/apps/web/app/api/hub-session/callback/route.ts +13 -47
- package/templates/apps/web/app/api/hub-session/email/route.ts +125 -0
- package/templates/apps/web/app/api/hub-session/one-tap/nonce/route.ts +49 -0
- package/templates/apps/web/app/api/hub-session/one-tap/route.ts +106 -0
- package/templates/apps/web/app/api/hub-session/open/route.ts +111 -0
- package/templates/apps/web/app/api/hub-session/sign-in/route.ts +23 -40
- package/templates/apps/web/app/api/hub-session/sign-out/route.ts +1 -10
- 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/auth.ts +133 -6
- package/templates/apps/web/components/sign-out-trigger.tsx +1 -1
- package/templates/apps/web/lib/__tests__/auth-email.test.ts +141 -0
- package/templates/apps/web/lib/__tests__/auth-phone.test.ts +445 -0
- package/templates/apps/web/lib/__tests__/auth-sms.test.ts +140 -0
- package/templates/apps/web/lib/__tests__/fixtures/tsconfig.flow.json +18 -0
- package/templates/apps/web/lib/__tests__/site-header.test.ts +13 -0
- package/templates/apps/web/lib/__tests__/telemetry-scrub.test.ts +19 -1
- package/templates/apps/web/lib/account-config.ts +24 -9
- package/templates/apps/web/lib/auth-email.ts +62 -6
- package/templates/apps/web/lib/auth-env.ts +13 -0
- package/templates/apps/web/lib/auth-sms.ts +180 -0
- package/templates/apps/web/lib/hub-session/__tests__/hub-session.test.ts +28 -0
- package/templates/apps/web/lib/hub-session/__tests__/spoke-sign-in.test.tsx +332 -0
- package/templates/apps/web/lib/hub-session/config.ts +7 -1
- package/templates/apps/web/lib/hub-session/entry.ts +238 -0
- package/templates/apps/web/lib/hub-session/index.ts +1 -4
- package/templates/apps/web/lib/hub-session/one-tap.tsx +148 -0
- package/templates/apps/web/lib/hub-session/session.ts +120 -2
- package/templates/apps/web/lib/hub-session/spoke-sign-in.tsx +277 -0
- package/templates/apps/web/lib/site-header.ts +14 -1
- package/templates/apps/web/lib/site-listing.ts +7 -0
- package/templates/apps/web/lib/telemetry-scrub.ts +11 -0
- package/templates/apps/web/lib/topology.generated.ts +39 -0
- package/templates/apps/web/messages/en.json +125 -21
- package/templates/apps/web/middleware.ts +34 -2
- package/templates/apps/web/security-headers.config.ts +21 -0
- package/versions.json +47 -47
- package/templates/apps/web/app/[locale]/(authed)/sign-in-gate.tsx +0 -162
- package/templates/apps/web/components/signed-in-nav.tsx +0 -79
- package/templates/apps/web/lib/hub-session/__tests__/sign-in-gate.test.tsx +0 -180
- package/templates/apps/web/lib/hub-session/sign-in-gate.tsx +0 -162
|
@@ -169,6 +169,49 @@ describe("one Inbox item", () => {
|
|
|
169
169
|
});
|
|
170
170
|
});
|
|
171
171
|
|
|
172
|
+
describe("#11007 AC-3a-9 — a message renders through the chat layout", () => {
|
|
173
|
+
it("the message is a start-side MessageBubble under RecordHeader, captioned with when it was sent", async () => {
|
|
174
|
+
await renderItem("message", "int_plain");
|
|
175
|
+
const frame = screen.getByTestId("account-item");
|
|
176
|
+
const header = within(frame).getByTestId("account-item-header");
|
|
177
|
+
expect(within(header).getByRole("heading", { level: 1 })).toHaveTextContent("Hello");
|
|
178
|
+
const back = within(header).getByTestId("account-item-back");
|
|
179
|
+
expect(back).toHaveAttribute("href", "/account");
|
|
180
|
+
expect(back).toHaveAttribute("data-back-link");
|
|
181
|
+
expect(back).toHaveAccessibleName("Inbox");
|
|
182
|
+
|
|
183
|
+
const conversation = within(frame).getByTestId("account-item-conversation");
|
|
184
|
+
const bubble = within(conversation).getByTestId("account-item-message");
|
|
185
|
+
expect(bubble).toHaveAttribute("data-side", "start");
|
|
186
|
+
expect(bubble).toHaveTextContent("A note.");
|
|
187
|
+
// The caption is from the account messages: "Sent · <when>".
|
|
188
|
+
expect(bubble).toHaveTextContent(/^Sent · /);
|
|
189
|
+
// No stacked head card or fields list.
|
|
190
|
+
expect(screen.queryByTestId("account-item-fields")).not.toBeInTheDocument();
|
|
191
|
+
expect(screen.queryByText("My messages")).not.toBeInTheDocument();
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it("an attached file is the bubble's note, from the account messages", async () => {
|
|
195
|
+
mockMemberMessages.mockResolvedValue({
|
|
196
|
+
ok: true,
|
|
197
|
+
body: { items: [{ ...MESSAGE, file: { filename: "plan.pdf" } }] },
|
|
198
|
+
});
|
|
199
|
+
await renderItem("message", "int_plain");
|
|
200
|
+
expect(screen.getByTestId("account-item-message")).toHaveTextContent("File · plan.pdf");
|
|
201
|
+
expect(screen.getByTestId("account-item-action-file-desk")).toHaveTextContent(
|
|
202
|
+
"Download plan.pdf",
|
|
203
|
+
);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it("the purchase kind keeps its stacked layout and fields", async () => {
|
|
207
|
+
await renderItem("purchase", "fc_done");
|
|
208
|
+
expect(screen.queryByTestId("account-item-header")).not.toBeInTheDocument();
|
|
209
|
+
expect(screen.queryByTestId("account-item-conversation")).not.toBeInTheDocument();
|
|
210
|
+
expect(screen.getByTestId("account-item-fields")).toBeInTheDocument();
|
|
211
|
+
expect(screen.getByTestId("account-item-back")).toHaveAttribute("data-back-link");
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
|
|
172
215
|
describe("a message's onboarding action (#8515 D6, AC-4)", () => {
|
|
173
216
|
it("an onboarding message links to the locale's onboarding page", async () => {
|
|
174
217
|
await renderItem("message", "int_onboarding", "fr");
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The account layout hands the generated seam's sign-out wiring to the client
|
|
3
3
|
* frame (#8465): a client component cannot import `topology.generated.ts`, so
|
|
4
|
-
* the server layout reads `SIGN_OUT_ENDPOINT`
|
|
5
|
-
*
|
|
4
|
+
* the server layout reads `SIGN_OUT_ENDPOINT` and passes it, with the home as
|
|
5
|
+
* the landing after a sign-out (#11095 D4), as props. Also pins that the Help center
|
|
6
6
|
* href is rendered only for an https URL (the #8467 review's Low finding).
|
|
7
7
|
*/
|
|
8
8
|
import { render } from "@testing-library/react";
|
|
9
|
+
import { localeHref } from "@working-theory/ui";
|
|
9
10
|
import type { ReactElement } from "react";
|
|
10
11
|
|
|
11
12
|
jest.mock("next-intl/server", () => ({
|
|
@@ -103,17 +104,21 @@ afterEach(() => {
|
|
|
103
104
|
});
|
|
104
105
|
|
|
105
106
|
describe("sign-out wiring (#8465)", () => {
|
|
106
|
-
|
|
107
|
+
// #11095 D4 — the spoke's /account redirects into the hub sign-in, which
|
|
108
|
+
// signs the person straight back in while their hub session lives, so a
|
|
109
|
+
// hub-session sign-out lands on the localized home.
|
|
110
|
+
it("passes the endpoint and the localized home on a hub sign-in spoke", async () => {
|
|
107
111
|
mockSeam = {
|
|
108
112
|
SIGN_IN_PATH: "/account",
|
|
109
113
|
SIGN_OUT_ENDPOINT: "/api/hub-session/sign-out",
|
|
110
114
|
};
|
|
111
115
|
const props = await renderLayout("fr");
|
|
112
116
|
expect(props.signOutEndpoint).toBe("/api/hub-session/sign-out");
|
|
113
|
-
expect(props.signInHref).toBe("
|
|
117
|
+
expect(props.signInHref).toBe(localeHref("fr", "/"));
|
|
118
|
+
expect(props.signInHref).not.toMatch(/account/);
|
|
114
119
|
});
|
|
115
120
|
|
|
116
|
-
it("
|
|
121
|
+
it("lands on the home when the seam names no sign-in path too", async () => {
|
|
117
122
|
mockSeam = {
|
|
118
123
|
SIGN_IN_PATH: null,
|
|
119
124
|
SIGN_OUT_ENDPOINT: "/api/hub-session/sign-out",
|
|
@@ -956,10 +956,10 @@ describe("the member kinds — piece and message (#7920, spec 7423 D8 · D12)",
|
|
|
956
956
|
href: `/account/inbox/message/${MESSAGE_WITH_FILE.id}/file`,
|
|
957
957
|
},
|
|
958
958
|
]);
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
959
|
+
// #11007 — the message renders as a chat bubble; its file is the bubble's note.
|
|
960
|
+
expect(detail.fields).toBeUndefined();
|
|
961
|
+
render(<>{detail.body}</>);
|
|
962
|
+
expect(screen.getByTestId("account-item-message")).toHaveTextContent("File · brand-guide.pdf");
|
|
963
963
|
});
|
|
964
964
|
|
|
965
965
|
it("the file action carries the locale prefix off the default locale", async () => {
|
|
@@ -976,7 +976,8 @@ describe("the member kinds — piece and message (#7920, spec 7423 D8 · D12)",
|
|
|
976
976
|
const [plain] = await kindOf("message").load(ctx);
|
|
977
977
|
const detail = kindOf("message").renderDetail(plain!, ctx);
|
|
978
978
|
expect(detail.actions).toBeUndefined();
|
|
979
|
-
|
|
979
|
+
render(<>{detail.body}</>);
|
|
980
|
+
expect(screen.getByTestId("account-item-message")).not.toHaveTextContent("File ·");
|
|
980
981
|
});
|
|
981
982
|
});
|
|
982
983
|
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* logo and the For-you items; this component wires them to the shell with
|
|
7
7
|
* what only the client has: the current path and the sign-out call.
|
|
8
8
|
*
|
|
9
|
-
* `createAuthClient()` at module scope is the `
|
|
9
|
+
* `createAuthClient()` at module scope is the `(auth)` cards' idiom. Log
|
|
10
10
|
* out ends the session, then navigates and refreshes so every RSC under the
|
|
11
11
|
* `(authed)` gate re-reads the (now absent) session.
|
|
12
12
|
*
|
|
@@ -18,13 +18,16 @@
|
|
|
18
18
|
* have no subscription".
|
|
19
19
|
*
|
|
20
20
|
* After any of the three, one plain line when some of the member's billing
|
|
21
|
-
* is on a Stripe account this spoke's key cannot read (#8217 D12)
|
|
22
|
-
*
|
|
23
|
-
*
|
|
21
|
+
* is on a Stripe account this spoke's key cannot read (#8217 D12); on a spoke
|
|
22
|
+
* that signs in through its hub, the member's Purchases (`loadPurchases()`,
|
|
23
|
+
* #11096 D9: offering, amount, date; nothing when there are none, the error
|
|
24
|
+
* row when the read fails); then each section a module contributes
|
|
25
|
+
* (`accountBillingSections`, #8231 D4), then each section the site adds
|
|
26
|
+
* (`siteBillingSections`, #9401 D7).
|
|
24
27
|
*/
|
|
25
28
|
|
|
26
29
|
import { AccountSettingsFrame, AccountSettingsPane, CurrentPlanCard } from "@working-theory/templates/account";
|
|
27
|
-
import { Button, Text } from "@working-theory/ui/primitives";
|
|
30
|
+
import { Button, MoneyAmount, Text } from "@working-theory/ui/primitives";
|
|
28
31
|
import type { Metadata } from "next";
|
|
29
32
|
import { getTranslations } from "next-intl/server";
|
|
30
33
|
import type { ReactElement } from "react";
|
|
@@ -33,7 +36,7 @@ import { accountBillingSections } from "../../../../../lib/account-config";
|
|
|
33
36
|
import { siteBillingSections } from "../../../../../lib/site-contributions";
|
|
34
37
|
import { accountSession } from "../account-data";
|
|
35
38
|
import { openBillingPortal } from "../actions";
|
|
36
|
-
import { type BillingState, loadBilling } from "../billing-source";
|
|
39
|
+
import { type BillingState, type PurchasesState, loadBilling, loadPurchases } from "../billing-source";
|
|
37
40
|
import { ErrorRow } from "../error-row";
|
|
38
41
|
import { memberSettingsFrame, SettingsSection, type Translate as MemberTranslate } from "../settings-frame";
|
|
39
42
|
|
|
@@ -113,6 +116,55 @@ function Subscription({
|
|
|
113
116
|
);
|
|
114
117
|
}
|
|
115
118
|
|
|
119
|
+
/** The member's purchases (#11096 D9): one row each — offering, amount, date. */
|
|
120
|
+
function Purchases({
|
|
121
|
+
state,
|
|
122
|
+
locale,
|
|
123
|
+
t,
|
|
124
|
+
}: {
|
|
125
|
+
state: PurchasesState;
|
|
126
|
+
locale: string;
|
|
127
|
+
t: Translate;
|
|
128
|
+
}): ReactElement | null {
|
|
129
|
+
if (state.kind === "failed") {
|
|
130
|
+
return (
|
|
131
|
+
<div data-testid="account-billing-purchases-error">
|
|
132
|
+
<ErrorRow message={t("billing.purchasesUnavailable")} retryLabel={t("inbox.retry")} />
|
|
133
|
+
</div>
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
if (state.items.length === 0) return null;
|
|
137
|
+
const date = new Intl.DateTimeFormat(locale, { dateStyle: "medium" });
|
|
138
|
+
return (
|
|
139
|
+
<div data-testid="account-billing-purchases">
|
|
140
|
+
<SettingsSection id="purchases" title={t("billing.purchases")}>
|
|
141
|
+
<div className="flex flex-col divide-y divide-(--color-border)">
|
|
142
|
+
{state.items.map((purchase) => (
|
|
143
|
+
<div
|
|
144
|
+
key={purchase.id}
|
|
145
|
+
className="flex flex-wrap items-baseline justify-between gap-2 py-3"
|
|
146
|
+
data-testid="account-billing-purchase"
|
|
147
|
+
>
|
|
148
|
+
<Text as="span" variant="body-sm" className="font-medium">
|
|
149
|
+
{purchase.offering}
|
|
150
|
+
</Text>
|
|
151
|
+
<Text as="span" variant="body-sm" tone="muted">
|
|
152
|
+
{purchase.amountMinor !== null && purchase.currency !== null ? (
|
|
153
|
+
<>
|
|
154
|
+
<MoneyAmount amountMinor={purchase.amountMinor} currency={purchase.currency} locale={locale} />
|
|
155
|
+
{" · "}
|
|
156
|
+
</>
|
|
157
|
+
) : null}
|
|
158
|
+
{date.format(new Date(purchase.purchasedAt))}
|
|
159
|
+
</Text>
|
|
160
|
+
</div>
|
|
161
|
+
))}
|
|
162
|
+
</div>
|
|
163
|
+
</SettingsSection>
|
|
164
|
+
</div>
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
|
|
116
168
|
export default async function AccountBillingPage({ params }: Props): Promise<ReactElement> {
|
|
117
169
|
const { locale } = await params;
|
|
118
170
|
const t = await getTranslations({ locale, namespace: "account" });
|
|
@@ -132,7 +184,7 @@ export default async function AccountBillingPage({ params }: Props): Promise<Rea
|
|
|
132
184
|
}
|
|
133
185
|
|
|
134
186
|
const { ctx } = session;
|
|
135
|
-
const state = await loadBilling(ctx.init);
|
|
187
|
+
const [state, purchases] = await Promise.all([loadBilling(ctx.init), loadPurchases(ctx.init)]);
|
|
136
188
|
const name = ctx.user.name || ctx.user.email;
|
|
137
189
|
|
|
138
190
|
return (
|
|
@@ -163,6 +215,8 @@ export default async function AccountBillingPage({ params }: Props): Promise<Rea
|
|
|
163
215
|
</div>
|
|
164
216
|
) : null}
|
|
165
217
|
|
|
218
|
+
{purchases !== null ? <Purchases state={purchases} locale={locale} t={t} /> : null}
|
|
219
|
+
|
|
166
220
|
{[...accountBillingSections, ...siteBillingSections].map((section) => (
|
|
167
221
|
<SettingsSection key={section.id} id={section.id} title={ctx.t(section.title)}>
|
|
168
222
|
{section.render(ctx)}
|
|
@@ -24,6 +24,13 @@
|
|
|
24
24
|
* false "you have no subscription";
|
|
25
25
|
* - otherwise `subscription`, absent optional fields read as `null`.
|
|
26
26
|
*
|
|
27
|
+
* `loadPurchases()` (#11096 D9) is the Purchases list under the plan card, on
|
|
28
|
+
* a spoke that signs in through its hub only: `member.purchases` with the hub
|
|
29
|
+
* credential — the leads of the caller's Person whose email is the caller's
|
|
30
|
+
* verified email, so a purchase link's account finds its purchase. A 401,
|
|
31
|
+
* 403 or 404 (an older hub) is an empty list; any other failure is `failed`.
|
|
32
|
+
* Everywhere else it is `null` and nothing is read.
|
|
33
|
+
*
|
|
27
34
|
* `billingPortalUrl()` is the one place a portal URL is minted, for
|
|
28
35
|
* `openBillingPortal` (`actions.ts`): the spoke's own key through the same
|
|
29
36
|
* loader on a hub-mode spoke, else the hub's portal route. `null` means no
|
|
@@ -31,10 +38,12 @@
|
|
|
31
38
|
*/
|
|
32
39
|
|
|
33
40
|
import {
|
|
41
|
+
member,
|
|
34
42
|
subscription,
|
|
35
43
|
type SubscriptionLifecycleStatus,
|
|
36
44
|
type SubscriptionPaymentMethod,
|
|
37
45
|
} from "@working-theory/api-client";
|
|
46
|
+
import type { MemberPurchase } from "@working-theory/validation";
|
|
38
47
|
|
|
39
48
|
import { forwardedCookieInit } from "../../../../lib/server-api";
|
|
40
49
|
import {
|
|
@@ -59,8 +68,11 @@ export type BillingState =
|
|
|
59
68
|
| { kind: "none"; unreadable: boolean }
|
|
60
69
|
| { kind: "failed" };
|
|
61
70
|
|
|
62
|
-
/**
|
|
63
|
-
|
|
71
|
+
/**
|
|
72
|
+
* The statuses that mean "nothing to show this caller" — no subscription
|
|
73
|
+
* (C9), no purchases (#11096 D9) — rather than a failed read.
|
|
74
|
+
*/
|
|
75
|
+
const NOTHING_TO_SHOW_STATUSES: ReadonlySet<number> = new Set([401, 403, 404]);
|
|
64
76
|
|
|
65
77
|
/** PII-safe error identity for logs (the `checkout.actions.ts` idiom: `err.name` only). */
|
|
66
78
|
function errorName(err: unknown): string {
|
|
@@ -95,7 +107,7 @@ export async function loadBilling(init: { headers: Record<string, string> }): Pr
|
|
|
95
107
|
try {
|
|
96
108
|
const res = await subscription.me(init, { include: "billing" });
|
|
97
109
|
if (!res.ok) {
|
|
98
|
-
if (
|
|
110
|
+
if (NOTHING_TO_SHOW_STATUSES.has(res.status)) return { kind: "none", unreadable: false };
|
|
99
111
|
console.error(`[account] read failed source=billing status=${res.status}`);
|
|
100
112
|
return { kind: "failed" };
|
|
101
113
|
}
|
|
@@ -116,6 +128,23 @@ export async function loadBilling(init: { headers: Record<string, string> }): Pr
|
|
|
116
128
|
}
|
|
117
129
|
}
|
|
118
130
|
|
|
131
|
+
export type PurchasesState = { kind: "items"; items: MemberPurchase[] } | { kind: "failed" };
|
|
132
|
+
|
|
133
|
+
/** The member's purchases on a hub-sign-in spoke, or `null` anywhere else (#11096 D9). */
|
|
134
|
+
export async function loadPurchases(init: { headers: Record<string, string> }): Promise<PurchasesState | null> {
|
|
135
|
+
if (SIGN_IN_PROVIDER !== "hub") return null;
|
|
136
|
+
try {
|
|
137
|
+
const res = await member.purchases(init);
|
|
138
|
+
if (res.ok) return { kind: "items", items: res.body.items };
|
|
139
|
+
if (NOTHING_TO_SHOW_STATUSES.has(res.status)) return { kind: "items", items: [] };
|
|
140
|
+
console.error(`[account] read failed source=purchases status=${res.status}`);
|
|
141
|
+
return { kind: "failed" };
|
|
142
|
+
} catch (err) {
|
|
143
|
+
logReadFailure("purchases", err);
|
|
144
|
+
return { kind: "failed" };
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
119
148
|
/**
|
|
120
149
|
* The caller's Stripe billing-portal URL, or `null` for no portal (#8217
|
|
121
150
|
* D10). Minted on a Manage click, never on render: on a hub-mode spoke from
|
|
@@ -145,7 +145,8 @@ describe("the consent page (#9966 D2, AC-4)", () => {
|
|
|
145
145
|
const fields = Array.from(form.querySelectorAll("input"));
|
|
146
146
|
expect(fields.map((f) => [f.type, f.name, f.value])).toEqual([["hidden", "ref", ref]]);
|
|
147
147
|
expect(screen.getByTestId("hub-connect-continue").textContent).toBe("Continue");
|
|
148
|
-
|
|
148
|
+
// #11095 D5: Cancel goes to the spoke's home, never an /account URL.
|
|
149
|
+
expect(screen.getByTestId("hub-connect-cancel").getAttribute("href")).toBe(`${SPOKE_ORIGIN}/`);
|
|
149
150
|
});
|
|
150
151
|
|
|
151
152
|
it.each([
|
|
@@ -156,6 +157,10 @@ describe("the consent page (#9966 D2, AC-4)", () => {
|
|
|
156
157
|
])("%s renders unavailable and no form", async (_name, ref) => {
|
|
157
158
|
await renderPage(ref());
|
|
158
159
|
expectUnavailable();
|
|
160
|
+
// #11095 D5: with no client read, the back link goes to the hub's home.
|
|
161
|
+
const back = screen.getByTestId("hub-connect-back");
|
|
162
|
+
expect(back.getAttribute("href")).toBe("/");
|
|
163
|
+
expect(back.textContent).toBe("Back to the site");
|
|
159
164
|
});
|
|
160
165
|
|
|
161
166
|
it("a client the registry does not answer for renders unavailable and no form", async () => {
|
|
@@ -175,6 +180,8 @@ describe("the consent page (#9966 D2, AC-4)", () => {
|
|
|
175
180
|
mintContinuation(query({ redirect_uri: "https://other.example.com/api/hub-session/callback" }), mockSecret),
|
|
176
181
|
);
|
|
177
182
|
expectUnavailable();
|
|
183
|
+
// #11095 D5: the client was read, so the back link goes to its home.
|
|
184
|
+
expect(screen.getByTestId("hub-connect-back").getAttribute("href")).toBe(`${SPOKE_ORIGIN}/`);
|
|
178
185
|
});
|
|
179
186
|
|
|
180
187
|
it("generateMetadata keeps the ref out of a cross-site Referer and the page out of the index", async () => {
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
* authorize keys sealed as `ref`. This page opens the ref, names the spoke
|
|
8
8
|
* from the registry (`hubSignIn.clientInfo`) — never from the query — and
|
|
9
9
|
* offers one Continue: a same-origin form POST of `ref` back to the authorize
|
|
10
|
-
* route, which alone sends `consent: true`. Cancel goes to
|
|
10
|
+
* route, which alone sends `consent: true`. Cancel goes to the spoke's home
|
|
11
|
+
* (#11095 D5): its `/account` would start the hub sign-in again.
|
|
11
12
|
*
|
|
12
13
|
* The form renders only when the ref's `redirect_uri` is on the origin the
|
|
13
14
|
* registry names, so the page never names one site while the code goes to
|
|
@@ -116,7 +117,10 @@ export default async function HubConnectPage({ params, searchParams }: Props): P
|
|
|
116
117
|
{t("unavailable.body")}
|
|
117
118
|
</Text>
|
|
118
119
|
</div>
|
|
119
|
-
<Link
|
|
120
|
+
<Link
|
|
121
|
+
href={client ? `${client.origin}/` : localeHref(locale, "/")}
|
|
122
|
+
data-testid="hub-connect-back"
|
|
123
|
+
>
|
|
120
124
|
{t("unavailable.back")}
|
|
121
125
|
</Link>
|
|
122
126
|
</div>
|
|
@@ -143,7 +147,7 @@ export default async function HubConnectPage({ params, searchParams }: Props): P
|
|
|
143
147
|
<Button type="submit" size="big" data-testid="hub-connect-continue">
|
|
144
148
|
{t("continue")}
|
|
145
149
|
</Button>
|
|
146
|
-
<Link href={
|
|
150
|
+
<Link href={`${client.origin}/`} data-testid="hub-connect-cancel">
|
|
147
151
|
{t("cancel")}
|
|
148
152
|
</Link>
|
|
149
153
|
</form>
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Account page's phone step (#11106, spec
|
|
3
|
+
* docs/specs/11106-the-workforce-foundation-roles-by-spec.md D9; AC-6's
|
|
4
|
+
* "a user sets and verifies a phone in the hub's Account settings").
|
|
5
|
+
*
|
|
6
|
+
* - the island: send a code, then verify it; a verified number shows with
|
|
7
|
+
* "Verified" and Remove; a refusal shows its line; a build without the
|
|
8
|
+
* step, or an unverified email, shows its line and no form;
|
|
9
|
+
* - the server actions: each is a SERVER call on the plugin with the
|
|
10
|
+
* request's headers, `verifyPhoneCode` always with `updatePhoneNumber:
|
|
11
|
+
* true`, Remove writes `phoneNumber: null`, a refusal maps to its reason,
|
|
12
|
+
* a build without the step answers `unavailable` with no call, and no log
|
|
13
|
+
* line carries the number or the code.
|
|
14
|
+
*/
|
|
15
|
+
import { act, fireEvent, render, screen } from "@testing-library/react";
|
|
16
|
+
|
|
17
|
+
const mockSendOtp = jest.fn();
|
|
18
|
+
const mockVerify = jest.fn();
|
|
19
|
+
const mockUpdateUser = jest.fn();
|
|
20
|
+
const mockPhoneStepActive = jest.fn();
|
|
21
|
+
// eslint-disable-next-line no-restricted-syntax -- #507: auth.ts is Better Auth's server singleton (a DB/HTTP boundary); its phone endpoints are the actions' one dependency.
|
|
22
|
+
jest.mock("../../../../../../auth", () => ({
|
|
23
|
+
__esModule: true,
|
|
24
|
+
phoneStepActive: () => mockPhoneStepActive(),
|
|
25
|
+
auth: {
|
|
26
|
+
api: {
|
|
27
|
+
sendPhoneNumberOTP: (...args: unknown[]) => mockSendOtp(...args),
|
|
28
|
+
verifyPhoneNumber: (...args: unknown[]) => mockVerify(...args),
|
|
29
|
+
updateUser: (...args: unknown[]) => mockUpdateUser(...args),
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
}));
|
|
33
|
+
|
|
34
|
+
const REQUEST_HEADERS = new Headers({ cookie: "better-auth.session_token=abc" });
|
|
35
|
+
jest.mock("next/headers", () => ({
|
|
36
|
+
__esModule: true,
|
|
37
|
+
headers: jest.fn(async () => REQUEST_HEADERS),
|
|
38
|
+
}));
|
|
39
|
+
|
|
40
|
+
const mockRefresh = jest.fn();
|
|
41
|
+
jest.mock("next/navigation", () => ({
|
|
42
|
+
__esModule: true,
|
|
43
|
+
useRouter: () => ({ refresh: mockRefresh }),
|
|
44
|
+
}));
|
|
45
|
+
|
|
46
|
+
import { removePhone, sendPhoneCode, verifyPhoneCode } from "../phone-actions";
|
|
47
|
+
import { PhoneVerification, type PhoneVerificationLabels } from "../phone-verification";
|
|
48
|
+
|
|
49
|
+
const NUMBER = "+15555550123";
|
|
50
|
+
const CODE = "482913";
|
|
51
|
+
|
|
52
|
+
const LABELS: PhoneVerificationLabels = {
|
|
53
|
+
title: "Phone",
|
|
54
|
+
lead: "Only you can set it.",
|
|
55
|
+
number: "Mobile number",
|
|
56
|
+
numberHint: "Include the country code.",
|
|
57
|
+
sendCode: "Send code",
|
|
58
|
+
sending: "Sending…",
|
|
59
|
+
code: "Code",
|
|
60
|
+
codeHint: "Six digits.",
|
|
61
|
+
verify: "Verify",
|
|
62
|
+
verifying: "Verifying…",
|
|
63
|
+
verified: "Verified",
|
|
64
|
+
remove: "Remove",
|
|
65
|
+
sent: "We texted you a code.",
|
|
66
|
+
unavailable: "Phone verification isn't available on this site.",
|
|
67
|
+
unverifiedEmail: "Confirm your email address first.",
|
|
68
|
+
errors: {
|
|
69
|
+
invalid_number: "Bad number.",
|
|
70
|
+
invalid_code: "Bad code.",
|
|
71
|
+
taken: "Taken.",
|
|
72
|
+
too_many: "Too many.",
|
|
73
|
+
unverified: "Unverified.",
|
|
74
|
+
signed_out: "Signed out.",
|
|
75
|
+
unavailable: "Unavailable.",
|
|
76
|
+
failed: "Failed.",
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const apiError = (code: string) => Object.assign(new Error(code), { body: { code } });
|
|
81
|
+
|
|
82
|
+
let logLines: string[] = [];
|
|
83
|
+
beforeEach(() => {
|
|
84
|
+
jest.clearAllMocks();
|
|
85
|
+
mockPhoneStepActive.mockReturnValue(true);
|
|
86
|
+
mockSendOtp.mockResolvedValue({ message: "code sent" });
|
|
87
|
+
mockVerify.mockResolvedValue({ status: true });
|
|
88
|
+
mockUpdateUser.mockResolvedValue({ status: true });
|
|
89
|
+
logLines = [];
|
|
90
|
+
jest.spyOn(console, "error").mockImplementation((...args: unknown[]) => {
|
|
91
|
+
logLines.push(args.map(String).join(" "));
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
afterEach(() => {
|
|
96
|
+
jest.restoreAllMocks();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
describe("the island", () => {
|
|
100
|
+
it("sends a code, then verifies it, and refreshes the page", async () => {
|
|
101
|
+
render(<PhoneVerification available emailVerified phone={null} labels={LABELS} />);
|
|
102
|
+
fireEvent.change(screen.getByTestId("account-phone-number-input"), { target: { value: NUMBER } });
|
|
103
|
+
await act(async () => {
|
|
104
|
+
fireEvent.click(screen.getByTestId("account-phone-send"));
|
|
105
|
+
});
|
|
106
|
+
expect(mockSendOtp).toHaveBeenCalledWith({ body: { phoneNumber: NUMBER }, headers: REQUEST_HEADERS });
|
|
107
|
+
expect(screen.getByTestId("account-phone-sent")).toHaveTextContent(LABELS.sent);
|
|
108
|
+
|
|
109
|
+
fireEvent.change(screen.getByTestId("account-phone-code-input"), { target: { value: CODE } });
|
|
110
|
+
await act(async () => {
|
|
111
|
+
fireEvent.click(screen.getByTestId("account-phone-verify"));
|
|
112
|
+
});
|
|
113
|
+
expect(mockVerify).toHaveBeenCalledWith({
|
|
114
|
+
body: { phoneNumber: NUMBER, code: CODE, updatePhoneNumber: true },
|
|
115
|
+
headers: REQUEST_HEADERS,
|
|
116
|
+
});
|
|
117
|
+
expect(mockRefresh).toHaveBeenCalledTimes(1);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("a refused code shows its line and refreshes nothing", async () => {
|
|
121
|
+
mockVerify.mockRejectedValue(apiError("INVALID_OTP"));
|
|
122
|
+
render(<PhoneVerification available emailVerified phone={null} labels={LABELS} />);
|
|
123
|
+
fireEvent.change(screen.getByTestId("account-phone-number-input"), { target: { value: NUMBER } });
|
|
124
|
+
await act(async () => {
|
|
125
|
+
fireEvent.click(screen.getByTestId("account-phone-send"));
|
|
126
|
+
});
|
|
127
|
+
fireEvent.change(screen.getByTestId("account-phone-code-input"), { target: { value: CODE } });
|
|
128
|
+
await act(async () => {
|
|
129
|
+
fireEvent.click(screen.getByTestId("account-phone-verify"));
|
|
130
|
+
});
|
|
131
|
+
expect(screen.getByTestId("account-phone-error")).toHaveTextContent(LABELS.errors.invalid_code);
|
|
132
|
+
expect(mockRefresh).not.toHaveBeenCalled();
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it("a verified number shows with Verified and Remove, which clears it", async () => {
|
|
136
|
+
render(
|
|
137
|
+
<PhoneVerification available emailVerified phone={{ number: NUMBER, verified: true }} labels={LABELS} />,
|
|
138
|
+
);
|
|
139
|
+
expect(screen.getByTestId("account-phone-number")).toHaveTextContent(NUMBER);
|
|
140
|
+
expect(screen.getByTestId("account-phone-verified")).toHaveTextContent(LABELS.verified);
|
|
141
|
+
expect(screen.queryByTestId("account-phone-number-input")).toBeNull();
|
|
142
|
+
await act(async () => {
|
|
143
|
+
fireEvent.click(screen.getByTestId("account-phone-remove"));
|
|
144
|
+
});
|
|
145
|
+
expect(mockUpdateUser).toHaveBeenCalledWith({ body: { phoneNumber: null }, headers: REQUEST_HEADERS });
|
|
146
|
+
expect(mockRefresh).toHaveBeenCalledTimes(1);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("a build without the step shows the not-available line and no form", () => {
|
|
150
|
+
render(<PhoneVerification available={false} emailVerified phone={null} labels={LABELS} />);
|
|
151
|
+
expect(screen.getByTestId("account-phone-unavailable")).toHaveTextContent(LABELS.unavailable);
|
|
152
|
+
expect(screen.queryByTestId("account-phone-send-form")).toBeNull();
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it("an unverified email shows the confirm-email line and no form", () => {
|
|
156
|
+
render(<PhoneVerification available emailVerified={false} phone={null} labels={LABELS} />);
|
|
157
|
+
expect(screen.getByTestId("account-phone-unverified-email")).toHaveTextContent(LABELS.unverifiedEmail);
|
|
158
|
+
expect(screen.queryByTestId("account-phone-send-form")).toBeNull();
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
describe("the server actions", () => {
|
|
163
|
+
it.each([
|
|
164
|
+
["INVALID_PHONE_NUMBER", "invalid_number"],
|
|
165
|
+
["EMAIL_NOT_VERIFIED", "unverified"],
|
|
166
|
+
["SESSION_REQUIRED", "signed_out"],
|
|
167
|
+
["SOMETHING_ELSE", "failed"],
|
|
168
|
+
])("sendPhoneCode maps %s to %s", async (code, reason) => {
|
|
169
|
+
mockSendOtp.mockRejectedValue(apiError(code));
|
|
170
|
+
expect(await sendPhoneCode(NUMBER)).toEqual({ ok: false, reason });
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it.each([
|
|
174
|
+
["INVALID_OTP", "invalid_code"],
|
|
175
|
+
["TOO_MANY_ATTEMPTS", "too_many"],
|
|
176
|
+
["PHONE_NUMBER_EXIST", "taken"],
|
|
177
|
+
])("verifyPhoneCode maps %s to %s", async (code, reason) => {
|
|
178
|
+
mockVerify.mockRejectedValue(apiError(code));
|
|
179
|
+
expect(await verifyPhoneCode(NUMBER, CODE)).toEqual({ ok: false, reason });
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it("verifyPhoneCode always asks for updatePhoneNumber, never a sign-in", async () => {
|
|
183
|
+
expect(await verifyPhoneCode(NUMBER, CODE)).toEqual({ ok: true });
|
|
184
|
+
expect(mockVerify.mock.calls[0]![0].body.updatePhoneNumber).toBe(true);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it("refuses untrusted input before any call", async () => {
|
|
188
|
+
expect(await sendPhoneCode({ phoneNumber: NUMBER })).toEqual({ ok: false, reason: "invalid_number" });
|
|
189
|
+
expect(await verifyPhoneCode(NUMBER, "1234567")).toEqual({ ok: false, reason: "invalid_code" });
|
|
190
|
+
expect(mockSendOtp).not.toHaveBeenCalled();
|
|
191
|
+
expect(mockVerify).not.toHaveBeenCalled();
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it("a build without the step answers unavailable with no call", async () => {
|
|
195
|
+
mockPhoneStepActive.mockReturnValue(false);
|
|
196
|
+
expect(await sendPhoneCode(NUMBER)).toEqual({ ok: false, reason: "unavailable" });
|
|
197
|
+
expect(await verifyPhoneCode(NUMBER, CODE)).toEqual({ ok: false, reason: "unavailable" });
|
|
198
|
+
expect(await removePhone()).toEqual({ ok: false, reason: "unavailable" });
|
|
199
|
+
expect(mockSendOtp).not.toHaveBeenCalled();
|
|
200
|
+
expect(mockVerify).not.toHaveBeenCalled();
|
|
201
|
+
expect(mockUpdateUser).not.toHaveBeenCalled();
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("no log line carries the number or the code", async () => {
|
|
205
|
+
mockSendOtp.mockRejectedValue(apiError("INVALID_PHONE_NUMBER"));
|
|
206
|
+
mockVerify.mockRejectedValue(apiError("INVALID_OTP"));
|
|
207
|
+
await sendPhoneCode(NUMBER);
|
|
208
|
+
await verifyPhoneCode(NUMBER, CODE);
|
|
209
|
+
expect(logLines.length).toBe(2);
|
|
210
|
+
for (const line of logLines) {
|
|
211
|
+
expect(line).not.toContain(NUMBER.slice(1));
|
|
212
|
+
expect(line).not.toContain(CODE);
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
});
|
package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/seam-imports.test.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment node
|
|
3
|
+
*
|
|
4
|
+
* User settings › General reaches sign-in only through the generated seam
|
|
5
|
+
* (#11138). A spoke that signs in through its hub keeps this page, but not
|
|
6
|
+
* `auth.ts` or any other sign-in or database file, so a direct import here
|
|
7
|
+
* would make create-ailk's spoke closure drop the page with them and refuse.
|
|
8
|
+
* Every non-test source file under `account/general` is read, and none may
|
|
9
|
+
* name one of those files, statically or by `import()`/`require`; the phone
|
|
10
|
+
* step goes through `loadPhoneApi` in `lib/topology.generated.ts` instead.
|
|
11
|
+
*/
|
|
12
|
+
import { readdirSync, readFileSync } from "node:fs";
|
|
13
|
+
import { dirname, join, relative, resolve } from "node:path";
|
|
14
|
+
|
|
15
|
+
const GENERAL = resolve(__dirname, "..");
|
|
16
|
+
const WEB = resolve(GENERAL, "../../../../..");
|
|
17
|
+
|
|
18
|
+
/** The sign-in and database files a spoke does not carry, relative to apps/web. */
|
|
19
|
+
const SIGN_IN_FILES = [
|
|
20
|
+
"auth",
|
|
21
|
+
"lib/prisma-for-auth",
|
|
22
|
+
"lib/mcp-oauth",
|
|
23
|
+
"lib/license-key-store",
|
|
24
|
+
"app/api/auth",
|
|
25
|
+
"app/[locale]/(auth)",
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
const sources = readdirSync(GENERAL).filter((name) => /\.tsx?$/.test(name));
|
|
29
|
+
|
|
30
|
+
function specifiers(text: string): string[] {
|
|
31
|
+
return [
|
|
32
|
+
...text.matchAll(/(?:\bfrom\s+|\bimport\s*\(\s*|\brequire\s*\(\s*)["'`]([^"'`]+)["'`]/g),
|
|
33
|
+
].map((m) => m[1] as string);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
describe("account/general imports sign-in only through the seam (#11138)", () => {
|
|
37
|
+
it("reads every source file", () => {
|
|
38
|
+
expect(sources).toEqual(expect.arrayContaining(["page.tsx", "phone-actions.ts"]));
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it.each(sources)("%s names no sign-in or database file", (name) => {
|
|
42
|
+
const file = join(GENERAL, name);
|
|
43
|
+
const reached = specifiers(readFileSync(file, "utf8"))
|
|
44
|
+
.filter((spec) => spec.startsWith("."))
|
|
45
|
+
.map((spec) =>
|
|
46
|
+
relative(WEB, resolve(dirname(file), spec))
|
|
47
|
+
.split("\\")
|
|
48
|
+
.join("/")
|
|
49
|
+
.replace(/\.tsx?$/, ""),
|
|
50
|
+
);
|
|
51
|
+
expect(
|
|
52
|
+
reached.filter((target) =>
|
|
53
|
+
SIGN_IN_FILES.some((seed) => target === seed || target.startsWith(`${seed}/`)),
|
|
54
|
+
),
|
|
55
|
+
).toEqual([]);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("the phone step reads the seam", () => {
|
|
59
|
+
for (const name of ["page.tsx", "phone-actions.ts"]) {
|
|
60
|
+
expect(readFileSync(join(GENERAL, name), "utf8")).toMatch(
|
|
61
|
+
/from "\.\.\/\.\.\/\.\.\/\.\.\/\.\.\/lib\/topology\.generated"/,
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
});
|