@rsc-kit/mcp 0.30.39 → 0.30.43
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/dist/recipes.js +196 -13
- package/dist/recipes.js.map +1 -1
- package/guides/admin-plugins.md +5 -5
- package/guides/admin.md +121 -17
- package/guides/api-routes.md +21 -0
- package/guides/caching.md +85 -3
- package/guides/coming-from-inertia.md +1 -1
- package/guides/coming-from-next.md +1 -0
- package/guides/edge-caching.md +72 -0
- package/guides/index.json +13 -3
- package/guides/laravel.md +8 -0
- package/guides/pages.md +177 -0
- package/guides/public-forms.md +113 -0
- package/guides/redirects.md +21 -1
- package/guides/your-own-backend.md +17 -0
- package/package.json +2 -2
package/guides/pages.md
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# Pages from blocks
|
|
2
|
+
|
|
3
|
+
> Landing pages, an about page, a pricing page - built in the admin panel from the app's own blocks, live on the next visit.
|
|
4
|
+
|
|
5
|
+
`@rsc-kit/press/pages` lets an editor build pages in the [admin panel](/guides/admin/)
|
|
6
|
+
from blocks the app defines - a hero, a feature grid, a call to action, a
|
|
7
|
+
[public form](/guides/public-forms/) - and serves them from one catch-all
|
|
8
|
+
route. The blocks are the app's code and look like the rest of the site; what
|
|
9
|
+
is on a page, and in what order, is the editor's.
|
|
10
|
+
|
|
11
|
+
## Blocks
|
|
12
|
+
|
|
13
|
+
A block is a schema for what an editor fills in and a component that draws
|
|
14
|
+
it:
|
|
15
|
+
|
|
16
|
+
```tsx title="src/site/blocks.tsx"
|
|
17
|
+
import * as z from 'zod'
|
|
18
|
+
import { defineBlock } from '@rsc-kit/press'
|
|
19
|
+
|
|
20
|
+
export const hero = defineBlock({
|
|
21
|
+
name: 'hero',
|
|
22
|
+
form: z.object({
|
|
23
|
+
heading: z.string().min(3).max(80),
|
|
24
|
+
lead: z.string().max(300).optional(),
|
|
25
|
+
}),
|
|
26
|
+
fields: { lead: { type: 'textarea' } },
|
|
27
|
+
render: ({ data }) => (
|
|
28
|
+
<section>
|
|
29
|
+
<h1>{data.heading}</h1>
|
|
30
|
+
{data.lead && <p>{data.lead}</p>}
|
|
31
|
+
</section>
|
|
32
|
+
),
|
|
33
|
+
})
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`form` is any Standard Schema, and `fields` overrides what it cannot say, as a
|
|
37
|
+
[resource's form](/guides/admin/#the-form-is-any-standard-schema) does. `render`
|
|
38
|
+
is a server component and may be async: a block that lists the latest posts
|
|
39
|
+
reads them itself. A block can place a public form - `render: () => <contact.Form />` -
|
|
40
|
+
so the editor decides where it goes and the code decides what it does.
|
|
41
|
+
|
|
42
|
+
## The pages
|
|
43
|
+
|
|
44
|
+
```ts title="src/site/pages.ts"
|
|
45
|
+
import { FileText } from 'lucide-react'
|
|
46
|
+
import type { DataSource } from '@rsc-kit/press'
|
|
47
|
+
import { definePages, type PageRow, type PageValues } from '@rsc-kit/press/pages'
|
|
48
|
+
import { features, hero, text } from './blocks'
|
|
49
|
+
|
|
50
|
+
export const site = definePages({
|
|
51
|
+
blocks: [hero, features, text],
|
|
52
|
+
source: pagesSource,
|
|
53
|
+
icon: FileText,
|
|
54
|
+
})
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Three files serve them:
|
|
58
|
+
|
|
59
|
+
```tsx title="src/app/[...path]/page.tsx"
|
|
60
|
+
import { site } from '@/site/pages'
|
|
61
|
+
|
|
62
|
+
export const generateMetadata = site.generateMetadata
|
|
63
|
+
|
|
64
|
+
export default function SitePage({ params }: { params: Promise<{ path: string }> }) {
|
|
65
|
+
return (
|
|
66
|
+
<main>
|
|
67
|
+
<site.Page params={params} />
|
|
68
|
+
</main>
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
```ts title="src/app/[...path]/middleware.ts"
|
|
74
|
+
import { site } from '@/site/pages'
|
|
75
|
+
|
|
76
|
+
export default site.middleware
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
```ts title="src/admin/panel.ts"
|
|
80
|
+
resources: [site.resource, products, customers],
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
The catch-all is the weakest route there is, so every page and route the app
|
|
84
|
+
has wins over it; it answers only the addresses nothing else does. A page's
|
|
85
|
+
slug is its address - `about`, `pricing/teams` - and the one named `home` is
|
|
86
|
+
served at `/` when the app has no `app/page.tsx` of its own (`home` changes
|
|
87
|
+
which).
|
|
88
|
+
|
|
89
|
+
The middleware asks whether there is a published page at the address before
|
|
90
|
+
anything is sent, so a draft or a typo is a real **404**. Without it the
|
|
91
|
+
route's shell has already gone out with a 200 by the time the page finds
|
|
92
|
+
nothing - see [Errors](/guides/errors/#when-the-page-has-to-decide).
|
|
93
|
+
|
|
94
|
+
## Live on the next visit
|
|
95
|
+
|
|
96
|
+
A save in the panel is live on the next visit, and nothing is rebuilt. A page
|
|
97
|
+
is looked up once and then kept, so most visits do not ask the source at all:
|
|
98
|
+
for 60 seconds, or until any page is saved. The page is kept with
|
|
99
|
+
[`cache()`](/guides/caching/#across-requests), in memory unless the app installs
|
|
100
|
+
a shared store. `revalidate` sets the lifetime, and `false` asks on every
|
|
101
|
+
request:
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
export const site = definePages({ blocks, source, revalidate: 300 })
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
A change made around the panel, straight in the database, shows when the kept
|
|
108
|
+
copy expires, or at once after `changed('press:pages')`. The build stores the route's
|
|
109
|
+
frame as one shell for every address, and the page streams into it. A page
|
|
110
|
+
also has a title and a description, which become its `<title>` and meta
|
|
111
|
+
description; a draft is a page with Published off, reachable only in the
|
|
112
|
+
panel.
|
|
113
|
+
|
|
114
|
+
## Where pages are kept
|
|
115
|
+
|
|
116
|
+
`source` is a [data source](/guides/admin/#any-data-source) of rows shaped
|
|
117
|
+
`{ id, title, slug, description?, published, blocks }`, where `blocks` is a
|
|
118
|
+
list of `{ type, data }` - a JSON column in a database. Its `list()` is also
|
|
119
|
+
how a page is found by its address: it is asked for `filters: { slug }`, and
|
|
120
|
+
must answer with the page at that slug. `memorySource` does; a Laravel or Go
|
|
121
|
+
backend behind `rpc()` filters on the column.
|
|
122
|
+
|
|
123
|
+
`memorySource` keeps the pages in the process's memory: an edit is gone
|
|
124
|
+
when the server restarts, and two servers each have their own copy. It is
|
|
125
|
+
for a demo, or for pages that only ever come from rows in code. Pages an
|
|
126
|
+
editor saves belong where the app keeps its other data. On a Laravel or Go
|
|
127
|
+
backend that is a `pages` table with a JSON `blocks` column, behind `rpc()`:
|
|
128
|
+
|
|
129
|
+
```ts title="src/site/pages.ts"
|
|
130
|
+
const pagesSource: DataSource<PageRow, PageValues> = {
|
|
131
|
+
list: (query) => rpc('Pages.list', query),
|
|
132
|
+
find: (id) => rpc('Pages.find', Number(id)),
|
|
133
|
+
create: (values) => rpc('Pages.create', values),
|
|
134
|
+
update: (id, values) => rpc('Pages.update', Number(id), values),
|
|
135
|
+
delete: (id) => rpc('Pages.delete', Number(id)),
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
```php title="app/Rsc/Pages.php"
|
|
140
|
+
public function list(array $query): array
|
|
141
|
+
{
|
|
142
|
+
$pages = Page::query()
|
|
143
|
+
->when($query['filters']['slug'] ?? null, fn ($q, $slug) => $q->where('slug', $slug))
|
|
144
|
+
->paginate($query['perPage'] ?? 15, page: $query['page'] ?? 1);
|
|
145
|
+
|
|
146
|
+
return ['rows' => $pages->items(), 'total' => $pages->total()];
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Cast `blocks` to an array on the model, and `published` to a boolean. An app
|
|
151
|
+
with no backend writes the same five functions over its own database -
|
|
152
|
+
Drizzle, Prisma, `bun:sqlite`.
|
|
153
|
+
|
|
154
|
+
Each block's data is checked by its own schema on every save, and a refusal
|
|
155
|
+
shows under that block's field. An address belongs to one page: saving a
|
|
156
|
+
second page at `/about` is refused under its slug.
|
|
157
|
+
|
|
158
|
+
## Blocks in any resource
|
|
159
|
+
|
|
160
|
+
The block editor is a field type, so any resource can have one - a product's
|
|
161
|
+
long description, a post's body:
|
|
162
|
+
|
|
163
|
+
```ts
|
|
164
|
+
form: z.object({ name: z.string(), body: z.array(z.any()) }),
|
|
165
|
+
fields: { body: { blocks: [text, gallery, quote] } },
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Draw what was saved with `Blocks`:
|
|
169
|
+
|
|
170
|
+
```tsx
|
|
171
|
+
import { Blocks } from '@rsc-kit/press'
|
|
172
|
+
|
|
173
|
+
<Blocks blocks={[text, gallery, quote]} value={post.body} />
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
A block whose kind the code no longer defines is left out of the page rather
|
|
177
|
+
than failing it, and the editor says that saving will remove it.
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# Public forms
|
|
2
|
+
|
|
3
|
+
> A contact form, a sign-up, a survey - drawn from a Standard Schema, checked in the browser and on the server, sent to any backend.
|
|
4
|
+
|
|
5
|
+
`@rsc-kit/press/forms` turns a Standard Schema into a form anyone may fill in.
|
|
6
|
+
It is the panel's form without the panel: the same fields read from the same
|
|
7
|
+
schema, the same browser checks, the same refusals under the same fields - and
|
|
8
|
+
a [theme](/guides/admin/#themes) to draw it. The `shadcn` theme draws both.
|
|
9
|
+
|
|
10
|
+
```ts title="src/forms/contact.ts"
|
|
11
|
+
import * as z from 'zod'
|
|
12
|
+
import { defineForm } from '@rsc-kit/press/forms'
|
|
13
|
+
import { shadcn } from '@rsc-kit/press/shadcn'
|
|
14
|
+
|
|
15
|
+
export const contact = defineForm({
|
|
16
|
+
name: 'contact',
|
|
17
|
+
form: z.object({
|
|
18
|
+
name: z.string().min(2),
|
|
19
|
+
email: z.email(),
|
|
20
|
+
message: z.string().min(10).max(2000),
|
|
21
|
+
}),
|
|
22
|
+
fields: { message: { type: 'textarea' } },
|
|
23
|
+
theme: shadcn,
|
|
24
|
+
submit: 'Send message',
|
|
25
|
+
done: 'Thanks - we will be in touch.',
|
|
26
|
+
handle: async (values) => {
|
|
27
|
+
await db.insert(messages).values(values)
|
|
28
|
+
},
|
|
29
|
+
})
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Place it in any page:
|
|
33
|
+
|
|
34
|
+
```tsx title="src/app/contact/page.tsx"
|
|
35
|
+
import { contact } from '@/forms/contact'
|
|
36
|
+
|
|
37
|
+
export default function ContactPage() {
|
|
38
|
+
return (
|
|
39
|
+
<main>
|
|
40
|
+
<h1>Contact us</h1>
|
|
41
|
+
<contact.Form />
|
|
42
|
+
</main>
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
The form reads nothing from the request, so the page around it is stored by
|
|
48
|
+
the build like any other static page. Only sending it runs on the server.
|
|
49
|
+
|
|
50
|
+
Install is the panel's: `bun add @rsc-kit/press`, and the
|
|
51
|
+
`@import "@rsc-kit/press/shadcn.css"` line in the app's stylesheet, as in
|
|
52
|
+
[Admin panels](/guides/admin/#install).
|
|
53
|
+
|
|
54
|
+
## What is checked, and where
|
|
55
|
+
|
|
56
|
+
The schema's constraints become the browser's - `required`, `minlength`,
|
|
57
|
+
`maxlength`, `type="email"`, a `pattern` - so a visitor hears about a missing
|
|
58
|
+
field before anything is sent, under the field, in their own language. The
|
|
59
|
+
schema then checks every submission on the server, which is the check that
|
|
60
|
+
counts: anyone can post without a browser. What it refuses comes back under
|
|
61
|
+
each field, with what was typed kept.
|
|
62
|
+
|
|
63
|
+
`handle` gets the values only once they have passed. A refusal it decides -
|
|
64
|
+
an address already signed up - goes under its field the same way:
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
import { fieldErrors } from '@rsc-kit/core/action'
|
|
68
|
+
|
|
69
|
+
handle: async ({ email }) => {
|
|
70
|
+
if (await subscribed(email)) fieldErrors({ email: 'That address is already on the list.' })
|
|
71
|
+
await subscribe(email)
|
|
72
|
+
},
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## A Laravel or Go backend
|
|
76
|
+
|
|
77
|
+
`handle` is a server function, so it can hand the values on with `rpc()`:
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
handle: (values) => rpc('Contact.send', values),
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
The backend validates again. A 422 from it - a Laravel `FormRequest`, a Go
|
|
84
|
+
handler's field errors - shows under the same fields as the schema's, with
|
|
85
|
+
nothing to catch.
|
|
86
|
+
|
|
87
|
+
## Once it is sent
|
|
88
|
+
|
|
89
|
+
`done` is what the visitor reads in place of the form; without one it says
|
|
90
|
+
the message was sent. `redirect` sends them somewhere instead - a thank-you
|
|
91
|
+
page, the account they just made - and a form has one or the other, not both.
|
|
92
|
+
|
|
93
|
+
## Bots
|
|
94
|
+
|
|
95
|
+
Every form carries a field people never see: off screen, out of the tab order,
|
|
96
|
+
hidden from screen readers and not autofilled. A bot filling in every input
|
|
97
|
+
fills that one too, and the submission is answered as though it worked and
|
|
98
|
+
dropped - `handle` never sees it, and the bot learns nothing. It is a filter
|
|
99
|
+
for the crudest spam, not a CAPTCHA; a form worth attacking wants rate
|
|
100
|
+
limiting in front of it as well.
|
|
101
|
+
|
|
102
|
+
The trap is named `homepage`, so a form cannot have a field of that name.
|
|
103
|
+
|
|
104
|
+
## Drawing it yourself
|
|
105
|
+
|
|
106
|
+
The theme's part is one component, `PublicForm`, typed `FormsTheme` from
|
|
107
|
+
`@rsc-kit/press/forms`. It is given the bound `action`, the `fields`, the
|
|
108
|
+
`submit` words, `done`, and the `honeypot` field's name to render hidden.
|
|
109
|
+
Replace it as you would a panel page:
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
theme: { ...shadcn, PublicForm: MyForm },
|
|
113
|
+
```
|
package/guides/redirects.md
CHANGED
|
@@ -172,7 +172,27 @@ An action is not a render, so there is no shell to be on either side of. Throw
|
|
|
172
172
|
from the action — a plain `"use server"` function or one built from
|
|
173
173
|
`createActionClient()` — and the client follows it as a navigation: the
|
|
174
174
|
layouts stay mounted and the history entry the form was on is replaced, so
|
|
175
|
-
Back does not return to the submitted form.
|
|
175
|
+
Back does not return to the submitted form.
|
|
176
|
+
|
|
177
|
+
The layouts are not rendered again, as on any navigation: most redirects —
|
|
178
|
+
save, then the list — change nothing a layout reads. One that does says so,
|
|
179
|
+
the way any action does. `revalidate('all')` before the `redirect()` asks for
|
|
180
|
+
the destination whole, layouts included; a named section counts too, since it
|
|
181
|
+
can live in a layout. A team switch whose name is in the sidebar:
|
|
182
|
+
|
|
183
|
+
```ts
|
|
184
|
+
'use server'
|
|
185
|
+
|
|
186
|
+
export async function switchTeam(id: string) {
|
|
187
|
+
await setCurrentTeam(id)
|
|
188
|
+
revalidate('all')
|
|
189
|
+
redirect('/dashboard')
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
Without it the page is the new team's and the sidebar still names the old one
|
|
194
|
+
until a reload. The same holds for a backend action: `Rsc::revalidate('all')`
|
|
195
|
+
before the redirect. A `<Form>` shows nothing for it;
|
|
176
196
|
signing in and arriving is the success.
|
|
177
197
|
|
|
178
198
|
To the caller, the action **resolves** — with `{ redirected: '/where' }` —
|
|
@@ -314,6 +314,22 @@ it cannot go stale: a stale one names a method since renamed, and nothing
|
|
|
314
314
|
fails until the browser calls it. Laravel's `rsc:host-manifest` is this
|
|
315
315
|
step; a Go registry's `WriteManifest` writes the same file.
|
|
316
316
|
|
|
317
|
+
### A message for the next page
|
|
318
|
+
|
|
319
|
+
`useFlash()` on the page shows what an action leaves for the next one. Your
|
|
320
|
+
side leaves one by setting a cookie on the reply, the way a login does: named
|
|
321
|
+
`rsc-flash`, its value a URI-encoded JSON list of `{ "message", "kind" }` -
|
|
322
|
+
`kind` one of `success`, `error`, `info`, `warning` - with `Path=/`, a short
|
|
323
|
+
`Max-Age` and `SameSite=Lax`.
|
|
324
|
+
|
|
325
|
+
```
|
|
326
|
+
Set-Cookie: rsc-flash=%5B%7B%22message%22%3A%22Saved.%22%2C%22kind%22%3A%22success%22%7D%5D; Path=/; Max-Age=60; SameSite=Lax
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
The browser reads it, so it is never `HttpOnly` and never encrypted - Laravel's
|
|
330
|
+
`Rsc::flash()` exempts it from `EncryptCookies`. A message the visitor's cookie
|
|
331
|
+
still carries goes first: append to the list, do not replace it.
|
|
332
|
+
|
|
317
333
|
## Urls you own
|
|
318
334
|
|
|
319
335
|
The renderer forwards any url the route tree does not own — `/login`, a
|
|
@@ -382,6 +398,7 @@ ordinary API, the way an app would write them:
|
|
|
382
398
|
| `Conformance.authorization` | return the forwarded `Authorization` header |
|
|
383
399
|
| `Conformance.cookie` | return the forwarded `Cookie` header |
|
|
384
400
|
| `Conformance.login` | set a cookie named `conformance_login` on the response, and return `"ok"` |
|
|
401
|
+
| `Conformance.flash` | leave the one-time message `"Saved."` (`"success"`) for the next page, after any the visitor's `rsc-flash` cookie still carries, and return `"ok"` |
|
|
385
402
|
| `Conformance.change` | say `conformance:changed` changed, as your webhook would, and return `"ok"` |
|
|
386
403
|
|
|
387
404
|
And three guards: `conformance-allow`, which passes, `conformance-deny`, which
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsc-kit/mcp",
|
|
3
|
-
"version": "0.30.
|
|
3
|
+
"version": "0.30.43",
|
|
4
4
|
"description": "An MCP server over what an rsc-kit build decided: the routes, why each one is static or not, and what it costs the browser.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
37
|
-
"create-rsc-kit": "^0.30.
|
|
37
|
+
"create-rsc-kit": "^0.30.43",
|
|
38
38
|
"zod": "^3.25"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|