@zhin.js/host-http 1.0.0
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 +49 -0
- package/lib/console-rest-pages.d.ts +70 -0
- package/lib/console-rest-pages.js +680 -0
- package/lib/console-rpc-extended.d.ts +36 -0
- package/lib/console-rpc-extended.js +579 -0
- package/lib/console-rpc.d.ts +98 -0
- package/lib/console-rpc.js +687 -0
- package/lib/http-host.d.ts +50 -0
- package/lib/http-host.js +410 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.js +8 -0
- package/lib/json-body.d.ts +12 -0
- package/lib/json-body.js +37 -0
- package/lib/openapi.d.ts +31 -0
- package/lib/openapi.js +136 -0
- package/lib/project-files.d.ts +20 -0
- package/lib/project-files.js +145 -0
- package/lib/timing-safe-equal.d.ts +2 -0
- package/lib/timing-safe-equal.js +10 -0
- package/lib/token-registry.d.ts +20 -0
- package/lib/token-registry.js +41 -0
- package/package.json +48 -0
- package/src/console-rest-pages.ts +880 -0
- package/src/console-rpc-extended.ts +696 -0
- package/src/console-rpc.ts +759 -0
- package/src/http-host.ts +533 -0
- package/src/index.ts +63 -0
- package/src/json-body.ts +41 -0
- package/src/openapi.ts +172 -0
- package/src/project-files.ts +161 -0
- package/src/timing-safe-equal.ts +9 -0
- package/src/token-registry.ts +58 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { AuthScope } from './token-registry.js';
|
|
2
|
+
import type { DatabaseHostConsole } from '@zhin.js/plugin-runtime';
|
|
3
|
+
import { type ConsoleRpcExtendedCtx } from './console-rpc-extended.js';
|
|
4
|
+
export type RuntimeConsoleRpcMessage = {
|
|
5
|
+
readonly type?: unknown;
|
|
6
|
+
readonly requestId?: unknown;
|
|
7
|
+
readonly [key: string]: unknown;
|
|
8
|
+
};
|
|
9
|
+
export type RuntimeConsoleRpcReply = Record<string, unknown>;
|
|
10
|
+
export type RuntimeConsolePage = {
|
|
11
|
+
readonly id: string;
|
|
12
|
+
readonly localName: string;
|
|
13
|
+
readonly title: string;
|
|
14
|
+
readonly route: string;
|
|
15
|
+
readonly module: string;
|
|
16
|
+
readonly order: number;
|
|
17
|
+
readonly hash: string;
|
|
18
|
+
};
|
|
19
|
+
export type RuntimeConsoleRpcContext = {
|
|
20
|
+
readonly authScope: AuthScope;
|
|
21
|
+
listPages(): Promise<readonly RuntimeConsolePage[]>;
|
|
22
|
+
/** Optional project config accessors for read-only config RPCs. */
|
|
23
|
+
readConfigYaml?(): Promise<string>;
|
|
24
|
+
listPluginKeys?(): Promise<readonly string[]>;
|
|
25
|
+
readConfigDocument?(): Promise<Record<string, unknown>>;
|
|
26
|
+
/**
|
|
27
|
+
* Full-scope write: replace project config file contents (YAML or JSON text).
|
|
28
|
+
* Runtime Host does not hot-reload the process — callers should restart.
|
|
29
|
+
*/
|
|
30
|
+
writeConfigYaml?(yaml: string): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Full-scope write: set `document[pluginName] = data` and persist.
|
|
33
|
+
* Returns whether a process restart is required (always true without ConfigFeature).
|
|
34
|
+
*/
|
|
35
|
+
setConfigKey?(pluginName: string, data: unknown): Promise<{
|
|
36
|
+
restartRequired: boolean;
|
|
37
|
+
}>;
|
|
38
|
+
/** Project file manager (allowlisted paths under project root). */
|
|
39
|
+
listProjectFiles?(): Promise<readonly unknown[]>;
|
|
40
|
+
readProjectFile?(filePath: string): Promise<{
|
|
41
|
+
content: string;
|
|
42
|
+
size: number;
|
|
43
|
+
}>;
|
|
44
|
+
saveProjectFile?(filePath: string, content: string): Promise<void>;
|
|
45
|
+
listEnvFiles?(): Promise<readonly {
|
|
46
|
+
name: string;
|
|
47
|
+
exists: boolean;
|
|
48
|
+
}[]>;
|
|
49
|
+
readEnvFile?(filename: string): Promise<string>;
|
|
50
|
+
writeEnvFile?(filename: string, content: string): Promise<void>;
|
|
51
|
+
/** Optional schema accessors (plugin schema.json / Runtime schema registry). */
|
|
52
|
+
getSchema?(pluginName?: string): Promise<unknown>;
|
|
53
|
+
getAllSchemas?(): Promise<Record<string, unknown>>;
|
|
54
|
+
/** Optional Adapter endpoint Console surface (Sandbox / Remote Console). */
|
|
55
|
+
listEndpoints?(): Promise<readonly RuntimeEndpointSummary[]>;
|
|
56
|
+
getEndpoint?(adapter: string, endpointId: string): Promise<RuntimeEndpointSummary | null>;
|
|
57
|
+
sendEndpointMessage?(input: RuntimeEndpointSendInput): Promise<{
|
|
58
|
+
messageId: string;
|
|
59
|
+
}>;
|
|
60
|
+
/** Optional Database host surface (CLI wires DatabaseHost from plugin-runtime). */
|
|
61
|
+
dbInfo?(): Promise<RuntimeDatabaseInfo> | RuntimeDatabaseInfo;
|
|
62
|
+
dbTables?(): Promise<readonly string[]> | readonly string[];
|
|
63
|
+
database?: DatabaseHostConsole;
|
|
64
|
+
/** Full-scope: request process restart (CLI daemon watches exit code). */
|
|
65
|
+
requestRestart?(): Promise<void> | void;
|
|
66
|
+
/** Extended RPC surface(cron/schedule、endpoint 社交/inbox),fullScope 由 authScope 推导。 */
|
|
67
|
+
extended?: Omit<ConsoleRpcExtendedCtx, 'fullScope'>;
|
|
68
|
+
};
|
|
69
|
+
export type RuntimeEndpointPhase = 'pending' | 'starting' | 'online' | 'failed' | 'unconfigured';
|
|
70
|
+
export type RuntimeEndpointSummary = {
|
|
71
|
+
readonly name: string;
|
|
72
|
+
readonly adapter: string;
|
|
73
|
+
readonly connected: boolean;
|
|
74
|
+
readonly status: 'online' | 'offline';
|
|
75
|
+
readonly phase?: RuntimeEndpointPhase;
|
|
76
|
+
readonly pendingLogin?: boolean;
|
|
77
|
+
};
|
|
78
|
+
export type RuntimeDatabaseInfo = {
|
|
79
|
+
readonly dialect: string | null;
|
|
80
|
+
readonly connected: boolean;
|
|
81
|
+
readonly tables: number;
|
|
82
|
+
};
|
|
83
|
+
export type RuntimeEndpointSendInput = {
|
|
84
|
+
readonly adapter: string;
|
|
85
|
+
readonly endpointId: string;
|
|
86
|
+
readonly channelId: string;
|
|
87
|
+
readonly channelType: string;
|
|
88
|
+
readonly content: unknown;
|
|
89
|
+
readonly parent?: {
|
|
90
|
+
type?: string;
|
|
91
|
+
id?: string;
|
|
92
|
+
name?: string;
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
export declare function pickRpcReply(message: RuntimeConsoleRpcMessage, payloads: readonly RuntimeConsoleRpcReply[]): RuntimeConsoleRpcReply | null;
|
|
96
|
+
export declare function dispatchRuntimeConsoleRpc(message: RuntimeConsoleRpcMessage, ctx: RuntimeConsoleRpcContext): Promise<RuntimeConsoleRpcReply[]>;
|
|
97
|
+
/** HTTP paths under apiBase that demo scope may call (ADR 0016). */
|
|
98
|
+
export declare function isDemoHttpAllowed(method: string, pathname: string, apiBase: string): boolean;
|