@sdxc/kit 2026.10.16 → 2026.10.20

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 (358) hide show
  1. package/README.md +391 -20
  2. package/changelog.jsonl +1160 -1035
  3. package/config.schema.json +47 -1
  4. package/dist/author.d.ts +36 -0
  5. package/dist/author.js +107 -0
  6. package/dist/cli.js +12 -0
  7. package/dist/commands/create.js +9 -4
  8. package/dist/commands/deploy.d.ts +23 -0
  9. package/dist/commands/deploy.js +167 -0
  10. package/dist/commands/destroy.d.ts +22 -0
  11. package/dist/commands/destroy.js +92 -0
  12. package/dist/commands/doctor.d.ts +26 -0
  13. package/dist/commands/doctor.js +65 -0
  14. package/dist/commands/initializers.d.ts +16 -0
  15. package/dist/commands/initializers.js +23 -0
  16. package/dist/commands/make.d.ts +72 -6
  17. package/dist/commands/make.js +127 -19
  18. package/dist/commands/middleware.d.ts +16 -0
  19. package/dist/commands/middleware.js +21 -0
  20. package/dist/commands/models.d.ts +18 -0
  21. package/dist/commands/models.js +29 -0
  22. package/dist/commands/notes.d.ts +17 -0
  23. package/dist/commands/notes.js +27 -0
  24. package/dist/commands/routes.d.ts +25 -0
  25. package/dist/commands/routes.js +50 -0
  26. package/dist/commands/run.d.ts +18 -2
  27. package/dist/commands/run.js +35 -12
  28. package/dist/commands/scaffold.d.ts +29 -0
  29. package/dist/commands/scaffold.js +33 -0
  30. package/dist/commands/schedule.d.ts +16 -0
  31. package/dist/commands/schedule.js +21 -0
  32. package/dist/commands/stats.d.ts +16 -0
  33. package/dist/commands/stats.js +21 -0
  34. package/dist/commands/ui/update.d.ts +6 -3
  35. package/dist/commands/ui/update.js +24 -7
  36. package/dist/commands/upgrade.d.ts +3 -1
  37. package/dist/commands/upgrade.js +88 -23
  38. package/dist/config.d.ts +18 -0
  39. package/dist/config.js +28 -1
  40. package/dist/contract.d.ts +97 -3
  41. package/dist/contract.js +360 -26
  42. package/dist/create/templates.d.ts +8 -1
  43. package/dist/create/templates.js +26 -2
  44. package/dist/dependencies.d.ts +4 -1
  45. package/dist/dependencies.js +13 -1
  46. package/dist/deploy/plan.d.ts +49 -0
  47. package/dist/deploy/plan.js +68 -0
  48. package/dist/destroy.d.ts +40 -0
  49. package/dist/destroy.js +311 -0
  50. package/dist/doctor/check.d.ts +71 -0
  51. package/dist/doctor/check.js +53 -0
  52. package/dist/doctor/checks.d.ts +23 -0
  53. package/dist/doctor/checks.js +68 -0
  54. package/dist/doctor/define.d.ts +59 -0
  55. package/dist/doctor/define.js +16 -0
  56. package/dist/doctor/emails.d.ts +18 -0
  57. package/dist/doctor/emails.js +243 -0
  58. package/dist/doctor/env.d.ts +26 -0
  59. package/dist/doctor/env.js +88 -0
  60. package/dist/doctor/files.d.ts +14 -0
  61. package/dist/doctor/files.js +34 -0
  62. package/dist/doctor/fixture.d.ts +23 -0
  63. package/dist/doctor/fixture.js +46 -0
  64. package/dist/doctor/install.d.ts +17 -0
  65. package/dist/doctor/install.js +37 -0
  66. package/dist/doctor/installed.d.ts +11 -0
  67. package/dist/doctor/installed.js +79 -0
  68. package/dist/doctor/layout.d.ts +23 -0
  69. package/dist/doctor/layout.js +83 -0
  70. package/dist/doctor/migrations.d.ts +16 -0
  71. package/dist/doctor/migrations.js +96 -0
  72. package/dist/doctor/models.d.ts +13 -0
  73. package/dist/doctor/models.js +69 -0
  74. package/dist/doctor/pins.d.ts +15 -0
  75. package/dist/doctor/pins.js +79 -0
  76. package/dist/doctor/project.d.ts +58 -0
  77. package/dist/doctor/project.js +261 -0
  78. package/dist/doctor/remix.d.ts +14 -0
  79. package/dist/doctor/remix.js +44 -0
  80. package/dist/doctor/routes.d.ts +11 -0
  81. package/dist/doctor/routes.js +49 -0
  82. package/dist/doctor/typegen.d.ts +13 -0
  83. package/dist/doctor/typegen.js +57 -0
  84. package/dist/doctor/ui.d.ts +14 -0
  85. package/dist/doctor/ui.js +51 -0
  86. package/dist/init.d.ts +5 -3
  87. package/dist/init.js +15 -7
  88. package/dist/initializers.d.ts +25 -0
  89. package/dist/initializers.js +89 -0
  90. package/dist/lock.d.ts +2 -2
  91. package/dist/make/actions.d.ts +23 -0
  92. package/dist/make/actions.js +82 -0
  93. package/dist/make/declare.d.ts +32 -4
  94. package/dist/make/declare.js +405 -27
  95. package/dist/make/email.d.ts +23 -0
  96. package/dist/make/email.js +111 -0
  97. package/dist/make/from-fields.d.ts +30 -0
  98. package/dist/make/from-fields.js +162 -0
  99. package/dist/make/from-model.d.ts +39 -0
  100. package/dist/make/from-model.js +161 -0
  101. package/dist/make/generate.d.ts +16 -5
  102. package/dist/make/generate.js +43 -14
  103. package/dist/make/guard.d.ts +35 -0
  104. package/dist/make/guard.js +73 -0
  105. package/dist/make/imports.d.ts +6 -0
  106. package/dist/make/imports.js +19 -0
  107. package/dist/make/index.d.ts +47 -4
  108. package/dist/make/index.js +287 -25
  109. package/dist/make/kinds.d.ts +31 -3
  110. package/dist/make/kinds.js +82 -9
  111. package/dist/make/mount.d.ts +25 -0
  112. package/dist/make/mount.js +135 -0
  113. package/dist/make/schema-diff.d.ts +58 -0
  114. package/dist/make/schema-diff.js +609 -0
  115. package/dist/make/schema.d.ts +76 -0
  116. package/dist/make/schema.js +206 -0
  117. package/dist/make/stubs.d.ts +7 -5
  118. package/dist/make/stubs.js +16 -5
  119. package/dist/make/test.d.ts +43 -0
  120. package/dist/make/test.js +149 -0
  121. package/dist/make/trigger.d.ts +31 -0
  122. package/dist/make/trigger.js +163 -0
  123. package/dist/models.d.ts +42 -0
  124. package/dist/models.js +149 -0
  125. package/dist/notes.d.ts +28 -0
  126. package/dist/notes.js +66 -0
  127. package/dist/reference.d.ts +27 -0
  128. package/dist/reference.js +103 -0
  129. package/dist/releases.d.ts +9 -0
  130. package/dist/releases.js +29 -8
  131. package/dist/routes/chains.d.ts +34 -0
  132. package/dist/routes/chains.js +95 -0
  133. package/dist/routes/filter.d.ts +53 -0
  134. package/dist/routes/filter.js +147 -0
  135. package/dist/routes/format.d.ts +23 -0
  136. package/dist/routes/format.js +123 -0
  137. package/dist/routes/helpers.d.ts +21 -0
  138. package/dist/routes/helpers.js +165 -0
  139. package/dist/routes/index.d.ts +56 -0
  140. package/dist/routes/index.js +167 -0
  141. package/dist/routes/modules.d.ts +116 -0
  142. package/dist/routes/modules.js +235 -0
  143. package/dist/routes/parse.d.ts +161 -0
  144. package/dist/routes/parse.js +621 -0
  145. package/dist/routes/routers.d.ts +69 -0
  146. package/dist/routes/routers.js +327 -0
  147. package/dist/scaffold/fields.d.ts +129 -0
  148. package/dist/scaffold/fields.js +421 -0
  149. package/dist/scaffold/index.d.ts +37 -0
  150. package/dist/scaffold/index.js +613 -0
  151. package/dist/scaffold/render.d.ts +51 -0
  152. package/dist/scaffold/render.js +332 -0
  153. package/dist/schedule.d.ts +45 -0
  154. package/dist/schedule.js +124 -0
  155. package/dist/stats.d.ts +37 -0
  156. package/dist/stats.js +126 -0
  157. package/dist/testing.d.ts +12 -2
  158. package/dist/testing.js +22 -3
  159. package/dist/ui/commands.d.ts +10 -3
  160. package/dist/ui/commands.js +85 -15
  161. package/dist/ui/registry.d.ts +8 -8
  162. package/dist/upgrade/agents.d.ts +49 -0
  163. package/dist/upgrade/agents.js +110 -0
  164. package/dist/upgrade/changelog.d.ts +2 -2
  165. package/dist/upgrade/project.d.ts +4 -0
  166. package/dist/upgrade/project.js +11 -1
  167. package/dist/upgrade/prompt.d.ts +11 -0
  168. package/dist/upgrade/prompt.js +50 -7
  169. package/package.json +6 -4
  170. package/registry/ui/alert-dialog.json +2 -2
  171. package/registry/ui/attachment.json +2 -2
  172. package/registry/ui/calendar.json +2 -2
  173. package/registry/ui/color-picker.json +2 -2
  174. package/registry/ui/command.json +2 -2
  175. package/registry/ui/date-picker.json +2 -2
  176. package/registry/ui/date-range-picker.json +2 -2
  177. package/registry/ui/dialog.json +2 -2
  178. package/registry/ui/file-trigger.json +2 -2
  179. package/registry/ui/heading-scope.json +2 -2
  180. package/registry/ui/message-scroller.json +2 -2
  181. package/registry/ui/number-field.json +2 -2
  182. package/registry/ui/range-calendar.json +2 -2
  183. package/registry/ui/resizable.json +2 -2
  184. package/registry/ui/select.json +2 -2
  185. package/registry/ui/shared-element.json +2 -2
  186. package/stubs/command.stub +4 -0
  187. package/stubs/command.test.stub +3 -0
  188. package/stubs/controller.api.resource.stub +23 -0
  189. package/stubs/controller.api.stub +21 -0
  190. package/stubs/controller.api.test.stub +18 -0
  191. package/stubs/controller.form.stub +40 -10
  192. package/stubs/controller.form.test.stub +61 -0
  193. package/stubs/controller.resource.form.stub +67 -0
  194. package/stubs/controller.resource.stub +28 -0
  195. package/stubs/controller.stub +15 -8
  196. package/stubs/controller.test.stub +3 -0
  197. package/stubs/email.stub +15 -38
  198. package/stubs/email.test.stub +12 -7
  199. package/stubs/factory.stub +4 -1
  200. package/stubs/initializer.stub +2 -0
  201. package/stubs/initializer.test.stub +3 -0
  202. package/stubs/job.cron.stub +4 -0
  203. package/stubs/job.stub +4 -0
  204. package/stubs/job.test.stub +3 -0
  205. package/stubs/mcp.resource.stub +3 -0
  206. package/stubs/mcp.stub +3 -0
  207. package/stubs/mcp.test.stub +3 -0
  208. package/stubs/middleware.stub +6 -1
  209. package/stubs/middleware.test.stub +3 -0
  210. package/stubs/model.stub +12 -3
  211. package/stubs/model.test.stub +3 -0
  212. package/stubs/policy.test.stub +36 -7
  213. package/stubs/scaffold.api.create.stub +34 -0
  214. package/stubs/scaffold.api.create.test.stub +37 -0
  215. package/stubs/scaffold.api.destroy.stub +34 -0
  216. package/stubs/scaffold.api.destroy.test.stub +44 -0
  217. package/stubs/scaffold.api.index.stub +23 -0
  218. package/stubs/scaffold.api.index.test.stub +31 -0
  219. package/stubs/scaffold.api.show.stub +27 -0
  220. package/stubs/scaffold.api.show.test.stub +41 -0
  221. package/stubs/scaffold.api.update.stub +44 -0
  222. package/stubs/scaffold.api.update.test.stub +46 -0
  223. package/stubs/scaffold.command.create.stub +22 -0
  224. package/stubs/scaffold.command.create.test.stub +30 -0
  225. package/stubs/scaffold.command.delete.stub +20 -0
  226. package/stubs/scaffold.command.delete.test.stub +39 -0
  227. package/stubs/scaffold.command.list.stub +18 -0
  228. package/stubs/scaffold.command.list.test.stub +31 -0
  229. package/stubs/scaffold.command.show.stub +19 -0
  230. package/stubs/scaffold.command.show.test.stub +37 -0
  231. package/stubs/scaffold.controller.destroy.stub +35 -0
  232. package/stubs/scaffold.controller.destroy.test.stub +65 -0
  233. package/stubs/scaffold.controller.edit.stub +97 -0
  234. package/stubs/scaffold.controller.edit.test.stub +91 -0
  235. package/stubs/scaffold.controller.index.stub +55 -0
  236. package/stubs/scaffold.controller.index.test.stub +32 -0
  237. package/stubs/scaffold.controller.new.stub +70 -0
  238. package/stubs/scaffold.controller.new.test.stub +81 -0
  239. package/stubs/scaffold.controller.show.stub +59 -0
  240. package/stubs/scaffold.controller.show.test.stub +43 -0
  241. package/stubs/scaffold.factory.stub +16 -0
  242. package/stubs/scaffold.form.stub +75 -0
  243. package/stubs/scaffold.mcp.create.stub +24 -0
  244. package/stubs/scaffold.mcp.create.test.stub +36 -0
  245. package/stubs/scaffold.mcp.delete.stub +31 -0
  246. package/stubs/scaffold.mcp.delete.test.stub +43 -0
  247. package/stubs/scaffold.mcp.get.stub +21 -0
  248. package/stubs/scaffold.mcp.get.test.stub +31 -0
  249. package/stubs/scaffold.mcp.list.stub +23 -0
  250. package/stubs/scaffold.mcp.list.test.stub +25 -0
  251. package/stubs/scaffold.mcp.update.stub +37 -0
  252. package/stubs/scaffold.mcp.update.test.stub +40 -0
  253. package/stubs/scaffold.migration.stub +2 -0
  254. package/stubs/scaffold.model.stub +35 -0
  255. package/stubs/scaffold.model.test.stub +25 -0
  256. package/stubs/scaffold.test-database.stub +33 -0
  257. package/stubs/scaffold.test-mcp.stub +92 -0
  258. package/stubs/scaffold.validator.stub +18 -0
  259. package/stubs/scaffold.validator.test.stub +26 -0
  260. package/stubs/service.stub +4 -0
  261. package/stubs/service.test.stub +3 -0
  262. package/stubs/validator.stub +3 -0
  263. package/stubs/validator.test.stub +3 -0
  264. package/templates/app/.env.example +16 -0
  265. package/templates/app/AGENTS.md +163 -0
  266. package/templates/app/CLAUDE.md +1 -0
  267. package/templates/app/README.md +79 -37
  268. package/templates/app/app/commands/about.test.ts +1 -1
  269. package/templates/app/app/commands/console.test.ts +26 -0
  270. package/templates/app/app/commands/console.ts +19 -0
  271. package/templates/app/app/commands/db/console.ts +6 -0
  272. package/templates/app/app/commands/db/fresh.test.ts +57 -0
  273. package/templates/app/app/commands/db/fresh.ts +37 -0
  274. package/templates/app/app/commands/db/migrate.test.ts +46 -0
  275. package/templates/app/app/commands/db/migrate.ts +88 -0
  276. package/templates/app/app/commands/db/prepare.test.ts +39 -0
  277. package/templates/app/app/commands/db/prepare.ts +35 -0
  278. package/templates/app/app/commands/db/seed.test.ts +38 -0
  279. package/templates/app/app/commands/db/seed.ts +26 -0
  280. package/templates/app/app/commands/deploy.test.ts +34 -0
  281. package/templates/app/app/commands/deploy.ts +18 -0
  282. package/templates/app/app/commands/emails/preview.test.tsx +63 -0
  283. package/templates/app/app/commands/emails/preview.ts +24 -0
  284. package/templates/app/app/commands/index.ts +72 -1
  285. package/templates/app/app/commands/typegen.test.ts +17 -0
  286. package/templates/app/app/commands/typegen.ts +16 -0
  287. package/templates/app/app/emails/index.ts +10 -0
  288. package/templates/app/app/http/controllers/api/health.tsx +15 -0
  289. package/templates/app/app/http/controllers/api/not-found.tsx +16 -0
  290. package/templates/app/app/http/controllers/api/openapi.tsx +17 -0
  291. package/templates/app/app/http/controllers/home.tsx +21 -13
  292. package/templates/app/app/http/controllers/mcp.tsx +16 -0
  293. package/templates/app/app/http/controllers/not-found.tsx +23 -18
  294. package/templates/app/app/http/controllers/robots.test.ts +18 -0
  295. package/templates/app/app/http/controllers/robots.ts +24 -0
  296. package/templates/app/app/http/controllers/sitemap.test.ts +28 -0
  297. package/templates/app/app/http/controllers/sitemap.ts +25 -0
  298. package/templates/app/app/http/middleware/access.test.ts +43 -0
  299. package/templates/app/app/http/middleware/access.ts +41 -0
  300. package/templates/app/app/http/middleware/api.ts +19 -0
  301. package/templates/app/app/http/middleware/page.test.ts +43 -0
  302. package/templates/app/app/http/middleware/page.ts +51 -0
  303. package/templates/app/app/http/middleware/server-timing.test.ts +15 -0
  304. package/templates/app/app/http/middleware/server-timing.ts +42 -0
  305. package/templates/app/app/initializers/assets.ts +1 -1
  306. package/templates/app/app/initializers/captcha.ts +11 -0
  307. package/templates/app/app/initializers/cli.ts +68 -2
  308. package/templates/app/app/initializers/database.test.ts +18 -0
  309. package/templates/app/app/initializers/database.ts +18 -0
  310. package/templates/app/app/initializers/dispatcher.ts +26 -0
  311. package/templates/app/app/initializers/honeypot.ts +11 -0
  312. package/templates/app/app/initializers/i18n.test.ts +16 -0
  313. package/templates/app/app/initializers/i18n.ts +28 -0
  314. package/templates/app/app/initializers/local-database.test.ts +33 -0
  315. package/templates/app/app/initializers/local-database.ts +53 -0
  316. package/templates/app/app/initializers/mail-transport.test.ts +27 -0
  317. package/templates/app/app/initializers/mail-transport.ts +26 -0
  318. package/templates/app/app/initializers/mail.test.ts +27 -0
  319. package/templates/app/app/initializers/mail.ts +19 -0
  320. package/templates/app/app/initializers/mcp.ts +1 -1
  321. package/templates/app/app/initializers/openapi.ts +21 -0
  322. package/templates/app/app/initializers/router.test.ts +68 -0
  323. package/templates/app/app/initializers/router.tsx +81 -25
  324. package/templates/app/app/initializers/seo.ts +15 -0
  325. package/templates/app/app/initializers/session.test.ts +34 -0
  326. package/templates/app/app/initializers/session.ts +29 -0
  327. package/templates/app/app/initializers/spam.ts +10 -0
  328. package/templates/app/app/jobs/email.test.tsx +70 -0
  329. package/templates/app/app/jobs/email.ts +16 -0
  330. package/templates/app/app/jobs/index.ts +6 -2
  331. package/templates/app/app/models/index.ts +10 -0
  332. package/templates/app/app/policies/abilities.ts +13 -0
  333. package/templates/app/app/policies/policy.test.ts +15 -0
  334. package/templates/app/app/policies/policy.ts +30 -0
  335. package/templates/app/app/services/commands.ts +30 -0
  336. package/templates/app/app/services/migrations.test.ts +92 -0
  337. package/templates/app/app/services/migrations.ts +117 -0
  338. package/templates/app/app/test/cloudflare-workers.ts +25 -0
  339. package/templates/app/app/test/local-database.ts +67 -0
  340. package/templates/app/app/test/session.ts +28 -0
  341. package/templates/app/bootstrap/cli.ts +1 -1
  342. package/templates/app/bootstrap/console.ts +13 -0
  343. package/templates/app/bootstrap/worker.ts +4 -4
  344. package/templates/app/cloudflare.config.ts +30 -2
  345. package/templates/app/config/constants.ts +19 -0
  346. package/templates/app/config/problems.ts +24 -0
  347. package/templates/app/config/security-policy.ts +34 -0
  348. package/templates/app/config/security-txt.ts +28 -0
  349. package/templates/app/database/migrations/.gitkeep +0 -0
  350. package/templates/app/database/seed.ts +12 -0
  351. package/templates/app/package.json +37 -6
  352. package/templates/app/resources/layouts/document.tsx +28 -7
  353. package/templates/app/resources/locales/en.json +10 -0
  354. package/templates/app/routes/api.ts +29 -0
  355. package/templates/app/routes/web.ts +6 -4
  356. package/templates/app/vite.config.ts +4 -0
  357. package/stubs/policy.stub +0 -13
  358. package/templates/app/config/router-context.d.ts +0 -20
