@axium/client 0.16.5 → 0.16.7
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/config.d.ts +1 -0
- package/dist/cli/index.js +5 -2
- package/dist/config.d.ts +1 -0
- package/dist/requests.d.ts +4 -0
- package/dist/requests.js +9 -0
- package/dist/user.js +3 -3
- package/lib/SessionList.svelte +1 -1
- package/package.json +2 -2
- package/styles/account.css +1 -1
package/dist/cli/config.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export declare function session(): {
|
|
|
21
21
|
emailVerified?: Date | null | undefined;
|
|
22
22
|
image?: string | null | undefined;
|
|
23
23
|
};
|
|
24
|
+
name?: string | null | undefined;
|
|
24
25
|
};
|
|
25
26
|
export declare function loadConfig(safe: boolean): Promise<void>;
|
|
26
27
|
export declare function saveConfig(): void;
|
package/dist/cli/index.js
CHANGED
|
@@ -60,13 +60,16 @@ import { styleText } from 'node:util';
|
|
|
60
60
|
import * as z from 'zod';
|
|
61
61
|
import $pkg from '../../package.json' with { type: 'json' };
|
|
62
62
|
import { config, resolveServerURL } from '../config.js';
|
|
63
|
-
import { prefix, setPrefix, setToken } from '../requests.js';
|
|
63
|
+
import { prefix, setPrefix, setToken, useUserAgent } from '../requests.js';
|
|
64
64
|
import { getCurrentSession, logout } from '../user.js';
|
|
65
65
|
import { loadConfig, saveConfig, updateCache } from './config.js';
|
|
66
|
+
import { capitalize } from 'utilium';
|
|
66
67
|
const safe = z.stringbool().default(false).parse(process.env.SAFE?.toLowerCase()) || process.argv.includes('--safe');
|
|
67
68
|
const debug = z.stringbool().default(false).parse(process.env.DEBUG?.toLowerCase()) || process.argv.includes('--debug');
|
|
68
69
|
if (debug)
|
|
69
70
|
io._setDebugOutput(true);
|
|
71
|
+
const clientUA = `Axium Client/${$pkg.version} (${capitalize(process.platform)}; ${process.arch})`;
|
|
72
|
+
useUserAgent(clientUA);
|
|
70
73
|
await loadConfig(safe);
|
|
71
74
|
process.on('SIGHUP', () => {
|
|
72
75
|
io.info('Reloading configuration due to SIGHUP.');
|
|
@@ -150,7 +153,7 @@ try {
|
|
|
150
153
|
});
|
|
151
154
|
server.on('error', e => io.exit('Failed to start local callback server: ' + e.message, 5));
|
|
152
155
|
const port = await serverReady.promise;
|
|
153
|
-
const authURL = new URL(
|
|
156
|
+
const authURL = new URL(`/login/client?port=${port}&client=${encodeURIComponent(clientUA)}`, url).href;
|
|
154
157
|
console.log('Authenticate by visiting this URL in your browser: ' + styleText('underline', authURL));
|
|
155
158
|
const { token } = await sessionReady.promise.catch(e => io.exit('Failed to obtain session: ' + e, 6));
|
|
156
159
|
setToken(token);
|
package/dist/config.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export declare const ClientConfig: z.ZodObject<{
|
|
|
7
7
|
session: z.ZodObject<{
|
|
8
8
|
id: z.ZodUUID;
|
|
9
9
|
userId: z.ZodUUID;
|
|
10
|
+
name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
10
11
|
expires: z.ZodCoercedDate<unknown>;
|
|
11
12
|
created: z.ZodCoercedDate<unknown>;
|
|
12
13
|
elevated: z.ZodBoolean;
|
package/dist/requests.d.ts
CHANGED
|
@@ -5,4 +5,8 @@ export declare let token: string | null;
|
|
|
5
5
|
export declare function setToken(value: string | null): void;
|
|
6
6
|
export declare let prefix: string;
|
|
7
7
|
export declare function setPrefix(value: string): void;
|
|
8
|
+
/**
|
|
9
|
+
* Only for use on non-browser clients, e.g. Node.js
|
|
10
|
+
*/
|
|
11
|
+
export declare function useUserAgent(ua: string | null): void;
|
|
8
12
|
export declare function fetchAPI<const E extends Endpoint, const M extends keyof $API[E] & RequestMethod>(method: M, endpoint: E, data?: RequestBody<M, E>, ...params: APIParameters<E>): Promise<M extends keyof APIValues[E] ? (APIValues[E][M] extends readonly [unknown, infer R] ? R : APIValues[E][M]) : unknown>;
|
package/dist/requests.js
CHANGED
|
@@ -8,6 +8,13 @@ export let prefix = '/api/';
|
|
|
8
8
|
export function setPrefix(value) {
|
|
9
9
|
prefix = value;
|
|
10
10
|
}
|
|
11
|
+
let userAgent = null;
|
|
12
|
+
/**
|
|
13
|
+
* Only for use on non-browser clients, e.g. Node.js
|
|
14
|
+
*/
|
|
15
|
+
export function useUserAgent(ua) {
|
|
16
|
+
userAgent = ua;
|
|
17
|
+
}
|
|
11
18
|
export async function fetchAPI(method, endpoint, data, ...params) {
|
|
12
19
|
const options = {
|
|
13
20
|
method,
|
|
@@ -31,6 +38,8 @@ export async function fetchAPI(method, endpoint, data, ...params) {
|
|
|
31
38
|
: '?' + new URLSearchParams(JSON.parse(JSON.stringify(data))).toString();
|
|
32
39
|
if (token)
|
|
33
40
|
options.headers.Authorization = 'Bearer ' + token;
|
|
41
|
+
if (userAgent)
|
|
42
|
+
options.headers['User-Agent'] = userAgent;
|
|
34
43
|
const parts = [];
|
|
35
44
|
for (const part of endpoint.split('/')) {
|
|
36
45
|
if (!part.startsWith(':')) {
|
package/dist/user.js
CHANGED
|
@@ -64,10 +64,10 @@ export async function userInfo(userId, noCache = false) {
|
|
|
64
64
|
_checkId(userId);
|
|
65
65
|
const cached = userCache.get(userId);
|
|
66
66
|
if (!noCache && cached)
|
|
67
|
-
return cached;
|
|
68
|
-
const result =
|
|
67
|
+
return await cached;
|
|
68
|
+
const result = fetchAPI('GET', 'users/:id', {}, userId);
|
|
69
69
|
userCache.set(userId, result);
|
|
70
|
-
return result;
|
|
70
|
+
return await result;
|
|
71
71
|
}
|
|
72
72
|
export async function updateUser(userId, data) {
|
|
73
73
|
_checkId(userId);
|
package/lib/SessionList.svelte
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
{#each sessions as session}
|
|
16
16
|
<div class="item session">
|
|
17
17
|
<p>
|
|
18
|
-
{session.id.slice(0, 4)}
|
|
18
|
+
{session.name ?? `${session.id.slice(0, 4)}...${session.id.slice(-4)}`}
|
|
19
19
|
{#if session.id == currentSession?.id}
|
|
20
20
|
<span class="current">Current</span>
|
|
21
21
|
{/if}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axium/client",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.7",
|
|
4
4
|
"author": "James Prevett <jp@jamespre.dev>",
|
|
5
5
|
"funding": {
|
|
6
6
|
"type": "individual",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"build": "tsc"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
|
-
"@axium/core": ">=0.20.
|
|
44
|
+
"@axium/core": ">=0.20.3",
|
|
45
45
|
"utilium": "^2.6.3",
|
|
46
46
|
"zod": "^4.0.5",
|
|
47
47
|
"svelte": "^5.36.0"
|