@feltdb/feltkit 0.3.17 → 0.3.19
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/dist/app.d.ts +246 -13
- package/dist/app.js +215 -6
- package/dist/app.js.map +1 -1
- package/dist/appboundry/build.d.ts +70 -0
- package/dist/appboundry/build.js +62 -2
- package/dist/appboundry/build.js.map +1 -1
- package/dist/appboundry/guest.js +57 -3
- package/dist/appboundry/guest.js.map +1 -1
- package/dist/appboundry/host.js +7 -0
- package/dist/appboundry/host.js.map +1 -1
- package/dist/authorize.js +1 -0
- package/dist/authorize.js.map +1 -1
- package/dist/cli/compose.d.ts +31 -0
- package/dist/cli/compose.js +274 -0
- package/dist/cli/compose.js.map +1 -0
- package/dist/cli/create.d.ts +201 -0
- package/dist/cli/create.js +1139 -0
- package/dist/cli/create.js.map +1 -0
- package/dist/cli/deploy-appboundry-self-hosted.d.ts +2 -0
- package/dist/cli/deploy-appboundry-self-hosted.js +1 -1
- package/dist/cli/deploy-appboundry-self-hosted.js.map +1 -1
- package/dist/cli/deploy-appboundry.js +3 -0
- package/dist/cli/deploy-appboundry.js.map +1 -1
- package/dist/cli/deploy.d.ts +1 -0
- package/dist/cli/deploy.js +66 -6
- package/dist/cli/deploy.js.map +1 -1
- package/dist/cli/domain.d.ts +174 -0
- package/dist/cli/domain.js +1119 -0
- package/dist/cli/domain.js.map +1 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +141 -7
- package/dist/cli/main.js.map +1 -1
- package/dist/cli/shell.d.ts +7 -0
- package/dist/cli/shell.js +59 -0
- package/dist/cli/shell.js.map +1 -0
- package/dist/client/index.d.ts +192 -5
- package/dist/client/index.js +301 -28
- package/dist/client/index.js.map +1 -1
- package/dist/component.d.ts +174 -0
- package/dist/component.js +77 -0
- package/dist/component.js.map +1 -0
- package/dist/composition/catalog.d.ts +3 -0
- package/dist/composition/catalog.js +217 -0
- package/dist/composition/catalog.js.map +1 -0
- package/dist/composition/contract.d.ts +165 -0
- package/dist/composition/contract.js +12 -0
- package/dist/composition/contract.js.map +1 -0
- package/dist/composition/execute.d.ts +110 -0
- package/dist/composition/execute.js +350 -0
- package/dist/composition/execute.js.map +1 -0
- package/dist/composition/generate.d.ts +105 -0
- package/dist/composition/generate.js +274 -0
- package/dist/composition/generate.js.map +1 -0
- package/dist/composition/plan.d.ts +131 -0
- package/dist/composition/plan.js +558 -0
- package/dist/composition/plan.js.map +1 -0
- package/dist/composition/profiles.d.ts +20 -0
- package/dist/composition/profiles.js +81 -0
- package/dist/composition/profiles.js.map +1 -0
- package/dist/composition/reconcile.d.ts +153 -0
- package/dist/composition/reconcile.js +282 -0
- package/dist/composition/reconcile.js.map +1 -0
- package/dist/composition/recover.d.ts +89 -0
- package/dist/composition/recover.js +407 -0
- package/dist/composition/recover.js.map +1 -0
- package/dist/composition/resolve.d.ts +2 -0
- package/dist/composition/resolve.js +208 -0
- package/dist/composition/resolve.js.map +1 -0
- package/dist/dashboard/assets/{index-DnIOVGF-.js → index-BrC1AtZ1.js} +5 -5
- package/dist/dashboard/index.html +1 -1
- package/dist/docs.d.ts +1 -1
- package/dist/docs.js +2 -0
- package/dist/docs.js.map +1 -1
- package/dist/index.d.ts +7 -3
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/react/auth.d.ts +131 -0
- package/dist/react/auth.js +830 -0
- package/dist/react/auth.js.map +1 -0
- package/dist/react/context.d.ts +8 -0
- package/dist/react/context.js +14 -0
- package/dist/react/context.js.map +1 -0
- package/dist/react/index.d.ts +3 -18
- package/dist/react/index.js +5 -13
- package/dist/react/index.js.map +1 -1
- package/dist/runtime/accounts.d.ts +33 -2
- package/dist/runtime/accounts.js +167 -27
- package/dist/runtime/accounts.js.map +1 -1
- package/dist/runtime/activity.d.ts +8 -1
- package/dist/runtime/activity.js.map +1 -1
- package/dist/runtime/audit.d.ts +43 -0
- package/dist/runtime/audit.js +52 -0
- package/dist/runtime/audit.js.map +1 -0
- package/dist/runtime/authority.d.ts +8 -1
- package/dist/runtime/authority.js +11 -2
- package/dist/runtime/authority.js.map +1 -1
- package/dist/runtime/challenges.d.ts +51 -0
- package/dist/runtime/challenges.js +121 -0
- package/dist/runtime/challenges.js.map +1 -0
- package/dist/runtime/changes.d.ts +22 -0
- package/dist/runtime/changes.js +51 -3
- package/dist/runtime/changes.js.map +1 -1
- package/dist/runtime/claims.d.ts +76 -0
- package/dist/runtime/claims.js +100 -0
- package/dist/runtime/claims.js.map +1 -0
- package/dist/runtime/context.d.ts +47 -5
- package/dist/runtime/contract.js +17 -3
- package/dist/runtime/contract.js.map +1 -1
- package/dist/runtime/data.d.ts +50 -4
- package/dist/runtime/data.js +113 -35
- package/dist/runtime/data.js.map +1 -1
- package/dist/runtime/escape-hatch.d.ts +37 -0
- package/dist/runtime/escape-hatch.js +76 -0
- package/dist/runtime/escape-hatch.js.map +1 -0
- package/dist/runtime/instance.js +2 -1
- package/dist/runtime/instance.js.map +1 -1
- package/dist/runtime/live.d.ts +48 -0
- package/dist/runtime/live.js +154 -0
- package/dist/runtime/live.js.map +1 -0
- package/dist/runtime/outbox.js +6 -0
- package/dist/runtime/outbox.js.map +1 -1
- package/dist/runtime/runtime.d.ts +103 -5
- package/dist/runtime/runtime.js +411 -41
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/runtime/search.d.ts +54 -0
- package/dist/runtime/search.js +66 -0
- package/dist/runtime/search.js.map +1 -0
- package/dist/runtime/services-rules.d.ts +12 -0
- package/dist/runtime/services-rules.js +8 -0
- package/dist/runtime/services-rules.js.map +1 -0
- package/dist/runtime/services.js +5 -3
- package/dist/runtime/services.js.map +1 -1
- package/dist/runtime/sessions.d.ts +16 -2
- package/dist/runtime/sessions.js +40 -4
- package/dist/runtime/sessions.js.map +1 -1
- package/dist/runtime/tenancy.d.ts +198 -0
- package/dist/runtime/tenancy.js +397 -0
- package/dist/runtime/tenancy.js.map +1 -0
- package/dist/runtime/tenant-scope.d.ts +9 -0
- package/dist/runtime/tenant-scope.js +127 -0
- package/dist/runtime/tenant-scope.js.map +1 -0
- package/dist/runtime/transactions.d.ts +83 -3
- package/dist/runtime/transactions.js +53 -11
- package/dist/runtime/transactions.js.map +1 -1
- package/dist/server/admin.js +52 -0
- package/dist/server/admin.js.map +1 -1
- package/dist/server/components.d.ts +44 -0
- package/dist/server/components.js +212 -0
- package/dist/server/components.js.map +1 -0
- package/dist/server/index.d.ts +4 -1
- package/dist/server/index.js +324 -63
- package/dist/server/index.js.map +1 -1
- package/dist/server/mcp.js +6 -3
- package/dist/server/mcp.js.map +1 -1
- package/dist/server/project.d.ts +27 -0
- package/dist/server/project.js +63 -0
- package/dist/server/project.js.map +1 -1
- package/dist/server/public.d.ts +2 -0
- package/dist/server/public.js +2 -0
- package/dist/server/public.js.map +1 -1
- package/dist/server/session-http.d.ts +48 -0
- package/dist/server/session-http.js +116 -0
- package/dist/server/session-http.js.map +1 -0
- package/dist/server/tenancy.d.ts +40 -0
- package/dist/server/tenancy.js +191 -0
- package/dist/server/tenancy.js.map +1 -0
- package/dist/testing/index.d.ts +19 -0
- package/dist/testing/index.js +22 -2
- package/dist/testing/index.js.map +1 -1
- package/docs/AGENT-OPERATIONS.md +1 -0
- package/docs/APPBOUNDRY.md +11 -1
- package/docs/ARCHITECTURE.md +5 -3
- package/docs/AUTH.md +267 -0
- package/docs/COMPONENTS.md +91 -0
- package/docs/GUARANTEES.md +74 -7
- package/docs/README.md +4 -2
- package/docs/RESOLVER.md +4 -2
- package/docs/SECURITY.md +5 -4
- package/docs/TRANSACTIONS.md +98 -1
- package/docs/UPSTREAM-GAPS.md +2 -0
- package/package.json +15 -12
- package/skills/.claude-plugin/marketplace.json +1 -1
- package/skills/.claude-plugin/plugin.json +1 -1
- package/skills/feltkit-data/SKILL.md +6 -0
- package/skills/feltkit-services/SKILL.md +1 -1
- package/dist/runtime/account-links.d.ts +0 -19
- package/dist/runtime/account-links.js +0 -45
- package/dist/runtime/account-links.js.map +0 -1
package/docs/ARCHITECTURE.md
CHANGED
|
@@ -14,7 +14,7 @@ shortest correct path:
|
|
|
14
14
|
| App query/mutation over HTTP | server → `runtime.call` → authority → `ctx.db` → FeltDB |
|
|
15
15
|
| Capability via AppPort or MCP | AppPort `HttpBinding`/MCP bridge → AppPort dispatch (validate → authorize → execute) → `runtime.call` → FeltDB |
|
|
16
16
|
| Service effect | `ctx.services.files` → AppPort Services `ServiceGateway` (authorize → effect → evidence) → FeltDB |
|
|
17
|
-
| Live query update | FeltDB operation journal → change feed → SSE → client re-runs the
|
|
17
|
+
| Live query update | FeltDB operation journal (+ the commit's described writes) → change feed → SSE, filtered per subscriber (tenant) with opaque predicate keys → client re-runs the queries whose predicates the change meets |
|
|
18
18
|
| Dashboard | admin API (admin token) → the same runtime and instance |
|
|
19
19
|
|
|
20
20
|
## Components
|
|
@@ -31,7 +31,9 @@ shortest correct path:
|
|
|
31
31
|
| `runtime/agent.ts` | The FeltKit agent: FeltDB `defineAgent`/executions (`findAgentExecution`, `resumeAgentExecution`, `cancelAgentExecution`) + `openAgentState` (`listTasks`, `listHandoffs`) on the shared instance; actions only through AppPort and AppPort Services; the action lifecycle (compare-and-swap state changes on FeltDB agent memory, restart reconciliation from evidence); approvals; playbooks; handoffs. |
|
|
32
32
|
| `runtime/idempotency.ts` | AppPort's published `IdempotencyStore` on FeltDB: atomic in-progress claims (a FeltDB `requireAbsent` / `ifVersion` transaction), records, release, and lookup by request id, so a replay after a crash is "outcome unknown" and records survive a restart. Checked by `@appport/testing`'s conformance suite. |
|
|
33
33
|
| `runtime/activity.ts` | Durable activity log built from commit results; links to Services evidence. |
|
|
34
|
-
| `runtime/changes.ts` | Change feed from FeltDB's operation journal (kept over collection subscriptions: see docs/UPSTREAM-GAPS.md F1/F7). |
|
|
34
|
+
| `runtime/changes.ts` | Change feed from FeltDB's operation journal (kept over collection subscriptions: see docs/UPSTREAM-GAPS.md F1/F7), with the keyed values of writes FeltKit committed. |
|
|
35
|
+
| `runtime/live.ts` | Live queries by predicate: keyed fields, the read set with its equality predicates, opaque keys (process-key HMAC). |
|
|
36
|
+
| `runtime/search.ts` | `ctx.db.search`: normalization, matching, the bounded scan (shared by the runtime and the AppBoundry guest). |
|
|
35
37
|
| `runtime/content.ts` | File bytes in `_feltkit_file_content`: stored before the file record, verified on read, removed with the file (FeltDB's content store is not used yet: no deletion, no memory runtime). |
|
|
36
38
|
| `runtime/runtime.ts` | Lifecycle, hot reload, `call()`, AppPort application construction. |
|
|
37
39
|
| `runtime/loader.ts` | Loads `feltkit/` (tsx in development, the esbuild bundle in production). |
|
|
@@ -93,7 +95,7 @@ of these APIs against the real package on the shared instance.
|
|
|
93
95
|
|
|
94
96
|
## One copy of FeltDB
|
|
95
97
|
|
|
96
|
-
FeltKit depends on `@feltdb/core` `>=0.21.0 <1.0.0` and `@appport/services` `>=0.
|
|
98
|
+
FeltKit depends on `@feltdb/core` `>=0.21.0 <1.0.0` and `@appport/services` `>=0.16.0 <1.0.0`, and
|
|
97
99
|
ships npm's latest of both. FeltDB 0.20 refuses `collection.find()` past 1,000 matches; FeltKit reads
|
|
98
100
|
every multi-record result in `db.query` pages instead (docs/UPSTREAM-GAPS.md, "Review 2026-11-03"). AppPort Services takes `@feltdb/core` as a peer dependency, so it uses the
|
|
99
101
|
application's copy and npm installs exactly one, with no `overrides`. Two module copies in one process
|
package/docs/AUTH.md
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
# Accounts, sessions, workspaces and the sign-in screens
|
|
2
|
+
|
|
3
|
+
FeltKit gives an application its people and their workspaces:
|
|
4
|
+
- sign-in (password, e-mailed links, Google, GitHub, any OpenID Connect provider);
|
|
5
|
+
- the account (profile, address, password, connected providers, sessions);
|
|
6
|
+
- tenancy (workspaces, roles, invitations, switching);
|
|
7
|
+
- the React screens for all of it.
|
|
8
|
+
|
|
9
|
+
Everything is enforced on the server. The state lives in the application's own FeltDB instance, and
|
|
10
|
+
e-mail goes through AppPort Services' notifications and Mailerport. A complete app built only from these
|
|
11
|
+
pieces is `examples/teams`.
|
|
12
|
+
|
|
13
|
+
## Configure
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { feltkit, s } from "@feltdb/feltkit";
|
|
17
|
+
|
|
18
|
+
export const app = feltkit({
|
|
19
|
+
name: "teams",
|
|
20
|
+
// One authorization model: workspace roles are ordinary roles.
|
|
21
|
+
roles: {
|
|
22
|
+
person: [], // every account, before it joins a workspace
|
|
23
|
+
owner: ["notes.*", "tenant.*"], // tenant.* = manage members and rename
|
|
24
|
+
admin: ["notes.*", "tenant.members.manage"],
|
|
25
|
+
member: ["notes.*"],
|
|
26
|
+
guest: ["notes.read"],
|
|
27
|
+
},
|
|
28
|
+
auth: {
|
|
29
|
+
accounts: {
|
|
30
|
+
roles: ["person"], // what every account holds everywhere
|
|
31
|
+
password: true, // default
|
|
32
|
+
magicLink: true, // e-mailed sign-in link + 8-digit code
|
|
33
|
+
email: { from: "auth@example.com", verify: "optional", templates: { /* optional */ } },
|
|
34
|
+
},
|
|
35
|
+
providers: { google: { clientId: "…" }, github: { clientId: "…" }, oidc: [{ id: "okta", issuer: "https://…", clientId: "…" }] },
|
|
36
|
+
session: { cookie: "auto", trustProxy: 1 },
|
|
37
|
+
tenant: {
|
|
38
|
+
name: "workspace", // the word the screens and messages use
|
|
39
|
+
roles: ["owner", "admin", "member", "guest"], // highest first; each a declared role
|
|
40
|
+
claims: { plan: { type: "enum", values: ["free", "pro"] }, seats: { type: "integer", default: 1 } }, // claim specs (plain data) or schemas
|
|
41
|
+
create: "anyone", // or "none"
|
|
42
|
+
invitations: { ttlMs: 7 * 24 * 3_600_000 }, // default 7 days, at most 30
|
|
43
|
+
switching: true,
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
`feltkit()` refuses a configuration that cannot work, and says what to change:
|
|
50
|
+
- a role that is not declared;
|
|
51
|
+
- `magicLink` without `email`;
|
|
52
|
+
- no way to sign in;
|
|
53
|
+
- a tenant with no role granting `tenant.members.manage`;
|
|
54
|
+
- `role` declared as a claim;
|
|
55
|
+
- an unknown e-mail template;
|
|
56
|
+
- an inline client secret.
|
|
57
|
+
|
|
58
|
+
Provider client secrets are credentials: `credential-ref:<id>-client-secret`, for example `FELTKIT_CREDENTIAL_GOOGLE_CLIENT_SECRET`.
|
|
59
|
+
|
|
60
|
+
### Mapping from `use auth`
|
|
61
|
+
|
|
62
|
+
If you know AuthBoundry's `use auth { … }` block, this is the same configuration in FeltKit's one
|
|
63
|
+
configuration language:
|
|
64
|
+
|
|
65
|
+
| `use auth` | `feltkit({ auth })` |
|
|
66
|
+
|---|---|
|
|
67
|
+
| `providers=[email]` | `accounts` (password) |
|
|
68
|
+
| `providers=[magic-link]` | `accounts.magicLink` |
|
|
69
|
+
| `providers=[google,github]` | `providers.google`, `providers.github` |
|
|
70
|
+
| `tenant=true` | `tenant` |
|
|
71
|
+
| `claims={role=enum[…]}` | `tenant.roles` |
|
|
72
|
+
| `claims={plan=enum[…]}` | `tenant.claims.plan` |
|
|
73
|
+
| `use mail { identities … }` | `accounts.email.from` and `identity` |
|
|
74
|
+
| `use mail { templates … }` | `accounts.email.templates` |
|
|
75
|
+
|
|
76
|
+
## Sign-in methods and account e-mail
|
|
77
|
+
|
|
78
|
+
| Method | How |
|
|
79
|
+
|---|---|
|
|
80
|
+
| Password | `POST /api/auth/signup`, `POST /api/auth/signin`. scrypt hashes. One answer for an unknown address and a wrong password, which take the same time. 10 failures per address and per client address in 15 minutes. |
|
|
81
|
+
| Magic link | `POST /api/auth/magic/request { email }` sends a link and an 8-digit code. `POST /api/auth/magic { token }` or `{ email, code }` redeems them. A new address gets a verified account when sign-up is open. |
|
|
82
|
+
| Google, GitHub, OIDC | Authorization code with PKCE (S256) and a `state` bound to the browser. Only a verified e-mail address is accepted. |
|
|
83
|
+
| Verify address | `POST /api/auth/verify/request { email }`, then `POST /api/auth/verify { token }`. |
|
|
84
|
+
| Reset password | `POST /api/auth/reset/request { email }`, then `POST /api/auth/reset { token, password }`. Signs the account out everywhere. |
|
|
85
|
+
|
|
86
|
+
**Sign-up and enumeration.** With `email.verify: "required"`, sign-up answers the same for a taken address
|
|
87
|
+
as for a new one: the address's owner gets a password-reset link instead. With optional verification, a new
|
|
88
|
+
account gets its session at once, so sign-up necessarily reveals a taken address (`CONFLICT`). Use
|
|
89
|
+
`verify: "required"`, or magic links alone, when that matters.
|
|
90
|
+
|
|
91
|
+
Every e-mailed secret (verify, reset, magic link, address change) is a **challenge**:
|
|
92
|
+
- **Lifetime:** durable in FeltDB, at most 15 minutes, single use, and superseded when another is requested for the same purpose.
|
|
93
|
+
- **Codes:** a code allows 5 wrong attempts, then the challenge is void.
|
|
94
|
+
- **Volume:** 5 challenges per address and purpose per hour.
|
|
95
|
+
- **Storage:** the record holds a nonce and digests only. The link token and the code are `HMAC(FELTKIT_AUTH_SECRET, nonce)`, computed when the e-mail is delivered, so neither the notification record nor the challenge record holds a usable secret.
|
|
96
|
+
- **Answers:** requests answer the same whether or not the address has an account, and whether or not it is over its limit.
|
|
97
|
+
|
|
98
|
+
E-mail goes through AppPort Services' notifications to Mailerport:
|
|
99
|
+
- **Development:** the message is printed by `feltkit dev`.
|
|
100
|
+
- **Production:** it goes to the Mailerport service at `MAILPORT_URL` with `MAILPORT_API_KEY`, as the identity you register there (default `auth`).
|
|
101
|
+
|
|
102
|
+
Your own text: `accounts.email.templates[purpose](input) → { subject, text, html? }`, where `purpose` is one of `verify`, `reset`, `magic-link`, `email-change` or `invitation`.
|
|
103
|
+
|
|
104
|
+
## Sessions
|
|
105
|
+
|
|
106
|
+
- **Browsers: an HttpOnly cookie.**
|
|
107
|
+
- **Cookie:** `createClient()` in a browser uses cookie mode. The cookie is `__Host-fk_session` over HTTPS (Secure, Path=/, no Domain), or `fk_session` on plain-HTTP development, with `HttpOnly; SameSite=Lax`. Page script never sees the token, and nothing is kept in `localStorage`.
|
|
108
|
+
- **Migration:** an older client's `localStorage` token is moved into the cookie once (`POST /api/auth/cookie`), then removed.
|
|
109
|
+
- **CSRF.**
|
|
110
|
+
- A cookie-authenticated `POST`, `PUT` or `DELETE` must send `X-FeltKit-CSRF`, an HMAC of the session's digest that `GET /api/session` hands the page. The client does this for you.
|
|
111
|
+
- A request with a foreign `Origin` is refused.
|
|
112
|
+
- Cross-site pages cannot read the token, and cannot send the header without a CORS preflight, which FeltKit never grants.
|
|
113
|
+
- **CLI, services, API keys: bearer tokens, unchanged.** `Authorization: Bearer <token>`, with no CSRF token: a bearer token is not an ambient credential. `createClient({ session: "bearer" })` keeps the bearer behaviour in a browser.
|
|
114
|
+
- **Lifetime and revocation.**
|
|
115
|
+
- Lifetime: 7 days by default (`auth.sessionTtlMs`).
|
|
116
|
+
- Signing out deletes the session and clears the cookie.
|
|
117
|
+
- `GET /api/auth/sessions` lists your sessions.
|
|
118
|
+
- `POST /api/auth/sessions/revoke` takes `{ ref }` for one, or `{ all: true, keepCurrent }` for all of them.
|
|
119
|
+
- **Rotation.** A password change, and switching, creating, leaving or joining a workspace, replace the session (a new token; the old one ends).
|
|
120
|
+
- **Always current.** An account session is resolved again on every request: the account as it is now, plus the live membership in its workspace. Changed roles, a disabled account, a removed membership or a changed role in a workspace take effect on the next request, not at expiry. Roles are never trusted as copied at sign-in. Dev, CLI and agent sessions carry the roles their issuer gave them.
|
|
121
|
+
- **Trusted proxies.** `auth.session.trustProxy` is the number of reverse proxies in front that append to `X-Forwarded-For` and set `X-Forwarded-Proto`. With the default (0) both headers are ignored, because a client could forge them; the client address used for throttling is then the socket's.
|
|
122
|
+
|
|
123
|
+
## Workspaces (tenancy)
|
|
124
|
+
|
|
125
|
+
A tenant ("workspace", or whatever `tenant.name` says) has members.
|
|
126
|
+
- **Membership.** Each member has one of `tenant.roles` and typed claims.
|
|
127
|
+
- **Where a role applies.** A session works in one tenant at a time. In it, the member holds their role's permissions: the same `roles`, `access` and `authorize` hook as everything else. There is no second policy.
|
|
128
|
+
|
|
129
|
+
| Operation | Route | Who |
|
|
130
|
+
|---|---|---|
|
|
131
|
+
| Your workspaces, the current one, what you may do | `GET /api/tenants` | signed in |
|
|
132
|
+
| Create (you hold the top role) and switch to it | `POST /api/tenants { name }` | `tenant.create: "anyone"` |
|
|
133
|
+
| Switch (`null`: none) | `POST /api/tenants/switch { tenantId }` | members of it only |
|
|
134
|
+
| Members | `GET /api/tenants/current/members` | members |
|
|
135
|
+
| Change a role | `POST …/members/role { principalId, role }` | `tenant.members.manage` |
|
|
136
|
+
| Set claims | `POST …/members/claims { principalId, claims }` | `tenant.members.manage` |
|
|
137
|
+
| Remove | `POST …/members/remove { principalId }` | `tenant.members.manage` |
|
|
138
|
+
| Add an agent or service | `POST …/members/add { principalId, role }` | `tenant.members.manage` |
|
|
139
|
+
| Leave | `POST /api/tenants/current/leave` | members |
|
|
140
|
+
| Rename | `POST /api/tenants/current/rename { name }` | `tenant.update` |
|
|
141
|
+
| Invite, list, withdraw | `POST`/`GET …/invitations`, `POST …/invitations/revoke` | `tenant.members.manage` |
|
|
142
|
+
| What an invitation is for | `POST /api/invitations/preview { token }` | its holder |
|
|
143
|
+
| Accept | `POST /api/invitations/accept { token }` | the invited, verified address |
|
|
144
|
+
|
|
145
|
+
Rules the server enforces:
|
|
146
|
+
- **The tenant is the session's.** A tenant id in a request is only ever a request to switch, checked against your memberships. A tenant you are not a member of does not exist for you (`NOT_FOUND`).
|
|
147
|
+
- **Rank.** `tenant.roles` is ordered, highest first. A manager assigns and changes only roles below their own, and only the top role assigns the top role. Nobody raises their own role. A workspace always keeps a holder of the top role. A role that is not declared cannot be assigned, so a workspace administrator cannot create a capability.
|
|
148
|
+
- **Invitations.**
|
|
149
|
+
- **Token:** a random token derived with the auth secret, never stored.
|
|
150
|
+
- **Use:** single use, and expiring.
|
|
151
|
+
- **Who may accept:** only an account whose verified address is the invited one (development identities may accept in development).
|
|
152
|
+
- **Withdrawn or expired:** refused.
|
|
153
|
+
- **Delivery:** e-mailed when the app sends account e-mail, and the inviter also gets the link to share.
|
|
154
|
+
- **Agents and services** are added directly, with a role, only when they hold an operator-issued identity (`feltkit session create --type agent`) or are application agents the app declares (`app.agent`). People join only by invitation.
|
|
155
|
+
An application agent (`app.agent`) works in the tenant of the call that triggered it only if it is an active member there itself, with its own membership role; otherwise it runs with no tenant (docs/TRANSACTIONS.md §8).
|
|
156
|
+
- **Claims** are typed by `tenant.claims`, validated on write, and set only by the server (a member manager through `POST …/members/claims`, or an invitation's `claims`, effective at acceptance). A request never supplies them, and `role` is the membership's role, not a claim you set. `null` removes a claim.
|
|
157
|
+
- **Declaring.** A claim is a **claim spec**, plain data a composition record can hold (`{ type: "enum", values: ["free", "pro"] }`, `{ type: "integer", default: 1 }`; types `enum`, `string`, `boolean`, `number`, `integer`; optional `default`), or a schema (`s.enum([...])`) in application code. Both compile to the same validation. `feltkit create --claim plan:enum(free|pro)` records one; a malformed spec is refused when the app is declared.
|
|
158
|
+
- **At the boundary.** On every call, when the live membership is resolved, each declared claim is classified: `verified` (stored, set through the server, valid under the declaration now; with who set it, when and how: `invitation`, `manager`, `self`), `default` (the declaration's default; nothing stored), `unavailable` (nothing stored, no default), `invalid` (a stored value the current declaration refuses; withheld). Only `verified` and `default` values appear in `tenant.claims`; `tenant.provenance[name]` carries the status and origin. A stored claim the declaration no longer names is dropped. Nothing upgrades a status.
|
|
159
|
+
- **In authorization.** `app.requireClaim(ctx, "plan", ["pro"])` (or a predicate) returns the value or fails `FORBIDDEN` with the reason named (`CLAIM_UNAVAILABLE`, `CLAIM_INVALID`, `CLAIM_NOT_ALLOWED`). It runs after the function's `access` permission, never instead of it. `feltkit create --require notes:plan=pro` makes every function of a workspace-scoped entity call it first.
|
|
160
|
+
|
|
161
|
+
### Data that belongs to a workspace
|
|
162
|
+
|
|
163
|
+
```ts
|
|
164
|
+
export const notes = app.collection("notes", { title: s.string() }, { tenant: true }); // field tenantId
|
|
165
|
+
export const channels = app.collection("channels", { … }, { tenant: { field: "workspaceId" } });
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
FeltKit treats each operation as follows:
|
|
169
|
+
- **insert:** sets the field to the session's tenant, and refuses a different value (`FORBIDDEN`, hint `TENANT_MISMATCH`).
|
|
170
|
+
- **get:** returns `null` for another tenant's record.
|
|
171
|
+
- **find, count, query:** return only the session's tenant's records.
|
|
172
|
+
- **patch, replace, delete:** another tenant's record is `NOT_FOUND`.
|
|
173
|
+
- **No tenant in the call:** these collections are closed (`FAILED_PRECONDITION`, hint `NO_TENANT`).
|
|
174
|
+
|
|
175
|
+
FeltKit adds an index on the field. Records written before a collection was scoped have no tenant, so they are visible to none.
|
|
176
|
+
|
|
177
|
+
### In your functions
|
|
178
|
+
|
|
179
|
+
```ts
|
|
180
|
+
handler: async (ctx) => {
|
|
181
|
+
const tenant = app.requireTenant(ctx); // { id, name, role, claims, provenance } — typed by auth.tenant
|
|
182
|
+
if (tenant.claims.role === "owner") { … }
|
|
183
|
+
const plan = app.requireClaim(ctx, "plan", ["pro"]); // FORBIDDEN unless the membership's plan is a verified (or default) "pro"
|
|
184
|
+
if (tenant.provenance.seats?.status === "default") { … } // nobody set seats; the declaration's default applies
|
|
185
|
+
}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
`ctx.auth.tenant` is the same value, untyped. The `authorize` hook sees it on `request.principal.tenant`.
|
|
189
|
+
In tests, `createTestApp()` provides:
|
|
190
|
+
- `t.tenancy`, the store, for setup;
|
|
191
|
+
- `t.as(who, { tenant })`, which works in a tenant exactly as a session does.
|
|
192
|
+
|
|
193
|
+
## React screens (`@feltdb/feltkit/react`)
|
|
194
|
+
|
|
195
|
+
```tsx
|
|
196
|
+
import { SignIn, AcceptInvitation, CreateTenant, TenantSwitcher, TenantSettings, AccountSettings,
|
|
197
|
+
AuthNotices, VerifyEmailBanner, useAuth, useTenant, useAuthRedirect } from "@feltdb/feltkit/react";
|
|
198
|
+
|
|
199
|
+
function App() {
|
|
200
|
+
const auth = useAuth();
|
|
201
|
+
const tenant = useTenant();
|
|
202
|
+
const { redirect } = useAuthRedirect();
|
|
203
|
+
if (auth.loading) return null;
|
|
204
|
+
if (redirect?.kind === "invitation") return <AcceptInvitation />; // signs in first when needed
|
|
205
|
+
if (!auth.user) return <SignIn brand={{ name: "Teams", logo: "/logo.png" }} />;
|
|
206
|
+
if (!tenant.current) return <CreateTenant />;
|
|
207
|
+
return (
|
|
208
|
+
<>
|
|
209
|
+
<TenantSwitcher />
|
|
210
|
+
<AuthNotices /><VerifyEmailBanner />
|
|
211
|
+
{/* your app; tenant.current is the workspace; switching re-runs every live query */}
|
|
212
|
+
</>
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
| Component | What it does |
|
|
218
|
+
|---|---|
|
|
219
|
+
| `SignIn` | Offers what the app enables: password, sign-up, magic link and code, providers, forgot and reset. Also handles the links that come back into the app: reset, verified, expired or used links. `returnTo` accepts only a path on this site. |
|
|
220
|
+
| `AcceptInvitation` | Shows what the invitation is for. Signs in first, with the invited address prefilled, when needed. Handles expired, withdrawn, used and wrong-account invitations. Keeps the invitation for the tab until it is accepted. |
|
|
221
|
+
| `TenantSwitcher` | The current workspace, with a keyboard-accessible menu to switch to another or create one. |
|
|
222
|
+
| `CreateTenant` | First-run screen: open one of your workspaces, or create one. |
|
|
223
|
+
| `TenantSettings` (`MembersPanel`, `InvitationsPanel`) | Name, members, roles, removal, leaving, invitations (copy link, withdraw). Shows only what the server says you may do. |
|
|
224
|
+
| `AccountSettings` | Profile, address and verification, address change, password, connected providers, sessions, sign out of other sessions, sign out. |
|
|
225
|
+
| `AuthNotices`, `VerifyEmailBanner` | What a link opened while signed in did; a reminder to verify. |
|
|
226
|
+
|
|
227
|
+
All of them include:
|
|
228
|
+
- loading, empty, error and expired states;
|
|
229
|
+
- labelled form controls and `aria-live` status;
|
|
230
|
+
- keyboard operation and visible focus;
|
|
231
|
+
- layouts that work from phones to desktops.
|
|
232
|
+
|
|
233
|
+
**Styling.**
|
|
234
|
+
- **Stylesheet:** the components add one small stylesheet (`fk-*` classes) to the page, before your own CSS, so your rules win.
|
|
235
|
+
- **Theming:** use CSS custom properties on any ancestor: `--fk-accent`, `--fk-accent-ink`, `--fk-surface`, `--fk-ink`, `--fk-muted`, `--fk-line`, `--fk-danger`, `--fk-radius`, `--fk-font`. They default to your app's `--accent`, `--surface`, `--ink`, `--muted`, `--line` and `--radius` when it defines them, and to the system's colours (light and dark) otherwise.
|
|
236
|
+
- **Overrides:** every component takes `className`. Render `<FeltKitAuthStyles disabled />` once to style everything yourself.
|
|
237
|
+
|
|
238
|
+
## AppBoundry
|
|
239
|
+
|
|
240
|
+
An artifact built with `feltkit build --target appboundry` behaves as follows:
|
|
241
|
+
- **Collections:** it carries the tenant-scoped collections, and the guest applies the same scope to the tenant its host resolves.
|
|
242
|
+
- **Closed by default:** a host that resolves no tenant leaves those collections closed.
|
|
243
|
+
- **What AppBoundry lacks today:** AppBoundry's host issues operator sessions and has no accounts or tenancy (FK-GAP-013). Sign-in, invitations and switching therefore need FeltKit's Node server (`feltkit dev`, `feltkit start`, `feltkit deploy`) until it does.
|
|
244
|
+
- **Declared and warned:** the build declares `auth.accounts` as `identity.accounts` and `auth.tenant` as `identity.tenancy` in the manifest, lists them under `omitted`, and warns. An AppBoundry host that knows the declaration refuses the artifact unless its operator accepts operator-issued sessions (`appboundry run --accounts operator-sessions`).
|
|
245
|
+
- **File links:** these, and the routes above, are Node-server routes.
|
|
246
|
+
|
|
247
|
+
## Deploying
|
|
248
|
+
|
|
249
|
+
| Setting | Why |
|
|
250
|
+
|---|---|
|
|
251
|
+
| `FELTKIT_AUTH_SECRET` (32+ bytes, the same on every process) | Derives challenge, invitation and CSRF tokens and signs provider state. In development, and with local production state, it is generated and kept beside the state. Changing it invalidates outstanding links and CSRF tokens, not sessions. |
|
|
252
|
+
| HTTPS in front | `__Host-` cookies need it, and production cookies are always `Secure`. |
|
|
253
|
+
| `auth.session.trustProxy` | The number of proxies that set `X-Forwarded-For` and `-Proto`. |
|
|
254
|
+
| `FELTKIT_PUBLIC_URL` (https in production) | The origin that e-mailed links and provider callbacks use, never the request's `Host`. |
|
|
255
|
+
| `MAILPORT_URL`, `MAILPORT_API_KEY` | Account e-mail and invitations in production. |
|
|
256
|
+
| One public origin for the app and its API | Cookie sessions are same-origin. A frontend on another origin uses `createClient({ url, session: "bearer" })`. |
|
|
257
|
+
|
|
258
|
+
## Migrating from the earlier auth API
|
|
259
|
+
|
|
260
|
+
- **Existing configuration:** `auth.accounts` and `auth.providers` work unchanged. Existing bearer sessions stay valid.
|
|
261
|
+
- **Browser client:** it now uses cookies. A token an older version left in `localStorage` is moved into the cookie on the first load. Pass `session: "bearer"` to keep the old behaviour.
|
|
262
|
+
- **Old links:** verification and reset links sent before this version stop working. They were stateless HMAC links (verification for 7 days); they are now durable 15-minute challenges. People ask for a new one.
|
|
263
|
+
- **Session response:** `GET /api/session` adds `transport`, `csrf` (cookie sessions), `tenant` and `tenancy`. `accounts` adds `password` and `magicLink`.
|
|
264
|
+
- **Workspaces you built yourself:** move them to `auth.tenant`.
|
|
265
|
+
- Make the workspace data `{ tenant: { field: "<your field>" } }`, so your records keep their field.
|
|
266
|
+
- Drop your membership and invitation collections.
|
|
267
|
+
- Take the workspace and role from `ctx.auth.tenant`, not from an argument.
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Runtime components
|
|
2
|
+
|
|
3
|
+
**Status:** implemented in FeltKit (`feltkit({ components })`, `defineComponent`, build, dev, start, deploy,
|
|
4
|
+
health). The AppBoundry side (`components@1`) is specified below and implemented on AppBoundry's side
|
|
5
|
+
separately; see "On AppBoundry".
|
|
6
|
+
|
|
7
|
+
## Why
|
|
8
|
+
|
|
9
|
+
Some applications need code that is not a function but must run with the application: a telephony gateway
|
|
10
|
+
that receives provider webhooks (form-encoded, provider-signed, at public URLs) and holds a WebSocket per
|
|
11
|
+
call; a bridge to a message bus; a long-lived poller. Before this, such code could only run beside FeltKit in a
|
|
12
|
+
launcher the application wrote itself, and `feltkit build` / `feltkit deploy` did not carry it: a deployment
|
|
13
|
+
served the UI and silently lacked the component (the deployment reported healthy). A deployment that omits a
|
|
14
|
+
required part of the application is not a deployment.
|
|
15
|
+
|
|
16
|
+
## Decision
|
|
17
|
+
|
|
18
|
+
A component is **part of the application**, not a second service:
|
|
19
|
+
|
|
20
|
+
| Concern | Contract |
|
|
21
|
+
|---|---|
|
|
22
|
+
| Declaration | `feltkit({ components: { <name>: { entry, routes, websocket?, required?, principal, credentials?, network? } } })` in `feltkit/app.ts`, validated with the rest of the application (one configuration surface). |
|
|
23
|
+
| Code | `entry` (outside `feltkit/`) default-exports `defineComponent(async (ctx) => instance)` from `@feltdb/feltkit/server`. |
|
|
24
|
+
| Identity | The application's. A component acts only as `component:<name>` or as the principal of one of the application's own `app.agent`s; any other id (a person's, another component's) is refused at definition, build and start. That identity resolves from the declaration (no session to expire). It acts toward the application only by calling its functions (`ctx.call`): roles must be declared; `authorize`, validation and Activity apply. In a tenant it has exactly the membership a tenant manager granted it, resolved on every call, so a removed membership is refused on the next call. It has no database access of its own. |
|
|
25
|
+
| Durable work | A mutation records work for a component in its own transaction: `ctx.afterCommit.work(component, kind, input, { maxAttempts? })`. Nothing exists if the mutation rolls back. The component claims it with `ctx.work.claim({ kinds?, limit?, leaseMs? })` (only its own work; a lease fenced by a version) and settles it with `ctx.work.finish(item, outcome)`: `done` (with a receipt, kept on the record), `retry` (backoff; `failed` after `maxAttempts`, default 5), `failed`, or `unknown` (the effect may have happened: never retried automatically; a person retries it, recorded as theirs). An expired lease makes the item claimable again with `resumed: true`; the earlier performer's settle is refused (CONFLICT). Each item carries the tenant it was recorded in and its provenance (request, function, principal). Work survives restarts (it is a row in `_feltkit_outbox`). Not yet supported in an AppBoundry artifact (refused at the effect). |
|
|
26
|
+
| Secrets | Only the credential ids it declares (`ctx.credential(id)`), from FeltKit's custody (`FELTKIT_CREDENTIAL_<ID>` in production). Never in the artifact. `ctx.model()` gives the environment's selected model and key. `ctx.derive(purpose)` gives stable secret material (HMAC of the app's auth secret). |
|
|
27
|
+
| Routes | Declared HTTP path prefixes on the **application's port** (e.g. `/twilio/`), plus WebSocket upgrades on them when `websocket: true`. They may not overlap FeltKit's own paths or each other. Responses carry `X-FeltKit-Component: <name>`. In development they answer any Host (so a provider can reach them through a tunnel) while FeltKit's own routes stay loopback-only; the component authenticates its own traffic (provider signatures). |
|
|
28
|
+
| Process | Same process as the runtime (FeltDB local state is single-writer per volume). Started after the runtime, stopped before it (`SIGTERM` → `close()`), supervised with the application's process by whatever supervises it (container restart policy, Fly, systemd). No second process to launch after deployment. |
|
|
29
|
+
| Health | `instance.health()` → `{ state: ready \| starting \| unconfigured \| degraded \| failed, detail?, checks? }`. `/_feltkit/health` and `/_feltkit/deployment` include every component. Application `status`: **ready** (200) — runtime and every required component ready; **partial** (503) — runtime ready, a required component not (e.g. `unconfigured`); **unhealthy** (503) — runtime not ready, or a required component `failed`; **starting** (503). Named `checks` let a control plane say *which* part is unavailable (e.g. `webhooks` vs `media`). A component that throws at start is reported `failed` with the reason; the application keeps serving. |
|
|
30
|
+
| Build | `feltkit build` bundles each component to `.feltkit/build/components/<name>.mjs` (dependencies external, installed by the artifact), verifies it loads and default-exports a component, and records `{ name, entry, file, sha256, size, routes, websocket, required, principal, credentials, network }` in `.feltkit/build/manifest.json`. |
|
|
31
|
+
| Deploy | Every `feltkit deploy` target that runs FeltKit carries `.feltkit/build` whole, so the component, its digest and its declaration travel with the functions. The boot check fails (no artifact written) unless each component loaded (`ready` or `unconfigured` with isolated state and no production configuration) **and** its first route reaches it. DEPLOY.md lists components, routes, required credentials (`FELTKIT_CREDENTIAL_<ID>`) and the health semantics. The image's health check is `/_feltkit/health`, so a container whose required component is down is unhealthy. |
|
|
32
|
+
| Rollback | Unchanged per target: start the previous artifact/image on the same state. The component is inside the artifact, so it rolls back with the functions; `/_feltkit/deployment` reports the component digest that runs. |
|
|
33
|
+
|
|
34
|
+
Rejected:
|
|
35
|
+
- **A sidecar process or container per component** (on FeltKit's own targets): a second lifecycle, a second
|
|
36
|
+
health surface and a second set of secrets for one application, and FeltDB local state cannot be shared
|
|
37
|
+
between processes.
|
|
38
|
+
- **A second port**: Cloudflare and Vercel route one port; Caddy, Fly and Docker setups would each need a second
|
|
39
|
+
route; path routing on the one port needs nothing new from any host.
|
|
40
|
+
- **An `inbound_webhook_events` surface only**: it would cover webhooks but not WebSocket media; components
|
|
41
|
+
cover both and leave signature schemes to the application, where they are provider-specific.
|
|
42
|
+
|
|
43
|
+
## Example
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
// feltkit/app.ts
|
|
47
|
+
export const app = feltkit({
|
|
48
|
+
name: "voice-agent",
|
|
49
|
+
roles: { voice: ["voice.ingest", "voice.tools"] /* … */ },
|
|
50
|
+
components: {
|
|
51
|
+
voice: {
|
|
52
|
+
entry: "gateway/component.ts",
|
|
53
|
+
routes: ["/twilio/", "/simulator/"],
|
|
54
|
+
websocket: true,
|
|
55
|
+
required: true,
|
|
56
|
+
principal: { id: "voice-runtime", roles: ["voice"] },
|
|
57
|
+
credentials: ["twilio-auth-token"],
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// gateway/component.ts
|
|
63
|
+
import { defineComponent } from "@feltdb/feltkit/server";
|
|
64
|
+
export default defineComponent(async (ctx) => {
|
|
65
|
+
const voice = await startVoice(ctx); // uses ctx.call / ctx.credential / ctx.model / ctx.derive
|
|
66
|
+
return { request: voice.request, upgrade: voice.upgrade, health: voice.health, close: voice.close };
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## On AppBoundry (`components@1`)
|
|
71
|
+
|
|
72
|
+
An `appboundry.app/1` guest is a WebAssembly module with no network, no secrets, JSON-only routes and no
|
|
73
|
+
WebSocket upgrades — by design: the sandbox is AppBoundry's security boundary. A component therefore cannot run
|
|
74
|
+
*inside* the guest. The AppBoundry extension carries it **beside** the guest, in the same artifact and the same
|
|
75
|
+
deployment, under the same application identity:
|
|
76
|
+
|
|
77
|
+
- Manifest: runtime interface `components@1` and a top-level `components` array: `{ name, kind: "node", entry:
|
|
78
|
+
"components/<name>.mjs", sha256, size, runtime: { node }, routes, websocket, required, principal, credentials,
|
|
79
|
+
network }`. The component file is a self-contained bundle (node built-ins only), its digest bound to the
|
|
80
|
+
artifact id (`sha256(manifest.json)`).
|
|
81
|
+
- The host runs one companion per component with the same context API (`ctx.call` → the guest's functions as
|
|
82
|
+
the declared principal; declared credentials only, mounted from the host's secret store; `derive`), routes
|
|
83
|
+
the declared prefixes (HTTP and WebSocket) to it, and reports per-component health in the deployment
|
|
84
|
+
evidence. A deployment is Running/ready only when every required component is ready.
|
|
85
|
+
- Companion execution is native code outside the sandbox. It is **off by default** and must be enabled
|
|
86
|
+
explicitly on a host; without it a deployment with components fails with a distinct code instead of running
|
|
87
|
+
half an application.
|
|
88
|
+
|
|
89
|
+
`feltkit build --target appboundry` emits this section. Applications that use accounts, tenancy or
|
|
90
|
+
`app.agent` still cannot run on AppBoundry (FK-GAP-013; AppBoundry hosts have neither), whatever their
|
|
91
|
+
components.
|
package/docs/GUARANTEES.md
CHANGED
|
@@ -147,6 +147,11 @@ writes the new one in the mutation's transaction, conditioned on the version it
|
|
|
147
147
|
- Nothing is atomic across FeltDB and external systems.
|
|
148
148
|
- `ctx.unsafe.feltdb` writes are not validated, not transactional with the mutation,
|
|
149
149
|
not attributed to it in the activity log, and invisible to whole-collection fences.
|
|
150
|
+
It reaches only collections the application declares that do not belong to a workspace:
|
|
151
|
+
platform collections (sessions, accounts, memberships, activity, the audit trail, API keys,
|
|
152
|
+
configuration) and workspace collections are refused with `FORBIDDEN`. A transaction id it
|
|
153
|
+
chooses must start with `app_` (other ids are FeltKit's own). Before 0.3.19 it
|
|
154
|
+
reached the whole instance (docs/SECURITY-REMEDIATION.md).
|
|
150
155
|
- File bytes are stored in the same FeltDB instance (`_feltkit_file_content`, with
|
|
151
156
|
their SHA-256, re-hashed on every read) before the file record is committed, so a
|
|
152
157
|
record never points at bytes that were not stored; if the record cannot be committed
|
|
@@ -208,16 +213,50 @@ published contract declares (`appport.integration/1` `failures`). Tests:
|
|
|
208
213
|
|
|
209
214
|
- The change stream requires a session unless the application has a public query.
|
|
210
215
|
- Within one server process, every committed write produces a change notification
|
|
211
|
-
naming its collection, at least once, typically within 150 ms
|
|
212
|
-
|
|
216
|
+
naming its collection, at least once, typically within 150 ms, to every subscriber
|
|
217
|
+
that could see it. Data is always re-read through the authorized query endpoint.
|
|
213
218
|
- After a reconnect, clients re-run every watched query.
|
|
214
|
-
-
|
|
219
|
+
- **Invalidation by predicate (local state).** A query's `reads` lists the collections it
|
|
220
|
+
read, then `collection#key` for each equality predicate of a collection it read only
|
|
221
|
+
through predicates (`get` by id; the equality clauses of `find`, `count`, `query`,
|
|
222
|
+
`search`; of a conjunction, one clause stands for it: `id`, else another keyed field,
|
|
223
|
+
else the tenant field). A change event for a write committed through FeltKit carries,
|
|
224
|
+
per collection, the keys of every changed record's keyed values before and after the
|
|
225
|
+
write. A watched query re-runs when a change's keys meet its predicates, when a
|
|
226
|
+
collection it read wholly changed, or when a change has no keys for a collection it
|
|
227
|
+
read. So inserts, updates (including a record moving out of a predicate) and deletes
|
|
228
|
+
re-run exactly the predicates they touch, and never fewer.
|
|
229
|
+
- **Keyed fields** are `id`, the fields of declared indexes and unique constraints,
|
|
230
|
+
references (`s.ref`) and the tenant field. A read filtering only on other fields counts
|
|
231
|
+
as a whole-collection read. Values of other fields never leave the server in any form.
|
|
232
|
+
- **Keys, not values.** A key is `HMAC-SHA256(K, collection‖field‖value)` (128 bits) with
|
|
233
|
+
K drawn at random per server process and never sent: a client cannot compute a key, only
|
|
234
|
+
compare the ones it is given, so it cannot test guessed values against the stream
|
|
235
|
+
offline. What a key it holds (from one of its own query results) can tell it is that a
|
|
236
|
+
record with that keyed value changed: the timing of changes, which the collection-level
|
|
237
|
+
stream already revealed per collection, now per keyed value.
|
|
238
|
+
- **Tenant isolation of the stream.** For a tenant-scoped collection the server sends a
|
|
239
|
+
change only for records whose tenant (before or after) is the subscriber's session's
|
|
240
|
+
tenant; another tenant's writes are not sent at all. If a change is withheld, the
|
|
241
|
+
session is looked up again (at most every 2 s) and, when it switched tenant, the client
|
|
242
|
+
is told to re-run everything.
|
|
243
|
+
- **When in doubt, re-run.** Writes FeltKit did not commit (`ctx.unsafe.feltdb`, AppPort
|
|
244
|
+
Services' stores, agent state), a description that reached the change feed after its
|
|
245
|
+
journal operation, an unreadable journal, every change on a FeltDB server (whose feed is
|
|
246
|
+
collection markers), and a restart (new key; the client re-runs on reconnect) all fall
|
|
247
|
+
back to per-collection invalidation. Clients that understand only collection names keep
|
|
248
|
+
working unchanged.
|
|
215
249
|
|
|
216
250
|
## Queries
|
|
217
251
|
|
|
218
252
|
- Queries cannot write through `ctx.db`. FeltKit does not sandbox handlers, so a query
|
|
219
253
|
can still make network calls or other side effects; FeltKit does not claim purity.
|
|
220
254
|
- `count` reads all matching records.
|
|
255
|
+
- `search` reads the records matching its equality `where` in pages, in the requested
|
|
256
|
+
order, until `limit` (≤ 100) match: cost is linear in the records matching `where`, not
|
|
257
|
+
in the result. It examines at most 50,000 records and then fails with
|
|
258
|
+
`FAILED_PRECONDITION` rather than answering incompletely. FeltDB has no text index yet
|
|
259
|
+
(docs/UPSTREAM-GAPS.md F23).
|
|
221
260
|
|
|
222
261
|
## Identity
|
|
223
262
|
|
|
@@ -297,6 +336,19 @@ no completion is reported as outcome unknown, never as success or failure. Enabl
|
|
|
297
336
|
the SHA-256 of a link token is stored (`_feltkit_file_links` on the `feltkit.files` handle).
|
|
298
337
|
Links are not revoked when membership changes; they expire.
|
|
299
338
|
|
|
339
|
+
## Accounts, sessions and workspaces
|
|
340
|
+
|
|
341
|
+
Full contract: AUTH.md.
|
|
342
|
+
- **Account sessions are current.** On every request (HTTP, AppPort, MCP) an account session is resolved from the account as it is now, and its workspace from the live membership. A disabled account, a removed membership or a changed role applies on the next request.
|
|
343
|
+
- **Browser sessions** are an HttpOnly cookie. A cookie-authenticated unsafe request needs the session's CSRF token, and a foreign `Origin` is refused. Bearer clients are unchanged.
|
|
344
|
+
- **Account e-mail secrets** are durable challenges: digest-only, at most 15 minutes, single use, superseded, with 5 code attempts and 5 issues per address and purpose per hour. Their tokens are derived with `FELTKIT_AUTH_SECRET` when delivered, and never stored.
|
|
345
|
+
- **Workspace data** (`{ tenant }` collections) is scoped to the session's workspace for every read and write, in FeltKit's runtime and in AppBoundry artifacts. No workspace means closed. A request cannot name another workspace's data into existence.
|
|
346
|
+
- **Workspace roles** are declared `roles`, ranked. Managers assign only below their own rank, nobody raises their own, and a workspace keeps a holder of its top role. Invitations are single use, expire, and are accepted only by the invited, verified address.
|
|
347
|
+
- **Known limits.**
|
|
348
|
+
- Throttling counters are per process, and in memory.
|
|
349
|
+
- Jobs, schedules and agent actions run as their principal without a workspace, so they cannot reach `{ tenant }` collections yet.
|
|
350
|
+
- AppBoundry hosts resolve no workspace (FK-GAP-013).
|
|
351
|
+
|
|
300
352
|
## Agents
|
|
301
353
|
|
|
302
354
|
The FeltKit agent is FeltDB's agent runtime and agent state on the shared instance
|
|
@@ -311,7 +363,7 @@ retry, timeout, cancellation, crashes, restart recovery), and, in a browser,
|
|
|
311
363
|
| Acts only through AppPort | Application capabilities via the application's dispatch pipeline; service operations via AppPort Services' `invoke()` and gateway. No other access to state. |
|
|
312
364
|
| Same authority as every interface | Actions run as the task owner. Before an approval changes anything, the owner is resolved and both the approver and the owner must be permitted to perform the action; otherwise the approval is refused, the reason is recorded in the action's history, and the action stays proposed. If the owner cannot be resolved (no session, not a dev identity), approval fails closed; no identity is substituted. |
|
|
313
365
|
| Approval | Consequential actions (AppPort's and AppPort Services' effect classes) wait for a person (`type: "user"`) who may perform them; agents cannot approve; there is no approve tool. |
|
|
314
|
-
| Mandatory approval | A mutation declared `approval: "required"` cannot be run directly by an agent, service or API key on any interface: FeltKit's HTTP API, AppPort, MCP, a job or schedule it queued. The refusal is `FORBIDDEN` with `details.approval: "required"`, recorded as a denial, before arguments are checked. It runs only inside the execution of an approved action for exactly that capability (an in-process context that no header, envelope field or transport name can set), as the proposer, whose own `access` is still checked, after a person who may perform it approves. The run's activity entry carries `authority.approval` (task, action, approver). People (`type: "user"`) call it directly. Discovery says so: the capability's description, and `feltkit_context` (`approval: "required"`, `invoke: "propose"`). An AppBoundry build refuses it. Tests: `packages/sdk/test/approval-required.test.ts`. |
|
|
366
|
+
| Mandatory approval | A mutation declared `approval: "required"` cannot be run directly by an agent, service or API key on any interface: FeltKit's HTTP API, AppPort, MCP, a job or schedule it queued. The refusal is `FORBIDDEN` with `details.approval: "required"`, recorded as a denial, before arguments are checked. It runs only inside the execution of an approved action for exactly that capability (an in-process context that no header, envelope field or transport name can set), as the proposer, whose own `access` is still checked, after a person who may perform it approves. The run's activity entry carries `authority.approval` (task, action, approver). People (`type: "user"`) call it directly. The check is on the principal type the session carries: an agent that holds a person's session (for example over MCP, which also accepts user sessions) is that person to FeltKit and is not stopped. Discovery says so: the capability's description, and `feltkit_context` (`approval: "required"`, `invoke: "propose"`). An AppBoundry build refuses it. Tests: `packages/sdk/test/approval-required.test.ts`. |
|
|
315
367
|
| One run per approval | Each action state change is a compare-and-swap on the action's record (FeltDB `supersede` with the expected revision). Of concurrent or repeated approvals one wins; the others return the current state and run nothing. |
|
|
316
368
|
| Attribution | Each action records who proposed it, who approved or rejected it, the principal it ran as, the request id, timestamps, the outcome and how it was determined, and a history of every transition with its actor. Agent activity entries carry the owner as principal and the proposer and approver in their detail. |
|
|
317
369
|
| Evidence | Each action's activity record and its final action record are cited by a checkpoint and verified by FeltDB at commit. Pending work is rebuilt from the open actions at every checkpoint. |
|
|
@@ -458,9 +510,10 @@ Intentionally **not available in production**:
|
|
|
458
510
|
would not be preserved (docs/UPSTREAM-GAPS.md).
|
|
459
511
|
- **Selecting a model** (`POST /models`). Production's model is selected on the host
|
|
460
512
|
(`feltkit model set --env production`).
|
|
461
|
-
- Data
|
|
513
|
+
- Data editing, function runs, capability invocation, session management,
|
|
462
514
|
creating, completing, or cancelling agent tasks, "run due work now", and the AppPort
|
|
463
|
-
Services console (its pages need their own origin; upstream gap S7).
|
|
515
|
+
Services console (its pages need their own origin; upstream gap S7). Data browsing
|
|
516
|
+
is served read-only in production.
|
|
464
517
|
|
|
465
518
|
Settling an action whose outcome is unknown (`resolve`) always needs a note. Evidence
|
|
466
519
|
of that exact request (AppPort's idempotency record, the function's activity entry, the
|
|
@@ -476,9 +529,23 @@ explicit environment that differs from `FELTKIT_ENV`. Operator sessions live in
|
|
|
476
529
|
environment's own instance and operator keys are per environment, so neither carries
|
|
477
530
|
across environments. Nothing is copied from development.
|
|
478
531
|
|
|
532
|
+
## Audit trail
|
|
533
|
+
|
|
534
|
+
- One record per committed mutation (`_feltkit_audit`, `runtime.auditTrail()`), written in the
|
|
535
|
+
mutation's own FeltDB transaction: the record and the writes it describes commit together or
|
|
536
|
+
not at all. A mutation that writes nothing, fails, or replays an idempotency key adds none.
|
|
537
|
+
- Attributed: principal, workspace, authorization decision (and the approval for an approved agent
|
|
538
|
+
action), function, interface, request id, FeltDB transaction id, and each write's collection,
|
|
539
|
+
id and operation (never values).
|
|
540
|
+
- Append-only: inserted with `requireAbsent`, never updated or deleted by FeltKit, never trimmed.
|
|
541
|
+
Application code cannot reach it (`ctx.db` and `ctx.unsafe.feltdb` refuse it).
|
|
542
|
+
- Part of the application's state: backups carry it and restore brings it back.
|
|
543
|
+
- Not tamper-evident against whoever operates the FeltDB instance, and refused or failed calls are
|
|
544
|
+
not in it (they are in the activity log).
|
|
545
|
+
|
|
479
546
|
## Activity log
|
|
480
547
|
|
|
481
|
-
- Recorded after the operation; a crash between commit and recording can lose an entry
|
|
548
|
+
- An operational feed, not the audit trail. Recorded after the operation; a crash between commit and recording can lose an entry
|
|
482
549
|
(FeltDB's commit is still durable). Recording failures are surfaced in `inspect` and
|
|
483
550
|
the dashboard, never thrown at callers.
|
|
484
551
|
- Keeps the most recent 2000 entries. Records argument names, never values.
|
package/docs/README.md
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
# FeltKit 0.3.
|
|
1
|
+
# FeltKit 0.3.19 documentation
|
|
2
2
|
|
|
3
3
|
Shipped with `@feltdb/feltkit`. In a project: `node_modules/@feltdb/feltkit/docs/`, or run `npx feltkit docs`.
|
|
4
|
-
Public copy: https://cdn.jsdelivr.net/npm/@feltdb/feltkit@0.3.
|
|
4
|
+
Public copy: https://cdn.jsdelivr.net/npm/@feltdb/feltkit@0.3.19/docs/README.md
|
|
5
5
|
|
|
6
6
|
- [ARCHITECTURE.md](ARCHITECTURE.md): How FeltKit is put together: one FeltDB instance, AppPort, AppPort Services
|
|
7
7
|
- [GUARANTEES.md](GUARANTEES.md): What FeltKit guarantees, and its known limitations
|
|
8
8
|
- [TRANSACTIONS.md](TRANSACTIONS.md): Mutations, ctx.db.sequence and ctx.afterCommit: the transaction contract
|
|
9
9
|
- [SECURITY.md](SECURITY.md): Authorization, sessions, credentials, and production Studio
|
|
10
|
+
- [AUTH.md](AUTH.md): Accounts, sessions, workspaces (tenancy), invitations, and the React sign-in and workspace screens
|
|
10
11
|
- [AGENT-OPERATIONS.md](AGENT-OPERATIONS.md): Agents: MCP, tasks, proposals, approvals, and evidence
|
|
11
12
|
- [RESOLVER.md](RESOLVER.md): Model references: change the model a deployed app uses through Resolver, without a redeploy
|
|
12
13
|
- [PATH-TO-PRODUCTION.md](PATH-TO-PRODUCTION.md): From a local app to production: deploy targets and what you must provide
|
|
13
14
|
- [BACKUP.md](BACKUP.md): Backing up and restoring an environment's state
|
|
15
|
+
- [COMPONENTS.md](COMPONENTS.md): Runtime components: a gateway or worker that runs with the application, as a declared principal
|
|
14
16
|
- [APPBOUNDRY.md](APPBOUNDRY.md): The AppBoundry artifact, deploying through AppBoundry, and the self-hosted runtime
|
|
15
17
|
- [APPBOUNDRY-DEPLOY-CONTRACT.md](APPBOUNDRY-DEPLOY-CONTRACT.md): The deployment contract FeltKit expects from AppBoundry (proposed)
|
|
16
18
|
- [WHY-FELTKIT.md](WHY-FELTKIT.md): Design choices, compared with Convex
|
package/docs/RESOLVER.md
CHANGED
|
@@ -161,7 +161,9 @@ never rewrites a reference name.
|
|
|
161
161
|
- **Managing references from Studio.** Studio shows the reference and its revision. Changes are made
|
|
162
162
|
in Resolver (its CLI or management pages), which owns their authorization and history.
|
|
163
163
|
- **Resolver's own pins.** `@appport/resolver` 0.2.0 pins `@feltdb/core` 0.21.0 and
|
|
164
|
-
`@appport/services` 0.15.0
|
|
165
|
-
versions never mix in the app; the app depends only on
|
|
164
|
+
`@appport/services` 0.15.0; FeltKit itself is on `@appport/services` 0.16.0 and `@appport/sdk` 1.7.0.
|
|
165
|
+
It is a separate service, so the versions never mix in the app; the app depends only on
|
|
166
|
+
`@appport/resolver-client`, whose own `@appport/sdk` 1.6.0 pin the root `package.json` overrides to 1.7.0
|
|
167
|
+
(it imports only the `AppPort` type) until a resolver-client release widens the range. The tests install it the
|
|
166
168
|
same way, outside the workspace (`test/fixtures/resolver-service.mjs`), so FeltKit keeps exactly
|
|
167
169
|
one `@feltdb/core` (the release check).
|
package/docs/SECURITY.md
CHANGED
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
|
|
37
37
|
- No Studio unless `FELTKIT_DASHBOARD=1`. With it, Studio answers only verified operators
|
|
38
38
|
(below) and offers only the operations listed in docs/GUARANTEES.md ("Production
|
|
39
|
-
operations"). Data browsing
|
|
40
|
-
task creation, the services console, and webhook replay are not served.
|
|
39
|
+
operations"). Data browsing is served read-only; data edits, function runs, capability
|
|
40
|
+
invocation, sessions, task creation, the services console, and webhook replay are not served.
|
|
41
41
|
- No development sign-in.
|
|
42
42
|
- Errors from application code are sanitized to `Internal error (request …)`; details
|
|
43
43
|
go to the server log.
|
|
@@ -64,8 +64,9 @@
|
|
|
64
64
|
`feltkit.operations.read`; actions need `feltkit.operations.write` and then whatever
|
|
65
65
|
the operation itself needs (the action's capability permission and `feltkit.agent.write`
|
|
66
66
|
for agent actions; the services' `jobs.retry` for job retry).
|
|
67
|
-
- **Not supported:** OIDC/SAML
|
|
68
|
-
|
|
67
|
+
- **Not supported for Studio operators:** OIDC/SAML sign-in to Studio (an application's own
|
|
68
|
+
users can sign in with Google, GitHub or any OpenID Connect provider: docs/AUTH.md; for Studio use
|
|
69
|
+
the `auth.authenticate` hook with your own verification), operator session listing or
|
|
69
70
|
revocation from Studio (sessions expire; rotating the operator key invalidates unused
|
|
70
71
|
grants, not existing sessions — revoke with `feltkit session revoke` while the server is
|
|
71
72
|
stopped), and MFA.
|