create-ailk 0.38.0 → 0.40.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (304) hide show
  1. package/dist/add-route.js +16 -1
  2. package/dist/body-heading.d.ts +2 -1
  3. package/dist/body-heading.js +31 -3
  4. package/dist/derive-architecture.js +3 -1
  5. package/dist/module-architecture.js +0 -3
  6. package/dist/remove-module.js +27 -14
  7. package/dist/routes.d.ts +36 -2
  8. package/dist/routes.js +269 -23
  9. package/dist/site-manifest.js +6 -4
  10. package/dist/site-roster.d.ts +11 -3
  11. package/dist/site-roster.js +48 -22
  12. package/dist/surfaces.d.ts +13 -3
  13. package/dist/surfaces.js +128 -194
  14. package/dist/sync-routes.js +22 -5
  15. package/dist/template-record.js +3 -1
  16. package/dist/topology.d.ts +11 -0
  17. package/dist/topology.js +253 -3
  18. package/package.json +3 -3
  19. package/templates/apps/web/CLAUDE.md +32 -4
  20. package/templates/apps/web/__tests__/__mocks__/next-intl-server.ts +6 -1
  21. package/templates/apps/web/__tests__/__mocks__/next-intl.ts +6 -1
  22. package/templates/apps/web/__tests__/auth/seam.test.ts +34 -0
  23. package/templates/apps/web/account.config.tsx +2 -3
  24. package/templates/apps/web/app/[locale]/(authed)/account/connect/__tests__/page.test.tsx +1 -1
  25. package/templates/apps/web/app/[locale]/(authed)/account/connect/page.tsx +1 -1
  26. package/templates/apps/web/app/[locale]/(authed)/signed-out-gate.generated.tsx +1 -1
  27. package/templates/apps/web/app/[locale]/layout.tsx +2 -2
  28. package/templates/apps/web/auth.config.tsx +107 -0
  29. package/templates/apps/web/auth.ts +2 -1
  30. package/templates/apps/web/i18n/request.ts +13 -2
  31. package/templates/apps/web/jest.config.cjs +10 -0
  32. package/templates/apps/web/lib/__tests__/deck-page.test.ts +9 -0
  33. package/templates/apps/web/lib/__tests__/fixtures/site-topology.ts +3 -0
  34. package/templates/apps/web/lib/__tests__/in-page-magnet-self-request.test.ts +1 -1
  35. package/templates/apps/web/lib/__tests__/in-page-magnet.test.ts +2 -2
  36. package/templates/apps/web/lib/__tests__/pricing-page.test.ts +1 -1
  37. package/templates/apps/web/lib/__tests__/server-api.test.ts +1 -1
  38. package/templates/apps/web/lib/__tests__/structured-data.test.tsx +17 -4
  39. package/templates/apps/web/lib/in-page-magnet.ts +2 -2
  40. package/templates/apps/web/lib/pricing-page.ts +3 -3
  41. package/templates/apps/web/lib/server-api.ts +1 -1
  42. package/templates/apps/web/{app/[locale]/contact → lib}/site-contact-email.ts +1 -1
  43. package/templates/apps/web/{app/[locale]/contact → lib}/site-contact-lines.ts +1 -1
  44. package/templates/apps/web/lib/site-header.ts +1 -1
  45. package/templates/apps/web/lib/topology.generated.ts +5 -0
  46. package/templates/apps/web/messages/en.json +0 -271
  47. package/templates/apps/web/middleware.ts +12 -25
  48. package/templates/apps/web/next.config.mjs +15 -0
  49. package/templates/apps/web/package.json +2 -0
  50. package/templates/apps/web/site-pages.config.tsx +85 -0
  51. package/templates/apps/web/types/messages.d.ts +6 -1
  52. package/templates/tools/body-heading.ts +30 -3
  53. package/versions.json +50 -48
  54. package/templates/apps/web/app/[locale]/(auth)/__tests__/auth-pages.test.tsx +0 -322
  55. package/templates/apps/web/app/[locale]/(auth)/__tests__/password-reset.test.tsx +0 -554
  56. package/templates/apps/web/app/[locale]/(auth)/consent/__tests__/consent-actions.test.ts +0 -56
  57. package/templates/apps/web/app/[locale]/(auth)/consent/__tests__/page.test.tsx +0 -164
  58. package/templates/apps/web/app/[locale]/(auth)/consent/consent-form.tsx +0 -132
  59. package/templates/apps/web/app/[locale]/(auth)/consent/consent.actions.ts +0 -51
  60. package/templates/apps/web/app/[locale]/(auth)/consent/page.tsx +0 -144
  61. package/templates/apps/web/app/[locale]/(auth)/forgot-password/forgot-password-card.tsx +0 -101
  62. package/templates/apps/web/app/[locale]/(auth)/forgot-password/page.tsx +0 -111
  63. package/templates/apps/web/app/[locale]/(auth)/layout.tsx +0 -81
  64. package/templates/apps/web/app/[locale]/(auth)/legal-footnote.tsx +0 -35
  65. package/templates/apps/web/app/[locale]/(auth)/reset-password/__tests__/return.test.tsx +0 -179
  66. package/templates/apps/web/app/[locale]/(auth)/reset-password/page.tsx +0 -157
  67. package/templates/apps/web/app/[locale]/(auth)/reset-password/reset-password-card.tsx +0 -126
  68. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/next-path.test.ts +0 -54
  69. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/page.test.tsx +0 -628
  70. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/remembered-method.test.ts +0 -43
  71. package/templates/apps/web/app/[locale]/(auth)/sign-in/__tests__/sign-in-card.test.tsx +0 -266
  72. package/templates/apps/web/app/[locale]/(auth)/sign-in/next-path.ts +0 -20
  73. package/templates/apps/web/app/[locale]/(auth)/sign-in/page.tsx +0 -234
  74. package/templates/apps/web/app/[locale]/(auth)/sign-in/remembered-method.ts +0 -37
  75. package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-card.tsx +0 -323
  76. package/templates/apps/web/app/[locale]/(auth)/sign-in/sign-in-text.ts +0 -93
  77. package/templates/apps/web/app/[locale]/(auth)/sign-up/__tests__/page.test.tsx +0 -301
  78. package/templates/apps/web/app/[locale]/(auth)/sign-up/__tests__/sign-up-card.test.tsx +0 -309
  79. package/templates/apps/web/app/[locale]/(auth)/sign-up/page.tsx +0 -201
  80. package/templates/apps/web/app/[locale]/(auth)/sign-up/sign-up-card.tsx +0 -366
  81. package/templates/apps/web/app/[locale]/(auth)/use-auth-card-flow.ts +0 -116
  82. package/templates/apps/web/app/[locale]/(auth)/verify-email/__tests__/actions.test.ts +0 -94
  83. package/templates/apps/web/app/[locale]/(auth)/verify-email/actions.ts +0 -77
  84. package/templates/apps/web/app/[locale]/(auth)/verify-email/page.tsx +0 -154
  85. package/templates/apps/web/app/[locale]/(authed)/account/appointments/[slug]/page.tsx +0 -3
  86. package/templates/apps/web/app/[locale]/(authed)/account/appointments/page.tsx +0 -3
  87. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/page.tsx +0 -3
  88. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/versions/[version]/file/route.ts +0 -2
  89. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/page.tsx +0 -3
  90. package/templates/apps/web/app/[locale]/(authed)/account/billing/page.tsx +0 -12
  91. package/templates/apps/web/app/[locale]/(authed)/account/general/page.tsx +0 -12
  92. package/templates/apps/web/app/[locale]/(authed)/account/inbox/[kind]/[id]/page.tsx +0 -12
  93. package/templates/apps/web/app/[locale]/(authed)/account/inbox/message/[id]/file/route.ts +0 -2
  94. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/page.tsx +0 -12
  95. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/page.tsx +0 -3
  96. package/templates/apps/web/app/[locale]/(authed)/account/layout.tsx +0 -10
  97. package/templates/apps/web/app/[locale]/(authed)/account/notifications/page.tsx +0 -3
  98. package/templates/apps/web/app/[locale]/(authed)/account/onboarding/page.tsx +0 -3
  99. package/templates/apps/web/app/[locale]/(authed)/account/page.tsx +0 -12
  100. package/templates/apps/web/app/[locale]/(authed)/account/privacy/export/route.ts +0 -2
  101. package/templates/apps/web/app/[locale]/(authed)/account/privacy/page.tsx +0 -3
  102. package/templates/apps/web/app/[locale]/(authed)/account/security/page.tsx +0 -3
  103. package/templates/apps/web/app/[locale]/(authed)/account/settings/page.tsx +0 -2
  104. package/templates/apps/web/app/[locale]/(authed)/account/support/page.tsx +0 -3
  105. package/templates/apps/web/app/[locale]/(authed)/leads/__tests__/page.test.tsx +0 -205
  106. package/templates/apps/web/app/[locale]/(authed)/leads/components/LeadsTable.tsx +0 -137
  107. package/templates/apps/web/app/[locale]/(authed)/leads/page.tsx +0 -122
  108. package/templates/apps/web/app/[locale]/(authed)/waitlist/components/ForbiddenState.tsx +0 -24
  109. package/templates/apps/web/app/[locale]/(authed)/waitlist/format.ts +0 -111
  110. package/templates/apps/web/app/[locale]/[slug]/[detail]/__tests__/page.test.tsx +0 -402
  111. package/templates/apps/web/app/[locale]/[slug]/[detail]/page.tsx +0 -143
  112. package/templates/apps/web/app/[locale]/[slug]/__tests__/page.test.tsx +0 -148
  113. package/templates/apps/web/app/[locale]/[slug]/page.tsx +0 -109
  114. package/templates/apps/web/app/[locale]/about/[slug]/page.tsx +0 -46
  115. package/templates/apps/web/app/[locale]/about/__tests__/about-routes.test.tsx +0 -353
  116. package/templates/apps/web/app/[locale]/about/page.tsx +0 -122
  117. package/templates/apps/web/app/[locale]/alternatives/__tests__/page.test.tsx +0 -161
  118. package/templates/apps/web/app/[locale]/alternatives/page.tsx +0 -112
  119. package/templates/apps/web/app/[locale]/careers/[slug]/[action]/page.tsx +0 -244
  120. package/templates/apps/web/app/[locale]/careers/[slug]/apply.actions.ts +0 -325
  121. package/templates/apps/web/app/[locale]/careers/[slug]/job-application-form.ts +0 -120
  122. package/templates/apps/web/app/[locale]/careers/[slug]/page.tsx +0 -73
  123. package/templates/apps/web/app/[locale]/careers/__tests__/apply.actions.test.ts +0 -497
  124. package/templates/apps/web/app/[locale]/careers/__tests__/careers-hub.test.tsx +0 -172
  125. package/templates/apps/web/app/[locale]/careers/__tests__/careers-set.test.tsx +0 -153
  126. package/templates/apps/web/app/[locale]/careers/__tests__/job-application-form.test.ts +0 -141
  127. package/templates/apps/web/app/[locale]/careers/__tests__/job-apply-page.test.tsx +0 -546
  128. package/templates/apps/web/app/[locale]/careers/__tests__/page-renderer-migration.test.tsx +0 -189
  129. package/templates/apps/web/app/[locale]/careers/page.tsx +0 -165
  130. package/templates/apps/web/app/[locale]/case-studies/[slug]/page.tsx +0 -49
  131. package/templates/apps/web/app/[locale]/case-studies/__tests__/hub-children.test.tsx +0 -65
  132. package/templates/apps/web/app/[locale]/case-studies/__tests__/page-renderer-migration.test.tsx +0 -125
  133. package/templates/apps/web/app/[locale]/case-studies/page.tsx +0 -49
  134. package/templates/apps/web/app/[locale]/clients/__tests__/page-renderer-migration.test.tsx +0 -85
  135. package/templates/apps/web/app/[locale]/clients/page.tsx +0 -47
  136. package/templates/apps/web/app/[locale]/contact/ConversationalIntakeWrapper.tsx +0 -249
  137. package/templates/apps/web/app/[locale]/contact/__tests__/ConversationalIntakeWrapper.test.tsx +0 -400
  138. package/templates/apps/web/app/[locale]/contact/__tests__/contact-form-magnet.test.ts +0 -138
  139. package/templates/apps/web/app/[locale]/contact/__tests__/contact-form-text.test.ts +0 -49
  140. package/templates/apps/web/app/[locale]/contact/__tests__/contact-magnet-page.test.tsx +0 -494
  141. package/templates/apps/web/app/[locale]/contact/__tests__/contact.actions.test.ts +0 -1122
  142. package/templates/apps/web/app/[locale]/contact/__tests__/intake-analytics.test.ts +0 -51
  143. package/templates/apps/web/app/[locale]/contact/__tests__/page-renderer-migration.test.tsx +0 -319
  144. package/templates/apps/web/app/[locale]/contact/contact-form-magnet.ts +0 -77
  145. package/templates/apps/web/app/[locale]/contact/contact-form-text.ts +0 -52
  146. package/templates/apps/web/app/[locale]/contact/contact.actions.ts +0 -403
  147. package/templates/apps/web/app/[locale]/contact/intake-analytics.ts +0 -49
  148. package/templates/apps/web/app/[locale]/contact/intake-script.ts +0 -92
  149. package/templates/apps/web/app/[locale]/contact/page.tsx +0 -267
  150. package/templates/apps/web/app/[locale]/courses/[slug]/page.tsx +0 -50
  151. package/templates/apps/web/app/[locale]/courses/__tests__/hub-children.test.tsx +0 -32
  152. package/templates/apps/web/app/[locale]/courses/__tests__/page-renderer-migration.test.tsx +0 -123
  153. package/templates/apps/web/app/[locale]/courses/page.tsx +0 -49
  154. package/templates/apps/web/app/[locale]/events/[slug]/page.tsx +0 -57
  155. package/templates/apps/web/app/[locale]/events/__tests__/hub-children.test.tsx +0 -32
  156. package/templates/apps/web/app/[locale]/events/__tests__/page-renderer-migration.test.tsx +0 -164
  157. package/templates/apps/web/app/[locale]/events/__tests__/program-event.test.tsx +0 -120
  158. package/templates/apps/web/app/[locale]/events/page.tsx +0 -60
  159. package/templates/apps/web/app/[locale]/faq/page.tsx +0 -54
  160. package/templates/apps/web/app/[locale]/features/[slug]/page.tsx +0 -54
  161. package/templates/apps/web/app/[locale]/features/__tests__/hub-children.test.tsx +0 -32
  162. package/templates/apps/web/app/[locale]/features/page.tsx +0 -50
  163. package/templates/apps/web/app/[locale]/for/[slug]/page.tsx +0 -54
  164. package/templates/apps/web/app/[locale]/for/__tests__/hub-children.test.tsx +0 -32
  165. package/templates/apps/web/app/[locale]/for/__tests__/page-renderer-migration.test.tsx +0 -90
  166. package/templates/apps/web/app/[locale]/for/page.tsx +0 -51
  167. package/templates/apps/web/app/[locale]/glossary/page.tsx +0 -53
  168. package/templates/apps/web/app/[locale]/how-to/[slug]/page.tsx +0 -50
  169. package/templates/apps/web/app/[locale]/how-to/__tests__/page-renderer-migration.test.tsx +0 -78
  170. package/templates/apps/web/app/[locale]/how-to/page.tsx +0 -50
  171. package/templates/apps/web/app/[locale]/integrations/[slug]/page.tsx +0 -54
  172. package/templates/apps/web/app/[locale]/integrations/__tests__/hub-children.test.tsx +0 -38
  173. package/templates/apps/web/app/[locale]/integrations/__tests__/page-renderer-migration.test.tsx +0 -141
  174. package/templates/apps/web/app/[locale]/integrations/page.tsx +0 -49
  175. package/templates/apps/web/app/[locale]/launch-service/page.tsx +0 -44
  176. package/templates/apps/web/app/[locale]/newsletter/__tests__/page.test.tsx +0 -236
  177. package/templates/apps/web/app/[locale]/newsletter/page.tsx +0 -179
  178. package/templates/apps/web/app/[locale]/page.tsx +0 -147
  179. package/templates/apps/web/app/[locale]/partners/[slug]/page.tsx +0 -45
  180. package/templates/apps/web/app/[locale]/partners/__tests__/hub-children.test.tsx +0 -32
  181. package/templates/apps/web/app/[locale]/partners/__tests__/page-renderer-migration.test.tsx +0 -125
  182. package/templates/apps/web/app/[locale]/partners/page.tsx +0 -49
  183. package/templates/apps/web/app/[locale]/portfolio/[slug]/page.tsx +0 -46
  184. package/templates/apps/web/app/[locale]/portfolio/__tests__/hub-children.test.tsx +0 -38
  185. package/templates/apps/web/app/[locale]/portfolio/page.tsx +0 -50
  186. package/templates/apps/web/app/[locale]/pricing/[slug]/__tests__/page.test.tsx +0 -324
  187. package/templates/apps/web/app/[locale]/pricing/[slug]/page.tsx +0 -87
  188. package/templates/apps/web/app/[locale]/pricing/__tests__/__snapshots__/unconnected.test.tsx.snap +0 -7
  189. package/templates/apps/web/app/[locale]/pricing/__tests__/offerings.test.tsx +0 -605
  190. package/templates/apps/web/app/[locale]/pricing/__tests__/page.test.tsx +0 -219
  191. package/templates/apps/web/app/[locale]/pricing/__tests__/pricing-pages.test.tsx +0 -215
  192. package/templates/apps/web/app/[locale]/pricing/__tests__/unconnected.test.tsx +0 -282
  193. package/templates/apps/web/app/[locale]/pricing/page.tsx +0 -120
  194. package/templates/apps/web/app/[locale]/privacy/page.tsx +0 -40
  195. package/templates/apps/web/app/[locale]/products/[slug]/page.tsx +0 -50
  196. package/templates/apps/web/app/[locale]/products/__tests__/hub-children.test.tsx +0 -32
  197. package/templates/apps/web/app/[locale]/products/__tests__/page-renderer-migration.test.tsx +0 -141
  198. package/templates/apps/web/app/[locale]/products/page.tsx +0 -49
  199. package/templates/apps/web/app/[locale]/projects/[slug]/page.tsx +0 -37
  200. package/templates/apps/web/app/[locale]/projects/__tests__/hub-children.test.tsx +0 -32
  201. package/templates/apps/web/app/[locale]/projects/__tests__/page-renderer-migration.test.tsx +0 -157
  202. package/templates/apps/web/app/[locale]/projects/page.tsx +0 -49
  203. package/templates/apps/web/app/[locale]/purchase-policy/page.tsx +0 -49
  204. package/templates/apps/web/app/[locale]/resources/[slug]/page.tsx +0 -54
  205. package/templates/apps/web/app/[locale]/resources/__tests__/hub-children.test.tsx +0 -38
  206. package/templates/apps/web/app/[locale]/resources/__tests__/page-renderer-migration.test.tsx +0 -151
  207. package/templates/apps/web/app/[locale]/resources/page.tsx +0 -49
  208. package/templates/apps/web/app/[locale]/services/[slug]/[child]/page.tsx +0 -68
  209. package/templates/apps/web/app/[locale]/services/[slug]/page.tsx +0 -88
  210. package/templates/apps/web/app/[locale]/services/__tests__/hub-children.test.tsx +0 -158
  211. package/templates/apps/web/app/[locale]/services/__tests__/page-renderer-migration.test.tsx +0 -187
  212. package/templates/apps/web/app/[locale]/services/__tests__/service-detail-sections.test.tsx +0 -224
  213. package/templates/apps/web/app/[locale]/services/__tests__/service-families.test.tsx +0 -368
  214. package/templates/apps/web/app/[locale]/services/page.tsx +0 -71
  215. package/templates/apps/web/app/[locale]/software/[slug]/page.tsx +0 -49
  216. package/templates/apps/web/app/[locale]/software/__tests__/page-renderer-migration.test.tsx +0 -81
  217. package/templates/apps/web/app/[locale]/software/page.tsx +0 -49
  218. package/templates/apps/web/app/[locale]/team/[slug]/page.tsx +0 -45
  219. package/templates/apps/web/app/[locale]/team/__tests__/hub-children.test.tsx +0 -32
  220. package/templates/apps/web/app/[locale]/team/__tests__/team-routes.test.tsx +0 -161
  221. package/templates/apps/web/app/[locale]/team/page.tsx +0 -50
  222. package/templates/apps/web/app/[locale]/tech-articles/[slug]/page.tsx +0 -54
  223. package/templates/apps/web/app/[locale]/tech-articles/__tests__/page-renderer-migration.test.tsx +0 -82
  224. package/templates/apps/web/app/[locale]/tech-articles/page.tsx +0 -49
  225. package/templates/apps/web/app/[locale]/templates/[slug]/__tests__/page.test.tsx +0 -203
  226. package/templates/apps/web/app/[locale]/templates/[slug]/page.tsx +0 -81
  227. package/templates/apps/web/app/[locale]/templates/__tests__/page.test.tsx +0 -237
  228. package/templates/apps/web/app/[locale]/templates/page.tsx +0 -114
  229. package/templates/apps/web/app/[locale]/terms/page.tsx +0 -40
  230. package/templates/apps/web/app/[locale]/testimonials/__tests__/page-renderer-migration.test.tsx +0 -85
  231. package/templates/apps/web/app/[locale]/testimonials/page.tsx +0 -51
  232. package/templates/apps/web/app/[locale]/thanks/[slug]/__tests__/page.test.tsx +0 -136
  233. package/templates/apps/web/app/[locale]/thanks/[slug]/page.tsx +0 -39
  234. package/templates/apps/web/app/[locale]/unsubscribe/__tests__/unsubscribe-rsc-boundary.test.tsx +0 -226
  235. package/templates/apps/web/app/[locale]/unsubscribe/__tests__/unsubscribe.test.tsx +0 -217
  236. package/templates/apps/web/app/[locale]/unsubscribe/page.tsx +0 -106
  237. package/templates/apps/web/app/[locale]/unsubscribe/unsubscribe-button.tsx +0 -94
  238. package/templates/apps/web/app/[locale]/unsubscribe/unsubscribe.actions.ts +0 -55
  239. package/templates/apps/web/app/[locale]/vs/[slug]/__tests__/page.test.tsx +0 -100
  240. package/templates/apps/web/app/[locale]/vs/[slug]/page.tsx +0 -60
  241. package/templates/apps/web/app/[locale]/whitepapers/[slug]/page.tsx +0 -54
  242. package/templates/apps/web/app/[locale]/whitepapers/__tests__/page-renderer-migration.test.tsx +0 -82
  243. package/templates/apps/web/app/[locale]/whitepapers/page.tsx +0 -49
  244. package/templates/apps/web/app/[locale]/working-agreement/__tests__/page.test.tsx +0 -63
  245. package/templates/apps/web/app/[locale]/working-agreement/page.tsx +0 -41
  246. package/templates/apps/web/app/api/auth/[...all]/route.ts +0 -16
  247. package/templates/apps/web/app/api/auth/hub/__tests__/continuation.test.ts +0 -143
  248. package/templates/apps/web/app/api/auth/hub/__tests__/entry-routes.test.ts +0 -749
  249. package/templates/apps/web/app/api/auth/hub/authorize/__tests__/route.test.ts +0 -964
  250. package/templates/apps/web/app/api/auth/hub/authorize/route.ts +0 -390
  251. package/templates/apps/web/app/api/auth/hub/continuation.ts +0 -127
  252. package/templates/apps/web/app/api/auth/hub/continue/[ref]/__tests__/route.test.ts +0 -188
  253. package/templates/apps/web/app/api/auth/hub/continue/[ref]/route.ts +0 -53
  254. package/templates/apps/web/app/api/auth/hub/email/route.ts +0 -111
  255. package/templates/apps/web/app/api/auth/hub/entry-shared.ts +0 -163
  256. package/templates/apps/web/app/api/auth/hub/password/__tests__/return.test.ts +0 -86
  257. package/templates/apps/web/app/api/auth/hub/password/__tests__/route.test.ts +0 -368
  258. package/templates/apps/web/app/api/auth/hub/password/return.ts +0 -86
  259. package/templates/apps/web/app/api/auth/hub/password/route.ts +0 -171
  260. package/templates/apps/web/app/api/auth/hub/purchase/route.ts +0 -230
  261. package/templates/apps/web/app/api/auth/hub/purchase-link/route.ts +0 -174
  262. package/templates/apps/web/app/api/auth/hub/sign-up/route.ts +0 -60
  263. package/templates/apps/web/app/api/auth/hub/sign-up-evidence.ts +0 -97
  264. package/templates/apps/web/app/api/auth/mcp/__tests__/continuation.test.ts +0 -92
  265. package/templates/apps/web/app/api/auth/mcp/continuation.ts +0 -89
  266. package/templates/apps/web/app/api/auth/mcp/continue/[ref]/__tests__/route.test.ts +0 -59
  267. package/templates/apps/web/app/api/auth/mcp/continue/[ref]/route.ts +0 -41
  268. package/templates/apps/web/app/api/hub-session/__tests__/routes.test.ts +0 -1166
  269. package/templates/apps/web/app/api/hub-session/callback/route.ts +0 -134
  270. package/templates/apps/web/app/api/hub-session/email/route.ts +0 -125
  271. package/templates/apps/web/app/api/hub-session/one-tap/nonce/route.ts +0 -49
  272. package/templates/apps/web/app/api/hub-session/one-tap/route.ts +0 -106
  273. package/templates/apps/web/app/api/hub-session/open/route.ts +0 -111
  274. package/templates/apps/web/app/api/hub-session/password/return/route.ts +0 -69
  275. package/templates/apps/web/app/api/hub-session/password/route.ts +0 -106
  276. package/templates/apps/web/app/api/hub-session/sign-in/route.ts +0 -91
  277. package/templates/apps/web/app/api/hub-session/sign-out/route.ts +0 -54
  278. package/templates/apps/web/components/sign-out-trigger.tsx +0 -62
  279. package/templates/apps/web/lib/__tests__/auth-routes.test.ts +0 -140
  280. package/templates/apps/web/lib/__tests__/hub-children.fixtures.ts +0 -279
  281. package/templates/apps/web/lib/__tests__/route-family.test.ts +0 -57
  282. package/templates/apps/web/lib/__tests__/service-listing.test.ts +0 -111
  283. package/templates/apps/web/lib/__tests__/template-listing.test.ts +0 -158
  284. package/templates/apps/web/lib/auth-routes.ts +0 -125
  285. package/templates/apps/web/lib/hub-children.tsx +0 -351
  286. package/templates/apps/web/lib/hub-session/__tests__/hub-session.test.ts +0 -433
  287. package/templates/apps/web/lib/hub-session/__tests__/spoke-sign-in.test.tsx +0 -332
  288. package/templates/apps/web/lib/hub-session/config.ts +0 -110
  289. package/templates/apps/web/lib/hub-session/entry.ts +0 -238
  290. package/templates/apps/web/lib/hub-session/index.ts +0 -21
  291. package/templates/apps/web/lib/hub-session/one-tap.tsx +0 -148
  292. package/templates/apps/web/lib/hub-session/reseal.ts +0 -90
  293. package/templates/apps/web/lib/hub-session/seal.ts +0 -86
  294. package/templates/apps/web/lib/hub-session/session.ts +0 -298
  295. package/templates/apps/web/lib/hub-session/spoke-sign-in.tsx +0 -277
  296. package/templates/apps/web/lib/meet-placeholder.ts +0 -5
  297. package/templates/apps/web/lib/next-path.ts +0 -35
  298. package/templates/apps/web/lib/posting-title.ts +0 -39
  299. package/templates/apps/web/lib/route-family.ts +0 -69
  300. package/templates/apps/web/lib/service-listing.ts +0 -89
  301. package/templates/apps/web/lib/template-listing.ts +0 -169
  302. package/templates/apps/web/src/lib/__tests__/lead-write.test.ts +0 -187
  303. package/templates/apps/web/src/lib/lead-write.ts +0 -90
  304. /package/templates/apps/web/{app/[locale]/contact → lib}/__tests__/site-contact-lines.test.ts +0 -0