@@ -0,0 +1,51 @@
1
+ /**
2
+ * The middleware every page declares: the parsed form body, the cross-origin check a
3
+ * cookie-backed form relies on, the visitor's session, access and language, the honeypot every
4
+ * form submission must pass, the security headers, and the document's assets and renderer. A
5
+ * page controller passes it as its `middleware`, so only requests that render a document pay.
6
+ */
7
+
8
+ import { assets } from "@sdxc/assets-middleware";
9
+ import { honeypot } from "@sdxc/honeypot/middleware";
10
+ import i18n from "@sdxc/i18n/middleware";
11
+ import { securityHeaders } from "@sdxc/security-headers/middleware";
12
+ import { cop } from "remix/middleware/cop";
13
+ import { formData } from "remix/middleware/form-data";
14
+ import { render } from "remix/middleware/render";
15
+ import { session } from "remix/middleware/session";
16
+ import { createMiddleware } from "remix/router";
17
+
18
+ import access from "~/app/http/middleware/access";
19
+ import { assetResolver } from "~/app/initializers/assets";
20
+ import { honeypot as trap } from "~/app/initializers/honeypot";
21
+ import { FALLBACK_LANGUAGE, RESOURCES, SUPPORTED_LANGUAGES } from "~/app/initializers/i18n";
22
+ import { sessionCookie, sessionStorage } from "~/app/initializers/session";
23
+ import { SECURITY_POLICY } from "~/config/security-policy";
24
+
25
+ /**
26
+ * Publishes `ctx.formData`, `ctx.session`, `ctx.access`, `ctx.locale`, `ctx.intl`, `ctx.honeypot`,
27
+ * `ctx.securityHeaders`, `ctx.assets` and `ctx.render` on a page's context. A POST without valid honeypot fields is refused with a 400
28
+ * before the controller runs; the security headers come right before the assets and renderer.
29
+ */
30
+ export default createMiddleware(
31
+ formData(),
32
+ cop(),
33
+ session(sessionCookie, sessionStorage),
34
+ access,
35
+ i18n({
36
+ detection: {
37
+ supportedLanguages: SUPPORTED_LANGUAGES,
38
+ fallbackLanguage: FALLBACK_LANGUAGE,
39
+ sessionKey: "lng",
40
+ },
41
+ resources: RESOURCES,
42
+ }),
43
+ honeypot(trap),
44
+ securityHeaders(SECURITY_POLICY),
45
+ assets(assetResolver, {
46
+ stylesheets: "resources/layouts/document.tsx",
47
+ script: "bootstrap/browser.ts",
48
+ nonce: (ctx) => ctx.securityHeaders.nonce,
49
+ }),
50
+ render({ assets: assetResolver }),
51
+ );
@@ -0,0 +1,15 @@
1
+ /**
2
+ * The `Server-Timing` header every response carries, checked through the app's router.
3
+ */
4
+
5
+ import { describe, expect, test } from "vitest";
6
+
7
+ import { createWebRouter } from "~/app/initializers/router";
8
+
9
+ describe("serverTiming", () => {
10
+ test("reports how long the request took", async () => {
11
+ let response = await createWebRouter().fetch("https://example.com/api/health");
12
+
13
+ expect(response.headers.get("server-timing")).toMatch(/^app(;dur=[\d.]+)?$/);
14
+ });
15
+ });
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Publishes a `Server-Timing` collector on every request as `ctx.timing` and writes what it
3
+ * measured onto the response, so browser devtools show where a request spent its time:
4
+ * `await ctx.timing.measure("db", "listPosts", () => listPosts())`.
5
+ */
6
+
7
+ import type { Middleware } from "remix/router";
8
+
9
+ import { TimingCollector } from "@sdxc/server-timing";
10
+ import { createContextKey } from "remix/router";
11
+
12
+ declare module "remix/router" {
13
+ interface RequestContext {
14
+ /** The request's timings, sent as its `Server-Timing` header. */
15
+ timing: TimingCollector;
16
+ }
17
+ }
18
+
19
+ /** Reads the request's collector by key, for code holding a context whose chain is unknown. */
20
+ export const Timing: { defaultValue?: TimingCollector } = createContextKey<TimingCollector>();
21
+
22
+ /**
23
+ * Creates the middleware. The whole request is measured as `app`, recorded after every entry a
24
+ * handler adds; the header goes on a copy of the response, so a redirect or a proxied
25
+ * response with immutable headers carries it too.
26
+ */
27
+ export default function serverTiming(): Middleware<{
28
+ key: typeof Timing;
29
+ value: TimingCollector;
30
+ property: "timing";
31
+ }> {
32
+ return async (ctx, next) => {
33
+ let timing = new TimingCollector();
34
+ ctx.set(Timing, timing, { property: "timing" });
35
+ let response = await timing.measure("app", "", () => next());
36
+ return new Response(response.body, {
37
+ status: response.status,
38
+ statusText: response.statusText,
39
+ headers: timing.toHeaders(new Headers(response.headers)),
40
+ });
41
+ };
42
+ }
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * The asset resolver, read from the manifest the Vite plugin writes: the source files
3
- * `vite dev` serves while editing, and the hashed files `vite build` emits. The document
3
+ * `vp dev` serves while editing, and the hashed files `vp build` emits. The document
4
4
  * links what it returns, so no tag names a file the build renamed.
