@wanji_dsh/dsh-sales 0.9.7 → 0.10.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 +8 -4
- package/README.zh.md +8 -4
- package/dist/client.js +374 -97
- package/dist/host.js +1454 -776
- package/dist/types/update/activity.d.ts +28 -0
- package/dist/types/update/coordinator.d.ts +44 -0
- package/dist/types/update/guard.d.ts +3 -0
- package/dist/types/update/integration.d.ts +6 -0
- package/dist/types/update/manager.d.ts +13 -0
- package/dist/types/update/routes.d.ts +6 -0
- package/dist/types/update/state.d.ts +13 -0
- package/dist/types/update/types.d.ts +88 -0
- package/dist/types/update/version.d.ts +1 -0
- package/dist/types/wechat/service.d.ts +4 -0
- package/docs/auto-update.md +41 -0
- package/package.json +3 -2
- package/runtime/wechat-manifest.json +1 -1
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export declare const pause: (signal: AbortSignal, ms?: number) => Promise<void>;
|
|
2
|
+
/** A draining barrier allows descendants of in-flight work to finish. */
|
|
3
|
+
export declare class UpdateActivity {
|
|
4
|
+
private scope;
|
|
5
|
+
private pending;
|
|
6
|
+
private draining;
|
|
7
|
+
run<T>(work: () => Promise<T>): Promise<T>;
|
|
8
|
+
prepare(signal: AbortSignal): Promise<() => void>;
|
|
9
|
+
}
|
|
10
|
+
export interface ClientReadiness {
|
|
11
|
+
revision: number;
|
|
12
|
+
busy: boolean;
|
|
13
|
+
dirty: boolean;
|
|
14
|
+
prepared?: string;
|
|
15
|
+
}
|
|
16
|
+
/** Missing heartbeats remain unknown; a timeout never proves a draft was saved. */
|
|
17
|
+
export declare class UpdateClients {
|
|
18
|
+
private windows;
|
|
19
|
+
private request?;
|
|
20
|
+
private now;
|
|
21
|
+
constructor(now?: () => number);
|
|
22
|
+
heartbeat(id: string, input: ClientReadiness): string | undefined;
|
|
23
|
+
unregister(id: string): void;
|
|
24
|
+
idle(): boolean;
|
|
25
|
+
prepare(id: string): void;
|
|
26
|
+
ready(id: string): boolean;
|
|
27
|
+
cancel(): void;
|
|
28
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { UpdateState } from './state.ts';
|
|
2
|
+
import { UpdateActivity, UpdateClients } from './activity.ts';
|
|
3
|
+
import { type UpdateSnapshot, type ResumeIntent } from './types.ts';
|
|
4
|
+
export interface UpdateOptions {
|
|
5
|
+
state: UpdateState;
|
|
6
|
+
manager: () => unknown;
|
|
7
|
+
version: string;
|
|
8
|
+
clients: UpdateClients;
|
|
9
|
+
activity: UpdateActivity;
|
|
10
|
+
sync: {
|
|
11
|
+
prepareUpdate(signal: AbortSignal): Promise<ResumeIntent>;
|
|
12
|
+
resumeAfterUpdate(intent: ResumeIntent): Promise<void>;
|
|
13
|
+
};
|
|
14
|
+
health(): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
/** Scheduling belongs to the plugin; package installation belongs to DSH. */
|
|
17
|
+
export declare class UpdateCoordinator {
|
|
18
|
+
private options;
|
|
19
|
+
private view;
|
|
20
|
+
private record;
|
|
21
|
+
private initialized?;
|
|
22
|
+
private checking?;
|
|
23
|
+
private job?;
|
|
24
|
+
private timer?;
|
|
25
|
+
private lifetime;
|
|
26
|
+
private disposed;
|
|
27
|
+
private invalid;
|
|
28
|
+
private nextCheck;
|
|
29
|
+
private failures;
|
|
30
|
+
constructor(options: UpdateOptions);
|
|
31
|
+
snapshot(): UpdateSnapshot;
|
|
32
|
+
initialize(): Promise<void>;
|
|
33
|
+
private initializeOnce;
|
|
34
|
+
private reconcile;
|
|
35
|
+
private reconcileOwned;
|
|
36
|
+
start(): void;
|
|
37
|
+
private schedule;
|
|
38
|
+
private tick;
|
|
39
|
+
check(): Promise<void>;
|
|
40
|
+
setAutomatic(enabled: boolean): Promise<void>;
|
|
41
|
+
requestInstall(manual?: boolean): Promise<void>;
|
|
42
|
+
private install;
|
|
43
|
+
dispose(): void;
|
|
44
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { HostContext } from '../knowledge-host.ts';
|
|
2
|
+
import type { WechatSyncService } from '../wechat/service.ts';
|
|
3
|
+
import { UpdateActivity } from './activity.ts';
|
|
4
|
+
import { UpdateCoordinator } from './coordinator.ts';
|
|
5
|
+
/** Optional native services: their absence must not prevent sales from starting. */
|
|
6
|
+
export declare function mountUpdates(ctx: HostContext, storageDir: string, activity: UpdateActivity, sync: WechatSyncService): UpdateCoordinator;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Manager, type Candidate, type VersionList, type Phase } from './types.ts';
|
|
2
|
+
export type Capability = {
|
|
3
|
+
status: 'ready';
|
|
4
|
+
manager: Manager;
|
|
5
|
+
installedVersion: string;
|
|
6
|
+
} | {
|
|
7
|
+
status: 'unsupported' | 'migration-required';
|
|
8
|
+
reason: string;
|
|
9
|
+
};
|
|
10
|
+
export declare function probeUpdateCapability(raw: unknown): Promise<Capability>;
|
|
11
|
+
export declare function selectCandidate(list: VersionList, running: string): Candidate | undefined;
|
|
12
|
+
/** A successful install response does not prove that HMR loaded new JavaScript. */
|
|
13
|
+
export declare function activationPhase(installed: string | undefined, running: string): Phase;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { HostContext } from '../knowledge-host.ts';
|
|
2
|
+
import type { UpdateCoordinator } from './coordinator.ts';
|
|
3
|
+
import type { UpdateClients } from './activity.ts';
|
|
4
|
+
export declare const UPDATE_METHOD = "wanji-sales-update/request";
|
|
5
|
+
/** Uses the same owner-authenticated shared Fetch channel as sales data routes. */
|
|
6
|
+
export declare function registerUpdateRoutes(ctx: HostContext, coordinator: UpdateCoordinator, clients: UpdateClients): void;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type UpdateRecord } from './types.ts';
|
|
2
|
+
/** Private updater state, never a copy of the profile's package files or business database. */
|
|
3
|
+
export declare class UpdateState {
|
|
4
|
+
readonly directory: string;
|
|
5
|
+
readonly filename: string;
|
|
6
|
+
readonly lockfile: string;
|
|
7
|
+
constructor(storageDir: string, profile: string);
|
|
8
|
+
private directoryReady;
|
|
9
|
+
read(): Promise<UpdateRecord>;
|
|
10
|
+
write(value: UpdateRecord): Promise<void>;
|
|
11
|
+
held(): Promise<boolean>;
|
|
12
|
+
acquire(): Promise<undefined | (() => Promise<void>)>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
export declare const PACKAGE_NAME = "@wanji_dsh/dsh-sales";
|
|
2
|
+
export declare const DEFAULT_AUTOMATIC = true;
|
|
3
|
+
export declare const REGISTRY = "https://registry.npmjs.org/";
|
|
4
|
+
export type Phase = 'idle' | 'checking' | 'available' | 'waiting-idle' | 'preparing' | 'installing' | 'verifying' | 'restart-required' | 'updated' | 'failed' | 'recovery-required' | 'unsupported' | 'migration-required';
|
|
5
|
+
export interface Bundle {
|
|
6
|
+
name: string;
|
|
7
|
+
version?: string;
|
|
8
|
+
updatable?: boolean;
|
|
9
|
+
update?: 'registry' | 'git';
|
|
10
|
+
enabled?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface PublishedVersion {
|
|
13
|
+
version: string;
|
|
14
|
+
tags: readonly string[];
|
|
15
|
+
prerelease: boolean;
|
|
16
|
+
bundle: boolean;
|
|
17
|
+
deprecated?: string;
|
|
18
|
+
incompatible?: unknown;
|
|
19
|
+
}
|
|
20
|
+
export type VersionList = {
|
|
21
|
+
status: 'listed';
|
|
22
|
+
installed: string;
|
|
23
|
+
registry: string | null;
|
|
24
|
+
versions: readonly PublishedVersion[];
|
|
25
|
+
} | {
|
|
26
|
+
status: 'refused';
|
|
27
|
+
problem: string;
|
|
28
|
+
reason: string;
|
|
29
|
+
};
|
|
30
|
+
export interface ChangeResult {
|
|
31
|
+
application: 'applied' | 'restart-required' | 'overridden' | 'failed' | 'cancelled';
|
|
32
|
+
error?: {
|
|
33
|
+
code?: string;
|
|
34
|
+
};
|
|
35
|
+
version?: string;
|
|
36
|
+
restartReason?: string;
|
|
37
|
+
}
|
|
38
|
+
export interface UpdateResult {
|
|
39
|
+
from: string;
|
|
40
|
+
to: string;
|
|
41
|
+
step: string;
|
|
42
|
+
result: ChangeResult;
|
|
43
|
+
restore?: ChangeResult;
|
|
44
|
+
}
|
|
45
|
+
export interface Manager {
|
|
46
|
+
listBundles(): Promise<readonly Bundle[]>;
|
|
47
|
+
listVersions(name: string, options: {
|
|
48
|
+
registry: string;
|
|
49
|
+
}, signal?: AbortSignal): Promise<VersionList>;
|
|
50
|
+
updateBundle(name: string, version: string, options: {
|
|
51
|
+
registry: string;
|
|
52
|
+
requestId: string;
|
|
53
|
+
}): Promise<UpdateResult>;
|
|
54
|
+
waitForInstall?(requestId: string): Promise<unknown>;
|
|
55
|
+
}
|
|
56
|
+
export interface Candidate {
|
|
57
|
+
version: string;
|
|
58
|
+
registry: string;
|
|
59
|
+
automatic: boolean;
|
|
60
|
+
}
|
|
61
|
+
export interface UpdateSnapshot {
|
|
62
|
+
phase: Phase;
|
|
63
|
+
runningVersion: string;
|
|
64
|
+
installedVersion?: string;
|
|
65
|
+
candidate?: Candidate;
|
|
66
|
+
automatic: boolean;
|
|
67
|
+
checkedAt?: number;
|
|
68
|
+
error?: string;
|
|
69
|
+
requestId?: string;
|
|
70
|
+
blocked?: string;
|
|
71
|
+
}
|
|
72
|
+
export interface ResumeIntent {
|
|
73
|
+
workspaceId?: string;
|
|
74
|
+
automatic: boolean;
|
|
75
|
+
}
|
|
76
|
+
export interface UpdateRecord {
|
|
77
|
+
schema: 1;
|
|
78
|
+
automatic: boolean;
|
|
79
|
+
requestId?: string;
|
|
80
|
+
from?: string;
|
|
81
|
+
to?: string;
|
|
82
|
+
phase: Phase;
|
|
83
|
+
startedAt?: number;
|
|
84
|
+
checkedAt?: number;
|
|
85
|
+
failedTarget?: string;
|
|
86
|
+
result?: UpdateResult;
|
|
87
|
+
resume?: ResumeIntent;
|
|
88
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const RUNNING_VERSION: string;
|
|
@@ -4,6 +4,7 @@ import { SourceWatcher } from './watcher.ts';
|
|
|
4
4
|
import { type NativeBackend } from './native.ts';
|
|
5
5
|
import type { SyncCapabilities, SyncStatus } from './types.ts';
|
|
6
6
|
import type { WechatRuntime } from './runtime.ts';
|
|
7
|
+
import type { ResumeIntent } from '../update/types.ts';
|
|
7
8
|
type Options = {
|
|
8
9
|
storageDir: string;
|
|
9
10
|
componentRoot: string;
|
|
@@ -27,6 +28,7 @@ export declare class WechatSyncService {
|
|
|
27
28
|
private failures;
|
|
28
29
|
private interval;
|
|
29
30
|
private closed;
|
|
31
|
+
private updatePreparing;
|
|
30
32
|
private capabilitiesAt;
|
|
31
33
|
private runtimePhase;
|
|
32
34
|
private capabilitiesLoading?;
|
|
@@ -49,6 +51,8 @@ export declare class WechatSyncService {
|
|
|
49
51
|
private schedule;
|
|
50
52
|
private cycle;
|
|
51
53
|
pause(workspace: string): SyncStatus;
|
|
54
|
+
prepareUpdate(signal: AbortSignal): Promise<ResumeIntent>;
|
|
55
|
+
resumeAfterUpdate(intent: ResumeIntent): Promise<void>;
|
|
52
56
|
authorize(workspace: string, requestId: string, approved: boolean): SyncStatus;
|
|
53
57
|
close(): Promise<void>;
|
|
54
58
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# 销售助手版本与更新(0.10.0 起)
|
|
2
|
+
|
|
3
|
+
本功能属于插件,使用现有 DSH 安装器,不修改 DSH 源码。公开可用版本以 npm `latest` 为准;源码中的版本不代表已发布。
|
|
4
|
+
|
|
5
|
+
## 默认自动更新
|
|
6
|
+
|
|
7
|
+
1. 首次先从 DSH「插件」页面按 npm 包名 `@wanji_dsh/dsh-sales` 安装包含此功能的版本。0.9.7 及更早版本需要手动升级一次;直接填 `.tgz` 地址不具有 registry 更新身份。旧 `@wanji/dsh-sales` 用户依分发文档迁移,保留配置与原 `storageDir`,不能同时启用两份插件。
|
|
8
|
+
2. 安装后自动检查,并在空闲时自动安装补丁;无需打开面板或勾选开关。页头「版本与更新」可查看进度;如主动关闭自动安装,该选择会保留到下次启动。
|
|
9
|
+
3. 同一 major/minor 的正式补丁可自动安装,例如 0.10.0 → 0.10.1。跨 minor(0.10 → 0.11)只提示,点「立即更新」后仍要先保存和等待任务结束。
|
|
10
|
+
|
|
11
|
+
Host 启动 60–120 秒后检查,随后约每 6 小时检查;只跟随兼容、未弃用的正式 `latest`,不跟随 `next`/beta,不猜测列表中最大的版本。网络失败分别延后 15 分钟、1 小时、6 小时;同一失败目标不会无限自动重试,可手动重试。退出 DSH 或禁用插件后不运行后台服务。
|
|
12
|
+
|
|
13
|
+
## 检查反馈
|
|
14
|
+
|
|
15
|
+
按 npm 包名安装且宿主支持更新时,点击「检查更新」立即显示「正在检查新版本」,完成后显示结果和上次检查时间。检查失败可重试,连接恢复后不保留旧连接错误。
|
|
16
|
+
|
|
17
|
+
源码链接、tgz 安装或缺少原生更新能力时,面板说明限制,并禁用不可执行的在线检查;不把安装方式限制显示成网络故障。本地开发版随源码构建更新。旧入口迁移必须保留配置与原数据目录,不同时启用两份销售助手。
|
|
18
|
+
|
|
19
|
+
## 保存与生效
|
|
20
|
+
|
|
21
|
+
所有已连接销售窗口停止编辑至少 60 秒、没有未保存内容/任务,才开始自动准备。每个窗口需再次确认保存;Host 等待 CRM、生成相关工具和写入完成,停止下一轮微信同步并排空当前采集、消息及媒体提交。准备 30 秒未完成就延后,保留已有业务任务。正在编辑的 CRM 表单也会阻止自动安装。
|
|
22
|
+
|
|
23
|
+
断开的窗口不能因为心跳过期就被当成已保存。请重新连接该窗口、保存后关闭;无法确认时保守延后。若窗口已异常退出,在确认内容已保存后可重启应用重新建立窗口状态。界面只展示实际阶段,不模拟下载百分比。安装期间新打开的销售窗口同样暂停编辑。
|
|
24
|
+
|
|
25
|
+
当前实测 Windows Desktop 0.2.2-rc.3 与 Mac 开发 SDK 0.2.2-rc.1 的安装器可能返回 `applied`,实际仍加载旧模块。因此插件分别显示“正在使用”和“已安装”:不一致时提示“已安装,下次重启应用生效”。不会强制重启;可以继续使用,方便时自行重启。重启后由新 Host 检查版本和本地 SQLite,再报告更新生效。微信组件未就绪则保留同步设置并重试,不能把安装成功当作同步成功。
|
|
26
|
+
|
|
27
|
+
## 数据与失败恢复
|
|
28
|
+
|
|
29
|
+
沿用现有 `storageDir`,不改业务数据库格式。微信消息、草稿、CRM 绑定、已处理状态、一次性 CRM 上下文文件和 `wechat-runtime` 内容缓存不随包替换。更新状态在 `storageDir/updates/<profile摘要>/`;不同 profile 独立,自动安装进程锁仅保护本插件,不是 DSH 所有手动操作的全局锁。
|
|
30
|
+
|
|
31
|
+
- 没有原生更新 API:销售功能继续运行,从 DSH「插件」页面手动更新。
|
|
32
|
+
- 保存失败:先解决草稿写入、其他窗口冲突或未完成任务,再尝试更新。
|
|
33
|
+
- 下载/安装失败:保留原始安装器策略,不自动批准安装脚本或版本豁免。原生安装器可能恢复旧包;恢复也可能失败。
|
|
34
|
+
- 记录损坏、安装结果未知或恢复失败:停止自动尝试,通过 DSH「插件」页面检查安装版本、日志和启用状态;必要时重新安装明确版本并恢复原配置。保留原数据目录,不清空 profile 或 pnpm store。
|
|
35
|
+
- 新版启动健康检查失败:不宣称更新成功,不承诺自动降级。使用修复版或人工恢复;原生 `updateBundle` 不能作为降级接口。
|
|
36
|
+
|
|
37
|
+
## English quick guide
|
|
38
|
+
|
|
39
|
+
From 0.10.0, update checks and idle patch installation are enabled by default. No setup or switch is required; **Version & updates** shows progress and allows disabling automatic installation. An explicit opt-out survives restarts. Install by the npm package name first; existing 0.9.7/tarball users need one manual upgrade or migration. Minor upgrades require confirmation. All sales windows must save and finish their tasks before installation. Unknown or disconnected windows defer updates.
|
|
40
|
+
|
|
41
|
+
Installation and activation are separate. Tested DSH versions can reload old modules even after reporting success, so the plugin shows **Installed · Takes effect after the next app restart** until the running build matches. It never forces a restart. Local data and runtime caches remain in the existing storage directory. On an unknown result or failed recovery, use DSH's Plugins page to inspect or reinstall a specific version without deleting that data.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wanji_dsh/dsh-sales",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Sales workspace with local Windows/macOS WeChat sync, one-time CRM context, Flash drafts and filtered knowledge.",
|
|
6
6
|
"engines": {
|
|
@@ -37,7 +37,8 @@
|
|
|
37
37
|
"!.dsh/**/__pycache__/**",
|
|
38
38
|
"runtime/*.py",
|
|
39
39
|
"runtime/*.json",
|
|
40
|
-
"docs/licenses/"
|
|
40
|
+
"docs/licenses/",
|
|
41
|
+
"docs/auto-update.md"
|
|
41
42
|
],
|
|
42
43
|
"scripts": {
|
|
43
44
|
"build": "node build.mjs && tsc -p tsconfig.host.json",
|