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,61 +0,0 @@
1
- /**
2
- * The account area's sign-up agreement gate (#8765 D7, spec
3
- * docs/specs/8765-sign-up-refuses-without-the-spec.md).
4
- *
5
- * `outstandingAgreements(ctx)` is the one read the layout and the Inbox
6
- * page share: `GET /v1/consent/account` for the caller, `cache()`d per
7
- * request (keyed on the context `accountSession`, itself cached, hands
8
- * both). The layout shows the interstitial in place of the account while
9
- * it answers anything; the Inbox page awaits it before any loader and
10
- * renders nothing meanwhile, because the App Router renders a page beside
11
- * its layout even when the layout never renders it — and the Inbox's
12
- * `member.messages` read stamps `readAt`.
13
- *
14
- * `[]` when none is outstanding (the read answered `complete: true`, or an
15
- * older hub answered 404). It fails closed (SEC-8765-C): any other answer —
16
- * a thrown read, a 401, 403, 429 or 5xx — is the registry's own agreements
17
- * from the same constant the API reads (#8438 C1), logged `read_failed`.
18
- */
19
-
20
- import { consent } from "@working-theory/api-client";
21
- import type { AccountContext } from "@working-theory/templates/account";
22
- import {
23
- resolveConsentStatement,
24
- SITE_CONSENT_CONFIG_DEFAULTS,
25
- signUpAgreements,
26
- } from "@working-theory/validation";
27
- import { cache } from "react";
28
-
29
- import type { AgreementsInterstitialAgreement } from "./agreements-prompt";
30
-
31
- export const outstandingAgreements = cache(
32
- async (ctx: AccountContext): Promise<AgreementsInterstitialAgreement[]> => {
33
- try {
34
- const res = await consent.accountAgreements(ctx.init, {
35
- locale: ctx.locale,
36
- });
37
- if (res.ok) {
38
- if (res.body.complete) return [];
39
- return res.body.agreements
40
- .filter((agreement) => !agreement.current)
41
- .map(({ id, statement, acceptedVersion }) => ({
42
- id,
43
- statement,
44
- acceptedVersion,
45
- }));
46
- }
47
- if (res.status === 404) return [];
48
- } catch {
49
- // Falls through to the registry's own agreements below.
50
- }
51
- console.error("[account]", {
52
- event: "account-agreements",
53
- outcome: "read_failed",
54
- });
55
- return signUpAgreements(SITE_CONSENT_CONFIG_DEFAULTS).map((purpose) => ({
56
- id: purpose.id,
57
- statement: resolveConsentStatement(purpose, ctx.locale).statement,
58
- acceptedVersion: null,
59
- }));
60
- },
61
- );
@@ -1,184 +0,0 @@
1
- "use client"; // Accept calls a Server Action then refreshes the router; Sign out is the frame's client hook
2
-
3
- /**
4
- * AgreementsInterstitial — the full-page sign-up-agreement ask (#8765 D7,
5
- * spec docs/specs/8765-sign-up-refuses-without-the-spec.md; replaces the
6
- * Inbox's `AgreementsPrompt` card, D8).
7
- *
8
- * The account layout renders this IN PLACE of `AccountFrame` and its
9
- * children whenever `GET /v1/consent/account` answers `complete: false`, or
10
- * fails closed on any read but a 2xx or an older hub's 404 (SEC-8765-C), so no
11
- * account page, rail, Inbox or For-you panel loads behind it. The file keeps
12
- * its name because `create-ailk`'s `surfaces.ts` syncs it by path.
13
- *
14
- * - One `h1`: the "updated" title when any agreement shown has an accepted
15
- * (older) version, else the "new" one — then the lead line.
16
- * - Each statement through `ConsentStatement`, its `[Label](key)` tokens
17
- * linked by `consentPoliciesFor(locale)` (D9) — the three destinations
18
- * `/contact` links (#8761).
19
- * - Accept posts every id through `acceptAccountAgreementsAction`, then
20
- * refreshes, so the layout's next read loads the account; a failed write
21
- * shows the error line and leaves the page as it is.
22
- * - Sign out is always there (D1's "never blocked"): `useAccountSignOut`,
23
- * the frame's own Log out.
24
- *
25
- * The wrapper carries the account area's `data-ailk-shell` marker, so the
26
- * page draws in the same app tokens as the account it stands in for.
27
- */
28
-
29
- import { ConsentStatement } from "@working-theory/ui/blocks";
30
- import {
31
- Button,
32
- Heading,
33
- InlineMessage,
34
- Text,
35
- } from "@working-theory/ui/primitives";
36
- import { useRouter } from "next/navigation";
37
- import { useState, type ReactElement } from "react";
38
-
39
- import { consentPoliciesFor } from "../../../../lib/consent-policies";
40
-
41
- import { useAccountSignOut } from "./account-frame";
42
- import { acceptAccountAgreementsAction } from "./agreements-actions";
43
-
44
- /** One sign-up agreement the person has not accepted at its current version. */
45
- export interface AgreementsInterstitialAgreement {
46
- id: string;
47
- /** The resolved statement, `[Label](key)` tokens included. */
48
- statement: string;
49
- /** The version last accepted, or `null` when never accepted. */
50
- acceptedVersion: number | null;
51
- }
52
-
53
- export interface AgreementsInterstitialLabels {
54
- titleNew: string;
55
- titleUpdated: string;
56
- lead: string;
57
- accept: string;
58
- signOut: string;
59
- error: string;
60
- /** Shown when a hub sign-out is refused or fails (#8465). */
61
- signOutFailed: string;
62
- }
63
-
64
- export interface AgreementsInterstitialProps {
65
- locale: string;
66
- agreements: AgreementsInterstitialAgreement[];
67
- labels: AgreementsInterstitialLabels;
68
- /** The seam's `SIGN_OUT_ENDPOINT`, as the frame takes it (#8465). */
69
- signOutEndpoint?: string | null;
70
- /** Where a hub sign-out lands; defaults to the site home. */
71
- signInHref?: string;
72
- }
73
-
74
- export function AgreementsInterstitial({
75
- locale,
76
- agreements,
77
- labels,
78
- signOutEndpoint,
79
- signInHref,
80
- }: AgreementsInterstitialProps): ReactElement {
81
- const router = useRouter();
82
- const { onSignOut, signOutFailed } = useAccountSignOut({
83
- locale,
84
- signOutEndpoint,
85
- signInHref,
86
- });
87
- const [pending, setPending] = useState(false);
88
- const [error, setError] = useState(false);
89
- const policies = consentPoliciesFor(locale);
90
-
91
- const title = agreements.some(
92
- (agreement) => agreement.acceptedVersion !== null,
93
- )
94
- ? labels.titleUpdated
95
- : labels.titleNew;
96
-
97
- async function accept(): Promise<void> {
98
- setPending(true);
99
- setError(false);
100
- try {
101
- const result = await acceptAccountAgreementsAction(
102
- agreements.map((agreement) => agreement.id),
103
- );
104
- if (result.ok) {
105
- router.refresh();
106
- return;
107
- }
108
- } catch {
109
- // Falls through to the error line below.
110
- }
111
- setError(true);
112
- setPending(false);
113
- }
114
-
115
- return (
116
- <div className="contents" data-ailk-shell="account">
117
- <main
118
- id="main"
119
- className="flex min-h-screen items-center justify-center bg-bg px-4 py-section text-fg"
120
- data-testid="account-agreements-interstitial"
121
- >
122
- <div className="flex w-full max-w-measure flex-col gap-6">
123
- <div className="flex flex-col gap-2">
124
- <Heading level={1} visual={2}>
125
- {title}
126
- </Heading>
127
- <Text as="p" tone="muted">
128
- {labels.lead}
129
- </Text>
130
- </div>
131
-
132
- <div className="flex flex-col gap-3">
133
- {agreements.map((agreement) => (
134
- <span
135
- key={agreement.id}
136
- data-testid={`account-agreements-statement-${agreement.id}`}
137
- >
138
- <ConsentStatement
139
- statement={agreement.statement}
140
- policies={policies}
141
- />
142
- </span>
143
- ))}
144
- </div>
145
-
146
- {error ? (
147
- <InlineMessage
148
- variant="error"
149
- data-testid="account-agreements-error"
150
- >
151
- {labels.error}
152
- </InlineMessage>
153
- ) : null}
154
- {signOutFailed ? (
155
- <InlineMessage variant="error" data-testid="account-sign-out-error">
156
- {labels.signOutFailed}
157
- </InlineMessage>
158
- ) : null}
159
-
160
- <div className="flex flex-col gap-3 md:flex-row">
161
- <Button
162
- type="button"
163
- size="big"
164
- disabled={pending}
165
- onClick={() => void accept()}
166
- data-testid="account-agreements-accept"
167
- >
168
- {labels.accept}
169
- </Button>
170
- <Button
171
- type="button"
172
- variant="ghost"
173
- size="big"
174
- onClick={onSignOut}
175
- data-testid="account-agreements-sign-out"
176
- >
177
- {labels.signOut}
178
- </Button>
179
- </div>
180
- </div>
181
- </main>
182
- </div>
183
- );
184
- }
@@ -1,426 +0,0 @@
1
- /**
2
- * The Appointments pages (#11154).
3
- *
4
- * `/account/appointments` and `/account/appointments/[slug]`, rendered as the
5
- * RSCs they are, with the api-client's `member.meetingTypes` (the offer) and
6
- * `schedule.meetings` (the Cal.com link) as the two mocked reads. Covers:
7
- * - the list renders `AccountListFrame`'s table Title · Duration · Price in
8
- * the read's order, a chevron on every row, each row opening the type's
9
- * booking page, the All count, and the phone rows' "<duration> · <price>"
10
- * captions; a priced type reads its price, an unpriced one "Free";
11
- * - an empty offer and a 404 (and a 401/403 while the email is unverified)
12
- * are the empty line; any other failure is the error row with Retry and
13
- * no frame (7423 D12);
14
- * - the booking page is one H1 over the `scheduler-embed` section (provider
15
- * cal, month view, the tight gap) built from the member read's Cal.com
16
- * link with the member's name and verified email as the section's
17
- * `prefill` (the booker opens with both filled), and "← All
18
- * appointments" under it;
19
- * - a slug the member read does not serve answers "This appointment type is
20
- * no longer offered." with no embed and no public read; a type the member read
21
- * gives no link is the error row; a dotted or malformed segment and
22
- * no session are not-found.
23
- */
24
-
25
- import { render, screen, within } from "@testing-library/react";
26
-
27
- jest.mock("next-intl/server", () => {
28
- const msgs: unknown = require("../../../../../../messages/en.json");
29
- const dig = (obj: unknown, path: string): unknown =>
30
- path
31
- .split(".")
32
- .reduce<unknown>(
33
- (acc, k) =>
34
- acc !== null && typeof acc === "object"
35
- ? (acc as Record<string, unknown>)[k]
36
- : undefined,
37
- obj,
38
- );
39
- return {
40
- __esModule: true,
41
- getTranslations: async (
42
- arg: string | { namespace?: string; locale?: string },
43
- ) => {
44
- const ns = typeof arg === "string" ? arg : (arg.namespace ?? "");
45
- const messages = dig(msgs, ns);
46
- return (key: string, values?: Record<string, unknown>): string => {
47
- const value = dig(messages, key);
48
- if (typeof value !== "string") return `${ns}.${key}`;
49
- return value.replace(/\{(\w+)\}/g, (m, name: string) =>
50
- values && name in values ? String(values[name]) : m,
51
- );
52
- };
53
- },
54
- };
55
- });
56
-
57
- jest.mock("next/headers", () => ({
58
- __esModule: true,
59
- headers: jest.fn().mockResolvedValue(new Headers()),
60
- cookies: jest.fn().mockResolvedValue({ toString: () => "session=abc" }),
61
- }));
62
-
63
- const mockGetSession = jest.fn();
64
- // 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.
65
- jest.mock("../../../../../../auth", () => ({
66
- __esModule: true,
67
- auth: {
68
- api: { getSession: (...args: unknown[]) => mockGetSession(...args) },
69
- },
70
- }));
71
-
72
- const mockMeetingTypes = jest.fn();
73
- const mockMeetings = jest.fn();
74
- jest.mock("@working-theory/api-client", () => ({
75
- __esModule: true,
76
- waitlistSignups: { me: jest.fn() },
77
- subscription: { me: jest.fn() },
78
- member: { meetingTypes: (...args: unknown[]) => mockMeetingTypes(...args) },
79
- schedule: { meetings: (...args: unknown[]) => mockMeetings(...args) },
80
- }));
81
-
82
- const mockNotFound = jest.fn(() => {
83
- throw new Error("NEXT_NOT_FOUND");
84
- });
85
- jest.mock("next/navigation", () => ({
86
- __esModule: true,
87
- notFound: () => mockNotFound(),
88
- useRouter: () => ({ push: jest.fn(), refresh: jest.fn() }),
89
- usePathname: () => "/account/appointments",
90
- }));
91
-
92
- // Render the real catalog, keeping the sections the page handed it: the Cal.com
93
- // island mounts its iframe in an effect, so the calLink is read from the data.
94
- const capturedSections: unknown[] = [];
95
- jest.mock("@working-theory/ui/sections", () => {
96
- const actual = jest.requireActual<
97
- typeof import("@working-theory/ui/sections")
98
- >("@working-theory/ui/sections");
99
- return {
100
- __esModule: true,
101
- ...actual,
102
- SectionRenderer: (props: Parameters<typeof actual.SectionRenderer>[0]) => {
103
- capturedSections.splice(0, capturedSections.length, ...props.sections);
104
- return actual.SectionRenderer(props);
105
- },
106
- };
107
- });
108
-
109
- import BookingPage, { memberBookerSection } from "../[slug]/page";
110
- import ListPage from "../page";
111
-
112
- /** The cookie a single site forwards (`forwardedCookieInit()`). */
113
- const INIT = { headers: { cookie: "session=abc" } };
114
-
115
- const VERIFIED = {
116
- user: {
117
- id: "user_1",
118
- name: "Ada",
119
- email: "ada@example.com",
120
- emailVerified: true,
121
- },
122
- };
123
- const UNVERIFIED = { user: { ...VERIFIED.user, emailVerified: false } };
124
-
125
- const TYPES = [
126
- {
127
- slug: "consult",
128
- title: "Consultation",
129
- durationMinutes: 30,
130
- price: { amountMinor: 5000, currency: "usd" },
131
- calLink: "sam/consult",
132
- },
133
- {
134
- slug: "review",
135
- title: "Design review",
136
- durationMinutes: 60,
137
- calLink: "sam/review",
138
- },
139
- {
140
- slug: "free-chat",
141
- title: "Free chat",
142
- durationMinutes: 15,
143
- price: { amountMinor: 0, currency: "usd" },
144
- },
145
- ];
146
-
147
- /** The public read: never consulted by the member pages (#11154); kept to assert it. */
148
- const MEETINGS = [
149
- {
150
- slug: "consult",
151
- visibility: "public",
152
- position: 0,
153
- bookable: true,
154
- calLink: "sam/consult",
155
- title: "Consultation",
156
- durationMinutes: 30,
157
- },
158
- {
159
- slug: "review",
160
- visibility: "public",
161
- position: 1,
162
- bookable: true,
163
- calLink: "sam/review",
164
- title: "Design review",
165
- durationMinutes: 60,
166
- },
167
- { slug: "gone", visibility: "public", position: 2, bookable: false },
168
- ];
169
-
170
- const ok = <T,>(body: T) => ({ ok: true, body });
171
- const refused = (status: number, code = "x") => ({
172
- ok: false,
173
- status,
174
- body: { ok: false, error: { code, message: "x" } },
175
- });
176
-
177
- beforeEach(() => {
178
- mockGetSession.mockReset().mockResolvedValue(VERIFIED);
179
- mockMeetingTypes.mockReset().mockResolvedValue(ok({ items: TYPES }));
180
- mockMeetings.mockReset().mockResolvedValue(ok({ meetings: MEETINGS }));
181
- mockNotFound.mockClear();
182
- capturedSections.length = 0;
183
- jest.spyOn(console, "error").mockImplementation(() => undefined);
184
- });
185
-
186
- afterEach(() => {
187
- jest.restoreAllMocks();
188
- });
189
-
190
- async function renderList(): Promise<void> {
191
- render(await ListPage({ params: Promise.resolve({ locale: "en" }) }));
192
- }
193
-
194
- async function renderBooking(slug: string): Promise<void> {
195
- render(
196
- await BookingPage({ params: Promise.resolve({ locale: "en", slug }) }),
197
- );
198
- }
199
-
200
- describe("/account/appointments — the types the member read serves (AC-1)", () => {
201
- it("renders Title · Duration · Price in the read's order, a chevron per row, each row opening its booking page", async () => {
202
- await renderList();
203
- expect(screen.getByRole("heading", { level: 1 })).toHaveTextContent(
204
- "Appointments",
205
- );
206
- expect(mockMeetingTypes).toHaveBeenCalledWith(INIT);
207
-
208
- const table = screen.getByTestId("appointments-table");
209
- expect(
210
- within(table)
211
- .getAllByRole("columnheader")
212
- .map((h) => h.textContent),
213
- ).toEqual(["Title", "Duration", "Price", ""]);
214
- const titles = within(table).getAllByTestId(/-title$/);
215
- expect(titles.map((t) => t.textContent)).toEqual([
216
- "Consultation",
217
- "Design review",
218
- "Free chat",
219
- ]);
220
- expect(titles.map((t) => t.getAttribute("href"))).toEqual([
221
- "/account/appointments/consult",
222
- "/account/appointments/review",
223
- "/account/appointments/free-chat",
224
- ]);
225
- for (const slug of ["consult", "review", "free-chat"]) {
226
- expect(
227
- screen.getByTestId(`appointments-table-row-${slug}-chevron`),
228
- ).toBeInTheDocument();
229
- }
230
-
231
- const consult = screen.getByTestId("appointments-table-row-consult");
232
- expect(consult).toHaveTextContent("30 min");
233
- expect(consult).toHaveTextContent("$50");
234
- expect(
235
- screen.getByTestId("appointments-table-row-review"),
236
- ).toHaveTextContent("Free");
237
- expect(
238
- screen.getByTestId("appointments-table-row-free-chat"),
239
- ).toHaveTextContent("Free");
240
-
241
- // The phone rows render the same read: their captions exist in the DOM.
242
- expect(
243
- screen.getAllByTestId("appointments-row").map((r) => r.textContent),
244
- ).toEqual([
245
- expect.stringContaining("30 min · $50"),
246
- expect.stringContaining("60 min · Free"),
247
- expect.stringContaining("15 min · Free"),
248
- ]);
249
-
250
- const nav = screen.getByTestId("appointments-facets");
251
- const items = within(nav).getAllByTestId(/^appointments-facets-item-/);
252
- expect(items.map((i) => i.getAttribute("data-testid"))).toEqual([
253
- "appointments-facets-item-all",
254
- ]);
255
- expect(items[0]).toHaveTextContent("All appointments");
256
- expect(items[0]).toHaveTextContent("3");
257
- // No public read serves the list: the member read alone decides it.
258
- expect(mockMeetings).not.toHaveBeenCalled();
259
- });
260
-
261
- it.each([
262
- ["an empty offer", ok({ items: [] }), VERIFIED],
263
- ["a 404 (no scheduling module)", refused(404, "not_found"), VERIFIED],
264
- [
265
- "a 403 while the email is unverified",
266
- refused(403, "forbidden"),
267
- UNVERIFIED,
268
- ],
269
- ])(
270
- "%s is the empty line, never the error row",
271
- async (_name, answer, session) => {
272
- mockGetSession.mockResolvedValue(session);
273
- mockMeetingTypes.mockResolvedValue(answer);
274
- await renderList();
275
- expect(screen.getByTestId("appointments-empty")).toHaveTextContent(
276
- "No appointment types are offered right now.",
277
- );
278
- expect(
279
- screen.getByTestId("appointments-facets-item-all"),
280
- ).toHaveTextContent("0");
281
- expect(screen.queryByTestId("appointments-table")).toBeNull();
282
- expect(screen.queryByTestId("inbox-error")).toBeNull();
283
- },
284
- );
285
-
286
- it.each([
287
- ["a 500", refused(500, "failed"), VERIFIED],
288
- ["a 403 with a verified email", refused(403, "forbidden"), VERIFIED],
289
- ])(
290
- "%s is the error row with Retry and no frame (7423 D12)",
291
- async (_name, answer, session) => {
292
- mockGetSession.mockResolvedValue(session);
293
- mockMeetingTypes.mockResolvedValue(answer);
294
- await renderList();
295
- expect(screen.getByTestId("inbox-error")).toHaveTextContent(
296
- "We couldn't load your appointment types.",
297
- );
298
- expect(screen.getByRole("button", { name: "Retry" })).toBeInTheDocument();
299
- expect(screen.queryByTestId("appointments-facets")).toBeNull();
300
- expect(screen.queryByTestId("appointments-empty")).toBeNull();
301
- },
302
- );
303
-
304
- it("signed out renders the heading alone and reads nothing", async () => {
305
- mockGetSession.mockResolvedValue(null);
306
- await renderList();
307
- expect(screen.getByRole("heading", { level: 1 })).toHaveTextContent(
308
- "Appointments",
309
- );
310
- expect(mockMeetingTypes).not.toHaveBeenCalled();
311
- expect(mockNotFound).not.toHaveBeenCalled();
312
- });
313
- });
314
-
315
- describe("/account/appointments/<slug> — the member's booking page (AC-2)", () => {
316
- it("renders one H1, the booker from the member read's Cal.com link pre-bound to the member, and the back link", async () => {
317
- await renderBooking("consult");
318
- const h1s = screen.getAllByRole("heading", { level: 1 });
319
- expect(h1s).toHaveLength(1);
320
- expect(h1s[0]).toHaveTextContent("Schedule a consultation meeting");
321
-
322
- expect(screen.getByTestId("scheduler-embed-section")).toBeInTheDocument();
323
- expect(screen.getByTestId("scheduler-embed-cal")).toHaveAttribute(
324
- "data-provider",
325
- "cal",
326
- );
327
- expect(capturedSections).toEqual([
328
- {
329
- id: "appointment-consult",
330
- type: "scheduler-embed",
331
- data: {
332
- provider: "cal",
333
- calLink: "sam/consult",
334
- prefill: { email: "ada@example.com", name: "Ada" },
335
- layout: "month_view",
336
- gapAbove: "tight",
337
- },
338
- },
339
- ]);
340
- // The member's own credential reads the offer and its link (#11154); the
341
- // public read, whose Live set excludes client-only slugs, is never used.
342
- expect(mockMeetingTypes).toHaveBeenCalledWith(INIT);
343
- expect(mockMeetings).not.toHaveBeenCalled();
344
-
345
- expect(screen.getByTestId("appointment-back")).toHaveTextContent(
346
- "← All appointments",
347
- );
348
- expect(screen.getByTestId("appointment-back")).toHaveAttribute(
349
- "href",
350
- "/account/appointments",
351
- );
352
- expect(screen.queryByTestId("appointment-not-offered")).toBeNull();
353
- expect(mockNotFound).not.toHaveBeenCalled();
354
- });
355
-
356
- it("the booker section carries the email alone when the session has no name", () => {
357
- expect(
358
- memberBookerSection("review", "sam/review", {
359
- name: null,
360
- email: "ada@example.com",
361
- }),
362
- ).toEqual({
363
- id: "appointment-review",
364
- type: "scheduler-embed",
365
- data: {
366
- provider: "cal",
367
- calLink: "sam/review",
368
- prefill: { email: "ada@example.com" },
369
- layout: "month_view",
370
- gapAbove: "tight",
371
- },
372
- });
373
- });
374
-
375
- it("a slug the member read does not serve says the type is no longer offered — no embed, no public read", async () => {
376
- await renderBooking("gone");
377
- expect(screen.getByTestId("appointment-not-offered")).toHaveTextContent(
378
- "This appointment type is no longer offered.",
379
- );
380
- expect(screen.queryByTestId("scheduler-embed-section")).toBeNull();
381
- expect(mockMeetings).not.toHaveBeenCalled();
382
- expect(screen.getByTestId("appointment-back")).toHaveAttribute(
383
- "href",
384
- "/account/appointments",
385
- );
386
- expect(mockNotFound).not.toHaveBeenCalled();
387
- });
388
-
389
- it("an offered type the member read carries no link for is the error row under its heading", async () => {
390
- mockMeetingTypes.mockResolvedValue(
391
- ok({ items: TYPES.map(({ calLink: _link, ...type }) => type) }),
392
- );
393
- await renderBooking("consult");
394
- expect(screen.getByRole("heading", { level: 1 })).toHaveTextContent(
395
- "Schedule a consultation meeting",
396
- );
397
- expect(screen.getByTestId("inbox-error")).toHaveTextContent(
398
- "We couldn't load this appointment type.",
399
- );
400
- expect(screen.queryByTestId("scheduler-embed-section")).toBeNull();
401
- });
402
-
403
- it("a failed member read is the error row, with no public read", async () => {
404
- mockMeetingTypes.mockResolvedValue(refused(500, "failed"));
405
- await renderBooking("consult");
406
- expect(screen.getByTestId("inbox-error")).toHaveTextContent(
407
- "We couldn't load this appointment type.",
408
- );
409
- expect(mockMeetings).not.toHaveBeenCalled();
410
- });
411
-
412
- it.each(["intro.html", "Bad Slug", ""])(
413
- "the segment %p is not found before any read",
414
- async (slug) => {
415
- await expect(renderBooking(slug)).rejects.toThrow("NEXT_NOT_FOUND");
416
- expect(mockMeetingTypes).not.toHaveBeenCalled();
417
- expect(mockMeetings).not.toHaveBeenCalled();
418
- },
419
- );
420
-
421
- it("no session is not found", async () => {
422
- mockGetSession.mockResolvedValue(null);
423
- await expect(renderBooking("consult")).rejects.toThrow("NEXT_NOT_FOUND");
424
- expect(mockMeetingTypes).not.toHaveBeenCalled();
425
- });
426
- });