create-ailk 0.36.0 → 0.37.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/component-catalog.json +40 -1
- package/component-catalog.md +7 -5
- package/dist/surfaces.js +60 -19
- package/dist/update.d.ts +19 -1
- package/dist/update.js +293 -35
- 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,50 +1,64 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* account/billing-source.ts (server code) — what User settings › Billing
|
|
3
3
|
* shows (#8232, spec docs/specs/8232-member-settings-account-general-and-spec.md
|
|
4
|
-
* D9).
|
|
4
|
+
* D9; #11165, the hub-read ruling of 2026-11-08).
|
|
5
5
|
*
|
|
6
6
|
* One of the account tree's TWO topology seams (roadmap D1; the other is
|
|
7
7
|
* `sign-in-method.ts`): no other file under the account tree tests
|
|
8
8
|
* `SIGN_IN_PROVIDER`, `TOPOLOGY` or `SIGN_IN_ENABLED`.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
10
|
+
* `loadBilling()` — the plan card and the History rows:
|
|
11
|
+
*
|
|
12
|
+
* - On a spoke that signs in through its hub, the HUB reads them
|
|
13
|
+
* (#11165): `member.billing(init)` with the hub credential answers the
|
|
14
|
+
* caller's vouched customers and, since #11165, `billing` — the plan,
|
|
15
|
+
* the History and whether a portal can open, read through the
|
|
16
|
+
* workspace's Organization's own Stripe connection — so no spoke needs
|
|
17
|
+
* a Stripe key or the commerce module for this page. `source: "hub"`
|
|
18
|
+
* is served as read; its empty History falls back to the member's
|
|
19
|
+
* purchase leads (`member.purchases`, #11096 D9), which carry no
|
|
20
|
+
* receipt. `source: "none"` — the Organization has no usable
|
|
21
|
+
* connection — and an older hub (no `billing`, or a 401, 403 or 404)
|
|
22
|
+
* take the spec 8217 fallback: the spoke's OWN key through the
|
|
23
|
+
* generated seam, `loadSpokeBilling()`, which reaches the rendered
|
|
24
|
+
* `billing/spoke-billing.action.ts` on a spoke that carries commerce
|
|
25
|
+
* and resolves `null` on one that does not — then `none` with no call.
|
|
26
|
+
* `source: "failed"`, or any other non-2xx or a throw, is `failed` —
|
|
27
|
+
* the error row, never a false "you have no subscription".
|
|
17
28
|
* - Otherwise `subscription.me(init, { include: "billing" })` — the plan
|
|
18
29
|
* name and the card summary are #8171's additive fields:
|
|
19
30
|
* - 401, 403 or 404 (the commerce-disabled build answers 404), or a
|
|
20
31
|
* 2xx whose `status` is `null` ⇒ `none` — the caller has no
|
|
21
32
|
* subscription (C9);
|
|
22
33
|
* - any other non-2xx, or a throw ⇒ `failed`, logged with the status
|
|
23
|
-
* or `err.name
|
|
24
|
-
* false "you have no subscription";
|
|
34
|
+
* or `err.name`;
|
|
25
35
|
* - otherwise `subscription`, absent optional fields read as `null`.
|
|
36
|
+
* A single site reads no History here.
|
|
26
37
|
*
|
|
27
|
-
* `
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
38
|
+
* `loadBillingOfferings()` (#11165) — the shown set's share of the page: the
|
|
39
|
+
* base plan, the Upgrade target and the offer card (`billing/offerings.ts`),
|
|
40
|
+
* read through `/pricing`'s own `readShownOfferings` (`lib/pricing-page.ts`:
|
|
41
|
+
* shared per instance for 15 s, so a view costs no API call of its own); a
|
|
42
|
+
* site that is not connected, an expired set or a failed read contributes
|
|
43
|
+
* nothing.
|
|
33
44
|
*
|
|
34
45
|
* `billingPortalUrl()` is the one place a portal URL is minted, for
|
|
35
|
-
* `openBillingPortal` (`actions.ts`):
|
|
36
|
-
*
|
|
46
|
+
* `openBillingPortal` (`actions.ts`): on a hub-mode spoke the hub's
|
|
47
|
+
* `member.billingPortal(init)` (#11165) — a 404 means no portal there (an
|
|
48
|
+
* older hub, no connection, no customer), so the spoke's own key through the
|
|
49
|
+
* same loader is tried; otherwise the hub's portal route. `null` means no
|
|
37
50
|
* portal — the action then redirects nowhere.
|
|
38
51
|
*/
|
|
39
52
|
|
|
53
|
+
import { member, subscription } from "@working-theory/api-client";
|
|
40
54
|
import {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
type
|
|
44
|
-
type
|
|
45
|
-
} from "@working-theory/
|
|
46
|
-
import type { MemberPurchase } from "@working-theory/validation";
|
|
55
|
+
memberBillingPortalResponseSchema,
|
|
56
|
+
memberBillingResponseSchema,
|
|
57
|
+
type MemberBillingPlan,
|
|
58
|
+
type MemberPurchase,
|
|
59
|
+
} from "@working-theory/validation";
|
|
47
60
|
|
|
61
|
+
import { readShownOfferings } from "../../../../lib/pricing-page";
|
|
48
62
|
import { forwardedCookieInit } from "../../../../lib/server-api";
|
|
49
63
|
import {
|
|
50
64
|
SIGN_IN_PROVIDER,
|
|
@@ -53,14 +67,15 @@ import {
|
|
|
53
67
|
} from "../../../../lib/topology.generated";
|
|
54
68
|
|
|
55
69
|
import { logReadFailure } from "./account-data";
|
|
70
|
+
import { billingOfferings, NO_BILLING_OFFERINGS, type BillingOfferings } from "./billing/offerings";
|
|
71
|
+
|
|
72
|
+
/** The plan card's data — the hub's own shape, which the other two reads are mapped into. */
|
|
73
|
+
export type BillingPlanState = MemberBillingPlan;
|
|
56
74
|
|
|
57
75
|
export type BillingState =
|
|
58
76
|
| {
|
|
59
77
|
kind: "subscription";
|
|
60
|
-
|
|
61
|
-
planName: string | null;
|
|
62
|
-
paymentMethod: SubscriptionPaymentMethod | null;
|
|
63
|
-
accessRevokesAt: string | null;
|
|
78
|
+
plan: BillingPlanState;
|
|
64
79
|
portalAvailable: boolean;
|
|
65
80
|
/** Some vouched billing is on a Stripe account this spoke's key cannot read (#8217 D12). */
|
|
66
81
|
unreadable: boolean;
|
|
@@ -68,9 +83,26 @@ export type BillingState =
|
|
|
68
83
|
| { kind: "none"; unreadable: boolean }
|
|
69
84
|
| { kind: "failed" };
|
|
70
85
|
|
|
86
|
+
/** One History row: a hub-read invoice or purchase (with its receipt), or a purchase lead (without). */
|
|
87
|
+
export type BillingHistoryItem = {
|
|
88
|
+
id: string;
|
|
89
|
+
paidAt: string;
|
|
90
|
+
offering: string;
|
|
91
|
+
amountMinor: number | null;
|
|
92
|
+
currency: string | null;
|
|
93
|
+
receiptUrl: string | null;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export type BillingHistoryState = { kind: "items"; items: BillingHistoryItem[] } | { kind: "failed" };
|
|
97
|
+
|
|
98
|
+
export interface BillingRead {
|
|
99
|
+
state: BillingState;
|
|
100
|
+
history: BillingHistoryState;
|
|
101
|
+
}
|
|
102
|
+
|
|
71
103
|
/**
|
|
72
104
|
* The statuses that mean "nothing to show this caller" — no subscription
|
|
73
|
-
* (C9), no purchases (#11096 D9) — rather than a failed read.
|
|
105
|
+
* (C9), no purchases (#11096 D9), no portal (#11165) — rather than a failed read.
|
|
74
106
|
*/
|
|
75
107
|
const NOTHING_TO_SHOW_STATUSES: ReadonlySet<number> = new Set([401, 403, 404]);
|
|
76
108
|
|
|
@@ -79,7 +111,22 @@ function errorName(err: unknown): string {
|
|
|
79
111
|
return err instanceof Error ? err.name : "unknown";
|
|
80
112
|
}
|
|
81
113
|
|
|
82
|
-
|
|
114
|
+
const NO_HISTORY: BillingHistoryState = { kind: "items", items: [] };
|
|
115
|
+
/** The whole read failed: one error row, so History claims nothing of its own. */
|
|
116
|
+
const FAILED: BillingRead = { state: { kind: "failed" }, history: NO_HISTORY };
|
|
117
|
+
|
|
118
|
+
function purchaseRow(purchase: MemberPurchase): BillingHistoryItem {
|
|
119
|
+
return {
|
|
120
|
+
id: purchase.id,
|
|
121
|
+
paidAt: purchase.purchasedAt,
|
|
122
|
+
offering: purchase.offering,
|
|
123
|
+
amountMinor: purchase.amountMinor,
|
|
124
|
+
currency: purchase.currency,
|
|
125
|
+
receiptUrl: null,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** A hub-mode spoke's own-key Billing: the rendered action through the seam, else none (#8217 D10). */
|
|
83
130
|
async function loadSpokeBillingState(): Promise<BillingState> {
|
|
84
131
|
let read: SpokeBillingRead | null;
|
|
85
132
|
try {
|
|
@@ -93,67 +140,148 @@ async function loadSpokeBillingState(): Promise<BillingState> {
|
|
|
93
140
|
if (read.kind !== "subscription") return read;
|
|
94
141
|
return {
|
|
95
142
|
kind: "subscription",
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
143
|
+
plan: {
|
|
144
|
+
name: read.planName,
|
|
145
|
+
status: read.status,
|
|
146
|
+
price: null,
|
|
147
|
+
renewsAt: null,
|
|
148
|
+
accessEndsAt: null,
|
|
149
|
+
card: read.paymentMethod === null ? null : { brand: read.paymentMethod.brand, last4: read.paymentMethod.last4 },
|
|
150
|
+
},
|
|
100
151
|
portalAvailable: true,
|
|
101
152
|
unreadable: read.unreadable,
|
|
102
153
|
};
|
|
103
154
|
}
|
|
104
155
|
|
|
105
|
-
|
|
106
|
-
|
|
156
|
+
/** The member's purchase leads as History rows (#11096 D9) — no receipt; a 401, 403 or 404 is none. */
|
|
157
|
+
async function loadPurchaseHistory(init: { headers: Record<string, string> }): Promise<BillingHistoryState> {
|
|
158
|
+
try {
|
|
159
|
+
const res = await member.purchases(init);
|
|
160
|
+
if (res.ok) return { kind: "items", items: res.body.items.map(purchaseRow) };
|
|
161
|
+
if (NOTHING_TO_SHOW_STATUSES.has(res.status)) return NO_HISTORY;
|
|
162
|
+
console.error(`[account] read failed source=purchases status=${res.status}`);
|
|
163
|
+
return { kind: "failed" };
|
|
164
|
+
} catch (err) {
|
|
165
|
+
logReadFailure("purchases", err);
|
|
166
|
+
return { kind: "failed" };
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** The spec 8217 fallback: the spoke's own key for the plan, the purchase leads for History. */
|
|
171
|
+
async function loadSpokeFallback(init: { headers: Record<string, string> }): Promise<BillingRead> {
|
|
172
|
+
const [state, history] = await Promise.all([loadSpokeBillingState(), loadPurchaseHistory(init)]);
|
|
173
|
+
return { state, history };
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** A hub-mode spoke's Billing (#11165): the hub's read first, the spoke's own key as the fallback. */
|
|
177
|
+
async function loadHubBilling(init: { headers: Record<string, string> }): Promise<BillingRead> {
|
|
178
|
+
let res: Awaited<ReturnType<typeof member.billing>>;
|
|
179
|
+
try {
|
|
180
|
+
res = await member.billing(init);
|
|
181
|
+
} catch (err) {
|
|
182
|
+
logReadFailure("billing", err);
|
|
183
|
+
return FAILED;
|
|
184
|
+
}
|
|
185
|
+
if (!res.ok) {
|
|
186
|
+
if (NOTHING_TO_SHOW_STATUSES.has(res.status)) return loadSpokeFallback(init);
|
|
187
|
+
console.error(`[account] read failed source=billing status=${res.status}`);
|
|
188
|
+
return FAILED;
|
|
189
|
+
}
|
|
190
|
+
// The hub's body is re-parsed here, so a receipt page the History links is
|
|
191
|
+
// a Stripe-hosted https: URL whatever answered (SEC-11165: the hub is the
|
|
192
|
+
// producer, never the spoke's trust anchor).
|
|
193
|
+
const parsed = memberBillingResponseSchema.safeParse(res.body);
|
|
194
|
+
if (!parsed.success) {
|
|
195
|
+
console.error("[account] read failed source=billing outcome=invalid_body");
|
|
196
|
+
return FAILED;
|
|
197
|
+
}
|
|
198
|
+
const billing = parsed.data.billing;
|
|
199
|
+
if (billing === undefined || billing.source === "none") return loadSpokeFallback(init);
|
|
200
|
+
if (billing.source === "failed") {
|
|
201
|
+
console.error("[account] read failed source=billing outcome=hub_read_failed");
|
|
202
|
+
return FAILED;
|
|
203
|
+
}
|
|
204
|
+
const state: BillingState =
|
|
205
|
+
billing.plan === null
|
|
206
|
+
? { kind: "none", unreadable: false }
|
|
207
|
+
: { kind: "subscription", plan: billing.plan, portalAvailable: billing.portalAvailable, unreadable: false };
|
|
208
|
+
const history =
|
|
209
|
+
billing.history.length > 0
|
|
210
|
+
? { kind: "items" as const, items: billing.history }
|
|
211
|
+
: await loadPurchaseHistory(init);
|
|
212
|
+
return { state, history };
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export async function loadBilling(init: { headers: Record<string, string> }): Promise<BillingRead> {
|
|
216
|
+
if (SIGN_IN_PROVIDER === "hub") return loadHubBilling(init);
|
|
107
217
|
try {
|
|
108
218
|
const res = await subscription.me(init, { include: "billing" });
|
|
109
219
|
if (!res.ok) {
|
|
110
|
-
if (NOTHING_TO_SHOW_STATUSES.has(res.status))
|
|
220
|
+
if (NOTHING_TO_SHOW_STATUSES.has(res.status)) {
|
|
221
|
+
return { state: { kind: "none", unreadable: false }, history: NO_HISTORY };
|
|
222
|
+
}
|
|
111
223
|
console.error(`[account] read failed source=billing status=${res.status}`);
|
|
112
|
-
return { kind: "failed" };
|
|
224
|
+
return { state: { kind: "failed" }, history: NO_HISTORY };
|
|
113
225
|
}
|
|
114
226
|
const sub = res.body;
|
|
115
|
-
if (sub.status === null) return { kind: "none", unreadable: false };
|
|
227
|
+
if (sub.status === null) return { state: { kind: "none", unreadable: false }, history: NO_HISTORY };
|
|
228
|
+
const card = sub.paymentMethod ?? null;
|
|
116
229
|
return {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
230
|
+
state: {
|
|
231
|
+
kind: "subscription",
|
|
232
|
+
plan: {
|
|
233
|
+
name: sub.planName ?? null,
|
|
234
|
+
status: sub.status,
|
|
235
|
+
price: null,
|
|
236
|
+
renewsAt: null,
|
|
237
|
+
accessEndsAt: sub.accessRevokesAt,
|
|
238
|
+
card: card === null ? null : { brand: card.brand, last4: card.last4 },
|
|
239
|
+
},
|
|
240
|
+
portalAvailable: sub.portalAvailable,
|
|
241
|
+
unreadable: false,
|
|
242
|
+
},
|
|
243
|
+
history: NO_HISTORY,
|
|
124
244
|
};
|
|
125
245
|
} catch (err) {
|
|
126
246
|
logReadFailure("billing", err);
|
|
127
|
-
return { kind: "failed" };
|
|
247
|
+
return { state: { kind: "failed" }, history: NO_HISTORY };
|
|
128
248
|
}
|
|
129
249
|
}
|
|
130
250
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
-
}
|
|
251
|
+
/** The shown set's share of Billing (#11165): the base plan, the Upgrade target and the offer. */
|
|
252
|
+
export async function loadBillingOfferings(): Promise<BillingOfferings> {
|
|
253
|
+
const read = await readShownOfferings();
|
|
254
|
+
return read.kind === "shown" ? billingOfferings(read.shownSet) : NO_BILLING_OFFERINGS;
|
|
146
255
|
}
|
|
147
256
|
|
|
148
257
|
/**
|
|
149
258
|
* The caller's Stripe billing-portal URL, or `null` for no portal (#8217
|
|
150
|
-
* D10). Minted on a Manage click, never on render: on a hub-mode
|
|
151
|
-
* the
|
|
259
|
+
* D10; #11165). Minted on a Manage click, never on render: on a hub-mode
|
|
260
|
+
* spoke from the hub's member portal route, else — a 404 there — from the
|
|
261
|
+
* spoke's own key (a loader that fails to load is `null`); otherwise from
|
|
152
262
|
* the hub's portal route — `null` on a non-2xx or a throw, logged with the
|
|
153
263
|
* status or `err.name` only.
|
|
154
264
|
*/
|
|
155
265
|
export async function billingPortalUrl(): Promise<string | null> {
|
|
266
|
+
const init = await forwardedCookieInit();
|
|
156
267
|
if (SIGN_IN_PROVIDER === "hub") {
|
|
268
|
+
try {
|
|
269
|
+
const res = await member.billingPortal(init);
|
|
270
|
+
if (res.ok) {
|
|
271
|
+
// Re-parsed before the redirect: a Stripe-hosted https: URL or nothing.
|
|
272
|
+
const url = memberBillingPortalResponseSchema.safeParse(res.body);
|
|
273
|
+
if (url.success) return url.data.url;
|
|
274
|
+
console.error("[openBillingPortal] source=member-billing outcome=invalid_body");
|
|
275
|
+
return null;
|
|
276
|
+
}
|
|
277
|
+
if (res.status !== 404) {
|
|
278
|
+
console.error(`[openBillingPortal] source=member-billing status=${res.status}`);
|
|
279
|
+
return null;
|
|
280
|
+
}
|
|
281
|
+
} catch (err) {
|
|
282
|
+
console.error(`[openBillingPortal] source=member-billing errName=${errorName(err)}`);
|
|
283
|
+
return null;
|
|
284
|
+
}
|
|
157
285
|
try {
|
|
158
286
|
return (await (await loadSpokeBilling())?.portalUrl()) ?? null;
|
|
159
287
|
} catch (err) {
|
|
@@ -161,7 +289,6 @@ export async function billingPortalUrl(): Promise<string | null> {
|
|
|
161
289
|
return null;
|
|
162
290
|
}
|
|
163
291
|
}
|
|
164
|
-
const init = await forwardedCookieInit();
|
|
165
292
|
try {
|
|
166
293
|
const res = await subscription.portalSession(init);
|
|
167
294
|
if (!res.ok) {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* Every field of every served step renders in order (the server checks
|
|
11
11
|
* every one, and evaluates no `showIf`), its copy resolved from the
|
|
12
12
|
* provider's `LocalizedString`s and rendered as text, never markup. Only
|
|
13
|
-
* the
|
|
13
|
+
* the seven input types the server answers render; a step title is a heading
|
|
14
14
|
* only when there is more than one step. Each control posts as
|
|
15
15
|
* `answer.<name>`; a blank optional answer is omitted by the action. No
|
|
16
16
|
* identity field is added — the server takes the name and email from the
|
|
@@ -18,12 +18,18 @@
|
|
|
18
18
|
*
|
|
19
19
|
* Controlled, posting what the state holds, so a refusal keeps every answer.
|
|
20
20
|
* The link is sent as typed (`inputMode="url"`, no browser URL check): the
|
|
21
|
-
* server's https rule is the only one
|
|
21
|
+
* server's https rule is the only one, and its `link_not_https` refusal
|
|
22
|
+
* shows INLINE under the link field whose value is not https (#11155). A
|
|
23
|
+
* `date` field (#11155) is a `DateInput` whose `min` is the member's own
|
|
24
|
+
* today; the server's rule (an ISO date not before today) is the one that
|
|
25
|
+
* counts.
|
|
22
26
|
*/
|
|
23
27
|
|
|
24
28
|
import {
|
|
25
29
|
Button,
|
|
30
|
+
DateInput,
|
|
26
31
|
Heading,
|
|
32
|
+
InlineMessage,
|
|
27
33
|
Input,
|
|
28
34
|
Label,
|
|
29
35
|
Select,
|
|
@@ -33,6 +39,7 @@ import {
|
|
|
33
39
|
SelectValue,
|
|
34
40
|
Text,
|
|
35
41
|
Textarea,
|
|
42
|
+
toIsoDate,
|
|
36
43
|
} from "@working-theory/ui/primitives";
|
|
37
44
|
import {
|
|
38
45
|
resolveLocalizedString,
|
|
@@ -59,11 +66,13 @@ import {
|
|
|
59
66
|
type RequestForm = NonNullable<MemberRequestFormResponse["form"]>;
|
|
60
67
|
type FormField = RequestForm["steps"][number]["fields"][number];
|
|
61
68
|
|
|
62
|
-
/** The input types the requests write answers (`ANSWERABLE`, 8170). */
|
|
63
|
-
const RENDERED = new Set(["text", "email", "tel", "textarea", "select", "url"]);
|
|
69
|
+
/** The input types the requests write answers (`ANSWERABLE`, 8170; `date` #11155). */
|
|
70
|
+
const RENDERED = new Set(["text", "email", "tel", "textarea", "select", "url", "date"]);
|
|
64
71
|
|
|
65
72
|
export interface RequestQuoteLabels extends NewPopupLabels {
|
|
66
73
|
submit: string;
|
|
74
|
+
/** The date picker button's accessible name. */
|
|
75
|
+
pickDate: string;
|
|
67
76
|
}
|
|
68
77
|
|
|
69
78
|
export interface RequestQuoteProps {
|
|
@@ -119,17 +128,38 @@ function RequestQuoteForm({
|
|
|
119
128
|
startTransition(() => dispatch(formData));
|
|
120
129
|
};
|
|
121
130
|
|
|
131
|
+
// A `link_not_https` refusal belongs to the link field(s) whose value is
|
|
132
|
+
// not https; with none to pin it on (the server's rule is stricter than
|
|
133
|
+
// this prefix check), it shows as the form's refusal instead.
|
|
134
|
+
const offendingLinks =
|
|
135
|
+
state.kind === "error" && state.code === "link_not_https"
|
|
136
|
+
? form.steps
|
|
137
|
+
.flatMap((step) => step.fields)
|
|
138
|
+
.filter((field) => {
|
|
139
|
+
const value = answers[field.name] ?? "";
|
|
140
|
+
return field.inputType === "url" && value.trim() !== "" && !value.startsWith("https://");
|
|
141
|
+
})
|
|
142
|
+
.map((field) => field.name)
|
|
143
|
+
: [];
|
|
144
|
+
const formRefusal = state.kind === "error" && offendingLinks.length === 0 ? state.code : null;
|
|
145
|
+
// The member's own calendar day — the date input's `min`.
|
|
146
|
+
const today = toIsoDate(new Date());
|
|
147
|
+
|
|
122
148
|
const renderField = (field: FormField): ReactElement | null => {
|
|
123
149
|
if (!RENDERED.has(field.inputType)) return null;
|
|
124
150
|
const controlId = `${id}-${field.name}`;
|
|
125
151
|
const helpId = `${controlId}-help`;
|
|
152
|
+
const errorId = `${controlId}-error`;
|
|
126
153
|
const help = field.copy.help ? text(field.copy.help) : null;
|
|
154
|
+
const error = offendingLinks.includes(field.name) ? labels.errors.link_not_https : null;
|
|
155
|
+
const describedBy = [help ? helpId : null, error ? errorId : null].filter(Boolean).join(" ");
|
|
127
156
|
const value = answers[field.name] ?? "";
|
|
128
157
|
const common = {
|
|
129
158
|
id: controlId,
|
|
130
159
|
name: `answer.${field.name}`,
|
|
131
160
|
required: field.required === true,
|
|
132
|
-
...(
|
|
161
|
+
...(describedBy ? { "aria-describedby": describedBy } : {}),
|
|
162
|
+
...(error ? { "aria-invalid": true as const } : {}),
|
|
133
163
|
"data-testid": `new-quote-field-${field.name}`,
|
|
134
164
|
};
|
|
135
165
|
const placeholder = field.copy.placeholder ? text(field.copy.placeholder) : undefined;
|
|
@@ -151,7 +181,7 @@ function RequestQuoteForm({
|
|
|
151
181
|
>
|
|
152
182
|
<SelectTrigger
|
|
153
183
|
id={controlId}
|
|
154
|
-
{...(
|
|
184
|
+
{...(describedBy ? { "aria-describedby": describedBy } : {})}
|
|
155
185
|
data-testid={common["data-testid"]}
|
|
156
186
|
>
|
|
157
187
|
<SelectValue {...(placeholder ? { placeholder } : {})} />
|
|
@@ -165,6 +195,16 @@ function RequestQuoteForm({
|
|
|
165
195
|
</SelectContent>
|
|
166
196
|
</Select>
|
|
167
197
|
);
|
|
198
|
+
} else if (field.inputType === "date") {
|
|
199
|
+
control = (
|
|
200
|
+
<DateInput
|
|
201
|
+
{...common}
|
|
202
|
+
value={value}
|
|
203
|
+
min={today}
|
|
204
|
+
pickerLabel={labels.pickDate}
|
|
205
|
+
onValueChange={(next) => setAnswer(field.name, next)}
|
|
206
|
+
/>
|
|
207
|
+
);
|
|
168
208
|
} else {
|
|
169
209
|
control = (
|
|
170
210
|
<Input
|
|
@@ -195,6 +235,11 @@ function RequestQuoteForm({
|
|
|
195
235
|
{help}
|
|
196
236
|
</Text>
|
|
197
237
|
) : null}
|
|
238
|
+
{error ? (
|
|
239
|
+
<InlineMessage id={errorId} variant="error" data-testid={`new-quote-field-${field.name}-error`}>
|
|
240
|
+
{error}
|
|
241
|
+
</InlineMessage>
|
|
242
|
+
) : null}
|
|
198
243
|
</div>
|
|
199
244
|
);
|
|
200
245
|
};
|
|
@@ -212,7 +257,7 @@ function RequestQuoteForm({
|
|
|
212
257
|
{step.fields.map(renderField)}
|
|
213
258
|
</div>
|
|
214
259
|
))}
|
|
215
|
-
{
|
|
260
|
+
{formRefusal ? <NewPopupRefusal code={formRefusal} labels={labels} /> : null}
|
|
216
261
|
<div>
|
|
217
262
|
<Button
|
|
218
263
|
type="submit"
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The account name the contact derives (#11167 ruling 5): "First Last" from
|
|
3
|
+
* the contact's given and family names, and the rule for when the account
|
|
4
|
+
* name may follow it — while it is empty, or equals what the PREVIOUS contact
|
|
5
|
+
* derived, so a name the person set by hand is never overwritten.
|
|
6
|
+
*
|
|
7
|
+
* Not in `contact-actions.ts`: Next.js makes every runtime export of a
|
|
8
|
+
* "use server" file a Server Action and fails the build on a synchronous one
|
|
9
|
+
* (the `invitation-id.ts` rule, #11141).
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { PROFILE_NAME_MAX } from "@working-theory/validation";
|
|
13
|
+
|
|
14
|
+
export type ContactNames = { givenName: string | null; familyName: string | null } | null;
|
|
15
|
+
|
|
16
|
+
/** "First Last", trimmed and cut to the profile name's width; `""` with neither name. */
|
|
17
|
+
export function derivedAccountName(contact: ContactNames): string {
|
|
18
|
+
return [contact?.givenName, contact?.familyName]
|
|
19
|
+
.map((part) => part?.trim() ?? "")
|
|
20
|
+
.filter((part) => part !== "")
|
|
21
|
+
.join(" ")
|
|
22
|
+
.slice(0, PROFILE_NAME_MAX)
|
|
23
|
+
.trim();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Whether the account name may follow the contact: it is empty, or it is
|
|
28
|
+
* exactly what the previous contact derived (so it was never set by hand).
|
|
29
|
+
*/
|
|
30
|
+
export function accountNameFollowsContact(
|
|
31
|
+
current: string | null | undefined,
|
|
32
|
+
previous: ContactNames,
|
|
33
|
+
): boolean {
|
|
34
|
+
const name = current?.trim() ?? "";
|
|
35
|
+
return name === "" || name === derivedAccountName(previous);
|
|
36
|
+
}
|
|
@@ -20,6 +20,20 @@
|
|
|
20
20
|
* another account), else `failed`. Logs carry a status or `err.name` only —
|
|
21
21
|
* never a name, a number, an address or an email.
|
|
22
22
|
*
|
|
23
|
+
* #11167 ruling 5 — the account name follows the contact. The member General
|
|
24
|
+
* renders no Name field; after a save that succeeded, `followContactName`
|
|
25
|
+
* derives "First Last" from the saved contact's given and family names and
|
|
26
|
+
* writes it as the account name (`member.updateProfile({ name })`, then the
|
|
27
|
+
* hub-session re-seal) ONLY while the account name is empty or equals the
|
|
28
|
+
* value the PREVIOUS contact derived — a name the person set by hand (on the
|
|
29
|
+
* Admin, or before this ruling) is never overwritten. The rule itself is
|
|
30
|
+
* `account-name.ts`. The account name is the stored one (`member.profile`,
|
|
31
|
+
* never the session's copy, which a spoke's cookie holds from its last
|
|
32
|
+
* re-seal), and the previous contact is `member.contact`, both read before
|
|
33
|
+
* the save; an unreadable name follows nothing, an unreadable contact counts
|
|
34
|
+
* as none, so only an empty name is then followed. A failed follow is logged
|
|
35
|
+
* and the save still answers `{ ok: true }`: the contact IS saved.
|
|
36
|
+
*
|
|
23
37
|
* Not a `*.actions.ts` file and no `*Action`-suffixed export: the write has no
|
|
24
38
|
* MCP twin by decision (8435 D12), and apps/mcp's parity test reads that
|
|
25
39
|
* suffix.
|
|
@@ -27,8 +41,11 @@
|
|
|
27
41
|
|
|
28
42
|
import { member } from "@working-theory/api-client";
|
|
29
43
|
|
|
44
|
+
import { resealHubSession } from "../../../../../lib/hub-session/reseal";
|
|
30
45
|
import { forwardedCookieInit } from "../../../../../lib/server-api";
|
|
31
46
|
|
|
47
|
+
import { accountNameFollowsContact, type ContactNames, derivedAccountName } from "./account-name";
|
|
48
|
+
|
|
32
49
|
/** PII-safe error identity for logs (the `profile-actions.ts` idiom: `err.name` only). */
|
|
33
50
|
function errorName(err: unknown): string {
|
|
34
51
|
return err instanceof Error ? err.name : "unknown";
|
|
@@ -50,6 +67,52 @@ export type SaveContactResult =
|
|
|
50
67
|
reason: "telephone" | "invalid" | "unverified" | "unavailable" | "failed";
|
|
51
68
|
};
|
|
52
69
|
|
|
70
|
+
type Init = Awaited<ReturnType<typeof forwardedCookieInit>>;
|
|
71
|
+
|
|
72
|
+
/** The person's confirmed contact before the save, or `null` when unread. */
|
|
73
|
+
async function previousContact(init: Init): Promise<ContactNames> {
|
|
74
|
+
try {
|
|
75
|
+
const res = await member.contact(init);
|
|
76
|
+
return res.ok ? res.body.contact : null;
|
|
77
|
+
} catch {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** The stored account name (`""` when none), or `undefined` when it cannot be read. */
|
|
83
|
+
async function currentAccountName(init: Init): Promise<string | undefined> {
|
|
84
|
+
try {
|
|
85
|
+
const res = await member.profile(init);
|
|
86
|
+
return res.ok ? (res.body.name ?? "") : undefined;
|
|
87
|
+
} catch {
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Writes the derived name as the account name when the rule allows; never throws. */
|
|
93
|
+
async function followContactName(
|
|
94
|
+
current: string | undefined,
|
|
95
|
+
previous: ContactNames,
|
|
96
|
+
next: ContactNames,
|
|
97
|
+
init: Init,
|
|
98
|
+
): Promise<void> {
|
|
99
|
+
const derived = derivedAccountName(next);
|
|
100
|
+
if (derived === "" || current === undefined) return;
|
|
101
|
+
if (!accountNameFollowsContact(current, previous) || current.trim() === derived) return;
|
|
102
|
+
try {
|
|
103
|
+
const res = await member.updateProfile({ name: derived }, init);
|
|
104
|
+
if (!res.ok) {
|
|
105
|
+
console.error(`[contact-actions] followContactName status=${res.status}`);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if ((await resealHubSession()) === "failed") {
|
|
109
|
+
console.error("[contact-actions] followContactName reseal=failed");
|
|
110
|
+
}
|
|
111
|
+
} catch (err) {
|
|
112
|
+
console.error(`[contact-actions] followContactName errName=${errorName(err)}`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
53
116
|
export async function saveContact(
|
|
54
117
|
input: Parameters<typeof member.updateContact>[0],
|
|
55
118
|
): Promise<SaveContactResult> {
|
|
@@ -59,8 +122,13 @@ export async function saveContact(
|
|
|
59
122
|
return { ok: false, reason: "invalid" };
|
|
60
123
|
|
|
61
124
|
try {
|
|
62
|
-
const
|
|
63
|
-
|
|
125
|
+
const init = await forwardedCookieInit();
|
|
126
|
+
const [previous, current] = await Promise.all([previousContact(init), currentAccountName(init)]);
|
|
127
|
+
const res = await member.updateContact(input, init);
|
|
128
|
+
if (res.ok) {
|
|
129
|
+
await followContactName(current, previous, res.body.contact, init);
|
|
130
|
+
return { ok: true };
|
|
131
|
+
}
|
|
64
132
|
console.error(`[contact-actions] saveContact status=${res.status}`);
|
|
65
133
|
if (res.status === 400) {
|
|
66
134
|
return {
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use client"; // owns the router.refresh() that follows a contact save
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ContactDetails — User settings › General's contact section on the member
|
|
5
|
+
* path (#8435 D13; #11167 ruling 5): the shared `AccountContactDetails` over
|
|
6
|
+
* `saveContact`, plus one thing the server action cannot do — after a save
|
|
7
|
+
* that succeeded it refreshes the route, so the rail's name shows the
|
|
8
|
+
* "First Last" the save may have derived for the account.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
AccountContactDetails,
|
|
13
|
+
type AccountContact,
|
|
14
|
+
type AccountContactLabels,
|
|
15
|
+
type AccountContactSaveResult,
|
|
16
|
+
} from "@working-theory/templates/account";
|
|
17
|
+
import { useRouter } from "next/navigation";
|
|
18
|
+
import type { ReactElement } from "react";
|
|
19
|
+
|
|
20
|
+
import { saveContact } from "./contact-actions";
|
|
21
|
+
|
|
22
|
+
export function ContactDetails({
|
|
23
|
+
contact,
|
|
24
|
+
labels,
|
|
25
|
+
}: {
|
|
26
|
+
contact: AccountContact | null;
|
|
27
|
+
labels: AccountContactLabels;
|
|
28
|
+
}): ReactElement {
|
|
29
|
+
const router = useRouter();
|
|
30
|
+
|
|
31
|
+
async function onSave(
|
|
32
|
+
next: AccountContact,
|
|
33
|
+
): Promise<AccountContactSaveResult> {
|
|
34
|
+
const result = await saveContact(next);
|
|
35
|
+
if (result.ok) router.refresh();
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<AccountContactDetails contact={contact} labels={labels} onSave={onSave} />
|
|
41
|
+
);
|
|
42
|
+
}
|