create-ailk 0.37.1 → 0.38.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 (230) 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 +18 -11
  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 +9 -15
  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 +67 -0
  26. package/dist/routes.d.ts +103 -0
  27. package/dist/routes.js +708 -0
  28. package/dist/site-manifest.js +1 -1
  29. package/dist/site-roster.d.ts +2 -1
  30. package/dist/site-roster.js +30 -8
  31. package/dist/spoke-checkout.d.ts +28 -27
  32. package/dist/spoke-checkout.js +71 -102
  33. package/dist/surfaces.d.ts +18 -0
  34. package/dist/surfaces.js +47 -282
  35. package/dist/sync-routes.d.ts +14 -1
  36. package/dist/sync-routes.js +86 -5
  37. package/dist/topology.d.ts +15 -1
  38. package/dist/topology.js +20 -4
  39. package/dist/update.d.ts +17 -2
  40. package/dist/update.js +480 -77
  41. package/package.json +3 -3
  42. package/templates/README.md +1 -1
  43. package/templates/apps/mcp/CLAUDE.md +5 -3
  44. package/templates/apps/web/CLAUDE.md +62 -20
  45. package/templates/apps/web/account.config.tsx +101 -0
  46. package/templates/apps/web/app/[locale]/(authed)/account/appointments/[slug]/page.tsx +3 -161
  47. package/templates/apps/web/app/[locale]/(authed)/account/appointments/page.tsx +3 -139
  48. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/page.tsx +3 -406
  49. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/versions/[version]/file/route.ts +2 -190
  50. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/page.tsx +3 -182
  51. package/templates/apps/web/app/[locale]/(authed)/account/billing/page.tsx +8 -420
  52. package/templates/apps/web/app/[locale]/(authed)/account/connect/page.tsx +1 -1
  53. package/templates/apps/web/app/[locale]/(authed)/account/general/page.tsx +8 -214
  54. package/templates/apps/web/app/[locale]/(authed)/account/inbox/[kind]/[id]/page.tsx +8 -115
  55. package/templates/apps/web/app/[locale]/(authed)/account/inbox/message/[id]/file/route.ts +2 -80
  56. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/page.tsx +8 -121
  57. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/page.tsx +3 -154
  58. package/templates/apps/web/app/[locale]/(authed)/account/layout.tsx +7 -149
  59. package/templates/apps/web/app/[locale]/(authed)/account/notifications/page.tsx +3 -143
  60. package/templates/apps/web/app/[locale]/(authed)/account/onboarding/page.tsx +3 -126
  61. package/templates/apps/web/app/[locale]/(authed)/account/page.tsx +8 -302
  62. package/templates/apps/web/app/[locale]/(authed)/account/privacy/export/route.ts +2 -102
  63. package/templates/apps/web/app/[locale]/(authed)/account/privacy/page.tsx +3 -240
  64. package/templates/apps/web/app/[locale]/(authed)/account/security/page.tsx +3 -131
  65. package/templates/apps/web/app/[locale]/(authed)/account/settings/page.tsx +2 -24
  66. package/templates/apps/web/app/[locale]/(authed)/account/support/page.tsx +3 -60
  67. package/templates/apps/web/app/[locale]/layout.tsx +45 -28
  68. package/templates/apps/web/app/apple-icon.tsx +72 -0
  69. package/templates/apps/web/app/llms.txt/__tests__/site-listing.test.ts +22 -12
  70. package/templates/apps/web/app/og/__tests__/__snapshots__/card.test.tsx.snap +3 -0
  71. package/templates/apps/web/app/og/__tests__/card.test.tsx +129 -0
  72. package/templates/apps/web/app/og/__tests__/route.test.ts +3 -4
  73. package/templates/apps/web/app/og/route.tsx +155 -72
  74. package/templates/apps/web/app/sitemap.xml/__tests__/site-listing.test.ts +12 -0
  75. package/templates/apps/web/i18n/request.ts +44 -1
  76. package/templates/apps/web/jest.config.cjs +13 -1
  77. package/templates/apps/web/lib/__tests__/auth-phone.test.ts +11 -0
  78. package/templates/apps/web/lib/__tests__/fixtures/site-topology.ts +70 -0
  79. package/templates/apps/web/lib/__tests__/nav-label-keys.test.ts +14 -0
  80. package/templates/apps/web/lib/__tests__/profile-back-link.test.ts +148 -61
  81. package/templates/apps/web/lib/__tests__/served-pages.test.ts +77 -0
  82. package/templates/apps/web/lib/__tests__/server-api.test.ts +37 -5
  83. package/templates/apps/web/lib/__tests__/structured-data.test.tsx +26 -13
  84. package/templates/apps/web/lib/listings.tsx +2 -2
  85. package/templates/apps/web/lib/nav-label-keys.ts +16 -2
  86. package/templates/apps/web/lib/paid-section-contracts.ts +35 -6
  87. package/templates/apps/web/lib/paid-sections.generated.ts +8 -0
  88. package/templates/apps/web/lib/profile-back-link.ts +105 -32
  89. package/templates/apps/web/lib/served-pages.ts +95 -0
  90. package/templates/apps/web/lib/site-brand.tsx +3 -5
  91. package/templates/apps/web/messages/en.json +8 -684
  92. package/templates/apps/web/middleware.ts +3 -1
  93. package/templates/apps/web/next.config.mjs +27 -0
  94. package/templates/apps/web/package.json +1 -0
  95. package/templates/customizations.yaml +9 -0
  96. package/templates/package.json +3 -1
  97. package/templates/tools/lint-architecture.ts +164 -11
  98. package/versions.json +48 -47
  99. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/account-frame-sign-out.test.tsx +0 -175
  100. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/agreements-prompt.test.tsx +0 -301
  101. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/billing.test.tsx +0 -515
  102. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/general.test.tsx +0 -883
  103. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/hub-mode.test.tsx +0 -758
  104. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/item.test.tsx +0 -264
  105. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout-sign-out.test.tsx +0 -167
  106. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout.test.tsx +0 -730
  107. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-menu.test.tsx +0 -355
  108. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-popups.test.tsx +0 -97
  109. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/notifications.test.tsx +0 -375
  110. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/onboarding.test.tsx +0 -323
  111. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/page.test.tsx +0 -1208
  112. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/popups.test.tsx +0 -418
  113. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/privacy.test.tsx +0 -462
  114. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/rich-translator.ts +0 -63
  115. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/security.test.tsx +0 -406
  116. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/settings.test.tsx +0 -93
  117. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/support.test.tsx +0 -208
  118. package/templates/apps/web/app/[locale]/(authed)/account/__tests__/thread.test.tsx +0 -340
  119. package/templates/apps/web/app/[locale]/(authed)/account/account-data.ts +0 -182
  120. package/templates/apps/web/app/[locale]/(authed)/account/account-frame.tsx +0 -353
  121. package/templates/apps/web/app/[locale]/(authed)/account/actions.ts +0 -57
  122. package/templates/apps/web/app/[locale]/(authed)/account/agreements-actions.ts +0 -58
  123. package/templates/apps/web/app/[locale]/(authed)/account/agreements-gate.ts +0 -61
  124. package/templates/apps/web/app/[locale]/(authed)/account/agreements-prompt.tsx +0 -184
  125. package/templates/apps/web/app/[locale]/(authed)/account/appointments/__tests__/page.test.tsx +0 -426
  126. package/templates/apps/web/app/[locale]/(authed)/account/appointments/appointments-data.ts +0 -76
  127. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/pay-form.tsx +0 -65
  128. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/review-form.tsx +0 -172
  129. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/file-route.test.ts +0 -333
  130. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/page.test.tsx +0 -936
  131. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/pay.test.tsx +0 -193
  132. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/review.test.tsx +0 -476
  133. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/artifact-actions.ts +0 -184
  134. package/templates/apps/web/app/[locale]/(authed)/account/artifacts/artifact-data.ts +0 -197
  135. package/templates/apps/web/app/[locale]/(authed)/account/billing/__tests__/offerings.test.ts +0 -99
  136. package/templates/apps/web/app/[locale]/(authed)/account/billing/offerings.ts +0 -123
  137. package/templates/apps/web/app/[locale]/(authed)/account/billing-source.ts +0 -303
  138. package/templates/apps/web/app/[locale]/(authed)/account/components/request-quote.tsx +0 -274
  139. package/templates/apps/web/app/[locale]/(authed)/account/error-row.tsx +0 -35
  140. package/templates/apps/web/app/[locale]/(authed)/account/for-you-labels.ts +0 -36
  141. package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/phone-verification.test.tsx +0 -215
  142. package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/seam-imports.test.ts +0 -65
  143. package/templates/apps/web/app/[locale]/(authed)/account/general/account-name.ts +0 -36
  144. package/templates/apps/web/app/[locale]/(authed)/account/general/billing-anchor.tsx +0 -27
  145. package/templates/apps/web/app/[locale]/(authed)/account/general/contact-actions.ts +0 -149
  146. package/templates/apps/web/app/[locale]/(authed)/account/general/contact-details.tsx +0 -42
  147. package/templates/apps/web/app/[locale]/(authed)/account/general/deletion-request.tsx +0 -132
  148. package/templates/apps/web/app/[locale]/(authed)/account/general/phone-actions.ts +0 -122
  149. package/templates/apps/web/app/[locale]/(authed)/account/general/phone-verification.tsx +0 -215
  150. package/templates/apps/web/app/[locale]/(authed)/account/general/photo-actions.ts +0 -73
  151. package/templates/apps/web/app/[locale]/(authed)/account/general/profile-form.tsx +0 -107
  152. package/templates/apps/web/app/[locale]/(authed)/account/general/profile-source.ts +0 -87
  153. package/templates/apps/web/app/[locale]/(authed)/account/inbox/message/[id]/file/__tests__/route.test.ts +0 -215
  154. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/member-thread-composer.tsx +0 -43
  155. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-data.ts +0 -88
  156. package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-write.ts +0 -31
  157. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/invitation-id.test.ts +0 -35
  158. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/page.test.tsx +0 -266
  159. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/actions.ts +0 -116
  160. package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/invitation-id.ts +0 -12
  161. package/templates/apps/web/app/[locale]/(authed)/account/new-actions.ts +0 -219
  162. package/templates/apps/web/app/[locale]/(authed)/account/new-menu.tsx +0 -365
  163. package/templates/apps/web/app/[locale]/(authed)/account/new-popups.tsx +0 -86
  164. package/templates/apps/web/app/[locale]/(authed)/account/onboarding/actions.ts +0 -120
  165. package/templates/apps/web/app/[locale]/(authed)/account/onboarding/onboarding-form.tsx +0 -322
  166. package/templates/apps/web/app/[locale]/(authed)/account/privacy/__tests__/export-route.test.ts +0 -173
  167. package/templates/apps/web/app/[locale]/(authed)/account/privacy/actions.ts +0 -103
  168. package/templates/apps/web/app/[locale]/(authed)/account/profile-actions.ts +0 -116
  169. package/templates/apps/web/app/[locale]/(authed)/account/retry-button.tsx +0 -27
  170. package/templates/apps/web/app/[locale]/(authed)/account/security/__tests__/hub-variant.test.tsx +0 -258
  171. package/templates/apps/web/app/[locale]/(authed)/account/security/security-panel.tsx +0 -130
  172. package/templates/apps/web/app/[locale]/(authed)/account/security/security-source.ts +0 -92
  173. package/templates/apps/web/app/[locale]/(authed)/account/settings-frame.tsx +0 -121
  174. package/templates/apps/web/app/[locale]/(authed)/account/sign-in-method.ts +0 -37
  175. package/templates/apps/web/app/[locale]/(authed)/account/support/support-form.tsx +0 -98
  176. package/templates/apps/web/app/[locale]/(authed)/account/support-actions.ts +0 -100
  177. package/templates/apps/web/app/[locale]/checkout/__tests__/pages.test.tsx +0 -139
  178. package/templates/apps/web/app/[locale]/checkout/__tests__/thank-you-account.test.tsx +0 -146
  179. package/templates/apps/web/app/[locale]/checkout/thank-you/page.tsx +0 -114
  180. package/templates/apps/web/app/[locale]/checkout/unavailable/page.tsx +0 -51
  181. package/templates/apps/web/app/[locale]/flows/[slug]/FlowStepperClient.tsx +0 -614
  182. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.count.test.tsx +0 -43
  183. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.deliverable.test.tsx +0 -214
  184. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.ending.test.tsx +0 -197
  185. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.invite.test.tsx +0 -286
  186. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.permalink.test.tsx +0 -520
  187. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.test.tsx +0 -376
  188. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.thanks-by-tier.test.tsx +0 -306
  189. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/account-invite.actions.test.ts +0 -69
  190. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/flow.actions.test.ts +0 -398
  191. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/magnet-page.test.tsx +0 -704
  192. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/save.actions.test.ts +0 -173
  193. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/two-route-tool.test.tsx +0 -141
  194. package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/verify.test.tsx +0 -249
  195. package/templates/apps/web/app/[locale]/flows/[slug]/account-invite.actions.ts +0 -35
  196. package/templates/apps/web/app/[locale]/flows/[slug]/email-moment.ts +0 -92
  197. package/templates/apps/web/app/[locale]/flows/[slug]/flow.actions.ts +0 -177
  198. package/templates/apps/web/app/[locale]/flows/[slug]/magnet-page.tsx +0 -472
  199. package/templates/apps/web/app/[locale]/flows/[slug]/page.tsx +0 -48
  200. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/LevelChart.tsx +0 -100
  201. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsCard.tsx +0 -99
  202. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsClient.tsx +0 -820
  203. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsEmailStep.tsx +0 -203
  204. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/ResultsClient.no-commerce.test.tsx +0 -194
  205. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/ResultsClient.report.test.tsx +0 -284
  206. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/by-result.test.tsx +0 -302
  207. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/cards.test.tsx +0 -402
  208. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/landing.test.tsx +0 -293
  209. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/page.test.tsx +0 -485
  210. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/score.test.tsx +0 -231
  211. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/checkout-seam.ts +0 -74
  212. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/meeting-seam.ts +0 -36
  213. package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/page.tsx +0 -420
  214. package/templates/apps/web/app/[locale]/flows/[slug]/save.actions.ts +0 -85
  215. package/templates/apps/web/app/[locale]/flows/[slug]/served-flow.ts +0 -91
  216. package/templates/apps/web/app/[locale]/flows/[slug]/start/page.tsx +0 -32
  217. package/templates/apps/web/app/[locale]/flows/[slug]/verify/page.tsx +0 -153
  218. package/templates/apps/web/app/[locale]/flows/[slug]/verify.actions.ts +0 -151
  219. package/templates/apps/web/app/[locale]/meet/confirmed/BookingHandOff.tsx +0 -128
  220. package/templates/apps/web/app/[locale]/meet/confirmed/__tests__/BookingHandOff.test.tsx +0 -126
  221. package/templates/apps/web/app/[locale]/purchase/__tests__/cancel.test.tsx +0 -162
  222. package/templates/apps/web/app/[locale]/purchase/__tests__/module-scope.test.ts +0 -68
  223. package/templates/apps/web/app/[locale]/purchase/__tests__/success.test.tsx +0 -411
  224. package/templates/apps/web/app/[locale]/purchase/cancel/page.tsx +0 -115
  225. package/templates/apps/web/app/[locale]/purchase/success/page.tsx +0 -348
  226. package/templates/apps/web/lib/__tests__/account-config.test.ts +0 -704
  227. package/templates/apps/web/lib/account-config.ts +0 -678
  228. package/templates/apps/web/lib/checkout-config.ts +0 -16
  229. package/templates/apps/web/src/lib/__tests__/commerce-sections.test.ts +0 -57
  230. package/templates/apps/web/src/lib/commerce-sections.ts +0 -55
