@bitakit/cli 0.2.11 → 0.3.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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bitakit/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "BitaKit project commands: add plugins and contributions, check a project with doctor.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"test": "node --test tests/*.test.mjs"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@bitakit/core": "^0.
|
|
29
|
-
"@bitakit/discovery": "^0.
|
|
28
|
+
"@bitakit/core": "^0.3.0",
|
|
29
|
+
"@bitakit/discovery": "^0.3.0",
|
|
30
30
|
"commander": "15.0.0",
|
|
31
31
|
"npm-check-updates": "^22.2.9",
|
|
32
32
|
"package-manager-detector": "^1.9.0",
|
|
@@ -52,6 +52,7 @@ commands, file locations, examples and the rules that matter; do not load every
|
|
|
52
52
|
| Another layout or frame, their own 404, error or sign-in page, a replaceable part | [references/layouts-and-screens.md](references/layouts-and-screens.md) |
|
|
53
53
|
| A rule around Actions: block, check or observe them | [references/interceptors.md](references/interceptors.md) |
|
|
54
54
|
| A user preference | [references/settings.md](references/settings.md) |
|
|
55
|
+
| Roles, permissions, or who may do what | [references/roles-and-permissions.md](references/roles-and-permissions.md) |
|
|
55
56
|
| Data that survives a reload or comes from a server or database | [references/data-and-api.md](references/data-and-api.md) |
|
|
56
57
|
| The app's colors, fonts or a theme file | The Theme files section of `node_modules/@bitakit/shell/README.md` |
|
|
57
58
|
| Tests, the browser preview, or what to report | [references/testing-and-preview.md](references/testing-and-preview.md) |
|
|
@@ -125,6 +126,8 @@ Decide before writing code, and tell the user the plan in a sentence or two.
|
|
|
125
126
|
| Data or logic that pages, Actions and other features use | Service with a `store()` | `services/<name>.ts` |
|
|
126
127
|
| Something the user triggers: button, link, menu entry | Action bound with `<Action>` | `actions/<name>.ts` |
|
|
127
128
|
| A choice the user keeps after a reload | Setting | `settings.ts` |
|
|
129
|
+
| Operations that roles may be allowed to perform | Permissions | `permissions.ts` |
|
|
130
|
+
| The app's roles and what each may do | Base roles (app only) | `src/roles.ts` |
|
|
128
131
|
| To tell other features that something happened | Event | `events.ts` |
|
|
129
132
|
| A place where other features can add buttons or UI | Slot and its outlet | `slots/<name>.ts` |
|
|
130
133
|
| Your UI in another feature's place or in the Shell | Slot contribution or Action slots | `ui/slots/<slot>.tsx` |
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Roles and permissions
|
|
2
|
+
|
|
3
|
+
Plugins declare what can be done; the app decides which roles may do it. Core only checks the
|
|
4
|
+
declarations; the authorization provider (Better Auth through `@bitakit/better-auth`) owns
|
|
5
|
+
membership, custom roles and every server-side decision.
|
|
6
|
+
|
|
7
|
+
## Declare a plugin's permissions
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
// src/plugins/content/permissions.ts
|
|
11
|
+
import { definePermissions } from '@bitakit/core';
|
|
12
|
+
|
|
13
|
+
export default definePermissions({ content: ['read', 'edit', 'publish'] });
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
- Resources and operations start with a lowercase letter (letters, digits, `-`).
|
|
17
|
+
- One resource has one owning plugin. Another plugin uses it, it never declares it again.
|
|
18
|
+
- A plugin never declares roles; a `roles.ts` in a plugin fails discovery.
|
|
19
|
+
|
|
20
|
+
## Define the app's base roles
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
// src/roles.ts
|
|
24
|
+
import { defineRoles } from '@bitakit/core';
|
|
25
|
+
|
|
26
|
+
export default defineRoles(
|
|
27
|
+
{
|
|
28
|
+
owner: { standard: 'owner', grants: { content: ['read', 'edit', 'publish'] } },
|
|
29
|
+
admin: { standard: 'admin', grants: { content: ['read', 'edit', 'publish'] } },
|
|
30
|
+
member: { standard: 'member', label: 'Editor', grants: { content: ['read', 'edit'] } },
|
|
31
|
+
viewer: { label: 'Reader', description: 'Can view content.', grants: { content: ['read'] } },
|
|
32
|
+
},
|
|
33
|
+
{ customRoles: true },
|
|
34
|
+
);
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
- `standard` extends the provider's built-in `owner`, `admin` or `member` (each once).
|
|
38
|
+
- `label`/`description` are defaults; translations (`roles.<id>.label|description`) override.
|
|
39
|
+
- `grants` are typed against the discovered permissions after `npx bitakit generate`.
|
|
40
|
+
- Order is display order only; it never ranks permissions.
|
|
41
|
+
- `customRoles: true` lets organizations create their own roles through the provider.
|
|
42
|
+
|
|
43
|
+
## Use them on the server
|
|
44
|
+
|
|
45
|
+
`npx bitakit generate` writes `src/bitakit.gen.access.ts` (only when declarations exist): the
|
|
46
|
+
composed, checked `accessConfiguration`, server-safe pure data. Authorization adapters build
|
|
47
|
+
their provider configuration from it; never import the client-side `bitakit.gen` config on a
|
|
48
|
+
server.
|
|
49
|
+
|
|
50
|
+
## Checks
|
|
51
|
+
|
|
52
|
+
`npx bitakit generate` (part of typecheck) and the runtime start reject, with every source file
|
|
53
|
+
named: a resource declared twice, a grant of an unknown resource or operation, a standard role
|
|
54
|
+
extended twice, and roles outside `src/roles.ts`. Fix the declaration; never rely on order.
|
|
55
|
+
|
|
56
|
+
## Rules
|
|
57
|
+
|
|
58
|
+
- Check capabilities on the server through the provider ("may this member publish content in
|
|
59
|
+
this organization?"), never role names or order. Client checks only shape the UI.
|
|
60
|
+
- Do not keep role lists, aliases or rank tables in the app; read the declared roles.
|