nest-my-admin 0.10.3 → 0.10.5
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/README.md +315 -205
- package/package.json +7 -5
package/README.md
CHANGED
|
@@ -1,49 +1,197 @@
|
|
|
1
|
-
|
|
1
|
+
<h1 align="center">nest-my-admin</h1>
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
admin
|
|
3
|
+
<p align="center">
|
|
4
|
+
An admin panel for <b>NestJS + TypeORM</b>, in the spirit of Django admin.<br>
|
|
5
|
+
Describe your entities once; get lists, forms, permissions, an audit log and a polished UI, served by your own Nest app.
|
|
6
|
+
</p>
|
|
5
7
|
|
|
6
|
-
>
|
|
7
|
-
>
|
|
8
|
-
|
|
9
|
-
>
|
|
10
|
-
|
|
8
|
+
<p align="center">
|
|
9
|
+
<a href="https://www.npmjs.com/package/nest-my-admin"><img alt="npm" src="https://img.shields.io/npm/v/nest-my-admin?color=0f766e"></a>
|
|
10
|
+
<a href="https://github.com/phantomboy0/nest-my-admin/blob/main/LICENSE"><img alt="MIT license" src="https://img.shields.io/npm/l/nest-my-admin?color=0f766e"></a>
|
|
11
|
+
<img alt="NestJS 11 and 12" src="https://img.shields.io/badge/NestJS-11%20%7C%2012-0f766e">
|
|
12
|
+
<img alt="TypeORM 0.3.20+ and 1.x" src="https://img.shields.io/badge/TypeORM-0.3.20%2B%20%7C%201.x-0f766e">
|
|
13
|
+
</p>
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
The
|
|
14
|
-
|
|
15
|
+
<p align="center">
|
|
16
|
+
<img alt="The dashboard of a demo shop: sales, orders, low stock, a sales goal, sales by day and the latest orders" src="https://raw.githubusercontent.com/phantomboy0/nest-my-admin/main/docs/images/dashboard.png" width="900">
|
|
17
|
+
</p>
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
@AdminResource(Product, { icon: 'package' })
|
|
21
|
+
export class ProductAdmin extends AdminResourceBase<Product> {
|
|
22
|
+
list: ListConfig<Product> = { columns: ['name', 'price', 'stock'], search: ['name'], filters: ['stock'] };
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
That class is a working admin page for `Product`: a searchable, filterable list, a create and edit form built from the
|
|
27
|
+
entity's columns, and the REST API behind them. Everything else is opt-in, and every write can go through your own
|
|
28
|
+
services, so the rules your app already enforces still apply.
|
|
29
|
+
|
|
30
|
+
- **No frontend to build.** The UI (React, shadcn) ships prebuilt inside the package and is served by Nest at the path
|
|
31
|
+
you choose. Your app stays a plain Nest app.
|
|
32
|
+
- **Your code stays in charge.** Override `create`, `update` or `delete` to call your services; the admin validates
|
|
33
|
+
with your class-validator DTOs and runs inside a transaction you can join.
|
|
34
|
+
- **Built for real operators.** Roles with field- and row-level rules, a permission debugger, two-factor sign-in, an
|
|
35
|
+
audit log with per-record history, a command palette, a phone layout, dark mode, and right-to-left Persian with the
|
|
36
|
+
Jalali calendar.
|
|
37
|
+
|
|
38
|
+
**Status.** Version 0.10. Before 1.0 a minor version may change an API; each release says what to change in
|
|
39
|
+
[UPGRADING.md](https://github.com/phantomboy0/nest-my-admin/blob/main/UPGRADING.md).
|
|
40
|
+
|
|
41
|
+
## A closer look
|
|
42
|
+
|
|
43
|
+
Every screenshot is the demo app in this repository ([run it yourself](#try-the-demo)).
|
|
44
|
+
|
|
45
|
+
<table>
|
|
46
|
+
<tr>
|
|
47
|
+
<td width="50%"><img alt="The product list with pictures, tabs, filter chips, price and stock badges" src="https://raw.githubusercontent.com/phantomboy0/nest-my-admin/main/docs/images/products.png"><br><b>Lists.</b> Tabs with live counts, filter chips, computed columns (pictures, badges, a price over the old one, on/off switches) and cells you edit in place.</td>
|
|
48
|
+
<td width="50%"><img alt="An order page with a fulfilment stepper, order lines, a payment card and record actions" src="https://raw.githubusercontent.com/phantomboy0/nest-my-admin/main/docs/images/order.png"><br><b>Record pages.</b> Sections and side cards, a stepper with the time of each step, child rows edited inline, and your own actions in the header.</td>
|
|
49
|
+
</tr>
|
|
50
|
+
<tr>
|
|
51
|
+
<td><img alt="The status filter open over a product list filtered by category" src="https://raw.githubusercontent.com/phantomboy0/nest-my-admin/main/docs/images/filters.png"><br><b>Filters that live in the URL.</b> Share a link and the other person sees the same list.</td>
|
|
52
|
+
<td><img alt="The quick view sheet of a product over the list" src="https://raw.githubusercontent.com/phantomboy0/nest-my-admin/main/docs/images/quick-view.png"><br><b>Quick view.</b> Click a row to read a record without leaving the list.</td>
|
|
53
|
+
</tr>
|
|
54
|
+
<tr>
|
|
55
|
+
<td><img alt="The command palette finding three lamps" src="https://raw.githubusercontent.com/phantomboy0/nest-my-admin/main/docs/images/command-palette.png"><br><b>Command palette.</b> <kbd>⌘K</kbd> goes to any page, creates a record or finds one by its title.</td>
|
|
56
|
+
<td><img alt="The permission debugger explaining what the catalog editor may do with products" src="https://raw.githubusercontent.com/phantomboy0/nest-my-admin/main/docs/images/debugger.png"><br><b>Permission debugger.</b> Why a user can or cannot view, change or delete something, field by field.</td>
|
|
57
|
+
</tr>
|
|
58
|
+
<tr>
|
|
59
|
+
<td><img alt="A role's permissions as a grid of resources and operations" src="https://raw.githubusercontent.com/phantomboy0/nest-my-admin/main/docs/images/permissions.png"><br><b>Roles, groups and users.</b> Define roles in code, or let administrators manage them in the admin.</td>
|
|
60
|
+
<td><img alt="The dashboard in Persian, right to left, with Persian digits and Jalali dates" src="https://raw.githubusercontent.com/phantomboy0/nest-my-admin/main/docs/images/rtl.png"><br><b>English and Persian.</b> Right to left, Persian digits, the Jalali calendar; any other language through your own translations.</td>
|
|
61
|
+
</tr>
|
|
62
|
+
<tr>
|
|
63
|
+
<td><img alt="The product list in dark mode" src="https://raw.githubusercontent.com/phantomboy0/nest-my-admin/main/docs/images/products-dark.png"><br><b>Dark mode</b>, and an accent colour each person or the whole team can choose.</td>
|
|
64
|
+
<td><img alt="The product form with its sections, a locked SKU and a floating save bar" src="https://raw.githubusercontent.com/phantomboy0/nest-my-admin/main/docs/images/product-form.png"><br><b>Forms from your DTOs.</b> Sections, tabs, widgets, read-only rules and a save bar that follows you (<kbd>⌘S</kbd>).</td>
|
|
65
|
+
</tr>
|
|
66
|
+
<tr>
|
|
67
|
+
<td align="center"><img alt="The product list on a phone, as cards" src="https://raw.githubusercontent.com/phantomboy0/nest-my-admin/main/docs/images/mobile-list.png" width="260"> <img alt="An order page on a phone" src="https://raw.githubusercontent.com/phantomboy0/nest-my-admin/main/docs/images/mobile-order.png" width="260"><br><b>Phones.</b> Lists turn into cards; filters and sorting move to a drawer.</td>
|
|
68
|
+
<td><img alt="A settings page with sections, a switch, an image field and a secret" src="https://raw.githubusercontent.com/phantomboy0/nest-my-admin/main/docs/images/settings.png"><br><b>Settings pages</b> for the values that are not rows: the shop's name, a logo, an API key that is never shown again.</td>
|
|
69
|
+
</tr>
|
|
70
|
+
</table>
|
|
71
|
+
|
|
72
|
+
## Quick start
|
|
73
|
+
|
|
74
|
+
Requirements: NestJS 11 or 12, TypeORM 0.3.20+ or 1.x, Node 20.19+ (or Bun), and Postgres, MySQL 8 or SQLite.
|
|
15
75
|
|
|
16
76
|
```bash
|
|
17
|
-
npm install nest-my-admin
|
|
18
|
-
npm install -D @nestjs/testing # only if you use the test helpers
|
|
77
|
+
npm install nest-my-admin
|
|
19
78
|
```
|
|
20
79
|
|
|
80
|
+
**1. An entity** (you probably have one already):
|
|
81
|
+
|
|
21
82
|
```ts
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
83
|
+
@Entity()
|
|
84
|
+
export class Product {
|
|
85
|
+
@PrimaryGeneratedColumn() id: number;
|
|
86
|
+
@Column() name: string;
|
|
87
|
+
@Column({ type: 'decimal', precision: 10, scale: 2 }) price: string;
|
|
88
|
+
@Column({ default: 0 }) stock: number;
|
|
89
|
+
}
|
|
25
90
|
```
|
|
26
91
|
|
|
27
|
-
|
|
92
|
+
**2. A resource** that says how the admin shows it:
|
|
28
93
|
|
|
29
94
|
```ts
|
|
95
|
+
import { AdminResource, AdminResourceBase, type ListConfig } from 'nest-my-admin';
|
|
96
|
+
|
|
30
97
|
@AdminResource(Product, { icon: 'package' })
|
|
31
98
|
export class ProductAdmin extends AdminResourceBase<Product> {
|
|
32
|
-
|
|
33
|
-
list: ListConfig<Product> = { columns: ['id', 'name', 'sku', 'price'] };
|
|
34
|
-
form: FormConfig = { create: CreateProductDto, update: UpdateProductDto };
|
|
35
|
-
create(dto: CreateProductDto) { return this.products.create(dto); } // your business rules run
|
|
99
|
+
list: ListConfig<Product> = { columns: ['name', 'price', 'stock'], search: ['name'], filters: ['stock'] };
|
|
36
100
|
}
|
|
101
|
+
```
|
|
37
102
|
|
|
38
|
-
|
|
39
|
-
@Module({ providers: [ProductsService, ProductAdmin] })
|
|
40
|
-
export class CatalogModule {}
|
|
103
|
+
**3. The module**, with the built-in sign-in. Its tables come from `ADMIN_AUTH_ENTITIES`:
|
|
41
104
|
|
|
42
|
-
|
|
105
|
+
```ts
|
|
106
|
+
import { AdminModule } from 'nest-my-admin';
|
|
107
|
+
import { ADMIN_AUTH_ENTITIES, builtinAuth } from 'nest-my-admin/auth';
|
|
108
|
+
|
|
109
|
+
@Module({
|
|
110
|
+
imports: [
|
|
111
|
+
TypeOrmModule.forRoot({ type: 'postgres', url: process.env.DATABASE_URL, entities: [Product, ...ADMIN_AUTH_ENTITIES], synchronize: true }),
|
|
112
|
+
AdminModule.forRoot({
|
|
113
|
+
title: 'My shop',
|
|
114
|
+
auth: builtinAuth({ bootstrapSuperuser: { username: 'admin', password: process.env.ADMIN_PASSWORD! } }),
|
|
115
|
+
}),
|
|
116
|
+
],
|
|
117
|
+
providers: [ProductAdmin],
|
|
118
|
+
})
|
|
43
119
|
export class AppModule {}
|
|
44
120
|
```
|
|
45
121
|
|
|
46
|
-
|
|
122
|
+
**4. Start your app** and open `http://localhost:3000/admin`. Sign in as `admin` with `ADMIN_PASSWORD`; the user is
|
|
123
|
+
created on the first boot, when the users table is empty.
|
|
124
|
+
|
|
125
|
+
From here, the usual next steps:
|
|
126
|
+
|
|
127
|
+
- Put a resource in a module of its own: the module becomes its sidebar group ([Sidebar groups and order](#sidebar-groups-and-order)).
|
|
128
|
+
- Give it a create and an update DTO, and override `create`/`update` to call your service ([Fields and forms](#fields-and-forms)).
|
|
129
|
+
- Add roles for people who are not superusers ([Permissions](#permissions)).
|
|
130
|
+
|
|
131
|
+
`synchronize: true` is for trying it out. In production, generate migrations as usual: the admin's tables are
|
|
132
|
+
ordinary entities.
|
|
133
|
+
|
|
134
|
+
### One package or four
|
|
135
|
+
|
|
136
|
+
`nest-my-admin` is the admin, its UI, the built-in sign-in and the test helpers at one version, so they cannot drift
|
|
137
|
+
apart:
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
import { AdminModule, AdminResource } from 'nest-my-admin';
|
|
141
|
+
import { builtinAuth } from 'nest-my-admin/auth'; // the built-in sign-in
|
|
142
|
+
import { createAdminTestingModule } from 'nest-my-admin/testing'; // in your tests (npm install -D @nestjs/testing)
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
They are `@nest-my-admin/core`, `@nest-my-admin/auth` and `@nest-my-admin/testing` under one name: the same objects.
|
|
146
|
+
The scoped packages still work on their own (keep them at one exact version). The rest of this page uses the scoped
|
|
147
|
+
names; either import works.
|
|
148
|
+
|
|
149
|
+
The package is ESM. CommonJS apps load it through Node's `require(esm)`; one compiled with `"module": "nodenext"`
|
|
150
|
+
(the `nest new` default since Nest 11) needs TypeScript 5.8+, and with `"module": "commonjs"` any 5.x works.
|
|
151
|
+
|
|
152
|
+
## Try the demo
|
|
153
|
+
|
|
154
|
+
The screenshots above come from `examples/demo-api`, a small shop with two months of orders:
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
git clone https://github.com/phantomboy0/nest-my-admin && cd nest-my-admin
|
|
158
|
+
bun install && bun run build
|
|
159
|
+
cd examples/demo-api && NMA_DEMO_SHOWCASE=1 bun src/main.ts
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Open `http://localhost:3000/admin` and sign in as `admin` / `admin-demo-pass` (a superuser) or `editor` /
|
|
163
|
+
`editor-demo-pass` (the catalog editor role: a good way to see permissions at work). The data lives in memory and
|
|
164
|
+
starts fresh on every run. Without `NMA_DEMO_SHOWCASE` the demo starts with the small data set the end-to-end tests
|
|
165
|
+
use.
|
|
166
|
+
|
|
167
|
+
## How it fits into your app
|
|
168
|
+
|
|
169
|
+
- **Resources.** `@AdminResource(Entity)` on a provider registers one page. The admin reads the entity's TypeORM
|
|
170
|
+
metadata and your DTOs' class-validator rules, and builds the list, the form and the API from them.
|
|
171
|
+
- **Writes go through you.** The base class creates, updates and deletes through the repository. Override any of them
|
|
172
|
+
to call your service instead: the DTO is already validated and you get a transactional `ctx.manager`.
|
|
173
|
+
- **Its own HTTP surface.** The admin is mounted as one handler on Nest's Express adapter at `path` (default
|
|
174
|
+
`/admin`). Your global guards, interceptors, pipes, filters and `setGlobalPrefix` do not touch it, and it does not
|
|
175
|
+
touch your routes.
|
|
176
|
+
- **Its own tables, only when you ask.** Sign-in, roles, files, the audit log and admin-wide settings each come with
|
|
177
|
+
entities you add to your DataSource (`ADMIN_AUTH_ENTITIES`, `ADMIN_RBAC_ENTITIES`, `ADMIN_FILE_ENTITIES`,
|
|
178
|
+
`ADMIN_AUDIT_ENTITIES`, `ADMIN_SETTING_ENTITIES`).
|
|
179
|
+
|
|
180
|
+
## Contents
|
|
181
|
+
|
|
182
|
+
- [Resources, lists and forms](#resources-lists-and-forms): [querying lists](#querying-lists), [sidebar and menu](#sidebar-groups-and-order), [list page](#the-list-page), [tabs and computed columns](#tabs-and-computed-columns), [lists at scale](#lists-at-scale), [relations](#relations-and-record-titles), [entity shapes](#entity-shapes), [languages and branding](#languages-theme-and-branding), [Persian](#persian-dates-and-phones), [fields and forms](#fields-and-forms), [files and rich text](#files-images-and-rich-text), [actions](#actions), [printing](#printing-records), [Excel](#exporting-a-list-to-excel), [settings pages](#settings-pages), [source resources](#source-resources), [inlines](#inlines), [the record page](#the-record-page)
|
|
183
|
+
- [Dashboard](#dashboard)
|
|
184
|
+
- [Transactions, context and errors](#transactions-context-and-errors)
|
|
185
|
+
- [Sign-in](#sign-in)
|
|
186
|
+
- [Permissions](#permissions)
|
|
187
|
+
- [Audit log](#audit-log)
|
|
188
|
+
- [Writing less](#writing-less)
|
|
189
|
+
- [Upgrading](#upgrading)
|
|
190
|
+
- [Develop](#develop)
|
|
191
|
+
|
|
192
|
+
## Resources, lists and forms
|
|
193
|
+
|
|
194
|
+
### Querying lists
|
|
47
195
|
|
|
48
196
|
Lists support filters and search with a URL syntax you can bookmark:
|
|
49
197
|
|
|
@@ -130,6 +278,34 @@ For joins or aggregates, override `findMany` and start from `this.buildListQuery
|
|
|
130
278
|
list: ListConfig<Product> = { columns: ['name', 'status', 'stock'], editable: ['status', 'stock'] };
|
|
131
279
|
```
|
|
132
280
|
|
|
281
|
+
### Tabs and computed columns
|
|
282
|
+
|
|
283
|
+
```ts
|
|
284
|
+
list: ListConfig<Product> = {
|
|
285
|
+
columns: ['picture', 'product', 'money', 'stockBadge', 'specCount', 'active'],
|
|
286
|
+
tabs: [
|
|
287
|
+
{ key: 'all', label: 'All' },
|
|
288
|
+
{ key: 'active', label: 'Active', filter: { 'filter[status][eq]': 'active' } },
|
|
289
|
+
{ key: 'out', label: 'Out of stock', where: (qb) => void qb.andWhere(`${qb.alias}.stock = 0`) },
|
|
290
|
+
],
|
|
291
|
+
computed: {
|
|
292
|
+
picture: { label: 'Picture', kind: 'image', source: { first: 'media', field: 'image', by: 'sort' } },
|
|
293
|
+
product: { label: 'Product', kind: 'title', source: 'name', subline: 'sku' },
|
|
294
|
+
money: { label: 'Price', kind: 'money', source: 'price', previous: 'compareAtPrice' },
|
|
295
|
+
stockBadge: { label: 'Stock', kind: 'badge', source: 'stock', map: (stock) => (Number(stock) === 0 ? { label: 'Out of stock', tone: 'bad' } : { label: `In stock · ${stock}`, tone: 'ok' }) },
|
|
296
|
+
specCount: { label: 'Specs', kind: 'count', source: { aggregate: 'count', relation: 'specs' }, sortable: true },
|
|
297
|
+
active: { label: 'Active', kind: 'toggle', source: { toggle: 'status', on: 'active', off: 'archived' } },
|
|
298
|
+
},
|
|
299
|
+
};
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
- **Tabs** sit above the list, at most six, each with its count for the person looking (`GET /api/resources/:r/tab-counts`). A tab is a set of filters (`filter`, the URL syntax) or a condition of your own (`where`), for what the filter bar does not offer.
|
|
303
|
+
- **Computed columns** are named in `list.columns` like fields.
|
|
304
|
+
- Kinds: `image`, `title` (with a `subline`), `money` (with the `previous` price struck through), `badge` (with `map` returning a label and a tone: `ok`, `warn`, `bad`, `info`, `neutral` or `primary`), `count`, `toggle` (an on/off switch over an enum).
|
|
305
|
+
- Sources: a field or a path (`category.name`), an aggregate (`count`, `sum`, `min`, `max`) or the first row of a one-to-many relation, an enum toggle, or `{ compute: (rows, ctx) => …, fields }`, called once per page.
|
|
306
|
+
- Aggregates and first rows count only the rows the viewer may see, and a column that reads something the viewer cannot see is left out.
|
|
307
|
+
- **Phones** show each row as a card: `list.mobile: { title, subtitle, badge, meta: [...] }` chooses what goes where.
|
|
308
|
+
|
|
133
309
|
### Lists at scale
|
|
134
310
|
|
|
135
311
|
- **`list.count`:**
|
|
@@ -265,6 +441,12 @@ AdminModule.forRoot({
|
|
|
265
441
|
- **Theme.** Light, dark or system, from the header. It is applied before the page renders, so nothing flashes.
|
|
266
442
|
- **Icons** for groups and resources: bell, book, box, boxes, briefcase, building, calendar, cart, chart, clock, credit-card, database, dollar, file, file-text, folder, globe, heart, history, home, image, inbox, key, layers, link, list, lock, mail, map, map-pin, message, package, phone, printer, receipt, server, settings, shield, shopping-bag, shopping-cart, star, store, tag, tags, ticket, truck, user, users, video, wallet, wrench, zap.
|
|
267
443
|
|
|
444
|
+
#### The accent colour, in the admin
|
|
445
|
+
|
|
446
|
+
`forRoot({ appearance: {} })` (add `ADMIN_SETTING_ENTITIES` to the DataSource) lets people choose the accent colour
|
|
447
|
+
in their account menu (Display). Each person's choice is kept in their browser; people with `appearance.manage` can
|
|
448
|
+
also set it for everyone. What applies: the person's own, then the admin-wide one, then `branding.primaryColor`.
|
|
449
|
+
|
|
268
450
|
### Persian, dates and phones
|
|
269
451
|
|
|
270
452
|
- **Search in Persian.**
|
|
@@ -679,7 +861,11 @@ export class OrderAdmin extends AdminResourceBase<Order> {
|
|
|
679
861
|
```
|
|
680
862
|
|
|
681
863
|
- **`inline`**: the child resource class. Its entity needs exactly one many-to-one (or owning one-to-one) relation to the parent's entity: that relation's field is the **link** (`orderId`). With several candidates, name it with `link: 'orderId'`. The server sets the link; a client that sends it is refused (422), and an update cannot change it.
|
|
682
|
-
- **`display`**: `cards` (default; each child is a card with the child's own form layout) or `table` (one row per child, one cell per field: for short rows like order lines; on phones the table scrolls sideways).
|
|
864
|
+
- **`display`**: `cards` (default; each child is a card with the child's own form layout) or `table` (one row per child, one cell per field: for short rows like order lines; on phones the table scrolls sideways), or `gallery` (a product's pictures: one box of thumbnails, one child per picture). A gallery needs `order`, and its picture is the first single-file `image` field in `fields`. Several files can be chosen or dropped at once (a new row each, up to `max`), each thumbnail has × (remove) and ☆ (make it the first by `order`; `cards.markFirst` labels it), thumbnails reorder by dragging, and the other fields of the thumbnail chosen (alt text, a variant) are edited below the box:
|
|
865
|
+
|
|
866
|
+
```ts
|
|
867
|
+
{ section: 'Pictures', inline: ProductPictureAdmin, display: 'gallery', fields: ['path', 'alt'], order: 'sort', max: 40, cards: { markFirst: 'Main picture' } }
|
|
868
|
+
```
|
|
683
869
|
- **`fields`**: which of the child's form fields the inline shows, in order (default: the child's update form fields without the link). Fields it does not show keep their stored values, and their DTO defaults on create.
|
|
684
870
|
- **`order`**: a number field of the child. Rows are read sorted by it (then by key), and dragging or the up/down buttons write 0, 1, 2… into it on save. Without it rows go by key and cannot be reordered.
|
|
685
871
|
- **`min`**, **`max`** (default 100, at most 500): how many rows a save may leave, checked on the server after the changes (422 on the inline). `max` is also how many rows are read: a record with more shows them read-only, with a link to the child's list filtered by the parent.
|
|
@@ -708,6 +894,92 @@ The parent's records carry `_perm.inlines.<child>.create`, and the inline hides
|
|
|
708
894
|
|
|
709
895
|
**Duplicate** copies the parent only, not its children (the copied form says so).
|
|
710
896
|
|
|
897
|
+
### The record page
|
|
898
|
+
|
|
899
|
+
The order page in the screenshots, from `examples/demo-api/src/sales/order.admin.ts`:
|
|
900
|
+
|
|
901
|
+
```ts
|
|
902
|
+
form: FormConfig = {
|
|
903
|
+
create: CreateOrderDto,
|
|
904
|
+
update: UpdateOrderDto,
|
|
905
|
+
mode: 'view', // opens as text; «Edit» turns it into the form
|
|
906
|
+
header: { badges: ['status'], subtitle: ['customer', 'createdAt', { computed: 'lineCount' }], stepper: 'fulfillment' },
|
|
907
|
+
layout: {
|
|
908
|
+
main: [
|
|
909
|
+
{ section: 'Order', fields: ['number', 'customer', 'total', 'tracking'], columns: 2 },
|
|
910
|
+
{ section: 'Lines', inline: OrderLineAdmin, display: 'table', order: 'position', max: 50, readonly: true },
|
|
911
|
+
{ section: 'Totals', summary: [{ label: 'Items', value: { computed: 'lineCount' } }, { label: 'Total', value: 'total' }] },
|
|
912
|
+
],
|
|
913
|
+
aside: [
|
|
914
|
+
{ title: 'Payment', icon: 'credit-card', fields: ['status', 'total', 'tracking'] },
|
|
915
|
+
{ title: 'Handled by', icon: 'user', fields: { relation: 'handledById', fields: ['position'] }, link: true },
|
|
916
|
+
],
|
|
917
|
+
},
|
|
918
|
+
};
|
|
919
|
+
|
|
920
|
+
fields: FieldsConfig<Order> = {
|
|
921
|
+
fulfillment: {
|
|
922
|
+
widget: 'stepper',
|
|
923
|
+
exclude: ['cancelled'],
|
|
924
|
+
history: { inline: OrderStatusLogAdmin, value: 'value', at: 'at', where: { field: 'fulfillment' } },
|
|
925
|
+
},
|
|
926
|
+
};
|
|
927
|
+
```
|
|
928
|
+
|
|
929
|
+
- **`layout.main`** is the form's sections; **`layout.aside`** puts cards beside them, with the record's own fields or a related record's (`relation`), linked to it with `link: true`.
|
|
930
|
+
- **`header`**: badges next to the title, a subtitle of fields and computed values, and a `stepper` across the page.
|
|
931
|
+
- **A stepper** shows an ordered enum as steps. With `history` it reads when each step was reached from a log of the record (a child resource), and `exclude` leaves out values that are not steps.
|
|
932
|
+
- **`summary`** is a section of label and value lines (totals), from fields or the list's computed columns (`list.computed`), like `lineCount` here.
|
|
933
|
+
- **`mode: 'view'`** opens records as text; people who may edit get «Edit».
|
|
934
|
+
- **A primary action** is the filled button last in the header, with a label per record, or hidden on records where it does not apply (`null`):
|
|
935
|
+
|
|
936
|
+
```ts
|
|
937
|
+
@AdminAction({
|
|
938
|
+
primary: true,
|
|
939
|
+
label: { static: 'Next step', for: (order: Order) => (order.status === 'draft' ? 'Move to «paid»' : order.status === 'paid' ? 'Move to «shipped»' : null) },
|
|
940
|
+
})
|
|
941
|
+
async advance(order: Order, _input: unknown, ctx: AdminContext) { /* … */ }
|
|
942
|
+
```
|
|
943
|
+
|
|
944
|
+
- **A soft warning** on a field never blocks a save: `fields: { caption: { warnIf: { empty: true, message: 'No alt text: screen readers will not know what the picture shows.' } } }`.
|
|
945
|
+
|
|
946
|
+
## Dashboard
|
|
947
|
+
|
|
948
|
+
A widget is a provider with `@AdminWidget` and a `load` method. With at least one widget the person may see, the
|
|
949
|
+
dashboard replaces the home page.
|
|
950
|
+
|
|
951
|
+
```ts
|
|
952
|
+
@AdminWidget('sales', { type: 'stat', title: 'Sales', order: 10 })
|
|
953
|
+
export class SalesWidget implements AdminWidgetSource {
|
|
954
|
+
constructor(@InjectRepository(Order) private readonly orders: Repository<Order>) {}
|
|
955
|
+
|
|
956
|
+
async load(params: { from: string; to: string; previousFrom: string; previousTo: string }) {
|
|
957
|
+
const now = await this.total(params.from, params.to);
|
|
958
|
+
const before = await this.total(params.previousFrom, params.previousTo);
|
|
959
|
+
return { value: now.toLocaleString('en-US'), unit: 'USD', change: before ? Math.round(((now - before) / before) * 100) : 0, previousLabel: 'vs the previous period' };
|
|
960
|
+
}
|
|
961
|
+
// …
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
@Module({ imports: [TypeOrmModule.forFeature([Order])], providers: [SalesWidget] })
|
|
965
|
+
export class DashboardModule {}
|
|
966
|
+
```
|
|
967
|
+
|
|
968
|
+
- **The period** (today, this week, this month, this year, or a range from the calendar, Jalali in Persian) is chosen on the page. The UI sends `from`, `to` and the period before it (`previousFrom`, `previousTo`); the server checks them (in order, at most 366 days).
|
|
969
|
+
- **Types** and what `load` returns:
|
|
970
|
+
|
|
971
|
+
| `type` | Returns |
|
|
972
|
+
| --- | --- |
|
|
973
|
+
| `stat` | `{ value, unit?, change?, previousLabel? }`: `value` is text you format; `change` is a percent against the previous period |
|
|
974
|
+
| `progress` | `{ percent, value, caption }`: a ring |
|
|
975
|
+
| `chart` | `{ kind: 'line' \| 'bar', labels, series: [{ label, values, dashed? }], total?, subtitle? }`: one or two series, the second often the previous period, dashed |
|
|
976
|
+
| `table` | `{ columns: [{ key, label }], rows, link? }`: a cell may be `{ label, tone }` (a badge); `link: { resource }` adds «View all» |
|
|
977
|
+
| `list` | `{ items: [{ text, icon?, status?, link? }] }`: `status` is a coloured dot (a tone: `ok`, `warn`, `bad`, …) |
|
|
978
|
+
|
|
979
|
+
- **Layout.** `order` sorts widgets; `size` (1 to 4) is how many of the four desktop columns one takes. Phones show one column. Each widget loads on its own, with its own placeholder and error.
|
|
980
|
+
- **Permissions.** A widget needs `dashboard.<name>`, or the code in its `permission` option; `dashboard.*` grants them all. Superusers see every widget.
|
|
981
|
+
- `examples/demo-api/src/dashboard/dashboard.module.ts` has one widget of each type.
|
|
982
|
+
|
|
711
983
|
## Transactions, context and errors
|
|
712
984
|
|
|
713
985
|
Every create, update and delete runs in one database transaction. Pass `ctx.manager` to your services so their writes
|
|
@@ -976,185 +1248,9 @@ Things hosts tend to write by hand that the admin already does:
|
|
|
976
1248
|
- **Inline children stay out of the sidebar** by default (`nav: false` unless they set `nav`): no extra group to hide them in.
|
|
977
1249
|
- **Labels in one language** are plain strings; other languages can come from `translate` (see Languages, theme and branding).
|
|
978
1250
|
|
|
979
|
-
## Upgrading
|
|
980
|
-
|
|
981
|
-
Nothing to change. What you may notice:
|
|
982
|
-
|
|
983
|
-
- A save with inline rows now answers with every refused row at once: each row runs in a savepoint, and the save still fails as a whole. One refused row keeps its own status and message; several are one 422 with every row's `fields`.
|
|
984
|
-
- Filter chips are no longer dashed «+» buttons (they read as "add"): a funnel and an arrow, after a «Filter:» caption, and a title in the popover. A yes/no filter is a switch on the chip (one click on, one click off); «No» is behind its arrow. An editable yes/no list cell is a switch that saves on click.
|
|
985
|
-
- Money inputs group digits as they are typed, and a `money` widget also fits a string DTO property.
|
|
986
|
-
- Calendars are always six rows, the column menu scrolls inside the window, a field's `warnIf` no longer remounts its input (the input lost its focus after the first letter), and native controls follow the dark theme (`color-scheme`).
|
|
987
|
-
- In Persian, the server's own texts are translated by the UI, class-validator's default messages included («must not be greater than 5»), without the property's name. English shows them exactly as sent, and a host's own words are never touched. A field the form does not show gives its message without its name.
|
|
988
|
-
|
|
989
|
-
New: `@AdminResource({ creatable: false })` (no «New», a create is refused, records can still be edited), `{ inline, existingOnly: true }` (rows only on an existing parent), `form.afterCreate: 'edit'` (saving a new record opens it), and `afterInlines(record, dto, ctx)` on a resource (a rule about a record and its rows, after both are written, inside the transaction).
|
|
990
|
-
|
|
991
|
-
## Upgrading to 0.10.2
|
|
992
|
-
|
|
993
|
-
Nothing to change. New: `builtinAuth({ issuerImage })`, an http(s) URL of your logo, sent as `image=` in the two-factor QR code. Only some authenticator apps read it; others, Ente Auth among them, show their own icons, matched on `issuer`. A value that is not an absolute http(s) URL fails at boot.
|
|
994
|
-
|
|
995
|
-
## Upgrading to 0.9.1
|
|
996
|
-
|
|
997
|
-
Nothing to change. New: `@AdminAction({ choices })` (see Actions): an input field whose dropdown a resource method fills when the dialog opens, re-checked when the action runs. Every dropdown in the dashboard (forms, filters, sort, page size, inline cell edits, language, roles, audit, debugger, the editor's heading level) is now the dashboard's own list, styled like the rest and right to left in Persian, instead of the browser's native `<select>`. Tests that drove a native select (`selectOption`) click the field, then the option (`getByRole('option', { name })`).
|
|
998
|
-
|
|
999
|
-
## Upgrading to 0.9.0
|
|
1000
|
-
|
|
1001
|
-
The contracts between the admin and your code are now enforced: the decorators' types refuse a method or class of the wrong shape at compile time, and the admin refuses a wrong value at run time (a 500 with `nest-my-admin: …` in the log, or a boot error) instead of reading it as something else. Code that already followed the docs keeps working; code that compiled only through `any` or plain JavaScript may now fail. What to check:
|
|
1002
|
-
|
|
1003
|
-
- **Resource classes.** `@AdminResource(Entity)` needs a class that extends `AdminResourceBase<Entity>`, and `@AdminSource(Row)` one that extends `AdminSourceBase<Row>` (compile errors now, as well as the boot errors before).
|
|
1004
|
-
- **Actions.** A method returns nothing or `{ message }` (`ActionOutcome`), sync or async. Anything else (the record, a string, `{ mesage }`) fails the run and its writes are rolled back. The first parameter of a record action is one of the resource's rows (typed: `extend(inst: Instance, …)` on an `AdminResourceBase<Instance>`). The next parameter is the input: give it the type of `input`, or leave `input` out and the parameter's class becomes the form. `input` that is not the parameter's class (or a parent of it), and a record parameter of another class, fail at boot. `label.for` returns a text or `null`, never a Promise.
|
|
1005
|
-
- **Parameter types need `emitDecoratorMetadata`** (as Nest's own injection does; tsc, SWC and Bun emit it, esbuild, Vite and tsx do not). Without it, an action whose method takes an input parameter and sets no `input` fails at boot: set `input: SomeDto`, or `input: false` for an action that takes none.
|
|
1006
|
-
- **`@AdminScope`** returns a column map or a callback at once, never a Promise: an async scope used to mean «no restriction»; now it is an error.
|
|
1007
|
-
- **`@AdminCan`** returns `true` or `false` at once. A Promise or another value is an error (a rule that throws still means «no», with a warning).
|
|
1008
|
-
- **`@AdminPrint`** returns `` html`…` `` (or a Promise of it). A plain string is refused: it was not escaped.
|
|
1009
|
-
- **`readonlyIf`** returns a boolean, and `readonlyFields()` an array of names.
|
|
1010
|
-
- **`findMany`** of a resource, a source or an inline child returns `{ items, total }` (`total` may be left out); an array is refused.
|
|
1011
|
-
- **Computed columns:** `compute()` returns an object of values by id, and a badge's `map()` a `{ label, tone }` with a known tone.
|
|
1012
|
-
- **Widgets** return the data of their `type` (a stat's `value` is text); `@AdminWidget` needs a class with `load()` and `@AdminSettingsPage` one with `load()` and `save()`.
|
|
1013
|
-
- **Hooks:** `@BeforeSave`/`@AfterSave` take `(dto | entity, ctx, mode: 'create' | 'update')`, `@BeforeDelete` `(entity, ctx, mode: 'soft' | 'hard')`, and return nothing: a hook that returns a value (`return dto` in a `@BeforeSave` that meant to change it) is a compile error and fails the save. Change `dto` in place.
|
|
1014
|
-
- **Resource methods:** `query()` returns the query builder it was given, at once (an `async query()` is an error); a list tab's `where(qb, ctx)` adds to `qb` at once; `relationOptions()` returns the query builder (or a Promise of it); `findOne()` a record or `null`; `create()`/`update()`/`restore()` the record or nothing (then it is reloaded); `links()` an array of `{ label, href }` (a link that is not http(s) or relative is still left out, now with a warning).
|
|
1015
|
-
- **Module options and adapters:** `resolveRoles` (option or adapter) returns an array of role names (a string used to be read letter by letter); a thrown error still means «no roles». `authenticate()` returns `{ user }` or `null`; `getUser()` a user or `null`; a global scope's `appliesTo()` a boolean; `translate` a string or `undefined` at once (an async `translate` used to show the declared texts silently; a throw still falls back). An `errorMapper` that returns something other than an `AdminError` or `undefined` is logged as an error. `files.storage.publicUrl()` returns a URL or `undefined` at once, and `get()` `{ body, contentType, size }` or `null`.
|
|
1016
|
-
- **What the types cannot see:** two DTO classes with the same properties are the same type to TypeScript; the boot check (with the parameter types) tells them apart.
|
|
1017
|
-
|
|
1018
|
-
New types: `ActionReturn` (what an action may return), `Awaitable<T>`, `RowOf<P>`, `TypedMethodDecorator<M>` and `TypedClassDecorator<I>` (for your own wrappers around the decorators).
|
|
1019
|
-
|
|
1020
|
-
## Upgrading to 0.8.1
|
|
1021
|
-
|
|
1022
|
-
Nothing to change. New: with `appearance` on, whoever holds `appearance.manage` uploads the **logo** (sidebar and sign-in page) and the **tab icon** (favicon) from the account menu, for everyone (PNG, JPEG, GIF, WebP, ICO or SVG, up to 512 KB; stored in `nma_setting`, served at `<path>/appearance/logo` and `/appearance/favicon`). An uploaded logo wins over `branding.logo`. Without a logo the sidebar shows the admin's own mark instead of the first letter of the title, and it is the default tab icon.
|
|
1023
|
-
|
|
1024
|
-
## Upgrading to 0.8.0
|
|
1025
|
-
|
|
1026
|
-
Nothing to change. New: [source resources](#source-resources): `@AdminSource(RowClass, …)` and `AdminSourceBase` give rows that are not database rows (an HTTP API, files, live state) the list, record page, forms and actions of a table; `inMemoryList` searches, filters, sorts and pages rows fetched whole.
|
|
1027
|
-
|
|
1028
|
-
## Upgrading to 0.7.4
|
|
1029
|
-
|
|
1030
|
-
Nothing to change. New: `@AdminField({ default })` starts action input forms and create forms at a value (checked at boot to fit the field), and `@AdminField({ fillFrom: '{crm}.example.com' })` fills a text field from other fields of the same form until someone types in it, in action dialogs too (see Field config).
|
|
1031
|
-
|
|
1032
|
-
## Upgrading to 0.7.3
|
|
1033
|
-
|
|
1034
|
-
Nothing to change. Smaller packages: `@nest-my-admin/core`, `/auth` and `/testing` no longer ship source maps (they pointed at sources the packages do not include), so core is about 1.2 MB instead of 1.9 MB; core no longer asks for `rxjs` and `@nest-my-admin/testing` no longer asks for `@nestjs/core`, neither of which they import.
|
|
1035
|
-
|
|
1036
|
-
## Upgrading to 0.7.2
|
|
1037
|
-
|
|
1038
|
-
Nothing to change. Fixed: 0.7 typed the context of `AdminSettingsSource.save` as `AdminWriteContext`, so code that calls a page's `save()` with an `AdminContext` stopped compiling; it takes an `AdminContext` again. Your own `save` may still declare `ctx: AdminWriteContext` to use `ctx.manager` without `!`.
|
|
1039
|
-
|
|
1040
|
-
## Upgrading to 0.7.1
|
|
1041
|
-
|
|
1042
|
-
Nothing to change. New: install `nest-my-admin` alone and import `nest-my-admin/auth` and `nest-my-admin/testing` (see the top of this page). To move to it, replace `@nest-my-admin/core`, `@nest-my-admin/auth` and `@nest-my-admin/testing` in your dependencies with `nest-my-admin`, keep `@nestjs/testing` among your dev dependencies, and change the imports (`@nest-my-admin/core` → `nest-my-admin`, `@nest-my-admin/auth` → `nest-my-admin/auth`, `@nest-my-admin/testing` → `nest-my-admin/testing`). `@nest-my-admin/testing` now marks `@nestjs/testing` an optional peer.
|
|
1043
|
-
|
|
1044
|
-
## Upgrading to 0.7
|
|
1045
|
-
|
|
1046
|
-
Nothing needs changing in an app on 0.6, except two type-only cases:
|
|
1047
|
-
|
|
1048
|
-
- an override that returns `super.relationOptions(...)` under an explicit `: SelectQueryBuilder<any>` return type: drop the annotation (`relationOptions` may now be async);
|
|
1049
|
-
- code that names `AdminMenuSection['items']` as a type: wrap it in `NonNullable<…>` (a `{ group }` section's items are optional);
|
|
1050
|
-
- code that reads `item.resource` or `item.page` of its own menu items as a string: they may now be classes too (`string | Function`), so narrow with `typeof item.resource === 'string'`.
|
|
1051
|
-
|
|
1052
|
-
New:
|
|
1251
|
+
## Upgrading
|
|
1053
1252
|
|
|
1054
|
-
|
|
1055
|
-
- `readonlyFields(record, ctx)` and `this.updateFields` (Fields and forms): lock a record's fields from one place.
|
|
1056
|
-
- `AdminWriteContext` and `AdminResourceBase<T, Id>` (Transactions, context and errors); with `transactions: false` writes now get the DataSource's own `ctx.manager`.
|
|
1057
|
-
- `relationOptions` may be async, and relation ids in its `values` (and `values._parent`) have the key's type.
|
|
1058
|
-
- `@AdminCan('create')` on an inline child (Inlines): whether rows may be added under a parent; `_perm.inlines` on the parent's records.
|
|
1059
|
-
- Menu sections from groups (`{ group: 'settings' }`) and menu items by class (The menu).
|
|
1060
|
-
- Layout nodes and aside cards take an optional `key`, for `translate`.
|
|
1061
|
-
|
|
1062
|
-
## Upgrading to 0.4
|
|
1063
|
-
|
|
1064
|
-
0.4 gives the admin a new look (the owner-admin design) and the features a shop owner's panel needs. All five packages are 0.4.0; upgrade them together. Every new feature is an option: an app that sets none of them gets the new look and today's behaviour, except for the points under "What a 0.3 app will notice".
|
|
1065
|
-
|
|
1066
|
-
**What a 0.3 app will notice**
|
|
1067
|
-
|
|
1068
|
-
- **The look.** New design tokens: the Vazirmatn font for every language (bundled), 12px cards, pill badges, a 256px sidebar with sections, a floating save bar with ⌘S, filter chips over lists, cards on phones. The default accent is `#5B5BD6`; to keep the old neutral one, set it back: `branding: { primaryColor: 'oklch(0.205 0 0)' }`.
|
|
1069
|
-
- **Persian digits by default in `fa`** (۱۲۳ and ٬ thousands separators). People switch back to Latin digits in their account menu (Display); the choice is kept per browser.
|
|
1070
|
-
- **Inline children leave navigation.** A resource another resource edits inline (`{ inline: ChildAdmin }`) is no longer in the sidebar, home, group pages, palette or global search; it keeps its URLs, permissions, history and audit entries. To keep it listed: `@AdminResource(Child, { nav: true })`.
|
|
1071
|
-
- **Contract changes** for code that reads the JSON API itself: `FieldSchema.currency` is `{ unit, position }` (a `currency: 'USD'` option still works), and a record's `_perm.actions` maps each record action to its label on that record, or `false` where it may not run (it was a list of names).
|
|
1072
|
-
- **The e2e/screenshot baselines of your own app**, if you keep any, change with the look.
|
|
1073
|
-
|
|
1074
|
-
**New options**
|
|
1075
|
-
|
|
1076
|
-
- **Currency**: `forRoot({ currency: { unit: { en: 'Toman', fa: 'تومان' } } })` labels every `money` field without a unit of its own; a field's `currency` (a code, or `{ unit, position }`) wins.
|
|
1077
|
-
- **A curated menu**: `forRoot({ menu: { sections: [{ key: 'sales', label: { fa: 'فروش' }, icon: 'shopping-cart', items: [{ resource: 'order', badge: { 'filter[status][eq]': 'paid' } }, { page: 'shop' }, { href: 'https://shop.example', label: 'Shop' }] }] } })`. Sections replace module groups in the sidebar, home, group pages, breadcrumbs and the palette; everything not placed goes into «Advanced», collapsed. Badges are counted for each user through the list's scoped count (`GET /api/menu/badges`, refreshed every minute).
|
|
1078
|
-
- **`nav: false`** on `@AdminResource` takes any resource out of navigation.
|
|
1079
|
-
- **Computed list columns**: `list.computed: { picture: { label, kind: 'image', source: { first: 'media', field: 'image', by: 'sort' } }, stock: { label, kind: 'badge', source: 'stock', map: (value, row) => ({ label, tone }) }, variants: { label, kind: 'count', source: { aggregate: 'count', relation: 'variants' }, sortable: true }, active: { label, kind: 'toggle', source: { toggle: 'status', on: 'active', off: 'archived' } } }`, named in `list.columns`. Kinds: image, title (with `subline`), money (with `previous`), badge, count, toggle; sources: a field or path, an aggregate or first row of a one-to-many relation (only the rows the viewer sees), an enum toggle, or `{ compute: (rows, ctx) => …, fields }` called once per page. A column reading something the viewer cannot see is cut.
|
|
1080
|
-
- **List tabs**: `list.tabs: [{ key: 'all', label }, { key: 'active', label, filter: { 'filter[status][eq]': 'active' } }, { key: 'out', label, where: (qb) => qb.andWhere(qb.alias + '.stock = 0') }]` (at most six), counted per user (`GET /api/resources/:r/tab-counts`).
|
|
1081
|
-
- **Primary record actions with per-record labels**: `@AdminAction({ primary: true, label: { static: 'Next step', for: (order) => (order.status === 'draft' ? 'Mark paid' : null) } })`: a filled button last in the record's header; `null` hides it on that record (and a run is refused).
|
|
1082
|
-
- **The record page**: `form.layout: { main: [...sections], aside: [{ title, fields: ['status', 'total'] }, { title, fields: { relation: 'customerId', fields: ['phone'] }, link: true }] }`, `form.mode: 'view'` (opens as text until «Edit»), `form.header: { badges, subtitle: ['customer', { computed: 'items' }], stepper: 'fulfillment' }`.
|
|
1083
|
-
- **Inline presentation**: an inline's `readonly`, `computed` (child computed columns as table columns) and `cards: { markFirst }`; a `{ summary: [{ label, value: 'total' | { computed } }] }` layout node; a field's `warnIf: { empty: true, message }` (a soft warning that never blocks a save).
|
|
1084
|
-
- **A stepper**: `fields: { fulfillment: { widget: 'stepper', exclude: ['cancelled'], history: { inline: StatusLogAdmin, value: 'value', at: 'at', where: { field: 'fulfillment' } } } }` shows an ordered enum as steps with the time each was reached.
|
|
1085
|
-
- **The accent colour, in the admin**: `forRoot({ appearance: {} })` (add `ADMIN_SETTING_ENTITIES` to the DataSource) lets people with `appearance.manage` set the accent for everyone (account menu → Display → «Use for everyone»); everyone may pick their own, kept in their browser. Order: their own, the admin-wide one, `branding.primaryColor`.
|
|
1086
|
-
- **A dashboard**: `@AdminWidget('sales', { type: 'stat' | 'chart' | 'table' | 'progress' | 'list', title, order, size, permission })` providers with `load(params, ctx)`; the period (today, week, month, year, a range; Jalali-aware) is computed by the UI and checked by the server. Codes `dashboard.<name>` (or the widget's `permission`); `dashboard.*` grants every widget. With a widget to show, the dashboard replaces the home page.
|
|
1087
|
-
- **`@nest-my-admin/testing`**: `expectNoLeaks` also crawls menu badges, tab counts, computed cells and the dashboard.
|
|
1088
|
-
|
|
1089
|
-
Still missing (planned): printing a record (an invoice, a shipping label) and exporting a list to Excel.
|
|
1090
|
-
|
|
1091
|
-
## Upgrading to 0.3.2
|
|
1092
|
-
|
|
1093
|
-
Nothing to change in an app on 0.3.1. New: `@AdminResource(Entity, { readonly: true })` for records only your own code writes (logs, orders, snapshots): the admin offers no New, Save, Delete, editable cell or inline add and remove, and its API answers 403 to every write, whatever the roles say; the resource's `@AdminAction`s still run with their usual permissions. The schema says `readonly: true`. Before, the way to get this was to throw from `create`/`update`/`delete`, and a superuser still saw the buttons.
|
|
1094
|
-
|
|
1095
|
-
## Upgrading to 0.3.1
|
|
1096
|
-
|
|
1097
|
-
A fix, nothing to change in an app on 0.3.0. A property of a create DTO that is not a column (a value your `create()` uses, such as the price of a first variant) is no longer shown on the edit form as an empty read-only field; a create-only column (a number fixed once saved) still is. `form.readonly` in the schema changes accordingly.
|
|
1098
|
-
|
|
1099
|
-
## Upgrading to 0.3.0
|
|
1100
|
-
|
|
1101
|
-
Nothing in 0.3.0 breaks an app that runs on 0.2.1: no option or export was removed or changed, no table or stored key changed, and a resource without inlines answers exactly as before (responses only gain fields). All five packages are 0.3.0; upgrade them together, as before.
|
|
1102
|
-
|
|
1103
|
-
**New**
|
|
1104
|
-
|
|
1105
|
-
- **Inlines**: child resources edited in the parent's form and saved with it in one transaction. See [Inlines](#inlines).
|
|
1106
|
-
- **`AdminFiles.register()` and `release()`**: files a host stored itself become files of a record's field. See "Registering files yourself" under [Files](#files-images-and-rich-text).
|
|
1107
|
-
- **A key column named `id` without a label is "شناسه" in Persian** (still "Id" in English).
|
|
1108
|
-
|
|
1109
|
-
**What a 0.2.1 app may notice**
|
|
1110
|
-
|
|
1111
|
-
- `relationOptions(field, qb, ctx, values)`: a key named `_parent` in `values` now has a meaning when the picker belongs to an inline (`?parent=` on the options route); without `?parent=` it is passed through as before.
|
|
1112
|
-
- The UI's lists, sidebar and header: the sidebar and the header stay in place while the page scrolls, and in right-to-left languages table headers start on the right like their cells.
|
|
1113
|
-
|
|
1114
|
-
## Upgrading to 0.2.1
|
|
1115
|
-
|
|
1116
|
-
Nothing in 0.2.1 breaks an app that runs on 0.2.0: no option or export was removed or changed, no table or stored key changed, and permissions decide as before. All five packages (`@nest-my-admin/core`, `ui`, `auth`, `testing` and `nest-my-admin`) are 0.2.1. Upgrade them together: `@nest-my-admin/auth` and `@nest-my-admin/testing` peer on the exact core version (0.2.1 of either does not install next to core 0.2.0), and core brings the UI of its own version.
|
|
1117
|
-
|
|
1118
|
-
**New**
|
|
1119
|
-
|
|
1120
|
-
- **`@AdminGroup` by key, for any members.** A module's `@AdminGroup` now configures the group of its key whoever the members are, also when they are only settings pages that say `group: '<key>'`, and also when the module provides nothing. See [Sidebar groups and order](#sidebar-groups-and-order).
|
|
1121
|
-
- **`order`** on `@AdminResource` and `@AdminSettingsPage`: the place inside the group (lower first, default 100, then by label).
|
|
1122
|
-
- **`AdminFiles`** (`publicFile(key)`, `openPublic(key)`): which keys are public files, for a host that serves them itself. See "Serving public files yourself" under [Files](#files-images-and-rich-text).
|
|
1123
|
-
- **The page is in the admin's language**: `GET <path>/` answers `<html lang dir>`, `<title>` and `Content-Language` for the default `locale` and your `title`.
|
|
1124
|
-
- **Documented:** the storage key of a settings page's file, `page/<name>/<field>/<yyyy>/<mm>/<uuid><ext>` (unchanged; it was only in the source).
|
|
1125
|
-
|
|
1126
|
-
**What a 0.2.0 app may notice**
|
|
1127
|
-
|
|
1128
|
-
- **A sidebar group can change its label, icon and place.** In 0.2.0 an `@AdminGroup` was read only when its module provided a resource, or a page without `group`. A group reached only through `group: '<key>'` therefore showed the key as its label ("Settings"), with no icon and order 100, even though a module carried `@AdminGroup({ key: '<key>', … })` (or was named like the key and carried `@AdminGroup` without a `key`). In 0.2.1 that module's label, icon and order apply. Group keys, URLs (`/g/<key>`) and permissions are unchanged. If you worked around it by leaving `group` off some pages, both spellings now give the same group.
|
|
1129
|
-
- A module that carries `@AdminGroup` now also wins over a module without the decorator whose name gives the same key, whichever is imported first (in 0.2.0, the one whose resource was registered first).
|
|
1130
|
-
- Two modules that configure one key differently: the first in import order wins (in 0.2.0, the first that had a resource or a page registered, which is nearly always the same), and 0.2.1 logs a warning at boot that names both.
|
|
1131
|
-
- **The served HTML.** `GET <path>/` used to answer `<html lang="en" dir="ltr">` and `<title>Admin</title>` whatever the admin's language. It now answers with the default `locale` (`lang`, `dir`, `Content-Language`) and your `title` in it. The page is still one page for every request (it does not vary by `Accept-Language`, and there is no `Vary` header), and `Cache-Control` is still `no-cache`. An admin with `locale: 'en'` and no `title` gets byte-for-byte what it got before, plus `Content-Language: en`. The UI behaves as before once it runs. If you serve your own UI build (`uiDistPath`), the `lang` and `dir` of its `<html>` and the `<title>` of its `<head>` are replaced the same way.
|
|
1132
|
-
- **Boot fails for `order` that is not a finite number** on a resource or a settings page. TypeScript did not accept the option in 0.2.0, so only untyped code that already passed one can be hit.
|
|
1133
|
-
|
|
1134
|
-
## Upgrading to 0.2
|
|
1135
|
-
|
|
1136
|
-
**Boot can now fail.** Each of these stops the app at start, with a message that names the class:
|
|
1137
|
-
|
|
1138
|
-
- An app that ran on 0.1 can be hit by one of them without using anything new: `widget: 'password'` (and the new `sensitive` and `secret`) on a property inside a group, that is a nested DTO or an embedded entity. Nothing applied those options there. Move the field to the top level.
|
|
1139
|
-
- The others come with the features of 0.2, as you adopt them:
|
|
1140
|
-
- a settings page whose name is reserved (`view`, `create`, `update`, `delete`, `purge`, `field`, `action`), a resource's name, or a custom permission of a resource (`order.export` and a page named `export`); a `permissions` entry that is a page's code (`page.<name>`, `page.<name>.update`); a resource named `page`, or whose name starts with `page:`, in an admin that has settings pages;
|
|
1141
|
-
- an action's input DTO with a `file`, `image` or `richtext` widget;
|
|
1142
|
-
- `atomic` on an action without `bulk: true`, on a resource action, or with `transactions: false`;
|
|
1143
|
-
- an action method named like a built-in operation (`view`, `create`, `update`, `delete`, `restore`, `purge`) or like a method of `AdminResourceBase`;
|
|
1144
|
-
- `@AdminCan('<name>')` whose name is not `update`, `delete` or a record action of that resource (a typo, or the name of a resource action);
|
|
1145
|
-
- `files` without `ADMIN_FILE_ENTITIES`, or `audit` without `ADMIN_AUDIT_ENTITIES`, in the entities of the DataSource they name.
|
|
1146
|
-
|
|
1147
|
-
**Behaviour that changed**
|
|
1148
|
-
|
|
1149
|
-
- **Core and UI go together.** `@nest-my-admin/ui` 0.2.0 is installed with `@nest-my-admin/core` 0.2.0; if you pin or override either, keep both on 0.2.0. `GET /api/session` now always carries `audit: { enabled, view }` (`SessionResponse.audit`), which the 0.2 UI reads.
|
|
1150
|
-
- **A 401 thrown by your code inside a write or a settings page's `load()` is answered as 400** with your message. The UI reads every 401 as "signed out"; the admin's own 401 is unchanged.
|
|
1151
|
-
- **Deleting a record releases its files only when the row is really gone** (read again inside the write). A `delete()` override that keeps the row keeps the files; a purge always releases them. A row that goes where the write cannot see it (MySQL and a service that ignores `ctx.manager`, or a delete queued for later) leaves its files as orphans. See [Files, images and rich text](#files-images-and-rich-text).
|
|
1152
|
-
- **With `audit` on:**
|
|
1153
|
-
- every admin write reads the stored row before and after your method, and inserts one row into `nma_audit` in the same transaction. If that insert fails, the write fails (500);
|
|
1154
|
-
- entry ids are 32-bit integers on Postgres and MySQL (2.1 billion entries); set `retentionDays` on a busy admin;
|
|
1155
|
-
- a purge always closes the record's history, even when your `purge()` keeps the row;
|
|
1156
|
-
- **not in the log:** changes made outside the admin, changes to `select: false` columns, and, on MySQL, a relation changed by a service that ignores `ctx.manager`;
|
|
1157
|
-
- **whatever is typed into the username box of a failed sign-in is stored** as typed, cut to 200 characters: a password typed there by mistake ends up in the log. Failed sign-ins are capped per address and username, per address, and per process.
|
|
1253
|
+
What to change, and what you may notice, for every release: [UPGRADING.md](https://github.com/phantomboy0/nest-my-admin/blob/main/UPGRADING.md).
|
|
1158
1254
|
|
|
1159
1255
|
## Develop
|
|
1160
1256
|
|
|
@@ -1169,4 +1265,18 @@ bun run e2e # Playwright (run `bunx playwright install
|
|
|
1169
1265
|
cd examples/demo-api && bun src/main.ts # DATABASE_URL=postgres://… or mysql://… to use a real database
|
|
1170
1266
|
```
|
|
1171
1267
|
|
|
1268
|
+
The README's screenshots are taken from the showcase shop in the Chrome installed on your machine (nothing is
|
|
1269
|
+
downloaded):
|
|
1270
|
+
|
|
1271
|
+
```bash
|
|
1272
|
+
cd examples/demo-api
|
|
1273
|
+
NMA_DEMO_SHOWCASE=1 NMA_UPLOAD_DIR=$(mktemp -d) PORT=3100 bun src/main.ts &
|
|
1274
|
+
bun scripts/showcase-shots.ts # all of docs/images, or name some: bun scripts/showcase-shots.ts order rtl
|
|
1275
|
+
bun scripts/render-product-images.ts # only after changing the catalog: redraws the product pictures
|
|
1276
|
+
```
|
|
1277
|
+
|
|
1172
1278
|
Design: `docs/superpowers/specs/2026-09-29-nest-my-admin-design.md`.
|
|
1279
|
+
|
|
1280
|
+
## License
|
|
1281
|
+
|
|
1282
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nest-my-admin",
|
|
3
|
-
"version": "0.10.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.10.5",
|
|
4
|
+
"description": "An admin panel for NestJS + TypeORM in the spirit of Django admin: lists, forms, roles, audit log and a prebuilt UI, served by your own app",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
"directory": "packages/nest-my-admin"
|
|
10
10
|
},
|
|
11
11
|
"homepage": "https://github.com/phantomboy0/nest-my-admin#readme",
|
|
12
|
+
"bugs": "https://github.com/phantomboy0/nest-my-admin/issues",
|
|
13
|
+
"keywords": ["nestjs", "nest", "typeorm", "admin", "admin-panel", "django-admin", "backoffice", "crud", "dashboard", "rbac", "audit-log", "rtl"],
|
|
12
14
|
"type": "module",
|
|
13
15
|
"main": "./index.js",
|
|
14
16
|
"types": "./index.d.ts",
|
|
@@ -39,8 +41,8 @@
|
|
|
39
41
|
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
40
42
|
},
|
|
41
43
|
"dependencies": {
|
|
42
|
-
"@nest-my-admin/auth": "0.10.
|
|
43
|
-
"@nest-my-admin/core": "0.10.
|
|
44
|
-
"@nest-my-admin/testing": "0.10.
|
|
44
|
+
"@nest-my-admin/auth": "0.10.5",
|
|
45
|
+
"@nest-my-admin/core": "0.10.5",
|
|
46
|
+
"@nest-my-admin/testing": "0.10.5"
|
|
45
47
|
}
|
|
46
48
|
}
|