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.
Files changed (169) hide show
  1. package/README.md +1 -1
  2. package/component-catalog.json +51 -1
  3. package/component-catalog.md +8 -5
  4. package/dist/lib/env-catalog.js +8 -0
  5. package/dist/surfaces.js +66 -22
  6. package/dist/topology.d.ts +4 -4
  7. package/dist/topology.js +104 -60
  8. package/dist/update.d.ts +19 -1
  9. package/dist/update.js +293 -35
  10. package/package.json +3 -3
  11. package/templates/.env.example +38 -0
  12. package/templates/apps/api/.env.example +45 -0
  13. package/templates/apps/api/CLAUDE.md +12 -4
  14. package/templates/apps/api/src/lib/__mocks__/prisma.ts +7 -0
  15. package/templates/apps/mcp/CLAUDE.md +4 -2
  16. package/templates/apps/web/.env.example +16 -0
  17. package/templates/apps/web/CLAUDE.md +73 -5
  18. package/templates/apps/web/app/[locale]/(auth)/__tests__/password-reset.test.tsx +2 -0
  19. package/templates/apps/web/app/[locale]/(auth)/reset-password/__tests__/return.test.tsx +179 -0
  20. package/templates/apps/web/app/[locale]/(auth)/reset-password/page.tsx +22 -2
  21. package/templates/apps/web/app/[locale]/(auth)/reset-password/reset-password-card.tsx +9 -2
  22. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/page.test.tsx +52 -1
  23. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/remembered-method.test.ts +43 -0
  24. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/sign-in-card.test.tsx +108 -1
  25. package/templates/apps/web/app/[locale]/(auth)/sign-in/page.tsx +36 -3
  26. package/templates/apps/web/app/[locale]/(auth)/sign-in/remembered-method.ts +37 -0
  27. package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-card.tsx +90 -33
  28. package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-text.ts +9 -4
  29. package/templates/apps/web/app/[locale]/(authed)/__tests__/gate.test.tsx +79 -348
  30. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/billing.test.tsx +241 -66
  31. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/general.test.tsx +242 -28
  32. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/hub-mode.test.tsx +377 -151
  33. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/item.test.tsx +26 -1
  34. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout-sign-out.test.tsx +10 -5
  35. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout.test.tsx +17 -6
  36. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-menu.test.tsx +51 -12
  37. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-popups.test.tsx +17 -2
  38. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/notifications.test.tsx +153 -2
  39. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/page.test.tsx +206 -23
  40. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/popups.test.tsx +150 -188
  41. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/privacy.test.tsx +235 -177
  42. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/rich-translator.ts +63 -0
  43. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/security.test.tsx +0 -3
  44. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/thread.test.tsx +340 -0
  45. package/templates/apps/web/app/[locale]/(authed)/account/account-data.ts +7 -5
  46. package/templates/apps/web/app/[locale]/(authed)/account/account-frame.tsx +20 -4
  47. package/templates/apps/web/app/[locale]/(authed)/account/actions.ts +8 -4
  48. package/templates/apps/web/app/[locale]/(authed)/account/appointments/[slug]/page.tsx +161 -0
  49. package/templates/apps/web/app/[locale]/(authed)/account/appointments/__tests__/page.test.tsx +426 -0
  50. package/templates/apps/web/app/[locale]/(authed)/account/appointments/appointments-data.ts +76 -0
  51. package/templates/apps/web/app/[locale]/(authed)/account/appointments/page.tsx +139 -0
  52. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/page.tsx +92 -24
  53. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/versions/[version]/file/route.ts +32 -1
  54. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/file-route.test.ts +76 -3
  55. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/page.test.tsx +290 -41
  56. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/artifact-data.ts +109 -11
  57. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/page.tsx +43 -44
  58. package/templates/apps/web/app/[locale]/(authed)/account/billing/__tests__/offerings.test.ts +99 -0
  59. package/templates/apps/web/app/[locale]/(authed)/account/billing/offerings.ts +123 -0
  60. package/templates/apps/web/app/[locale]/(authed)/account/billing/page.tsx +323 -73
  61. package/templates/apps/web/app/[locale]/(authed)/account/billing-source.ts +199 -43
  62. package/templates/apps/web/app/[locale]/(authed)/account/components/request-quote.tsx +52 -7
  63. package/templates/apps/web/app/[locale]/(authed)/account/connect/__tests__/page.test.tsx +8 -1
  64. package/templates/apps/web/app/[locale]/(authed)/account/connect/page.tsx +7 -3
  65. package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/phone-verification.test.tsx +215 -0
  66. package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/seam-imports.test.ts +65 -0
  67. package/templates/apps/web/app/[locale]/(authed)/account/general/account-name.ts +36 -0
  68. package/templates/apps/web/app/[locale]/(authed)/account/general/contact-actions.ts +70 -2
  69. package/templates/apps/web/app/[locale]/(authed)/account/general/contact-details.tsx +42 -0
  70. package/templates/apps/web/app/[locale]/(authed)/account/general/page.tsx +97 -53
  71. package/templates/apps/web/app/[locale]/(authed)/account/general/phone-actions.ts +122 -0
  72. package/templates/apps/web/app/[locale]/(authed)/account/general/phone-verification.tsx +215 -0
  73. package/templates/apps/web/app/[locale]/(authed)/account/general/photo-actions.ts +73 -0
  74. package/templates/apps/web/app/[locale]/(authed)/account/general/profile-form.tsx +12 -9
  75. package/templates/apps/web/app/[locale]/(authed)/account/general/profile-source.ts +18 -4
  76. package/templates/apps/web/app/[locale]/(authed)/account/inbox/[kind]/[id]/page.tsx +20 -2
  77. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/member-thread-composer.tsx +43 -0
  78. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/page.tsx +125 -0
  79. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-data.ts +88 -0
  80. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-write.ts +31 -0
  81. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/invitation-id.test.ts +35 -0
  82. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/page.test.tsx +266 -0
  83. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/actions.ts +116 -0
  84. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/invitation-id.ts +12 -0
  85. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/page.tsx +154 -0
  86. package/templates/apps/web/app/[locale]/(authed)/account/layout.tsx +9 -6
  87. package/templates/apps/web/app/[locale]/(authed)/account/new-menu.tsx +33 -8
  88. package/templates/apps/web/app/[locale]/(authed)/account/new-popups.tsx +31 -52
  89. package/templates/apps/web/app/[locale]/(authed)/account/notifications/page.tsx +44 -4
  90. package/templates/apps/web/app/[locale]/(authed)/account/page.tsx +69 -49
  91. package/templates/apps/web/app/[locale]/(authed)/account/privacy/__tests__/export-route.test.ts +173 -0
  92. package/templates/apps/web/app/[locale]/(authed)/account/privacy/actions.ts +42 -4
  93. package/templates/apps/web/app/[locale]/(authed)/account/privacy/export/route.ts +102 -0
  94. package/templates/apps/web/app/[locale]/(authed)/account/privacy/page.tsx +147 -137
  95. package/templates/apps/web/app/[locale]/(authed)/account/security/__tests__/hub-variant.test.tsx +258 -0
  96. package/templates/apps/web/app/[locale]/(authed)/account/security/page.tsx +21 -22
  97. package/templates/apps/web/app/[locale]/(authed)/account/security/security-panel.tsx +34 -6
  98. package/templates/apps/web/app/[locale]/(authed)/account/security/security-source.ts +37 -7
  99. package/templates/apps/web/app/[locale]/(authed)/account/settings/page.tsx +0 -2
  100. package/templates/apps/web/app/[locale]/(authed)/account/settings-frame.tsx +8 -5
  101. package/templates/apps/web/app/[locale]/(authed)/layout.tsx +15 -13
  102. package/templates/apps/web/app/[locale]/(authed)/signed-out-gate.generated.tsx +20 -52
  103. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsClient.tsx +3 -2
  104. package/templates/apps/web/app/[locale]/layout.tsx +24 -75
  105. package/templates/apps/web/app/[locale]/purchase/__tests__/success.test.tsx +50 -0
  106. package/templates/apps/web/app/[locale]/purchase/success/page.tsx +48 -7
  107. package/templates/apps/web/app/api/auth/hub/__tests__/entry-routes.test.ts +749 -0
  108. package/templates/apps/web/app/api/auth/hub/authorize/__tests__/route.test.ts +166 -7
  109. package/templates/apps/web/app/api/auth/hub/authorize/route.ts +96 -30
  110. package/templates/apps/web/app/api/auth/hub/continuation.ts +51 -2
  111. package/templates/apps/web/app/api/auth/hub/email/route.ts +111 -0
  112. package/templates/apps/web/app/api/auth/hub/entry-shared.ts +163 -0
  113. package/templates/apps/web/app/api/auth/hub/password/__tests__/return.test.ts +86 -0
  114. package/templates/apps/web/app/api/auth/hub/password/__tests__/route.test.ts +368 -0
  115. package/templates/apps/web/app/api/auth/hub/password/return.ts +86 -0
  116. package/templates/apps/web/app/api/auth/hub/password/route.ts +171 -0
  117. package/templates/apps/web/app/api/auth/hub/purchase/route.ts +230 -0
  118. package/templates/apps/web/app/api/auth/hub/purchase-link/route.ts +174 -0
  119. package/templates/apps/web/app/api/auth/hub/sign-up/route.ts +60 -0
  120. package/templates/apps/web/app/api/auth/hub/sign-up-evidence.ts +97 -0
  121. package/templates/apps/web/app/api/hub-session/__tests__/routes.test.ts +738 -7
  122. package/templates/apps/web/app/api/hub-session/callback/route.ts +13 -47
  123. package/templates/apps/web/app/api/hub-session/email/route.ts +125 -0
  124. package/templates/apps/web/app/api/hub-session/one-tap/nonce/route.ts +49 -0
  125. package/templates/apps/web/app/api/hub-session/one-tap/route.ts +106 -0
  126. package/templates/apps/web/app/api/hub-session/open/route.ts +111 -0
  127. package/templates/apps/web/app/api/hub-session/password/return/route.ts +69 -0
  128. package/templates/apps/web/app/api/hub-session/password/route.ts +106 -0
  129. package/templates/apps/web/app/api/hub-session/sign-in/route.ts +23 -40
  130. package/templates/apps/web/app/api/hub-session/sign-out/route.ts +1 -10
  131. package/templates/apps/web/auth.ts +133 -6
  132. package/templates/apps/web/components/sign-out-trigger.tsx +1 -1
  133. package/templates/apps/web/lib/__tests__/account-config.test.ts +129 -1
  134. package/templates/apps/web/lib/__tests__/auth-email.test.ts +141 -0
  135. package/templates/apps/web/lib/__tests__/auth-phone.test.ts +445 -0
  136. package/templates/apps/web/lib/__tests__/auth-sms.test.ts +140 -0
  137. package/templates/apps/web/lib/__tests__/fixtures/tsconfig.flow.json +18 -0
  138. package/templates/apps/web/lib/__tests__/offerings-pricing.test.ts +33 -0
  139. package/templates/apps/web/lib/__tests__/site-header.test.ts +13 -0
  140. package/templates/apps/web/lib/__tests__/telemetry-scrub.test.ts +19 -1
  141. package/templates/apps/web/lib/account-config.ts +132 -8
  142. package/templates/apps/web/lib/auth-email.ts +62 -6
  143. package/templates/apps/web/lib/auth-env.ts +13 -0
  144. package/templates/apps/web/lib/auth-routes.ts +11 -6
  145. package/templates/apps/web/lib/auth-sms.ts +180 -0
  146. package/templates/apps/web/lib/hub-session/__tests__/hub-session.test.ts +28 -0
  147. package/templates/apps/web/lib/hub-session/__tests__/spoke-sign-in.test.tsx +332 -0
  148. package/templates/apps/web/lib/hub-session/config.ts +7 -1
  149. package/templates/apps/web/lib/hub-session/entry.ts +238 -0
  150. package/templates/apps/web/lib/hub-session/index.ts +1 -4
  151. package/templates/apps/web/lib/hub-session/one-tap.tsx +148 -0
  152. package/templates/apps/web/lib/hub-session/session.ts +120 -2
  153. package/templates/apps/web/lib/hub-session/spoke-sign-in.tsx +277 -0
  154. package/templates/apps/web/lib/offerings-pricing.ts +4 -1
  155. package/templates/apps/web/lib/site-header.ts +14 -1
  156. package/templates/apps/web/lib/telemetry-scrub.ts +11 -0
  157. package/templates/apps/web/lib/topology.generated.ts +39 -0
  158. package/templates/apps/web/messages/en.json +264 -96
  159. package/templates/apps/web/middleware.ts +34 -2
  160. package/templates/apps/web/security-headers.config.ts +21 -0
  161. package/versions.json +48 -48
  162. package/templates/apps/web/app/[locale]/(authed)/account/components/schedule-service.tsx +0 -276
  163. package/templates/apps/web/app/[locale]/(authed)/account/components/send-message.tsx +0 -128
  164. package/templates/apps/web/app/[locale]/(authed)/account/settings/__tests__/theme-modes.test.ts +0 -42
  165. package/templates/apps/web/app/[locale]/(authed)/account/settings/theme-modes.ts +0 -40
  166. package/templates/apps/web/app/[locale]/(authed)/sign-in-gate.tsx +0 -162
  167. package/templates/apps/web/components/signed-in-nav.tsx +0 -79
  168. package/templates/apps/web/lib/hub-session/__tests__/sign-in-gate.test.tsx +0 -180
  169. package/templates/apps/web/lib/hub-session/sign-in-gate.tsx +0 -162
