@siming-org/server 0.3.0 → 0.5.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/dist/chunk-XZWVPHDG.js +2980 -0
- package/dist/index.d.ts +39 -2
- package/dist/index.js +3 -1
- package/dist/main.js +43 -3
- package/package.json +2 -2
- package/web-dist/assets/index-CDjWDFDb.js +150 -0
- package/web-dist/assets/index-DRm1IYKE.css +1 -0
- package/web-dist/index.html +2 -2
- package/dist/chunk-T7QAGG73.js +0 -1558
- package/web-dist/assets/index-B_ZlCIgd.css +0 -1
- package/web-dist/assets/index-hBW7IJvz.js +0 -121
package/dist/index.d.ts
CHANGED
|
@@ -2,11 +2,48 @@ import { Hono } from 'hono';
|
|
|
2
2
|
import { SimingClient, SimingConfig } from '@siming-org/core';
|
|
3
3
|
import { ServerType } from '@hono/node-server';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* 认证中间件(T202608310001 F3)——鉴权三层模型的第一层。
|
|
7
|
+
* 职责:① 预鉴权可达端点直通(whoami 除外——做尝试性凭证解析,失败落 none 不 401)
|
|
8
|
+
* ② open 模式直通 ③ Bearer Token / 会话 Cookie 认证 ④ admin-only 端点集中拦截。
|
|
9
|
+
* 错误通道:core AppError 子类(UnauthorizedError 401 / ForbiddenError 403),onError 单源响应。
|
|
10
|
+
* 资源级归属校验(assertProjectScope/resolveProjectFilter)由各路由 handler 经 routes/auth-guard.ts 承担。
|
|
11
|
+
*/
|
|
12
|
+
/** 请求认证上下文(app Variables 注入,handler 经 c.get('auth') 消费) */
|
|
13
|
+
type AuthContext = {
|
|
14
|
+
kind: 'open';
|
|
15
|
+
} | {
|
|
16
|
+
kind: 'admin';
|
|
17
|
+
} | {
|
|
18
|
+
kind: 'project';
|
|
19
|
+
projectId: string;
|
|
20
|
+
} | {
|
|
21
|
+
kind: 'none';
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* admin-only 路由表(D8:按 routes/ 真实路由表机械枚举——project 上下文命中即 403)。
|
|
25
|
+
* ⚠ 新增/变更端点必须同步本表(E2E 403 矩阵从同一路由清单遍历生成,防手写漏项)。
|
|
26
|
+
* skill/agent 的作用域相关写(scope=global 创建/copy)路径级无法判定 → 由 handler 级
|
|
27
|
+
* requireAdminLike 承担(见 routes/auth-guard.ts)。不含:auth/password(会话/admin token 均可用)。
|
|
28
|
+
*/
|
|
29
|
+
declare const ADMIN_ONLY_ROUTES: readonly {
|
|
30
|
+
method: string;
|
|
31
|
+
pattern: RegExp;
|
|
32
|
+
}[];
|
|
33
|
+
|
|
5
34
|
interface CreateAppOptions {
|
|
6
35
|
/** Web UI 根目录注入(测试用);null = 显式禁用静态服务。默认走解析链 resolveWebDistRoot() */
|
|
7
36
|
webRoot?: string | null;
|
|
37
|
+
/** 鉴权开关(T202608310001 F1):默认 false = 现状全权(存量行为零破坏) */
|
|
38
|
+
authEnabled?: boolean;
|
|
39
|
+
}
|
|
40
|
+
/** Hono Variables:认证上下文(中间件注入,守卫/路由消费) */
|
|
41
|
+
interface AuthEnv {
|
|
42
|
+
Variables: {
|
|
43
|
+
auth: AuthContext;
|
|
44
|
+
};
|
|
8
45
|
}
|
|
9
|
-
declare function createApp(client: SimingClient, opts?: CreateAppOptions): Hono
|
|
46
|
+
declare function createApp(client: SimingClient, opts?: CreateAppOptions): Hono<AuthEnv>;
|
|
10
47
|
|
|
11
48
|
/**
|
|
12
49
|
* startServer(N018 §2/D2 拆分):main.ts 薄壳化后由两处消费——
|
|
@@ -44,4 +81,4 @@ declare function resolveWebDistRoot(): string | null;
|
|
|
44
81
|
*/
|
|
45
82
|
declare function createStaticRoutes(webRoot: string | null): Hono;
|
|
46
83
|
|
|
47
|
-
export { type CreateAppOptions, MONGO_PROBE_TIMEOUT_MS, type RunningServer, createApp, createStaticRoutes, resolveWebDistRoot, startServer };
|
|
84
|
+
export { ADMIN_ONLY_ROUTES, type AuthContext, type CreateAppOptions, MONGO_PROBE_TIMEOUT_MS, type RunningServer, createApp, createStaticRoutes, resolveWebDistRoot, startServer };
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
|
+
ADMIN_ONLY_ROUTES,
|
|
2
3
|
MONGO_PROBE_TIMEOUT_MS,
|
|
3
4
|
createApp,
|
|
4
5
|
createStaticRoutes,
|
|
5
6
|
resolveWebDistRoot,
|
|
6
7
|
startServer
|
|
7
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-XZWVPHDG.js";
|
|
8
9
|
export {
|
|
10
|
+
ADMIN_ONLY_ROUTES,
|
|
9
11
|
MONGO_PROBE_TIMEOUT_MS,
|
|
10
12
|
createApp,
|
|
11
13
|
createStaticRoutes,
|
package/dist/main.js
CHANGED
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
import {
|
|
2
2
|
startServer
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-XZWVPHDG.js";
|
|
4
4
|
|
|
5
5
|
// src/config/env.ts
|
|
6
|
-
import { SIMING_CONFIG_ENV_KEYS, SIMING_CONFIG_KEYS, SimingConfigSchema } from "@siming-org/core";
|
|
6
|
+
import { SIMING_CONFIG_ENV_KEYS, SIMING_CONFIG_KEYS, SimingConfigSchema, parseAuthEnabledEnvValue } from "@siming-org/core";
|
|
7
7
|
function parseEnv(processEnv = process.env) {
|
|
8
8
|
const input = {};
|
|
9
9
|
for (const key of SIMING_CONFIG_KEYS) {
|
|
10
10
|
const value = processEnv[SIMING_CONFIG_ENV_KEYS[key]];
|
|
11
|
-
if (value
|
|
11
|
+
if (value === void 0) continue;
|
|
12
|
+
if (key === "auth") {
|
|
13
|
+
try {
|
|
14
|
+
input[key] = { enabled: parseAuthEnabledEnvValue(value) };
|
|
15
|
+
} catch (e) {
|
|
16
|
+
console.error(`Invalid environment configuration:
|
|
17
|
+
${SIMING_CONFIG_ENV_KEYS[key]}: ${e instanceof Error ? e.message : String(e)}`);
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
input[key] = value;
|
|
12
23
|
}
|
|
13
24
|
const result = SimingConfigSchema.safeParse(input);
|
|
14
25
|
if (!result.success) {
|
|
@@ -21,7 +32,36 @@ function parseEnv(processEnv = process.env) {
|
|
|
21
32
|
return result.data;
|
|
22
33
|
}
|
|
23
34
|
|
|
35
|
+
// src/config/workspace-guard.ts
|
|
36
|
+
import { existsSync } from "fs";
|
|
37
|
+
import { dirname } from "path";
|
|
38
|
+
import { fileURLToPath } from "url";
|
|
39
|
+
import { SIMING_CONFIG_ENV_KEYS as SIMING_CONFIG_ENV_KEYS2 } from "@siming-org/core";
|
|
40
|
+
function findDevJsonDir(startDirs, exists = existsSync) {
|
|
41
|
+
for (const startDir of startDirs) {
|
|
42
|
+
let current = startDir;
|
|
43
|
+
for (; ; ) {
|
|
44
|
+
if (exists(`${current}/.siming/dev.json`)) return current;
|
|
45
|
+
const parent = dirname(current);
|
|
46
|
+
if (parent === current) break;
|
|
47
|
+
current = parent;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
function assertDirectStartAllowed(processEnv = process.env, startDirs = [dirname(fileURLToPath(import.meta.url)), process.cwd()], exists = existsSync) {
|
|
53
|
+
const hasPort = processEnv[SIMING_CONFIG_ENV_KEYS2.port] !== void 0;
|
|
54
|
+
const hasMongoUri = processEnv[SIMING_CONFIG_ENV_KEYS2.mongoUri] !== void 0;
|
|
55
|
+
if (hasPort && hasMongoUri) return;
|
|
56
|
+
if (findDevJsonDir(startDirs, exists) === null) return;
|
|
57
|
+
console.error("[siming] \u68C0\u6D4B\u5230\u5E76\u884C\u5F00\u53D1\u5DE5\u4F5C\u533A\uFF08.siming/dev.json\uFF09\uFF0C\u4F46 server \u76F4\u542F\u7F3A\u5C11\u9694\u79BB\u914D\u7F6E\uFF0C\u62D2\u7EDD\u542F\u52A8\uFF1A");
|
|
58
|
+
console.error(" \u6B63\u786E\u5165\u53E3\uFF1Apnpm dev \u6216 bash scripts/dev-server.sh");
|
|
59
|
+
console.error(` \u6216\u663E\u5F0F\u4F20\u5165 ${SIMING_CONFIG_ENV_KEYS2.port} \u4E0E ${SIMING_CONFIG_ENV_KEYS2.mongoUri} \u540E\u76F4\u542F`);
|
|
60
|
+
process.exit(1);
|
|
61
|
+
}
|
|
62
|
+
|
|
24
63
|
// src/main.ts
|
|
64
|
+
assertDirectStartAllowed();
|
|
25
65
|
var env = parseEnv();
|
|
26
66
|
async function bootstrap() {
|
|
27
67
|
const running = await startServer(env);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@siming-org/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Wuchao",
|
|
6
6
|
"engines": {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"@hono/zod-validator": "^0.4.2",
|
|
22
22
|
"hono": "^4.6.0",
|
|
23
23
|
"zod": "^4.4.3",
|
|
24
|
-
"@siming-org/core": "0.
|
|
24
|
+
"@siming-org/core": "0.5.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/node": "^26.2.0",
|