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