@sdxc/kit 2026.10.17 → 2026.10.21

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 (295) hide show
  1. package/README.md +397 -22
  2. package/changelog.jsonl +1171 -1092
  3. package/config.schema.json +53 -1
  4. package/dist/cli.js +12 -0
  5. package/dist/commands/deploy.d.ts +23 -0
  6. package/dist/commands/deploy.js +167 -0
  7. package/dist/commands/destroy.d.ts +22 -0
  8. package/dist/commands/destroy.js +92 -0
  9. package/dist/commands/doctor.d.ts +26 -0
  10. package/dist/commands/doctor.js +65 -0
  11. package/dist/commands/initializers.d.ts +16 -0
  12. package/dist/commands/initializers.js +23 -0
  13. package/dist/commands/make.d.ts +78 -6
  14. package/dist/commands/make.js +134 -20
  15. package/dist/commands/middleware.d.ts +16 -0
  16. package/dist/commands/middleware.js +21 -0
  17. package/dist/commands/models.d.ts +18 -0
  18. package/dist/commands/models.js +29 -0
  19. package/dist/commands/notes.d.ts +17 -0
  20. package/dist/commands/notes.js +27 -0
  21. package/dist/commands/routes.d.ts +25 -0
  22. package/dist/commands/routes.js +50 -0
  23. package/dist/commands/run.d.ts +16 -0
  24. package/dist/commands/run.js +32 -11
  25. package/dist/commands/scaffold.d.ts +30 -0
  26. package/dist/commands/scaffold.js +34 -0
  27. package/dist/commands/schedule.d.ts +16 -0
  28. package/dist/commands/schedule.js +21 -0
  29. package/dist/commands/stats.d.ts +16 -0
  30. package/dist/commands/stats.js +21 -0
  31. package/dist/commands/ui/update.d.ts +6 -3
  32. package/dist/commands/ui/update.js +24 -7
  33. package/dist/commands/upgrade.d.ts +3 -1
  34. package/dist/commands/upgrade.js +88 -23
  35. package/dist/config.d.ts +20 -0
  36. package/dist/config.js +32 -1
  37. package/dist/contract.d.ts +101 -3
  38. package/dist/contract.js +371 -26
  39. package/dist/create/templates.js +3 -2
  40. package/dist/dependencies.d.ts +5 -1
  41. package/dist/dependencies.js +16 -1
  42. package/dist/deploy/plan.d.ts +49 -0
  43. package/dist/deploy/plan.js +68 -0
  44. package/dist/destroy.d.ts +40 -0
  45. package/dist/destroy.js +317 -0
  46. package/dist/doctor/check.d.ts +71 -0
  47. package/dist/doctor/check.js +53 -0
  48. package/dist/doctor/checks.d.ts +23 -0
  49. package/dist/doctor/checks.js +70 -0
  50. package/dist/doctor/define.d.ts +59 -0
  51. package/dist/doctor/define.js +16 -0
  52. package/dist/doctor/emails.d.ts +18 -0
  53. package/dist/doctor/emails.js +243 -0
  54. package/dist/doctor/env.d.ts +26 -0
  55. package/dist/doctor/env.js +88 -0
  56. package/dist/doctor/files.d.ts +14 -0
  57. package/dist/doctor/files.js +34 -0
  58. package/dist/doctor/fixture.d.ts +23 -0
  59. package/dist/doctor/fixture.js +46 -0
  60. package/dist/doctor/install.d.ts +17 -0
  61. package/dist/doctor/install.js +37 -0
  62. package/dist/doctor/installed.d.ts +11 -0
  63. package/dist/doctor/installed.js +79 -0
  64. package/dist/doctor/jsdoc.d.ts +44 -0
  65. package/dist/doctor/jsdoc.js +201 -0
  66. package/dist/doctor/layout.d.ts +23 -0
  67. package/dist/doctor/layout.js +83 -0
  68. package/dist/doctor/migrations.d.ts +16 -0
  69. package/dist/doctor/migrations.js +96 -0
  70. package/dist/doctor/models.d.ts +13 -0
  71. package/dist/doctor/models.js +69 -0
  72. package/dist/doctor/pins.d.ts +15 -0
  73. package/dist/doctor/pins.js +79 -0
  74. package/dist/doctor/project.d.ts +58 -0
  75. package/dist/doctor/project.js +261 -0
  76. package/dist/doctor/remix.d.ts +14 -0
  77. package/dist/doctor/remix.js +44 -0
  78. package/dist/doctor/routes.d.ts +11 -0
  79. package/dist/doctor/routes.js +49 -0
  80. package/dist/doctor/typegen.d.ts +13 -0
  81. package/dist/doctor/typegen.js +57 -0
  82. package/dist/doctor/ui.d.ts +14 -0
  83. package/dist/doctor/ui.js +51 -0
  84. package/dist/initializers.d.ts +25 -0
  85. package/dist/initializers.js +89 -0
  86. package/dist/lock.d.ts +2 -2
  87. package/dist/make/actions.d.ts +23 -0
  88. package/dist/make/actions.js +82 -0
  89. package/dist/make/declare.d.ts +31 -3
  90. package/dist/make/declare.js +284 -9
  91. package/dist/make/email.d.ts +23 -0
  92. package/dist/make/email.js +111 -0
  93. package/dist/make/from-fields.d.ts +30 -0
  94. package/dist/make/from-fields.js +162 -0
  95. package/dist/make/from-model.d.ts +39 -0
  96. package/dist/make/from-model.js +161 -0
  97. package/dist/make/generate.d.ts +25 -5
  98. package/dist/make/generate.js +76 -22
  99. package/dist/make/guard.d.ts +35 -0
  100. package/dist/make/guard.js +73 -0
  101. package/dist/make/imports.d.ts +6 -0
  102. package/dist/make/imports.js +19 -0
  103. package/dist/make/index.d.ts +49 -4
  104. package/dist/make/index.js +290 -29
  105. package/dist/make/kinds.d.ts +34 -2
  106. package/dist/make/kinds.js +92 -8
  107. package/dist/make/mount.d.ts +25 -0
  108. package/dist/make/mount.js +135 -0
  109. package/dist/make/schema-diff.d.ts +58 -0
  110. package/dist/make/schema-diff.js +609 -0
  111. package/dist/make/schema.d.ts +76 -0
  112. package/dist/make/schema.js +206 -0
  113. package/dist/make/stubs.d.ts +14 -7
  114. package/dist/make/stubs.js +24 -8
  115. package/dist/make/test.d.ts +43 -0
  116. package/dist/make/test.js +150 -0
  117. package/dist/make/trigger.d.ts +31 -0
  118. package/dist/make/trigger.js +163 -0
  119. package/dist/models.d.ts +42 -0
  120. package/dist/models.js +149 -0
  121. package/dist/notes.d.ts +28 -0
  122. package/dist/notes.js +66 -0
  123. package/dist/reference.d.ts +27 -0
  124. package/dist/reference.js +103 -0
  125. package/dist/releases.d.ts +9 -0
  126. package/dist/releases.js +29 -8
  127. package/dist/routes/chains.d.ts +34 -0
  128. package/dist/routes/chains.js +95 -0
  129. package/dist/routes/filter.d.ts +53 -0
  130. package/dist/routes/filter.js +147 -0
  131. package/dist/routes/format.d.ts +23 -0
  132. package/dist/routes/format.js +123 -0
  133. package/dist/routes/helpers.d.ts +21 -0
  134. package/dist/routes/helpers.js +165 -0
  135. package/dist/routes/index.d.ts +56 -0
  136. package/dist/routes/index.js +167 -0
  137. package/dist/routes/modules.d.ts +116 -0
  138. package/dist/routes/modules.js +235 -0
  139. package/dist/routes/parse.d.ts +161 -0
  140. package/dist/routes/parse.js +621 -0
  141. package/dist/routes/routers.d.ts +69 -0
  142. package/dist/routes/routers.js +327 -0
  143. package/dist/scaffold/fields.d.ts +129 -0
  144. package/dist/scaffold/fields.js +421 -0
  145. package/dist/scaffold/index.d.ts +39 -0
  146. package/dist/scaffold/index.js +622 -0
  147. package/dist/scaffold/render.d.ts +61 -0
  148. package/dist/scaffold/render.js +417 -0
  149. package/dist/schedule.d.ts +45 -0
  150. package/dist/schedule.js +124 -0
  151. package/dist/stats.d.ts +37 -0
  152. package/dist/stats.js +126 -0
  153. package/dist/ui/commands.d.ts +10 -3
  154. package/dist/ui/commands.js +85 -15
  155. package/dist/ui/registry.d.ts +8 -8
  156. package/dist/upgrade/agents.d.ts +49 -0
  157. package/dist/upgrade/agents.js +110 -0
  158. package/dist/upgrade/changelog.d.ts +2 -2
  159. package/dist/upgrade/project.d.ts +4 -0
  160. package/dist/upgrade/project.js +11 -1
  161. package/dist/upgrade/prompt.d.ts +11 -0
  162. package/dist/upgrade/prompt.js +50 -7
  163. package/package.json +6 -4
  164. package/registry/ui/alert-dialog.json +2 -2
  165. package/registry/ui/attachment.json +2 -2
  166. package/registry/ui/calendar.json +2 -2
  167. package/registry/ui/color-picker.json +2 -2
  168. package/registry/ui/command.json +2 -2
  169. package/registry/ui/date-picker.json +2 -2
  170. package/registry/ui/date-range-picker.json +2 -2
  171. package/registry/ui/dialog.json +2 -2
  172. package/registry/ui/file-trigger.json +2 -2
  173. package/registry/ui/heading-scope.json +2 -2
  174. package/registry/ui/message-scroller.json +2 -2
  175. package/registry/ui/number-field.json +2 -2
  176. package/registry/ui/range-calendar.json +2 -2
  177. package/registry/ui/resizable.json +2 -2
  178. package/registry/ui/select.json +2 -2
  179. package/registry/ui/shared-element.json +2 -2
  180. package/registry/ui/sidebar.json +3 -3
  181. package/registry/ui/typeset.json +3 -3
  182. package/stubs/command.spec.stub +15 -0
  183. package/stubs/controller.api.resource.stub +23 -0
  184. package/stubs/controller.api.spec.stub +15 -0
  185. package/stubs/controller.form.stub +2 -2
  186. package/stubs/controller.form.test.stub +2 -2
  187. package/stubs/controller.resource.form.stub +67 -0
  188. package/stubs/controller.resource.stub +28 -0
  189. package/stubs/controller.spec.stub +15 -0
  190. package/stubs/email.stub +9 -14
  191. package/stubs/email.test.stub +9 -9
  192. package/stubs/factory.stub +1 -1
  193. package/stubs/mcp.spec.stub +16 -0
  194. package/stubs/model.stub +3 -3
  195. package/stubs/policy.test.stub +34 -8
  196. package/stubs/scaffold.api.create.stub +34 -0
  197. package/stubs/scaffold.api.create.test.stub +37 -0
  198. package/stubs/scaffold.api.destroy.stub +34 -0
  199. package/stubs/scaffold.api.destroy.test.stub +44 -0
  200. package/stubs/scaffold.api.index.stub +23 -0
  201. package/stubs/scaffold.api.index.test.stub +31 -0
  202. package/stubs/scaffold.api.show.stub +27 -0
  203. package/stubs/scaffold.api.show.test.stub +41 -0
  204. package/stubs/scaffold.api.update.stub +44 -0
  205. package/stubs/scaffold.api.update.test.stub +46 -0
  206. package/stubs/scaffold.command.create.stub +22 -0
  207. package/stubs/scaffold.command.create.test.stub +30 -0
  208. package/stubs/scaffold.command.delete.stub +20 -0
  209. package/stubs/scaffold.command.delete.test.stub +39 -0
  210. package/stubs/scaffold.command.list.stub +18 -0
  211. package/stubs/scaffold.command.list.test.stub +31 -0
  212. package/stubs/scaffold.command.show.stub +19 -0
  213. package/stubs/scaffold.command.show.test.stub +37 -0
  214. package/stubs/scaffold.controller.destroy.stub +35 -0
  215. package/stubs/scaffold.controller.destroy.test.stub +65 -0
  216. package/stubs/scaffold.controller.edit.stub +97 -0
  217. package/stubs/scaffold.controller.edit.test.stub +91 -0
  218. package/stubs/scaffold.controller.index.stub +55 -0
  219. package/stubs/scaffold.controller.index.test.stub +32 -0
  220. package/stubs/scaffold.controller.new.stub +70 -0
  221. package/stubs/scaffold.controller.new.test.stub +81 -0
  222. package/stubs/scaffold.controller.show.stub +59 -0
  223. package/stubs/scaffold.controller.show.test.stub +43 -0
  224. package/stubs/scaffold.factory.stub +16 -0
  225. package/stubs/scaffold.form.stub +75 -0
  226. package/stubs/scaffold.mcp.create.stub +24 -0
  227. package/stubs/scaffold.mcp.create.test.stub +36 -0
  228. package/stubs/scaffold.mcp.delete.stub +31 -0
  229. package/stubs/scaffold.mcp.delete.test.stub +43 -0
  230. package/stubs/scaffold.mcp.get.stub +21 -0
  231. package/stubs/scaffold.mcp.get.test.stub +31 -0
  232. package/stubs/scaffold.mcp.list.stub +23 -0
  233. package/stubs/scaffold.mcp.list.test.stub +25 -0
  234. package/stubs/scaffold.mcp.update.stub +37 -0
  235. package/stubs/scaffold.mcp.update.test.stub +40 -0
  236. package/stubs/scaffold.migration.stub +3 -0
  237. package/stubs/scaffold.model.stub +35 -0
  238. package/stubs/scaffold.model.test.stub +25 -0
  239. package/stubs/scaffold.spec.stub +7 -0
  240. package/stubs/scaffold.test-database.stub +33 -0
  241. package/stubs/scaffold.test-mcp.stub +92 -0
  242. package/stubs/scaffold.validator.stub +18 -0
  243. package/stubs/scaffold.validator.test.stub +26 -0
  244. package/templates/app/AGENTS.md +167 -0
  245. package/templates/app/CLAUDE.md +1 -0
  246. package/templates/app/README.md +33 -15
  247. package/templates/app/app/commands/console.test.ts +26 -0
  248. package/templates/app/app/commands/console.ts +19 -0
  249. package/templates/app/app/commands/db/fresh.test.ts +57 -0
  250. package/templates/app/app/commands/db/fresh.ts +37 -0
  251. package/templates/app/app/commands/db/migrate.test.ts +17 -1
  252. package/templates/app/app/commands/db/migrate.ts +51 -18
  253. package/templates/app/app/commands/db/prepare.test.ts +39 -0
  254. package/templates/app/app/commands/db/prepare.ts +35 -0
  255. package/templates/app/app/commands/db/seed.test.ts +38 -0
  256. package/templates/app/app/commands/db/seed.ts +26 -0
  257. package/templates/app/app/commands/deploy.test.ts +34 -0
  258. package/templates/app/app/commands/deploy.ts +18 -0
  259. package/templates/app/app/commands/emails/preview.test.tsx +63 -0
  260. package/templates/app/app/commands/emails/preview.ts +24 -0
  261. package/templates/app/app/commands/index.ts +57 -2
  262. package/templates/app/app/commands/typegen.test.ts +20 -1
  263. package/templates/app/app/commands/typegen.ts +16 -2
  264. package/templates/app/app/emails/index.ts +10 -0
  265. package/templates/app/app/http/middleware/access.test.ts +43 -0
  266. package/templates/app/app/http/middleware/access.ts +41 -0
  267. package/templates/app/app/http/middleware/api.ts +12 -3
  268. package/templates/app/app/http/middleware/page.test.ts +4 -1
  269. package/templates/app/app/http/middleware/page.ts +7 -5
  270. package/templates/app/app/initializers/cli.ts +35 -2
  271. package/templates/app/app/initializers/dispatcher.ts +9 -1
  272. package/templates/app/app/initializers/mail-transport.test.ts +33 -0
  273. package/templates/app/app/initializers/mail-transport.ts +26 -0
  274. package/templates/app/app/initializers/mail.test.ts +17 -17
  275. package/templates/app/app/initializers/mail.ts +15 -7
  276. package/templates/app/app/initializers/router.test.ts +7 -0
  277. package/templates/app/app/initializers/router.tsx +13 -3
  278. package/templates/app/app/jobs/email.test.tsx +70 -0
  279. package/templates/app/app/jobs/email.ts +16 -0
  280. package/templates/app/app/jobs/index.ts +6 -2
  281. package/templates/app/app/policies/abilities.ts +13 -0
  282. package/templates/app/app/policies/policy.test.ts +15 -0
  283. package/templates/app/app/policies/policy.ts +30 -0
  284. package/templates/app/app/services/commands.ts +30 -0
  285. package/templates/app/app/services/migrations.test.ts +48 -1
  286. package/templates/app/app/services/migrations.ts +66 -9
  287. package/templates/app/app/test/cloudflare-workers.ts +2 -0
  288. package/templates/app/app/test/local-database.ts +67 -0
  289. package/templates/app/app/test/session.ts +28 -0
  290. package/templates/app/bootstrap/console.ts +13 -0
  291. package/templates/app/cloudflare.config.ts +3 -3
  292. package/templates/app/database/seed.ts +12 -0
  293. package/templates/app/package.json +3 -1
  294. package/templates/app/spec/config.jsonc +16 -0
  295. package/stubs/policy.stub +0 -16
