create-knit 0.8.0 → 0.9.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: knit-add-permission
|
|
3
|
-
description: Add a custom permission to a Knit app, enforce it on the server and grant it to a group or user - customPermissions, requirePermission, resource rules, row-level policies, seeds and a denied-request test. Use when asked to restrict who can do something, add a role-like capability ("only editors can publish"), limit users to their own rows ("editors change only their own posts"), or grant permissions in a Knit project.
|
|
3
|
+
description: Add a custom permission to a Knit app, enforce it on the server and grant it to a group or user - customPermissions, requirePermission, resource rules, row-level policies (incl. organization-scoped rows), seeds and a denied-request test. Use when asked to restrict who can do something, add a role-like capability ("only editors can publish"), limit users to their own rows ("editors change only their own posts") or their organization's rows ("each team sees only its projects"), or grant permissions in a Knit project.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Add a permission and grant it
|
|
@@ -14,6 +14,7 @@ description: Add a custom permission to a Knit app, enforce it on the server and
|
|
|
14
14
|
- Server route: `await requirePermission(event, 'blog.publish_post')` in a route under `layers/<app>/server/api/` (auto-imported there).
|
|
15
15
|
- Resource: put the name in the action's rule, e.g. `permissions: { update: 'blog.publish_post' }` or `[isOwner('authorId'), 'blog.change_post']` (any rule allows).
|
|
16
16
|
- Only some rows ("their own posts", "their team's tickets"): a row-level policy on the model, in `layers/<app>/server/database/schema.ts` (`pnpm manage generate policy <app> <model>` writes a starting one): `defineModelMeta(table, { policy: { assignOwner: 'authorId', change: [isRowOwner('authorId'), 'blog.change_any_post'] } })`. The admin, resources and broadcasts all apply it; your own server code applies it with `useModel(table).as(await requestActor(event))`. Use `scope` only for rows a user must not see at all (it hides them from visitors too). Guide: `knit_docs { "topic": "permissions" }`.
|
|
17
|
+
- Rows that belong to an organization ("each customer sees only their company's projects"): turn on organizations (`NUXT_KNIT_AUTH_ORGANIZATIONS_ENABLED=true`), give the model an `organizationId` column referencing `organization.id` from `@knit-framework/core/schema`, and run `pnpm manage generate policy <app> <model> --organization`: `scope: inActiveOrganization('organizationId')`, `assignOrganization: 'organizationId'`, and `hasOrganizationRole('owner', 'admin')` for what only the organization's admins may do. `ctx.organization` (`{ id, role }` or `null`) is in every rule. In tests, `createTestClient().switchOrganization(id)`. Guide: `knit_docs { "topic": "organizations" }`.
|
|
17
18
|
4. **Create the permission rows.** The server creates them when it starts. A running `pnpm dev` reloads on the `admin.ts` change; restart it if the permission is still unknown. Granting before that fails with `KNIT_E1903` (`knit_docs { "topic": "errors/KNIT_E1903" }`).
|
|
18
19
|
5. **Grant it.**
|
|
19
20
|
- By hand: `/admin/auth/groups/:id` (a matrix per group) or `/admin/auth/users/:id`.
|
|
@@ -67,6 +67,14 @@ NUXT_BETTER_AUTH_URL=
|
|
|
67
67
|
# NUXT_KNIT_AUTH_TWO_FACTOR=optional
|
|
68
68
|
# Passkeys (WebAuthn): true (default) | false
|
|
69
69
|
# NUXT_KNIT_AUTH_PASSKEYS=true
|
|
70
|
+
# Organizations (docs/organizations.md): users create them, invite members and switch the active one
|
|
71
|
+
# NUXT_KNIT_AUTH_ORGANIZATIONS_ENABLED=false
|
|
72
|
+
# NUXT_KNIT_AUTH_ORGANIZATIONS_ALLOW_USER_TO_CREATE=true
|
|
73
|
+
# Creator's role: owner (default) | admin
|
|
74
|
+
# NUXT_KNIT_AUTH_ORGANIZATIONS_CREATOR_ROLE=owner
|
|
75
|
+
# Invitation lifetime in seconds (default 48 hours)
|
|
76
|
+
# NUXT_KNIT_AUTH_ORGANIZATIONS_INVITATION_EXPIRES_IN=172800
|
|
77
|
+
# NUXT_KNIT_AUTH_ORGANIZATIONS_MEMBERSHIP_LIMIT=100
|
|
70
78
|
|
|
71
79
|
# Email. Mailer: console (dev default, prints to the terminal) | smtp | memory (in-process outbox)
|
|
72
80
|
# Empty mailer = smtp when NUXT_MAIL_URL is set, otherwise console.
|
package/template/base/llms.txt
CHANGED
|
@@ -21,6 +21,7 @@ Agents working in a Knit project: read AGENTS.md, and use the `knit` MCP server
|
|
|
21
21
|
- [Admin](node_modules/@knit-framework/core/docs/admin.md): `registerAdminModel` options, filters, actions, inlines, history, user tools, REST API
|
|
22
22
|
- [Auth & permissions](node_modules/@knit-framework/core/docs/auth.md): Users, staff, superusers, groups, permissions, `/accounts/*` pages
|
|
23
23
|
- [Row-level permissions](node_modules/@knit-framework/core/docs/permissions.md): `defineModelMeta(table, { policy })`, `useModel(table).as(actor)`, what the admin, resources and realtime apply
|
|
24
|
+
- [Organizations](node_modules/@knit-framework/core/docs/organizations.md): `NUXT_KNIT_AUTH_ORGANIZATIONS_ENABLED`, invitations, roles, `inActiveOrganization` / `hasOrganizationRole` / `assignOrganization`, `useOrganization()`, `switchOrganization()` in tests
|
|
24
25
|
- [Internationalization](node_modules/@knit-framework/core/docs/i18n.md): Translations, locales per layer, translating models, the language switcher
|
|
25
26
|
- [Email](node_modules/@knit-framework/core/docs/email.md): `sendMail()`, mailers, templates, auth emails
|
|
26
27
|
- [Background tasks](node_modules/@knit-framework/core/docs/tasks.md): `defineTask`, `enqueue`, the worker, cron schedules
|
|
@@ -32,6 +33,7 @@ Agents working in a Knit project: read AGENTS.md, and use the `knit` MCP server
|
|
|
32
33
|
- [Logging](node_modules/@knit-framework/core/docs/logging.md): LogLayer: pretty dev output, JSON in production, request logs, redaction
|
|
33
34
|
- [Security](node_modules/@knit-framework/core/docs/security.md): CSRF, security headers, CSP
|
|
34
35
|
- [Testing](node_modules/@knit-framework/core/docs/testing.md): Test databases, factories, the HTTP client, `pnpm test`
|
|
36
|
+
- [Knit in Nuxt DevTools](node_modules/@knit-framework/core/docs/devtools.md): the dev-only Knit tab (models, routes, tasks, mail, realtime, errors, migrations), its actions and who may read it
|
|
35
37
|
- [`manage` CLI](node_modules/@knit-framework/core/docs/cli.md): Every command, `startapp` and `generate`, JSON output for scripts and agents, seeds, custom commands
|
|
36
38
|
- [Configuration](node_modules/@knit-framework/core/docs/configuration.md): Every environment variable and setting
|
|
37
39
|
- [Deployment](node_modules/@knit-framework/core/docs/deployment/index.md): production checklist, what Knit needs from a host, and one page per host (Docker, VPS with systemd and Caddy, Fly.io, Railway, Render; Vercel and Netlify with limits; Cloudflare not supported)
|
package/template/versions.json
CHANGED