yaml-admin-front
v0.0.81
Published
A frontend library that auto-builds a `react-admin` UI from a single `admin.yml`. With only entity definitions in YAML, it renders list/show/create/edit screens, menus, icons, and upload fields out of the box.
Readme
yaml-admin-front
A frontend library that auto-builds a react-admin UI from a single admin.yml. With only entity definitions in YAML, it renders list/show/create/edit screens, menus, icons, and upload fields out of the box.
Features
- YAML-driven automation: Reads
entitydefinitions and dynamically createsResources and CRUD screens - Built-in auth: Works with
/member/loginand/member/isloginendpoints and JWT tokens - File uploads: Switch between Local or S3 strategies via YAML (
upload.local/upload.s3) - Icons: Use
@iconify/reacticon names directly in YAML for menu/resource icons
Installation
npm i yaml-admin-front
# peers if not already present
npm i react-admin react react-dom @iconify/reactRecommended environment
- Node.js: 18+
- React: 19.x
- react-admin: ^5.10
Quick Start (Vite example)
// App.jsx
import { YMLAdmin } from 'yaml-admin-front';
import adminYamlText from './admin.yml?raw';
export default function App() {
return <YMLAdmin adminYaml={adminYamlText} />;
}API host resolution order used by the frontend:
- YAML
api-host.uri→ 2) envVITE_HOST_API→ 3) defaulthttp://localhost:6911
admin.yml Key Sections
Minimal example (see full example in the repo at example/admin.yml):
api-host:
uri: localhost:6911
entity:
member:
label: 'User'
icon: 'solar:user-hands-outline'
fields:
- { name: name, type: string, required: true }
upload:
# choose one
# local: { enable: true }
# s3: { enable: true }- api-host.uri: Backend API base (if missing scheme,
http://is prepended) - entity.‹name›: Label/icon/fields; drives
Resourcecreation and CRUD screens - upload.local / upload.s3: Select upload strategy. If omitted, plain data provider is used (no uploads)
When a field includes private: true, secure upload flows are used automatically.
Component API
type YMLAdminProps = {
adminYaml: string; // YAML as a string (e.g., Vite ?raw import)
i18nProvider?: any; // react-admin i18nProvider
custom?: Record<string, any>; // inject custom components/fields if needed
};Notes
YMLAdminparsesadminYamland composes thereact-adminAdmin/Resourcetree.- If an entity has
custom: true, only theResourceis added; no auto-scaffolded CRUD.
Authentication
- Login:
POST /member/login→ on{ token }, saved tolocalStorage.tokenand sent viax-access-tokenheader - Session check:
GET /member/islogin→{ r: true }means authenticated - Token header: all requests include
x-access-tokenautomatically
If you use yaml-admin-api on the backend, you can configure login/checks from the same YAML.
File Uploads
Depending on YAML, the data provider is wrapped with an upload adapter.
- Local uploads:
PUT /api/local/media/upload(… ) - S3 uploads: Uses presigned URLs for multipart uploads and calls complete/abort APIs
Secure uploads use dedicated /secure endpoints. Multipart flows support progress callbacks.
Environment Variables
- VITE_HOST_API: Default API base (URL or
host:port). Overridden by YAMLapi-host.uriwhen present.
Examples
- Frontend example:
example/front1 - API example:
example/api1 - Sample YAML:
example/admin.yml
From the repo root you can run both examples together with:
npm run devLicense
MIT