5
5
  */
6
6
 
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The CAPTCHA a form asks a visitor to pass before its action runs: Cloudflare Turnstile,
3
+ * verified on the server with `TURNSTILE_SECRET_KEY`. A form renders the widget with
4
+ * `TURNSTILE_SITE_KEY` and its action declares `captcha(turnstile)`.
5
+ */
6
+
7
+ import { Turnstile } from "@sdxc/captcha/turnstile";
8
+ import { env } from "cloudflare:workers";
9
+
10
+ /** Verifies the token the widget writes into the form, once per submission. */
11
+ export const turnstile = new Turnstile({ secretKey: env.TURNSTILE_SECRET_KEY });
@@ -5,11 +5,22 @@
5
5
  */
6
6
 
7
7
  import { createCLI, lazy } from "@sdxc/cli";
8
+ import { models } from "@sdxc/data-model/cli";
9
+ import { Database, database } from "@sdxc/database-middleware/cli";
10
+ import i18n from "@sdxc/i18n/middleware/cli";
8
11
  import { createLogger } from "@sdxc/logger";
9
12
  import { log } from "@sdxc/logger/middleware/cli";
13
+ import mailer from "@sdxc/mail/middleware/cli";
14
+ import { PrintTransport } from "@sdxc/mail/print";
15
+ import { trace } from "@sdxc/trace-context/middleware/cli";
10
16
 
