@axium/server 0.39.1 → 0.39.3

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/config.js CHANGED
@@ -98,7 +98,7 @@ export const defaultConfig = {
98
98
  audit: {
99
99
  allow_raw: false,
100
100
  retention: 30,
101
- min_severity: 'error',
101
+ min_severity: 'notice',
102
102
  auto_suspend: 'critical',
103
103
  },
104
104
  auth: {
package/dist/linking.js CHANGED
@@ -54,6 +54,14 @@ export function linkRoutes(options = {}) {
54
54
  }
55
55
  }
56
56
  }
57
+ const hooksBuiltin = `
58
+ import { errorText } from '@axium/core/io';
59
+
60
+ export function handleError({ error, status }) {
61
+ console.error(error);
62
+ return { message: errorText(error), stack: error.stack, status: error.status || status };
63
+ }
64
+ `;
57
65
  export function writePluginHooks() {
58
66
  const hooksPath = join(import.meta.dirname, '../.hooks.js');
59
67
  io.start('Writing web client hooks for plugins');
@@ -64,6 +72,7 @@ export function writePluginHooks() {
64
72
  const specifier = relative(resolve(import.meta.dirname, '..'), resolve(plugin.dirname, plugin.server.web_client_hooks));
65
73
  hooks += `import '${specifier}';\n`;
66
74
  }
75
+ hooks += hooksBuiltin;
67
76
  writeFileSync(hooksPath, hooks, 'utf8');
68
77
  io.done();
69
78
  io.debug('Wrote', hooksPath);
package/dist/requests.js CHANGED
@@ -46,7 +46,14 @@ export async function parseBody(request, schema) {
46
46
  }
47
47
  export function parseSearch(request, schema) {
48
48
  const url = new URL(request.url);
49
- const searchParams = Object.fromEntries(url.searchParams.entries());
49
+ const searchParams = Object.fromEntries(url.searchParams.entries().map(([k, v]) => {
50
+ try {
51
+ return [k, JSON.parse(v)];
52
+ }
53
+ catch {
54
+ error(400, 'Invalid query parameter: ' + k);
55
+ }
56
+ }));
50
57
  try {
51
58
  return schema.parse(searchParams);
52
59
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axium/server",
3
- "version": "0.39.1",
3
+ "version": "0.39.3",
4
4
  "author": "James Prevett <axium@jamespre.dev>",
5
5
  "funding": {
6
6
  "type": "individual",
@@ -47,7 +47,7 @@
47
47
  "clean": "rm -rf build .svelte-kit node_modules/{.vite,.vite-temp}"
48
48
  },
49
49
  "peerDependencies": {
50
- "@axium/client": ">=0.17.0",
50
+ "@axium/client": ">=0.18.3",
51
51
  "@axium/core": ">=0.21.0",
52
52
  "kysely": "^0.28.0",
53
53
  "utilium": "^2.6.0",
@@ -1,9 +1,8 @@
1
1
  <script lang="ts">
2
- import { text } from '@axium/client';
2
+ import { deleteUser, fetchAPI, text } from '@axium/client';
3
3
  import { ClipboardCopy, FormDialog, Icon, SessionList, ZodForm, ZodInput } from '@axium/client/components';
4
- import { fetchAPI } from '@axium/client/requests';
4
+ import { toast } from '@axium/client/toast';
5
5
  import '@axium/client/styles/account';
6
- import { deleteUser } from '@axium/client/user';
7
6
  import { preferenceLabels, Preferences, User } from '@axium/core';
8
7
  import { formatDateRange } from '@axium/core/format';
9
8
 
@@ -14,8 +13,13 @@
14
13
  let sessions = $state(user.sessions);
15
14
 
16
15
  async function updateValue(val: User) {
17
- const result = await fetchAPI('PATCH', 'admin/users', val);
18
- Object.assign(user, result);
16
+ try {
17
+ const result = await fetchAPI('PATCH', 'admin/users', val);
18
+ Object.assign(user, result);
19
+ toast('success', text('page.admin.toast.user_updated'));
20
+ } catch (e) {
21
+ toast('error', e);
22
+ }
19
23
  }
20
24
  </script>
21
25
 
@@ -78,8 +82,13 @@
78
82
  {/if}
79
83
  <button
80
84
  onclick={async () => {
81
- const { isSuspended } = await fetchAPI('PATCH', 'admin/users', { isSuspended: !user.isSuspended, id: user.id });
82
- user.isSuspended = isSuspended;
85
+ try {
86
+ const { isSuspended } = await fetchAPI('PATCH', 'admin/users', { isSuspended: !user.isSuspended, id: user.id });
87
+ user.isSuspended = isSuspended;
88
+ await toast('success', text(`page.admin.toast.${isSuspended ? 'suspended' : 'unsuspended'}`));
89
+ } catch (e) {
90
+ await toast('error', e);
91
+ }
83
92
  }}>{user.isSuspended ? text('page.admin.users.unsuspend') : text('page.admin.users.suspend')}</button
84
93
  >
85
94
  </div>
package/template.html CHANGED
@@ -11,7 +11,7 @@
11
11
  </head>
12
12
 
13
13
  <body>
14
- <div style="display: contents">%sveltekit.body%</div>
14
+ %sveltekit.body%
15
15
  <div id="toasts"></div>
16
16
  </body>
17
17
  </html>