@@ -1,205 +0,0 @@
1
- /**
2
- * Tests for the signed-in owner's lead inbox (#5678 Deliverable 2).
3
- *
4
- * Covers:
5
- * 1. Renders one row per lead, with a `null` name shown as the
6
- * "unavailable" sentinel rather than blank.
7
- * 2. Renders the forward-only "next" link when `nextCursor` is present, and
8
- * omits it when it is `null`.
9
- * 3. Forwards `?cursor=` from `searchParams` to the api-client call.
10
- * 4. Renders an EmptyState — not a headerless table — for an empty page.
11
- * 5. Renders ForbiddenState on a 401/403; falls back to the first page
12
- * when a supplied `?cursor=` 400s; rethrows every other error.
13
- * 6. With no session, renders ForbiddenState and makes no apps/api request
14
- * — the (authed) layout's gate renders concurrently, so the page must
15
- * not spend (or fail) an API call on a visitor it will never serve
16
- * (#6865).
17
- */
18
- import { render, screen } from "@testing-library/react";
19
-
20
- jest.mock("next-intl/server", () => ({
21
- __esModule: true,
22
- getTranslations: jest.fn().mockImplementation(async () => (key: string, values?: Record<string, unknown>) =>
23
- values ? `copy:${key}:${JSON.stringify(values)}` : `copy:${key}`,
24
- ),
25
- }));
26
-
27
- jest.mock("next/headers", () => ({
28
- __esModule: true,
29
- headers: jest.fn().mockResolvedValue(new Headers()),
30
- cookies: jest.fn().mockResolvedValue({ toString: () => "session=abc" }),
31
- }));
32
-
33
- const mockGetSession = jest.fn();
34
- // eslint-disable-next-line no-restricted-syntax -- #507: mock-internal rewrite pending; auth.ts's lazy Better-Auth singleton has no HTTP/DB boundary a unit test can mock without standing up Prisma.
35
- jest.mock("../../../../../auth", () => ({
36
- __esModule: true,
37
- auth: { api: { getSession: (...args: unknown[]) => mockGetSession(...args) } },
38
- }));
39
-
40
- const mockList = jest.fn();
41
- jest.mock("@working-theory/api-client", () => ({
42
- __esModule: true,
43
- leads: { list: (...args: unknown[]) => mockList(...args) },
44
- }));
45
-
46
- import Page from "../page";
47
-
48
- const FIXTURE_PAGE = {
49
- items: [
50
- {
51
- id: "lead_1",
52
- name: "Ada Lovelace",
53
- email: "ada@example.com",
54
- source: "web",
55
- createdAt: "2026-09-01T10:00:00.000Z",
56
- },
57
- {
58
- id: "lead_2",
59
- name: null,
60
- email: "anon@example.com",
61
- source: "conversational-intake",
62
- createdAt: "2026-08-31T09:00:00.000Z",
63
- },
64
- ],
65
- nextCursor: null as string | null,
66
- };
67
-
68
- function renderPage(cursor?: string) {
69
- return Page({
70
- params: Promise.resolve({ locale: "en" }),
71
- searchParams: Promise.resolve(cursor ? { cursor } : {}),
72
- });
73
- }
74
-
75
- describe("LeadsInboxPage", () => {
76
- beforeEach(() => {
77
- mockList.mockReset();
78
- mockGetSession.mockReset();
79
- mockGetSession.mockResolvedValue({ user: { id: "user_1" } });
80
- });
81
-
82
- // #6865: the (authed) layout renders SignInGate to an anonymous visitor,
83
- // but Next renders this page concurrently — it must not call apps/api.
84
- it("makes no apps/api request and renders ForbiddenState with no session", async () => {
85
- mockGetSession.mockResolvedValue(null);
86
- render(await renderPage("lead_9"));
87
-
88
- expect(mockList).not.toHaveBeenCalled();
89
- expect(screen.getByTestId("waitlist-forbidden")).toBeInTheDocument();
90
- expect(screen.queryByTestId("leads-inbox-page")).not.toBeInTheDocument();
91
- });
92
-
93
- it("renders one row per lead, with email and source", async () => {
94
- mockList.mockResolvedValue({ ok: true, body: FIXTURE_PAGE });
95
- render(await renderPage());
96
-
97
- expect(screen.getByTestId("leads-inbox-page")).toBeInTheDocument();
98
- const first = screen.getByTestId("leads-table-row-lead_1");
99
- expect(first).toHaveTextContent("Ada Lovelace");
100
- expect(first).toHaveTextContent("ada@example.com");
101
- expect(first).toHaveTextContent("web");
102
- expect(screen.getByTestId("leads-table-row-lead_2")).toHaveTextContent(
103
- "conversational-intake",
104
- );
105
- expect(screen.getAllByTestId(/^leads-table-row-/)).toHaveLength(2);
106
- });
107
-
108
- it("renders a null name as the unavailable sentinel", async () => {
109
- mockList.mockResolvedValue({ ok: true, body: FIXTURE_PAGE });
110
- render(await renderPage());
111
-
112
- expect(screen.getByTestId("leads-table-row-lead_2")).toHaveTextContent(
113
- "copy:table.unavailable",
114
- );
115
- });
116
-
117
- it("omits the next link when nextCursor is null", async () => {
118
- mockList.mockResolvedValue({ ok: true, body: FIXTURE_PAGE });
119
- render(await renderPage());
120
-
121
- expect(screen.queryByTestId("leads-table-next")).not.toBeInTheDocument();
122
- });
123
-
124
- it("renders the next link pointing at the next cursor", async () => {
125
- mockList.mockResolvedValue({
126
- ok: true,
127
- body: { ...FIXTURE_PAGE, nextCursor: "lead_2" },
128
- });
129
- render(await renderPage());
130
-
131
- const next = screen.getByTestId("leads-table-next");
132
- expect(next).toBeInTheDocument();
133
- expect(next).toHaveAttribute("href", "/en/leads?cursor=lead_2");
134
- });
135
-
136
- it("forwards ?cursor= to the api-client call", async () => {
137
- mockList.mockResolvedValue({ ok: true, body: FIXTURE_PAGE });
138
- render(await renderPage("lead_9"));
139
-
140
- expect(mockList).toHaveBeenCalledWith(
141
- { cursor: "lead_9" },
142
- expect.objectContaining({ headers: expect.objectContaining({ cookie: "session=abc" }) }),
143
- );
144
- });
145
-
146
- it("renders an EmptyState when the owner has no leads", async () => {
147
- mockList.mockResolvedValue({ ok: true, body: { items: [], nextCursor: null } });
148
- render(await renderPage());
149
-
150
- expect(screen.getByTestId("leads-table-empty")).toBeInTheDocument();
151
- expect(screen.queryByTestId("leads-table")).not.toBeInTheDocument();
152
- });
153
-
154
- it("renders ForbiddenState on a 401 rather than throwing", async () => {
155
- mockList.mockResolvedValue({
156
- ok: false,
157
- status: 401,
158
- body: { error: { code: "unauthorized", message: "Unauthorized" } },
159
- });
160
- render(await renderPage());
161
-
162
- expect(screen.getByTestId("waitlist-forbidden")).toBeInTheDocument();
163
- });
164
-
165
- it("rethrows a non-401/403 error", async () => {
166
- mockList.mockResolvedValue({
167
- ok: false,
168
- status: 500,
169
- body: { error: { code: "internal_error", message: "Boom" } },
170
- });
171
- await expect(renderPage()).rejects.toThrow();
172
- });
173
-
174
- // PR #5705 security review, finding 3.
175
- it("falls back to the first page when a supplied ?cursor= 400s", async () => {
176
- mockList
177
- .mockResolvedValueOnce({
178
- ok: false,
179
- status: 400,
180
- body: {
181
- error: {
182
- code: "validation_failed",
183
- message: "cursor does not resolve within this scope",
184
- },
185
- },
186
- })
187
- .mockResolvedValueOnce({ ok: true, body: FIXTURE_PAGE });
188
-
189
- render(await renderPage("lead_gone"));
190
-
191
- expect(screen.getByTestId("leads-table")).toBeInTheDocument();
192
- expect(mockList).toHaveBeenNthCalledWith(1, { cursor: "lead_gone" }, expect.anything());
193
- expect(mockList).toHaveBeenNthCalledWith(2, {}, expect.anything());
194
- });
195
-
196
- it("rethrows a 400 on the FIRST page — there is no cursor to blame", async () => {
197
- mockList.mockResolvedValue({
198
- ok: false,
199
- status: 400,
200
- body: { error: { code: "validation_failed", message: "Invalid query parameters" } },
201
- });
202
- await expect(renderPage()).rejects.toThrow();
203
- expect(mockList).toHaveBeenCalledTimes(1);
204
- });
205
- });
@@ -1,137 +0,0 @@
1
- /**
2
- * LeadsTable — the lead inbox's paginated table (#5678 Deliverable 2).
3
- *
4
- * App-local composition: `Table` primitive + `EmptyState` when there are no
5
- * rows + a single forward-only "next page" link. Every string is
6
- * caller-supplied (translatable) and every value arrives pre-formatted — this
7
- * component formats nothing itself (Rule 10: formatting happens in the page,
8
- * via `../../waitlist/format.js`).
9
- *
10
- * Deliberately NOT an import of the structurally identical
11
- * `../../waitlist/components/SignupsTable.tsx`, despite sharing its shape:
12
- * that file is an `ownedFiles` entry of a PAID module slice
13
- * (`packages/create-ailk/src/module-architecture.ts` — the
14
- * `apps/web/app/[locale]/(authed)/waitlist/**` block, which belongs to the
15
- * `multi-tenant` slice, not `signal-collectors` as the card's brief had it;
16
- * verified at HEAD, the `SignupsTable.tsx` entry is on line 1035 inside
17
- * `MODULE_SLICES["multi-tenant"].ownedFiles`). A scaffold built without that
18
- * module has no such file. Lead capture — and therefore this inbox — ships at
19
- * every level including Free, so importing it would make a base-tier page
20
- * depend on a file the strip removes. The pattern is reused; the file is not.
21
- *
22
- * `EmptyState`-when-empty follows `ExperimentsTable`'s idiom rather than
23
- * `SignupsTable`'s (which always renders a table): a headerless table is not
24
- * an acceptable empty state for a page whose whole body is this one table.
25
- *
26
- * `ForbiddenState` and `format.ts`, by contrast, are safe to import: both are
27
- * deliberately EXCLUDED from that same `ownedFiles` list (see the module
28
- * file's own ESCALATION comment above the list — they are shared with the
29
- * Free `(authed)/account` page, which already imports both), so both survive
30
- * in a build without the paid slice.
31
- */
32
-
33
- import type { LeadInboxRow } from "@working-theory/api-client";
34
- import {
35
- EmptyState,
36
- Link,
37
- Table,
38
- TableBody,
39
- TableCaption,
40
- TableCell,
41
- TableHead,
42
- TableHeader,
43
- TableRow,
44
- } from "@working-theory/ui/primitives";
45
- import type { ReactElement } from "react";
46
-
47
- export interface LeadsTableLabels {
48
- caption: string;
49
- columnName: string;
50
- columnEmail: string;
51
- columnSource: string;
52
- columnCreated: string;
53
- unavailable: string;
54
- next: string;
55
- emptyHeadline: string;
56
- emptyDescription: string;
57
- }
58
-
59
- export interface LeadsTableProps {
60
- locale: string;
61
- /**
62
- * `created` is pre-formatted by the caller (Rule 10 — this component never
63
- * formats a value itself). `lead.name` is `null` when the capture form took
64
- * no name; it renders `labels.unavailable`, the same sentinel handling the
65
- * caller's own `format.ts` uses elsewhere on the authed surface.
66
- *
67
- * There is no page/URL column: the `Lead` record persists no page or
68
- * referrer field, so `source` is the only capture-origin signal.
69
- */
70
- rows: Array<{
71
- lead: LeadInboxRow;
72
- created: string;
73
- }>;
74
- nextCursor: string | null;
75
- labels: LeadsTableLabels;
76
- }
77
-
78
- function buildNextHref(locale: string, nextCursor: string): string {
79
- const params = new URLSearchParams();
80
- params.set("cursor", nextCursor);
81
- return `/${locale}/leads?${params.toString()}`;
82
- }
83
-
84
- export function LeadsTable({
85
- locale,
86
- rows,
87
- nextCursor,
88
- labels,
89
- }: LeadsTableProps): ReactElement {
90
- if (rows.length === 0) {
91
- return (
92
- <div data-testid="leads-table-empty">
93
- <EmptyState headline={labels.emptyHeadline} description={labels.emptyDescription} />
94
- </div>
95
- );
96
- }
97
-
98
- return (
99
- <div data-testid="leads-table-wrapper">
100
- <Table data-testid="leads-table">
101
- <TableCaption>{labels.caption}</TableCaption>
102
- <TableHeader>
103
- <TableRow>
104
- <TableHead scope="col">{labels.columnName}</TableHead>
105
- <TableHead scope="col">{labels.columnEmail}</TableHead>
106
- <TableHead scope="col">{labels.columnSource}</TableHead>
107
- <TableHead scope="col">{labels.columnCreated}</TableHead>
108
- </TableRow>
109
- </TableHeader>
110
- <TableBody>
111
- {rows.map(({ lead, created }) => (
112
- <TableRow key={lead.id} data-testid={`leads-table-row-${lead.id}`}>
113
- <TableCell>{lead.name ?? labels.unavailable}</TableCell>
114
- <TableCell>{lead.email}</TableCell>
115
- <TableCell>{lead.source}</TableCell>
116
- <TableCell>{created}</TableCell>
117
- </TableRow>
118
- ))}
119
- </TableBody>
120
- </Table>
121
- {nextCursor !== null ? (
122
- <div className="mt-3 flex justify-end">
123
- <Link
124
- href={buildNextHref(locale, nextCursor)}
125
- data-testid="leads-table-next"
126
- // 24px hit-area floor (Rule 14) — a bare inline link's
127
- // line-height box falls short on its own (#4665, caught on the
128
- // worker's own re-inspection of the render evidence).
129
- className="inline-flex min-h-6 items-center px-2"
130
- >
131
- {labels.next}
132
- </Link>
133
- </div>
134
- ) : null}
135
- </div>
136
- );
137
- }
@@ -1,122 +0,0 @@
1
- /**
2
- * /[locale]/leads — the signed-in site owner's lead inbox (#5678).
3
- *
4
- * RSC: reads `GET /v1/leads` through `@working-theory/api-client`'s `leads`
5
- * namespace, forwarding the caller's cookie session
6
- * (`../../../../lib/server-api`, #4665 D9) — never a hand-rolled `fetch`
7
- * (`architecture.yaml`: `apps/web` may not reach `apps/api` directly). The
8
- * route is owner-scoped server-side, so this page passes no site or workspace
9
- * argument; the only query it owns is the forward-only `?cursor=`.
10
- *
11
- * A 401/403 renders `ForbiddenState` (no leak of why — the same shape the
12
- * waitlist comparison page uses); every other error (a 400 on a malformed
13
- * cursor, a 500) rethrows to the route's error boundary rather than being
14
- * swallowed.
15
- *
16
- * The page reads the session itself before any API call (#6865): Next renders
17
- * it concurrently with the (authed) layout, so for an anonymous visitor the
18
- * layout's `SignInGate` wins but this page would still have called
19
- * `leads.list()` — spending (or, with no API reachable, failing) a request
20
- * for a result nobody sees. No session renders `ForbiddenState` with no
21
- * apps/api request, the same guard `../account/page.tsx` carries.
22
- */
23
-
24
- import { leads, type LeadInboxPage } from "@working-theory/api-client";
25
- import { PageHeader } from "@working-theory/ui/blocks";
26
- import { Container, Heading, Text } from "@working-theory/ui/primitives";
27
- import type { Metadata } from "next";
28
- import { headers } from "next/headers";
29
- import { getTranslations } from "next-intl/server";
30
- import type { ReactElement } from "react";
31
-
32
- import { auth } from "../../../../auth";
33
- import { ApiError, forwardedCookieInit, unwrapApiResult } from "../../../../lib/server-api";
34
- import { ForbiddenState } from "../waitlist/components/ForbiddenState";
35
- import { formatDateTime } from "../waitlist/format";
36
-
37
- import { LeadsTable } from "./components/LeadsTable";
38
-
39
- interface Props {
40
- params: Promise<{ locale: string }>;
41
- searchParams: Promise<{ cursor?: string }>;
42
- }
43
-
44
- export async function generateMetadata({ params }: Props): Promise<Metadata> {
45
- const { locale } = await params;
46
- const t = await getTranslations({ locale, namespace: "leadsInbox" });
47
- return { title: t("title"), description: t("description") };
48
- }
49
-
50
- export default async function LeadsInboxPage({
51
- params,
52
- searchParams,
53
- }: Props): Promise<ReactElement> {
54
- const { locale } = await params;
55
- const { cursor } = await searchParams;
56
- const t = await getTranslations({ locale, namespace: "leadsInbox" });
57
-
58
- const forbidden = (
59
- <ForbiddenState headline={t("forbiddenHeadline")} description={t("forbiddenDescription")} />
60
- );
61
-
62
- const session = await auth.api.getSession({ headers: await headers() });
63
- if (!session) return forbidden;
64
-
65
- const init = await forwardedCookieInit();
66
-
67
- let page: LeadInboxPage;
68
- try {
69
- page = await unwrapApiResult(leads.list(cursor ? { cursor } : {}, init));
70
- } catch (err) {
71
- if (err instanceof ApiError && (err.status === 401 || err.status === 403)) {
72
- return forbidden;
73
- }
74
- // A 400 means the `?cursor=` in the URL did not resolve — it was typed,
75
- // or it is a stale next-page link whose row has since gone. That is a bad
76
- // address, not a broken page, so fall back to the first page rather than
77
- // letting it reach the route's error boundary (PR #5705 security review,
78
- // finding 3). A 400 from the FIRST-page read has no cursor to blame and
79
- // would be a genuine contract break, so it is rethrown.
80
- if (err instanceof ApiError && err.status === 400 && cursor) {
81
- page = await unwrapApiResult(leads.list({}, init));
82
- } else {
83
- throw err;
84
- }
85
- }
86
-
87
- const rows = page.items.map((lead) => ({
88
- lead,
89
- created: formatDateTime(lead.createdAt, locale),
90
- }));
91
-
92
- return (
93
- <main className="min-h-screen bg-surface text-fg" data-testid="leads-inbox-page">
94
- <PageHeader />
95
- <Container className="flex flex-col gap-6 py-section">
96
- <div>
97
- <Heading level={1}>{t("title")}</Heading>
98
- <Text as="p" variant="body-sm" tone="muted" className="mt-1">
99
- {t("description")}
100
- </Text>
101
- </div>
102
-
103
- <LeadsTable
104
- locale={locale}
105
- rows={rows}
106
- nextCursor={page.nextCursor}
107
- labels={{
108
- caption: t("table.caption"),
109
- columnName: t("table.columnName"),
110
- columnEmail: t("table.columnEmail"),
111
- columnSource: t("table.columnSource"),
112
- columnCreated: t("table.columnCreated"),
113
- unavailable: t("table.unavailable"),
114
- next: t("table.next"),
115
- emptyHeadline: t("table.emptyHeadline"),
116
- emptyDescription: t("table.emptyDescription"),
117
- }}
118
- />
119
- </Container>
120
- </main>
121
- );
122
- }
@@ -1,24 +0,0 @@
1
- /**
2
- * ForbiddenState — the dashboard's shared 401/403 rendering (#4665 D9, §2.2
3
- * Security: "a 401/403 renders an EmptyState (no leak of why)").
4
- */
5
-
6
- import { EmptyState } from "@working-theory/ui/primitives";
7
- import type { ReactElement } from "react";
8
-
9
- export function ForbiddenState({
10
- headline,
11
- description,
12
- }: {
13
- headline: string;
14
- description: string;
15
- }): ReactElement {
16
- return (
17
- <div
18
- className="flex min-h-[50vh] items-center justify-center py-section"
19
- data-testid="waitlist-forbidden"
20
- >
21
- <EmptyState headline={headline} description={description} />
22
- </div>
23
- );
24
- }
@@ -1,111 +0,0 @@
1
- /**
2
- * Display formatting for the waitlist operator dashboard (#4665 D4/D10, UI).
3
- *
4
- * The ONE place a number, rate, or date becomes a string for this surface
5
- * (Rule 10 — formatting happens in `apps/web`, never inside a
6
- * `packages/ui/src/blocks/*` component). Every formatter here is
7
- * locale-aware; the caller supplies the active `[locale]` route segment.
8
- *
9
- * `null` is D4's "unavailable" sentinel (an unscored / non-qualifying
10
- * experiment) — rendered as an em dash, never `0` or an empty string, so an
11
- * unscored row is never misread as a zero row.
12
- */
13
-
14
- import { formatNumber, formatPercent } from "@working-theory/web-i18n";
15
-
16
- /** D4/D9's "no value" rendering — never `0`, never blank. */
17
- export const UNAVAILABLE = "—";
18
-
19
- /** Format a raw count (signups, tier counts, question `answered`). */
20
- export function formatCount(value: number, locale: string): string {
21
- return formatNumber(value, locale);
22
- }
23
-
24
- /**
25
- * Format a rate/share (0–1) as a percentage, or the unavailable sentinel when
26
- * `null` (D4 — `qualified`/`qualificationRate` are `null` for a
27
- * `lead-capture` experiment; a distribution `share` is always a number).
28
- */
29
- export function formatRate(value: number | null, locale: string): string {
30
- if (value === null) return UNAVAILABLE;
31
- return formatPercent(value, locale);
32
- }
33
-
34
- /** Format an ISO-8601 datetime for display (list/comparison/drill-down). */
35
- export function formatDateTime(iso: string, locale: string): string {
36
- return new Intl.DateTimeFormat(locale, {
37
- dateStyle: "medium",
38
- timeStyle: "short",
39
- }).format(new Date(iso));
40
- }
41
-
42
- // ─── FEAT-074 U4a (#4715) — the targeting-maturity Level display ────────────
43
- //
44
- // Presentation-only mapping (spec D5): `level_3` -> the integer `3`,
45
- // `level_0` -> `0` (the Gate). Scoped to the ONE experiment this Level
46
- // vocabulary applies to — every other experiment's tier renders unchanged
47
- // (AC-5's "a non-targeting experiment renders exactly as before"). Pure
48
- // parsing only, no i18n — the CALLER (the page, which already owns every
49
- // `getTranslations` call on this surface) turns the returned number into
50
- // the "Level N" / Gate string via its own `t()`.
51
-
52
- /** The one experiment this Level vocabulary applies to. */
53
- export const TARGETING_MATURITY_EXPERIMENT_KEY = "targeting-maturity";
54
-
55
- const LEVEL_TIER_RE = /^level_(\d+)$/;
56
-
57
- /**
58
- * The Level number for a `targeting-maturity` `level_N` tier — `0` for the
59
- * Gate, `N` otherwise. `null` for any other experiment, a `null` tier, or an
60
- * unrecognized tier shape — the caller falls back to the raw tier /
61
- * `labels.unavailable` unchanged (D5).
62
- */
63
- export function targetingMaturityLevel(
64
- tier: string | null,
65
- experimentKey: string,
66
- ): number | null {
67
- if (experimentKey !== TARGETING_MATURITY_EXPERIMENT_KEY || tier === null) return null;
68
- const match = LEVEL_TIER_RE.exec(tier);
69
- return match ? Number(match[1]) : null;
70
- }
71
-
72
- /**
73
- * The `ref(<name>)` def names that DECIDED the matched tier, for the
74
- * ScoreTrace drill-down's "deciding factors" section (AC-5) — every
75
- * `kind: "predicate"` entry in a `RuleTraceEntry[]`-shaped `ruleTrace`
76
- * whose `tier` equals the signup's own tier AND whose `result` is `true`,
77
- * with every `ref(...)` segment in its `path` extracted (there is no
78
- * separate `def` field — `evaluatePredicateNode`'s own path-building embeds
79
- * each traversed def as `ref(<name>)`). Duck-typed against `unknown`
80
- * (`ruleTrace` is `z.unknown()` at this boundary — `waitlist-dashboard.ts`'s
81
- * schema comment), mirroring the identical extraction the backend's
82
- * `playbook-compile.ts` uses for its Level-1 loop-back framing — this is
83
- * the read-side counterpart, not a fork of it (no shared module: the two
84
- * sides are in different apps, which may not cross-import — `architecture.yaml`).
85
- * `[]` for any other experiment (AC-5's non-targeting byte-unchanged floor).
86
- */
87
- export function decidingDefsFor(
88
- tier: string | null,
89
- ruleTrace: unknown,
90
- experimentKey: string,
91
- ): string[] {
92
- if (experimentKey !== TARGETING_MATURITY_EXPERIMENT_KEY || tier === null) return [];
93
- if (!Array.isArray(ruleTrace)) return [];
94
- const seen = new Set<string>();
95
- const names: string[] = [];
96
- for (const entry of ruleTrace) {
97
- if (typeof entry !== "object" || entry === null) continue;
98
- const e = entry as Record<string, unknown>;
99
- if (e["kind"] !== "predicate" || e["tier"] !== tier || e["result"] !== true) continue;
100
- const path = e["path"];
101
- if (typeof path !== "string") continue;
102
- for (const m of path.matchAll(/ref\(([^)]+)\)/g)) {
103
- const name = m[1]!;
104
- if (!seen.has(name)) {
105
- seen.add(name);
106
- names.push(name);
107
- }
108
- }
109
- }
110
- return names;
111
- }