wedos-cli 1.0.0 → 1.0.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/package.json +1 -1
- package/src/commands/domain.js +65 -25
- package/src/index.js +54 -22
- package/src/lib/wapi.js +22 -2
package/package.json
CHANGED
package/src/commands/domain.js
CHANGED
|
@@ -37,30 +37,67 @@ export function createDomainCommand() {
|
|
|
37
37
|
.description('Kontrola dostupnosti domény (lze zadat více)')
|
|
38
38
|
.option('--json', 'Výstup jako JSON')
|
|
39
39
|
.action(async (domains, options) => {
|
|
40
|
-
const spinner = ora('Kontroluji dostupnost...').start();
|
|
41
40
|
try {
|
|
42
41
|
const client = new WapiClient(getCredentials());
|
|
43
|
-
const
|
|
44
|
-
|
|
42
|
+
const results = [];
|
|
43
|
+
|
|
44
|
+
// Check each domain individually (WAPI returns status per domain via response code)
|
|
45
|
+
for (const domainName of domains) {
|
|
46
|
+
const spinner = ora(`Kontroluji ${domainName}...`).start();
|
|
47
|
+
const response = await client.domainCheck(domainName);
|
|
48
|
+
spinner.stop();
|
|
49
|
+
|
|
50
|
+
const code = parseInt(response.code);
|
|
51
|
+
let status, reason;
|
|
52
|
+
|
|
53
|
+
// Response codes for domain-check:
|
|
54
|
+
// 1000 = available
|
|
55
|
+
// 3201 = already registered
|
|
56
|
+
// 3204 = quarantined
|
|
57
|
+
// 3205 = reserved
|
|
58
|
+
// 3206 = blocked
|
|
59
|
+
switch (code) {
|
|
60
|
+
case 1000:
|
|
61
|
+
status = 'available';
|
|
62
|
+
reason = 'Volná k registraci';
|
|
63
|
+
break;
|
|
64
|
+
case 3201:
|
|
65
|
+
status = 'registered';
|
|
66
|
+
reason = 'Již registrovaná';
|
|
67
|
+
break;
|
|
68
|
+
case 3204:
|
|
69
|
+
status = 'quarantine';
|
|
70
|
+
reason = 'V karanténě';
|
|
71
|
+
break;
|
|
72
|
+
case 3205:
|
|
73
|
+
status = 'reserved';
|
|
74
|
+
reason = 'Rezervovaná';
|
|
75
|
+
break;
|
|
76
|
+
case 3206:
|
|
77
|
+
status = 'blocked';
|
|
78
|
+
reason = 'Blokovaná';
|
|
79
|
+
break;
|
|
80
|
+
default:
|
|
81
|
+
status = 'error';
|
|
82
|
+
reason = response.result || 'Neznámá chyba';
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
results.push({ domain: domainName, code, status, reason });
|
|
86
|
+
}
|
|
45
87
|
|
|
46
88
|
if (options.json) {
|
|
47
|
-
|
|
89
|
+
console.log(JSON.stringify(results, null, 2));
|
|
48
90
|
} else {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const text = status ? chalk.green('Volná') : chalk.red('Zaregistrovaná');
|
|
56
|
-
console.log(`${icon} ${domain} - ${text}`);
|
|
57
|
-
}
|
|
58
|
-
} else {
|
|
59
|
-
formatResponse(response);
|
|
91
|
+
console.log(chalk.bold('\n🔍 Dostupnost domén:\n'));
|
|
92
|
+
for (const result of results) {
|
|
93
|
+
const isAvailable = result.status === 'available';
|
|
94
|
+
const icon = isAvailable ? chalk.green('✓') : chalk.red('✗');
|
|
95
|
+
const text = isAvailable ? chalk.green(result.reason) : chalk.red(result.reason);
|
|
96
|
+
console.log(` ${icon} ${chalk.bold(result.domain)} - ${text}`);
|
|
60
97
|
}
|
|
98
|
+
console.log('');
|
|
61
99
|
}
|
|
62
100
|
} catch (error) {
|
|
63
|
-
spinner.stop();
|
|
64
101
|
printError(error);
|
|
65
102
|
process.exit(1);
|
|
66
103
|
}
|
|
@@ -108,17 +145,20 @@ export function createDomainCommand() {
|
|
|
108
145
|
spinner.stop();
|
|
109
146
|
|
|
110
147
|
const checkCode = parseInt(checkResponse.code);
|
|
111
|
-
if (!isSuccess(checkCode)) {
|
|
112
|
-
formatResponse(checkResponse);
|
|
113
|
-
process.exit(1);
|
|
114
|
-
}
|
|
115
148
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
149
|
+
// Response codes for domain-check:
|
|
150
|
+
// 1000 = available, 3201 = registered, 3204 = quarantine, 3205 = reserved, 3206 = blocked
|
|
151
|
+
if (checkCode !== 1000) {
|
|
152
|
+
let reason;
|
|
153
|
+
switch (checkCode) {
|
|
154
|
+
case 3201: reason = 'Doména je již registrovaná'; break;
|
|
155
|
+
case 3204: reason = 'Doména je v karanténě'; break;
|
|
156
|
+
case 3205: reason = 'Doména je rezervovaná'; break;
|
|
157
|
+
case 3206: reason = 'Doména je blokovaná'; break;
|
|
158
|
+
default: reason = checkResponse.result || 'Neznámá chyba';
|
|
121
159
|
}
|
|
160
|
+
printError(`Doména ${domainName} není k dispozici pro registraci`);
|
|
161
|
+
printInfo(`Důvod: ${reason}`);
|
|
122
162
|
process.exit(1);
|
|
123
163
|
}
|
|
124
164
|
|
package/src/index.js
CHANGED
|
@@ -20,7 +20,7 @@ const program = new Command();
|
|
|
20
20
|
program
|
|
21
21
|
.name('wedos')
|
|
22
22
|
.description('CLI nástroj pro WEDOS WAPI - registrace domén, správa DNS a další')
|
|
23
|
-
.version('1.0.
|
|
23
|
+
.version('1.0.2')
|
|
24
24
|
.hook('preAction', (thisCommand) => {
|
|
25
25
|
// Show banner for main commands (not subcommands)
|
|
26
26
|
const commandName = thisCommand.args[0];
|
|
@@ -137,36 +137,68 @@ program
|
|
|
137
137
|
process.exit(1);
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
-
const spinner = ora({
|
|
141
|
-
text: `Kontroluji ${domains.length} doména(y)...`,
|
|
142
|
-
spinner: 'dots12',
|
|
143
|
-
color: 'cyan',
|
|
144
|
-
}).start();
|
|
145
|
-
|
|
146
140
|
try {
|
|
147
141
|
const client = new WapiClient(getCredentials());
|
|
148
|
-
const
|
|
149
|
-
|
|
142
|
+
const results = [];
|
|
143
|
+
|
|
144
|
+
// Check each domain individually (WAPI returns status per domain via response code)
|
|
145
|
+
for (const domainName of domains) {
|
|
146
|
+
const spinner = ora({
|
|
147
|
+
text: `Kontroluji ${domainName}...`,
|
|
148
|
+
spinner: 'dots12',
|
|
149
|
+
color: 'cyan',
|
|
150
|
+
}).start();
|
|
151
|
+
|
|
152
|
+
const response = await client.domainCheck(domainName);
|
|
153
|
+
spinner.stop();
|
|
154
|
+
|
|
155
|
+
const code = parseInt(response.code);
|
|
156
|
+
let status, reason;
|
|
157
|
+
|
|
158
|
+
// Response codes for domain-check:
|
|
159
|
+
// 1000 = available, 3201 = registered, 3204 = quarantine, 3205 = reserved, 3206 = blocked
|
|
160
|
+
switch (code) {
|
|
161
|
+
case 1000:
|
|
162
|
+
status = 'available';
|
|
163
|
+
reason = 'Volná k registraci';
|
|
164
|
+
break;
|
|
165
|
+
case 3201:
|
|
166
|
+
status = 'registered';
|
|
167
|
+
reason = 'Již registrovaná';
|
|
168
|
+
break;
|
|
169
|
+
case 3204:
|
|
170
|
+
status = 'quarantine';
|
|
171
|
+
reason = 'V karanténě';
|
|
172
|
+
break;
|
|
173
|
+
case 3205:
|
|
174
|
+
status = 'reserved';
|
|
175
|
+
reason = 'Rezervovaná';
|
|
176
|
+
break;
|
|
177
|
+
case 3206:
|
|
178
|
+
status = 'blocked';
|
|
179
|
+
reason = 'Blokovaná';
|
|
180
|
+
break;
|
|
181
|
+
default:
|
|
182
|
+
status = 'error';
|
|
183
|
+
reason = response.result || 'Neznámá chyba';
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
results.push({ domain: domainName, code, status, reason });
|
|
187
|
+
}
|
|
150
188
|
|
|
151
189
|
if (options.json) {
|
|
152
|
-
|
|
190
|
+
console.log(JSON.stringify(results, null, 2));
|
|
153
191
|
} else {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
printHeader('Dostupnost domén', '🔍');
|
|
157
|
-
console.log('');
|
|
192
|
+
printHeader('Dostupnost domén', '🔍');
|
|
193
|
+
console.log('');
|
|
158
194
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
console.log('');
|
|
164
|
-
} else {
|
|
165
|
-
formatResponse(response);
|
|
195
|
+
for (const result of results) {
|
|
196
|
+
const available = result.status === 'available';
|
|
197
|
+
printDomainCheck(result.domain, available, result.reason);
|
|
166
198
|
}
|
|
199
|
+
console.log('');
|
|
167
200
|
}
|
|
168
201
|
} catch (error) {
|
|
169
|
-
spinner.stop();
|
|
170
202
|
printError(error);
|
|
171
203
|
process.exit(1);
|
|
172
204
|
}
|
package/src/lib/wapi.js
CHANGED
|
@@ -103,11 +103,22 @@ export class WapiClient {
|
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
async domainCreate(options) {
|
|
106
|
+
// Parse rules - can be "Jméno Příjmení" string or {fname, lname} object
|
|
107
|
+
let rules = options.rules;
|
|
108
|
+
if (typeof rules === 'string') {
|
|
109
|
+
const parts = rules.trim().split(/\s+/);
|
|
110
|
+
if (parts.length >= 2) {
|
|
111
|
+
rules = { fname: parts[0], lname: parts.slice(1).join(' ') };
|
|
112
|
+
} else {
|
|
113
|
+
rules = { fname: parts[0], lname: parts[0] };
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
106
117
|
const data = {
|
|
107
118
|
name: options.name,
|
|
108
119
|
period: options.period || 1,
|
|
109
120
|
owner_c: options.ownerContact,
|
|
110
|
-
rules:
|
|
121
|
+
rules: rules,
|
|
111
122
|
};
|
|
112
123
|
|
|
113
124
|
if (options.adminContact) {
|
|
@@ -118,7 +129,16 @@ export class WapiClient {
|
|
|
118
129
|
if (options.nsset) {
|
|
119
130
|
data.nsset = options.nsset;
|
|
120
131
|
} else if (options.dns) {
|
|
121
|
-
|
|
132
|
+
// Convert array of {name: "..."} to {server1: {name: "..."}, server2: {name: "..."}}
|
|
133
|
+
if (Array.isArray(options.dns)) {
|
|
134
|
+
const dnsObj = {};
|
|
135
|
+
options.dns.forEach((server, index) => {
|
|
136
|
+
dnsObj[`server${index + 1}`] = server;
|
|
137
|
+
});
|
|
138
|
+
data.dns = dnsObj;
|
|
139
|
+
} else {
|
|
140
|
+
data.dns = options.dns;
|
|
141
|
+
}
|
|
122
142
|
} else {
|
|
123
143
|
// Default to WEDOS NSSET
|
|
124
144
|
data.nsset = 'WEDOS';
|