create-ailk 0.39.0 → 0.40.1

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 (203) hide show
  1. package/component-catalog.json +1 -1
  2. package/component-catalog.md +1 -1
  3. package/dist/add-route.js +15 -0
  4. package/dist/body-heading.d.ts +2 -1
  5. package/dist/body-heading.js +31 -3
  6. package/dist/module-architecture.js +0 -3
  7. package/dist/remove-module.js +13 -4
  8. package/dist/routes.d.ts +7 -0
  9. package/dist/routes.js +1 -1
  10. package/dist/site-roster.js +7 -1
  11. package/dist/surfaces.d.ts +2 -0
  12. package/dist/surfaces.js +59 -172
  13. package/package.json +3 -3
  14. package/templates/apps/web/CLAUDE.md +19 -2
  15. package/templates/apps/web/__tests__/__mocks__/next-intl-server.ts +3 -2
  16. package/templates/apps/web/__tests__/__mocks__/next-intl.ts +3 -2
  17. package/templates/apps/web/app/[locale]/layout.tsx +42 -25
  18. package/templates/apps/web/app/api/revalidate/__tests__/route.test.ts +56 -1
  19. package/templates/apps/web/app/api/revalidate/route.ts +45 -4
  20. package/templates/apps/web/app/llms.txt/__tests__/site-listing.test.ts +53 -0
  21. package/templates/apps/web/app/llms.txt/route.ts +5 -2
  22. package/templates/apps/web/i18n/request.ts +5 -1
  23. package/templates/apps/web/jest.config.cjs +6 -0
  24. package/templates/apps/web/lib/__tests__/deck-page.test.ts +9 -0
  25. package/templates/apps/web/lib/__tests__/hub-site-config.test.ts +239 -0
  26. package/templates/apps/web/lib/__tests__/in-page-magnet-self-request.test.ts +1 -1
  27. package/templates/apps/web/lib/__tests__/in-page-magnet.test.ts +2 -2
  28. package/templates/apps/web/lib/__tests__/pricing-page.test.ts +1 -1
  29. package/templates/apps/web/lib/__tests__/profile-back-link.test.ts +58 -0
  30. package/templates/apps/web/lib/__tests__/served-pages.test.ts +163 -20
  31. package/templates/apps/web/lib/__tests__/site-brand.test.ts +77 -0
  32. package/templates/apps/web/{app/[locale]/contact → lib}/__tests__/site-contact-lines.test.ts +64 -0
  33. package/templates/apps/web/lib/__tests__/site-identity-feature-list.test.ts +115 -3
  34. package/templates/apps/web/lib/__tests__/structured-data.test.tsx +17 -4
  35. package/templates/apps/web/lib/hub-site-config.ts +151 -0
  36. package/templates/apps/web/lib/in-page-magnet.ts +2 -2
  37. package/templates/apps/web/lib/pricing-page.ts +3 -3
  38. package/templates/apps/web/lib/profile-back-link.ts +49 -12
  39. package/templates/apps/web/lib/served-pages.ts +144 -39
  40. package/templates/apps/web/lib/site-brand.tsx +66 -0
  41. package/templates/apps/web/{app/[locale]/contact → lib}/site-contact-email.ts +25 -5
  42. package/templates/apps/web/{app/[locale]/contact → lib}/site-contact-lines.ts +21 -5
  43. package/templates/apps/web/lib/site-header.ts +1 -1
  44. package/templates/apps/web/lib/site-identity.ts +38 -2
  45. package/templates/apps/web/messages/en.json +3 -119
  46. package/templates/apps/web/next.config.mjs +7 -0
  47. package/templates/apps/web/package.json +1 -0
  48. package/templates/apps/web/site-pages.config.tsx +85 -0
  49. package/templates/tools/body-heading.ts +30 -3
  50. package/versions.json +50 -49
  51. package/templates/apps/web/app/[locale]/(authed)/leads/__tests__/page.test.tsx +0 -205
  52. package/templates/apps/web/app/[locale]/(authed)/leads/components/LeadsTable.tsx +0 -137
  53. package/templates/apps/web/app/[locale]/(authed)/leads/page.tsx +0 -122
  54. package/templates/apps/web/app/[locale]/(authed)/waitlist/components/ForbiddenState.tsx +0 -24
  55. package/templates/apps/web/app/[locale]/(authed)/waitlist/format.ts +0 -111
  56. package/templates/apps/web/app/[locale]/[slug]/[detail]/__tests__/page.test.tsx +0 -402
  57. package/templates/apps/web/app/[locale]/[slug]/[detail]/page.tsx +0 -143
  58. package/templates/apps/web/app/[locale]/[slug]/__tests__/page.test.tsx +0 -148
  59. package/templates/apps/web/app/[locale]/[slug]/page.tsx +0 -109
  60. package/templates/apps/web/app/[locale]/about/[slug]/page.tsx +0 -46
  61. package/templates/apps/web/app/[locale]/about/__tests__/about-routes.test.tsx +0 -353
  62. package/templates/apps/web/app/[locale]/about/page.tsx +0 -122
  63. package/templates/apps/web/app/[locale]/alternatives/__tests__/page.test.tsx +0 -161
  64. package/templates/apps/web/app/[locale]/alternatives/page.tsx +0 -112
  65. package/templates/apps/web/app/[locale]/careers/[slug]/[action]/page.tsx +0 -244
  66. package/templates/apps/web/app/[locale]/careers/[slug]/apply.actions.ts +0 -325
  67. package/templates/apps/web/app/[locale]/careers/[slug]/job-application-form.ts +0 -120
  68. package/templates/apps/web/app/[locale]/careers/[slug]/page.tsx +0 -73
  69. package/templates/apps/web/app/[locale]/careers/__tests__/apply.actions.test.ts +0 -497
  70. package/templates/apps/web/app/[locale]/careers/__tests__/careers-hub.test.tsx +0 -172
  71. package/templates/apps/web/app/[locale]/careers/__tests__/careers-set.test.tsx +0 -153
  72. package/templates/apps/web/app/[locale]/careers/__tests__/job-application-form.test.ts +0 -141
  73. package/templates/apps/web/app/[locale]/careers/__tests__/job-apply-page.test.tsx +0 -546
  74. package/templates/apps/web/app/[locale]/careers/__tests__/page-renderer-migration.test.tsx +0 -189
  75. package/templates/apps/web/app/[locale]/careers/page.tsx +0 -165
  76. package/templates/apps/web/app/[locale]/case-studies/[slug]/page.tsx +0 -49
  77. package/templates/apps/web/app/[locale]/case-studies/__tests__/hub-children.test.tsx +0 -65
  78. package/templates/apps/web/app/[locale]/case-studies/__tests__/page-renderer-migration.test.tsx +0 -125
  79. package/templates/apps/web/app/[locale]/case-studies/page.tsx +0 -49
  80. package/templates/apps/web/app/[locale]/clients/__tests__/page-renderer-migration.test.tsx +0 -85
  81. package/templates/apps/web/app/[locale]/clients/page.tsx +0 -47
  82. package/templates/apps/web/app/[locale]/contact/ConversationalIntakeWrapper.tsx +0 -249
  83. package/templates/apps/web/app/[locale]/contact/__tests__/ConversationalIntakeWrapper.test.tsx +0 -400
  84. package/templates/apps/web/app/[locale]/contact/__tests__/contact-form-magnet.test.ts +0 -138
  85. package/templates/apps/web/app/[locale]/contact/__tests__/contact-form-text.test.ts +0 -49
  86. package/templates/apps/web/app/[locale]/contact/__tests__/contact-magnet-page.test.tsx +0 -494
  87. package/templates/apps/web/app/[locale]/contact/__tests__/contact.actions.test.ts +0 -1122
  88. package/templates/apps/web/app/[locale]/contact/__tests__/intake-analytics.test.ts +0 -51
  89. package/templates/apps/web/app/[locale]/contact/__tests__/page-renderer-migration.test.tsx +0 -319
  90. package/templates/apps/web/app/[locale]/contact/contact-form-magnet.ts +0 -77
  91. package/templates/apps/web/app/[locale]/contact/contact-form-text.ts +0 -52
  92. package/templates/apps/web/app/[locale]/contact/contact.actions.ts +0 -403
  93. package/templates/apps/web/app/[locale]/contact/intake-analytics.ts +0 -49
  94. package/templates/apps/web/app/[locale]/contact/intake-script.ts +0 -92
  95. package/templates/apps/web/app/[locale]/contact/page.tsx +0 -267
  96. package/templates/apps/web/app/[locale]/courses/[slug]/page.tsx +0 -50
  97. package/templates/apps/web/app/[locale]/courses/__tests__/hub-children.test.tsx +0 -32
  98. package/templates/apps/web/app/[locale]/courses/__tests__/page-renderer-migration.test.tsx +0 -123
  99. package/templates/apps/web/app/[locale]/courses/page.tsx +0 -49
  100. package/templates/apps/web/app/[locale]/events/[slug]/page.tsx +0 -57
  101. package/templates/apps/web/app/[locale]/events/__tests__/hub-children.test.tsx +0 -32
  102. package/templates/apps/web/app/[locale]/events/__tests__/page-renderer-migration.test.tsx +0 -164
  103. package/templates/apps/web/app/[locale]/events/__tests__/program-event.test.tsx +0 -120
  104. package/templates/apps/web/app/[locale]/events/page.tsx +0 -60
  105. package/templates/apps/web/app/[locale]/faq/page.tsx +0 -54
  106. package/templates/apps/web/app/[locale]/features/[slug]/page.tsx +0 -54
  107. package/templates/apps/web/app/[locale]/features/__tests__/hub-children.test.tsx +0 -32
  108. package/templates/apps/web/app/[locale]/features/page.tsx +0 -50
  109. package/templates/apps/web/app/[locale]/for/[slug]/page.tsx +0 -54
  110. package/templates/apps/web/app/[locale]/for/__tests__/hub-children.test.tsx +0 -32
  111. package/templates/apps/web/app/[locale]/for/__tests__/page-renderer-migration.test.tsx +0 -90
  112. package/templates/apps/web/app/[locale]/for/page.tsx +0 -51
  113. package/templates/apps/web/app/[locale]/glossary/page.tsx +0 -53
  114. package/templates/apps/web/app/[locale]/how-to/[slug]/page.tsx +0 -50
  115. package/templates/apps/web/app/[locale]/how-to/__tests__/page-renderer-migration.test.tsx +0 -78
  116. package/templates/apps/web/app/[locale]/how-to/page.tsx +0 -50
  117. package/templates/apps/web/app/[locale]/integrations/[slug]/page.tsx +0 -54
  118. package/templates/apps/web/app/[locale]/integrations/__tests__/hub-children.test.tsx +0 -38
  119. package/templates/apps/web/app/[locale]/integrations/__tests__/page-renderer-migration.test.tsx +0 -141
  120. package/templates/apps/web/app/[locale]/integrations/page.tsx +0 -49
  121. package/templates/apps/web/app/[locale]/launch-service/page.tsx +0 -44
  122. package/templates/apps/web/app/[locale]/newsletter/__tests__/page.test.tsx +0 -236
  123. package/templates/apps/web/app/[locale]/newsletter/page.tsx +0 -179
  124. package/templates/apps/web/app/[locale]/page.tsx +0 -147
  125. package/templates/apps/web/app/[locale]/partners/[slug]/page.tsx +0 -45
  126. package/templates/apps/web/app/[locale]/partners/__tests__/hub-children.test.tsx +0 -32
  127. package/templates/apps/web/app/[locale]/partners/__tests__/page-renderer-migration.test.tsx +0 -125
  128. package/templates/apps/web/app/[locale]/partners/page.tsx +0 -49
  129. package/templates/apps/web/app/[locale]/portfolio/[slug]/page.tsx +0 -46
  130. package/templates/apps/web/app/[locale]/portfolio/__tests__/hub-children.test.tsx +0 -38
  131. package/templates/apps/web/app/[locale]/portfolio/page.tsx +0 -50
  132. package/templates/apps/web/app/[locale]/pricing/[slug]/__tests__/page.test.tsx +0 -324
  133. package/templates/apps/web/app/[locale]/pricing/[slug]/page.tsx +0 -87
  134. package/templates/apps/web/app/[locale]/pricing/__tests__/__snapshots__/unconnected.test.tsx.snap +0 -7
  135. package/templates/apps/web/app/[locale]/pricing/__tests__/offerings.test.tsx +0 -605
  136. package/templates/apps/web/app/[locale]/pricing/__tests__/page.test.tsx +0 -219
  137. package/templates/apps/web/app/[locale]/pricing/__tests__/pricing-pages.test.tsx +0 -215
  138. package/templates/apps/web/app/[locale]/pricing/__tests__/unconnected.test.tsx +0 -282
  139. package/templates/apps/web/app/[locale]/pricing/page.tsx +0 -120
  140. package/templates/apps/web/app/[locale]/privacy/page.tsx +0 -40
  141. package/templates/apps/web/app/[locale]/products/[slug]/page.tsx +0 -50
  142. package/templates/apps/web/app/[locale]/products/__tests__/hub-children.test.tsx +0 -32
  143. package/templates/apps/web/app/[locale]/products/__tests__/page-renderer-migration.test.tsx +0 -141
  144. package/templates/apps/web/app/[locale]/products/page.tsx +0 -49
  145. package/templates/apps/web/app/[locale]/projects/[slug]/page.tsx +0 -37
  146. package/templates/apps/web/app/[locale]/projects/__tests__/hub-children.test.tsx +0 -32
  147. package/templates/apps/web/app/[locale]/projects/__tests__/page-renderer-migration.test.tsx +0 -157
  148. package/templates/apps/web/app/[locale]/projects/page.tsx +0 -49
  149. package/templates/apps/web/app/[locale]/purchase-policy/page.tsx +0 -49
  150. package/templates/apps/web/app/[locale]/resources/[slug]/page.tsx +0 -54
  151. package/templates/apps/web/app/[locale]/resources/__tests__/hub-children.test.tsx +0 -38
  152. package/templates/apps/web/app/[locale]/resources/__tests__/page-renderer-migration.test.tsx +0 -151
  153. package/templates/apps/web/app/[locale]/resources/page.tsx +0 -49
  154. package/templates/apps/web/app/[locale]/services/[slug]/[child]/page.tsx +0 -68
  155. package/templates/apps/web/app/[locale]/services/[slug]/page.tsx +0 -88
  156. package/templates/apps/web/app/[locale]/services/__tests__/hub-children.test.tsx +0 -158
  157. package/templates/apps/web/app/[locale]/services/__tests__/page-renderer-migration.test.tsx +0 -187
  158. package/templates/apps/web/app/[locale]/services/__tests__/service-detail-sections.test.tsx +0 -224
  159. package/templates/apps/web/app/[locale]/services/__tests__/service-families.test.tsx +0 -368
  160. package/templates/apps/web/app/[locale]/services/page.tsx +0 -71
  161. package/templates/apps/web/app/[locale]/software/[slug]/page.tsx +0 -49
  162. package/templates/apps/web/app/[locale]/software/__tests__/page-renderer-migration.test.tsx +0 -81
  163. package/templates/apps/web/app/[locale]/software/page.tsx +0 -49
  164. package/templates/apps/web/app/[locale]/team/[slug]/page.tsx +0 -45
  165. package/templates/apps/web/app/[locale]/team/__tests__/hub-children.test.tsx +0 -32
  166. package/templates/apps/web/app/[locale]/team/__tests__/team-routes.test.tsx +0 -161
  167. package/templates/apps/web/app/[locale]/team/page.tsx +0 -50
  168. package/templates/apps/web/app/[locale]/tech-articles/[slug]/page.tsx +0 -54
  169. package/templates/apps/web/app/[locale]/tech-articles/__tests__/page-renderer-migration.test.tsx +0 -82
  170. package/templates/apps/web/app/[locale]/tech-articles/page.tsx +0 -49
  171. package/templates/apps/web/app/[locale]/templates/[slug]/__tests__/page.test.tsx +0 -203
  172. package/templates/apps/web/app/[locale]/templates/[slug]/page.tsx +0 -81
  173. package/templates/apps/web/app/[locale]/templates/__tests__/page.test.tsx +0 -237
  174. package/templates/apps/web/app/[locale]/templates/page.tsx +0 -114
  175. package/templates/apps/web/app/[locale]/terms/page.tsx +0 -40
  176. package/templates/apps/web/app/[locale]/testimonials/__tests__/page-renderer-migration.test.tsx +0 -85
  177. package/templates/apps/web/app/[locale]/testimonials/page.tsx +0 -51
  178. package/templates/apps/web/app/[locale]/thanks/[slug]/__tests__/page.test.tsx +0 -136
  179. package/templates/apps/web/app/[locale]/thanks/[slug]/page.tsx +0 -39
  180. package/templates/apps/web/app/[locale]/unsubscribe/__tests__/unsubscribe-rsc-boundary.test.tsx +0 -226
  181. package/templates/apps/web/app/[locale]/unsubscribe/__tests__/unsubscribe.test.tsx +0 -217
  182. package/templates/apps/web/app/[locale]/unsubscribe/page.tsx +0 -106
  183. package/templates/apps/web/app/[locale]/unsubscribe/unsubscribe-button.tsx +0 -94
  184. package/templates/apps/web/app/[locale]/unsubscribe/unsubscribe.actions.ts +0 -55
  185. package/templates/apps/web/app/[locale]/vs/[slug]/__tests__/page.test.tsx +0 -100
  186. package/templates/apps/web/app/[locale]/vs/[slug]/page.tsx +0 -60
  187. package/templates/apps/web/app/[locale]/whitepapers/[slug]/page.tsx +0 -54
  188. package/templates/apps/web/app/[locale]/whitepapers/__tests__/page-renderer-migration.test.tsx +0 -82
  189. package/templates/apps/web/app/[locale]/whitepapers/page.tsx +0 -49
  190. package/templates/apps/web/app/[locale]/working-agreement/__tests__/page.test.tsx +0 -63
  191. package/templates/apps/web/app/[locale]/working-agreement/page.tsx +0 -41
  192. package/templates/apps/web/lib/__tests__/hub-children.fixtures.ts +0 -279
  193. package/templates/apps/web/lib/__tests__/route-family.test.ts +0 -57
  194. package/templates/apps/web/lib/__tests__/service-listing.test.ts +0 -111
  195. package/templates/apps/web/lib/__tests__/template-listing.test.ts +0 -158
  196. package/templates/apps/web/lib/hub-children.tsx +0 -351
  197. package/templates/apps/web/lib/meet-placeholder.ts +0 -5
  198. package/templates/apps/web/lib/posting-title.ts +0 -39
  199. package/templates/apps/web/lib/route-family.ts +0 -69
  200. package/templates/apps/web/lib/service-listing.ts +0 -89
  201. package/templates/apps/web/lib/template-listing.ts +0 -169
  202. package/templates/apps/web/src/lib/__tests__/lead-write.test.ts +0 -187
  203. package/templates/apps/web/src/lib/lead-write.ts +0 -90
