dsh-mobile-ios 0.2.6 → 0.2.8
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 -21
- package/README.md +284 -284
- package/cordis.patch.yml +20 -20
- package/entries/plugin.mjs +246 -246
- package/entries/sidecar.mjs +111 -111
- package/lib/client.js +1294 -1193
- package/lib/vendor/qrcode-generator.cjs +2297 -2297
- package/lib/vendor/qrcode-utf8.cjs +26 -26
- package/package.json +53 -53
- package/src/adapter/artifacts.mjs +235 -235
- package/src/adapter/cordis-host.mjs +1225 -1225
- package/src/adapter/mock-host.mjs +437 -437
- package/src/adapter/mux-host.mjs +99 -99
- package/src/adapter/session-history.mjs +241 -241
- package/src/cloudflare.mjs +628 -628
- package/src/cloudflared-install.mjs +139 -0
- package/src/dns-label.mjs +32 -32
- package/src/dns-probe.mjs +90 -90
- package/src/file-log.mjs +68 -68
- package/src/gateway.mjs +285 -285
- package/src/pairing.mjs +300 -300
- package/src/protocol.mjs +59 -59
- package/src/provision-local.mjs +309 -309
- package/src/rest.mjs +812 -786
- package/src/ring.mjs +148 -148
- package/src/server.mjs +219 -219
- package/src/tunnel.mjs +523 -504
- package/src/version.mjs +24 -24
- package/src/ws.mjs +332 -332
package/src/protocol.mjs
CHANGED
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
// protocol.mjs — 契约 v0.2 的常量与错误码表
|
|
2
|
-
// 原则:错误码只增不改;客户端按 code 分流,不按 message 文本匹配。
|
|
3
|
-
|
|
4
|
-
export const PROTOCOL_VERSION = '1.0';
|
|
5
|
-
export const PROTOCOL_MAJOR_SUPPORTED = [1];
|
|
6
|
-
|
|
7
|
-
export const EV_KINDS = ['state', 'log', 'turn', 'todo', 'artifact', 'gateway'];
|
|
8
|
-
// idle:宿主里会话存在、但没有在跑任何回合(可以继续说话)。
|
|
9
|
-
// 与 interrupted 的区别是「我们没有理由说它被打断过」——见 cordis-host.mjs 的映射说明。
|
|
10
|
-
export const TASK_STATUS = ['running', 'needsYou', 'done', 'failed', 'idle', 'interrupted', 'cancelled'];
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* 错误码表。
|
|
14
|
-
* http:REST 场景返回的 HTTP 状态;wsClose:WS 场景的关闭码(null 表示不关连接)。
|
|
15
|
-
* retry:客户端是否应退避重试(false 表示"不要重试,按文案引导用户")。
|
|
16
|
-
*/
|
|
17
|
-
export const ERRORS = {
|
|
18
|
-
4001: { message: '凭证已失效,请重新配对', http: 401, retry: false, action: 'needsPairing' },
|
|
19
|
-
4003: { message: '这台主机不信任当前地址', http: 403, retry: false, action: 'rePair' },
|
|
20
|
-
4004: { message: '协议版本不兼容,请更新主机端', http: 400, retry: false, action: 'readOnly' },
|
|
21
|
-
4007: { message: '主机忙,稍后重试', http: 503, retry: true, action: 'backoff' },
|
|
22
|
-
4008: { message: '配对码已过期或错误', http: 400, retry: false, action: 'rePair' },
|
|
23
|
-
4009: { message: '这台设备已被撤销', http: 401, retry: false, action: 'clearCredential' },
|
|
24
|
-
4010: { message: '待办已过期', http: 409, retry: false, action: 'grayOut' },
|
|
25
|
-
4011: { message: '任务不存在', http: 404, retry: false, action: 'interrupted' },
|
|
26
|
-
4021: { message: '当前主机不支持该方法', http: 501, retry: false, action: 'hideControl' },
|
|
27
|
-
4029: { message: '操作过于频繁', http: 429, retry: true, action: 'backoff' },
|
|
28
|
-
4400: { message: '请求参数不合法', http: 400, retry: false, action: 'fixRequest' },
|
|
29
|
-
4404: { message: '接口不存在', http: 404, retry: false, action: 'fixRequest' },
|
|
30
|
-
4500: { message: '主机内部错误', http: 500, retry: true, action: 'backoff' },
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export class GatewayError extends Error {
|
|
34
|
-
constructor(code, message, extra = {}) {
|
|
35
|
-
super(message || ERRORS[code]?.message || 'UNKNOWN');
|
|
36
|
-
this.code = code;
|
|
37
|
-
this.extra = extra;
|
|
38
|
-
}
|
|
39
|
-
toJSON() {
|
|
40
|
-
return { code: this.code, message: this.message, ...this.extra };
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export const fail = (code, message, extra) => new GatewayError(code, message, extra);
|
|
45
|
-
|
|
46
|
-
export function newId(prefix) {
|
|
47
|
-
// 只用于内部 id(ticket / 连接 id / 设备 id),不需要密码学强度之外的特性
|
|
48
|
-
const rand = Math.random().toString(36).slice(2, 8);
|
|
49
|
-
return `${prefix}_${Date.now().toString(36)}${rand}`;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function majorOf(version) {
|
|
53
|
-
const n = Number.parseInt(String(version || '').split('.')[0], 10);
|
|
54
|
-
return Number.isFinite(n) ? n : NaN;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function isSupportedProtocol(version) {
|
|
58
|
-
return PROTOCOL_MAJOR_SUPPORTED.includes(majorOf(version));
|
|
59
|
-
}
|
|
1
|
+
// protocol.mjs — 契约 v0.2 的常量与错误码表
|
|
2
|
+
// 原则:错误码只增不改;客户端按 code 分流,不按 message 文本匹配。
|
|
3
|
+
|
|
4
|
+
export const PROTOCOL_VERSION = '1.0';
|
|
5
|
+
export const PROTOCOL_MAJOR_SUPPORTED = [1];
|
|
6
|
+
|
|
7
|
+
export const EV_KINDS = ['state', 'log', 'turn', 'todo', 'artifact', 'gateway'];
|
|
8
|
+
// idle:宿主里会话存在、但没有在跑任何回合(可以继续说话)。
|
|
9
|
+
// 与 interrupted 的区别是「我们没有理由说它被打断过」——见 cordis-host.mjs 的映射说明。
|
|
10
|
+
export const TASK_STATUS = ['running', 'needsYou', 'done', 'failed', 'idle', 'interrupted', 'cancelled'];
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 错误码表。
|
|
14
|
+
* http:REST 场景返回的 HTTP 状态;wsClose:WS 场景的关闭码(null 表示不关连接)。
|
|
15
|
+
* retry:客户端是否应退避重试(false 表示"不要重试,按文案引导用户")。
|
|
16
|
+
*/
|
|
17
|
+
export const ERRORS = {
|
|
18
|
+
4001: { message: '凭证已失效,请重新配对', http: 401, retry: false, action: 'needsPairing' },
|
|
19
|
+
4003: { message: '这台主机不信任当前地址', http: 403, retry: false, action: 'rePair' },
|
|
20
|
+
4004: { message: '协议版本不兼容,请更新主机端', http: 400, retry: false, action: 'readOnly' },
|
|
21
|
+
4007: { message: '主机忙,稍后重试', http: 503, retry: true, action: 'backoff' },
|
|
22
|
+
4008: { message: '配对码已过期或错误', http: 400, retry: false, action: 'rePair' },
|
|
23
|
+
4009: { message: '这台设备已被撤销', http: 401, retry: false, action: 'clearCredential' },
|
|
24
|
+
4010: { message: '待办已过期', http: 409, retry: false, action: 'grayOut' },
|
|
25
|
+
4011: { message: '任务不存在', http: 404, retry: false, action: 'interrupted' },
|
|
26
|
+
4021: { message: '当前主机不支持该方法', http: 501, retry: false, action: 'hideControl' },
|
|
27
|
+
4029: { message: '操作过于频繁', http: 429, retry: true, action: 'backoff' },
|
|
28
|
+
4400: { message: '请求参数不合法', http: 400, retry: false, action: 'fixRequest' },
|
|
29
|
+
4404: { message: '接口不存在', http: 404, retry: false, action: 'fixRequest' },
|
|
30
|
+
4500: { message: '主机内部错误', http: 500, retry: true, action: 'backoff' },
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export class GatewayError extends Error {
|
|
34
|
+
constructor(code, message, extra = {}) {
|
|
35
|
+
super(message || ERRORS[code]?.message || 'UNKNOWN');
|
|
36
|
+
this.code = code;
|
|
37
|
+
this.extra = extra;
|
|
38
|
+
}
|
|
39
|
+
toJSON() {
|
|
40
|
+
return { code: this.code, message: this.message, ...this.extra };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export const fail = (code, message, extra) => new GatewayError(code, message, extra);
|
|
45
|
+
|
|
46
|
+
export function newId(prefix) {
|
|
47
|
+
// 只用于内部 id(ticket / 连接 id / 设备 id),不需要密码学强度之外的特性
|
|
48
|
+
const rand = Math.random().toString(36).slice(2, 8);
|
|
49
|
+
return `${prefix}_${Date.now().toString(36)}${rand}`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function majorOf(version) {
|
|
53
|
+
const n = Number.parseInt(String(version || '').split('.')[0], 10);
|
|
54
|
+
return Number.isFinite(n) ? n : NaN;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function isSupportedProtocol(version) {
|
|
58
|
+
return PROTOCOL_MAJOR_SUPPORTED.includes(majorOf(version));
|
|
59
|
+
}
|