@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
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How a browser holds its FeltKit session: an HttpOnly cookie, never script-readable storage.
|
|
3
|
+
*
|
|
4
|
+
* cookie `__Host-fk_session` (Secure, Path=/, no Domain) on HTTPS; `fk_session` on plain-HTTP
|
|
5
|
+
* development. HttpOnly, SameSite=Lax. Its value is the same opaque `fks_` session token a
|
|
6
|
+
* bearer client holds; only its digest is stored (runtime/sessions.ts).
|
|
7
|
+
* CSRF a cookie-authenticated unsafe request (anything but GET/HEAD) must send
|
|
8
|
+
* `X-FeltKit-CSRF`: an HMAC of the session's digest under the auth secret, given to the page
|
|
9
|
+
* by `GET /api/session`. A cross-site page cannot read it, and cannot send a custom header
|
|
10
|
+
* without a CORS preflight, which FeltKit never grants. A foreign `Origin` is refused too.
|
|
11
|
+
* bearer `Authorization: Bearer` (CLI, services, API keys, server-to-server) is unchanged, needs
|
|
12
|
+
* no CSRF token (it is not an ambient credential), and wins over a cookie.
|
|
13
|
+
* proxies `auth.session.trustProxy` = how many reverse proxies in front of the server append to
|
|
14
|
+
* X-Forwarded-For / set X-Forwarded-Proto. 0 (the default) trusts neither header.
|
|
15
|
+
*/
|
|
16
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
17
|
+
export declare const SECURE_COOKIE = "__Host-fk_session";
|
|
18
|
+
export declare const DEV_COOKIE = "fk_session";
|
|
19
|
+
export declare const CSRF_HEADER = "x-feltkit-csrf";
|
|
20
|
+
/** A client asking for its session as a cookie (the browser client) instead of a token in the body. */
|
|
21
|
+
export declare const SESSION_MODE_HEADER = "x-feltkit-session";
|
|
22
|
+
export interface SessionHttpOptions {
|
|
23
|
+
/** "auto" (default): Secure in production, and whenever the request arrived over HTTPS. */
|
|
24
|
+
cookie?: "auto" | "secure" | "insecure";
|
|
25
|
+
/** Number of trusted reverse proxies in front of the server. Default 0. */
|
|
26
|
+
trustProxy?: number;
|
|
27
|
+
}
|
|
28
|
+
export declare function parseCookies(request: IncomingMessage): Record<string, string>;
|
|
29
|
+
/** The session token a cookie carries, if any. */
|
|
30
|
+
export declare function cookieToken(request: IncomingMessage): string | undefined;
|
|
31
|
+
/** The client address: the socket's, or with trusted proxies the address the outermost trusted proxy saw. */
|
|
32
|
+
export declare function clientAddress(request: IncomingMessage, options: SessionHttpOptions): string;
|
|
33
|
+
/** Whether the request reached the client side over HTTPS (directly, or as a trusted proxy says). */
|
|
34
|
+
export declare function isHttps(request: IncomingMessage, options: SessionHttpOptions): boolean;
|
|
35
|
+
/** Set the session cookie. `expiresAt` makes it persistent for the session's lifetime. */
|
|
36
|
+
export declare function setSessionCookie(response: ServerResponse, request: IncomingMessage, token: string, expiresAt: string | undefined, options: SessionHttpOptions, production: boolean): void;
|
|
37
|
+
export declare function clearSessionCookie(response: ServerResponse): void;
|
|
38
|
+
/** The CSRF token for a session: bound to it, useless for any other, never stored. */
|
|
39
|
+
export declare function csrfToken(secret: string, sessionToken: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* Refuse a cookie-authenticated request that could have been made by another site: an unsafe method
|
|
42
|
+
* without the session's CSRF token, or any request whose Origin is not this server's.
|
|
43
|
+
*/
|
|
44
|
+
export declare function checkCookieRequest(request: IncomingMessage, sessionToken: string, secret: string, options?: {
|
|
45
|
+
token?: boolean;
|
|
46
|
+
}): void;
|
|
47
|
+
/** Whether the client asked for a cookie session (the browser client sends this on sign-in). */
|
|
48
|
+
export declare function wantsCookie(request: IncomingMessage): boolean;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { createHash, createHmac, timingSafeEqual } from "node:crypto";
|
|
2
|
+
import { FeltKitError } from "../errors.js";
|
|
3
|
+
export const SECURE_COOKIE = "__Host-fk_session";
|
|
4
|
+
export const DEV_COOKIE = "fk_session";
|
|
5
|
+
export const CSRF_HEADER = "x-feltkit-csrf";
|
|
6
|
+
/** A client asking for its session as a cookie (the browser client) instead of a token in the body. */
|
|
7
|
+
export const SESSION_MODE_HEADER = "x-feltkit-session";
|
|
8
|
+
export function parseCookies(request) {
|
|
9
|
+
const header = request.headers.cookie;
|
|
10
|
+
const out = {};
|
|
11
|
+
if (typeof header !== "string")
|
|
12
|
+
return out;
|
|
13
|
+
for (const part of header.split(";")) {
|
|
14
|
+
const index = part.indexOf("=");
|
|
15
|
+
if (index < 1)
|
|
16
|
+
continue;
|
|
17
|
+
const name = part.slice(0, index).trim();
|
|
18
|
+
if (!(name in out))
|
|
19
|
+
out[name] = decodeURIComponent(part.slice(index + 1).trim());
|
|
20
|
+
}
|
|
21
|
+
return out;
|
|
22
|
+
}
|
|
23
|
+
/** The session token a cookie carries, if any. */
|
|
24
|
+
export function cookieToken(request) {
|
|
25
|
+
const cookies = parseCookies(request);
|
|
26
|
+
const token = cookies[SECURE_COOKIE] ?? cookies[DEV_COOKIE];
|
|
27
|
+
return token && token.startsWith("fks_") && token.length <= 128 ? token : undefined;
|
|
28
|
+
}
|
|
29
|
+
function trustedHops(options) {
|
|
30
|
+
const hops = options.trustProxy ?? 0;
|
|
31
|
+
return Number.isInteger(hops) && hops > 0 ? hops : 0;
|
|
32
|
+
}
|
|
33
|
+
/** The client address: the socket's, or with trusted proxies the address the outermost trusted proxy saw. */
|
|
34
|
+
export function clientAddress(request, options) {
|
|
35
|
+
const hops = trustedHops(options);
|
|
36
|
+
const socket = request.socket?.remoteAddress ?? "unknown";
|
|
37
|
+
if (!hops)
|
|
38
|
+
return socket;
|
|
39
|
+
const header = request.headers["x-forwarded-for"];
|
|
40
|
+
const chain = (Array.isArray(header) ? header.join(",") : header ?? "").split(",").map((s) => s.trim()).filter(Boolean);
|
|
41
|
+
// Each trusted proxy appends the address it received from; the last `hops` entries are theirs to vouch for.
|
|
42
|
+
return chain.length >= hops ? chain[chain.length - hops] : chain[0] ?? socket;
|
|
43
|
+
}
|
|
44
|
+
/** Whether the request reached the client side over HTTPS (directly, or as a trusted proxy says). */
|
|
45
|
+
export function isHttps(request, options) {
|
|
46
|
+
if (request.socket.encrypted)
|
|
47
|
+
return true;
|
|
48
|
+
if (!trustedHops(options))
|
|
49
|
+
return false;
|
|
50
|
+
const proto = request.headers["x-forwarded-proto"];
|
|
51
|
+
return String(Array.isArray(proto) ? proto[0] : proto ?? "").split(",")[0].trim().toLowerCase() === "https";
|
|
52
|
+
}
|
|
53
|
+
function secureCookie(request, options, production) {
|
|
54
|
+
if (options.cookie === "secure")
|
|
55
|
+
return true;
|
|
56
|
+
if (options.cookie === "insecure")
|
|
57
|
+
return false;
|
|
58
|
+
return production || isHttps(request, options);
|
|
59
|
+
}
|
|
60
|
+
/** Set the session cookie. `expiresAt` makes it persistent for the session's lifetime. */
|
|
61
|
+
export function setSessionCookie(response, request, token, expiresAt, options, production) {
|
|
62
|
+
const secure = secureCookie(request, options, production);
|
|
63
|
+
const name = secure ? SECURE_COOKIE : DEV_COOKIE;
|
|
64
|
+
const maxAge = expiresAt ? Math.max(0, Math.floor((Date.parse(expiresAt) - Date.now()) / 1000)) : undefined;
|
|
65
|
+
const cookie = [`${name}=${encodeURIComponent(token)}`, "Path=/", "HttpOnly", "SameSite=Lax", ...(secure ? ["Secure"] : []), ...(maxAge !== undefined ? [`Max-Age=${maxAge}`] : [])].join("; ");
|
|
66
|
+
// Clear the other name, so a switch between HTTP and HTTPS never leaves two sessions behind.
|
|
67
|
+
const other = secure ? `${DEV_COOKIE}=; Path=/; HttpOnly; SameSite=Lax; Max-Age=0` : null;
|
|
68
|
+
appendCookies(response, other ? [cookie, other] : [cookie]);
|
|
69
|
+
}
|
|
70
|
+
export function clearSessionCookie(response) {
|
|
71
|
+
appendCookies(response, [`${SECURE_COOKIE}=; Path=/; HttpOnly; SameSite=Lax; Secure; Max-Age=0`, `${DEV_COOKIE}=; Path=/; HttpOnly; SameSite=Lax; Max-Age=0`]);
|
|
72
|
+
}
|
|
73
|
+
function appendCookies(response, cookies) {
|
|
74
|
+
const existing = response.getHeader("Set-Cookie");
|
|
75
|
+
const list = existing === undefined ? [] : Array.isArray(existing) ? existing.map(String) : [String(existing)];
|
|
76
|
+
response.setHeader("Set-Cookie", [...list, ...cookies]);
|
|
77
|
+
}
|
|
78
|
+
/** The CSRF token for a session: bound to it, useless for any other, never stored. */
|
|
79
|
+
export function csrfToken(secret, sessionToken) {
|
|
80
|
+
const digest = createHash("sha256").update(sessionToken).digest("hex");
|
|
81
|
+
return createHmac("sha256", secret).update(`feltkit.csrf.v1\n${digest}`).digest("base64url");
|
|
82
|
+
}
|
|
83
|
+
const SAFE = new Set(["GET", "HEAD", "OPTIONS"]);
|
|
84
|
+
/**
|
|
85
|
+
* Refuse a cookie-authenticated request that could have been made by another site: an unsafe method
|
|
86
|
+
* without the session's CSRF token, or any request whose Origin is not this server's.
|
|
87
|
+
*/
|
|
88
|
+
export function checkCookieRequest(request, sessionToken, secret, options = {}) {
|
|
89
|
+
const origin = request.headers.origin;
|
|
90
|
+
if (typeof origin === "string" && origin !== "null") {
|
|
91
|
+
let host;
|
|
92
|
+
try {
|
|
93
|
+
host = new URL(origin).host;
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
host = "";
|
|
97
|
+
}
|
|
98
|
+
if (host !== request.headers.host)
|
|
99
|
+
throw new FeltKitError("FORBIDDEN", "Cross-site request refused.", { hint: "CSRF" });
|
|
100
|
+
}
|
|
101
|
+
else if (origin === "null") {
|
|
102
|
+
throw new FeltKitError("FORBIDDEN", "Cross-site request refused.", { hint: "CSRF" });
|
|
103
|
+
}
|
|
104
|
+
if (SAFE.has(request.method ?? "GET") || options.token === false)
|
|
105
|
+
return;
|
|
106
|
+
const given = request.headers[CSRF_HEADER];
|
|
107
|
+
const expected = csrfToken(secret, sessionToken);
|
|
108
|
+
if (typeof given !== "string" || given.length !== expected.length || !timingSafeEqual(Buffer.from(given), Buffer.from(expected))) {
|
|
109
|
+
throw new FeltKitError("FORBIDDEN", "This request is missing its CSRF token. Reload the page and try again.", { hint: "CSRF" });
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/** Whether the client asked for a cookie session (the browser client sends this on sign-in). */
|
|
113
|
+
export function wantsCookie(request) {
|
|
114
|
+
return String(request.headers[SESSION_MODE_HEADER] ?? "").toLowerCase() === "cookie";
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=session-http.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-http.js","sourceRoot":"","sources":["../../src/server/session-http.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,MAAM,CAAC,MAAM,aAAa,GAAG,mBAAmB,CAAC;AACjD,MAAM,CAAC,MAAM,UAAU,GAAG,YAAY,CAAC;AACvC,MAAM,CAAC,MAAM,WAAW,GAAG,gBAAgB,CAAC;AAC5C,uGAAuG;AACvG,MAAM,CAAC,MAAM,mBAAmB,GAAG,mBAAmB,CAAC;AASvD,MAAM,UAAU,YAAY,CAAC,OAAwB;IACnD,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC;IACtC,MAAM,GAAG,GAA2B,EAAE,CAAC;IACvC,IAAI,OAAO,MAAM,KAAK,QAAQ;QAAE,OAAO,GAAG,CAAC;IAC3C,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QACrC,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAChC,IAAI,KAAK,GAAG,CAAC;YAAE,SAAS;QACxB,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;QACzC,IAAI,CAAC,CAAC,IAAI,IAAI,GAAG,CAAC;YAAE,GAAG,CAAC,IAAI,CAAC,GAAG,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAA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AAW,EAAE,6BAA6B,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;IAC1H,CAAC;SAAM,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;QAC7B,MAAM,IAAI,YAAY,CAAC,WAAW,EAAE,6BAA6B,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;IACvF,CAAC;IACD,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,IAAI,KAAK,CAAC,IAAI,OAAO,CAAC,KAAK,KAAK,KAAK;QAAE,OAAO;IACzE,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAC3C,MAAM,QAAQ,GAAG,SAAS,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACjD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,KAAK,QAAQ,CAAC,MAAM,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC;QACjI,MAAM,IAAI,YAAY,CAAC,WAAW,EAAE,wEAAwE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;IAClI,CAAC;AACH,CAAC;AAED,gGAAgG;AAChG,MAAM,UAAU,WAAW,CAAC,OAAwB;IAClD,OAAO,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,mBAAmB,CAAC,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,KAAK,QAAQ,CAAC;AACvF,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tenancy over HTTP (`auth.tenant`): your tenants, switching, members, invitations.
|
|
3
|
+
*
|
|
4
|
+
* GET /api/tenants mine, the current one, and the app's tenancy settings
|
|
5
|
+
* POST /api/tenants { name } create one (you hold its top role) and work in it
|
|
6
|
+
* POST /api/tenants/switch { tenantId } work in another of yours (or { tenantId: null }: none)
|
|
7
|
+
* GET /api/tenants/current/members
|
|
8
|
+
* POST /api/tenants/current/members/role { principalId, role } tenant.members.manage
|
|
9
|
+
* POST /api/tenants/current/members/claims { principalId, claims } tenant.members.manage
|
|
10
|
+
* POST /api/tenants/current/members/remove { principalId } tenant.members.manage
|
|
11
|
+
* POST /api/tenants/current/members/add { principalId, role } tenant.members.manage (agents and services only)
|
|
12
|
+
* POST /api/tenants/current/leave
|
|
13
|
+
* POST /api/tenants/current/rename { name } tenant.update
|
|
14
|
+
* GET /api/tenants/current/invitations tenant.members.manage
|
|
15
|
+
* POST /api/tenants/current/invitations { email, role, claims?, send? } tenant.members.manage
|
|
16
|
+
* POST /api/tenants/current/invitations/revoke { id } tenant.members.manage
|
|
17
|
+
* POST /api/invitations/preview { token } what a link is for (its holder only)
|
|
18
|
+
* POST /api/invitations/accept { token } join, and work in the tenant
|
|
19
|
+
*
|
|
20
|
+
* The tenant is always the session's (resolved from the live membership): a tenant id in a request
|
|
21
|
+
* body is only ever a request to switch, which is checked against your memberships. Switching,
|
|
22
|
+
* creating, leaving and accepting rotate the session (a new token; the old one ends).
|
|
23
|
+
*/
|
|
24
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
25
|
+
import type { FeltKitRuntime } from "../runtime/runtime.js";
|
|
26
|
+
import { type Principal } from "../runtime/authority.js";
|
|
27
|
+
export interface TenancyHttp {
|
|
28
|
+
runtime: FeltKitRuntime;
|
|
29
|
+
identify(request: IncomingMessage): Promise<{
|
|
30
|
+
principal: Principal | null;
|
|
31
|
+
token?: string;
|
|
32
|
+
}>;
|
|
33
|
+
sendSession(request: IncomingMessage, response: ServerResponse, status: number, issued: {
|
|
34
|
+
token: string;
|
|
35
|
+
principal: Principal;
|
|
36
|
+
expiresAt?: string;
|
|
37
|
+
}, extra?: Record<string, unknown>): void;
|
|
38
|
+
}
|
|
39
|
+
/** Handle a tenancy route; false when the path is not one. */
|
|
40
|
+
export declare function handleTenancy(http: TenancyHttp, request: IncomingMessage, response: ServerResponse, pathname: string): Promise<boolean>;
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { grantsPermission } from "@appport/authorization";
|
|
2
|
+
import { FeltKitError } from "../errors.js";
|
|
3
|
+
import { fromAppPortPrincipal } from "../runtime/authority.js";
|
|
4
|
+
import { MANAGE_MEMBERS, UPDATE_TENANT } from "../runtime/tenancy.js";
|
|
5
|
+
import { normalizeEmail } from "../runtime/accounts.js";
|
|
6
|
+
import { readJSON, sendJSON } from "./http.js";
|
|
7
|
+
/** Handle a tenancy route; false when the path is not one. */
|
|
8
|
+
export async function handleTenancy(http, request, response, pathname) {
|
|
9
|
+
if (!pathname.startsWith("/api/tenants") && !pathname.startsWith("/api/invitations/"))
|
|
10
|
+
return false;
|
|
11
|
+
const { runtime } = http;
|
|
12
|
+
const tenancy = runtime.tenancy;
|
|
13
|
+
if (!tenancy)
|
|
14
|
+
throw new FeltKitError("NOT_FOUND", "This app has no tenants (auth.tenant).");
|
|
15
|
+
const method = request.method ?? "GET";
|
|
16
|
+
const word = tenancy.config.name ?? "workspace";
|
|
17
|
+
// An invitation link's holder may see what it is for before signing in.
|
|
18
|
+
if (pathname === "/api/invitations/preview" && method === "POST") {
|
|
19
|
+
const body = await readJSON(request);
|
|
20
|
+
return done(response, 200, { ok: true, invitation: await tenancy.preview(body.token) });
|
|
21
|
+
}
|
|
22
|
+
const { principal, token } = await http.identify(request);
|
|
23
|
+
if (!principal || !token)
|
|
24
|
+
throw new FeltKitError("UNAUTHORIZED", `Sign in to use your ${word}s.`);
|
|
25
|
+
/** Replace this session with one working in `tenantId` (or none): a new token, the old one ends. */
|
|
26
|
+
const rotate = async (tenantId, status = 200, extra = {}) => {
|
|
27
|
+
const session = await runtime.sessions.get(token);
|
|
28
|
+
const base = fromAppPortPrincipal(session?.principal);
|
|
29
|
+
const attributes = (session?.attributes ?? {});
|
|
30
|
+
if (!session || !base)
|
|
31
|
+
throw new FeltKitError("UNAUTHORIZED", "The session ended. Sign in again.");
|
|
32
|
+
if (tenantId)
|
|
33
|
+
await tenancy.touch(tenantId, base.id);
|
|
34
|
+
const issued = await runtime.issueSession(base, {
|
|
35
|
+
kind: typeof attributes.kind === "string" ? attributes.kind : "session",
|
|
36
|
+
...(typeof attributes.label === "string" ? { label: attributes.label } : {}),
|
|
37
|
+
...(session.expiresAt ? { ttlMs: Math.max(60_000, Date.parse(session.expiresAt) - Date.now()) } : {}),
|
|
38
|
+
via: "http",
|
|
39
|
+
tenantId,
|
|
40
|
+
});
|
|
41
|
+
await runtime.sessions.delete(token);
|
|
42
|
+
http.sendSession(request, response, status, issued, { tenant: issued.principal.tenant ?? null, ...extra });
|
|
43
|
+
};
|
|
44
|
+
/** The caller's current tenant, with the permission `need` (from their roles there). */
|
|
45
|
+
const current = (need) => {
|
|
46
|
+
const tenant = principal.tenant;
|
|
47
|
+
if (!tenant)
|
|
48
|
+
throw new FeltKitError("FAILED_PRECONDITION", `Choose a ${word} first.`, { hint: "NO_TENANT" });
|
|
49
|
+
if (need && !grantsPermission(runtime.authority.permissionsFor(principal), need)) {
|
|
50
|
+
throw new FeltKitError("FORBIDDEN", `Your role in this ${word} (${tenant.role}) cannot do that.`, { hint: need });
|
|
51
|
+
}
|
|
52
|
+
return { ...tenant, principalId: principal.id, ...(principal.displayName ? { displayName: principal.displayName } : {}) };
|
|
53
|
+
};
|
|
54
|
+
if (pathname === "/api/tenants" && method === "GET") {
|
|
55
|
+
return done(response, 200, {
|
|
56
|
+
ok: true,
|
|
57
|
+
tenants: await tenancy.tenantsFor(principal.id),
|
|
58
|
+
current: principal.tenant ?? null,
|
|
59
|
+
settings: {
|
|
60
|
+
name: word,
|
|
61
|
+
roles: tenancy.roles,
|
|
62
|
+
create: tenancy.config.create ?? "anyone",
|
|
63
|
+
invitations: tenancy.config.invitations !== false,
|
|
64
|
+
switching: tenancy.config.switching !== false,
|
|
65
|
+
// What this caller may do in the current tenant (for the screens; the server checks again).
|
|
66
|
+
can: principal.tenant
|
|
67
|
+
? {
|
|
68
|
+
manageMembers: grantsPermission(runtime.authority.permissionsFor(principal), MANAGE_MEMBERS),
|
|
69
|
+
update: grantsPermission(runtime.authority.permissionsFor(principal), UPDATE_TENANT),
|
|
70
|
+
assign: tenancy.roles.filter((r) => tenancy.canAssign(principal.tenant.role, r)),
|
|
71
|
+
}
|
|
72
|
+
: null,
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
if (pathname === "/api/tenants" && method === "POST") {
|
|
77
|
+
const body = await readJSON(request);
|
|
78
|
+
const account = runtime.accounts && principal.id.startsWith("acct_") ? await runtime.accounts.get(principal.id) : null;
|
|
79
|
+
const tenant = await tenancy.create(body.name, { ...principal, ...(account ? { email: account.email } : {}) });
|
|
80
|
+
runtime.recordAuth("tenant.created", principal, { tenantId: tenant.id });
|
|
81
|
+
await rotate(tenant.id, 201);
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
if (pathname === "/api/tenants/switch" && method === "POST") {
|
|
85
|
+
if (tenancy.config.switching === false && principal.tenant)
|
|
86
|
+
throw new FeltKitError("FORBIDDEN", `Switching ${word}s is not enabled for this app.`);
|
|
87
|
+
const body = await readJSON(request);
|
|
88
|
+
const target = body.tenantId === null ? null : String(body.tenantId ?? "");
|
|
89
|
+
// Only to a tenant you are an active member of; anything else is NOT_FOUND (it may not exist for you).
|
|
90
|
+
if (target !== null && !(await tenancy.context(target, principal.id)))
|
|
91
|
+
throw new FeltKitError("NOT_FOUND", `No such ${word}.`);
|
|
92
|
+
runtime.recordAuth("tenant.switched", principal, { from: principal.tenant?.id ?? null, to: target });
|
|
93
|
+
await rotate(target);
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
if (pathname === "/api/tenants/current/members" && method === "GET") {
|
|
97
|
+
const tenant = current();
|
|
98
|
+
const members = await tenancy.members(tenant.id);
|
|
99
|
+
const accounts = runtime.accounts;
|
|
100
|
+
const view = await Promise.all(members.map(async (m) => {
|
|
101
|
+
const account = accounts && m.principalId.startsWith("acct_") ? await accounts.get(m.principalId) : null;
|
|
102
|
+
return { principalId: m.principalId, type: m.principalType, role: m.role, claims: m.claims, displayName: account?.name ?? m.displayName ?? account?.email ?? m.principalId, email: account?.email ?? m.email ?? null, joinedAt: m.createdAt, you: m.principalId === principal.id };
|
|
103
|
+
}));
|
|
104
|
+
return done(response, 200, { ok: true, members: view });
|
|
105
|
+
}
|
|
106
|
+
if (pathname === "/api/tenants/current/members/role" && method === "POST") {
|
|
107
|
+
const actor = current(MANAGE_MEMBERS);
|
|
108
|
+
const body = await readJSON(request);
|
|
109
|
+
const updated = await tenancy.setRole(actor, String(body.principalId ?? ""), body.role);
|
|
110
|
+
runtime.recordAuth("tenant.role-changed", principal, { tenantId: actor.id, subject: updated.principalId, role: updated.role });
|
|
111
|
+
return done(response, 200, { ok: true, member: { principalId: updated.principalId, role: updated.role } });
|
|
112
|
+
}
|
|
113
|
+
// An agent or service identity (one an operator issued a session for) joins directly; people are invited.
|
|
114
|
+
if (pathname === "/api/tenants/current/members/add" && method === "POST") {
|
|
115
|
+
const actor = current(MANAGE_MEMBERS);
|
|
116
|
+
const body = await readJSON(request);
|
|
117
|
+
const subject = String(body.principalId ?? "");
|
|
118
|
+
const identity = await runtime.knownNonPersonPrincipal(subject);
|
|
119
|
+
if (!identity)
|
|
120
|
+
throw new FeltKitError("NOT_FOUND", "No agent or service with that id has a session here.", { hint: "Issue it one: feltkit session create --type agent --id <id> --role <role>" });
|
|
121
|
+
const member = await tenancy.addPrincipal(actor, identity, body.role);
|
|
122
|
+
runtime.recordAuth("tenant.member-added", principal, { tenantId: actor.id, subject, role: member.role, type: identity.type });
|
|
123
|
+
return done(response, 201, { ok: true, member: { principalId: member.principalId, role: member.role, type: member.principalType } });
|
|
124
|
+
}
|
|
125
|
+
if (pathname === "/api/tenants/current/members/claims" && method === "POST") {
|
|
126
|
+
const actor = current(MANAGE_MEMBERS);
|
|
127
|
+
const body = await readJSON(request);
|
|
128
|
+
const updated = await tenancy.setClaims(actor, String(body.principalId ?? ""), body.claims);
|
|
129
|
+
runtime.recordAuth("tenant.claims-changed", principal, { tenantId: actor.id, subject: updated.principalId, claims: Object.keys(updated.claims) });
|
|
130
|
+
return done(response, 200, { ok: true, member: { principalId: updated.principalId, claims: updated.claims } });
|
|
131
|
+
}
|
|
132
|
+
if (pathname === "/api/tenants/current/members/remove" && method === "POST") {
|
|
133
|
+
const actor = current(MANAGE_MEMBERS);
|
|
134
|
+
const body = await readJSON(request);
|
|
135
|
+
const subject = String(body.principalId ?? "");
|
|
136
|
+
if (subject === principal.id)
|
|
137
|
+
throw new FeltKitError("INVALID_ARGUMENT", `To leave the ${word}, use leave.`);
|
|
138
|
+
await tenancy.remove(actor, subject);
|
|
139
|
+
runtime.recordAuth("tenant.member-removed", principal, { tenantId: actor.id, subject });
|
|
140
|
+
return done(response, 200, { ok: true });
|
|
141
|
+
}
|
|
142
|
+
if (pathname === "/api/tenants/current/leave" && method === "POST") {
|
|
143
|
+
const actor = current();
|
|
144
|
+
await tenancy.remove(actor, principal.id);
|
|
145
|
+
runtime.recordAuth("tenant.left", principal, { tenantId: actor.id });
|
|
146
|
+
const next = (await tenancy.tenantsFor(principal.id))[0]?.id ?? null;
|
|
147
|
+
await rotate(next);
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
if (pathname === "/api/tenants/current/rename" && method === "POST") {
|
|
151
|
+
const actor = current(UPDATE_TENANT);
|
|
152
|
+
const body = await readJSON(request);
|
|
153
|
+
const tenant = await tenancy.rename(actor, body.name);
|
|
154
|
+
return done(response, 200, { ok: true, tenant: { id: tenant.id, name: tenant.name } });
|
|
155
|
+
}
|
|
156
|
+
if (pathname === "/api/tenants/current/invitations" && method === "GET") {
|
|
157
|
+
const actor = current(MANAGE_MEMBERS);
|
|
158
|
+
return done(response, 200, { ok: true, invitations: await tenancy.invitations(actor.id) });
|
|
159
|
+
}
|
|
160
|
+
if (pathname === "/api/tenants/current/invitations" && method === "POST") {
|
|
161
|
+
const actor = current(MANAGE_MEMBERS);
|
|
162
|
+
const body = await readJSON(request);
|
|
163
|
+
const email = normalizeEmail(body.email);
|
|
164
|
+
const { invitation, token: inviteToken } = await tenancy.invite(actor, { email, role: body.role, ...(body.claims !== undefined ? { claims: body.claims } : {}) });
|
|
165
|
+
runtime.recordAuth("tenant.invited", principal, { tenantId: actor.id, invitation: invitation.id, role: invitation.role });
|
|
166
|
+
const sent = body.send !== false ? await runtime.sendInvitation(invitation.id, email) : false;
|
|
167
|
+
return done(response, 201, { ok: true, invitation, link: runtime.invitationLink(inviteToken), sent });
|
|
168
|
+
}
|
|
169
|
+
if (pathname === "/api/tenants/current/invitations/revoke" && method === "POST") {
|
|
170
|
+
const actor = current(MANAGE_MEMBERS);
|
|
171
|
+
const body = await readJSON(request);
|
|
172
|
+
await tenancy.revokeInvitation(actor, body.id);
|
|
173
|
+
runtime.recordAuth("tenant.invitation-revoked", principal, { tenantId: actor.id, invitation: String(body.id) });
|
|
174
|
+
return done(response, 200, { ok: true });
|
|
175
|
+
}
|
|
176
|
+
if (pathname === "/api/invitations/accept" && method === "POST") {
|
|
177
|
+
const body = await readJSON(request);
|
|
178
|
+
const account = runtime.accounts && principal.id.startsWith("acct_") ? await runtime.accounts.get(principal.id) : null;
|
|
179
|
+
// The invited address must be yours, verified. Development identities (no address) may accept in development only.
|
|
180
|
+
const { tenantId } = await tenancy.accept(body.token, { ...principal, ...(account ? { email: account.email, emailVerified: account.emailVerified } : {}) }, { allowAnyAddress: !account && runtime.environment.development });
|
|
181
|
+
runtime.recordAuth("tenant.invitation-accepted", principal, { tenantId });
|
|
182
|
+
await rotate(tenantId);
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
throw new FeltKitError("NOT_FOUND", `No API endpoint ${method} ${pathname}.`);
|
|
186
|
+
}
|
|
187
|
+
function done(response, status, body) {
|
|
188
|
+
sendJSON(response, status, body);
|
|
189
|
+
return true;
|
|
190
|
+
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AAI,CAAC;AACd,CAAC"}
|
package/dist/testing/index.d.ts
CHANGED
|
@@ -9,9 +9,28 @@ export interface Caller {
|
|
|
9
9
|
export interface CallerOptions {
|
|
10
10
|
/** Hold a session (default true), as every production caller does. */
|
|
11
11
|
session?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Work in this tenant (`auth.tenant`): resolved on every call exactly as the server resolves a
|
|
14
|
+
* session's tenant (the live membership's role and claims; none if the caller is not a member).
|
|
15
|
+
*/
|
|
16
|
+
tenant?: string;
|
|
12
17
|
}
|
|
13
18
|
export interface TestApp extends Caller {
|
|
14
19
|
runtime: FeltKitRuntime;
|
|
20
|
+
/** Tenants, memberships and invitations (`auth.tenant`), for setting up a test; null without tenancy. */
|
|
21
|
+
readonly tenancy: FeltKitRuntime["tenancy"];
|
|
22
|
+
/**
|
|
23
|
+
* Provision a tenant for a test whatever `auth.tenant.create` says. An application declared with `create: "none"`
|
|
24
|
+
* offers no way to create a workspace (people and its own code are refused): its workspaces are provisioned outside
|
|
25
|
+
* it. The runtime has no operator path for that yet, so this is the test harness's: it opens creation on the test's
|
|
26
|
+
* own tenancy store for this one call. The creator becomes the first holder of the top role, as with `tenancy.create`.
|
|
27
|
+
*/
|
|
28
|
+
provisionTenant(name: string, creator: PrincipalInput & {
|
|
29
|
+
email?: string;
|
|
30
|
+
}): Promise<{
|
|
31
|
+
id: string;
|
|
32
|
+
name: string;
|
|
33
|
+
}>;
|
|
15
34
|
/** Act as a declared dev user (by id) or any principal: signed in, with a session. */
|
|
16
35
|
as(who: string | PrincipalInput, options?: CallerOptions): Caller;
|
|
17
36
|
/** Restart the runtime on the same state, to test durability. */
|
package/dist/testing/index.js
CHANGED
|
@@ -60,7 +60,8 @@ export async function createTestApp(options = {}) {
|
|
|
60
60
|
const run = async (name, args) => {
|
|
61
61
|
if (principal && options.session !== false)
|
|
62
62
|
await signIn(principal);
|
|
63
|
-
const
|
|
63
|
+
const acting = principal && options.tenant ? await runtime.withTenant(principal, options.tenant) : principal;
|
|
64
|
+
const result = await runtime.call(name, args ?? {}, { principal: acting, via: "test" });
|
|
64
65
|
if (!result.ok)
|
|
65
66
|
throw new FeltKitError(result.error.code, result.error.message, { details: result.error.details, ...(result.error.hint ? { hint: result.error.hint } : {}), ...(result.error.retryable ? { retryable: true } : {}) });
|
|
66
67
|
return result.value;
|
|
@@ -75,6 +76,24 @@ export async function createTestApp(options = {}) {
|
|
|
75
76
|
get runtime() {
|
|
76
77
|
return runtime;
|
|
77
78
|
},
|
|
79
|
+
get tenancy() {
|
|
80
|
+
return runtime.tenancy;
|
|
81
|
+
},
|
|
82
|
+
async provisionTenant(name, creator) {
|
|
83
|
+
const store = runtime.tenancy;
|
|
84
|
+
if (!store)
|
|
85
|
+
throw new Error("provisionTenant: this application has no tenancy (auth.tenant).");
|
|
86
|
+
const config = store.config;
|
|
87
|
+
const previous = config.create;
|
|
88
|
+
config.create = "anyone";
|
|
89
|
+
try {
|
|
90
|
+
const tenant = await store.create(name, principalFor(creator));
|
|
91
|
+
return { id: tenant.id, name: tenant.name };
|
|
92
|
+
}
|
|
93
|
+
finally {
|
|
94
|
+
config.create = previous;
|
|
95
|
+
}
|
|
96
|
+
},
|
|
78
97
|
query: anonymous.query,
|
|
79
98
|
mutation: anonymous.mutation,
|
|
80
99
|
as: (who, options) => caller(principalFor(who), options),
|
|
@@ -103,8 +122,9 @@ export async function createArtifactTestApp(path, options = {}) {
|
|
|
103
122
|
const { ArtifactHost } = await import("../appboundry/host.js");
|
|
104
123
|
const host = await ArtifactHost.open(resolve(path), options);
|
|
105
124
|
const principalFor = (who) => {
|
|
125
|
+
// A principal may carry the tenant its host resolved (`auth.tenant`), as a host that has tenancy passes it.
|
|
106
126
|
if (typeof who !== "string")
|
|
107
|
-
return { id: who.id, type: who.type ?? "user", roles: who.roles, ...(who.displayName ? { displayName: who.displayName } : {}) };
|
|
127
|
+
return { id: who.id, type: who.type ?? "user", roles: who.roles, ...(who.displayName ? { displayName: who.displayName } : {}), ...(who.tenant ? { tenant: who.tenant } : {}) };
|
|
108
128
|
const user = host.manifest.identity.devUsers.find((u) => u.id === who);
|
|
109
129
|
if (!user)
|
|
110
130
|
throw new Error(`"${who}" is not a dev user in the artifact's manifest. Pass a principal object instead.`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,EAAE,kBAAkB,EAA0B,MAAM,2BAA2B,CAAC;AACvF,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,EAAE,kBAAkB,EAA0B,MAAM,2BAA2B,CAAC;AACvF,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAoCrE,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,UAAgE,EAAE;IACpG,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,UAAU,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAChE,MAAM,OAAO,GAAG,IAAI,eAAe,EAAE,CAAC;IACtC,IAAI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CAAC;QACtH,OAAO,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,IAAI,EAAG,IAAI,CAAC,IAA0B,IAAI,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;IAChJ,CAAC,CAAC;IACF,MAAM,MAAM,GAAG,CAAC,SAA2B,EAAU,EAAE,CAAC,CAAC;QACvD,KAAK,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,IAAI,EAAE,EAAE,SAAS,CAAQ;QACrE,QAAQ,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,IAAI,EAAE,EAAE,SAAS,CAAQ;KACzE,CAAC,CAAC;IACH,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IAC/B,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,CAAC,KAAK,EAAE,QAAQ,EAAE,SAAS,CAAC,QAAQ,EAAE,EAAE,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC;AAC3I,CAAC"}
|
package/docs/AGENT-OPERATIONS.md
CHANGED
|
@@ -25,6 +25,7 @@ response is not proof; **a deployment receipt is proof.**
|
|
|
25
25
|
|---|---|---|
|
|
26
26
|
| Agent principals | `Principal { type: "user" \| "agent" \| "service" }`, agent sessions (`feltkit session create --type agent`), revocable by reference, checked on every request | `runtime/authority.ts`, `runtime/sessions.ts` |
|
|
27
27
|
| Per-call authority | `Authority.authorize()` returns a `Decision` (decisionId, policyVersion), recorded in activity. Roles resolve to permissions on every call | `runtime/authority.ts`, `runtime/activity.ts` |
|
|
28
|
+
| Application agents acting as themselves on the app's own triggers (`app.agent`, FK-GAP-008): a mutation's `ctx.afterCommit.agent` or an `app.event`, run by the services worker as the agent principal, at least once with a lease and retries | after-commit outbox + `Runtime#call` | `runtime/runtime.ts` (`#runAgent`), `runtime/transactions.ts`, docs/TRANSACTIONS.md §8 |
|
|
28
29
|
| Propose, approve (people only), execute, evidence | `AgentHost`: proposals, approval by a `user` only, execution as the task owner, checkpoints with FeltDB-verified evidence, handoffs | `runtime/agent.ts` |
|
|
29
30
|
| AppPort and MCP for **application** capabilities | Functions as AppPort capabilities (authority before input), `/appport`, `/mcp` (bearer token per request) | `runtime/capabilities.ts`, `server/mcp.ts` |
|
|
30
31
|
| Operator access to production | Signed one-time grants, then `operator` sessions; `feltkit.operations.read\|write` | `server/operators.ts` |
|
package/docs/APPBOUNDRY.md
CHANGED
|
@@ -103,6 +103,8 @@ Handlers run with the same `ctx`:
|
|
|
103
103
|
preconditions and read fences; reads see the mutation's own pending writes; a query cannot
|
|
104
104
|
write. Records are validated by the guest with your schemas, and again by AppBoundry with the
|
|
105
105
|
manifest's.
|
|
106
|
+
`ctx.db.search` runs in the guest on the existing read operations (`db.query` pages in a
|
|
107
|
+
query, `db.find` in a mutation, its `where` pushed down), so it needs no new host interface.
|
|
106
108
|
- **`ctx.auth`**: the principal and its permissions, from your roles. `access` is enforced by
|
|
107
109
|
AppBoundry before the handler runs.
|
|
108
110
|
- **`ctx.services`**: files, notifications, configuration, jobs (`enqueue`, run as the
|
|
@@ -121,6 +123,12 @@ command. AppBoundry also decides where the data is: a local state directory, or
|
|
|
121
123
|
FeltDB environment from its own runtime configuration. The artifact, and your code, are the
|
|
122
124
|
same either way; FeltKit does not know which one runs it, and nothing is rebuilt to switch.
|
|
123
125
|
|
|
126
|
+
Built-in accounts (`auth.accounts`) and tenancy (`auth.tenant`) are FeltKit server routes
|
|
127
|
+
(`/api/auth/*`, `/api/tenants/*`) that an AppBoundry host does not serve (FK-GAP-013). The build
|
|
128
|
+
warns, and declares them in the manifest (`identity.accounts`, `identity.tenancy`) so the host can
|
|
129
|
+
refuse the artifact unless its operator accepts that people get sessions only from an operator,
|
|
130
|
+
and that tenant-scoped collections stay closed. See [AUTH.md](AUTH.md#appboundry).
|
|
131
|
+
|
|
124
132
|
## Schema lifecycle in an artifact
|
|
125
133
|
|
|
126
134
|
`manifest.json` carries `state.contract`: the FeltDB state contract the application's
|
|
@@ -224,6 +232,7 @@ artifact that behaves differently from your application:
|
|
|
224
232
|
|---|---|
|
|
225
233
|
| `ctx.unsafe.feltdb` | it writes FeltDB around validation and transactions; an artifact reaches state only through `ctx.db` |
|
|
226
234
|
| `ctx.agent` | FeltKit's agent runs in the FeltKit server |
|
|
235
|
+
| `app.agent` (and `ctx.afterCommit.agent`) | application agents run after a commit, as their own principal, on FeltKit's runtime; the host protocol runs guest code only inside a call, as its caller (docs/TRANSACTIONS.md §8) |
|
|
227
236
|
| `app.integration(...)` | integrations call external APIs; an artifact has no network access |
|
|
228
237
|
| `feltkit({ auth: { authenticate } })` | not yet supported; identity comes from AppBoundry sessions |
|
|
229
238
|
| `Intl`, `toLocaleString` / `toLocaleDateString` / `toLocaleTimeString`, `localeCompare` | the guest engine has no locale data (see below), so they would give different output than under `feltkit dev` |
|
|
@@ -271,7 +280,8 @@ your own digit grouping).
|
|
|
271
280
|
|
|
272
281
|
The build lists these (`omitted` in the manifest) instead of pretending to carry them:
|
|
273
282
|
Studio and the MCP endpoint, API keys, schedules, intelligence, and webhook delivery
|
|
274
|
-
(`emit()` records the event; AppBoundry delivers nothing because the artifact has no network)
|
|
283
|
+
(`emit()` records the event; AppBoundry delivers nothing because the artifact has no network),
|
|
284
|
+
and the account and tenant routes of `auth.accounts` and `auth.tenant` (also declared in `identity`).
|
|
275
285
|
|
|
276
286
|
## Rebuilding the engine
|
|
277
287
|
|