@feltdb/feltkit 0.3.9 → 0.3.11

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.
Files changed (66) hide show
  1. package/dist/app.d.ts +6 -0
  2. package/dist/app.js +22 -2
  3. package/dist/app.js.map +1 -1
  4. package/dist/appboundry/build.js +32 -5
  5. package/dist/appboundry/build.js.map +1 -1
  6. package/dist/appboundry/guest.js +37 -1
  7. package/dist/appboundry/guest.js.map +1 -1
  8. package/dist/appboundry/host.d.ts +25 -0
  9. package/dist/appboundry/host.js +363 -0
  10. package/dist/appboundry/host.js.map +1 -0
  11. package/dist/cli/deploy.d.ts +3 -3
  12. package/dist/cli/deploy.js +56 -6
  13. package/dist/cli/deploy.js.map +1 -1
  14. package/dist/cli/fly.d.ts +20 -0
  15. package/dist/cli/fly.js +120 -0
  16. package/dist/cli/fly.js.map +1 -0
  17. package/dist/cli/main.js +101 -6
  18. package/dist/cli/main.js.map +1 -1
  19. package/dist/cli/skills.d.ts +8 -0
  20. package/dist/cli/skills.js +37 -0
  21. package/dist/cli/skills.js.map +1 -1
  22. package/dist/cli/vercel.d.ts +1 -1
  23. package/dist/cli/vercel.js +3 -3
  24. package/dist/cli/vercel.js.map +1 -1
  25. package/dist/errors.d.ts +7 -1
  26. package/dist/errors.js +1 -0
  27. package/dist/errors.js.map +1 -1
  28. package/dist/index.d.ts +1 -1
  29. package/dist/runtime/capabilities.d.ts +1 -1
  30. package/dist/runtime/capabilities.js +19 -2
  31. package/dist/runtime/capabilities.js.map +1 -1
  32. package/dist/runtime/context.d.ts +7 -0
  33. package/dist/runtime/contract.js +4 -1
  34. package/dist/runtime/contract.js.map +1 -1
  35. package/dist/runtime/data.d.ts +24 -0
  36. package/dist/runtime/data.js +43 -1
  37. package/dist/runtime/data.js.map +1 -1
  38. package/dist/runtime/deployment.d.ts +3 -3
  39. package/dist/runtime/deployment.js +16 -4
  40. package/dist/runtime/deployment.js.map +1 -1
  41. package/dist/runtime/outbox.d.ts +83 -0
  42. package/dist/runtime/outbox.js +92 -0
  43. package/dist/runtime/outbox.js.map +1 -0
  44. package/dist/runtime/runtime.d.ts +7 -1
  45. package/dist/runtime/runtime.js +144 -15
  46. package/dist/runtime/runtime.js.map +1 -1
  47. package/dist/runtime/services.d.ts +8 -0
  48. package/dist/runtime/services.js +47 -1
  49. package/dist/runtime/services.js.map +1 -1
  50. package/dist/runtime/targets.d.ts +9 -5
  51. package/dist/runtime/targets.js +55 -3
  52. package/dist/runtime/targets.js.map +1 -1
  53. package/dist/schema.d.ts +30 -2
  54. package/dist/schema.js +39 -2
  55. package/dist/schema.js.map +1 -1
  56. package/dist/testing/index.d.ts +21 -0
  57. package/dist/testing/index.js +29 -0
  58. package/dist/testing/index.js.map +1 -1
  59. package/package.json +4 -4
  60. package/skills/.claude-plugin/marketplace.json +1 -1
  61. package/skills/.claude-plugin/plugin.json +1 -1
  62. package/skills/feltkit-agent/SKILL.md +1 -1
  63. package/skills/feltkit-build/SKILL.md +29 -1
  64. package/skills/feltkit-data/SKILL.md +1 -1
  65. package/skills/feltkit-operations/SKILL.md +4 -3
  66. package/skills/feltkit-services/SKILL.md +20 -2
