@axium/client 0.37.1 → 0.38.0
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 +4 -7
- package/dist/cli/config.d.ts +26 -10
- package/dist/cli/config.js +39 -28
- package/dist/cli/index.js +19 -17
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/user.js +3 -2
- package/dist/web/hooks.js +1 -6
- package/lib/MediaControls.svelte +1 -1
- package/package.json +6 -4
- package/dist/config.d.ts +0 -10
- package/dist/config.js +0 -24
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
|
|
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 {
|
|
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
|
-
|
|
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) {
|
package/dist/cli/config.d.ts
CHANGED
|
@@ -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;
|
package/dist/cli/config.js
CHANGED
|
@@ -1,17 +1,50 @@
|
|
|
1
1
|
import { persistFeaturesTo } from '@axium/core/node/features';
|
|
2
2
|
import { loadPlugin } 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
|
|
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
|
+
export const configManager = new ConfigManager(z.looseObject({
|
|
27
|
+
token: z.base64url().nullish(),
|
|
28
|
+
server: z.url().nullish(),
|
|
29
|
+
plugins: z.string().array().default([]),
|
|
30
|
+
}), { enableIncludes: true, xdg: 'axium/config' })
|
|
31
|
+
.$loadOptions()
|
|
32
|
+
.on('change', () => {
|
|
33
|
+
if (config.server)
|
|
34
|
+
setPrefix(config.server);
|
|
35
|
+
if (config.token)
|
|
36
|
+
setToken(config.token);
|
|
37
|
+
})
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
39
|
+
.on('post_load', async (path, file, options) => {
|
|
40
|
+
for (const plugin of config.plugins ?? [])
|
|
41
|
+
await loadPlugin('client', plugin, path, options.plugins);
|
|
42
|
+
})
|
|
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,33 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import { createPluginCommand, outputDaemonStatus } from '@axium/core/node';
|
|
2
|
+
import { createPluginCommand } from '@axium/core/node';
|
|
4
3
|
import { _findPlugin, plugins } from '@axium/core/plugins';
|
|
4
|
+
import { configCommand } from '@james-pre/config/cli';
|
|
5
|
+
import { Service } from '@james-pre/systemd';
|
|
6
|
+
import { serviceCommand } from '@james-pre/systemd/cli';
|
|
5
7
|
import { CommanderError, program } from 'commander';
|
|
6
8
|
import * as io from 'ioium/node';
|
|
7
|
-
import { basename } from 'node:path';
|
|
9
|
+
import { basename, join } from 'node:path';
|
|
8
10
|
import { styleText } from 'node:util';
|
|
11
|
+
import { bytes as formatBytes } from 'utilium/format';
|
|
9
12
|
import * as z from 'zod';
|
|
10
13
|
import $pkg from '../../package.json' with { type: 'json' };
|
|
11
|
-
import { config } from '../config.js';
|
|
12
14
|
import { prefix, useUserAgent } from '../requests.js';
|
|
13
15
|
import { connect as connectSocket } from '../socket.js';
|
|
14
16
|
import { logout } from '../user.js';
|
|
15
17
|
import { clientUA, login } from './auth.js';
|
|
16
18
|
import * as cache from './cache.js';
|
|
17
|
-
import {
|
|
19
|
+
import { config, configManager, session } from './config.js';
|
|
18
20
|
const safe = z.stringbool().default(false).parse(process.env.SAFE?.toLowerCase()) || process.argv.includes('--safe');
|
|
19
21
|
const debug = z.stringbool().default(false).parse(process.env.DEBUG?.toLowerCase()) || process.argv.includes('--debug');
|
|
20
22
|
if (debug)
|
|
21
23
|
io._setDebugOutput(true);
|
|
22
24
|
useUserAgent(clientUA);
|
|
23
|
-
|
|
25
|
+
const loadOptions = { plugins: { safe } };
|
|
26
|
+
configManager.loadDefaults(loadOptions);
|
|
24
27
|
cache.load();
|
|
25
28
|
process.on('SIGHUP', () => {
|
|
26
29
|
io.info('Reloading configuration due to SIGHUP.');
|
|
27
|
-
|
|
30
|
+
configManager.reloadFiles();
|
|
28
31
|
});
|
|
29
32
|
program
|
|
30
33
|
.version($pkg.version)
|
|
@@ -50,6 +53,11 @@ program.command('logout').action(async () => {
|
|
|
50
53
|
const { id, userId } = session();
|
|
51
54
|
await logout(userId, id);
|
|
52
55
|
});
|
|
56
|
+
configCommand(program, configManager, { defaultType: 'user', sensitive: ['token'] });
|
|
57
|
+
serviceCommand(program, {
|
|
58
|
+
service: user => new Service('axium-client', { user: user ?? true }),
|
|
59
|
+
source: () => ({ link: join(import.meta.dirname, '../../axium-client.service') }),
|
|
60
|
+
});
|
|
53
61
|
program.command('status').action(() => {
|
|
54
62
|
if (!config.token)
|
|
55
63
|
return console.log('Not logged in.');
|
|
@@ -60,7 +68,7 @@ program.command('status').action(() => {
|
|
|
60
68
|
console.log(styleText('whiteBright', 'Session:'), 'valid until', session.expires.toLocaleDateString(), styleText('dim', `(${session.id})`));
|
|
61
69
|
const { user } = session;
|
|
62
70
|
console.log(styleText('whiteBright', 'User:'), user.name, `<${user.email}>`, styleText('dim', `(${user.id})`));
|
|
63
|
-
|
|
71
|
+
console.log(styleText('whiteBright', 'Daemon:'), new Service('axium-client', { user: true }).shortStatus());
|
|
64
72
|
});
|
|
65
73
|
program
|
|
66
74
|
.command('daemon')
|
|
@@ -76,16 +84,10 @@ program
|
|
|
76
84
|
});
|
|
77
85
|
const axcPlugin = createPluginCommand('client', program, {
|
|
78
86
|
safe,
|
|
79
|
-
loadedBy: () =>
|
|
87
|
+
loadedBy: () => configManager.filePaths.next().value,
|
|
80
88
|
enabled: config.plugins,
|
|
81
|
-
enable(spec)
|
|
82
|
-
|
|
83
|
-
saveConfig();
|
|
84
|
-
},
|
|
85
|
-
disable(spec) {
|
|
86
|
-
config.plugins = config.plugins.filter(p => p !== spec);
|
|
87
|
-
saveConfig();
|
|
88
|
-
},
|
|
89
|
+
enable: spec => configManager.update({ plugins: [...config.plugins, spec] }),
|
|
90
|
+
disable: spec => configManager.update({ plugins: config.plugins.filter(p => p !== spec) }),
|
|
89
91
|
});
|
|
90
92
|
axcPlugin
|
|
91
93
|
.command('run')
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
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);
|
package/dist/web/hooks.js
CHANGED
|
@@ -15,12 +15,7 @@ export async function init() {
|
|
|
15
15
|
void pwa.unregister().catch(() => { });
|
|
16
16
|
await loadLocale().catch(() => { });
|
|
17
17
|
if (session && session.expires.getTime() < Date.now() + day)
|
|
18
|
-
|
|
19
|
-
await extendCurrentSession(session.userId);
|
|
20
|
-
}
|
|
21
|
-
catch {
|
|
22
|
-
console.debug('Failed to extend current session');
|
|
23
|
-
}
|
|
18
|
+
void extendCurrentSession(session.userId).catch(() => console.debug('Failed to extend current session'));
|
|
24
19
|
if (feature('themes')) {
|
|
25
20
|
const theme = themeStyles[session?.user?.preferences?.theme || 'default'] || {};
|
|
26
21
|
for (const [prop, value] of Object.entries(theme))
|
package/lib/MediaControls.svelte
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { formatDuration } from '
|
|
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.
|
|
3
|
+
"version": "0.38.0",
|
|
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.
|
|
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.
|
|
56
|
+
"utilium": "^3.8.0",
|
|
57
57
|
"zod": "^4.0.5"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@
|
|
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
|
-
}
|