@rsc-kit/mcp 0.30.39 → 0.30.42

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 CHANGED
@@ -218,6 +218,13 @@ router.replace or a Suspense key: the form already does this. It is the form
218
218
  only - a <Link> or visit() to the same path with another query is a page of its
219
219
  own. A search to ANOTHER page still shows that page's shell first.
220
220
 
221
+ A REDIRECT FROM AN ACTION keeps the layouts as they were, like a link: right
222
+ for save-then-list. If the action changed what a LAYOUT reads (team switch,
223
+ sign-in, a count in the sidebar), call revalidate('all') BEFORE redirect() -
224
+ the destination then comes back whole, layouts included. A named section counts
225
+ too. Backend: Rsc::revalidate('all') before the redirect. Without it the page is
226
+ new and the sidebar is stale until a reload.
227
+
221
228
  A MESSAGE FOR THE NEXT PAGE ("Saved." after a save that redirects): the return
222
229
  value goes to the form, which the redirect replaced. Call
223
230
  await flash('Product saved.') from @rsc-kit/core/flash in the action before
@@ -226,7 +233,12 @@ useFlash(({ message, kind }) => toast(message)) from @rsc-kit/core/useFlash.
226
233
  kind: 'success' (default) | 'error' | 'info' | 'warning'. flash() sets a cookie:
227
234
  an action, middleware or route.ts, NEVER a page. The browser takes it after the
228
235
  navigation (or when the cookie changes) and clears it, so a stored page stays
229
- cacheable. Do NOT read it in a server component, and render it as text.`,
236
+ cacheable. Do NOT read it in a server component, and render it as text.
237
+ From the backend, the same message: Laravel Rsc::flash('Invoice sent.') or
238
+ Rsc::flash('Declined.', 'error'); Go rsckit.Flash(ctx, rsckit.FlashSuccess,
239
+ "Invoice sent."). In an action called by rpc() it rides the host call onto the
240
+ page, as a login cookie does; NOT from a batched read. The same useFlash()
241
+ shows it. Nothing secret: the browser reads it, unencrypted.`,
230
242
  },
