@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.
- package/README.md +1 -0
- package/changelog.jsonl +57 -0
- package/dist/author.d.ts +36 -0
- package/dist/author.js +107 -0
- package/dist/commands/create.js +9 -4
- package/dist/commands/run.d.ts +2 -2
- package/dist/commands/run.js +5 -3
- package/dist/contract.js +1 -1
- package/dist/create/templates.d.ts +8 -1
- package/dist/create/templates.js +25 -2
- package/dist/init.d.ts +5 -3
- package/dist/init.js +15 -7
- package/dist/make/declare.d.ts +4 -4
- package/dist/make/declare.js +124 -21
- package/dist/make/generate.js +8 -2
- package/dist/make/index.js +5 -1
- package/dist/make/kinds.d.ts +2 -1
- package/dist/make/kinds.js +3 -2
- package/dist/testing.d.ts +12 -2
- package/dist/testing.js +22 -3
- package/package.json +3 -3
- package/stubs/command.stub +4 -0
- package/stubs/command.test.stub +3 -0
- package/stubs/controller.api.stub +21 -0
- package/stubs/controller.api.test.stub +18 -0
- package/stubs/controller.form.stub +39 -9
- package/stubs/controller.form.test.stub +61 -0
- package/stubs/controller.stub +15 -8
- package/stubs/controller.test.stub +3 -0
- package/stubs/email.stub +12 -30
- package/stubs/email.test.stub +6 -1
- package/stubs/factory.stub +3 -0
- package/stubs/initializer.stub +2 -0
- package/stubs/initializer.test.stub +3 -0
- package/stubs/job.cron.stub +4 -0
- package/stubs/job.stub +4 -0
- package/stubs/job.test.stub +3 -0
- package/stubs/mcp.resource.stub +3 -0
- package/stubs/mcp.stub +3 -0
- package/stubs/mcp.test.stub +3 -0
- package/stubs/middleware.stub +6 -1
- package/stubs/middleware.test.stub +3 -0
- package/stubs/model.stub +10 -1
- package/stubs/model.test.stub +3 -0
- package/stubs/policy.stub +3 -0
- package/stubs/policy.test.stub +3 -0
- package/stubs/service.stub +4 -0
- package/stubs/service.test.stub +3 -0
- package/stubs/validator.stub +3 -0
- package/stubs/validator.test.stub +3 -0
- package/templates/app/.env.example +16 -0
- package/templates/app/README.md +62 -35
- package/templates/app/app/commands/about.test.ts +1 -1
- package/templates/app/app/commands/db/console.ts +6 -0
- package/templates/app/app/commands/db/migrate.test.ts +30 -0
- package/templates/app/app/commands/db/migrate.ts +55 -0
- package/templates/app/app/commands/index.ts +16 -0
- package/templates/app/app/commands/typegen.test.ts +17 -0
- package/templates/app/app/commands/typegen.ts +16 -0
- package/templates/app/app/http/controllers/api/health.tsx +15 -0
- package/templates/app/app/http/controllers/api/not-found.tsx +16 -0
- package/templates/app/app/http/controllers/api/openapi.tsx +17 -0
- package/templates/app/app/http/controllers/home.tsx +21 -13
- package/templates/app/app/http/controllers/mcp.tsx +16 -0
- package/templates/app/app/http/controllers/not-found.tsx +23 -18
- package/templates/app/app/http/controllers/robots.test.ts +18 -0
- package/templates/app/app/http/controllers/robots.ts +24 -0
- package/templates/app/app/http/controllers/sitemap.test.ts +28 -0
- package/templates/app/app/http/controllers/sitemap.ts +25 -0
- package/templates/app/app/http/middleware/api.ts +10 -0
- package/templates/app/app/http/middleware/page.test.ts +40 -0
- package/templates/app/app/http/middleware/page.ts +49 -0
- package/templates/app/app/http/middleware/server-timing.test.ts +15 -0
- package/templates/app/app/http/middleware/server-timing.ts +42 -0
- package/templates/app/app/initializers/assets.ts +1 -1
- package/templates/app/app/initializers/captcha.ts +11 -0
- package/templates/app/app/initializers/cli.ts +42 -2
- package/templates/app/app/initializers/database.test.ts +18 -0
- package/templates/app/app/initializers/database.ts +18 -0
- package/templates/app/app/initializers/dispatcher.ts +18 -0
- package/templates/app/app/initializers/honeypot.ts +11 -0
- package/templates/app/app/initializers/i18n.test.ts +16 -0
- package/templates/app/app/initializers/i18n.ts +28 -0
- package/templates/app/app/initializers/local-database.test.ts +33 -0
- package/templates/app/app/initializers/local-database.ts +53 -0
- package/templates/app/app/initializers/mail.test.ts +27 -0
- package/templates/app/app/initializers/mail.ts +11 -0
- package/templates/app/app/initializers/mcp.ts +1 -1
- package/templates/app/app/initializers/openapi.ts +21 -0
- package/templates/app/app/initializers/router.test.ts +61 -0
- package/templates/app/app/initializers/router.tsx +72 -26
- package/templates/app/app/initializers/seo.ts +15 -0
- package/templates/app/app/initializers/session.test.ts +34 -0
- package/templates/app/app/initializers/session.ts +29 -0
- package/templates/app/app/initializers/spam.ts +10 -0
- package/templates/app/app/models/index.ts +10 -0
- package/templates/app/app/services/migrations.test.ts +45 -0
- package/templates/app/app/services/migrations.ts +60 -0
- package/templates/app/app/test/cloudflare-workers.ts +25 -0
- package/templates/app/bootstrap/cli.ts +1 -1
- package/templates/app/bootstrap/worker.ts +4 -4
- package/templates/app/cloudflare.config.ts +29 -1
- package/templates/app/config/constants.ts +19 -0
- package/templates/app/config/problems.ts +24 -0
- package/templates/app/config/security-policy.ts +34 -0
- package/templates/app/config/security-txt.ts +28 -0
- package/templates/app/database/migrations/.gitkeep +0 -0
- package/templates/app/package.json +35 -5
- package/templates/app/resources/layouts/document.tsx +28 -7
- package/templates/app/resources/locales/en.json +10 -0
- package/templates/app/routes/api.ts +29 -0
- package/templates/app/routes/web.ts +6 -4
- package/templates/app/vite.config.ts +4 -0
- package/templates/app/config/router-context.d.ts +0 -20
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The {{title}} form, rendered and submitted through the app's router, so every middleware
|
|
3
|
+
* and the page chain's checks run as they do in the Worker.
|
|
4
|
+
*
|
|
5
|
+
* @see {@link https://sdxc.dev/docs/building-remix-apps/forms-and-params}
|
|
6
|
+
* @see {@link https://sdxc.dev/docs/operations-and-testing/testing}{{header}}
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { unwrap } from "@sdxc/result";
|
|
10
|
+
import { describe, expect, test } from "vitest";
|
|
11
|
+
|
|
12
|
+
import { honeypot } from "~/app/initializers/honeypot";
|
|
13
|
+
import { createWebRouter } from "~/app/initializers/router";
|
|
14
|
+
import routes from "{{routes}}";
|
|
15
|
+
|
|
16
|
+
/** Posts `form` to the form's action. */
|
|
17
|
+
function submit(form: Record<string, string>) {
|
|
18
|
+
return createWebRouter().fetch(
|
|
19
|
+
new Request(new URL(routes.{{path}}.action.href(), "https://example.com"), {
|
|
20
|
+
method: "POST",
|
|
21
|
+
body: new URLSearchParams(form),
|
|
22
|
+
}),
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
describe("{{name}}", () => {
|
|
27
|
+
test("renders the form with its honeypot fields and CAPTCHA widget", async () => {
|
|
28
|
+
let response = await createWebRouter().fetch(
|
|
29
|
+
new URL(routes.{{path}}.index.href(), "https://example.com"),
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
expect(response.status).toBe(200);
|
|
33
|
+
let html = await response.text();
|
|
34
|
+
expect(html).toContain(`name="${honeypot.tokenField}"`);
|
|
35
|
+
expect(html).toContain('class="cf-turnstile"');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test("refuses a submission without the honeypot fields", async () => {
|
|
39
|
+
let response = await submit({});
|
|
40
|
+
|
|
41
|
+
expect(response.status).toBe(400);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test("refuses a submission that filled the trap", async () => {
|
|
45
|
+
let { token, tokenField, trapField } = unwrap(await honeypot.issue());
|
|
46
|
+
|
|
47
|
+
let response = await submit({ [tokenField]: token, [trapField]: "https://spam.example" });
|
|
48
|
+
|
|
49
|
+
expect(response.status).toBe(400);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test("refuses a submission without a CAPTCHA token", async () => {
|
|
53
|
+
let { token, tokenField } = unwrap(await honeypot.issue());
|
|
54
|
+
|
|
55
|
+
let response = await submit({ [tokenField]: token });
|
|
56
|
+
|
|
57
|
+
expect(response.status).toBe(403);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test.todo("saves a {{title}} submission");
|
|
61
|
+
});
|
package/stubs/controller.stub
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The {{title}} page: describe what a visitor finds here and why the route exists.
|
|
3
|
+
*
|
|
4
|
+
* @see {@link https://sdxc.dev/docs/building-remix-apps/wire-the-router}
|
|
5
|
+
* @see {@link https://sdxc.dev/docs/building-remix-apps/interface-with-remix-ui}{{header}}
|
|
3
6
|
*/
|
|
4
7
|
|
|
5
8
|
import { createAction } from "remix/router";
|
|
6
9
|
|
|
10
|
+
import page from "~/app/http/middleware/page";
|
|
7
11
|
import DocumentLayout from "~/resources/layouts/document";
|
|
8
12
|
import routes from "{{routes}}";
|
|
9
13
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
export default createAction(routes.{{path}}, {
|
|
15
|
+
middleware: page,
|
|
16
|
+
/** Renders the {{title}} page. */
|
|
17
|
+
handler: (ctx) =>
|
|
18
|
+
ctx.render(
|
|
19
|
+
<DocumentLayout assets={ctx.assets} intl={ctx.intl} url={ctx.url} title="{{title}}">
|
|
20
|
+
<h1>{{title}}</h1>
|
|
21
|
+
{/* TODO: render the page */}
|
|
22
|
+
</DocumentLayout>,
|
|
23
|
+
),
|
|
24
|
+
});
|
package/stubs/email.stub
CHANGED
|
@@ -1,44 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The {{title}} email: describe who receives it and what it tells them.
|
|
3
|
+
*
|
|
4
|
+
* @see {@link https://sdxc.dev/docs/data-and-background-work/send-email}
|
|
5
|
+
* @see {@link https://sdxc.dev/api/mail}{{header}}
|
|
3
6
|
*/
|
|
4
7
|
|
|
5
|
-
import
|
|
6
|
-
import type { Email as EmailContract } from "@sdxc/mail";
|
|
8
|
+
import { defineEmail, Email } from "@sdxc/mail";
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
/** What the {{title}} email says. */
|
|
10
|
+
/** What the {{title}} email says, already translated for its reader. */
|
|
11
11
|
export interface {{Name}}Copy {
|
|
12
12
|
heading: string;
|
|
13
13
|
body: string;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
/** The {{title}} email, sent with `new {{Name}}Email(recipient, copy)`. */
|
|
17
|
+
export const {{Name}}Email = defineEmail<{{Name}}Copy>({
|
|
18
|
+
subject: (copy) => copy.heading,
|
|
19
|
+
body: (handle) => () => (
|
|
19
20
|
<Email.Layout preview={handle.props.heading} title={handle.props.heading}>
|
|
20
21
|
<Email.Heading>{handle.props.heading}</Email.Heading>
|
|
21
22
|
<Email.Text>{handle.props.body}</Email.Text>
|
|
23
|
+
{/* TODO: lay out the rest of the email */}
|
|
22
24
|
</Email.Layout>
|
|
23
|
-
)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** The {{title}} email, addressed to one recipient. */
|
|
27
|
-
export class {{Name}}Email implements EmailContract {
|
|
28
|
-
constructor(
|
|
29
|
-
private recipient: string,
|
|
30
|
-
private copy: {{Name}}Copy,
|
|
31
|
-
) {}
|
|
32
|
-
|
|
33
|
-
get to() {
|
|
34
|
-
return { email: this.recipient };
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
get subject() {
|
|
38
|
-
return this.copy.heading;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
body() {
|
|
42
|
-
return <{{Name}}Body {...this.copy} />;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
25
|
+
),
|
|
26
|
+
});
|
package/stubs/email.test.stub
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The {{title}} email.
|
|
3
|
+
*
|
|
4
|
+
* @see {@link https://sdxc.dev/docs/data-and-background-work/send-email}
|
|
5
|
+
* @see {@link https://sdxc.dev/docs/operations-and-testing/testing}{{header}}
|
|
3
6
|
*/
|
|
4
7
|
|
|
8
|
+
import { render } from "@sdxc/mail";
|
|
5
9
|
import { describe, expect, test } from "vitest";
|
|
6
10
|
|
|
7
11
|
import { {{Name}}Email } from "{{specifier}}";
|
|
8
12
|
|
|
9
13
|
describe("{{Name}}Email", () => {
|
|
10
|
-
test("is addressed to its recipient under its heading", () => {
|
|
14
|
+
test("is addressed to its recipient under its heading", async () => {
|
|
11
15
|
let email = new {{Name}}Email("ada@example.com", { heading: "Hello", body: "Welcome." });
|
|
12
16
|
|
|
13
17
|
expect(email.to).toEqual({ email: "ada@example.com" });
|
|
14
18
|
expect(email.subject).toBe("Hello");
|
|
19
|
+
expect((await render(email.body())).text).toContain("Welcome.");
|
|
15
20
|
});
|
|
16
21
|
});
|
package/stubs/factory.stub
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The {{title}} factory tests seed rows with, through the same model the app writes with.
|
|
3
|
+
*
|
|
4
|
+
* @see {@link https://sdxc.dev/docs/data-and-background-work/data-models}
|
|
5
|
+
* @see {@link https://sdxc.dev/docs/operations-and-testing/test-data}{{header}}
|
|
3
6
|
*/
|
|
4
7
|
|
|
5
8
|
import { defineFactory } from "@sdxc/data-model/testing";
|
package/stubs/initializer.stub
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The app's one {{title}}: describe what it is configured with and who reads it. Build it
|
|
3
3
|
* here, once, so every caller shares the same instance.
|
|
4
|
+
*
|
|
5
|
+
* @see {@link https://sdxc.dev/docs/building-remix-apps/wire-the-router}{{header}}
|
|
4
6
|
*/
|
|
5
7
|
|
|
6
8
|
/** The {{title}} every caller imports. */
|
package/stubs/job.cron.stub
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The scheduled {{title}} job: describe what each run sweeps or reports, and why on this
|
|
3
3
|
* schedule.
|
|
4
|
+
*
|
|
5
|
+
* @see {@link https://sdxc.dev/docs/data-and-background-work/jobs-and-cron}
|
|
6
|
+
* @see {@link https://sdxc.dev/api/jobs}{{header}}
|
|
4
7
|
*/
|
|
5
8
|
|
|
6
9
|
import { createJobHandler } from "@sdxc/jobs";
|
|
@@ -9,4 +12,5 @@ import jobs from "~/app/jobs";
|
|
|
9
12
|
|
|
10
13
|
export default createJobHandler(jobs.{{path}}, async (ctx) => {
|
|
11
14
|
ctx.log.set({ job: { name: "{{name}}" } });
|
|
15
|
+
// TODO: do the work, through the services on `ctx`
|
|
12
16
|
});
|
package/stubs/job.stub
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The {{title}} job: describe what it changes and why it runs off the request.
|
|
3
|
+
*
|
|
4
|
+
* @see {@link https://sdxc.dev/docs/data-and-background-work/jobs-and-cron}
|
|
5
|
+
* @see {@link https://sdxc.dev/api/jobs}{{header}}
|
|
3
6
|
*/
|
|
4
7
|
|
|
5
8
|
import { createJobHandler } from "@sdxc/jobs";
|
|
@@ -8,4 +11,5 @@ import jobs from "~/app/jobs";
|
|
|
8
11
|
|
|
9
12
|
export default createJobHandler(jobs.{{path}}, async (ctx) => {
|
|
10
13
|
ctx.log.set({ job: { name: "{{name}}" } });
|
|
14
|
+
// TODO: do the work, through the services on `ctx`
|
|
11
15
|
});
|
package/stubs/job.test.stub
CHANGED
package/stubs/mcp.resource.stub
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Answers the `{{uri}}` resource: describe what a read returns, and `null` for one that does
|
|
3
3
|
* not exist.
|
|
4
|
+
*
|
|
5
|
+
* @see {@link https://sdxc.dev/docs/operations-and-testing/mcp-server}
|
|
6
|
+
* @see {@link https://sdxc.dev/api/mcp}{{header}}
|
|
4
7
|
*/
|
|
5
8
|
|
|
6
9
|
import { createResource } from "@sdxc/mcp";
|
package/stubs/mcp.stub
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Answers the `{{tool}}` tool: describe what it returns, and what a model should do when it
|
|
3
3
|
* finds nothing.
|
|
4
|
+
*
|
|
5
|
+
* @see {@link https://sdxc.dev/docs/operations-and-testing/mcp-server}
|
|
6
|
+
* @see {@link https://sdxc.dev/api/mcp}{{header}}
|
|
4
7
|
*/
|
|
5
8
|
|
|
6
9
|
import { createTool } from "@sdxc/mcp";
|
package/stubs/mcp.test.stub
CHANGED
package/stubs/middleware.stub
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The {{title}} middleware: describe what it publishes on the context or which requests it
|
|
3
3
|
* answers before the handler runs.
|
|
4
|
+
*
|
|
5
|
+
* @see {@link https://sdxc.dev/docs/building-remix-apps/wire-the-router}{{header}}
|
|
4
6
|
*/
|
|
5
7
|
|
|
6
8
|
import type { Middleware } from "remix/router";
|
|
7
9
|
|
|
8
10
|
/** Creates the middleware; add it to a router's chain or to a route's `lazy()` guards. */
|
|
9
11
|
export default function {{key}}(): Middleware {
|
|
10
|
-
return (_context, next) =>
|
|
12
|
+
return (_context, next) => {
|
|
13
|
+
// TODO: publish on the context, or answer before the handler runs
|
|
14
|
+
return next();
|
|
15
|
+
};
|
|
11
16
|
}
|
package/stubs/model.stub
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The {{title}} model and its table: describe what a row records and the rules that keep it
|
|
3
3
|
* consistent. Keep the columns in step with the migration that creates the table.
|
|
4
|
+
*
|
|
5
|
+
* @see {@link https://sdxc.dev/docs/data-and-background-work/data-models}
|
|
6
|
+
* @see {@link https://sdxc.dev/api/data-model}{{header}}
|
|
4
7
|
*/
|
|
5
8
|
|
|
6
9
|
import type { TableRow } from "remix/data-table";
|
|
7
10
|
|
|
8
11
|
import { column as c, table } from "remix/data-table";
|
|
9
12
|
import { createModel } from "@sdxc/data-model";
|
|
13
|
+
import { generateUUID } from "@sdxc/uuid/v7";
|
|
10
14
|
|
|
11
15
|
/** The `{{snake}}` table, as its migration creates it. */
|
|
12
16
|
export const {{key}}Table = table({
|
|
@@ -15,10 +19,15 @@ export const {{key}}Table = table({
|
|
|
15
19
|
id: c.text().primaryKey(),
|
|
16
20
|
created_at: c.integer(),
|
|
17
21
|
updated_at: c.integer(),
|
|
22
|
+
// TODO: add the columns the migration creates
|
|
18
23
|
},
|
|
24
|
+
/** `create` and `update` stamp `created_at` and `updated_at` with the database's clock. */
|
|
25
|
+
timestamps: true,
|
|
19
26
|
});
|
|
20
27
|
|
|
21
28
|
/** One {{title}} row as it reads back from the database. */
|
|
22
29
|
export type {{Name}}Row = TableRow<typeof {{key}}Table>;
|
|
23
30
|
|
|
24
|
-
export const {{Name}} = createModel({{key}}Table, {});
|
|
31
|
+
export const {{Name}} = createModel({{key}}Table, { generateId: generateUUID });
|
|
32
|
+
|
|
33
|
+
export default {{Name}};
|
package/stubs/model.test.stub
CHANGED
package/stubs/policy.stub
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The {{title}} policy: describe who may do what, and why the rule sits here.
|
|
3
|
+
*
|
|
4
|
+
* @see {@link https://sdxc.dev/docs/identity-and-security/authorization}
|
|
5
|
+
* @see {@link https://sdxc.dev/api/authz}{{header}}
|
|
3
6
|
*/
|
|
4
7
|
|
|
5
8
|
/** Who an authorization rule is asked about; `null` for an anonymous visitor. */
|
package/stubs/policy.test.stub
CHANGED
package/stubs/service.stub
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* {{title}}: describe the rule this service carries out across models, and what a caller can
|
|
3
3
|
* rely on when it succeeds.
|
|
4
|
+
*
|
|
5
|
+
* @see {@link https://sdxc.dev/docs/conventions/result-everywhere}
|
|
6
|
+
* @see {@link https://sdxc.dev/api/result}{{header}}
|
|
4
7
|
*/
|
|
5
8
|
|
|
6
9
|
import type { Result } from "@sdxc/result";
|
|
@@ -9,5 +12,6 @@ import { success } from "@sdxc/result";
|
|
|
9
12
|
|
|
10
13
|
/** Carries out {{title}}; a failure says why nothing changed. */
|
|
11
14
|
export function {{key}}(): Result<void, Error> {
|
|
15
|
+
// TODO: carry out the rule across models
|
|
12
16
|
return success(undefined);
|
|
13
17
|
}
|
package/stubs/service.test.stub
CHANGED
package/stubs/validator.stub
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The fields the {{title}} form submits, validated before anything trusts them.
|
|
3
|
+
*
|
|
4
|
+
* @see {@link https://sdxc.dev/docs/building-remix-apps/forms-and-params}
|
|
5
|
+
* @see {@link https://sdxc.dev/api/validate}{{header}}
|
|
3
6
|
*/
|
|
4
7
|
|
|
5
8
|
import * as s from "remix/data-schema";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# The Worker's secrets, with values for local development. `sdxc create` copies this file to
|
|
2
|
+
# `.dev.vars`, which `bun dev` reads; copy it yourself in a fresh clone. Set each one for
|
|
3
|
+
# production with `cf workers secrets update <NAME>` before the first deploy.
|
|
4
|
+
|
|
5
|
+
# Signs the session cookie. Use a long random value in production; changing it signs every
|
|
6
|
+
# visitor out.
|
|
7
|
+
SESSION_SECRET=development-session-secret
|
|
8
|
+
|
|
9
|
+
# Signs the honeypot fields every page form carries. Use a long random value in production.
|
|
10
|
+
HONEYPOT_SECRET=development-honeypot-secret
|
|
11
|
+
|
|
12
|
+
# Cloudflare Turnstile, which a form asks a visitor to pass. These are Cloudflare's test keys,
|
|
13
|
+
# which render a visible widget that always passes; create a widget in the Cloudflare dashboard
|
|
14
|
+
# for the production keys.
|
|
15
|
+
TURNSTILE_SITE_KEY=1x00000000000000000000AA
|
|
16
|
+
TURNSTILE_SECRET_KEY=1x0000000000000000000000000000000AA
|
package/templates/app/README.md
CHANGED
|
@@ -1,57 +1,84 @@
|
|
|
1
1
|
# App
|
|
2
2
|
|
|
3
|
-
A Remix v3
|
|
3
|
+
A Remix v3 app on Cloudflare Workers, built on the `@sdxc/*` packages.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Start
|
|
6
6
|
|
|
7
7
|
```sh
|
|
8
8
|
bun install
|
|
9
|
-
|
|
9
|
+
sdxc run typegen
|
|
10
|
+
sdxc run db migrate
|
|
10
11
|
bun dev
|
|
11
12
|
```
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
In a fresh clone, copy `.env.example` to `.dev.vars` first. Run `sdxc run typegen` again
|
|
15
|
+
whenever you change a binding in `cloudflare.config.ts`.
|
|
15
16
|
|
|
16
|
-
##
|
|
17
|
-
|
|
18
|
-
`sdxc make <kind> <name>` writes a file of that kind where it belongs, with a test beside it,
|
|
19
|
-
and adds any `@sdxc/*` package the file imports to `package.json`. The `sdxc` command comes
|
|
20
|
-
from `npm add -g @sdxc/kit`:
|
|
17
|
+
## Everyday commands
|
|
21
18
|
|
|
22
19
|
```sh
|
|
23
|
-
sdxc make controller about
|
|
20
|
+
sdxc make controller about # a page, mapped in routes/web.ts
|
|
21
|
+
sdxc make controller api/keys --routes api # a JSON endpoint
|
|
22
|
+
sdxc make migration create-posts # then: sdxc run db migrate
|
|
23
|
+
sdxc make model post # then: ctx.models.post
|
|
24
24
|
sdxc make job reports/daily --cron "0 8 * * *"
|
|
25
|
-
sdxc make
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
A controller, a job and an MCP tool or resource are also declared and mapped, so they answer
|
|
29
|
-
as soon as the command finishes.
|
|
25
|
+
sdxc make email welcome # then: ctx.email.later(new WelcomeEmail(to, copy))
|
|
26
|
+
sdxc make command users/grant # then: sdxc run users grant
|
|
30
27
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
request. It runs on Bun, outside the Worker, through its package script:
|
|
35
|
-
|
|
36
|
-
```sh
|
|
37
|
-
bun run cli about
|
|
38
|
-
bun run cli --help
|
|
28
|
+
sdxc run db console # SQL prompt over the local database
|
|
29
|
+
bun check # format, lint and types
|
|
30
|
+
bun test
|
|
39
31
|
```
|
|
40
32
|
|
|
41
|
-
|
|
42
|
-
project.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
33
|
+
`sdxc make` writes the file where it belongs with a test beside it, and maps it so it works
|
|
34
|
+
right away. `sdxc` comes with the project; `npm add -g @sdxc/kit` puts it on your path.
|
|
35
|
+
|
|
36
|
+
## Where things go
|
|
37
|
+
|
|
38
|
+
| Folder | What lives there |
|
|
39
|
+
| ---------------------- | ----------------------------------------------------------- |
|
|
40
|
+
| `routes/` | URL contracts: `web.ts` for pages, `api.ts` for endpoints |
|
|
41
|
+
| `app/http/` | Controllers, middleware and input validators |
|
|
42
|
+
| `app/models/` | Database models, one per table |
|
|
43
|
+
| `app/jobs/` | Background jobs |
|
|
44
|
+
| `app/emails/` | Emails |
|
|
45
|
+
| `app/commands/` | Commands for `sdxc run` |
|
|
46
|
+
| `app/initializers/` | The one instance of each service: database, mailer, router… |
|
|
47
|
+
| `resources/` | Layouts, components and translations (`resources/locales/`) |
|
|
48
|
+
| `database/migrations/` | SQL migrations |
|
|
49
|
+
| `config/` | Site settings, security policy, security.txt, API problems |
|
|
50
|
+
|
|
51
|
+
## What a handler gets
|
|
52
|
+
|
|
53
|
+
Every request, job and command can read:
|
|
54
|
+
|
|
55
|
+
- `ctx.db` and `ctx.models`: the D1 database and its models.
|
|
56
|
+
- `ctx.email` (requests and commands): sends email, `later()` after the response or
|
|
57
|
+
`await send()` before it. A command prints it instead of sending it.
|
|
58
|
+
- `ctx.log`, with a `trace_id` shared by a request and the jobs it starts.
|
|
59
|
+
- `ctx.timing`: adds entries to the `Server-Timing` header (requests only).
|
|
60
|
+
- `ctx.ip` and `ctx.userAgent` (requests only): the client's address, or `null`, and its parsed
|
|
61
|
+
`User-Agent` header.
|
|
62
|
+
|
|
63
|
+
Pages also get `ctx.session`, `ctx.intl` for translated copy, and forms protected by a
|
|
64
|
+
honeypot, Turnstile and a spam filter. Before a page loads a script, style, image or font from
|
|
65
|
+
another origin, add that origin to `config/security-policy.ts`. API errors use the catalog in
|
|
66
|
+
`config/problems.ts`.
|
|
67
|
+
|
|
68
|
+
## Before the first deploy
|
|
69
|
+
|
|
70
|
+
1. Create the resources and put their ids in `cloudflare.config.ts`:
|
|
71
|
+
`bunx cf d1 create <name>`, `bunx cf kv namespace create <name>`, and
|
|
72
|
+
`bunx cf queues create <name>` (the `name` in `package.json`).
|
|
73
|
+
2. Set every secret in `.env.example` with `bunx cf workers secrets update <NAME>`.
|
|
74
|
+
3. Edit `config/constants.ts`: your domain, site name and description, and a `MAIL_FROM`
|
|
75
|
+
address on a domain with Cloudflare Email Routing.
|
|
76
|
+
4. Put your contact in `config/security-txt.ts`.
|
|
77
|
+
5. Deploy:
|
|
48
78
|
|
|
49
79
|
```sh
|
|
50
80
|
bun check
|
|
51
|
-
bun test
|
|
52
81
|
bun build
|
|
82
|
+
sdxc run db migrate --remote
|
|
53
83
|
bun cf:deploy
|
|
54
84
|
```
|
|
55
|
-
|
|
56
|
-
Create the job queue once before the first deploy: `bunx cf queues create <name>`, using the
|
|
57
|
-
`name` in `package.json`.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `db migrate --remote`, which hands the chain to `cf d1 migrations apply` for the production
|
|
3
|
+
* database named in `cloudflare.config.ts`.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { invoke } from "@sdxc/cli/test";
|
|
7
|
+
import { describe, expect, test } from "vitest";
|
|
8
|
+
|
|
9
|
+
import { cli } from "~/app/initializers/cli";
|
|
10
|
+
|
|
11
|
+
describe("db migrate", () => {
|
|
12
|
+
test("--remote applies the chain through cf to the configured database", async () => {
|
|
13
|
+
let run = await invoke(cli, ["db", "migrate", "--remote"], {
|
|
14
|
+
exec: {
|
|
15
|
+
"cf d1 migrations apply 00000000-0000-4000-8000-000000000000 --dir database/migrations": {
|
|
16
|
+
code: 0,
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
expect(run.code).toBe(0);
|
|
22
|
+
expect(run.exec[0]?.command.slice(0, 5)).toEqual([
|
|
23
|
+
"cf",
|
|
24
|
+
"d1",
|
|
25
|
+
"migrations",
|
|
26
|
+
"apply",
|
|
27
|
+
"00000000-0000-4000-8000-000000000000",
|
|
28
|
+
]);
|
|
29
|
+
});
|
|
30
|
+
});
|