@@ -16,6 +16,7 @@ interface. Nothing here grants a permission.
16
16
  ```
17
17
  feltkit/app.ts the application: feltkit({ name, roles, dev, services })
18
18
  feltkit/<module>.ts functions; each export is "<module>:<export>" (tasks.ts list → "tasks:list")
19
+ feltkit/_*.ts helpers shared by function modules (pure business rules); not loaded as functions
19
20
  feltkit/_generated/api.ts generated by `feltkit dev` / `feltkit codegen`; never edit
20
21
  src/ the frontend (Vite + React)
21
22
  tests/*.test.ts run by `feltkit test`
@@ -28,6 +29,10 @@ tests/*.test.ts run by `feltkit test`
28
29
  2. Declare data with `app.collection(name, shape)`; names starting with `_feltkit`, `_flow`, `_feltdb`, `_appport`, and AppPort Services' collections are reserved.
29
30
  3. Write functions with `app.query` / `app.mutation`. Give each an `access` permission (or `"public"` / `"authenticated"`).
30
31
  4. To expose a function to AppPort clients and agents, add `capability: { name: "<noun>.<verb>" }` **and** a `returns` schema.
32
+ Names are lowercase `<namespace>.<operation>`, ASCII letters and digits only: no hyphens, underscores or capitals
33
+ (`exceptions.add-evidence` fails at load; write `exceptions.addevidence` or `evidence.add`). The `returns` schema is
34
+ the published contract and rejects undeclared fields: derive it from the collection with `s.doc(tasks)`, and project
35
+ with `.pick(...)`, `.omit(...)`, `.extend({...})`; never restate a collection's fields in a second schema.
31
36
  5. Grant the permission to roles in `feltkit({ roles })`. Use `npx feltkit dev`; check the dashboard's Capabilities screen.
32
37
  People sign in to a deployed app through built-in accounts, `auth: { accounts: { roles: ["member"] } }` (the starter has it; the frontend calls `useSession().signUp/signIn`), or an identity provider through `auth.authenticate`.
33
38
  Password reset and address verification: `auth.accounts.email: { from, verify? }` (Mailerport; `MAILPORT_URL`/`MAILPORT_API_KEY` in production; the client's `requestPasswordReset`, `resetPassword`, `requestVerification`, `handleRedirect`). Google, GitHub, or OIDC sign-in: `auth.providers` with a `clientId` each and the secret as `credential-ref:<id>-client-secret`; never put a client secret in code. Both need `FELTKIT_PUBLIC_URL` and `FELTKIT_AUTH_SECRET` in production (`feltkit vercel env` sets them).
@@ -52,7 +57,7 @@ import { app, tasks } from "./app.js";
52
57
  export const list = app.query({
53
58
  access: "tasks.read",
54
59
  capability: { name: "tasks.list" },
55
- returns: s.array(s.object({ id: s.string(), title: s.string(), done: s.boolean(), __version: s.number() })),
60
+ returns: s.array(s.doc(tasks)), // the stored record: declared fields + id + __version
56
61
  handler: (ctx) => ctx.db.find(tasks, {}),
57
62
  });
58
63
 
@@ -78,6 +83,18 @@ export const complete = app.mutation({
78
83
  (see the feltkit-services skill), `ctx.environment`, `ctx.requestId`, `ctx.log`. `ctx.unsafe.feltdb` bypasses
79
84
  validation and the transaction: do not use it unless the user asks and understands that.
80
85
 
86
+ - **Errors.** `fail(code, message)`. A valid request the current state does not allow ("only an approved invoice can
87
+ be scheduled") is `FAILED_PRECONDITION`, not `CONFLICT` (a concurrent write) or `INVALID_ARGUMENT`.
88
+ - **Authority first.** A caller without a function's `access` gets `FORBIDDEN` before its arguments are checked. An
89
+ agent that gets `FORBIDDEN` lacks the authority: hand the step to a person; do not retry with other input.
90
+ - **Services run as the caller.** Every role that calls a function needs the service permissions the function uses
91
+ (`ctx.services.configuration.get` in a mutation → `configuration.read` on each calling role).
92
+ - **Effects that announce the change**: `ctx.afterCommit.notifications.send(...)`, `.webhooks.emit(...)`,
93
+ `.jobs.enqueue(...)` happen only if the mutation commits (recorded in its transaction, performed after it).
94
+ `ctx.services.*` effects happen even if the commit is later refused.
95
+ - **Ordering an append-only log** written in the same transaction (audit events): `seq: await ctx.db.sequence("audit")`
96
+ and `orderBy: [{ field: "seq", direction: "asc" }]`. Never order by `Date.now()`: several writes share a millisecond.
97
+
81
98
  ## Existing APIs and model decisions
82
99
 
83
100
  Connect an HTTP API the user already runs as AppPort capabilities (never call `fetch` from a mutation):
@@ -99,6 +116,7 @@ A consequential call whose outcome is unknown is never re-sent; declare `verify`
99
116
  To let the environment's model choose a next step, start a decision from a mutation with the options you allow:
100
117
  `ctx.agent.start({ objective, decision: { question, options: [{ id, label, capability?, input? }] } })`.
101
118
  The choice is a proposal; consequential options wait for a person. See `examples/invoices` in the FeltKit repo.
119
+ `ctx.agent` ties the app to a FeltKit server: an AppBoundry artifact refuses it (see Portability).
102
120
 
103
121
  **Choosing the model and its API key.** The starter enables every AppPort Service (files, notifications,
104
122
  configuration, apiKeys, webhooks, jobs, schedules, intelligence; each configured in Studio → Services → Manage) and
@@ -145,6 +163,16 @@ test("a member completes a task", async () => {
145
163
 
146
164
  Each test app gets an isolated FeltDB instance. Test denials too (`app.as("viewer")` should be refused writes).
147
165
 
166
+ ## Portability (AppBoundry)
167
+
168
+ `npx feltkit build --target appboundry` compiles the app into `<name>.app` (runs without the project or FeltKit). It
169
+ refuses, naming file and line: `ctx.agent`, `ctx.unsafe`, `ctx.afterCommit`, `ctx.db.sequence`, `app.integration`,
170
+ `auth.authenticate`, Node built-ins, and locale-dependent code (`Intl`, `toLocaleString`, `localeCompare`: the
171
+ artifact has no locale data; format for people in the frontend). It omits Studio, `/mcp`, API keys, schedules and
172
+ webhook delivery. A plain `feltkit build` prints the same list as a warning. If the user wants the artifact, avoid
173
+ these from the start, and test it with `createArtifactTestApp("<name>.app")` from `@feltdb/feltkit/testing` (same
174
+ `as(who).query/mutation` calls). No npm release of AppBoundry runs the format yet; it is built from its repository.
175
+
148
176
  ## When to stop and ask
149
177
 
150
178
  - Changing roles or `access` (it changes who can do what everywhere, including agents and API keys).
@@ -76,4 +76,4 @@ Deleting records, bulk changes, schema changes that drop fields, or anything in
76
76
 
77
77
  ## Compatibility
78
78
 
79
- `@feltdb/feltkit` 0.1.x on `@feltdb/core` 0.13.0. Details: the project's `docs/GUARANTEES.md`. Verified in Claude Code only.
79
+ `@feltdb/feltkit` 0.3.x on `@feltdb/core` 0.18.0. Details: the project's `docs/GUARANTEES.md`. Verified in Claude Code only.
@@ -77,8 +77,9 @@ the API keys page (Studio → Services → Manage). Production API keys need `FE
77
77
  For a deployment whose data is in FeltDB (Vercel, `--target hosted|self-hosted`), run `--env production` commands in