@@ -0,0 +1,67 @@
1
+ /**
2
+ * The {{title}} form, for a visitor `{{ability}}` admits: the page that shows it and the action
3
+ * that receives it. Describe what a submission changes and where the visitor lands afterwards.
4
+ *
5
+ * @see {@link https://sdxc.dev/docs/building-remix-apps/forms-and-params}
6
+ * @see {@link https://sdxc.dev/docs/identity-and-security/protect-forms}
7
+ * @see {@link https://sdxc.dev/docs/identity-and-security/authorization}{{header}}
8
+ */
9
+
10
+ import { captcha } from "@sdxc/captcha/middleware";
11
+ import { TurnstileWidget } from "@sdxc/captcha/turnstile/ui";
12
+ import { HoneypotFields } from "@sdxc/honeypot/ui";
13
+ import { unwrap } from "@sdxc/result";
14
+ import { spam } from "@sdxc/spam/middleware";
15
+ import { env } from "cloudflare:workers";
16
+ import { createController } from "remix/router";
17
+
18
+ import page from "~/app/http/middleware/page";
19
+ import { turnstile } from "~/app/initializers/captcha";
20
+ import { spamFilter } from "~/app/initializers/spam";
21
+ import abilities from "~/app/policies/abilities";
22
+ import DocumentLayout from "~/resources/layouts/document";
23
+ import routes from "{{routes}}";
24
+
25
+ export default createController(routes.{{path}}, {
26
+ middleware: page,
27
+ actions: {
28
+ /**
29
+ * Renders the form with fresh honeypot fields, which the page middleware checks on submit,
30
+ * and the Turnstile widget, admitted by the response's CSP nonce.
31
+ */
32
+ async index(ctx) {
33
+ {{pageAccess}}
34
+ let fields = unwrap(await ctx.honeypot.issue());
35
+ return ctx.render(
36
+ <DocumentLayout assets={ctx.assets} intl={ctx.intl} url={ctx.url} title="{{title}}">
37
+ <h1>{{title}}</h1>
38
+ <form method="post" action={routes.{{path}}.action.href({{params}})}>
39
+ <HoneypotFields {...fields} />
40
+ {/* TODO: replace the message field with the fields this form submits */}
41
+ <label>
42
+ Message <textarea name="message" required />
43
+ </label>
44
+ <TurnstileWidget siteKey={env.TURNSTILE_SITE_KEY} nonce={ctx.assets.nonce} />
45
+ <button type="submit">Send</button>
46
+ </form>
47
+ </DocumentLayout>,
48
+ );
49
+ },
50
+
51
+ /**
52
+ * Receives a submission that passed the honeypot, the CAPTCHA (a 403 otherwise), the
53
+ * spam filter (a 422 otherwise) and `{{ability}}`, and sends the visitor back to the form.
54
+ */
55
+ action: {
56
+ middleware: [captcha(turnstile), spam(spamFilter, { fields: { content: "message" } })],
57
+ async handler(ctx) {
58
+ {{access}}
59
+ // TODO: save the submission, then redirect where the visitor should land
60
+ return new Response(null, {
61
+ status: 303,
62
+ headers: { location: routes.{{path}}.index.href({{params}}) },
63
+ });
64
+ },
65
+ },
66
+ },
67
+ });
@@ -0,0 +1,28 @@
1
+ /**
2
+ * The {{title}} page, for a visitor `{{ability}}` admits: describe what they find here and why
3
+ * the route exists.
4
+ *
5
+ * @see {@link https://sdxc.dev/docs/building-remix-apps/wire-the-router}
6
+ * @see {@link https://sdxc.dev/docs/identity-and-security/authorization}{{header}}
7
+ */
8
+
9
+ import { createAction } from "remix/router";
10
+
11
+ import page from "~/app/http/middleware/page";
12
+ import abilities from "~/app/policies/abilities";
13
+ import DocumentLayout from "~/resources/layouts/document";
14
+ import routes from "{{routes}}";
15
+
16
+ export default createAction(routes.{{path}}, {
17
+ middleware: page,
18
+ /** Renders the {{title}} page once `ctx.access` admits `{{ability}}`. */
19
+ async handler(ctx) {
20
+ {{pageAccess}}
21
+ return ctx.render(
22
+ <DocumentLayout assets={ctx.assets} intl={ctx.intl} url={ctx.url} title="{{title}}">
23
+ <h1>{{title}}</h1>
24
+ {/* TODO: render the page */}
25
+ </DocumentLayout>,
26
+ );
27
+ },
28
+ });
@@ -0,0 +1,15 @@
1
+ # The {{title}} page, opened through a real browser the way a visitor reaches it.
2
+ #
3
+ # @see https://sdxc.dev/docs/operations-and-testing/testing
4
+ # @see https://sdxc.dev/docs/building-remix-apps/wire-the-router
5
+
6
+ use browser
7
+
8
+ test "{{title}} page loads" {
9
+ when {
10
+ browser.open "{{url}}"
11
+ }
12
+ then {
13
+ expect browser.heading "{{title}}"
14
+ }
15
+ }
package/stubs/email.stub CHANGED
@@ -1,26 +1,21 @@
1
1
  /**
2
- * The {{title}} email: describe who receives it and what it tells them.
2
+ * The {{title}} email: describe who receives it and what it tells them. Its props are declared
3
+ * in `app/emails/index.ts`; translate copy with `handle.props.t`, in `handle.props.locale`.
3
4
  *
4
5
  * @see {@link https://sdxc.dev/docs/data-and-background-work/send-email}
5
6
  * @see {@link https://sdxc.dev/api/mail}{{header}}
6
7
  */