@@ -1,41 +1,74 @@
1
1
  /**
2
- * /[locale]/account/billing — User settings › Billing (#8339 D8; builds on
3
- * #8232 D9, AC-MAA-19).
2
+ * /[locale]/account/billing — User settings › Billing (#8339 D8; #11165,
3
+ * the operator's rulings of 2026-11-08 against the organization Billing's
4
+ * card shape).
4
5
  *
5
6
  * RSC, outside the account layout's SignedInShell (#8430), in the member's
6
- * four-tab settings frame (D7) — standalone, the Admin's shape. Lays out like the Admin's
7
- * organization Billing page (`OrgBillingPanel`'s `current-plan` layout):
8
- * the shared `CurrentPlanCard` (@working-theory/templates/account, spec
9
- * 8339 D5), by `loadBilling()`'s answer (`billing-source.ts`, the billing
10
- * topology seam):
7
+ * settings frame (D7) — since #11167 every group is a card the pane draws.
8
+ * The page, top to bottom, by `loadBilling()` and `loadBillingOfferings()`
9
+ * (`billing-source.ts`, the billing topology seam):
11
10
  *
12
- * - a subscription — the plan (or `unnamedPlan`), the status plus when
13
- * access ends (when set, C4 — `subscription.me` carries no price), the
14
- * card on file, then Manage billing when a portal is available;
15
- * - no subscription — the same card shape with the plain line and no
16
- * button (C5);
17
- * - a failed read — the area's error row with Retry, never a false "you
18
- * have no subscription".
11
+ * (A) the OFFER CARD — the first live Offer product of the shown set
12
+ * (#11166), when the workspace shows one: its Stripe name, description
13
+ * and first image, Claim offer to the Offerings checkout, an x that
14
+ * dismisses it for this person (`OfferCard`, remembered under a key
15
+ * derived from the person's email, never the email itself);
16
+ * (B) the PLAN CARD, one of two (`CurrentPlanCard`): (B1) a current
17
+ * subscription — the plan name with its price beside it, one line
18
+ * ("Renews on December 1 · Visa 4242"; "Payment due"; "Access ends
19
+ * <date>") and Manage plan, which opens Stripe's Customer Portal and
20
+ * returns here; (B2) no subscription — the shown set's lowest-priced
21
+ * live plan, its Stripe description (or the fallback line until the
22
+ * operator sets one) and Upgrade to the Offerings checkout for the
23
+ * next live plan above it by price; a shown set with no live plan
24
+ * renders no plan card. A failed read is the error row with Retry,
25
+ * never a false "no subscription";
26
+ * (C) HISTORY — the member's paid invoices and purchases, newest first,
27
+ * Date (MM/DD/YYYY) · Offering · Amount · Receipt (`BillingHistoryCard`),
28
+ * absent when there are none.
19
29
  *
20
- * After any of the three, one plain line when some of the member's billing
21
- * is on a Stripe account this spoke's key cannot read (#8217 D12), then
22
- * each section a module contributes (`accountBillingSections`, #8231 D4),
23
- * then each section the site adds (`siteBillingSections`, #9401 D7).
30
+ * Then one plain line when some of the member's billing is on a Stripe
31
+ * account this spoke's key cannot read (#8217 D12), each section a module
32
+ * contributes (`accountBillingSections`, #8231 D4) and each the site adds
33
+ * (`siteBillingSections`, #9401 D7). The old "Current plan" heading, the
34
+ * plain purchases list and "You don't have a subscription." are gone.
24
35
  */