231
243
  {
232
244
  topic: 'prefetch',
@@ -663,6 +675,19 @@ for a component under its own <Suspense> and for a parallel route slot. Only
663
675
  an authorization check should NOT be there: the layouts above already
664
676
  rendered. See the redirects guide.
665
677
 
678
+ TO LET A CDN KEEP A PAGE RENDERED PER REQUEST: export const revalidate = 60
679
+ (seconds, a number literal; a layout may export it too and the smallest wins,
680
+ 0 anywhere turns it off). The page is rendered whole, then sent Cache-Control:
681
+ public, max-age=0, s-maxage=60, stale-while-revalidate=86400 with an ETag
682
+ only if the render read nothing of the visitor; a 404 is kept a minute at
683
+ most. A revalidate page calls its backend as nobody: no cookie, no
684
+ Authorization, and a cookie the backend sets is dropped - do NOT export it on
685
+ a page that shows who is signed in. Otherwise the page is sent private,
686
+ no-store with Cache-Status: rsc-kit; fwd=bypass; detail=<reason> (cookies,
687
+ headers, request, connection, host-middleware, set-cookie, nonce, status,
688
+ failed-render, payload-url) and a log line naming what read the visitor. It is
689
+ not prerendered.
690
+
666
691
  FOR AN EDGE THAT CACHES PAGES: rsc-kit implements the edge contract (v2,
667
692
  docs: reference/edge-contract). Every server build writes .output/edge.json -
668
693
  { v: 2, build, shells, static, bypass } - whose shells are url patterns ("/",
@@ -910,6 +935,12 @@ apiUrl refuses a page, because fetching one gets html. It checks the PATH, not
910
935
  the response type - for types across the boundary use a server action or a
911
936
  query, where the return type is the function's because it is the same function.
912
937
 
938
+ A POST, PUT, PATCH or DELETE a browser sends from another site is answered 403
939
+ before the handler runs (Sec-Fetch-Site, else Origin against the host - Go's
940
+ http.CrossOriginProtection rule; actions and forms too). No CSRF token: do NOT
941
+ add one. A webhook or server sends neither header and is never refused. Another
942
+ origin that should post: rscKit({ trustedOrigins: ['https://admin.example.com'] }).
943
+
913
944
  They run their directory's \`middleware.ts\`, so an endpoint under a guarded
914
945
  path is guarded.
915
946
 
@@ -1281,6 +1312,10 @@ IMPORTS
1281
1312
  (optimistic: option + React's useOptimistic)
1282
1313
  cache from 'react' -> cache from @rsc-kit/core/cache: React's dedupes only inside a render; this one
1283
1314
  spans the request (guards, actions, api routes). The build names files still on React's
1315
+ unstable_cache, revalidateTag -> cache(fn, { key, revalidate, tags }) from @rsc-kit/core/cache keeps answers ACROSS
1316
+ requests (memory, or installCacheStore({ get, set }) for Redis/KV); changed(tag)
1317
+ from @rsc-kit/core/changed makes the next ask miss - no purge. Runs as nobody:
1318
+ cookies()/headers() throw inside it; arguments and answers are JSON
1284
1319
  @react-email/render, renderToString in an action -> the same call, in a module that starts with "use ssr"
1285
1320
  (the build warns naming the app file and the package; the stub throws when called)
1286
1321
  (how_to emails). Next gets away with it only for externalised packages; here it is explicit
@@ -2651,21 +2686,27 @@ add a second runner. The one in tests/ goes through the real build already.`,
2651
2686
  },
2652
2687
  {
2653
2688
  topic: 'admin',
2654
- summary: 'An admin panel with @rsc-kit/admin: resources over any data source, server or client tables, Standard Schema forms, auth, tenants, plugins',
2655
- body: `@rsc-kit/admin draws a shadcn admin panel (sidebar, data table, dialogs)
2656
- from resources. The app keeps what is its own: where the data lives, who may
2657
- see it, whose it is. Full guides: admin, admin-plugins.
2689
+ summary: 'An admin panel with @rsc-kit/press: resources over any data source, server or client tables, Standard Schema forms, auth, tenants, plugins, themes',
2690
+ body: `@rsc-kit/press builds an admin panel from resources; a theme draws it
2691
+ (@rsc-kit/press/shadcn: sidebar, data table, dialogs). The app keeps what is
2692
+ its own: where the data lives, who may see it, whose it is. Full guides:
2693
+ admin, admin-plugins. There is no @rsc-kit/admin any more - do not import it.
2694
+ @rsc-kit/press defineResource, memorySource, perTenant, definePlugin, types
2695
+ @rsc-kit/press/admin definePanel, resourceParams, recordParams, listSearch, pluginsSearch, AdminTheme
2696
+ @rsc-kit/press/forms defineForm - a public form from a schema (how_to public-forms)
2697
+ @rsc-kit/press/pages definePages - pages an editor builds from blocks (how_to pages)
2698
+ @rsc-kit/press/shadcn shadcn (the theme; it draws panels and public forms)
2658
2699
 
2659
2700
  SETUP: the app needs Tailwind v4 + shadcn (create-rsc-kit --tailwind --shadcn).
2660
2701
  In the app's stylesheet, after tailwind and shadcn:
2661
- @import "@rsc-kit/admin/styles.css";
2702
+ @import "@rsc-kit/press/shadcn.css";
2662
2703
  Without it the panel renders unstyled - the line is Tailwind's @source for the
2663
- panel's components.
2704
+ theme's components.
2664
2705
 
2665
2706
  A RESOURCE:
2666
2707
  \`\`\`ts
2667
2708
  import * as z from 'zod'
2668
- import { defineResource } from '@rsc-kit/admin'
2709
+ import { defineResource } from '@rsc-kit/press'
2669
2710
 
2670
2711
  export const products = defineResource<Product>()({
2671
2712
  name: 'products', key: 'id', title: 'name',
@@ -2708,7 +2749,7 @@ suppressHydrationWarning. modeToggle: false hides it.
2708
2749
  A DATA SOURCE is five functions, and the panel calls nothing else - a
2709
2750
  database, ORM, REST API or rpc() into Laravel/Go alike:
2710
2751
  \`\`\`ts
2711
- import type { DataSource } from '@rsc-kit/admin'
2752
+ import type { DataSource } from '@rsc-kit/press'
2712
2753
 
2713
2754
  const source: DataSource<Customer, Values> = {
2714
2755
  async list({ q, sort, dir, page, perPage, filters, searchable }, { tenant }) { return { rows, total } },
@@ -2747,7 +2788,8 @@ panel's own Delete below the table. bulkActions: [{ name: 'publish', label:
2747
2788
  'Publish', destructive?: true, run: (rows, context) => ... }] adds more. run
2748
2789
  gets ROWS, each found with the source's find() as the visitor - an id that is
2749
2790
  not theirs never reaches it - after authorize. destructive asks first. The
2750
- toast says "Publish: 3 products." unless run returns a string. 'delete' is
2791
+ toast says "3 products published." with done: 'published' (else "Publish: 3
2792
+ products."), or run's own string. 'delete' is
2751
2793
  reserved, and a readOnly resource with bulkActions throws.
2752
2794
 
2753
2795
  TABLE MODE: 'server' - each search/filter/sort/page is a request, list() gets
@@ -2759,10 +2801,12 @@ perPage: null if any resource using it is client mode.
2759
2801
 
2760
2802
  THE PANEL:
2761
2803
  \`\`\`ts
2762
- import { definePanel } from '@rsc-kit/admin'
2804
+ import { definePanel } from '@rsc-kit/press/admin'
2805
+ import { shadcn } from '@rsc-kit/press/shadcn'
2763
2806
 
2764
2807
  export const panel = definePanel({
2765
2808
  path: '/admin',
2809
+ theme: shadcn, // required; { ...shadcn, Dashboard: Mine } replaces one page
2766
2810
  resources: [products, customers],
2767
2811
  authorize: async () => (await currentUser())?.isAdmin === true,
2768
2812
  user: currentUser, // { name, email?, avatar? } for the sidebar footer
@@ -2774,6 +2818,11 @@ export const panel = definePanel({
2774
2818
  AUTH: the panel has no login of its own; authorize asks the app's. It runs on
2775
2819
  every page AND every save, delete and tenant switch (actions are public
2776
2820
  endpoints). A refusal is a 404. Do NOT guard only the pages.
2821
+ THEME: an AdminTheme is an object of components - Shell, Brand,
2822
+ TenantSwitcher, Nav, Breadcrumbs, UserMenu, Dashboard, Index, Table, Form,
2823
+ Plugins, Cell, Loading. Each gets data, bound server actions and drawn
2824
+ elements as props, never a component, so any may be a client component. The
2825
+ panel owns the guard, the data and the Suspense boundaries; a theme only draws.
2777
2826
  TENANTS: current() is read from the session; the panel refuses a current
2778
2827
  tenant that is not in tenants() (a forged cookie). switch() runs in a server
2779
2828
  action, so cookies().set works there.
@@ -2791,7 +2840,7 @@ sections by their files. Each re-exports from the panel:
2791
2840
  export default panel.Create
2792
2841
  src/app/admin/[resource]/[id]/page.tsx export const params = recordParams
2793
2842
  export default panel.Edit
2794
- resourceParams, recordParams and listSearch come from '@rsc-kit/admin'. The
2843
+ resourceParams, recordParams and listSearch come from '@rsc-kit/press/admin'. The
2795
2844
  section MUST be named admin-table.section.tsx: a delete refreshes it by name.
2796
2845
 
2797
2846
  PLUGINS: definePlugin({ name, resources?, widgets?, onChange? }). A widget is
@@ -2799,9 +2848,139 @@ PLUGINS: definePlugin({ name, resources?, widgets?, onChange? }). A widget is
2799
2848
  onChange(change) runs after a save/delete is written, with { panel, resource,
2800
2849
  id, change, values?, tenant }; a plugin that throws is logged and never fails
2801
2850
  the save. Export a function of options returning the plugin. Publish with
2802
- @rsc-kit/admin and react as PEER dependencies and the npm keyword
2851
+ @rsc-kit/press and react as PEER dependencies and the npm keyword
2803
2852
  rsc-kit-admin-plugin.`,
2804
2853
  },
2854
+ {
2855
+ topic: 'public-forms',
2856
+ summary: 'A public form (contact, sign-up, survey) from a Standard Schema with @rsc-kit/press/forms: browser and server checks, a bot trap, any backend',
2857
+ body: `defineForm turns a Standard Schema into a form anyone may fill in - the
2858
+ admin panel's form without the panel, drawn by the same theme. Full guide:
2859
+ public-forms.
2860
+
2861
+ \`\`\`ts title="src/forms/contact.ts"
2862
+ import * as z from 'zod'
2863
+ import { defineForm } from '@rsc-kit/press/forms'
2864
+ import { shadcn } from '@rsc-kit/press/shadcn'
2865
+
2866
+ export const contact = defineForm({
2867
+ name: 'contact', // unique; lowercase letters, digits, dashes
2868
+ form: z.object({ name: z.string().min(2), email: z.email(), message: z.string().min(10) }),
2869
+ fields: { message: { type: 'textarea' } }, // what the schema cannot say
2870
+ theme: shadcn,
2871
+ submit: 'Send message',
2872
+ done: 'Thanks - we will be in touch.', // shown in place of the form
2873
+ // redirect: '/thanks', // OR this; never both
2874
+ handle: async (values) => { await db.insert(messages).values(values) },
2875
+ })
2876
+ \`\`\`
2877
+
2878
+ \`\`\`tsx title="src/app/contact/page.tsx"
2879
+ import { contact } from '@/forms/contact'
2880
+ export default function ContactPage() {
2881
+ return <main><h1>Contact us</h1><contact.Form /></main>
2882
+ }
2883
+ \`\`\`
2884
+
2885
+ The form reads nothing from the request: the page stays static and is stored
2886
+ by the build. Do NOT add connection() or a Suspense boundary for it.
2887
+
2888
+ CHECKS: the schema's constraints become the browser's (required, minlength,
2889
+ type="email", pattern), with the message under the field. The schema checks
2890
+ every submission on the server again, and handle() only gets values that
2891
+ passed. A refusal handle() decides goes under its field:
2892
+ import { fieldErrors } from '@rsc-kit/core/action'
2893
+ if (await subscribed(email)) fieldErrors({ email: 'Already on the list.' })
2894
+
2895
+ A BACKEND: handle: (values) => rpc('Contact.send', values). A 422 from Laravel
2896
+ or Go lands under the same fields, uncaught.
2897
+
2898
+ THE BOT TRAP: every form carries a hidden field named homepage. Filled in, the
2899
+ submission is answered as a success and dropped - handle() never runs. So a
2900
+ form cannot have a field named homepage. It is not a CAPTCHA; rate-limit a form
2901
+ worth attacking.
2902
+
2903
+ A THEME draws it with one component, PublicForm (type FormsTheme from
2904
+ @rsc-kit/press/forms); replace it with theme: { ...shadcn, PublicForm: Mine }.
2905
+ SETUP is the panel's: bun add @rsc-kit/press, and
2906
+ @import "@rsc-kit/press/shadcn.css" in the stylesheet.`,
2907
+ },
2908
+ {
2909
+ topic: 'pages',
2910
+ summary: 'Landing pages built in the admin panel from the app\'s blocks with @rsc-kit/press/pages: defineBlock, definePages, one catch-all route, real 404s',
2911
+ body: `An editor builds pages in the admin panel from blocks the app defines; one
2912
+ catch-all route serves them, read from the source on every request - a save is
2913
+ live on the next visit, nothing is rebuilt. Full guide: pages.
2914
+
2915
+ A BLOCK is a schema for what the editor fills in, and a server component:
2916
+ \`\`\`tsx title="src/site/blocks.tsx"
2917
+ import * as z from 'zod'
2918
+ import { defineBlock } from '@rsc-kit/press'
2919
+
2920
+ export const hero = defineBlock({
2921
+ name: 'hero', // lowercase, digits, dashes
2922
+ form: z.object({ heading: z.string().min(3), lead: z.string().optional() }),
2923
+ fields: { lead: { type: 'textarea' } },
2924
+ render: ({ data }) => <section><h1>{data.heading}</h1>{data.lead && <p>{data.lead}</p>}</section>,
2925
+ })
2926
+ // A block may place a public form: render: () => <contact.Form />
2927
+ \`\`\`
2928
+
2929
+ THE PAGES and the three files that serve them:
2930
+ \`\`\`ts title="src/site/pages.ts"
2931
+ import { definePages } from '@rsc-kit/press/pages'
2932
+ export const site = definePages({ blocks: [hero, features, text], source: pagesSource })
2933
+ \`\`\`
2934
+ \`\`\`tsx title="src/app/[...path]/page.tsx"
2935
+ import { site } from '@/site/pages'
2936
+ export const generateMetadata = site.generateMetadata
2937
+ export default function SitePage({ params }: { params: Promise<{ path: string }> }) {
2938
+ return <main><site.Page params={params} /></main>
2939
+ }
2940
+ \`\`\`
2941
+ \`\`\`ts title="src/app/[...path]/middleware.ts"
2942
+ import { site } from '@/site/pages'
2943
+ export default site.middleware // REQUIRED for real 404s
2944
+ \`\`\`
2945
+ And resources: [site.resource, ...] in definePanel.
2946
+
2947
+ Without the middleware, a draft or a typo answers 200: the route's shell has
2948
+ gone out before the page finds nothing. site.middleware does the lookup before
2949
+ anything is sent.
2950
+
2951
+ A catch-all is the weakest route: every other page wins over it. The slug is
2952
+ the address (about, pricing/teams); the page with slug home is served at / when
2953
+ there is no app/page.tsx (definePages({ home }) renames it; /home itself 404s).
2954
+
2955
+ THE SOURCE: rows { id, title, slug, description?, published, blocks }, blocks a
2956
+ list of { type, data } (a JSON column). list() is asked for filters: { slug } to
2957
+ find a page and MUST honour it. memorySource does; a Laravel/Go backend filters
2958
+ the column. memorySource is demo-only: edits are lost on restart and not
2959
+ shared between replicas - real pages go in the app's database (a pages table,
2960
+ JSON blocks column, behind rpc()). Each block's data is checked by its own schema on save, errors under
2961
+ blocks.<index>.<field>; a second page at a taken slug is refused under slug.
2962
+
2963
+ A looked-up page is kept between requests with cache() (memory unless the app
2964
+ calls installCacheStore) for definePages({ revalidate }) seconds, 60 by default,
2965
+ false to ask every request. A save in the panel calls changed('press:pages'), so
2966
+ it is live on the next visit; a write straight to the database shows on expiry,
2967
+ or at once after the app calls changed('press:pages') itself.
2968
+
2969
+ BLOCKS IN ANY RESOURCE: fields: { body: { blocks: [text, quote] } } on a
2970
+ z.array(z.any()) property gives it the block editor; draw it with
2971
+ <Blocks blocks={[text, quote]} value={post.body} /> from @rsc-kit/press.
2972
+ A block kind the code no longer defines is left out of the page, not an error.
2973
+
2974
+ UPLOADS: fields: { photo: { type: 'image', storage, maxSize } } on a z.url()
2975
+ (or z.string()) property; type: 'file' with accept: '.pdf' for documents.
2976
+ Works in a resource, a block and a public form. storage is
2977
+ { put(file, { field, tenant }) => Promise<string> } - press ships none; the
2978
+ string is what the record saves (a url). Write to S3/R2/disk from put; a
2979
+ Laravel/Go backend gets the url, not the file (rpc() carries JSON), so use the
2980
+ bucket its disk reads. Uploads are stored only after the rest of the form
2981
+ passes. Image fields refuse SVG unless accept says so. Make the property
2982
+ .nullable() for a Remove button that saves null. Old files are not deleted.`,
2983
+ },
2805
2984
  ];
2806
2985
  /** Every topic, with one line each — what a caller reads before choosing. */
2807
2986
  export function listTopics() {