@axium/client 0.23.4 → 0.23.6
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/dist/cli/config.js +5 -6
- package/dist/cli/index.js +128 -117
- package/package.json +3 -1
package/dist/cli/config.js
CHANGED
|
@@ -42,14 +42,13 @@ export const _dayMs = 24 * 3600_000;
|
|
|
42
42
|
export async function updateCache(force) {
|
|
43
43
|
if (!force && config.cache && config.cache.fetched + _dayMs > Date.now())
|
|
44
44
|
return;
|
|
45
|
-
io.
|
|
46
|
-
|
|
45
|
+
const [session, apps] = await io.track('Fetching metadata', Promise.all([getCurrentSession(), fetchAPI('GET', 'apps')]));
|
|
46
|
+
config.cache = { fetched: Date.now(), session, apps };
|
|
47
47
|
try {
|
|
48
|
-
|
|
49
|
-
saveConfig();
|
|
50
|
-
io.done();
|
|
48
|
+
io.writeJSON(axcConfig, config);
|
|
51
49
|
}
|
|
52
|
-
catch {
|
|
50
|
+
catch (e) {
|
|
51
|
+
io.error(e);
|
|
53
52
|
return;
|
|
54
53
|
}
|
|
55
54
|
}
|
package/dist/cli/index.js
CHANGED
|
@@ -52,10 +52,11 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
|
|
|
52
52
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
53
53
|
});
|
|
54
54
|
import { outputDaemonStatus, pluginText } from '@axium/core/node';
|
|
55
|
-
import * as io from 'ioium/node';
|
|
56
55
|
import { _findPlugin, plugins } from '@axium/core/plugins';
|
|
57
|
-
import { program } from 'commander';
|
|
56
|
+
import { CommanderError, program } from 'commander';
|
|
57
|
+
import * as io from 'ioium/node';
|
|
58
58
|
import { createServer } from 'node:http';
|
|
59
|
+
import * as os from 'node:os';
|
|
59
60
|
import { createInterface } from 'node:readline/promises';
|
|
60
61
|
import { styleText } from 'node:util';
|
|
61
62
|
import * as z from 'zod';
|
|
@@ -64,50 +65,48 @@ import { config, resolveServerURL } from '../config.js';
|
|
|
64
65
|
import { prefix, setPrefix, setToken, useUserAgent } from '../requests.js';
|
|
65
66
|
import { getCurrentSession, logout } from '../user.js';
|
|
66
67
|
import { loadConfig, saveConfig, updateCache } from './config.js';
|
|
67
|
-
import { capitalize } from 'utilium';
|
|
68
68
|
const safe = z.stringbool().default(false).parse(process.env.SAFE?.toLowerCase()) || process.argv.includes('--safe');
|
|
69
69
|
const debug = z.stringbool().default(false).parse(process.env.DEBUG?.toLowerCase()) || process.argv.includes('--debug');
|
|
70
70
|
if (debug)
|
|
71
71
|
io._setDebugOutput(true);
|
|
72
|
-
const clientUA = `Axium Client/${$pkg.version} (${
|
|
72
|
+
const clientUA = `Axium Client/${$pkg.version} (${os.type()}; ${process.arch})`;
|
|
73
73
|
useUserAgent(clientUA);
|
|
74
74
|
await loadConfig(safe);
|
|
75
75
|
process.on('SIGHUP', () => {
|
|
76
76
|
io.info('Reloading configuration due to SIGHUP.');
|
|
77
77
|
void loadConfig(safe);
|
|
78
78
|
});
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
.
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
.
|
|
110
|
-
.action(async (url) => {
|
|
79
|
+
program
|
|
80
|
+
.version($pkg.version)
|
|
81
|
+
.name('axium-client')
|
|
82
|
+
.alias('axc')
|
|
83
|
+
.description('Axium client CLI')
|
|
84
|
+
.configureHelp({ showGlobalOptions: true })
|
|
85
|
+
.option('--debug', 'override debug mode')
|
|
86
|
+
.option('--no-debug', 'override debug mode')
|
|
87
|
+
.option('--refresh-session', 'Force a refresh of session and user metadata from server', false)
|
|
88
|
+
.option('--cache-only', 'Run entirely from local cache, even if it is expired.', false)
|
|
89
|
+
.option('--safe', 'do not execute code from plugins', false)
|
|
90
|
+
.hook('preAction', async (axc, action) => {
|
|
91
|
+
const opt = axc.optsWithGlobals();
|
|
92
|
+
if (!config.token)
|
|
93
|
+
return;
|
|
94
|
+
if (!opt.cacheOnly && action.name() != 'login')
|
|
95
|
+
await updateCache(opt.refreshSession);
|
|
96
|
+
});
|
|
97
|
+
program.on('option:debug', () => io._setDebugOutput(true));
|
|
98
|
+
program
|
|
99
|
+
.command('login')
|
|
100
|
+
.description('Log in to your account on an Axium server')
|
|
101
|
+
.argument('[server]', 'Axium server URL')
|
|
102
|
+
.action(async (url) => {
|
|
103
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
104
|
+
try {
|
|
105
|
+
const rl = __addDisposableResource(env_1, createInterface({
|
|
106
|
+
input: process.stdin,
|
|
107
|
+
output: process.stdout,
|
|
108
|
+
}), false);
|
|
109
|
+
rl.on('SIGINT', () => io.exit('Aborted.', 7));
|
|
111
110
|
if (prefix[0] != '/')
|
|
112
111
|
url ||= prefix;
|
|
113
112
|
url ||= await rl.question('Axium server URL: ');
|
|
@@ -159,93 +158,105 @@ try {
|
|
|
159
158
|
const { token } = await sessionReady.promise.catch(e => io.exit('Failed to obtain session: ' + e, 6));
|
|
160
159
|
setToken(token);
|
|
161
160
|
server.close();
|
|
162
|
-
io.
|
|
163
|
-
const session = await getCurrentSession().catch(e => io.exit(e.message, 6));
|
|
164
|
-
io.done();
|
|
161
|
+
const session = await io.track('Verifying session', getCurrentSession().catch(e => io.exit(e.message, 6)));
|
|
165
162
|
io.debug('Session UUID: ' + session.id);
|
|
166
163
|
console.log(`Welcome ${session.user.name}! Your session is valid until ${session.expires.toLocaleDateString()}.`);
|
|
167
164
|
config.token = token;
|
|
168
165
|
config.server = url;
|
|
169
166
|
saveConfig();
|
|
170
167
|
await updateCache(true);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
.
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
.
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
.
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
.
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
168
|
+
}
|
|
169
|
+
catch (e_1) {
|
|
170
|
+
env_1.error = e_1;
|
|
171
|
+
env_1.hasError = true;
|
|
172
|
+
}
|
|
173
|
+
finally {
|
|
174
|
+
__disposeResources(env_1);
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
program.command('logout').action(async () => {
|
|
178
|
+
if (!config.token)
|
|
179
|
+
io.exit('Not logged in.', 4);
|
|
180
|
+
if (!config.cache)
|
|
181
|
+
io.exit('No session data available.', 3);
|
|
182
|
+
await logout(config.cache.session.userId, config.cache.session.id);
|
|
183
|
+
});
|
|
184
|
+
program.command('status').action(() => {
|
|
185
|
+
if (!config.token)
|
|
186
|
+
return console.log('Not logged in.');
|
|
187
|
+
if (!config.cache)
|
|
188
|
+
return console.log('No session data available.');
|
|
189
|
+
const { session } = config.cache;
|
|
190
|
+
console.log('Logged in to', new URL(prefix).host);
|
|
191
|
+
console.log(styleText('whiteBright', 'Session:'), 'valid until', session.expires.toLocaleDateString(), styleText('dim', `(${session.id})`));
|
|
192
|
+
const { user } = session;
|
|
193
|
+
console.log(styleText('whiteBright', 'User:'), user.name, `<${user.email}>`, styleText('dim', `(${user.id})`));
|
|
194
|
+
outputDaemonStatus('axium-client');
|
|
195
|
+
});
|
|
196
|
+
program
|
|
197
|
+
.command('run')
|
|
198
|
+
.argument('[plugin]', 'The plugin to run')
|
|
199
|
+
.action(async (name) => {
|
|
200
|
+
if (name) {
|
|
201
|
+
const plugin = _findPlugin(name);
|
|
202
|
+
await plugin._client?.run();
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
for (const plugin of plugins.values())
|
|
206
|
+
await plugin._client?.run();
|
|
207
|
+
});
|
|
208
|
+
const axiumPlugin = program.command('plugin').alias('plugins').description('Manage plugins');
|
|
209
|
+
axiumPlugin
|
|
210
|
+
.command('list')
|
|
211
|
+
.alias('ls')
|
|
212
|
+
.description('List loaded plugins')
|
|
213
|
+
.option('-l, --long', 'use the long listing format')
|
|
214
|
+
.option('--no-versions', 'do not show plugin versions')
|
|
215
|
+
.action(opt => {
|
|
216
|
+
if (!plugins.size) {
|
|
217
|
+
console.log('No plugins loaded.');
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
if (!opt.long) {
|
|
221
|
+
console.log(Array.from(plugins.keys()).join(', '));
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
console.log(styleText('whiteBright', plugins.size + ' plugin(s) loaded:'));
|
|
225
|
+
for (const plugin of plugins.values()) {
|
|
226
|
+
console.log(plugin.name, opt.versions ? plugin.version : '');
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
axiumPlugin
|
|
230
|
+
.command('info')
|
|
231
|
+
.description('Get information about a plugin')
|
|
232
|
+
.argument('<plugin>', 'the plugin to get information about')
|
|
233
|
+
.action((search) => {
|
|
234
|
+
const plugin = _findPlugin(search);
|
|
235
|
+
for (const line of pluginText(plugin))
|
|
236
|
+
console.log(line);
|
|
237
|
+
});
|
|
238
|
+
axiumPlugin
|
|
239
|
+
.command('remove')
|
|
240
|
+
.alias('rm')
|
|
241
|
+
.description('Remove a plugin')
|
|
242
|
+
.argument('<plugin>', 'the plugin to remove')
|
|
243
|
+
.action((search) => {
|
|
244
|
+
const plugin = _findPlugin(search);
|
|
245
|
+
config.plugins = config.plugins.filter(p => p !== plugin.specifier);
|
|
246
|
+
plugins.delete(plugin.name);
|
|
247
|
+
saveConfig();
|
|
248
|
+
});
|
|
249
|
+
try {
|
|
243
250
|
await program.parseAsync();
|
|
244
251
|
}
|
|
245
|
-
catch (
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
|
|
252
|
+
catch (e) {
|
|
253
|
+
if (e && e instanceof CommanderError) {
|
|
254
|
+
process.exit(1);
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
if (typeof e == 'number')
|
|
258
|
+
process.exit(e);
|
|
259
|
+
io.done(true);
|
|
260
|
+
io.exit(e);
|
|
261
|
+
}
|
|
251
262
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axium/client",
|
|
3
|
-
"version": "0.23.
|
|
3
|
+
"version": "0.23.6",
|
|
4
4
|
"author": "James Prevett <jp@jamespre.dev>",
|
|
5
5
|
"funding": {
|
|
6
6
|
"type": "individual",
|
|
@@ -46,6 +46,8 @@
|
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"@axium/core": ">=0.27.1",
|
|
49
|
+
"ioium": "^1.0.2",
|
|
50
|
+
"semver": "^7.7.4",
|
|
49
51
|
"svelte": "^5.36.0",
|
|
50
52
|
"utilium": "^3.0.0",
|
|
51
53
|
"zod": "^4.0.5"
|