25
36
 
26
- import { AccountSettingsFrame, AccountSettingsPane, CurrentPlanCard } from "@working-theory/templates/account";
27
- import { Button, Text } from "@working-theory/ui/primitives";
37
+ import { createHash } from "node:crypto";
38
+
39
+ import {
40
+ AccountSettingsFrame,
41
+ AccountSettingsPane,
42
+ BillingHistoryCard,
43
+ CurrentPlanCard,
44
+ OfferCard,
45
+ type BillingHistoryRowView,
46
+ } from "@working-theory/templates/account";
47
+ import { Button, Link, MoneyAmount, Text } from "@working-theory/ui/primitives";
28
48
  import type { Metadata } from "next";
29
49
  import { getTranslations } from "next-intl/server";
30
- import type { ReactElement } from "react";
50
+ import type { ReactElement, ReactNode } from "react";
31
51
 
32
52
  import { accountBillingSections } from "../../../../../lib/account-config";
53
+ import { formatMinorUnits } from "../../../../../lib/offerings-pricing";
33
54
  import { siteBillingSections } from "../../../../../lib/site-contributions";
34
55
  import { accountSession } from "../account-data";
35
56
  import { openBillingPortal } from "../actions";
36
- import { type BillingState, loadBilling } from "../billing-source";
57
+ import {
58
+ type BillingHistoryState,
59
+ type BillingPlanState,
60
+ type BillingState,
61
+ loadBilling,
62
+ loadBillingOfferings,
63
+ } from "../billing-source";
37
64
  import { ErrorRow } from "../error-row";
