create-ailk 0.36.0 → 0.37.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 +20 -2
- package/component-catalog.json +40 -1
- package/component-catalog.md +7 -5
- package/dist/add-route.d.ts +5 -0
- package/dist/add-route.js +10 -2
- package/dist/surfaces.js +60 -19
- package/dist/sync-routes.d.ts +15 -1
- package/dist/sync-routes.js +58 -6
- package/dist/template-record.d.ts +11 -0
- package/dist/template-record.js +18 -0
- package/dist/update.d.ts +33 -1
- package/dist/update.js +439 -56
- package/package.json +3 -3
- package/templates/.env.example +17 -0
- package/templates/apps/api/.env.example +38 -0
- package/templates/apps/api/CLAUDE.md +3 -0
- package/templates/apps/api/src/lib/__mocks__/prisma.ts +7 -0
- package/templates/apps/mcp/CLAUDE.md +1 -1
- package/templates/apps/web/CLAUDE.md +28 -1
- package/templates/apps/web/app/[locale]/(auth)/reset-password/__tests__/return.test.tsx +179 -0
- package/templates/apps/web/app/[locale]/(auth)/reset-password/page.tsx +22 -2
- package/templates/apps/web/app/[locale]/(auth)/reset-password/reset-password-card.tsx +9 -2
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/billing.test.tsx +240 -76
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/general.test.tsx +242 -28
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/hub-mode.test.tsx +369 -196
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/item.test.tsx +26 -1
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout.test.tsx +17 -6
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-menu.test.tsx +51 -12
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-popups.test.tsx +17 -2
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/notifications.test.tsx +153 -2
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/page.test.tsx +206 -23
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/popups.test.tsx +150 -188
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/privacy.test.tsx +235 -177
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/rich-translator.ts +63 -0
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/security.test.tsx +0 -3
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/thread.test.tsx +340 -0
- package/templates/apps/web/app/[locale]/(authed)/account/account-data.ts +7 -5
- package/templates/apps/web/app/[locale]/(authed)/account/account-frame.tsx +19 -3
- package/templates/apps/web/app/[locale]/(authed)/account/actions.ts +8 -4
- package/templates/apps/web/app/[locale]/(authed)/account/appointments/[slug]/page.tsx +161 -0
- package/templates/apps/web/app/[locale]/(authed)/account/appointments/__tests__/page.test.tsx +426 -0
- package/templates/apps/web/app/[locale]/(authed)/account/appointments/appointments-data.ts +76 -0
- package/templates/apps/web/app/[locale]/(authed)/account/appointments/page.tsx +139 -0
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/page.tsx +92 -24
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/versions/[version]/file/route.ts +32 -1
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/file-route.test.ts +76 -3
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/page.test.tsx +290 -41
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/artifact-data.ts +109 -11
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/page.tsx +43 -44
- package/templates/apps/web/app/[locale]/(authed)/account/billing/__tests__/offerings.test.ts +99 -0
- package/templates/apps/web/app/[locale]/(authed)/account/billing/offerings.ts +123 -0
- package/templates/apps/web/app/[locale]/(authed)/account/billing/page.tsx +309 -113
- package/templates/apps/web/app/[locale]/(authed)/account/billing-source.ts +192 -65
- package/templates/apps/web/app/[locale]/(authed)/account/components/request-quote.tsx +52 -7
- package/templates/apps/web/app/[locale]/(authed)/account/general/account-name.ts +36 -0
- package/templates/apps/web/app/[locale]/(authed)/account/general/contact-actions.ts +70 -2
- package/templates/apps/web/app/[locale]/(authed)/account/general/contact-details.tsx +42 -0
- package/templates/apps/web/app/[locale]/(authed)/account/general/page.tsx +55 -58
- package/templates/apps/web/app/[locale]/(authed)/account/general/phone-verification.tsx +2 -1
- package/templates/apps/web/app/[locale]/(authed)/account/general/photo-actions.ts +73 -0
- package/templates/apps/web/app/[locale]/(authed)/account/general/profile-form.tsx +12 -9
- package/templates/apps/web/app/[locale]/(authed)/account/general/profile-source.ts +18 -4
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/[kind]/[id]/page.tsx +20 -2
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/member-thread-composer.tsx +43 -0
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/page.tsx +125 -0
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-data.ts +88 -0
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-write.ts +31 -0
- package/templates/apps/web/app/[locale]/(authed)/account/layout.tsx +3 -2
- package/templates/apps/web/app/[locale]/(authed)/account/new-menu.tsx +33 -8
- package/templates/apps/web/app/[locale]/(authed)/account/new-popups.tsx +31 -52
- package/templates/apps/web/app/[locale]/(authed)/account/notifications/page.tsx +44 -4
- package/templates/apps/web/app/[locale]/(authed)/account/page.tsx +69 -49
- package/templates/apps/web/app/[locale]/(authed)/account/privacy/__tests__/export-route.test.ts +173 -0
- package/templates/apps/web/app/[locale]/(authed)/account/privacy/actions.ts +42 -4
- package/templates/apps/web/app/[locale]/(authed)/account/privacy/export/route.ts +102 -0
- package/templates/apps/web/app/[locale]/(authed)/account/privacy/page.tsx +147 -137
- package/templates/apps/web/app/[locale]/(authed)/account/security/__tests__/hub-variant.test.tsx +258 -0
- package/templates/apps/web/app/[locale]/(authed)/account/security/page.tsx +18 -21
- package/templates/apps/web/app/[locale]/(authed)/account/security/security-panel.tsx +34 -6
- package/templates/apps/web/app/[locale]/(authed)/account/security/security-source.ts +37 -7
- package/templates/apps/web/app/[locale]/(authed)/account/settings/page.tsx +0 -2
- package/templates/apps/web/app/[locale]/(authed)/account/settings-frame.tsx +8 -5
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsClient.tsx +3 -2
- package/templates/apps/web/app/api/auth/hub/password/__tests__/return.test.ts +86 -0
- package/templates/apps/web/app/api/auth/hub/password/__tests__/route.test.ts +368 -0
- package/templates/apps/web/app/api/auth/hub/password/return.ts +86 -0
- package/templates/apps/web/app/api/auth/hub/password/route.ts +171 -0
- package/templates/apps/web/app/api/hub-session/__tests__/routes.test.ts +263 -0
- package/templates/apps/web/app/api/hub-session/password/return/route.ts +69 -0
- package/templates/apps/web/app/api/hub-session/password/route.ts +106 -0
- package/templates/apps/web/lib/__tests__/account-config.test.ts +129 -1
- package/templates/apps/web/lib/__tests__/offerings-pricing.test.ts +33 -0
- package/templates/apps/web/lib/account-config.ts +132 -8
- package/templates/apps/web/lib/auth-routes.ts +11 -6
- package/templates/apps/web/lib/offerings-pricing.ts +4 -1
- package/templates/apps/web/messages/en.json +156 -80
- package/versions.json +48 -48
- package/templates/apps/web/app/[locale]/(authed)/account/components/schedule-service.tsx +0 -276
- package/templates/apps/web/app/[locale]/(authed)/account/components/send-message.tsx +0 -128
- package/templates/apps/web/app/[locale]/(authed)/account/settings/__tests__/theme-modes.test.ts +0 -42
- package/templates/apps/web/app/[locale]/(authed)/account/settings/theme-modes.ts +0 -40
|
@@ -1,52 +1,75 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* /[locale]/account/privacy — User settings › Privacy (#8438 D14
|
|
2
|
+
* /[locale]/account/privacy — User settings › Privacy (#8438 D14; #11164 —
|
|
3
|
+
* Ploy's row-and-card shape, operator rulings 2026-11-08).
|
|
3
4
|
*
|
|
4
5
|
* RSC, outside the account layout's SignedInShell (#8430), in the member's
|
|
5
6
|
* settings frame (D7) — standalone, the Admin's shape. In DOM order:
|
|
6
7
|
*
|
|
7
|
-
* 1.
|
|
8
|
-
* privacy policy.
|
|
9
|
-
* 2.
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
8
|
+
* 1. The title and the lead, with "Privacy Policy" linked to the site's
|
|
9
|
+
* privacy policy (`consentPoliciesFor(locale).privacy`, #8765 D9).
|
|
10
|
+
* 2. One card:
|
|
11
|
+
* - account-privacy-data-use — "How we use your data", collapsed, a
|
|
12
|
+
* disclosure button whose chevron expands it in place to the two
|
|
13
|
+
* bullets (`DataUseDisclosure`);
|
|
14
|
+
* - account-privacy-data-consent — one `ConsentSwitchList` row per
|
|
15
|
+
* `area: "data"` purpose, the shipped one being "Help improve our AI
|
|
16
|
+
* models" (`ai_training`, #11164 AC-2: a consent, off until ticked,
|
|
17
|
+
* written through `setConsentAction`), with its description and the
|
|
18
|
+
* given/withdrawn date line; a site that declares none shows the one
|
|
19
|
+
* line. A failed consents read shows the unavailable line in its place
|
|
20
|
+
* and everything else still renders.
|
|
21
|
+
* 3. One card: account-privacy-your-data — the "Your data" table
|
|
22
|
+
* (`AccountDataTable`): Export data, a download of the person's own
|
|
23
|
+
* records through this site's `./export` route; Delete stored sessions,
|
|
24
|
+
* which confirms first, then calls `deleteStoredSessionsAction` and
|
|
25
|
+
* reports the count. The same card on every surface, a spoke that
|
|
26
|
+
* signs in through its hub included (#11194): the two member routes
|
|
27
|
+
* the table calls are on `HUB_SESSION_ROUTES`, each answered for the
|
|
28
|
+
* spoke's own workspace from the hub session.
|
|
21
29
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
30
|
+
* Gone (#11164 rulings 1, 2, 5, 6): the Cookies section (the choice cannot
|
|
31
|
+
* change without a new banner prompt), the summary row, the agreements list
|
|
32
|
+
* (the ledger keeps the record) and the account-deletion line and button. An
|
|
33
|
+
* account-deletion request now lives in the Delete row's confirmation, which
|
|
34
|
+
* points at Support — on every surface but a hub-mode spoke whose hub answers
|
|
35
|
+
* no member route (`via: "none"`), where Support must not take it
|
|
36
|
+
* (SEC-7894-11); `POST /v1/member/deletion-request` is unchanged.
|
|
37
|
+
*
|
|
38
|
+
* The registry purpose this app names itself: `ai_training` →
|
|
39
|
+
* `settings.privacy.purposes.ai_training` (title, description); a purpose a
|
|
40
|
+
* site adds is labelled by its statement and described by its description.
|
|
41
|
+
* The lead is one `t.rich` message whose `<policy>` tag is the link (the
|
|
42
|
+
* billing tab's `accessEnds` idiom); the metadata description is the same
|
|
43
|
+
* message through `t.markup` with the tag dropped.
|
|
24
44
|
*/
|
|
25
45
|
|
|
26
46
|
import { member } from "@working-theory/api-client";
|
|
27
47
|
import {
|
|
48
|
+
AccountDataTable,
|
|
28
49
|
AccountSettingsFrame,
|
|
29
50
|
AccountSettingsPane,
|
|
30
|
-
AgreementList,
|
|
31
51
|
ConsentSwitchList,
|
|
52
|
+
DataUseDisclosure,
|
|
53
|
+
type ConsentSwitchRow,
|
|
32
54
|
} from "@working-theory/templates/account";
|
|
33
55
|
import { localeHref } from "@working-theory/ui";
|
|
34
|
-
import {
|
|
56
|
+
import {
|
|
57
|
+
Link,
|
|
58
|
+
SERVER_TIME_ZONE,
|
|
59
|
+
Text,
|
|
60
|
+
formatLocalTime,
|
|
61
|
+
} from "@working-theory/ui/primitives";
|
|
62
|
+
import { AI_TRAINING_PURPOSE_ID } from "@working-theory/validation";
|
|
35
63
|
import type { Metadata } from "next";
|
|
36
|
-
import { cookies } from "next/headers";
|
|
37
64
|
import { getTranslations } from "next-intl/server";
|
|
38
65
|
import type { ReactElement } from "react";
|
|
39
66
|
|
|
40
67
|
import { consentPoliciesFor } from "../../../../../lib/consent-policies";
|
|
41
68
|
import { accountSession } from "../account-data";
|
|
42
|
-
import { DeletionRequest } from "../general/deletion-request";
|
|
43
69
|
import { loadProfileSource } from "../general/profile-source";
|
|
44
70
|
import { memberSettingsFrame, type Translate } from "../settings-frame";
|
|
45
71
|
|
|
46
|
-
import { setConsentAction } from "./actions";
|
|
47
|
-
|
|
48
|
-
/** The cookie banner's own choice cookie (`layout.tsx`'s `CONSENT_COOKIE_NAME`, #5557). */
|
|
49
|
-
const CONSENT_COOKIE_NAME = "ailk-consent";
|
|
72
|
+
import { deleteStoredSessionsAction, setConsentAction } from "./actions";
|
|
50
73
|
|
|
51
74
|
interface Props {
|
|
52
75
|
params: Promise<{ locale: string }>;
|
|
@@ -55,14 +78,34 @@ interface Props {
|
|
|
55
78
|
export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
|
56
79
|
const { locale } = await params;
|
|
57
80
|
const t = await getTranslations({ locale, namespace: "account" });
|
|
58
|
-
return {
|
|
81
|
+
return {
|
|
82
|
+
title: t("settings.privacy.title"),
|
|
83
|
+
description: t.markup("settings.privacy.lead", {
|
|
84
|
+
policy: (chunks) => chunks,
|
|
85
|
+
}),
|
|
86
|
+
};
|
|
59
87
|
}
|
|
60
88
|
|
|
61
|
-
export default async function AccountPrivacyPage({
|
|
89
|
+
export default async function AccountPrivacyPage({
|
|
90
|
+
params,
|
|
91
|
+
}: Props): Promise<ReactElement> {
|
|
62
92
|
const { locale } = await params;
|
|
63
93
|
const t = await getTranslations({ locale, namespace: "account" });
|
|
64
94
|
const session = await accountSession(locale);
|
|
65
|
-
const frame = memberSettingsFrame(
|
|
95
|
+
const frame = memberSettingsFrame(
|
|
96
|
+
locale,
|
|
97
|
+
t as unknown as Translate,
|
|
98
|
+
"privacy",
|
|
99
|
+
);
|
|
100
|
+
const policyHref =
|
|
101
|
+
consentPoliciesFor(locale)["privacy"] ?? localeHref(locale, "/privacy");
|
|
102
|
+
const lead = t.rich("settings.privacy.lead", {
|
|
103
|
+
policy: (chunks) => (
|
|
104
|
+
<Link href={policyHref} data-testid="account-privacy-policy">
|
|
105
|
+
{chunks}
|
|
106
|
+
</Link>
|
|
107
|
+
),
|
|
108
|
+
});
|
|
66
109
|
|
|
67
110
|
// Unreachable behind the (authed) gate; a session that expired between
|
|
68
111
|
// the layout and the page renders the pane's title alone.
|
|
@@ -72,7 +115,7 @@ export default async function AccountPrivacyPage({ params }: Props): Promise<Rea
|
|
|
72
115
|
<AccountSettingsPane
|
|
73
116
|
id="account-settings-privacy"
|
|
74
117
|
title={t("settings.privacy.title")}
|
|
75
|
-
lead={
|
|
118
|
+
lead={lead}
|
|
76
119
|
>
|
|
77
120
|
{null}
|
|
78
121
|
</AccountSettingsPane>
|
|
@@ -84,16 +127,7 @@ export default async function AccountPrivacyPage({ params }: Props): Promise<Rea
|
|
|
84
127
|
const name = ctx.user.name || ctx.user.email;
|
|
85
128
|
const source = await loadProfileSource(ctx);
|
|
86
129
|
|
|
87
|
-
let
|
|
88
|
-
try {
|
|
89
|
-
const value = (await cookies()).get(CONSENT_COOKIE_NAME)?.value;
|
|
90
|
-
cookieChoice = value === "accepted" || value === "declined" ? value : null;
|
|
91
|
-
} catch {
|
|
92
|
-
cookieChoice = null;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
let dataRows: { id: string; label: string; description?: string; granted: boolean; dateLine?: string }[] = [];
|
|
96
|
-
let agreementRows: { id: string; statement: string; version: number; acceptedLine?: string }[] = [];
|
|
130
|
+
let dataRows: ConsentSwitchRow[] = [];
|
|
97
131
|
let consentsAvailable = true;
|
|
98
132
|
try {
|
|
99
133
|
const res = await member.consents(ctx.init, { locale });
|
|
@@ -102,27 +136,32 @@ export default async function AccountPrivacyPage({ params }: Props): Promise<Rea
|
|
|
102
136
|
.filter((purpose) => purpose.area === "data")
|
|
103
137
|
.map((purpose) => ({
|
|
104
138
|
id: purpose.id,
|
|
105
|
-
|
|
139
|
+
...(purpose.id === AI_TRAINING_PURPOSE_ID
|
|
140
|
+
? {
|
|
141
|
+
label: t("settings.privacy.purposes.ai_training.title"),
|
|
142
|
+
description: t(
|
|
143
|
+
"settings.privacy.purposes.ai_training.description",
|
|
144
|
+
),
|
|
145
|
+
}
|
|
146
|
+
: {
|
|
147
|
+
label: purpose.statement,
|
|
148
|
+
...(purpose.description
|
|
149
|
+
? { description: purpose.description }
|
|
150
|
+
: {}),
|
|
151
|
+
}),
|
|
106
152
|
granted: purpose.effective,
|
|
107
|
-
...(purpose.description ? { description: purpose.description } : {}),
|
|
108
153
|
...(purpose.state
|
|
109
154
|
? {
|
|
110
155
|
dateLine: purpose.state.granted
|
|
111
|
-
? t("settings.privacy.given", {
|
|
112
|
-
|
|
156
|
+
? t("settings.privacy.given", {
|
|
157
|
+
date: formatDate(purpose.state.at, locale),
|
|
158
|
+
})
|
|
159
|
+
: t("settings.privacy.withdrawn", {
|
|
160
|
+
date: formatDate(purpose.state.at, locale),
|
|
161
|
+
}),
|
|
113
162
|
}
|
|
114
163
|
: {}),
|
|
115
164
|
}));
|
|
116
|
-
agreementRows = res.body.purposes
|
|
117
|
-
.filter((purpose) => purpose.kind === "agreement")
|
|
118
|
-
.map((purpose) => ({
|
|
119
|
-
id: purpose.id,
|
|
120
|
-
statement: purpose.statement,
|
|
121
|
-
version: purpose.policyVersion,
|
|
122
|
-
...(purpose.state?.granted
|
|
123
|
-
? { acceptedLine: t("settings.privacy.accepted", { date: formatDate(purpose.state.at, locale) }) }
|
|
124
|
-
: {}),
|
|
125
|
-
}));
|
|
126
165
|
} else {
|
|
127
166
|
consentsAvailable = false;
|
|
128
167
|
}
|
|
@@ -135,96 +174,67 @@ export default async function AccountPrivacyPage({ params }: Props): Promise<Rea
|
|
|
135
174
|
<AccountSettingsPane
|
|
136
175
|
id="account-settings-privacy"
|
|
137
176
|
title={t("settings.privacy.title")}
|
|
138
|
-
lead={
|
|
177
|
+
lead={lead}
|
|
139
178
|
>
|
|
140
|
-
|
|
141
|
-
<
|
|
142
|
-
{t("settings.privacy.
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
<div data-testid="account-privacy-cookies" className="flex flex-col gap-1">
|
|
150
|
-
<Heading level={2} visual={4} className="!text-body-sm !font-medium">
|
|
151
|
-
{t("settings.privacy.cookiesTitle")}
|
|
152
|
-
</Heading>
|
|
153
|
-
<div className="flex flex-wrap items-baseline gap-3">
|
|
154
|
-
<Text as="span" variant="body-sm" tone="muted">
|
|
155
|
-
{cookieChoice === "accepted"
|
|
156
|
-
? t("settings.privacy.cookiesAccepted")
|
|
157
|
-
: cookieChoice === "declined"
|
|
158
|
-
? t("settings.privacy.cookiesDeclined")
|
|
159
|
-
: t("settings.privacy.cookiesUnset")}
|
|
160
|
-
</Text>
|
|
161
|
-
<Link
|
|
162
|
-
href={localeHref(locale, "/privacy#cookie-settings")}
|
|
163
|
-
className="inline-flex min-h-6 items-center"
|
|
164
|
-
data-testid="account-cookie-settings"
|
|
165
|
-
>
|
|
166
|
-
{t("settings.privacy.cookiesChange")}
|
|
167
|
-
</Link>
|
|
168
|
-
</div>
|
|
169
|
-
</div>
|
|
170
|
-
|
|
171
|
-
{consentsAvailable ? (
|
|
172
|
-
<>
|
|
173
|
-
<div data-testid="account-privacy-consents" className="flex flex-col gap-2">
|
|
174
|
-
<Heading level={2} visual={4} className="!text-body-sm !font-medium">
|
|
175
|
-
{t("settings.privacy.consentsTitle")}
|
|
176
|
-
</Heading>
|
|
177
|
-
<ConsentSwitchList
|
|
178
|
-
rows={dataRows}
|
|
179
|
-
onChange={setConsentAction}
|
|
180
|
-
emptyLine={t("settings.privacy.consentsEmpty")}
|
|
181
|
-
testIdPrefix="account-privacy-data-consent"
|
|
182
|
-
/>
|
|
183
|
-
</div>
|
|
184
|
-
|
|
185
|
-
<div data-testid="account-privacy-agreements" className="flex flex-col gap-2">
|
|
186
|
-
<Heading level={2} visual={4} className="!text-body-sm !font-medium">
|
|
187
|
-
{t("settings.privacy.agreementsTitle")}
|
|
188
|
-
</Heading>
|
|
189
|
-
<AgreementList
|
|
190
|
-
rows={agreementRows}
|
|
191
|
-
notAcceptedLine={t("settings.privacy.agreementsEmpty")}
|
|
192
|
-
emptyLine={t("settings.privacy.agreementsEmpty")}
|
|
193
|
-
testIdPrefix="account-privacy-agreement"
|
|
194
|
-
policies={consentPoliciesFor(locale)}
|
|
195
|
-
/>
|
|
196
|
-
</div>
|
|
197
|
-
</>
|
|
198
|
-
) : (
|
|
199
|
-
<span data-testid="account-privacy-unavailable">
|
|
200
|
-
<Text as="p" variant="body-sm" tone="muted">
|
|
201
|
-
{t("settings.privacy.unavailable")}
|
|
202
|
-
</Text>
|
|
203
|
-
</span>
|
|
204
|
-
)}
|
|
205
|
-
|
|
206
|
-
<div data-testid="account-deletion">
|
|
207
|
-
<DeletionRequest
|
|
208
|
-
via={source.via}
|
|
209
|
-
supportHref={localeHref(locale, "/account/support")}
|
|
210
|
-
labels={{
|
|
211
|
-
lead: t("settings.privacy.deletionLead"),
|
|
212
|
-
action: t("settings.privacy.deletion"),
|
|
213
|
-
sentSite: t("settings.privacy.deletionSentSite"),
|
|
214
|
-
sentHub: t("settings.privacy.deletionSentHub"),
|
|
215
|
-
unverified: t("settings.privacy.deletionUnverified"),
|
|
216
|
-
unavailable: t("settings.privacy.deletionUnavailable"),
|
|
217
|
-
error: t("settings.privacy.deletionError"),
|
|
218
|
-
viaSupport: t("settings.privacy.deletionViaSupport"),
|
|
219
|
-
supportLink: t("settings.privacy.deletionSupportLink"),
|
|
220
|
-
}}
|
|
179
|
+
<>
|
|
180
|
+
<DataUseDisclosure
|
|
181
|
+
title={t("settings.privacy.dataUse.title")}
|
|
182
|
+
bullets={[
|
|
183
|
+
t("settings.privacy.dataUse.bullet1"),
|
|
184
|
+
t("settings.privacy.dataUse.bullet2"),
|
|
185
|
+
]}
|
|
186
|
+
testId="account-privacy-data-use"
|
|
221
187
|
/>
|
|
222
|
-
|
|
188
|
+
{consentsAvailable ? (
|
|
189
|
+
<ConsentSwitchList
|
|
190
|
+
rows={dataRows}
|
|
191
|
+
onChange={setConsentAction}
|
|
192
|
+
emptyLine={t("settings.privacy.consentsEmpty")}
|
|
193
|
+
testIdPrefix="account-privacy-data-consent"
|
|
194
|
+
/>
|
|
195
|
+
) : (
|
|
196
|
+
<span data-testid="account-privacy-unavailable">
|
|
197
|
+
<Text as="p" variant="body-sm" tone="muted" className="pt-3">
|
|
198
|
+
{t("settings.privacy.unavailable")}
|
|
199
|
+
</Text>
|
|
200
|
+
</span>
|
|
201
|
+
)}
|
|
202
|
+
</>
|
|
203
|
+
<AccountDataTable
|
|
204
|
+
exportHref={localeHref(locale, "/account/privacy/export")}
|
|
205
|
+
onDeleteSessions={deleteStoredSessionsAction}
|
|
206
|
+
supportHref={
|
|
207
|
+
source.via === "none"
|
|
208
|
+
? null
|
|
209
|
+
: localeHref(locale, "/account/support")
|
|
210
|
+
}
|
|
211
|
+
testIdPrefix="account-privacy-your-data"
|
|
212
|
+
labels={{
|
|
213
|
+
title: t("settings.privacy.yourData.title"),
|
|
214
|
+
exportLabel: t("settings.privacy.yourData.exportLabel"),
|
|
215
|
+
exportButton: t("settings.privacy.yourData.exportButton"),
|
|
216
|
+
deleteLabel: t("settings.privacy.yourData.deleteLabel"),
|
|
217
|
+
deleteDescription: t("settings.privacy.yourData.deleteDescription"),
|
|
218
|
+
deleteButton: t("settings.privacy.yourData.deleteButton"),
|
|
219
|
+
confirmTitle: t("settings.privacy.yourData.confirmTitle"),
|
|
220
|
+
confirmBody: t("settings.privacy.yourData.confirmBody"),
|
|
221
|
+
confirmCancel: t("settings.privacy.yourData.confirmCancel"),
|
|
222
|
+
confirmDelete: t("settings.privacy.yourData.confirmDelete"),
|
|
223
|
+
deleting: t("settings.privacy.yourData.deleting"),
|
|
224
|
+
deleteFailed: t("settings.privacy.yourData.deleteFailed"),
|
|
225
|
+
accountDeletion: t("settings.privacy.yourData.accountDeletion"),
|
|
226
|
+
accountDeletionLink: t(
|
|
227
|
+
"settings.privacy.yourData.accountDeletionLink",
|
|
228
|
+
),
|
|
229
|
+
}}
|
|
230
|
+
/>
|
|
223
231
|
</AccountSettingsPane>
|
|
224
232
|
</AccountSettingsFrame>
|
|
225
233
|
);
|
|
226
234
|
}
|
|
227
235
|
|
|
236
|
+
// #11159: a `t()` argument is a string, so this RSC reads the day in the
|
|
237
|
+
// server fallback zone — never the host's, which the unpinned form read.
|
|
228
238
|
function formatDate(iso: string, locale: string): string {
|
|
229
|
-
return
|
|
239
|
+
return formatLocalTime(iso, "date", { timeZone: SERVER_TIME_ZONE, locale });
|
|
230
240
|
}
|
package/templates/apps/web/app/[locale]/(authed)/account/security/__tests__/hub-variant.test.tsx
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Security on a spoke that signs in through its hub (#11162 AC-1, AC-3).
|
|
3
|
+
*
|
|
4
|
+
* The generated web seam is mocked to its `signIn: "hub"` render, as
|
|
5
|
+
* `account/__tests__/hub-mode.test.tsx` mocks it; this suite sits beside the
|
|
6
|
+
* route so it copies with it. Covers:
|
|
7
|
+
*
|
|
8
|
+
* - AC-1: the tab renders the Sign-in methods panel — the Password row
|
|
9
|
+
* with Set / Not set read from the hub's `me` for the signed-in person
|
|
10
|
+
* (the Bearer credential, never a cookie), the secure-link line naming
|
|
11
|
+
* the person's email, Set password or Change password — and Log out; no
|
|
12
|
+
* "managed at <host>" sentence and no link to the hub's Security page,
|
|
13
|
+
* and the seam's accounts reader is never asked.
|
|
14
|
+
* - AC-2 (the spoke's half): Set / Change password POSTs `{ locale }` to
|
|
15
|
+
* the spoke's own `/api/hub-session/password`, same-origin, and asks
|
|
16
|
+
* Better Auth for nothing; a 202 is "Link sent", anything else the
|
|
17
|
+
* failure line.
|
|
18
|
+
* - AC-3: a hub that answers no state — no `hasPassword`, a refusal, a
|
|
19
|
+
* failed read — renders the panel's unavailable line, never a form.
|
|
20
|
+
*/
|
|
21
|
+
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
22
|
+
import { tmpdir } from "node:os";
|
|
23
|
+
import { join } from "node:path";
|
|
24
|
+
|
|
25
|
+
import { act, fireEvent, render, screen } from "@testing-library/react";
|
|
26
|
+
|
|
27
|
+
jest.mock("next-intl/server", () => {
|
|
28
|
+
const msgs: unknown = require("../../../../../../messages/en.json");
|
|
29
|
+
const dig = (obj: unknown, path: string): unknown =>
|
|
30
|
+
path.split(".").reduce<unknown>(
|
|
31
|
+
(acc, k) => (acc !== null && typeof acc === "object" ? (acc as Record<string, unknown>)[k] : undefined),
|
|
32
|
+
obj,
|
|
33
|
+
);
|
|
34
|
+
return {
|
|
35
|
+
__esModule: true,
|
|
36
|
+
getTranslations: async (arg: string | { namespace?: string; locale?: string }) => {
|
|
37
|
+
const ns = typeof arg === "string" ? arg : (arg.namespace ?? "");
|
|
38
|
+
const messages = dig(msgs, ns);
|
|
39
|
+
return (key: string, values?: Record<string, unknown>): string => {
|
|
40
|
+
const value = dig(messages, key);
|
|
41
|
+
if (typeof value !== "string") return `${ns}.${key}`;
|
|
42
|
+
return value.replace(/\{(\w+)\}/g, (m, name: string) =>
|
|
43
|
+
values && name in values ? String(values[name]) : m,
|
|
44
|
+
);
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const mockHeaders = jest.fn();
|
|
51
|
+
jest.mock("next/headers", () => ({
|
|
52
|
+
__esModule: true,
|
|
53
|
+
headers: (...args: unknown[]) => mockHeaders(...args),
|
|
54
|
+
cookies: jest.fn().mockImplementation(async () => ({ toString: () => "", set: jest.fn() })),
|
|
55
|
+
}));
|
|
56
|
+
|
|
57
|
+
const mockReadSession = jest.fn();
|
|
58
|
+
const mockReadOwnAccounts = jest.fn();
|
|
59
|
+
// eslint-disable-next-line no-restricted-syntax -- #507: the seam is generated per build (#7894 D8); its `signIn: "hub"` render is the boundary under test, and no env or HTTP surface selects it.
|
|
60
|
+
jest.mock("../../../../../../lib/topology.generated", () => ({
|
|
61
|
+
__esModule: true,
|
|
62
|
+
TOPOLOGY: "spoke",
|
|
63
|
+
SIGN_IN_ENABLED: true,
|
|
64
|
+
SIGN_IN_PROVIDER: "hub",
|
|
65
|
+
SIGN_IN_PATH: "/account",
|
|
66
|
+
SIGN_UP_PATH: null,
|
|
67
|
+
SIGN_OUT_ENDPOINT: "/api/hub-session/sign-out",
|
|
68
|
+
readSession: (...args: unknown[]) => mockReadSession(...args),
|
|
69
|
+
registerSiteStores: () => Promise.resolve(),
|
|
70
|
+
loadSpokeBilling: () => Promise.resolve(null),
|
|
71
|
+
readOwnAccounts: (...args: unknown[]) => mockReadOwnAccounts(...args),
|
|
72
|
+
}));
|
|
73
|
+
|
|
74
|
+
const mockHubMe = jest.fn();
|
|
75
|
+
jest.mock("@working-theory/api-client", () => ({
|
|
76
|
+
__esModule: true,
|
|
77
|
+
visitorForwardHeaders: () => null,
|
|
78
|
+
hubSignIn: { me: (...args: unknown[]) => mockHubMe(...args) },
|
|
79
|
+
}));
|
|
80
|
+
|
|
81
|
+
const mockRequestPasswordReset = jest.fn();
|
|
82
|
+
const mockSignOut = jest.fn();
|
|
83
|
+
jest.mock("better-auth/react", () => ({
|
|
84
|
+
__esModule: true,
|
|
85
|
+
createAuthClient: () => ({
|
|
86
|
+
requestPasswordReset: (...args: unknown[]) => mockRequestPasswordReset(...args),
|
|
87
|
+
signOut: (...args: unknown[]) => mockSignOut(...args),
|
|
88
|
+
}),
|
|
89
|
+
}));
|
|
90
|
+
|
|
91
|
+
const mockPush = jest.fn();
|
|
92
|
+
jest.mock("next/navigation", () => ({
|
|
93
|
+
__esModule: true,
|
|
94
|
+
useRouter: () => ({ push: mockPush, refresh: jest.fn(), replace: jest.fn() }),
|
|
95
|
+
usePathname: () => "/account/security",
|
|
96
|
+
redirect: jest.fn(),
|
|
97
|
+
}));
|
|
98
|
+
|
|
99
|
+
import { seal } from "../../../../../../lib/hub-session/seal";
|
|
100
|
+
import SecurityPage from "../page";
|
|
101
|
+
|
|
102
|
+
const HUB = "https://hub.example.com";
|
|
103
|
+
const SESSION_SECRET = "s".repeat(43);
|
|
104
|
+
const CREDENTIAL = `ailk_hst_${"t".repeat(43)}`;
|
|
105
|
+
const BEARER = { headers: { authorization: `Bearer ${CREDENTIAL}` } };
|
|
106
|
+
const USER = {
|
|
107
|
+
name: "Ada Lovelace",
|
|
108
|
+
email: "ada@example.com",
|
|
109
|
+
emailVerified: true,
|
|
110
|
+
createdAt: "2026-09-01T00:00:00.000Z",
|
|
111
|
+
};
|
|
112
|
+
const WIRE_USER = { id: "user_1", ...USER };
|
|
113
|
+
|
|
114
|
+
const ENV = process.env;
|
|
115
|
+
let contentRoot: string;
|
|
116
|
+
const realFetch = Object.getOwnPropertyDescriptor(globalThis, "fetch");
|
|
117
|
+
const mockFetch = jest.fn();
|
|
118
|
+
|
|
119
|
+
beforeEach(() => {
|
|
120
|
+
contentRoot = mkdtempSync(join(tmpdir(), "ailk-security-hub-"));
|
|
121
|
+
writeFileSync(join(contentRoot, "_site.mdx"), '---\nsiteName: "Test"\n---\n');
|
|
122
|
+
process.env = {
|
|
123
|
+
...ENV,
|
|
124
|
+
AILK_CONTENT_ROOT: contentRoot,
|
|
125
|
+
AILK_HUB_SIGN_IN_URL: HUB,
|
|
126
|
+
AILK_HUB_CLIENT_ID: "spoke_0001",
|
|
127
|
+
AILK_HUB_CLIENT_SECRET: `ailk_hcs_${"c".repeat(43)}`,
|
|
128
|
+
AILK_HUB_SESSION_SECRET: SESSION_SECRET,
|
|
129
|
+
NEXT_PUBLIC_BASE_URL: "https://spoke.example.com",
|
|
130
|
+
};
|
|
131
|
+
const sealed = seal(
|
|
132
|
+
{ v: 1, accessToken: CREDENTIAL, expiresAt: Date.now() + 60_000, user: USER },
|
|
133
|
+
SESSION_SECRET,
|
|
134
|
+
"session",
|
|
135
|
+
"__Host-ailk-hub-session",
|
|
136
|
+
);
|
|
137
|
+
mockHeaders.mockReset().mockResolvedValue(new Headers({ cookie: `__Host-ailk-hub-session=${sealed}` }));
|
|
138
|
+
mockReadSession.mockReset().mockResolvedValue({ user: USER });
|
|
139
|
+
mockReadOwnAccounts.mockReset().mockResolvedValue(null);
|
|
140
|
+
mockHubMe.mockReset();
|
|
141
|
+
mockRequestPasswordReset.mockReset();
|
|
142
|
+
mockSignOut.mockReset();
|
|
143
|
+
mockPush.mockReset();
|
|
144
|
+
mockFetch.mockReset();
|
|
145
|
+
Object.defineProperty(globalThis, "fetch", { value: mockFetch, writable: true, configurable: true });
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
afterEach(() => {
|
|
149
|
+
rmSync(contentRoot, { recursive: true, force: true });
|
|
150
|
+
process.env = ENV;
|
|
151
|
+
if (realFetch) Object.defineProperty(globalThis, "fetch", realFetch);
|
|
152
|
+
else Reflect.deleteProperty(globalThis, "fetch");
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
function hubAnswers(body: Record<string, unknown>): void {
|
|
156
|
+
mockHubMe.mockResolvedValue({ ok: true, status: 200, body: { user: WIRE_USER, billingCustomerId: null, ...body } });
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async function renderSecurity(): Promise<void> {
|
|
160
|
+
render(await SecurityPage({ params: Promise.resolve({ locale: "en" }) }));
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** The panel's shape every hub render shares: Log out, and none of the retired pointer. */
|
|
164
|
+
function expectNoPointer(): void {
|
|
165
|
+
expect(screen.getByTestId("account-security-log-out")).toBeInTheDocument();
|
|
166
|
+
expect(screen.queryByTestId("account-security-hub")).not.toBeInTheDocument();
|
|
167
|
+
expect(screen.queryByTestId("account-security-hub-link")).not.toBeInTheDocument();
|
|
168
|
+
expect(screen.queryByTestId("account-security-sentence")).not.toBeInTheDocument();
|
|
169
|
+
expect(screen.queryByText(/managed at/i)).toBeNull();
|
|
170
|
+
expect(screen.queryByText(/main site/i)).toBeNull();
|
|
171
|
+
expect(mockReadOwnAccounts).not.toHaveBeenCalled();
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
describe("AC-1 — the Sign-in methods panel on a hub-mode spoke", () => {
|
|
175
|
+
it("renders the Password row as Set, the change line naming the email, and Change password, read from the hub with the credential", async () => {
|
|
176
|
+
hubAnswers({ hasPassword: true });
|
|
177
|
+
await renderSecurity();
|
|
178
|
+
|
|
179
|
+
expect(mockHubMe).toHaveBeenCalledTimes(1);
|
|
180
|
+
expect(mockHubMe).toHaveBeenCalledWith(BEARER);
|
|
181
|
+
expect(screen.getByText("Sign-in methods")).toBeInTheDocument();
|
|
182
|
+
expect(screen.getByTestId("account-security-password")).toBeInTheDocument();
|
|
183
|
+
expect(screen.getByTestId("account-security-password-status")).toHaveTextContent("Set");
|
|
184
|
+
expect(screen.getByTestId("account-security-password-note")).toHaveTextContent(
|
|
185
|
+
"We'll email ada@example.com a secure link to change your password.",
|
|
186
|
+
);
|
|
187
|
+
expect(screen.getByTestId("account-security-password-request")).toHaveTextContent("Change password");
|
|
188
|
+
expectNoPointer();
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it("renders the Password row as Not set, the set line naming the email, and Set password", async () => {
|
|
192
|
+
hubAnswers({ hasPassword: false });
|
|
193
|
+
await renderSecurity();
|
|
194
|
+
|
|
195
|
+
expect(screen.getByTestId("account-security-password-status")).toHaveTextContent("Not set");
|
|
196
|
+
expect(screen.getByTestId("account-security-password-note")).toHaveTextContent(
|
|
197
|
+
"We'll email ada@example.com a secure link to create your password.",
|
|
198
|
+
);
|
|
199
|
+
expect(screen.getByTestId("account-security-password-request")).toHaveTextContent("Set password");
|
|
200
|
+
expectNoPointer();
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
describe("AC-2 — Set / Change password asks the spoke's own route", () => {
|
|
205
|
+
it("POSTs { locale } to /api/hub-session/password same-origin, asks Better Auth nothing, and a 202 is Link sent", async () => {
|
|
206
|
+
hubAnswers({ hasPassword: false });
|
|
207
|
+
mockFetch.mockResolvedValue({ ok: true, status: 202 });
|
|
208
|
+
await renderSecurity();
|
|
209
|
+
|
|
210
|
+
await act(async () => {
|
|
211
|
+
fireEvent.click(screen.getByTestId("account-security-password-request"));
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
expect(mockFetch).toHaveBeenCalledTimes(1);
|
|
215
|
+
expect(mockFetch).toHaveBeenCalledWith("/api/hub-session/password", {
|
|
216
|
+
method: "POST",
|
|
217
|
+
credentials: "same-origin",
|
|
218
|
+
headers: { "content-type": "application/json" },
|
|
219
|
+
body: JSON.stringify({ locale: "en" }),
|
|
220
|
+
});
|
|
221
|
+
expect(mockRequestPasswordReset).not.toHaveBeenCalled();
|
|
222
|
+
expect(await screen.findByTestId("account-security-password-sent")).toBeInTheDocument();
|
|
223
|
+
expect(screen.queryByTestId("account-security-password-error")).not.toBeInTheDocument();
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it("anything but a 202 is the failure line, and nothing navigates", async () => {
|
|
227
|
+
hubAnswers({ hasPassword: true });
|
|
228
|
+
mockFetch.mockResolvedValue({ ok: false, status: 503 });
|
|
229
|
+
await renderSecurity();
|
|
230
|
+
|
|
231
|
+
await act(async () => {
|
|
232
|
+
fireEvent.click(screen.getByTestId("account-security-password-request"));
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
expect(await screen.findByTestId("account-security-password-error")).toBeInTheDocument();
|
|
236
|
+
expect(screen.queryByTestId("account-security-password-sent")).not.toBeInTheDocument();
|
|
237
|
+
expect(mockPush).not.toHaveBeenCalled();
|
|
238
|
+
expect(mockRequestPasswordReset).not.toHaveBeenCalled();
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
describe("AC-3 — a hub that answers no state renders the unavailable line, never a form", () => {
|
|
243
|
+
it.each([
|
|
244
|
+
["a hub older than #11162 (no hasPassword)", () => hubAnswers({})],
|
|
245
|
+
["a refused credential", () => mockHubMe.mockResolvedValue({ ok: false, status: 401, body: { ok: false } })],
|
|
246
|
+
["a failed read", () => mockHubMe.mockRejectedValue(new Error("network"))],
|
|
247
|
+
])("%s", async (_label, arrange) => {
|
|
248
|
+
jest.spyOn(console, "error").mockImplementation(() => undefined);
|
|
249
|
+
arrange();
|
|
250
|
+
await renderSecurity();
|
|
251
|
+
|
|
252
|
+
expect(screen.getByTestId("inbox-error")).toHaveTextContent("We couldn't check your password settings.");
|
|
253
|
+
expect(screen.queryByTestId("account-security-password")).not.toBeInTheDocument();
|
|
254
|
+
expect(screen.queryByTestId("account-security-password-request")).not.toBeInTheDocument();
|
|
255
|
+
expect(screen.queryByText(/Sign-in methods/)).toBeNull();
|
|
256
|
+
expectNoPointer();
|
|
257
|
+
});
|
|
258
|
+
});
|