create-ailk 0.37.0 → 0.38.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 (232) hide show
  1. package/README.md +149 -2
  2. package/component-catalog.json +44 -6
  3. package/component-catalog.md +6 -5
  4. package/dist/add-module.js +16 -1
  5. package/dist/add-route.d.ts +7 -2
  6. package/dist/add-route.js +28 -13
  7. package/dist/cli.js +52 -0
  8. package/dist/declined-routes.d.ts +13 -0
  9. package/dist/declined-routes.js +74 -0
  10. package/dist/derive-architecture.d.ts +0 -6
  11. package/dist/derive-architecture.js +9 -15
  12. package/dist/index.d.ts +1 -0
  13. package/dist/index.js +3 -0
  14. package/dist/language-import.d.ts +93 -0
  15. package/dist/language-import.js +270 -43
  16. package/dist/lib/import-mdx.js +1 -1
  17. package/dist/lib/scaffold-render-sweep.d.ts +6 -3
  18. package/dist/lib/scaffold-render-sweep.js +8 -4
  19. package/dist/migrate-content.d.ts +6 -2
  20. package/dist/migrate-content.js +62 -5
  21. package/dist/module-architecture.js +139 -103
  22. package/dist/paid-sections.d.ts +13 -0
  23. package/dist/paid-sections.js +35 -5
  24. package/dist/programmatic.js +6 -16
  25. package/dist/remove-module.js +67 -0
  26. package/dist/routes.d.ts +103 -0
  27. package/dist/routes.js +708 -0
  28. package/dist/site-manifest.js +1 -1
  29. package/dist/site-roster.d.ts +2 -1
  30. package/dist/site-roster.js +30 -8
  31. package/dist/spoke-checkout.d.ts +28 -27
  32. package/dist/spoke-checkout.js +71 -102
  33. package/dist/surfaces.d.ts +18 -0
  34. package/dist/surfaces.js +47 -282
  35. package/dist/sync-routes.d.ts +28 -1
  36. package/dist/sync-routes.js +144 -11
  37. package/dist/template-record.d.ts +11 -0
  38. package/dist/template-record.js +18 -0
  39. package/dist/topology.d.ts +15 -1
  40. package/dist/topology.js +20 -4
  41. package/dist/update.d.ts +31 -2
  42. package/dist/update.js +627 -99
  43. package/package.json +3 -3
  44. package/templates/README.md +1 -1
  45. package/templates/apps/mcp/CLAUDE.md +5 -3
  46. package/templates/apps/web/CLAUDE.md +62 -20
  47. package/templates/apps/web/account.config.tsx +101 -0
  48. package/templates/apps/web/app/[locale]/(authed)/account/appointments/[slug]/page.tsx +3 -161
  49. package/templates/apps/web/app/[locale]/(authed)/account/appointments/page.tsx +3 -139
  50. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/page.tsx +3 -406
  51. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/versions/[version]/file/route.ts +2 -190
  52. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/page.tsx +3 -182
  53. package/templates/apps/web/app/[locale]/(authed)/account/billing/page.tsx +8 -420
  54. package/templates/apps/web/app/[locale]/(authed)/account/connect/page.tsx +1 -1
  55. package/templates/apps/web/app/[locale]/(authed)/account/general/page.tsx +8 -214
  56. package/templates/apps/web/app/[locale]/(authed)/account/inbox/[kind]/[id]/page.tsx +8 -115
  57. package/templates/apps/web/app/[locale]/(authed)/account/inbox/message/[id]/file/route.ts +2 -80
  58. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/page.tsx +8 -121
  59. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/page.tsx +3 -154
  60. package/templates/apps/web/app/[locale]/(authed)/account/layout.tsx +7 -149
  61. package/templates/apps/web/app/[locale]/(authed)/account/notifications/page.tsx +3 -143
  62. package/templates/apps/web/app/[locale]/(authed)/account/onboarding/page.tsx +3 -126
  63. package/templates/apps/web/app/[locale]/(authed)/account/page.tsx +8 -302
  64. package/templates/apps/web/app/[locale]/(authed)/account/privacy/export/route.ts +2 -102
  65. package/templates/apps/web/app/[locale]/(authed)/account/privacy/page.tsx +3 -240
  66. package/templates/apps/web/app/[locale]/(authed)/account/security/page.tsx +3 -131
  67. package/templates/apps/web/app/[locale]/(authed)/account/settings/page.tsx +2 -24
  68. package/templates/apps/web/app/[locale]/(authed)/account/support/page.tsx +3 -60
  69. package/templates/apps/web/app/[locale]/layout.tsx +45 -28
  70. package/templates/apps/web/app/apple-icon.tsx +72 -0
  71. package/templates/apps/web/app/llms.txt/__tests__/site-listing.test.ts +22 -12
  72. package/templates/apps/web/app/og/__tests__/__snapshots__/card.test.tsx.snap +3 -0
  73. package/templates/apps/web/app/og/__tests__/card.test.tsx +129 -0
  74. package/templates/apps/web/app/og/__tests__/route.test.ts +3 -4
  75. package/templates/apps/web/app/og/route.tsx +155 -72
  76. package/templates/apps/web/app/sitemap.xml/__tests__/site-listing.test.ts +12 -0
  77. package/templates/apps/web/i18n/request.ts +44 -1
  78. package/templates/apps/web/jest.config.cjs +13 -1
  79. package/templates/apps/web/lib/__tests__/auth-phone.test.ts +11 -0
  80. package/templates/apps/web/lib/__tests__/fixtures/site-topology.ts +70 -0
  81. package/templates/apps/web/lib/__tests__/nav-label-keys.test.ts +14 -0
  82. package/templates/apps/web/lib/__tests__/profile-back-link.test.ts +148 -61
  83. package/templates/apps/web/lib/__tests__/served-pages.test.ts +77 -0
  84. package/templates/apps/web/lib/__tests__/server-api.test.ts +37 -5
  85. package/templates/apps/web/lib/__tests__/structured-data.test.tsx +26 -13
  86. package/templates/apps/web/lib/listings.tsx +2 -2
  87. package/templates/apps/web/lib/nav-label-keys.ts +16 -2
  88. package/templates/apps/web/lib/paid-section-contracts.ts +35 -6
  89. package/templates/apps/web/lib/paid-sections.generated.ts +8 -0
  90. package/templates/apps/web/lib/profile-back-link.ts +105 -32
  91. package/templates/apps/web/lib/served-pages.ts +95 -0
  92. package/templates/apps/web/lib/site-brand.tsx +3 -5
  93. package/templates/apps/web/messages/en.json +8 -684
  94. package/templates/apps/web/middleware.ts +3 -1
  95. package/templates/apps/web/next.config.mjs +27 -0
  96. package/templates/apps/web/package.json +1 -0
  97. package/templates/customizations.yaml +9 -0
  98. package/templates/package.json +3 -1
  99. package/templates/tools/lint-architecture.ts +164 -11
  100. package/versions.json +48 -47
  101. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/account-frame-sign-out.test.tsx +0 -175
  102. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/agreements-prompt.test.tsx +0 -301
  103. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/billing.test.tsx +0 -515
  104. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/general.test.tsx +0 -883
  105. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/hub-mode.test.tsx +0 -758
  106. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/item.test.tsx +0 -264
  107. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout-sign-out.test.tsx +0 -167
  108. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout.test.tsx +0 -730
  109. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-menu.test.tsx +0 -355
  110. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-popups.test.tsx +0 -97
  111. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/notifications.test.tsx +0 -375
  112. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/onboarding.test.tsx +0 -323
  113. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/page.test.tsx +0 -1208
  114. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/popups.test.tsx +0 -418
  115. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/privacy.test.tsx +0 -462
  116. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/rich-translator.ts +0 -63
  117. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/security.test.tsx +0 -406
  118. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/settings.test.tsx +0 -93
  119. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/support.test.tsx +0 -208
  120. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/thread.test.tsx +0 -340
  121. package/templates/apps/web/app/[locale]/(authed)/account/account-data.ts +0 -182
  122. package/templates/apps/web/app/[locale]/(authed)/account/account-frame.tsx +0 -353
  123. package/templates/apps/web/app/[locale]/(authed)/account/actions.ts +0 -57
  124. package/templates/apps/web/app/[locale]/(authed)/account/agreements-actions.ts +0 -58
  125. package/templates/apps/web/app/[locale]/(authed)/account/agreements-gate.ts +0 -61
  126. package/templates/apps/web/app/[locale]/(authed)/account/agreements-prompt.tsx +0 -184
  127. package/templates/apps/web/app/[locale]/(authed)/account/appointments/__tests__/page.test.tsx +0 -426
  128. package/templates/apps/web/app/[locale]/(authed)/account/appointments/appointments-data.ts +0 -76
  129. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/pay-form.tsx +0 -65
  130. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/review-form.tsx +0 -172
  131. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/file-route.test.ts +0 -333
  132. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/page.test.tsx +0 -936
  133. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/pay.test.tsx +0 -193
  134. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/review.test.tsx +0 -476
  135. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/artifact-actions.ts +0 -184
  136. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/artifact-data.ts +0 -197
  137. package/templates/apps/web/app/[locale]/(authed)/account/billing/__tests__/offerings.test.ts +0 -99
  138. package/templates/apps/web/app/[locale]/(authed)/account/billing/offerings.ts +0 -123
  139. package/templates/apps/web/app/[locale]/(authed)/account/billing-source.ts +0 -303
  140. package/templates/apps/web/app/[locale]/(authed)/account/components/request-quote.tsx +0 -274
  141. package/templates/apps/web/app/[locale]/(authed)/account/error-row.tsx +0 -35
  142. package/templates/apps/web/app/[locale]/(authed)/account/for-you-labels.ts +0 -36
  143. package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/phone-verification.test.tsx +0 -215
  144. package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/seam-imports.test.ts +0 -65
  145. package/templates/apps/web/app/[locale]/(authed)/account/general/account-name.ts +0 -36
  146. package/templates/apps/web/app/[locale]/(authed)/account/general/billing-anchor.tsx +0 -27
  147. package/templates/apps/web/app/[locale]/(authed)/account/general/contact-actions.ts +0 -149
  148. package/templates/apps/web/app/[locale]/(authed)/account/general/contact-details.tsx +0 -42
  149. package/templates/apps/web/app/[locale]/(authed)/account/general/deletion-request.tsx +0 -132
  150. package/templates/apps/web/app/[locale]/(authed)/account/general/phone-actions.ts +0 -122
  151. package/templates/apps/web/app/[locale]/(authed)/account/general/phone-verification.tsx +0 -215
  152. package/templates/apps/web/app/[locale]/(authed)/account/general/photo-actions.ts +0 -73
  153. package/templates/apps/web/app/[locale]/(authed)/account/general/profile-form.tsx +0 -107
  154. package/templates/apps/web/app/[locale]/(authed)/account/general/profile-source.ts +0 -87
  155. package/templates/apps/web/app/[locale]/(authed)/account/inbox/message/[id]/file/__tests__/route.test.ts +0 -215
  156. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/member-thread-composer.tsx +0 -43
  157. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-data.ts +0 -88
  158. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-write.ts +0 -31
  159. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/invitation-id.test.ts +0 -35
  160. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/page.test.tsx +0 -266
  161. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/actions.ts +0 -116
  162. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/invitation-id.ts +0 -12
  163. package/templates/apps/web/app/[locale]/(authed)/account/new-actions.ts +0 -219
  164. package/templates/apps/web/app/[locale]/(authed)/account/new-menu.tsx +0 -365
  165. package/templates/apps/web/app/[locale]/(authed)/account/new-popups.tsx +0 -86
  166. package/templates/apps/web/app/[locale]/(authed)/account/onboarding/actions.ts +0 -120
  167. package/templates/apps/web/app/[locale]/(authed)/account/onboarding/onboarding-form.tsx +0 -322
  168. package/templates/apps/web/app/[locale]/(authed)/account/privacy/__tests__/export-route.test.ts +0 -173
  169. package/templates/apps/web/app/[locale]/(authed)/account/privacy/actions.ts +0 -103
  170. package/templates/apps/web/app/[locale]/(authed)/account/profile-actions.ts +0 -116
  171. package/templates/apps/web/app/[locale]/(authed)/account/retry-button.tsx +0 -27
  172. package/templates/apps/web/app/[locale]/(authed)/account/security/__tests__/hub-variant.test.tsx +0 -258
  173. package/templates/apps/web/app/[locale]/(authed)/account/security/security-panel.tsx +0 -130
  174. package/templates/apps/web/app/[locale]/(authed)/account/security/security-source.ts +0 -92
  175. package/templates/apps/web/app/[locale]/(authed)/account/settings-frame.tsx +0 -121
  176. package/templates/apps/web/app/[locale]/(authed)/account/sign-in-method.ts +0 -37
  177. package/templates/apps/web/app/[locale]/(authed)/account/support/support-form.tsx +0 -98
  178. package/templates/apps/web/app/[locale]/(authed)/account/support-actions.ts +0 -100
  179. package/templates/apps/web/app/[locale]/checkout/__tests__/pages.test.tsx +0 -139
  180. package/templates/apps/web/app/[locale]/checkout/__tests__/thank-you-account.test.tsx +0 -146
  181. package/templates/apps/web/app/[locale]/checkout/thank-you/page.tsx +0 -114
  182. package/templates/apps/web/app/[locale]/checkout/unavailable/page.tsx +0 -51
  183. package/templates/apps/web/app/[locale]/flows/[slug]/FlowStepperClient.tsx +0 -614
  184. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.count.test.tsx +0 -43
  185. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.deliverable.test.tsx +0 -214
  186. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.ending.test.tsx +0 -197
  187. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.invite.test.tsx +0 -286
  188. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.permalink.test.tsx +0 -520
  189. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.test.tsx +0 -376
  190. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.thanks-by-tier.test.tsx +0 -306
  191. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/account-invite.actions.test.ts +0 -69
  192. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/flow.actions.test.ts +0 -398
  193. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/magnet-page.test.tsx +0 -704
  194. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/save.actions.test.ts +0 -173
  195. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/two-route-tool.test.tsx +0 -141
  196. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/verify.test.tsx +0 -249
  197. package/templates/apps/web/app/[locale]/flows/[slug]/account-invite.actions.ts +0 -35
  198. package/templates/apps/web/app/[locale]/flows/[slug]/email-moment.ts +0 -92
  199. package/templates/apps/web/app/[locale]/flows/[slug]/flow.actions.ts +0 -177
  200. package/templates/apps/web/app/[locale]/flows/[slug]/magnet-page.tsx +0 -472
  201. package/templates/apps/web/app/[locale]/flows/[slug]/page.tsx +0 -48
  202. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/LevelChart.tsx +0 -100
  203. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsCard.tsx +0 -99
  204. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsClient.tsx +0 -820
  205. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsEmailStep.tsx +0 -203
  206. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/ResultsClient.no-commerce.test.tsx +0 -194
  207. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/ResultsClient.report.test.tsx +0 -284
  208. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/by-result.test.tsx +0 -302
  209. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/cards.test.tsx +0 -402
  210. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/landing.test.tsx +0 -293
  211. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/page.test.tsx +0 -485
  212. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/score.test.tsx +0 -231
  213. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/checkout-seam.ts +0 -74
  214. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/meeting-seam.ts +0 -36
  215. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/page.tsx +0 -420
  216. package/templates/apps/web/app/[locale]/flows/[slug]/save.actions.ts +0 -85
  217. package/templates/apps/web/app/[locale]/flows/[slug]/served-flow.ts +0 -91
  218. package/templates/apps/web/app/[locale]/flows/[slug]/start/page.tsx +0 -32
  219. package/templates/apps/web/app/[locale]/flows/[slug]/verify/page.tsx +0 -153
  220. package/templates/apps/web/app/[locale]/flows/[slug]/verify.actions.ts +0 -151
  221. package/templates/apps/web/app/[locale]/meet/confirmed/BookingHandOff.tsx +0 -128
  222. package/templates/apps/web/app/[locale]/meet/confirmed/__tests__/BookingHandOff.test.tsx +0 -126
  223. package/templates/apps/web/app/[locale]/purchase/__tests__/cancel.test.tsx +0 -162
  224. package/templates/apps/web/app/[locale]/purchase/__tests__/module-scope.test.ts +0 -68
  225. package/templates/apps/web/app/[locale]/purchase/__tests__/success.test.tsx +0 -411
  226. package/templates/apps/web/app/[locale]/purchase/cancel/page.tsx +0 -115
  227. package/templates/apps/web/app/[locale]/purchase/success/page.tsx +0 -348
  228. package/templates/apps/web/lib/__tests__/account-config.test.ts +0 -704
  229. package/templates/apps/web/lib/account-config.ts +0 -678
  230. package/templates/apps/web/lib/checkout-config.ts +0 -16
  231. package/templates/apps/web/src/lib/__tests__/commerce-sections.test.ts +0 -57
  232. package/templates/apps/web/src/lib/commerce-sections.ts +0 -55