@@ -1,69 +0,0 @@
1
- // oss: false
2
- /**
3
- * #8771 AC-4 (the action) — accountInviteLinkAction builds #8757's link on the
4
- * server and answers null when it cannot.
5
- */
6
- import { readFileSync } from "node:fs";
7
- import { join } from "node:path";
8
-
9
- const mockGetLocale = jest.fn();
10
- jest.mock("next-intl/server", () => ({
11
- getLocale: (...args: unknown[]) => mockGetLocale(...args),
12
- }));
13
-
14
- const mockInviteHref = jest.fn();
15
- // eslint-disable-next-line no-restricted-syntax -- accountInviteHref reads the generated topology (build output); this file asserts the action's own decision
16
- jest.mock("../../../../../lib/account-invite", () => ({
17
- accountInviteHref: (...args: unknown[]) => mockInviteHref(...args),
18
- }));
19
-
20
- import { accountInviteLinkAction } from "../account-invite.actions";
21
-
22
- beforeEach(() => {
23
- jest.clearAllMocks();
24
- mockGetLocale.mockResolvedValue("fr");
25
- mockInviteHref.mockImplementation(
26
- (locale: string, email: string) => `/${locale}/sign-in?email=${email}`,
27
- );
28
- });
29
-
30
- describe("accountInviteLinkAction", () => {
31
- it("returns what accountInviteHref returns for the request's locale", async () => {
32
- await expect(accountInviteLinkAction("jane@example.com")).resolves.toBe(
33
- "/fr/sign-in?email=jane@example.com",
34
- );
35
- expect(mockInviteHref).toHaveBeenCalledWith("fr", "jane@example.com");
36
- });
37
-
38
- it.each(["nope", "a\r\n@b.example", "a b@example.com"])(
39
- "refuses %j",
40
- async (email) => {
41
- await expect(accountInviteLinkAction(email)).resolves.toBeNull();
42
- expect(mockInviteHref).not.toHaveBeenCalled();
43
- },
44
- );
45
-
46
- it("answers null when the locale cannot be read", async () => {
47
- mockGetLocale.mockRejectedValue(new Error("no request scope"));
48
- await expect(
49
- accountInviteLinkAction("jane@example.com"),
50
- ).resolves.toBeNull();
51
- });
52
-
53
- it("answers null for a site with no sign-in", async () => {
54
- mockInviteHref.mockReturnValue(null);
55
- await expect(
56
- accountInviteLinkAction("jane@example.com"),
57
- ).resolves.toBeNull();
58
- });
59
-
60
- it("makes no API call, and carries the oss marker on its first line", () => {
61
- const source = readFileSync(
62
- join(__dirname, "..", "account-invite.actions.ts"),
63
- "utf8",
64
- );
65
- expect(source.split("\n")[0]).toBe("// oss: false");
66
- expect(source).not.toMatch(/\bfetch\(/);
67
- expect(source).not.toContain("@working-theory/api-client");
68
- });
69
- });
@@ -1,398 +0,0 @@
1
- // oss: false
2
- /**
3
- * Tests for submitFlowStepAction Server Action (#3957 D8).
4
- *
5
- * Acceptance criteria verified here:
6
- * - submitFlowStepAction(slug, validPayload) calls api-client flows.submitStep
7
- * and returns { ok: true, response } passthrough.
8
- * - invalid slug / invalid payload → { ok: false, kind: "invalid_input" }
9
- * without calling api-client.
10
- * - api-client 400 → kind "invalid_input"; 409 → kind "step_conflict";
11
- * 429 → kind "rate_limited" carrying retryAfterSeconds; other statuses /
12
- * a thrown error → kind "network".
13
- * - #4730 — the visitor's `x-forwarded-for` (read from THIS action's own
14
- * incoming request via next/headers) is forwarded on the outbound
15
- * flows.submitStep call; absent entirely when no header is present.
16
- * - Parity: submitFlowStepAction is paired with ailkSubmitFlowStep per ADR 0013.
17
- */
18
-
19
- import { submitFlowStepAction } from "../flow.actions.js";
20
-
21
- // #9255 — the write bot check's verdict. `checkBotId` reads Vercel's
22
- // request context, which jest has none of, so every case decides it here.
23
- const checkBotIdMock = jest.fn();
24
- jest.mock("botid/server", () => ({
25
- checkBotId: (...args: unknown[]) => checkBotIdMock(...args),
26
- }));
27
-
28
- jest.mock("@working-theory/api-client", () => ({
29
- flows: {
30
- submitStep: jest.fn(),
31
- },
32
- }));
33
-
34
- // #4730 — default: no incoming headers to forward, matching every
35
- // pre-existing test's 2-arg `flows.submitStep(slug, payload)` expectation
36
- // byte-for-byte. Individual #4730 tests override with a real x-forwarded-for.
37
- jest.mock("next/headers", () => ({
38
- __esModule: true,
39
- headers: jest.fn().mockResolvedValue({ get: () => null }),
40
- }));
41
-
42
- import { flows } from "@working-theory/api-client";
43
- import { headers } from "next/headers";
44
- const mockSubmitStep = flows.submitStep as jest.Mock;
45
- const mockHeaders = headers as jest.Mock;
46
-
47
- afterEach(() => {
48
- jest.clearAllMocks();
49
- mockHeaders.mockResolvedValue({ get: () => null });
50
- });
51
-
52
- const VALID_PAYLOAD = {
53
- stepKey: "contact",
54
- values: { email: "jane@example.com" },
55
- };
56
-
57
- describe("submitFlowStepAction — valid input", () => {
58
- it("calls flows.submitStep and returns the response passthrough on success", async () => {
59
- mockSubmitStep.mockResolvedValueOnce({
60
- ok: true,
61
- body: {
62
- sessionId: "sess1",
63
- landed: "contact",
64
- nextStepKey: "budget",
65
- completed: false,
66
- },
67
- });
68
-
69
- const result = await submitFlowStepAction("get-a-quote", VALID_PAYLOAD);
70
-
71
- expect(mockSubmitStep).toHaveBeenCalledWith(
72
- "get-a-quote",
73
- expect.objectContaining(VALID_PAYLOAD),
74
- );
75
- expect(result).toEqual({
76
- ok: true,
77
- response: {
78
- sessionId: "sess1",
79
- landed: "contact",
80
- nextStepKey: "budget",
81
- completed: false,
82
- },
83
- });
84
- });
85
-
86
- it("threads sessionId and locale through to the api-client call", async () => {
87
- mockSubmitStep.mockResolvedValueOnce({
88
- ok: true,
89
- body: {
90
- sessionId: "sess1",
91
- landed: "budget",
92
- nextStepKey: "thanks",
93
- completed: false,
94
- },
95
- });
96
-
97
- await submitFlowStepAction("get-a-quote", {
98
- sessionId: "sess1",
99
- stepKey: "budget",
100
- values: { budget: "small" },
101
- locale: "en",
102
- });
103
-
104
- expect(mockSubmitStep).toHaveBeenCalledWith("get-a-quote", {
105
- sessionId: "sess1",
106
- stepKey: "budget",
107
- values: { budget: "small" },
108
- locale: "en",
109
- });
110
- });
111
- });
112
-
113
- describe("submitFlowStepAction — invalid input", () => {
114
- it("returns invalid_input without calling api-client for a malformed slug", async () => {
115
- const result = await submitFlowStepAction("Not A Slug!", VALID_PAYLOAD);
116
-
117
- expect(result).toMatchObject({ ok: false, kind: "invalid_input" });
118
- expect(mockSubmitStep).not.toHaveBeenCalled();
119
- });
120
-
121
- it("returns invalid_input without calling api-client for a missing stepKey", async () => {
122
- const result = await submitFlowStepAction("get-a-quote", {
123
- stepKey: "",
124
- values: {},
125
- });
126
-
127
- expect(result).toMatchObject({ ok: false, kind: "invalid_input" });
128
- expect(mockSubmitStep).not.toHaveBeenCalled();
129
- });
130
- });
131
-
132
- describe("submitFlowStepAction — api-client failure mapping", () => {
133
- it("maps a 400 response to kind invalid_input", async () => {
134
- mockSubmitStep.mockResolvedValueOnce({ ok: false, status: 400, body: {} });
135
-
136
- const result = await submitFlowStepAction("get-a-quote", VALID_PAYLOAD);
137
-
138
- expect(result).toEqual({ ok: false, kind: "invalid_input" });
139
- });
140
-
141
- it("maps a 409 response to kind step_conflict", async () => {
142
- mockSubmitStep.mockResolvedValueOnce({ ok: false, status: 409, body: {} });
143
-
144
- const result = await submitFlowStepAction("get-a-quote", VALID_PAYLOAD);
145
-
146
- expect(result).toEqual({ ok: false, kind: "step_conflict" });
147
- });
148
-
149
- it("maps a 429 response to kind rate_limited, carrying retryAfterSeconds (#4730)", async () => {
150
- mockSubmitStep.mockResolvedValueOnce({
151
- ok: false,
152
- status: 429,
153
- body: { error: "rate_limited", retryAfterSeconds: 37 },
154
- });
155
-
156
- const result = await submitFlowStepAction("get-a-quote", VALID_PAYLOAD);
157
-
158
- expect(result).toEqual({
159
- ok: false,
160
- kind: "rate_limited",
161
- retryAfterSeconds: 37,
162
- });
163
- });
164
-
165
- it("maps a 429 response with no retryAfterSeconds to kind rate_limited alone (#4730)", async () => {
166
- mockSubmitStep.mockResolvedValueOnce({ ok: false, status: 429, body: {} });
167
-
168
- const result = await submitFlowStepAction("get-a-quote", VALID_PAYLOAD);
169
-
170
- expect(result).toEqual({ ok: false, kind: "rate_limited" });
171
- });
172
-
173
- it("maps any other failing status to kind network", async () => {
174
- mockSubmitStep.mockResolvedValueOnce({ ok: false, status: 500, body: {} });
175
-
176
- const result = await submitFlowStepAction("get-a-quote", VALID_PAYLOAD);
177
-
178
- expect(result).toEqual({ ok: false, kind: "network" });
179
- });
180
-
181
- it("maps a thrown error to kind network", async () => {
182
- mockSubmitStep.mockRejectedValueOnce(new Error("network down"));
183
-
184
- const result = await submitFlowStepAction("get-a-quote", VALID_PAYLOAD);
185
-
186
- expect(result).toEqual({ ok: false, kind: "network" });
187
- });
188
-
189
- it("logs a thrown error server-side without leaking submitted values", async () => {
190
- const thrown = new Error("network down");
191
- mockSubmitStep.mockRejectedValueOnce(thrown);
192
- const consoleErrorSpy = jest
193
- .spyOn(console, "error")
194
- .mockImplementation(() => {});
195
-
196
- const result = await submitFlowStepAction("get-a-quote", VALID_PAYLOAD);
197
-
198
- expect(result).toEqual({ ok: false, kind: "network" });
199
- expect(consoleErrorSpy).toHaveBeenCalledTimes(1);
200
- const [logLine, loggedErr] = consoleErrorSpy.mock.calls[0] as [
201
- string,
202
- unknown,
203
- ];
204
- expect(logLine).toContain("[submitFlowStepAction]");
205
- expect(logLine).toContain("get-a-quote");
206
- expect(logLine).toContain(VALID_PAYLOAD.stepKey);
207
- expect(logLine).not.toContain("jane@example.com");
208
- expect(loggedErr).toBe(thrown);
209
-
210
- consoleErrorSpy.mockRestore();
211
- });
212
- });
213
-
214
- describe("submitFlowStepAction — visitor IP forwarding (#4730)", () => {
215
- it("forwards x-forwarded-for from the action's own incoming request as init.headers", async () => {
216
- mockHeaders.mockResolvedValueOnce({
217
- get: (name: string) =>
218
- name === "x-forwarded-for" ? "203.0.113.7, 9.9.9.9" : null,
219
- });
220
- mockSubmitStep.mockResolvedValueOnce({
221
- ok: true,
222
- body: {
223
- sessionId: "sess1",
224
- landed: "contact",
225
- nextStepKey: "budget",
226
- completed: false,
227
- },
228
- });
229
-
230
- await submitFlowStepAction("get-a-quote", VALID_PAYLOAD);
231
-
232
- expect(mockSubmitStep).toHaveBeenCalledWith(
233
- "get-a-quote",
234
- expect.objectContaining(VALID_PAYLOAD),
235
- { headers: { "x-forwarded-for": "203.0.113.7, 9.9.9.9" } },
236
- );
237
- });
238
-
239
- it("falls back to x-real-ip when x-forwarded-for is absent", async () => {
240
- mockHeaders.mockResolvedValueOnce({
241
- get: (name: string) => (name === "x-real-ip" ? "198.51.100.4" : null),
242
- });
243
- mockSubmitStep.mockResolvedValueOnce({
244
- ok: true,
245
- body: {
246
- sessionId: "sess1",
247
- landed: "contact",
248
- nextStepKey: "budget",
249
- completed: false,
250
- },
251
- });
252
-
253
- await submitFlowStepAction("get-a-quote", VALID_PAYLOAD);
254
-
255
- expect(mockSubmitStep).toHaveBeenCalledWith(
256
- "get-a-quote",
257
- expect.objectContaining(VALID_PAYLOAD),
258
- { headers: { "x-forwarded-for": "198.51.100.4" } },
259
- );
260
- });
261
-
262
- it("calls flows.submitStep with exactly two arguments when no visitor IP header is present", async () => {
263
- // Default mock (no x-forwarded-for / x-real-ip) — mirrors every other
264
- // test in this file; asserted explicitly here as the #4730 regression
265
- // floor: no header ⇒ no third argument, ever an explicit `undefined`.
266
- mockSubmitStep.mockResolvedValueOnce({
267
- ok: true,
268
- body: {
269
- sessionId: "sess1",
270
- landed: "contact",
271
- nextStepKey: "budget",
272
- completed: false,
273
- },
274
- });
275
-
276
- await submitFlowStepAction("get-a-quote", VALID_PAYLOAD);
277
-
278
- expect(mockSubmitStep).toHaveBeenCalledWith(
279
- "get-a-quote",
280
- expect.objectContaining(VALID_PAYLOAD),
281
- );
282
- expect(mockSubmitStep.mock.calls[0]).toHaveLength(2);
283
- });
284
-
285
- it("degrades to no forwarded header when headers() itself throws", async () => {
286
- mockHeaders.mockRejectedValueOnce(new Error("no request scope"));
287
- mockSubmitStep.mockResolvedValueOnce({
288
- ok: true,
289
- body: {
290
- sessionId: "sess1",
291
- landed: "contact",
292
- nextStepKey: "budget",
293
- completed: false,
294
- },
295
- });
296
-
297
- const result = await submitFlowStepAction("get-a-quote", VALID_PAYLOAD);
298
-
299
- expect(result).toEqual({
300
- ok: true,
301
- response: {
302
- sessionId: "sess1",
303
- landed: "contact",
304
- nextStepKey: "budget",
305
- completed: false,
306
- },
307
- });
308
- expect(mockSubmitStep.mock.calls[0]).toHaveLength(2);
309
- });
310
- });
311
-
312
- // #9255 D4 — the write bot check runs after the slug and payload checks,
313
- // immediately before the write (spec
314
- // docs/specs/9255-an-edge-bot-challenge-in-spec.md §5.1 AC-2).
315
- describe("submitFlowStepAction — the write bot check (#9255)", () => {
316
- const BOT = {
317
- isHuman: false,
318
- isBot: true,
319
- isVerifiedBot: false,
320
- bypassed: false,
321
- };
322
- const HUMAN = { ...BOT, isHuman: true, isBot: false };
323
- const BOT_ENV_KEYS = [
324
- "VERCEL",
325
- "AILK_BOT_CHECK",
326
- "AILK_BOOKING_BOT_CHECK",
327
- ] as const;
328
- const priorBotEnv = new Map(
329
- BOT_ENV_KEYS.map((name) => [name, process.env[name]]),
330
- );
331
-
332
- let botLogSpies: jest.SpyInstance[] = [];
333
-
334
- beforeEach(() => {
335
- checkBotIdMock.mockReset();
336
- for (const name of BOT_ENV_KEYS) delete process.env[name];
337
- process.env.VERCEL = "1";
338
- botLogSpies = [
339
- jest.spyOn(console, "warn").mockImplementation(() => undefined),
340
- jest.spyOn(console, "error").mockImplementation(() => undefined),
341
- ];
342
- });
343
-
344
- afterEach(() => {
345
- for (const [name, value] of priorBotEnv) {
346
- if (value === undefined) delete process.env[name];
347
- else process.env[name] = value;
348
- }
349
- for (const spy of botLogSpies) spy.mockRestore();
350
- });
351
-
352
- it.each([
353
- ["a bot", () => checkBotIdMock.mockResolvedValue(BOT)],
354
- [
355
- "a check that fails",
356
- () => checkBotIdMock.mockRejectedValue(new Error("boom")),
357
- ],
358
- ])("%s gets kind network, and nothing is sent", async (_label, decide) => {
359
- decide();
360
- expect(
361
- await submitFlowStepAction("lead-magnet", VALID_PAYLOAD),
362
- ).toStrictEqual({
363
- ok: false,
364
- kind: "network",
365
- });
366
- expect(checkBotIdMock).toHaveBeenCalledTimes(1);
367
- expect(mockSubmitStep).not.toHaveBeenCalled();
368
- });
369
-
370
- it("a human sends exactly what the check off sends", async () => {
371
- checkBotIdMock.mockResolvedValue(HUMAN);
372
- mockSubmitStep.mockResolvedValue({
373
- ok: true,
374
- status: 200,
375
- body: { sessionId: "s1", nextStepKey: null, completed: true },
376
- });
377
- delete process.env.VERCEL;
378
- await submitFlowStepAction("lead-magnet", VALID_PAYLOAD);
379
- process.env.VERCEL = "1";
380
- expect(
381
- await submitFlowStepAction("lead-magnet", VALID_PAYLOAD),
382
- ).toMatchObject({ ok: true });
383
- expect(checkBotIdMock).toHaveBeenCalledTimes(1);
384
- expect(mockSubmitStep).toHaveBeenCalledTimes(2);
385
- expect(mockSubmitStep.mock.calls[1]).toEqual(mockSubmitStep.mock.calls[0]);
386
- });
387
-
388
- it("an invalid payload answers invalid_input with no check", async () => {
389
- checkBotIdMock.mockResolvedValue(BOT);
390
- expect(
391
- await submitFlowStepAction("lead-magnet", { stepKey: "", values: {} }),
392
- ).toMatchObject({
393
- ok: false,
394
- kind: "invalid_input",
395
- });
396
- expect(checkBotIdMock).not.toHaveBeenCalled();
397
- });
398
- });