78
78
  the project's folder: they read the deployment's FeltDB settings from `.env.local` and refuse when they are missing
79
79
  (never fall back to `.feltkit/production/state`, which the deployment does not read). Nothing needs to stop.
80
- `npx feltkit vercel deploy` and `npx feltkit cloudflare deploy` sign the owner in on their first production deploy
81
- (Cloudflare needs Docker running locally and the Workers Paid plan); `npx feltkit manage` prints a
80
+ `npx feltkit vercel deploy`, `npx feltkit cloudflare deploy` and `npx feltkit fly deploy` sign the owner in on their first
81
+ production deploy (Cloudflare needs Docker running locally and the Workers Paid plan; Fly needs flyctl, and with the
82
+ default `--data volume` the state is on the Fly volume, so sign in through the Studio link it prints); `npx feltkit manage` prints a
82
83
  one-time link to production Studio (`/_feltkit/`, on by default for Vercel).
83
84
 
84
85
  ## Recover
@@ -94,4 +95,4 @@ Anything in production; deleting or restoring state; revoking sessions or keys;
94
95
 
95
96
  ## Compatibility
96
97
 
97
- `@feltdb/feltkit` 0.1.x. Verified in Claude Code only.
98
+ `@feltdb/feltkit` 0.3.x. Verified in Claude Code only.
@@ -48,7 +48,25 @@ export const checkout = app.mutation({
48
48
  });
49
49
  ```
50
50
 
51
- Service effects commit on their own: they are not part of the mutation's transaction.
51
+ **Service calls inside functions run as the caller.** Every role that can reach a function needs the service
52
+ permissions that function uses: if `checkout` reads `configuration.get`, every role that calls `checkout` needs
53
+ `configuration.read`. A refusal says so: `orders:checkout called configuration.get as grace (roles: clerk), which does
54
+ not grant configuration.read`, with the file to change (`feltkit/app.ts`, roles).
55
+
56
+ Service effects commit on their own: they are not part of the mutation's transaction. A notification or webhook
57
+ sent from `ctx.services` stays sent if the mutation later fails at commit (`CONFLICT`). For effects that announce the
58
+ mutation's change, use `ctx.afterCommit`:
59
+
60
+ ```ts
61
+ ctx.afterCommit.notifications.send({ recipient: "ada", type: "order", title: "Paid" }); // only if this commits
62
+ ctx.afterCommit.webhooks.emit("order.paid", { orderId });
63
+ ctx.afterCommit.jobs.enqueue("invoice.send", { orderId });
64
+ ```
65
+
66
+ Each is recorded in the mutation's transaction (`_feltkit_outbox`) and performed after the commit, as the caller.
67
+ If the process stops in between, the services worker performs it later (at least once; notifications are
68
+ deduplicated by their idempotency key, jobs and webhook events may repeat). An AppBoundry artifact refuses
69
+ `ctx.afterCommit`.
52
70
 
53
71
  ## Configure a service
54
72
 
@@ -119,6 +137,6 @@ affect other systems. Confirm with the user before doing any of them.
119
137
 
120
138
  ## Compatibility
121
139
 
122
- `@feltdb/feltkit` 0.3.x with `@appport/services` 0.9.1 (shared instance; `credential.store` / `credential.status`; `servicesContract` for Managed FeltDB).
140
+ `@feltdb/feltkit` 0.3.x with `@appport/services` 0.13.0 (shared instance; `credential.store` / `credential.status`; `servicesContract` for Managed FeltDB).
123
141
  The console is development-only.
124
142
  Verified in Claude Code only.