@@ -1,515 +0,0 @@
1
- /**
2
- * Tests for /[locale]/account/billing — User settings › Billing (#8232, spec
3
- * docs/specs/8232-member-settings-account-general-and-spec.md D1, D9; #11165,
4
- * the card shape of 2026-11-08). The single-site render: `subscription.me`
5
- * and `offerings.shown` are the mocked boundaries (the shown set reaches the
6
- * page through `/pricing`'s shared 15 s reader, so each case moves `Date.now`
7
- * past its window).
8
- *
9
- * Covers:
10
- * #11165 AC-1 (B1) — a subscription renders the plan card: the name, the
11
- * status line with the card ("Active · Visa 4242", "Payment due",
12
- * "Access ends <Month D>"), Manage plan; no "Current plan" heading; no
13
- * Manage without a portal.
14
- * #11165 AC-2 (B2) — with no subscription (`status: null`, 401, 403, 404)
15
- * the shown set's lowest-priced live plan is the card, with its Stripe
16
- * description or the fallback line and Upgrade to the next live plan by
17
- * price — Essentials → Growth on a three-plan set; one plan has no
18
- * Upgrade; a set with no live plan, an unconnected site or an expired
19
- * set renders no plan card; "You don't have a subscription." is gone.
20
- * #11165 AC-3 (A) — the first live Offer renders above the plan card with
21
- * Claim offer to the Offerings checkout carrying its promotion code;
22
- * none without one. (The dismissal is `OfferCard`'s own suite.)
23
- * #11165 AC-4 (C) — a single site reads no History and renders no card.
24
- * (d) a 500 or a throw shows the error row, never a plan card; (e) a
25
- * contributed billing section renders after the base content; (f) the
26
- * read asks for `include: "billing"`.
27
- * #9401 AC-9: a section the site adds renders after the modules'.
28
- * #8217 AC-1 (D10, D11): `openBillingPortal()` mints the portal through
29
- * the hub's route, once, with the cookie init, and redirects there.
30
- */
31
- import { render, screen, within } from "@testing-library/react";
32
-
33
- jest.mock("next-intl/server", () => {
34
- const msgs: unknown = require("../../../../../messages/en.json");
35
- const dig = (obj: unknown, path: string): unknown =>
36
- path.split(".").reduce<unknown>(
37
- (acc, k) => (acc !== null && typeof acc === "object" ? (acc as Record<string, unknown>)[k] : undefined),
38
- obj,
39
- );
40
- return {
41
- __esModule: true,
42
- getTranslations: async (arg: string | { namespace?: string; locale?: string }) => {
43
- const ns = typeof arg === "string" ? arg : (arg.namespace ?? "");
44
- const messages = dig(msgs, ns);
45
- const t = (key: string, values?: Record<string, unknown>): string => {
46
- const value = dig(messages, key);
47
- if (typeof value !== "string") return `${ns}.${key}`;
48
- return value.replace(/\{(\w+)\}/g, (m, name: string) =>
49
- values && name in values ? String(values[name]) : m,
50
- );
51
- };
52
- // #11175: the dated messages carry a `<date>` tag and render through `t.rich`.
53
- const { withRich } = require("./rich-translator") as typeof import("./rich-translator");
54
- return withRich(t, (key: string) => dig(messages, key), ns);
55
- },
56
- };
57
- });
58
-
59
- jest.mock("next/headers", () => ({
60
- __esModule: true,
61
- headers: jest.fn().mockResolvedValue(new Headers()),
62
- cookies: jest.fn().mockResolvedValue({ toString: () => "session=abc" }),
63
- }));
64
-
65
- const mockGetSession = jest.fn();
66
- // eslint-disable-next-line no-restricted-syntax -- #507: mock-internal rewrite pending; auth.ts's lazy Better-Auth singleton has no HTTP/DB boundary a unit test of the session fields can mock without standing up Prisma.
67
- jest.mock("../../../../../auth", () => ({
68
- __esModule: true,
69
- auth: { api: { getSession: (...args: unknown[]) => mockGetSession(...args) } },
70
- }));
71
-
72
- const mockSubscriptionMe = jest.fn();
73
- const mockPortalSession = jest.fn();
74
- const mockMemberPurchases = jest.fn();
75
- const mockMemberBilling = jest.fn();
76
- const mockOfferingsShown = jest.fn();
77
- jest.mock("@working-theory/api-client", () => ({
78
- __esModule: true,
79
- waitlistSignups: { me: jest.fn() },
80
- flowCheckouts: { me: jest.fn() },
81
- subscription: {
82
- me: (...args: unknown[]) => mockSubscriptionMe(...args),
83
- portalSession: (...args: unknown[]) => mockPortalSession(...args),
84
- },
85
- leads: { submit: jest.fn() },
86
- member: {
87
- purchases: (...args: unknown[]) => mockMemberPurchases(...args),
88
- billing: (...args: unknown[]) => mockMemberBilling(...args),
89
- billingPortal: jest.fn(),
90
- },
91
- offerings: { shown: (...args: unknown[]) => mockOfferingsShown(...args) },
92
- hubSignIn: { me: jest.fn() },
93
- visitorForwardHeaders: () => null,
94
- }));
95
-
96
- const mockRedirect = jest.fn();
97
- jest.mock("next/navigation", () => ({
98
- __esModule: true,
99
- useRouter: () => ({ push: jest.fn(), refresh: jest.fn(), replace: jest.fn() }),
100
- usePathname: () => "/account/billing",
101
- redirect: (...args: unknown[]) => mockRedirect(...args),
102
- }));
103
-
104
- import type { AccountBillingSection } from "@working-theory/templates/account";
105
- import type { OfferingsProduct, WorkspaceShownSetWire } from "@working-theory/validation";
106
-
107
- import { accountBillingSections } from "../../../../../lib/account-config";
108
- import { siteBillingSections } from "../../../../../lib/site-contributions";
109
- import { openBillingPortal } from "../actions";
110
-
111
- // The Billing route's own page, loaded with `import()`: architecture.yaml bans
112
- // a static import of a relative billing/ path to keep OSS code out of the
113
- // apps-paid/billing service's source, and this route directory shares the name.
114
- const loadPage = async () => (await import("../billing/page")).default;
115
-
116
- const SESSION = {
117
- user: {
118
- id: "user_1",
119
- name: "Ada Lovelace",
120
- email: "ada@example.com",
121
- emailVerified: true,
122
- createdAt: new Date("2026-09-01T00:00:00.000Z"),
123
- },
124
- };
125
-
126
- const ACTIVE = {
127
- actionRequired: false,
128
- status: "active",
129
- accessRevokesAt: null,
130
- portalAvailable: true,
131
- planName: "Pro",
132
- paymentMethod: { brand: "visa", last4: "4242", expMonth: 4, expYear: 2027 },
133
- };
134
-
135
- const answer = (body: Record<string, unknown>) => ({ ok: true, body: { ...ACTIVE, ...body } });
136
- const noSubscription = () => mockSubscriptionMe.mockResolvedValue(answer({ status: null }));
137
-
138
- // ─── The shown set: the Sam Henry workspace's three plans and one offer ──────
139
-
140
- function plan(slug: string, name: string, amount: number, extra: Partial<OfferingsProduct> = {}): OfferingsProduct {
141
- return {
142
- productId: `prod_${slug.replace(/-/g, "")}`,
143
- plan: slug,
144
- name,
145
- description: null,
146
- marketingFeatures: [],
147
- unitLabel: null,
148
- note: null,
149
- termsNote: null,
150
- ailkGroup: "plan",
151
- ailkOrder: null,
152
- prices: [
153
- {
154
- priceId: `price_${slug.replace(/-/g, "")}_monthly`,
155
- lookupKey: `${slug}_monthly`,
156
- plan: slug,
157
- period: "monthly",
158
- interval: "month",
159
- amount,
160
- currency: "usd",
161
- },
162
- ],
163
- recommended: false,
164
- ...extra,
165
- };
166
- }
167
-
168
- const OFFER: OfferingsProduct = {
169
- ...plan("welcome", "Two weeks of Growth, on us", 0),
170
- productId: "prod_welcome",
171
- description: "Try the Growth plan for two weeks before you commit.",
172
- ailkGroup: "offer",
173
- prices: [
174
- { priceId: "price_welcome_once", lookupKey: "welcome_once", plan: "welcome", period: "once", interval: null, amount: 0, currency: "usd" },
175
- ],
176
- image: "https://files.stripe.com/links/offer.png",
177
- promotionCode: "WELCOME20",
178
- };
179
-
180
- /** Growth listed before Essentials, so the order under test is the price's, not the snapshot's. */
181
- function threePlans(offerings: OfferingsProduct[] = [plan("growth", "Growth", 2_500_000), plan("essentials", "Essentials", 1_250_000), plan("scale", "Scale", 5_000_000)]): WorkspaceShownSetWire {
182
- return {
183
- productIds: offerings.map((o) => o.productId),
184
- recommended: { plan: null, addon: null },
185
- offerings,
186
- state: "current",
187
- snapshotAt: "2026-11-08T00:00:00.000Z",
188
- };
189
- }
190
-
191
- const shown = (shownSet: WorkspaceShownSetWire) => mockOfferingsShown.mockResolvedValue({ ok: true, body: { status: "shown", shownSet } });
192
-
193
- // /pricing's reader shares one read per instance for 15 s; each case starts
194
- // past the last one's window, so its own answer is read.
195
- let clock = Date.UTC(2026, 10, 8);
196
- jest.spyOn(Date, "now").mockImplementation(() => clock);
197
-
198
- beforeEach(() => {
199
- mockGetSession.mockReset().mockResolvedValue(SESSION);
200
- mockSubscriptionMe.mockReset().mockResolvedValue(answer({}));
201
- mockPortalSession.mockReset();
202
- mockMemberPurchases.mockReset();
203
- mockMemberBilling.mockReset();
204
- mockOfferingsShown.mockReset().mockResolvedValue({ ok: true, body: { status: "unconnected" } });
205
- clock += 60_000;
206
- mockRedirect.mockReset();
207
- });
208
-
209
- async function renderPage(locale = "en"): Promise<void> {
210
- const Page = await loadPage();
211
- render(await Page({ params: Promise.resolve({ locale }) }));
212
- }
213
-
214
- describe("the frame (D7)", () => {
215
- it("renders in the settings frame with Billing current and the new lead", async () => {
216
- await renderPage();
217
- expect(screen.getByRole("heading", { level: 1 })).toHaveTextContent("Billing");
218
- expect(screen.getByText("Your plan, purchases and payment method.")).toBeInTheDocument();
219
- expect(screen.getByTestId("account-settings-back")).toHaveAttribute("href", "/account");
220
- expect(screen.getByTestId("account-settings-rail-billing")).toHaveAttribute("aria-current", "page");
221
- expect(screen.getByTestId("account-settings-rail-general")).not.toHaveAttribute("aria-current");
222
- });
223
- });
224
-
225
- describe("the standalone shape (#8430)", () => {
226
- it("takes the screen as the Admin's settings do: the rail column and the pane are the page's own landmarks", async () => {
227
- await renderPage();
228
- const settings = screen.getByTestId("account-settings");
229
- expect(settings).toHaveClass("min-h-screen");
230
- const column = within(settings).getByRole("complementary");
231
- expect(column.firstElementChild).toBe(screen.getByTestId("account-settings-back"));
232
- expect(column).toContainElement(screen.getByTestId("account-settings-rail"));
233
- expect(within(settings).getByRole("main")).toContainElement(
234
- screen.getByRole("heading", { level: 1 }),
235
- );
236
- });
237
- });
238
-
239
- describe("#11165 AC-1 (B1) — a subscription is the plan card", () => {
240
- it("shows the plan name, the status line with the card, and Manage plan — and no 'Current plan' heading", async () => {
241
- await renderPage();
242
- const card = screen.getByTestId("account-billing");
243
- expect(within(card).getByRole("heading", { level: 2 })).toHaveTextContent("Pro");
244
- expect(within(card).getByTestId("account-billing-plan")).toHaveTextContent("Pro");
245
- expect(within(card).getByTestId("account-billing-status")).toHaveTextContent("Active · Visa 4242");
246
- expect(within(card).getByTestId("account-billing-payment")).toHaveTextContent("Visa 4242");
247
- expect(screen.getByTestId("account-billing-manage")).toHaveTextContent("Manage plan");
248
- expect(screen.queryByText("Current plan")).not.toBeInTheDocument();
249
- expect(screen.queryByText("You don't have a subscription.")).not.toBeInTheDocument();
250
- expect(screen.queryByTestId("account-billing-unreadable")).not.toBeInTheDocument();
251
- // The single site's read carries no price or renewal date (#8171's fields only).
252
- expect(within(card).queryByTestId("account-billing-price")).not.toBeInTheDocument();
253
- // Exactly one card on the pane: no empty shell for the absent offer or History.
254
- expect(screen.getAllByTestId("account-settings-billing-card")).toHaveLength(1);
255
- });
256
-
257
- it("no plan name reads as 'Your subscription', and no card leaves the status alone", async () => {
258
- mockSubscriptionMe.mockResolvedValue(answer({ status: "past_due", planName: null, paymentMethod: null }));
259
- await renderPage();
260
- expect(screen.getByTestId("account-billing-plan")).toHaveTextContent("Your subscription");
261
- expect(screen.getByTestId("account-billing-status")).toHaveTextContent("Payment due");
262
- expect(screen.queryByTestId("account-billing-payment")).not.toBeInTheDocument();
263
- });
264
-
265
- it("an older API without the billing fields still renders the status", async () => {
266
- mockSubscriptionMe.mockResolvedValue({
267
- ok: true,
268
- body: { actionRequired: false, status: "trialing", accessRevokesAt: null, portalAvailable: false },
269
- });
270
- await renderPage();
271
- expect(screen.getByTestId("account-billing-status")).toHaveTextContent("Trial");
272
- });
273
-
274
- it("canceled with an access end reads 'Access ends <Month D>' in a <time>", async () => {
275
- mockSubscriptionMe.mockResolvedValue(
276
- answer({ status: "canceled", accessRevokesAt: "2026-10-20T00:00:00.000Z" }),
277
- );
278
- await renderPage();
279
- const status = screen.getByTestId("account-billing-status");
280
- expect(status).toHaveTextContent("Access ends October 20 · Visa 4242");
281
- expect(within(status).getByText("October 20")).toHaveAttribute("dateTime", "2026-10-20T00:00:00.000Z");
282
- });
283
-
284
- it("no portal, no Manage plan", async () => {
285
- mockSubscriptionMe.mockResolvedValue(answer({ portalAvailable: false }));
286
- await renderPage();
287
- expect(screen.getByTestId("account-billing")).toBeInTheDocument();
288
- expect(screen.queryByTestId("account-billing-manage")).not.toBeInTheDocument();
289
- });
290
-
291
- it("(f) the read asks for the billing fields with the caller's cookie", async () => {
292
- await renderPage();
293
- expect(mockSubscriptionMe).toHaveBeenCalledWith(
294
- { headers: { cookie: "session=abc" } },
295
- { include: "billing" },
296
- );
297
- });
298
- });
299
-
300
- describe("#11165 AC-2 (B2) — no subscription is the base plan with Upgrade", () => {
301
- it("renders the lowest-priced live plan — Essentials, its price muted, the fallback line — with Upgrade to the next by price, Growth", async () => {
302
- noSubscription();
303
- shown(threePlans());
304
- await renderPage();
305
- const card = screen.getByTestId("account-billing");
306
- expect(within(card).getByTestId("account-billing-plan")).toHaveTextContent("Essentials");
307
- expect(within(card).getByTestId("account-billing-price")).toHaveTextContent("$12,500/mo");
308
- expect(within(card).getByTestId("account-billing-description")).toHaveTextContent(
309
- "Entry-level plan with access to 1, 2, 3, and more.",
310
- );
311
- const upgrade = within(card).getByTestId("account-billing-upgrade");
312
- expect(upgrade).toHaveTextContent("Upgrade");
313
- expect(upgrade).toHaveAttribute("href", "/api/offerings/checkout/growth_monthly");
314
- expect(screen.queryByTestId("account-billing-manage")).not.toBeInTheDocument();
315
- expect(screen.queryByTestId("account-billing-status")).not.toBeInTheDocument();
316
- expect(screen.queryByText("You don't have a subscription.")).not.toBeInTheDocument();
317
- });
318
-
319
- it("the Stripe product's description wins over the fallback line", async () => {
320
- noSubscription();
321
- shown(threePlans([plan("essentials", "Essentials", 1_250_000, { description: "Two sites, one seat." })]));
322
- await renderPage();
323
- expect(screen.getByTestId("account-billing-description")).toHaveTextContent("Two sites, one seat.");
324
- // One plan: nothing above it, so no Upgrade.
325
- expect(screen.queryByTestId("account-billing-upgrade")).not.toBeInTheDocument();
326
- });
327
-
328
- it.each([401, 403, 404])("a %i is no subscription: the base plan, never an error row", async (status) => {
329
- mockSubscriptionMe.mockResolvedValue({ ok: false, status, body: {} });
330
- shown(threePlans());
331
- await renderPage();
332
- expect(screen.getByTestId("account-billing-plan")).toHaveTextContent("Essentials");
333
- expect(screen.queryByTestId("inbox-error")).not.toBeInTheDocument();
334
- });
335
-
336
- it.each([
337
- ["an unconnected site", () => undefined],
338
- ["an empty answer", () => mockOfferingsShown.mockResolvedValue({ ok: true, body: { status: "empty" } })],
339
- ["a failed read", () => mockOfferingsShown.mockRejectedValue(new TypeError("fetch failed"))],
340
- ["a shown set with no live plan", () => shown(threePlans([{ ...plan("seo", "SEO audit", 1000), ailkGroup: "addon" }]))],
341
- ["an expired set", () => shown({ ...threePlans(), state: "expired", offerings: [] })],
342
- ])("with no subscription and %s there is no plan card at all", async (_label, arrange) => {
343
- const errorSpy = jest.spyOn(console, "error").mockImplementation(() => {});
344
- noSubscription();
345
- arrange();
346
- await renderPage();
347
- expect(screen.queryByTestId("account-billing")).not.toBeInTheDocument();
348
- expect(screen.queryByTestId("account-billing-upgrade")).not.toBeInTheDocument();
349
- expect(screen.queryByTestId("inbox-error")).not.toBeInTheDocument();
350
- // Nothing to show is no card at all — never an empty shell.
351
- expect(screen.queryByTestId("account-settings-billing-card")).not.toBeInTheDocument();
352
- errorSpy.mockRestore();
353
- });
354
- });
355
-
356
- describe("#11165 AC-3 (A) — the offer card", () => {
357
- it("renders the first live Offer above the plan card: its name, description, image and Claim offer with its promotion code", async () => {
358
- noSubscription();
359
- shown(threePlans([plan("essentials", "Essentials", 1_250_000), OFFER]));
360
- await renderPage();
361
- const offer = screen.getByTestId("account-billing-offer");
362
- expect(within(offer).getByRole("heading", { level: 2 })).toHaveTextContent("Two weeks of Growth, on us");
363
- expect(within(offer).getByTestId("account-billing-offer-description")).toHaveTextContent(
364
- "Try the Growth plan for two weeks before you commit.",
365
- );
366
- expect(within(offer).getByRole("img", { name: "Two weeks of Growth, on us" })).toHaveAttribute(
367
- "src",
368
- "https://files.stripe.com/links/offer.png",
369
- );
370
- expect(within(offer).getByTestId("account-billing-offer-claim")).toHaveAttribute(
371
- "href",
372
- "/api/offerings/checkout/welcome_once?promo=WELCOME20",
373
- );
374
- expect(within(offer).getByRole("button", { name: "Dismiss offer" })).toBeInTheDocument();
375
- const card = screen.getByTestId("account-billing");
376
- expect(offer.compareDocumentPosition(card) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
377
- // Two cards — the offer's own and the plan's — and the offer's is the first.
378
- const cards = screen.getAllByTestId("account-settings-billing-card");
379
- expect(cards).toHaveLength(2);
380
- expect(cards[0]).toContainElement(offer);
381
- });
382
-
383
- it("renders beside a subscription too, and none when the shown set has no offer", async () => {
384
- shown(threePlans([plan("essentials", "Essentials", 1_250_000), OFFER]));
385
- await renderPage();
386
- expect(screen.getByTestId("account-billing-offer")).toBeInTheDocument();
387
- expect(screen.getByTestId("account-billing-manage")).toBeInTheDocument();
388
- });
389
-
390
- it("none when the shown set has no offer — and no shell for it", async () => {
391
- shown(threePlans());
392
- await renderPage();
393
- expect(screen.queryByTestId("account-billing-offer")).not.toBeInTheDocument();
394
- expect(screen.getAllByTestId("account-settings-billing-card")).toHaveLength(1);
395
- });
396
- });
397
-
398
- describe("(d) — a failed read is the error row, never a plan card", () => {
399
- it("a 500 shows the error row with Retry", async () => {
400
- mockSubscriptionMe.mockResolvedValue({ ok: false, status: 500, body: {} });
401
- shown(threePlans());
402
- await renderPage();
403
- expect(screen.getByTestId("inbox-error")).toHaveTextContent("We couldn't load your billing details.");
404
- expect(screen.getByTestId("inbox-retry")).toBeInTheDocument();
405
- expect(screen.queryByTestId("account-billing")).not.toBeInTheDocument();
406
- });
407
-
408
- it("a throw shows the error row", async () => {
409
- mockSubscriptionMe.mockRejectedValue(new TypeError("fetch failed"));
410
- await renderPage();
411
- expect(screen.getByTestId("inbox-error")).toBeInTheDocument();
412
- expect(screen.queryByTestId("account-billing")).not.toBeInTheDocument();
413
- });
414
- });
415
-
416
- describe("#11165 AC-4 (C) — no History on a single site", () => {
417
- it("never reads member.purchases or member.billing, and renders no History card or purchases list", async () => {
418
- await renderPage();
419
- expect(mockMemberPurchases).not.toHaveBeenCalled();
420
- expect(mockMemberBilling).not.toHaveBeenCalled();
421
- expect(screen.queryByTestId("account-billing-history")).not.toBeInTheDocument();
422
- expect(screen.queryByText("Purchases")).not.toBeInTheDocument();
423
- });
424
- });
425
-
426
- describe("AC-2 (e) — contributed billing sections render after the base content", () => {
427
- const section: AccountBillingSection = {
428
- id: "licence",
429
- title: "settings.billing.title",
430
- render: () => <p data-testid="licence-body">Licence</p>,
431
- };
432
-
433
- beforeAll(() => {
434
- accountBillingSections.push(section);
435
- });
436
-
437
- afterAll(() => {
438
- accountBillingSections.splice(accountBillingSections.indexOf(section), 1);
439
- });
440
-
441
- const states: [string, () => void, string][] = [
442
- ["a subscription", () => undefined, "account-billing"],
443
- ["no subscription", () => { noSubscription(); shown(threePlans()); }, "account-billing"],
444
- ["a 404", () => { mockSubscriptionMe.mockResolvedValue({ ok: false, status: 404, body: {} }); shown(threePlans()); }, "account-billing"],
445
- ["a failed read", () => mockSubscriptionMe.mockResolvedValue({ ok: false, status: 500, body: {} }), "inbox-error"],
446
- ];
447
-
448
- it.each(states)("after %s", async (_label, arrange, baseTestId) => {
449
- arrange();
450
- await renderPage();
451
- const base = screen.getByTestId(baseTestId);
452
- const contributed = screen.getByTestId("account-settings-licence");
453
- expect(within(contributed).getByTestId("licence-body")).toBeInTheDocument();
454
- expect(base.compareDocumentPosition(contributed) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
455
- });
456
- });
457
-
458
- describe("#9401 AC-9 — a site's own section renders after the modules' (D7)", () => {
459
- const moduleSection: AccountBillingSection = {
460
- id: "module",
461
- title: "settings.billing.history",
462
- render: () => <p data-testid="module-body">Module</p>,
463
- };
464
- const siteSection: AccountBillingSection = {
465
- id: "site",
466
- title: "settings.billing.title",
467
- render: () => <p data-testid="site-body">Site</p>,
468
- };
469
-
470
- beforeAll(() => {
471
- accountBillingSections.push(moduleSection);
472
- siteBillingSections.push(siteSection);
473
- });
474
-
475
- afterAll(() => {
476
- accountBillingSections.splice(accountBillingSections.indexOf(moduleSection), 1);
477
- siteBillingSections.splice(siteBillingSections.indexOf(siteSection), 1);
478
- });
479
-
480
- it("renders the module's section, then the site's, each under its translated title", async () => {
481
- await renderPage();
482
- const contributed = screen.getByTestId("account-settings-module");
483
- const site = screen.getByTestId("account-settings-site");
484
- expect(within(contributed).getByTestId("module-body")).toBeInTheDocument();
485
- expect(within(site).getByTestId("site-body")).toBeInTheDocument();
486
- expect(within(contributed).getByRole("heading", { level: 2 })).toHaveTextContent("History");
487
- expect(within(site).getByRole("heading", { level: 2 })).toHaveTextContent("Billing");
488
- expect(contributed.compareDocumentPosition(site) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
489
- });
490
- });
491
-
492
- describe("#8217 AC-1 — the single site's Manage plan (D10, D11)", () => {
493
- const PORTAL_URL = "https://billing.stripe.com/p/session/test_single_site";
494
-
495
- it("mints the portal once through the hub's route with the cookie init, then redirects there", async () => {
496
- mockPortalSession.mockResolvedValue({ ok: true, body: { url: PORTAL_URL } });
497
- await openBillingPortal();
498
- expect(mockPortalSession).toHaveBeenCalledTimes(1);
499
- expect(mockPortalSession).toHaveBeenCalledWith({ headers: { cookie: "session=abc" } });
500
- expect(mockRedirect).toHaveBeenCalledTimes(1);
501
- expect(mockRedirect).toHaveBeenCalledWith(PORTAL_URL);
502
- });
503
-
504
- it.each([
505
- ["a non-2xx", () => mockPortalSession.mockResolvedValue({ ok: false, status: 404, body: {} }), "[openBillingPortal] status=404"],
506
- ["a throw", () => mockPortalSession.mockRejectedValue(new TypeError("fetch failed")), "[openBillingPortal] errName=TypeError"],
507
- ])("%s redirects nowhere and logs only a status or a name", async (_label, arrange, line) => {
508
- const errorSpy = jest.spyOn(console, "error").mockImplementation(() => {});
509
- arrange();
510
- await openBillingPortal();
511
- expect(mockRedirect).not.toHaveBeenCalled();
512
- expect(errorSpy.mock.calls.map((args) => args.join(" "))).toEqual([line]);
513
- errorSpy.mockRestore();
514
- });
515
- });