@axium/server 0.33.1 → 0.33.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/api/admin.js +8 -1
- package/dist/main.js +14 -2
- package/dist/serve.js +3 -18
- package/package.json +1 -1
- package/routes/admin/users/[id]/+page.svelte +17 -6
package/dist/api/admin.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AuditFilter, Severity } from '@axium/core';
|
|
1
|
+
import { AuditFilter, Severity, UserAdminChange } from '@axium/core';
|
|
2
2
|
import { errorText, writeJSON } from '@axium/core/node/io';
|
|
3
3
|
import { getVersionInfo } from '@axium/core/node/packages';
|
|
4
4
|
import { _findPlugin, plugins, PluginUpdate, serverConfigs } from '@axium/core/plugins';
|
|
@@ -87,6 +87,13 @@ addRoute({
|
|
|
87
87
|
const users = await db.selectFrom('users').selectAll().execute();
|
|
88
88
|
return users;
|
|
89
89
|
},
|
|
90
|
+
async PATCH(req) {
|
|
91
|
+
await assertAdmin(this, req);
|
|
92
|
+
const userChange = await parseBody(req, UserAdminChange);
|
|
93
|
+
const userId = userChange.id;
|
|
94
|
+
delete userChange.id;
|
|
95
|
+
return await db.updateTable('users').set(userChange).where('id', '=', userId).returningAll().executeTakeFirstOrThrow();
|
|
96
|
+
},
|
|
90
97
|
async PUT(req) {
|
|
91
98
|
await assertAdmin(this, req);
|
|
92
99
|
const { name, email } = await parseBody(req, z.object({ name: z.string(), email: z.email() }));
|
package/dist/main.js
CHANGED
|
@@ -57,6 +57,8 @@ import { formatDateRange } from '@axium/core/format';
|
|
|
57
57
|
import { io, outputDaemonStatus, pluginText } from '@axium/core/node';
|
|
58
58
|
import { _findPlugin, plugins, runIntegrations } from '@axium/core/plugins';
|
|
59
59
|
import { Argument, Option, program } from 'commander';
|
|
60
|
+
import { allLogLevels } from 'logzen';
|
|
61
|
+
import { createWriteStream } from 'node:fs';
|
|
60
62
|
import { access } from 'node:fs/promises';
|
|
61
63
|
import { join, resolve } from 'node:path/posix';
|
|
62
64
|
import { createInterface } from 'node:readline/promises';
|
|
@@ -66,9 +68,9 @@ import * as z from 'zod';
|
|
|
66
68
|
import $pkg from '../package.json' with { type: 'json' };
|
|
67
69
|
import { audit, getEvents, styleSeverity } from './audit.js';
|
|
68
70
|
import { diffUpdate, lookupUser, userText } from './cli.js';
|
|
69
|
-
import config, { ConfigFile, configFiles, saveConfigTo } from './config.js';
|
|
71
|
+
import config, { ConfigFile, configFiles, reloadConfigs, saveConfigTo } from './config.js';
|
|
70
72
|
import * as db from './database.js';
|
|
71
|
-
import { _portActions, _portMethods, restrictedPorts } from './io.js';
|
|
73
|
+
import { _portActions, _portMethods, dirs, logger, restrictedPorts } from './io.js';
|
|
72
74
|
import { linkRoutes, listRouteLinks, unlinkRoutes, writePluginHooks } from './linking.js';
|
|
73
75
|
import { serve } from './serve.js';
|
|
74
76
|
async function rlConfirm(question = 'Is this ok') {
|
|
@@ -104,6 +106,10 @@ try {
|
|
|
104
106
|
input: process.stdin,
|
|
105
107
|
output: process.stdout,
|
|
106
108
|
}), false);
|
|
109
|
+
process.on('SIGHUP', () => {
|
|
110
|
+
io.info('Reloading configuration due to SIGHUP.');
|
|
111
|
+
void reloadConfigs();
|
|
112
|
+
});
|
|
107
113
|
// Need these before Command is set up (e.g. for CLI integrations)
|
|
108
114
|
({
|
|
109
115
|
safe,
|
|
@@ -626,6 +632,7 @@ try {
|
|
|
626
632
|
if (updatedRoles || updatedTags || changeSuspend) {
|
|
627
633
|
user = await db.database
|
|
628
634
|
.updateTable('users')
|
|
635
|
+
.where('id', '=', user.id)
|
|
629
636
|
.set({ roles, tags, isSuspended: !changeSuspend ? user.isSuspended : (opt.suspend ?? !opt.unsuspend) })
|
|
630
637
|
.returningAll()
|
|
631
638
|
.executeTakeFirstOrThrow()
|
|
@@ -757,6 +764,11 @@ try {
|
|
|
757
764
|
ssl_key: opt.ssl ? join(opt.ssl, 'key.pem') : config.web.ssl_key,
|
|
758
765
|
build: opt.build ? resolve(opt.build) : config.web.build,
|
|
759
766
|
});
|
|
767
|
+
logger.attach(createWriteStream(join(dirs.at(-1), 'server.log')), { output: allLogLevels });
|
|
768
|
+
db.connect();
|
|
769
|
+
await db.clean({});
|
|
770
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
771
|
+
process.on('beforeExit', () => db.database.destroy());
|
|
760
772
|
server.listen(opt.port, () => {
|
|
761
773
|
console.log('Server is listening on port ' + opt.port);
|
|
762
774
|
});
|
package/dist/serve.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import { apps } from '@axium/core';
|
|
2
|
-
import { _debugOutput, debug, warn
|
|
2
|
+
import { _debugOutput, debug, warn } from '@axium/core/node/io';
|
|
3
3
|
import { plugins } from '@axium/core/plugins';
|
|
4
4
|
import '@axium/server/api/index';
|
|
5
|
-
import {
|
|
6
|
-
import { clean, connect, database } from '@axium/server/database';
|
|
7
|
-
import { dirs, logger } from '@axium/server/io';
|
|
8
|
-
import { allLogLevels } from 'logzen';
|
|
9
|
-
import { createWriteStream, readFileSync } from 'node:fs';
|
|
5
|
+
import { readFileSync } from 'node:fs';
|
|
10
6
|
import { createServer, ServerResponse } from 'node:http';
|
|
11
7
|
import { createServer as createSecureServer } from 'node:https';
|
|
12
8
|
import { join } from 'node:path/posix';
|
|
@@ -175,15 +171,4 @@ export async function serve(opt) {
|
|
|
175
171
|
/**
|
|
176
172
|
* Perform initial setup for when the server is serving web pages.
|
|
177
173
|
*/
|
|
178
|
-
export async function init() {
|
|
179
|
-
logger.attach(createWriteStream(join(dirs.at(-1), 'server.log')), { output: allLogLevels });
|
|
180
|
-
await loadDefaultConfigs();
|
|
181
|
-
connect();
|
|
182
|
-
await clean({});
|
|
183
|
-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
184
|
-
process.on('beforeExit', () => database.destroy());
|
|
185
|
-
process.on('SIGHUP', () => {
|
|
186
|
-
info('Reloading configuration due to SIGHUP.');
|
|
187
|
-
void reloadConfigs();
|
|
188
|
-
});
|
|
189
|
-
}
|
|
174
|
+
export async function init() { }
|
package/package.json
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { ClipboardCopy, FormDialog, Icon, SessionList, ZodForm } from '@axium/client/components';
|
|
2
|
+
import { ClipboardCopy, FormDialog, Icon, SessionList, ZodForm, ZodInput } from '@axium/client/components';
|
|
3
3
|
import { fetchAPI } from '@axium/client/requests';
|
|
4
4
|
import '@axium/client/styles/account';
|
|
5
5
|
import { deleteUser } from '@axium/client/user';
|
|
6
|
-
import { preferenceLabels, Preferences } from '@axium/core';
|
|
6
|
+
import { preferenceLabels, Preferences, User } from '@axium/core';
|
|
7
7
|
import { formatDateRange } from '@axium/core/format';
|
|
8
8
|
|
|
9
9
|
const { data } = $props();
|
|
10
|
-
|
|
10
|
+
let user = $state(data.user);
|
|
11
|
+
const { session } = data;
|
|
11
12
|
|
|
12
13
|
let sessions = $state(user.sessions);
|
|
14
|
+
|
|
15
|
+
async function updateValue(val: User) {
|
|
16
|
+
const result = await fetchAPI('PATCH', 'admin/users', val);
|
|
17
|
+
Object.assign(user, result);
|
|
18
|
+
}
|
|
13
19
|
</script>
|
|
14
20
|
|
|
15
21
|
<svelte:head>
|
|
@@ -68,7 +74,12 @@
|
|
|
68
74
|
{:else}
|
|
69
75
|
<p>No</p>
|
|
70
76
|
{/if}
|
|
71
|
-
<button
|
|
77
|
+
<button
|
|
78
|
+
onclick={async () => {
|
|
79
|
+
const { isSuspended } = await fetchAPI('PATCH', 'admin/users', { isSuspended: !user.isSuspended, id: user.id });
|
|
80
|
+
user.isSuspended = isSuspended;
|
|
81
|
+
}}>{user.isSuspended ? 'Unsuspend' : 'Suspend'}</button
|
|
82
|
+
>
|
|
72
83
|
</div>
|
|
73
84
|
<div class="item info">
|
|
74
85
|
<p>Profile Image</p>
|
|
@@ -82,11 +93,11 @@
|
|
|
82
93
|
</div>
|
|
83
94
|
<div class="item info">
|
|
84
95
|
<p>Roles</p>
|
|
85
|
-
<
|
|
96
|
+
<ZodInput bind:rootValue={user} path="roles" schema={User.shape.roles} {updateValue} noLabel />
|
|
86
97
|
</div>
|
|
87
98
|
<div class="item info">
|
|
88
99
|
<p>Tags</p>
|
|
89
|
-
<
|
|
100
|
+
<ZodInput bind:rootValue={user} path="tags" schema={User.shape.tags} {updateValue} noLabel />
|
|
90
101
|
</div>
|
|
91
102
|
|
|
92
103
|
<button class="inline-button icon-text danger" command="show-modal" commandfor="delete-user">
|