@feltdb/feltkit 0.3.30 → 0.3.31
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 +27 -9
- package/dist/app.js +36 -2
- package/dist/app.js.map +1 -1
- package/dist/appboundry/build.js +2 -0
- package/dist/appboundry/build.js.map +1 -1
- package/dist/appboundry/guest.js +23 -1
- package/dist/appboundry/guest.js.map +1 -1
- package/dist/authorize.d.ts +24 -3
- package/dist/authorize.js.map +1 -1
- package/dist/docs.d.ts +1 -1
- package/dist/docs.js +1 -0
- package/dist/docs.js.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/policy.d.ts +172 -0
- package/dist/policy.js +311 -0
- package/dist/policy.js.map +1 -0
- package/dist/runtime/activity.d.ts +16 -0
- package/dist/runtime/activity.js.map +1 -1
- package/dist/runtime/application-authority.d.ts +20 -1
- package/dist/runtime/application-authority.js +60 -12
- package/dist/runtime/application-authority.js.map +1 -1
- package/dist/runtime/assemble.d.ts +13 -0
- package/dist/runtime/assemble.js +29 -1
- package/dist/runtime/assemble.js.map +1 -1
- package/dist/runtime/content.d.ts +50 -0
- package/dist/runtime/content.js +98 -1
- package/dist/runtime/content.js.map +1 -1
- package/dist/runtime/context.d.ts +62 -11
- package/dist/runtime/contract.js +11 -2
- package/dist/runtime/contract.js.map +1 -1
- package/dist/runtime/data.d.ts +25 -0
- package/dist/runtime/data.js +92 -8
- package/dist/runtime/data.js.map +1 -1
- package/dist/runtime/image-variants.d.ts +48 -0
- package/dist/runtime/image-variants.js +295 -0
- package/dist/runtime/image-variants.js.map +1 -0
- package/dist/runtime/integrations.js +1 -3
- package/dist/runtime/integrations.js.map +1 -1
- package/dist/runtime/live.d.ts +10 -7
- package/dist/runtime/live.js +24 -12
- package/dist/runtime/live.js.map +1 -1
- package/dist/runtime/local-authority.d.ts +47 -5
- package/dist/runtime/local-authority.js +195 -13
- package/dist/runtime/local-authority.js.map +1 -1
- package/dist/runtime/policies.d.ts +89 -0
- package/dist/runtime/policies.js +152 -0
- package/dist/runtime/policies.js.map +1 -0
- package/dist/runtime/runtime.d.ts +19 -1
- package/dist/runtime/runtime.js +192 -4
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/runtime/services-rules.d.ts +9 -0
- package/dist/runtime/services-rules.js +47 -1
- package/dist/runtime/services-rules.js.map +1 -1
- package/dist/runtime/services.d.ts +117 -9
- package/dist/runtime/services.js +154 -13
- package/dist/runtime/services.js.map +1 -1
- package/dist/server/admin.d.ts +21 -0
- package/dist/server/admin.js +114 -0
- package/dist/server/admin.js.map +1 -1
- package/dist/server/index.js +33 -6
- package/dist/server/index.js.map +1 -1
- package/dist/server/operators.d.ts +1 -0
- package/dist/server/operators.js +1 -1
- package/dist/server/operators.js.map +1 -1
- package/dist/testing/index.d.ts +11 -0
- package/dist/testing/index.js +7 -0
- package/dist/testing/index.js.map +1 -1
- package/docs/AGENT-OPERATIONS.md +1 -1
- package/docs/ARCHITECTURE.md +2 -1
- package/docs/GUARANTEES.md +80 -6
- package/docs/POLICIES.md +121 -0
- package/docs/README.md +3 -2
- package/docs/SECURITY.md +30 -0
- package/docs/TRANSACTIONS.md +4 -0
- package/package.json +11 -7
- package/skills/.claude-plugin/marketplace.json +1 -1
- package/skills/.claude-plugin/plugin.json +1 -1
- package/skills/feltkit-services/SKILL.md +1 -1
package/docs/GUARANTEES.md
CHANGED
|
@@ -69,6 +69,7 @@ this inside its commit lock; a failed check rejects the whole transaction with
|
|
|
69
69
|
| `get(id)` | `ifVersion` / `requireAbsent` precondition on that record | The record changed, appeared, or was deleted |
|
|
70
70
|
| `find(filter)`, `count(filter)` with at least one field | FeltDB read basis on the equality predicate, captured before the read | Any matching record changed, appeared (phantom), disappeared, or stopped matching — by any writer |
|
|
71
71
|
| `query({ where })` with some `eq` clauses | Read basis on the `eq` clauses only (range clauses dropped) | Same as above, for a superset of the read: may report conflicts the range would have excluded, never misses one |
|
|
72
|
+
| `query({ where })` with an `in` clause (non-empty) | One read basis per distinct value: that value as an equality, with the read's `eq` clauses (a second `in` is dropped) | Any record whose field is in the set changed, appeared or disappeared; a write outside the set does not conflict. An empty `in` is checked as a read without it |
|
|
72
73
|
| `find()`/`count()` with no filter, or `query` with only range clauses | The collection's change marker (`_feltkit_collections`), touched by every commit made through `ctx.db` or the dashboard | Any commit to the collection through FeltKit. **Not** writes made through `ctx.unsafe.feltdb`. |
|
|
73
74
|
| Records the mutation wrote | `ifVersion` on updates and deletes, at the version the mutation **first read** (a `get` before the `patch`); `requireAbsent` on inserts | Lost updates, including a change committed between the handler's read and its write |
|
|
74
75
|
|
|
@@ -155,7 +156,7 @@ writes the new one in the mutation's transaction, conditioned on the version it
|
|
|
155
156
|
- File bytes are stored in the same FeltDB instance (`_feltkit_file_content`, with
|
|
156
157
|
their SHA-256, re-hashed on every read) before the file record is committed, so a
|
|
157
158
|
record never points at bytes that were not stored; if the record cannot be committed
|
|
158
|
-
the bytes are removed. Deleting a file removes its bytes. FeltDB 0.15's content store
|
|
159
|
+
the bytes are removed. Deleting a file removes its bytes and the image variants derived from them. FeltDB 0.15's content store
|
|
159
160
|
is not used: it cannot delete content, and the memory runtime has none (UPSTREAM-GAPS
|
|
160
161
|
F6, F8, F9).
|
|
161
162
|
- Files are capped at 1 MiB by default (`services.files.maxBytes`).
|
|
@@ -225,7 +226,10 @@ published contract declares (`appport.integration/1` `failures`). Tests:
|
|
|
225
226
|
write. A watched query re-runs when a change's keys meet its predicates, when a
|
|
226
227
|
collection it read wholly changed, or when a change has no keys for a collection it
|
|
227
228
|
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
|
+
re-run exactly the predicates they touch, and never fewer. A set membership (`in`) on a
|
|
230
|
+
keyed field is one predicate per value (preferred after an equality on `id` or another
|
|
231
|
+
keyed field, before the tenant field), so a change to a record in the set re-runs the
|
|
232
|
+
query and one outside it does not.
|
|
229
233
|
- **Keyed fields** are `id`, the fields of declared indexes and unique constraints,
|
|
230
234
|
references (`s.ref`) and the tenant field. A read filtering only on other fields counts
|
|
231
235
|
as a whole-collection read. Values of other fields never leave the server in any form.
|
|
@@ -252,6 +256,17 @@ published contract declares (`appport.integration/1` `failures`). Tests:
|
|
|
252
256
|
- Queries cannot write through `ctx.db`. FeltKit does not sandbox handlers, so a query
|
|
253
257
|
can still make network calls or other side effects; FeltKit does not claim purity.
|
|
254
258
|
- `count` reads all matching records.
|
|
259
|
+
- **Set membership** (`where: [{ field, in: [...] }]`, FRAME-GAP-05): at most 256 strings, finite numbers,
|
|
260
|
+
booleans or nulls, with `eq`'s equality; an empty list matches nothing; checked before FeltDB sees it
|
|
261
|
+
(`INVALID_ARGUMENT`). A FeltDB without `in` (0.21.0 and before) is `FAILED_PRECONDITION`, never a wrong
|
|
262
|
+
answer. A cursor continues only the same set. Inside a mutation, pending writes are matched too.
|
|
263
|
+
- **Index directions** (`indexes: [{ fields, directions }]`): FeltDB's state contract declares index fields
|
|
264
|
+
only (ascending), so FeltKit also declares an index with a `desc` direction to an embedded FeltDB (local,
|
|
265
|
+
memory) as `<name>_ordered`, at start and reload (idempotent; durable across restarts). With
|
|
266
|
+
`{ fields: ["authorId", "createdAt"], directions: ["asc", "desc"] }`, `where authorId in [...] orderBy
|
|
267
|
+
createdAt desc` is an index merge: a page examines about `limit + 1` records, whatever the authors have
|
|
268
|
+
written (`test/membership-query.test.ts`, by `explain` and `plan.recordsExamined`). A FeltDB server serves
|
|
269
|
+
`in` as a predicate (same results; cost as an unindexed predicate).
|
|
255
270
|
- `search` reads the records matching its equality `where` in pages, in the requested
|
|
256
271
|
order, until `limit` (≤ 100) match: cost is linear in the records matching `where`, not
|
|
257
272
|
in the result. It examines at most 50,000 records and then fails with
|
|
@@ -323,8 +338,8 @@ no completion is reported as outcome unknown, never as success or failure. Enabl
|
|
|
323
338
|
|
|
324
339
|
| Service | What runs | Verified (packages/sdk/test) |
|
|
325
340
|
|---|---|---|
|
|
326
|
-
| Files | records with audit; bytes in the same instance | persistence, authorization, upload/read/delete, restart (`services`) |
|
|
327
|
-
| Notifications | in-app channel, delivered inline; recipient-only | persistence, delivery, recipient-only access, restart (`services`) |
|
|
341
|
+
| Files | records with audit; bytes in the same instance; links (cacheable on request), image variants | persistence, authorization, upload/read/delete, restart (`services`); links (`file-links`); cacheable links and variants (`file-cache-variants`) |
|
|
342
|
+
| Notifications | in-app channel, delivered inline; recipient-only; inbox paging (`page`, `unreadCount`, `markAllRead`) on the recipient timeline index | persistence, delivery, recipient-only access, restart (`services`); paging, cursors bound to the walk, counts, mark-all-read as the caller, the contract's indexes (`notification-paging`) |
|
|
328
343
|
| Configuration | variables and credential references for the running environment | persistence, environment separation; the console page edits the environment the application reads (`services`, `console`) |
|
|
329
344
|
| API keys | created, rotated, revoked on the package's page; accepted on `/appport` and `/mcp` with `services.apiKeys.roles` | secret shown once, never listed, revocation → 401, survives restart (`console`) |
|
|
330
345
|
| Webhooks | signed delivery to registered endpoints; history | signed with the environment's secret, delivered as the emitter, secret in no record or log (`console`) |
|
|
@@ -349,6 +364,14 @@ no completion is reported as outcome unknown, never as success or failure. Enabl
|
|
|
349
364
|
- FeltKit is single-tenant per application: the Services tenant is the application
|
|
350
365
|
name. Configuration environments map `development`/`test` → `development`,
|
|
351
366
|
`production` → `production`.
|
|
367
|
+
- **Notification inbox** (`ctx.services.notifications.page / unreadCount / markAllRead`, FRAME-GAP-08):
|
|
368
|
+
AppPort Services' `inbox`, `unreadCount` and `markAllRead`, as the caller, for the caller's own
|
|
369
|
+
notifications. Pages are newest first (`createdAt` desc, `id` asc) from the
|
|
370
|
+
`notifications_by_recipient(_type)` indexes (in FeltKit's contract with Services' contract version 4):
|
|
371
|
+
a page reads about `limit` records. A cursor works only for the walk that issued it. With `unread` a page
|
|
372
|
+
may be short or empty and still carry `nextCursor`. `unreadCount` stops at `max` (`complete: false`).
|
|
373
|
+
`markAllRead` marks at most 1,000 per call, each as `markRead` does, and is not atomic. A Services
|
|
374
|
+
release without them: `FAILED_PRECONDITION` naming it. Artifacts: `UNAVAILABLE`.
|
|
352
375
|
- Files belong to the workspace they were uploaded in (`metadata["feltkit.tenant"]`, set by
|
|
353
376
|
FeltKit): a caller with `files.read` reads the files of its own workspace, or, working in none,
|
|
354
377
|
those uploaded in none; any other is NOT_FOUND. Per-resource access is the application's: a function checks the resource
|
|
@@ -357,7 +380,57 @@ no completion is reported as outcome unknown, never as success or failure. Enabl
|
|
|
357
380
|
until then. Upload links are single use, create the file as the issuing principal (the role
|
|
358
381
|
snapshot taken at issue), with the metadata the function fixed, and within its `maxBytes`. Only
|
|
359
382
|
the SHA-256 of a link token is stored (`_feltkit_file_links` on the `feltkit.files` handle).
|
|
360
|
-
Links are not revoked when membership changes; they expire.
|
|
383
|
+
Links are not revoked when membership changes; they expire. A link serves only the content it was
|
|
384
|
+
issued for: if the record comes to name other bytes (another checksum), the link is refused.
|
|
385
|
+
- **Cacheable file links** (`files.link(id, { cache: true })`, opt-in; FRAME-GAP-01). By default a
|
|
386
|
+
download is `Cache-Control: private, no-store` and every call is a new URL. With `cache`:
|
|
387
|
+
- **Same URL in a window.** Time is cut into windows of half the link's lifetime
|
|
388
|
+
(`expiresInSeconds`, default 3600 with `cache`, at most 3600). Within one window, the same caller
|
|
389
|
+
(principal and workspace) asking for the same file, content (checksum and storage key), variant and
|
|
390
|
+
disposition gets the same URL; `stableUntil` says when the next call will be a new one. Each URL
|
|
391
|
+
lives until the end of the following window, so it is issued with at least half its lifetime left
|
|
392
|
+
and never lives longer than asked (`expiresAt`).
|
|
393
|
+
- **No cross-principal reuse.** The token is HMAC-SHA256, under a random per-process key that is never
|
|
394
|
+
stored, of that scope; another principal (or the same person in another workspace) gets another URL.
|
|
395
|
+
Nothing a URL contains is derived from the bytes alone, so identical bytes in two workspaces never
|
|
396
|
+
share an address. Only the token's digest is stored, as for every link. A restart changes the key:
|
|
397
|
+
URLs issued after it are new (one more download each), never weaker.
|
|
398
|
+
- **Headers.** `Cache-Control: private, max-age=<seconds until expiresAt>, immutable` and a strong
|
|
399
|
+
`ETag` (the SHA-256 of the bytes served). `If-None-Match` answers `304` only after the link was
|
|
400
|
+
redeemed (valid, unexpired, the file still exists with the same content). `private`: never a
|
|
401
|
+
shared cache.
|
|
402
|
+
- **The tradeoff, bounded.** A copy a browser already holds is shown until its `max-age` runs out,
|
|
403
|
+
even if the file is removed or the caller loses access meanwhile: at most `expiresInSeconds`
|
|
404
|
+
(≤ 1 hour) after the link was issued. New downloads through the link stop at once (removed file,
|
|
405
|
+
changed content, expiry: `404`). Use the default (`no-store`) for content whose access must end
|
|
406
|
+
the moment it is revoked, or a shorter `expiresInSeconds`.
|
|
407
|
+
- **Image variants** (`services.files.variants`, `files.link(id, { variant })`; FRAME-GAP-06).
|
|
408
|
+
- **Declared, fixed set.** `variants: { w640: { width: 640 }, avatar64: { width: 64, height: 64, fit:
|
|
409
|
+
"cover" } }`: `width`/`height` 1-4096, `fit` `inside` (default: fits the box) or `cover` (fills it,
|
|
410
|
+
centre-cropped), `format` `auto` (default: PNG when the result has transparency, else JPEG), `jpeg` or
|
|
411
|
+
`png`, `quality` 1-100 (JPEG, default 80). Checked when the application is declared. Never upscaled.
|
|
412
|
+
A link names a declared variant or is refused (`INVALID_ARGUMENT`).
|
|
413
|
+
- **Authorized exactly as the original.** A variant is reachable only through a link to its file, issued
|
|
414
|
+
by `files.link` after the same checks (`files.read`, the file's workspace, the application's own
|
|
415
|
+
check); it is never a file record of its own.
|
|
416
|
+
- **Derived once,** on the first download through a variant link (concurrent first downloads in a process
|
|
417
|
+
derive once), and kept as derived content in `_feltkit_file_variants`, keyed by the original's storage
|
|
418
|
+
key and the variant's name, with a digest of its spec and codec (a changed declaration derives it again)
|
|
419
|
+
and the SHA-256 of its bytes (verified on every read).
|
|
420
|
+
- **Removed with the original's bytes.** The recorded byte release of `files.remove` (above) removes every
|
|
421
|
+
variant of the bytes it releases (`{ released: true, variantsReleased }`), also when an earlier attempt
|
|
422
|
+
already removed the bytes; a variant derived while its bytes were being released is removed by the
|
|
423
|
+
derivation itself.
|
|
424
|
+
- **Never silent.** JPEG (EXIF orientation applied) and PNG are resized. Any other format, an image over
|
|
425
|
+
`services.files.maxVariantPixels` (default 24,000,000, checked from the header before decoding),
|
|
426
|
+
bytes that do not decode, or an image already within the variant are served as the original:
|
|
427
|
+
`X-FeltKit-Variant: original` and `X-FeltKit-Variant-Reason: …` on the download, and the link's
|
|
428
|
+
`variant: { status: "original", reason }` once known (`pending` before the first download, `ready`
|
|
429
|
+
with `width`, `height`, `contentType` after). A served variant is `X-FeltKit-Variant: <name>`.
|
|
430
|
+
- **Costs.** Codecs are pure JavaScript (`jpeg-js`, `pngjs`): the first download of each file and
|
|
431
|
+
variant decodes on the server's event loop (roughly 50-150 ms per megapixel).
|
|
432
|
+
- **AppBoundry artifacts:** `files.link` (variants and cacheable links included) is refused
|
|
433
|
+
(`UNAVAILABLE`), as before; `feltkit build --target appboundry` warns that variants are not served.
|
|
361
434
|
- **Removing a file does not strand its bytes, and does not release bytes another live file uses,**
|
|
362
435
|
except in one documented window (below: a reference made the instant after the removal, and a
|
|
363
436
|
stop before the bytes are put back), which is recorded, not hidden. A file is
|
|
@@ -614,7 +687,8 @@ across environments. Nothing is copied from development.
|
|
|
614
687
|
|
|
615
688
|
| Primitive | Guarantee | Verified by |
|
|
616
689
|
|---|---|---|
|
|
617
|
-
| `ctx.authority.decide({ capability, onBehalfOf?, resource?, context? })` | AuthBoundry through the same `authBoundryAuthority` the platform uses. The asking principal is always `feltkit({ authority }).executor`; `onBehalfOf` names the requester, and an allow for it must echo that requester and a `delegation_id`. Fails closed (unconfigured, unreachable, slow, malformed, inexact, missing credential). Credentials are custody references resolved per decision; each decision is in the activity log with its ids, never a credential | `test/application-platform.test.ts` |
|
|
690
|
+
| `ctx.authority.decide({ capability, onBehalfOf?, agent?, resource?, context? })` | AuthBoundry through the same `authBoundryAuthority` the platform uses. The asking principal is always `feltkit({ authority }).executor`; `onBehalfOf` names the requester, and an allow for it must echo that requester and a `delegation_id`. `onBehalfOf` is mapped as `ctx.authority.grants` maps the delegator (FRAME-GAP-11): an application principal id (no `:`, e.g. `"ada"`) goes through `authority.principal` (default `user:<id>`); an AuthBoundry principal (`<type>:<id>`, e.g. `"user:ada"`) is sent unchanged; `{ person }` always maps and `{ principal }` never does, for ids that break that rule. The decision's `onBehalfOf` is the principal asked about. Fails closed (unconfigured, unreachable, slow, malformed, inexact, missing credential). Credentials are custody references resolved per decision; each decision is in the activity log with its ids, never a credential | `test/application-platform.test.ts`, `test/local-authority.test.ts` (both forms against a real local AuthBoundry) |
|
|
691
|
+
| Per-agent delegation (`authority.local`) | Every `app.agent` is an AuthBoundry agent of the application (`agent:<id>`), registered at each start with its own credential in custody; agents registered at run time (`ctx.authority.agents.register`, needs `feltkit.authority.agents`, never by an agent) are registered again too. A grant may name an agent (`grants.grant({ agent })`) and then allows only that agent. **An agent caller decides as itself, always**, with its own credential: a grant to another agent or to the executor never allows it, and naming another agent is a deny. Anyone else decides as the executor unless it names a registered agent. An unregistered agent is a deny. Revoking a grant stops that grant only; revoking an agent stops all of its grants. With a hosted AuthBoundry, agent callers decide as the executor (no per-agent credentials) | `test/local-authority.test.ts` (real local AuthBoundry) |
|
|
618
692
|
| `ctx.integrations.invoke(capability, input)` | A declared integration operation from application code, as the caller, under the operation's own `access`; the input is validated against the operation's declared schema before anything is sent (`INVALID_ARGUMENT`), as AppPort validates a capability call; its credential resolved for the request only; the call recorded before and after; never in results, records or errors; rotation applies to the next call; a removed credential fails the call | `test/application-platform.test.ts` |
|
|
619
693
|
| The agent's catalog (`ctx.agent.catalog()` in actions, `runtime.agent.tools(principal)`; `ctx.agent.tools()` is its allowed subset, shaped as model tools) | Every capability the application and its services offer, not a model's tool list: for each, whether this principal may use it (`allowed`, the policy's decision) and how (`invoke`); for an integration operation, its `integration`, its input schema, and `readiness` (not ready while the base URL or the credential's value is missing, with what to fix; never a value). Permission and readiness are separate answers | `test/application-platform.test.ts` |
|
|
620
694
|
| Integration exposure (`expose: false`, per operation or integration) | The operation is not an AppPort capability: no session can call it on `/appport`, whatever it holds; application code still can, under `access`. A `verify` probe must stay exposed (verification runs it through AppPort), checked when the app is defined | `test/application-platform.test.ts` |
|
package/docs/POLICIES.md
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# Policies
|
|
2
|
+
|
|
3
|
+
FeltKit decides who may call a function in layers. Every layer must allow, and the first refusal
|
|
4
|
+
wins. All of them run at the one execution boundary every interface goes through: HTTP functions,
|
|
5
|
+
AppPort capabilities, MCP tools, agent actions, jobs, approved actions, and AppBoundry artifacts.
|
|
6
|
+
|
|
7
|
+
| Order | Layer | Declared with | Decides |
|
|
8
|
+
|---|---|---|---|
|
|
9
|
+
| 1 | Roles | `roles` and each function's `access` | May this caller call this function at all? Checked before the arguments are read. |
|
|
10
|
+
| 2 | Approval | `approval: "required"` | A non-person caller needs a person's approval for this exact action. |
|
|
11
|
+
| 3 | Ownership | `owner` on the function | The record named by an argument belongs to the caller. |
|
|
12
|
+
| 4 | **Policies** | `app.policy(rule)`, plus managed versions | Owner, shared-with, record state, input, role, tenant role, agent delegation. |
|
|
13
|
+
| 5 | Hook | `feltkit({ authorize })` | Anything else, in code. It sees the policy decision. |
|
|
14
|
+
|
|
15
|
+
Evaluation is deterministic. No model takes part in any decision. Delegated authority is decided by
|
|
16
|
+
AuthBoundry, the owner of delegation, whose decision id is kept as evidence.
|
|
17
|
+
|
|
18
|
+
## Declaring policies
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { app, docs } from "./app.js";
|
|
22
|
+
import * as d from "./docs.js";
|
|
23
|
+
|
|
24
|
+
app.policy({
|
|
25
|
+
id: "docs.read.owner-or-shared",
|
|
26
|
+
effect: "allow",
|
|
27
|
+
functions: [d.read], // definitions, not strings: renaming breaks the import
|
|
28
|
+
resource: { collection: docs, id: "docId" }, // the record, loaded by the "docId" argument
|
|
29
|
+
when: [{ any: [{ owner: "ownerId" }, { sharedWith: "sharedWith" }, { role: "admin" }] }],
|
|
30
|
+
});
|
|
31
|
+
app.policy({ id: "docs.remove.kept", description: "published documents are kept", effect: "deny",
|
|
32
|
+
functions: [d.remove], resource: { collection: docs, id: "docId" }, when: [{ field: "status", eq: "published" }] });
|
|
33
|
+
app.policy({ id: "refund.small", effect: "allow", functions: [refund], principals: { roles: ["member"] },
|
|
34
|
+
resource: { collection: invoices, id: "invoiceId" }, when: [{ owner: "ownerId" }, { arg: "amount", gt: 0, lte: 100 }],
|
|
35
|
+
evidence: "durable" });
|
|
36
|
+
app.policy({ id: "docs.publish.delegated", effect: "allow", functions: [d.publish], principals: { types: ["agent", "service"] },
|
|
37
|
+
resource: { collection: docs, id: "docId" }, when: [{ delegated: { capability: "docs.publish", onBehalfOf: { field: "ownerId" } } }] });
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Conditions:
|
|
41
|
+
|
|
42
|
+
| Condition | Holds when |
|
|
43
|
+
|---|---|
|
|
44
|
+
| `{ owner: "<field>" }` | the resource's field is the caller's id |
|
|
45
|
+
| `{ owner: "<field>", via: { collection, field } }` | the resource's field references a record whose `field` is the caller's id (e.g. `createdBy` → `participants.principalId`) |
|
|
46
|
+
| `{ sharedWith: "<field>" }` | the resource's field is a list containing the caller's id |
|
|
47
|
+
| `{ field: "<f>", eq / ne / in / notIn / lt / lte / gt / gte }` | the resource's field compares as given |
|
|
48
|
+
| `{ arg: "<a>", …same operators }` | the validated argument compares as given |
|
|
49
|
+
| `{ role: r \| [r…] }` | the caller holds the application role |
|
|
50
|
+
| `{ tenantRole: r \| [r…] }` | the caller's role in their current workspace is one of these |
|
|
51
|
+
| `{ delegated: { capability, onBehalfOf: { field, via? } \| { arg } } }` | the caller is an agent or service, and AuthBoundry allows the application's executor to exercise `capability` for that person (a delegation that exists, is in force, and covers it) |
|
|
52
|
+
| `{ any: [...] }`, `{ not: c }` | composition |
|
|
53
|
+
|
|
54
|
+
`principals` limits which callers a rule applies to: `types`, `roles`, and `anonymous: true`.
|
|
55
|
+
|
|
56
|
+
## Semantics
|
|
57
|
+
|
|
58
|
+
- **Deny overrides.** If an applicable deny rule's conditions all hold, the call is refused, whatever else allows it.
|
|
59
|
+
- **Deny by default once governed.** A function named by any allow rule runs only if an applicable
|
|
60
|
+
allow rule's conditions all hold. A function no policy names is decided by the other layers only.
|
|
61
|
+
- **Unevaluable means not held.** A missing record, a missing field, or an authority that cannot be
|
|
62
|
+
reached never allows. A deny rule that depends on it does not apply. So an unreachable AuthBoundry
|
|
63
|
+
refuses a delegated call.
|
|
64
|
+
- A person acts with their own authority. A `delegated` condition never holds for a `user` principal.
|
|
65
|
+
- A refusal is `FORBIDDEN` (`UNAUTHORIZED` for an anonymous caller). Its details name the deny rule
|
|
66
|
+
that `matched`, or each allow rule's first `unmet` condition.
|
|
67
|
+
|
|
68
|
+
## Managed policies: changed without a redeploy
|
|
69
|
+
|
|
70
|
+
A managed version is a complete, immutable set of rules stored in the application's own FeltDB. The
|
|
71
|
+
active version applies on top of the code policies. It adds rules and cannot remove a code rule.
|
|
72
|
+
Activating, or deactivating, takes effect on the next call in every process: the active pointer is
|
|
73
|
+
read for each decision (compare-and-swap writes, cached only by its record version).
|
|
74
|
+
|
|
75
|
+
Managed rules name functions as `"<module>:<export>"`, and may also name an integration operation
|
|
76
|
+
by its capability (`"registry.lookup"`). Every rule is validated against the deployed project when
|
|
77
|
+
it is stored and again when it is activated. A rule that names a missing function or collection is
|
|
78
|
+
refused.
|
|
79
|
+
|
|
80
|
+
| Route (admin API) | Development | Production |
|
|
81
|
+
|---|---|---|
|
|
82
|
+
| `GET /policies`, `/policies/versions`, `/policies/history`, `GET /decisions` | admin token | `feltkit.operations.read` |
|
|
83
|
+
| `POST /policies/simulate` `{ function, principal, args }` | admin token | `feltkit.operations.read` |
|
|
84
|
+
| `POST /policies/versions` `{ rules, note? }` | admin token | **`feltkit.policies.manage`** |
|
|
85
|
+
| `POST /policies/active` `{ version: n \| null }` | admin token | **`feltkit.policies.manage`** |
|
|
86
|
+
|
|
87
|
+
Changing policy changes who may do what, so production requires its own permission, separate from
|
|
88
|
+
`feltkit.operations.write`. History records the signed-in operator, and a client-chosen `by` is refused.
|
|
89
|
+
|
|
90
|
+
## Simulation and evidence
|
|
91
|
+
|
|
92
|
+
- `runtime.simulatePolicy({ function, principal, args })`, or `POST /policies/simulate`, runs the
|
|
93
|
+
policies in force against the real records. Nothing runs and nothing is recorded.
|
|
94
|
+
- Decision evidence (`_feltkit_decisions`, append-only) records:
|
|
95
|
+
- every refusal, from any layer (role, approval, ownership, policy or hook) and for signed-in callers;
|
|
96
|
+
- every allow of a rule marked `evidence: "durable"`.
|
|
97
|
+
|
|
98
|
+
Each record names the layer, the policy version (`code:<digest>[+managed:<n>]`), the matched and
|
|
99
|
+
unmet rules, AuthBoundry's delegation decisions, and the argument names. It never holds argument
|
|
100
|
+
values. A durable allow whose record cannot be written does not run.
|
|
101
|
+
- The activity log carries the policy decision too (`authority.policy`).
|
|
102
|
+
|
|
103
|
+
## Integration operations
|
|
104
|
+
|
|
105
|
+
An integration operation reaches the same managed policies and hook (`kind: "integration"`), whether
|
|
106
|
+
it is called through its AppPort/MCP capability or through `ctx.integrations.invoke`. A refused call
|
|
107
|
+
never reaches the remote API.
|
|
108
|
+
|
|
109
|
+
## Testing
|
|
110
|
+
|
|
111
|
+
`createTestApp()` exposes `app.policies.simulate(fn, who, args)`, `app.policies.decisions(filter)`,
|
|
112
|
+
and `app.policies.store` (create and activate managed versions).
|
|
113
|
+
|
|
114
|
+
## Limits (current)
|
|
115
|
+
|
|
116
|
+
- **AppBoundry artifacts** enforce the code policies they carry, with the same evaluator.
|
|
117
|
+
- Managed versions live in the host's FeltDB and are not part of `appboundry-guest/1`, so an
|
|
118
|
+
artifact does not apply them.
|
|
119
|
+
- A `delegated` condition has no authority to ask in the guest, so it does not hold there.
|
|
120
|
+
- Code policies cannot name integration operations: managed rules can.
|
|
121
|
+
- Managed versions add rules. Removing a code rule needs a deploy.
|
package/docs/README.md
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
# FeltKit 0.3.
|
|
1
|
+
# FeltKit 0.3.31 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.31/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
10
|
- [AUTH.md](AUTH.md): Accounts, sessions, workspaces (tenancy), invitations, and the React sign-in and workspace screens
|
|
11
|
+
- [POLICIES.md](POLICIES.md): Declarative policies (owner, sharing, state, input, roles, delegation), managed versions without a redeploy, simulation, decision evidence
|
|
11
12
|
- [EXTENSION-HOSTS.md](EXTENSION-HOSTS.md): Running the app in a browser extension: ownership, token storage, session end, lifecycle, gaps
|
|
12
13
|
- [INVOCATIONS.md](INVOCATIONS.md): Surfaces and invocations: registering entry points, the feltkit.invocation/1 contract, the durable lifecycle, dispatch and recovery
|
|
13
14
|
- [EXECUTION.md](EXECUTION.md): Placement-neutral execution: the control plane and execution environments, the execution contract, adapters, placement, authority and evidence
|
package/docs/SECURITY.md
CHANGED
|
@@ -112,6 +112,11 @@ Every entry point was exercised by `packages/sdk/test/auth.test.ts`.
|
|
|
112
112
|
|
|
113
113
|
### Credentials and API keys
|
|
114
114
|
|
|
115
|
+
- **Agent credentials (local authority).** Each registered agent's AuthBoundry credential is kept in
|
|
116
|
+
custody (`credential-ref:authboundry-local-agent:<agent>`), resolved only for that agent's decisions,
|
|
117
|
+
never recorded, logged or returned. An agent caller can decide only as itself; registering agents needs
|
|
118
|
+
`feltkit.authority.agents` and is refused to agents (docs/LOCAL-AUTHORITY.md).
|
|
119
|
+
|
|
115
120
|
- Service credentials are references (`credential-ref:<id>`) resolved only inside the
|
|
116
121
|
effect that needs them, from `FELTKIT_CREDENTIAL_<ID>` when it is set, else (development
|
|
117
122
|
and test) from the environment's encrypted vault. Studio shows whether each reference is
|
|
@@ -163,6 +168,28 @@ Every entry point was exercised by `packages/sdk/test/auth.test.ts`.
|
|
|
163
168
|
`integrations.test.ts` (discovery without authority, no credential in records),
|
|
164
169
|
`platform.test.ts` (production routes).
|
|
165
170
|
|
|
171
|
+
## File links
|
|
172
|
+
|
|
173
|
+
- A file link is a capability: holding it downloads that file until it expires (≤ 1 hour). The function
|
|
174
|
+
that issues it authorizes the resource first; the route reads no session, so links work as `<img src>`.
|
|
175
|
+
Only the SHA-256 of a token is stored.
|
|
176
|
+
- **Default:** `Cache-Control: private, no-store`, a new URL every call.
|
|
177
|
+
- **Cacheable links (`cache: true`, opt-in):** `private, max-age=<remaining>, immutable`, ETag/304.
|
|
178
|
+
- Tokens are HMAC-SHA256 of { file, content, variant, disposition, principal, workspace, window } under a
|
|
179
|
+
random per-process key that is never stored. Another principal never receives the same URL, and no
|
|
180
|
+
URL is derived from the bytes alone, so identical bytes in two workspaces never share an address.
|
|
181
|
+
- **Accepted risk:** a browser that already downloaded a file keeps showing its copy until `max-age`
|
|
182
|
+
runs out (at most the link's `expiresInSeconds`, ≤ 1 hour), after a removal or a loss of access.
|
|
183
|
+
`private` keeps it out of shared caches; new downloads through the link stop at once.
|
|
184
|
+
- A link serves only the content it was issued for: a record that comes to name other bytes refuses it.
|
|
185
|
+
- **Image variants** are served only through a link to their original, so they are authorized exactly as
|
|
186
|
+
it is. Decoding untrusted images: the format is sniffed from the bytes (never the declared type), the
|
|
187
|
+
pixel count is checked from the header before decoding (`services.files.maxVariantPixels`), the JPEG
|
|
188
|
+
decoder runs with its own resolution and memory limits, and anything that fails is served as the
|
|
189
|
+
original, saying so. The codecs are pure JavaScript (no native code). Every download, variant or not,
|
|
190
|
+
keeps `Content-Security-Policy: …; sandbox`; reasons in `X-FeltKit-Variant-Reason` are FeltKit's own
|
|
191
|
+
text, reduced to printable ASCII.
|
|
192
|
+
|
|
166
193
|
## Known gaps
|
|
167
194
|
|
|
168
195
|
- No rate limiting on FeltKit's own endpoints. Put a reverse proxy in front of
|
|
@@ -179,5 +206,8 @@ Every entry point was exercised by `packages/sdk/test/auth.test.ts`.
|
|
|
179
206
|
- Production operator sessions cannot be listed or revoked from Studio; there is no MFA
|
|
180
207
|
and no external identity-provider integration beyond the `auth.authenticate` hook.
|
|
181
208
|
- Production Studio has no rate limiting of its own, like every FeltKit endpoint.
|
|
209
|
+
- The first download of an image variant decodes on the server's event loop. With a large
|
|
210
|
+
`maxVariantPixels`, many first downloads at once slow other requests; the default (24 MP) and the files
|
|
211
|
+
byte cap (1 MiB by default) bound it.
|
|
182
212
|
|
|
183
213
|
Report vulnerabilities privately to the repository owner.
|
package/docs/TRANSACTIONS.md
CHANGED
|
@@ -251,6 +251,10 @@ export const assistant = app.agent("assistant", {
|
|
|
251
251
|
if (text.includes("@assistant")) ctx.afterCommit.agent("assistant", { roomId });
|
|
252
252
|
```
|
|
253
253
|
|
|
254
|
+
An agent's handler that asks AuthBoundry (`ctx.authority.decide`) decides **as the agent**, with its
|
|
255
|
+
own credential, when the application uses a local authority (docs/LOCAL-AUTHORITY.md, "Several agents"):
|
|
256
|
+
only a person's grant to that agent allows it, never a grant to the executor or to another agent.
|
|
257
|
+
|
|
254
258
|
### Triggers, and why these two
|
|
255
259
|
|
|
256
260
|
- **`ctx.afterCommit.agent(name, input)`** is the general one. The application decides, in the
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@feltdb/feltkit",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.31",
|
|
4
4
|
"description": "FeltKit: one application, one FeltDB instance, one developer experience. SDK, runtime, CLI, and dashboard.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -54,19 +54,21 @@
|
|
|
54
54
|
"prepack": "npm run build"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@appport/authorization": "1.
|
|
57
|
+
"@appport/authorization": "1.2.0",
|
|
58
58
|
"@appport/integration": "1.2.5",
|
|
59
59
|
"@appport/protocol": "1.5.0",
|
|
60
60
|
"@appport/resolver-client": "0.3.0",
|
|
61
61
|
"@appport/schema": "1.1.6",
|
|
62
|
-
"@appport/sdk": "1.
|
|
63
|
-
"@appport/server": "1.3.
|
|
64
|
-
"@appport/services": ">=0.
|
|
62
|
+
"@appport/sdk": "1.9.0",
|
|
63
|
+
"@appport/server": "1.3.3",
|
|
64
|
+
"@appport/services": ">=0.19.0 <1.0.0",
|
|
65
65
|
"@feltdb/core": ">=0.21.0 <1.0.0",
|
|
66
|
-
"create-feltkit": "0.3.
|
|
66
|
+
"create-feltkit": "0.3.31",
|
|
67
67
|
"esbuild": "0.28.2",
|
|
68
68
|
"express": "4.22.3",
|
|
69
|
+
"jpeg-js": "0.4.4",
|
|
69
70
|
"mailerport": ">=0.1.0 <1.0.0",
|
|
71
|
+
"pngjs": "7.0.0",
|
|
70
72
|
"tsx": "4.23.15"
|
|
71
73
|
},
|
|
72
74
|
"peerDependencies": {
|
|
@@ -86,7 +88,8 @@
|
|
|
86
88
|
}
|
|
87
89
|
},
|
|
88
90
|
"devDependencies": {
|
|
89
|
-
"@appport/testing": "1.2.
|
|
91
|
+
"@appport/testing": "1.2.6",
|
|
92
|
+
"@authboundry/local": "0.1.0",
|
|
90
93
|
"@mailerport/service": "0.1.0",
|
|
91
94
|
"@feltdb/webllm": ">=0.20.0 <1.0.0",
|
|
92
95
|
"@modelcontextprotocol/sdk": "1.32.2",
|
|
@@ -94,6 +97,7 @@
|
|
|
94
97
|
"@stack-ui/react": "0.9.0",
|
|
95
98
|
"@stack-ui/tokens": "0.9.0",
|
|
96
99
|
"@types/node": "22.19.1",
|
|
100
|
+
"@types/pngjs": "6.0.5",
|
|
97
101
|
"@types/react": "19.3.0",
|
|
98
102
|
"@types/react-dom": "19.3.0",
|
|
99
103
|
"@vitejs/plugin-react": "5.1.0",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://anthropic.com/claude-code/plugin.schema.json",
|
|
3
3
|
"name": "feltkit",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.31",
|
|
5
5
|
"description": "Skills for building and operating FeltKit applications: project structure and SDK, AppPort Services, FeltDB data and consistency, the FeltKit agent over MCP, and operations. Guidance only: they grant no permission.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "FeltKit"
|
|
@@ -143,6 +143,6 @@ affect other systems. Confirm with the user before doing any of them.
|
|
|
143
143
|
|
|
144
144
|
## Compatibility
|
|
145
145
|
|
|
146
|
-
`@feltdb/feltkit` 0.3.x with `@appport/services` 0.
|
|
146
|
+
`@feltdb/feltkit` 0.3.x with `@appport/services` 0.19.0 (shared instance; transactional job and webhook creation; `credential.store` / `credential.status`; `servicesContract` for Managed FeltDB; the inbound event lifecycle and inbound integration management).
|
|
147
147
|
The console is development-only.
|
|
148
148
|
Verified in Claude Code only.
|