create-ailk 0.37.1 → 0.39.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 (318) hide show
  1. package/README.md +129 -0
  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 +2 -2
  6. package/dist/add-route.js +19 -12
  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 +12 -16
  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 +73 -2
  26. package/dist/routes.d.ts +130 -0
  27. package/dist/routes.js +954 -0
  28. package/dist/site-manifest.js +6 -4
  29. package/dist/site-roster.d.ts +11 -2
  30. package/dist/site-roster.js +63 -21
  31. package/dist/spoke-checkout.d.ts +28 -27
  32. package/dist/spoke-checkout.js +71 -102
  33. package/dist/surfaces.d.ts +26 -0
  34. package/dist/surfaces.js +105 -293
  35. package/dist/sync-routes.d.ts +14 -1
  36. package/dist/sync-routes.js +108 -10
  37. package/dist/template-record.js +3 -1
  38. package/dist/topology.d.ts +26 -1
  39. package/dist/topology.js +273 -7
  40. package/dist/update.d.ts +17 -2
  41. package/dist/update.js +480 -77
  42. package/package.json +3 -3
  43. package/templates/README.md +1 -1
  44. package/templates/apps/mcp/CLAUDE.md +5 -3
  45. package/templates/apps/web/CLAUDE.md +87 -23
  46. package/templates/apps/web/__tests__/__mocks__/next-intl-server.ts +5 -1
  47. package/templates/apps/web/__tests__/__mocks__/next-intl.ts +5 -1
  48. package/templates/apps/web/__tests__/auth/seam.test.ts +34 -0
  49. package/templates/apps/web/account.config.tsx +100 -0
  50. package/templates/apps/web/app/[locale]/(authed)/account/connect/__tests__/page.test.tsx +1 -1
  51. package/templates/apps/web/app/[locale]/(authed)/account/connect/page.tsx +2 -2
  52. package/templates/apps/web/app/[locale]/(authed)/signed-out-gate.generated.tsx +1 -1
  53. package/templates/apps/web/app/[locale]/layout.tsx +46 -29
  54. package/templates/apps/web/app/apple-icon.tsx +72 -0
  55. package/templates/apps/web/app/llms.txt/__tests__/site-listing.test.ts +22 -12
  56. package/templates/apps/web/app/og/__tests__/__snapshots__/card.test.tsx.snap +3 -0
  57. package/templates/apps/web/app/og/__tests__/card.test.tsx +129 -0
  58. package/templates/apps/web/app/og/__tests__/route.test.ts +3 -4
  59. package/templates/apps/web/app/og/route.tsx +155 -72
  60. package/templates/apps/web/app/sitemap.xml/__tests__/site-listing.test.ts +12 -0
  61. package/templates/apps/web/auth.config.tsx +107 -0
  62. package/templates/apps/web/auth.ts +2 -1
  63. package/templates/apps/web/i18n/request.ts +51 -1
  64. package/templates/apps/web/jest.config.cjs +17 -1
  65. package/templates/apps/web/lib/__tests__/auth-phone.test.ts +11 -0
  66. package/templates/apps/web/lib/__tests__/fixtures/site-topology.ts +73 -0
  67. package/templates/apps/web/lib/__tests__/nav-label-keys.test.ts +14 -0
  68. package/templates/apps/web/lib/__tests__/profile-back-link.test.ts +148 -61
  69. package/templates/apps/web/lib/__tests__/served-pages.test.ts +77 -0
  70. package/templates/apps/web/lib/__tests__/server-api.test.ts +37 -5
  71. package/templates/apps/web/lib/__tests__/structured-data.test.tsx +26 -13
  72. package/templates/apps/web/lib/listings.tsx +2 -2
  73. package/templates/apps/web/lib/nav-label-keys.ts +16 -2
  74. package/templates/apps/web/lib/paid-section-contracts.ts +35 -6
  75. package/templates/apps/web/lib/paid-sections.generated.ts +8 -0
  76. package/templates/apps/web/lib/profile-back-link.ts +105 -32
  77. package/templates/apps/web/lib/served-pages.ts +95 -0
  78. package/templates/apps/web/lib/server-api.ts +1 -1
  79. package/templates/apps/web/lib/site-brand.tsx +3 -5
  80. package/templates/apps/web/lib/topology.generated.ts +5 -0
  81. package/templates/apps/web/messages/en.json +8 -836
  82. package/templates/apps/web/middleware.ts +15 -26
  83. package/templates/apps/web/next.config.mjs +35 -0
  84. package/templates/apps/web/package.json +2 -0
  85. package/templates/apps/web/types/messages.d.ts +6 -1
  86. package/templates/customizations.yaml +9 -0
  87. package/templates/package.json +3 -1
  88. package/templates/tools/lint-architecture.ts +164 -11
  89. package/versions.json +49 -47
  90. package/templates/apps/web/app/[locale]/(auth)/__tests__/auth-pages.test.tsx +0 -322
  91. package/templates/apps/web/app/[locale]/(auth)/__tests__/password-reset.test.tsx +0 -554
  92. package/templates/apps/web/app/[locale]/(auth)/consent/__tests__/consent-actions.test.ts +0 -56
  93. package/templates/apps/web/app/[locale]/(auth)/consent/__tests__/page.test.tsx +0 -164
  94. package/templates/apps/web/app/[locale]/(auth)/consent/consent-form.tsx +0 -132
  95. package/templates/apps/web/app/[locale]/(auth)/consent/consent.actions.ts +0 -51
  96. package/templates/apps/web/app/[locale]/(auth)/consent/page.tsx +0 -144
  97. package/templates/apps/web/app/[locale]/(auth)/forgot-password/forgot-password-card.tsx +0 -101
  98. package/templates/apps/web/app/[locale]/(auth)/forgot-password/page.tsx +0 -111
  99. package/templates/apps/web/app/[locale]/(auth)/layout.tsx +0 -81
  100. package/templates/apps/web/app/[locale]/(auth)/legal-footnote.tsx +0 -35
  101. package/templates/apps/web/app/[locale]/(auth)/reset-password/__tests__/return.test.tsx +0 -179
  102. package/templates/apps/web/app/[locale]/(auth)/reset-password/page.tsx +0 -157
  103. package/templates/apps/web/app/[locale]/(auth)/reset-password/reset-password-card.tsx +0 -126
  104. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/next-path.test.ts +0 -54
  105. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/page.test.tsx +0 -628
  106. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/remembered-method.test.ts +0 -43
  107. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/sign-in-card.test.tsx +0 -266
  108. package/templates/apps/web/app/[locale]/(auth)/sign-in/next-path.ts +0 -20
  109. package/templates/apps/web/app/[locale]/(auth)/sign-in/page.tsx +0 -234
  110. package/templates/apps/web/app/[locale]/(auth)/sign-in/remembered-method.ts +0 -37
  111. package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-card.tsx +0 -323
  112. package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-text.ts +0 -93
  113. package/templates/apps/web/app/[locale]/(auth)/sign-up/__tests__/page.test.tsx +0 -301
  114. package/templates/apps/web/app/[locale]/(auth)/sign-up/__tests__/sign-up-card.test.tsx +0 -309
  115. package/templates/apps/web/app/[locale]/(auth)/sign-up/page.tsx +0 -201
  116. package/templates/apps/web/app/[locale]/(auth)/sign-up/sign-up-card.tsx +0 -366
  117. package/templates/apps/web/app/[locale]/(auth)/use-auth-card-flow.ts +0 -116
  118. package/templates/apps/web/app/[locale]/(auth)/verify-email/__tests__/actions.test.ts +0 -94
  119. package/templates/apps/web/app/[locale]/(auth)/verify-email/actions.ts +0 -77
  120. package/templates/apps/web/app/[locale]/(auth)/verify-email/page.tsx +0 -154
  121. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/account-frame-sign-out.test.tsx +0 -175
  122. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/agreements-prompt.test.tsx +0 -301
  123. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/billing.test.tsx +0 -515
  124. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/general.test.tsx +0 -883
  125. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/hub-mode.test.tsx +0 -758
  126. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/item.test.tsx +0 -264
  127. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout-sign-out.test.tsx +0 -167
  128. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout.test.tsx +0 -730
  129. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-menu.test.tsx +0 -355
  130. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-popups.test.tsx +0 -97
  131. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/notifications.test.tsx +0 -375
  132. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/onboarding.test.tsx +0 -323
  133. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/page.test.tsx +0 -1208
  134. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/popups.test.tsx +0 -418
  135. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/privacy.test.tsx +0 -462
  136. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/rich-translator.ts +0 -63
  137. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/security.test.tsx +0 -406
  138. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/settings.test.tsx +0 -93
  139. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/support.test.tsx +0 -208
  140. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/thread.test.tsx +0 -340
  141. package/templates/apps/web/app/[locale]/(authed)/account/account-data.ts +0 -182
  142. package/templates/apps/web/app/[locale]/(authed)/account/account-frame.tsx +0 -353
  143. package/templates/apps/web/app/[locale]/(authed)/account/actions.ts +0 -57
  144. package/templates/apps/web/app/[locale]/(authed)/account/agreements-actions.ts +0 -58
  145. package/templates/apps/web/app/[locale]/(authed)/account/agreements-gate.ts +0 -61
  146. package/templates/apps/web/app/[locale]/(authed)/account/agreements-prompt.tsx +0 -184
  147. package/templates/apps/web/app/[locale]/(authed)/account/appointments/[slug]/page.tsx +0 -161
  148. package/templates/apps/web/app/[locale]/(authed)/account/appointments/__tests__/page.test.tsx +0 -426
  149. package/templates/apps/web/app/[locale]/(authed)/account/appointments/appointments-data.ts +0 -76
  150. package/templates/apps/web/app/[locale]/(authed)/account/appointments/page.tsx +0 -139
  151. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/page.tsx +0 -406
  152. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/pay-form.tsx +0 -65
  153. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/review-form.tsx +0 -172
  154. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/versions/[version]/file/route.ts +0 -190
  155. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/file-route.test.ts +0 -333
  156. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/page.test.tsx +0 -936
  157. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/pay.test.tsx +0 -193
  158. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/review.test.tsx +0 -476
  159. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/artifact-actions.ts +0 -184
  160. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/artifact-data.ts +0 -197
  161. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/page.tsx +0 -182
  162. package/templates/apps/web/app/[locale]/(authed)/account/billing/__tests__/offerings.test.ts +0 -99
  163. package/templates/apps/web/app/[locale]/(authed)/account/billing/offerings.ts +0 -123
  164. package/templates/apps/web/app/[locale]/(authed)/account/billing/page.tsx +0 -424
  165. package/templates/apps/web/app/[locale]/(authed)/account/billing-source.ts +0 -303
  166. package/templates/apps/web/app/[locale]/(authed)/account/components/request-quote.tsx +0 -274
  167. package/templates/apps/web/app/[locale]/(authed)/account/error-row.tsx +0 -35
  168. package/templates/apps/web/app/[locale]/(authed)/account/for-you-labels.ts +0 -36
  169. package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/phone-verification.test.tsx +0 -215
  170. package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/seam-imports.test.ts +0 -65
  171. package/templates/apps/web/app/[locale]/(authed)/account/general/account-name.ts +0 -36
  172. package/templates/apps/web/app/[locale]/(authed)/account/general/billing-anchor.tsx +0 -27
  173. package/templates/apps/web/app/[locale]/(authed)/account/general/contact-actions.ts +0 -149
  174. package/templates/apps/web/app/[locale]/(authed)/account/general/contact-details.tsx +0 -42
  175. package/templates/apps/web/app/[locale]/(authed)/account/general/deletion-request.tsx +0 -132
  176. package/templates/apps/web/app/[locale]/(authed)/account/general/page.tsx +0 -218
  177. package/templates/apps/web/app/[locale]/(authed)/account/general/phone-actions.ts +0 -122
  178. package/templates/apps/web/app/[locale]/(authed)/account/general/phone-verification.tsx +0 -215
  179. package/templates/apps/web/app/[locale]/(authed)/account/general/photo-actions.ts +0 -73
  180. package/templates/apps/web/app/[locale]/(authed)/account/general/profile-form.tsx +0 -107
  181. package/templates/apps/web/app/[locale]/(authed)/account/general/profile-source.ts +0 -87
  182. package/templates/apps/web/app/[locale]/(authed)/account/inbox/[kind]/[id]/page.tsx +0 -119
  183. package/templates/apps/web/app/[locale]/(authed)/account/inbox/message/[id]/file/__tests__/route.test.ts +0 -215
  184. package/templates/apps/web/app/[locale]/(authed)/account/inbox/message/[id]/file/route.ts +0 -80
  185. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/member-thread-composer.tsx +0 -43
  186. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/page.tsx +0 -125
  187. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-data.ts +0 -88
  188. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-write.ts +0 -31
  189. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/invitation-id.test.ts +0 -35
  190. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/page.test.tsx +0 -266
  191. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/actions.ts +0 -116
  192. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/invitation-id.ts +0 -12
  193. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/page.tsx +0 -154
  194. package/templates/apps/web/app/[locale]/(authed)/account/layout.tsx +0 -152
  195. package/templates/apps/web/app/[locale]/(authed)/account/new-actions.ts +0 -219
  196. package/templates/apps/web/app/[locale]/(authed)/account/new-menu.tsx +0 -365
  197. package/templates/apps/web/app/[locale]/(authed)/account/new-popups.tsx +0 -86
  198. package/templates/apps/web/app/[locale]/(authed)/account/notifications/page.tsx +0 -143
  199. package/templates/apps/web/app/[locale]/(authed)/account/onboarding/actions.ts +0 -120
  200. package/templates/apps/web/app/[locale]/(authed)/account/onboarding/onboarding-form.tsx +0 -322
  201. package/templates/apps/web/app/[locale]/(authed)/account/onboarding/page.tsx +0 -126
  202. package/templates/apps/web/app/[locale]/(authed)/account/page.tsx +0 -306
  203. package/templates/apps/web/app/[locale]/(authed)/account/privacy/__tests__/export-route.test.ts +0 -173
  204. package/templates/apps/web/app/[locale]/(authed)/account/privacy/actions.ts +0 -103
  205. package/templates/apps/web/app/[locale]/(authed)/account/privacy/export/route.ts +0 -102
  206. package/templates/apps/web/app/[locale]/(authed)/account/privacy/page.tsx +0 -240
  207. package/templates/apps/web/app/[locale]/(authed)/account/profile-actions.ts +0 -116
  208. package/templates/apps/web/app/[locale]/(authed)/account/retry-button.tsx +0 -27
  209. package/templates/apps/web/app/[locale]/(authed)/account/security/__tests__/hub-variant.test.tsx +0 -258
  210. package/templates/apps/web/app/[locale]/(authed)/account/security/page.tsx +0 -131
  211. package/templates/apps/web/app/[locale]/(authed)/account/security/security-panel.tsx +0 -130
  212. package/templates/apps/web/app/[locale]/(authed)/account/security/security-source.ts +0 -92
  213. package/templates/apps/web/app/[locale]/(authed)/account/settings/page.tsx +0 -24
  214. package/templates/apps/web/app/[locale]/(authed)/account/settings-frame.tsx +0 -121
  215. package/templates/apps/web/app/[locale]/(authed)/account/sign-in-method.ts +0 -37
  216. package/templates/apps/web/app/[locale]/(authed)/account/support/page.tsx +0 -60
  217. package/templates/apps/web/app/[locale]/(authed)/account/support/support-form.tsx +0 -98
  218. package/templates/apps/web/app/[locale]/(authed)/account/support-actions.ts +0 -100
  219. package/templates/apps/web/app/[locale]/checkout/__tests__/pages.test.tsx +0 -139
  220. package/templates/apps/web/app/[locale]/checkout/__tests__/thank-you-account.test.tsx +0 -146
  221. package/templates/apps/web/app/[locale]/checkout/thank-you/page.tsx +0 -114
  222. package/templates/apps/web/app/[locale]/checkout/unavailable/page.tsx +0 -51
  223. package/templates/apps/web/app/[locale]/flows/[slug]/FlowStepperClient.tsx +0 -614
  224. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.count.test.tsx +0 -43
  225. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.deliverable.test.tsx +0 -214
  226. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.ending.test.tsx +0 -197
  227. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.invite.test.tsx +0 -286
  228. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.permalink.test.tsx +0 -520
  229. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.test.tsx +0 -376
  230. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.thanks-by-tier.test.tsx +0 -306
  231. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/account-invite.actions.test.ts +0 -69
  232. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/flow.actions.test.ts +0 -398
  233. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/magnet-page.test.tsx +0 -704
  234. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/save.actions.test.ts +0 -173
  235. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/two-route-tool.test.tsx +0 -141
  236. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/verify.test.tsx +0 -249
  237. package/templates/apps/web/app/[locale]/flows/[slug]/account-invite.actions.ts +0 -35
  238. package/templates/apps/web/app/[locale]/flows/[slug]/email-moment.ts +0 -92
  239. package/templates/apps/web/app/[locale]/flows/[slug]/flow.actions.ts +0 -177
  240. package/templates/apps/web/app/[locale]/flows/[slug]/magnet-page.tsx +0 -472
  241. package/templates/apps/web/app/[locale]/flows/[slug]/page.tsx +0 -48
  242. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/LevelChart.tsx +0 -100
  243. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsCard.tsx +0 -99
  244. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsClient.tsx +0 -820
  245. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsEmailStep.tsx +0 -203
  246. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/ResultsClient.no-commerce.test.tsx +0 -194
  247. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/ResultsClient.report.test.tsx +0 -284
  248. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/by-result.test.tsx +0 -302
  249. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/cards.test.tsx +0 -402
  250. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/landing.test.tsx +0 -293
  251. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/page.test.tsx +0 -485
  252. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/score.test.tsx +0 -231
  253. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/checkout-seam.ts +0 -74
  254. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/meeting-seam.ts +0 -36
  255. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/page.tsx +0 -420
  256. package/templates/apps/web/app/[locale]/flows/[slug]/save.actions.ts +0 -85
  257. package/templates/apps/web/app/[locale]/flows/[slug]/served-flow.ts +0 -91
  258. package/templates/apps/web/app/[locale]/flows/[slug]/start/page.tsx +0 -32
  259. package/templates/apps/web/app/[locale]/flows/[slug]/verify/page.tsx +0 -153
  260. package/templates/apps/web/app/[locale]/flows/[slug]/verify.actions.ts +0 -151
  261. package/templates/apps/web/app/[locale]/meet/confirmed/BookingHandOff.tsx +0 -128
  262. package/templates/apps/web/app/[locale]/meet/confirmed/__tests__/BookingHandOff.test.tsx +0 -126
  263. package/templates/apps/web/app/[locale]/purchase/__tests__/cancel.test.tsx +0 -162
  264. package/templates/apps/web/app/[locale]/purchase/__tests__/module-scope.test.ts +0 -68
  265. package/templates/apps/web/app/[locale]/purchase/__tests__/success.test.tsx +0 -411
  266. package/templates/apps/web/app/[locale]/purchase/cancel/page.tsx +0 -115
  267. package/templates/apps/web/app/[locale]/purchase/success/page.tsx +0 -348
  268. package/templates/apps/web/app/api/auth/[...all]/route.ts +0 -16
  269. package/templates/apps/web/app/api/auth/hub/__tests__/continuation.test.ts +0 -143
  270. package/templates/apps/web/app/api/auth/hub/__tests__/entry-routes.test.ts +0 -749
  271. package/templates/apps/web/app/api/auth/hub/authorize/__tests__/route.test.ts +0 -964
  272. package/templates/apps/web/app/api/auth/hub/authorize/route.ts +0 -390
  273. package/templates/apps/web/app/api/auth/hub/continuation.ts +0 -127
  274. package/templates/apps/web/app/api/auth/hub/continue/[ref]/__tests__/route.test.ts +0 -188
  275. package/templates/apps/web/app/api/auth/hub/continue/[ref]/route.ts +0 -53
  276. package/templates/apps/web/app/api/auth/hub/email/route.ts +0 -111
  277. package/templates/apps/web/app/api/auth/hub/entry-shared.ts +0 -163
  278. package/templates/apps/web/app/api/auth/hub/password/__tests__/return.test.ts +0 -86
  279. package/templates/apps/web/app/api/auth/hub/password/__tests__/route.test.ts +0 -368
  280. package/templates/apps/web/app/api/auth/hub/password/return.ts +0 -86
  281. package/templates/apps/web/app/api/auth/hub/password/route.ts +0 -171
  282. package/templates/apps/web/app/api/auth/hub/purchase/route.ts +0 -230
  283. package/templates/apps/web/app/api/auth/hub/purchase-link/route.ts +0 -174
  284. package/templates/apps/web/app/api/auth/hub/sign-up/route.ts +0 -60
  285. package/templates/apps/web/app/api/auth/hub/sign-up-evidence.ts +0 -97
  286. package/templates/apps/web/app/api/auth/mcp/__tests__/continuation.test.ts +0 -92
  287. package/templates/apps/web/app/api/auth/mcp/continuation.ts +0 -89
  288. package/templates/apps/web/app/api/auth/mcp/continue/[ref]/__tests__/route.test.ts +0 -59
  289. package/templates/apps/web/app/api/auth/mcp/continue/[ref]/route.ts +0 -41
  290. package/templates/apps/web/app/api/hub-session/__tests__/routes.test.ts +0 -1166
  291. package/templates/apps/web/app/api/hub-session/callback/route.ts +0 -134
  292. package/templates/apps/web/app/api/hub-session/email/route.ts +0 -125
  293. package/templates/apps/web/app/api/hub-session/one-tap/nonce/route.ts +0 -49
  294. package/templates/apps/web/app/api/hub-session/one-tap/route.ts +0 -106
  295. package/templates/apps/web/app/api/hub-session/open/route.ts +0 -111
  296. package/templates/apps/web/app/api/hub-session/password/return/route.ts +0 -69
  297. package/templates/apps/web/app/api/hub-session/password/route.ts +0 -106
  298. package/templates/apps/web/app/api/hub-session/sign-in/route.ts +0 -91
  299. package/templates/apps/web/app/api/hub-session/sign-out/route.ts +0 -54
  300. package/templates/apps/web/components/sign-out-trigger.tsx +0 -62
  301. package/templates/apps/web/lib/__tests__/account-config.test.ts +0 -704
  302. package/templates/apps/web/lib/__tests__/auth-routes.test.ts +0 -140
  303. package/templates/apps/web/lib/account-config.ts +0 -678
  304. package/templates/apps/web/lib/auth-routes.ts +0 -125
  305. package/templates/apps/web/lib/checkout-config.ts +0 -16
  306. package/templates/apps/web/lib/hub-session/__tests__/hub-session.test.ts +0 -433
  307. package/templates/apps/web/lib/hub-session/__tests__/spoke-sign-in.test.tsx +0 -332
  308. package/templates/apps/web/lib/hub-session/config.ts +0 -110
  309. package/templates/apps/web/lib/hub-session/entry.ts +0 -238
  310. package/templates/apps/web/lib/hub-session/index.ts +0 -21
  311. package/templates/apps/web/lib/hub-session/one-tap.tsx +0 -148
  312. package/templates/apps/web/lib/hub-session/reseal.ts +0 -90
  313. package/templates/apps/web/lib/hub-session/seal.ts +0 -86
  314. package/templates/apps/web/lib/hub-session/session.ts +0 -298
  315. package/templates/apps/web/lib/hub-session/spoke-sign-in.tsx +0 -277
  316. package/templates/apps/web/lib/next-path.ts +0 -35
  317. package/templates/apps/web/src/lib/__tests__/commerce-sections.test.ts +0 -57
  318. package/templates/apps/web/src/lib/commerce-sections.ts +0 -55
