@axium/server 0.33.0 → 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/config.d.ts +2 -2
- package/dist/config.js +1 -1
- package/dist/database.d.ts +4 -4
- package/dist/database.js +2 -2
- 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/schemas/config.json +3 -1
- package/schemas/db.json +3 -2
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/config.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export declare const Config: z.ZodObject<{
|
|
|
21
21
|
}, z.core.$loose>>;
|
|
22
22
|
db: z.ZodOptional<z.ZodObject<{
|
|
23
23
|
host: z.ZodOptional<z.ZodString>;
|
|
24
|
-
port: z.ZodOptional<z.
|
|
24
|
+
port: z.ZodOptional<z.ZodInt>;
|
|
25
25
|
password: z.ZodOptional<z.ZodString>;
|
|
26
26
|
user: z.ZodOptional<z.ZodString>;
|
|
27
27
|
database: z.ZodOptional<z.ZodString>;
|
|
@@ -97,7 +97,7 @@ export declare const ConfigFile: z.ZodObject<{
|
|
|
97
97
|
}, z.core.$loose>>>;
|
|
98
98
|
db: z.ZodOptional<z.ZodOptional<z.ZodObject<{
|
|
99
99
|
host: z.ZodOptional<z.ZodString>;
|
|
100
|
-
port: z.ZodOptional<z.
|
|
100
|
+
port: z.ZodOptional<z.ZodInt>;
|
|
101
101
|
password: z.ZodOptional<z.ZodString>;
|
|
102
102
|
user: z.ZodOptional<z.ZodString>;
|
|
103
103
|
database: z.ZodOptional<z.ZodString>;
|
package/dist/config.js
CHANGED
package/dist/database.d.ts
CHANGED
|
@@ -439,7 +439,7 @@ export declare const SchemaFile: z.ZodObject<{
|
|
|
439
439
|
drop_indexes: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodTemplateLiteral<`${string}:${string}`>>>>;
|
|
440
440
|
}, z.core.$strict>], "delta">>;
|
|
441
441
|
wipe: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString>>>;
|
|
442
|
-
latest: z.ZodOptional<z.
|
|
442
|
+
latest: z.ZodOptional<z.ZodInt32>;
|
|
443
443
|
acl_tables: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>>;
|
|
444
444
|
}, z.core.$strip>;
|
|
445
445
|
export interface SchemaFile extends z.infer<typeof SchemaFile> {
|
|
@@ -555,11 +555,11 @@ export declare function getFullSchema(opt?: {
|
|
|
555
555
|
versions: Record<string, number>;
|
|
556
556
|
};
|
|
557
557
|
export declare const UpgradesInfo: z.ZodObject<{
|
|
558
|
-
current: z.ZodDefault<z.ZodRecord<z.ZodString, z.
|
|
558
|
+
current: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodInt32>>;
|
|
559
559
|
upgrades: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
560
560
|
timestamp: z.ZodCoercedDate<unknown>;
|
|
561
|
-
from: z.ZodRecord<z.ZodString, z.
|
|
562
|
-
to: z.ZodRecord<z.ZodString, z.
|
|
561
|
+
from: z.ZodRecord<z.ZodString, z.ZodInt32>;
|
|
562
|
+
to: z.ZodRecord<z.ZodString, z.ZodInt32>;
|
|
563
563
|
}, z.core.$strip>>>;
|
|
564
564
|
}, z.core.$strip>;
|
|
565
565
|
export interface UpgradesInfo extends z.infer<typeof UpgradesInfo> {
|
package/dist/database.js
CHANGED
|
@@ -352,7 +352,7 @@ export const SchemaFile = z.object({
|
|
|
352
352
|
/** List of tables to wipe */
|
|
353
353
|
wipe: z.string().array().optional().default([]),
|
|
354
354
|
/** Set the latest version, defaults to the last one */
|
|
355
|
-
latest: z.
|
|
355
|
+
latest: z.int32().nonnegative().optional(),
|
|
356
356
|
/** Maps tables to their ACL tables, e.g. `"storage": "acl.storage"` */
|
|
357
357
|
acl_tables: z.record(z.string(), z.string()).optional().default({}),
|
|
358
358
|
});
|
|
@@ -416,7 +416,7 @@ const schemaToIntrospected = {
|
|
|
416
416
|
integer: 'int4',
|
|
417
417
|
'text[]': '_text',
|
|
418
418
|
};
|
|
419
|
-
const VersionMap = z.record(z.string(), z.
|
|
419
|
+
const VersionMap = z.record(z.string(), z.int32().nonnegative());
|
|
420
420
|
export const UpgradesInfo = z.object({
|
|
421
421
|
current: VersionMap.default({}),
|
|
422
422
|
upgrades: z.object({ timestamp: z.coerce.date(), from: VersionMap, to: VersionMap }).array().default([]),
|
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, { configFiles,
|
|
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">
|
package/schemas/config.json
CHANGED