@axium/client 0.23.5 → 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.
@@ -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.start('Fetching metadata');
46
- const [session, apps] = await Promise.all([getCurrentSession(), fetchAPI('GET', 'apps')]).catch(io.exit);
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
- config.cache = { fetched: Date.now(), session, apps };
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} (${capitalize(process.platform)}; ${process.arch})`;
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
- var rl, axiumPlugin;
80
- const env_1 = { stack: [], error: void 0, hasError: false };
81
- try {
82
- rl = __addDisposableResource(env_1, createInterface({
83
- input: process.stdin,
84
- output: process.stdout,
85
- }), false);
86
- rl.on('SIGINT', () => io.exit('Aborted.', 7));
87
- program
88
- .version($pkg.version)
89
- .name('axium-client')
90
- .alias('axc')
91
- .description('Axium client CLI')
92
- .configureHelp({ showGlobalOptions: true })
93
- .option('--debug', 'override debug mode')
94
- .option('--no-debug', 'override debug mode')
95
- .option('--refresh-session', 'Force a refresh of session and user metadata from server', false)
96
- .option('--cache-only', 'Run entirely from local cache, even if it is expired.', false)
97
- .option('--safe', 'do not execute code from plugins', false)
98
- .hook('preAction', async (axc, action) => {
99
- const opt = axc.optsWithGlobals();
100
- if (!config.token)
101
- return;
102
- if (!opt.cacheOnly && action.name() != 'login')
103
- await updateCache(opt.refreshSession);
104
- });
105
- program.on('option:debug', () => io._setDebugOutput(true));
106
- program
107
- .command('login')
108
- .description('Log in to your account on an Axium server')
109
- .argument('[server]', 'Axium server URL')
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.start('Verifying session');
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
- program.command('logout').action(async () => {
173
- if (!config.token)
174
- io.exit('Not logged in.', 4);
175
- if (!config.cache)
176
- io.exit('No session data available.', 3);
177
- await logout(config.cache.session.userId, config.cache.session.id);
178
- });
179
- program.command('status').action(() => {
180
- if (!config.token)
181
- return console.log('Not logged in.');
182
- if (!config.cache)
183
- return console.log('No session data available.');
184
- console.log('Logged in to', new URL(prefix).host);
185
- console.log(styleText('whiteBright', 'Session ID:'), config.cache.session.id);
186
- const { user } = config.cache.session;
187
- console.log(styleText('whiteBright', 'User:'), user.name, `<${user.email}>`, styleText('dim', `(${user.id})`));
188
- outputDaemonStatus('axium-client');
189
- });
190
- program
191
- .command('run')
192
- .argument('[plugin]', 'The plugin to run')
193
- .action(async (name) => {
194
- if (name) {
195
- const plugin = _findPlugin(name);
196
- await plugin._client?.run();
197
- return;
198
- }
199
- for (const plugin of plugins.values())
200
- await plugin._client?.run();
201
- });
202
- axiumPlugin = program.command('plugin').alias('plugins').description('Manage plugins');
203
- axiumPlugin
204
- .command('list')
205
- .alias('ls')
206
- .description('List loaded plugins')
207
- .option('-l, --long', 'use the long listing format')
208
- .option('--no-versions', 'do not show plugin versions')
209
- .action(opt => {
210
- if (!plugins.size) {
211
- console.log('No plugins loaded.');
212
- return;
213
- }
214
- if (!opt.long) {
215
- console.log(Array.from(plugins.keys()).join(', '));
216
- return;
217
- }
218
- console.log(styleText('whiteBright', plugins.size + ' plugin(s) loaded:'));
219
- for (const plugin of plugins.values()) {
220
- console.log(plugin.name, opt.versions ? plugin.version : '');
221
- }
222
- });
223
- axiumPlugin
224
- .command('info')
225
- .description('Get information about a plugin')
226
- .argument('<plugin>', 'the plugin to get information about')
227
- .action((search) => {
228
- const plugin = _findPlugin(search);
229
- for (const line of pluginText(plugin))
230
- console.log(line);
231
- });
232
- axiumPlugin
233
- .command('remove')
234
- .alias('rm')
235
- .description('Remove a plugin')
236
- .argument('<plugin>', 'the plugin to remove')
237
- .action((search) => {
238
- const plugin = _findPlugin(search);
239
- config.plugins = config.plugins.filter(p => p !== plugin.specifier);
240
- plugins.delete(plugin.name);
241
- saveConfig();
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 (e_1) {
246
- env_1.error = e_1;
247
- env_1.hasError = true;
248
- }
249
- finally {
250
- __disposeResources(env_1);
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.5",
3
+ "version": "0.23.6",
4
4
  "author": "James Prevett <jp@jamespre.dev>",
5
5
  "funding": {
6
6
  "type": "individual",
@@ -46,7 +46,7 @@
46
46
  },
47
47
  "peerDependencies": {
48
48
  "@axium/core": ">=0.27.1",
49
- "ioium": "^1.0.0",
49
+ "ioium": "^1.0.2",
50
50
  "semver": "^7.7.4",
51
51
  "svelte": "^5.36.0",
52
52
  "utilium": "^3.0.0",