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,125 +0,0 @@
1
- /**
2
- * The auth route group's segment list and its path predicate (#5963).
3
- *
4
- * ONE module, so the list `app/[locale]/layout.tsx` branches on to drop the
5
- * marketing chrome and the list the `(auth)` group's page segments exist at
6
- * cannot drift. A route group contributes no URL segment, so these are the
7
- * real paths: `/sign-in`, `/sign-up`, `/forgot-password`, `/reset-password`,
8
- * `/verify-email` and the MCP consent step `/consent` (#10357), each under next-intl's `as-needed` prefixing (bare for
9
- * the default locale, `/<locale>/…` otherwise).
10
- *
11
- * `isAccountPath()` (#7430, spec 7423 D4) is the same predicate for the
12
- * signed-in account area — `/account` and everything under it — which the
13
- * layout also renders without the marketing chrome.
14
- *
15
- * `isBookingPath()` (#8843 D10) is the same predicate for the scheduling
16
- * module's booking pages — `/meet`, `/meet/<slug>` and `/private`, never
17
- * `/meet/confirmed`, plus the member's own booking page
18
- * `/account/appointments/<slug>` (#11154) — which the layout renders
19
- * chrome-free only where the module is installed (`lib/modules.generated.ts`)
20
- * and the middleware grants the scheduling CSP. This module imports nothing,
21
- * so edge code can import it too.
22
- *
23
- * No Next.js import — pure functions, asserted directly by their own suite.
24
- */
25
-
26
- /** The six segments the `(auth)` route group serves. */
27
- export const AUTH_SEGMENTS = [
28
- "sign-in",
29
- "sign-up",
30
- "forgot-password",
31
- "reset-password",
32
- "verify-email",
33
- // The MCP consent step (#10357 D6).
34
- "consent",
35
- ] as const;
36
-
37
- export type AuthSegment = (typeof AUTH_SEGMENTS)[number];
38
-
39
- /**
40
- * Whether `pathname` addresses one of the five auth routes.
41
- *
42
- * Locale-prefix-aware the same way `resolveLocalePath()` is: strip a leading
43
- * `/<locale>` when it matches an ENABLED locale, then compare the first
44
- * remaining segment against the list. A prefix that is not an enabled locale
45
- * is a first segment, not a prefix.
46
- *
47
- * Fail-safe direction: an absent or empty pathname answers `false`. The
48
- * layout's branch reads a header that can legitimately be missing (a direct
49
- * render in a unit test, a path the middleware matcher excludes), and a
50
- * missing header must never strip a marketing page's chrome. The worst case
51
- * is an auth page that renders WITH chrome, which the group's own tests catch.
52
- */
53
- export function isAuthPath(
54
- pathname: string | undefined | null,
55
- locales: readonly string[],
56
- ): boolean {
57
- const first = firstSegment(pathname, locales);
58
- return AUTH_SEGMENTS.some((segment) => segment === first);
59
- }
60
-
61
- /**
62
- * Whether `pathname` addresses the account area: `/account` or any path
63
- * under it, bare or locale-prefixed (spec 7423 D4). The same prefix rule and
64
- * the same fail-safe direction as `isAuthPath()` — an absent or empty
65
- * pathname answers `false`, so a missing header never strips a marketing
66
- * page's chrome.
67
- */
68
- export function isAccountPath(
69
- pathname: string | undefined | null,
70
- locales: readonly string[],
71
- ): boolean {
72
- return firstSegment(pathname, locales) === "account";
73
- }
74
-
75
- /**
76
- * Whether `pathname` addresses a booking page: `/private`, `/meet`, or
77
- * `/meet/<slug>` for any slug but `confirmed` (the booker's confirmation
78
- * page, which keeps the marketing chrome), or the member's booking page
79
- * `/account/appointments/<slug>` (#11154) — never the Appointments list
80
- * itself, which embeds nothing. The same prefix rule and the same fail-safe
81
- * direction as `isAuthPath()`.
82
- */
83
- export function isBookingPath(
84
- pathname: string | undefined | null,
85
- locales: readonly string[],
86
- ): boolean {
87
- const [first, second, third] = segments(pathname, locales);
88
- if (first === "private") return true;
89
- if (first === "account") return second === "appointments" && third !== undefined;
90
- return first === "meet" && second !== "confirmed";
91
- }
92
-
93
- /**
94
- * The first path segment after an enabled-locale prefix, or `undefined` for
95
- * an absent or empty pathname.
96
- */
97
- function firstSegment(
98
- pathname: string | undefined | null,
99
- locales: readonly string[],
100
- ): string | undefined {
101
- return segments(pathname, locales)[0];
102
- }
103
-
104
- /**
105
- * The path's segments after an enabled-locale prefix (empty for an absent or
106
- * empty pathname). A trailing slash adds no segment.
107
- */
108
- function segments(
109
- pathname: string | undefined | null,
110
- locales: readonly string[],
111
- ): string[] {
112
- if (!pathname) return [];
113
-
114
- // Drop a query string / fragment — `x-pathname` carries the path, but a
115
- // caller passing a full request path should get the same verdict.
116
- const path = pathname.split(/[?#]/)[0] ?? "";
117
- const bare =
118
- locales.length > 0
119
- ? path.replace(new RegExp(`^/(${locales.join("|")})(?=/|$)`), "")
120
- : path;
121
-
122
- const parts = bare.split("/").slice(1);
123
- if (parts.at(-1) === "") parts.pop();
124
- return parts;
125
- }
@@ -1,16 +0,0 @@
1
- // checkout-config.ts — this spoke's checkout stamp, as data (#7838, #8748).
2
- //
3
- // Written once by create-ailk and yours from then on: `create-ailk update`
4
- // never rewrites it. Keep it to data: no import, and no code. A spoke sells
5
- // through its hub's Offerings buy route, /api/offerings/checkout/<lookup_key>
6
- // (#9142); the thank-you page and, on a spoke that signs in through its hub,
7
- // the billing action read `site` from here.
8
- //
9
- // site The paid-session stamp the thank-you page checks
10
- // (`metadata.site`) before it prefills "Open your account". Never
11
- // "default". The create-ailk writer stamps the line below.
12
- const SITE = "example-site";
13
-
14
- export const checkoutConfig = {
15
- site: SITE,
16
- };
@@ -1,433 +0,0 @@
1
- /**
2
- * @jest-environment node
3
- */
4
-
5
- /**
6
- * The spoke's hub-session module (#7894 D7, D12, D13; spec
7
- * docs/specs/7894-the-hub-signs-in-its-spec.md AC-5, AC-7, AC-8).
8
- *
9
- * Covers the sealed cookie (a value sealed under a key derived from the
10
- * CLIENT secret never opens — AC-5), the configuration, the session read, the
11
- * one request-init re-target `forwardedCookieInit()` makes on a hub-mode spoke
12
- * (AC-7), and the buyer read that never trusts the cookie for a customer id
13
- * (AC-8). The api-client's `hubSignIn` is the one external boundary mocked.
14
- */
15
-
16
- import { createCipheriv, hkdfSync, randomBytes } from "node:crypto";
17
-
18
- const mockMe = jest.fn();
19
- jest.mock("@working-theory/api-client", () => ({
20
- __esModule: true,
21
- hubSignIn: { me: (...args: unknown[]) => mockMe(...args) },
22
- }));
23
-
24
- const mockHeaders = jest.fn();
25
- jest.mock("next/headers", () => ({
26
- __esModule: true,
27
- headers: (...args: unknown[]) => mockHeaders(...args),
28
- cookies: jest.fn(),
29
- }));
30
-
31
- // eslint-disable-next-line no-restricted-syntax -- #507: the sign-in provider is a generated constant (#7894 D8), not a runtime input; the seam IS the boundary between a hub and a hub-mode spoke build, and no env or HTTP surface selects it.
32
- jest.mock("../../topology.generated", () => ({
33
- __esModule: true,
34
- SIGN_IN_PROVIDER: "hub",
35
- }));
36
-
37
- import { cookies } from "next/headers";
38
-
39
- import { forwardedCookieInit } from "../../server-api";
40
- import { hubSessionConfig } from "../config";
41
- import { resealHubSession } from "../reseal";
42
- import { seal, unseal } from "../seal";
43
- import {
44
- type HubSessionPayload,
45
- hubNextPath,
46
- hubSessionBuyer,
47
- hubSessionInit,
48
- readHubSession,
49
- sessionCookieName,
50
- } from "../session";
51
-
52
- const ENV = process.env;
53
- const SESSION_SECRET = "s".repeat(43);
54
- const CLIENT_SECRET = `ailk_hcs_${"c".repeat(43)}`;
55
- const CREDENTIAL = `ailk_hst_${"t".repeat(43)}`;
56
- const COOKIE = "ailk-hub-session";
57
-
58
- const USER = {
59
- name: "Ada Lovelace",
60
- email: "ada@example.com",
61
- emailVerified: true,
62
- createdAt: "2026-09-01T00:00:00.000Z",
63
- };
64
-
65
- function configure(overrides: Record<string, string | undefined> = {}): void {
66
- process.env = {
67
- ...ENV,
68
- AILK_HUB_SIGN_IN_URL: "https://hub.example.com",
69
- AILK_HUB_CLIENT_ID: "spoke_0001",
70
- AILK_HUB_CLIENT_SECRET: CLIENT_SECRET,
71
- AILK_HUB_SESSION_SECRET: SESSION_SECRET,
72
- NEXT_PUBLIC_BASE_URL: "http://127.0.0.1:3100",
73
- ...overrides,
74
- };
75
- for (const [key, value] of Object.entries(overrides)) {
76
- if (value === undefined) delete process.env[key];
77
- }
78
- }
79
-
80
- function payload(overrides: Partial<HubSessionPayload> = {}): HubSessionPayload {
81
- return {
82
- v: 1,
83
- accessToken: CREDENTIAL,
84
- expiresAt: Date.now() + 60_000,
85
- user: USER,
86
- ...overrides,
87
- };
88
- }
89
-
90
- function headersWith(value: string, name = COOKIE): Headers {
91
- return new Headers({ cookie: `other=1; ${name}=${value}` });
92
- }
93
-
94
- beforeEach(() => {
95
- configure();
96
- mockMe.mockReset();
97
- mockHeaders.mockReset();
98
- });
99
-
100
- afterAll(() => {
101
- process.env = ENV;
102
- });
103
-
104
- describe("seal", () => {
105
- it("round-trips a value for the same secret, purpose and cookie name", () => {
106
- const sealed = seal({ a: 1 }, SESSION_SECRET, "session", COOKIE);
107
- expect(unseal(sealed, SESSION_SECRET, "session", COOKIE)).toEqual({ a: 1 });
108
- });
109
-
110
- it("opens nothing under another secret, purpose or cookie name, or altered", () => {
111
- const sealed = seal({ a: 1 }, SESSION_SECRET, "session", COOKIE);
112
- expect(unseal(sealed, "x".repeat(43), "session", COOKIE)).toBeNull();
113
- expect(unseal(sealed, SESSION_SECRET, "flow", COOKIE)).toBeNull();
114
- expect(unseal(sealed, SESSION_SECRET, "session", "ailk-hub-flow")).toBeNull();
115
- const flipped = Buffer.from(sealed, "base64url");
116
- flipped[flipped.length - 1] = (flipped[flipped.length - 1] ?? 0) ^ 1;
117
- expect(unseal(flipped.toString("base64url"), SESSION_SECRET, "session", COOKIE)).toBeNull();
118
- expect(unseal("", SESSION_SECRET, "session", COOKIE)).toBeNull();
119
- });
120
-
121
- // #8146 AC-4: the `continue` purpose was added to seal.ts. These two
122
- // ciphertexts were sealed on `main` BEFORE that edit and committed as
123
- // literals, so any change to INFO.session, INFO.flow or deriveKey fails
124
- // here — the round trips above cannot see a key change (a changed key still
125
- // round-trips with itself, and would silently log out every live spoke).
126
- it("still opens a `session` value sealed before the `continue` purpose existed", () => {
127
- const sealed =
128
- "T0OSblxM1tRcJ4f5OP4VDvQA5TvWQdW3K_GvZlFzETSgVCw1tzEEaDWfAhHz0HZgY1sg8vA2fy0au73t";
129
- expect(unseal(sealed, SESSION_SECRET, "session", COOKIE)).toEqual({
130
- v: 1,
131
- fixed: "session-vector",
132
- });
133
- });
134
-
135
- it("still opens a `flow` value sealed before the `continue` purpose existed", () => {
136
- const sealed =
137
- "TI60LmvzNlRIp6a4BexFT9zmNoOWn8ZYBhW2VtOklk6lwUtrEWwtJ15XSJeAfgeNpSc322z-PWlZ";
138
- expect(unseal(sealed, SESSION_SECRET, "flow", "ailk-hub-flow")).toEqual({
139
- v: 1,
140
- fixed: "flow-vector",
141
- });
142
- });
143
-
144
- it("uses a fresh IV per seal", () => {
145
- expect(seal({ a: 1 }, SESSION_SECRET, "session", COOKIE)).not.toBe(
146
- seal({ a: 1 }, SESSION_SECRET, "session", COOKIE),
147
- );
148
- });
149
- });
150
-
151
- describe("hubSessionConfig", () => {
152
- it("reads the four variables and the site origin; the redirect URI is the site's, never a header's", () => {
153
- expect(hubSessionConfig()).toEqual({
154
- hubOrigin: "https://hub.example.com",
155
- clientId: "spoke_0001",
156
- clientSecret: CLIENT_SECRET,
157
- sessionSecret: SESSION_SECRET,
158
- siteOrigin: "http://127.0.0.1:3100",
159
- redirectUri: "http://127.0.0.1:3100/api/hub-session/callback",
160
- secure: false,
161
- oneTap: false,
162
- });
163
- });
164
-
165
- // #11096 D10 — One Tap is on only for exactly `on`.
166
- it.each([
167
- ["on", true],
168
- ["ON", false],
169
- ["1", false],
170
- ["", false],
171
- ])("AILK_HUB_ONE_TAP=%p reads oneTap %p", (value, expected) => {
172
- configure({ AILK_HUB_ONE_TAP: value });
173
- expect(hubSessionConfig()?.oneTap).toBe(expected);
174
- });
175
-
176
- it("is secure on an https site", () => {
177
- configure({ NEXT_PUBLIC_BASE_URL: "https://spoke.example.com/" });
178
- expect(hubSessionConfig()).toMatchObject({
179
- siteOrigin: "https://spoke.example.com",
180
- secure: true,
181
- });
182
- expect(sessionCookieName({ secure: true })).toBe("__Host-ailk-hub-session");
183
- });
184
-
185
- it.each([
186
- ["no hub origin", { AILK_HUB_SIGN_IN_URL: undefined }],
187
- ["an http hub off loopback", { AILK_HUB_SIGN_IN_URL: "http://hub.example.com" }],
188
- ["a hub URL with a path", { AILK_HUB_SIGN_IN_URL: "https://hub.example.com/x" }],
189
- ["no client id", { AILK_HUB_CLIENT_ID: undefined }],
190
- ["no client secret", { AILK_HUB_CLIENT_SECRET: undefined }],
191
- ["a short session secret", { AILK_HUB_SESSION_SECRET: "short" }],
192
- ["an http site off loopback", { NEXT_PUBLIC_BASE_URL: "http://spoke.example.com" }],
193
- ])("is null with %s", (_label, overrides) => {
194
- configure(overrides);
195
- expect(hubSessionConfig()).toBeNull();
196
- });
197
- });
198
-
199
- describe("readHubSession", () => {
200
- it("reads the person from a sealed, unexpired cookie", async () => {
201
- const sealed = seal(payload(), SESSION_SECRET, "session", COOKIE);
202
- await expect(readHubSession(headersWith(sealed))).resolves.toEqual({ user: USER });
203
- });
204
-
205
- it("reads null with no cookie, an expired one, or with no configuration", async () => {
206
- await expect(readHubSession(new Headers())).resolves.toBeNull();
207
- const expired = seal(payload({ expiresAt: Date.now() - 1 }), SESSION_SECRET, "session", COOKIE);
208
- await expect(readHubSession(headersWith(expired))).resolves.toBeNull();
209
- const sealed = seal(payload(), SESSION_SECRET, "session", COOKIE);
210
- configure({ AILK_HUB_SESSION_SECRET: undefined });
211
- await expect(readHubSession(headersWith(sealed))).resolves.toBeNull();
212
- });
213
-
214
- it("AC-5: a cookie sealed with a key derived from AILK_HUB_CLIENT_SECRET reads as null", async () => {
215
- // Every way the client secret could have keyed the cookie: the module's own
216
- // seal with the client secret as the session secret, and a raw HKDF of it.
217
- const viaSeal = seal(payload(), CLIENT_SECRET, "session", COOKIE);
218
- await expect(readHubSession(headersWith(viaSeal))).resolves.toBeNull();
219
-
220
- const key = Buffer.from(hkdfSync("sha256", CLIENT_SECRET, Buffer.alloc(0), "ailk-hub-session/v1", 32));
221
- const iv = randomBytes(12);
222
- const cipher = createCipheriv("aes-256-gcm", key, iv);
223
- cipher.setAAD(Buffer.from(COOKIE));
224
- const body = Buffer.concat([cipher.update(JSON.stringify(payload())), cipher.final()]);
225
- const forged = Buffer.concat([iv, cipher.getAuthTag(), body]).toString("base64url");
226
- await expect(readHubSession(headersWith(forged))).resolves.toBeNull();
227
- });
228
-
229
- it("reads null for a well-sealed value of the wrong shape", async () => {
230
- const sealed = seal({ v: 2, accessToken: CREDENTIAL }, SESSION_SECRET, "session", COOKIE);
231
- await expect(readHubSession(headersWith(sealed))).resolves.toBeNull();
232
- });
233
- });
234
-
235
- describe("AC-7 — forwardedCookieInit on a hub-mode spoke", () => {
236
- it("is exactly the Bearer credential signed in", async () => {
237
- const sealed = seal(payload(), SESSION_SECRET, "session", COOKIE);
238
- mockHeaders.mockResolvedValue(headersWith(sealed));
239
- await expect(forwardedCookieInit()).resolves.toEqual({
240
- headers: { authorization: `Bearer ${CREDENTIAL}` },
241
- });
242
- await expect(hubSessionInit()).resolves.toEqual({
243
- headers: { authorization: `Bearer ${CREDENTIAL}` },
244
- });
245
- });
246
-
247
- it("is exactly no header signed out — never the visitor's cookie", async () => {
248
- mockHeaders.mockResolvedValue(new Headers({ cookie: "better-auth.session_token=abc" }));
249
- await expect(forwardedCookieInit()).resolves.toEqual({ headers: {} });
250
- });
251
- });
252
-
253
- describe("AC-8 — hubSessionBuyer reads the customer live, never from the cookie", () => {
254
- function request(cookie?: string): Request {
255
- return new Request("http://127.0.0.1:3100/api/buy", {
256
- headers: cookie === undefined ? {} : { cookie: `${COOKIE}=${cookie}` },
257
- });
258
- }
259
- const signedIn = (): Request => request(seal(payload(), SESSION_SECRET, "session", COOKIE));
260
-
261
- it("returns the customer /me vouches for, sending the credential", async () => {
262
- mockMe.mockResolvedValue({ ok: true, body: { user: USER, billingCustomerId: "cus_known" } });
263
- await expect(hubSessionBuyer(signedIn())).resolves.toEqual({ customerId: "cus_known" });
264
- expect(mockMe).toHaveBeenCalledWith({ headers: { authorization: `Bearer ${CREDENTIAL}` } });
265
- });
266
-
267
- it("is null with no session, without calling the hub", async () => {
268
- await expect(hubSessionBuyer(request())).resolves.toBeNull();
269
- expect(mockMe).not.toHaveBeenCalled();
270
- });
271
-
272
- it("is null when /me refuses the credential though the cookie is intact (a revoked credential)", async () => {
273
- mockMe.mockResolvedValue({ ok: false, status: 401, body: null });
274
- await expect(hubSessionBuyer(signedIn())).resolves.toBeNull();
275
- });
276
-
277
- it("is null when /me names no customer, or the read throws", async () => {
278
- mockMe.mockResolvedValueOnce({ ok: true, body: { user: USER, billingCustomerId: null } });
279
- await expect(hubSessionBuyer(signedIn())).resolves.toBeNull();
280
- mockMe.mockRejectedValueOnce(new Error("network"));
281
- await expect(hubSessionBuyer(signedIn())).resolves.toBeNull();
282
- });
283
- });
284
-
285
- describe("hubNextPath", () => {
286
- it.each([
287
- ["/account", "/account"],
288
- ["/fr/account/inbox?tab=x", "/fr/account/inbox?tab=x"],
289
- ["https://evil.example.com/", "/account"],
290
- ["//evil.example.com", "/account"],
291
- ["/api/hub-session/sign-out", "/account"],
292
- ["/api", "/account"],
293
- ["/en/../api/hub-session/sign-in?next=/account", "/account"],
294
- ["/%2e%2e/api/hub-session/sign-in", "/account"],
295
- ["/\u65e5\u672c", "/account"],
296
- [null, "/account"],
297
- ])("%s → %s", (raw, expected) => {
298
- expect(hubNextPath(raw)).toBe(expected);
299
- });
300
- });
301
-
302
- // #8232 D11 (spec docs/specs/8232-member-settings-account-general-and-spec.md
303
- // AC-5) — after a member's profile save, the spoke re-seals its session from
304
- // the hub's /me. Only `user` changes; the credential and its expiry are kept,
305
- // so a re-seal never extends a session (SEC-8232-1), and the cookie is
306
- // written with the attributes the callback writes at sign-in (SEC-8232-2).
307
- describe("#8232 AC-5 — resealHubSession", () => {
308
- const mockSet = jest.fn();
309
- const RENAMED = { ...USER, name: "Ada King" };
310
-
311
- beforeEach(() => {
312
- mockSet.mockReset();
313
- jest.mocked(cookies).mockResolvedValue({ set: mockSet } as never);
314
- });
315
-
316
- function signedIn(overrides: Partial<HubSessionPayload> = {}, name = COOKIE): void {
317
- mockHeaders.mockResolvedValue(headersWith(seal(payload(overrides), SESSION_SECRET, "session", name), name));
318
- }
319
-
320
- it("re-seals the session with /me's person, keeping the credential and expiry, once, with the sign-in attributes", async () => {
321
- const expiresAt = Date.now() + 60_000;
322
- signedIn({ expiresAt });
323
- mockMe.mockResolvedValue({ ok: true, body: { user: RENAMED, billingCustomerId: null } });
324
-
325
- await expect(resealHubSession()).resolves.toBe("resealed");
326
-
327
- expect(mockMe).toHaveBeenCalledTimes(1);
328
- expect(mockMe).toHaveBeenCalledWith({ headers: { authorization: `Bearer ${CREDENTIAL}` } });
329
- expect(mockSet).toHaveBeenCalledTimes(1);
330
- const [name, value, options] = mockSet.mock.calls[0] as [string, string, Record<string, unknown>];
331
- expect(name).toBe(COOKIE);
332
- expect(options).toEqual({
333
- httpOnly: true,
334
- sameSite: "lax",
335
- path: "/",
336
- secure: false,
337
- maxAge: expect.any(Number),
338
- });
339
- expect(options["maxAge"]).toBeGreaterThan(0);
340
- expect(options["maxAge"]).toBeLessThanOrEqual(60);
341
- expect(unseal(value, SESSION_SECRET, "session", COOKIE)).toEqual({
342
- v: 1,
343
- accessToken: CREDENTIAL,
344
- expiresAt,
345
- user: RENAMED,
346
- });
347
- });
348
-
349
- it("writes the __Host- cookie with Secure on an https site", async () => {
350
- configure({ NEXT_PUBLIC_BASE_URL: "https://spoke.example.com" });
351
- signedIn({}, "__Host-ailk-hub-session");
352
- mockMe.mockResolvedValue({ ok: true, body: { user: RENAMED, billingCustomerId: null } });
353
-
354
- await expect(resealHubSession()).resolves.toBe("resealed");
355
- const [name, , options] = mockSet.mock.calls[0] as [string, string, Record<string, unknown>];
356
- expect(name).toBe("__Host-ailk-hub-session");
357
- expect(options).toMatchObject({ secure: true, httpOnly: true });
358
- });
359
-
360
- it("is skipped with no configuration (a single site), calling neither /me nor set", async () => {
361
- signedIn();
362
- configure({ AILK_HUB_SESSION_SECRET: undefined });
363
- await expect(resealHubSession()).resolves.toBe("skipped");
364
- expect(mockMe).not.toHaveBeenCalled();
365
- expect(mockSet).not.toHaveBeenCalled();
366
- });
367
-
368
- it("is skipped with no session cookie, calling neither /me nor set", async () => {
369
- mockHeaders.mockResolvedValue(new Headers());
370
- await expect(resealHubSession()).resolves.toBe("skipped");
371
- expect(mockMe).not.toHaveBeenCalled();
372
- expect(mockSet).not.toHaveBeenCalled();
373
- });
374
-
375
- it.each([
376
- ["a non-2xx", () => mockMe.mockResolvedValue({ ok: false, status: 401, body: null })],
377
- ["a throw", () => mockMe.mockRejectedValue(new Error("network"))],
378
- [
379
- "a user with a non-string email",
380
- () => mockMe.mockResolvedValue({ ok: true, body: { user: { ...RENAMED, email: 42 }, billingCustomerId: null } }),
381
- ],
382
- [
383
- "a user with a non-boolean emailVerified",
384
- () =>
385
- mockMe.mockResolvedValue({ ok: true, body: { user: { ...RENAMED, emailVerified: "yes" }, billingCustomerId: null } }),
386
- ],
387
- [
388
- "a user with a non-string createdAt",
389
- () => mockMe.mockResolvedValue({ ok: true, body: { user: { ...RENAMED, createdAt: 1 }, billingCustomerId: null } }),
390
- ],
391
- [
392
- "a user whose name is neither a string nor null",
393
- () => mockMe.mockResolvedValue({ ok: true, body: { user: { ...RENAMED, name: 7 }, billingCustomerId: null } }),
394
- ],
395
- ])("fails on %s from /me and leaves the cookie as it is", async (_label, arrange) => {
396
- signedIn();
397
- arrange();
398
- await expect(resealHubSession()).resolves.toBe("failed");
399
- expect(mockSet).not.toHaveBeenCalled();
400
- });
401
-
402
- it("is skipped when the session has under a second left, with no call and no write", async () => {
403
- signedIn({ expiresAt: Date.now() + 500 });
404
- await expect(resealHubSession()).resolves.toBe("skipped");
405
- expect(mockMe).not.toHaveBeenCalled();
406
- expect(mockSet).not.toHaveBeenCalled();
407
- });
408
-
409
- it("fails, never throws, when the cookie write is refused", async () => {
410
- signedIn();
411
- mockMe.mockResolvedValue({ ok: true, body: { user: RENAMED, billingCustomerId: null } });
412
- mockSet.mockImplementation(() => {
413
- throw new Error("Cookies can only be modified in a Server Action or Route Handler");
414
- });
415
- await expect(resealHubSession()).resolves.toBe("failed");
416
- });
417
- });
418
-
419
- describe("readBodyText (#11096) — the spoke's body read caps BYTES, not characters", () => {
420
- const post = (body: string): Request =>
421
- new Request("https://spoke.example/api/hub-session/email", { method: "POST", body });
422
-
423
- it("reads a body within 8 KB", async () => {
424
- const { readBodyText } = await import("../entry");
425
- await expect(readBodyText(post("a".repeat(8_192)))).resolves.toBe("a".repeat(8_192));
426
- });
427
-
428
- it("refuses a body under 8 K characters but over 8 KB of UTF-8", async () => {
429
- const { readBodyText } = await import("../entry");
430
- // 3 000 three-byte characters: 3 000 characters, 9 000 bytes.
431
- await expect(readBodyText(post("€".repeat(3_000)))).resolves.toBeNull();
432
- });
433
- });