@axium/server 0.44.0 → 0.44.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/dist/{cli.d.ts → cli/common.d.ts} +1 -1
- package/dist/{cli.js → cli/common.js} +2 -2
- package/dist/cli/config.d.ts +1 -0
- package/dist/cli/config.js +69 -0
- package/dist/{db/cli.js → cli/db.js} +10 -32
- package/dist/cli/index.d.ts +5 -0
- package/dist/cli/index.js +303 -0
- package/dist/cli/plugins.d.ts +1 -0
- package/dist/cli/plugins.js +148 -0
- package/dist/cli/user.d.ts +1 -0
- package/dist/cli/user.js +102 -0
- package/dist/io.d.ts +1 -1
- package/dist/io.js +9 -4
- package/dist/linking.d.ts +1 -2
- package/dist/main.d.ts +2 -1
- package/dist/main.js +6 -584
- package/package.json +4 -3
- package/patches/patch.js +12 -0
- package/routes/admin/+page.svelte +2 -2
- package/routes/admin/plugins/+page.svelte +2 -2
- /package/dist/{db/cli.d.ts → cli/db.d.ts} +0 -0
package/dist/main.js
CHANGED
|
@@ -1,82 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
5
|
-
var dispose, inner;
|
|
6
|
-
if (async) {
|
|
7
|
-
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
8
|
-
dispose = value[Symbol.asyncDispose];
|
|
9
|
-
}
|
|
10
|
-
if (dispose === void 0) {
|
|
11
|
-
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
12
|
-
dispose = value[Symbol.dispose];
|
|
13
|
-
if (async) inner = dispose;
|
|
14
|
-
}
|
|
15
|
-
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
16
|
-
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
17
|
-
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
18
|
-
}
|
|
19
|
-
else if (async) {
|
|
20
|
-
env.stack.push({ async: true });
|
|
21
|
-
}
|
|
22
|
-
return value;
|
|
23
|
-
};
|
|
24
|
-
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
25
|
-
return function (env) {
|
|
26
|
-
function fail(e) {
|
|
27
|
-
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
28
|
-
env.hasError = true;
|
|
29
|
-
}
|
|
30
|
-
var r, s = 0;
|
|
31
|
-
function next() {
|
|
32
|
-
while (r = env.stack.pop()) {
|
|
33
|
-
try {
|
|
34
|
-
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
35
|
-
if (r.dispose) {
|
|
36
|
-
var result = r.dispose.call(r.value);
|
|
37
|
-
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
38
|
-
}
|
|
39
|
-
else s |= 1;
|
|
40
|
-
}
|
|
41
|
-
catch (e) {
|
|
42
|
-
fail(e);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
46
|
-
if (env.hasError) throw env.error;
|
|
47
|
-
}
|
|
48
|
-
return next();
|
|
49
|
-
};
|
|
50
|
-
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
51
|
-
var e = new Error(message);
|
|
52
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
53
|
-
});
|
|
54
|
-
import { apps } from '@axium/core';
|
|
55
|
-
import { AuditFilter, severityNames } from '@axium/core/audit';
|
|
56
|
-
import { formatBytes, formatDateRange, formatMs } from '@axium/core/format';
|
|
57
|
-
import { outputDaemonStatus, pluginText } from '@axium/core/node';
|
|
58
|
-
import { _findPlugin, plugins, runIntegrations } from '@axium/core/plugins';
|
|
59
|
-
import { Argument, Option, program } from 'commander';
|
|
2
|
+
import { runIntegrations } from '@axium/core/plugins';
|
|
3
|
+
import { program } from 'commander';
|
|
60
4
|
import * as io from 'ioium/node';
|
|
61
|
-
import {
|
|
62
|
-
import { createWriteStream, readFileSync } from 'node:fs';
|
|
63
|
-
import { access, watch } from 'node:fs/promises';
|
|
64
|
-
import { join, resolve } from 'node:path/posix';
|
|
65
|
-
import { parseArgs, styleText } from 'node:util';
|
|
66
|
-
import { getByString, isJSON, setByString } from 'utilium';
|
|
67
|
-
import { searchForWorkspaceRoot } from 'vite';
|
|
5
|
+
import { parseArgs } from 'node:util';
|
|
68
6
|
import * as z from 'zod';
|
|
69
|
-
import
|
|
70
|
-
import
|
|
71
|
-
import
|
|
72
|
-
import { diffUpdate, lookupUser, cliOptions as opts, rl, rlConfirm, userText } from './cli.js';
|
|
73
|
-
import config, { ConfigFile, configFiles, reloadConfigs, saveConfigTo } from './config.js';
|
|
74
|
-
import { dbInitTables } from './db/cli.js';
|
|
75
|
-
import './db/cli.js';
|
|
76
|
-
import * as db from './db/index.js';
|
|
77
|
-
import { _portActions, _portMethods, dirs, logger, restrictedPorts } from './io.js';
|
|
78
|
-
import { linkRoutes, listRouteLinks, unlinkRoutes, writePluginHooks } from './linking.js';
|
|
79
|
-
import { serve } from './serve.js';
|
|
7
|
+
import './cli/db.js';
|
|
8
|
+
import config, { reloadConfigs } from './config.js';
|
|
9
|
+
import './cli/index.js';
|
|
80
10
|
process.on('SIGHUP', () => {
|
|
81
11
|
io.info('Reloading configuration due to SIGHUP.');
|
|
82
12
|
void reloadConfigs();
|
|
@@ -99,514 +29,6 @@ await config.loadDefaults(safe);
|
|
|
99
29
|
if (configFromCLI)
|
|
100
30
|
await config.load(configFromCLI, { safe });
|
|
101
31
|
await runIntegrations();
|
|
102
|
-
program
|
|
103
|
-
.version($pkg.version)
|
|
104
|
-
.name('axium')
|
|
105
|
-
.description('Axium server CLI')
|
|
106
|
-
.configureHelp({ showGlobalOptions: true })
|
|
107
|
-
.option('--safe', 'do not execute code from plugins', false)
|
|
108
|
-
.option('--debug', 'override debug mode')
|
|
109
|
-
.option('--no-debug', 'override debug mode')
|
|
110
|
-
.option('-c, --config <path>', 'path to the config file')
|
|
111
|
-
.hook('preAction', (_, action) => {
|
|
112
|
-
const opt = action.optsWithGlobals();
|
|
113
|
-
opt.force && io.warn('--force: Protections disabled.');
|
|
114
|
-
if (typeof opt.debug == 'boolean') {
|
|
115
|
-
config.set({ debug: opt.debug });
|
|
116
|
-
io._setDebugOutput(opt.debug);
|
|
117
|
-
}
|
|
118
|
-
try {
|
|
119
|
-
db.connect();
|
|
120
|
-
}
|
|
121
|
-
catch (e) {
|
|
122
|
-
if (!noAutoDB.includes(action.name()))
|
|
123
|
-
throw e;
|
|
124
|
-
}
|
|
125
|
-
})
|
|
126
|
-
.hook('postAction', async (_, action) => {
|
|
127
|
-
if (!noAutoDB.includes(action.name()))
|
|
128
|
-
await db.database.destroy();
|
|
129
|
-
})
|
|
130
|
-
.on('option:debug', () => config.set({ debug: true }));
|
|
131
|
-
const noAutoDB = ['init', 'serve', 'check'];
|
|
132
|
-
const axiumConfig = program
|
|
133
|
-
.command('config')
|
|
134
|
-
.description('Manage the configuration')
|
|
135
|
-
.addOption(opts.global)
|
|
136
|
-
.option('-j, --json', 'values are JSON encoded', false)
|
|
137
|
-
.option('-r, --redact', 'Do not output sensitive values', false);
|
|
138
|
-
function configReplacer(opt) {
|
|
139
|
-
return (key, value) => {
|
|
140
|
-
return opt.redact && ['password', 'secret'].includes(key) ? '[redacted]' : value;
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
axiumConfig
|
|
144
|
-
.command('dump')
|
|
145
|
-
.description('Output the entire current configuration')
|
|
146
|
-
.action(function axium_config_dump() {
|
|
147
|
-
const opt = this.optsWithGlobals();
|
|
148
|
-
const value = config.plain();
|
|
149
|
-
console.log(opt.json ? JSON.stringify(value, configReplacer(opt), 4) : value);
|
|
150
|
-
});
|
|
151
|
-
axiumConfig
|
|
152
|
-
.command('get')
|
|
153
|
-
.description('Get a config value')
|
|
154
|
-
.argument('<key>', 'the key to get')
|
|
155
|
-
.action(function axium_config_get(key) {
|
|
156
|
-
const opt = this.optsWithGlobals();
|
|
157
|
-
const value = getByString(config.plain(), key);
|
|
158
|
-
console.log(opt.json ? JSON.stringify(value, configReplacer(opt), 4) : value);
|
|
159
|
-
});
|
|
160
|
-
axiumConfig
|
|
161
|
-
.command('set')
|
|
162
|
-
.description('Set a config value. Note setting objects is not supported.')
|
|
163
|
-
.argument('<key>', 'the key to set')
|
|
164
|
-
.argument('<value>', 'the value')
|
|
165
|
-
.action(function axium_config_set(key, value) {
|
|
166
|
-
const opt = this.optsWithGlobals();
|
|
167
|
-
if (opt.json && !isJSON(value))
|
|
168
|
-
io.exit('Invalid JSON');
|
|
169
|
-
const obj = {};
|
|
170
|
-
setByString(obj, key, opt.json ? JSON.parse(value) : value);
|
|
171
|
-
config.save(obj, opt.global);
|
|
172
|
-
});
|
|
173
|
-
axiumConfig
|
|
174
|
-
.command('list')
|
|
175
|
-
.alias('ls')
|
|
176
|
-
.alias('files')
|
|
177
|
-
.description('List loaded config files')
|
|
178
|
-
.action(() => {
|
|
179
|
-
for (const path of config.files.keys())
|
|
180
|
-
console.log(path);
|
|
181
|
-
});
|
|
182
|
-
axiumConfig
|
|
183
|
-
.command('schema')
|
|
184
|
-
.description('Get the JSON schema for the configuration file')
|
|
185
|
-
.action(() => {
|
|
186
|
-
const opt = axiumConfig.optsWithGlobals();
|
|
187
|
-
try {
|
|
188
|
-
const schema = z.toJSONSchema(ConfigFile, { io: 'input' });
|
|
189
|
-
console.log(opt.json ? JSON.stringify(schema, configReplacer(opt), 4) : schema);
|
|
190
|
-
}
|
|
191
|
-
catch (e) {
|
|
192
|
-
io.exit(e);
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
const axiumPlugin = program.command('plugin').alias('plugins').description('Manage plugins').addOption(opts.global);
|
|
196
|
-
axiumPlugin
|
|
197
|
-
.command('list')
|
|
198
|
-
.alias('ls')
|
|
199
|
-
.description('List loaded plugins')
|
|
200
|
-
.option('-l, --long', 'use the long listing format')
|
|
201
|
-
.option('--no-versions', 'do not show plugin versions')
|
|
202
|
-
.action(opt => {
|
|
203
|
-
if (!plugins.size) {
|
|
204
|
-
console.log('No plugins loaded.');
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
if (!opt.long) {
|
|
208
|
-
console.log(Array.from(plugins.keys()).join(', '));
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
console.log(styleText('whiteBright', plugins.size + ' plugin(s) loaded:'));
|
|
212
|
-
for (const plugin of plugins.values()) {
|
|
213
|
-
console.log(plugin.name, opt.versions ? plugin.version : '');
|
|
214
|
-
}
|
|
215
|
-
});
|
|
216
|
-
axiumPlugin
|
|
217
|
-
.command('info')
|
|
218
|
-
.description('Get information about a plugin')
|
|
219
|
-
.argument('<plugin>', 'the plugin to get information about')
|
|
220
|
-
.action((search) => {
|
|
221
|
-
const plugin = _findPlugin(search);
|
|
222
|
-
for (const line of pluginText(plugin))
|
|
223
|
-
console.log(line);
|
|
224
|
-
});
|
|
225
|
-
axiumPlugin
|
|
226
|
-
.command('remove')
|
|
227
|
-
.alias('rm')
|
|
228
|
-
.description('Remove a plugin')
|
|
229
|
-
.argument('<plugin>', 'the plugin to remove')
|
|
230
|
-
.action(async (search, opt) => {
|
|
231
|
-
const plugin = _findPlugin(search);
|
|
232
|
-
await plugin._hooks?.remove?.(opt);
|
|
233
|
-
for (const [path, data] of configFiles) {
|
|
234
|
-
if (!data.plugins)
|
|
235
|
-
continue;
|
|
236
|
-
data.plugins = data.plugins.filter(p => p !== plugin.specifier);
|
|
237
|
-
saveConfigTo(path, data);
|
|
238
|
-
}
|
|
239
|
-
plugins.delete(plugin.name);
|
|
240
|
-
});
|
|
241
|
-
axiumPlugin
|
|
242
|
-
.command('init')
|
|
243
|
-
.alias('setup')
|
|
244
|
-
.alias('install')
|
|
245
|
-
.description('Initialize a plugin. This could include adding tables to the database or linking routes.')
|
|
246
|
-
.addOption(opts.timeout)
|
|
247
|
-
.addOption(opts.check)
|
|
248
|
-
.argument('<plugin>', 'the plugin to initialize')
|
|
249
|
-
.action(async (search) => {
|
|
250
|
-
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
251
|
-
try {
|
|
252
|
-
const plugin = _findPlugin(search);
|
|
253
|
-
if (!plugin)
|
|
254
|
-
io.exit(`Can't find a plugin matching "${search}"`);
|
|
255
|
-
const _ = __addDisposableResource(env_1, db.connect(), true);
|
|
256
|
-
const info = db.getUpgradeInfo();
|
|
257
|
-
const exclude = Object.keys(info.current);
|
|
258
|
-
if (exclude.includes(plugin.name))
|
|
259
|
-
io.exit('Plugin is already initialized (database)');
|
|
260
|
-
const schema = db.schema.getFull({ exclude });
|
|
261
|
-
const delta = db.delta.compute({ tables: {}, indexes: {} }, schema);
|
|
262
|
-
if (db.delta.isEmpty(delta)) {
|
|
263
|
-
io.info('Plugin does not define any database schema.');
|
|
264
|
-
return;
|
|
265
|
-
}
|
|
266
|
-
for (const text of db.delta.display(delta))
|
|
267
|
-
console.log(text);
|
|
268
|
-
await rlConfirm();
|
|
269
|
-
await db.delta.apply(delta);
|
|
270
|
-
Object.assign(info.current, schema.versions);
|
|
271
|
-
db.setUpgradeInfo(info);
|
|
272
|
-
}
|
|
273
|
-
catch (e_1) {
|
|
274
|
-
env_1.error = e_1;
|
|
275
|
-
env_1.hasError = true;
|
|
276
|
-
}
|
|
277
|
-
finally {
|
|
278
|
-
const result_1 = __disposeResources(env_1);
|
|
279
|
-
if (result_1)
|
|
280
|
-
await result_1;
|
|
281
|
-
}
|
|
282
|
-
});
|
|
283
|
-
const axiumApps = program.command('apps').description('Manage Axium apps').addOption(opts.global);
|
|
284
|
-
axiumApps
|
|
285
|
-
.command('list')
|
|
286
|
-
.alias('ls')
|
|
287
|
-
.description('List apps added by plugins')
|
|
288
|
-
.option('-l, --long', 'use the long listing format')
|
|
289
|
-
.option('-b, --builtin', 'include built-in apps')
|
|
290
|
-
.action(opt => {
|
|
291
|
-
if (!apps.size) {
|
|
292
|
-
console.log('No apps.');
|
|
293
|
-
return;
|
|
294
|
-
}
|
|
295
|
-
if (!opt.long) {
|
|
296
|
-
console.log(Array.from(apps.values().map(app => app.name)).join(', '));
|
|
297
|
-
return;
|
|
298
|
-
}
|
|
299
|
-
console.log(styleText('whiteBright', apps.size + ' app(s) loaded:'));
|
|
300
|
-
for (const app of apps.values()) {
|
|
301
|
-
console.log(app.name, styleText('dim', `(${app.id})`));
|
|
302
|
-
}
|
|
303
|
-
});
|
|
304
|
-
const argUserLookup = new Argument('<user>', 'the UUID or email of the user to operate on').argParser(lookupUser);
|
|
305
|
-
program
|
|
306
|
-
.command('user')
|
|
307
|
-
.description('Get or change information about a user')
|
|
308
|
-
.addArgument(argUserLookup)
|
|
309
|
-
.option('-S, --sessions', 'show user sessions')
|
|
310
|
-
.option('-P, --passkeys', 'show user passkeys')
|
|
311
|
-
.option('--add-role <role...>', 'add roles to the user')
|
|
312
|
-
.option('--remove-role <role...>', 'remove roles from the user')
|
|
313
|
-
.option('--tag <tag...>', 'Add tags to the user')
|
|
314
|
-
.option('--untag <tag...>', 'Remove tags from the user')
|
|
315
|
-
.option('--delete', 'Delete the user')
|
|
316
|
-
.option('--suspend', 'Suspend the user')
|
|
317
|
-
.addOption(new Option('--unsuspend', 'Un-suspend the user').conflicts('suspend'))
|
|
318
|
-
.action(async (_user, opt) => {
|
|
319
|
-
let user = await _user;
|
|
320
|
-
const [updatedRoles, roles, rolesDiff] = diffUpdate(user.roles, opt.addRole, opt.removeRole);
|
|
321
|
-
const [updatedTags, tags, tagsDiff] = diffUpdate(user.tags, opt.tag, opt.untag);
|
|
322
|
-
const changeSuspend = (opt.suspend || opt.unsuspend) && user.isSuspended != (opt.suspend ?? !opt.unsuspend);
|
|
323
|
-
if (updatedRoles || updatedTags || changeSuspend) {
|
|
324
|
-
user = await db.database
|
|
325
|
-
.updateTable('users')
|
|
326
|
-
.where('id', '=', user.id)
|
|
327
|
-
.set({ roles, tags, isSuspended: !changeSuspend ? user.isSuspended : (opt.suspend ?? !opt.unsuspend) })
|
|
328
|
-
.returningAll()
|
|
329
|
-
.executeTakeFirstOrThrow()
|
|
330
|
-
.then(u => {
|
|
331
|
-
if (updatedRoles && rolesDiff)
|
|
332
|
-
console.log(`> Updated roles: ${rolesDiff}`);
|
|
333
|
-
if (updatedTags && tagsDiff)
|
|
334
|
-
console.log(`> Updated tags: ${tagsDiff}`);
|
|
335
|
-
if (changeSuspend)
|
|
336
|
-
console.log(opt.suspend ? '> Suspended' : '> Un-suspended');
|
|
337
|
-
return u;
|
|
338
|
-
})
|
|
339
|
-
.catch(e => io.exit('Failed to update user: ' + e.message));
|
|
340
|
-
}
|
|
341
|
-
if (opt.delete) {
|
|
342
|
-
const confirmed = await rl
|
|
343
|
-
.question(`Are you sure you want to delete ${userText(user, true)}? (y/N) `)
|
|
344
|
-
.then(v => z.stringbool().parseAsync(v))
|
|
345
|
-
.catch(() => false);
|
|
346
|
-
if (!confirmed)
|
|
347
|
-
console.log(styleText('dim', '> Delete aborted.'));
|
|
348
|
-
else
|
|
349
|
-
await db.database
|
|
350
|
-
.deleteFrom('users')
|
|
351
|
-
.where('id', '=', user.id)
|
|
352
|
-
.executeTakeFirstOrThrow()
|
|
353
|
-
.then(() => console.log(styleText(['red', 'bold'], '> Deleted')))
|
|
354
|
-
.catch(e => io.exit('Failed to delete user: ' + e.message));
|
|
355
|
-
}
|
|
356
|
-
console.log([
|
|
357
|
-
user.isSuspended && styleText('yellowBright', 'Suspended'),
|
|
358
|
-
user.isAdmin && styleText('redBright', 'Administrator'),
|
|
359
|
-
'UUID: ' + user.id,
|
|
360
|
-
'Name: ' + user.name,
|
|
361
|
-
`Email: ${user.email}, ${user.emailVerified ? 'verified on ' + formatDateRange(user.emailVerified) : styleText(config.auth.email_verification ? 'yellow' : 'dim', 'not verified')}`,
|
|
362
|
-
'Registered ' + formatDateRange(user.registeredAt),
|
|
363
|
-
`Roles: ${user.roles.length ? user.roles.join(', ') : styleText('dim', '(none)')}`,
|
|
364
|
-
`Tags: ${user.tags.length ? user.tags.join(', ') : styleText('dim', '(none)')}`,
|
|
365
|
-
]
|
|
366
|
-
.filter(v => v)
|
|
367
|
-
.join('\n'));
|
|
368
|
-
if (opt.sessions) {
|
|
369
|
-
const sessions = await db.database.selectFrom('sessions').where('userId', '=', user.id).selectAll().execute();
|
|
370
|
-
console.log(styleText('bold', 'Sessions:'));
|
|
371
|
-
if (!sessions.length)
|
|
372
|
-
console.log(styleText('dim', '(none)'));
|
|
373
|
-
else
|
|
374
|
-
for (const session of sessions) {
|
|
375
|
-
console.log(`\t${session.id}\tcreated ${formatDateRange(session.created).padEnd(40)}\texpires ${formatDateRange(session.expires).padEnd(40)}\t${session.elevated ? styleText('yellow', '(elevated)') : ''}`);
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
if (opt.passkeys) {
|
|
379
|
-
const passkeys = await db.database.selectFrom('passkeys').where('userId', '=', user.id).selectAll().execute();
|
|
380
|
-
console.log(styleText('bold', 'Passkeys:'));
|
|
381
|
-
for (const passkey of passkeys) {
|
|
382
|
-
console.log(`\t${passkey.id}: created ${formatDateRange(passkey.createdAt).padEnd(40)} used ${passkey.counter} times. ${passkey.deviceType}, ${passkey.backedUp ? '' : 'not '}backed up; transports are [${passkey.transports.join(', ')}], ${passkey.name ? 'named ' + JSON.stringify(passkey.name) : 'unnamed'}.`);
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
});
|
|
386
|
-
program
|
|
387
|
-
.command('toggle-admin')
|
|
388
|
-
.description('Toggle whether a user is an administrator')
|
|
389
|
-
.addArgument(argUserLookup)
|
|
390
|
-
.action(async (_user) => {
|
|
391
|
-
const user = await _user;
|
|
392
|
-
const isAdmin = !user.isAdmin;
|
|
393
|
-
await db.database.updateTable('users').set({ isAdmin }).where('id', '=', user.id).executeTakeFirstOrThrow();
|
|
394
|
-
await audit('admin_change', undefined, { user: user.id });
|
|
395
|
-
console.log(`${userText(user)} is ${isAdmin ? 'now' : 'no longer'} an administrator. (${styleText(['whiteBright', 'bold'], isAdmin.toString())})`);
|
|
396
|
-
});
|
|
397
|
-
program
|
|
398
|
-
.command('status')
|
|
399
|
-
.alias('stats')
|
|
400
|
-
.description('Get information about the server')
|
|
401
|
-
.action(async () => {
|
|
402
|
-
console.log('Axium Server v' + $pkg.version);
|
|
403
|
-
console.log(styleText('whiteBright', 'Debug mode:'), config.debug ? styleText('yellow', 'enabled') : 'disabled');
|
|
404
|
-
const configFiles = config.files.keys().toArray();
|
|
405
|
-
console.log(styleText('whiteBright', 'Loaded config files:'), styleText(['dim', 'bold'], `(${configFiles.length})`), configFiles.join(', '));
|
|
406
|
-
outputDaemonStatus('axium');
|
|
407
|
-
process.stdout.write(styleText('whiteBright', 'Database: '));
|
|
408
|
-
try {
|
|
409
|
-
console.log(await db.statText());
|
|
410
|
-
}
|
|
411
|
-
catch {
|
|
412
|
-
console.log(styleText('red', 'Unavailable'));
|
|
413
|
-
}
|
|
414
|
-
console.log(styleText('whiteBright', 'Loaded plugins:'), styleText(['dim', 'bold'], `(${plugins.size || 'none'})`), Array.from(plugins.keys()).join(', '));
|
|
415
|
-
for (const plugin of plugins.values()) {
|
|
416
|
-
if (!plugin._hooks?.statusText)
|
|
417
|
-
continue;
|
|
418
|
-
const text = await plugin._hooks?.statusText();
|
|
419
|
-
console.log(styleText('bold', plugin.name), plugin.version + ':', text.includes('\n') ? '\n' + text : text);
|
|
420
|
-
}
|
|
421
|
-
});
|
|
422
|
-
program
|
|
423
|
-
.command('ports')
|
|
424
|
-
.description('Enable or disable use of restricted ports (e.g. 443)')
|
|
425
|
-
.addArgument(new Argument('<action>', 'The action to take').choices(_portActions))
|
|
426
|
-
.addOption(new Option('-m, --method <method>', 'the method to use').choices(_portMethods).default('node-cap'))
|
|
427
|
-
.option('-N, --node <path>', 'the path to the node binary')
|
|
428
|
-
.action(async (action, opt) => {
|
|
429
|
-
await restrictedPorts({ ...opt, action });
|
|
430
|
-
});
|
|
431
|
-
program
|
|
432
|
-
.command('init')
|
|
433
|
-
.description('Install Axium server')
|
|
434
|
-
.addOption(opts.force)
|
|
435
|
-
.addOption(opts.check)
|
|
436
|
-
.option('-s, --skip', 'Skip already initialized steps', false)
|
|
437
|
-
.action(async (opt) => {
|
|
438
|
-
await db.init(opt);
|
|
439
|
-
await dbInitTables();
|
|
440
|
-
await restrictedPorts({ method: 'node-cap', action: 'enable' });
|
|
441
|
-
});
|
|
442
|
-
program
|
|
443
|
-
.command('serve')
|
|
444
|
-
.description('Start the Axium server')
|
|
445
|
-
.option('-p, --port <port>', 'the port to listen on', Number.parseInt, config.web.port)
|
|
446
|
-
.option('--ssl <prefix>', 'the prefix for the cert.pem and key.pem SSL files')
|
|
447
|
-
.option('-b, --build <path>', 'the path to the handler build')
|
|
448
|
-
.action(async (opt) => {
|
|
449
|
-
if (opt.port < 1 || opt.port > 65535)
|
|
450
|
-
io.exit('Invalid port');
|
|
451
|
-
const server = await serve({
|
|
452
|
-
secure: opt.ssl ? true : config.web.secure,
|
|
453
|
-
ssl_cert: opt.ssl ? join(opt.ssl, 'cert.pem') : config.web.ssl_cert,
|
|
454
|
-
ssl_key: opt.ssl ? join(opt.ssl, 'key.pem') : config.web.ssl_key,
|
|
455
|
-
build: opt.build ? resolve(opt.build) : config.web.build,
|
|
456
|
-
});
|
|
457
|
-
logger.attach(createWriteStream(join(dirs.at(-1), 'server.log')), { output: allLogLevels });
|
|
458
|
-
db.connect();
|
|
459
|
-
await db.clean({});
|
|
460
|
-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
461
|
-
process.on('beforeExit', () => db.database.destroy());
|
|
462
|
-
server.listen(opt.port, () => {
|
|
463
|
-
console.log('Server is listening on port ' + opt.port);
|
|
464
|
-
});
|
|
465
|
-
});
|
|
466
|
-
program
|
|
467
|
-
.command('link')
|
|
468
|
-
.description('Link routes provided by plugins and the server')
|
|
469
|
-
.addOption(new Option('-l, --list', 'list route links').conflicts('delete'))
|
|
470
|
-
.option('-d, --delete', 'delete route links')
|
|
471
|
-
.argument('[name...]', 'List of plugin names to operate on. If not specified, operates on all plugins and built-in routes.')
|
|
472
|
-
.action(async function axium_link(names) {
|
|
473
|
-
const opt = this.optsWithGlobals();
|
|
474
|
-
const linkOpts = { only: names };
|
|
475
|
-
if (opt.list) {
|
|
476
|
-
for (const link of listRouteLinks(linkOpts)) {
|
|
477
|
-
const idText = link.id.startsWith('#') ? `(${link.id.slice(1)})` : link.id;
|
|
478
|
-
const fromColor = await access(link.from)
|
|
479
|
-
.then(() => 'cyanBright')
|
|
480
|
-
.catch(() => 'redBright');
|
|
481
|
-
console.log(`${idText}:\t ${styleText(fromColor, link.from)}\t->\t${link.to.replace(/.*\/node_modules\//, styleText('dim', '$&'))}`);
|
|
482
|
-
}
|
|
483
|
-
return;
|
|
484
|
-
}
|
|
485
|
-
if (opt.delete) {
|
|
486
|
-
unlinkRoutes(linkOpts);
|
|
487
|
-
return;
|
|
488
|
-
}
|
|
489
|
-
io.start('Linking routes');
|
|
490
|
-
linkRoutes(linkOpts);
|
|
491
|
-
io.done();
|
|
492
|
-
io.start('Writing web client hooks for plugins');
|
|
493
|
-
writePluginHooks();
|
|
494
|
-
io.done();
|
|
495
|
-
});
|
|
496
|
-
program
|
|
497
|
-
.command('audit')
|
|
498
|
-
.description('View audit logs')
|
|
499
|
-
.option('-x, --extra', 'Include the extra object when listing events')
|
|
500
|
-
.option('-t, --include-tags', 'Include tags when listing events')
|
|
501
|
-
.addOption(new Option('-s, --summary', 'Summarize audit log entries instead of displaying individual ones').conflicts(['extra', 'includeTags']))
|
|
502
|
-
.optionsGroup('Filters:')
|
|
503
|
-
.option('--since <date>', 'Filter for events since a date')
|
|
504
|
-
.option('--until <date>', 'Filter for events until a date')
|
|
505
|
-
.option('--user <uuid|null>', 'Filter for events triggered by a user')
|
|
506
|
-
.addOption(new Option('--severity <level>', 'Filter for events at or above a severity level').choices(severityNames))
|
|
507
|
-
.option('--source <source>', 'Filter by source')
|
|
508
|
-
.option('--tag <tag...>', 'Filter by tag(s)')
|
|
509
|
-
.option('--event <event>', 'Filter by event name')
|
|
510
|
-
.action(async (opt) => {
|
|
511
|
-
const filter = await AuditFilter.parseAsync(opt).catch(e => io.exit('Invalid filter: ' + z.prettifyError(e)));
|
|
512
|
-
const events = await getEvents(filter).execute();
|
|
513
|
-
if (opt.summary) {
|
|
514
|
-
const groups = Object.groupBy(events, e => e.severity);
|
|
515
|
-
const maxGroupLength = Math.max(...Object.values(groups).map(g => g.length.toString().length), 0);
|
|
516
|
-
for (const [severity, group] of Object.entries(groups)) {
|
|
517
|
-
if (!group?.length)
|
|
518
|
-
continue;
|
|
519
|
-
console.log(styleText('white', group.length.toString().padStart(maxGroupLength)), styleSeverity(severity, true), 'events. Latest occurred', group.at(-1).timestamp.toLocaleString());
|
|
520
|
-
}
|
|
521
|
-
return;
|
|
522
|
-
}
|
|
523
|
-
let maxSource = 0, maxName = 0, maxTags = 0, maxExtra = 0;
|
|
524
|
-
for (const event of events) {
|
|
525
|
-
maxSource = Math.max(maxSource, event.source.length);
|
|
526
|
-
maxName = Math.max(maxName, event.name.length);
|
|
527
|
-
event._tags = !event.tags.length
|
|
528
|
-
? ''
|
|
529
|
-
: opt.includeTags
|
|
530
|
-
? '# ' + event.tags.join(', ')
|
|
531
|
-
: `(${event.tags.length} tag${event.tags.length == 1 ? '' : 's'})`;
|
|
532
|
-
maxTags = Math.max(maxTags, event._tags.length);
|
|
533
|
-
const extraKeys = Object.keys(event.extra);
|
|
534
|
-
event._extra = !extraKeys.length ? '' : opt.extra ? JSON.stringify(event.extra) : '+' + extraKeys.length;
|
|
535
|
-
maxExtra = Math.max(maxExtra, event._extra.length);
|
|
536
|
-
}
|
|
537
|
-
for (const event of events) {
|
|
538
|
-
console.log(styleSeverity(event.severity, true), styleText('dim', io.prettyDate(event.timestamp)), event.source.padEnd(maxSource), styleText('whiteBright', event.name.padEnd(maxName)), styleText('gray', event._tags.padEnd(maxTags)), 'by', event.userId ? event.userId : styleText(['dim', 'italic'], 'unknown'.padEnd(36)), styleText('blue', event._extra));
|
|
539
|
-
}
|
|
540
|
-
});
|
|
541
|
-
program
|
|
542
|
-
.command('build')
|
|
543
|
-
.description('Create the Vite build for the server')
|
|
544
|
-
.option('--show-garbage-output', 'Show all output from the build process')
|
|
545
|
-
.option('-s, --diagnostics', 'Show build time and bundle size')
|
|
546
|
-
.option('-m, --no-minify', 'Whether to use minification')
|
|
547
|
-
.action(async (options) => {
|
|
548
|
-
io.start('Building');
|
|
549
|
-
const { time, size } = await build(options);
|
|
550
|
-
io.done();
|
|
551
|
-
if (options.diagnostics) {
|
|
552
|
-
console.log('Took', styleText('blueBright', formatMs(time)), 'with a bundle size of', styleText('blueBright', formatBytes(size)));
|
|
553
|
-
}
|
|
554
|
-
});
|
|
555
|
-
program
|
|
556
|
-
.command('develop')
|
|
557
|
-
.alias('dev')
|
|
558
|
-
.description('Develop with axium')
|
|
559
|
-
.argument('[dir]', 'The project directory', searchForWorkspaceRoot(process.cwd()))
|
|
560
|
-
.option('-g, --git', 'Use .gitignore to ignore files (can improve performance)')
|
|
561
|
-
.action(async (dir, opts) => {
|
|
562
|
-
let buildId = 0, server;
|
|
563
|
-
logger.attach(createWriteStream(join(dirs.at(-1), 'server.log')), { output: allLogLevels });
|
|
564
|
-
db.connect();
|
|
565
|
-
await db.clean({});
|
|
566
|
-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
567
|
-
process.on('beforeExit', () => db.database.destroy());
|
|
568
|
-
async function rebuild() {
|
|
569
|
-
server?.close();
|
|
570
|
-
process.stdout.clearLine(0);
|
|
571
|
-
process.stdout.cursorTo(0);
|
|
572
|
-
io.start('Building');
|
|
573
|
-
const { time } = await build({ minify: false });
|
|
574
|
-
buildId++;
|
|
575
|
-
process.stdout.clearLine(0);
|
|
576
|
-
process.stdout.cursorTo(0);
|
|
577
|
-
server = await serve(config.web);
|
|
578
|
-
server.listen(config.web.port);
|
|
579
|
-
process.stdout.write(`Build #${buildId} finished in ${formatMs(time)}`);
|
|
580
|
-
}
|
|
581
|
-
const ignore = ['node_modules', '.git'];
|
|
582
|
-
try {
|
|
583
|
-
if (!opts.git)
|
|
584
|
-
throw null;
|
|
585
|
-
const gitignore = readFileSync(join(dir, '.gitignore'), 'utf8');
|
|
586
|
-
for (const rawLine of gitignore.split('\n')) {
|
|
587
|
-
const line = rawLine.trim();
|
|
588
|
-
if (!line || line[0] == '#')
|
|
589
|
-
continue;
|
|
590
|
-
ignore.push(line);
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
catch {
|
|
594
|
-
// It's fine if we don't have a .gitignore
|
|
595
|
-
}
|
|
596
|
-
io.debug('Watching', dir);
|
|
597
|
-
await rebuild();
|
|
598
|
-
try {
|
|
599
|
-
for await (const _event of watch(dir, { recursive: true, ignore })) {
|
|
600
|
-
// @todo see if we can be more efficient based on event data
|
|
601
|
-
await rebuild();
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
catch (err) {
|
|
605
|
-
if (err.name === 'AbortError')
|
|
606
|
-
return;
|
|
607
|
-
throw err;
|
|
608
|
-
}
|
|
609
|
-
});
|
|
610
32
|
try {
|
|
611
33
|
await program.parseAsync();
|
|
612
34
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axium/server",
|
|
3
|
-
"version": "0.44.
|
|
3
|
+
"version": "0.44.2",
|
|
4
4
|
"author": "James Prevett <axium@jamespre.dev>",
|
|
5
5
|
"funding": {
|
|
6
6
|
"type": "individual",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"types": "dist/index.d.ts",
|
|
21
21
|
"exports": {
|
|
22
22
|
".": "./dist/index.js",
|
|
23
|
+
"./cli": "./dist/cli/index.js",
|
|
23
24
|
"./database": "./dist/db/index.js",
|
|
24
25
|
"./*": "./dist/*.js",
|
|
25
26
|
"./$hooks": "./web/hooks.server.ts",
|
|
@@ -43,11 +44,11 @@
|
|
|
43
44
|
"build": "tsc",
|
|
44
45
|
"build:schemas": "mkdir -p schemas && node dist/main.js config schema -j > schemas/config.json && node dist/main.js db json-schema -j > schemas/db.json",
|
|
45
46
|
"clean": "rm -rf build .svelte-kit node_modules/{.vite,.vite-temp}",
|
|
46
|
-
"postinstall": "patch
|
|
47
|
+
"postinstall": "node patches/patch.js"
|
|
47
48
|
},
|
|
48
49
|
"peerDependencies": {
|
|
49
50
|
"@axium/client": ">=0.21.0",
|
|
50
|
-
"@axium/core": ">=0.
|
|
51
|
+
"@axium/core": ">=0.28.0",
|
|
51
52
|
"@simplewebauthn/browser": "^13.3.0",
|
|
52
53
|
"@sveltejs/adapter-node": "^5.2.12",
|
|
53
54
|
"@sveltejs/kit": "2.56.1",
|
package/patches/patch.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { relative, join } from 'node:path';
|
|
2
|
+
import { execFileSync } from 'node:child_process';
|
|
3
|
+
|
|
4
|
+
// If this package is installed as a dependency (inside node_modules),
|
|
5
|
+
// we want to run patch-package from the consumer's root directory (INIT_CWD).
|
|
6
|
+
const cwd = process.cwd();
|
|
7
|
+
const init = cwd.includes('node_modules') ? process.env.INIT_CWD || cwd : cwd;
|
|
8
|
+
|
|
9
|
+
const patchesRelativePath = relative(init, join(cwd, 'patches'));
|
|
10
|
+
|
|
11
|
+
const npx = process.platform === 'win32' ? 'npx.cmd' : 'npx';
|
|
12
|
+
execFileSync(npx, ['patch-package', '--patch-dir', patchesRelativePath], { cwd: init, stdio: 'inherit' });
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { text } from '@axium/client';
|
|
3
3
|
import { Version } from '@axium/client/components';
|
|
4
4
|
import { Severity } from '@axium/core';
|
|
5
|
-
import {
|
|
5
|
+
import { fetchPackageMetadata } from '@axium/core/packages';
|
|
6
6
|
import { _throw, capitalize } from 'utilium';
|
|
7
7
|
|
|
8
8
|
const { data } = $props();
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
{#each packages as name}
|
|
19
19
|
<p>
|
|
20
20
|
Axium {capitalize(name)}
|
|
21
|
-
<Version v={data.versions[name]} latest={
|
|
21
|
+
<Version v={data.versions[name]} latest={fetchPackageMetadata('@axium/' + name).then(pkg => pkg?._latest || _throw(null))} />
|
|
22
22
|
</p>
|
|
23
23
|
{/each}
|
|
24
24
|
|