@actiondock/core 2.0.11 → 2.2.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/README.md +61 -30
- package/dist/app/app.d.ts +73 -0
- package/dist/app/app.js +700 -0
- package/dist/app/index.d.ts +2 -0
- package/dist/app/index.js +2 -0
- package/dist/app/types.d.ts +283 -0
- package/dist/app/types.js +1 -0
- package/dist/catalog/action-index.d.ts +9 -0
- package/dist/catalog/action-index.js +93 -0
- package/dist/catalog/action-resolver.d.ts +20 -0
- package/dist/catalog/action-resolver.js +95 -0
- package/dist/catalog/index.d.ts +5 -0
- package/dist/catalog/index.js +5 -0
- package/dist/catalog/location-registry.d.ts +15 -0
- package/dist/catalog/location-registry.js +138 -0
- package/dist/catalog/package-catalog.d.ts +7 -0
- package/dist/catalog/package-catalog.js +76 -0
- package/dist/catalog/types.d.ts +68 -0
- package/dist/catalog/types.js +1 -0
- package/dist/doctor/doctor.d.ts +7 -0
- package/dist/doctor/doctor.js +613 -0
- package/dist/doctor/index.d.ts +2 -0
- package/dist/doctor/index.js +2 -0
- package/dist/doctor/types.d.ts +23 -0
- package/dist/doctor/types.js +1 -0
- package/dist/errors.d.ts +122 -0
- package/dist/errors.js +123 -0
- package/dist/execution/index.d.ts +2 -0
- package/dist/execution/index.js +2 -0
- package/dist/execution/service.d.ts +79 -0
- package/dist/execution/service.js +633 -0
- package/dist/execution/types.d.ts +131 -0
- package/dist/execution/types.js +1 -0
- package/dist/export/index.d.ts +1 -0
- package/dist/export/index.js +1 -0
- package/dist/export/templates.d.ts +71 -0
- package/dist/export/templates.js +621 -0
- package/dist/filter/index.d.ts +1 -0
- package/dist/filter/index.js +1 -0
- package/dist/filter/intent.d.ts +33 -0
- package/dist/filter/intent.js +123 -0
- package/dist/host/host.d.ts +55 -0
- package/dist/host/host.js +740 -0
- package/dist/host/index.d.ts +2 -0
- package/dist/host/index.js +2 -0
- package/dist/host/types.d.ts +81 -0
- package/dist/host/types.js +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +20 -0
- package/dist/ipc/diagnostic.d.ts +65 -0
- package/dist/ipc/diagnostic.js +129 -0
- package/dist/ipc/host.d.ts +7 -0
- package/dist/ipc/host.js +93 -0
- package/dist/ipc/index.d.ts +4 -0
- package/dist/ipc/index.js +4 -0
- package/dist/ipc/target.d.ts +56 -0
- package/dist/ipc/target.js +297 -0
- package/dist/ipc/types.d.ts +42 -0
- package/dist/ipc/types.js +1 -0
- package/dist/platform/default.d.ts +32 -0
- package/dist/platform/default.js +40 -0
- package/dist/platform/index.d.ts +3 -0
- package/dist/platform/index.js +3 -0
- package/dist/platform/node-fs.d.ts +37 -0
- package/dist/platform/node-fs.js +81 -0
- package/dist/platform/types.d.ts +104 -0
- package/dist/platform/types.js +1 -0
- package/dist/profile/client.d.ts +162 -0
- package/dist/profile/client.js +467 -0
- package/dist/profile/index.d.ts +3 -0
- package/dist/profile/index.js +3 -0
- package/dist/profile/manager.d.ts +47 -0
- package/dist/profile/manager.js +294 -0
- package/dist/profile/types.d.ts +61 -0
- package/dist/profile/types.js +1 -0
- package/dist/project/closure.d.ts +25 -0
- package/dist/project/closure.js +68 -0
- package/dist/project/digest.d.ts +29 -0
- package/dist/project/digest.js +324 -0
- package/dist/project/index.d.ts +10 -0
- package/dist/project/index.js +10 -0
- package/dist/project/init.d.ts +26 -0
- package/dist/project/init.js +175 -0
- package/dist/project/loader.d.ts +99 -0
- package/dist/project/loader.js +484 -0
- package/dist/project/lockfile.d.ts +55 -0
- package/dist/project/lockfile.js +175 -0
- package/dist/project/manifest.d.ts +22 -0
- package/dist/project/manifest.js +220 -0
- package/dist/project/resolver.d.ts +116 -0
- package/dist/project/resolver.js +376 -0
- package/dist/project/transactions.d.ts +103 -0
- package/dist/project/transactions.js +1203 -0
- package/dist/project/types-generator.d.ts +33 -0
- package/dist/project/types-generator.js +168 -0
- package/dist/project/types.d.ts +107 -0
- package/dist/project/types.js +1 -0
- package/dist/registry/index.d.ts +5 -0
- package/dist/registry/index.js +5 -0
- package/dist/registry/lock.d.ts +27 -0
- package/dist/registry/lock.js +93 -0
- package/dist/registry/registry.d.ts +45 -0
- package/dist/registry/registry.js +611 -0
- package/dist/registry/resolve.d.ts +62 -0
- package/dist/registry/resolve.js +195 -0
- package/dist/registry/scan.d.ts +38 -0
- package/dist/registry/scan.js +135 -0
- package/dist/registry/types.d.ts +117 -0
- package/dist/registry/types.js +1 -0
- package/dist/runtime/action-collection.d.ts +27 -0
- package/dist/runtime/action-collection.js +57 -0
- package/dist/runtime/clock.d.ts +19 -0
- package/dist/runtime/clock.js +17 -0
- package/dist/runtime/context.d.ts +86 -0
- package/dist/runtime/context.js +242 -0
- package/dist/runtime/env.d.ts +56 -0
- package/dist/runtime/env.js +159 -0
- package/dist/runtime/events.d.ts +93 -0
- package/dist/runtime/events.js +604 -0
- package/dist/runtime/execution-manager.d.ts +48 -0
- package/dist/runtime/execution-manager.js +66 -0
- package/dist/runtime/index.d.ts +10 -0
- package/dist/runtime/index.js +10 -0
- package/dist/runtime/module-loader.d.ts +34 -0
- package/dist/runtime/module-loader.js +16 -0
- package/dist/runtime/process.d.ts +9 -0
- package/dist/runtime/process.js +146 -0
- package/dist/runtime/runner.d.ts +293 -0
- package/dist/runtime/runner.js +984 -0
- package/dist/runtime/standalone.d.ts +89 -0
- package/dist/runtime/standalone.js +536 -0
- package/dist/schema/validator.d.ts +28 -0
- package/dist/schema/validator.js +116 -0
- package/dist/server/body.d.ts +40 -0
- package/dist/server/body.js +93 -0
- package/dist/server/index.d.ts +5 -0
- package/dist/server/index.js +5 -0
- package/dist/server/routes/actions.d.ts +5 -0
- package/dist/server/routes/actions.js +298 -0
- package/dist/server/routes/common.d.ts +47 -0
- package/dist/server/routes/common.js +104 -0
- package/dist/server/routes/config.d.ts +6 -0
- package/dist/server/routes/config.js +173 -0
- package/dist/server/routes/doctor.d.ts +5 -0
- package/dist/server/routes/doctor.js +63 -0
- package/dist/server/routes/health.d.ts +5 -0
- package/dist/server/routes/health.js +35 -0
- package/dist/server/routes/index.d.ts +9 -0
- package/dist/server/routes/index.js +9 -0
- package/dist/server/routes/info.d.ts +7 -0
- package/dist/server/routes/info.js +158 -0
- package/dist/server/routes/playbooks.d.ts +5 -0
- package/dist/server/routes/playbooks.js +134 -0
- package/dist/server/routes/runs.d.ts +5 -0
- package/dist/server/routes/runs.js +343 -0
- package/dist/server/routes/state.d.ts +6 -0
- package/dist/server/routes/state.js +169 -0
- package/dist/server/security.d.ts +44 -0
- package/dist/server/security.js +101 -0
- package/dist/server/server.d.ts +15 -0
- package/dist/server/server.js +355 -0
- package/dist/server/types.d.ts +78 -0
- package/dist/server/types.js +1 -0
- package/dist/storage/data-dir-lock.d.ts +119 -0
- package/dist/storage/data-dir-lock.js +1016 -0
- package/dist/storage/driver.d.ts +9 -0
- package/dist/storage/driver.js +59 -0
- package/dist/storage/index.d.ts +64 -0
- package/dist/storage/index.js +98 -0
- package/dist/storage/lazy.d.ts +8 -0
- package/dist/storage/lazy.js +44 -0
- package/dist/storage/mask.d.ts +26 -0
- package/dist/storage/mask.js +48 -0
- package/dist/storage/params.d.ts +13 -0
- package/dist/storage/params.js +32 -0
- package/dist/storage/sqlite.d.ts +79 -0
- package/dist/storage/sqlite.js +689 -0
- package/dist/storage/types.d.ts +172 -0
- package/dist/storage/types.js +14 -0
- package/dist/target/index.d.ts +4 -0
- package/dist/target/index.js +4 -0
- package/dist/target/local.d.ts +52 -0
- package/dist/target/local.js +343 -0
- package/dist/target/remote.d.ts +76 -0
- package/dist/target/remote.js +839 -0
- package/dist/target/target.d.ts +6 -0
- package/dist/target/target.js +35 -0
- package/dist/target/types.d.ts +246 -0
- package/dist/target/types.js +34 -0
- package/dist/utils/index.d.ts +49 -0
- package/dist/utils/index.js +180 -0
- package/dist/version.d.ts +4 -0
- package/dist/version.js +4 -0
- package/package.json +13 -13
- package/src/build/index.ts +0 -1
- package/src/build/templates.ts +0 -59
- package/src/catalog/action-index.ts +0 -92
- package/src/catalog/action-resolver.ts +0 -120
- package/src/catalog/index.ts +0 -5
- package/src/catalog/location-registry.ts +0 -134
- package/src/catalog/package-catalog.ts +0 -87
- package/src/catalog/types.ts +0 -75
- package/src/doctor/doctor.ts +0 -419
- package/src/doctor/index.ts +0 -2
- package/src/doctor/types.ts +0 -25
- package/src/execution/index.ts +0 -2
- package/src/execution/service.ts +0 -322
- package/src/execution/types.ts +0 -73
- package/src/export/index.ts +0 -1
- package/src/export/templates.ts +0 -590
- package/src/filter/index.ts +0 -1
- package/src/filter/intent.ts +0 -154
- package/src/index.ts +0 -16
- package/src/profile/client.ts +0 -552
- package/src/profile/index.ts +0 -3
- package/src/profile/manager.ts +0 -341
- package/src/profile/types.ts +0 -71
- package/src/project/index.ts +0 -4
- package/src/project/init.ts +0 -242
- package/src/project/loader.ts +0 -479
- package/src/project/manifest.ts +0 -299
- package/src/project/types.ts +0 -141
- package/src/registry/index.ts +0 -2
- package/src/registry/registry.ts +0 -940
- package/src/registry/types.ts +0 -127
- package/src/runtime/clock.ts +0 -41
- package/src/runtime/context.ts +0 -259
- package/src/runtime/env.ts +0 -172
- package/src/runtime/events.ts +0 -142
- package/src/runtime/execution-manager.ts +0 -74
- package/src/runtime/index.ts +0 -10
- package/src/runtime/module-loader.ts +0 -67
- package/src/runtime/process.ts +0 -245
- package/src/runtime/runner.ts +0 -527
- package/src/runtime/standalone.ts +0 -429
- package/src/schema/validator.ts +0 -61
- package/src/server/body.ts +0 -112
- package/src/server/index.ts +0 -7
- package/src/server/routes/actions.ts +0 -262
- package/src/server/routes/common.ts +0 -126
- package/src/server/routes/config.ts +0 -147
- package/src/server/routes/doctor.ts +0 -29
- package/src/server/routes/health.ts +0 -40
- package/src/server/routes/index.ts +0 -9
- package/src/server/routes/info.ts +0 -221
- package/src/server/routes/playbooks.ts +0 -109
- package/src/server/routes/runs.ts +0 -301
- package/src/server/routes/state.ts +0 -133
- package/src/server/runtime-registry.ts +0 -115
- package/src/server/security.ts +0 -115
- package/src/server/server.ts +0 -251
- package/src/server/types.ts +0 -57
- package/src/storage/driver.ts +0 -126
- package/src/storage/index.ts +0 -81
- package/src/storage/mask.ts +0 -34
- package/src/storage/sqlite.ts +0 -714
- package/src/storage/types.ts +0 -139
- package/src/utils/index.ts +0 -62
package/src/storage/driver.ts
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
|
-
import type { SqliteDriver } from "./types";
|
|
3
|
-
|
|
4
|
-
export type SqliteDriverFactory = (dbPath: string) => SqliteDriver;
|
|
5
|
-
|
|
6
|
-
/** ESM 环境下可用的 CommonJS require,用于动态加载 node:sqlite / bun:sqlite */
|
|
7
|
-
const cjsRequire = createRequire(import.meta.url);
|
|
8
|
-
|
|
9
|
-
let customDriverFactory: SqliteDriverFactory | undefined;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* 注册全局默认 SQLite 驱动工厂。
|
|
13
|
-
*/
|
|
14
|
-
export function setSqliteDriverFactory(factory: SqliteDriverFactory): void {
|
|
15
|
-
customDriverFactory = factory;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* 创建默认 SQLite 驱动实例。
|
|
20
|
-
* 优先使用外部注册的工厂,其次根据当前运行时环境自动适配。
|
|
21
|
-
*/
|
|
22
|
-
export function createDefaultSqliteDriver(dbPath: string): SqliteDriver {
|
|
23
|
-
if (customDriverFactory) {
|
|
24
|
-
return customDriverFactory(dbPath);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// 检查是否在 Bun 运行时环境
|
|
28
|
-
if (typeof (globalThis as any).Bun !== "undefined") {
|
|
29
|
-
try {
|
|
30
|
-
const { Database } = (globalThis as any).Bun.sqlite || cjsRequire("bun:sqlite");
|
|
31
|
-
const db = new Database(dbPath);
|
|
32
|
-
// bun:sqlite 的 statement 未 finalize 时会一直持有数据库文件句柄,
|
|
33
|
-
// Windows 下导致 db.close() 后文件仍被锁(EBUSY 无法删除)。
|
|
34
|
-
// 跟踪全部 prepared statement,close() 时统一 finalize 释放句柄。
|
|
35
|
-
const openStatements = new Set<any>();
|
|
36
|
-
return {
|
|
37
|
-
exec(sql: string) {
|
|
38
|
-
db.exec(sql);
|
|
39
|
-
},
|
|
40
|
-
prepare(sql: string) {
|
|
41
|
-
const stmt = db.prepare(sql);
|
|
42
|
-
openStatements.add(stmt);
|
|
43
|
-
return {
|
|
44
|
-
run(...args: any[]) {
|
|
45
|
-
const params = args.length === 1 && Array.isArray(args[0]) ? args[0] : args;
|
|
46
|
-
const res = stmt.run(...params);
|
|
47
|
-
return { changes: res.changes, lastInsertRowid: res.lastInsertRowid };
|
|
48
|
-
},
|
|
49
|
-
get<T>(...args: any[]): T | undefined {
|
|
50
|
-
const params = args.length === 1 && Array.isArray(args[0]) ? args[0] : args;
|
|
51
|
-
return stmt.get(...params) as T | undefined;
|
|
52
|
-
},
|
|
53
|
-
all<T>(...args: any[]): T[] {
|
|
54
|
-
const params = args.length === 1 && Array.isArray(args[0]) ? args[0] : args;
|
|
55
|
-
return stmt.all(...params) as T[];
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
},
|
|
59
|
-
transaction<T>(fn: () => T extends PromiseLike<unknown> ? never : T): T {
|
|
60
|
-
return db.transaction(fn)() as T;
|
|
61
|
-
},
|
|
62
|
-
close() {
|
|
63
|
-
for (const stmt of openStatements) {
|
|
64
|
-
try {
|
|
65
|
-
stmt.finalize();
|
|
66
|
-
} catch {
|
|
67
|
-
// 已 finalize 或重复释放时忽略
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
openStatements.clear();
|
|
71
|
-
db.close();
|
|
72
|
-
},
|
|
73
|
-
};
|
|
74
|
-
} catch {
|
|
75
|
-
// 若在 Bun 下获取 bun:sqlite 失败,回退到标准 Node 驱动尝试
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// 在 Node.js 环境下使用 node:sqlite
|
|
80
|
-
try {
|
|
81
|
-
const { DatabaseSync } = cjsRequire("node:sqlite");
|
|
82
|
-
const db = new DatabaseSync(dbPath);
|
|
83
|
-
return {
|
|
84
|
-
exec(sql: string) {
|
|
85
|
-
db.exec(sql);
|
|
86
|
-
},
|
|
87
|
-
prepare(sql: string) {
|
|
88
|
-
const stmt = db.prepare(sql);
|
|
89
|
-
return {
|
|
90
|
-
run(...args: any[]) {
|
|
91
|
-
const params = args.length === 1 && Array.isArray(args[0]) ? args[0] : args;
|
|
92
|
-
const res = stmt.run(...params);
|
|
93
|
-
return { changes: res.changes, lastInsertRowid: res.lastInsertRowid };
|
|
94
|
-
},
|
|
95
|
-
get<T>(...args: any[]): T | undefined {
|
|
96
|
-
const params = args.length === 1 && Array.isArray(args[0]) ? args[0] : args;
|
|
97
|
-
return stmt.get(...params) as T | undefined;
|
|
98
|
-
},
|
|
99
|
-
all<T>(...args: any[]): T[] {
|
|
100
|
-
const params = args.length === 1 && Array.isArray(args[0]) ? args[0] : args;
|
|
101
|
-
return stmt.all(...params) as T[];
|
|
102
|
-
},
|
|
103
|
-
};
|
|
104
|
-
},
|
|
105
|
-
transaction<T>(fn: () => T extends PromiseLike<unknown> ? never : T): T {
|
|
106
|
-
db.exec("BEGIN");
|
|
107
|
-
try {
|
|
108
|
-
const res = fn();
|
|
109
|
-
if (res && typeof (res as any).then === "function") {
|
|
110
|
-
throw new Error("Async transactions are not allowed in SQLite");
|
|
111
|
-
}
|
|
112
|
-
db.exec("COMMIT");
|
|
113
|
-
return res;
|
|
114
|
-
} catch (e) {
|
|
115
|
-
db.exec("ROLLBACK");
|
|
116
|
-
throw e;
|
|
117
|
-
}
|
|
118
|
-
},
|
|
119
|
-
close() {
|
|
120
|
-
db.close();
|
|
121
|
-
},
|
|
122
|
-
};
|
|
123
|
-
} catch (err: any) {
|
|
124
|
-
throw new Error(`Failed to initialize SQLite driver: ${err?.message || String(err)}`);
|
|
125
|
-
}
|
|
126
|
-
}
|
package/src/storage/index.ts
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { join } from "node:path";
|
|
2
|
-
import { getActionDockHome } from "../utils";
|
|
3
|
-
import { SqliteRuntimeStorage } from "./sqlite";
|
|
4
|
-
import type { RuntimeStorage, StorageOptions } from "./types";
|
|
5
|
-
|
|
6
|
-
export * from "./driver";
|
|
7
|
-
export * from "./mask";
|
|
8
|
-
export * from "./sqlite";
|
|
9
|
-
export * from "./types";
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* 解析并计算目标 SQLite 数据库文件的绝对路径。
|
|
13
|
-
*
|
|
14
|
-
* 优先级规则:
|
|
15
|
-
* 1. inMemory: true -> 返回 ":memory:"
|
|
16
|
-
* 2. 显式指定 dataDir -> 返回 `<dataDir>/<packageId>/runtime.db`
|
|
17
|
-
* 3. 显式指定 projectRoot(开发态项目) -> 返回 `<projectRoot>/.actiondock/runtime.db`
|
|
18
|
-
* 4. 默认独立二进制存储路径 -> 返回 `~/.actiondock/data/<packageId>/runtime.db`
|
|
19
|
-
*
|
|
20
|
-
* @param packageId 所属 Package ID
|
|
21
|
-
* @param options 路径解析选项
|
|
22
|
-
*/
|
|
23
|
-
export function resolveDatabasePath(
|
|
24
|
-
packageId: string,
|
|
25
|
-
options: { projectRoot?: string; dataDir?: string; inMemory?: boolean } = {}
|
|
26
|
-
): string {
|
|
27
|
-
if (options.inMemory) {
|
|
28
|
-
return ":memory:";
|
|
29
|
-
}
|
|
30
|
-
if (options.dataDir) {
|
|
31
|
-
return join(options.dataDir, packageId, "runtime.db");
|
|
32
|
-
}
|
|
33
|
-
if (options.projectRoot) {
|
|
34
|
-
return join(options.projectRoot, ".actiondock", "runtime.db");
|
|
35
|
-
}
|
|
36
|
-
// 独立执行二进制默认存储路径: ~/.actiondock/data/<package-id>/runtime.db
|
|
37
|
-
return join(getActionDockHome(), ".actiondock", "data", packageId, "runtime.db");
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* 工厂函数:为指定 Package 创建或连接 RuntimeStorage 实例。
|
|
42
|
-
*
|
|
43
|
-
* @param packageId 目标 Package ID
|
|
44
|
-
* @param options 存储配置参数(支持 projectRoot, dataDir, inMemory)
|
|
45
|
-
*/
|
|
46
|
-
export function createStorage(
|
|
47
|
-
packageId: string,
|
|
48
|
-
options: { projectRoot?: string; dataDir?: string; inMemory?: boolean } = {}
|
|
49
|
-
): RuntimeStorage {
|
|
50
|
-
const dbPath = resolveDatabasePath(packageId, options);
|
|
51
|
-
return new SqliteRuntimeStorage({ dbPath, packageId });
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* 工厂函数:创建或连接 ActionDock 全局共享数据库(~/.actiondock/global.db)。
|
|
56
|
-
* 用于跨 Package 共享的全局配置项存储。
|
|
57
|
-
*
|
|
58
|
-
* @param customHomeOrOptions 自定义家目录路径或配置对象(可选)
|
|
59
|
-
* @param dataDirArg 自定义数据存储目录(可选)
|
|
60
|
-
*/
|
|
61
|
-
export function createGlobalStorage(
|
|
62
|
-
customHomeOrOptions?: string | { customHome?: string; dataDir?: string },
|
|
63
|
-
dataDirArg?: string
|
|
64
|
-
): RuntimeStorage {
|
|
65
|
-
let customHome: string | undefined;
|
|
66
|
-
let dataDir: string | undefined;
|
|
67
|
-
|
|
68
|
-
if (typeof customHomeOrOptions === "object" && customHomeOrOptions !== null) {
|
|
69
|
-
customHome = customHomeOrOptions.customHome;
|
|
70
|
-
dataDir = customHomeOrOptions.dataDir;
|
|
71
|
-
} else {
|
|
72
|
-
customHome = customHomeOrOptions;
|
|
73
|
-
dataDir = dataDirArg;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const dbPath = dataDir
|
|
77
|
-
? join(dataDir, "global.db")
|
|
78
|
-
: join(getActionDockHome(customHome), ".actiondock", "global.db");
|
|
79
|
-
return new SqliteRuntimeStorage({ dbPath, packageId: "__global__" });
|
|
80
|
-
}
|
|
81
|
-
|
package/src/storage/mask.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { ConfigItemDefinition } from "../project/types";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 检查指定配置项是否为敏感数据(密码、私钥、Token、密钥等)。
|
|
5
|
-
*
|
|
6
|
-
* 判定逻辑:
|
|
7
|
-
* 1. 若 actiondock.json 中显式声明了 `secret: true`,直接判定为敏感。
|
|
8
|
-
* 2. 若未显式声明,使用正则探测包含 PASSWORD/SECRET/TOKEN/KEY/PASS/AUTH/CREDENTIAL/PRIVATE_KEY 的通用敏感命名特征。
|
|
9
|
-
*
|
|
10
|
-
* @param key 配置键名
|
|
11
|
-
* @param declaredItem 项目中声明的配置元数据(可选)
|
|
12
|
-
*/
|
|
13
|
-
export function isSecretConfigKey(
|
|
14
|
-
key: string,
|
|
15
|
-
declaredItem?: ConfigItemDefinition
|
|
16
|
-
): boolean {
|
|
17
|
-
if (declaredItem?.secret === true) {
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
// 匹配常见敏感词命名特征
|
|
21
|
-
return /^(.*_)?(PASSWORD|SECRET|TOKEN|KEY|PASS|AUTH|CREDENTIAL|PRIVATE_KEY)(_.*)?$/i.test(key);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* 对敏感数据的值进行掩码脱敏处理(返回 "********")。
|
|
26
|
-
*
|
|
27
|
-
* @param value 原始数据值
|
|
28
|
-
* @returns 掩码脱敏后的安全展示字符串
|
|
29
|
-
*/
|
|
30
|
-
export function maskSecretValue(value: unknown): string {
|
|
31
|
-
if (value === undefined) return "undefined";
|
|
32
|
-
if (value === null) return "null";
|
|
33
|
-
return "********";
|
|
34
|
-
}
|