@sdxc/kit 2026.10.16 → 2026.10.17

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 (114) hide show
  1. package/README.md +1 -0
  2. package/changelog.jsonl +57 -0
  3. package/dist/author.d.ts +36 -0
  4. package/dist/author.js +107 -0
  5. package/dist/commands/create.js +9 -4
  6. package/dist/commands/run.d.ts +2 -2
  7. package/dist/commands/run.js +5 -3
  8. package/dist/contract.js +1 -1
  9. package/dist/create/templates.d.ts +8 -1
  10. package/dist/create/templates.js +25 -2
  11. package/dist/init.d.ts +5 -3
  12. package/dist/init.js +15 -7
  13. package/dist/make/declare.d.ts +4 -4
  14. package/dist/make/declare.js +124 -21
  15. package/dist/make/generate.js +8 -2
  16. package/dist/make/index.js +5 -1
  17. package/dist/make/kinds.d.ts +2 -1
  18. package/dist/make/kinds.js +3 -2
  19. package/dist/testing.d.ts +12 -2
  20. package/dist/testing.js +22 -3
  21. package/package.json +3 -3
  22. package/stubs/command.stub +4 -0
  23. package/stubs/command.test.stub +3 -0
  24. package/stubs/controller.api.stub +21 -0
  25. package/stubs/controller.api.test.stub +18 -0
  26. package/stubs/controller.form.stub +39 -9
  27. package/stubs/controller.form.test.stub +61 -0
  28. package/stubs/controller.stub +15 -8
  29. package/stubs/controller.test.stub +3 -0
  30. package/stubs/email.stub +12 -30
  31. package/stubs/email.test.stub +6 -1
  32. package/stubs/factory.stub +3 -0
  33. package/stubs/initializer.stub +2 -0
  34. package/stubs/initializer.test.stub +3 -0
  35. package/stubs/job.cron.stub +4 -0
  36. package/stubs/job.stub +4 -0
  37. package/stubs/job.test.stub +3 -0
  38. package/stubs/mcp.resource.stub +3 -0
  39. package/stubs/mcp.stub +3 -0
  40. package/stubs/mcp.test.stub +3 -0
  41. package/stubs/middleware.stub +6 -1
  42. package/stubs/middleware.test.stub +3 -0
  43. package/stubs/model.stub +10 -1
  44. package/stubs/model.test.stub +3 -0
  45. package/stubs/policy.stub +3 -0
  46. package/stubs/policy.test.stub +3 -0
  47. package/stubs/service.stub +4 -0
  48. package/stubs/service.test.stub +3 -0
  49. package/stubs/validator.stub +3 -0
  50. package/stubs/validator.test.stub +3 -0
  51. package/templates/app/.env.example +16 -0
  52. package/templates/app/README.md +62 -35
  53. package/templates/app/app/commands/about.test.ts +1 -1
  54. package/templates/app/app/commands/db/console.ts +6 -0
  55. package/templates/app/app/commands/db/migrate.test.ts +30 -0
  56. package/templates/app/app/commands/db/migrate.ts +55 -0
  57. package/templates/app/app/commands/index.ts +16 -0
  58. package/templates/app/app/commands/typegen.test.ts +17 -0
  59. package/templates/app/app/commands/typegen.ts +16 -0
  60. package/templates/app/app/http/controllers/api/health.tsx +15 -0
  61. package/templates/app/app/http/controllers/api/not-found.tsx +16 -0
  62. package/templates/app/app/http/controllers/api/openapi.tsx +17 -0
  63. package/templates/app/app/http/controllers/home.tsx +21 -13
  64. package/templates/app/app/http/controllers/mcp.tsx +16 -0
  65. package/templates/app/app/http/controllers/not-found.tsx +23 -18
  66. package/templates/app/app/http/controllers/robots.test.ts +18 -0
  67. package/templates/app/app/http/controllers/robots.ts +24 -0
  68. package/templates/app/app/http/controllers/sitemap.test.ts +28 -0
  69. package/templates/app/app/http/controllers/sitemap.ts +25 -0
  70. package/templates/app/app/http/middleware/api.ts +10 -0
  71. package/templates/app/app/http/middleware/page.test.ts +40 -0
  72. package/templates/app/app/http/middleware/page.ts +49 -0
  73. package/templates/app/app/http/middleware/server-timing.test.ts +15 -0
  74. package/templates/app/app/http/middleware/server-timing.ts +42 -0
  75. package/templates/app/app/initializers/assets.ts +1 -1
  76. package/templates/app/app/initializers/captcha.ts +11 -0
  77. package/templates/app/app/initializers/cli.ts +42 -2
  78. package/templates/app/app/initializers/database.test.ts +18 -0
  79. package/templates/app/app/initializers/database.ts +18 -0
  80. package/templates/app/app/initializers/dispatcher.ts +18 -0
  81. package/templates/app/app/initializers/honeypot.ts +11 -0
  82. package/templates/app/app/initializers/i18n.test.ts +16 -0
  83. package/templates/app/app/initializers/i18n.ts +28 -0
  84. package/templates/app/app/initializers/local-database.test.ts +33 -0
  85. package/templates/app/app/initializers/local-database.ts +53 -0
  86. package/templates/app/app/initializers/mail.test.ts +27 -0
  87. package/templates/app/app/initializers/mail.ts +11 -0
  88. package/templates/app/app/initializers/mcp.ts +1 -1
  89. package/templates/app/app/initializers/openapi.ts +21 -0
  90. package/templates/app/app/initializers/router.test.ts +61 -0
  91. package/templates/app/app/initializers/router.tsx +72 -26
  92. package/templates/app/app/initializers/seo.ts +15 -0
  93. package/templates/app/app/initializers/session.test.ts +34 -0
  94. package/templates/app/app/initializers/session.ts +29 -0
  95. package/templates/app/app/initializers/spam.ts +10 -0
  96. package/templates/app/app/models/index.ts +10 -0
  97. package/templates/app/app/services/migrations.test.ts +45 -0
  98. package/templates/app/app/services/migrations.ts +60 -0
  99. package/templates/app/app/test/cloudflare-workers.ts +25 -0
  100. package/templates/app/bootstrap/cli.ts +1 -1
  101. package/templates/app/bootstrap/worker.ts +4 -4
  102. package/templates/app/cloudflare.config.ts +29 -1
  103. package/templates/app/config/constants.ts +19 -0
  104. package/templates/app/config/problems.ts +24 -0
  105. package/templates/app/config/security-policy.ts +34 -0
  106. package/templates/app/config/security-txt.ts +28 -0
  107. package/templates/app/database/migrations/.gitkeep +0 -0
  108. package/templates/app/package.json +35 -5
  109. package/templates/app/resources/layouts/document.tsx +28 -7
  110. package/templates/app/resources/locales/en.json +10 -0
  111. package/templates/app/routes/api.ts +29 -0
  112. package/templates/app/routes/web.ts +6 -4
  113. package/templates/app/vite.config.ts +4 -0
  114. package/templates/app/config/router-context.d.ts +0 -20
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Applies a chain of SQL migrations the way `cf d1 migrations apply` does: in name order, each
3
+ * once, recorded in the same `d1_migrations` table, so local and remote databases agree on
4
+ * what ran whichever tool applied it.
5
+ */
6
+
7
+ import type { Result } from "@sdxc/result";
8
+
9
+ import { failure, success } from "@sdxc/result";
10
+
11
+ /** One migration file: its name, as `0001_CreatePosts.sql`, and its SQL. */
12
+ export interface Migration {
13
+ name: string;
14
+ sql: string;
15
+ }
16
+
17
+ /** The synchronous SQLite client a migration runs on; it runs several statements per call. */
18
+ export interface MigrationDatabase {
19
+ exec(sql: string): void;
20
+ query(sql: string): { all(): unknown[] };
21
+ }
22
+
23
+ /** The table D1 records applied migrations in, as Wrangler and `cf` create it. */
24
+ const JOURNAL = `CREATE TABLE IF NOT EXISTS "d1_migrations"(
25
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
26
+ name TEXT UNIQUE,
27
+ applied_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL
28
+ )`;
29
+
30
+ /**
31
+ * Runs every migration the journal lacks, each in its own transaction with its journal row, so
32
+ * a failing migration leaves the database as the previous one left it.
33
+ *
34
+ * @returns The names applied, in order; a failure names the migration that stopped the run.
35
+ */
36
+ export function applyMigrations(
37
+ database: MigrationDatabase,
38
+ migrations: readonly Migration[],
39
+ ): Result<string[], Error> {
40
+ database.exec(JOURNAL);
41
+ let rows = database.query("SELECT name FROM d1_migrations").all() as { name: string }[];
42
+ let applied = new Set(rows.map((row) => row.name));
43
+ let pending = [...migrations]
44
+ .filter((migration) => !applied.has(migration.name))
45
+ .sort((a, b) => a.name.localeCompare(b.name));
46
+
47
+ let names: string[] = [];
48
+ for (let migration of pending) {
49
+ try {
50
+ database.exec(
51
+ `BEGIN;\n${migration.sql}\n;INSERT INTO d1_migrations (name) VALUES ('${migration.name.replaceAll("'", "''")}');\nCOMMIT;`,
52
+ );
53
+ } catch (error) {
54
+ database.exec("ROLLBACK");
55
+ return failure(new Error(`${migration.name} failed`, { cause: error }));
56
+ }
57
+ names.push(migration.name);
58
+ }
59
+ return success(names);
60
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * The `cloudflare:workers` module under Vitest, which imports the app's modules in Node, outside
3
+ * the Worker runtime. It carries the development secrets `.env.example` lists, so a module that
4
+ * reads `env` at import loads the same way it does under `bun dev`. Its bindings are in-memory
5
+ * stand-ins that behave like Cloudflare's, so a test reads and writes real SQL through `DB`.
6
+ */
7
+
8
+ import {
9
+ createD1Database,
10
+ createKVNamespace,
11
+ createRateLimit,
12
+ createSendEmail,
13
+ } from "@sdxc/cloudflare-mocks";
14
+
15
+ /** The bindings and secrets the app reads, with the values a project starts with for development. */
16
+ export const env = {
17
+ DB: createD1Database(),
18
+ EMAIL: createSendEmail(),
19
+ RATE_LIMITER: createRateLimit(),
20
+ SESSIONS: createKVNamespace(),
21
+ SESSION_SECRET: "development-session-secret",
22
+ HONEYPOT_SECRET: "development-honeypot-secret",
23
+ TURNSTILE_SITE_KEY: "1x00000000000000000000AA",
24
+ TURNSTILE_SECRET_KEY: "1x0000000000000000000000000000000AA",
25
+ } as Partial<Cloudflare.Env> as Cloudflare.Env;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * The command line's entry point, started by `bun run cli` or `sdxc run`: it runs the command
2
+ * The command line's entry point, started by `sdxc run`: it runs the command
3
3
  * the arguments name and exits with its code. The Worker never imports it, so no command ships
4
4
  * in the server build.
5
5
  */
@@ -1,7 +1,7 @@
1
1
  /**
2
- * The Worker's entry point. `fetch` builds the router and forwards the request to it, and
3
- * `queue` hands each delivered batch to the job dispatcher, so every request and every job
4
- * reaches the app through the initializers that configure it.
2
+ * The Worker's entry point. `fetch` forwards each request to the router, which serves pages
3
+ * and the API alike, and `queue` hands each delivered batch to the job dispatcher, so every
4
+ * request and every job reaches the app through the initializers that configure it.
5
5
  */
6
6
 
7
7
  import * as cloudflare from "@sdxc/jobs/cloudflare";
@@ -13,7 +13,7 @@ import { createWebRouter } from "~/app/initializers/router";
13
13
  const JOBS = cloudflare.worker(dispatcher);
14
14
 
15
15
  export default {
16
- /** Answers a request through the web router. */
16
+ /** Answers a request through the router. */
17
17
  async fetch(request) {
18
18
  let router = createWebRouter();
19
19
  return await router.fetch(request);
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Cloudflare configuration for the Worker, read by `cf` and the Vite plugin alike. Every
3
- * binding and trigger the app reads is declared here, so `bun cf:typegen` types `env` from
3
+ * binding and trigger the app reads is declared here, so `sdxc run typegen` types `env` from
4
4
  * this file and local development simulates exactly what production provides.
5
5
  */
6
6
 
@@ -21,8 +21,36 @@ export default defineConfig({
21
21
  */
22
22
  triggers: [triggers.queue({ name: manifest.name })],
23
23
  env: {
24
+ /**
25
+ * The app's database. `cf d1 create <name>` prints the id to put here, where the
26
+ * `sdxc run db` commands read it; until then, `bun dev` runs on a local copy.
27
+ */
28
+ DB: bindings.d1({ name: manifest.name, id: "00000000-0000-4000-8000-000000000000" }),
29
+ /**
30
+ * Sends the app's email. Cloudflare delivers only from an address on a domain with Email
31
+ * Routing enabled, so set `MAIL_FROM` in `config/constants.ts` to one before deploying.
32
+ */
33
+ EMAIL: bindings.sendEmail(),
24
34
  /** Where the job dispatcher enqueues; `cf queues create <name>` before the first deploy. */
25
35
  QUEUE: bindings.queue({ name: manifest.name }),
36
+ /**
37
+ * 100 requests per minute per client address, across every route. The router's
38
+ * adapter declares the same budget for the `RateLimit` headers; keep the two in step.
39
+ */
40
+ RATE_LIMITER: bindings.rateLimit({ namespace: "1001", simple: { limit: 100, period: 60 } }),
41
+ /**
42
+ * Visitors' sessions. `cf kv namespace create <name>` prints the id to put here; until
43
+ * then, `bun dev` keeps sessions in a local copy.
44
+ */
45
+ SESSIONS: bindings.kv({ id: "00000000000000000000000000000000" }),
46
+ /** Signs the session cookie. */
47
+ SESSION_SECRET: bindings.secret(),
48
+ /** Signs the honeypot fields every page form carries. */
49
+ HONEYPOT_SECRET: bindings.secret(),
50
+ /** The Turnstile widget's site key, which a form renders. */
51
+ TURNSTILE_SITE_KEY: bindings.secret(),
52
+ /** Verifies the Turnstile token a form submits. */
53
+ TURNSTILE_SECRET_KEY: bindings.secret(),
26
54
  },
27
55
  },
28
56
  });
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Values the app is configured with that never change between requests. Edit them when the app
3
+ * gets its own domain, since links and identifiers built from them are published.
4
+ */
5
+
6
+ /** The origin the app is published at: canonical links, the sitemap and robots.txt name it. */
7
+ export const SITE_URL = "https://example.com";
8
+
9
+ /** The app's name, as `og:site_name` and structured data publish it. */
10
+ export const SITE_NAME = "App";
11
+
12
+ /** The description a page without its own publishes, in search results and link previews. */
13
+ export const SITE_DESCRIPTION = "A Remix app on Cloudflare Workers.";
14
+
15
+ /** Where problem `type` URIs point; each problem's slug follows it, so it ends in `/`. */
16
+ export const PROBLEMS_URL = "https://example.com/problems/";
17
+
18
+ /** Who the app's email comes from: an address on a domain Cloudflare Email Routing verified. */
19
+ export const MAIL_FROM = { email: "no-reply@example.com", name: "App" };
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Every problem the API answers with, by name. A handler returns `problems.<name>()` and the
3
+ * OpenAPI document publishes each entry, so a client branches on a `type` the server declared.
4
+ */
5
+
6
+ import * as s from "@sdxc/json-schema";
7
+ import { defineProblems, ISSUES_SCHEMA } from "@sdxc/problem";
8
+
9
+ import { PROBLEMS_URL } from "~/config/constants";
10
+
11
+ export default defineProblems(PROBLEMS_URL, {
12
+ notFound: { slug: "not-found", status: 404, title: "The resource does not exist" },
13
+ tooManyRequests: {
14
+ slug: "too-many-requests",
15
+ status: 429,
16
+ title: "Too many requests from this address",
17
+ },
18
+ validationError: {
19
+ slug: "validation-error",
20
+ status: 422,
21
+ title: "The request failed validation",
22
+ extensions: s.object({ errors: ISSUES_SCHEMA }),
23
+ },
24
+ });
@@ -0,0 +1,34 @@
1
+ /**
2
+ * The security headers every page is sent with: a Content-Security-Policy that admits this
3
+ * origin and the response's nonce, and the headers that keep the page out of frames and its
4
+ * referrer and device APIs to itself. Name an origin here before a page loads from it.
5
+ */
6
+
7
+ import type { SecurityHeaders } from "@sdxc/security-headers";
8
+
9
+ /** Where Cloudflare Turnstile loads its script and renders its challenge frame. */
10
+ const TURNSTILE_ORIGIN = "https://challenges.cloudflare.com";
11
+
12
+ /** The policy `app/http/middleware/page.ts` applies to every page response. */
13
+ export const SECURITY_POLICY: SecurityHeaders.Policy = {
14
+ contentSecurityPolicy: {
15
+ defaultSrc: ["self"],
16
+ /** The document's inline import map is admitted by the response's nonce. */
17
+ scriptSrc: ["self", "nonce", TURNSTILE_ORIGIN],
18
+ /** `css()` styles render as `<style>` elements while the page streams, before any nonce. */
19
+ styleSrc: ["self", "unsafe-inline"],
20
+ imgSrc: ["self", "data:"],
21
+ fontSrc: ["self"],
22
+ /** Same-origin requests, including the dev server's HMR socket. */
23
+ connectSrc: ["self"],
24
+ frameSrc: [TURNSTILE_ORIGIN],
25
+ formAction: ["self"],
26
+ frameAncestors: ["none"],
27
+ baseUri: ["none"],
28
+ objectSrc: ["none"],
29
+ },
30
+ strictTransportSecurity: { maxAge: 31_536_000 },
31
+ referrerPolicy: "strict-origin-when-cross-origin",
32
+ crossOriginOpenerPolicy: "same-origin",
33
+ permissionsPolicy: { camera: [], microphone: [], geolocation: [], payment: [], usb: [] },
34
+ };
@@ -0,0 +1,28 @@
1
+ /**
2
+ * The app's security.txt (RFC 9116), served at `/.well-known/security.txt` so a researcher who
3
+ * finds a vulnerability knows where to report it. Review it before `expires`; a test fails a
4
+ * month ahead so the file never goes stale.
5
+ */
6
+
7
+ import type { SecurityTxt } from "@sdxc/well-known/security-txt";
8
+
9
+ import { serve } from "@sdxc/well-known/middleware";
10
+ import { securityTxt } from "@sdxc/well-known/security-txt";
11
+
12
+ import { SITE_URL } from "~/config/constants";
13
+
14
+ /** Where reports go and until when this file is current; replace the contact with yours. */
15
+ export const SECURITY_TXT: SecurityTxt = {
16
+ contact: [new URL("mailto:security@example.com")],
17
+ expires: new Date("2027-10-15T00:00:00Z"),
18
+ encryption: [],
19
+ acknowledgments: [],
20
+ preferredLanguages: ["en"],
21
+ canonical: [new URL("/.well-known/security.txt", SITE_URL)],
22
+ policy: [],
23
+ hiring: [],
24
+ extensions: {},
25
+ };
26
+
27
+ /** The entry the router's `wellKnown()` serves the file through. */
28
+ export const securityTxtEntry = serve(securityTxt, () => SECURITY_TXT);
File without changes
@@ -3,36 +3,66 @@
3
3
  "private": true,
4
4
  "type": "module",
5
5
  "scripts": {
6
- "build": "vite build",
6
+ "build": "vp build",
7
7
  "cf:deploy": "cf deploy --prebuilt",
8
- "cf:typegen": "cf workers types",
9
8
  "check": "vp check",
10
9
  "cli": "bun ./bootstrap/cli.ts",
11
- "dev": "vite dev",
12
- "start": "vite preview",
10
+ "dev": "vp dev",
11
+ "start": "vp preview",
13
12
  "test": "vp test run",
14
13
  "typecheck": "tsc --noEmit"
15
14
  },
16
15
  "dependencies": {
17
16
  "@pitlane/assets": "0.1.0",
18
17
  "@sdxc/assets-middleware": "0.0.1",
18
+ "@sdxc/captcha": "0.0.1",
19
19
  "@sdxc/cli": "0.0.1",
20
+ "@sdxc/data-model": "0.0.1",
21
+ "@sdxc/data-table-d1": "0.0.1",
22
+ "@sdxc/database-middleware": "0.0.1",
23
+ "@sdxc/get-client-ip": "0.0.1",
24
+ "@sdxc/honeypot": "0.0.1",
25
+ "@sdxc/http": "0.0.1",
26
+ "@sdxc/i18n": "0.0.1",
20
27
  "@sdxc/jobs": "0.0.1",
28
+ "@sdxc/json-schema": "0.0.1",
21
29
  "@sdxc/lazy-route": "0.0.1",
22
30
  "@sdxc/logger": "0.0.1",
31
+ "@sdxc/mail": "0.0.1",
23
32
  "@sdxc/mcp": "0.0.1",
33
+ "@sdxc/no-www-middleware": "0.0.1",
34
+ "@sdxc/openapi": "0.0.1",
35
+ "@sdxc/problem": "0.0.1",
36
+ "@sdxc/rate-limit": "0.0.1",
37
+ "@sdxc/result": "0.0.1",
38
+ "@sdxc/robots": "0.0.1",
39
+ "@sdxc/security-headers": "0.0.1",
40
+ "@sdxc/seo": "0.0.1",
41
+ "@sdxc/server-timing": "0.0.1",
42
+ "@sdxc/session-storage-kv": "0.0.1",
43
+ "@sdxc/sitemap": "0.0.1",
44
+ "@sdxc/spam": "0.0.1",
45
+ "@sdxc/trace-context": "0.0.1",
46
+ "@sdxc/trailing-slash-middleware": "0.0.1",
24
47
  "@sdxc/ui": "0.0.1",
48
+ "@sdxc/user-agent": "0.0.1",
49
+ "@sdxc/well-known": "0.0.1",
25
50
  "remix": "3.0.0"
26
51
  },
27
52
  "devDependencies": {
28
53
  "@cloudflare/vite-plugin": "2.0.0-beta.sha-ad79608dd",
29
54
  "@pitlane/vite-plugin-remix": "0.8.0",
55
+ "@sdxc/cloudflare-mocks": "0.0.1",
56
+ "@sdxc/kit": "0.0.1",
30
57
  "@types/node": "^26.6.5",
31
58
  "cf": "1.0.0-beta.5",
32
59
  "typescript": "^6.0.3",
33
- "vite": "^8.3.4",
60
+ "vite": "npm:@voidzero-dev/vite-plus-core@0.3.3",
34
61
  "vite-plus": "0.3.3",
35
62
  "vitest": "4.1.11"
36
63
  },
64
+ "overrides": {
65
+ "vite": "npm:@voidzero-dev/vite-plus-core@0.3.3"
66
+ },
37
67
  "packageManager": "bun@1.4.2"
38
68
  }
@@ -1,15 +1,21 @@
1
1
  /**
2
- * The HTML document every page renders inside: the head tags, the page title, and the
2
+ * The HTML document every page renders inside: the head tags, the page's title, description,
3
+ * canonical link and link-preview tags, and the
3
4
  * stylesheets imported below in cascade order. The client entry is linked only by a page
4
5
  * that carries an island.
5
6
  */
6
7
 
7
8
  import type { DocumentAssets } from "@sdxc/assets-middleware";
9
+ import type { I18n } from "@sdxc/i18n";
8
10
  import type { Handle, RemixNode } from "remix/component";
9
11
 
12
+ import { IntlProvider } from "@sdxc/i18n/ui";
13
+ import { Seo } from "@sdxc/seo";
10
14
  import { css } from "remix/component";
11
15
  import { ImportMap } from "remix/component/server";
12
16
 
17
+ import { seo } from "~/app/initializers/seo";
18
+
13
19
  import "@sdxc/ui/reset.css";
14
20
  import "@sdxc/ui/theme.css";
15
21
 
@@ -17,9 +23,18 @@ namespace DocumentLayout {
17
23
  export interface Props {
18
24
  /** The page's content, rendered inside `<main>`. */
19
25
  children: RemixNode;
20
- /** The stylesheets and client entry the request resolved, from `ctx.assets`. */
26
+ /**
27
+ * The stylesheets, client entry and CSP nonce the request resolved, from `ctx.assets`;
28
+ * the nonce is read only when the page hydrates, for its inline import map.
29
+ */
21
30
  assets: DocumentAssets;
31
+ /** The request's translator, from `ctx.intl`: it sets `<html lang>` and is what `intl(handle)` reads below it. */
32
+ intl: I18n;
22
33
  title: string;
34
+ /** The page's summary in search results and link previews; the site's description by default. */
35
+ description?: string;
36
+ /** The request's URL, from `ctx.url`, which the canonical link names on `SITE_URL`. */
37
+ url: URL;
23
38
  /** Whether the page carries an island, the only reason to link the client entry. */
24
39
  hydrates?: boolean;
25
40
  }
@@ -28,11 +43,11 @@ namespace DocumentLayout {
28
43
  /** Renders the `<html>`, `<head>` and `<body>` shell around a page. */
29
44
  export default function DocumentLayout(handle: Handle<DocumentLayout.Props>) {
30
45
  return () => {
31
- let { assets, children, hydrates = false, title } = handle.props;
46
+ let { assets, children, description, hydrates = false, intl, title, url } = handle.props;
32
47
  let { script, stylesheets } = assets;
33
48
 
34
49
  return (
35
- <html lang="en" class="system">
50
+ <html lang={intl.locale} class="system">
36
51
  <head>
37
52
  <meta charSet="utf-8" data-rmx-key="charset" />
38
53
  <meta
@@ -40,15 +55,21 @@ export default function DocumentLayout(handle: Handle<DocumentLayout.Props>) {
40
55
  content="width=device-width, initial-scale=1"
41
56
  data-rmx-key="viewport"
42
57
  />
43
- <title data-rmx-key="title">{title}</title>
58
+ <Seo.Meta
59
+ title={title}
60
+ description={description}
61
+ canonical={seo.canonical(url)}
62
+ site={seo.site}
63
+ og={{ locale: intl.locale }}
64
+ />
44
65
  {stylesheets.map((href) => (
45
66
  <link key={href} rel="stylesheet" href={href} data-rmx-key={href} />
46
67
  ))}
47
- {hydrates ? <ImportMap value={script.importMap} /> : null}
68
+ {hydrates ? <ImportMap value={script.importMap} nonce={assets.nonce} /> : null}
48
69
  </head>
49
70
  <body>
50
71
  <main mix={css({ maxInlineSize: "48rem", marginInline: "auto", padding: "1.5rem" })}>
51
- {children}
72
+ <IntlProvider intl={intl}>{children}</IntlProvider>
52
73
  </main>
53
74
  {hydrates ? <script type="module" src={script.href}></script> : null}
54
75
  </body>
@@ -0,0 +1,10 @@
1
+ {
2
+ "home": {
3
+ "title": "Welcome",
4
+ "body": "Edit {#file}app/http/controllers/home.tsx{/file}, or add a page with {#command}sdxc make controller <name>{/command}."
5
+ },
6
+ "notFound": {
7
+ "title": "Not found",
8
+ "back": "Back home"
9
+ }
10
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * The API route contract: every endpoint a machine client calls, and the OpenAPI operation
3
+ * that types each documented one, so the published document and the handler that parses a
4
+ * request read the same schemas.
5
+ */
6
+
7
+ import * as s from "@sdxc/json-schema";
8
+ import { defineOperation } from "@sdxc/openapi";
9
+ import { get, post, route } from "remix/routes";
10
+
11
+ /** The JSON endpoints under `/api`, and the MCP endpoint an agent connects to. */
12
+ const ROUTES = route({
13
+ api: {
14
+ health: get("/api/health"),
15
+ openapi: get("/api/openapi.json"),
16
+ notFound: "/api/*path",
17
+ },
18
+ mcp: post("/mcp"),
19
+ });
20
+
21
+ export default ROUTES;
22
+
23
+ /** GET /api/health, the check a monitor or load balancer polls. */
24
+ export const HEALTH = defineOperation("health", ROUTES.api.health, {
25
+ summary: "Check the service",
26
+ responses: {
27
+ 200: { description: "The service is up", body: s.object({ status: s.literal("ok") }) },
28
+ },
29
+ });
@@ -1,12 +1,14 @@
1
1
  /**
2
- * The web route contract: every URL the app answers, by name. Controllers and links build
2
+ * The web route contract: every page the app serves, by name. Controllers and links build
3
3
  * URLs with `routes.<name>.href()`, so a pattern changes here and nowhere else.
4
4
  */
5
5
 
6
- import { get, post, route } from "remix/routes";
6
+ import { get, route } from "remix/routes";
7
7
 
8
- /** The home page and the MCP endpoint an agent connects to. */
8
+ /** The pages, and the 404 page for any path no other route claims. */
9
9
  export default route({
10
10
  home: get("/"),
11
- mcp: post("/mcp"),
11
+ robots: get("/robots.txt"),
12
+ sitemap: get("/sitemap.xml"),
13
+ notFound: "/*path",
12
14
  });
@@ -26,6 +26,10 @@ export default defineConfig({
26
26
 
27
27
  test: {
28
28
  include: ["app/**/*.test.ts?(x)", "resources/**/*.test.ts?(x)"],
29
+ /** Vitest runs modules in Node, so the Worker runtime's module resolves to a stand-in. */
30
+ alias: {
31
+ "cloudflare:workers": new URL("app/test/cloudflare-workers.ts", import.meta.url).pathname,
32
+ },
29
33
  },
30
34
 
31
35
  fmt: {
@@ -1,20 +0,0 @@
1
- /**
2
- * What the router's global middleware adds to every request context: `render()` publishes
3
- * `ctx.render` and `formData()` publishes `ctx.formData`. Declaring them here lets the
4
- * default handler and any helper typed as `RequestContext` read them.
5
- */
6
-
7
- import type { RemixNode } from "remix/component";
8
- import type { Renderer } from "remix/middleware/render";
9
- import type {} from "remix/router";
10
-
11
- declare module "remix/router" {
12
- interface RequestContext {
13
- /** Renders a `remix/component` node into an HTML `Response`. */
14
- render: Renderer<RemixNode>;
15
- /** The request's parsed form body. */
16
- formData: FormData;
17
- }
18
- }
19
-
20
- export {};