@@ -1,325 +0,0 @@
1
- "use server";
2
-
3
- /**
4
- * captureLeadAction — the job page's apply form (#8746 D4, D5). Paired, like
5
- * /contact's action of the same name, with the `ailkCaptureLead` MCP tool: an
6
- * application is a lead written to `POST /v1/leads/submit`, so an agent
7
- * applies through the same capture route. A distinct `*Action` name would
8
- * claim a capability with no MCP twin (`apps/mcp/__tests__/parity.test.ts`).
9
- *
10
- * The page binds the posting's slug as the first argument
11
- * (`captureLeadAction.bind(null, slug)`); it travels as the lead's hidden
12
- * `job` value and must be a slug. Bound arguments round-trip through the
13
- * browser, so it is attribution, never authorization.
14
- *
15
- * The lead (#8746 AC-5): source `flow:job-application` — always, so it is an
16
- * Inbox submission of the Job application magnet (a post from the built-in
17
- * form too: the magnet is seeded into every workspace and never deleted) —
18
- * the applicant's email, and a payload of `name` (first + last),
19
- * `first_name`, `last_name`, the optional `phone` and `linkedin_url`, any
20
- * extra field the owner added to the magnet (bounded as /contact bounds
21
- * them), and `job`. `name`, `job` and the read fields are spread after the
22
- * extras, so no form field overrides them. The write goes through the site's
23
- * lead writer (`src/lib/lead-write.ts`), which adds `payload.site` and
24
- * `payload.page` ("careers") and sends no `siteId`. An accepted post tells
25
- * the API so (`consent: true`, #9130): the hub requires it of a
26
- * `flow:job-application` lead and records `payload.consent` itself.
27
- *
28
- * #10054 D6 — a posting that names its own magnet binds `{ job, flow }`
29
- * instead: the flow, slug-checked, is written as `payload.applicationFlow`
30
- * beside `job`, and no form field overrides it. The source stays
31
- * `flow:job-application`, so the hub still records consent.
32
- *
33
- * Checks, before any write: the honeypot (a filled one answers success and
34
- * sends nothing); first name, last name and email required; a LinkedIn URL,
35
- * when given, an http(s) URL — a bare domain gains `https://`, the flow
36
- * engine's `url` idiom; the terms box ticked, as the form block requires; and
37
- * the per-visitor limit /contact runs, in /contact's own bucket so a visitor's
38
- * lead posts stay at 30 per 10 minutes however they are split (with no
39
- * readable client address, /contact's shared, wider bucket — never skipped,
40
- * #9967). Outcomes map as /contact's do: the API's
41
- * `lead_capture_not_configured` or an unreachable API is `unavailable`, any
42
- * other refusal the generic error.
43
- */
44
-
45
- import { visitorForwardHeaders } from "@working-theory/api-client";
46
- import {
47
- LEAD_CAPTURE_HONEYPOT,
48
- type LeadCaptureFormState,
49
- } from "@working-theory/ui";
50
- import {
51
- accountEmailHintSchema,
52
- flowLeadSource,
53
- flowSlugSchema,
54
- JOB_APPLICATION_FLOW_SLUG,
55
- leadSubmitNextSchema,
56
- } from "@working-theory/validation";
57
- import { cookies, headers } from "next/headers";
58
- import { getLocale, getTranslations } from "next-intl/server";
59
- import { z } from "zod";
60
-
61
- import { accountInviteHref } from "../../../../lib/account-invite";
62
- import { runBotCheck } from "../../../../lib/bot-check";
63
- import {
64
- consentVisitorHeader,
65
- readConsentVisitor,
66
- } from "../../../../lib/consent-visitor";
67
- import { writeLead } from "../../../../src/lib/lead-write";
68
- import { takeVisitorLimit } from "../../../../src/lib/rate-limit";
69
-
70
- const GENERIC_ERROR = "Something went wrong, please try again.";
71
- const RATE_LIMITED =
72
- "Too many applications from here. Please try again in a few minutes.";
73
- const CONSENT_REQUIRED = "Please accept the terms to send your application.";
74
-
75
- const RATE_LIMIT_MAX_CALLS = 30;
76
- const RATE_LIMIT_WINDOW_MS = 10 * 60 * 1000;
77
- /** Outside a request scope there is no address: the shared bucket. */
78
- const NO_HEADERS = { get: () => null };
79
-
80
- const SOURCE = flowLeadSource(JOB_APPLICATION_FLOW_SLUG);
81
- const JOB_SLUG_RE = /^[a-z0-9][a-z0-9-]{0,127}$/;
82
- const HAS_SCHEME_RE = /^[a-z][a-z0-9+.-]*:\/\//i;
83
-
84
- /** Field names the action reads itself, or writes — never copied from the form. */
85
- const RESERVED_FIELDS = new Set([
86
- "first_name",
87
- "last_name",
88
- "email",
89
- "phone",
90
- "linkedin_url",
91
- "consent",
92
- "name",
93
- "job",
94
- "applicationFlow",
95
- "source",
96
- LEAD_CAPTURE_HONEYPOT,
97
- ]);
98
- const MAX_EXTRA_FIELDS = 20;
99
- const MAX_EXTRA_FIELD_LENGTH = 2000;
100
-
101
- const optionalText = (max: number) =>
102
- z.preprocess(
103
- (v) => (typeof v === "string" && v.trim() !== "" ? v.trim() : undefined),
104
- z.string().max(max).optional(),
105
- );
106
-
107
- /** A LinkedIn URL: blank is absent; a bare domain gains `https://`; only http(s). */
108
- const linkedinUrl = z.preprocess(
109
- (v) => {
110
- if (typeof v !== "string" || v.trim() === "") return undefined;
111
- const value = v.trim();
112
- return HAS_SCHEME_RE.test(value) ? value : `https://${value}`;
113
- },
114
- z
115
- .string()
116
- .max(2000)
117
- .refine((value) => {
118
- try {
119
- const url = new URL(value);
120
- return (
121
- (url.protocol === "https:" || url.protocol === "http:") &&
122
- url.hostname.includes(".") &&
123
- // No credentials: `https://linkedin.com@evil.example/` would show
124
- // the operator a LinkedIn-looking link to another host.
125
- url.username === "" &&
126
- url.password === ""
127
- );
128
- } catch {
129
- return false;
130
- }
131
- }, "Enter a valid URL.")
132
- .optional(),
133
- );
134
-
135
- const applicationSchema = z.object({
136
- first_name: z.string().trim().min(1, "Enter your first name.").max(100),
137
- last_name: z.string().trim().min(1, "Enter your last name.").max(100),
138
- email: z.string().trim().email("Enter a valid email address.").max(254),
139
- phone: optionalText(32),
140
- linkedin_url: linkedinUrl,
141
- });
142
-
143
- /** The extra fields, or `null` over the bounds. Files and `$ACTION_…` keys are skipped. */
144
- function extraFields(formData: FormData): Record<string, string> | null {
145
- const extra: Record<string, string> = {};
146
- let count = 0;
147
- for (const [key, value] of formData.entries()) {
148
- if (RESERVED_FIELDS.has(key) || key.startsWith("$ACTION")) continue;
149
- if (typeof value !== "string") continue;
150
- if (value.length > MAX_EXTRA_FIELD_LENGTH) return null;
151
- if (!Object.hasOwn(extra, key)) count += 1;
152
- if (count > MAX_EXTRA_FIELDS) return null;
153
- extra[key] = value;
154
- }
155
- return extra;
156
- }
157
-
158
- function isNotConfigured(res: { status: number; body: unknown }): boolean {
159
- return (
160
- res.status === 503 &&
161
- typeof res.body === "object" &&
162
- res.body !== null &&
163
- (res.body as { error?: unknown }).error === "lead_capture_not_configured"
164
- );
165
- }
166
-
167
- function isApiUnreachable(res: { status: number }): boolean {
168
- return res.status === 0 || res.status === 502 || res.status === 504;
169
- }
170
-
171
- const field = (formData: FormData, name: string): unknown =>
172
- formData.get(name) ?? undefined;
173
-
174
- /**
175
- * #8771 D7 — the thank-you's "Track this in your account" link, when the API
176
- * answered `next: { completion: "invite" }` and this site can build one; else
177
- * exactly `{ kind: "success" }`. The application is already written, so a
178
- * refusal or a throw anywhere here is still a success — an error would invite
179
- * a duplicate application.
180
- */
181
- async function successState(
182
- next: unknown,
183
- email: string,
184
- ): Promise<LeadCaptureFormState> {
185
- try {
186
- const parsed = leadSubmitNextSchema.safeParse(next);
187
- if (!parsed.success || parsed.data.completion !== "invite") {
188
- return { kind: "success" };
189
- }
190
- const hint = accountEmailHintSchema.safeParse(email);
191
- if (!hint.success) return { kind: "success" };
192
- const locale = await getLocale();
193
- const href = accountInviteHref(locale, hint.data);
194
- if (href === null) return { kind: "success" };
195
- const t = await getTranslations({ locale, namespace: "contact" });
196
- return { kind: "success", next: { href, label: t("trackInAccount") } };
197
- } catch {
198
- return { kind: "success" };
199
- }
200
- }
201
-
202
- /**
203
- * The bound posting: today's string `job`, or `{ job, flow }` (D6). `null`
204
- * for anything else — a bound argument comes back from the browser, so its
205
- * type is checked, not only its text.
206
- */
207
- function readPosting(posting: unknown): { job: string; applicationFlow?: string } | null {
208
- if (typeof posting === "string") return JOB_SLUG_RE.test(posting) ? { job: posting } : null;
209
- if (typeof posting !== "object" || posting === null) return null;
210
- const { job, flow } = posting as { job?: unknown; flow?: unknown };
211
- if (typeof job !== "string" || !JOB_SLUG_RE.test(job)) return null;
212
- if (!flowSlugSchema.safeParse(flow).success) return null;
213
- return { job, applicationFlow: flow as string };
214
- }
215
-
216
- export async function captureLeadAction(
217
- posting: string | { job: string; flow: string },
218
- _prevState: LeadCaptureFormState,
219
- formData: FormData,
220
- ): Promise<LeadCaptureFormState> {
221
- const honeypot = formData.get(LEAD_CAPTURE_HONEYPOT);
222
- if (typeof honeypot === "string" && honeypot !== "")
223
- return { kind: "success" };
224
-
225
- const attribution = readPosting(posting);
226
- if (attribution === null) {
227
- return { kind: "error", message: GENERIC_ERROR };
228
- }
229
- const { job, applicationFlow } = attribution;
230
-
231
- const fieldErrors: Record<string, string> = {};
232
- if (formData.get("consent") !== "true")
233
- fieldErrors.consent = CONSENT_REQUIRED;
234
-
235
- const parsed = applicationSchema.safeParse({
236
- first_name: field(formData, "first_name") ?? "",
237
- last_name: field(formData, "last_name") ?? "",
238
- email: field(formData, "email") ?? "",
239
- phone: field(formData, "phone"),
240
- linkedin_url: field(formData, "linkedin_url"),
241
- });
242
- if (!parsed.success) {
243
- for (const issue of parsed.error.issues) {
244
- const name = String(issue.path[0] ?? "form");
245
- fieldErrors[name] ??= issue.message;
246
- }
247
- }
248
- if (!parsed.success || Object.keys(fieldErrors).length > 0) {
249
- return { kind: "error", fieldErrors };
250
- }
251
-
252
- const extra = extraFields(formData);
253
- if (extra === null) return { kind: "error", message: GENERIC_ERROR };
254
-
255
- const { first_name, last_name, email, phone, linkedin_url } = parsed.data;
256
- const payload = {
257
- ...extra,
258
- name: `${first_name} ${last_name}`,
259
- first_name,
260
- last_name,
261
- ...(phone !== undefined && { phone }),
262
- ...(linkedin_url !== undefined && { linkedin_url }),
263
- job,
264
- ...(applicationFlow !== undefined && { applicationFlow }),
265
- };
266
-
267
- let requestHeaders: Awaited<ReturnType<typeof headers>> | undefined;
268
- try {
269
- requestHeaders = await headers();
270
- } catch {
271
- // No request scope — no forwarding, and the visitor is "unknown".
272
- }
273
-
274
- if (
275
- !takeVisitorLimit(
276
- "contact",
277
- requestHeaders ?? NO_HEADERS,
278
- RATE_LIMIT_MAX_CALLS,
279
- RATE_LIMIT_WINDOW_MS,
280
- ).allowed
281
- ) {
282
- return { kind: "error", message: RATE_LIMITED };
283
- }
284
-
285
- let init: { headers: Record<string, string> } | undefined;
286
- if (requestHeaders) {
287
- const forwarded = visitorForwardHeaders(
288
- requestHeaders,
289
- process.env.AILK_VISITOR_FORWARD_KEY,
290
- );
291
- if (forwarded) init = { headers: forwarded };
292
- }
293
- try {
294
- const visitorId = readConsentVisitor(await cookies());
295
- if (visitorId)
296
- init = {
297
- headers: {
298
- ...(init?.headers ?? {}),
299
- ...consentVisitorHeader(visitorId),
300
- },
301
- };
302
- } catch {
303
- // No request scope — submit with no visitor-link header.
304
- }
305
-
306
- // #9255 D4 — the spoke edge's bot check, immediately before the write.
307
- const botCheck = await runBotCheck({
308
- source: "bot-check",
309
- target: "captureLeadAction",
310
- scope: "write",
311
- });
312
- if (botCheck === "bot") return { kind: "error", message: GENERIC_ERROR };
313
- if (botCheck === "unavailable") return { kind: "unavailable" };
314
-
315
- const res = await writeLead(
316
- { source: SOURCE, email, page: "careers", consent: true, payload },
317
- init,
318
- );
319
- if (!res.ok) {
320
- if (isNotConfigured(res) || isApiUnreachable(res))
321
- return { kind: "unavailable" };
322
- return { kind: "error", message: GENERIC_ERROR };
323
- }
324
- return successState(res.body.next, email);
325
- }
@@ -1,120 +0,0 @@
1
- /**
2
- * jobApplicationFormFromConfig — the Job application magnet's field step, as
3
- * the shared `LeadCaptureForm` block renders it on a job page (#8746 D5).
4
- *
5
- * Reads the config's first step, which must be a `field` step holding fields
6
- * named `first_name`, `last_name` and `email` (what the apply action needs);
7
- * anything else answers `null` and the page renders the built-in form, the
8
- * seeded config itself (`jobApplicationFormFallback`).
9
- *
10
- * Each `text`, `email`, `tel`, `url`, `textarea` or `select` field is mapped
11
- * in order. First and last name sit side by side, then email and phone; every
12
- * other field runs full width. `consent` and `address` fields are not
13
- * rendered: the block draws its own terms box, labelled with the step's first
14
- * `consent` field's label when it has one (as /contact does). The step's
15
- * `copy.title` heads the section and its `copy.cta` is the submit label — or,
16
- * when step 1 has none, the last field step's (#8840 D3: the two-step seed
17
- * carries "Submit application" on step 2 only).
18
- *
19
- * Copy resolves with the one LocalizedString rule every flow surface shares
20
- * (`resolveLocalizedString`). Pure: no fetch, no React.
21
- */
22
- import type { ContactFormField } from "@working-theory/ui";
23
- import {
24
- jobApplicationFlowConfig,
25
- resolveLocalizedString,
26
- type FlowConfig,
27
- } from "@working-theory/validation";
28
-
29
- export interface JobApplicationFormView {
30
- /** The step's `copy.title`. */
31
- title: string;
32
- fields: ContactFormField[];
33
- /** The step's first consent field's label — `[Label](key)` tokens intact. */
34
- consentStatement?: string;
35
- /** The step's `copy.cta`, else the last field step's (#8840 D3). */
36
- submitLabel?: string;
37
- }
38
-
39
- type FieldStep = Extract<FlowConfig["steps"][number], { type: "field" }>;
40
- type FieldDef = FieldStep["fields"][number];
41
-
42
- const RENDERED_TYPES = [
43
- "text",
44
- "email",
45
- "tel",
46
- "url",
47
- "textarea",
48
- "select",
49
- ] as const;
50
- type RenderedType = (typeof RENDERED_TYPES)[number];
51
-
52
- const REQUIRED_NAMES = ["first_name", "last_name", "email"] as const;
53
- const PAIRED_NAMES: ReadonlySet<string> = new Set([
54
- "first_name",
55
- "last_name",
56
- "email",
57
- "phone",
58
- ]);
59
-
60
- function isRendered(type: FieldDef["inputType"]): type is RenderedType {
61
- return (RENDERED_TYPES as readonly string[]).includes(type);
62
- }
63
-
64
- export function jobApplicationFormFromConfig(
65
- config: FlowConfig,
66
- locale: string,
67
- ): JobApplicationFormView | null {
68
- const step = config.steps[0];
69
- if (step?.type !== "field") return null;
70
- const names = new Set(step.fields.map((f) => f.name));
71
- if (!REQUIRED_NAMES.every((name) => names.has(name))) return null;
72
-
73
- const resolve = (value: Record<string, string>): string =>
74
- resolveLocalizedString(value, locale, config.defaultLocale);
75
-
76
- const fields: ContactFormField[] = [];
77
- for (const field of step.fields) {
78
- if (!isRendered(field.inputType)) continue;
79
- fields.push({
80
- name: field.name,
81
- type: field.inputType,
82
- label: resolve(field.copy.label),
83
- required: field.required ?? false,
84
- ...(field.copy.placeholder !== undefined && {
85
- placeholder: resolve(field.copy.placeholder),
86
- }),
87
- ...(field.copy.help !== undefined && {
88
- helpText: resolve(field.copy.help),
89
- }),
90
- ...(field.options !== undefined && {
91
- options: field.options.map((o) => ({
92
- value: o.value,
93
- label: resolve(o.label),
94
- })),
95
- }),
96
- colSpan: PAIRED_NAMES.has(field.name) ? 1 : 2,
97
- });
98
- }
99
-
100
- const consent = step.fields.find((f) => f.inputType === "consent");
101
- const cta =
102
- step.copy.cta ??
103
- config.steps.filter((s): s is FieldStep => s.type === "field").at(-1)?.copy.cta;
104
- return {
105
- title: resolve(step.copy.title),
106
- fields,
107
- ...(consent !== undefined && {
108
- consentStatement: resolve(consent.copy.label),
109
- }),
110
- ...(cta !== undefined && { submitLabel: resolve(cta) }),
111
- };
112
- }
113
-
114
- /** The built-in form: the seeded magnet's own config. */
115
- export function jobApplicationFormFallback(
116
- locale: string,
117
- ): JobApplicationFormView {
118
- // The seeded config always maps — its test pins first_name, last_name, email.
119
- return jobApplicationFormFromConfig(jobApplicationFlowConfig, locale)!;
120
- }
@@ -1,73 +0,0 @@
1
- // JobPosting detail page. Reads the JobPosting MDX for the given slug, renders via
2
- // @working-theory/page-renderer, and emits a JSON-LD <script>. Unknown slugs 404 through renderPage.
3
- // Careers list at /careers links here; each job posting lives at /careers/<slug>.
4
- //
5
- // Under the posting, inside <main>, an Apply button (#8849 D8) opens
6
- // /careers/<slug>/apply — the multi-step walk where the `signal-collectors`
7
- // module is present (#8840 D11), else the Free apply page,
8
- // careers/[slug]/[action] (#8849 D7), which draws the one-step application
9
- // form this page used to draw under `#apply`. The posting's JSON-LD
10
- // ApplyAction targets the same URL (#8849 D3). The page makes no hub read.
11
- import type { getMdxSource as defaultGetMdxSource } from "@working-theory/page-renderer";
12
- import {
13
- getMdxSource as loadMdxSource,
14
- renderPage,
15
- renderPageMetadata,
16
- } from "@working-theory/page-renderer";
17
- import { Button, Container, Link, localeHref } from "@working-theory/ui";
18
- import type { Metadata } from "next";
19
- import { getTranslations } from "next-intl/server";
20
- import type { ReactElement } from "react";
21
-
22
- interface Props {
23
- params: Promise<{ locale: string; slug: string }>;
24
- getMdxSource?: typeof defaultGetMdxSource;
25
- }
26
-
27
- export async function generateMetadata({
28
- params,
29
- }: Pick<Props, "params">): Promise<Metadata> {
30
- const { locale, slug } = await params;
31
- return renderPageMetadata({ type: "JobPosting", slug, locale });
32
- }
33
-
34
- export default async function Page({
35
- params,
36
- getMdxSource,
37
- }: Props): Promise<ReactElement> {
38
- const { locale, slug } = await params;
39
- // A page that composes `sections[]` renders them (JSON-LD is built from
40
- // the same sections); a prose page renders its MDX body — the rule
41
- // /vs/[slug] applies (#10122).
42
- const source = await (getMdxSource ?? loadMdxSource)(
43
- "JobPosting",
44
- slug,
45
- locale,
46
- );
47
- const composed =
48
- source !== null &&
49
- Array.isArray((source.frontmatter as { sections?: unknown[] }).sections) &&
50
- ((source.frontmatter as { sections?: unknown[] }).sections?.length ?? 0) >
51
- 0;
52
- const t = await getTranslations({ locale, namespace: "careers" });
53
- return renderPage({
54
- type: "JobPosting",
55
- slug,
56
- locale,
57
- ...(composed ? {} : { bodyMode: "mdx-body" as const }),
58
- trailing: (
59
- <Container className="pb-section">
60
- <Button asChild size="big">
61
- <Link
62
- href={localeHref(locale, `/careers/${slug}/apply`)}
63
- variant="bare"
64
- data-testid="job-apply-cta"
65
- >
66
- {t("apply")}
67
- </Link>
68
- </Button>
69
- </Container>
70
- ),
71
- ...(getMdxSource !== undefined && { getMdxSource }),
72
- });
73
- }