@axium/server 0.34.0 → 0.34.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/README.md CHANGED
@@ -1 +1,9 @@
1
1
  # Axium Server
2
+
3
+ Axium Server is the main server application and framework for Axium.
4
+
5
+ It includes:
6
+
7
+ - The `axium` (server) CLI
8
+ - The web UI/server and HTTP API
9
+ - Lots of database stuff
package/dist/audit.js CHANGED
@@ -20,8 +20,6 @@ export function styleSeverity(sev, align = false) {
20
20
  return styleText(severityFormat[sev], text.toUpperCase());
21
21
  }
22
22
  function output(event) {
23
- if (event.severity > Severity[capitalize(config.audit.min_severity)])
24
- return;
25
23
  console.error('[audit]', styleText('dim', io.prettyDate(event.timestamp)), styleSeverity(event.severity), event.name);
26
24
  }
27
25
  export async function audit_raw(event) {
@@ -29,6 +27,8 @@ export async function audit_raw(event) {
29
27
  io.warn('[audit] Ignoring raw event (disabled)');
30
28
  return;
31
29
  }
30
+ if (event.severity > Severity[capitalize(config.audit.min_severity)])
31
+ return;
32
32
  const result = await database.insertInto('audit_log').values(event).returningAll().executeTakeFirstOrThrow();
33
33
  output(result);
34
34
  }
@@ -48,6 +48,8 @@ export async function audit(eventName, userId, extra) {
48
48
  io.warn('Ignoring audit event with unknown event name: ' + eventName);
49
49
  return;
50
50
  }