7
8
 
8
- import { defineEmail, Email } from "@sdxc/mail";
9
+ import { createEmail, Email } from "@sdxc/mail";
9
10
 
10
- /** What the {{title}} email says, already translated for its reader. */
11
- export interface {{Name}}Copy {
12
- heading: string;
13
- body: string;
14
- }
11
+ import emails from "~/app/emails";
15
12
 
16
- /** The {{title}} email, sent with `new {{Name}}Email(recipient, copy)`. */
17
- export const {{Name}}Email = defineEmail<{{Name}}Copy>({
18
- subject: (copy) => copy.heading,
13
+ export default createEmail(emails.{{path}}, {
14
+ subject: {{subject}},
19
15
  body: (handle) => () => (
20
- <Email.Layout preview={handle.props.heading} title={handle.props.heading}>
21
- <Email.Heading>{handle.props.heading}</Email.Heading>
22
- <Email.Text>{handle.props.body}</Email.Text>
23
- {/* TODO: lay out the rest of the email */}
16
+ <Email.Layout lang={handle.props.locale} title={{layoutTitle}}>
17
+ {{body}}
24
18
  </Email.Layout>
25
19
  ),
20
+ preview: () => ({{preview}}),
26
21
  });
@@ -1,21 +1,21 @@
1
1
  /**
2
- * The {{title}} email.
2
+ * The {{title}} email, rendered through the app's email registry.
3
3
  *
4
4
  * @see {@link https://sdxc.dev/docs/data-and-background-work/send-email}
5
5
  * @see {@link https://sdxc.dev/docs/operations-and-testing/testing}{{header}}
6
6
  */
7
7
 
8
- import { render } from "@sdxc/mail";
8
+ import { unwrap } from "@sdxc/result";
9
9
  import { describe, expect, test } from "vitest";
10
10
 
11
- import { {{Name}}Email } from "{{specifier}}";
11
+ import emails from "~/app/emails";
12
+ import { mail } from "~/app/initializers/mail";
12
13
 
13
- describe("{{Name}}Email", () => {
14
- test("is addressed to its recipient under its heading", async () => {
15
- let email = new {{Name}}Email("ada@example.com", { heading: "Hello", body: "Welcome." });
14
+ describe("{{title}} email", () => {
15
+ test("renders its props into the subject and both body parts", async () => {
16
+ let rendered = unwrap(await mail.render(emails.{{path}}, { props: {{sample}} }));
16
17
 
17
- expect(email.to).toEqual({ email: "ada@example.com" });
18
- expect(email.subject).toBe("Hello");
19
- expect((await render(email.body())).text).toContain("Welcome.");
18
+ expect(rendered.subject).toBe({{subjectSample}});
19
+ expect(rendered.text).toContain({{textSample}});
20
20
  });
21
21
  });
@@ -10,4 +10,4 @@ import { defineFactory } from "@sdxc/data-model/testing";
10
10
  import { {{Name}} } from "{{model}}";
11
11
 
12
12
  /** A complete {{title}} row; a test overrides only the fields it is about. */
13
- export const {{Name}}Factory = defineFactory({{Name}}, {});
13
+ export const {{Name}}Factory = defineFactory({{Name}}, {{{attributes}}});
@@ -0,0 +1,16 @@
1
+ # The {{title}} MCP tool, called over `/mcp` the way a client calls it.
2
+ #
3
+ # @see https://sdxc.dev/docs/operations-and-testing/testing
4
+ # @see https://sdxc.dev/docs/operations-and-testing/mcp-server
5
+
6
+ use mcp
7
+
8
+ test "{{tool}} answers over /mcp" {
9
+ when {
10
+ let result = mcp.call "/mcp" "{{tool}}" {} on "web"
11
+ }
12
+ then {
13
+ expect result.ok true
14
+ expect result.is_error false
15
+ }
16
+ }
package/stubs/model.stub CHANGED
@@ -12,14 +12,14 @@ import { column as c, table } from "remix/data-table";
12
12
  import { createModel } from "@sdxc/data-model";
13
13
  import { generateUUID } from "@sdxc/uuid/v7";
14
14
 
15
- /** The `{{snake}}` table, as its migration creates it. */
15
+ /** The `{{table}}` table, as its migration creates it. */
16
16
  export const {{key}}Table = table({
17
- name: "{{snake}}",
17
+ name: "{{table}}",
18
18
  columns: {
19
19
  id: c.text().primaryKey(),
20
+ {{columns}}
20
21
  created_at: c.integer(),
21
22
  updated_at: c.integer(),
22
- // TODO: add the columns the migration creates
23
23
  },
24
24
  /** `create` and `update` stamp `created_at` and `updated_at` with the database's clock. */
25
25
  timestamps: true,
@@ -1,20 +1,46 @@
1
1
  /**
2
- * The {{title}} policy.
2
+ * Who may do what with `{{path}}`: anyone reads one, and a signed-in member creates, updates and
3
+ * deletes one. Change its grants in `app/policies/policy.ts` and keep these cases in step.
3
4
  *
4
5
  * @see {@link https://sdxc.dev/docs/identity-and-security/authorization}
5
- * @see {@link https://sdxc.dev/docs/operations-and-testing/testing}{{header}}
6
+ * @see {@link https://sdxc.dev/api/authz}{{header}}
6
7
  */
7
8
 
9
+ import type { ContextOf } from "@sdxc/authz";
10
+
11
+ import { testAccess } from "@sdxc/authz/testing";
8
12
  import { describe, expect, test } from "vitest";
9
13
 
10
- import { {{key}} } from "{{specifier}}";
14
+ import abilities from "~/app/policies/abilities";
15
+ import policy from "~/app/policies/policy";
16
+
17
+ /** The record each check passes; no grant reads its fields until one gains a condition. */
18
+ const RECORD = { id: "1" } as ContextOf<typeof abilities.{{path}}.read>["{{key}}"];
11
19
 
12
- describe("{{key}}", () => {
13
- test("refuses an anonymous visitor", () => {
14
- expect({{key}}(null)).toBe(false);
20
+ describe("{{path}}", () => {
21
+ test("lets a guest read one", () => {
22
+ let guest = testAccess(policy, { roles: [] });
23
+
24
+ expect(guest.can(abilities.{{path}}.read, { {{key}}: RECORD })).toBe(true);
15
25
  });
16
26
 
17
- test("allows a signed-in actor", () => {
18
- expect({{key}}({ id: "1" })).toBe(true);
27
+ test("lets a member create, update and delete one", () => {
28
+ let member = testAccess(policy, { roles: ["member"], facts: { actor: { id: "1" } } });
29
+
30
+ expect(member.can(abilities.{{path}}.create)).toBe(true);
31
+ expect(member.can(abilities.{{path}}.update, { {{key}}: RECORD })).toBe(true);
32
+ expect(member.can(abilities.{{path}}.delete, { {{key}}: RECORD })).toBe(true);
33
+ });
34
+
35
+ test("refuses a guest every write", () => {
36
+ let guest = testAccess(policy, { roles: [] });
37
+
38
+ expect(guest.check(abilities.{{path}}.create)).toMatchObject({ allowed: false });
39
+ expect(guest.check(abilities.{{path}}.update, { {{key}}: RECORD })).toMatchObject({
40
+ allowed: false,
41
+ });
42
+ expect(guest.check(abilities.{{path}}.delete, { {{key}}: RECORD })).toMatchObject({
43
+ allowed: false,
44
+ });
19
45
  });
20
46
  });
@@ -0,0 +1,34 @@
1
+ /**
2
+ * `POST /api/{{plural}}`: creates a {{words}} from the JSON body the `{{CONSTANT}}_CREATE`
3
+ * operation in `routes/api.ts` types. A body the operation or the model refuses is the
4
+ * `validationError` problem, and a caller `{{path}}.create` refuses gets a 403.
5
+ *
6
+ * @see {@link https://sdxc.dev/docs/http-apis/json-apis}
7
+ * @see {@link https://sdxc.dev/docs/identity-and-security/authorization}{{header}}
8
+ */
9
+
10
+ import { issuesFrom } from "@sdxc/problem";
11
+ import { isFailure } from "@sdxc/result";
12
+ import { createAction } from "remix/router";
13
+
14
+ import api from "~/app/http/middleware/api";
15
+ import abilities from "~/app/policies/abilities";
16
+ import problems from "~/config/problems";
17
+ import routes, { {{CONSTANT}}_CREATE } from "~/routes/api";
18
+
19
+ export default createAction(routes.api.{{pluralKey}}.create, {
20
+ middleware: api,
21
+ /** Answers the created {{words}} as `data` with a 201. */
22
+ async handler(ctx) {
23
+ if (!ctx.access.can(abilities.{{path}}.create)) return new Response(null, { status: 403 });
24
+ let input = await {{CONSTANT}}_CREATE.parse(ctx.request, ctx.params);
25
+ if (isFailure(input)) {
26
+ return problems.validationError({ extensions: { errors: issuesFrom(input.error) } });
27
+ }
28
+ let created = await ctx.models.{{key}}.create(input.data.body);
29
+ if (isFailure(created)) {
30
+ return problems.validationError({ extensions: { errors: issuesFrom(created.error) } });
31
+ }
32
+ return Response.json({ data: created.data }, { status: 201 });
33
+ },
34
+ });
@@ -0,0 +1,37 @@
1
+ /**
2
+ * `POST /api/{{plural}}` through the app's router. The API binds every caller as a guest until
3
+ * it authenticates them, and the policy grants a guest reads alone, so the write answers 403.
4
+ *
5
+ * @see {@link https://sdxc.dev/docs/http-apis/json-apis}
6
+ * @see {@link https://sdxc.dev/docs/operations-and-testing/testing}{{header}}
7
+ */
8
+
9
+ import { beforeAll, describe, expect, test } from "vitest";
10
+
11
+ import "~/app/http/controllers/api/{{plural}}/create";
12
+ import { createWebRouter } from "~/app/initializers/router";
13
+ import { migrate } from "~/app/test/database";
14
+ import routes from "~/routes/api";
15
+
16
+ beforeAll(migrate);
17
+
18
+ /** Posts `body` as JSON to the endpoint. */
19
+ function submit(body: Record<string, unknown>) {
20
+ return createWebRouter().fetch(
21
+ new Request(new URL(routes.api.{{pluralKey}}.create.href(), "https://example.com"), {
22
+ method: "POST",
23
+ headers: { "content-type": "application/json" },
24
+ body: JSON.stringify(body),
25
+ }),
26
+ );
27
+ }
28
+
29
+ describe("api/{{plural}}/create", () => {
30
+ test("answers 403 to a guest, who may only read", async () => {
31
+ let response = await submit({ {{jsonSample}} });
32
+
33
+ expect(response.status).toBe(403);
34
+ });
35
+
36
+ test.todo("creates the {{words}} for a caller {{path}}.create admits");
37
+ });
@@ -0,0 +1,34 @@
1
+ /**
2
+ * `DELETE /api/{{plural}}/:id`: deletes the {{words}} and answers 204, as the
3
+ * `{{CONSTANT}}_DESTROY` operation in `routes/api.ts` documents it. An id no {{words}} has, or
4
+ * one `{{path}}.read` hides, is the `notFound` problem; a caller `{{path}}.delete` refuses gets
5
+ * a 403.
6
+ *
7
+ * @see {@link https://sdxc.dev/docs/http-apis/json-apis}
8
+ * @see {@link https://sdxc.dev/docs/identity-and-security/authorization}{{header}}
9
+ */
10
+
11
+ import { isFailure } from "@sdxc/result";
12
+ import { createAction } from "remix/router";
13
+
14
+ import api from "~/app/http/middleware/api";
15
+ import abilities from "~/app/policies/abilities";
16
+ import problems from "~/config/problems";
17
+ import routes from "~/routes/api";
18
+
19
+ export default createAction(routes.api.{{pluralKey}}.destroy, {
20
+ middleware: api,
21
+ /** Answers an empty 204 once the {{words}} is gone. */
22
+ async handler(ctx) {
23
+ let row = await ctx.models.{{key}}.find(ctx.params.id);
24
+ if (row === null || !ctx.access.can(abilities.{{path}}.read, { {{key}}: row })) {
25
+ return problems.notFound();
26
+ }
27
+ if (!ctx.access.can(abilities.{{path}}.delete, { {{key}}: row })) {
28
+ return new Response(null, { status: 403 });
29
+ }
30
+ let deleted = await ctx.models.{{key}}.delete(ctx.params.id);
31
+ if (isFailure(deleted)) return problems.notFound();
32
+ return new Response(null, { status: 204 });
33
+ },
34
+ });
@@ -0,0 +1,44 @@
1
+ /**
2
+ * `DELETE /api/{{plural}}/:id` through the app's router. The API binds every caller as a guest
3
+ * until it authenticates them, and the policy grants a guest reads alone, so the write answers 403.
4
+ *
5
+ * @see {@link https://sdxc.dev/docs/http-apis/json-apis}
6
+ * @see {@link https://sdxc.dev/docs/operations-and-testing/testing}{{header}}
7
+ */
8
+
9
+ import { beforeAll, describe, expect, test } from "vitest";
10
+
11
+ import "~/app/http/controllers/api/{{plural}}/destroy";
12
+ import { createWebRouter } from "~/app/initializers/router";
13
+ import { factories, migrate } from "~/app/test/database";
14
+ import { {{Name}}Factory } from "~/database/factories/{{name}}";
15
+ import routes from "~/routes/api";
16
+
17
+ beforeAll(migrate);
18
+
19
+ /** Sends a DELETE for the {{words}} with `id`. */
20
+ function destroy(id: string) {
21
+ return createWebRouter().fetch(
22
+ new Request(new URL(routes.api.{{pluralKey}}.destroy.href({ id }), "https://example.com"), {
23
+ method: "DELETE",
24
+ }),
25
+ );
26
+ }
27
+
28
+ describe("api/{{plural}}/destroy", () => {
29
+ test("answers 403 to a guest, who may only read", async () => {
30
+ let row = await factories().create({{Name}}Factory);
31
+
32
+ let response = await destroy(row.id);
33
+
34
+ expect(response.status).toBe(403);
35
+ });
36
+
37
+ test("answers the notFound problem for an id no {{words}} has", async () => {
38
+ let response = await destroy("missing");
39
+
40
+ expect(response.status).toBe(404);
41
+ });
42
+
43
+ test.todo("deletes the {{words}} for a caller {{path}}.delete admits");
44
+ });
@@ -0,0 +1,23 @@
1
+ /**
2
+ * `GET /api/{{plural}}`: every {{words}} `{{path}}.read` admits, newest first, as the
3
+ * `{{PLURAL_CONSTANT}}_INDEX` operation in `routes/api.ts` documents it.
4
+ *
5
+ * @see {@link https://sdxc.dev/docs/http-apis/json-apis}
6
+ * @see {@link https://sdxc.dev/docs/identity-and-security/authorization}{{header}}
7
+ */
8
+
9
+ import { createAction } from "remix/router";
10
+
11
+ import api from "~/app/http/middleware/api";
12
+ import abilities from "~/app/policies/abilities";
13
+ import routes from "~/routes/api";
14
+
15
+ export default createAction(routes.api.{{pluralKey}}.index, {
16
+ middleware: api,
17
+ /** Lists the {{pluralWords}} the caller may read, so a hidden one is left out of `data`. */
18
+ async handler(ctx) {
19
+ let all = await ctx.models.{{key}}.query().orderBy("created_at", "desc").all();
20
+ let data = all.filter((row) => ctx.access.can(abilities.{{path}}.read, { {{key}}: row }));
21
+ return Response.json({ data });
22
+ },
23
+ });
@@ -0,0 +1,31 @@
1
+ /**
2
+ * `GET /api/{{plural}}` through the app's router, so the API chain and its access checks run as
3
+ * they do in the Worker.
4
+ *
5
+ * @see {@link https://sdxc.dev/docs/http-apis/json-apis}
6
+ * @see {@link https://sdxc.dev/docs/operations-and-testing/testing}{{header}}
7
+ */
8
+
9
+ import { beforeAll, describe, expect, test } from "vitest";
10
+
11
+ import "~/app/http/controllers/api/{{plural}}/index";
12
+ import { createWebRouter } from "~/app/initializers/router";
13
+ import { factories, migrate } from "~/app/test/database";
14
+ import { {{Name}}Factory } from "~/database/factories/{{name}}";
15
+ import routes from "~/routes/api";
16
+
17
+ beforeAll(migrate);
18
+
19
+ describe("api/{{plural}}/index", () => {
20
+ test("answers every {{words}} the caller may read as data", async () => {
21
+ let row = await factories().create({{Name}}Factory);
22
+
23
+ let response = await createWebRouter().fetch(
24
+ new URL(routes.api.{{pluralKey}}.index.href(), "https://example.com"),
25
+ );
26
+
27
+ expect(response.status).toBe(200);
28
+ let body = (await response.json()) as { data: Array<{ id: string }> };
29
+ expect(body.data.map((item) => item.id)).toContain(row.id);
30
+ });
31
+ });
@@ -0,0 +1,27 @@
1
+ /**
2
+ * `GET /api/{{plural}}/:id`: one {{words}}, as the `{{CONSTANT}}_SHOW` operation in
3
+ * `routes/api.ts` documents it. An id no {{words}} has, and one `{{path}}.read` hides, is the
4
+ * `notFound` problem.
5
+ *
6
+ * @see {@link https://sdxc.dev/docs/http-apis/json-apis}
7
+ * @see {@link https://sdxc.dev/docs/identity-and-security/authorization}{{header}}
8
+ */
9
+
10
+ import { createAction } from "remix/router";
11
+
12
+ import api from "~/app/http/middleware/api";
13
+ import abilities from "~/app/policies/abilities";
14
+ import problems from "~/config/problems";
15
+ import routes from "~/routes/api";
16
+
17
+ export default createAction(routes.api.{{pluralKey}}.show, {
18
+ middleware: api,
19
+ /** Answers the {{words}} as `data`. */
20
+ async handler(ctx) {
21
+ let row = await ctx.models.{{key}}.find(ctx.params.id);
22
+ if (row === null || !ctx.access.can(abilities.{{path}}.read, { {{key}}: row })) {
23
+ return problems.notFound();
24
+ }
25
+ return Response.json({ data: row });
26
+ },
27
+ });
@@ -0,0 +1,41 @@
1
+ /**
2
+ * `GET /api/{{plural}}/:id` through the app's router, so the API chain and its access checks run
3
+ * as they do in the Worker.
4
+ *
5
+ * @see {@link https://sdxc.dev/docs/http-apis/json-apis}
6
+ * @see {@link https://sdxc.dev/docs/operations-and-testing/testing}{{header}}
7
+ */
8
+
9
+ import { beforeAll, describe, expect, test } from "vitest";
10
+
11
+ import "~/app/http/controllers/api/{{plural}}/show";
12
+ import { createWebRouter } from "~/app/initializers/router";
13
+ import { factories, migrate } from "~/app/test/database";
14
+ import { {{Name}}Factory } from "~/database/factories/{{name}}";
15
+ import routes from "~/routes/api";
16
+
17
+ beforeAll(migrate);
18
+
19
+ /** Fetches the {{words}} with `id`. */
20
+ function show(id: string) {
21
+ return createWebRouter().fetch(
22
+ new URL(routes.api.{{pluralKey}}.show.href({ id }), "https://example.com"),
23
+ );
24
+ }
25
+
26
+ describe("api/{{plural}}/show", () => {
27
+ test("answers the {{words}} as data", async () => {
28
+ let row = await factories().create({{Name}}Factory);
29
+
30
+ let response = await show(row.id);
31
+
32
+ expect(response.status).toBe(200);
33
+ expect(((await response.json()) as { data: { id: string } }).data.id).toBe(row.id);
34
+ });
35
+
36
+ test("answers the notFound problem for an id no {{words}} has", async () => {
37
+ let response = await show("missing");
38
+
39
+ expect(response.status).toBe(404);
40
+ });
41
+ });
@@ -0,0 +1,44 @@
1
+ /**
2
+ * `PATCH /api/{{plural}}/:id`: changes the fields the JSON body names, typed by the
3
+ * `{{CONSTANT}}_UPDATE` operation in `routes/api.ts`; the others keep their values. An id no
4
+ * {{words}} has, or one `{{path}}.read` hides, is the `notFound` problem, a refused body the
5
+ * `validationError` one, and a caller `{{path}}.update` refuses gets a 403.
6
+ *
7
+ * @see {@link https://sdxc.dev/docs/http-apis/json-apis}
8
+ * @see {@link https://sdxc.dev/docs/identity-and-security/authorization}{{header}}
9
+ */
10
+
11
+ import { NotFound } from "@sdxc/data-model";
12
+ import { issuesFrom } from "@sdxc/problem";
13
+ import { isFailure } from "@sdxc/result";
14
+ import { createAction } from "remix/router";
15
+
16
+ import api from "~/app/http/middleware/api";
17
+ import abilities from "~/app/policies/abilities";
18
+ import problems from "~/config/problems";
19
+ import routes, { {{CONSTANT}}_UPDATE } from "~/routes/api";
20
+
21
+ export default createAction(routes.api.{{pluralKey}}.update, {
22
+ middleware: api,
23
+ /** Answers the saved {{words}} as `data`. */
24
+ async handler(ctx) {
25
+ let { id } = ctx.params;
26
+ let row = await ctx.models.{{key}}.find(id);
27
+ if (row === null || !ctx.access.can(abilities.{{path}}.read, { {{key}}: row })) {
28
+ return problems.notFound();
29
+ }
30
+ if (!ctx.access.can(abilities.{{path}}.update, { {{key}}: row })) {
31
+ return new Response(null, { status: 403 });
32
+ }
33
+ let input = await {{CONSTANT}}_UPDATE.parse(ctx.request, ctx.params);
34
+ if (isFailure(input)) {
35
+ return problems.validationError({ extensions: { errors: issuesFrom(input.error) } });
36
+ }
37
+ let updated = await ctx.models.{{key}}.update(id, input.data.body);
38
+ if (isFailure(updated)) {
39
+ if (updated.error instanceof NotFound) return problems.notFound();
40
+ return problems.validationError({ extensions: { errors: issuesFrom(updated.error) } });
41
+ }
42
+ return Response.json({ data: updated.data });
43
+ },
44
+ });
@@ -0,0 +1,46 @@
1
+ /**
2
+ * `PATCH /api/{{plural}}/:id` through the app's router. The API binds every caller as a guest
3
+ * until it authenticates them, and the policy grants a guest reads alone, so the write answers 403.
4
+ *
5
+ * @see {@link https://sdxc.dev/docs/http-apis/json-apis}
6
+ * @see {@link https://sdxc.dev/docs/operations-and-testing/testing}{{header}}
7
+ */
8
+
9
+ import { beforeAll, describe, expect, test } from "vitest";
10
+
11
+ import "~/app/http/controllers/api/{{plural}}/update";
12
+ import { createWebRouter } from "~/app/initializers/router";
13
+ import { factories, migrate } from "~/app/test/database";
14
+ import { {{Name}}Factory } from "~/database/factories/{{name}}";
15
+ import routes from "~/routes/api";
16
+
17
+ beforeAll(migrate);
18
+
19
+ /** Sends `body` as JSON to the endpoint of the {{words}} with `id`. */
20
+ function submit(id: string, body: Record<string, unknown>) {
21
+ return createWebRouter().fetch(
22
+ new Request(new URL(routes.api.{{pluralKey}}.update.href({ id }), "https://example.com"), {
23
+ method: "PATCH",
24
+ headers: { "content-type": "application/json" },
25
+ body: JSON.stringify(body),
26
+ }),
27
+ );
28
+ }
29
+
30
+ describe("api/{{plural}}/update", () => {
31
+ test("answers 403 to a guest, who may only read", async () => {
32
+ let row = await factories().create({{Name}}Factory);
33
+
34
+ let response = await submit(row.id, { {{changedJson}} });
35
+
36
+ expect(response.status).toBe(403);
37
+ });
38
+
39
+ test("answers the notFound problem for an id no {{words}} has", async () => {
40
+ let response = await submit("missing", { {{changedJson}} });
41
+
42
+ expect(response.status).toBe(404);
43
+ });
44
+
45
+ test.todo("changes the {{words}} for a caller {{path}}.update admits");
46
+ });