11
17
  import commandset from "~/app/commands";
18
+ import { FALLBACK_LANGUAGE, RESOURCES, SUPPORTED_LANGUAGES } from "~/app/initializers/i18n";
19
+ import { openLocalDatabase } from "~/app/initializers/local-database";
12
20
  import { logger } from "~/app/initializers/logger";
21
+ import { mail } from "~/app/initializers/mail";
22
+ import registry from "~/app/models";
23
+ import { MAIL_FROM } from "~/config/constants";
13
24
 
14
25
  import manifest from "../../package.json" with { type: "json" };
15
26
 
@@ -22,14 +33,69 @@ const COMMAND_LOGGER = createLogger({
22
33
  sink: (record) => process.stderr.write(`${JSON.stringify(record)}\n`),
23
34
  });
24
35
 
25
- /** The command line `bootstrap/cli.ts` runs and a command's test invokes. */
36
+ /**
37
+ * The command line `bootstrap/cli.ts` runs and a command's test invokes. A command reads the
38
+ * local database as `ctx.db` and its models as `ctx.models`, prints the email it sends to stderr
39
+ * through `ctx.email`, and writes its output in the language `LANG` names through `ctx.intl`.
40
+ */
26
41
  export const cli = createCLI({
27
42
  name: manifest.name,
28
43
  commands: commandset,
29
- middleware: [log(COMMAND_LOGGER)],
44
+ middleware: [
45
+ log(COMMAND_LOGGER),
46
+ trace(),
47
+ database(openLocalDatabase),
48
+ models(registry, (ctx) => ({ db: ctx.require(Database) })),
49
+ mailer({
50
+ transport: (ctx) => new PrintTransport({ write: (text) => ctx.stderr(text) }),
51
+ from: MAIL_FROM,
52
+ mail,
53
+ }),
54
+ i18n({
55
+ resources: RESOURCES,
56
+ supportedLanguages: SUPPORTED_LANGUAGES,
57
+ fallbackLanguage: FALLBACK_LANGUAGE,
58
+ }),
59
+ ],
30
60
  });
