create-ailk 0.38.0 → 0.40.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 (304) hide show
  1. package/dist/add-route.js +16 -1
  2. package/dist/body-heading.d.ts +2 -1
  3. package/dist/body-heading.js +31 -3
  4. package/dist/derive-architecture.js +3 -1
  5. package/dist/module-architecture.js +0 -3
  6. package/dist/remove-module.js +27 -14
  7. package/dist/routes.d.ts +36 -2
  8. package/dist/routes.js +269 -23
  9. package/dist/site-manifest.js +6 -4
  10. package/dist/site-roster.d.ts +11 -3
  11. package/dist/site-roster.js +48 -22
  12. package/dist/surfaces.d.ts +13 -3
  13. package/dist/surfaces.js +128 -194
  14. package/dist/sync-routes.js +22 -5
  15. package/dist/template-record.js +3 -1
  16. package/dist/topology.d.ts +11 -0
  17. package/dist/topology.js +253 -3
  18. package/package.json +3 -3
  19. package/templates/apps/web/CLAUDE.md +32 -4
  20. package/templates/apps/web/__tests__/__mocks__/next-intl-server.ts +6 -1
  21. package/templates/apps/web/__tests__/__mocks__/next-intl.ts +6 -1
  22. package/templates/apps/web/__tests__/auth/seam.test.ts +34 -0
  23. package/templates/apps/web/account.config.tsx +2 -3
  24. package/templates/apps/web/app/[locale]/(authed)/account/connect/__tests__/page.test.tsx +1 -1
  25. package/templates/apps/web/app/[locale]/(authed)/account/connect/page.tsx +1 -1
  26. package/templates/apps/web/app/[locale]/(authed)/signed-out-gate.generated.tsx +1 -1
  27. package/templates/apps/web/app/[locale]/layout.tsx +2 -2
  28. package/templates/apps/web/auth.config.tsx +107 -0
  29. package/templates/apps/web/auth.ts +2 -1
  30. package/templates/apps/web/i18n/request.ts +13 -2
  31. package/templates/apps/web/jest.config.cjs +10 -0
  32. package/templates/apps/web/lib/__tests__/deck-page.test.ts +9 -0
  33. package/templates/apps/web/lib/__tests__/fixtures/site-topology.ts +3 -0
  34. package/templates/apps/web/lib/__tests__/in-page-magnet-self-request.test.ts +1 -1
  35. package/templates/apps/web/lib/__tests__/in-page-magnet.test.ts +2 -2
  36. package/templates/apps/web/lib/__tests__/pricing-page.test.ts +1 -1
  37. package/templates/apps/web/lib/__tests__/server-api.test.ts +1 -1
  38. package/templates/apps/web/lib/__tests__/structured-data.test.tsx +17 -4
  39. package/templates/apps/web/lib/in-page-magnet.ts +2 -2
  40. package/templates/apps/web/lib/pricing-page.ts +3 -3
  41. package/templates/apps/web/lib/server-api.ts +1 -1
  42. package/templates/apps/web/{app/[locale]/contact → lib}/site-contact-email.ts +1 -1
  43. package/templates/apps/web/{app/[locale]/contact → lib}/site-contact-lines.ts +1 -1
  44. package/templates/apps/web/lib/site-header.ts +1 -1
  45. package/templates/apps/web/lib/topology.generated.ts +5 -0
  46. package/templates/apps/web/messages/en.json +0 -271
  47. package/templates/apps/web/middleware.ts +12 -25
  48. package/templates/apps/web/next.config.mjs +15 -0
  49. package/templates/apps/web/package.json +2 -0
  50. package/templates/apps/web/site-pages.config.tsx +85 -0
  51. package/templates/apps/web/types/messages.d.ts +6 -1
  52. package/templates/tools/body-heading.ts +30 -3
  53. package/versions.json +50 -48
  54. package/templates/apps/web/app/[locale]/(auth)/__tests__/auth-pages.test.tsx +0 -322
  55. package/templates/apps/web/app/[locale]/(auth)/__tests__/password-reset.test.tsx +0 -554
  56. package/templates/apps/web/app/[locale]/(auth)/consent/__tests__/consent-actions.test.ts +0 -56
  57. package/templates/apps/web/app/[locale]/(auth)/consent/__tests__/page.test.tsx +0 -164
  58. package/templates/apps/web/app/[locale]/(auth)/consent/consent-form.tsx +0 -132
  59. package/templates/apps/web/app/[locale]/(auth)/consent/consent.actions.ts +0 -51
  60. package/templates/apps/web/app/[locale]/(auth)/consent/page.tsx +0 -144
  61. package/templates/apps/web/app/[locale]/(auth)/forgot-password/forgot-password-card.tsx +0 -101
  62. package/templates/apps/web/app/[locale]/(auth)/forgot-password/page.tsx +0 -111
  63. package/templates/apps/web/app/[locale]/(auth)/layout.tsx +0 -81
  64. package/templates/apps/web/app/[locale]/(auth)/legal-footnote.tsx +0 -35
  65. package/templates/apps/web/app/[locale]/(auth)/reset-password/__tests__/return.test.tsx +0 -179
  66. package/templates/apps/web/app/[locale]/(auth)/reset-password/page.tsx +0 -157
  67. package/templates/apps/web/app/[locale]/(auth)/reset-password/reset-password-card.tsx +0 -126
  68. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/next-path.test.ts +0 -54
  69. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/page.test.tsx +0 -628
  70. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/remembered-method.test.ts +0 -43
  71. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/sign-in-card.test.tsx +0 -266
  72. package/templates/apps/web/app/[locale]/(auth)/sign-in/next-path.ts +0 -20
  73. package/templates/apps/web/app/[locale]/(auth)/sign-in/page.tsx +0 -234
  74. package/templates/apps/web/app/[locale]/(auth)/sign-in/remembered-method.ts +0 -37
  75. package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-card.tsx +0 -323
  76. package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-text.ts +0 -93
  77. package/templates/apps/web/app/[locale]/(auth)/sign-up/__tests__/page.test.tsx +0 -301
  78. package/templates/apps/web/app/[locale]/(auth)/sign-up/__tests__/sign-up-card.test.tsx +0 -309
  79. package/templates/apps/web/app/[locale]/(auth)/sign-up/page.tsx +0 -201
  80. package/templates/apps/web/app/[locale]/(auth)/sign-up/sign-up-card.tsx +0 -366
  81. package/templates/apps/web/app/[locale]/(auth)/use-auth-card-flow.ts +0 -116
  82. package/templates/apps/web/app/[locale]/(auth)/verify-email/__tests__/actions.test.ts +0 -94
  83. package/templates/apps/web/app/[locale]/(auth)/verify-email/actions.ts +0 -77
  84. package/templates/apps/web/app/[locale]/(auth)/verify-email/page.tsx +0 -154
  85. package/templates/apps/web/app/[locale]/(authed)/account/appointments/[slug]/page.tsx +0 -3
  86. package/templates/apps/web/app/[locale]/(authed)/account/appointments/page.tsx +0 -3
  87. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/page.tsx +0 -3
  88. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/versions/[version]/file/route.ts +0 -2
  89. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/page.tsx +0 -3
  90. package/templates/apps/web/app/[locale]/(authed)/account/billing/page.tsx +0 -12
  91. package/templates/apps/web/app/[locale]/(authed)/account/general/page.tsx +0 -12
  92. package/templates/apps/web/app/[locale]/(authed)/account/inbox/[kind]/[id]/page.tsx +0 -12
  93. package/templates/apps/web/app/[locale]/(authed)/account/inbox/message/[id]/file/route.ts +0 -2
  94. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/page.tsx +0 -12
  95. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/page.tsx +0 -3
  96. package/templates/apps/web/app/[locale]/(authed)/account/layout.tsx +0 -10
  97. package/templates/apps/web/app/[locale]/(authed)/account/notifications/page.tsx +0 -3
  98. package/templates/apps/web/app/[locale]/(authed)/account/onboarding/page.tsx +0 -3
  99. package/templates/apps/web/app/[locale]/(authed)/account/page.tsx +0 -12
  100. package/templates/apps/web/app/[locale]/(authed)/account/privacy/export/route.ts +0 -2
  101. package/templates/apps/web/app/[locale]/(authed)/account/privacy/page.tsx +0 -3
  102. package/templates/apps/web/app/[locale]/(authed)/account/security/page.tsx +0 -3
  103. package/templates/apps/web/app/[locale]/(authed)/account/settings/page.tsx +0 -2
  104. package/templates/apps/web/app/[locale]/(authed)/account/support/page.tsx +0 -3
  105. package/templates/apps/web/app/[locale]/(authed)/leads/__tests__/page.test.tsx +0 -205
  106. package/templates/apps/web/app/[locale]/(authed)/leads/components/LeadsTable.tsx +0 -137
  107. package/templates/apps/web/app/[locale]/(authed)/leads/page.tsx +0 -122
  108. package/templates/apps/web/app/[locale]/(authed)/waitlist/components/ForbiddenState.tsx +0 -24
  109. package/templates/apps/web/app/[locale]/(authed)/waitlist/format.ts +0 -111
  110. package/templates/apps/web/app/[locale]/[slug]/[detail]/__tests__/page.test.tsx +0 -402
  111. package/templates/apps/web/app/[locale]/[slug]/[detail]/page.tsx +0 -143
  112. package/templates/apps/web/app/[locale]/[slug]/__tests__/page.test.tsx +0 -148
  113. package/templates/apps/web/app/[locale]/[slug]/page.tsx +0 -109
  114. package/templates/apps/web/app/[locale]/about/[slug]/page.tsx +0 -46
  115. package/templates/apps/web/app/[locale]/about/__tests__/about-routes.test.tsx +0 -353
  116. package/templates/apps/web/app/[locale]/about/page.tsx +0 -122
  117. package/templates/apps/web/app/[locale]/alternatives/__tests__/page.test.tsx +0 -161
  118. package/templates/apps/web/app/[locale]/alternatives/page.tsx +0 -112
  119. package/templates/apps/web/app/[locale]/careers/[slug]/[action]/page.tsx +0 -244
  120. package/templates/apps/web/app/[locale]/careers/[slug]/apply.actions.ts +0 -325
  121. package/templates/apps/web/app/[locale]/careers/[slug]/job-application-form.ts +0 -120
  122. package/templates/apps/web/app/[locale]/careers/[slug]/page.tsx +0 -73
  123. package/templates/apps/web/app/[locale]/careers/__tests__/apply.actions.test.ts +0 -497
  124. package/templates/apps/web/app/[locale]/careers/__tests__/careers-hub.test.tsx +0 -172
  125. package/templates/apps/web/app/[locale]/careers/__tests__/careers-set.test.tsx +0 -153
  126. package/templates/apps/web/app/[locale]/careers/__tests__/job-application-form.test.ts +0 -141
  127. package/templates/apps/web/app/[locale]/careers/__tests__/job-apply-page.test.tsx +0 -546
  128. package/templates/apps/web/app/[locale]/careers/__tests__/page-renderer-migration.test.tsx +0 -189
  129. package/templates/apps/web/app/[locale]/careers/page.tsx +0 -165
  130. package/templates/apps/web/app/[locale]/case-studies/[slug]/page.tsx +0 -49
  131. package/templates/apps/web/app/[locale]/case-studies/__tests__/hub-children.test.tsx +0 -65
  132. package/templates/apps/web/app/[locale]/case-studies/__tests__/page-renderer-migration.test.tsx +0 -125
  133. package/templates/apps/web/app/[locale]/case-studies/page.tsx +0 -49
  134. package/templates/apps/web/app/[locale]/clients/__tests__/page-renderer-migration.test.tsx +0 -85
  135. package/templates/apps/web/app/[locale]/clients/page.tsx +0 -47
  136. package/templates/apps/web/app/[locale]/contact/ConversationalIntakeWrapper.tsx +0 -249
  137. package/templates/apps/web/app/[locale]/contact/__tests__/ConversationalIntakeWrapper.test.tsx +0 -400
  138. package/templates/apps/web/app/[locale]/contact/__tests__/contact-form-magnet.test.ts +0 -138
  139. package/templates/apps/web/app/[locale]/contact/__tests__/contact-form-text.test.ts +0 -49
  140. package/templates/apps/web/app/[locale]/contact/__tests__/contact-magnet-page.test.tsx +0 -494
  141. package/templates/apps/web/app/[locale]/contact/__tests__/contact.actions.test.ts +0 -1122
  142. package/templates/apps/web/app/[locale]/contact/__tests__/intake-analytics.test.ts +0 -51
  143. package/templates/apps/web/app/[locale]/contact/__tests__/page-renderer-migration.test.tsx +0 -319
  144. package/templates/apps/web/app/[locale]/contact/contact-form-magnet.ts +0 -77
  145. package/templates/apps/web/app/[locale]/contact/contact-form-text.ts +0 -52
  146. package/templates/apps/web/app/[locale]/contact/contact.actions.ts +0 -403
  147. package/templates/apps/web/app/[locale]/contact/intake-analytics.ts +0 -49
  148. package/templates/apps/web/app/[locale]/contact/intake-script.ts +0 -92
  149. package/templates/apps/web/app/[locale]/contact/page.tsx +0 -267
  150. package/templates/apps/web/app/[locale]/courses/[slug]/page.tsx +0 -50
  151. package/templates/apps/web/app/[locale]/courses/__tests__/hub-children.test.tsx +0 -32
  152. package/templates/apps/web/app/[locale]/courses/__tests__/page-renderer-migration.test.tsx +0 -123
  153. package/templates/apps/web/app/[locale]/courses/page.tsx +0 -49
  154. package/templates/apps/web/app/[locale]/events/[slug]/page.tsx +0 -57
  155. package/templates/apps/web/app/[locale]/events/__tests__/hub-children.test.tsx +0 -32
  156. package/templates/apps/web/app/[locale]/events/__tests__/page-renderer-migration.test.tsx +0 -164
  157. package/templates/apps/web/app/[locale]/events/__tests__/program-event.test.tsx +0 -120
  158. package/templates/apps/web/app/[locale]/events/page.tsx +0 -60
  159. package/templates/apps/web/app/[locale]/faq/page.tsx +0 -54
  160. package/templates/apps/web/app/[locale]/features/[slug]/page.tsx +0 -54
  161. package/templates/apps/web/app/[locale]/features/__tests__/hub-children.test.tsx +0 -32
  162. package/templates/apps/web/app/[locale]/features/page.tsx +0 -50
  163. package/templates/apps/web/app/[locale]/for/[slug]/page.tsx +0 -54
  164. package/templates/apps/web/app/[locale]/for/__tests__/hub-children.test.tsx +0 -32
  165. package/templates/apps/web/app/[locale]/for/__tests__/page-renderer-migration.test.tsx +0 -90
  166. package/templates/apps/web/app/[locale]/for/page.tsx +0 -51
  167. package/templates/apps/web/app/[locale]/glossary/page.tsx +0 -53
  168. package/templates/apps/web/app/[locale]/how-to/[slug]/page.tsx +0 -50
  169. package/templates/apps/web/app/[locale]/how-to/__tests__/page-renderer-migration.test.tsx +0 -78
  170. package/templates/apps/web/app/[locale]/how-to/page.tsx +0 -50
  171. package/templates/apps/web/app/[locale]/integrations/[slug]/page.tsx +0 -54
  172. package/templates/apps/web/app/[locale]/integrations/__tests__/hub-children.test.tsx +0 -38
  173. package/templates/apps/web/app/[locale]/integrations/__tests__/page-renderer-migration.test.tsx +0 -141
  174. package/templates/apps/web/app/[locale]/integrations/page.tsx +0 -49
  175. package/templates/apps/web/app/[locale]/launch-service/page.tsx +0 -44
  176. package/templates/apps/web/app/[locale]/newsletter/__tests__/page.test.tsx +0 -236
  177. package/templates/apps/web/app/[locale]/newsletter/page.tsx +0 -179
  178. package/templates/apps/web/app/[locale]/page.tsx +0 -147
  179. package/templates/apps/web/app/[locale]/partners/[slug]/page.tsx +0 -45
  180. package/templates/apps/web/app/[locale]/partners/__tests__/hub-children.test.tsx +0 -32
  181. package/templates/apps/web/app/[locale]/partners/__tests__/page-renderer-migration.test.tsx +0 -125
  182. package/templates/apps/web/app/[locale]/partners/page.tsx +0 -49
  183. package/templates/apps/web/app/[locale]/portfolio/[slug]/page.tsx +0 -46
  184. package/templates/apps/web/app/[locale]/portfolio/__tests__/hub-children.test.tsx +0 -38
  185. package/templates/apps/web/app/[locale]/portfolio/page.tsx +0 -50
  186. package/templates/apps/web/app/[locale]/pricing/[slug]/__tests__/page.test.tsx +0 -324
  187. package/templates/apps/web/app/[locale]/pricing/[slug]/page.tsx +0 -87
  188. package/templates/apps/web/app/[locale]/pricing/__tests__/__snapshots__/unconnected.test.tsx.snap +0 -7
  189. package/templates/apps/web/app/[locale]/pricing/__tests__/offerings.test.tsx +0 -605
  190. package/templates/apps/web/app/[locale]/pricing/__tests__/page.test.tsx +0 -219
  191. package/templates/apps/web/app/[locale]/pricing/__tests__/pricing-pages.test.tsx +0 -215
  192. package/templates/apps/web/app/[locale]/pricing/__tests__/unconnected.test.tsx +0 -282
  193. package/templates/apps/web/app/[locale]/pricing/page.tsx +0 -120
  194. package/templates/apps/web/app/[locale]/privacy/page.tsx +0 -40
  195. package/templates/apps/web/app/[locale]/products/[slug]/page.tsx +0 -50
  196. package/templates/apps/web/app/[locale]/products/__tests__/hub-children.test.tsx +0 -32
  197. package/templates/apps/web/app/[locale]/products/__tests__/page-renderer-migration.test.tsx +0 -141
  198. package/templates/apps/web/app/[locale]/products/page.tsx +0 -49
  199. package/templates/apps/web/app/[locale]/projects/[slug]/page.tsx +0 -37
  200. package/templates/apps/web/app/[locale]/projects/__tests__/hub-children.test.tsx +0 -32
  201. package/templates/apps/web/app/[locale]/projects/__tests__/page-renderer-migration.test.tsx +0 -157
  202. package/templates/apps/web/app/[locale]/projects/page.tsx +0 -49
  203. package/templates/apps/web/app/[locale]/purchase-policy/page.tsx +0 -49
  204. package/templates/apps/web/app/[locale]/resources/[slug]/page.tsx +0 -54
  205. package/templates/apps/web/app/[locale]/resources/__tests__/hub-children.test.tsx +0 -38
  206. package/templates/apps/web/app/[locale]/resources/__tests__/page-renderer-migration.test.tsx +0 -151
  207. package/templates/apps/web/app/[locale]/resources/page.tsx +0 -49
  208. package/templates/apps/web/app/[locale]/services/[slug]/[child]/page.tsx +0 -68
  209. package/templates/apps/web/app/[locale]/services/[slug]/page.tsx +0 -88
  210. package/templates/apps/web/app/[locale]/services/__tests__/hub-children.test.tsx +0 -158
  211. package/templates/apps/web/app/[locale]/services/__tests__/page-renderer-migration.test.tsx +0 -187
  212. package/templates/apps/web/app/[locale]/services/__tests__/service-detail-sections.test.tsx +0 -224
  213. package/templates/apps/web/app/[locale]/services/__tests__/service-families.test.tsx +0 -368
  214. package/templates/apps/web/app/[locale]/services/page.tsx +0 -71
  215. package/templates/apps/web/app/[locale]/software/[slug]/page.tsx +0 -49
  216. package/templates/apps/web/app/[locale]/software/__tests__/page-renderer-migration.test.tsx +0 -81
  217. package/templates/apps/web/app/[locale]/software/page.tsx +0 -49
  218. package/templates/apps/web/app/[locale]/team/[slug]/page.tsx +0 -45
  219. package/templates/apps/web/app/[locale]/team/__tests__/hub-children.test.tsx +0 -32
  220. package/templates/apps/web/app/[locale]/team/__tests__/team-routes.test.tsx +0 -161
  221. package/templates/apps/web/app/[locale]/team/page.tsx +0 -50
  222. package/templates/apps/web/app/[locale]/tech-articles/[slug]/page.tsx +0 -54
  223. package/templates/apps/web/app/[locale]/tech-articles/__tests__/page-renderer-migration.test.tsx +0 -82
  224. package/templates/apps/web/app/[locale]/tech-articles/page.tsx +0 -49
  225. package/templates/apps/web/app/[locale]/templates/[slug]/__tests__/page.test.tsx +0 -203
  226. package/templates/apps/web/app/[locale]/templates/[slug]/page.tsx +0 -81
  227. package/templates/apps/web/app/[locale]/templates/__tests__/page.test.tsx +0 -237
  228. package/templates/apps/web/app/[locale]/templates/page.tsx +0 -114
  229. package/templates/apps/web/app/[locale]/terms/page.tsx +0 -40
  230. package/templates/apps/web/app/[locale]/testimonials/__tests__/page-renderer-migration.test.tsx +0 -85
  231. package/templates/apps/web/app/[locale]/testimonials/page.tsx +0 -51
  232. package/templates/apps/web/app/[locale]/thanks/[slug]/__tests__/page.test.tsx +0 -136
  233. package/templates/apps/web/app/[locale]/thanks/[slug]/page.tsx +0 -39
  234. package/templates/apps/web/app/[locale]/unsubscribe/__tests__/unsubscribe-rsc-boundary.test.tsx +0 -226
  235. package/templates/apps/web/app/[locale]/unsubscribe/__tests__/unsubscribe.test.tsx +0 -217
  236. package/templates/apps/web/app/[locale]/unsubscribe/page.tsx +0 -106
  237. package/templates/apps/web/app/[locale]/unsubscribe/unsubscribe-button.tsx +0 -94
  238. package/templates/apps/web/app/[locale]/unsubscribe/unsubscribe.actions.ts +0 -55
  239. package/templates/apps/web/app/[locale]/vs/[slug]/__tests__/page.test.tsx +0 -100
  240. package/templates/apps/web/app/[locale]/vs/[slug]/page.tsx +0 -60
  241. package/templates/apps/web/app/[locale]/whitepapers/[slug]/page.tsx +0 -54
  242. package/templates/apps/web/app/[locale]/whitepapers/__tests__/page-renderer-migration.test.tsx +0 -82
  243. package/templates/apps/web/app/[locale]/whitepapers/page.tsx +0 -49
  244. package/templates/apps/web/app/[locale]/working-agreement/__tests__/page.test.tsx +0 -63
  245. package/templates/apps/web/app/[locale]/working-agreement/page.tsx +0 -41
  246. package/templates/apps/web/app/api/auth/[...all]/route.ts +0 -16
  247. package/templates/apps/web/app/api/auth/hub/__tests__/continuation.test.ts +0 -143
  248. package/templates/apps/web/app/api/auth/hub/__tests__/entry-routes.test.ts +0 -749
  249. package/templates/apps/web/app/api/auth/hub/authorize/__tests__/route.test.ts +0 -964
  250. package/templates/apps/web/app/api/auth/hub/authorize/route.ts +0 -390
  251. package/templates/apps/web/app/api/auth/hub/continuation.ts +0 -127
  252. package/templates/apps/web/app/api/auth/hub/continue/[ref]/__tests__/route.test.ts +0 -188
  253. package/templates/apps/web/app/api/auth/hub/continue/[ref]/route.ts +0 -53
  254. package/templates/apps/web/app/api/auth/hub/email/route.ts +0 -111
  255. package/templates/apps/web/app/api/auth/hub/entry-shared.ts +0 -163
  256. package/templates/apps/web/app/api/auth/hub/password/__tests__/return.test.ts +0 -86
  257. package/templates/apps/web/app/api/auth/hub/password/__tests__/route.test.ts +0 -368
  258. package/templates/apps/web/app/api/auth/hub/password/return.ts +0 -86
  259. package/templates/apps/web/app/api/auth/hub/password/route.ts +0 -171
  260. package/templates/apps/web/app/api/auth/hub/purchase/route.ts +0 -230
  261. package/templates/apps/web/app/api/auth/hub/purchase-link/route.ts +0 -174
  262. package/templates/apps/web/app/api/auth/hub/sign-up/route.ts +0 -60
  263. package/templates/apps/web/app/api/auth/hub/sign-up-evidence.ts +0 -97
  264. package/templates/apps/web/app/api/auth/mcp/__tests__/continuation.test.ts +0 -92
  265. package/templates/apps/web/app/api/auth/mcp/continuation.ts +0 -89
  266. package/templates/apps/web/app/api/auth/mcp/continue/[ref]/__tests__/route.test.ts +0 -59
  267. package/templates/apps/web/app/api/auth/mcp/continue/[ref]/route.ts +0 -41
  268. package/templates/apps/web/app/api/hub-session/__tests__/routes.test.ts +0 -1166
  269. package/templates/apps/web/app/api/hub-session/callback/route.ts +0 -134
  270. package/templates/apps/web/app/api/hub-session/email/route.ts +0 -125
  271. package/templates/apps/web/app/api/hub-session/one-tap/nonce/route.ts +0 -49
  272. package/templates/apps/web/app/api/hub-session/one-tap/route.ts +0 -106
  273. package/templates/apps/web/app/api/hub-session/open/route.ts +0 -111
  274. package/templates/apps/web/app/api/hub-session/password/return/route.ts +0 -69
  275. package/templates/apps/web/app/api/hub-session/password/route.ts +0 -106
  276. package/templates/apps/web/app/api/hub-session/sign-in/route.ts +0 -91
  277. package/templates/apps/web/app/api/hub-session/sign-out/route.ts +0 -54
  278. package/templates/apps/web/components/sign-out-trigger.tsx +0 -62
  279. package/templates/apps/web/lib/__tests__/auth-routes.test.ts +0 -140
  280. package/templates/apps/web/lib/__tests__/hub-children.fixtures.ts +0 -279
  281. package/templates/apps/web/lib/__tests__/route-family.test.ts +0 -57
  282. package/templates/apps/web/lib/__tests__/service-listing.test.ts +0 -111
  283. package/templates/apps/web/lib/__tests__/template-listing.test.ts +0 -158
  284. package/templates/apps/web/lib/auth-routes.ts +0 -125
  285. package/templates/apps/web/lib/hub-children.tsx +0 -351
  286. package/templates/apps/web/lib/hub-session/__tests__/hub-session.test.ts +0 -433
  287. package/templates/apps/web/lib/hub-session/__tests__/spoke-sign-in.test.tsx +0 -332
  288. package/templates/apps/web/lib/hub-session/config.ts +0 -110
  289. package/templates/apps/web/lib/hub-session/entry.ts +0 -238
  290. package/templates/apps/web/lib/hub-session/index.ts +0 -21
  291. package/templates/apps/web/lib/hub-session/one-tap.tsx +0 -148
  292. package/templates/apps/web/lib/hub-session/reseal.ts +0 -90
  293. package/templates/apps/web/lib/hub-session/seal.ts +0 -86
  294. package/templates/apps/web/lib/hub-session/session.ts +0 -298
  295. package/templates/apps/web/lib/hub-session/spoke-sign-in.tsx +0 -277
  296. package/templates/apps/web/lib/meet-placeholder.ts +0 -5
  297. package/templates/apps/web/lib/next-path.ts +0 -35
  298. package/templates/apps/web/lib/posting-title.ts +0 -39
  299. package/templates/apps/web/lib/route-family.ts +0 -69
  300. package/templates/apps/web/lib/service-listing.ts +0 -89
  301. package/templates/apps/web/lib/template-listing.ts +0 -169
  302. package/templates/apps/web/src/lib/__tests__/lead-write.test.ts +0 -187
  303. package/templates/apps/web/src/lib/lead-write.ts +0 -90
  304. /package/templates/apps/web/{app/[locale]/contact → lib}/__tests__/site-contact-lines.test.ts +0 -0
