@axium/core 0.13.0 → 0.14.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/api.d.ts +5 -5
- package/dist/node/plugins.js +3 -18
- package/dist/packages.d.ts +12 -0
- package/dist/packages.js +51 -0
- package/dist/plugins.d.ts +0 -4
- package/dist/plugins.js +2 -17
- package/package.json +1 -1
package/dist/api.d.ts
CHANGED
|
@@ -5,8 +5,9 @@ import type { AccessControl, AccessMap } from './access.js';
|
|
|
5
5
|
import type { App } from './apps.js';
|
|
6
6
|
import type { AuditEvent, AuditFilter, Severity } from './audit.js';
|
|
7
7
|
import type { NewSessionResponse, Session, Verification } from './auth.js';
|
|
8
|
+
import type { PackageVersionInfo } from './packages.js';
|
|
8
9
|
import type { Passkey, PasskeyAuthenticationResponse, PasskeyChangeable, PasskeyRegistration } from './passkeys.js';
|
|
9
|
-
import type { PluginInternal
|
|
10
|
+
import type { PluginInternal } from './plugins.js';
|
|
10
11
|
import type { RequestMethod } from './requests.js';
|
|
11
12
|
import type { LogoutSessions, User, UserAuthOptions, UserChangeable, UserInternal, UserPublic, UserRegistration } from './user.js';
|
|
12
13
|
export interface AdminSummary {
|
|
@@ -16,7 +17,7 @@ export interface AdminSummary {
|
|
|
16
17
|
auditEvents: Record<keyof typeof Severity, number>;
|
|
17
18
|
configFiles: number;
|
|
18
19
|
plugins: number;
|
|
19
|
-
|
|
20
|
+
versions: Record<'core' | 'server' | 'client', PackageVersionInfo>;
|
|
20
21
|
}
|
|
21
22
|
/**
|
|
22
23
|
* Types for all API endpoints
|
|
@@ -25,12 +26,11 @@ export interface AdminSummary {
|
|
|
25
26
|
export interface $API {
|
|
26
27
|
metadata: {
|
|
27
28
|
GET: {
|
|
28
|
-
|
|
29
|
+
versions: PackageVersionInfo[];
|
|
29
30
|
routes: Record<string, {
|
|
30
31
|
params: Record<string, string | null>;
|
|
31
32
|
methods: string[];
|
|
32
33
|
}>;
|
|
33
|
-
plugins: Record<string, string>;
|
|
34
34
|
};
|
|
35
35
|
};
|
|
36
36
|
apps: {
|
|
@@ -116,7 +116,7 @@ export interface $API {
|
|
|
116
116
|
};
|
|
117
117
|
};
|
|
118
118
|
'admin/plugins': {
|
|
119
|
-
GET: (Omit<PluginInternal, '_hooks' | '_client'> &
|
|
119
|
+
GET: (Omit<PluginInternal, '_hooks' | '_client'> & PackageVersionInfo)[];
|
|
120
120
|
};
|
|
121
121
|
'admin/audit/events': {
|
|
122
122
|
OPTIONS: {
|
package/dist/node/plugins.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as io from '@axium/core/node/io';
|
|
2
2
|
import { Plugin, plugins } from '@axium/core/plugins';
|
|
3
3
|
import * as fs from 'node:fs';
|
|
4
|
-
import { dirname,
|
|
5
|
-
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { dirname, resolve } from 'node:path/posix';
|
|
6
5
|
import { styleText } from 'node:util';
|
|
7
6
|
import * as z from 'zod';
|
|
8
7
|
import { apps } from '../apps.js';
|
|
8
|
+
import { locatePackage } from '../packages.js';
|
|
9
9
|
export function* pluginText(plugin) {
|
|
10
10
|
yield styleText('whiteBright', plugin.name);
|
|
11
11
|
yield `Version: ${plugin.version}`;
|
|
@@ -19,24 +19,9 @@ export function* pluginText(plugin) {
|
|
|
19
19
|
yield `Hooks: ${plugin._client ? styleText(['dim', 'bold'], `(${Object.keys(plugin._client).length}) `) + Object.keys(plugin._client).join(', ') : plugin.client.hooks || styleText('dim', '(none)')}`;
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
function _locatePlugin(specifier, loadedBy) {
|
|
23
|
-
if (specifier[0] == '/' || ['.', '..'].includes(specifier.split('/')[0])) {
|
|
24
|
-
const path = resolve(dirname(loadedBy), specifier);
|
|
25
|
-
const stats = fs.statSync(path);
|
|
26
|
-
if (stats.isFile())
|
|
27
|
-
return path;
|
|
28
|
-
if (!stats.isDirectory())
|
|
29
|
-
throw new Error('Can not resolve plugin path: ' + path);
|
|
30
|
-
return join(path, 'package.json');
|
|
31
|
-
}
|
|
32
|
-
let packageDir = dirname(fileURLToPath(import.meta.resolve(specifier)));
|
|
33
|
-
for (; !fs.existsSync(join(packageDir, 'package.json')); packageDir = dirname(packageDir))
|
|
34
|
-
;
|
|
35
|
-
return join(packageDir, 'package.json');
|
|
36
|
-
}
|
|
37
22
|
export async function loadPlugin(mode, specifier, loadedBy, safeMode = false) {
|
|
38
23
|
try {
|
|
39
|
-
const path =
|
|
24
|
+
const path = locatePackage(specifier, loadedBy);
|
|
40
25
|
io.debug(`Loading plugin at ${path} (from ${loadedBy})`);
|
|
41
26
|
let imported;
|
|
42
27
|
try {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare function locatePackage(specifier: string, loadedBy: string): string;
|
|
2
|
+
export interface PackageVersionInfo {
|
|
3
|
+
name: string;
|
|
4
|
+
version: string;
|
|
5
|
+
latest: string | null;
|
|
6
|
+
}
|
|
7
|
+
export declare function setPackageCacheTTL(seconds: number): void;
|
|
8
|
+
/**
|
|
9
|
+
* @param name Package name
|
|
10
|
+
* @param version The current/installed version
|
|
11
|
+
*/
|
|
12
|
+
export declare function getVersionInfo(specifier: string, from?: string): Promise<PackageVersionInfo>;
|
package/dist/packages.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import { dirname, join, resolve } from 'node:path/posix';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { lt as ltVersion } from 'semver';
|
|
5
|
+
import { warn } from './io.js';
|
|
6
|
+
function isRelative(specifier) {
|
|
7
|
+
return specifier[0] == '/' || ['.', '..'].includes(specifier.split('/')[0]);
|
|
8
|
+
}
|
|
9
|
+
export function locatePackage(specifier, loadedBy) {
|
|
10
|
+
if (isRelative(specifier)) {
|
|
11
|
+
const path = resolve(dirname(loadedBy), specifier);
|
|
12
|
+
const stats = fs.statSync(path);
|
|
13
|
+
if (stats.isFile())
|
|
14
|
+
return path;
|
|
15
|
+
if (!stats.isDirectory())
|
|
16
|
+
throw new Error('Can not resolve package path: ' + path);
|
|
17
|
+
return join(path, 'package.json');
|
|
18
|
+
}
|
|
19
|
+
let packageDir = dirname(fileURLToPath(import.meta.resolve(specifier)));
|
|
20
|
+
for (; !fs.existsSync(join(packageDir, 'package.json')); packageDir = dirname(packageDir))
|
|
21
|
+
;
|
|
22
|
+
return join(packageDir, 'package.json');
|
|
23
|
+
}
|
|
24
|
+
let cacheTTL = 1000 * 60 * 60;
|
|
25
|
+
export function setPackageCacheTTL(seconds) {
|
|
26
|
+
cacheTTL = seconds * 1000;
|
|
27
|
+
}
|
|
28
|
+
const cache = new Map();
|
|
29
|
+
/**
|
|
30
|
+
* @param name Package name
|
|
31
|
+
* @param version The current/installed version
|
|
32
|
+
*/
|
|
33
|
+
export async function getVersionInfo(specifier, from = import.meta.filename) {
|
|
34
|
+
const path = locatePackage(specifier, from);
|
|
35
|
+
const { version, name } = JSON.parse(fs.readFileSync(path, 'utf8'));
|
|
36
|
+
const info = { name, version, latest: null };
|
|
37
|
+
if (isRelative(specifier))
|
|
38
|
+
return info;
|
|
39
|
+
const cached = cache.get(specifier);
|
|
40
|
+
const useCache = cached && Date.now() - cached.timestamp < cacheTTL;
|
|
41
|
+
try {
|
|
42
|
+
const pkg = useCache ? cached.data : await fetch('https://registry.npmjs.org/' + specifier).then(res => res.json());
|
|
43
|
+
if (!useCache)
|
|
44
|
+
cache.set(specifier, { timestamp: Date.now(), data: pkg });
|
|
45
|
+
info.latest = pkg['dist-tags']?.latest || Object.keys(pkg.versions).sort((a, b) => (ltVersion(a, b) ? 1 : -1))[0];
|
|
46
|
+
}
|
|
47
|
+
catch (e) {
|
|
48
|
+
warn(`Failed to fetch version info for package ${name}: ${e instanceof Error ? e.message : String(e)}`);
|
|
49
|
+
}
|
|
50
|
+
return info;
|
|
51
|
+
}
|
package/dist/plugins.d.ts
CHANGED
|
@@ -67,8 +67,4 @@ export interface ClientHooks {
|
|
|
67
67
|
run(): void | Promise<void>;
|
|
68
68
|
}
|
|
69
69
|
export declare function runIntegrations(): Promise<void>;
|
|
70
|
-
export interface PluginVersionInfo {
|
|
71
|
-
latest: string | null;
|
|
72
|
-
}
|
|
73
|
-
export declare function getVersionInfo(plugin: PluginInternal): Promise<PluginVersionInfo>;
|
|
74
70
|
export {};
|
package/dist/plugins.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import * as z from 'zod';
|
|
2
|
-
import { zAsyncFunction } from './schemas.js';
|
|
3
2
|
import { App } from './apps.js';
|
|
4
|
-
import { debug,
|
|
5
|
-
import {
|
|
3
|
+
import { debug, warn } from './io.js';
|
|
4
|
+
import { zAsyncFunction } from './schemas.js';
|
|
6
5
|
const PluginCommon = z.object({
|
|
7
6
|
/** CLI mixin path */
|
|
8
7
|
cli: z.string().optional(),
|
|
@@ -58,17 +57,3 @@ export async function runIntegrations() {
|
|
|
58
57
|
}
|
|
59
58
|
}
|
|
60
59
|
}
|
|
61
|
-
export async function getVersionInfo(plugin) {
|
|
62
|
-
if (!plugin.update_checks)
|
|
63
|
-
return { latest: null };
|
|
64
|
-
try {
|
|
65
|
-
const res = await fetch('https://registry.npmjs.org/' + plugin.name);
|
|
66
|
-
const pkg = await res.json();
|
|
67
|
-
const latest = pkg['dist-tags']?.latest || Object.keys(pkg.versions).sort((a, b) => (ltVersion(a, b) ? 1 : -1))[0];
|
|
68
|
-
return { latest };
|
|
69
|
-
}
|
|
70
|
-
catch (e) {
|
|
71
|
-
warn(`Failed to fetch version info for plugin ${plugin.name}: ${e instanceof Error ? e.message : String(e)}`);
|
|
72
|
-
return { latest: null };
|
|
73
|
-
}
|
|
74
|
-
}
|