create-ailk 0.35.1 → 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/README.md +1 -1
- package/component-catalog.json +51 -1
- package/component-catalog.md +8 -5
- package/dist/lib/env-catalog.js +8 -0
- package/dist/surfaces.js +66 -22
- package/dist/topology.d.ts +4 -4
- package/dist/topology.js +104 -60
- package/dist/update.d.ts +19 -1
- package/dist/update.js +293 -35
- package/package.json +3 -3
- package/templates/.env.example +38 -0
- package/templates/apps/api/.env.example +45 -0
- package/templates/apps/api/CLAUDE.md +12 -4
- package/templates/apps/api/src/lib/__mocks__/prisma.ts +7 -0
- package/templates/apps/mcp/CLAUDE.md +4 -2
- package/templates/apps/web/.env.example +16 -0
- package/templates/apps/web/CLAUDE.md +73 -5
- package/templates/apps/web/app/[locale]/(auth)/__tests__/password-reset.test.tsx +2 -0
- 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]/(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 +241 -66
- 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 +377 -151
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/item.test.tsx +26 -1
- 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__/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 +20 -4
- 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 +323 -73
- package/templates/apps/web/app/[locale]/(authed)/account/billing-source.ts +199 -43
- package/templates/apps/web/app/[locale]/(authed)/account/components/request-quote.tsx +52 -7
- 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/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 +97 -53
- 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 +215 -0
- 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/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 +9 -6
- 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 +21 -22
- 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]/(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]/results/[payload]/ResultsClient.tsx +3 -2
- package/templates/apps/web/app/[locale]/layout.tsx +24 -75
- 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 +166 -7
- package/templates/apps/web/app/api/auth/hub/authorize/route.ts +96 -30
- 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/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/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 +738 -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/password/return/route.ts +69 -0
- package/templates/apps/web/app/api/hub-session/password/route.ts +106 -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/auth.ts +133 -6
- package/templates/apps/web/components/sign-out-trigger.tsx +1 -1
- package/templates/apps/web/lib/__tests__/account-config.test.ts +129 -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__/offerings-pricing.test.ts +33 -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 +132 -8
- 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-routes.ts +11 -6
- 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/offerings-pricing.ts +4 -1
- package/templates/apps/web/lib/site-header.ts +14 -1
- 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 +264 -96
- package/templates/apps/web/middleware.ts +34 -2
- package/templates/apps/web/security-headers.config.ts +21 -0
- 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
- 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
|
@@ -1,41 +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.
|
|
37
|
+
*
|
|
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.
|
|
26
44
|
*
|
|
27
45
|
* `billingPortalUrl()` is the one place a portal URL is minted, for
|
|
28
|
-
* `openBillingPortal` (`actions.ts`):
|
|
29
|
-
*
|
|
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
|
|
30
50
|
* portal — the action then redirects nowhere.
|
|
31
51
|
*/
|
|
32
52
|
|
|
53
|
+
import { member, subscription } from "@working-theory/api-client";
|
|
33
54
|
import {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
type
|
|
37
|
-
|
|
55
|
+
memberBillingPortalResponseSchema,
|
|
56
|
+
memberBillingResponseSchema,
|
|
57
|
+
type MemberBillingPlan,
|
|
58
|
+
type MemberPurchase,
|
|
59
|
+
} from "@working-theory/validation";
|
|
38
60
|
|
|
61
|
+
import { readShownOfferings } from "../../../../lib/pricing-page";
|
|
39
62
|
import { forwardedCookieInit } from "../../../../lib/server-api";
|
|
40
63
|
import {
|
|
41
64
|
SIGN_IN_PROVIDER,
|
|
@@ -44,14 +67,15 @@ import {
|
|
|
44
67
|
} from "../../../../lib/topology.generated";
|
|
45
68
|
|
|
46
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;
|
|
47
74
|
|
|
48
75
|
export type BillingState =
|
|
49
76
|
| {
|
|
50
77
|
kind: "subscription";
|
|
51
|
-
|
|
52
|
-
planName: string | null;
|
|
53
|
-
paymentMethod: SubscriptionPaymentMethod | null;
|
|
54
|
-
accessRevokesAt: string | null;
|
|
78
|
+
plan: BillingPlanState;
|
|
55
79
|
portalAvailable: boolean;
|
|
56
80
|
/** Some vouched billing is on a Stripe account this spoke's key cannot read (#8217 D12). */
|
|
57
81
|
unreadable: boolean;
|
|
@@ -59,15 +83,50 @@ export type BillingState =
|
|
|
59
83
|
| { kind: "none"; unreadable: boolean }
|
|
60
84
|
| { kind: "failed" };
|
|
61
85
|
|
|
62
|
-
/**
|
|
63
|
-
|
|
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
|
+
|
|
103
|
+
/**
|
|
104
|
+
* The statuses that mean "nothing to show this caller" — no subscription
|
|
105
|
+
* (C9), no purchases (#11096 D9), no portal (#11165) — rather than a failed read.
|
|
106
|
+
*/
|
|
107
|
+
const NOTHING_TO_SHOW_STATUSES: ReadonlySet<number> = new Set([401, 403, 404]);
|
|
64
108
|
|
|
65
109
|
/** PII-safe error identity for logs (the `checkout.actions.ts` idiom: `err.name` only). */
|
|
66
110
|
function errorName(err: unknown): string {
|
|
67
111
|
return err instanceof Error ? err.name : "unknown";
|
|
68
112
|
}
|
|
69
113
|
|
|
70
|
-
|
|
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). */
|
|
71
130
|
async function loadSpokeBillingState(): Promise<BillingState> {
|
|
72
131
|
let read: SpokeBillingRead | null;
|
|
73
132
|
try {
|
|
@@ -81,50 +140,148 @@ async function loadSpokeBillingState(): Promise<BillingState> {
|
|
|
81
140
|
if (read.kind !== "subscription") return read;
|
|
82
141
|
return {
|
|
83
142
|
kind: "subscription",
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
+
},
|
|
88
151
|
portalAvailable: true,
|
|
89
152
|
unreadable: read.unreadable,
|
|
90
153
|
};
|
|
91
154
|
}
|
|
92
155
|
|
|
93
|
-
|
|
94
|
-
|
|
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);
|
|
95
217
|
try {
|
|
96
218
|
const res = await subscription.me(init, { include: "billing" });
|
|
97
219
|
if (!res.ok) {
|
|
98
|
-
if (
|
|
220
|
+
if (NOTHING_TO_SHOW_STATUSES.has(res.status)) {
|
|
221
|
+
return { state: { kind: "none", unreadable: false }, history: NO_HISTORY };
|
|
222
|
+
}
|
|
99
223
|
console.error(`[account] read failed source=billing status=${res.status}`);
|
|
100
|
-
return { kind: "failed" };
|
|
224
|
+
return { state: { kind: "failed" }, history: NO_HISTORY };
|
|
101
225
|
}
|
|
102
226
|
const sub = res.body;
|
|
103
|
-
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;
|
|
104
229
|
return {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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,
|
|
112
244
|
};
|
|
113
245
|
} catch (err) {
|
|
114
246
|
logReadFailure("billing", err);
|
|
115
|
-
return { kind: "failed" };
|
|
247
|
+
return { state: { kind: "failed" }, history: NO_HISTORY };
|
|
116
248
|
}
|
|
117
249
|
}
|
|
118
250
|
|
|
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;
|
|
255
|
+
}
|
|
256
|
+
|
|
119
257
|
/**
|
|
120
258
|
* The caller's Stripe billing-portal URL, or `null` for no portal (#8217
|
|
121
|
-
* D10). Minted on a Manage click, never on render: on a hub-mode
|
|
122
|
-
* 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
|
|
123
262
|
* the hub's portal route — `null` on a non-2xx or a throw, logged with the
|
|
124
263
|
* status or `err.name` only.
|
|
125
264
|
*/
|
|
126
265
|
export async function billingPortalUrl(): Promise<string | null> {
|
|
266
|
+
const init = await forwardedCookieInit();
|
|
127
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
|
+
}
|
|
128
285
|
try {
|
|
129
286
|
return (await (await loadSpokeBilling())?.portalUrl()) ?? null;
|
|
130
287
|
} catch (err) {
|
|
@@ -132,7 +289,6 @@ export async function billingPortalUrl(): Promise<string | null> {
|
|
|
132
289
|
return null;
|
|
133
290
|
}
|
|
134
291
|
}
|
|
135
|
-
const init = await forwardedCookieInit();
|
|
136
292
|
try {
|
|
137
293
|
const res = await subscription.portalSession(init);
|
|
138
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"
|
|
@@ -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>
|