31
61
 
32
62
  cli.map(
33
63
  commandset.about,
34
64
  lazy(() => import("~/app/commands/about")),
35
65
  );
66
+ cli.map(
67
+ commandset.console,
68
+ lazy(() => import("~/app/commands/console")),
69
+ );
70
+ cli.map(
71
+ commandset.db.console,
72
+ lazy(() => import("~/app/commands/db/console")),
73
+ );
74
+ cli.map(
75
+ commandset.db.migrate,
76
+ lazy(() => import("~/app/commands/db/migrate")),
77
+ );
78
+ cli.map(
79
+ commandset.db.fresh,
80
+ lazy(() => import("~/app/commands/db/fresh")),
81
+ );
82
+ cli.map(
83
+ commandset.db.prepare,
84
+ lazy(() => import("~/app/commands/db/prepare")),
85
+ );
86
+ cli.map(
87
+ commandset.db.seed,
88
+ lazy(() => import("~/app/commands/db/seed")),
89
+ );
90
+ cli.map(
91
+ commandset.deploy,
92
+ lazy(() => import("~/app/commands/deploy")),
93
+ );
94
+ cli.map(
95
+ commandset.emails.preview,
96
+ lazy(() => import("~/app/commands/emails/preview")),
97
+ );
98
+ cli.map(
99
+ commandset.typegen,
100
+ lazy(() => import("~/app/commands/typegen")),
101
+ );
@@ -0,0 +1,18 @@
1
+ /**
2
+ * The database the router and the job dispatcher publish as `ctx.db`, run against the
3
+ * in-memory D1 stand-in tests receive as the `DB` binding.
4
+ */
5
+
6
+ import { describe, expect, test } from "vitest";
7
+
8
+ import { openDatabase } from "~/app/initializers/database";
9
+
10
+ describe("openDatabase", () => {
11
+ test("runs SQL through the DB binding", async () => {
12
+ let db = openDatabase();
13
+
14
+ let result = await db.exec("SELECT 41 + 1 AS answer");
15
+
16
+ expect(result.rows).toEqual([{ answer: 42 }]);
17
+ });
18
+ });
@@ -0,0 +1,18 @@
1
+ /**
2
+ * The app's database: `remix/data-table` over the `DB` D1 binding. The router and the job
3
+ * dispatcher publish it as `ctx.db`, so a controller, a job and a model bound with
4
+ * `Model.bind({ db: ctx.db })` all read and write the same tables.
5
+ */
6
+
7
+ import { createD1DatabaseAdapter } from "@sdxc/data-table-d1";
8
+ import { env } from "cloudflare:workers";
9
+ import { Database } from "remix/data-table";
10
+
11
+ /**
12
+ * Opens the database over the `DB` binding. Timestamps are written as epoch milliseconds,
13
+ * since `sdxc make model` types `created_at` and `updated_at` as integer columns and D1 binds
14
+ * no `Date`.
15
+ */
16
+ export function openDatabase(): Database {
17
+ return new Database(createD1DatabaseAdapter(env.DB), { now: () => Date.now() });
18
+ }
@@ -4,15 +4,41 @@
4
4
  * loader, so a module is imported only once a message for its job arrives.
