@feltdb/feltkit 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +22 -2
- package/bin/feltkit.js +3 -0
- package/dist/app.d.ts +151 -0
- package/dist/app.js +130 -0
- package/dist/app.js.map +1 -0
- package/dist/cli/deploy.d.ts +8 -0
- package/dist/cli/deploy.js +125 -0
- package/dist/cli/deploy.js.map +1 -0
- package/dist/cli/main.d.ts +9 -0
- package/dist/cli/main.js +365 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/cli/output.d.ts +18 -0
- package/dist/cli/output.js +87 -0
- package/dist/cli/output.js.map +1 -0
- package/dist/client/index.d.ts +125 -0
- package/dist/client/index.js +306 -0
- package/dist/client/index.js.map +1 -0
- package/dist/dashboard/assets/index-BLnBFDJs.css +1 -0
- package/dist/dashboard/assets/index-CxJGCspE.js +15 -0
- package/dist/dashboard/index.html +16 -0
- package/dist/errors.d.ts +31 -0
- package/dist/errors.js +54 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/react/index.d.ts +40 -0
- package/dist/react/index.js +85 -0
- package/dist/react/index.js.map +1 -0
- package/dist/runtime/activity.d.ts +97 -0
- package/dist/runtime/activity.js +99 -0
- package/dist/runtime/activity.js.map +1 -0
- package/dist/runtime/authority.d.ts +78 -0
- package/dist/runtime/authority.js +176 -0
- package/dist/runtime/authority.js.map +1 -0
- package/dist/runtime/changes.d.ts +34 -0
- package/dist/runtime/changes.js +85 -0
- package/dist/runtime/changes.js.map +1 -0
- package/dist/runtime/context.d.ts +51 -0
- package/dist/runtime/context.js +2 -0
- package/dist/runtime/context.js.map +1 -0
- package/dist/runtime/data.d.ts +139 -0
- package/dist/runtime/data.js +374 -0
- package/dist/runtime/data.js.map +1 -0
- package/dist/runtime/environment.d.ts +36 -0
- package/dist/runtime/environment.js +62 -0
- package/dist/runtime/environment.js.map +1 -0
- package/dist/runtime/instance.d.ts +77 -0
- package/dist/runtime/instance.js +230 -0
- package/dist/runtime/instance.js.map +1 -0
- package/dist/runtime/loader.d.ts +11 -0
- package/dist/runtime/loader.js +99 -0
- package/dist/runtime/loader.js.map +1 -0
- package/dist/runtime/projects.d.ts +51 -0
- package/dist/runtime/projects.js +139 -0
- package/dist/runtime/projects.js.map +1 -0
- package/dist/runtime/runtime.d.ts +178 -0
- package/dist/runtime/runtime.js +448 -0
- package/dist/runtime/runtime.js.map +1 -0
- package/dist/runtime/services.d.ts +177 -0
- package/dist/runtime/services.js +418 -0
- package/dist/runtime/services.js.map +1 -0
- package/dist/runtime/sessions.d.ts +55 -0
- package/dist/runtime/sessions.js +107 -0
- package/dist/runtime/sessions.js.map +1 -0
- package/dist/schema.d.ts +56 -0
- package/dist/schema.js +44 -0
- package/dist/schema.js.map +1 -0
- package/dist/server/admin.d.ts +115 -0
- package/dist/server/admin.js +326 -0
- package/dist/server/admin.js.map +1 -0
- package/dist/server/http.d.ts +19 -0
- package/dist/server/http.js +99 -0
- package/dist/server/http.js.map +1 -0
- package/dist/server/index.d.ts +52 -0
- package/dist/server/index.js +296 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/mcp.d.ts +12 -0
- package/dist/server/mcp.js +77 -0
- package/dist/server/mcp.js.map +1 -0
- package/dist/server/project.d.ts +60 -0
- package/dist/server/project.js +331 -0
- package/dist/server/project.js.map +1 -0
- package/dist/server/public.d.ts +14 -0
- package/dist/server/public.js +15 -0
- package/dist/server/public.js.map +1 -0
- package/dist/testing/index.d.ts +20 -0
- package/dist/testing/index.js +64 -0
- package/dist/testing/index.js.map +1 -0
- package/package.json +84 -4
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sessions, stored in the application's FeltDB instance behind AppPort's
|
|
3
|
+
* `SessionStore` interface.
|
|
4
|
+
*
|
|
5
|
+
* A session id is an opaque bearer token (256 bits of randomness). Only its SHA-256
|
|
6
|
+
* digest is stored, so reading the database does not reveal usable credentials.
|
|
7
|
+
* Roles live on the session's principal; permissions are always resolved from the
|
|
8
|
+
* current policy at decision time and never cached on the session.
|
|
9
|
+
*/
|
|
10
|
+
import type { StateFirstDB } from "@feltdb/core";
|
|
11
|
+
import type { Session } from "@appport/protocol";
|
|
12
|
+
import { type Principal } from "./authority.js";
|
|
13
|
+
export declare const SESSIONS_COLLECTION = "_feltkit_sessions";
|
|
14
|
+
/** The AppPort SessionStore contract (declared structurally: @appport/core keeps it off its public surface). */
|
|
15
|
+
export interface CreateSessionInput {
|
|
16
|
+
applicationId: string;
|
|
17
|
+
principal?: Session["principal"];
|
|
18
|
+
permissions?: readonly string[];
|
|
19
|
+
ttlMs?: number;
|
|
20
|
+
attributes?: Session["attributes"];
|
|
21
|
+
}
|
|
22
|
+
export interface SessionStore {
|
|
23
|
+
create(input: CreateSessionInput): Promise<Session>;
|
|
24
|
+
get(id: string): Promise<Session | undefined>;
|
|
25
|
+
put(session: Session): Promise<void>;
|
|
26
|
+
delete(id: string): Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
export interface SessionSummary {
|
|
29
|
+
/** First 12 hex characters of the token digest. Identifies a session without revealing it. */
|
|
30
|
+
ref: string;
|
|
31
|
+
principal: Principal | null;
|
|
32
|
+
kind: string;
|
|
33
|
+
label?: string;
|
|
34
|
+
createdAt: string;
|
|
35
|
+
expiresAt?: string;
|
|
36
|
+
}
|
|
37
|
+
export declare class FeltDbSessionStore implements SessionStore {
|
|
38
|
+
#private;
|
|
39
|
+
constructor(db: StateFirstDB, options?: {
|
|
40
|
+
defaultTtlMs?: number;
|
|
41
|
+
});
|
|
42
|
+
create(input: CreateSessionInput): Promise<Session>;
|
|
43
|
+
get(token: string): Promise<Session | undefined>;
|
|
44
|
+
put(session: Session): Promise<void>;
|
|
45
|
+
delete(token: string): Promise<void>;
|
|
46
|
+
/** Revoke by summary ref (digest prefix). Returns the number revoked. */
|
|
47
|
+
revoke(ref: string): Promise<number>;
|
|
48
|
+
list(): Promise<SessionSummary[]>;
|
|
49
|
+
/** Issue a session for a FeltKit principal. */
|
|
50
|
+
issue(applicationId: string, principal: Principal, options: {
|
|
51
|
+
kind: string;
|
|
52
|
+
label?: string;
|
|
53
|
+
ttlMs?: number;
|
|
54
|
+
}): Promise<Session>;
|
|
55
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
2
|
+
import { normalizePrincipal, toAppPortPrincipal, fromAppPortPrincipal } from "./authority.js";
|
|
3
|
+
export const SESSIONS_COLLECTION = "_feltkit_sessions";
|
|
4
|
+
const digest = (token) => createHash("sha256").update(token).digest("hex");
|
|
5
|
+
export class FeltDbSessionStore {
|
|
6
|
+
#db;
|
|
7
|
+
#defaultTtlMs;
|
|
8
|
+
constructor(db, options = {}) {
|
|
9
|
+
this.#db = db;
|
|
10
|
+
this.#defaultTtlMs = options.defaultTtlMs ?? 7 * 24 * 60 * 60 * 1000;
|
|
11
|
+
}
|
|
12
|
+
async create(input) {
|
|
13
|
+
const token = `fks_${randomBytes(32).toString("base64url")}`;
|
|
14
|
+
const now = Date.now();
|
|
15
|
+
const ttl = input.ttlMs ?? this.#defaultTtlMs;
|
|
16
|
+
const record = {
|
|
17
|
+
id: digest(token),
|
|
18
|
+
...(input.principal ? { principal: input.principal } : {}),
|
|
19
|
+
applicationId: input.applicationId,
|
|
20
|
+
createdAt: new Date(now).toISOString(),
|
|
21
|
+
...(ttl > 0 ? { expiresAt: new Date(now + ttl).toISOString() } : {}),
|
|
22
|
+
...(input.attributes ? { attributes: input.attributes } : {}),
|
|
23
|
+
};
|
|
24
|
+
await this.#db.transaction({ operations: [{ collection: SESSIONS_COLLECTION, id: record.id, requireAbsent: true, value: record }] });
|
|
25
|
+
return this.#toSession(token, record);
|
|
26
|
+
}
|
|
27
|
+
async get(token) {
|
|
28
|
+
if (typeof token !== "string" || !token.startsWith("fks_") || token.length > 128)
|
|
29
|
+
return undefined;
|
|
30
|
+
const record = (await this.#db.collection(SESSIONS_COLLECTION).get(digest(token))) ?? null;
|
|
31
|
+
if (!record)
|
|
32
|
+
return undefined;
|
|
33
|
+
if (record.expiresAt && Date.parse(record.expiresAt) <= Date.now())
|
|
34
|
+
return undefined;
|
|
35
|
+
return this.#toSession(token, record);
|
|
36
|
+
}
|
|
37
|
+
async put(session) {
|
|
38
|
+
const id = digest(session.id);
|
|
39
|
+
const { permissions: _ignored, ...rest } = session;
|
|
40
|
+
const value = { ...rest, id };
|
|
41
|
+
const current = await this.#db.collection(SESSIONS_COLLECTION).get(id);
|
|
42
|
+
await this.#db.transaction({
|
|
43
|
+
operations: [
|
|
44
|
+
current
|
|
45
|
+
? { collection: SESSIONS_COLLECTION, id, ifVersion: current.__version, value: value }
|
|
46
|
+
: { collection: SESSIONS_COLLECTION, id, requireAbsent: true, value: value },
|
|
47
|
+
],
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
async delete(token) {
|
|
51
|
+
await this.#remove(digest(token));
|
|
52
|
+
}
|
|
53
|
+
/** Revoke by summary ref (digest prefix). Returns the number revoked. */
|
|
54
|
+
async revoke(ref) {
|
|
55
|
+
if (!/^[0-9a-f]{12,64}$/.test(ref))
|
|
56
|
+
return 0;
|
|
57
|
+
const matches = (await this.#db.collection(SESSIONS_COLLECTION).find({})).filter((r) => r.id.startsWith(ref));
|
|
58
|
+
if (matches.length !== 1)
|
|
59
|
+
return 0;
|
|
60
|
+
await this.#remove(matches[0].id);
|
|
61
|
+
return 1;
|
|
62
|
+
}
|
|
63
|
+
async list() {
|
|
64
|
+
const now = Date.now();
|
|
65
|
+
return (await this.#db.collection(SESSIONS_COLLECTION).find({}))
|
|
66
|
+
.filter((r) => !r.expiresAt || Date.parse(r.expiresAt) > now)
|
|
67
|
+
.map((r) => {
|
|
68
|
+
const attributes = (r.attributes ?? {});
|
|
69
|
+
return {
|
|
70
|
+
ref: r.id.slice(0, 12),
|
|
71
|
+
principal: fromAppPortPrincipal(r.principal),
|
|
72
|
+
kind: typeof attributes.kind === "string" ? attributes.kind : "session",
|
|
73
|
+
...(typeof attributes.label === "string" ? { label: attributes.label } : {}),
|
|
74
|
+
createdAt: r.createdAt,
|
|
75
|
+
...(r.expiresAt ? { expiresAt: r.expiresAt } : {}),
|
|
76
|
+
};
|
|
77
|
+
})
|
|
78
|
+
.sort((a, b) => b.createdAt.localeCompare(a.createdAt));
|
|
79
|
+
}
|
|
80
|
+
/** Issue a session for a FeltKit principal. */
|
|
81
|
+
issue(applicationId, principal, options) {
|
|
82
|
+
const normalized = normalizePrincipal(principal);
|
|
83
|
+
return this.create({
|
|
84
|
+
applicationId,
|
|
85
|
+
principal: toAppPortPrincipal(normalized),
|
|
86
|
+
...(options.ttlMs !== undefined ? { ttlMs: options.ttlMs } : {}),
|
|
87
|
+
attributes: { kind: options.kind, ...(options.label ? { label: options.label } : {}) },
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
async #remove(id) {
|
|
91
|
+
const current = await this.#db.collection(SESSIONS_COLLECTION).get(id);
|
|
92
|
+
if (!current)
|
|
93
|
+
return;
|
|
94
|
+
await this.#db.transaction({ operations: [{ collection: SESSIONS_COLLECTION, id, ifVersion: current.__version }] });
|
|
95
|
+
}
|
|
96
|
+
#toSession(token, record) {
|
|
97
|
+
return {
|
|
98
|
+
id: token,
|
|
99
|
+
...(record.principal ? { principal: record.principal } : {}),
|
|
100
|
+
applicationId: record.applicationId,
|
|
101
|
+
createdAt: record.createdAt,
|
|
102
|
+
...(record.expiresAt ? { expiresAt: record.expiresAt } : {}),
|
|
103
|
+
...(record.attributes ? { attributes: record.attributes } : {}),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=sessions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sessions.js","sourceRoot":"","sources":["../../src/runtime/sessions.ts"],"names":[],"mappings":"AAWA,OA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,EAAE,MAAM,CAAC,SAAS;YAC3B,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC5D,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAChE,CAAC;IACJ,CAAC;CACF"}
|
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Collection and argument schemas.
|
|
3
|
+
*
|
|
4
|
+
* FeltKit uses AppPort's schema builder (`s`) as its only schema language, so the
|
|
5
|
+
* same definition validates a mutation's arguments, renders an AppPort capability's
|
|
6
|
+
* JSON Schema, and validates records written through `ctx.db`.
|
|
7
|
+
*
|
|
8
|
+
* FeltDB stores JSON documents and does not itself enforce these shapes. FeltKit
|
|
9
|
+
* validates every write made through `ctx.db`; writes made through the raw FeltDB
|
|
10
|
+
* escape hatch are not validated.
|
|
11
|
+
*/
|
|
12
|
+
import { s, type Schema } from "@appport/sdk";
|
|
13
|
+
export { s };
|
|
14
|
+
export type { Schema };
|
|
15
|
+
/** Shorthand field types accepted wherever a schema is expected. */
|
|
16
|
+
export type FieldShorthand = "string" | "number" | "boolean" | "string?" | "number?" | "boolean?";
|
|
17
|
+
export type FieldInput = Schema | FieldShorthand;
|
|
18
|
+
export type ShapeInput = Record<string, FieldInput>;
|
|
19
|
+
type ShorthandType<T> = T extends "string" ? string : T extends "number" ? number : T extends "boolean" ? boolean : never;
|
|
20
|
+
type FieldType<F> = F extends Schema<infer T> ? T : F extends `${infer Base}?` ? ShorthandType<Base> | undefined : ShorthandType<F>;
|
|
21
|
+
type OptionalFieldKeys<S extends ShapeInput> = {
|
|
22
|
+
[K in keyof S]: S[K] extends `${string}?` ? K : S[K] extends {
|
|
23
|
+
isOptional: true;
|
|
24
|
+
} ? K : never;
|
|
25
|
+
}[keyof S];
|
|
26
|
+
/** The TypeScript type described by a shape. */
|
|
27
|
+
export type InferShape<S extends ShapeInput> = {
|
|
28
|
+
[K in Exclude<keyof S, OptionalFieldKeys<S>>]: FieldType<S[K]>;
|
|
29
|
+
} & {
|
|
30
|
+
[K in OptionalFieldKeys<S>]?: Exclude<FieldType<S[K]>, undefined>;
|
|
31
|
+
};
|
|
32
|
+
export type Simplify<T> = {
|
|
33
|
+
[K in keyof T]: T[K];
|
|
34
|
+
} & {};
|
|
35
|
+
/** Fields every stored record carries. `__version` is FeltDB's own record version. */
|
|
36
|
+
export interface SystemFields {
|
|
37
|
+
id: string;
|
|
38
|
+
__version: number;
|
|
39
|
+
}
|
|
40
|
+
export type Doc<S extends ShapeInput> = Simplify<InferShape<S> & SystemFields>;
|
|
41
|
+
export declare const RESERVED_FIELDS: readonly ["id", "__version"];
|
|
42
|
+
export declare function toSchema(field: FieldInput): Schema;
|
|
43
|
+
export declare function shapeToObjectSchema(shape: ShapeInput, options?: {
|
|
44
|
+
additionalProperties?: boolean;
|
|
45
|
+
}): Schema;
|
|
46
|
+
export interface ValidationIssueJSON {
|
|
47
|
+
path: string;
|
|
48
|
+
message: string;
|
|
49
|
+
}
|
|
50
|
+
export declare function validate(schema: Schema, value: unknown): {
|
|
51
|
+
ok: true;
|
|
52
|
+
value: unknown;
|
|
53
|
+
} | {
|
|
54
|
+
ok: false;
|
|
55
|
+
issues: ValidationIssueJSON[];
|
|
56
|
+
};
|
package/dist/schema.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Collection and argument schemas.
|
|
3
|
+
*
|
|
4
|
+
* FeltKit uses AppPort's schema builder (`s`) as its only schema language, so the
|
|
5
|
+
* same definition validates a mutation's arguments, renders an AppPort capability's
|
|
6
|
+
* JSON Schema, and validates records written through `ctx.db`.
|
|
7
|
+
*
|
|
8
|
+
* FeltDB stores JSON documents and does not itself enforce these shapes. FeltKit
|
|
9
|
+
* validates every write made through `ctx.db`; writes made through the raw FeltDB
|
|
10
|
+
* escape hatch are not validated.
|
|
11
|
+
*/
|
|
12
|
+
import { s } from "@appport/sdk";
|
|
13
|
+
export { s };
|
|
14
|
+
export const RESERVED_FIELDS = ["id", "__version"];
|
|
15
|
+
export function toSchema(field) {
|
|
16
|
+
if (typeof field !== "string") {
|
|
17
|
+
if (!field || field.appport !== "schema") {
|
|
18
|
+
throw new TypeError("Expected an `s.*` schema or one of \"string\", \"number\", \"boolean\" (optionally with a trailing \"?\").");
|
|
19
|
+
}
|
|
20
|
+
return field;
|
|
21
|
+
}
|
|
22
|
+
const optional = field.endsWith("?");
|
|
23
|
+
const base = optional ? field.slice(0, -1) : field;
|
|
24
|
+
const schema = base === "string" ? s.string() : base === "number" ? s.number() : base === "boolean" ? s.boolean() : undefined;
|
|
25
|
+
if (!schema)
|
|
26
|
+
throw new TypeError(`Unknown field type "${field}". Use "string", "number", "boolean", or an s.* schema.`);
|
|
27
|
+
return optional ? s.optional(schema) : schema;
|
|
28
|
+
}
|
|
29
|
+
export function shapeToObjectSchema(shape, options = {}) {
|
|
30
|
+
const fields = {};
|
|
31
|
+
for (const [key, value] of Object.entries(shape))
|
|
32
|
+
fields[key] = toSchema(value);
|
|
33
|
+
return s.object(fields, { additionalProperties: options.additionalProperties ?? false });
|
|
34
|
+
}
|
|
35
|
+
export function validate(schema, value) {
|
|
36
|
+
const result = schema.validate(value);
|
|
37
|
+
if (result.ok)
|
|
38
|
+
return { ok: true, value: result.value ?? value };
|
|
39
|
+
return {
|
|
40
|
+
ok: false,
|
|
41
|
+
issues: (result.issues ?? []).map((issue) => ({ path: (issue.path ?? []).join(".") || "(root)", message: issue.message })),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAA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,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,MAAM,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAChF,OAAO,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,oBAAoB,EAAE,OAAO,CAAC,oBAAoB,IAAI,KAAK,EAAE,CAAC,CAAC;AAC3F,CAAC;AAOD,MAAM,UAAU,QAAQ,CAAC,MAAc,EAAE,KAAc;IACrD,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAwG,CAAC;IAC7I,IAAI,MAAM,CAAC,EAAE;QAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,KAAK,EAAE,CAAC;IACjE,OAAO;QACL,EAAE,EAAE,KAAK;QACT,MAAM,EAAE,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,QAAQ,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;KAC3H,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The admin API behind the dashboard and `feltkit inspect`.
|
|
3
|
+
*
|
|
4
|
+
* Mounted at /_feltkit/api. Every request needs the environment's admin token
|
|
5
|
+
* (`x-feltkit-admin`), which lives in .feltkit/<env>/admin-token (mode 0600) and is
|
|
6
|
+
* never sent to the application's frontend. The dashboard is served only in
|
|
7
|
+
* development unless explicitly enabled, and in production every write endpoint
|
|
8
|
+
* is disabled regardless of configuration.
|
|
9
|
+
*
|
|
10
|
+
* The dashboard does not get its own authority over application behavior:
|
|
11
|
+
* - "Run function" and "Invoke capability" execute *as a chosen identity* through
|
|
12
|
+
* the same runtime.call / AppPort pipeline as any other caller, so the same
|
|
13
|
+
* access rules apply and the call is recorded with that identity.
|
|
14
|
+
* - Raw record edits (development only) are validated against the collection
|
|
15
|
+
* schema, committed through the same atomic writer, and recorded as `admin`
|
|
16
|
+
* activity by the "dashboard" principal. They are labeled as bypassing function
|
|
17
|
+
* access rules — that is what a development data editor is for.
|
|
18
|
+
*/
|
|
19
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
20
|
+
import type { FeltKitRuntime } from "../runtime/runtime.js";
|
|
21
|
+
import { type ActivityEntry } from "../runtime/activity.js";
|
|
22
|
+
export interface AdminContext {
|
|
23
|
+
runtime: FeltKitRuntime;
|
|
24
|
+
adminToken: string;
|
|
25
|
+
projectDir: string;
|
|
26
|
+
url: () => string;
|
|
27
|
+
}
|
|
28
|
+
export declare function handleAdmin(ctx: AdminContext, request: IncomingMessage, response: ServerResponse, path: string, url: URL): Promise<void>;
|
|
29
|
+
/** Everything the Overview screen and `feltkit inspect` show. Never includes credentials. */
|
|
30
|
+
export declare function overviewPayload(runtime: FeltKitRuntime): Promise<{
|
|
31
|
+
counts: Record<string, number>;
|
|
32
|
+
services: import("../runtime/services.js").ServiceStatus[];
|
|
33
|
+
capabilities: {
|
|
34
|
+
name: any;
|
|
35
|
+
version: any;
|
|
36
|
+
versions: any;
|
|
37
|
+
description: any;
|
|
38
|
+
effect: any;
|
|
39
|
+
authorization: any;
|
|
40
|
+
idempotency: any;
|
|
41
|
+
input: any;
|
|
42
|
+
output: any;
|
|
43
|
+
function: {
|
|
44
|
+
name: string;
|
|
45
|
+
kind: "query" | "mutation";
|
|
46
|
+
access: string;
|
|
47
|
+
} | null;
|
|
48
|
+
/** Observed, not declared: services these calls actually used. */
|
|
49
|
+
services: string[];
|
|
50
|
+
recent: {
|
|
51
|
+
id: string;
|
|
52
|
+
at: string;
|
|
53
|
+
outcome: "success" | "error" | "denied";
|
|
54
|
+
via: import("../runtime/activity.js").ActivityVia;
|
|
55
|
+
principal: string | null;
|
|
56
|
+
durationMs: number;
|
|
57
|
+
error: {
|
|
58
|
+
code: string;
|
|
59
|
+
message: string;
|
|
60
|
+
} | null;
|
|
61
|
+
}[];
|
|
62
|
+
}[];
|
|
63
|
+
recentActivity: ActivityEntry[];
|
|
64
|
+
recentErrors: ActivityEntry[];
|
|
65
|
+
recentDenials: ActivityEntry[];
|
|
66
|
+
devUsers: import("../app.js").DevUser[];
|
|
67
|
+
application: {
|
|
68
|
+
name: string;
|
|
69
|
+
version: string;
|
|
70
|
+
description: string | null;
|
|
71
|
+
};
|
|
72
|
+
state: import("../runtime/runtime.js").RuntimeState;
|
|
73
|
+
startedAt: string;
|
|
74
|
+
generation: number;
|
|
75
|
+
loadedAt: string;
|
|
76
|
+
environment: {
|
|
77
|
+
name: import("../runtime/environment.js").EnvironmentName;
|
|
78
|
+
production: boolean;
|
|
79
|
+
development: boolean;
|
|
80
|
+
};
|
|
81
|
+
instance: {
|
|
82
|
+
storage: string;
|
|
83
|
+
location: string;
|
|
84
|
+
sequence: number;
|
|
85
|
+
environment: string;
|
|
86
|
+
mode: "local" | "remote" | "memory";
|
|
87
|
+
namespace: string;
|
|
88
|
+
instanceId: string;
|
|
89
|
+
feltdbVersion: string;
|
|
90
|
+
durable: boolean;
|
|
91
|
+
openedAt: string;
|
|
92
|
+
pid: number;
|
|
93
|
+
};
|
|
94
|
+
collections: {
|
|
95
|
+
description?: string | undefined;
|
|
96
|
+
name: string;
|
|
97
|
+
schema: import("@appport/protocol").JSONSchema;
|
|
98
|
+
}[];
|
|
99
|
+
functions: import("../runtime/runtime.js").FunctionInfo[];
|
|
100
|
+
roles: Readonly<Record<string, readonly string[]>>;
|
|
101
|
+
policyVersion: string;
|
|
102
|
+
activity: {
|
|
103
|
+
mode: "writes" | "all" | "errors";
|
|
104
|
+
lastError: {
|
|
105
|
+
at: string;
|
|
106
|
+
message: string;
|
|
107
|
+
} | null;
|
|
108
|
+
};
|
|
109
|
+
changeFeed: {
|
|
110
|
+
lastError: string | null;
|
|
111
|
+
};
|
|
112
|
+
components: {
|
|
113
|
+
[k: string]: string[];
|
|
114
|
+
};
|
|
115
|
+
}>;
|