dsh-config-manager 0.4.1 → 0.4.2
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/lib/cli/actions.js +2 -3
- package/lib/cli/import-source.js +2 -6
- package/lib/cli/index.js +2 -3
- package/lib/client.d.ts +0 -5
- package/lib/client.js +26116 -25801
- package/lib/core/exporter.js +2 -4
- package/lib/core/host-schedulers/cache-cleanup.d.ts +41 -0
- package/lib/core/host-schedulers/cache-cleanup.js +45 -0
- package/lib/core/host-schedulers/lifecycle-hooks.d.ts +51 -0
- package/lib/core/host-schedulers/lifecycle-hooks.js +78 -0
- package/lib/core/host-schedulers/market-cache.d.ts +40 -0
- package/lib/core/host-schedulers/market-cache.js +92 -0
- package/lib/core/model-tools.js +2 -6
- package/lib/core/restore.d.ts +0 -2
- package/lib/core/restore.js +16 -18
- package/lib/core/verify-recovery.js +4 -7
- package/lib/index.d.ts +3 -22
- package/lib/index.js +69 -325
- package/lib/profiles/dsh-profile-manager.d.ts +23 -1
- package/lib/profiles/dsh-profile-manager.js +70 -2
- package/lib/routes/kit.d.ts +21 -0
- package/lib/routes/kit.js +29 -0
- package/lib/routes/prefs.js +6 -6
- package/lib/routes/recovery.js +25 -41
- package/lib/routes/route-support.d.ts +23 -1
- package/lib/routes/route-support.js +185 -0
- package/lib/routes/snapshots.js +4 -11
- package/lib/routes/sync.js +5 -7
- package/lib/security/redaction.d.ts +5 -1
- package/lib/security/redaction.js +26 -23
- package/lib/sync/backup-scheduler.js +2 -6
- package/lib/ui/backup-inspect.d.ts +1 -1
- package/lib/ui/dsh-profiles-view.d.ts +0 -10
- package/lib/ui/dsh-profiles-view.js +3 -7
- package/lib/ui/snapshots-view.d.ts +0 -14
- package/lib/ui/snapshots-view.js +16 -2
- package/lib/utils/paths.d.ts +20 -4
- package/lib/utils/paths.js +22 -6
- package/lib/utils/time.d.ts +31 -0
- package/lib/utils/time.js +54 -0
- package/package.json +1 -1
- package/src/cli/actions.ts +2 -3
- package/src/cli/import-source.ts +2 -7
- package/src/cli/index.ts +2 -3
- package/src/client/about/AboutPanel.tsx +1 -1
- package/src/client/about/ReleaseBody.tsx +22 -52
- package/src/client/about/ReleaseNotesDialog.tsx +15 -69
- package/src/client/about/release-notes-view.ts +4 -11
- package/src/client/common/info-hint-guard.test.ts +11 -5
- package/src/client/common/ui.tsx +23 -0
- package/src/client/config-manager.module.css +201 -32
- package/src/client/css-token-guard.test.ts +135 -1
- package/src/client/import/ConflictList.tsx +3 -3
- package/src/client/import/ImportWizardView.tsx +1 -1
- package/src/client/library/ArtifactRow.tsx +2 -2
- package/src/client/library/RestorePlanView.tsx +21 -9
- package/src/client/library/report-dismiss.test.ts +5 -3
- package/src/client/locales/about.ts +97 -0
- package/src/client/locales/backup.ts +141 -0
- package/src/client/locales/common.ts +113 -0
- package/src/client/locales/export.ts +184 -0
- package/src/client/locales/foreign.ts +184 -0
- package/src/client/locales/import-compat.ts +32 -0
- package/src/client/locales/import.ts +192 -0
- package/src/client/locales/next-steps.ts +25 -0
- package/src/client/locales/overview-control.ts +32 -0
- package/src/client/locales/overview.ts +145 -0
- package/src/client/locales/profiles.ts +263 -0
- package/src/client/locales/report.ts +17 -0
- package/src/client/locales/restore.ts +132 -0
- package/src/client/locales/sessions.ts +257 -0
- package/src/client/locales/shell.ts +149 -0
- package/src/client/locales.ts +49 -1783
- package/src/client/market/MarketImportReview.tsx +2 -2
- package/src/client/market/MarketPanel.tsx +1 -1
- package/src/client/market/market-view.ts +3 -5
- package/src/client/recovery/RecoveryPanel.tsx +62 -1054
- package/src/client/recovery/SessionHealthCard.tsx +134 -0
- package/src/client/recovery/SessionHealthDialog.tsx +665 -0
- package/src/client/recovery/SessionLayoutSection.tsx +284 -0
- package/src/client/recovery/recovery-api.ts +10 -1
- package/src/client/recovery/recovery-panel-layout.test.ts +20 -5
- package/src/client/recovery/session-dialog-mount.test.ts +16 -9
- package/src/client/recovery/use-recovery-write.test.ts +90 -0
- package/src/client/recovery/use-recovery-write.ts +53 -0
- package/src/client/run-store.ts +57 -2
- package/src/client/sync/PushPreviewCard.tsx +2 -2
- package/src/client/sync/SyncConfirmView.tsx +5 -5
- package/src/client/sync/SyncLogList.tsx +2 -2
- package/src/client/sync/history-model.ts +4 -5
- package/src/client/sync/sync-view.ts +3 -4
- package/src/core/exporter.ts +2 -4
- package/src/core/host-schedulers/cache-cleanup.test.ts +84 -0
- package/src/core/host-schedulers/cache-cleanup.ts +74 -0
- package/src/core/host-schedulers/lifecycle-hooks.test.ts +111 -0
- package/src/core/host-schedulers/lifecycle-hooks.ts +118 -0
- package/src/core/host-schedulers/market-cache.test.ts +93 -0
- package/src/core/host-schedulers/market-cache.ts +116 -0
- package/src/core/model-tools.ts +2 -7
- package/src/core/restore-failure-state.test.ts +210 -0
- package/src/core/restore.ts +16 -18
- package/src/core/verify-recovery.ts +4 -7
- package/src/index.ts +76 -330
- package/src/profiles/dsh-profile-copy-rollback.test.ts +156 -0
- package/src/profiles/dsh-profile-manager.ts +71 -3
- package/src/routes/kit.ts +37 -0
- package/src/routes/prefs.ts +6 -6
- package/src/routes/recovery.ts +25 -42
- package/src/routes/route-support.ts +208 -1
- package/src/routes/snapshots.ts +4 -9
- package/src/routes/sync.ts +4 -7
- package/src/security/redaction.ts +29 -23
- package/src/sync/backup-scheduler.ts +3 -6
- package/src/sync/sync-config.test.ts +24 -13
- package/src/ui/backup-inspect.ts +1 -1
- package/src/ui/dsh-profiles-view.ts +3 -5
- package/src/ui/i18n.test.ts +8 -3
- package/src/ui/snapshots-view.ts +2 -2
- package/src/utils/paths.test.ts +36 -1
- package/src/utils/paths.ts +30 -6
- package/src/utils/time.test.ts +46 -0
- package/src/utils/time.ts +55 -0
|
@@ -74,6 +74,72 @@ function isInsideDir(root, candidate) {
|
|
|
74
74
|
}
|
|
75
75
|
/** t89:profiles 根目录枚举失败的原因码(诊断/日志用)。 */
|
|
76
76
|
export const PROFILES_ROOT_UNREADABLE = 'profiles-root-unreadable';
|
|
77
|
+
/** 回滚复制目标目录的缺省删除实现(递归强制;不存在不算错)。 */
|
|
78
|
+
const defaultProfileRemove = async (target) => {
|
|
79
|
+
await rm(target, { recursive: true, force: true });
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* 复制失败时回滚目标目录(cross-F3 收尾 / tech-debt #5)。
|
|
83
|
+
*
|
|
84
|
+
* **顺序即不变量:先删内容,标记留到最后。** 标记(`.dcm-copy-in-progress.json`)是「这个目录是半截副本」
|
|
85
|
+
* 的唯一证据 —— `listIncompleteCopies()` 只认它,`requireManagedDir` 也只认它,没有 package.json
|
|
86
|
+
* 又没有标记的目录既不进列表、删除还报 notFound(孤儿)。
|
|
87
|
+
*
|
|
88
|
+
* 此前 catch 里是一把 `rm(recursive)` 加一句注释:rm 先删掉标记再失败(例如某个只读子目录让它中途放弃),
|
|
89
|
+
* 残留目录恰好落进那个「看不见也删不掉」的形态。这里两道保险:
|
|
90
|
+
* ① 逐条删顶层内容,标记不参与删除批次 —— 中途失败时标记必然还在;
|
|
91
|
+
* ② 收尾时若目录仍存在而标记没了(rm 部分生效 / 外部工具删过),**按原样重写标记**再放手。
|
|
92
|
+
*
|
|
93
|
+
* 因此只要返回,残留(若还在)**必然**能被 `listIncompleteCopies()` / `listIncompleteCopiesScan()`
|
|
94
|
+
* 扫到,并能经 `remove()`(UI 的 diskApi.profileDelete)删除。
|
|
95
|
+
*
|
|
96
|
+
* @param remove 删除实现(缺省递归强制删除),仅供测试注入「部分失败」的 fs。
|
|
97
|
+
*/
|
|
98
|
+
export async function rollbackCopiedProfileDir(destDir, marker, remove = defaultProfileRemove) {
|
|
99
|
+
const markerPath = join(destDir, PROFILE_COPY_MARKER_FILENAME);
|
|
100
|
+
const failedEntries = [];
|
|
101
|
+
let entries = [];
|
|
102
|
+
try {
|
|
103
|
+
entries = await readdir(destDir, { withFileTypes: true });
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
// 读不出目录(已被删掉 / 无权限):交给下面的存在性判据,不在此下结论
|
|
107
|
+
entries = [];
|
|
108
|
+
}
|
|
109
|
+
for (const entry of entries) {
|
|
110
|
+
// 标记不进删除批次:它必须活到「内容全删完」那一刻
|
|
111
|
+
if (entry.name === PROFILE_COPY_MARKER_FILENAME)
|
|
112
|
+
continue;
|
|
113
|
+
try {
|
|
114
|
+
await remove(join(destDir, entry.name));
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
failedEntries.push(entry.name);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (failedEntries.length === 0) {
|
|
121
|
+
// 内容已空:连标记带目录一起删(这一步失败也不影响下面的补写)
|
|
122
|
+
try {
|
|
123
|
+
await remove(destDir);
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
// 目录删不掉(标记已随 rm 消失的风险由下面兜住)
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (!existsSync(destDir))
|
|
130
|
+
return { removed: true, failedEntries: [], markerRestored: false };
|
|
131
|
+
let markerRestored = false;
|
|
132
|
+
if (!existsSync(markerPath)) {
|
|
133
|
+
try {
|
|
134
|
+
atomicWriteFileSync(markerPath, `${JSON.stringify(marker, null, 2)}\n`, { mode: 0o644 });
|
|
135
|
+
markerRestored = true;
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
// 目录已不可写:连标记都补不回去,只能让调用方照常抛错(用户可手动删)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return { removed: false, failedEntries, markerRestored };
|
|
142
|
+
}
|
|
77
143
|
/** 「档案」= DSH profile 的读写引擎(同步 fs;profile 数量级为个位数,无需异步)。 */
|
|
78
144
|
export class DshProfileManager {
|
|
79
145
|
homeDir;
|
|
@@ -225,11 +291,13 @@ export class DshProfileManager {
|
|
|
225
291
|
}
|
|
226
292
|
}
|
|
227
293
|
catch (error) {
|
|
294
|
+
// 回滚失败 ≠ 放任孤儿:rollbackCopiedProfileDir 把标记留到最后,并在「目录还在、标记没了」时补写标记
|
|
295
|
+
// —— 残留目录因此仍能被 listIncompleteCopies() 扫到,并能经 remove()(UI 的「删除残留副本」)删掉。
|
|
228
296
|
try {
|
|
229
|
-
await
|
|
297
|
+
await rollbackCopiedProfileDir(destDir, marker);
|
|
230
298
|
}
|
|
231
299
|
catch {
|
|
232
|
-
//
|
|
300
|
+
// 连回滚入口都抛(理论上不会):标记在写盘前就已落盘,用户仍可手动删掉这个半套目录
|
|
233
301
|
}
|
|
234
302
|
throw new DshProfileError('copyFailed', `copyFailed: ${error instanceof Error ? error.message : String(error)}`);
|
|
235
303
|
}
|
package/lib/routes/kit.d.ts
CHANGED
|
@@ -73,6 +73,27 @@ export declare function writeJson(res: ServerResponse, status: number, body: unk
|
|
|
73
73
|
export declare function writeJsonError(res: ServerResponse, status: number, message: string, code?: string): void;
|
|
74
74
|
/** 统一错误出口:RouteError(含子类)用其 status/code,其余 500 + 消息(已由调用方脱敏)。 */
|
|
75
75
|
export declare function writeRouteError(res: ServerResponse, error: unknown): void;
|
|
76
|
+
/** 写一条诊断日志所需的最小宿主形状(只取 host.log,避免 kit 依赖整个 RoutesEnv)。 */
|
|
77
|
+
export interface MutationLogSink {
|
|
78
|
+
log: {
|
|
79
|
+
warn(message: string): void;
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* mutation gate 的 423 家族**唯一映射点**(tech-debt #9)。
|
|
84
|
+
*
|
|
85
|
+
* 为什么收在这里:改造前这段「两行日志 + 两行 423 写回」被抄了 12 处
|
|
86
|
+
* (组合根 withMutationGate 自己的 catch、snapshots /restore 的自拼包壳、prefs、sync、
|
|
87
|
+
* recovery 的 8 个写路由),新增 gate 行为时必然漏改一处 —— 与 kit 头注释里 F-02/F-03 同因。
|
|
88
|
+
*
|
|
89
|
+
* 命中 → 写 `423 {error, code}`(字段顺序与旧 writeJson 逐字一致)并返回 true;
|
|
90
|
+
* 未命中 → 返回 false,**调用方按自己路由既有的兜底口径写**(sync 走 SyncRouteError、
|
|
91
|
+
* snapshots 的 /restore 兜 400、组合根 gate 必须 rethrow 给 endpoint 的 errorRenderer …)。
|
|
92
|
+
* 用返回布尔而不是「内置兜底」正是为了不改这些既有语义。
|
|
93
|
+
*
|
|
94
|
+
* 内部诊断(op/reason/detail)只进日志;用户看到的是 error.message(友好文案,无技术细节)。
|
|
95
|
+
*/
|
|
96
|
+
export declare function writeMutationError(res: ServerResponse, host: MutationLogSink, error: unknown): boolean;
|
|
76
97
|
/** Cap on raw JSON bodies (4 MiB) —— 文件上传走 MAX_UPLOAD_BYTES 的另一条路径。 */
|
|
77
98
|
export declare const MAX_JSON_BODY_BYTES: number;
|
|
78
99
|
/** 读取 JSON 请求体:非法 JSON / 超限 / 非对象 → undefined(调用方决定语义)。 */
|
package/lib/routes/kit.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { invalidateEngineLocale } from '../core/engine-locale.js';
|
|
2
|
+
import { TransactionRecoveryRequiredError } from '../core/phase3-host.js';
|
|
3
|
+
import { EnvironmentLockUnavailableError } from '../utils/env-lock.js';
|
|
2
4
|
import { engineMsg } from './messages.js';
|
|
3
5
|
/** kit 产出的路由上挂的声明信息(供注册点兜底断言与 route-parity 测试读取)。 */
|
|
4
6
|
export const ROUTE_SPEC = Symbol('dsh-config-manager.routeSpec');
|
|
@@ -46,6 +48,33 @@ export function writeRouteError(res, error) {
|
|
|
46
48
|
}
|
|
47
49
|
writeJsonError(res, 500, errorMessage(error));
|
|
48
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* mutation gate 的 423 家族**唯一映射点**(tech-debt #9)。
|
|
53
|
+
*
|
|
54
|
+
* 为什么收在这里:改造前这段「两行日志 + 两行 423 写回」被抄了 12 处
|
|
55
|
+
* (组合根 withMutationGate 自己的 catch、snapshots /restore 的自拼包壳、prefs、sync、
|
|
56
|
+
* recovery 的 8 个写路由),新增 gate 行为时必然漏改一处 —— 与 kit 头注释里 F-02/F-03 同因。
|
|
57
|
+
*
|
|
58
|
+
* 命中 → 写 `423 {error, code}`(字段顺序与旧 writeJson 逐字一致)并返回 true;
|
|
59
|
+
* 未命中 → 返回 false,**调用方按自己路由既有的兜底口径写**(sync 走 SyncRouteError、
|
|
60
|
+
* snapshots 的 /restore 兜 400、组合根 gate 必须 rethrow 给 endpoint 的 errorRenderer …)。
|
|
61
|
+
* 用返回布尔而不是「内置兜底」正是为了不改这些既有语义。
|
|
62
|
+
*
|
|
63
|
+
* 内部诊断(op/reason/detail)只进日志;用户看到的是 error.message(友好文案,无技术细节)。
|
|
64
|
+
*/
|
|
65
|
+
export function writeMutationError(res, host, error) {
|
|
66
|
+
if (error instanceof EnvironmentLockUnavailableError) {
|
|
67
|
+
host.log.warn(`mutation lock blocked: op=${error.op} reason=${error.reason}${error.detail !== undefined ? ` detail=${error.detail}` : ''}`);
|
|
68
|
+
writeJsonError(res, 423, error.message, 'mutation-locked');
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
if (error instanceof TransactionRecoveryRequiredError) {
|
|
72
|
+
host.log.warn(`transaction recovery required: ${error.message}`);
|
|
73
|
+
writeJsonError(res, 423, error.message, 'transaction-recovery-required');
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
49
78
|
/** Cap on raw JSON bodies (4 MiB) —— 文件上传走 MAX_UPLOAD_BYTES 的另一条路径。 */
|
|
50
79
|
export const MAX_JSON_BODY_BYTES = 4 * 1024 * 1024;
|
|
51
80
|
/** 读取 JSON 请求体:非法 JSON / 超限 / 非对象 → undefined(调用方决定语义)。 */
|
package/lib/routes/prefs.js
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
* W1(host-entry#F-02/#F-03):路由只在这里声明一次 —— endpoint({ path, methods }, handler) 的
|
|
7
7
|
* path/methods 就是唯一声明处;围栏、方法判定与顶层异常处理由 src/routes/kit.ts 在注册点统一提供。
|
|
8
8
|
*/
|
|
9
|
-
import { endpoint, requireJsonObject, writeJson } from './kit.js';
|
|
10
|
-
import {
|
|
9
|
+
import { endpoint, requireJsonObject, writeJson, writeMutationError } from './kit.js';
|
|
10
|
+
import { runWithMutationLock } from '../utils/env-lock.js';
|
|
11
11
|
import { readUiPrefs, updateUiPrefs } from '../sync/ui-prefs.js';
|
|
12
12
|
import { UpdateChecker, wantsForcedUpdateCheck } from '../core/update-check.js';
|
|
13
13
|
export function prefsRoutes(env) {
|
|
@@ -23,11 +23,11 @@ export function prefsRoutes(env) {
|
|
|
23
23
|
return await runWithMutationLock(host.mutationLock, { op: 'ui-prefs', target: 'star/release-notes', isBlocked: () => host.safeModeIsBlocked?.() ?? false }, async () => await updateUiPrefs(syncDir, patch));
|
|
24
24
|
}
|
|
25
25
|
catch (error) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
// 423 家族(SAFE MODE / 环境锁)的唯一映射在 kit;其余错误仍是本文件既有的 500 兜底(零写入)。
|
|
27
|
+
if (!writeMutationError(res, host, error)) {
|
|
28
|
+
writeJson(res, 500, { error: error instanceof Error ? error.message : String(error) });
|
|
29
29
|
}
|
|
30
|
-
|
|
30
|
+
return null;
|
|
31
31
|
}
|
|
32
32
|
};
|
|
33
33
|
// 版本更新检查器:每进程一个(进程内缓存 10 分钟;用户点「重新检查」走 ?force=1)。
|
package/lib/routes/recovery.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* W1(host-entry#F-02/#F-03):路由只在这里声明一次 —— endpoint({ path, methods }, handler) 的
|
|
5
5
|
* path/methods 就是唯一声明处;围栏、方法判定与顶层异常处理由 src/routes/kit.ts 在注册点统一提供。
|
|
6
6
|
*/
|
|
7
|
-
import { endpoint, readJsonBody, writeJson } from './kit.js';
|
|
7
|
+
import { endpoint, readJsonBody, writeJson, writeMutationError } from './kit.js';
|
|
8
8
|
// t6:「英文界面零中文」——迁移历史 summary 一律由目录键产生;engineMsg 与宿主 makeRouteEnv 的
|
|
9
9
|
// `msg` 同源(t2 起 this.msg = engineMsg),但它是**活翻译器**,不依赖 env 是否注入取词器。
|
|
10
10
|
import { engineMsg } from './messages.js';
|
|
@@ -13,7 +13,7 @@ import { RollbackLedgerRefusedError, RollbackPointEngine } from '../core/rollbac
|
|
|
13
13
|
import { isRollbackEnabled, setRollbackEnabled } from '../core/rollback-gate.js';
|
|
14
14
|
import { readRollbackEnabledSync, updateUiPrefs } from '../sync/ui-prefs.js';
|
|
15
15
|
import { reconcileForkSessions } from '../core/fork-reconcile.js';
|
|
16
|
-
import {
|
|
16
|
+
import { runWithMutationLock } from '../utils/env-lock.js';
|
|
17
17
|
import { scanSessionHealth } from '../utils/session-health-scan.js';
|
|
18
18
|
import { applySessionTitles } from '../core/session-meta.js';
|
|
19
19
|
import { applySessionLogTitles } from '../core/session-title.js';
|
|
@@ -586,12 +586,10 @@ export function recoveryRoutes(env) {
|
|
|
586
586
|
});
|
|
587
587
|
}
|
|
588
588
|
catch (error) {
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
writeJson(res,
|
|
592
|
-
return;
|
|
589
|
+
// 423 家族(SAFE MODE / 环境锁)的唯一映射在 kit;本组其余错误仍是既有的 500 { error } 口径。
|
|
590
|
+
if (!writeMutationError(res, host, error)) {
|
|
591
|
+
writeJson(res, 500, { error: error instanceof Error ? error.message : String(error) });
|
|
593
592
|
}
|
|
594
|
-
writeJson(res, 500, { error: error instanceof Error ? error.message : String(error) });
|
|
595
593
|
}
|
|
596
594
|
return;
|
|
597
595
|
}
|
|
@@ -649,12 +647,10 @@ export function recoveryRoutes(env) {
|
|
|
649
647
|
});
|
|
650
648
|
}
|
|
651
649
|
catch (error) {
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
writeJson(res,
|
|
655
|
-
return;
|
|
650
|
+
// 423 家族(SAFE MODE / 环境锁)的唯一映射在 kit;本组其余错误仍是既有的 500 { error } 口径。
|
|
651
|
+
if (!writeMutationError(res, host, error)) {
|
|
652
|
+
writeJson(res, 500, { error: error instanceof Error ? error.message : String(error) });
|
|
656
653
|
}
|
|
657
|
-
writeJson(res, 500, { error: error instanceof Error ? error.message : String(error) });
|
|
658
654
|
}
|
|
659
655
|
return;
|
|
660
656
|
}
|
|
@@ -857,12 +853,10 @@ export function recoveryRoutes(env) {
|
|
|
857
853
|
writeJson(res, 200, { ok: true, rollbackEnabled: wanted, rollbackActive: isRollbackEnabled() });
|
|
858
854
|
}
|
|
859
855
|
catch (error) {
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
writeJson(res,
|
|
863
|
-
return;
|
|
856
|
+
// 423 家族(SAFE MODE / 环境锁)的唯一映射在 kit;本组其余错误仍是既有的 500 { error } 口径。
|
|
857
|
+
if (!writeMutationError(res, host, error)) {
|
|
858
|
+
writeJson(res, 500, { error: error instanceof Error ? error.message : String(error) });
|
|
864
859
|
}
|
|
865
|
-
writeJson(res, 500, { error: error instanceof Error ? error.message : String(error) });
|
|
866
860
|
}
|
|
867
861
|
return;
|
|
868
862
|
}
|
|
@@ -900,11 +894,9 @@ export function recoveryRoutes(env) {
|
|
|
900
894
|
writeJson(res, 200, { ok: true, ...result });
|
|
901
895
|
}
|
|
902
896
|
catch (error) {
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
writeJson(res, 423, { error: error.message, code: 'mutation-locked' });
|
|
897
|
+
// 423 家族(SAFE MODE / 环境锁)的唯一映射在 kit;本组其余错误仍是既有的口径。
|
|
898
|
+
if (writeMutationError(res, host, error))
|
|
906
899
|
return;
|
|
907
|
-
}
|
|
908
900
|
// 引擎侧的**显式拒绝**带机器码(存储不可用 / 台账读不出):按码映射 HTTP,
|
|
909
901
|
// 不回落成泛化 500 —— 界面要能说清「是存储栈缺了」还是「台账真读不出来」。
|
|
910
902
|
if (error instanceof RollbackLedgerRefusedError) {
|
|
@@ -1050,12 +1042,10 @@ export function recoveryRoutes(env) {
|
|
|
1050
1042
|
reply(result);
|
|
1051
1043
|
}
|
|
1052
1044
|
catch (error) {
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
writeJson(res,
|
|
1056
|
-
return;
|
|
1045
|
+
// 423 家族(SAFE MODE / 环境锁)的唯一映射在 kit;本组其余错误仍是既有的 500 { error } 口径。
|
|
1046
|
+
if (!writeMutationError(res, host, error)) {
|
|
1047
|
+
writeJson(res, 500, { error: error instanceof Error ? error.message : String(error) });
|
|
1057
1048
|
}
|
|
1058
|
-
writeJson(res, 500, { error: error instanceof Error ? error.message : String(error) });
|
|
1059
1049
|
}
|
|
1060
1050
|
return;
|
|
1061
1051
|
}
|
|
@@ -1086,12 +1076,10 @@ export function recoveryRoutes(env) {
|
|
|
1086
1076
|
reply(result);
|
|
1087
1077
|
}
|
|
1088
1078
|
catch (error) {
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
writeJson(res,
|
|
1092
|
-
return;
|
|
1079
|
+
// 423 家族(SAFE MODE / 环境锁)的唯一映射在 kit;本组其余错误仍是既有的 500 { error } 口径。
|
|
1080
|
+
if (!writeMutationError(res, host, error)) {
|
|
1081
|
+
writeJson(res, 500, { error: error instanceof Error ? error.message : String(error) });
|
|
1093
1082
|
}
|
|
1094
|
-
writeJson(res, 500, { error: error instanceof Error ? error.message : String(error) });
|
|
1095
1083
|
}
|
|
1096
1084
|
return;
|
|
1097
1085
|
}
|
|
@@ -1135,12 +1123,10 @@ export function recoveryRoutes(env) {
|
|
|
1135
1123
|
writeJson(res, result.ok ? 200 : 503, result);
|
|
1136
1124
|
}
|
|
1137
1125
|
catch (error) {
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
writeJson(res,
|
|
1141
|
-
return;
|
|
1126
|
+
// 423 家族(SAFE MODE / 环境锁)的唯一映射在 kit;本组其余错误仍是既有的 500 { error } 口径。
|
|
1127
|
+
if (!writeMutationError(res, host, error)) {
|
|
1128
|
+
writeJson(res, 500, { error: error instanceof Error ? error.message : String(error) });
|
|
1142
1129
|
}
|
|
1143
|
-
writeJson(res, 500, { error: error instanceof Error ? error.message : String(error) });
|
|
1144
1130
|
}
|
|
1145
1131
|
return;
|
|
1146
1132
|
}
|
|
@@ -1269,12 +1255,10 @@ export function recoveryRoutes(env) {
|
|
|
1269
1255
|
});
|
|
1270
1256
|
}
|
|
1271
1257
|
catch (error) {
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
writeJson(res,
|
|
1275
|
-
return;
|
|
1258
|
+
// 423 家族(SAFE MODE / 环境锁)的唯一映射在 kit;本组其余错误仍是既有的 500 { error } 口径。
|
|
1259
|
+
if (!writeMutationError(res, host, error)) {
|
|
1260
|
+
writeJson(res, 500, { error: error instanceof Error ? error.message : String(error) });
|
|
1276
1261
|
}
|
|
1277
|
-
writeJson(res, 500, { error: error instanceof Error ? error.message : String(error) });
|
|
1278
1262
|
}
|
|
1279
1263
|
}),
|
|
1280
1264
|
];
|
|
@@ -15,10 +15,11 @@ import { RouteError } from './kit.ts';
|
|
|
15
15
|
import type { MsgFunc } from '../core/messages.ts';
|
|
16
16
|
import type { SectionId } from '../schema/types.ts';
|
|
17
17
|
import type { HostContext, ImportPlan, PlanItemKind } from '../core/types.ts';
|
|
18
|
+
import type { CredentialProvider } from '@deepseek-ai/dsh-credentials';
|
|
18
19
|
import type { RestoreActionKind, RestorePlan, RestoreReport } from '../core/restore.ts';
|
|
19
20
|
import type { RestoreResumeHint } from '../core/restore-resume.ts';
|
|
20
21
|
import type { RestoreJournalPort } from '../core/restore-wal.ts';
|
|
21
|
-
import type { SyncTransportType } from '../sync/sync-config.ts';
|
|
22
|
+
import type { SyncConfig, SyncTransportType } from '../sync/sync-config.ts';
|
|
22
23
|
import type { AutosyncAutoApplyTier, AutosyncConflictPolicy, AutosyncInterval, AutosyncRunStatus } from '../sync/autosync-config.ts';
|
|
23
24
|
/**
|
|
24
25
|
* 同步 token 的 DSH credentials 引用名(POSIX env-var 形态,满足 CredentialRef 品牌要求)。
|
|
@@ -273,3 +274,24 @@ export declare function executeRestorePlan(plan: RestorePlan, exec: RestoreExecu
|
|
|
273
274
|
}) => void, journal?: RestoreJournalPort, resumeHint?: RestoreResumeHint): Promise<RestoreReport>;
|
|
274
275
|
/** 宿主 restore 执行器装配:ctx.fs(home-relative)+ 快照目录(node fs)+ runDshPlugin。 */
|
|
275
276
|
export declare function makeRestoreExecutor(snapshotDir: string, host: HostContext, profile: string): RestoreExecutor;
|
|
277
|
+
/** parseSyncBody 的凭据写入依赖(只用到 set;测试可注入内存 mock)。 */
|
|
278
|
+
export interface ParseSyncBodyDeps {
|
|
279
|
+
credentials: Pick<CredentialProvider, 'set'>;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* 解析同步请求体,按 transport 分支返回归一化的 SyncConfig(可辨识联合,schemaVersion=2)。
|
|
283
|
+
* 请求体形状(flat,M4 契约):
|
|
284
|
+
* - git: { transport:'git', repoUrl, token? } —— token 非空写 SYNC_CREDENTIAL_REF;
|
|
285
|
+
* git 可执行文件固定使用系统 PATH 中的 git(不再接受自定义 gitBin)。
|
|
286
|
+
* - webdav: { transport:'webdav', url, username?, password? } —— password 非空写 SYNC_WEBDAV_CREDENTIAL_REF。
|
|
287
|
+
* 返回值不含任何 secret(password/token 只进 credentials,永不回传/落同步文件)。
|
|
288
|
+
*/
|
|
289
|
+
export declare function parseSyncBody(body: Record<string, unknown>, deps: ParseSyncBodyDeps): Promise<SyncConfig>;
|
|
290
|
+
/** 由 SyncConfig 合成 WebDAV 通道 baseUrl(webdav.url,尾部规范化带 '/';git 通道返回 '')。 */
|
|
291
|
+
export declare function webdavBaseUrl(cfg: SyncConfig): string;
|
|
292
|
+
/**
|
|
293
|
+
* 补全 webdav 配置缺失的 username(从持久化配置回填;纯函数,不修改入参)。
|
|
294
|
+
* 语义与 password 一致:请求未带 username(表单留空/挂载自动加载)→ 沿用已保存的值;
|
|
295
|
+
* 请求显式带 username → 原样保留(用户新输入优先)。非 webdav / 无持久化 → 原样返回。
|
|
296
|
+
*/
|
|
297
|
+
export declare function mergePersistedWebDavUsername(cfg: SyncConfig, persisted: SyncConfig | null): SyncConfig;
|
|
@@ -25,6 +25,7 @@ import { decryptCredentials, SecurityError } from '../security/index.js';
|
|
|
25
25
|
import { engineMsg } from '../core/engine-locale.js';
|
|
26
26
|
import { createPreRestoreAttemptDir } from '../core/restore.js';
|
|
27
27
|
import { collectRestoreWalEntries, createRestoreWal, restoreActionStepId, restoreWalHandlesFromSteps } from '../core/restore-wal.js';
|
|
28
|
+
import { GIST_PROVIDER, cloudSecretRef, isS3CompatProvider, isWebDavConfig, parseSyncChannel, validateCloudChannelInput, validateRepoUrl, validateWebDavUrl } from '../sync/sync-config.js';
|
|
28
29
|
import { DEFAULT_AUTOSYNC_AUTO_APPLY_TIER, DEFAULT_AUTOSYNC_CONFLICT_POLICY, DEFAULT_AUTOSYNC_REALTIME, DEFAULT_AUTOSYNC_REMOTE_CHECK_MS, lastRunFailureMessage, readAllAutosyncConfigs, readAutosyncConfig } from '../sync/autosync-config.js';
|
|
29
30
|
import { SYNC_CHANNELS } from '../sync/sync-config.js';
|
|
30
31
|
import { normalizeSessionsInclude } from '../sync/sync-selection.js';
|
|
@@ -634,4 +635,188 @@ export function makeRestoreExecutor(snapshotDir, host, profile) {
|
|
|
634
635
|
},
|
|
635
636
|
};
|
|
636
637
|
}
|
|
638
|
+
/**
|
|
639
|
+
* 解析同步请求体,按 transport 分支返回归一化的 SyncConfig(可辨识联合,schemaVersion=2)。
|
|
640
|
+
* 请求体形状(flat,M4 契约):
|
|
641
|
+
* - git: { transport:'git', repoUrl, token? } —— token 非空写 SYNC_CREDENTIAL_REF;
|
|
642
|
+
* git 可执行文件固定使用系统 PATH 中的 git(不再接受自定义 gitBin)。
|
|
643
|
+
* - webdav: { transport:'webdav', url, username?, password? } —— password 非空写 SYNC_WEBDAV_CREDENTIAL_REF。
|
|
644
|
+
* 返回值不含任何 secret(password/token 只进 credentials,永不回传/落同步文件)。
|
|
645
|
+
*/
|
|
646
|
+
export async function parseSyncBody(body, deps) {
|
|
647
|
+
const rawTransport = body['transport'];
|
|
648
|
+
// 通道值解析:接受通道名(s3/gist);也接受**具体兼容商**(oss/cos/minio/kodo)直接落到 s3 通道
|
|
649
|
+
const transport = parseSyncChannel(rawTransport) ?? (isS3CompatProvider(rawTransport) ? 's3' : 'git');
|
|
650
|
+
if (transport === 's3')
|
|
651
|
+
return parseCloudS3Body(body, rawTransport, deps);
|
|
652
|
+
if (transport === 'gist')
|
|
653
|
+
return parseCloudGistBody(body, deps);
|
|
654
|
+
if (transport === 'webdav') {
|
|
655
|
+
const url = typeof body['url'] === 'string' ? body['url'].trim() : '';
|
|
656
|
+
if (url === '')
|
|
657
|
+
throw new SyncRouteError('url is required for webdav');
|
|
658
|
+
const urlError = validateWebDavUrl(url);
|
|
659
|
+
if (urlError !== null)
|
|
660
|
+
throw new SyncRouteError(urlError);
|
|
661
|
+
const username = typeof body['username'] === 'string' && body['username'] !== '' ? body['username'] : undefined;
|
|
662
|
+
const password = typeof body['password'] === 'string' && body['password'] !== '' ? body['password'] : undefined;
|
|
663
|
+
if (password !== undefined) {
|
|
664
|
+
try {
|
|
665
|
+
await deps.credentials.set(credentialRef(SYNC_WEBDAV_CREDENTIAL_REF), password);
|
|
666
|
+
}
|
|
667
|
+
catch (error) {
|
|
668
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
669
|
+
throw new SyncRouteError(engineMsg('host.syncWebdavPasswordWriteFailed', { reason, ref: SYNC_WEBDAV_CREDENTIAL_REF }));
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
return {
|
|
673
|
+
schemaVersion: 2,
|
|
674
|
+
transport: 'webdav',
|
|
675
|
+
webdav: { url, ...(username !== undefined ? { username } : {}) },
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
// git 通道(沿用现有逻辑)
|
|
679
|
+
const repoUrl = typeof body['repoUrl'] === 'string' ? body['repoUrl'].trim() : '';
|
|
680
|
+
if (repoUrl === '')
|
|
681
|
+
throw new SyncRouteError('repoUrl is required');
|
|
682
|
+
const urlError = validateRepoUrl(repoUrl);
|
|
683
|
+
if (urlError !== null)
|
|
684
|
+
throw new SyncRouteError(urlError);
|
|
685
|
+
const token = typeof body['token'] === 'string' && body['token'] !== '' ? body['token'] : undefined;
|
|
686
|
+
if (token !== undefined) {
|
|
687
|
+
try {
|
|
688
|
+
await deps.credentials.set(credentialRef(SYNC_CREDENTIAL_REF), token);
|
|
689
|
+
}
|
|
690
|
+
catch (error) {
|
|
691
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
692
|
+
throw new SyncRouteError(engineMsg('host.syncTokenWriteFailed', { reason, ref: SYNC_CREDENTIAL_REF }));
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
return {
|
|
696
|
+
schemaVersion: 2,
|
|
697
|
+
transport: 'git',
|
|
698
|
+
git: { repoUrl },
|
|
699
|
+
};
|
|
700
|
+
}
|
|
701
|
+
/** 请求体字段 → 去空白字符串(非字符串 = 空)。 */
|
|
702
|
+
function syncStr(value) {
|
|
703
|
+
return typeof value === 'string' ? value.trim() : '';
|
|
704
|
+
}
|
|
705
|
+
/** 云端点密钥写入失败 → 可操作错误(**含 ref 名、绝不含密钥值**)。 */
|
|
706
|
+
function cloudCredentialWriteError(ref, kind, error) {
|
|
707
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
708
|
+
return new SyncRouteError(engineMsg('host.syncCredentialWriteFailed', { kind, reason, ref }), 400, 'cloud.credentialsWriteFailed');
|
|
709
|
+
}
|
|
710
|
+
/**
|
|
711
|
+
* s3 通道请求体 → SyncConfig(provider 必填或由 transport 直接给出)。
|
|
712
|
+
* 非密字段按 validateCloudChannelInput 校验(错误码 = HTTP body.code,由 UI 映射字典);
|
|
713
|
+
* 密钥**只写**进 DSH credentials 的 cloudSecretRef(provider) 槽位,绝不进返回值 / 文件 / 日志。
|
|
714
|
+
*/
|
|
715
|
+
async function parseCloudS3Body(body, rawTransport, deps) {
|
|
716
|
+
const provider = isS3CompatProvider(body['provider'])
|
|
717
|
+
? body['provider']
|
|
718
|
+
: (isS3CompatProvider(rawTransport) ? rawTransport : null);
|
|
719
|
+
if (provider === null) {
|
|
720
|
+
throw new SyncRouteError('provider is required for s3 (s3/oss/cos/minio/kodo)', 400, 'cloud.providerUnknown');
|
|
721
|
+
}
|
|
722
|
+
const endpoint = syncStr(body['endpoint']).replace(/\/+$/, '');
|
|
723
|
+
const region = syncStr(body['region']);
|
|
724
|
+
const bucket = syncStr(body['bucket']);
|
|
725
|
+
const accessKeyId = syncStr(body['accessKeyId']);
|
|
726
|
+
const prefix = syncStr(body['prefix']);
|
|
727
|
+
const pathStyle = typeof body['pathStyle'] === 'boolean' ? body['pathStyle'] : undefined;
|
|
728
|
+
const dialectId = body['dialectId'] === 'aws4' || body['dialectId'] === 'oss4' ? body['dialectId'] : undefined;
|
|
729
|
+
const issue = validateCloudChannelInput(provider, {
|
|
730
|
+
endpoint,
|
|
731
|
+
region,
|
|
732
|
+
bucket,
|
|
733
|
+
accessKeyId,
|
|
734
|
+
...(prefix === '' ? {} : { prefix }),
|
|
735
|
+
...(pathStyle === undefined ? {} : { pathStyle }),
|
|
736
|
+
...(dialectId === undefined ? {} : { dialectId }),
|
|
737
|
+
});
|
|
738
|
+
if (issue !== null)
|
|
739
|
+
throw new SyncRouteError(issue, 400, issue);
|
|
740
|
+
const secret = typeof body['secret'] === 'string' && body['secret'] !== '' ? body['secret'] : undefined;
|
|
741
|
+
if (secret !== undefined) {
|
|
742
|
+
const ref = cloudSecretRef(provider);
|
|
743
|
+
try {
|
|
744
|
+
await deps.credentials.set(credentialRef(ref), secret);
|
|
745
|
+
}
|
|
746
|
+
catch (error) {
|
|
747
|
+
throw cloudCredentialWriteError(ref, engineMsg('host.syncKindS3Secret'), error);
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
return {
|
|
751
|
+
schemaVersion: 2,
|
|
752
|
+
transport: 's3',
|
|
753
|
+
s3: {
|
|
754
|
+
provider,
|
|
755
|
+
endpoint,
|
|
756
|
+
region,
|
|
757
|
+
bucket,
|
|
758
|
+
accessKeyId,
|
|
759
|
+
...(prefix === '' ? {} : { prefix }),
|
|
760
|
+
...(pathStyle === undefined ? {} : { pathStyle }),
|
|
761
|
+
...(dialectId === undefined ? {} : { dialectId }),
|
|
762
|
+
},
|
|
763
|
+
};
|
|
764
|
+
}
|
|
765
|
+
/**
|
|
766
|
+
* gist 通道请求体 → SyncConfig。token 只写进 cloudSecretRef('gist') 槽位
|
|
767
|
+
* (请求体字段名 token 或 secret 都接受;值绝不进返回值 / 文件 / 日志)。
|
|
768
|
+
*/
|
|
769
|
+
async function parseCloudGistBody(body, deps) {
|
|
770
|
+
const gistId = syncStr(body['gistId']);
|
|
771
|
+
const apiBaseUrl = syncStr(body['apiBaseUrl']);
|
|
772
|
+
const filePrefix = syncStr(body['filePrefix']);
|
|
773
|
+
const issue = validateCloudChannelInput(GIST_PROVIDER, {
|
|
774
|
+
gistId,
|
|
775
|
+
...(apiBaseUrl === '' ? {} : { apiBaseUrl }),
|
|
776
|
+
...(filePrefix === '' ? {} : { filePrefix }),
|
|
777
|
+
});
|
|
778
|
+
if (issue !== null)
|
|
779
|
+
throw new SyncRouteError(issue, 400, issue);
|
|
780
|
+
const token = typeof body['token'] === 'string' && body['token'] !== ''
|
|
781
|
+
? body['token']
|
|
782
|
+
: (typeof body['secret'] === 'string' && body['secret'] !== '' ? body['secret'] : undefined);
|
|
783
|
+
if (token !== undefined) {
|
|
784
|
+
const ref = cloudSecretRef(GIST_PROVIDER);
|
|
785
|
+
try {
|
|
786
|
+
await deps.credentials.set(credentialRef(ref), token);
|
|
787
|
+
}
|
|
788
|
+
catch (error) {
|
|
789
|
+
throw cloudCredentialWriteError(ref, 'Gist token', error);
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
return {
|
|
793
|
+
schemaVersion: 2,
|
|
794
|
+
transport: 'gist',
|
|
795
|
+
gist: {
|
|
796
|
+
gistId,
|
|
797
|
+
...(apiBaseUrl === '' ? {} : { apiBaseUrl }),
|
|
798
|
+
...(filePrefix === '' ? {} : { filePrefix }),
|
|
799
|
+
},
|
|
800
|
+
};
|
|
801
|
+
}
|
|
802
|
+
/** 由 SyncConfig 合成 WebDAV 通道 baseUrl(webdav.url,尾部规范化带 '/';git 通道返回 '')。 */
|
|
803
|
+
export function webdavBaseUrl(cfg) {
|
|
804
|
+
if (!isWebDavConfig(cfg))
|
|
805
|
+
return '';
|
|
806
|
+
return cfg.webdav.url.replace(/\/+$/, '') + '/';
|
|
807
|
+
}
|
|
808
|
+
/**
|
|
809
|
+
* 补全 webdav 配置缺失的 username(从持久化配置回填;纯函数,不修改入参)。
|
|
810
|
+
* 语义与 password 一致:请求未带 username(表单留空/挂载自动加载)→ 沿用已保存的值;
|
|
811
|
+
* 请求显式带 username → 原样保留(用户新输入优先)。非 webdav / 无持久化 → 原样返回。
|
|
812
|
+
*/
|
|
813
|
+
export function mergePersistedWebDavUsername(cfg, persisted) {
|
|
814
|
+
if (!isWebDavConfig(cfg) || (cfg.webdav.username !== undefined && cfg.webdav.username !== ''))
|
|
815
|
+
return cfg;
|
|
816
|
+
if (persisted !== null && isWebDavConfig(persisted)
|
|
817
|
+
&& typeof persisted.webdav.username === 'string' && persisted.webdav.username !== '') {
|
|
818
|
+
return { ...cfg, webdav: { ...cfg.webdav, username: persisted.webdav.username } };
|
|
819
|
+
}
|
|
820
|
+
return cfg;
|
|
821
|
+
}
|
|
637
822
|
//# sourceMappingURL=route-support.js.map
|
package/lib/routes/snapshots.js
CHANGED
|
@@ -4,13 +4,12 @@
|
|
|
4
4
|
* W1(host-entry#F-02/#F-03):路由只在这里声明一次 —— endpoint({ path, methods }, handler) 的
|
|
5
5
|
* path/methods 就是唯一声明处;围栏、方法判定与顶层异常处理由 src/routes/kit.ts 在注册点统一提供。
|
|
6
6
|
*/
|
|
7
|
-
import { endpoint, readJsonBody, writeJson } from './kit.js';
|
|
8
|
-
import { TransactionRecoveryRequiredError } from '../core/phase3-host.js';
|
|
7
|
+
import { endpoint, readJsonBody, writeJson, writeMutationError } from './kit.js';
|
|
9
8
|
import { deleteSnapshot, isValidSnapshotId, listSnapshots, planRestore, setSnapshotPinned } from '../core/restore.js';
|
|
10
9
|
import { snapshotFileDiff, summarizeRestoreChanges } from '../core/snapshot-diff.js';
|
|
11
10
|
import { buildFileDiffBody, buildRestoreBody, executeRestorePlan, makeRestoreExecutor } from './route-support.js';
|
|
12
11
|
import { probeRestoreResume, runRestoreWithResume } from '../core/restore-resume.js';
|
|
13
|
-
import {
|
|
12
|
+
import { runWithMutationLock } from '../utils/env-lock.js';
|
|
14
13
|
import { isENOENT } from '../utils/guards.js';
|
|
15
14
|
import { join } from 'node:path';
|
|
16
15
|
import { createHash } from 'node:crypto';
|
|
@@ -185,14 +184,8 @@ export function snapshotRoutes(env) {
|
|
|
185
184
|
});
|
|
186
185
|
}
|
|
187
186
|
catch (error) {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
writeJson(res, 423, { error: error.message, code: 'mutation-locked' });
|
|
191
|
-
}
|
|
192
|
-
else if (error instanceof TransactionRecoveryRequiredError) {
|
|
193
|
-
writeJson(res, 423, { error: error.message, code: 'transaction-recovery-required' });
|
|
194
|
-
}
|
|
195
|
-
else {
|
|
187
|
+
// 423 家族(SAFE MODE / 环境锁 / 未收敛事务)的唯一映射在 kit;本路由其余错误沿用 400 口径。
|
|
188
|
+
if (!writeMutationError(res, host, error)) {
|
|
196
189
|
writeJson(res, 400, { error: error instanceof Error ? error.message : String(error) });
|
|
197
190
|
}
|
|
198
191
|
}
|
package/lib/routes/sync.js
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* W1(host-entry#F-02/#F-03):路由只在这里声明一次 —— endpoint({ path, methods }, handler) 的
|
|
5
5
|
* path/methods 就是唯一声明处;围栏、方法判定与顶层异常处理由 src/routes/kit.ts 在注册点统一提供。
|
|
6
6
|
*/
|
|
7
|
-
import { endpoint, queryParam, requireJsonObject, readJsonBody, writeJson } from './kit.js';
|
|
8
|
-
import {
|
|
7
|
+
import { endpoint, queryParam, requireJsonObject, readJsonBody, writeJson, writeMutationError } from './kit.js';
|
|
8
|
+
import { runWithMutationLock } from '../utils/env-lock.js';
|
|
9
9
|
import { FileSnapshotStore } from '../core/index.js';
|
|
10
10
|
import { rollback as performRollback } from '../core/rollback.js';
|
|
11
11
|
/**
|
|
@@ -377,11 +377,9 @@ export function syncRoutes(env) {
|
|
|
377
377
|
writeJson(res, 200, { ok: true, lastSyncChannel: channel });
|
|
378
378
|
}
|
|
379
379
|
catch (error) {
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
}
|
|
384
|
-
writeSyncRouteError(res, error);
|
|
380
|
+
// 423 家族(SAFE MODE / 环境锁)的唯一映射在 kit;其余沿用本组既有 SyncRouteError 口径。
|
|
381
|
+
if (!writeMutationError(res, host, error))
|
|
382
|
+
writeSyncRouteError(res, error);
|
|
385
383
|
}
|
|
386
384
|
}),
|
|
387
385
|
// ------------------------------------------------------ sync/push
|
|
@@ -36,7 +36,11 @@ export declare function maskHighEntropy(text: string): string;
|
|
|
36
36
|
export declare function redact(text: string, blacklist?: readonly string[]): string;
|
|
37
37
|
/** 对象级掩码:字段名命中敏感名单 → 整值替换(返回新对象,不改原对象;结构与类型保留) */
|
|
38
38
|
export declare function redactValue(value: unknown, blacklist?: readonly string[]): unknown;
|
|
39
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* 预编译脱敏器(多次调用复用;blacklist 为附加规范化字段名)。
|
|
41
|
+
* 正则实例**在创建时**各复制一份:模块级常量若与本函数共享,多线程无害但会让「谁动了 lastIndex」
|
|
42
|
+
* 不可追溯;复制成本只有一次,换来每个脱敏器实例自持状态。
|
|
43
|
+
*/
|
|
40
44
|
export declare function createRedactor(blacklist?: readonly string[]): (text: string) => string;
|
|
41
45
|
/** 默认名单(文档用;redact 的默认附加名单为空,内置判定已含 DEFAULT_SECRET_FIELD_NAMES) */
|
|
42
46
|
export { DEFAULT_SECRET_FIELD_NAMES };
|