@feltdb/feltkit 0.3.1 → 0.3.3
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 +11 -0
- package/dist/cli/deploy.js +285 -49
- package/dist/cli/deploy.js.map +1 -1
- package/dist/cli/main.js +106 -21
- 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/connect.d.ts +65 -0
- package/dist/runtime/connect.js +246 -0
- package/dist/runtime/connect.js.map +1 -0
- package/dist/runtime/context.d.ts +6 -0
- package/dist/runtime/contract.d.ts +50 -0
- package/dist/runtime/contract.js +124 -0
- package/dist/runtime/contract.js.map +1 -0
- package/dist/runtime/data.d.ts +23 -0
- package/dist/runtime/data.js +48 -1
- package/dist/runtime/data.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 +48 -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 +41 -16
- 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 +57 -0
- package/dist/runtime/targets.js +106 -0
- package/dist/runtime/targets.js.map +1 -0
- package/dist/server/admin.d.ts +3 -1
- package/dist/server/admin.js +199 -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/http.js +3 -1
- package/dist/server/http.js.map +1 -1
- package/dist/server/index.js +55 -2
- package/dist/server/index.js.map +1 -1
- package/dist/server/management.d.ts +40 -0
- package/dist/server/management.js +93 -51
- package/dist/server/management.js.map +1 -1
- package/dist/server/project.d.ts +8 -0
- package/dist/server/project.js +27 -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-build/SKILL.md +4 -2
- package/skills/feltkit-operations/SKILL.md +18 -0
- package/skills/feltkit-services/SKILL.md +3 -3
- package/dist/dashboard/assets/index--1Tqbv_A.css +0 -1
- package/dist/dashboard/assets/index-D9529PVz.js +0 -15
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { FeltKitError, isFeltKitError } from "../errors.js";
|
|
2
|
+
import { feltdbContract } from "./contract.js";
|
|
3
|
+
const PROBE = "_feltkit_meta";
|
|
4
|
+
/** Read, then (on a server) write, then compare contracts. Local state is only read. */
|
|
5
|
+
export async function verifyStorage(environment, db, app) {
|
|
6
|
+
const storage = environment.storage;
|
|
7
|
+
const remote = storage.kind === "remote" ? storage : null;
|
|
8
|
+
try {
|
|
9
|
+
await db.collection(PROBE).get("probe");
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
throw remote ? storageError(remote, environment, error, "read") : error;
|
|
13
|
+
}
|
|
14
|
+
if (!remote)
|
|
15
|
+
return;
|
|
16
|
+
try {
|
|
17
|
+
await db.transaction({ operations: [{ collection: PROBE, id: "startup", value: { id: "startup" } }] });
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
throw storageError(remote, environment, error, "write");
|
|
21
|
+
}
|
|
22
|
+
if (remote.applicationId)
|
|
23
|
+
await verifyContract(remote, environment, db, app);
|
|
24
|
+
}
|
|
25
|
+
/** FeltDB's primitive for each contract field type (feltdb::state_contract::PrimitiveType). */
|
|
26
|
+
const PRIMITIVE = { text: "string", integer: "integer", number: "number", boolean: "boolean", json: "json" };
|
|
27
|
+
async function verifyContract(remote, environment, db, app) {
|
|
28
|
+
let active;
|
|
29
|
+
try {
|
|
30
|
+
// The active revision's schema, as FeltDB's own client reads it (application:revision:read).
|
|
31
|
+
const answer = (await db.schema.get());
|
|
32
|
+
active = answer.schema?.collections ?? [];
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
throw storageError(remote, environment, error, "contract");
|
|
36
|
+
}
|
|
37
|
+
const byName = new Map(active.map((c) => [c.name, new Map((c.fields ?? []).map((f) => [f.name, f]))]));
|
|
38
|
+
const problems = [];
|
|
39
|
+
const contract = feltdbContract(app);
|
|
40
|
+
for (const collection of contract.collections) {
|
|
41
|
+
const fields = byName.get(collection.name);
|
|
42
|
+
if (!fields) {
|
|
43
|
+
problems.push(collection.name);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
for (const field of collection.fields) {
|
|
47
|
+
const declared = fields.get(field.name);
|
|
48
|
+
if (!declared)
|
|
49
|
+
problems.push(`${collection.name}.${field.name}`);
|
|
50
|
+
else if (declared.field_type?.kind === "primitive" && declared.field_type.primitive !== PRIMITIVE[field.type]) {
|
|
51
|
+
problems.push(`${collection.name}.${field.name} (${declared.field_type.primitive}, the app stores ${field.type})`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// An index the app's reads need (a tenant-scoped read is refused without one).
|
|
56
|
+
const indexes = new Set(active.flatMap((c) => (c.indexes ?? []).map((i) => `${c.name}/${i.name}`)));
|
|
57
|
+
for (const index of contract.indexes) {
|
|
58
|
+
if (byName.has(index.collection) && !indexes.has(`${index.collection}/${index.name}`))
|
|
59
|
+
problems.push(`index ${index.name}`);
|
|
60
|
+
}
|
|
61
|
+
if (problems.length) {
|
|
62
|
+
const shown = problems.slice(0, 12).join(", ") + (problems.length > 12 ? `, and ${problems.length - 12} more` : "");
|
|
63
|
+
throw new FeltKitError("CONFIGURATION", `The active FeltDB contract for application ${remote.applicationId} (${environment.name}) does not match this app: ${shown}. Nothing was written.`, {
|
|
64
|
+
hint: "Publish the contract this build stores (it is in the deploy artifact): npx feltdb publish --contract feltdb.contract.json. Then start again.",
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function storageError(remote, environment, error, step) {
|
|
69
|
+
if (isFeltKitError(error))
|
|
70
|
+
return error;
|
|
71
|
+
const e = error;
|
|
72
|
+
const origin = new URL(remote.url).origin;
|
|
73
|
+
const where = remote.applicationId ? `application ${remote.applicationId} (${environment.name})` : `namespace "${environment.namespace}"`;
|
|
74
|
+
const reason = e.message ?? String(error);
|
|
75
|
+
if (e.status === 401 || e.code === "AUTHENTICATION_REQUIRED" || e.code === "UNAUTHORIZED") {
|
|
76
|
+
return new FeltKitError("CONFIGURATION", `FeltDB at ${origin} refused FELTDB_TOKEN (${e.code ?? "AUTHENTICATION_REQUIRED"}): ${reason}`, {
|
|
77
|
+
hint: remote.applicationId ? "Set FELTDB_TOKEN to the application's runtime key (from `feltdb init-managed`); it may have been revoked." : `Set FELTDB_TOKEN to a key the server issued for namespace "${environment.namespace}" (feltdb-server keys create --namespace ${environment.namespace}).`,
|
|
78
|
+
cause: error,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
if (e.status === 403 || e.code === "FORBIDDEN") {
|
|
82
|
+
const scope = step === "write" ? "state:write" : step === "contract" ? "application:revision:read" : "state:read";
|
|
83
|
+
return new FeltKitError("CONFIGURATION", `FELTDB_TOKEN may not ${step === "contract" ? "read the active contract of" : `${step} state in`} ${where} on ${origin} (${e.code ?? "FORBIDDEN"}): ${reason}`, {
|
|
84
|
+
hint: `Use a key with ${scope}${remote.applicationId ? " (feltdb init-managed --runtime-scopes minimal issues one)" : ` for namespace "${environment.namespace}"`}.`,
|
|
85
|
+
cause: error,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
if (e.status === 404 && step === "contract") {
|
|
89
|
+
return new FeltKitError("CONFIGURATION", `FeltDB at ${origin} has no active contract for ${where}: ${reason}`, {
|
|
90
|
+
hint: "Create the application from the artifact's contract (npx feltdb init-managed --contract feltdb.contract.json), or check FELTDB_APPLICATION_ID.",
|
|
91
|
+
cause: error,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return new FeltKitError("UNAVAILABLE", `FeltKit could not ${step === "contract" ? "read the active contract" : `${step} state`} on FeltDB at ${origin} (FELTDB_URL) for ${where}: ${reason} It does not fall back to local state.`, {
|
|
95
|
+
hint: "Check FELTDB_URL and that the server is running and reachable from this host.",
|
|
96
|
+
cause: error,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=storage-check.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage-check.js","sourceRoot":"","sources":["../../src/runtime/storage-check.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAK/C,MAAM,KAAK,GAAG,eAAe,CAAC;AAE9B,wFAAwF;AACxF,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,WAAkC,EAAE,EAAgB,EAAE,GAAe;IACvG,MAAM,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC;IACpC,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;IAC1D,IAAI,CAAC;QACH,MAAM,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC1C,CAAC;IAAC,OAAO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AK,CAAC,CAAC,IAAI,IAAI,WAAW,MAAM,MAAM,EAAE,EAAE;YACvM,IAAI,EAAE,kBAAkB,KAAK,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,4DAA4D,CAAC,CAAC,CAAC,mBAAmB,WAAW,CAAC,SAAS,GAAG,GAAG;YACpK,KAAK,EAAE,KAAK;SACb,CAAC,CAAC;IACL,CAAC;IACD,IAAI,CAAC,CAAC,MAAM,KAAK,GAAG,IAAI,IAAI,KAAK,UAAU,EAAE,CAAC;QAC5C,OAAO,IAAI,YAAY,CAAC,eAAe,EAAE,aAAa,MAAM,+BAA+B,KAAK,KAAK,MAAM,EAAE,EAAE;YAC7G,IAAI,EAAE,gJAAgJ;YACtJ,KAAK,EAAE,KAAK;SACb,CAAC,CAAC;IACL,CAAC;IACD,OAAO,IAAI,YAAY,CAAC,aAAa,EAAE,qBAAqB,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,0BAA0B,CAAC,CAAC,CAAC,GAAG,IAAI,QAAQ,iBAAiB,MAAM,qBAAqB,KAAK,KAAK,MAAM,wCAAwC,EAAE;QAClO,IAAI,EAAE,+EAA+E;QACrF,KAAK,EAAE,KAAK;KACb,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
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
|
+
*
|
|
10
|
+
* This is the one definition of each target's contract: what it needs (configuration and
|
|
11
|
+
* secrets), where state lives and how it is recovered, who may touch it, how the FeltDB side
|
|
12
|
+
* is provisioned and checked, what stops startup, how it is observed, and how it is upgraded
|
|
13
|
+
* and rolled back. `feltkit deploy` renders DEPLOY.md and .env.example from it, and the
|
|
14
|
+
* runtime enforces its storage rule at startup (runtime/environment.ts): a target never
|
|
15
|
+
* changes where state is stored. A container target with FELTDB_URL set, or a separate-app
|
|
16
|
+
* target without it, refuses to start rather than keep state somewhere else.
|
|
17
|
+
*/
|
|
18
|
+
export type DeployTarget = "container" | "hosted" | "self-hosted";
|
|
19
|
+
/**
|
|
20
|
+
* How the deployed process stores state, as FELTKIT_STORAGE. Written into the artifact's
|
|
21
|
+
* image (and `.feltkit/target.json`), so it holds however the artifact is started.
|
|
22
|
+
*
|
|
23
|
+
* local a local FeltDB directory only; FELTDB_* is refused
|
|
24
|
+
* managed Managed FeltDB: FELTDB_URL, FELTDB_TOKEN and FELTDB_APPLICATION_ID required
|
|
25
|
+
* server a FeltDB server's namespace API: FELTDB_URL and FELTDB_TOKEN required,
|
|
26
|
+
* FELTDB_APPLICATION_ID refused (that is an application-scoped authority: hosted)
|
|
27
|
+
* remote any FeltDB server (artifacts from FeltKit 0.3, before targets were explicit)
|
|
28
|
+
*/
|
|
29
|
+
export type StorageMode = "local" | "managed" | "server" | "remote";
|
|
30
|
+
export interface TargetVariable {
|
|
31
|
+
name: string;
|
|
32
|
+
/** A secret: from the platform's secret store, never in the image or a committed file. */
|
|
33
|
+
secret: boolean;
|
|
34
|
+
/** Required always, or only when the app enables API keys. */
|
|
35
|
+
required: true | "apiKeys" | false;
|
|
36
|
+
purpose: string;
|
|
37
|
+
}
|
|
38
|
+
export interface TargetContract {
|
|
39
|
+
id: DeployTarget;
|
|
40
|
+
title: string;
|
|
41
|
+
storage: StorageMode;
|
|
42
|
+
/** Where the app runs, and where its state is. */
|
|
43
|
+
runtime: string;
|
|
44
|
+
state: string;
|
|
45
|
+
variables: TargetVariable[];
|
|
46
|
+
persistence: string;
|
|
47
|
+
recovery: string;
|
|
48
|
+
identity: string;
|
|
49
|
+
provisioning: string;
|
|
50
|
+
startupFailures: string[];
|
|
51
|
+
health: string;
|
|
52
|
+
upgrade: string;
|
|
53
|
+
rollback: string;
|
|
54
|
+
}
|
|
55
|
+
export declare const TARGETS: Record<DeployTarget, TargetContract>;
|
|
56
|
+
export declare const DEPLOY_TARGETS: Record<DeployTarget, string>;
|
|
57
|
+
export declare const isDeployTarget: (value: unknown) => value is DeployTarget;
|
|
@@ -0,0 +1,106 @@
|
|
|
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
|
+
*
|
|
10
|
+
* This is the one definition of each target's contract: what it needs (configuration and
|
|
11
|
+
* secrets), where state lives and how it is recovered, who may touch it, how the FeltDB side
|
|
12
|
+
* is provisioned and checked, what stops startup, how it is observed, and how it is upgraded
|
|
13
|
+
* and rolled back. `feltkit deploy` renders DEPLOY.md and .env.example from it, and the
|
|
14
|
+
* runtime enforces its storage rule at startup (runtime/environment.ts): a target never
|
|
15
|
+
* changes where state is stored. A container target with FELTDB_URL set, or a separate-app
|
|
16
|
+
* target without it, refuses to start rather than keep state somewhere else.
|
|
17
|
+
*/
|
|
18
|
+
const VERIFIER = {
|
|
19
|
+
name: "FELTKIT_API_KEY_VERIFIER_KEY",
|
|
20
|
+
secret: true,
|
|
21
|
+
required: "apiKeys",
|
|
22
|
+
purpose: "verifies issued API keys: 32+ random bytes (openssl rand -base64 32), the same for every process; changing it invalidates every API key",
|
|
23
|
+
};
|
|
24
|
+
const SHARED_FAILURES = [
|
|
25
|
+
"FELTKIT_STATE_DIR set: it selects local state, which this target does not use",
|
|
26
|
+
"FELTDB_URL unreachable: startup stops, naming the origin; nothing is written locally",
|
|
27
|
+
"FELTDB_TOKEN refused (401): startup stops with AUTHENTICATION_REQUIRED",
|
|
28
|
+
"FELTDB_TOKEN without state:read and state:write: startup stops, naming the missing scope",
|
|
29
|
+
];
|
|
30
|
+
export const TARGETS = {
|
|
31
|
+
container: {
|
|
32
|
+
id: "container",
|
|
33
|
+
title: "Everything in one container: the app and its data (FeltDB) on a volume",
|
|
34
|
+
storage: "local",
|
|
35
|
+
runtime: "one container (or one Node process)",
|
|
36
|
+
state: "FeltDB on the /data volume (/data/state)",
|
|
37
|
+
variables: [
|
|
38
|
+
{ name: "FELTKIT_API_KEY_VERIFIER_KEY", secret: true, required: false, purpose: "overrides the verifier key kept beside the state (/data/state-api-key-verifier)" },
|
|
39
|
+
],
|
|
40
|
+
persistence: "FeltDB state and the keys kept beside it are on the /data volume. The container's own filesystem holds nothing that must survive.",
|
|
41
|
+
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.",
|
|
42
|
+
identity: "Sessions and API keys are issued by this app (`feltkit session create`, Studio); the volume holds them. Only this process opens the state.",
|
|
43
|
+
provisioning: "None: the state is created on first start. There is no separate database to provision or contract to publish.",
|
|
44
|
+
startupFailures: [
|
|
45
|
+
"FELTDB_URL, FELTDB_TOKEN or FELTDB_APPLICATION_ID set: this target keeps state on its volume, so it refuses rather than store it elsewhere",
|
|
46
|
+
"the volume's state open in another process: startup stops, naming its owner",
|
|
47
|
+
],
|
|
48
|
+
health: "GET /_feltkit/health (the image's HEALTHCHECK). `npx feltkit readiness --env production` with the container stopped reports durability and keys.",
|
|
49
|
+
upgrade: "Deploy again and start the new image on the same volume. FeltDB opens state written by earlier versions.",
|
|
50
|
+
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.",
|
|
51
|
+
},
|
|
52
|
+
hosted: {
|
|
53
|
+
id: "hosted",
|
|
54
|
+
title: "App container only; data in Managed FeltDB (hosted)",
|
|
55
|
+
storage: "managed",
|
|
56
|
+
runtime: "a stateless app container, any number of them",
|
|
57
|
+
state: "Managed FeltDB, one application per app (FELTDB_APPLICATION_ID)",
|
|
58
|
+
variables: [
|
|
59
|
+
{ name: "FELTDB_URL", secret: false, required: true, purpose: "Managed FeltDB's API origin (https)" },
|
|
60
|
+
{ name: "FELTDB_APPLICATION_ID", secret: false, required: true, purpose: "the managed application, from `feltdb init-managed`" },
|
|
61
|
+
{ name: "FELTDB_TOKEN", secret: true, required: true, purpose: "the application's runtime key (never the control key)" },
|
|
62
|
+
VERIFIER,
|
|
63
|
+
],
|
|
64
|
+
persistence: "All state is in Managed FeltDB. The container holds none: replace, scale or move it freely.",
|
|
65
|
+
recovery: "Managed FeltDB keeps and recovers the state. A restarted or replaced container reads the same state.",
|
|
66
|
+
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.",
|
|
67
|
+
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.",
|
|
68
|
+
startupFailures: [
|
|
69
|
+
"FELTDB_URL, FELTDB_TOKEN or FELTDB_APPLICATION_ID missing: startup stops, naming it",
|
|
70
|
+
...SHARED_FAILURES,
|
|
71
|
+
"active contract missing a collection or field the app stores: startup stops, listing them; publish the artifact's feltdb.contract.json",
|
|
72
|
+
"FELTKIT_API_KEY_VERIFIER_KEY missing with API keys enabled: startup stops (there is no shared disk to keep one on)",
|
|
73
|
+
],
|
|
74
|
+
health: "GET /_feltkit/health. Startup has already proved FeltDB answers with this key and contract.",
|
|
75
|
+
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.",
|
|
76
|
+
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.",
|
|
77
|
+
},
|
|
78
|
+
"self-hosted": {
|
|
79
|
+
id: "self-hosted",
|
|
80
|
+
title: "App container only; data on a FeltDB server you operate",
|
|
81
|
+
storage: "server",
|
|
82
|
+
runtime: "a stateless app container, any number of them",
|
|
83
|
+
state: "your `feltdb-server`, in the namespace named after the app",
|
|
84
|
+
variables: [
|
|
85
|
+
{ name: "FELTDB_URL", secret: false, required: true, purpose: "your FeltDB server's origin (https, or a private network address)" },
|
|
86
|
+
{ name: "FELTDB_TOKEN", secret: true, required: true, purpose: "a key for the app's namespace with state:read,state:write" },
|
|
87
|
+
VERIFIER,
|
|
88
|
+
],
|
|
89
|
+
persistence: "All state is on your FeltDB server, in the app's namespace. The container holds none.",
|
|
90
|
+
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.",
|
|
91
|
+
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.",
|
|
92
|
+
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.",
|
|
93
|
+
startupFailures: [
|
|
94
|
+
"FELTDB_URL or FELTDB_TOKEN missing: startup stops, naming it",
|
|
95
|
+
"FELTDB_APPLICATION_ID set: that is an application-scoped authority; use the hosted target",
|
|
96
|
+
...SHARED_FAILURES,
|
|
97
|
+
"FELTKIT_API_KEY_VERIFIER_KEY missing with API keys enabled: startup stops",
|
|
98
|
+
],
|
|
99
|
+
health: "GET /_feltkit/health. Startup has already proved the server answers with this key.",
|
|
100
|
+
upgrade: "Deploy again and start the new image; upgrade the server separately, following FeltDB's notes.",
|
|
101
|
+
rollback: "Start the previous image against the same server.",
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
export const DEPLOY_TARGETS = Object.fromEntries(Object.values(TARGETS).map((t) => [t.id, t.title]));
|
|
105
|
+
export const isDeployTarget = (value) => typeof value === "string" && value in TARGETS;
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AC9D;CACF,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.d.ts
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* access rules — that is what a development data editor is for.
|
|
18
18
|
*/
|
|
19
19
|
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
20
|
-
import type { RunningConsole } from "./management.js";
|
|
20
|
+
import type { EmbeddedManagement, RunningConsole } from "./management.js";
|
|
21
21
|
import type { FeltKitRuntime } from "../runtime/runtime.js";
|
|
22
22
|
import type { Principal } from "../runtime/authority.js";
|
|
23
23
|
import { type ActivityEntry } from "../runtime/activity.js";
|
|
@@ -28,6 +28,8 @@ export interface AdminContext {
|
|
|
28
28
|
url: () => string;
|
|
29
29
|
/** The AppPort Services management console, when one is served. */
|
|
30
30
|
console?: RunningConsole | null;
|
|
31
|
+
/** AppPort Services' management contract for Studio's own Services screens (development only). */
|
|
32
|
+
management?: EmbeddedManagement | null;
|
|
31
33
|
}
|
|
32
34
|
export declare function handleAdmin(ctx: AdminContext, request: IncomingMessage, response: ServerResponse, path: string, url: URL): Promise<void>;
|
|
33
35
|
/** Everything the Overview screen and `feltkit inspect` show. Never includes credentials. */
|
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,62 @@ 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
|
+
}
|
|
251
|
+
// Studio's Services screens: AppPort Services' own management contract (the routes its
|
|
252
|
+
// packaged pages call), as the dev identity named in `x-feltkit-as`. Authorized by the
|
|
253
|
+
// services' gateway; FeltKit adds no second authorization layer.
|
|
254
|
+
if (segments[0] === "services" && segments[1] === "manage") {
|
|
255
|
+
requireDevelopment("Managing services from Studio");
|
|
256
|
+
if (!ctx.management)
|
|
257
|
+
throw new FeltKitError("NOT_FOUND", "Service management is not served here.");
|
|
258
|
+
const principal = identityFor(runtime, request.headers["x-feltkit-as"]);
|
|
259
|
+
if (!principal)
|
|
260
|
+
throw new FeltKitError("INVALID_ARGUMENT", "Choose a dev identity; service operations are authorized as that identity.");
|
|
261
|
+
const rest = path.slice(path.indexOf("/manage") + "/manage".length) || "/";
|
|
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);
|
|
268
|
+
return await ctx.management.handle(request, response, principal);
|
|
269
|
+
}
|
|
270
|
+
// Files with their bytes: FeltKit stores content in the same instance (runtime/content.ts),
|
|
271
|
+
// so uploads and deletes go through FeltKit's Files, authorized by the gateway as `as`.
|
|
272
|
+
if (segments[0] === "services" && segments[1] === "files" && (segments.length === 2 || segments.length === 3 || (segments.length === 4 && segments[3] === "content"))) {
|
|
273
|
+
requireDevelopment("Managing files from Studio");
|
|
274
|
+
const body = method === "POST" ? await readJSON(request) : {};
|
|
275
|
+
const principal = identityFor(runtime, method === "POST" ? body.as : url.searchParams.get("as") ?? request.headers["x-feltkit-as"]);
|
|
276
|
+
if (!principal)
|
|
277
|
+
throw new FeltKitError("INVALID_ARGUMENT", "Choose a dev identity; the file operation is authorized as that identity.");
|
|
278
|
+
const requestId = `req_${randomUUID()}`;
|
|
279
|
+
const release = runtime.services.enter(requestId, principal);
|
|
280
|
+
try {
|
|
281
|
+
const files = runtime.services.bind(principal, requestId, new Set(), true).files;
|
|
282
|
+
if (method === "POST" && segments.length === 2) {
|
|
283
|
+
if (typeof body.contentBase64 !== "string")
|
|
284
|
+
throw new FeltKitError("INVALID_ARGUMENT", "Send the file as contentBase64.");
|
|
285
|
+
const file = await files.upload({ name: String(body.name ?? ""), ...(typeof body.contentType === "string" && body.contentType ? { contentType: body.contentType } : {}), content: new Uint8Array(Buffer.from(body.contentBase64, "base64")) });
|
|
286
|
+
return sendJSON(response, 201, { file });
|
|
287
|
+
}
|
|
288
|
+
if (method === "GET" && segments.length === 4) {
|
|
289
|
+
const { file, bytes } = await files.read(segments[2]);
|
|
290
|
+
return sendJSON(response, 200, { file, contentBase64: Buffer.from(bytes).toString("base64") });
|
|
291
|
+
}
|
|
292
|
+
if (method === "DELETE" && segments.length === 3) {
|
|
293
|
+
await files.remove(segments[2]);
|
|
294
|
+
return sendJSON(response, 200, { ok: true });
|
|
295
|
+
}
|
|
296
|
+
throw new FeltKitError("NOT_FOUND", `${method} ${path} is not a file operation.`);
|
|
297
|
+
}
|
|
298
|
+
finally {
|
|
299
|
+
release();
|
|
300
|
+
}
|
|
301
|
+
}
|
|
243
302
|
// Execution and delivery history, from the services' own records.
|
|
244
303
|
if (method === "GET" && segments[0] === "services" && segments[1] === "jobs" && segments.length === 2) {
|
|
245
304
|
const jobs = runtime.services.jobs;
|
|
@@ -307,8 +366,69 @@ export async function handleAdmin(ctx, request, response, path, url) {
|
|
|
307
366
|
}
|
|
308
367
|
if (method === "POST" && segments[0] === "models" && segments[1] === "test" && segments.length === 2)
|
|
309
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
|
+
}
|
|
310
385
|
if (method === "GET" && segments[0] === "integrations" && segments.length === 1)
|
|
311
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
|
+
}
|
|
312
432
|
if (method === "POST" && segments[0] === "integrations" && segments[2] === "check" && segments.length === 3)
|
|
313
433
|
return sendJSON(response, 200, await runtime.integrations.check(segments[1]));
|
|
314
434
|
// Credentials: references, where each value is kept, and a write path that never echoes it.
|
|
@@ -730,6 +850,33 @@ async function handleProduction(ctx, request, response, path, url) {
|
|
|
730
850
|
throw error;
|
|
731
851
|
}
|
|
732
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
|
+
}
|
|
733
880
|
case "POST /services/deliveries/:id/replay": {
|
|
734
881
|
await requireOperator(runtime, operator, OPERATOR_PERMISSIONS.write);
|
|
735
882
|
throw new FeltKitError("FORBIDDEN", REPLAY_DISABLED);
|
|
@@ -866,6 +1013,8 @@ async function modelsView(runtime) {
|
|
|
866
1013
|
return {
|
|
867
1014
|
status: await runtime.models.status(),
|
|
868
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() : [],
|
|
869
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 })),
|
|
870
1019
|
};
|
|
871
1020
|
}
|
|
@@ -897,6 +1046,11 @@ export async function selectModel(runtime, body, options = {}) {
|
|
|
897
1046
|
let stored = null;
|
|
898
1047
|
if (apiKey)
|
|
899
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
|
+
}
|
|
900
1054
|
await runtime.models.select({
|
|
901
1055
|
provider,
|
|
902
1056
|
model,
|
|
@@ -916,6 +1070,51 @@ async function testModel(runtime) {
|
|
|
916
1070
|
return { ok: false, error: { code: e.code ?? "INTERNAL", message: e.message, hint: e.hint ?? null, problem: e.details?.problem ?? null } };
|
|
917
1071
|
}
|
|
918
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
|
+
}
|
|
919
1118
|
async function integrationsView(runtime) {
|
|
920
1119
|
return {
|
|
921
1120
|
integrations: runtime.integrations.definitions().map((i) => runtime.integrations.status(i)),
|