@rsc-kit/mcp 0.40.0 → 0.42.0

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 (60) hide show
  1. package/dist/recipes.js +37 -20
  2. package/dist/recipes.js.map +1 -1
  3. package/guides/admin-plugins.md +206 -6
  4. package/guides/api-routes.md +159 -215
  5. package/guides/authorization.md +103 -114
  6. package/guides/backend-answered-pages.md +301 -250
  7. package/guides/bap-vs-inertia.md +67 -25
  8. package/guides/blueprints.md +307 -174
  9. package/guides/bun.md +42 -25
  10. package/guides/caching.md +46 -49
  11. package/guides/coming-from-inertia.md +5 -5
  12. package/guides/commands.md +251 -200
  13. package/guides/connection.md +50 -54
  14. package/guides/content-security-policy.md +133 -84
  15. package/guides/domains.md +190 -149
  16. package/guides/edge-caching.md +242 -268
  17. package/guides/emails.md +96 -45
  18. package/guides/errors.md +116 -137
  19. package/guides/feature-flags.md +100 -30
  20. package/guides/file-uploads.md +101 -26
  21. package/guides/fonts.md +139 -110
  22. package/guides/forms.md +520 -538
  23. package/guides/images.md +87 -28
  24. package/guides/index.json +13 -33
  25. package/guides/instrumentation.md +134 -95
  26. package/guides/isr.md +3 -3
  27. package/guides/live-data-in-production.md +695 -0
  28. package/guides/live-data.md +170 -839
  29. package/guides/mcp.md +83 -59
  30. package/guides/metadata.md +124 -179
  31. package/guides/navigation.md +118 -147
  32. package/guides/no-javascript.md +49 -57
  33. package/guides/offline.md +118 -153
  34. package/guides/openapi.md +100 -35
  35. package/guides/pages.md +160 -50
  36. package/guides/ppr.md +178 -256
  37. package/guides/pwa.md +251 -218
  38. package/guides/queries.md +171 -300
  39. package/guides/react-compiler.md +90 -50
  40. package/guides/redirects.md +141 -177
  41. package/guides/response-headers.md +76 -74
  42. package/guides/route-interception.md +112 -111
  43. package/guides/routing.md +216 -322
  44. package/guides/sections.md +63 -66
  45. package/guides/seo-files.md +127 -65
  46. package/guides/server-actions.md +285 -357
  47. package/guides/static-generation.md +131 -199
  48. package/guides/testing.md +272 -150
  49. package/guides/third-party-scripts.md +94 -47
  50. package/guides/typed-routes.md +115 -113
  51. package/guides/url-validation.md +113 -61
  52. package/guides/validation.md +53 -62
  53. package/guides/view-transitions.md +159 -132
  54. package/guides/where-it-runs.md +226 -162
  55. package/package.json +2 -2
  56. package/guides/admin.md +0 -520
  57. package/guides/deployment.md +0 -598
  58. package/guides/go.md +0 -538
  59. package/guides/laravel.md +0 -786
  60. package/guides/your-own-backend.md +0 -587
@@ -1,11 +1,24 @@
1
1
  # Admin plugins
2
2
 
3
- > Writing an @rsc-kit/press plugin, publishing it as a package, and selling it.
3
+ > Adding to an @rsc-kit/press panel from a package, or from a plugin installed while the panel runs - writing one, publishing it and selling it.
4
4
 
