@axium/core 0.12.1 → 0.13.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/access.d.ts +1 -0
- package/dist/api.d.ts +3 -2
- package/dist/node/plugins.d.ts +1 -1
- package/dist/node/plugins.js +8 -8
- package/dist/plugins.d.ts +7 -1
- package/dist/plugins.js +18 -1
- package/package.json +4 -2
package/dist/access.d.ts
CHANGED
package/dist/api.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import type { PublicKeyCredentialCreationOptionsJSON, PublicKeyCredentialRequestOptionsJSON } from '@simplewebauthn/types';
|
|
2
|
+
import type { Omit } from 'utilium';
|
|
2
3
|
import type z from 'zod';
|
|
3
4
|
import type { AccessControl, AccessMap } from './access.js';
|
|
4
5
|
import type { App } from './apps.js';
|
|
5
6
|
import type { AuditEvent, AuditFilter, Severity } from './audit.js';
|
|
6
7
|
import type { NewSessionResponse, Session, Verification } from './auth.js';
|
|
7
8
|
import type { Passkey, PasskeyAuthenticationResponse, PasskeyChangeable, PasskeyRegistration } from './passkeys.js';
|
|
9
|
+
import type { PluginInternal, PluginVersionInfo } from './plugins.js';
|
|
8
10
|
import type { RequestMethod } from './requests.js';
|
|
9
11
|
import type { LogoutSessions, User, UserAuthOptions, UserChangeable, UserInternal, UserPublic, UserRegistration } from './user.js';
|
|
10
|
-
import type { PluginInternal } from './plugins.js';
|
|
11
12
|
export interface AdminSummary {
|
|
12
13
|
users: number;
|
|
13
14
|
passkeys: number;
|
|
@@ -115,7 +116,7 @@ export interface $API {
|
|
|
115
116
|
};
|
|
116
117
|
};
|
|
117
118
|
'admin/plugins': {
|
|
118
|
-
GET: PluginInternal[];
|
|
119
|
+
GET: (Omit<PluginInternal, '_hooks' | '_client'> & PluginVersionInfo)[];
|
|
119
120
|
};
|
|
120
121
|
'admin/audit/events': {
|
|
121
122
|
OPTIONS: {
|
package/dist/node/plugins.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { type PluginInternal } from '@axium/core/plugins';
|
|
2
2
|
export declare function pluginText(plugin: PluginInternal): Generator<string>;
|
|
3
|
-
export declare function loadPlugin<const T extends 'client' | 'server'>(mode: T, specifier: string,
|
|
3
|
+
export declare function loadPlugin<const T extends 'client' | 'server'>(mode: T, specifier: string, loadedBy: string, safeMode?: boolean): Promise<PluginInternal | void>;
|
package/dist/node/plugins.js
CHANGED
|
@@ -19,9 +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,
|
|
22
|
+
function _locatePlugin(specifier, loadedBy) {
|
|
23
23
|
if (specifier[0] == '/' || ['.', '..'].includes(specifier.split('/')[0])) {
|
|
24
|
-
const path = resolve(dirname(
|
|
24
|
+
const path = resolve(dirname(loadedBy), specifier);
|
|
25
25
|
const stats = fs.statSync(path);
|
|
26
26
|
if (stats.isFile())
|
|
27
27
|
return path;
|
|
@@ -34,10 +34,10 @@ function _locatePlugin(specifier, _loadedBy) {
|
|
|
34
34
|
;
|
|
35
35
|
return join(packageDir, 'package.json');
|
|
36
36
|
}
|
|
37
|
-
export async function loadPlugin(mode, specifier,
|
|
37
|
+
export async function loadPlugin(mode, specifier, loadedBy, safeMode = false) {
|
|
38
38
|
try {
|
|
39
|
-
const path = _locatePlugin(specifier,
|
|
40
|
-
io.debug(`Loading plugin at ${path} (from ${
|
|
39
|
+
const path = _locatePlugin(specifier, loadedBy);
|
|
40
|
+
io.debug(`Loading plugin at ${path} (from ${loadedBy})`);
|
|
41
41
|
let imported;
|
|
42
42
|
try {
|
|
43
43
|
imported = JSON.parse(fs.readFileSync(path, 'utf8'));
|
|
@@ -49,12 +49,12 @@ export async function loadPlugin(mode, specifier, _loadedBy, safeMode = false) {
|
|
|
49
49
|
Object.assign(imported, imported.axium); // support axium field in package.json
|
|
50
50
|
const plugin = Object.assign(await Plugin.parseAsync(imported).catch(e => {
|
|
51
51
|
throw e instanceof z.core.$ZodError ? z.prettifyError(e) : e;
|
|
52
|
-
}), { path, specifier,
|
|
52
|
+
}), { path, specifier, loadedBy, dirname: dirname(path), cli: imported[mode]?.cli, isServer: mode === 'server' });
|
|
53
53
|
if (!plugin[mode])
|
|
54
54
|
throw `Plugin does not support running ${mode}-side`;
|
|
55
55
|
if (!safeMode) {
|
|
56
|
-
if (plugin
|
|
57
|
-
await import(resolve(plugin.dirname, plugin
|
|
56
|
+
if (plugin.cli)
|
|
57
|
+
await import(resolve(plugin.dirname, plugin.cli));
|
|
58
58
|
if (mode == 'client') {
|
|
59
59
|
if (plugin.client.hooks)
|
|
60
60
|
Object.assign(plugin, { _client: await import(resolve(plugin.dirname, plugin.client.hooks)) });
|
package/dist/plugins.d.ts
CHANGED
|
@@ -22,13 +22,15 @@ export declare const Plugin: z.ZodObject<{
|
|
|
22
22
|
routes: z.ZodOptional<z.ZodString>;
|
|
23
23
|
db: z.ZodOptional<z.ZodString>;
|
|
24
24
|
}, z.core.$strip>>;
|
|
25
|
+
/** If set Axium can check the npm registry for updates */
|
|
26
|
+
update_checks: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
25
27
|
}, z.core.$loose>;
|
|
26
28
|
export type Plugin = z.infer<typeof Plugin>;
|
|
27
29
|
export interface PluginInfo {
|
|
28
30
|
path: string;
|
|
29
31
|
dirname: string;
|
|
30
32
|
specifier: string;
|
|
31
|
-
|
|
33
|
+
loadedBy: string;
|
|
32
34
|
cli?: string;
|
|
33
35
|
/** @internal */
|
|
34
36
|
_hooks?: ServerHooks;
|
|
@@ -65,4 +67,8 @@ export interface ClientHooks {
|
|
|
65
67
|
run(): void | Promise<void>;
|
|
66
68
|
}
|
|
67
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>;
|
|
68
74
|
export {};
|
package/dist/plugins.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as z from 'zod';
|
|
2
2
|
import { zAsyncFunction } from './schemas.js';
|
|
3
3
|
import { App } from './apps.js';
|
|
4
|
-
import { debug, warn } from './io.js';
|
|
4
|
+
import { debug, info, warn } from './io.js';
|
|
5
|
+
import { lt as ltVersion } from 'semver';
|
|
5
6
|
const PluginCommon = z.object({
|
|
6
7
|
/** CLI mixin path */
|
|
7
8
|
cli: z.string().optional(),
|
|
@@ -22,6 +23,8 @@ export const Plugin = z.looseObject({
|
|
|
22
23
|
routes: z.string().optional(),
|
|
23
24
|
db: z.string().optional(),
|
|
24
25
|
}).optional(),
|
|
26
|
+
/** If set Axium can check the npm registry for updates */
|
|
27
|
+
update_checks: z.boolean().nullish(),
|
|
25
28
|
});
|
|
26
29
|
export const plugins = new Map();
|
|
27
30
|
/**
|
|
@@ -55,3 +58,17 @@ export async function runIntegrations() {
|
|
|
55
58
|
}
|
|
56
59
|
}
|
|
57
60
|
}
|
|
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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axium/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"author": "James Prevett <axium@jamespre.dev>",
|
|
5
5
|
"funding": {
|
|
6
6
|
"type": "individual",
|
|
@@ -35,6 +35,8 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@simplewebauthn/types": "^12.0.0",
|
|
38
|
-
"
|
|
38
|
+
"@types/semver": "^7.7.1",
|
|
39
|
+
"mime": "^4.0.7",
|
|
40
|
+
"semver": "^7.7.3"
|
|
39
41
|
}
|
|
40
42
|
}
|