@airdraft/plugin-schema-editor
v0.1.9
Published
Airdraft schema editor plugin — API routes and file adapter for GUI-driven collection management
Readme
@airdraft/plugin-schema-editor
In-browser schema editor plugin for Airdraft. Adds PATCH /schema API routes for mutating collection schemas at runtime, protected by an admin key. Powers the <SchemaEditor> component in @airdraft/react-ui.
Installation
npm install @airdraft/plugin-schema-editorUsage
import { defineConfig } from '@airdraft/core'
import { withSchemaEditor } from '@airdraft/plugin-schema-editor'
export const airdraft = defineConfig({
adapter,
schemaPath: './airdraft.schema.json', // required — path to the mutable schema file
plugins: [
withSchemaEditor({
adminKey: process.env.CMS_ADMIN_KEY,
}),
],
})Options
| Option | Type | Default | Description |
|---|---|---|---|
| adminKey? | string | — | Key required for all schema mutation routes. In NODE_ENV=development, routes are open without a key. Required in production. |
| adapter? | SchemaAdapter | FileSchemaAdapter | Override the schema persistence adapter. Defaults to FileSchemaAdapter using config.schemaPath. |
| skipAdminKeyCheck? | boolean | false | Bypass the admin-key check (use when auth is enforced upstream). |
API routes
The plugin registers the following routes on the CMS handler:
| Route | Description |
|---|---|
| PATCH /schema/collections/:name | Upsert a collection |
| DELETE /schema/collections/:name | Delete a collection |
| PATCH /schema/collections/:name/fields/:key | Upsert a field |
| DELETE /schema/collections/:name/fields/:key | Delete a field |
All routes require the X-Admin-Key header (or Authorization: Bearer <adminKey>) unless skipAdminKeyCheck: true.
Reserved collection names
The following names cannot be used as collection names (they conflict with built-in API routes):
schema · media · openapi · health · apply · collections
Schema persistence
By default, schema changes are written to the JSON file at config.schemaPath. The file is the single source of truth — the in-memory schema is rebuilt from it on the next request.
Exports
| Export | Description |
|---|---|
| withSchemaEditor(options?) | Creates the schema editor plugin |
| WithSchemaEditorOptions | Options type |
| FileSchemaAdapter | Default file-based schema adapter |
Changelog
See CHANGELOG.md.
