@wkgeo/cli 0.0.0-stage → 1.1.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/CHANGELOG.md +223 -0
- package/LICENSE +21 -0
- package/README.md +1042 -3
- package/SKILL.md +927 -0
- package/lib/ai/client.mjs +161 -0
- package/lib/ai/config.mjs +221 -0
- package/lib/ai/context.mjs +468 -0
- package/lib/ai/log.mjs +53 -0
- package/lib/api.mjs +339 -0
- package/lib/args.mjs +235 -0
- package/lib/cli.mjs +168 -0
- package/lib/cms.mjs +330 -0
- package/lib/commands/ai.mjs +392 -0
- package/lib/commands/apps.mjs +116 -0
- package/lib/commands/auth.mjs +1288 -0
- package/lib/commands/billing.mjs +666 -0
- package/lib/commands/cms.mjs +2533 -0
- package/lib/commands/config-auth.mjs +621 -0
- package/lib/commands/config.mjs +434 -0
- package/lib/commands/dnscred.mjs +428 -0
- package/lib/commands/domainops.mjs +546 -0
- package/lib/commands/domainorder.mjs +439 -0
- package/lib/commands/import.mjs +164 -0
- package/lib/commands/index.mjs +541 -0
- package/lib/commands/logs.mjs +141 -0
- package/lib/commands/orders.mjs +444 -0
- package/lib/commands/overview.mjs +394 -0
- package/lib/commands/plugins.mjs +678 -0
- package/lib/commands/site.mjs +435 -0
- package/lib/commands/siteops.mjs +1012 -0
- package/lib/commands/sites.mjs +905 -0
- package/lib/commands/skill.mjs +119 -0
- package/lib/commands/template.mjs +258 -0
- package/lib/config.mjs +351 -0
- package/lib/credentials.mjs +160 -0
- package/lib/device-store.mjs +132 -0
- package/lib/device.mjs +464 -0
- package/lib/errors.mjs +299 -0
- package/lib/format.mjs +339 -0
- package/lib/http.mjs +71 -0
- package/lib/index.mjs +44 -0
- package/lib/local-import.mjs +185 -0
- package/lib/login.mjs +1638 -0
- package/lib/oauth-urls.mjs +163 -0
- package/lib/page.mjs +393 -0
- package/lib/pkce.mjs +48 -0
- package/lib/proxy.mjs +454 -0
- package/lib/qr.mjs +31 -0
- package/lib/runtime.mjs +650 -0
- package/lib/site-state.mjs +137 -0
- package/lib/tar.mjs +207 -0
- package/lib/template-package.mjs +522 -0
- package/package.json +53 -4
- package/wkgeo.mjs +17 -0
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 域名成交全链路命令(task-21,2026-10-28 老板单)
|
|
3
|
+
* ============================================================================
|
|
4
|
+
*
|
|
5
|
+
* 六条命令对应服务端 6 个动作(`wkgeo-cli-fc` 自持,走 `/cli`):
|
|
6
|
+
*
|
|
7
|
+
* wkgeo domain order create --domain <d> [--years N] [--confirm] ① 平台模板下注册
|
|
8
|
+
* wkgeo domain template create --order <id> --license <执照.jpg> ② 客户实名模板 + 提交实名
|
|
9
|
+
* wkgeo domain charge --order <id> ③ 自持扣费(钱包)
|
|
10
|
+
* wkgeo domain template status --order <id> ④ 模板审核 + 域名侧实名
|
|
11
|
+
* wkgeo domain transfer --order <id> ⑤ 快速过户(按模板 ID)
|
|
12
|
+
* wkgeo domain order status <id> ⑥ 全链状态
|
|
13
|
+
*
|
|
14
|
+
* ## 三句必须让客户看懂的话
|
|
15
|
+
* 1. **注册即已实名**:域名是在平台「已实名」的企业模板下注册的,注册成功那一刻就继承模板实名,
|
|
16
|
+
* **可以立即解析、立即建站**;过户不是"能不能用"的前提,只是为了把持有者写到客户名下。
|
|
17
|
+
* 2. **模板认证成功 ≠ 域名实名认证成功**(阿里云控制台原话):`domain template status` 会把
|
|
18
|
+
* 两份状态分别列出来,别拿一条当另一条。
|
|
19
|
+
* 3. 过户默认**不加**「过户后 60 天禁止转出」限制(要加就 `--keep-transfer-lock`)。
|
|
20
|
+
*
|
|
21
|
+
* ## 安全口径
|
|
22
|
+
* · `domain order create` **默认 dry-run**:真跑四步预检 + 建单,但**不提交注册任务、不花钱**。
|
|
23
|
+
* 真下单要 `--no-dry-run --confirm`,服务端还要 `CLI_DOMAIN_ORDER_ENABLED=1`(两道门)。
|
|
24
|
+
* · 营业执照**只在本次请求里出现**:本地只报大小 + sha 前 8 位,**不打印内容、不回显 base64**。
|
|
25
|
+
* · `domain charge` 真的扣钱包余额;`domain transfer` 真的提交过户。两条都幂等(重复调用不会重复扣/重复过户),
|
|
26
|
+
* 先 `domain order status <id>` 看清状态再跑。
|
|
27
|
+
*/
|
|
28
|
+
import { readFileSync, statSync } from 'node:fs';
|
|
29
|
+
|
|
30
|
+
import { UsageError, CliError } from '../errors.mjs';
|
|
31
|
+
import { formatMoney } from '../format.mjs';
|
|
32
|
+
|
|
33
|
+
/** 服务端还没发版时,把"未知动作"翻译成"服务端缺口",别让人以为命令用错了 */
|
|
34
|
+
function isActionNotDeployed(err) {
|
|
35
|
+
const msg = String((err && err.message) || '');
|
|
36
|
+
return /未知动作|未知操作|未在权限表中登记|Unknown action/i.test(msg);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function callOps(ctx, action, payload, what) {
|
|
40
|
+
try {
|
|
41
|
+
return await ctx.callData(action, payload);
|
|
42
|
+
} catch (e) {
|
|
43
|
+
if (isActionNotDeployed(e)) {
|
|
44
|
+
throw new CliError(`服务端尚未部署「${what}」(${action})`, {
|
|
45
|
+
kind: 'not_deployed',
|
|
46
|
+
code: e.code,
|
|
47
|
+
hint: '这是服务端缺口(wkgeo-cli-fc 未发版),不是命令用错了;部署后用 `wkgeo whoami` 看动作面是否已包含它',
|
|
48
|
+
raw: e.raw,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
throw e;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const PHASE_ORDER = [
|
|
56
|
+
['created', '建单'],
|
|
57
|
+
['registered_under_platform', '平台模板下注册'],
|
|
58
|
+
['template_pending', '客户模板提审'],
|
|
59
|
+
['charged', '扣费'],
|
|
60
|
+
['template_verified', '模板实名通过'],
|
|
61
|
+
['transferred', '过户'],
|
|
62
|
+
];
|
|
63
|
+
|
|
64
|
+
const PHASE_TEXT = {
|
|
65
|
+
created: '订单已建(等待注册)',
|
|
66
|
+
registered_under_platform: '已在平台实名模板下注册(**域名已实名,可立即解析建站**)',
|
|
67
|
+
template_pending: '客户实名模板已提交审核',
|
|
68
|
+
charged: '已扣费',
|
|
69
|
+
template_verified: '客户模板实名已通过',
|
|
70
|
+
transferred: '已过户到客户名下',
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
function phaseText(phase) {
|
|
74
|
+
return PHASE_TEXT[String(phase || '')] || String(phase || '—');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** 统一把订单 id 从位置参数或 --order 里取出来 */
|
|
78
|
+
function orderIdOf(ctx, positionalName) {
|
|
79
|
+
const { flags, positional } = ctx;
|
|
80
|
+
const fromPos = positionalName ? positional[positionalName] : '';
|
|
81
|
+
const id = String(flags.order || fromPos || '').trim();
|
|
82
|
+
if (!id) throw new UsageError('缺订单 id:用 --order <id>(或 `domain order status <id>` 查到的 id)');
|
|
83
|
+
return id;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 读营业执照并转 base64。
|
|
88
|
+
*
|
|
89
|
+
* **只在这里读一次**:内容不进日志、不进输出、不进错误消息;对外只暴露大小与 sha 前 8 位。
|
|
90
|
+
* 阿里云 `RegistrantProfileRealNameVerification` 的硬要求:JPG / BMP,55KB~1MB(PDF 会被拒)。
|
|
91
|
+
*/
|
|
92
|
+
function readLicenseSpec(file) {
|
|
93
|
+
const p = String(file || '').trim();
|
|
94
|
+
if (!p) throw new UsageError('缺 --license <营业执照图片路径>:JPG / BMP,55KB~1MB');
|
|
95
|
+
let st;
|
|
96
|
+
try {
|
|
97
|
+
st = statSync(p);
|
|
98
|
+
} catch {
|
|
99
|
+
throw new UsageError(`找不到执照文件:${p}`);
|
|
100
|
+
}
|
|
101
|
+
if (!st.isFile()) throw new UsageError(`不是文件:${p}`);
|
|
102
|
+
const ext = p.toLowerCase().split('.').pop();
|
|
103
|
+
if (ext === 'pdf') {
|
|
104
|
+
throw new UsageError('阿里云模板实名接口只收 JPG / BMP 图片,不收 PDF:请把营业执照导出成 JPG(≥55KB)再上传');
|
|
105
|
+
}
|
|
106
|
+
if (!['jpg', 'jpeg', 'bmp'].includes(ext)) {
|
|
107
|
+
throw new UsageError(`只认 .jpg / .jpeg / .bmp(收到 .${ext}):阿里云实名接口的硬要求`);
|
|
108
|
+
}
|
|
109
|
+
const buf = readFileSync(p);
|
|
110
|
+
if (!buf.length) throw new UsageError('执照文件是空的(0 字节)');
|
|
111
|
+
return { base64: buf.toString('base64'), bytes: buf.length, name: p };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function shortId(id) {
|
|
115
|
+
const s = String(id || '');
|
|
116
|
+
return s.length > 12 ? `${s.slice(0, 8)}…` : s || '—';
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/* ============================ ① 建单(平台模板下注册) ============================ */
|
|
120
|
+
|
|
121
|
+
export const domainOrderCreateCommand = {
|
|
122
|
+
name: 'domain order create',
|
|
123
|
+
summary: '买域名并建单(**默认 dry-run**:预检 + 建单,不提交注册、不花钱)',
|
|
124
|
+
usage:
|
|
125
|
+
'wkgeo domain order create --domain <域名> [--years <年>] [--no-dry-run --confirm] [--permit-premium] [--profile <模板ID>] [--json]',
|
|
126
|
+
args: [],
|
|
127
|
+
flags: {
|
|
128
|
+
domain: { type: 'string', desc: '要买的域名(不带 www)' },
|
|
129
|
+
years: { type: 'string', desc: '购买年限(1–10,默认 1)' },
|
|
130
|
+
'dry-run': {
|
|
131
|
+
type: 'boolean',
|
|
132
|
+
desc: '默认 true;显式 --no-dry-run 才会真的提交阿里云注册任务(还要 --confirm + 服务端闸门)',
|
|
133
|
+
},
|
|
134
|
+
confirm: { type: 'boolean', desc: '确认可以真下单(服务端 CLI_DOMAIN_ORDER_ENABLED=1 是第二道门)' },
|
|
135
|
+
'permit-premium': { type: 'boolean', desc: '允许溢价域名(贵,先看报价)' },
|
|
136
|
+
profile: { type: 'string', desc: '平台实名模板 ID(默认服务端 5234871 上海启寒企业实名)' },
|
|
137
|
+
},
|
|
138
|
+
examples: [
|
|
139
|
+
'wkgeo domain order create --domain newbrand.com # dry-run:预检 + 建单(推荐先跑这个)',
|
|
140
|
+
'wkgeo domain order create --domain newbrand.com --years 3 --json',
|
|
141
|
+
'wkgeo domain order create --domain newbrand.com --no-dry-run --confirm # 真下单(花钱,慎用)',
|
|
142
|
+
],
|
|
143
|
+
notes: [
|
|
144
|
+
'域名是在**平台实名模板**(上海启寒,企业实名已通过)下注册的 ⇒ **注册成功即已实名,可立即解析建站**,不过户也能用。',
|
|
145
|
+
'dry-run 会真建单(有 order id),后续 template create / charge / transfer 都能在这条单上继续跑(全部模拟)。',
|
|
146
|
+
'真下单会扣阿里云账户余额且不可撤销:必须同时满足 --no-dry-run + --confirm + 服务端 env 闸门。',
|
|
147
|
+
],
|
|
148
|
+
async run(ctx) {
|
|
149
|
+
const { out, flags } = ctx;
|
|
150
|
+
const domain = String(flags.domain || '').trim();
|
|
151
|
+
if (!domain) throw new UsageError('缺 --domain <域名>:wkgeo domain order create --domain example.com');
|
|
152
|
+
const payload = { domain, dry_run: flags['dry-run'] === false ? false : true };
|
|
153
|
+
if (flags.years !== undefined) payload.years = Number(flags.years);
|
|
154
|
+
if (flags.confirm === true) payload.confirm = true;
|
|
155
|
+
if (flags['permit-premium'] === true) payload.permit_premium = true;
|
|
156
|
+
if (flags.profile) payload.registrantProfileId = String(flags.profile);
|
|
157
|
+
|
|
158
|
+
const data = (await callOps(ctx, 'domain.orderCreate', payload, '域名下单建单')) || {};
|
|
159
|
+
const order = data.order || {};
|
|
160
|
+
const checks = Array.isArray(data.checks) ? data.checks : [];
|
|
161
|
+
const price = data.price || order.price || {};
|
|
162
|
+
|
|
163
|
+
if (!out.json) {
|
|
164
|
+
out.head(`域名建单:${order.domain || domain}`);
|
|
165
|
+
out.table(
|
|
166
|
+
[
|
|
167
|
+
{ title: '预检', key: 'step', width: 20 },
|
|
168
|
+
{ title: '结果', key: 'ok', width: 6 },
|
|
169
|
+
{ title: '说明', key: 'detail', width: 46 },
|
|
170
|
+
],
|
|
171
|
+
checks.map((c) => ({ step: c.step, ok: c.ok ? '通过' : '注意', detail: String(c.detail || '') })),
|
|
172
|
+
);
|
|
173
|
+
out.info(` 订单号 ${order.id || '—'}`);
|
|
174
|
+
out.info(` 状态 ${order.phase || '—'}(${phaseText(order.phase)})`);
|
|
175
|
+
out.info(` 官方价 ${price.official_cents != null ? formatMoney(price.official_cents) : '—'}`);
|
|
176
|
+
out.info(` 售价 ${price.sale_cents != null ? formatMoney(price.sale_cents) : order.amount_text || '—'}`);
|
|
177
|
+
out.info(` 平台模板 ${order.platform_template_id || '—'}`);
|
|
178
|
+
if (data.dry_run !== false) {
|
|
179
|
+
out.ok('dry-run:已建单并完成预检,**没有提交注册任务、没有花钱**。');
|
|
180
|
+
out.info(' 下一步:wkgeo domain template create --order <订单号> --license <营业执照.jpg>');
|
|
181
|
+
} else {
|
|
182
|
+
out.ok(data.message || '注册任务已提交');
|
|
183
|
+
if (data.aliyun_task_no) out.info(` 阿里云任务号 ${data.aliyun_task_no}`);
|
|
184
|
+
}
|
|
185
|
+
out.notice(' 注册即已实名:域名继承平台企业模板的实名,**现在就能解析建站**,过户只是为了把持有者写到客户名下。');
|
|
186
|
+
}
|
|
187
|
+
ctx.done(data);
|
|
188
|
+
return data;
|
|
189
|
+
},
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
/* ============================ ② 客户实名模板 ============================ */
|
|
193
|
+
|
|
194
|
+
export const domainTemplateCreateCommand = {
|
|
195
|
+
name: 'domain template create',
|
|
196
|
+
summary: '建客户实名模板(只要一张营业执照)+ 提交实名审核',
|
|
197
|
+
usage:
|
|
198
|
+
'wkgeo domain template create --order <订单id> --license <执照.jpg> [--org <企业全称>] [--credit-code <18位统一社会信用代码>] [--phone <手机>] [--json]',
|
|
199
|
+
args: [],
|
|
200
|
+
flags: {
|
|
201
|
+
order: { type: 'string', desc: '订单 id(domain order create 返回的那个)' },
|
|
202
|
+
license: { type: 'string', desc: '营业执照图片路径(**只收 JPG/BMP,55KB~1MB**;PDF 会被阿里云拒)' },
|
|
203
|
+
org: { type: 'string', desc: '企业全称(默认取账号资料的 company)' },
|
|
204
|
+
'credit-code': { type: 'string', desc: '18 位统一社会信用代码(阿里云实名必填,账号资料里没有)' },
|
|
205
|
+
contact: { type: 'string', desc: '联系人姓名(默认取账号昵称)' },
|
|
206
|
+
phone: { type: 'string', desc: '联系电话(默认取账号资料的 mobile)' },
|
|
207
|
+
email: { type: 'string', desc: '邮箱(阿里云要求填)' },
|
|
208
|
+
province: { type: 'string', desc: '省份(中文,如 上海市)' },
|
|
209
|
+
city: { type: 'string', desc: '城市(中文)' },
|
|
210
|
+
address: { type: 'string', desc: '详细地址(中文)' },
|
|
211
|
+
'postal-code': { type: 'string', desc: '邮编' },
|
|
212
|
+
},
|
|
213
|
+
examples: [
|
|
214
|
+
'wkgeo domain template create --order 7f3a… --license ./license.jpg --org 上海某某科技有限公司 --credit-code 91310000MA1FL0XXXX --phone 13800000000',
|
|
215
|
+
],
|
|
216
|
+
notes: [
|
|
217
|
+
'**只收一张营业执照**:其余联系人字段默认取账号资料(company / mobile / nickname),可推导的不用重复填。',
|
|
218
|
+
'统一社会信用代码**无法推导**,必须由客户提供(营业执照上的 18 位)。',
|
|
219
|
+
'执照只存受控位置(阿里云模板实名材料),库里只留路径 + sha256 前 8 位 + 大小,**不回显内容**。',
|
|
220
|
+
'真实审核一般 1 个工作日(部分 3~5 个工作日):用 `domain template status --order <id>` 轮询。',
|
|
221
|
+
],
|
|
222
|
+
async run(ctx) {
|
|
223
|
+
const { out, flags } = ctx;
|
|
224
|
+
const orderId = orderIdOf(ctx, null);
|
|
225
|
+
const lic = readLicenseSpec(flags.license);
|
|
226
|
+
const payload = { order: orderId, license_base64: lic.base64 };
|
|
227
|
+
for (const [k, v] of [
|
|
228
|
+
['org', flags.org],
|
|
229
|
+
['credit_code', flags['credit-code']],
|
|
230
|
+
['contact', flags.contact],
|
|
231
|
+
['phone', flags.phone],
|
|
232
|
+
['email', flags.email],
|
|
233
|
+
['province', flags.province],
|
|
234
|
+
['city', flags.city],
|
|
235
|
+
['address', flags.address],
|
|
236
|
+
['postal_code', flags['postal-code']],
|
|
237
|
+
]) {
|
|
238
|
+
if (v !== undefined && String(v).trim()) payload[k] = String(v).trim();
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const data = (await callOps(ctx, 'domain.templateCreate', payload, '客户实名模板')) || {};
|
|
242
|
+
const order = data.order || {};
|
|
243
|
+
if (!out.json) {
|
|
244
|
+
out.head(`客户实名模板:${order.domain || ''}`);
|
|
245
|
+
out.info(` 执照 ${lic.name}(${Math.round(lic.bytes / 1024)}KB,已本地校验格式)`);
|
|
246
|
+
out.info(` 模板 ID ${data.customer_template_id || order.customer_template_id || '—'}`);
|
|
247
|
+
out.info(` 订单状态 ${order.phase || '—'}(${phaseText(order.phase)})`);
|
|
248
|
+
if (data.dry_run !== false) {
|
|
249
|
+
out.ok('dry-run:材料校验通过(**未上传**),已模拟「创建模板 + 提交实名」并推进到 template_pending。');
|
|
250
|
+
} else {
|
|
251
|
+
out.ok(data.message || '模板已创建并提交实名审核');
|
|
252
|
+
}
|
|
253
|
+
out.notice(' 阿里云原话:模板认证成功 ≠ 域名实名认证成功 —— 用 `domain template status` 看两份状态。');
|
|
254
|
+
}
|
|
255
|
+
ctx.done(data);
|
|
256
|
+
return data;
|
|
257
|
+
},
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
/* ============================ ③ 收费 ============================ */
|
|
261
|
+
|
|
262
|
+
export const domainChargeCommand = {
|
|
263
|
+
name: 'domain charge',
|
|
264
|
+
summary: '扣费(自持钱包,幂等:同一单重复调用不会重复扣)',
|
|
265
|
+
usage: 'wkgeo domain charge --order <订单id> [--dry-run] [--json]',
|
|
266
|
+
args: [],
|
|
267
|
+
flags: {
|
|
268
|
+
order: { type: 'string', desc: '订单 id' },
|
|
269
|
+
'dry-run': { type: 'boolean', desc: '只模拟扣费,不动钱包余额(默认 false)' },
|
|
270
|
+
},
|
|
271
|
+
examples: ['wkgeo domain charge --order 7f3a…', 'wkgeo domain charge --order 7f3a… --dry-run'],
|
|
272
|
+
notes: [
|
|
273
|
+
'幂等:订单已经扣过费时直接回读,不重复扣(幂等键 `domain-order:<订单id>`)。',
|
|
274
|
+
'余额不足返回 402 且**不留半张脏单**:先 `wkgeo wallet recharge` 充值再重试。',
|
|
275
|
+
'审计里有:用户 / 金额 / 域名 / 订单号(写 `admin_audit_log`,action=`cli.ops.domain.charge`)。',
|
|
276
|
+
],
|
|
277
|
+
async run(ctx) {
|
|
278
|
+
const { out, flags } = ctx;
|
|
279
|
+
const payload = { order: orderIdOf(ctx, null) };
|
|
280
|
+
if (flags['dry-run'] === true) payload.dry_run = true;
|
|
281
|
+
const data = (await callOps(ctx, 'domain.charge', payload, '域名成交扣费')) || {};
|
|
282
|
+
if (!out.json) {
|
|
283
|
+
out.head('域名成交扣费');
|
|
284
|
+
if (data.simulated) {
|
|
285
|
+
out.ok(`dry-run:模拟扣费 ${data.amount_text || formatMoney(data.amount_cents)}(**没有**动钱包余额)。`);
|
|
286
|
+
} else if (data.idempotent) {
|
|
287
|
+
out.ok(data.message || '这笔订单已经扣过费,本次没有重复扣。');
|
|
288
|
+
} else {
|
|
289
|
+
out.ok(`已扣费 ${data.amount_text || formatMoney(data.amount_cents)}`);
|
|
290
|
+
if (data.balance_after_text) out.info(` 钱包余额 ${data.balance_after_text}`);
|
|
291
|
+
if (data.pay_order) out.info(` 支付单号 ${data.pay_order.out_trade_no || data.pay_order.id}`);
|
|
292
|
+
}
|
|
293
|
+
out.info(` 订单状态 ${(data.order && data.order.phase) || '—'}(${phaseText(data.order && data.order.phase)})`);
|
|
294
|
+
}
|
|
295
|
+
ctx.done(data);
|
|
296
|
+
return data;
|
|
297
|
+
},
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
/* ============================ ④ 模板审核状态 ============================ */
|
|
301
|
+
|
|
302
|
+
export const domainTemplateStatusCommand = {
|
|
303
|
+
name: 'domain template status',
|
|
304
|
+
summary: '查模板实名审核 + 域名侧实名(两份状态分开看)',
|
|
305
|
+
usage: 'wkgeo domain template status --order <订单id> [--json]',
|
|
306
|
+
args: [],
|
|
307
|
+
flags: { order: { type: 'string', desc: '订单 id' } },
|
|
308
|
+
examples: ['wkgeo domain template status --order 7f3a…'],
|
|
309
|
+
notes: [
|
|
310
|
+
'阿里云原话:**模板认证成功 ≠ 域名实名认证成功**;`template` 与 `domain_realname` 是两份独立状态。',
|
|
311
|
+
'模板状态取自 `QueryRegistrantProfiles.RealNameStatus`(AUDITING / SUCCEED / FAILED / NONAUDIT)。',
|
|
312
|
+
'审核失败时会给人话原因(重传执照 / 信息与执照不一致),改完重新 `domain template create` 即可。',
|
|
313
|
+
],
|
|
314
|
+
async run(ctx) {
|
|
315
|
+
const { out, flags } = ctx;
|
|
316
|
+
const data = (await callOps(ctx, 'domain.templateStatus', { order: orderIdOf(ctx, null) }, '模板实名状态')) || {};
|
|
317
|
+
const tpl = data.template || {};
|
|
318
|
+
const dr = data.domain_realname || {};
|
|
319
|
+
if (!out.json) {
|
|
320
|
+
out.head(`模板实名:${(data.order && data.order.domain) || ''}`);
|
|
321
|
+
out.info(` 模板 ID ${tpl.profile_id || '—'}`);
|
|
322
|
+
out.info(` 模板状态 ${tpl.status || '—'}(${tpl.status_text || '—'})`);
|
|
323
|
+
out.info(` 域名实名 ${dr.status || '—'}(${dr.status_text || '—'})`);
|
|
324
|
+
if (data.can_transfer || tpl.status === 'SUCCEED') out.ok('模板已认证:可以过户 —— wkgeo domain transfer --order <订单id>');
|
|
325
|
+
else if (tpl.status === 'FAILED') out.warn(`模板实名失败:${(data.order && data.order.last_error) || '原因未返回'}`);
|
|
326
|
+
else out.info(' 还在审核中:稍后再查(一般 1 个工作日,部分 3~5 个工作日)。');
|
|
327
|
+
out.notice(' 模板认证成功 ≠ 域名实名认证成功:上面两行是两份状态。');
|
|
328
|
+
}
|
|
329
|
+
ctx.done(data);
|
|
330
|
+
return data;
|
|
331
|
+
},
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
/* ============================ ⑤ 快速过户 ============================ */
|
|
335
|
+
|
|
336
|
+
export const domainTransferCommand = {
|
|
337
|
+
name: 'domain transfer',
|
|
338
|
+
summary: '快速过户(按客户模板 ID 改持有者信息,不收集资料、不走人工流)',
|
|
339
|
+
usage: 'wkgeo domain transfer --order <订单id> [--dry-run] [--keep-transfer-lock] [--json]',
|
|
340
|
+
args: [],
|
|
341
|
+
flags: {
|
|
342
|
+
order: { type: 'string', desc: '订单 id' },
|
|
343
|
+
'dry-run': { type: 'boolean', desc: '只模拟过户,不提交阿里云任务(默认 false)' },
|
|
344
|
+
'keep-transfer-lock': {
|
|
345
|
+
type: 'boolean',
|
|
346
|
+
desc: '保留「过户后 60 天禁止转出」限制(默认不加,后续可直接转出)',
|
|
347
|
+
},
|
|
348
|
+
},
|
|
349
|
+
examples: [
|
|
350
|
+
'wkgeo domain transfer --order 7f3a…',
|
|
351
|
+
'wkgeo domain transfer --order 7f3a… --keep-transfer-lock',
|
|
352
|
+
],
|
|
353
|
+
notes: [
|
|
354
|
+
'前置:客户模板**必须实名通过**(`template_verified`)+ 订单**已扣费**;不满足直接拒(409/402)。',
|
|
355
|
+
'域名要满足过户前提:在本账号内、未过期、没开「禁止更新锁」(clientUpdateProhibited 等)。',
|
|
356
|
+
'调用 `SaveTaskForUpdatingRegistrantInfoByRegistrantProfileID`(按模板 ID 改持有者),提交后轮询任务结果。',
|
|
357
|
+
'幂等:已有任务号就先轮询、不重复提交;已过户直接回读。',
|
|
358
|
+
],
|
|
359
|
+
async run(ctx) {
|
|
360
|
+
const { out, flags } = ctx;
|
|
361
|
+
const payload = { order: orderIdOf(ctx, null) };
|
|
362
|
+
if (flags['dry-run'] === true) payload.dry_run = true;
|
|
363
|
+
if (flags['keep-transfer-lock'] === true) payload.keep_transfer_lock = true;
|
|
364
|
+
const data = (await callOps(ctx, 'domain.transfer', payload, '域名快速过户')) || {};
|
|
365
|
+
if (!out.json) {
|
|
366
|
+
out.head(`快速过户:${(data.order && data.order.domain) || ''}`);
|
|
367
|
+
if (data.idempotent) out.ok(data.message || '已经过户完成,本次没有重复提交。');
|
|
368
|
+
else if (data.simulated) out.ok(data.message || 'dry-run:模拟过户完成(没有真的提交任务)。');
|
|
369
|
+
else if (data.transferred) out.ok(data.message || '过户成功');
|
|
370
|
+
else if (data.pending) out.info(data.message || '过户任务已提交,阿里云处理中');
|
|
371
|
+
if (data.aliyun_transfer_task_id) out.info(` 阿里云任务号 ${data.aliyun_transfer_task_id}`);
|
|
372
|
+
out.info(` 订单状态 ${(data.order && data.order.phase) || '—'}(${phaseText(data.order && data.order.phase)})`);
|
|
373
|
+
}
|
|
374
|
+
ctx.done(data);
|
|
375
|
+
return data;
|
|
376
|
+
},
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
/* ============================ ⑥ 全链状态 ============================ */
|
|
380
|
+
|
|
381
|
+
export const domainOrderStatusCommand = {
|
|
382
|
+
name: 'domain order status',
|
|
383
|
+
summary: '看这条订单走到哪一步(各步时间戳 + 阿里云订单/任务号 + 错误)',
|
|
384
|
+
usage: 'wkgeo domain order status <订单id> [--json]',
|
|
385
|
+
args: [{ name: 'id', required: true, desc: '订单 id(domain order create 返回的 uuid)' }],
|
|
386
|
+
flags: {},
|
|
387
|
+
examples: ['wkgeo domain order status 7f3a1c2e-…'],
|
|
388
|
+
notes: [
|
|
389
|
+
'状态链:created → registered_under_platform → template_pending → charged → template_verified → transferred(只前进)。',
|
|
390
|
+
'真单会顺带查阿里云任务进度与域名归属;`dry_run: true` 的订单只列库里记的步骤。',
|
|
391
|
+
],
|
|
392
|
+
async run(ctx) {
|
|
393
|
+
const { out, positional } = ctx;
|
|
394
|
+
const data = (await callOps(ctx, 'domain.orderShow', { order: String(positional.id || '').trim() }, '订单状态')) || {};
|
|
395
|
+
const order = data.order || {};
|
|
396
|
+
const steps = Array.isArray(data.steps) ? data.steps : [];
|
|
397
|
+
if (!out.json) {
|
|
398
|
+
out.head(`订单 ${shortId(order.id)}${data.dry_run ? '(dry-run)' : ''}`);
|
|
399
|
+
out.info(` 域名 ${order.domain || '—'}`);
|
|
400
|
+
out.info(` 金额 ${order.amount_text || formatMoney(order.amount_cents)}`);
|
|
401
|
+
out.table(
|
|
402
|
+
[
|
|
403
|
+
{ title: '步骤', key: 'step', width: 26 },
|
|
404
|
+
{ title: '状态', key: 'state', width: 8 },
|
|
405
|
+
{ title: '时间', key: 'at', width: 24 },
|
|
406
|
+
],
|
|
407
|
+
steps.map((s) => ({
|
|
408
|
+
step: s.text || s.phase,
|
|
409
|
+
state: s.reached ? '✓' : '·',
|
|
410
|
+
at: s.at || '',
|
|
411
|
+
})),
|
|
412
|
+
);
|
|
413
|
+
const raw = data.raw || {};
|
|
414
|
+
if (raw.aliyun_domain_order_id) out.info(` 阿里云订单任务号 ${raw.aliyun_domain_order_id}`);
|
|
415
|
+
if (raw.aliyun_transfer_task_id) out.info(` 阿里云过户任务号 ${raw.aliyun_transfer_task_id}`);
|
|
416
|
+
if (raw.customer_template_id) out.info(` 客户模板 ID ${raw.customer_template_id}`);
|
|
417
|
+
if (raw.pay_order_id) out.info(` 支付单号 ${raw.pay_order_id}`);
|
|
418
|
+
if (data.pay_order) out.info(` 支付状态 ${data.pay_order.status}(${formatMoney(data.pay_order.wallet_paid_cents)})`);
|
|
419
|
+
if (data.domain) out.info(` 域名状态 ${(data.domain.status || []).join(', ') || '—'}(到期 ${data.domain.expiration_date || '—'})`);
|
|
420
|
+
if (order.last_error) out.warn(`最近错误:${order.last_error}`);
|
|
421
|
+
out.info(` 当前:${order.phase || '—'}(${phaseText(order.phase)})`);
|
|
422
|
+
if (data.dry_run) out.notice(' dry-run 订单:所有阿里云写操作都是模拟的,不会花钱、不会真过户。');
|
|
423
|
+
}
|
|
424
|
+
ctx.done(data);
|
|
425
|
+
return data;
|
|
426
|
+
},
|
|
427
|
+
};
|
|
428
|
+
|
|
429
|
+
/** 给 `cli/lib/commands/index.mjs` 一次性注册用 */
|
|
430
|
+
export const DOMAIN_ORDER_COMMANDS = [
|
|
431
|
+
domainOrderCreateCommand,
|
|
432
|
+
domainTemplateCreateCommand,
|
|
433
|
+
domainChargeCommand,
|
|
434
|
+
domainTemplateStatusCommand,
|
|
435
|
+
domainTransferCommand,
|
|
436
|
+
domainOrderStatusCommand,
|
|
437
|
+
];
|
|
438
|
+
|
|
439
|
+
export { PHASE_ORDER };
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `wkgeo import` —— 把老网站内容搬进 CMS。
|
|
3
|
+
*
|
|
4
|
+
* ## 现在的真实能力(**如实写,不画饼**)
|
|
5
|
+
* 后端**还没有**带鉴权的 HTTP 导入入口(`aliyun/fc/wkgeo-cms/src` 的动作表里没有 import 类动作),
|
|
6
|
+
* 所以这条命令走的是**本机运维脚本** `tencent/cloudbase/import-site.mjs`:
|
|
7
|
+
* * 它直连数据库(`service_role`),**需要运维权限**;
|
|
8
|
+
* * 默认 **dry-run**(只抓取 + 打印计划 + 写中间 JSON),加 `--apply` 才写库;
|
|
9
|
+
* * 导入内容默认 `draft`,核对完再发布。
|
|
10
|
+
*
|
|
11
|
+
* ## 为什么还要把它做成命令
|
|
12
|
+
* AI / 运维要的是"一条命令、参数一致、默认安全":
|
|
13
|
+
* `wkgeo import --url=https://old-site.com --json` 就是"先看看会导入什么",
|
|
14
|
+
* 看完再 `--apply`。脚本的参数一个字母都没改(见 `buildImportArgs`),
|
|
15
|
+
* 所以文档里已有的用法仍然成立。
|
|
16
|
+
*
|
|
17
|
+
* ## 安全约束(**写在命令里,不交给 AI 自觉**)
|
|
18
|
+
* 1. 默认 dry-run:不带 `--apply` 永不写库;
|
|
19
|
+
* 2. 目标站必须明确(`--site` 或本地 `wkgeo site use` 选中的那个)——
|
|
20
|
+
* **不允许**让脚本自己猜,导错站的代价太高;
|
|
21
|
+
* 3. 脚本找不到时**明确说是缺什么**(不是"未知错误")。
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { CliError, UsageError } from '../errors.mjs';
|
|
25
|
+
import { buildImportArgs, resolveImportScript, runNodeCommand, tailText } from '../local-import.mjs';
|
|
26
|
+
|
|
27
|
+
export const importCommand = {
|
|
28
|
+
name: 'import',
|
|
29
|
+
summary: '把老网站内容导入本平台(默认 dry-run;需要运维权限的本机脚本)',
|
|
30
|
+
usage:
|
|
31
|
+
'wkgeo import --url=<老站网址> [--site <站点ID>] [--dry-run | --apply] [--status draft|published]\n' +
|
|
32
|
+
' [--out <中间JSON>] [--max-pages 40] [--delay 250] [--include 正则] [--exclude 正则] [--overwrite] [--no-probe]',
|
|
33
|
+
flags: {
|
|
34
|
+
url: { type: 'string', required: true, desc: '老站首页地址(http/https)' },
|
|
35
|
+
site: { type: 'string', desc: '目标站(站点 ID / 域名 / 站点名;默认用 `wkgeo site use` 选中的站点)' },
|
|
36
|
+
'dry-run': { type: 'boolean', desc: '只抓取 + 打印计划,不写库(**默认就是它**)' },
|
|
37
|
+
apply: { type: 'boolean', desc: '真写库:建栏目 / 传素材 / 建内容 / 写正文(与 --dry-run 二选一)' },
|
|
38
|
+
status: { type: 'string', desc: '导入内容的初始状态:draft 草稿(默认)/ published 已发布' },
|
|
39
|
+
out: { type: 'string', desc: '中间 JSON 的落盘路径(默认 .tmp-build/import-<host>.json)' },
|
|
40
|
+
'max-pages': { type: 'string', desc: '最多抓多少页(默认 40)' },
|
|
41
|
+
delay: { type: 'string', desc: '每页间隔毫秒(默认 250;robots 的 Crawl-delay 更大时以它为准)' },
|
|
42
|
+
include: { type: 'string', desc: '只抓路径匹配这个正则的页面(首页总会抓)' },
|
|
43
|
+
exclude: { type: 'string', desc: '跳过路径匹配这个正则的页面' },
|
|
44
|
+
overwrite: { type: 'boolean', desc: '已存在的同名内容也覆盖正文(默认跳过,只增不毁)' },
|
|
45
|
+
'no-probe': { type: 'boolean', desc: '不做可访问性探测(脚本的 --no-probe)' },
|
|
46
|
+
},
|
|
47
|
+
examples: [
|
|
48
|
+
'wkgeo import --url=https://old-site.com --json # 先看计划(默认 dry-run,不写库)',
|
|
49
|
+
'wkgeo import --url=https://old-site.com --site 8f3c… --apply --json',
|
|
50
|
+
'wkgeo import --url=https://old-site.com --max-pages 80 --delay 500 --out .tmp-build/plan.json',
|
|
51
|
+
],
|
|
52
|
+
notes: [
|
|
53
|
+
'⚠️ **需要运维权限**:当前这条命令调用的是本仓库的本机脚本 `tencent/cloudbase/import-site.mjs`(service_role 直连数据库),' +
|
|
54
|
+
'客户 / AI 端不应当用它;带鉴权的 HTTP 导入入口后端还没做(见 docs/规划-CLI与AI建站.md §5.2)。',
|
|
55
|
+
'默认 **dry-run**:不带 `--apply` 永不写库;导入内容默认 `draft`(`--status published` 才直接上线)。',
|
|
56
|
+
'脚本位置可用 `WKONGAI_IMPORT_SCRIPT` 指定;找不到脚本时会明确报"没有本地导入器"。',
|
|
57
|
+
'`import` 不转发全局的 `--timeout`(那个是登录回调用的),单请求超时由脚本自己的默认值决定。',
|
|
58
|
+
],
|
|
59
|
+
async run(ctx) {
|
|
60
|
+
const { out, flags } = ctx;
|
|
61
|
+
|
|
62
|
+
if (flags.apply === true && flags.dryRun === true) {
|
|
63
|
+
throw new UsageError('--apply 与 --dry-run 只能二选一(默认就是 dry-run)');
|
|
64
|
+
}
|
|
65
|
+
const url = String(flags.url || '').trim();
|
|
66
|
+
if (!/^https?:\/\//i.test(url)) {
|
|
67
|
+
throw new UsageError(`--url 要以 http:// 或 https:// 开头,收到:${url || '(空)'}`);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** 目标站:显式 `--site` > 本地选中的站。都没有就报错(**绝不猜**) */
|
|
71
|
+
let siteRef = String(flags.site || '').trim();
|
|
72
|
+
let siteSource = siteRef ? 'flag' : '';
|
|
73
|
+
if (!siteRef) {
|
|
74
|
+
const local = ctx.readSiteState();
|
|
75
|
+
if (local && local.id) {
|
|
76
|
+
siteRef = local.id;
|
|
77
|
+
siteSource = 'local';
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (!siteRef) {
|
|
81
|
+
throw new UsageError(
|
|
82
|
+
'还没有指定目标站:加 `--site <站点ID或域名>`,或先 `wkgeo site use <站点ID>` 选一个\n' +
|
|
83
|
+
'(导入会往这个站写栏目/内容,导错站的代价很高,所以不替你猜)',
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* 找脚本。⚠️ **不传 moduleUrl**:让 `resolveImportScript` 用它自己的模块位置做相对解析
|
|
89
|
+
* (本文件在 `cli/lib/commands/`,层级与 `cli/lib/` 不同,传错会解析到错目录)。
|
|
90
|
+
*/
|
|
91
|
+
const resolved = resolveImportScript({ env: ctx.env, cwd: process.cwd() });
|
|
92
|
+
if (resolved.error) {
|
|
93
|
+
throw new CliError(resolved.error.message, { kind: resolved.error.kind, hint: resolved.error.hint });
|
|
94
|
+
}
|
|
95
|
+
const script = resolved.script;
|
|
96
|
+
|
|
97
|
+
const apply = flags.apply === true;
|
|
98
|
+
const args = buildImportArgs({
|
|
99
|
+
url,
|
|
100
|
+
site: siteRef,
|
|
101
|
+
apply,
|
|
102
|
+
status: flags.status,
|
|
103
|
+
out: flags.out,
|
|
104
|
+
maxPages: flags.maxPages,
|
|
105
|
+
delay: flags.delay,
|
|
106
|
+
include: flags.include,
|
|
107
|
+
exclude: flags.exclude,
|
|
108
|
+
overwrite: flags.overwrite === true,
|
|
109
|
+
noProbe: flags.noProbe === true,
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
if (!out.json) {
|
|
113
|
+
out.head(`老站导入(${apply ? '写库 --apply' : 'dry-run,不写库'})`);
|
|
114
|
+
out.line(` 老站:${url}`);
|
|
115
|
+
out.line(` 目标站:${siteRef}${siteSource === 'local' ? '(来自 `wkgeo site use`)' : ''}`);
|
|
116
|
+
out.line(` 脚本:${script}`);
|
|
117
|
+
out.warn(' 这一步走的是**本机运维脚本**(service_role 直连数据库):需要运维/管理员权限。');
|
|
118
|
+
out.line('');
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const runScript = typeof ctx.runScript === 'function' ? ctx.runScript : runNodeCommand;
|
|
122
|
+
const res = runScript(process.execPath, [script, ...args], {
|
|
123
|
+
/** JSON 模式:子进程输出收进信封(否则 stdout 里会混进一堆日志,破坏"只有一个 JSON"的约定) */
|
|
124
|
+
stdio: out.json ? ['inherit', 'pipe', 'pipe'] : 'inherit',
|
|
125
|
+
encoding: 'utf8',
|
|
126
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
127
|
+
cwd: process.cwd(),
|
|
128
|
+
env: ctx.env || process.env,
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
const status = res && typeof res.status === 'number' ? res.status : 1;
|
|
132
|
+
const data = {
|
|
133
|
+
url,
|
|
134
|
+
site: siteRef,
|
|
135
|
+
site_source: siteSource,
|
|
136
|
+
dry_run: !apply,
|
|
137
|
+
apply,
|
|
138
|
+
script,
|
|
139
|
+
exit_code: status,
|
|
140
|
+
/** 只在 JSON 模式里有内容(人类模式是直通终端) */
|
|
141
|
+
log_tail: out.json ? tailText(res && res.stdout, 4000) || '' : '',
|
|
142
|
+
stderr_tail: out.json ? tailText(res && res.stderr, 2000) || '' : '',
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
if (status !== 0) {
|
|
146
|
+
const tail = tailText((res && (res.stderr || res.stdout)) || '', 800).trim();
|
|
147
|
+
throw new CliError(`导入脚本以退出码 ${status} 结束${tail ? `:${tail.split('\n').slice(-3).join(' / ')}` : ''}`, {
|
|
148
|
+
kind: 'import_failed',
|
|
149
|
+
code: status,
|
|
150
|
+
hint:
|
|
151
|
+
'看上面的日志定位(常见:--url 打不开 / 目标站不存在 / 没有数据库凭证 / 触发了 robots 限制)。' +
|
|
152
|
+
'dry-run 阶段失败不会动数据库,可以放心重试。',
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (!out.json) {
|
|
157
|
+
out.ok(apply ? '导入完成(已写库)' : '计划已生成(dry-run,未写库)');
|
|
158
|
+
out.info(apply ? ' 导入的内容默认是草稿:核对后用 `wkgeo contents list --status draft` 查看,再 `--status published` 上线。' : ' 下一步:核对计划无误后加 `--apply` 真写库(同一份 plan,看到的和写的一致)。');
|
|
159
|
+
} else {
|
|
160
|
+
ctx.done(data);
|
|
161
|
+
}
|
|
162
|
+
return data;
|
|
163
|
+
},
|
|
164
|
+
};
|