@axium/client 0.37.2 → 0.38.1

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/auth.js CHANGED
@@ -53,15 +53,14 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
53
53
  import { NewSessionResponse } from '@axium/core';
54
54
  import * as io from 'ioium/node';
55
55
  import { createServer } from 'node:http';
56
+ import * as os from 'node:os';
56
57
  import { createInterface } from 'node:readline/promises';
57
58
  import { styleText } from 'node:util';
58
- import { config, resolveServerURL } from '../config.js';
59
+ import $pkg from '../../package.json' with { type: 'json' };
59
60
  import { prefix, setPrefix, setToken } from '../requests.js';
60
61
  import { getCurrentSession } from '../user.js';
61
62
  import * as cache from './cache.js';
62
- import { saveConfig } from './config.js';
63
- import * as os from 'node:os';
64
- import $pkg from '../../package.json' with { type: 'json' };
63
+ import { configManager, resolveServerURL } from './config.js';
65
64
  export const clientUA = `Axium Client/${$pkg.version} (${os.type()}; ${process.arch})`;
66
65
  export async function login(url) {
67
66
  const env_1 = { stack: [], error: void 0, hasError: false };
@@ -125,9 +124,7 @@ export async function login(url) {
125
124
  const session = await io.track('Verifying session', getCurrentSession().catch(e => io.exit(e, 6)));
126
125
  io.debug('Session UUID: ' + session.id);
127
126
  console.log(`Welcome ${session.user.name}! Your session is valid until ${session.expires.toLocaleDateString()}.`);
128
- config.token = token;
129
- config.server = url;
130
- saveConfig();
127
+ configManager.update({ token, server: url });
131
128
  await cache.update(true);
132
129
  }
133
130
  catch (e_1) {
@@ -1,6 +1,31 @@
1
1
  import { type PluginLoadOptions } from '@axium/core/node/plugins';
2
+ import { Manager as ConfigManager } from '@james-pre/config';
3
+ import * as z from 'zod';
4
+ export declare function resolveServerURL(server: string): string;
5
+ export declare const configManager: ConfigManager<z.ZodObject<{
6
+ token: z.ZodOptional<z.ZodNullable<z.ZodBase64URL>>;
7
+ server: z.ZodOptional<z.ZodNullable<z.ZodURL>>;
8
+ plugins: z.ZodDefault<z.ZodArray<z.ZodString>>;
9
+ }, z.core.$loose>, import("@axium/client").LoadOptions & {
10
+ plugins?: PluginLoadOptions;
11
+ }, {
12
+ [x: string]: unknown;
13
+ token?: string | null | undefined;
14
+ server?: string | null | undefined;
15
+ plugins?: string[] | undefined;
16
+ }, {
17
+ [x: string]: unknown;
18
+ token?: string | null | undefined;
19
+ server?: string | null | undefined;
20
+ plugins?: string[] | undefined;
21
+ }>;
22
+ export declare const config: {
23
+ [x: string]: unknown;
24
+ plugins: string[];
25
+ token?: string | null | undefined;
26
+ server?: string | null | undefined;
27
+ };
2
28
  export declare const configDir: string;
3
- export declare const axcConfigPath: string;
4
29
  export declare function session(): {
5
30
  id: string;
6
31
  userId: string;
@@ -25,12 +50,3 @@ export declare function session(): {
25
50
  };
26
51
  name?: string | null | undefined;
27
52
  };
28
- export interface LoadConfigOptions {
29
- plugins?: PluginLoadOptions;
30
- }
31
- /**
32
- *
33
- * @param safe whether to run code from plugins
34
- */
35
- export declare function loadConfig(options?: LoadConfigOptions): Promise<void>;
36
- export declare function saveConfig(): void;
@@ -1,17 +1,50 @@
1
1
  import { persistFeaturesTo } from '@axium/core/node/features';
2
- import { loadPlugin } from '@axium/core/node/plugins';
2
+ import { loadPlugin, trackPluginLoading } from '@axium/core/node/plugins';
3
+ import { Manager as ConfigManager } from '@james-pre/config';
4
+ import { debug, warn } from 'ioium';
3
5
  import * as io from 'ioium/node';
4
- import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
5
- import { homedir } from 'node:os';
6
6
  import { join } from 'node:path/posix';
7
- import { ClientConfig, config } from '../config.js';
7
+ import * as z from 'zod';
8
8
  import { setPrefix, setToken } from '../requests.js';
9
9
  import * as cache from './cache.js';
10
+ import { homedir } from 'node:os';
11
+ import { mkdirSync } from 'node:fs';
12
+ export function resolveServerURL(server) {
13
+ if (!server.startsWith('http://') && !server.startsWith('https://'))
14
+ server = 'https://' + server;
15
+ const url = new URL(server);
16
+ if (url.pathname.endsWith('/api'))
17
+ url.pathname += '/';
18
+ else if (url.pathname.at(-1) == '/' && !url.pathname.endsWith('/api/'))
19
+ url.pathname += 'api/';
20
+ if (url.pathname != '/api/')
21
+ warn('Resolved server URL is not at the top level: ' + url.href);
22
+ else
23
+ debug('Resolved server URL: ' + url.href);
24
+ return url.href;
25
+ }
26
+ async function loadPlugins(path, options) {
27
+ for (const plugin of config.plugins ?? [])
28
+ await loadPlugin('client', plugin, path, options);
29
+ }
30
+ export const configManager = new ConfigManager(z.looseObject({
31
+ token: z.base64url().nullish(),
32
+ server: z.url().nullish(),
33
+ plugins: z.string().array().default([]),
34
+ }), { enableIncludes: true, xdg: 'axium/config' })
35
+ .$loadOptions()
36
+ .on('change', () => {
37
+ if (config.server)
38
+ setPrefix(config.server);
39
+ if (config.token)
40
+ setToken(config.token);
41
+ })
42
+ .on('post_load', (path, file, options) => trackPluginLoading(loadPlugins(path, options.plugins)))
43
+ .on('load_error', (path, stage, error) => io.warn('Failed to load config:', io.errorText(error)))
44
+ .on('write', path => io.debug('Saved config to', path));
45
+ export const config = configManager.data;
10
46
  export const configDir = join(process.env.XDG_CONFIG_HOME || join(homedir(), '.config'), 'axium');
11
47
  mkdirSync(configDir, { recursive: true });
12
- export const axcConfigPath = join(configDir, 'config.json');
13
- if (!existsSync(axcConfigPath))
14
- writeFileSync(axcConfigPath, '{}');
15
48
  persistFeaturesTo(join(configDir, 'features.json'));
16
49
  export function session() {
17
50
  if (!config.token)
@@ -20,25 +53,3 @@ export function session() {
20
53
  io.exit('No session data available.', 3);
21
54
  return cache.meta.data.session;
22
55
  }
23
- /**
24
- *
25
- * @param safe whether to run code from plugins
26
- */
27
- export async function loadConfig(options = {}) {
28
- try {
29
- Object.assign(config, io.readJSON(axcConfigPath, ClientConfig));
30
- if (config.server)
31
- setPrefix(config.server);
32
- if (config.token)
33
- setToken(config.token);
34
- for (const plugin of config.plugins ?? [])
35
- await loadPlugin('client', plugin, axcConfigPath, options.plugins);
36
- }
37
- catch (e) {
38
- io.warn('Failed to load config: ' + io.errorText(e));
39
- }
40
- }
41
- export function saveConfig() {
42
- io.writeJSON(axcConfigPath, config);
43
- io.debug('Saved config to ' + axcConfigPath);
44
- }
package/dist/cli/index.js CHANGED
@@ -1,30 +1,35 @@
1
1
  #! /usr/bin/env node
2
- import { formatBytes } from '@axium/core';
3
- import { createPluginCommand, outputDaemonStatus } from '@axium/core/node';
2
+ import { createPluginCommand } from '@axium/core/node';
3
+ import { waitForPlugins } from '@axium/core/node/plugins';
4
4
  import { _findPlugin, plugins } from '@axium/core/plugins';
5
+ import { configCommand } from '@james-pre/config/cli';
6
+ import { Service } from '@james-pre/systemd';
7
+ import { serviceCommand } from '@james-pre/systemd/cli';
5
8
  import { CommanderError, program } from 'commander';
6
9
  import * as io from 'ioium/node';
7
- import { basename } from 'node:path';
10
+ import { basename, join } from 'node:path';
8
11
  import { styleText } from 'node:util';
12
+ import { bytes as formatBytes } from 'utilium/format';
9
13
  import * as z from 'zod';
10
14
  import $pkg from '../../package.json' with { type: 'json' };
11
- import { config } from '../config.js';
12
15
  import { prefix, useUserAgent } from '../requests.js';
13
16
  import { connect as connectSocket } from '../socket.js';
14
17
  import { logout } from '../user.js';
15
18
  import { clientUA, login } from './auth.js';
16
19
  import * as cache from './cache.js';
17
- import { axcConfigPath, loadConfig, saveConfig, session } from './config.js';
20
+ import { config, configManager, session } from './config.js';
18
21
  const safe = z.stringbool().default(false).parse(process.env.SAFE?.toLowerCase()) || process.argv.includes('--safe');
19
22
  const debug = z.stringbool().default(false).parse(process.env.DEBUG?.toLowerCase()) || process.argv.includes('--debug');
20
23
  if (debug)
21
24
  io._setDebugOutput(true);
22
25
  useUserAgent(clientUA);
23
- await loadConfig({ plugins: { safe } });
26
+ const loadOptions = { plugins: { safe } };
27
+ configManager.loadDefaults(loadOptions);
28
+ await waitForPlugins();
24
29
  cache.load();
25
30
  process.on('SIGHUP', () => {
26
31
  io.info('Reloading configuration due to SIGHUP.');
27
- void loadConfig({ plugins: { safe } });
32
+ configManager.reloadFiles({ plugins: { safe, reload: true } });
28
33
  });
29
34
  program
30
35
  .version($pkg.version)
@@ -50,6 +55,11 @@ program.command('logout').action(async () => {
50
55
  const { id, userId } = session();
51
56
  await logout(userId, id);
52
57
  });
58
+ configCommand(program, configManager, { defaultType: 'user', sensitive: ['token'] });
59
+ serviceCommand(program, {
60
+ service: user => new Service('axium-client', { user: user ?? true }),
61
+ source: () => ({ link: join(import.meta.dirname, '../../axium-client.service') }),
62
+ });
53
63
  program.command('status').action(() => {
54
64
  if (!config.token)
55
65
  return console.log('Not logged in.');
@@ -60,7 +70,7 @@ program.command('status').action(() => {
60
70
  console.log(styleText('whiteBright', 'Session:'), 'valid until', session.expires.toLocaleDateString(), styleText('dim', `(${session.id})`));
61
71
  const { user } = session;
62
72
  console.log(styleText('whiteBright', 'User:'), user.name, `<${user.email}>`, styleText('dim', `(${user.id})`));
63
- outputDaemonStatus('axium-client', true);
73
+ console.log(styleText('whiteBright', 'Daemon:'), new Service('axium-client', { user: true }).shortStatus());
64
74
  });
65
75
  program
66
76
  .command('daemon')
@@ -76,16 +86,10 @@ program
76
86
  });
77
87
  const axcPlugin = createPluginCommand('client', program, {
78
88
  safe,
79
- loadedBy: () => axcConfigPath,
89
+ loadedBy: () => configManager.filePaths.next().value,
80
90
  enabled: config.plugins,
81
- enable(spec) {
82
- config.plugins.push(spec);
83
- saveConfig();
84
- },
85
- disable(spec) {
86
- config.plugins = config.plugins.filter(p => p !== spec);
87
- saveConfig();
88
- },
91
+ enable: spec => configManager.update({ plugins: [...config.plugins, spec] }),
92
+ disable: spec => configManager.update({ plugins: config.plugins.filter(p => p !== spec) }),
89
93
  });
90
94
  axcPlugin
91
95
  .command('run')
package/dist/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  export * from './access.js';
2
2
  export * from './cache.js';
3
- export * from './config.js';
4
3
  export * from './locales.js';
5
4
  export * as preferences from './preferences.js';
6
5
  export * from './requests.js';
package/dist/index.js CHANGED
@@ -1,6 +1,5 @@
1
1
  export * from './access.js';
2
2
  export * from './cache.js';
3
- export * from './config.js';
4
3
  export * from './locales.js';
5
4
  export * as preferences from './preferences.js';
6
5
  export * from './requests.js';
package/dist/user.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { PasskeyRegistration } from '@axium/core/passkeys';
1
2
  import { UserRegistrationInit } from '@axium/core/user';
2
3
  import { startAuthentication, startRegistration } from '@simplewebauthn/browser';
3
4
  import * as z from 'zod';
@@ -50,7 +51,7 @@ export async function register(_data) {
50
51
  const data = UserRegistrationInit.parse(_data);
51
52
  const { options, userId } = await fetchAPI('PUT', 'register', data);
52
53
  const response = await startRegistration({ optionsJSON: options });
53
- await fetchAPI('POST', 'register', { userId, response, ...data });
54
+ await fetchAPI('POST', 'register', { userId, response: PasskeyRegistration.parse(response), ...data });
54
55
  }
55
56
  function _checkId(userId) {
56
57
  try {
@@ -115,7 +116,7 @@ export async function createPasskey(userId) {
115
116
  _checkId(userId);
116
117
  const options = await fetchAPI('OPTIONS', 'users/:id/passkeys', {}, userId);
117
118
  const response = await startRegistration({ optionsJSON: options });
118
- return await fetchAPI('PUT', 'users/:id/passkeys', response, userId);
119
+ return await fetchAPI('PUT', 'users/:id/passkeys', PasskeyRegistration.parse(response), userId);
119
120
  }
120
121
  export async function updatePasskey(passkeyId, data) {
121
122
  return await fetchAPI('PATCH', 'passkeys/:id', data, passkeyId);
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import { formatDuration } from '@axium/core';
2
+ import { duration as formatDuration } from 'utilium/format';
3
3
  import Icon from './Icon.svelte';
4
4
  import type { MediaState } from './reactive/media.svelte.js';
5
5
  import type { Snippet } from 'svelte';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axium/client",
3
- "version": "0.37.2",
3
+ "version": "0.38.1",
4
4
  "author": "James Prevett <jp@jamespre.dev>",
5
5
  "funding": {
6
6
  "type": "individual",
@@ -49,15 +49,17 @@
49
49
  "build": "tsc"
50
50
  },
51
51
  "peerDependencies": {
52
- "@axium/core": ">=0.39.0",
52
+ "@axium/core": ">=0.40.0",
53
53
  "ioium": "^1.7.0",
54
54
  "semver": "^7.7.4",
55
55
  "svelte": "^5.36.0",
56
- "utilium": "^3.2.0",
56
+ "utilium": "^3.8.0",
57
57
  "zod": "^4.0.5"
58
58
  },
59
59
  "dependencies": {
60
- "@simplewebauthn/browser": "^13.1.0",
60
+ "@james-pre/config": "^1.2.0",
61
+ "@james-pre/systemd": "^0.2.0",
62
+ "@simplewebauthn/browser": "^14.0.0",
61
63
  "commander": "^15.0.0",
62
64
  "music-metadata": "^11.12.3",
63
65
  "socket.io-client": "^4.8.3"
package/dist/config.d.ts DELETED
@@ -1,10 +0,0 @@
1
- import * as z from 'zod';
2
- export declare const ClientConfig: z.ZodObject<{
3
- token: z.ZodOptional<z.ZodNullable<z.ZodBase64URL>>;
4
- server: z.ZodOptional<z.ZodNullable<z.ZodURL>>;
5
- plugins: z.ZodDefault<z.ZodArray<z.ZodString>>;
6
- }, z.core.$loose>;
7
- export interface ClientConfig extends z.infer<typeof ClientConfig> {
8
- }
9
- export declare const config: ClientConfig;
10
- export declare function resolveServerURL(server: string): string;
package/dist/config.js DELETED
@@ -1,24 +0,0 @@
1
- import { debug, warn } from 'ioium';
2
- import * as z from 'zod';
3
- export const ClientConfig = z.looseObject({
4
- token: z.base64url().nullish(),
5
- server: z.url().nullish(),
6
- plugins: z.string().array().default([]),
7
- });
8
- export const config = {
9
- plugins: [],
10
- };
11
- export function resolveServerURL(server) {
12
- if (!server.startsWith('http://') && !server.startsWith('https://'))
13
- server = 'https://' + server;
14
- const url = new URL(server);
15
- if (url.pathname.endsWith('/api'))
16
- url.pathname += '/';
17
- else if (url.pathname.at(-1) == '/' && !url.pathname.endsWith('/api/'))
18
- url.pathname += 'api/';
19
- if (url.pathname != '/api/')
20
- warn('Resolved server URL is not at the top level: ' + url.href);
21
- else
22
- debug('Resolved server URL: ' + url.href);
23
- return url.href;
24
- }