@feltdb/feltkit 0.3.2 → 0.3.4
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/README.md +7 -0
- package/dist/cli/deploy.d.ts +14 -1
- package/dist/cli/deploy.js +421 -64
- package/dist/cli/deploy.js.map +1 -1
- package/dist/cli/main.js +89 -17
- package/dist/cli/main.js.map +1 -1
- package/dist/dashboard/apple-touch-icon.png +0 -0
- package/dist/dashboard/assets/feltkit-mark-BygpVIiS.png +0 -0
- package/dist/dashboard/assets/index-B-ra0AY9.css +1 -0
- package/dist/dashboard/assets/index-DnJaSnzt.js +15 -0
- package/dist/dashboard/favicon.png +0 -0
- package/dist/dashboard/index.html +5 -3
- package/dist/dashboard/theme.js +6 -0
- package/dist/runtime/changes.d.ts +9 -0
- package/dist/runtime/changes.js +47 -3
- package/dist/runtime/changes.js.map +1 -1
- package/dist/runtime/connect.d.ts +65 -0
- package/dist/runtime/connect.js +246 -0
- package/dist/runtime/connect.js.map +1 -0
- package/dist/runtime/contract.d.ts +15 -5
- package/dist/runtime/contract.js +36 -12
- package/dist/runtime/contract.js.map +1 -1
- package/dist/runtime/decisions.d.ts +32 -4
- package/dist/runtime/decisions.js +69 -0
- package/dist/runtime/decisions.js.map +1 -1
- package/dist/runtime/environment.js +41 -0
- package/dist/runtime/environment.js.map +1 -1
- package/dist/runtime/readiness.js +5 -3
- package/dist/runtime/readiness.js.map +1 -1
- package/dist/runtime/runtime.d.ts +11 -0
- package/dist/runtime/runtime.js +33 -15
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/runtime/services.d.ts +11 -2
- package/dist/runtime/services.js +5 -0
- package/dist/runtime/services.js.map +1 -1
- package/dist/runtime/storage-check.d.ts +12 -0
- package/dist/runtime/storage-check.js +99 -0
- package/dist/runtime/storage-check.js.map +1 -0
- package/dist/runtime/targets.d.ts +72 -0
- package/dist/runtime/targets.js +173 -0
- package/dist/runtime/targets.js.map +1 -0
- package/dist/server/admin.js +153 -0
- package/dist/server/admin.js.map +1 -1
- package/dist/server/brand.d.ts +5 -0
- package/dist/server/brand.js +6 -0
- package/dist/server/brand.js.map +1 -0
- package/dist/server/index.js +50 -0
- package/dist/server/index.js.map +1 -1
- package/dist/server/project.d.ts +8 -0
- package/dist/server/project.js +30 -3
- package/dist/server/project.js.map +1 -1
- package/package.json +5 -5
- package/skills/.claude-plugin/marketplace.json +1 -1
- package/skills/.claude-plugin/plugin.json +1 -1
- package/skills/feltkit-operations/SKILL.md +3 -1
- package/skills/feltkit-services/SKILL.md +3 -3
- package/dist/dashboard/assets/index-Bo2oHR18.css +0 -1
- package/dist/dashboard/assets/index-DK_Jda9P.js +0 -15
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deployment targets: where a deployed FeltKit application runs, and where its state is.
|
|
3
|
+
*
|
|
4
|
+
* container the app and its FeltDB state in one container, state on a local volume
|
|
5
|
+
* hosted a separate app container; state in Managed FeltDB (application-scoped,
|
|
6
|
+
* contract-enforced)
|
|
7
|
+
* self-hosted a separate app container; state on a FeltDB server you operate
|
|
8
|
+
* (`feltdb-server`, namespace API)
|
|
9
|
+
* vercel the app on Vercel's container runtime (stateless instances that
|
|
10
|
+
* scale to zero); state in Managed FeltDB, or with `--data self-hosted`
|
|
11
|
+
* on a FeltDB server you operate
|
|
12
|
+
*
|
|
13
|
+
* This is the one definition of each target's contract: what it needs (configuration and
|
|
14
|
+
* secrets), where state lives and how it is recovered, who may touch it, how the FeltDB side
|
|
15
|
+
* is provisioned and checked, what stops startup, how it is observed, and how it is upgraded
|
|
16
|
+
* and rolled back. `feltkit deploy` renders DEPLOY.md and .env.example from it, and the
|
|
17
|
+
* runtime enforces its storage rule at startup (runtime/environment.ts): a target never
|
|
18
|
+
* changes where state is stored. A container target with FELTDB_URL set, or a separate-app
|
|
19
|
+
* target without it, refuses to start rather than keep state somewhere else.
|
|
20
|
+
*/
|
|
21
|
+
import { FeltKitError } from "../errors.js";
|
|
22
|
+
export const VERCEL_DATA = ["managed", "self-hosted"];
|
|
23
|
+
const VERIFIER = {
|
|
24
|
+
name: "FELTKIT_API_KEY_VERIFIER_KEY",
|
|
25
|
+
secret: true,
|
|
26
|
+
required: "apiKeys",
|
|
27
|
+
purpose: "verifies issued API keys: 32+ random bytes (openssl rand -base64 32), the same for every process; changing it invalidates every API key",
|
|
28
|
+
};
|
|
29
|
+
const SHARED_FAILURES = [
|
|
30
|
+
"FELTKIT_STATE_DIR set: it selects local state, which this target does not use",
|
|
31
|
+
"FELTDB_URL unreachable: startup stops, naming the origin; nothing is written locally",
|
|
32
|
+
"FELTDB_TOKEN refused (401): startup stops with AUTHENTICATION_REQUIRED",
|
|
33
|
+
"FELTDB_TOKEN without state:read and state:write: startup stops, naming the missing scope",
|
|
34
|
+
];
|
|
35
|
+
const CONTAINER = {
|
|
36
|
+
id: "container",
|
|
37
|
+
title: "Everything in one container: the app and its data (FeltDB) on a volume",
|
|
38
|
+
storage: "local",
|
|
39
|
+
runtime: "one container (or one Node process)",
|
|
40
|
+
state: "FeltDB on the /data volume (/data/state)",
|
|
41
|
+
variables: [
|
|
42
|
+
{ name: "FELTKIT_API_KEY_VERIFIER_KEY", secret: true, required: false, purpose: "overrides the verifier key kept beside the state (/data/state-api-key-verifier)" },
|
|
43
|
+
],
|
|
44
|
+
persistence: "FeltDB state and the keys kept beside it are on the /data volume. The container's own filesystem holds nothing that must survive.",
|
|
45
|
+
recovery: "Back up the volume (stop the container, or snapshot the volume). Restore it and start the same image. A single-host store: one container per volume; a second one refuses the volume's lock.",
|
|
46
|
+
identity: "Sessions and API keys are issued by this app (`feltkit session create`, Studio); the volume holds them. Only this process opens the state.",
|
|
47
|
+
provisioning: "None: the state is created on first start. There is no separate database to provision or contract to publish.",
|
|
48
|
+
startupFailures: [
|
|
49
|
+
"FELTDB_URL, FELTDB_TOKEN or FELTDB_APPLICATION_ID set: this target keeps state on its volume, so it refuses rather than store it elsewhere",
|
|
50
|
+
"the volume's state open in another process: startup stops, naming its owner",
|
|
51
|
+
],
|
|
52
|
+
health: "GET /_feltkit/health (the image's HEALTHCHECK). `npx feltkit readiness --env production` with the container stopped reports durability and keys.",
|
|
53
|
+
upgrade: "Deploy again and start the new image on the same volume. FeltDB opens state written by earlier versions.",
|
|
54
|
+
rollback: "Start the previous image on the same volume. Back up the volume before an upgrade: state a newer version wrote may not open in an older one.",
|
|
55
|
+
};
|
|
56
|
+
const HOSTED = {
|
|
57
|
+
id: "hosted",
|
|
58
|
+
title: "App container only; data in Managed FeltDB (hosted)",
|
|
59
|
+
storage: "managed",
|
|
60
|
+
runtime: "a stateless app container, any number of them",
|
|
61
|
+
state: "Managed FeltDB, one application per app (FELTDB_APPLICATION_ID)",
|
|
62
|
+
variables: [
|
|
63
|
+
{ name: "FELTDB_URL", secret: false, required: true, purpose: "Managed FeltDB's API origin (https)" },
|
|
64
|
+
{ name: "FELTDB_APPLICATION_ID", secret: false, required: true, purpose: "the managed application, from `feltdb init-managed`" },
|
|
65
|
+
{ name: "FELTDB_TOKEN", secret: true, required: true, purpose: "the application's runtime key (never the control key)" },
|
|
66
|
+
VERIFIER,
|
|
67
|
+
],
|
|
68
|
+
persistence: "All state is in Managed FeltDB. The container holds none: replace, scale or move it freely.",
|
|
69
|
+
recovery: "Managed FeltDB keeps and recovers the state. A restarted or replaced container reads the same state.",
|
|
70
|
+
identity: "The container authenticates to FeltDB with the runtime key (state:read, state:write); people and agents never hold a FeltDB key. Sessions are FeltKit's and stored in FeltDB, so every container accepts them.",
|
|
71
|
+
provisioning: "Create the application from the artifact's feltdb.contract.json (`npx feltdb init-managed --contract feltdb.contract.json --runtime-scopes minimal`). It declares every collection the app stores, AppPort Services' included. At startup the app compares its contract with the active one and refuses to start on a difference.",
|
|
72
|
+
startupFailures: [
|
|
73
|
+
"FELTDB_URL, FELTDB_TOKEN or FELTDB_APPLICATION_ID missing: startup stops, naming it",
|
|
74
|
+
...SHARED_FAILURES,
|
|
75
|
+
"active contract missing a collection or field the app stores: startup stops, listing them; publish the artifact's feltdb.contract.json",
|
|
76
|
+
"FELTKIT_API_KEY_VERIFIER_KEY missing with API keys enabled: startup stops (there is no shared disk to keep one on)",
|
|
77
|
+
],
|
|
78
|
+
health: "GET /_feltkit/health. Startup has already proved FeltDB answers with this key and contract.",
|
|
79
|
+
upgrade: "Deploy again. When feltdb.contract.json changed, publish it first (`npx feltdb publish --contract feltdb.contract.json`); then start the new image. Additive changes keep the old image working.",
|
|
80
|
+
rollback: "Start the previous image. If its contract needs collections or fields the active contract dropped, it refuses to start: publish that image's contract again.",
|
|
81
|
+
};
|
|
82
|
+
const SELF_HOSTED = {
|
|
83
|
+
id: "self-hosted",
|
|
84
|
+
title: "App container only; data on a FeltDB server you operate",
|
|
85
|
+
storage: "server",
|
|
86
|
+
runtime: "a stateless app container, any number of them",
|
|
87
|
+
state: "your `feltdb-server`, in the namespace named after the app",
|
|
88
|
+
variables: [
|
|
89
|
+
{ name: "FELTDB_URL", secret: false, required: true, purpose: "your FeltDB server's origin (https, or a private network address)" },
|
|
90
|
+
{ name: "FELTDB_TOKEN", secret: true, required: true, purpose: "a key for the app's namespace with state:read,state:write" },
|
|
91
|
+
VERIFIER,
|
|
92
|
+
],
|
|
93
|
+
persistence: "All state is on your FeltDB server, in the app's namespace. The container holds none.",
|
|
94
|
+
recovery: "Back up and restore the server's data directory (its state log and keys file) as you operate it; a restarted container reads the same state.",
|
|
95
|
+
identity: "The container authenticates with a namespace key (state:read, state:write). A key for another namespace is refused, so apps on one server are isolated. People and agents never hold a FeltDB key.",
|
|
96
|
+
provisioning: "Create a key for the app's namespace (`feltdb-server keys create --keys <keys.json> --name <app> --namespace <app> --scope state:read,state:write`). The namespace API keeps no contract: FeltKit validates every record against its schemas, and the server enforces keys and scopes. For contract enforcement on your own server, run it application-scoped and use the hosted target.",
|
|
97
|
+
startupFailures: [
|
|
98
|
+
"FELTDB_URL or FELTDB_TOKEN missing: startup stops, naming it",
|
|
99
|
+
"FELTDB_APPLICATION_ID set: that is an application-scoped authority; use the hosted target",
|
|
100
|
+
...SHARED_FAILURES,
|
|
101
|
+
"FELTKIT_API_KEY_VERIFIER_KEY missing with API keys enabled: startup stops",
|
|
102
|
+
],
|
|
103
|
+
health: "GET /_feltkit/health. Startup has already proved the server answers with this key.",
|
|
104
|
+
upgrade: "Deploy again and start the new image; upgrade the server separately, following FeltDB's notes.",
|
|
105
|
+
rollback: "Start the previous image against the same server.",
|
|
106
|
+
};
|
|
107
|
+
const OPERATOR_KEY = {
|
|
108
|
+
name: "FELTKIT_OPERATOR_KEY",
|
|
109
|
+
secret: true,
|
|
110
|
+
required: "dashboard",
|
|
111
|
+
purpose: "signs operator sign-ins for production Studio (FELTKIT_DASHBOARD=1): 32+ random bytes (openssl rand -base64 32), the same for every instance, or a grant made on one is refused by the others",
|
|
112
|
+
};
|
|
113
|
+
const VERCEL_PORT = {
|
|
114
|
+
name: "PORT",
|
|
115
|
+
secret: false,
|
|
116
|
+
required: true,
|
|
117
|
+
value: "3000",
|
|
118
|
+
purpose: "the port the container listens on; Vercel routes to it only when it is set in the project's environment (its default is 80)",
|
|
119
|
+
};
|
|
120
|
+
const VERCEL_SHARED = {
|
|
121
|
+
runtime: "Vercel's container runtime (beta): stateless instances that scale with traffic and to zero after 5 idle minutes",
|
|
122
|
+
persistence: "All state is in FeltDB. Instances share no disk and lose theirs when they stop; FeltKit keeps only per-process files there (in /tmp). Live queries reach every instance through FeltDB.",
|
|
123
|
+
health: "GET /_feltkit/health; `vercel logs <deployment-url>` for output. Startup has already proved FeltDB answers with this key. Vercel does not run the image's HEALTHCHECK.",
|
|
124
|
+
upgrade: "Deploy again (`npx feltkit deploy --target vercel`, then `npx vercel deploy --prod` in the artifact). Vercel switches traffic to the new deployment once it is ready.",
|
|
125
|
+
rollback: "`npx vercel rollback` (or promote an earlier deployment in the dashboard); it runs against the same FeltDB.",
|
|
126
|
+
limits: [
|
|
127
|
+
"Vercel's container runtime is in beta; Secure Compute and static IPs are not available for containers",
|
|
128
|
+
"a request, including a live-query stream, ends at the function's maximum duration (300 s by default); the client reconnects and refreshes by itself",
|
|
129
|
+
"request and response bodies are limited to 4.5 MB, which includes file uploads",
|
|
130
|
+
"jobs, schedules, and webhook retries run inside the app, so they progress only while an instance is running: with no traffic, Vercel scales to zero and they wait",
|
|
131
|
+
],
|
|
132
|
+
};
|
|
133
|
+
/** The Vercel target's contract, for where its data is (Managed FeltDB by default). */
|
|
134
|
+
function vercelContract(data) {
|
|
135
|
+
const managed = data === "managed";
|
|
136
|
+
const base = managed ? HOSTED : SELF_HOSTED;
|
|
137
|
+
return {
|
|
138
|
+
id: "vercel",
|
|
139
|
+
data,
|
|
140
|
+
title: managed ? "Vercel; data in Managed FeltDB" : "Vercel; data on a FeltDB server you operate",
|
|
141
|
+
storage: base.storage,
|
|
142
|
+
runtime: VERCEL_SHARED.runtime,
|
|
143
|
+
state: base.state,
|
|
144
|
+
variables: [...base.variables.filter((v) => v.name !== VERIFIER.name), VERIFIER, OPERATOR_KEY, VERCEL_PORT],
|
|
145
|
+
persistence: VERCEL_SHARED.persistence,
|
|
146
|
+
recovery: base.recovery.replace("container", "deployment"),
|
|
147
|
+
identity: base.identity.replace("The container authenticates", "Every instance authenticates"),
|
|
148
|
+
provisioning: base.provisioning,
|
|
149
|
+
startupFailures: [...base.startupFailures, "FELTKIT_STORAGE, set by the image, cannot be overridden into local state: there is no disk to keep it on"],
|
|
150
|
+
health: VERCEL_SHARED.health,
|
|
151
|
+
upgrade: VERCEL_SHARED.upgrade + (managed ? " When feltdb.contract.json changed, publish it first (`npx feltdb publish --contract feltdb.contract.json`)." : ""),
|
|
152
|
+
rollback: VERCEL_SHARED.rollback,
|
|
153
|
+
limits: VERCEL_SHARED.limits,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
/** A target's contract; `data` chooses where a Vercel deployment's data is. */
|
|
157
|
+
export function targetContract(target, data) {
|
|
158
|
+
if (target === "vercel")
|
|
159
|
+
return vercelContract(data ?? "managed");
|
|
160
|
+
if (data)
|
|
161
|
+
throw new FeltKitError("INVALID_ARGUMENT", `--data applies to --target vercel only; the ${target} target always keeps its data in ${TARGETS[target].state}.`);
|
|
162
|
+
return TARGETS[target];
|
|
163
|
+
}
|
|
164
|
+
export const isVercelData = (value) => typeof value === "string" && VERCEL_DATA.includes(value);
|
|
165
|
+
export const TARGETS = {
|
|
166
|
+
container: CONTAINER,
|
|
167
|
+
hosted: HOSTED,
|
|
168
|
+
"self-hosted": SELF_HOSTED,
|
|
169
|
+
vercel: vercelContract("managed"),
|
|
170
|
+
};
|
|
171
|
+
export const DEPLOY_TARGETS = Object.fromEntries(Object.values(TARGETS).map((t) => [t.id, t.title]));
|
|
172
|
+
export const isDeployTarget = (value) => typeof value === "string" && value in TARGETS;
|
|
173
|
+
//# sourceMappingURL=targets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"targets.js","sourceRoot":"","sources":["../../src/runtime/targets.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAM5C,MAAM,CAAC,MAAM,WAAW,GAA0B,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;AA+C7E,MAAM,QAAQ,GAAmB;IAC/B,IAAI,EAAE,8BAA8B;IACpC,MAAM,EAAE,IAAI;IACZ,QAAQ,EAAE,SAAS;IACnB,OAAO,EAAE,yIAAyI;CACnJ,CAAC;AAEF,MAAM,eAAe,GAAG;IACtB,+EAA+E;IAC/E,sFAAsF;IACtF,wEAAwE;IACxE,0FAA0F;CAC3F,CAAC;AAEF,MAAM,SAAS,GAAmB;IAChC,EAAE,EAAE,WAAW;IACf,KAAK,EAAE,wEAAwE;IAC/E,OAAO,EAAE,OAAO;IAChB,OAAO,EAAE,qCAAqC;IAC9C,KAAK,EAAE,0CAA0C;IACjD,SAAS,EAAE;QACT,EAAE,IAAI,EAAE,8BAA8B,EAAE,MAAM,EA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AAI,SAAS,CAAC,CAAC;IAClE,IAAI,IAAI;QAAE,MAAM,IAAI,YAAY,CAAC,kBAAkB,EAAE,+CAA+C,MAAM,oCAAoC,OAAO,CAAC,MAAM,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC;IACxK,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC;AACzB,CAAC;AAED,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAc,EAAuB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAK,WAAiC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAErJ,MAAM,CAAC,MAAM,OAAO,GAAyC;IAC3D,SAAS,EAAE,SAAS;IACpB,MAAM,EAAE,MAAM;IACd,aAAa,EAAE,WAAW;IAC1B,MAAM,EAAE,cAAc,CAAC,SAAS,CAAC;CAClC,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAiC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAiC,CAAC;AAEnK,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAc,EAAyB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,IAAI,OAAO,CAAC"}
|
package/dist/server/admin.js
CHANGED
|
@@ -11,6 +11,8 @@ import { systemPrincipal } from "../runtime/authority.js";
|
|
|
11
11
|
import { credentialId, looksLikeSecret } from "../runtime/credentials.js";
|
|
12
12
|
import { assessReadiness } from "../runtime/readiness.js";
|
|
13
13
|
import { INTEGRATION_CALLS } from "../runtime/integrations.js";
|
|
14
|
+
import { SAVED_MODELS } from "../runtime/decisions.js";
|
|
15
|
+
import { fromOpenApi, validateDraft, writeIntegration } from "../runtime/connect.js";
|
|
14
16
|
import { OPERATOR_PERMISSIONS, authenticateOperator, checkWrite, csrfFor, newRequestId, operatorKey, requireOperator, setSessionCookie, signIn } from "./operators.js";
|
|
15
17
|
const DASHBOARD = { id: "dashboard", type: "service", roles: [] };
|
|
16
18
|
/** Platform collections the data explorer may show, read-only, with what to redact. */
|
|
@@ -38,6 +40,7 @@ const PLATFORM_COLLECTIONS = {
|
|
|
38
40
|
"_feltdb.AgentHandoff": { owner: "FeltDB", description: "Agent handoffs (FeltDB agent state)" },
|
|
39
41
|
[COLLECTION_MARKERS]: { owner: "FeltKit", description: "Per-collection change markers used to fence whole-collection reads" },
|
|
40
42
|
[FILE_CONTENT_COLLECTION]: { owner: "FeltKit", description: "File bytes (base64)", redact: (r) => ({ ...r, data: `<${String(r.data ?? "").length} base64 chars>` }) },
|
|
43
|
+
[SAVED_MODELS]: { owner: "FeltKit", description: "Saved models: provider, model, endpoint, and credential reference (never a key)" },
|
|
41
44
|
[INTEGRATION_CALLS]: { owner: "FeltKit", description: "Integration calls: recorded before and after each request, with verification evidence (credentials are never stored)" },
|
|
42
45
|
};
|
|
43
46
|
export async function handleAdmin(ctx, request, response, path, url) {
|
|
@@ -240,6 +243,11 @@ export async function handleAdmin(ctx, request, response, path, url) {
|
|
|
240
243
|
throw new FeltKitError("INVALID_ARGUMENT", "Choose a dev identity to open the services console as; service operations are authorized as that identity.");
|
|
241
244
|
return sendJSON(response, 200, { url: await ctx.console.ticket(principal, typeof body.page === "string" ? body.page : "/services") });
|
|
242
245
|
}
|
|
246
|
+
// What the Services screens' forms offer: declared catalogs, what the services' own records
|
|
247
|
+
// already use, the app's capabilities, and credential references (never values).
|
|
248
|
+
if (method === "GET" && segments[0] === "services" && segments[1] === "catalog" && segments.length === 2) {
|
|
249
|
+
return sendJSON(response, 200, await servicesCatalog(runtime));
|
|
250
|
+
}
|
|
243
251
|
// Studio's Services screens: AppPort Services' own management contract (the routes its
|
|
244
252
|
// packaged pages call), as the dev identity named in `x-feltkit-as`. Authorized by the
|
|
245
253
|
// services' gateway; FeltKit adds no second authorization layer.
|
|
@@ -252,6 +260,11 @@ export async function handleAdmin(ctx, request, response, path, url) {
|
|
|
252
260
|
throw new FeltKitError("INVALID_ARGUMENT", "Choose a dev identity; service operations are authorized as that identity.");
|
|
253
261
|
const rest = path.slice(path.indexOf("/manage") + "/manage".length) || "/";
|
|
254
262
|
request.url = `${rest}${url.search}`;
|
|
263
|
+
// Work created here (jobs, schedules) runs later as its creator, resolved from an active
|
|
264
|
+
// session, so revoking the creator's sessions stops it. Like the services console, Studio
|
|
265
|
+
// gives the identity it acts as a session before it writes.
|
|
266
|
+
if (method !== "GET" && method !== "HEAD")
|
|
267
|
+
await studioSession(runtime, principal);
|
|
255
268
|
return await ctx.management.handle(request, response, principal);
|
|
256
269
|
}
|
|
257
270
|
// Files with their bytes: FeltKit stores content in the same instance (runtime/content.ts),
|
|
@@ -353,8 +366,69 @@ export async function handleAdmin(ctx, request, response, path, url) {
|
|
|
353
366
|
}
|
|
354
367
|
if (method === "POST" && segments[0] === "models" && segments[1] === "test" && segments.length === 2)
|
|
355
368
|
return sendJSON(response, 200, await testModel(runtime));
|
|
369
|
+
// Switch to a saved model (authorized as `as`: intelligence.write), or forget one.
|
|
370
|
+
if (segments[0] === "models" && segments[1] === "saved" && segments[2]) {
|
|
371
|
+
requireDevelopment("Changing the model from Studio");
|
|
372
|
+
if (method === "POST" && segments[3] === "use" && segments.length === 4) {
|
|
373
|
+
const body = await readJSON(request);
|
|
374
|
+
const principal = identityFor(runtime, body.as);
|
|
375
|
+
if (!principal)
|
|
376
|
+
throw new FeltKitError("INVALID_ARGUMENT", "Choose a dev identity; the switch is authorized as that identity.");
|
|
377
|
+
await runtime.models.use(segments[2], principal);
|
|
378
|
+
return sendJSON(response, 200, await modelsView(runtime));
|
|
379
|
+
}
|
|
380
|
+
if (method === "DELETE" && segments.length === 3) {
|
|
381
|
+
await runtime.models.forget(segments[2]);
|
|
382
|
+
return sendJSON(response, 200, await modelsView(runtime));
|
|
383
|
+
}
|
|
384
|
+
}
|
|
356
385
|
if (method === "GET" && segments[0] === "integrations" && segments.length === 1)
|
|
357
386
|
return sendJSON(response, 200, await integrationsView(runtime));
|
|
387
|
+
// Connect an API (development): read an OpenAPI document into operations, then write the
|
|
388
|
+
// integration module (feltkit/<name>.ts) and grant <name>.* to the chosen roles. The dev
|
|
389
|
+
// server reloads and publishes its operations. A key, if given, goes to custody as `as`.
|
|
390
|
+
if (method === "POST" && segments[0] === "integrations" && segments[1] === "openapi" && segments.length === 2) {
|
|
391
|
+
requireDevelopment("Connecting an API from Studio");
|
|
392
|
+
const body = await readJSON(request);
|
|
393
|
+
let document;
|
|
394
|
+
if (typeof body.url === "string" && body.url.trim()) {
|
|
395
|
+
const target = new URL(body.url.trim());
|
|
396
|
+
if (!/^https?:$/.test(target.protocol))
|
|
397
|
+
throw new FeltKitError("INVALID_ARGUMENT", "The document URL must be http(s).");
|
|
398
|
+
const fetched = await fetch(target, { headers: { accept: "application/json" }, redirect: "follow", signal: AbortSignal.timeout(10_000) }).catch((error) => {
|
|
399
|
+
throw new FeltKitError("UNAVAILABLE", `Could not fetch the document: ${error.message}`);
|
|
400
|
+
});
|
|
401
|
+
if (!fetched.ok)
|
|
402
|
+
throw new FeltKitError("UNAVAILABLE", `The document URL answered ${fetched.status}.`);
|
|
403
|
+
document = parseDocument(await fetched.text());
|
|
404
|
+
}
|
|
405
|
+
else if (typeof body.document === "string" && body.document.trim()) {
|
|
406
|
+
document = parseDocument(body.document);
|
|
407
|
+
}
|
|
408
|
+
else {
|
|
409
|
+
throw new FeltKitError("INVALID_ARGUMENT", "Give the document's URL, or paste it.");
|
|
410
|
+
}
|
|
411
|
+
return sendJSON(response, 200, fromOpenApi(document, typeof body.name === "string" ? body.name : undefined));
|
|
412
|
+
}
|
|
413
|
+
if (method === "POST" && segments[0] === "integrations" && segments[1] === "connect" && segments.length === 2) {
|
|
414
|
+
requireDevelopment("Connecting an API from Studio");
|
|
415
|
+
if (!ctx.projectDir)
|
|
416
|
+
throw new FeltKitError("UNAVAILABLE", "This server has no project directory to write to.");
|
|
417
|
+
const body = await readJSON(request);
|
|
418
|
+
const draft = body.integration;
|
|
419
|
+
const roles = Array.isArray(body.roles) ? body.roles.filter((r) => typeof r === "string" && r in (runtime.app.options.roles ?? {})) : [];
|
|
420
|
+
const apiKey = typeof body.apiKey === "string" ? body.apiKey.trim() : "";
|
|
421
|
+
const principal = apiKey ? identityFor(runtime, body.as) : null;
|
|
422
|
+
if (apiKey && !principal)
|
|
423
|
+
throw new FeltKitError("INVALID_ARGUMENT", "Choose a dev identity; the key is stored as that identity.");
|
|
424
|
+
validateDraft(draft);
|
|
425
|
+
if (apiKey && draft.auth.kind === "none")
|
|
426
|
+
throw new FeltKitError("INVALID_ARGUMENT", "This API is set to use no key; choose how the key is sent, or leave the key empty.");
|
|
427
|
+
const written = writeIntegration(ctx.projectDir, draft, { existing: runtime.integrations.definitions().map((i) => i.name), roles });
|
|
428
|
+
const stored = apiKey && principal ? await storeCredential(runtime, { ref: `credential-ref:${draft.name}`, value: apiKey }, principal, "dashboard") : null;
|
|
429
|
+
runtime.activity.record({ kind: "admin", name: "integration.connect", via: "dashboard", requestId: `req_${randomUUID()}`, principal: DASHBOARD, outcome: "success", durationMs: 0, detail: { integration: draft.name, file: written.file, operations: draft.operations.length, granted: written.granted } });
|
|
430
|
+
return sendJSON(response, 200, { ...written, credential: draft.auth.kind === "none" ? null : `credential-ref:${draft.name}`, ...(stored ? { stored } : {}) });
|
|
431
|
+
}
|
|
358
432
|
if (method === "POST" && segments[0] === "integrations" && segments[2] === "check" && segments.length === 3)
|
|
359
433
|
return sendJSON(response, 200, await runtime.integrations.check(segments[1]));
|
|
360
434
|
// Credentials: references, where each value is kept, and a write path that never echoes it.
|
|
@@ -776,6 +850,33 @@ async function handleProduction(ctx, request, response, path, url) {
|
|
|
776
850
|
throw error;
|
|
777
851
|
}
|
|
778
852
|
}
|
|
853
|
+
// Production has no services console (see docs/SECURITY.md); these are the operations an
|
|
854
|
+
// operator needs that only the console offered. Each runs through AppPort Services'
|
|
855
|
+
// own invoke as the signed-in operator, so the services' gateway authorizes it
|
|
856
|
+
// (webhooks.register, jobs.create) exactly as anywhere else.
|
|
857
|
+
case "POST /services/webhooks":
|
|
858
|
+
case "POST /services/jobs": {
|
|
859
|
+
const { p, body } = await write();
|
|
860
|
+
const capability = route === "POST /services/webhooks" ? "webhooks.register" : "jobs.create";
|
|
861
|
+
const input = route === "POST /services/webhooks"
|
|
862
|
+
? { url: body.url, events: body.events, signingCredentialRef: body.signingCredentialRef }
|
|
863
|
+
: { type: body.type, ...(body.payload !== undefined ? { payload: body.payload } : {}), ...(body.runAt !== undefined ? { runAt: body.runAt } : {}), ...(body.maxAttempts !== undefined ? { maxAttempts: body.maxAttempts } : {}) };
|
|
864
|
+
const requestId = newRequestId();
|
|
865
|
+
const started = Date.now();
|
|
866
|
+
const who = { id: p.id, type: p.type, roles: p.roles };
|
|
867
|
+
try {
|
|
868
|
+
const item = (await runtime.services.invoke(capability, input, p, undefined, requestId));
|
|
869
|
+
runtime.activity.record({ kind: "service", name: capability, via: "dashboard", requestId, principal: who, outcome: "success", durationMs: Date.now() - started, detail: { id: item?.id ?? null } });
|
|
870
|
+
return sendJSON(response, 201, { item });
|
|
871
|
+
}
|
|
872
|
+
catch (error) {
|
|
873
|
+
const denied = isDenied(error);
|
|
874
|
+
runtime.activity.record({ kind: "service", name: capability, via: "dashboard", requestId, principal: who, outcome: denied ? "denied" : "error", durationMs: Date.now() - started, error: { code: denied ? "FORBIDDEN" : (error.code ?? "INTERNAL"), message: error.message } });
|
|
875
|
+
if (denied)
|
|
876
|
+
throw new FeltKitError("FORBIDDEN", `${p.id} may not ${capability === "webhooks.register" ? "register webhook endpoints" : "enqueue jobs"} (${capability}).`);
|
|
877
|
+
throw error;
|
|
878
|
+
}
|
|
879
|
+
}
|
|
779
880
|
case "POST /services/deliveries/:id/replay": {
|
|
780
881
|
await requireOperator(runtime, operator, OPERATOR_PERMISSIONS.write);
|
|
781
882
|
throw new FeltKitError("FORBIDDEN", REPLAY_DISABLED);
|
|
@@ -912,6 +1013,8 @@ async function modelsView(runtime) {
|
|
|
912
1013
|
return {
|
|
913
1014
|
status: await runtime.models.status(),
|
|
914
1015
|
intelligence: Boolean(runtime.services.intelligence),
|
|
1016
|
+
// Saved models: every one this environment has used or saved; the active one is marked.
|
|
1017
|
+
saved: runtime.services.intelligence ? await runtime.models.saved() : [],
|
|
915
1018
|
catalog: INTELLIGENCE_CATALOG.map((p) => ({ id: p.id, displayName: p.displayName, protocol: p.protocol, credential: p.credential, models: p.models.map((m) => m.id), modelSelection: p.modelSelection, endpoints: p.endpoints.map((e) => e.url), customEndpoint: p.customEndpoint })),
|
|
916
1019
|
};
|
|
917
1020
|
}
|
|
@@ -943,6 +1046,11 @@ export async function selectModel(runtime, body, options = {}) {
|
|
|
943
1046
|
let stored = null;
|
|
944
1047
|
if (apiKey)
|
|
945
1048
|
stored = await storeCredential(runtime, { ref: credentialRef, value: apiKey, provider }, options.principal ?? HOST_CUSTODY, options.via ?? "dashboard");
|
|
1049
|
+
// `activate: false`: save it to switch to later; the model in use does not change.
|
|
1050
|
+
if (body.activate === false) {
|
|
1051
|
+
await runtime.models.save({ provider, model, endpoint: typeof body.endpoint === "string" && body.endpoint ? body.endpoint : null, ...(credentialRef ? { credentialRef } : {}) }, (options.principal ?? HOST_CUSTODY).id);
|
|
1052
|
+
return stored;
|
|
1053
|
+
}
|
|
946
1054
|
await runtime.models.select({
|
|
947
1055
|
provider,
|
|
948
1056
|
model,
|
|
@@ -962,6 +1070,51 @@ async function testModel(runtime) {
|
|
|
962
1070
|
return { ok: false, error: { code: e.code ?? "INTERNAL", message: e.message, hint: e.hint ?? null, problem: e.details?.problem ?? null } };
|
|
963
1071
|
}
|
|
964
1072
|
}
|
|
1073
|
+
/**
|
|
1074
|
+
* Choices for the Services screens: notification types and webhook events (declared in
|
|
1075
|
+
* feltkit({ services }), plus those the services' records already use), job types with their
|
|
1076
|
+
* functions, the mutations that could handle a job, every capability (the application's and
|
|
1077
|
+
* AppPort Services'), and credential references with whether each is set.
|
|
1078
|
+
*/
|
|
1079
|
+
async function servicesCatalog(runtime) {
|
|
1080
|
+
const raw = runtime.instance.handle("feltkit.admin");
|
|
1081
|
+
const tenant = runtime.app.name;
|
|
1082
|
+
const observed = async (collection, pick) => {
|
|
1083
|
+
const rows = (await raw.collection(collection).find({}, { limit: 500 }).catch(() => []));
|
|
1084
|
+
return rows.filter((r) => r.tenantId === undefined || r.tenantId === tenant).flatMap((r) => [pick(r)].flat()).filter((v) => typeof v === "string" && v.length > 0);
|
|
1085
|
+
};
|
|
1086
|
+
const unique = (...lists) => [...new Set(lists.flat())].sort();
|
|
1087
|
+
const services = runtime.services;
|
|
1088
|
+
const manifest = runtime.appport.manifest();
|
|
1089
|
+
return {
|
|
1090
|
+
notificationTypes: { declared: [...services.notificationTypes], all: unique(services.notificationTypes, await observed("notifications", (r) => r.type)) },
|
|
1091
|
+
webhookEvents: {
|
|
1092
|
+
declared: [...services.webhookEvents],
|
|
1093
|
+
all: unique(services.webhookEvents, await observed("webhook_endpoints", (r) => r.events), await observed("webhook_deliveries", (r) => r.eventType)),
|
|
1094
|
+
},
|
|
1095
|
+
jobHandlers: { ...services.jobHandlers },
|
|
1096
|
+
mutations: runtime.functions().filter((f) => f.kind === "mutation").map((f) => f.name),
|
|
1097
|
+
capabilities: unique((manifest.capabilities ?? []).map((c) => c.name).filter((name) => !name.startsWith("appport.")), services.capabilities().filter((c) => c.invocable).map((c) => c.name)),
|
|
1098
|
+
credentials: (await credentialInventory(runtime)).map((c) => ({ ref: c.ref, present: Boolean(c.present), usedBy: c.usedBy ?? [] })),
|
|
1099
|
+
};
|
|
1100
|
+
}
|
|
1101
|
+
const STUDIO_SESSION_MS = 8 * 60 * 60_000;
|
|
1102
|
+
/** A session for a dev identity Studio acts as, unless it already has a live one with the same roles. */
|
|
1103
|
+
async function studioSession(runtime, principal) {
|
|
1104
|
+
const live = await runtime.resolvePrincipal(principal.id);
|
|
1105
|
+
if (live && live.roles.length === principal.roles.length && principal.roles.every((r) => live.roles.includes(r)))
|
|
1106
|
+
return;
|
|
1107
|
+
await runtime.issueSession(principal, { kind: "services-studio", label: "Studio → Services", ttlMs: STUDIO_SESSION_MS, via: "dashboard" });
|
|
1108
|
+
}
|
|
1109
|
+
/** An OpenAPI document as text: JSON only (YAML needs converting first). */
|
|
1110
|
+
function parseDocument(text) {
|
|
1111
|
+
try {
|
|
1112
|
+
return JSON.parse(text);
|
|
1113
|
+
}
|
|
1114
|
+
catch {
|
|
1115
|
+
throw new FeltKitError("INVALID_ARGUMENT", text.trim().startsWith("{") ? "The document is not valid JSON." : "Only JSON OpenAPI documents can be read here. Convert YAML to JSON first (for example: npx js-yaml openapi.yaml > openapi.json).");
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
965
1118
|
async function integrationsView(runtime) {
|
|
966
1119
|
return {
|
|
967
1120
|
integrations: runtime.integrations.definitions().map((i) => runtime.integrations.status(i)),
|