@shamar/adonis 0.1.0 → 0.1.1
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 +177 -0
- package/package.json +10 -5
package/README.md
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# @shamar/adonis
|
|
2
|
+
|
|
3
|
+
AdonisJS **service provider** for Shamar — panels, routes, controllers, Edge views, CSS assets, and Cherubim auth wiring.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @shamar/adonis
|
|
9
|
+
# pick one persistence stack:
|
|
10
|
+
pnpm add @adonisjs/lucid # SQL
|
|
11
|
+
# or
|
|
12
|
+
pnpm add mongoose # MongoDB
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### Peer dependencies
|
|
16
|
+
|
|
17
|
+
| Peer | Required when |
|
|
18
|
+
|------|----------------|
|
|
19
|
+
| `@adonisjs/core` `>=6` | Always |
|
|
20
|
+
| `@adonisjs/lucid` `>=21` | `orm: 'lucid'` |
|
|
21
|
+
| `mongoose` `>=8` | `orm: 'mongoose'` |
|
|
22
|
+
| `edge.js` `>=6` | Rendering Edge views (usually already present) |
|
|
23
|
+
|
|
24
|
+
Workspace packages pulled in automatically: `@shamar/core`, `@shamar/cherubim`, `@shamar/lucid`, `@shamar/mongoose`.
|
|
25
|
+
|
|
26
|
+
## Configure
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
node ace configure @shamar/adonis
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
You choose **Lucid** or **Mongoose**. Codemods then:
|
|
33
|
+
|
|
34
|
+
1. Register `@shamar/adonis/provider` in `adonisrc.ts`
|
|
35
|
+
2. Write `config/shamar.ts` from the package stub
|
|
36
|
+
|
|
37
|
+
Your app still owns the database connection (Lucid provider or `mongoose.connect`).
|
|
38
|
+
|
|
39
|
+
## Quick start
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
// config/shamar.ts
|
|
43
|
+
import { defineConfig, panel } from '@shamar/adonis'
|
|
44
|
+
|
|
45
|
+
export default defineConfig({
|
|
46
|
+
orm: 'lucid', // or 'mongoose'
|
|
47
|
+
branding: { name: 'Admin' },
|
|
48
|
+
panels: [
|
|
49
|
+
panel('admin')
|
|
50
|
+
.path('/admin')
|
|
51
|
+
.discoverResources('app/resources/admin'),
|
|
52
|
+
],
|
|
53
|
+
})
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
// app/resources/admin/product_resource.ts
|
|
58
|
+
import { Resource, form, table, TextInput, TextColumn } from '@shamar/core'
|
|
59
|
+
import Product from '#models/product'
|
|
60
|
+
|
|
61
|
+
export default class ProductResource extends Resource {
|
|
62
|
+
static model = Product
|
|
63
|
+
static slug = 'products'
|
|
64
|
+
static label = 'Products'
|
|
65
|
+
|
|
66
|
+
static form() {
|
|
67
|
+
return form((f) => {
|
|
68
|
+
f.schema([
|
|
69
|
+
TextInput.make('name').required(),
|
|
70
|
+
TextInput.make('sku').required().unique(),
|
|
71
|
+
])
|
|
72
|
+
})
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
static table() {
|
|
76
|
+
return table((t) => {
|
|
77
|
+
t.schema([
|
|
78
|
+
TextColumn.make('name').sortable().searchable(),
|
|
79
|
+
TextColumn.make('sku').sortable().searchable(),
|
|
80
|
+
])
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Open `/admin` after starting the server. Single-panel apps can still use legacy top-level `path` + `resources` (normalized into one default panel).
|
|
87
|
+
|
|
88
|
+
## Config reference
|
|
89
|
+
|
|
90
|
+
`defineConfig` accepts:
|
|
91
|
+
|
|
92
|
+
| Key | Description |
|
|
93
|
+
|-----|-------------|
|
|
94
|
+
| `orm` | `'lucid'` \| `'mongoose'` (default Lucid). Panels may override. |
|
|
95
|
+
| `panels` | Array of `panel(id).path(…).discoverResources(…).branding(…)` |
|
|
96
|
+
| `branding` | Default branding inherited by panels |
|
|
97
|
+
| `apiPrefix` | JSON API prefix (default `/api/shamar`) |
|
|
98
|
+
| `adapter` | Escape hatch: custom `DataAdapter` (or factory) for all panels |
|
|
99
|
+
| `auth` | Session / API / policy wiring (see below) |
|
|
100
|
+
|
|
101
|
+
### Auth
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
auth: {
|
|
105
|
+
guard: 'web', // Adonis auth guard (default web)
|
|
106
|
+
loginPath: '/login',
|
|
107
|
+
logoutPath: '/logout',
|
|
108
|
+
required: true, // default true when guard or resolveUser is set
|
|
109
|
+
strictPermissions: true, // Cherubim strict mode
|
|
110
|
+
superUser: (user) => user.permissions?.includes('*'),
|
|
111
|
+
roleResolver: { resolveRolePermissions },
|
|
112
|
+
policies: { posts: instancePolicy(PostPolicy, 'posts') },
|
|
113
|
+
resolveUser: async (ctx) => { /* map session → CherubimUser */ },
|
|
114
|
+
apiKeys: {
|
|
115
|
+
resolve: (plainText, ctx) => resolveFromApiKey(plainText, store, { loadUser }),
|
|
116
|
+
protectApi: true, // RequireApiKeyMiddleware on /api/shamar
|
|
117
|
+
intersectGatewayAbilities: true,
|
|
118
|
+
},
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Full RBAC, policies, and credential details: [`@shamar/cherubim`](../cherubim).
|
|
123
|
+
|
|
124
|
+
### API keys admin UI
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
import { ApiKeyResource } from '@shamar/adonis'
|
|
128
|
+
import ApiKey from '#models/api_key'
|
|
129
|
+
|
|
130
|
+
export default class AppApiKeyResource extends ApiKeyResource {
|
|
131
|
+
static override model = ApiKey
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Register under a panel’s `discoverResources` folder (or `.resources([...])`).
|
|
136
|
+
|
|
137
|
+
### Middleware export
|
|
138
|
+
|
|
139
|
+
Apply API-key checks on selected routes without `protectApi`:
|
|
140
|
+
|
|
141
|
+
```ts
|
|
142
|
+
import router from '@adonisjs/core/services/router'
|
|
143
|
+
|
|
144
|
+
const middleware = router.named({
|
|
145
|
+
shamarApiKey: () => import('@shamar/adonis/require_api_key_middleware'),
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
router
|
|
149
|
+
.group(() => {
|
|
150
|
+
router.get('/mobile/products', /* … */)
|
|
151
|
+
})
|
|
152
|
+
.use([middleware.shamarApiKey()])
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Assets & views
|
|
156
|
+
|
|
157
|
+
Shipped with the package (no copy step required for defaults):
|
|
158
|
+
|
|
159
|
+
- Edge templates under `resources/views/shamar`
|
|
160
|
+
- Admin CSS under `assets/` (built via `pnpm build:css` in this package)
|
|
161
|
+
|
|
162
|
+
Override branding colors via `branding.primaryColor` / `accentColor` in config.
|
|
163
|
+
|
|
164
|
+
## Package exports
|
|
165
|
+
|
|
166
|
+
| Export | Purpose |
|
|
167
|
+
|--------|---------|
|
|
168
|
+
| `@shamar/adonis` | `defineConfig`, `panel`, `ApiKeyResource`, runtime helpers |
|
|
169
|
+
| `@shamar/adonis/provider` | Service provider |
|
|
170
|
+
| `@shamar/adonis/require_api_key_middleware` | Named middleware |
|
|
171
|
+
|
|
172
|
+
## Related
|
|
173
|
+
|
|
174
|
+
- [`@shamar/core`](../core) — Resource DSL
|
|
175
|
+
- [`@shamar/cherubim`](../cherubim) — policies, Authorizer, API keys
|
|
176
|
+
- [`@shamar/lucid`](../lucid) / [`@shamar/mongoose`](../mongoose) — adapters
|
|
177
|
+
- [Playground](../../apps/playground) — Mongoose dual-panel demo
|
package/package.json
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shamar/adonis",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "AdonisJS service provider for Shamar admin — routes, controllers, middleware, Edge views.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/coolsam726/shamar.git",
|
|
10
|
+
"directory": "packages/adonis"
|
|
11
|
+
},
|
|
7
12
|
"main": "./dist/index.js",
|
|
8
13
|
"types": "./dist/index.d.ts",
|
|
9
14
|
"exports": {
|
|
@@ -27,10 +32,10 @@
|
|
|
27
32
|
"stubs"
|
|
28
33
|
],
|
|
29
34
|
"dependencies": {
|
|
30
|
-
"@shamar/
|
|
31
|
-
"@shamar/
|
|
32
|
-
"@shamar/
|
|
33
|
-
"@shamar/
|
|
35
|
+
"@shamar/core": "0.1.1",
|
|
36
|
+
"@shamar/mongoose": "0.1.1",
|
|
37
|
+
"@shamar/lucid": "0.1.1",
|
|
38
|
+
"@shamar/cherubim": "0.1.1"
|
|
34
39
|
},
|
|
35
40
|
"peerDependencies": {
|
|
36
41
|
"@adonisjs/core": ">=6.0.0",
|