5
- A plugin is a plain object that adds to an [admin panel](/guides/admin/)
6
- without changing its code. Everything in one is something an app could write
7
- itself; a plugin is the same thing in a package, so it can be installed,
8
- versioned and sold.
5
+ A plugin adds resources, dashboard widgets and a reaction to every save and
6
+ delete to an [admin panel](/guides/admin/), without changing its code:
7
+
8
+ ```ts title="src/admin/panel.ts"
9
+ import { auditLog } from 'rsc-kit-admin-audit-log'
10
+
11
+ export const panel = definePanel({
12
+ theme: shadcn,
13
+ resources: [products, customers],
14
+ plugins: [auditLog({ keep: 500 })],
15
+ })
16
+ ```
17
+
18
+ Everything in one is something an app could write itself; a plugin is the
19
+ same thing in a package, so it can be installed, versioned and sold. A plugin
20
+ can also be [installed while the panel runs](#a-plugin-installed-while-the-panel-runs),
21
+ from a url, with no deploy.
9
22
 
10
23
  ```ts
11
24
  interface PanelPlugin {
@@ -16,7 +29,7 @@ interface PanelPlugin {
16
29
  }
17
30
  ```
18
31
 
19
- ## A whole plugin
32
+ ## Writing a plugin
20
33
 
21
34
  An audit log: it records every save and delete, and shows the latest on the
22
35
  dashboard.
@@ -107,3 +120,190 @@ the same as Filament's paid plugins:
107
120
 
108
121
  Keep a free listing on npm - the README and the keyword - pointing at where it
109
122
  is sold, so it is found the same way a free plugin is.
123
+
124
+ ## A plugin installed while the panel runs
125
+
126
+ A panel with `installs` lets the people who run it add a plugin by pasting a
127
+ url - another company's service, on its own server, with no deploy and no code
128
+ loaded into the app:
129
+
130
+ ```ts title="src/admin/panel.ts"
131
+ import { memoryInstallations } from '@rsc-kit/press'
132
+
133
+ export const panel = definePanel({
134
+ // ...
135
+ installs: {
136
+ store: memoryInstallations(),
137
+ manage: async () => (await currentUser())?.isOwner === true,
138
+ },
139
+ })
140
+ ```
141
+
142
+ ```tsx title="src/app/admin/plugins/page.tsx"
143
+ import { pluginsSearch } from '@rsc-kit/press/admin'
144
+ import { panel } from '@/admin/panel'
145
+
146
+ export const searchParams = pluginsSearch
147
+
148
+ export default panel.Plugins
149
+ ```
150
+
151
+ | Option | What it does |
152
+ | --- | --- |
153
+ | `store` | Where installations and their secrets are kept, per tenant. `memoryInstallations()` lasts as long as the process; a real app keeps them in its database. |
154
+ | `allow(url)` | Which urls the panel may fetch. By default https to a public host name - not localhost, not an IP address, not `.local` or `.internal`. In development, allow localhost. |
155
+ | `manage()` | Who may install and uninstall. The panel's `authorize` unless said - an owner, usually. |
156
+
157
+ ### Installing one
158
+
159
+ 1. On the Plugins page, someone `manage` admits pastes the plugin's manifest url.
160
+ 2. The panel fetches it and shows what it adds, what it may see, and where it
161
+ runs.
162
+ 3. **Install** fetches it again. A manifest that changed since it was reviewed
163
+ is refused: "The plugin changed since you reviewed it. Review it again."
164
+ 4. The installation is stored for the current tenant with a new secret, shown
165
+ on the Plugins page until someone presses "I've copied it".
166
+ 5. The person pastes the installation id and secret into the plugin's own
167
+ settings. Until then the plugin refuses every call.
168
+
169
+ Uninstalling deletes the installation and its secret, so every call stops at
170
+ once and its resources leave the sidebar.
171
+
172
+ ### Writing one
173
+
174
+ An installed plugin is a manifest and an endpoint. The manifest is JSON,
175
+ served at a url:
176
+
177
+ ```ts title="manifest.ts"
178
+ import type { PluginManifest } from '@rsc-kit/press'
179
+
180
+ export const manifest: PluginManifest = {
181
+ name: 'product-reviews',
182
+ label: 'Product reviews',
183
+ description: 'Reviews of your products, moderated before they are shown.',
184
+ endpoint: 'https://reviews.example.com/rpc',
185
+ scopes: ['read:products'],
186
+ events: ['products'],
187
+ resources: [
188
+ {
189
+ name: 'reviews',
190
+ singular: 'Review',
191
+ key: 'id',
192
+ title: 'author',
193
+ columns: [
194
+ { key: 'author', searchable: true },
195
+ { key: 'productId', relation: 'products', label: 'Product' },
196
+ { key: 'rating' },
197
+ { key: 'status', format: 'badge' },
198
+ ],
199
+ form: {
200
+ type: 'object',
201
+ required: ['author', 'productId', 'rating', 'status'],
202
+ properties: {
203
+ author: { type: 'string', minLength: 2, maxLength: 60 },
204
+ productId: { type: 'string', relation: 'products', title: 'Product' },
205
+ rating: { type: 'integer', minimum: 1, maximum: 5 },
206
+ status: { type: 'string', enum: ['pending', 'approved', 'rejected'] },
207
+ body: { type: 'string', format: 'textarea', maxLength: 2000, title: 'Review' },
208
+ },
209
+ },
210
+ filters: ['status'],
211
+ bulkActions: [{ name: 'approve', label: 'Approve', done: 'approved' }],
212
+ },
213
+ ],
214
+ }
215
+ ```
216
+
217
+ - `endpoint` must share the manifest's origin. The panel POSTs every call there.
218
+ - `scopes` are what it may see of the app's own resources, as `read:<resource>`.
219
+ A relation to one of the app's resources needs its scope.
220
+ - `events` are the resources whose saves and deletes it is told about: its own,
221
+ or ones it may read.
222
+ - `form` is a flat JSON Schema. The browser checks its constraints; the panel
223
+ never runs a `pattern` on the server, so the plugin checks everything again.
224
+ - A resource name the app or another plugin already has is refused at install.
225
+ - Unknown fields are refused, so a manifest cannot ask for something the
226
+ person installing did not see.
227
+
228
+ The endpoint verifies each call with `verifyPluginRequest`, then answers it:
229
+
230
+ ```ts title="rpc.ts"
231
+ import type { PluginRequest } from '@rsc-kit/press'
232
+ import { verifyPluginRequest } from '@rsc-kit/press/signing'
233
+
234
+ export async function POST(request: Request): Promise<Response> {
235
+ const verified = await verifyPluginRequest<PluginRequest>(request, (id) => secrets.get(id))
236
+
237
+ if (!verified) return new Response(null, { status: 401 })
238
+
239
+ const call = verified.body
240
+ const rows = reviewsOf(verified.installation)
241
+
242
+ switch (call.type) {
243
+ case 'list':
244
+ return Response.json({ rows: page(rows, call.query), total: rows.length })
245
+ case 'find': {
246
+ const row = rows.find((r) => r.id === call.id)
247
+
248
+ return row ? Response.json({ row }) : new Response(null, { status: 404 })
249
+ }
250
+ case 'create':
251
+ case 'update':
252
+ if (/https?:\/\//.test(String(call.values.body ?? ''))) {
253
+ return Response.json({ errors: { body: ['Links are not allowed in a review.'] } }, { status: 422 })
254
+ }
255
+
256
+ return Response.json({ row: save(rows, call) })
257
+ case 'delete':
258
+ case 'bulk':
259
+ case 'change':
260
+ // ...
261
+ return Response.json({})
262
+ }
263
+ }
264
+ ```
265
+
266
+ | Call | Has | Answers |
267
+ | --- | --- | --- |
268
+ | `list` | `resource`, `query` | `{ rows, total }`, or `{ rows, next, prev }` |
269
+ | `find` | `resource`, `id` | `{ row }`, or 404 for none |
270
+ | `create` | `resource`, `values` | `{ row }` |
271
+ | `update` | `resource`, `id`, `values` | `{ row }` |
272
+ | `delete` | `resource`, `id` | Anything 2xx |
273
+ | `bulk` | `resource`, `action`, `ids` | Anything 2xx |
274
+ | `change` | `change`: a `RecordChange` | Anything 2xx |
275
+
276
+ Every call also has `tenant`. A 422 with `{ errors: { field: [message] } }`
277
+ shows under the form's fields, as a Laravel backend's does. Anything else that
278
+ is not a 2xx is an error with the plugin's name on it. `verifyPluginRequest`
279
+ answers `null` for a bad signature, an installation `secretOf` does not know,
280
+ or a call older than `tolerance` seconds (300 unless said); otherwise
281
+ `{ installation, body }`.
282
+
283
+ ### Limits
284
+
285
+ | | |
286
+ | --- | --- |
287
+ | Manifest | 256 KB, 5 seconds, no redirects followed |
288
+ | A call | 10 seconds, 5 MB answer |
289
+ | An event | 3 seconds |
290
+
291
+ A dashboard count from a plugin that is down shows a dash, not an error page.
292
+ Installations are per tenant, so a team that did not install a plugin gets a
293
+ 404 for its pages.
294
+
295
+ ### The signature
296
+
297
+ For a plugin not written in JavaScript: each call carries three headers.
298
+
299
+ ```
300
+ x-rsc-admin-installation: <installation id>
301
+ x-rsc-admin-timestamp: <unix seconds>
302
+ x-rsc-admin-signature: sha256=<hex HMAC-SHA256 of "<timestamp>.<body>" with the secret>
303
+ ```
304
+
305
+ Compare the signature in constant time, refuse an empty secret, and refuse a
306
+ timestamp more than a few minutes old.
307
+
308
+ `examples/admin` serves a whole installed plugin at `/demo-plugin`, with its
309
+ settings page, manifest and endpoint.