5
5
  */
6
6
 
7
+ import type { JobDispatcherContext } from "@sdxc/jobs";
8
+
9
+ import { models } from "@sdxc/data-model/jobs";
10
+ import { Database } from "@sdxc/database-middleware";
11
+ import { database } from "@sdxc/database-middleware/jobs";
7
12
  import { createJobDispatcher } from "@sdxc/jobs";
8
13
  import * as cloudflare from "@sdxc/jobs/cloudflare";
14
+ import mailer from "@sdxc/mail/middleware/jobs";
9
15
  import { env } from "cloudflare:workers";
10
16
 
17
+ import { openDatabase } from "~/app/initializers/database";
11
18
  import { logger } from "~/app/initializers/logger";
19
+ import { mail } from "~/app/initializers/mail";
20
+ import { queue, transport } from "~/app/initializers/mail-transport";
21
+ import jobs from "~/app/jobs";
22
+ import registry from "~/app/models";
23
+ import { MAIL_FROM } from "~/config/constants";
12
24
 
13
25
  /** The dispatcher `bootstrap/worker.ts` hands queue batches and cron triggers to. */
14
26
  export const dispatcher = createJobDispatcher({
15
27
  logger,
16
28
  queue: cloudflare.queue(() => env.QUEUE),
29
+ middleware: [
30
+ database(openDatabase),
31
+ models(registry, (ctx) => ({ db: ctx.require(Database) })),
32
+ mailer({ transport, from: MAIL_FROM, mail, queue }),
33
+ ] as const,
17
34
  timeout: "5 minutes",
18
35
  });
