@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,546 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 自持成交链命令:域名查价 / 下单(默认 dry-run)/ 订单状态 / 云解析读写 / ESA 开通 / 建站收口
|
|
3
|
+
*
|
|
4
|
+
* ## 为什么这些命令直接打 `/cli`
|
|
5
|
+
* 2026-10-28 老板定:「cli 那块重购买域名,域名解析,esa,建站,全部使用自己的 fc,
|
|
6
|
+
* 不要共用网上那一套。」⇒ 12 条动作住进 `wkgeo-cli-fc`(自持链路),
|
|
7
|
+
* `data()` 默认就打 `/cli`(`GATEWAY_PREFIXES.cli`),所以这里**不需要传 prefix**。
|
|
8
|
+
*
|
|
9
|
+
* ## 命名为什么是 `domain zone …` 而不是 `domain dns …`
|
|
10
|
+
* `wkgeo domain dns` / `domain records` 已经存在,讲的是"**照抄表**:你该去别处加哪几条解析"(只读)。
|
|
11
|
+
* 这里的 `domain zone …` 是**真的动账号里的云解析**(写 / 改 / 删),语义完全不同,不能混名。
|
|
12
|
+
*
|
|
13
|
+
* ## 安全口径
|
|
14
|
+
* · `domain buy` **默认 dry-run**,只做四步预检 + 报价;真下单必须 `--confirm`
|
|
15
|
+
* (服务端还有第二道闸 `CLI_DOMAIN_ORDER_ENABLED=1`,两边都开才会真发注册任务)。
|
|
16
|
+
* · 平台自有域名(wkgeo.com / wkgeo.com.cn / wkongai.cn / wukong2000.cn)买不了、也不许写解析,
|
|
17
|
+
* 服务端已经挡了,这里只负责把话说清楚。
|
|
18
|
+
* · `domain zone delete` 必须显式 `--yes`(删错一条解析就是线上事故)。
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { UsageError, CliError } from '../errors.mjs';
|
|
22
|
+
import { formatMoney } from '../format.mjs';
|
|
23
|
+
|
|
24
|
+
/** 服务端还没发版时,把"未知动作"翻译成"服务端缺口",别让人以为命令用错了 */
|
|
25
|
+
function isActionNotDeployed(err) {
|
|
26
|
+
const msg = String((err && err.message) || '');
|
|
27
|
+
return /未知动作|未知操作|未在权限表中登记|Unknown action/i.test(msg);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function callOps(ctx, action, payload, what) {
|
|
31
|
+
try {
|
|
32
|
+
return await ctx.callData(action, payload);
|
|
33
|
+
} catch (e) {
|
|
34
|
+
if (isActionNotDeployed(e)) {
|
|
35
|
+
throw new CliError(`服务端尚未部署「${what}」(${action})`, {
|
|
36
|
+
kind: 'not_deployed',
|
|
37
|
+
code: e.code,
|
|
38
|
+
hint: '这是服务端缺口(wkgeo-cli-fc 未发版),不是命令用错了;部署后用 `wkgeo whoami` 看动作面是否已包含它',
|
|
39
|
+
raw: e.raw,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
throw e;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const AVAIL_ICON = (one) => (one.available ? '可注册' : one.avail_text || '不可注册');
|
|
47
|
+
|
|
48
|
+
/* ============================ 域名查价 / 下单 ============================ */
|
|
49
|
+
|
|
50
|
+
export const domainSearchCommand = {
|
|
51
|
+
name: 'domain search',
|
|
52
|
+
summary: '查域名能不能注册 + 真实报价(阿里云 CheckDomain,走自持 fc)',
|
|
53
|
+
usage: 'wkgeo domain search <域名> [<域名>…] [--years <年>] [--json]',
|
|
54
|
+
args: [{ name: 'domains', variadic: true, required: true, desc: '要查的域名,可给多个(一次最多 20 个)' }],
|
|
55
|
+
flags: {
|
|
56
|
+
years: { type: 'string', desc: '按几年期报价(1–10,默认 1)' },
|
|
57
|
+
},
|
|
58
|
+
examples: [
|
|
59
|
+
'wkgeo domain search newbrand.com',
|
|
60
|
+
'wkgeo domain search a.com b.com --years 3',
|
|
61
|
+
],
|
|
62
|
+
notes: [
|
|
63
|
+
'`--years` 影响的是**官方报价**(不同年限折扣不同);售价 = 官方价 ×1.2 向上取整到元。',
|
|
64
|
+
'`Avail` 码:1 可注册 / 0 已被占用 / 3 预登记 / 4 可赎回 / -2 暂停注册 / -3 黑名单 / -1 查询失败。',
|
|
65
|
+
'溢价域名(`premium: true`)可以查,但下单必须额外 `--permit-premium`(服务端默认拒绝)。',
|
|
66
|
+
],
|
|
67
|
+
async run(ctx) {
|
|
68
|
+
const { out, flags, positional } = ctx;
|
|
69
|
+
const domains = (positional.domains || []).map((d) => String(d).trim()).filter(Boolean);
|
|
70
|
+
if (!domains.length) throw new UsageError('至少给一个域名:wkgeo domain search <域名>');
|
|
71
|
+
const payload = { domains: domains.join(','), domain: domains[0] };
|
|
72
|
+
if (flags.years !== undefined) payload.years = Number(flags.years);
|
|
73
|
+
|
|
74
|
+
const data = (await callOps(ctx, 'domain.search', payload, '域名查价')) || {};
|
|
75
|
+
const results = Array.isArray(data.results) ? data.results : [];
|
|
76
|
+
|
|
77
|
+
if (!out.json) {
|
|
78
|
+
out.head(`域名查价(${results.length} 个)`);
|
|
79
|
+
out.table(
|
|
80
|
+
[
|
|
81
|
+
{ title: '域名', key: 'domain', width: 30 },
|
|
82
|
+
{ title: '状态', key: 'state', width: 12 },
|
|
83
|
+
{ title: '官方价', key: 'price', width: 12 },
|
|
84
|
+
{ title: '售价', key: 'sale', width: 12 },
|
|
85
|
+
{ title: '备注', key: 'note', width: 26 },
|
|
86
|
+
],
|
|
87
|
+
results.map((one) => ({
|
|
88
|
+
domain: one.domain,
|
|
89
|
+
state: one.ok === false ? '查询失败' : AVAIL_ICON(one),
|
|
90
|
+
price: one.price_text || '—',
|
|
91
|
+
sale: one.sale_text || '—',
|
|
92
|
+
note: one.platform_owned
|
|
93
|
+
? `平台自有(${one.platform_owned})`
|
|
94
|
+
: one.ok === false
|
|
95
|
+
? String(one.error || '').slice(0, 40)
|
|
96
|
+
: one.premium
|
|
97
|
+
? '溢价域名(需 --permit-premium)'
|
|
98
|
+
: one.reason || '',
|
|
99
|
+
})),
|
|
100
|
+
);
|
|
101
|
+
out.info(' 真实报价来自阿里云 CheckDomain;价目单位是人民币(分已折算)。');
|
|
102
|
+
out.info(' 要买:wkgeo domain buy <域名>(默认 dry-run,只预检不下单)');
|
|
103
|
+
}
|
|
104
|
+
ctx.done({ ...data, results });
|
|
105
|
+
return data;
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export const domainBuyCommand = {
|
|
110
|
+
name: 'domain buy',
|
|
111
|
+
summary: '买域名(**默认 dry-run**:校验 + 报价 + 余额预检;真下单要 --confirm)',
|
|
112
|
+
usage: 'wkgeo domain buy <域名> [--years <年>] [--confirm] [--permit-premium] [--profile <模板ID>] [--json]',
|
|
113
|
+
args: [{ name: 'domain', required: true, desc: '要买的域名(不带 www)' }],
|
|
114
|
+
flags: {
|
|
115
|
+
years: { type: 'string', desc: '购买年限(1–10,默认 1)' },
|
|
116
|
+
confirm: {
|
|
117
|
+
type: 'boolean',
|
|
118
|
+
desc: '确认可以真下单(还会被服务端闸门 CLI_DOMAIN_ORDER_ENABLED=1 再挡一次)',
|
|
119
|
+
},
|
|
120
|
+
'permit-premium': { type: 'boolean', desc: '允许下单溢价域名(贵,先看清楚报价)' },
|
|
121
|
+
profile: { type: 'string', desc: '实名模板 ID(默认服务端 5234871 上海启寒企业实名)' },
|
|
122
|
+
},
|
|
123
|
+
examples: [
|
|
124
|
+
'wkgeo domain buy newbrand.com # dry-run:预检 + 报价',
|
|
125
|
+
'wkgeo domain buy newbrand.com --permit-premium --confirm # 溢价域名真下单(需服务端闸门也开)',
|
|
126
|
+
],
|
|
127
|
+
notes: [
|
|
128
|
+
'四步预检:反查归属(已持有 ⇒ 幂等成功,不重复下单)/ 可注册性 / 实名模板 / 账户余额 ≥ max(售价, ¥500)。',
|
|
129
|
+
'**真下单会扣账户余额**,且下单后不能撤销 —— 所以默认 dry-run,`--confirm` 才发注册任务。',
|
|
130
|
+
'同一域名 + 同年限 10 分钟内重复调用是幂等的:dry-run 命中 dry-run,真下单命中原 TaskNo,不会重复扣款。',
|
|
131
|
+
],
|
|
132
|
+
async run(ctx) {
|
|
133
|
+
const { out, flags, positional } = ctx;
|
|
134
|
+
const payload = { domain: positional.domain };
|
|
135
|
+
if (flags.years !== undefined) payload.years = Number(flags.years);
|
|
136
|
+
if (flags.profile) payload.registrantProfileId = flags.profile;
|
|
137
|
+
if (flags['permit-premium']) payload.permitPremium = true;
|
|
138
|
+
if (flags.confirm) {
|
|
139
|
+
payload.confirm = true;
|
|
140
|
+
payload.dry_run = false;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const data = (await callOps(ctx, 'domain.buy', payload, '域名下单')) || {};
|
|
144
|
+
const checks = (data.precheck && Array.isArray(data.precheck.checks) ? data.precheck.checks : []);
|
|
145
|
+
|
|
146
|
+
if (!out.json) {
|
|
147
|
+
out.head(`域名下单预检:${data.domain}(${data.years} 年)`);
|
|
148
|
+
out.table(
|
|
149
|
+
[
|
|
150
|
+
{ title: '检查项', key: 'step', width: 20 },
|
|
151
|
+
{ title: '结果', key: 'state', width: 8 },
|
|
152
|
+
{ title: '说明', key: 'detail', width: 60 },
|
|
153
|
+
],
|
|
154
|
+
checks.map((c) => ({
|
|
155
|
+
step: c.step,
|
|
156
|
+
state: c.ok ? '通过' : '未过',
|
|
157
|
+
detail: String(c.detail || '').slice(0, 80),
|
|
158
|
+
})),
|
|
159
|
+
);
|
|
160
|
+
const q = data.quote || {};
|
|
161
|
+
out.line(` 官方价:${q.price_text || '—'} 售价:${q.sale_text || '—'}(${q.markup || '+20%'})`);
|
|
162
|
+
if (data.balance) {
|
|
163
|
+
out.line(` 账户余额:${formatMoney(data.balance.available_cents)} 门槛:${formatMoney(data.balance.min_cents)}`);
|
|
164
|
+
}
|
|
165
|
+
out.line(` 实名模板:${data.registrant_profile_id || '—'}`);
|
|
166
|
+
|
|
167
|
+
if (data.already_owned) {
|
|
168
|
+
out.ok(`这个域名已经在账号里(${data.message || '幂等返回'}),不会再下单`);
|
|
169
|
+
} else if (data.dry_run) {
|
|
170
|
+
out.warn(`本次是 dry-run,**没有下单**${data.block_reason ? `(${data.block_reason})` : ''}`);
|
|
171
|
+
out.info(' 预检全过就加 --confirm 真下单(会扣余额,不可撤销)');
|
|
172
|
+
} else if (data.ordered) {
|
|
173
|
+
out.ok(`已提交注册任务:TaskNo=${data.task_no}(下单会扣余额)`);
|
|
174
|
+
out.info(` 跟进状态:wkgeo domain order --task ${data.task_no}`);
|
|
175
|
+
} else {
|
|
176
|
+
out.warn(`未下单:${data.block_reason || '预检未通过'}`);
|
|
177
|
+
}
|
|
178
|
+
if (data.idempotent) out.info(` 幂等命中(${Math.round((data.memo_age_ms || 0) / 1000)} 秒前的同请求结果)`);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/* 真下单是**花钱**动作:即便 --json 也要在 stderr 留一句,别让自动化脚本静默扣款 */
|
|
182
|
+
if (data.ordered && !data.dry_run) {
|
|
183
|
+
out.notice(`⚠️ 已真下单(TaskNo=${data.task_no}),会从账户余额扣款。`);
|
|
184
|
+
}
|
|
185
|
+
ctx.done({ ...data, checks });
|
|
186
|
+
return data;
|
|
187
|
+
},
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
export const domainOrderCommand = {
|
|
191
|
+
name: 'domain order',
|
|
192
|
+
summary: '查域名注册任务状态 / 某个域名的归属与到期时间',
|
|
193
|
+
usage: 'wkgeo domain order --task <TaskNo> | --domain <域名>',
|
|
194
|
+
flags: {
|
|
195
|
+
task: { type: 'string', desc: '下单返回的 TaskNo(QueryTaskDetailList)' },
|
|
196
|
+
domain: { type: 'string', desc: '查这个域名在不在账号里 + 到期时间(QueryDomainByDomainName)' },
|
|
197
|
+
},
|
|
198
|
+
examples: ['wkgeo domain order --task 9001', 'wkgeo domain order --domain newbrand.com'],
|
|
199
|
+
notes: ['任务状态:WAITING_EXECUTE / EXECUTING / EXECUTE_SUCCESS / EXECUTE_FAILURE。'],
|
|
200
|
+
async run(ctx) {
|
|
201
|
+
const { out, flags } = ctx;
|
|
202
|
+
if (!flags.task && !flags.domain) throw new UsageError('需要 --task <TaskNo> 或 --domain <域名>');
|
|
203
|
+
const payload = {};
|
|
204
|
+
if (flags.task) payload.taskNo = flags.task;
|
|
205
|
+
if (flags.domain) payload.domain = flags.domain;
|
|
206
|
+
|
|
207
|
+
const data = (await callOps(ctx, 'domain.orderStatus', payload, '域名订单状态')) || {};
|
|
208
|
+
if (!out.json) {
|
|
209
|
+
const tasks = Array.isArray(data.tasks) ? data.tasks : [];
|
|
210
|
+
if (tasks.length) {
|
|
211
|
+
out.head(`注册任务(${tasks.length} 个)`);
|
|
212
|
+
out.table(
|
|
213
|
+
[
|
|
214
|
+
{ title: 'TaskNo', key: 'task_no', width: 16 },
|
|
215
|
+
{ title: '类型', key: 'task_type', width: 18 },
|
|
216
|
+
{ title: '状态', key: 'task_status', width: 18 },
|
|
217
|
+
{ title: '域名', key: 'domain', width: 28 },
|
|
218
|
+
{ title: '失败原因', key: 'fail', width: 30 },
|
|
219
|
+
],
|
|
220
|
+
tasks.map((t) => ({
|
|
221
|
+
task_no: t.task_no,
|
|
222
|
+
task_type: t.task_type,
|
|
223
|
+
task_status: t.task_status,
|
|
224
|
+
domain: t.domain,
|
|
225
|
+
fail: String(t.fail_reason || t.error_msg || '').slice(0, 40),
|
|
226
|
+
})),
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
if (data.domain_info) {
|
|
230
|
+
const d = data.domain_info;
|
|
231
|
+
out.head(`域名:${d.domain || '—'}`);
|
|
232
|
+
out.line(` 在账号里:${d.owned ? '是' : '否'} 状态:${d.status || '—'} 到期:${d.expiration_date || '—'}`);
|
|
233
|
+
}
|
|
234
|
+
if (data.done) out.ok(data.success ? '任务已成功' : '任务已结束但失败');
|
|
235
|
+
}
|
|
236
|
+
ctx.done(data);
|
|
237
|
+
return data;
|
|
238
|
+
},
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
/* ============================== 云解析(真写) ============================== */
|
|
242
|
+
|
|
243
|
+
const DNS_FLAGS = {
|
|
244
|
+
domain: { type: 'string', desc: '完整域名(服务端按最长后缀找 zone,如 cli-e2e.wkago.com ⇒ zone wkago.com)' },
|
|
245
|
+
type: { type: 'string', desc: '记录类型:A / AAAA / CNAME / TXT / MX / SRV / CAA' },
|
|
246
|
+
value: { type: 'string', desc: '记录值(CNAME 填目标域名,TXT 填文本)' },
|
|
247
|
+
rr: { type: 'string', desc: '主机记录(不填就从域名里推:cli-e2e.wkago.com ⇒ cli-e2e)' },
|
|
248
|
+
ttl: { type: 'string', desc: 'TTL 秒(600–86400,默认 600)' },
|
|
249
|
+
'record-id': { type: 'string', desc: '记录 ID(update / delete 必填,来自 domain zone list)' },
|
|
250
|
+
yes: { type: 'boolean', desc: '删除必须显式确认' },
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
export const domainZoneListCommand = {
|
|
254
|
+
name: 'domain zone list',
|
|
255
|
+
summary: '列账号里某个域名的真实解析记录(自持 alidns,不是"照抄表")',
|
|
256
|
+
usage: 'wkgeo domain zone list --domain <域名> [--type <类型>] [--rr <主机记录>] [--json]',
|
|
257
|
+
flags: { domain: DNS_FLAGS.domain, type: DNS_FLAGS.type, rr: DNS_FLAGS.rr },
|
|
258
|
+
examples: ['wkgeo domain zone list --domain wkago.com', 'wkgeo domain zone list --domain cli-e2e.wkago.com --type CNAME'],
|
|
259
|
+
notes: ['只想看"我还该加哪几条解析"?用 `wkgeo domain dns`(那张是给客户照抄的表)。'],
|
|
260
|
+
async run(ctx) {
|
|
261
|
+
const { out, flags } = ctx;
|
|
262
|
+
if (!flags.domain) throw new UsageError('需要 --domain <域名>');
|
|
263
|
+
const data = (await callOps(ctx, 'domain.dns.list', { domain: flags.domain, type: flags.type, rr: flags.rr }, '列解析记录')) || {};
|
|
264
|
+
const rows = Array.isArray(data.rows) ? data.rows : [];
|
|
265
|
+
if (!out.json) {
|
|
266
|
+
out.head(`解析记录:${data.zone || flags.domain}(${rows.length} 条,zone=${data.zone || '—'})`);
|
|
267
|
+
if (!rows.length) out.info(' 这个 zone 下没有解析记录');
|
|
268
|
+
else {
|
|
269
|
+
out.table(
|
|
270
|
+
[
|
|
271
|
+
{ title: '记录ID', key: 'record_id', width: 14 },
|
|
272
|
+
{ title: '主机', key: 'rr', width: 20 },
|
|
273
|
+
{ title: '类型', key: 'type', width: 8 },
|
|
274
|
+
{ title: '值', key: 'value', width: 46 },
|
|
275
|
+
{ title: 'TTL', key: 'ttl', width: 8 },
|
|
276
|
+
{ title: '状态', key: 'status', width: 10 },
|
|
277
|
+
],
|
|
278
|
+
rows.map((r) => ({ ...r, value: String(r.value || '').slice(0, 60) })),
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
ctx.done({ ...data, rows });
|
|
283
|
+
return data;
|
|
284
|
+
},
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
export const domainZoneAddCommand = {
|
|
288
|
+
name: 'domain zone add',
|
|
289
|
+
summary: '加一条解析(写后自动回读确认;同值幂等,不同值会让你改用 update)',
|
|
290
|
+
usage: 'wkgeo domain zone add --domain <域名> --type <类型> --value <值> [--rr <主机>] [--ttl <秒>] [--json]',
|
|
291
|
+
flags: { domain: DNS_FLAGS.domain, type: DNS_FLAGS.type, value: DNS_FLAGS.value, rr: DNS_FLAGS.rr, ttl: DNS_FLAGS.ttl },
|
|
292
|
+
examples: [
|
|
293
|
+
'wkgeo domain zone add --domain cli-e2e.wkago.com --type CNAME --value c-cli-e2e.intl.wkgeo.com.cn',
|
|
294
|
+
'wkgeo domain zone add --domain _verify.wkago.com --type TXT --value "verify=abc"',
|
|
295
|
+
],
|
|
296
|
+
notes: [
|
|
297
|
+
'写完立刻回读:**回读值不符会报 502**(这时记录可能已经写进去了,先去 `domain zone list` 看一眼,别急着重加)。',
|
|
298
|
+
'平台自有域名(wkgeo.com 等)默认禁止写解析,除非服务端开了 `CLI_DNS_PLATFORM_ZONES=1`。',
|
|
299
|
+
],
|
|
300
|
+
async run(ctx) {
|
|
301
|
+
const { out, flags } = ctx;
|
|
302
|
+
if (!flags.domain) throw new UsageError('需要 --domain <域名>');
|
|
303
|
+
if (!flags.type) throw new UsageError('需要 --type <类型>(A / AAAA / CNAME / TXT / MX / SRV / CAA)');
|
|
304
|
+
if (!flags.value) throw new UsageError('需要 --value <记录值>');
|
|
305
|
+
const payload = { domain: flags.domain, type: flags.type, value: flags.value };
|
|
306
|
+
if (flags.rr) payload.rr = flags.rr;
|
|
307
|
+
if (flags.ttl !== undefined) payload.ttl = Number(flags.ttl);
|
|
308
|
+
|
|
309
|
+
const data = (await callOps(ctx, 'domain.dns.add', payload, '新增解析')) || {};
|
|
310
|
+
if (!out.json) {
|
|
311
|
+
out.head(`新增解析:${data.rr}.${data.zone}(${data.type})`);
|
|
312
|
+
if (data.unchanged) out.ok('已有同值记录,未重复写(幂等)');
|
|
313
|
+
else out.ok(`已写入(RecordId=${data.record_id}),回读值一致:${data.readback ? data.readback.value : '—'}`);
|
|
314
|
+
}
|
|
315
|
+
ctx.done(data);
|
|
316
|
+
return data;
|
|
317
|
+
},
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
export const domainZoneUpdateCommand = {
|
|
321
|
+
name: 'domain zone update',
|
|
322
|
+
summary: '改一条解析(按 RecordId 全量覆盖,写后回读确认)',
|
|
323
|
+
usage:
|
|
324
|
+
'wkgeo domain zone update --record-id <记录ID> [--domain <域名>] [--type <类型>] --value <值> [--rr <主机>] [--ttl <秒>]',
|
|
325
|
+
flags: {
|
|
326
|
+
'record-id': DNS_FLAGS['record-id'],
|
|
327
|
+
domain: DNS_FLAGS.domain,
|
|
328
|
+
type: DNS_FLAGS.type,
|
|
329
|
+
value: DNS_FLAGS.value,
|
|
330
|
+
rr: DNS_FLAGS.rr,
|
|
331
|
+
ttl: DNS_FLAGS.ttl,
|
|
332
|
+
},
|
|
333
|
+
examples: ['wkgeo domain zone update --record-id 8123456 --value c-new.intl.wkgeo.com.cn'],
|
|
334
|
+
notes: ['阿里云 UpdateDomainRecord 是**全量覆盖**:没给的字段会丢,所以服务端会先读出旧记录再补全。'],
|
|
335
|
+
async run(ctx) {
|
|
336
|
+
const { out, flags } = ctx;
|
|
337
|
+
if (!flags['record-id']) throw new UsageError('需要 --record-id(用 `wkgeo domain zone list` 查)');
|
|
338
|
+
if (!flags.domain) throw new UsageError('需要 --domain <域名>(用来定位 zone)');
|
|
339
|
+
if (!flags.value) throw new UsageError('需要 --value <新记录值>');
|
|
340
|
+
const payload = { domain: flags.domain, recordId: flags['record-id'], value: flags.value };
|
|
341
|
+
if (flags.type) payload.type = flags.type;
|
|
342
|
+
if (flags.rr) payload.rr = flags.rr;
|
|
343
|
+
if (flags.ttl !== undefined) payload.ttl = Number(flags.ttl);
|
|
344
|
+
|
|
345
|
+
const data = (await callOps(ctx, 'domain.dns.update', payload, '修改解析')) || {};
|
|
346
|
+
if (!out.json) {
|
|
347
|
+
out.head(`修改解析:RecordId=${data.record_id}`);
|
|
348
|
+
if (data.unchanged) out.ok('值没变,未写(幂等)');
|
|
349
|
+
else out.ok(`已更新,回读值一致:${data.readback ? data.readback.value : '—'}`);
|
|
350
|
+
}
|
|
351
|
+
ctx.done(data);
|
|
352
|
+
return data;
|
|
353
|
+
},
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
export const domainZoneDeleteCommand = {
|
|
357
|
+
name: 'domain zone delete',
|
|
358
|
+
summary: '删一条解析(必须 --yes;重复删是幂等的)',
|
|
359
|
+
usage: 'wkgeo domain zone delete --domain <域名> --record-id <记录ID> --yes',
|
|
360
|
+
flags: { domain: DNS_FLAGS.domain, 'record-id': DNS_FLAGS['record-id'], yes: DNS_FLAGS.yes },
|
|
361
|
+
examples: ['wkgeo domain zone delete --domain cli-e2e.wkago.com --record-id 8123456 --yes'],
|
|
362
|
+
notes: ['删错一条解析 = 线上事故,所以这里强制 `--yes`。'],
|
|
363
|
+
async run(ctx) {
|
|
364
|
+
const { out, flags } = ctx;
|
|
365
|
+
if (!flags['record-id']) throw new UsageError('需要 --record-id(用 `wkgeo domain zone list` 查)');
|
|
366
|
+
if (!flags.domain) throw new UsageError('需要 --domain <域名>(用来定位 zone)');
|
|
367
|
+
if (!flags.yes) {
|
|
368
|
+
throw new UsageError(`删除解析需要显式确认:加 --yes\n 待删:${flags['record-id']}(${flags.domain})`);
|
|
369
|
+
}
|
|
370
|
+
const data = (await callOps(ctx, 'domain.dns.delete', { domain: flags.domain, recordId: flags['record-id'] }, '删除解析')) || {};
|
|
371
|
+
if (!out.json) {
|
|
372
|
+
if (data.already_absent) out.ok('记录本来就不在了(幂等成功)');
|
|
373
|
+
else out.ok(`已删除 RecordId=${flags['record-id']},回读确认已消失`);
|
|
374
|
+
}
|
|
375
|
+
ctx.done(data);
|
|
376
|
+
return data;
|
|
377
|
+
},
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
/* ================================= ESA ================================= */
|
|
381
|
+
|
|
382
|
+
const ESA_FLAGS = {
|
|
383
|
+
pool: { type: 'string', desc: '池位:id / set_code / 站点名(如 intl-1、intl.wkgeo.com.cn)' },
|
|
384
|
+
site: { type: 'string', desc: '站点 id(与 --pool 二选一)' },
|
|
385
|
+
host: { type: 'string', desc: '要接的完整域名(如 cli-e2e.wkago.com)' },
|
|
386
|
+
endpoint: { type: 'string', desc: '回源桶端点(默认复用池行 origin 记录)' },
|
|
387
|
+
'record-id': { type: 'string', desc: 'ESA 回源记录 id(不填按记录名自动查)' },
|
|
388
|
+
'no-cert': { type: 'boolean', desc: '不申请免费证书(只接域名)' },
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
export const esaSiteCommand = {
|
|
392
|
+
name: 'esa site',
|
|
393
|
+
summary: '确认池位对应的 ESA 站点就绪(读站点,不开新站 —— 开站要花钱)',
|
|
394
|
+
usage: 'wkgeo esa site --pool <池位> | --site <站点id>',
|
|
395
|
+
flags: { pool: ESA_FLAGS.pool, site: ESA_FLAGS.site },
|
|
396
|
+
examples: ['wkgeo esa site --pool intl-1'],
|
|
397
|
+
notes: ['只回读 `GetSite`(站点名 / 覆盖区域 / 接入方式 / NS);**本命令不会创建站点**。'],
|
|
398
|
+
async run(ctx) {
|
|
399
|
+
const { out, flags } = ctx;
|
|
400
|
+
if (!flags.pool && !flags.site) throw new UsageError('需要 --pool <池位> 或 --site <站点id>');
|
|
401
|
+
const payload = {};
|
|
402
|
+
if (flags.pool) payload.pool = flags.pool;
|
|
403
|
+
if (flags.site) payload.siteId = flags.site;
|
|
404
|
+
const data = (await callOps(ctx, 'esa.site.ensure', payload, 'ESA 站点就绪')) || {};
|
|
405
|
+
if (!out.json) {
|
|
406
|
+
const s = data.site || {};
|
|
407
|
+
out.head(`ESA 站点:${s.site_name || '—'}`);
|
|
408
|
+
out.line(` SiteId:${s.site_id || '—'} 状态:${s.status || '—'} 覆盖:${s.coverage || '—'} 接入:${s.access_type || '—'}`);
|
|
409
|
+
out.line(` 池位:${(data.pool && data.pool.set_code) || '—'} apex:${data.apex || '—'}`);
|
|
410
|
+
out.ok('站点已在本账号内,可以接源站记录 / CustomHostname');
|
|
411
|
+
}
|
|
412
|
+
ctx.done(data);
|
|
413
|
+
return data;
|
|
414
|
+
},
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
export const esaRecordCommand = {
|
|
418
|
+
name: 'esa record',
|
|
419
|
+
summary: '建/改 ESA 的 S3 回源记录(同值幂等;记录名必须是单标签子域)',
|
|
420
|
+
usage: 'wkgeo esa record --pool <池位> --host <域名> [--endpoint <桶端点>]',
|
|
421
|
+
flags: { pool: ESA_FLAGS.pool, site: ESA_FLAGS.site, host: ESA_FLAGS.host, endpoint: ESA_FLAGS.endpoint },
|
|
422
|
+
examples: ['wkgeo esa record --pool intl-1 --host cli-e2e.wkago.com'],
|
|
423
|
+
notes: [
|
|
424
|
+
'记录名 = `c-<slug>.<池域>`(单标签,ESA 的硬要求);HostPolicy 必须是 follow_origin_domain。',
|
|
425
|
+
'写后回读:源站类型 / Data / HostPolicy 任何一项不符都会报错。',
|
|
426
|
+
],
|
|
427
|
+
async run(ctx) {
|
|
428
|
+
const { out, flags } = ctx;
|
|
429
|
+
if (!flags.host) throw new UsageError('需要 --host <域名>');
|
|
430
|
+
if (!flags.pool && !flags.site) throw new UsageError('需要 --pool <池位> 或 --site <站点id>');
|
|
431
|
+
const payload = { host: flags.host };
|
|
432
|
+
if (flags.pool) payload.pool = flags.pool;
|
|
433
|
+
if (flags.site) payload.siteId = flags.site;
|
|
434
|
+
if (flags.endpoint) payload.endpoint = flags.endpoint;
|
|
435
|
+
const data = (await callOps(ctx, 'esa.record.s3', payload, 'ESA 回源记录')) || {};
|
|
436
|
+
if (!out.json) {
|
|
437
|
+
out.head(`回源记录:${data.record_name || '—'}`);
|
|
438
|
+
out.line(` RecordId:${data.record_id || '—'} 回源:${data.endpoint || '—'}(${data.endpoint_source || '—'})`);
|
|
439
|
+
if (data.unchanged) out.ok('记录已存在且一致(幂等)');
|
|
440
|
+
else out.ok(data.updated ? '已更新并回读确认' : '已创建并回读确认');
|
|
441
|
+
out.info(` 下一步:wkgeo esa hostname --pool ${flags.pool || ''} --host ${flags.host} --record-id ${data.record_id || '<id>'}`);
|
|
442
|
+
}
|
|
443
|
+
ctx.done(data);
|
|
444
|
+
return data;
|
|
445
|
+
},
|
|
446
|
+
};
|
|
447
|
+
|
|
448
|
+
export const esaHostnameCommand = {
|
|
449
|
+
name: 'esa hostname',
|
|
450
|
+
summary: '接 CustomHostname + 申请免费证书(幂等;100 次/小时限流,别重试)',
|
|
451
|
+
usage: 'wkgeo esa hostname --pool <池位> --host <域名> [--record-id <id>] [--no-cert]',
|
|
452
|
+
flags: { pool: ESA_FLAGS.pool, site: ESA_FLAGS.site, host: ESA_FLAGS.host, 'record-id': ESA_FLAGS['record-id'], 'no-cert': ESA_FLAGS['no-cert'] },
|
|
453
|
+
examples: ['wkgeo esa hostname --pool intl-1 --host cli-e2e.wkago.com'],
|
|
454
|
+
notes: [
|
|
455
|
+
'**先有回源记录再接域名**:没回源记录也没给 --record-id 会直接 400(避免接出个黑洞)。',
|
|
456
|
+
'证书是免费 DV,DNS 必须先解析到 ESA 才能签下来;签不下来不会假装成功。',
|
|
457
|
+
],
|
|
458
|
+
async run(ctx) {
|
|
459
|
+
const { out, flags } = ctx;
|
|
460
|
+
if (!flags.host) throw new UsageError('需要 --host <域名>');
|
|
461
|
+
if (!flags.pool && !flags.site) throw new UsageError('需要 --pool <池位> 或 --site <站点id>');
|
|
462
|
+
const payload = { hostname: flags.host };
|
|
463
|
+
if (flags.pool) payload.pool = flags.pool;
|
|
464
|
+
if (flags.site) payload.siteId = flags.site;
|
|
465
|
+
if (flags['record-id']) payload.recordId = flags['record-id'];
|
|
466
|
+
if (flags['no-cert']) payload.applyCert = false;
|
|
467
|
+
|
|
468
|
+
const data = (await callOps(ctx, 'esa.hostname.ensure', payload, 'ESA CustomHostname')) || {};
|
|
469
|
+
if (!out.json) {
|
|
470
|
+
out.head(`CustomHostname:${flags.host}`);
|
|
471
|
+
out.line(` HostnameId:${data.hostname_id || '—'} 回源记录:${data.record_id || '—'}`);
|
|
472
|
+
if (data.unchanged) out.ok('已存在且指向正确(幂等,未重复创建)');
|
|
473
|
+
else out.ok(data.created ? '已创建' : '已更新指向');
|
|
474
|
+
if (data.cert_apply && data.cert_apply.skipped) out.info(` 证书:${data.cert_apply.reason || '已有可用证书,跳过申请'}`);
|
|
475
|
+
else if (data.cert_apply) out.info(' 证书:已提交免费证书申请(DNS 生效后才会签发)');
|
|
476
|
+
}
|
|
477
|
+
ctx.done(data);
|
|
478
|
+
return data;
|
|
479
|
+
},
|
|
480
|
+
};
|
|
481
|
+
|
|
482
|
+
export const esaKvCommand = {
|
|
483
|
+
name: 'esa kv',
|
|
484
|
+
summary: '把域名写进边缘路由 KV(`host:<域名>` → 站点目录,写后 GetKv 回读)',
|
|
485
|
+
usage: 'wkgeo esa kv --host <域名> --site-id <站点id>',
|
|
486
|
+
flags: { host: ESA_FLAGS.host, 'site-id': { type: 'string', desc: '站点 id(KV 的值就是它,边缘据此改写路径)' } },
|
|
487
|
+
examples: ['wkgeo esa kv --host cli-e2e.wkago.com --site-id 8f0c…'],
|
|
488
|
+
notes: [
|
|
489
|
+
'KV 值是**站点 id**(= 桶里的顶层目录),边缘路由器命中后把 `/<path>` 改写成 `/<siteId>/<path>`。',
|
|
490
|
+
'BatchPutKv 回 200 只代表"收到",不代表生效 —— 所以这里强制 GetKv 回读,读不到就是失败。',
|
|
491
|
+
'生效有约 10 秒延迟;回读失败会自动重试几次。',
|
|
492
|
+
],
|
|
493
|
+
async run(ctx) {
|
|
494
|
+
const { out, flags } = ctx;
|
|
495
|
+
if (!flags.host) throw new UsageError('需要 --host <域名>');
|
|
496
|
+
if (!flags['site-id']) throw new UsageError('需要 --site-id <站点id>(值就是它,不能是路径)');
|
|
497
|
+
const data = (await callOps(ctx, 'esa.kv.put', { host: flags.host, siteId: flags['site-id'] }, '边缘路由 KV')) || {};
|
|
498
|
+
if (!out.json) {
|
|
499
|
+
out.head(`边缘路由 KV:${data.key || `host:${flags.host}`}`);
|
|
500
|
+
out.line(` 值:${data.value || '—'} 别名:${(data.aliases || []).join(', ') || '—'}`);
|
|
501
|
+
out.ok(`已写入并回读确认(第 ${data.attempts || 1} 次),路径前缀 ${data.path_hint || ''}`);
|
|
502
|
+
}
|
|
503
|
+
ctx.done(data);
|
|
504
|
+
return data;
|
|
505
|
+
},
|
|
506
|
+
};
|
|
507
|
+
|
|
508
|
+
/* ============================== 建站收口 ============================== */
|
|
509
|
+
|
|
510
|
+
export const siteCreateCommand = {
|
|
511
|
+
name: 'site create',
|
|
512
|
+
summary: '建站 + 自持收口(池位 / 短域 / host KV 回读确认)',
|
|
513
|
+
usage: 'wkgeo site create --name <站点名> (--region domestic|overseas|global | --pool intl-1) [--json]',
|
|
514
|
+
flags: {
|
|
515
|
+
name: { type: 'string', desc: '站点名称(必填)' },
|
|
516
|
+
region: { type: 'string', desc: '加速区域:domestic / overseas / global' },
|
|
517
|
+
pool: { type: 'string', desc: '池位 / 区域别名(intl-1、intl、cn1、global…)' },
|
|
518
|
+
},
|
|
519
|
+
examples: ['wkgeo site create --name 演示站 --pool intl'],
|
|
520
|
+
notes: [
|
|
521
|
+
'建站本身委托站内核(同一进程内的自持副本,不发 HTTP),**收口由 CLI fc 自己做完**:',
|
|
522
|
+
'池位分配 / 短域 prefix_host / `host:<短域>` KV —— 三者都过才回 ok。',
|
|
523
|
+
'KV 回读失败会明确报失败(不会假装建好了);KV 生效约 10 秒。',
|
|
524
|
+
],
|
|
525
|
+
async run(ctx) {
|
|
526
|
+
const { out, flags } = ctx;
|
|
527
|
+
if (!flags.name) throw new UsageError('需要 --name <站点名称>');
|
|
528
|
+
if (!flags.region && !flags.pool) throw new UsageError('需要 --region 或 --pool(domestic / overseas / global)');
|
|
529
|
+
const payload = { name: flags.name };
|
|
530
|
+
if (flags.region) payload.region = flags.region;
|
|
531
|
+
if (flags.pool) payload.pool = flags.pool;
|
|
532
|
+
|
|
533
|
+
const data = (await callOps(ctx, 'site.create', payload, '建站收口')) || {};
|
|
534
|
+
if (!out.json) {
|
|
535
|
+
const c = data.closeout || {};
|
|
536
|
+
out.head(`建站完成:${data.name || flags.name}`);
|
|
537
|
+
out.line(` 站点 id:${data.site_id || data.id || '—'}`);
|
|
538
|
+
out.line(` 池位:${c.set_code || '—'}(${c.pool_id || '—'}) 短域:${c.prefix_host || '—'}`);
|
|
539
|
+
out.line(` host KV:${c.kv ? (c.kv.verified ? `已验证(${c.kv.via})` : '未验证') : '—'}`);
|
|
540
|
+
if (c.ok) out.ok(`短域可直接访问:${c.prefix_url || `https://${c.prefix_host}`}`);
|
|
541
|
+
else out.warn(`收口未完成:${c.code || ''} ${c.message || ''}`.trim());
|
|
542
|
+
}
|
|
543
|
+
ctx.done(data);
|
|
544
|
+
return data;
|
|
545
|
+
},
|
|
546
|
+
};
|