38
- import { memberSettingsFrame, SettingsSection, type Translate as MemberTranslate } from "../settings-frame";
65
+ import {
66
+ memberSettingsFrame,
67
+ SettingsSection,
68
+ type Translate as MemberTranslate,
69
+ } from "../settings-frame";
70
+
71
+ import type { BillingOfferView, BillingPlanView } from "./offerings";
39
72
 
40
73
  interface Props {
41
74
  params: Promise<{ locale: string }>;
@@ -44,14 +77,66 @@ interface Props {
44
77
  export async function generateMetadata({ params }: Props): Promise<Metadata> {
45
78
  const { locale } = await params;
46
79
  const t = await getTranslations({ locale, namespace: "account" });
47
- return { title: t("settings.billing.title"), description: t("settings.billing.lead") };
80
+ return {
81
+ title: t("settings.billing.title"),
82
+ description: t("settings.billing.lead"),
83
+ };
48
84
  }
49
85
 
50
- /** The statuses with a message key; any other renders as the API sent it. */
51
- const KNOWN_STATUSES: ReadonlySet<string> = new Set(["trialing", "active", "past_due", "canceled"]);
52
-
53
86
  type Translate = Awaited<ReturnType<typeof getTranslations<"account">>>;
54
87
 
88
+ // The pill: 44px on a phone (the primary-action floor) and full width there,
89
+ // 36px from md up — the settings cards' one submit style (#11167).
90
+ const PILL_CLASS =
91
+ "max-md:w-full max-md:min-h-11 !rounded-full whitespace-nowrap";
92
+
93
+ /** A day as the mockup writes it — "December 1" — read in UTC, the server's zone. */
94
+ function monthDay(iso: string, locale: string): ReactNode {
95
+ return (
96
+ <time dateTime={iso}>
97
+ {new Intl.DateTimeFormat(locale, {
98
+ month: "long",
99
+ day: "numeric",
100
+ timeZone: "UTC",
101
+ }).format(new Date(iso))}
102
+ </time>
103
+ );
104
+ }
105
+
106
+ /** A History date as MM/DD/YYYY in the page's locale, read in UTC. */
107
+ function numericDate(iso: string, locale: string): string {
108
+ return new Intl.DateTimeFormat(locale, {
109
+ month: "2-digit",
110
+ day: "2-digit",
111
+ year: "numeric",
112
+ timeZone: "UTC",
113
+ }).format(new Date(iso));
114
+ }
115
+
116
+ /** "Visa 4242" — Stripe's lower-case brand, capitalized. */
117
+ function cardLabel(
118
+ card: BillingPlanState["card"],
119
+ t: Translate,
120
+ ): string | null {
121
+ if (card === null) return null;
122
+ const brand = card.brand.charAt(0).toUpperCase() + card.brand.slice(1);
123
+ return t("settings.billing.card", { brand, last4: card.last4 });
124
+ }
125
+
126
+ /** "$12,500/mo" — the amount in the price's currency, with its interval word. */
127
+ function priceLabel(
128
+ price: NonNullable<BillingPlanState["price"]>,
129
+ locale: string,
130
+ t: Translate,
131
+ ): string {
132
+ const amount = formatMinorUnits(price.amountMinor, price.currency, locale);
133
+ if (price.interval === "month")
134
+ return t("settings.billing.perMonth", { amount });
135
+ if (price.interval === "year")
136
+ return t("settings.billing.perYear", { amount });
137
+ return amount;
138
+ }
139
+
55
140
  function Subscription({
56
141
  state,
57
142
  locale,
@@ -61,70 +146,210 @@ function Subscription({
61
146
  locale: string;
62
147
  t: Translate;
63
148
  }): ReactElement {
64
- const card = state.paymentMethod;
65
- const statusLabel = KNOWN_STATUSES.has(state.status)
66
- ? t(`settings.billing.statuses.${state.status}`)
67
- : state.status;
68
- const line = (
69
- <span data-testid="account-billing-status">
70
- {state.accessRevokesAt
71
- ? `${statusLabel} · ${t("settings.billing.accessEnds", {
72
- date: new Intl.DateTimeFormat(locale, { dateStyle: "medium" }).format(
73
- new Date(state.accessRevokesAt),
74
- ),
75
- })}`
76
- : statusLabel}
77
- </span>
78
- );
79
- const caption = (
80
- <span data-testid="account-billing-payment">
81
- {card !== null
82
- ? t("settings.billing.card", {
83
- brand: card.brand,
84
- last4: card.last4,
85
- month: String(card.expMonth).padStart(2, "0"),
86
- year: String(card.expYear),
149
+ const { plan } = state;
150
+ const { renewsAt, accessEndsAt } = plan;
151
+ // The one line under the name: the renewal while it renews, the access
152
+ // end once it is set to end, else the status word — then the card on file.
153
+ const status: ReactNode =
154
+ renewsAt !== null &&
155
+ (plan.status === "active" || plan.status === "trialing")
156
+ ? t.rich("settings.billing.renews", {
157
+ date: () => monthDay(renewsAt, locale),
158
+ })
159
+ : plan.status === "canceled" && accessEndsAt !== null
160
+ ? t.rich("settings.billing.accessEnds", {
161
+ date: () => monthDay(accessEndsAt, locale),
87
162
  })
88
- : t("settings.billing.noCard")}
89
- </span>
90
- );
163
+ : t(`settings.billing.statuses.${plan.status}`);
164
+ const card = cardLabel(plan.card, t);
91
165
  return (
92
166
  <CurrentPlanCard
93
- title={t("settings.billing.currentPlan")}
94
- heading={
95
- <span data-testid="account-billing-plan">
96
- {state.planName ?? t("settings.billing.unnamedPlan")}
167
+ name={plan.name ?? t("settings.billing.unnamedPlan")}
168
+ price={
169
+ plan.price === null ? undefined : priceLabel(plan.price, locale, t)
170
+ }
171
+ line={
172
+ <span data-testid="account-billing-status">
173
+ {status}
174
+ {card !== null ? (
175
+ <>
176
+ {" · "}
177
+ <span data-testid="account-billing-payment">{card}</span>
178
+ </>
179
+ ) : null}
97
180
  </span>
98
181
  }
99
- line={line}
100
- caption={caption}
101
182
  action={
102
183
  state.portalAvailable ? (
103
184
  <form action={openBillingPortal}>
104
- <Button type="submit" variant="outline" data-testid="account-billing-manage">
185
+ <Button
186
+ type="submit"
187
+ className={PILL_CLASS}
188
+ data-testid="account-billing-manage"
189
+ >
105
190
  {t("settings.billing.manage")}
106
191
  </Button>
107
192
  </form>
108
193
  ) : undefined
109
194
  }
110
195
  testId="account-billing"
111
- cardTestId="account-billing-card"
112
196
  />
113
197
  );
114
198
  }
115
199
 
116
- export default async function AccountBillingPage({ params }: Props): Promise<ReactElement> {
200
+ /** The base plan a member without a subscription starts on, with Upgrade to the next (#11165 B2). */
201
+ function BasePlan({
202
+ base,
203
+ next,
204
+ locale,
205
+ t,
206
+ }: {
207
+ base: BillingPlanView;
208
+ next: BillingPlanView | null;
209
+ locale: string;
210
+ t: Translate;
211
+ }): ReactElement {
212
+ const upgradeHref = next?.checkoutHref ?? null;
213
+ return (
214
+ <CurrentPlanCard
215
+ name={base.name}
216
+ price={priceLabel(base.price, locale, t)}
217
+ description={base.description ?? t("settings.billing.planFallback")}
218
+ action={
219
+ upgradeHref !== null ? (
220
+ <Button asChild className={PILL_CLASS}>
221
+ <Link
222
+ href={upgradeHref}
223
+ variant="bare"
224
+ data-testid="account-billing-upgrade"
225
+ >
226
+ {t("settings.billing.upgrade")}
227
+ </Link>
228
+ </Button>
229
+ ) : undefined
230
+ }
231
+ testId="account-billing"
232
+ />
233
+ );
234
+ }
235
+
236
+ /** The History card (#11165 C): the error row for a failed read, else the rows — the page renders it only when there are any. */
237
+ function History({
238
+ history,
239
+ locale,
240
+ t,
241
+ }: {
242
+ history: BillingHistoryState;
243
+ locale: string;
244
+ t: Translate;
245
+ }): ReactElement {
246
+ if (history.kind === "failed") {
247
+ return (
248
+ <div data-testid="account-billing-history-error">
249
+ <ErrorRow
250
+ message={t("settings.billing.historyUnavailable")}
251
+ retryLabel={t("inbox.retry")}
252
+ />
253
+ </div>
254
+ );
255
+ }
256
+ const rows: BillingHistoryRowView[] = history.items.map((item) => ({
257
+ id: item.id,
258
+ date: numericDate(item.paidAt, locale),
259
+ dateTime: item.paidAt,
260
+ offering: item.offering,
261
+ amount:
262
+ item.amountMinor !== null && item.currency !== null ? (
263
+ <MoneyAmount
264
+ amountMinor={item.amountMinor}
265
+ currency={item.currency}
266
+ locale={locale}
267
+ />
268
+ ) : (
269
+ "—"
270
+ ),
271
+ receiptHref: item.receiptUrl,
272
+ }));
273
+ return (
274
+ <BillingHistoryCard
275
+ rows={rows}
276
+ labels={{
277
+ title: t("settings.billing.history"),
278
+ date: t("settings.billing.historyDate"),
279
+ offering: t("settings.billing.historyOffering"),
280
+ amount: t("settings.billing.historyAmount"),
281
+ receipt: t("settings.billing.historyReceipt"),
282
+ view: t("settings.billing.historyView"),
283
+ }}
284
+ testIdPrefix="account-billing-history"
285
+ />
286
+ );
287
+ }
288
+
289
+ /**
290
+ * The offer dismissal's per-person key: a SHA-256 digest of the person's
291
+ * email under a fixed label, computed on the server, so the browser's store
292
+ * names no address and a shared browser keeps each person's dismissals
293
+ * apart. A pseudonym, not a secret: the stored value is product ids only.
294
+ */
295
+ function offerPersistKey(email: string): string {
296
+ const digest = createHash("sha256")
297
+ .update(`ailk:billing-offer:${email.trim().toLowerCase()}`)
298
+ .digest("hex");
299
+ return `account:billing-offer:${digest.slice(0, 16)}`;
300
+ }
301
+
302
+ /**
303
+ * The offer card (#11165 A), built as the pane's DIRECT child — the pane
304
+ * reads `ownCard` off the element it is given — so it draws its own card and
305
+ * a dismissal leaves no shell; the page builds it only for a live offer.
306
+ */
307
+ function offerCard(
308
+ offer: BillingOfferView & { claimHref: string },
309
+ email: string,
310
+ t: Translate,
311
+ ): ReactElement {
312
+ return (
313
+ <OfferCard
314
+ id={offer.productId}
315
+ persistKey={offerPersistKey(email)}
316
+ title={offer.name}
317
+ description={offer.description}
318
+ image={
319
+ offer.image === null ? null : { src: offer.image, alt: offer.name }
320
+ }
321
+ claimHref={offer.claimHref}
322
+ claimLabel={t("settings.billing.claimOffer")}
323
+ dismissLabel={t("settings.billing.dismissOffer")}
324
+ testId="account-billing-offer"
325
+ cardTestId="account-settings-billing-card"
326
+ ownCard
327
+ />
328
+ );
329
+ }
330
+
331
+ export default async function AccountBillingPage({
332
+ params,
333
+ }: Props): Promise<ReactElement> {
117
334
  const { locale } = await params;
118
335
  const t = await getTranslations({ locale, namespace: "account" });
119
336
  const session = await accountSession(locale);
120
- const frame = memberSettingsFrame(locale, t as unknown as MemberTranslate, "billing");
337
+ const frame = memberSettingsFrame(
338
+ locale,
339
+ t as unknown as MemberTranslate,
340
+ "billing",
341
+ );
121
342
 
122
343
  // Unreachable behind the (authed) gate; a session that expired between
123
344
  // the layout and the page renders the pane's title alone.
124
345
  if (!session) {
125
346
  return (
126
347
  <AccountSettingsFrame {...frame} name="">
127
- <AccountSettingsPane id="account-settings-billing" title={t("settings.billing.title")} lead="">
348
+ <AccountSettingsPane
349
+ id="account-settings-billing"
350
+ title={t("settings.billing.title")}
351
+ lead=""
352
+ >
128
353
  {null}
129
354
  </AccountSettingsPane>
130
355
  </AccountSettingsFrame>
@@ -132,8 +357,18 @@ export default async function AccountBillingPage({ params }: Props): Promise<Rea
132
357
  }
133
358
 
134
359
  const { ctx } = session;
135
- const state = await loadBilling(ctx.init);
360
+ const [{ state, history }, offerings] = await Promise.all([
361
+ loadBilling(ctx.init),
362
+ loadBillingOfferings(),
363
+ ]);
136
364
  const name = ctx.user.name || ctx.user.email;
365
+ // Every pane child below is one card, so each slot is decided here and a
366
+ // slot with nothing to show passes nothing — never an empty card (#11165).
367
+ const offer =
368
+ offerings.offer !== null && offerings.offer.claimHref !== null
369
+ ? { ...offerings.offer, claimHref: offerings.offer.claimHref }
370
+ : null;
371
+ const hasHistory = history.kind === "failed" || history.items.length > 0;
137
372
 
138
373
  return (
139
374
  <AccountSettingsFrame {...frame} name={name}>
@@ -142,17 +377,24 @@ export default async function AccountBillingPage({ params }: Props): Promise<Rea
142
377
  title={t("settings.billing.title")}
143
378
  lead={t("settings.billing.lead")}
144
379
  >
380
+ {offer !== null ? offerCard(offer, ctx.user.email, t) : null}
381
+
145
382
  {state.kind === "subscription" ? (
146
383
  <Subscription state={state} locale={locale} t={t} />
147
384
  ) : state.kind === "none" ? (
148
- <CurrentPlanCard
149
- title={t("settings.billing.currentPlan")}
150
- line={<span data-testid="account-billing-none">{t("settings.billing.none")}</span>}
151
- testId="account-billing"
152
- cardTestId="account-billing-card"
153
- />
385
+ offerings.base !== null ? (
386
+ <BasePlan
387
+ base={offerings.base}
388
+ next={offerings.next}
389
+ locale={locale}
390
+ t={t}
391
+ />
392
+ ) : null
154
393
  ) : (
155
- <ErrorRow message={t("settings.billing.unavailable")} retryLabel={t("inbox.retry")} />
394
+ <ErrorRow
395
+ message={t("settings.billing.unavailable")}
396
+ retryLabel={t("inbox.retry")}
397
+ />
156
398
  )}
157
399
 
158
400
  {state.kind !== "failed" && state.unreadable ? (
@@ -163,8 +405,16 @@ export default async function AccountBillingPage({ params }: Props): Promise<Rea
163
405
  </div>
164
406
  ) : null}
165
407
 
408
+ {hasHistory ? (
409
+ <History history={history} locale={locale} t={t} />
410
+ ) : null}
411
+
166
412
  {[...accountBillingSections, ...siteBillingSections].map((section) => (
167
- <SettingsSection key={section.id} id={section.id} title={ctx.t(section.title)}>
413
+ <SettingsSection
414
+ key={section.id}
415
+ id={section.id}
416
+ title={ctx.t(section.title)}
417
+ >
168
418
  {section.render(ctx)}
169
419
  </SettingsSection>
170
420
  ))}