@@ -1,134 +0,0 @@
1
- /**
2
- * Finish a sign-in through the hub (#7894 D2, D7) — `GET /api/hub-session/callback?code=…&state=…`.
3
- *
4
- * The URI an operator registers on the hub (`spokes sign-in-client
5
- * --redirect-uri <site>/api/hub-session/callback`). It reads and clears the
6
- * flow cookie, checks the returned `state` against it in constant time, and
7
- * exchanges the code, the PKCE verifier and the client secret at the hub API
8
- * (the api-client adds this site's spoke key; the hub requires both). On
9
- * success the credential and its person are sealed into the session cookie,
10
- * whose `Max-Age` is the credential's own lifetime, and the visitor lands on
11
- * the flow cookie's `next` — never on a value from this request's query.
12
- *
13
- * Every other outcome — no flow cookie, an expired one, a state mismatch, an
14
- * `error` from the hub, a failed exchange — lands on the site's home
15
- * (#11095 D4; `/account` would redirect straight back into the sign-in, a
16
- * loop) after BURNING any code it received
17
- * (`hubSignIn.revoke({ code })`, best-effort): a code this route cannot
18
- * complete must not stay live for someone else to complete (SEC-7894-4).
19
- * The log line names the reason only — never the query string, a code, a
20
- * state or a credential.
21
- */
22
- import { timingSafeEqual } from "node:crypto";
23
-
24
- import { hubSignIn } from "@working-theory/api-client";
25
- import { hubAuthorizationCodeSchema } from "@working-theory/validation";
26
-
27
- import {
28
- type HubSessionConfig,
29
- hubSessionConfig,
30
- } from "../../../../lib/hub-session/config";
31
- import { unseal } from "../../../../lib/hub-session/seal";
32
- import {
33
- HUB_SESSION_HOME_PATH,
34
- cookieHeader,
35
- flowCookieName,
36
- hubNextPath,
37
- readCookie,
38
- seeOther,
39
- sessionCookieFor,
40
- } from "../../../../lib/hub-session/session";
41
- import { SIGN_IN_PROVIDER } from "../../../../lib/topology.generated";
42
-
43
- /** What the sign-in route sealed into the flow cookie. */
44
- interface FlowPayload {
45
- v: 1;
46
- state: string;
47
- verifier: string;
48
- next: string;
49
- expiresAt: number;
50
- }
51
-
52
- function isFlow(value: unknown): value is FlowPayload {
53
- if (typeof value !== "object" || value === null) return false;
54
- const v = value as Record<string, unknown>;
55
- return (
56
- v["v"] === 1 &&
57
- typeof v["state"] === "string" &&
58
- typeof v["verifier"] === "string" &&
59
- typeof v["next"] === "string" &&
60
- typeof v["expiresAt"] === "number"
61
- );
62
- }
63
-
64
- function sameState(a: string, b: string): boolean {
65
- const x = Buffer.from(a, "utf8");
66
- const y = Buffer.from(b, "utf8");
67
- return x.length === y.length && timingSafeEqual(x, y);
68
- }
69
-
70
- /** Burn a code this route cannot complete. Best-effort: a failure is logged, never thrown. */
71
- async function burn(config: HubSessionConfig, code: string | null): Promise<void> {
72
- if (code === null || !hubAuthorizationCodeSchema.safeParse(code).success) {
73
- return;
74
- }
75
- try {
76
- await hubSignIn.revoke(
77
- { clientId: config.clientId, clientSecret: config.clientSecret },
78
- { code },
79
- );
80
- } catch (err) {
81
- console.error(
82
- `[hub-session] code burn failed errName=${err instanceof Error ? err.name : "unknown"}`,
83
- );
84
- }
85
- }
86
-
87
- // platform-decisions-waiver: api-versioning — sign-in redirect endpoint, not a versioned API contract (spec 7894 §7)
88
- export async function GET(request: Request): Promise<Response> {
89
- if (SIGN_IN_PROVIDER !== "hub") return new Response(null, { status: 404 });
90
- const config = hubSessionConfig();
91
- if (config === null) return seeOther(HUB_SESSION_HOME_PATH);
92
-
93
- const params = new URL(request.url).searchParams;
94
- const code = params.get("code");
95
- const flowName = flowCookieName(config);
96
- const clearFlow = cookieHeader(flowName, "", 0, config);
97
-
98
- const refuse = async (reason: string): Promise<Response> => {
99
- await burn(config, code);
100
- console.warn(`[hub-session] sign-in not completed reason=${reason}`);
101
- return seeOther(HUB_SESSION_HOME_PATH, [clearFlow]);
102
- };
103
-
104
- const sealed = readCookie(request.headers.get("cookie"), flowName);
105
- const flow =
106
- sealed === undefined
107
- ? null
108
- : unseal(sealed, config.sessionSecret, "flow", flowName);
109
- if (!isFlow(flow)) return refuse("no_flow");
110
- if (flow.expiresAt <= Date.now()) return refuse("flow_expired");
111
- const state = params.get("state");
112
- if (state === null || !sameState(state, flow.state)) {
113
- return refuse("state_mismatch");
114
- }
115
- if (params.has("error")) return refuse("hub_error");
116
- if (code === null) return refuse("no_code");
117
-
118
- let exchanged: Awaited<ReturnType<typeof hubSignIn.exchange>>;
119
- try {
120
- exchanged = await hubSignIn.exchange(
121
- { clientId: config.clientId, clientSecret: config.clientSecret },
122
- { code, redirectUri: config.redirectUri, codeVerifier: flow.verifier },
123
- );
124
- } catch {
125
- return refuse("exchange_failed");
126
- }
127
- if (!exchanged.ok) return refuse(`exchange_status_${exchanged.status}`);
128
-
129
- // The cookie's lifetime is the credential's: a malformed answer from the
130
- // hub must never yield a session that does not expire (#11096 D6).
131
- const session = sessionCookieFor(config, exchanged.body);
132
- if (session === null) return refuse("token_response_invalid");
133
- return seeOther(hubNextPath(flow.next), [clearFlow, session]);
134
- }
@@ -1,125 +0,0 @@
1
- /**
2
- * The spoke's own sign-in form, posted (#11096 D2) — `POST /api/hub-session/email`.
3
- *
4
- * The signed-out `/account` of a spoke that signs in through its hub is the
5
- * spoke's own form (`lib/hub-session/spoke-sign-in.tsx`): one email field, the
6
- * hub's sign-up agreements, Continue with Google. Its email lands here as a
7
- * native form POST; this route starts a flow and asks the hub web, server to
8
- * server, to mail the hub's magic link for it. Using the link signs the person
9
- * in on the hub and comes back through the callback, with no hub page shown.
10
- *
11
- * 1. 404 unless `SIGN_IN_PROVIDER` is `"hub"`; not configured → 303
12
- * `/account?error=unavailable`.
13
- * 2. Same-origin only (`Sec-Fetch-Site`, `Origin`), else 403.
14
- * 3. 10 posts per visitor per 10 minutes, then the bot check; a refusal is
15
- * 303 `/account?error=unavailable`.
16
- * 4. The form is `spokeEmailFormSchema`: one `email`, an optional `next`,
17
- * zero or more ticked `agreements`. Any other field — a `password` among
18
- * them (D5) — or a repeated `email` or `next` is 400.
19
- * 5. A flow starts as `GET /api/hub-session/sign-in` starts one.
20
- * 6. The hub web's `POST /api/auth/hub/email` gets the authorize keys, the
21
- * email, the locale and — only when one was ticked — the agreements.
22
- * 7. 202 → 303 `/account?sent=1` with the flow cookie; `agreements_required`
23
- * → `/account?error=agreements`; anything else → `?error=unavailable`.
24
- * Only the 202 sets a cookie.
25
- *
26
- * The answer never says whether the address has an account. Nothing here logs
27
- * the email, the agreements or the flow.
28
- */
29
- import { spokeEmailFormSchema } from "@working-theory/validation";
30
-
31
- import { runBotCheck } from "../../../../lib/bot-check";
32
- import { hubSessionConfig } from "../../../../lib/hub-session/config";
33
- import {
34
- accountPath,
35
- hubError,
36
- localeOfPath,
37
- postToHub,
38
- readFormFields,
39
- } from "../../../../lib/hub-session/entry";
40
- import {
41
- hubNextPath,
42
- isSameOrigin,
43
- seeOther,
44
- startHubFlow,
45
- } from "../../../../lib/hub-session/session";
46
- import { SIGN_IN_PROVIDER } from "../../../../lib/topology.generated";
47
- import { takeVisitorLimit } from "../../../../src/lib/rate-limit";
48
-
49
- /** The hub web's email route (D2). */
50
- const HUB_EMAIL_PATH = "/api/auth/hub/email";
51
-
52
- /** The per-visitor budget for this route. */
53
- const VISITOR_LIMIT = 10;
54
- const VISITOR_WINDOW_MS = 10 * 60_000;
55
-
56
- /** The fields the form may carry, and which of them may repeat. */
57
- const SINGLE_FIELDS = new Set(["email", "next"]);
58
- const AGREEMENTS_FIELD = "agreements";
59
-
60
- /** The form as `spokeEmailFormSchema` reads it, or `null` for a refused shape. */
61
- function formBody(fields: Map<string, string[]>): Record<string, unknown> | null {
62
- const body: Record<string, unknown> = {};
63
- for (const [name, values] of fields) {
64
- if (name === AGREEMENTS_FIELD) {
65
- body[name] = values;
66
- } else if (SINGLE_FIELDS.has(name)) {
67
- if (values.length !== 1) return null;
68
- body[name] = values[0];
69
- } else {
70
- // An unknown field (a password among them) is refused, never dropped.
71
- return null;
72
- }
73
- }
74
- return body;
75
- }
76
-
77
- function badRequest(): Response {
78
- return new Response(null, { status: 400, headers: { "Cache-Control": "no-store" } });
79
- }
80
-
81
- // platform-decisions-waiver: api-versioning — sign-in form endpoint, not a versioned API contract (spec 11096 §6)
82
- export async function POST(request: Request): Promise<Response> {
83
- if (SIGN_IN_PROVIDER !== "hub") return new Response(null, { status: 404 });
84
- const config = hubSessionConfig();
85
- if (config === null) return seeOther(accountPath("en", "error=unavailable"));
86
- if (!isSameOrigin(request, config.siteOrigin)) {
87
- return new Response(null, { status: 403 });
88
- }
89
-
90
- if (!takeVisitorLimit("hub-session-email", request.headers, VISITOR_LIMIT, VISITOR_WINDOW_MS).allowed) {
91
- return seeOther(accountPath("en", "error=unavailable"));
92
- }
93
- const bot = await runBotCheck({ source: "hub-session", target: "email", scope: "write" });
94
- if (bot !== "pass") return seeOther(accountPath("en", "error=unavailable"));
95
-
96
- const fields = await readFormFields(request);
97
- const raw = fields === null ? null : formBody(fields);
98
- const parsed = raw === null ? null : spokeEmailFormSchema.safeParse(raw);
99
- if (parsed === null || !parsed.success) return badRequest();
100
- const next = hubNextPath(parsed.data.next);
101
- const locale = localeOfPath(next);
102
-
103
- const flow = startHubFlow(config, next);
104
- const answer = await postToHub(config, HUB_EMAIL_PATH, {
105
- client_id: config.clientId,
106
- redirect_uri: config.redirectUri,
107
- state: flow.state,
108
- code_challenge: flow.challenge,
109
- code_challenge_method: "S256",
110
- email: parsed.data.email,
111
- locale,
112
- ...(parsed.data.agreements ? { agreements: parsed.data.agreements } : {}),
113
- });
114
-
115
- if (answer?.status === 202) {
116
- return seeOther(accountPath(locale, "sent=1"), [flow.cookie]);
117
- }
118
- if (answer?.status === 400 && hubError(answer) === "agreements_required") {
119
- return seeOther(accountPath(locale, "error=agreements"));
120
- }
121
- console.warn(
122
- `[hub-session] email entry not sent status=${answer === null ? "unreachable" : answer.status}`,
123
- );
124
- return seeOther(accountPath(locale, "error=unavailable"));
125
- }
@@ -1,49 +0,0 @@
1
- /**
2
- * One Tap's nonce (#11096 D10) — `POST /api/hub-session/one-tap/nonce`.
3
- *
4
- * Before the spoke's sign-in page asks Google for a One Tap credential, it
5
- * asks here for a nonce: 32 random bytes, answered to the page and sealed
6
- * into a 300 s `HttpOnly` cookie. Google signs the nonce into the ID token,
7
- * and `POST /api/hub-session/one-tap` hands the hub the cookie's copy, so a
8
- * token minted for another page or another visitor does not verify.
9
- *
10
- * 404 unless this is a hub-sign-in spoke with `AILK_HUB_ONE_TAP=on`; 403
11
- * unless same-origin. Nothing here logs the nonce.
12
- */
13
- import { randomBytes } from "node:crypto";
14
-
15
- import { hubSessionConfig } from "../../../../../lib/hub-session/config";
16
- import { seal } from "../../../../../lib/hub-session/seal";
17
- import {
18
- ONE_TAP_NONCE_TTL_SECONDS,
19
- cookieHeader,
20
- isSameOrigin,
21
- oneTapCookieName,
22
- } from "../../../../../lib/hub-session/session";
23
- import { SIGN_IN_PROVIDER } from "../../../../../lib/topology.generated";
24
-
25
- // platform-decisions-waiver: api-versioning — sign-in step, not a versioned API contract (spec 11096 §6)
26
- export function POST(request: Request): Response {
27
- const config = SIGN_IN_PROVIDER === "hub" ? hubSessionConfig() : null;
28
- if (config === null || !config.oneTap) return new Response(null, { status: 404 });
29
- if (!isSameOrigin(request, config.siteOrigin)) {
30
- return new Response(null, { status: 403 });
31
- }
32
- const nonce = randomBytes(32).toString("base64url");
33
- const name = oneTapCookieName(config);
34
- const sealed = seal(
35
- { v: 1, nonce, expiresAt: Date.now() + ONE_TAP_NONCE_TTL_SECONDS * 1000 },
36
- config.sessionSecret,
37
- "flow",
38
- name,
39
- );
40
- return Response.json(
41
- { nonce },
42
- {
43
- headers: {
44
- "Cache-Control": "no-store",
45
- "Set-Cookie": cookieHeader(name, sealed, ONE_TAP_NONCE_TTL_SECONDS, config),
46
- },
47
- },
48
- );
49
- }
@@ -1,106 +0,0 @@
1
- /**
2
- * Google One Tap for a returning person (#11096 D10) — `POST /api/hub-session/one-tap`.
3
- *
4
- * The spoke's `OneTap` island posts Google's ID token here as
5
- * `{ credential }`. This route reads and clears the nonce cookie the nonce
6
- * route set, and forwards the token, that nonce and this site's own origin to
7
- * the hub API's `POST /v1/hub-sign-in/google`, authenticated as this spoke's
8
- * client. The hub verifies the token against Google's keys and mints the
9
- * credential the code exchange mints; this route seals it into the session
10
- * cookie (`sessionCookieFor`) and answers `{ ok: true }`. The page then
11
- * navigates to `next` on this site. No hub page and no Google page is shown.
12
- *
13
- * - 404 unless this is a hub-sign-in spoke with `AILK_HUB_ONE_TAP=on`;
14
- * - 403 unless same-origin;
15
- * - 400 for a body other than `spokeOneTapBodySchema` (a `password` field
16
- * among them, D5) or with no live nonce cookie — no hub call;
17
- * - 401 `{ ok: false }` for every hub refusal, so the page leaves the form
18
- * as it is.
19
- *
20
- * Nothing here logs the token, the nonce or the credential.
21
- */
22
- import { hubSignIn } from "@working-theory/api-client";
23
- import { spokeOneTapBodySchema } from "@working-theory/validation";
24
-
25
- import { hubSessionConfig } from "../../../../lib/hub-session/config";
26
- import { readBodyText } from "../../../../lib/hub-session/entry";
27
- import { unseal } from "../../../../lib/hub-session/seal";
28
- import {
29
- cookieHeader,
30
- isSameOrigin,
31
- oneTapCookieName,
32
- readCookie,
33
- sessionCookieFor,
34
- } from "../../../../lib/hub-session/session";
35
- import { SIGN_IN_PROVIDER } from "../../../../lib/topology.generated";
36
- import { takeVisitorLimit } from "../../../../src/lib/rate-limit";
37
-
38
- const VISITOR_LIMIT = 10;
39
- const VISITOR_WINDOW_MS = 10 * 60_000;
40
-
41
- function answer(status: number, ok: boolean, setCookies: readonly string[]): Response {
42
- const headers = new Headers({ "Cache-Control": "no-store" });
43
- for (const value of setCookies) headers.append("Set-Cookie", value);
44
- return Response.json({ ok }, { status, headers });
45
- }
46
-
47
- /** `text` as JSON, or `null` when there is none or it does not parse. */
48
- function parseJson(text: string | null): unknown {
49
- if (text === null) return null;
50
- try {
51
- return JSON.parse(text) as unknown;
52
- } catch {
53
- return null;
54
- }
55
- }
56
-
57
- /** The nonce the cookie seals, or `null` — absent, unreadable or expired. */
58
- function sealedNonce(value: unknown): string | null {
59
- if (typeof value !== "object" || value === null) return null;
60
- const v = value as Record<string, unknown>;
61
- if (v["v"] !== 1 || typeof v["nonce"] !== "string") return null;
62
- if (typeof v["expiresAt"] !== "number" || v["expiresAt"] <= Date.now()) return null;
63
- return v["nonce"];
64
- }
65
-
66
- // platform-decisions-waiver: api-versioning — sign-in step, not a versioned API contract (spec 11096 §6)
67
- export async function POST(request: Request): Promise<Response> {
68
- const config = SIGN_IN_PROVIDER === "hub" ? hubSessionConfig() : null;
69
- if (config === null || !config.oneTap) return new Response(null, { status: 404 });
70
- if (!isSameOrigin(request, config.siteOrigin)) {
71
- return new Response(null, { status: 403 });
72
- }
73
- if (!takeVisitorLimit("hub-session-one-tap", request.headers, VISITOR_LIMIT, VISITOR_WINDOW_MS).allowed) {
74
- return answer(429, false, []);
75
- }
76
-
77
- // The nonce is single use: cleared on every answer from here on.
78
- const name = oneTapCookieName(config);
79
- const clearNonce = cookieHeader(name, "", 0, config);
80
- const sealed = readCookie(request.headers.get("cookie"), name);
81
- const nonce =
82
- sealed === undefined ? null : sealedNonce(unseal(sealed, config.sessionSecret, "flow", name));
83
-
84
- const body = spokeOneTapBodySchema.safeParse(parseJson(await readBodyText(request)));
85
- if (!body.success || nonce === null) return answer(400, false, [clearNonce]);
86
-
87
- let res: Awaited<ReturnType<typeof hubSignIn.google>>;
88
- try {
89
- res = await hubSignIn.google(
90
- { clientId: config.clientId, clientSecret: config.clientSecret },
91
- { idToken: body.data.credential, nonce, origin: config.siteOrigin },
92
- );
93
- } catch (err) {
94
- console.error(
95
- `[hub-session] one tap failed errName=${err instanceof Error ? err.name : "unknown"}`,
96
- );
97
- return answer(401, false, [clearNonce]);
98
- }
99
- if (!res.ok) {
100
- console.warn(`[hub-session] one tap refused status=${res.status}`);
101
- return answer(401, false, [clearNonce]);
102
- }
103
- const session = sessionCookieFor(config, res.body);
104
- if (session === null) return answer(401, false, [clearNonce]);
105
- return answer(200, true, [clearNonce, session]);
106
- }
@@ -1,111 +0,0 @@
1
- /**
2
- * "Open my account" from a purchase link (#11096 D9) — `POST /api/hub-session/open`.
3
- *
4
- * After a paid Checkout Session the hub mails the buyer one link to this
5
- * spoke's `/account?claim=<claim>`. That page's GET changes nothing (a mail
6
- * scanner that follows the link creates no account, SEC-11096-3): it shows
7
- * the agreements and one "Open my account" button, whose form posts the
8
- * claim here. This route starts a flow and spends the claim at the hub web's
9
- * `POST /api/auth/hub/purchase`, server to server, as this spoke's client.
10
- *
11
- * - 200 `{ verifyUrl }` on the hub's own origin → 303 there, with the flow
12
- * cookie: the hub's verify creates the account, and the redirects land on
13
- * `/account` signed in;
14
- * - 409 `account_exists` → 303 `/account?error=exists` (the form asks for
15
- * the email instead: a claim never signs an existing account in);
16
- * - anything else → 303 `/account?error=claim`.
17
- *
18
- * The checks in front are the email route's (D2 steps 1–3); the body is
19
- * `spokeOpenFormSchema`, the one `claim` field. Nothing here logs the claim.
20
- */
21
- import { hubPurchaseResponseSchema, spokeOpenFormSchema } from "@working-theory/validation";
22
-
23
- import { runBotCheck } from "../../../../lib/bot-check";
24
- import { hubSessionConfig } from "../../../../lib/hub-session/config";
25
- import {
26
- accountPath,
27
- hubError,
28
- postToHub,
29
- readFormFields,
30
- } from "../../../../lib/hub-session/entry";
31
- import {
32
- HUB_SESSION_FALLBACK_PATH,
33
- isSameOrigin,
34
- seeOther,
35
- startHubFlow,
36
- } from "../../../../lib/hub-session/session";
37
- import { SIGN_IN_PROVIDER } from "../../../../lib/topology.generated";
38
- import { takeVisitorLimit } from "../../../../src/lib/rate-limit";
39
-
40
- /** The hub web's claim-spending route (D9). */
41
- const HUB_PURCHASE_PATH = "/api/auth/hub/purchase";
42
-
43
- const VISITOR_LIMIT = 10;
44
- const VISITOR_WINDOW_MS = 10 * 60_000;
45
-
46
- /** The one `claim` field, or `null` for any other shape. */
47
- function formBody(fields: Map<string, string[]>): Record<string, unknown> | null {
48
- const body: Record<string, unknown> = {};
49
- for (const [name, values] of fields) {
50
- if (values.length !== 1) return null;
51
- body[name] = values[0];
52
- }
53
- return body;
54
- }
55
-
56
- /** `raw` when it is a URL on `hubOrigin`, else `null`. */
57
- function hubUrl(raw: string, hubOrigin: string): string | null {
58
- try {
59
- const url = new URL(raw);
60
- return url.origin === hubOrigin ? url.toString() : null;
61
- } catch {
62
- return null;
63
- }
64
- }
65
-
66
- // platform-decisions-waiver: api-versioning — sign-in form endpoint, not a versioned API contract (spec 11096 §6)
67
- export async function POST(request: Request): Promise<Response> {
68
- if (SIGN_IN_PROVIDER !== "hub") return new Response(null, { status: 404 });
69
- const config = hubSessionConfig();
70
- if (config === null) return seeOther(accountPath("en", "error=unavailable"));
71
- if (!isSameOrigin(request, config.siteOrigin)) {
72
- return new Response(null, { status: 403 });
73
- }
74
- const refused = seeOther(accountPath("en", "error=claim"));
75
- if (!takeVisitorLimit("hub-session-open", request.headers, VISITOR_LIMIT, VISITOR_WINDOW_MS).allowed) {
76
- return refused;
77
- }
78
- if ((await runBotCheck({ source: "hub-session", target: "open", scope: "write" })) !== "pass") {
79
- return refused;
80
- }
81
-
82
- const fields = await readFormFields(request);
83
- const raw = fields === null ? null : formBody(fields);
84
- const parsed = raw === null ? null : spokeOpenFormSchema.safeParse(raw);
85
- if (parsed === null || !parsed.success) {
86
- return new Response(null, { status: 400, headers: { "Cache-Control": "no-store" } });
87
- }
88
-
89
- const flow = startHubFlow(config, HUB_SESSION_FALLBACK_PATH);
90
- const answer = await postToHub(config, HUB_PURCHASE_PATH, {
91
- claim: parsed.data.claim,
92
- client_id: config.clientId,
93
- redirect_uri: config.redirectUri,
94
- state: flow.state,
95
- code_challenge: flow.challenge,
96
- code_challenge_method: "S256",
97
- });
98
-
99
- if (answer?.status === 200) {
100
- const body = hubPurchaseResponseSchema.safeParse(answer.body);
101
- const verifyUrl = body.success ? hubUrl(body.data.verifyUrl, config.hubOrigin) : null;
102
- if (verifyUrl !== null) return seeOther(verifyUrl, [flow.cookie]);
103
- }
104
- if (answer?.status === 409 && hubError(answer) === "account_exists") {
105
- return seeOther(accountPath("en", "error=exists"));
106
- }
107
- console.warn(
108
- `[hub-session] purchase claim not opened status=${answer === null ? "unreachable" : answer.status} reason=${hubError(answer) ?? "none"}`,
109
- );
110
- return refused;
111
- }
@@ -1,69 +0,0 @@
1
- /**
2
- * Where the hub's set-password page returns a spoke's person (#11162) —
3
- * `GET /api/hub-session/password/return?next=<path>`.
4
- *
5
- * Saving a password on the hub ends every session and every spoke
6
- * credential the person held (`onPasswordReset`, SEC-7894-5) — the Security
7
- * tab's own copy says so. The sealed cookie this spoke keeps therefore
8
- * names a credential the hub no longer honours, and a page that read it as
9
- * signed in would fail closed on the hub's refusal instead of showing the
10
- * tab. So the hub's page lands here first:
11
- *
12
- * 1. 404 unless `SIGN_IN_PROVIDER` is `"hub"`; not configured → 303 home.
13
- * 2. `next` is the sanitized same-origin page path (`hubNextPath`), else
14
- * `/account`.
15
- * 3. With a session cookie, the hub is asked once whether the credential
16
- * still stands (`GET /v1/hub-sign-in/me`). A 401 — the one status the
17
- * hub answers a credential it no longer honours — clears the cookie, so
18
- * the gate on `next` shows this spoke's own sign-in form and the person
19
- * comes back to the tab with a fresh credential; a credential the hub
20
- * still honours, no cookie, or a hub that cannot answer (a limit, an
21
- * outage, a thrown read) leaves the cookie as it is.
22
- * 4. 303 to `next`, always.
23
- *
24
- * A GET, reachable cross-site: it changes nothing an attacker could not
25
- * already cause — the one write is to drop a cookie the hub has ALREADY
26
- * refused, and no credential is revoked here. Nothing is logged but a
27
- * status; the credential never is.
28
- */
29
- import { hubSignIn } from "@working-theory/api-client";
30
-
31
- import { hubSessionConfig } from "../../../../../lib/hub-session/config";
32
- import {
33
- cookieHeader,
34
- HUB_SESSION_HOME_PATH,
35
- hubNextPath,
36
- readHubSessionPayload,
37
- seeOther,
38
- sessionCookieName,
39
- } from "../../../../../lib/hub-session/session";
40
- import { SIGN_IN_PROVIDER } from "../../../../../lib/topology.generated";
41
-
42
- /**
43
- * Whether the hub still honours the credential: `false` only on its 401,
44
- * `null` when it could not answer — any other status, or a thrown read.
45
- */
46
- async function credentialStands(accessToken: string): Promise<boolean | null> {
47
- try {
48
- const res = await hubSignIn.me({ headers: { authorization: `Bearer ${accessToken}` } });
49
- if (res.ok) return true;
50
- return res.status === 401 ? false : null;
51
- } catch {
52
- return null;
53
- }
54
- }
55
-
56
- // platform-decisions-waiver: api-versioning — a sign-in step of the spoke's own form, not a versioned API contract (spec 11096 §6)
57
- export async function GET(request: Request): Promise<Response> {
58
- if (SIGN_IN_PROVIDER !== "hub") return new Response(null, { status: 404 });
59
- const config = hubSessionConfig();
60
- if (config === null) return seeOther(HUB_SESSION_HOME_PATH);
61
-
62
- const next = hubNextPath(new URL(request.url).searchParams.get("next"));
63
- const session = readHubSessionPayload(request.headers);
64
- if (session === null) return seeOther(next);
65
-
66
- const stands = await credentialStands(session.accessToken);
67
- if (stands !== false) return seeOther(next);
68
- return seeOther(next, [cookieHeader(sessionCookieName(config), "", 0, config)]);
69
- }