36
+
37
+ dispatcher.map(jobs.email, () => import("~/app/jobs/email"));
38
+
39
+ declare module "@sdxc/jobs" {
40
+ /** Types every job handler's `ctx` with what the dispatcher's middleware publishes: `ctx.db`, `ctx.models` and `ctx.email`. */
41
+ interface JobTypes {
42
+ context: JobDispatcherContext<typeof dispatcher>;
43
+ }
44
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The honeypot every page form carries: a hidden trap field a person never fills, and a token
3
+ * signing when the form was rendered. The page middleware refuses a submission that fails
4
+ * either, so a form needs only to render the fields.
5
+ */
6
+
7
+ import { Honeypot } from "@sdxc/honeypot";
8
+ import { env } from "cloudflare:workers";
9
+
10
+ /** Signs with `HONEYPOT_SECRET`; set it with `cf workers secrets update` before deploying. */
11
+ export const honeypot = new Honeypot({ secret: env.HONEYPOT_SECRET });
@@ -0,0 +1,16 @@
1
+ /**
2
+ * The translator a job or an email uses, which reads the same bundles a page does.
3
+ */
4
+
5
+ import { describe, expect, test } from "vitest";
6
+
7
+ import { translate } from "~/app/initializers/i18n";
8
+
9
+ describe("translate", () => {
10
+ test("binds the fallback language for an unsupported one", () => {
11
+ let { locale, t } = translate("fr");
12
+
13
+ expect(locale).toBe("en");
14
+ expect(t("notFound.title")).toBe("Not found");
15
+ });
16
+ });
@@ -0,0 +1,28 @@
1
+ /**
2
+ * The app's languages and message bundles, in one place so the page middleware, a job and an
3
+ * email reach the same copy. Add a language by adding its bundle under `resources/locales/` and
4
+ * listing it in {@link SUPPORTED_LANGUAGES}.
5
+ */
6
+
7
+ import { createTranslator } from "@sdxc/i18n";
8
+
9
+ import en from "~/resources/locales/en.json";
10
+
11
+ /** The languages a page can render in; a request asking for any other gets the fallback. */
12
+ export const SUPPORTED_LANGUAGES = ["en"];
13
+
14
+ /** The language that answers a request asking for none the app speaks, and any key a bundle lacks. */
15
+ export const FALLBACK_LANGUAGE = "en";
16
+
17
+ /** The message bundles, one per supported language, as MessageFormat 2 strings. */
18
+ export const RESOURCES = { en };
19
+
20
+ /**
21
+ * Translates outside a request, such as in a job or an email, into the recipient's language:
22
+ * `translate(user.language).t("home.title")`. An unsupported language binds the fallback.
23
+ */
24
+ export const translate = createTranslator({
25
+ resources: RESOURCES,
26
+ supportedLanguages: SUPPORTED_LANGUAGES,
27
+ fallbackLanguage: FALLBACK_LANGUAGE,
28
+ });
@@ -0,0 +1,33 @@
1
+ /**
2
+ * The local database a command reads as `ctx.db`, opened in memory so the test leaves the
3
+ * project's own copy untouched.
4
+ */
5
+
6
+ import { createModel } from "@sdxc/data-model";
7
+ import { unwrap } from "@sdxc/result";
8
+ import { column as c, table } from "remix/data-table";
9
+ import { describe, expect, test } from "vitest";
10
+
11
+ import { openLocalDatabase } from "~/app/initializers/local-database";
12
+
13
+ /** A table with the timestamp columns `sdxc make model` writes. */
14
+ const POSTS = table({
15
+ name: "posts",
16
+ columns: { id: c.text().primaryKey(), created_at: c.integer(), updated_at: c.integer() },
17
+ timestamps: true,
18
+ });
19
+
20
+ describe("openLocalDatabase", () => {
21
+ test("writes timestamps as epoch milliseconds, as the Worker's database does", async () => {
22
+ let db = openLocalDatabase(":memory:");
23
+ await db.exec(
24
+ "CREATE TABLE posts (id TEXT PRIMARY KEY, created_at INTEGER NOT NULL, updated_at INTEGER NOT NULL)",
25
+ );
26
+
27
+ let posts = createModel(POSTS, {}).bind({ db });
28
+
29
+ let row = unwrap(await posts.create({ id: "p1" }));
30
+
31
+ expect(typeof row.created_at).toBe("number");
32
+ });
33
+ });
@@ -0,0 +1,53 @@
1
+ /**
2
+ * The local copy of the app's D1 database, opened as the SQLite file `bun dev` keeps it in, so a
3
+ * command reads and writes the rows the dev server serves. Miniflare names that file after the
4
+ * database id in `cloudflare.config.ts`, so it is found without starting the Worker runtime.
5
+ */
6
+
7
+ import { createHmac, createHash } from "node:crypto";
8
+ import { mkdirSync } from "node:fs";
9
+ import { dirname, join } from "node:path";
10
+
11
+ import type { Database } from "remix/data-table";
12
+
13
+ import { createSqliteDatabase } from "remix/data-table/sqlite";
14
+
15
+ import config from "../../cloudflare.config";
16
+ import manifest from "../../package.json" with { type: "json" };
17
+
18
+ /** The Durable Object namespace Miniflare stores every local D1 database under. */
19
+ const NAMESPACE = "miniflare-D1DatabaseObject";
20
+
21
+ /**
22
+ * Miniflare's object id for `name`: an HMAC-SHA256 of the name and an HMAC of that, both keyed by
23
+ * the namespace's SHA-256 and cut to 16 bytes, so one database id always maps to one file.
24
+ */
25
+ function objectId(namespace: string, name: string): string {
26
+ let key = createHash("sha256").update(namespace).digest();
27
+ let id = createHmac("sha256", key).update(name).digest().subarray(0, 16);
28
+ let mac = createHmac("sha256", key).update(id).digest().subarray(0, 16);
29
+ return Buffer.concat([id, mac]).toString("hex");
30
+ }
31
+
32
+ /** The project's root, which every path a command reads is resolved against. */
33
+ export const PROJECT_ROOT = join(import.meta.dirname, "../..");
34
+
35
+ /** The `DB` binding's id, as `cloudflare.config.ts` declares it, or its name until it has one. */
36
+ export const DATABASE_ID = config.worker.env.DB.id ?? config.worker.env.DB.name ?? manifest.name;
37
+
38
+ /** The SQLite file `bun dev` and `sdxc run db migrate` use for the `DB` binding. */
39
+ export const LOCAL_DATABASE_FILE = join(
40
+ PROJECT_ROOT,
41
+ ".cloudflare/state/v3/d1",
42
+ NAMESPACE,
43
+ `${objectId(NAMESPACE, DATABASE_ID)}.sqlite`,
44
+ );
45
+
46
+ /**
47
+ * Opens the local database, creating the file where `bun dev` will find it when none exists yet.
48
+ * Timestamps are written as epoch milliseconds, as the Worker's database writes them.
49
+ */
50
+ export function openLocalDatabase(filename = LOCAL_DATABASE_FILE): Database {
51
+ if (filename !== ":memory:") mkdirSync(dirname(filename), { recursive: true });
52
+ return createSqliteDatabase({ filename }, { now: () => Date.now() });
53
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * The app's mail transport, delivering into the in-memory `send_email` stand-in tests receive
3
+ * as the `EMAIL` binding.
4
+ */
5
+
6
+ import { Mailer } from "@sdxc/mail";
7
+ import { env } from "cloudflare:workers";
8
+ import { describe, expect, test } from "vitest";
9
+
10
+ import { transport } from "~/app/initializers/mail-transport";
11
+ import { MAIL_FROM } from "~/config/constants";
12
+
13
+ describe("transport", () => {
14
+ test("delivers a message through the EMAIL binding", async () => {
15
+ let mailer = new Mailer({ transport, from: MAIL_FROM });
16
+
17
+ await mailer.send({
18
+ to: { email: "ada@example.com" },
19
+ subject: "Welcome",
20
+ html: "<p>Hello.</p>",
21
+ });
22
+
23
+ expect(env.EMAIL).toMatchObject({
24
+ messages: [expect.objectContaining({ subject: "Welcome" })],
25
+ });
26
+ });
27
+ });
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Where the Worker's email goes: Cloudflare's `send_email` binding, which `bun dev` simulates and
3
+ * a deploy delivers through Email Routing, and the `email` job `ctx.email.queue()` hands
4
+ * deliveries to. Both run only in the Worker, so the command line never imports this module.
5
+ */
6
+
7
+ import type { QueuedEmail } from "@sdxc/mail";
8
+
9
+ import { CloudflareTransport } from "@sdxc/mail/cloudflare";
10
+ import { env } from "cloudflare:workers";
11
+
12
+ import jobs from "~/app/jobs";
13
+
14
+ /** Sends through the `EMAIL` binding, from an address on a domain Email Routing verified. */
15
+ export const transport = new CloudflareTransport(env.EMAIL);
16
+
17
+ /**
18
+ * Hands a queued email to the `email` job, which delivers it with retries. The dispatcher is
19
+ * imported when the first email is queued, since its own middleware imports this module.
20
+ *
21
+ * @param delivery - The declared email's name, its recipient, locale and props.
22
+ */
23
+ export async function queue(delivery: QueuedEmail): Promise<void> {
24
+ let { dispatcher } = await import("~/app/initializers/dispatcher");
25
+ await dispatcher.enqueue(jobs.email, delivery);
26
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * The email registry: every declared email has a template mapped, so a send never fails for
3
+ * an email `sdxc make email` declared but nothing maps.
4
+ */
5
+
6
+ import type { AnyEmailDeclaration } from "@sdxc/mail";
7
+
8
+ import { isEmailDeclaration } from "@sdxc/mail";
9
+ import { describe, expect, test } from "vitest";
10
+
11
+ import emails from "~/app/emails";
12
+ import { mail } from "~/app/initializers/mail";
13
+
14
+ /** Every declaration in the map, walking its groups. */
15
+ function declared(tree: object): AnyEmailDeclaration[] {
16
+ return Object.values(tree).flatMap((value: object) =>
17
+ isEmailDeclaration(value) ? [value] : declared(value),
18
+ );
19
+ }
20
+
21
+ describe("mail", () => {
22
+ test("maps a template for every declared email", () => {
23
+ let names = declared(emails).map((email) => email.name);
24
+
25
+ expect(mail.mapped.map((email) => email.name).sort()).toEqual(names.sort());
26
+ });
27
+ });
@@ -0,0 +1,19 @@
1
+ /**
2
+ * The email registry: every email `app/emails/index.ts` declares, mapped onto its template
3
+ * through `lazy()`, so a send imports only the template it renders. It holds no transport, so
4
+ * the Worker's mailers and the command line share it; `sdxc make email` adds the mapping.
5
+ */
6
+
7
+ import { createMail } from "@sdxc/mail";
8
+
9
+ import { translate } from "~/app/initializers/i18n";
10
+
11
+ /** The registry the router, the job dispatcher and the command line hand their mailers. */
12
+ export const mail = createMail({ translator: translate });
13
+
14
+ declare module "@sdxc/mail" {
15
+ /** Types the `t()` every template receives with the keys of the app's message bundles. */
16
+ interface MailTypes {
17
+ translate: ReturnType<typeof translate>["t"];
18
+ }
19
+ }
@@ -6,7 +6,7 @@
6
6
 
7
7
  import { createHandler } from "@sdxc/mcp";
8
8
 
9
- /** The handler the `/mcp` route forwards to. */
9
+ /** The server `app/http/controllers/mcp.ts` forwards each `/mcp` request to. */
10
10
  const mcp = createHandler({
11
11
  name: "app",
12
12
  version: "1.0.0",
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The API's OpenAPI document. Add each operation `routes/api.ts` declares, so
3
+ * `/api/openapi.json` lists every documented endpoint.
4
+ */
5
+
6
+ import { createDocument } from "@sdxc/openapi";
7
+
8
+ import problems from "~/config/problems";
9
+ import { HEALTH } from "~/routes/api";
10
+
11
+ /**
12
+ * Starts the document for the origin the API is served from, which OpenAPI requires as an
13
+ * absolute server URL; `build()` assembles it, failing on a contract it cannot express.
14
+ */
15
+ export function createApiDocument(origin: string) {
16
+ return createDocument({
17
+ info: { title: "App API", version: "1.0.0" },
18
+ servers: [{ url: origin }],
19
+ problems,
20
+ }).add(HEALTH);
21
+ }
@@ -0,0 +1,68 @@
1
+ /**
2
+ * The router's own middleware, checked through a request's log record: what every page and
3
+ * endpoint gets before its controller runs.
4
+ */
5
+
6
+ import { Log } from "@sdxc/logger";
7
+ import { describe, expect, test } from "vitest";
8
+
9
+ import { createWebRouter } from "~/app/initializers/router";
10
+ import { SECURITY_TXT } from "~/config/security-txt";
11
+
12
+ /** How far ahead of `Expires` security.txt must be renewed. */
13
+ const RENEWAL_WINDOW_MS = 30 * 24 * 60 * 60 * 1000;
14
+
15
+ /** Fetches `request` through the router and answers the log record it wrote. */
16
+ async function record(request: Request) {
17
+ let records: Array<Readonly<Record<string, unknown>>> = [];
18
+ let log = new Log({ kind: "request", sink: (written) => records.push(written) });
19
+ await log.run(() => createWebRouter().fetch(request));
20
+ return records[0];
21
+ }
22
+
23
+ describe("router", () => {
24
+ test("continues the caller's W3C trace", async () => {
25
+ let written = await record(
26
+ new Request("https://example.com/api/health", {
27
+ headers: { traceparent: "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01" },
28
+ }),
29
+ );
30
+
31
+ expect(written).toMatchObject({
32
+ trace_id: "4bf92f3577b34da6a3ce929d0e0e4736",
33
+ parent_span_id: "00f067aa0ba902b7",
34
+ });
35
+ });
36
+
37
+ test("redirects a path with a trailing slash to the canonical one", async () => {
38
+ let response = await createWebRouter().fetch("https://example.com/sitemap.xml/?page=2");
39
+
40
+ expect(response.status).toBe(308);
41
+ expect(response.headers.get("location")).toBe("https://example.com/sitemap.xml?page=2");
42
+ });
43
+
44
+ test("serves security.txt with its contact", async () => {
45
+ let response = await createWebRouter().fetch("https://example.com/.well-known/security.txt");
46
+
47
+ expect(response.status).toBe(200);
48
+ expect(await response.text()).toContain("Contact: mailto:security@example.com");
49
+ });
50
+
51
+ test("keeps security.txt current for at least another month", () => {
52
+ expect(SECURITY_TXT.expires.getTime() - Date.now()).toBeGreaterThan(RENEWAL_WINDOW_MS);
53
+ });
54
+
55
+ test("previews the mapped emails at /_emails while developing", async () => {
56
+ let response = await createWebRouter().fetch("https://example.com/_emails");
57
+
58
+ expect(response.status).toBe(200);
59
+ expect(await response.text()).toContain("Email previews");
60
+ });
61
+
62
+ test("redirects the www. host to the apex domain", async () => {
63
+ let response = await createWebRouter().fetch("https://www.example.com/sitemap.xml");
64
+
65
+ expect(response.status).toBe(308);
66
+ expect(response.headers.get("location")).toBe("https://example.com/sitemap.xml");
67
+ });
68
+ });