51
+ if (cfg.severity > Severity[capitalize(config.audit.min_severity)])
52
+ return;
51
53
  try {
52
54
  if (cfg.extra)
53
55
  extra = cfg.extra.parse(extra);
package/dist/config.d.ts CHANGED
@@ -9,8 +9,8 @@ export declare const Config: z.ZodObject<{
9
9
  audit: z.ZodOptional<z.ZodObject<{
10
10
  allow_raw: z.ZodOptional<z.ZodBoolean>;
11
11
  retention: z.ZodOptional<z.ZodNumber>;
12
- min_severity: z.ZodOptional<z.ZodLiteral<"Emergency" | "Alert" | "Critical" | "Error" | "Warning" | "Notice" | "Info" | "Debug" | "emergency" | "alert" | "critical" | "error" | "warning" | "notice" | "info" | "debug">>;
13
- auto_suspend: z.ZodOptional<z.ZodLiteral<"Emergency" | "Alert" | "Critical" | "Error" | "Warning" | "Notice" | "Info" | "Debug" | "emergency" | "alert" | "critical" | "error" | "warning" | "notice" | "info" | "debug">>;
12
+ min_severity: z.ZodOptional<z.ZodLiteral<"emergency" | "alert" | "critical" | "error" | "warning" | "notice" | "info" | "debug">>;
13
+ auto_suspend: z.ZodOptional<z.ZodLiteral<"emergency" | "alert" | "critical" | "error" | "warning" | "notice" | "info" | "debug">>;
14
14
  }, z.core.$loose>>;
15
15
  auth: z.ZodOptional<z.ZodObject<{
16
16
  passkey_probation: z.ZodOptional<z.ZodNumber>;
@@ -86,8 +86,8 @@ export declare const ConfigFile: z.ZodObject<{
86
86
  audit: z.ZodOptional<z.ZodOptional<z.ZodObject<{
87
87
  allow_raw: z.ZodOptional<z.ZodBoolean>;
88
88
  retention: z.ZodOptional<z.ZodNumber>;
89
- min_severity: z.ZodOptional<z.ZodLiteral<"Emergency" | "Alert" | "Critical" | "Error" | "Warning" | "Notice" | "Info" | "Debug" | "emergency" | "alert" | "critical" | "error" | "warning" | "notice" | "info" | "debug">>;
90
- auto_suspend: z.ZodOptional<z.ZodLiteral<"Emergency" | "Alert" | "Critical" | "Error" | "Warning" | "Notice" | "Info" | "Debug" | "emergency" | "alert" | "critical" | "error" | "warning" | "notice" | "info" | "debug">>;
89
+ min_severity: z.ZodOptional<z.ZodLiteral<"emergency" | "alert" | "critical" | "error" | "warning" | "notice" | "info" | "debug">>;
90
+ auto_suspend: z.ZodOptional<z.ZodLiteral<"emergency" | "alert" | "critical" | "error" | "warning" | "notice" | "info" | "debug">>;
91
91
  }, z.core.$loose>>>;
92
92
  auth: z.ZodOptional<z.ZodOptional<z.ZodObject<{
93
93
  passkey_probation: z.ZodOptional<z.ZodNumber>;
package/dist/config.js CHANGED
@@ -1,15 +1,14 @@
1
+ import { serverConfigs, toBaseName } from '@axium/core';
1
2
  import * as io from '@axium/core/node/io';
2
3
  import { loadPlugin } from '@axium/core/node/plugins';
3
4
  import { levelText } from 'logzen';
4
5
  import { existsSync, readFileSync, writeFileSync } from 'node:fs';
5
6
  import { dirname, join, resolve } from 'node:path/posix';
6
- import { capitalize, deepAssign, omit } from 'utilium';
7
+ import { deepAssign, omit } from 'utilium';
7
8
  import * as z from 'zod';
8
9
  import { dirs, logger, systemDir } from './io.js';
9
10
  import { _duplicateStateWarnings, _unique } from './state.js';
10
- import { serverConfigs, toBaseName } from '@axium/core';
11
11
  const audit_severity_levels = ['emergency', 'alert', 'critical', 'error', 'warning', 'notice', 'info', 'debug'];
12
- const z_audit_severity = z.literal([...audit_severity_levels, ...audit_severity_levels.map(capitalize)]);
13
12
  export const Config = z
14
13
  .looseObject({
15
14
  /** Whether /api/admin is enabled */
@@ -25,8 +24,9 @@ export const Config = z
25
24
  allow_raw: z.boolean(),
26
25
  /** How many days to keep events in the audit log */
27
26
  retention: z.number().min(0),
28
- min_severity: z_audit_severity,
29
- auto_suspend: z_audit_severity,
27
+ /** Minimum severity level. Less severe events will be ignored. */
28
+ min_severity: z.literal(audit_severity_levels),
29
+ auto_suspend: z.literal(audit_severity_levels),
30
30
  })
31
31
  .partial(),
32
32
  auth: z
package/dist/main.js CHANGED
@@ -82,17 +82,30 @@ async function rlConfirm(question = 'Is this ok') {
82
82
  io.exit('Aborted.');
83
83
  }
84
84
  async function dbInitTables() {
85
- const info = db.getUpgradeInfo();
86
- const schema = db.getFullSchema({ exclude: Object.keys(info.current) });
87
- const delta = db.computeDelta({ tables: {}, indexes: [] }, schema);
88
- if (db.deltaIsEmpty(delta))
89
- return;
90
- for (const text of db.displayDelta(delta))
91
- console.log(text);
92
- await rlConfirm();
93
- await db.applyDelta(delta);
94
- Object.assign(info.current, schema.versions);
95
- db.setUpgradeInfo(info);
85
+ const env_2 = { stack: [], error: void 0, hasError: false };
86
+ try {
87
+ const info = db.getUpgradeInfo();
88
+ const schema = db.getFullSchema({ exclude: Object.keys(info.current) });
89
+ const delta = db.computeDelta({ tables: {}, indexes: [] }, schema);
90
+ if (db.deltaIsEmpty(delta))
91
+ return;
92
+ for (const text of db.displayDelta(delta))
93
+ console.log(text);
94
+ await rlConfirm();
95
+ const _ = __addDisposableResource(env_2, db.connect(), true);
96
+ await db.applyDelta(delta);
97
+ Object.assign(info.current, schema.versions);
98
+ db.setUpgradeInfo(info);
99
+ }
100
+ catch (e_2) {
101
+ env_2.error = e_2;
102
+ env_2.hasError = true;
103
+ }
104
+ finally {
105
+ const result_1 = __disposeResources(env_2);
106
+ if (result_1)
107
+ await result_1;
108
+ }
96
109
  }
97
110
  function configReplacer(opt) {
98
111
  return (key, value) => {
@@ -265,7 +278,7 @@ try {
265
278
  .description('Check the structure of the database')
266
279
  .option('-s, --strict', 'Throw errors instead of emitting warnings for most column problems')
267
280
  .action(async (opt) => {
268
- const env_2 = { stack: [], error: void 0, hasError: false };
281
+ const env_3 = { stack: [], error: void 0, hasError: false };
269
282
  try {
270
283
  await io.run('Checking for sudo', 'which sudo').catch(io.exit);
271
284
  await io.run('Checking for psql', 'which psql').catch(io.exit);
@@ -277,7 +290,7 @@ try {
277
290
  await db._sql(`SELECT 1 FROM pg_database WHERE datname = 'axium'`, 'Checking for database').then(throwUnlessRows).catch(io.exit);
278
291
  await db._sql(`SELECT 1 FROM pg_roles WHERE rolname = 'axium'`, 'Checking for user').then(throwUnlessRows).catch(io.exit);
279
292
  io.start('Connecting to database');
280
- const _ = __addDisposableResource(env_2, db.connect(), true);
293
+ const _ = __addDisposableResource(env_3, db.connect(), true);
281
294
  io.done();
282
295
  io.start('Getting schema metadata');
283
296
  const schemas = await db.database.introspection.getSchemas().catch(io.exit);
@@ -316,14 +329,14 @@ try {
316
329
  else
317
330
  io.warn(unchecked);
318
331
  }
319
- catch (e_2) {
320
- env_2.error = e_2;
321
- env_2.hasError = true;
332
+ catch (e_3) {
333
+ env_3.error = e_3;
334
+ env_3.hasError = true;
322
335
  }
323
336
  finally {
324
- const result_1 = __disposeResources(env_2);
325
- if (result_1)
326
- await result_1;
337
+ const result_2 = __disposeResources(env_3);
338
+ if (result_2)
339
+ await result_2;
327
340
  }
328
341
  });
329
342
  axiumDB
@@ -572,21 +585,21 @@ try {
572
585
  .addOption(opts.check)
573
586
  .argument('<plugin>', 'the plugin to initialize')
574
587
  .action(async (search) => {
575
- const env_3 = { stack: [], error: void 0, hasError: false };
588
+ const env_4 = { stack: [], error: void 0, hasError: false };
576
589
  try {
577
590
  const plugin = _findPlugin(search);
578
591
  if (!plugin)
579
592
  io.exit(`Can't find a plugin matching "${search}"`);
580
- const _ = __addDisposableResource(env_3, db.connect(), true);
593
+ const _ = __addDisposableResource(env_4, db.connect(), true);
581
594
  }
582
- catch (e_3) {
583
- env_3.error = e_3;
584
- env_3.hasError = true;
595
+ catch (e_4) {
596
+ env_4.error = e_4;
597
+ env_4.hasError = true;
585
598
  }
586
599
  finally {
587
- const result_2 = __disposeResources(env_3);
588
- if (result_2)
589
- await result_2;
600
+ const result_3 = __disposeResources(env_4);
601
+ if (result_3)
602
+ await result_3;
590
603
  }
591
604
  });
592
605
  axiumApps = program.command('apps').description('Manage Axium apps').addOption(opts.global);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axium/server",
3
- "version": "0.34.0",
3
+ "version": "0.34.2",
4
4
  "author": "James Prevett <axium@jamespre.dev>",
5
5
  "funding": {
6
6
  "type": "individual",
@@ -40,15 +40,7 @@
40
40
  "warning",
41
41
  "notice",
42
42
  "info",
43
- "debug",
44
- "Emergency",
45
- "Alert",
46
- "Critical",
47
- "Error",
48
- "Warning",
49
- "Notice",
50
- "Info",
51
- "Debug"
43
+ "debug"
52
44
  ]
53
45
  },
54
46
  "auto_suspend": {
@@ -61,15 +53,7 @@
61
53
  "warning",
62
54
  "notice",
63
55
  "info",
64
- "debug",
65
- "Emergency",
66
- "Alert",
67
- "Critical",
68
- "Error",
69
- "Warning",
70
- "Notice",
71
- "Info",
72
- "Debug"
56
+ "debug"
73
57
  ]
74
58
  }
75
59
  },