@@ -1,21 +0,0 @@
1
- /**
2
- * The spoke's hub-client module (#7894 D7) — sign-in through the hub, with no
3
- * database. It imports no spoke removal seed and no `(auth)` file, so a spoke
4
- * keeps it (create-ailk's closure guard proves that, spec 7894 D9).
5
- */
6
-
7
- export {
8
- HUB_SESSION_CALLBACK_PATH,
9
- type HubSessionConfig,
10
- hubSessionConfig,
11
- } from "./config";
12
- export {
13
- type HubSessionPayload,
14
- type HubSessionUser,
15
- hubNextPath,
16
- hubSessionBuyer,
17
- hubSessionInit,
18
- readHubSession,
19
- } from "./session";
20
- export { resealHubSession } from "./reseal";
21
- export { SpokeSignIn, type SpokeSignInProps } from "./spoke-sign-in";
@@ -1,148 +0,0 @@
1
- "use client"; // "use client" — loads Google's Identity Services script and handles its credential callback in the browser.
2
-
3
- /**
4
- * OneTap — Google One Tap on a spoke's signed-out account page (#11096 D10).
5
- *
6
- * Rendered by `SpokeSignIn` only when the spoke sets `AILK_HUB_ONE_TAP=on`
7
- * and its hub reports a One Tap client id. On mount it asks this site's
8
- * `POST /api/hub-session/one-tap/nonce` for a nonce, loads
9
- * `https://accounts.google.com/gsi/client`, and calls
10
- * `google.accounts.id.initialize({ client_id, nonce, callback,
11
- * use_fedcm_for_prompt: true })` then `prompt()`. Google's callback hands the
12
- * ID token to `POST /api/hub-session/one-tap`; only on `{ ok: true }` — the
13
- * session cookie is set by then — does the page move, to `next`, on this
14
- * site. Any other answer leaves the form as it is. Nothing here logs the
15
- * token or the nonce.
16
- */
17
-
18
- import { type ReactElement, useEffect } from "react";
19
-
20
- const GSI_SRC = "https://accounts.google.com/gsi/client";
21
-
22
- interface GoogleIdentity {
23
- accounts?: {
24
- id?: {
25
- initialize(options: {
26
- client_id: string;
27
- nonce: string;
28
- callback: (response: { credential?: string }) => void;
29
- use_fedcm_for_prompt: boolean;
30
- }): void;
31
- prompt(): void;
32
- };
33
- };
34
- }
35
-
36
- /** The one navigation the island makes — a test seam. */
37
- export const oneTapNavigation = {
38
- assign(url: string): void {
39
- window.location.assign(url);
40
- },
41
- };
42
-
43
- function googleIdentity(): GoogleIdentity | undefined {
44
- return (window as unknown as { google?: GoogleIdentity }).google;
45
- }
46
-
47
- /** How long the island waits for Google's script before it gives up. */
48
- const GSI_TIMEOUT_MS = 10_000;
49
-
50
- /**
51
- * Google's script, loaded once per page. Always settles: it rejects when the
52
- * script fails, loads without `google.accounts.id`, or has not loaded within
53
- * 10 s (a tag already on the page may have loaded before this listened). A
54
- * rejection leaves the form as it is.
55
- */
56
- export function loadGoogle(): Promise<void> {
57
- if (googleIdentity()?.accounts?.id) return Promise.resolve();
58
- return new Promise((resolve, reject) => {
59
- const fail = (): void => reject(new Error("gsi"));
60
- const timer = setTimeout(fail, GSI_TIMEOUT_MS);
61
- const existing = document.querySelector<HTMLScriptElement>(`script[src="${GSI_SRC}"]`);
62
- const script = existing ?? document.createElement("script");
63
- script.addEventListener(
64
- "load",
65
- () => {
66
- clearTimeout(timer);
67
- if (googleIdentity()?.accounts?.id) resolve();
68
- else fail();
69
- },
70
- { once: true },
71
- );
72
- script.addEventListener(
73
- "error",
74
- () => {
75
- clearTimeout(timer);
76
- fail();
77
- },
78
- { once: true },
79
- );
80
- if (existing === null) {
81
- script.src = GSI_SRC;
82
- script.async = true;
83
- document.head.appendChild(script);
84
- }
85
- });
86
- }
87
-
88
- async function postJson(url: string, body: unknown): Promise<unknown> {
89
- const res = await fetch(url, {
90
- method: "POST",
91
- credentials: "same-origin",
92
- headers: { "content-type": "application/json" },
93
- body: JSON.stringify(body),
94
- });
95
- if (!res.ok) return null;
96
- return res.json().catch(() => null);
97
- }
98
-
99
- export interface OneTapProps {
100
- /** The hub's Google client id, from the hub's client info. */
101
- clientId: string;
102
- /** Where to land once signed in — a path on this site, already sanitized. */
103
- next: string;
104
- }
105
-
106
- export function OneTap({ clientId, next }: OneTapProps): ReactElement {
107
- useEffect(() => {
108
- let cancelled = false;
109
- const onCredential = async (response: { credential?: string }): Promise<void> => {
110
- if (typeof response.credential !== "string") return;
111
- const answer = await postJson("/api/hub-session/one-tap", {
112
- credential: response.credential,
113
- }).catch(() => null);
114
- if (
115
- typeof answer === "object" &&
116
- answer !== null &&
117
- (answer as { ok?: unknown }).ok === true
118
- ) {
119
- oneTapNavigation.assign(next);
120
- }
121
- };
122
- const start = async (): Promise<void> => {
123
- const minted = await postJson("/api/hub-session/one-tap/nonce", {});
124
- const nonce =
125
- typeof minted === "object" && minted !== null
126
- ? (minted as { nonce?: unknown }).nonce
127
- : undefined;
128
- if (typeof nonce !== "string") return;
129
- await loadGoogle();
130
- const id = googleIdentity()?.accounts?.id;
131
- if (cancelled || !id) return;
132
- id.initialize({
133
- client_id: clientId,
134
- nonce,
135
- callback: (response) => void onCredential(response),
136
- use_fedcm_for_prompt: true,
137
- });
138
- id.prompt();
139
- };
140
- start().catch(() => undefined);
141
- return () => {
142
- cancelled = true;
143
- };
144
- }, [clientId, next]);
145
-
146
- // Google draws its own prompt; this marker only names the island.
147
- return <div hidden data-testid="spoke-sign-in-one-tap" data-client-id={clientId} />;
148
- }
@@ -1,90 +0,0 @@
1
- /**
2
- * The spoke's session re-seal (#8232, spec
3
- * docs/specs/8232-member-settings-account-general-and-spec.md D11; roadmap
4
- * D9).
5
- *
6
- * After a member saves their name through the hub (`PATCH /v1/member/profile`),
7
- * the sealed session cookie still names the person as they were at sign-in.
8
- * `resealHubSession()` re-reads the person from the hub's own record,
9
- * `GET /v1/hub-sign-in/me`, with the session's credential, and writes the
10
- * cookie again so the next render shows the new name:
11
- *
12
- * - no hub-session configuration (a single site) or no session cookie ⇒
13
- * `"skipped"`, with no call;
14
- * - `/me` refusing, throwing, or answering a person of the wrong shape ⇒
15
- * `"failed"`, and the cookie is left as it is (sign-out is the sign-out
16
- * route's job — a transient hub error never signs the member out);
17
- * - otherwise only `user` changes. `v`, `accessToken` and `expiresAt` are
18
- * kept exactly and `Max-Age` is the remaining lifetime, so a re-seal
19
- * never extends a session (SEC-8232-1). The cookie's name, key and
20
- * attributes are the ones the callback route writes at sign-in
21
- * (`cookieHeader`: `HttpOnly`, `SameSite=Lax`, `Path=/`, `Secure` on an
22
- * https site — SEC-8232-2).
23
- *
24
- * It tests no topology: a single site has no configuration and no cookie.
25
- * Nothing here logs a credential, a cookie value, a name or an email.
26
- */
27
-
28
- import { hubSignIn } from "@working-theory/api-client";
29
- import { cookies, headers } from "next/headers";
30
-
31
- import { hubSessionConfig } from "./config";
32
- import { seal } from "./seal";
33
- import { type HubSessionUser, readHubSessionPayload, sessionCookieName } from "./session";
34
-
35
- /**
36
- * The person `/me` names, when every field is the type the session holds.
37
- * It repeats `session.ts`'s private shape check on purpose: `sync-routes`
38
- * brings this file to a scaffold whose own `session.ts` it never updates,
39
- * so it cannot rely on a new export there.
40
- */
41
- function sessionUser(value: unknown): HubSessionUser | null {
42
- if (typeof value !== "object" || value === null) return null;
43
- const user = value as Record<string, unknown>;
44
- const { name, email, emailVerified, createdAt } = user;
45
- if (
46
- typeof email !== "string" ||
47
- typeof emailVerified !== "boolean" ||
48
- typeof createdAt !== "string" ||
49
- (name !== null && typeof name !== "string")
50
- ) {
51
- return null;
52
- }
53
- return { name, email, emailVerified, createdAt };
54
- }
55
-
56
- /** Re-seals the hub session cookie from the hub's `/me`. Never throws. */
57
- export async function resealHubSession(): Promise<"resealed" | "skipped" | "failed"> {
58
- const config = hubSessionConfig();
59
- if (config === null) return "skipped";
60
- const payload = readHubSessionPayload(await headers());
61
- if (payload === null) return "skipped";
62
- const maxAge = Math.floor((payload.expiresAt - Date.now()) / 1000);
63
- if (maxAge <= 0) return "skipped";
64
-
65
- let user: HubSessionUser | null;
66
- try {
67
- const res = await hubSignIn.me({
68
- headers: { authorization: `Bearer ${payload.accessToken}` },
69
- });
70
- user = res.ok ? sessionUser(res.body.user) : null;
71
- } catch {
72
- user = null;
73
- }
74
- if (user === null) return "failed";
75
-
76
- const name = sessionCookieName(config);
77
- try {
78
- (await cookies()).set(name, seal({ ...payload, user }, config.sessionSecret, "session", name), {
79
- httpOnly: true,
80
- sameSite: "lax",
81
- path: "/",
82
- maxAge,
83
- secure: config.secure,
84
- });
85
- } catch {
86
- // Outside a Server Action or route handler Next refuses a cookie write.
87
- return "failed";
88
- }
89
- return "resealed";
90
- }
@@ -1,86 +0,0 @@
1
- /**
2
- * Sealed values for the hub sign-in (#7894 D7, #8146 D3).
3
- *
4
- * AES-256-GCM with a fresh 12-byte IV per seal. The key is HKDF-SHA256 of the
5
- * caller's secret with one info string per purpose, so the three purposes
6
- * never share a key, and the caller-supplied name is the additional
7
- * authenticated data, so a value sealed for one name never opens as another.
8
- * Two secrets feed this module: `AILK_HUB_SESSION_SECRET` for the spoke's
9
- * `session` and `flow` cookies, and `BETTER_AUTH_SECRET` for the hub's
10
- * `continue` ref (`app/api/auth/hub/continuation.ts`, hub and standalone
11
- * sites only; the entry is unused on a spoke). The key never derives from the
12
- * client secret: a leaked client secret forges no spoke session.
13
- *
14
- * Wire form: base64url(iv ‖ tag ‖ ciphertext). Anything that does not open —
15
- * a wrong key, a wrong name, a truncated or altered value — reads as `null`,
16
- * never a throw. Node `crypto` only; no dependency.
17
- */
18
-
19
- import {
20
- createCipheriv,
21
- createDecipheriv,
22
- hkdfSync,
23
- randomBytes,
24
- } from "node:crypto";
25
-
26
- /** The things this module seals, each under its own derived key. */
27
- export type SealPurpose = "session" | "flow" | "continue";
28
-
29
- const INFO: Record<SealPurpose, string> = {
30
- session: "ailk-hub-session/v1",
31
- flow: "ailk-hub-flow/v1",
32
- continue: "ailk-hub-continue/v1",
33
- };
34
-
35
- const IV_BYTES = 12;
36
- const TAG_BYTES = 16;
37
-
38
- function deriveKey(secret: string, purpose: SealPurpose): Buffer {
39
- return Buffer.from(
40
- hkdfSync("sha256", secret, Buffer.alloc(0), INFO[purpose], 32),
41
- );
42
- }
43
-
44
- /** `value` as JSON, sealed for the cookie `name`. */
45
- export function seal(
46
- value: unknown,
47
- secret: string,
48
- purpose: SealPurpose,
49
- name: string,
50
- ): string {
51
- const iv = randomBytes(IV_BYTES);
52
- const cipher = createCipheriv("aes-256-gcm", deriveKey(secret, purpose), iv);
53
- cipher.setAAD(Buffer.from(name, "utf8"));
54
- const body = Buffer.concat([
55
- cipher.update(JSON.stringify(value), "utf8"),
56
- cipher.final(),
57
- ]);
58
- return Buffer.concat([iv, cipher.getAuthTag(), body]).toString("base64url");
59
- }
60
-
61
- /** The JSON value `sealed` holds for the cookie `name`, or `null` when it does not open. */
62
- export function unseal(
63
- sealed: string,
64
- secret: string,
65
- purpose: SealPurpose,
66
- name: string,
67
- ): unknown {
68
- try {
69
- const raw = Buffer.from(sealed, "base64url");
70
- if (raw.length <= IV_BYTES + TAG_BYTES) return null;
71
- const decipher = createDecipheriv(
72
- "aes-256-gcm",
73
- deriveKey(secret, purpose),
74
- raw.subarray(0, IV_BYTES),
75
- );
76
- decipher.setAAD(Buffer.from(name, "utf8"));
77
- decipher.setAuthTag(raw.subarray(IV_BYTES, IV_BYTES + TAG_BYTES));
78
- const text = Buffer.concat([
79
- decipher.update(raw.subarray(IV_BYTES + TAG_BYTES)),
80
- decipher.final(),
81
- ]).toString("utf8");
82
- return JSON.parse(text) as unknown;
83
- } catch {
84
- return null;
85
- }
86
- }
@@ -1,298 +0,0 @@
1
- /**
2
- * The spoke's hub session (#7894 D7, D12, D13) — read, forwarded, never stored.
3
- *
4
- * A spoke that signs in through its hub has no database: after the callback
5
- * route exchanges a code, the hub-issued credential and the person it names
6
- * live in ONE sealed, `HttpOnly` cookie. This module is everything that reads
7
- * it:
8
- *
9
- * - `readHubSession(headers)` — the web seam's `readSession` on a hub-mode
10
- * spoke: unseals the cookie from the `Cookie` header, no network. Expired,
11
- * unreadable or sealed under another key ⇒ `null`.
12
- * - `hubSessionInit()` — what `forwardedCookieInit()` returns on such a
13
- * spoke: the credential as `Authorization: Bearer`, the ONE request-init
14
- * re-target the account area reads the hub through (D12). The api-client
15
- * adds the spoke key itself; the hub admits the credential only beside it.
16
- * - `hubSessionBuyer(request)` — a customer the hub vouches for at buy time
17
- * (D13): read live from `GET /v1/hub-sign-in/me`, never from the cookie.
18
- *
19
- * And the two writers every route that starts or finishes a sign-in shares
20
- * (#11096 D2, D6): `startHubFlow` seals a new flow, and `sessionCookieFor`
21
- * seals a credential the hub answered into the session cookie.
22
- *
23
- * Nothing here logs a credential, a cookie value or an email.
24
- */
25
-
26
- import { createHash, randomBytes } from "node:crypto";
27
-
28
- import { type HubSignInTokenResponse, hubSignIn } from "@working-theory/api-client";
29
- import { headers as requestHeaders } from "next/headers";
30
-
31
- import { resolveNextPath } from "../next-path";
32
-
33
- import { type HubSessionConfig, hubSessionConfig } from "./config";
34
- import { seal, unseal } from "./seal";
35
-
36
- /** The session cookie: `__Host-` on an https site, plain on a loopback one. */
37
- export function sessionCookieName(config: Pick<HubSessionConfig, "secure">): string {
38
- return config.secure ? "__Host-ailk-hub-session" : "ailk-hub-session";
39
- }
40
-
41
- /** The flow cookie that carries state, verifier and `next` across the hub hop. */
42
- export function flowCookieName(config: Pick<HubSessionConfig, "secure">): string {
43
- return config.secure ? "__Host-ailk-hub-flow" : "ailk-hub-flow";
44
- }
45
-
46
- /** One Tap's nonce cookie (#11096 D10), named as the other two are. */
47
- export function oneTapCookieName(config: Pick<HubSessionConfig, "secure">): string {
48
- return config.secure ? "__Host-ailk-hub-one-tap" : "ailk-hub-one-tap";
49
- }
50
-
51
- /** How long a One Tap nonce lives — Google's prompt and the person's tap. */
52
- export const ONE_TAP_NONCE_TTL_SECONDS = 300;
53
-
54
- /** The person a hub session names — the fields the account area reads. */
55
- export interface HubSessionUser {
56
- name: string | null;
57
- email: string;
58
- emailVerified: boolean;
59
- createdAt: string;
60
- }
61
-
62
- /** What the session cookie holds (sealed). */
63
- export interface HubSessionPayload {
64
- v: 1;
65
- accessToken: string;
66
- /** Epoch milliseconds; the cookie's own `Max-Age` ends at the same time. */
67
- expiresAt: number;
68
- user: HubSessionUser;
69
- }
70
-
71
- /** The value of cookie `name` in a `Cookie` header, or `undefined`. */
72
- export function readCookie(header: string | null, name: string): string | undefined {
73
- if (header === null) return undefined;
74
- for (const part of header.split(";")) {
75
- const at = part.indexOf("=");
76
- if (at === -1) continue;
77
- if (part.slice(0, at).trim() === name) return part.slice(at + 1).trim();
78
- }
79
- return undefined;
80
- }
81
-
82
- /**
83
- * A `Set-Cookie` value for one of this module's cookies — always `HttpOnly`,
84
- * `SameSite=Lax` (the hub's top-level redirect back must carry the flow
85
- * cookie) and `Path=/`; `Secure` on an https site. `maxAge` 0 clears it.
86
- */
87
- export function cookieHeader(
88
- name: string,
89
- value: string,
90
- maxAge: number,
91
- config: Pick<HubSessionConfig, "secure">,
92
- ): string {
93
- return [
94
- `${name}=${value}`,
95
- "Path=/",
96
- "HttpOnly",
97
- "SameSite=Lax",
98
- `Max-Age=${Math.max(0, Math.floor(maxAge))}`,
99
- ...(config.secure ? ["Secure"] : []),
100
- ].join("; ");
101
- }
102
-
103
- function isPayload(value: unknown): value is HubSessionPayload {
104
- if (typeof value !== "object" || value === null) return false;
105
- const v = value as Record<string, unknown>;
106
- const user = v["user"] as Record<string, unknown> | null | undefined;
107
- return (
108
- v["v"] === 1 &&
109
- typeof v["accessToken"] === "string" &&
110
- typeof v["expiresAt"] === "number" &&
111
- typeof user === "object" &&
112
- user !== null &&
113
- typeof user["email"] === "string" &&
114
- typeof user["emailVerified"] === "boolean" &&
115
- (user["name"] === null || typeof user["name"] === "string") &&
116
- typeof user["createdAt"] === "string"
117
- );
118
- }
119
-
120
- /** The sealed session in `headers`, or `null` — not configured, absent, expired or unreadable. */
121
- export function readHubSessionPayload(headers: Headers): HubSessionPayload | null {
122
- const config = hubSessionConfig();
123
- if (config === null) return null;
124
- const name = sessionCookieName(config);
125
- const sealed = readCookie(headers.get("cookie"), name);
126
- if (sealed === undefined || sealed === "") return null;
127
- const value = unseal(sealed, config.sessionSecret, "session", name);
128
- if (!isPayload(value) || value.expiresAt <= Date.now()) return null;
129
- return value;
130
- }
131
-
132
- /** The web seam's `readSession` on a hub-mode spoke: the person, or `null`. */
133
- export function readHubSession(
134
- headers: Headers,
135
- ): Promise<{ user: HubSessionUser } | null> {
136
- const payload = readHubSessionPayload(headers);
137
- return Promise.resolve(payload === null ? null : { user: payload.user });
138
- }
139
-
140
- /**
141
- * `forwardedCookieInit()` on a hub-mode spoke (D12): the credential as a
142
- * Bearer header signed in, no header at all signed out. Never the visitor's
143
- * cookie — the hub has no session for it.
144
- */
145
- export async function hubSessionInit(): Promise<{ headers: Record<string, string> }> {
146
- const payload = readHubSessionPayload(await requestHeaders());
147
- return payload === null
148
- ? { headers: {} }
149
- : { headers: { authorization: `Bearer ${payload.accessToken}` } };
150
- }
151
-
152
- /**
153
- * The customer the hub vouches for, for a spoke's buy route (D13): read live
154
- * from `GET /v1/hub-sign-in/me` with the person's credential (the api-client
155
- * adds the spoke key). `null` with no session, when the hub refuses the
156
- * credential (a revoked one reads as signed out here), when it names no
157
- * customer, or on any failure — a buyer is never taken from the cookie.
158
- */
159
- export async function hubSessionBuyer(
160
- request: Request,
161
- ): Promise<{ customerId: string } | null> {
162
- const payload = readHubSessionPayload(request.headers);
163
- if (payload === null) return null;
164
- try {
165
- const res = await hubSignIn.me({
166
- headers: { authorization: `Bearer ${payload.accessToken}` },
167
- });
168
- if (!res.ok) return null;
169
- const customerId = res.body.billingCustomerId;
170
- return typeof customerId === "string" && customerId !== ""
171
- ? { customerId }
172
- : null;
173
- } catch {
174
- return null;
175
- }
176
- }
177
-
178
- /** Where to land after signing in, when `next` is missing or refused. */
179
- export const HUB_SESSION_FALLBACK_PATH = "/account";
180
-
181
- /**
182
- * Where a sign-in this site cannot complete lands (#11095 D4): the site's
183
- * home. Never `/account`, whose signed-out gate redirects straight back into
184
- * the sign-in — a loop.
185
- */
186
- export const HUB_SESSION_HOME_PATH = "/";
187
-
188
- /**
189
- * The post-sign-in path for `raw`: `resolveNextPath`'s same-origin rule,
190
- * printable ASCII only (it becomes a `Location` header), and never a path
191
- * that resolves under `/api` — dot segments included — so a sign-in lands on
192
- * a page and never re-enters a route handler.
193
- */
194
- export function hubNextPath(raw: unknown): string {
195
- const next = resolveNextPath(raw, HUB_SESSION_FALLBACK_PATH);
196
- if (!/^[\x21-\x7e]+$/.test(next)) return HUB_SESSION_FALLBACK_PATH;
197
- const path = new URL(next, "http://site.invalid").pathname;
198
- return path === "/api" || path.startsWith("/api/")
199
- ? HUB_SESSION_FALLBACK_PATH
200
- : next;
201
- }
202
-
203
- /** How long a sign-in may take on the hub before the flow cookie expires. */
204
- export const FLOW_TTL_SECONDS = 600;
205
-
206
- /** The longest session the spoke keeps — the hub's own credential lifetime (spec 7894 D5). */
207
- const MAX_SESSION_SECONDS = 86_400;
208
-
209
- /** A sign-in flow just started: what the hub is sent, and the cookie that remembers it. */
210
- export interface HubFlow {
211
- /** The opaque `state` the hub echoes back. */
212
- state: string;
213
- /** The S256 challenge of the sealed verifier. */
214
- challenge: string;
215
- /** The `Set-Cookie` value of the sealed flow cookie (ten minutes). */
216
- cookie: string;
217
- }
218
-
219
- /**
220
- * Start a sign-in through the hub (#7894 D2; shared by every route that
221
- * starts one, #11096 D2): a `state` and a PKCE verifier (32 random bytes
222
- * each, base64url) sealed with the sanitized `next` into the flow cookie.
223
- * Nothing here logs the state, the verifier or the challenge.
224
- */
225
- export function startHubFlow(config: HubSessionConfig, next: unknown): HubFlow {
226
- const state = randomBytes(32).toString("base64url");
227
- const verifier = randomBytes(32).toString("base64url");
228
- const challenge = createHash("sha256").update(verifier).digest("base64url");
229
- const name = flowCookieName(config);
230
- const flow = seal(
231
- {
232
- v: 1,
233
- state,
234
- verifier,
235
- next: hubNextPath(next),
236
- expiresAt: Date.now() + FLOW_TTL_SECONDS * 1000,
237
- },
238
- config.sessionSecret,
239
- "flow",
240
- name,
241
- );
242
- return { state, challenge, cookie: cookieHeader(name, flow, FLOW_TTL_SECONDS, config) };
243
- }
244
-
245
- /**
246
- * The session cookie for a credential the hub answered (#11096 D6) — the
247
- * callback's code exchange and One Tap's both mint one. `null` when
248
- * `expiresIn` is not a whole number of seconds from 1 to a day: a malformed
249
- * answer from the hub must never yield a session that does not expire.
250
- */
251
- export function sessionCookieFor(
252
- config: HubSessionConfig,
253
- token: Pick<HubSignInTokenResponse, "accessToken" | "expiresIn" | "user">,
254
- ): string | null {
255
- const { accessToken, expiresIn, user } = token;
256
- if (!Number.isInteger(expiresIn) || expiresIn < 1 || expiresIn > MAX_SESSION_SECONDS) {
257
- return null;
258
- }
259
- const payload: HubSessionPayload = {
260
- v: 1,
261
- accessToken,
262
- expiresAt: Date.now() + expiresIn * 1000,
263
- user: {
264
- name: user.name,
265
- email: user.email,
266
- emailVerified: user.emailVerified,
267
- createdAt: user.createdAt,
268
- },
269
- };
270
- const name = sessionCookieName(config);
271
- return cookieHeader(name, seal(payload, config.sessionSecret, "session", name), expiresIn, config);
272
- }
273
-
274
- /**
275
- * Whether `request` comes from a page on `siteOrigin`: a `Sec-Fetch-Site`
276
- * other than `same-origin`, an `Origin` other than the site's, or a request
277
- * carrying neither is not. The check every state-changing POST of this
278
- * module's routes makes before anything else.
279
- */
280
- export function isSameOrigin(request: Request, siteOrigin: string | null): boolean {
281
- const fetchSite = request.headers.get("sec-fetch-site");
282
- const origin = request.headers.get("origin");
283
- if (fetchSite === null && origin === null) return false;
284
- if (fetchSite !== null && fetchSite !== "same-origin") return false;
285
- if (origin !== null && origin !== siteOrigin) return false;
286
- return true;
287
- }
288
-
289
- /** A 303 with no cache and no referrer, carrying each `Set-Cookie` given. */
290
- export function seeOther(location: string, setCookies: readonly string[] = []): Response {
291
- const headers = new Headers({
292
- Location: location,
293
- "Cache-Control": "no-store",
294
- "Referrer-Policy": "no-referrer",
295
- });
296
- for (const value of setCookies) headers.append("Set-Cookie", value);
297
- return new Response(null, { status: 303, headers });
298
- }