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,749 +0,0 @@
1
- /**
2
- * @jest-environment node
3
- */
4
-
5
- /**
6
- * The hub web's spoke-facing entry routes (#11096 D2, D3, D9; AC-1, AC-2,
7
- * AC-4, AC-6).
8
- *
9
- * POST /api/auth/hub/email a spoke asks for the hub's magic link
10
- * GET /api/auth/hub/sign-up the agreements a spoke's form shows
11
- * POST /api/auth/hub/purchase-link the hub API's signed purchase receiver
12
- * POST /api/auth/hub/purchase a spoke spends a purchase claim
13
- *
14
- * Better Auth (`auth.api.signInMagicLink`, the internal adapter) and
15
- * `@working-theory/api-client` (the hub API's entry check, client info, the
16
- * sign-up evidence and the mail relay) are the external boundaries; both are
17
- * doubles. The routes' own decisions are under test: what each accepts, in
18
- * what order it refuses, what it hands Better Auth, and what it sends.
19
- */
20
-
21
- import { createHash, createHmac } from "node:crypto";
22
-
23
- // --- Mocks set up BEFORE imports ---
24
-
25
- const mockSecret = "k".repeat(43);
26
- const mockSignInMagicLink = jest.fn();
27
- const mockFindUserByEmail = jest.fn();
28
- const mockFindVerificationValue = jest.fn();
29
- const mockCreateVerificationValue = jest.fn();
30
- const mockDeleteVerificationByIdentifier = jest.fn();
31
- // eslint-disable-next-line no-restricted-syntax -- auth.ts is the Better Auth singleton (its adapter needs a live database); this stand-in for its server calls and internal adapter is the repo-standard double for that boundary (see authorize/__tests__/route.test.ts).
32
- jest.mock("../../../../../auth", () => ({
33
- __esModule: true,
34
- auth: {
35
- api: {
36
- signInMagicLink: (...args: unknown[]) => mockSignInMagicLink(...args),
37
- },
38
- $context: Promise.resolve({
39
- internalAdapter: {
40
- findUserByEmail: (...args: unknown[]) => mockFindUserByEmail(...args),
41
- findVerificationValue: (...args: unknown[]) =>
42
- mockFindVerificationValue(...args),
43
- createVerificationValue: (...args: unknown[]) =>
44
- mockCreateVerificationValue(...args),
45
- deleteVerificationByIdentifier: (...args: unknown[]) =>
46
- mockDeleteVerificationByIdentifier(...args),
47
- },
48
- }),
49
- },
50
- resolveSecret: () => mockSecret,
51
- }));
52
-
53
- const mockEntry = jest.fn();
54
- const mockClientInfo = jest.fn();
55
- const mockSignUpEvidence = jest.fn();
56
- const mockMailSend = jest.fn();
57
- jest.mock("@working-theory/api-client", () => ({
58
- __esModule: true,
59
- hubSignIn: {
60
- entry: (...args: unknown[]) => mockEntry(...args),
61
- clientInfo: (...args: unknown[]) => mockClientInfo(...args),
62
- },
63
- consent: {
64
- signUpEvidence: (...args: unknown[]) => mockSignUpEvidence(...args),
65
- },
66
- authEmail: { send: (...args: unknown[]) => mockMailSend(...args) },
67
- }));
68
-
69
- import { mintContinuation, openContinuation } from "../continuation";
70
- import { POST as emailPOST } from "../email/route";
71
- import { __resetRefusedCallers } from "../entry-shared";
72
- import { POST as purchaseLinkPOST } from "../purchase-link/route";
73
- import { POST as purchasePOST } from "../purchase/route";
74
- import { GET as signUpGET } from "../sign-up/route";
75
- import { resetHubSignUpEvidenceCache } from "../sign-up-evidence";
76
-
77
- const HUB = "https://hub.example";
78
- const SPOKE = "https://spoke.example";
79
- const CALLBACK = `${SPOKE}/api/hub-session/callback`;
80
- const CONTINUE = "/api/auth/hub/continue";
81
- const WEBHOOK_SECRET = "purchase-webhook-secret";
82
- const BASIC = "Basic c3Bva2VfYWJjOnNlY3JldA==";
83
- const SPOKE_KEY = "ailk_spk_spoke";
84
- const SESSION_ID = "cs_live_abc123";
85
-
86
- const AUTHORIZE = {
87
- client_id: "spoke_abc",
88
- redirect_uri: CALLBACK,
89
- state: "s".repeat(43),
90
- code_challenge: "c".repeat(43),
91
- code_challenge_method: "S256",
92
- };
93
- const SIX_KEYS = new URLSearchParams({
94
- response_type: "code",
95
- ...AUTHORIZE,
96
- }).toString();
97
-
98
- const ACCOUNT_TERMS = {
99
- purposeId: "account_terms",
100
- policyVersion: 1,
101
- locale: "en",
102
- statement:
103
- "I accept the [Terms](terms), [Privacy Policy](privacy), and [Working Agreement](working_agreement).",
104
- statementHash: "a".repeat(64),
105
- };
106
-
107
- function evidence(agreements: unknown[] = [ACCOUNT_TERMS]) {
108
- return { ok: true, body: { workspaceId: "ws_hub", agreements } };
109
- }
110
-
111
- const ORIGINAL_ENV = process.env;
112
-
113
- beforeEach(() => {
114
- jest.resetAllMocks();
115
- resetHubSignUpEvidenceCache();
116
- __resetRefusedCallers();
117
- process.env = {
118
- ...ORIGINAL_ENV,
119
- BETTER_AUTH_URL: `${HUB}/api/auth`,
120
- AUTH_EMAIL_WEBHOOK_SECRET: WEBHOOK_SECRET,
121
- AILK_AUTH_SIGNUP_OPEN: "1",
122
- NEXT_PUBLIC_ENABLED_LOCALES: "en",
123
- };
124
- delete process.env.GOOGLE_CLIENT_ID;
125
- delete process.env.GOOGLE_CLIENT_SECRET;
126
- mockEntry.mockResolvedValue({ ok: true, body: { clientId: "spoke_abc" } });
127
- mockSignInMagicLink.mockResolvedValue({ status: true });
128
- mockSignUpEvidence.mockResolvedValue(evidence());
129
- mockClientInfo.mockResolvedValue({
130
- ok: true,
131
- body: { clientId: "spoke_abc", name: "Spoke", origin: SPOKE },
132
- });
133
- mockFindVerificationValue.mockResolvedValue(null);
134
- mockCreateVerificationValue.mockResolvedValue({});
135
- mockDeleteVerificationByIdentifier.mockResolvedValue(undefined);
136
- mockFindUserByEmail.mockResolvedValue(null);
137
- mockMailSend.mockResolvedValue({ ok: true, status: 202 });
138
- });
139
-
140
- afterAll(() => {
141
- process.env = ORIGINAL_ENV;
142
- });
143
-
144
- // ── POST /api/auth/hub/email (D2) ───────────────────────────────────────────
145
-
146
- function emailRequest(
147
- body: unknown,
148
- headers: Record<string, string> = {
149
- authorization: BASIC,
150
- "x-ailk-spoke-key": SPOKE_KEY,
151
- },
152
- ): Request {
153
- return new Request(`${HUB}/api/auth/hub/email`, {
154
- method: "POST",
155
- headers: { "content-type": "application/json", ...headers },
156
- body: typeof body === "string" ? body : JSON.stringify(body),
157
- });
158
- }
159
-
160
- const EMAIL_BODY = { ...AUTHORIZE, email: "pat@example.com", locale: "en" };
161
-
162
- describe("POST /api/auth/hub/email (D2)", () => {
163
- it("AC-1: asks the API's entry check with the spoke's two headers, then sends the link to the sealed continue path", async () => {
164
- const res = await emailPOST(emailRequest(EMAIL_BODY));
165
-
166
- expect(res.status).toBe(202);
167
- expect(await res.json()).toEqual({ sent: true });
168
- expect(mockEntry).toHaveBeenCalledWith(
169
- { authorization: BASIC, spokeKey: SPOKE_KEY },
170
- {
171
- clientId: "spoke_abc",
172
- redirectUri: CALLBACK,
173
- email: "pat@example.com",
174
- },
175
- );
176
- expect(mockSignInMagicLink).toHaveBeenCalledTimes(1);
177
- const [call] = mockSignInMagicLink.mock.calls[0] as [
178
- { body: Record<string, unknown>; headers: Headers },
179
- ];
180
- const callbackURL = String(call.body.callbackURL);
181
- expect(callbackURL.startsWith(`${CONTINUE}/`)).toBe(true);
182
- expect(
183
- openContinuation(callbackURL.slice(`${CONTINUE}/`.length), mockSecret),
184
- ).toBe(SIX_KEYS);
185
- // No agreements ticked: a sign-in request, no metadata.
186
- expect(call.body).toEqual({ email: "pat@example.com", callbackURL });
187
- });
188
-
189
- it("SEC-11096-12: Better Auth gets only the pinned Origin — never the spoke's Authorization or key", async () => {
190
- await emailPOST(emailRequest(EMAIL_BODY));
191
- const [call] = mockSignInMagicLink.mock.calls[0] as [{ headers: Headers }];
192
- expect([...call.headers.entries()]).toEqual([["origin", HUB]]);
193
- });
194
-
195
- it("AC-2: ticked agreements reach Better Auth as metadata with the locale, unchanged", async () => {
196
- await emailPOST(
197
- emailRequest({ ...EMAIL_BODY, agreements: ["account_terms"] }),
198
- );
199
- const [call] = mockSignInMagicLink.mock.calls[0] as [
200
- { body: Record<string, unknown> },
201
- ];
202
- expect(call.body.metadata).toEqual({
203
- agreements: ["account_terms"],
204
- locale: "en",
205
- });
206
- });
207
-
208
- it("AC-1: the API's 401 is passed on as 401 and nothing is sent", async () => {
209
- mockEntry.mockResolvedValue({
210
- ok: false,
211
- status: 401,
212
- body: { ok: false, error: { code: "invalid_client" } },
213
- });
214
- const res = await emailPOST(emailRequest(EMAIL_BODY));
215
- expect(res.status).toBe(401);
216
- expect(await res.json()).toEqual({ error: "invalid_client" });
217
- expect(mockSignInMagicLink).not.toHaveBeenCalled();
218
- });
219
-
220
- it("the API's 429 is passed on with its error", async () => {
221
- mockEntry.mockResolvedValue({
222
- ok: false,
223
- status: 429,
224
- body: { ok: false, error: { code: "rate_limited" } },
225
- });
226
- const res = await emailPOST(emailRequest(EMAIL_BODY));
227
- expect(res.status).toBe(429);
228
- expect(mockSignInMagicLink).not.toHaveBeenCalled();
229
- });
230
-
231
- it("a request without the spoke's two headers is 401 with no API call", async () => {
232
- const res = await emailPOST(emailRequest(EMAIL_BODY, {}));
233
- expect(res.status).toBe(401);
234
- expect(mockEntry).not.toHaveBeenCalled();
235
- });
236
-
237
- it.each([
238
- ["a Bearer authorization", { authorization: "Bearer x", "x-ailk-spoke-key": SPOKE_KEY }],
239
- ["a Basic header with no credentials", { authorization: "Basic ", "x-ailk-spoke-key": SPOKE_KEY }],
240
- ["a Basic header that is not base64", { authorization: "Basic a b", "x-ailk-spoke-key": SPOKE_KEY }],
241
- ])("%s is 401 invalid_client with no API call", async (_name, headers) => {
242
- const res = await emailPOST(emailRequest(EMAIL_BODY, headers));
243
- expect(res.status).toBe(401);
244
- expect(await res.json()).toEqual({ error: "invalid_client" });
245
- expect(mockEntry).not.toHaveBeenCalled();
246
- });
247
-
248
- it("a caller the API refused ten times in ten minutes is 429 before any API call; another caller is not", async () => {
249
- process.env.VERCEL = "1";
250
- mockEntry.mockResolvedValue({
251
- ok: false,
252
- status: 401,
253
- body: { ok: false, error: { code: "invalid_client" } },
254
- });
255
- const from = (ip: string): Request =>
256
- emailRequest(EMAIL_BODY, {
257
- authorization: BASIC,
258
- "x-ailk-spoke-key": SPOKE_KEY,
259
- "x-vercel-forwarded-for": ip,
260
- });
261
-
262
- for (let i = 0; i < 10; i += 1) {
263
- expect((await emailPOST(from("203.0.113.9"))).status).toBe(401);
264
- }
265
- const limited = await emailPOST(from("203.0.113.9"));
266
- expect(limited.status).toBe(429);
267
- expect(await limited.json()).toEqual({ error: "rate_limited" });
268
- expect(Number(limited.headers.get("retry-after"))).toBeGreaterThan(0);
269
- expect(mockEntry).toHaveBeenCalledTimes(10);
270
-
271
- mockEntry.mockResolvedValue({ ok: true, body: { clientId: "spoke_abc" } });
272
- expect((await emailPOST(from("198.51.100.4"))).status).toBe(202);
273
- });
274
-
275
- it("a spoke the API accepts is never limited by its own successes", async () => {
276
- process.env.VERCEL = "1";
277
- for (let i = 0; i < 15; i += 1) {
278
- const res = await emailPOST(
279
- emailRequest(EMAIL_BODY, {
280
- authorization: BASIC,
281
- "x-ailk-spoke-key": SPOKE_KEY,
282
- "x-vercel-forwarded-for": "203.0.113.20",
283
- }),
284
- );
285
- expect(res.status).toBe(202);
286
- }
287
- });
288
-
289
- it("AC-2: AGREEMENTS_REQUIRED from the plugin is 400 agreements_required", async () => {
290
- mockSignInMagicLink.mockRejectedValue({
291
- statusCode: 400,
292
- body: { code: "AGREEMENTS_REQUIRED" },
293
- });
294
- const res = await emailPOST(
295
- emailRequest({ ...EMAIL_BODY, agreements: ["account_terms"] }),
296
- );
297
- expect(res.status).toBe(400);
298
- expect(await res.json()).toEqual({ error: "agreements_required" });
299
- });
300
-
301
- it("SIGN_UP_CLOSED is 400 sign_up_closed; any other throw is 503", async () => {
302
- mockSignInMagicLink.mockRejectedValueOnce({
303
- body: { code: "SIGN_UP_CLOSED" },
304
- });
305
- const closed = await emailPOST(
306
- emailRequest({ ...EMAIL_BODY, agreements: ["account_terms"] }),
307
- );
308
- expect(closed.status).toBe(400);
309
- expect(await closed.json()).toEqual({ error: "sign_up_closed" });
310
-
311
- mockSignInMagicLink.mockRejectedValueOnce(new Error("boom"));
312
- const failed = await emailPOST(emailRequest(EMAIL_BODY));
313
- expect(failed.status).toBe(503);
314
- });
315
-
316
- it("AC-6: an added password field is 400 invalid_request and no entry call", async () => {
317
- const res = await emailPOST(
318
- emailRequest({ ...EMAIL_BODY, password: "hunter22" }),
319
- );
320
- expect(res.status).toBe(400);
321
- expect(await res.json()).toEqual({ error: "invalid_request" });
322
- expect(mockEntry).not.toHaveBeenCalled();
323
- expect(mockSignInMagicLink).not.toHaveBeenCalled();
324
- });
325
-
326
- it.each([
327
- ["not JSON", "{"],
328
- ["over 4 KB", JSON.stringify({ ...EMAIL_BODY, pad: "x".repeat(5000) })],
329
- ["a response_type key", { ...EMAIL_BODY, response_type: "code" }],
330
- ])("%s → 400, no call", async (_name, body) => {
331
- const res = await emailPOST(emailRequest(body));
332
- expect(res.status).toBe(400);
333
- expect(mockEntry).not.toHaveBeenCalled();
334
- });
335
-
336
- it("503 with no pinned origin", async () => {
337
- delete process.env.BETTER_AUTH_URL;
338
- const res = await emailPOST(emailRequest(EMAIL_BODY));
339
- expect(res.status).toBe(503);
340
- expect(mockEntry).not.toHaveBeenCalled();
341
- });
342
- });
343
-
344
- // ── GET /api/auth/hub/sign-up (D3) ──────────────────────────────────────────
345
-
346
- describe("GET /api/auth/hub/sign-up (D3)", () => {
347
- it("answers sign-up open, Google, and each agreement with its policy links absolute on the hub", async () => {
348
- process.env.GOOGLE_CLIENT_ID = "g";
349
- process.env.GOOGLE_CLIENT_SECRET = "g-secret";
350
-
351
- const res = await signUpGET(
352
- new Request(`${HUB}/api/auth/hub/sign-up?locale=en`),
353
- );
354
-
355
- expect(res.status).toBe(200);
356
- expect(res.headers.get("cache-control")).toBe("public, max-age=60");
357
- const body = (await res.json()) as {
358
- signUpOpen: boolean;
359
- google: boolean;
360
- agreements: Array<{
361
- purposeId: string;
362
- statement: string;
363
- policies: Record<string, string>;
364
- }>;
365
- };
366
- expect(body.signUpOpen).toBe(true);
367
- expect(body.google).toBe(true);
368
- expect(body.agreements).toHaveLength(1);
369
- expect(body.agreements[0]!.purposeId).toBe("account_terms");
370
- expect(body.agreements[0]!.statement).toBe(ACCOUNT_TERMS.statement);
371
- expect(body.agreements[0]!.policies.terms).toMatch(new RegExp(`^${HUB}/`));
372
- expect(mockSignUpEvidence).toHaveBeenCalledWith({ locale: "en" });
373
- });
374
-
375
- it("Google off and sign-up closed are reported as such", async () => {
376
- delete process.env.AILK_AUTH_SIGNUP_OPEN;
377
- const res = await signUpGET(new Request(`${HUB}/api/auth/hub/sign-up`));
378
- const body = (await res.json()) as { signUpOpen: boolean; google: boolean };
379
- expect(body).toMatchObject({ signUpOpen: false, google: false });
380
- });
381
-
382
- it("an unreadable evidence read is a 503, never an empty agreement list", async () => {
383
- mockSignUpEvidence.mockResolvedValue({
384
- ok: false,
385
- status: 503,
386
- body: null,
387
- });
388
- const res = await signUpGET(new Request(`${HUB}/api/auth/hub/sign-up`));
389
- expect(res.status).toBe(503);
390
- expect(res.headers.get("cache-control")).toBe("no-store");
391
- });
392
- });
393
-
394
- // ── POST /api/auth/hub/purchase-link (D9) ───────────────────────────────────
395
-
396
- const LINK_BODY = {
397
- email: "buyer@example.com",
398
- clientId: "spoke_abc",
399
- sessionId: SESSION_ID,
400
- policyVersion: 1,
401
- locale: "en",
402
- };
403
-
404
- function signedLink(
405
- body: unknown,
406
- opts: { secret?: string; ageSeconds?: number; signature?: string } = {},
407
- ): Request {
408
- const raw = typeof body === "string" ? body : JSON.stringify(body);
409
- const ts = String(Math.floor(Date.now() / 1000) - (opts.ageSeconds ?? 0));
410
- const signature =
411
- opts.signature ??
412
- `sha256=${createHmac("sha256", opts.secret ?? WEBHOOK_SECRET)
413
- .update(`v0:purchase-link:${ts}:${raw}`, "utf8")
414
- .digest("hex")}`;
415
- return new Request(`${HUB}/api/auth/hub/purchase-link`, {
416
- method: "POST",
417
- headers: {
418
- "content-type": "application/json",
419
- "x-ailk-purchase-timestamp": ts,
420
- "x-ailk-purchase-signature": signature,
421
- },
422
- body: raw,
423
- });
424
- }
425
-
426
- /** The account-open sends the relay received. */
427
- function accountOpenSends(): Array<Record<string, unknown>> {
428
- return mockMailSend.mock.calls
429
- .map(([raw]) => JSON.parse(String(raw)) as Record<string, unknown>)
430
- .filter((body) => body.kind === "account-open");
431
- }
432
-
433
- describe("POST /api/auth/hub/purchase-link (D9)", () => {
434
- it("AC-4: a valid signature → 202 and one account-open send to the spoke's /account?claim=", async () => {
435
- const res = await purchaseLinkPOST(signedLink(LINK_BODY));
436
-
437
- expect(res.status).toBe(202);
438
- const sends = accountOpenSends();
439
- expect(sends).toHaveLength(1);
440
- expect(sends[0]!.to).toBe("buyer@example.com");
441
- const url = new URL(String(sends[0]!.url));
442
- expect(`${url.origin}${url.pathname}`).toBe(`${SPOKE}/account`);
443
- const claim = url.searchParams.get("claim") ?? "";
444
- // The claim opens only under its own name, never as a continuation.
445
- expect(openContinuation(claim, mockSecret)).toBeNull();
446
- const query = new URLSearchParams(
447
- openContinuation(claim, mockSecret, Date.now(), "hub-purchase") ?? "",
448
- );
449
- expect(Object.fromEntries(query)).toEqual({
450
- e: "buyer@example.com",
451
- c: "spoke_abc",
452
- s: SESSION_ID,
453
- v: "1",
454
- l: "en",
455
- });
456
- expect(mockCreateVerificationValue).toHaveBeenCalledWith(
457
- expect.objectContaining({
458
- identifier: `purchase-link:${createHash("sha256").update(SESSION_ID).digest("hex")}`,
459
- }),
460
- );
461
- });
462
-
463
- it("SEC-11096-13: the same body again → 202 and no second send", async () => {
464
- mockFindVerificationValue.mockResolvedValue({
465
- value: "1",
466
- expiresAt: new Date(Date.now() + 60_000),
467
- });
468
- const res = await purchaseLinkPOST(signedLink(LINK_BODY));
469
- expect(res.status).toBe(202);
470
- expect(accountOpenSends()).toHaveLength(0);
471
- });
472
-
473
- it.each([
474
- ["a bad signature", () => signedLink(LINK_BODY, { secret: "other" })],
475
- [
476
- "a 301-second-old timestamp",
477
- () => signedLink(LINK_BODY, { ageSeconds: 301 }),
478
- ],
479
- ["no signature", () => signedLink(LINK_BODY, { signature: "" })],
480
- [
481
- "an invalid body behind a bad signature",
482
- () => signedLink("{not json", { secret: "other" }),
483
- ],
484
- ])("%s → 401, nothing sent or written", async (_name, build) => {
485
- const res = await purchaseLinkPOST(build());
486
- expect(res.status).toBe(401);
487
- expect(accountOpenSends()).toHaveLength(0);
488
- expect(mockCreateVerificationValue).not.toHaveBeenCalled();
489
- });
490
-
491
- it("a validly signed invalid body → 400", async () => {
492
- const res = await purchaseLinkPOST(
493
- signedLink({ ...LINK_BODY, sessionId: "not-a-session" }),
494
- );
495
- expect(res.status).toBe(400);
496
- });
497
-
498
- it("503 with no secret, before anything else", async () => {
499
- delete process.env.AUTH_EMAIL_WEBHOOK_SECRET;
500
- const res = await purchaseLinkPOST(signedLink(LINK_BODY, { secret: "" }));
501
- expect(res.status).toBe(503);
502
- });
503
-
504
- it.each([
505
- [
506
- "evidence asking for two agreements",
507
- [ACCOUNT_TERMS, { ...ACCOUNT_TERMS, purposeId: "newsletter" }],
508
- ],
509
- [
510
- "account_terms at another version",
511
- [{ ...ACCOUNT_TERMS, policyVersion: 2 }],
512
- ],
513
- ])("%s → 202, nothing sent or written", async (_name, agreements) => {
514
- mockSignUpEvidence.mockResolvedValue(evidence(agreements));
515
- const res = await purchaseLinkPOST(signedLink(LINK_BODY));
516
- expect(res.status).toBe(202);
517
- expect(accountOpenSends()).toHaveLength(0);
518
- expect(mockCreateVerificationValue).not.toHaveBeenCalled();
519
- });
520
-
521
- it("a client the registry does not know → 202, nothing sent or written", async () => {
522
- mockClientInfo.mockResolvedValue({ ok: false, status: 404, body: null });
523
- const res = await purchaseLinkPOST(signedLink(LINK_BODY));
524
- expect(res.status).toBe(202);
525
- expect(accountOpenSends()).toHaveLength(0);
526
- expect(mockCreateVerificationValue).not.toHaveBeenCalled();
527
- });
528
-
529
- it("an evidence read that fails → 503, nothing sent or written, so the next try can send", async () => {
530
- mockSignUpEvidence.mockResolvedValue({ ok: false, status: 502, body: null });
531
- const res = await purchaseLinkPOST(signedLink(LINK_BODY));
532
- expect(res.status).toBe(503);
533
- expect(accountOpenSends()).toHaveLength(0);
534
- expect(mockCreateVerificationValue).not.toHaveBeenCalled();
535
- });
536
-
537
- it("a send the relay refuses → 503 and the once-per-session marker is removed", async () => {
538
- mockMailSend.mockResolvedValue({ ok: false, status: 500 });
539
- const res = await purchaseLinkPOST(signedLink(LINK_BODY));
540
- expect(res.status).toBe(503);
541
- const identifier = `purchase-link:${createHash("sha256").update(SESSION_ID).digest("hex")}`;
542
- expect(mockCreateVerificationValue).toHaveBeenCalledWith(
543
- expect.objectContaining({ identifier }),
544
- );
545
- expect(mockDeleteVerificationByIdentifier).toHaveBeenCalledWith(identifier);
546
- });
547
- });
548
-
549
- // ── POST /api/auth/hub/purchase (D9) ────────────────────────────────────────
550
-
551
- function claimFor(
552
- overrides: Partial<Record<"e" | "c" | "s" | "v" | "l", string>> = {},
553
- now = Date.now(),
554
- name = "hub-purchase",
555
- ): string {
556
- const query = new URLSearchParams({
557
- e: "buyer@example.com",
558
- c: "spoke_abc",
559
- s: SESSION_ID,
560
- v: "1",
561
- l: "en",
562
- ...overrides,
563
- }).toString();
564
- return mintContinuation(query, mockSecret, now, name, 72 * 3600);
565
- }
566
-
567
- function purchaseRequest(
568
- body: unknown,
569
- headers: Record<string, string> = {
570
- authorization: BASIC,
571
- "x-ailk-spoke-key": SPOKE_KEY,
572
- },
573
- ): Request {
574
- return new Request(`${HUB}/api/auth/hub/purchase`, {
575
- method: "POST",
576
- headers: { "content-type": "application/json", ...headers },
577
- body: JSON.stringify(body),
578
- });
579
- }
580
-
581
- describe("POST /api/auth/hub/purchase (D9)", () => {
582
- beforeEach(() => {
583
- // The plugin's capture: the token reaches the store, nothing is mailed.
584
- mockSignInMagicLink.mockImplementation(async () => {
585
- const { purchaseCapture } = jest.requireActual<
586
- typeof import("../../../../../lib/auth-email")
587
- >("../../../../../lib/auth-email");
588
- const store = purchaseCapture.getStore();
589
- if (store) store.token = "CAPTURED_TOKEN";
590
- return { status: true };
591
- });
592
- });
593
-
594
- it("AC-4: an authenticated spoke and a fresh claim for a new address → 200 verifyUrl on the pinned origin; nothing mailed", async () => {
595
- const res = await purchasePOST(
596
- purchaseRequest({ ...AUTHORIZE, claim: claimFor() }),
597
- );
598
-
599
- expect(res.status).toBe(200);
600
- expect(res.headers.get("cache-control")).toBe("no-store");
601
- const { verifyUrl } = (await res.json()) as { verifyUrl: string };
602
- const url = new URL(verifyUrl);
603
- expect(`${url.origin}${url.pathname}`).toBe(
604
- `${HUB}/api/auth/magic-link/verify`,
605
- );
606
- expect(url.searchParams.get("token")).toBe("CAPTURED_TOKEN");
607
- const callbackURL = url.searchParams.get("callbackURL") ?? "";
608
- expect(
609
- openContinuation(callbackURL.slice(`${CONTINUE}/`.length), mockSecret),
610
- ).toBe(SIX_KEYS);
611
-
612
- expect(mockEntry).toHaveBeenCalledWith(
613
- { authorization: BASIC, spokeKey: SPOKE_KEY },
614
- {
615
- clientId: "spoke_abc",
616
- redirectUri: CALLBACK,
617
- email: "buyer@example.com",
618
- },
619
- );
620
- const [call] = mockSignInMagicLink.mock.calls[0] as [
621
- { body: Record<string, unknown>; headers: Headers },
622
- ];
623
- expect(call.body).toEqual({
624
- email: "buyer@example.com",
625
- callbackURL,
626
- metadata: { agreements: ["account_terms"], locale: "en" },
627
- });
628
- expect([...call.headers.entries()]).toEqual([["origin", HUB]]);
629
- expect(mockMailSend).not.toHaveBeenCalled();
630
- expect(mockCreateVerificationValue).toHaveBeenCalledWith(
631
- expect.objectContaining({
632
- identifier: `purchase-claim:${createHash("sha256").update(SESSION_ID).digest("hex")}`,
633
- }),
634
- );
635
- });
636
-
637
- it("the same claim again → 410 claim_used, no token", async () => {
638
- mockFindVerificationValue.mockResolvedValue({
639
- value: "1",
640
- expiresAt: new Date(Date.now() + 60_000),
641
- });
642
- const res = await purchasePOST(
643
- purchaseRequest({ ...AUTHORIZE, claim: claimFor() }),
644
- );
645
- expect(res.status).toBe(410);
646
- expect(await res.json()).toEqual({ error: "claim_used" });
647
- expect(mockSignInMagicLink).not.toHaveBeenCalled();
648
- });
649
-
650
- it("SEC-11096-4: an existing address → 409 account_exists, no token, the claim not spent", async () => {
651
- mockFindUserByEmail.mockResolvedValue({ user: { id: "u1" } });
652
- const res = await purchasePOST(
653
- purchaseRequest({ ...AUTHORIZE, claim: claimFor() }),
654
- );
655
- expect(res.status).toBe(409);
656
- expect(await res.json()).toEqual({ error: "account_exists" });
657
- expect(mockSignInMagicLink).not.toHaveBeenCalled();
658
- expect(mockCreateVerificationValue).not.toHaveBeenCalled();
659
- });
660
-
661
- it.each([
662
- ["a claim minted for another client", () => claimFor({ c: "spoke_other" })],
663
- ["an expired claim", () => claimFor({}, Date.now() - 73 * 3600 * 1000)],
664
- ["a hub-continue ref", () => claimFor({}, Date.now(), "hub-continue")],
665
- ])("%s → 410 claim_invalid, no entry call", async (_name, build) => {
666
- const res = await purchasePOST(
667
- purchaseRequest({ ...AUTHORIZE, claim: build() }),
668
- );
669
- expect(res.status).toBe(410);
670
- expect(await res.json()).toEqual({ error: "claim_invalid" });
671
- expect(mockEntry).not.toHaveBeenCalled();
672
- });
673
-
674
- it("SEC-11096-2: evidence bumped to version 2 after a version-1 claim → 410 terms_changed", async () => {
675
- mockSignUpEvidence.mockResolvedValue(
676
- evidence([{ ...ACCOUNT_TERMS, policyVersion: 2 }]),
677
- );
678
- const res = await purchasePOST(
679
- purchaseRequest({ ...AUTHORIZE, claim: claimFor() }),
680
- );
681
- expect(res.status).toBe(410);
682
- expect(await res.json()).toEqual({ error: "terms_changed" });
683
- expect(mockSignInMagicLink).not.toHaveBeenCalled();
684
- });
685
-
686
- it("the API refusing the spoke is passed on, and nothing is spent", async () => {
687
- mockEntry.mockResolvedValue({
688
- ok: false,
689
- status: 401,
690
- body: { ok: false, error: { code: "invalid_client" } },
691
- });
692
- const res = await purchasePOST(
693
- purchaseRequest({ ...AUTHORIZE, claim: claimFor() }),
694
- );
695
- expect(res.status).toBe(401);
696
- expect(mockCreateVerificationValue).not.toHaveBeenCalled();
697
- });
698
-
699
- it("AC-6: an added password field is 400 invalid_request", async () => {
700
- const res = await purchasePOST(
701
- purchaseRequest({ ...AUTHORIZE, claim: claimFor(), password: "x" }),
702
- );
703
- expect(res.status).toBe(400);
704
- expect(mockEntry).not.toHaveBeenCalled();
705
- });
706
-
707
- it("no token captured (Better Auth refused or mailed nothing) → 503, and the claim is not spent", async () => {
708
- mockSignInMagicLink.mockResolvedValue({ status: true });
709
- const res = await purchasePOST(
710
- purchaseRequest({ ...AUTHORIZE, claim: claimFor() }),
711
- );
712
- expect(res.status).toBe(503);
713
- expect(mockDeleteVerificationByIdentifier).toHaveBeenCalledWith(
714
- `purchase-claim:${createHash("sha256").update(SESSION_ID).digest("hex")}`,
715
- );
716
- });
717
-
718
- it("a spend that fails after the claim was marked leaves it spendable: the retry succeeds", async () => {
719
- const rows = new Map<string, { value: string; expiresAt: Date }>();
720
- mockFindVerificationValue.mockImplementation(async (id: string) => rows.get(id) ?? null);
721
- mockCreateVerificationValue.mockImplementation(
722
- async (row: { identifier: string; value: string; expiresAt: Date }) => {
723
- rows.set(row.identifier, row);
724
- return row;
725
- },
726
- );
727
- mockDeleteVerificationByIdentifier.mockImplementation(async (id: string) => {
728
- rows.delete(id);
729
- });
730
- const succeed = mockSignInMagicLink.getMockImplementation();
731
- mockSignInMagicLink.mockRejectedValueOnce(new Error("boom"));
732
-
733
- const failed = await purchasePOST(
734
- purchaseRequest({ ...AUTHORIZE, claim: claimFor() }),
735
- );
736
- expect(failed.status).toBe(503);
737
-
738
- mockSignInMagicLink.mockImplementation(succeed!);
739
- const retried = await purchasePOST(
740
- purchaseRequest({ ...AUTHORIZE, claim: claimFor() }),
741
- );
742
- expect(retried.status).toBe(200);
743
- // And once spent, it stays spent.
744
- const again = await purchasePOST(
745
- purchaseRequest({ ...AUTHORIZE, claim: claimFor() }),
746
- );
747
- expect(again.status).toBe(410);
748
- });
749
- });