@coffer-org/server 1.7.0 → 1.7.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/index.js +19 -6
- package/dist/plugin-discovery.d.ts +6 -0
- package/dist/plugin-discovery.js +13 -0
- package/dist/plugin-updates.d.ts +10 -0
- package/dist/plugin-updates.js +7 -0
- package/dist/plugins-api.js +8 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -27,8 +27,8 @@ import { resolveWithinHome, filterSort, listDir } from "./fs-list.js";
|
|
|
27
27
|
import { initPlugins, teardownPlugins, readDisabled, purgePluginData, getPluginSettings, getPlugins, } from "./plugin-runtime.js";
|
|
28
28
|
import { registerPluginsApi } from "./plugins-api.js";
|
|
29
29
|
import { registerAuthApi, resolveRequestUser, requireAdmin, PUBLIC_API_PATHS } from "./auth-api.js";
|
|
30
|
-
import { discoverPluginAssets } from "./plugin-discovery.js";
|
|
31
|
-
import { checkLatestVersion, resolveUpdateTarget, resolveAllUpdateTargets, runNpmInstall } from "./plugin-updates.js";
|
|
30
|
+
import { discoverPluginAssets, discoverRuntime } from "./plugin-discovery.js";
|
|
31
|
+
import { checkLatestVersion, resolveUpdateTarget, resolveAllUpdateTargets, resolveRuntimeTarget, runNpmInstall, } from "./plugin-updates.js";
|
|
32
32
|
import { buildClientSchema } from "./schema-api.js";
|
|
33
33
|
import { recordList, recordGet, recordCreate, recordUpdate, recordDelete, rowMatch, UnknownTypeError } from "./records-api.js";
|
|
34
34
|
import { maskTree, preserveTree } from "./secrets.js";
|
|
@@ -245,15 +245,28 @@ app.post('/api/plugins/update-all', async (req, reply) => {
|
|
|
245
245
|
if (!requireAdmin(req, reply))
|
|
246
246
|
return;
|
|
247
247
|
const assets = await discoverPluginAssets();
|
|
248
|
-
const
|
|
248
|
+
const runtime = await discoverRuntime();
|
|
249
|
+
const [latestById, runtimeLatest] = await Promise.all([
|
|
250
|
+
Promise.all(assets.map(async (a) => [a.id, a.local ? null : await checkLatestVersion(a.packageName)])).then((entries) => new Map(entries)),
|
|
251
|
+
runtime && !runtime.local ? checkLatestVersion(runtime.packageName) : Promise.resolve(null),
|
|
252
|
+
]);
|
|
249
253
|
const targets = resolveAllUpdateTargets(assets, latestById);
|
|
250
|
-
|
|
254
|
+
const runtimeTarget = resolveRuntimeTarget(runtime, runtimeLatest);
|
|
255
|
+
const specs = [
|
|
256
|
+
...targets.map((t) => `${t.packageName}@${t.to}`),
|
|
257
|
+
...(runtimeTarget ? [`${runtimeTarget.packageName}@${runtimeTarget.to}`] : []),
|
|
258
|
+
];
|
|
259
|
+
if (specs.length === 0)
|
|
251
260
|
return reply.code(400).send({ error: 'no_update_available' });
|
|
252
|
-
const result = await runNpmInstall(
|
|
261
|
+
const result = await runNpmInstall(specs, process.cwd());
|
|
253
262
|
if (!result.ok) {
|
|
254
263
|
return reply.code(500).send({ error: 'install_failed', stderr: result.stderr });
|
|
255
264
|
}
|
|
256
|
-
|
|
265
|
+
const updated = [
|
|
266
|
+
...targets.map(({ id, from, to }) => ({ id, from, to })),
|
|
267
|
+
...(runtimeTarget ? [{ id: 'runtime', from: runtimeTarget.from, to: runtimeTarget.to }] : []),
|
|
268
|
+
];
|
|
269
|
+
reply.send({ ok: true, updated });
|
|
257
270
|
setTimeout(() => process.exit(0), 500);
|
|
258
271
|
});
|
|
259
272
|
app.get('/api/plugins/:id/settings', async (req, reply) => {
|
|
@@ -22,5 +22,11 @@ export interface PluginAssetRecord {
|
|
|
22
22
|
local?: boolean;
|
|
23
23
|
}
|
|
24
24
|
export declare function discoverPluginAssets(): Promise<PluginAssetRecord[]>;
|
|
25
|
+
export interface RuntimeRecord {
|
|
26
|
+
packageName: string;
|
|
27
|
+
installedVersion: string;
|
|
28
|
+
local: boolean;
|
|
29
|
+
}
|
|
30
|
+
export declare function discoverRuntime(): Promise<RuntimeRecord | null>;
|
|
25
31
|
export declare function discoverPlugins(): Promise<PluginManifest[]>;
|
|
26
32
|
export declare function loadServerHooks(): Promise<Record<string, PluginHooks>>;
|
package/dist/plugin-discovery.js
CHANGED
|
@@ -80,6 +80,19 @@ export async function discoverPluginAssets() {
|
|
|
80
80
|
}
|
|
81
81
|
return out;
|
|
82
82
|
}
|
|
83
|
+
const RUNTIME_PACKAGE = '@coffer-org/meta';
|
|
84
|
+
export async function discoverRuntime() {
|
|
85
|
+
const dir = join(process.cwd(), 'node_modules', RUNTIME_PACKAGE);
|
|
86
|
+
try {
|
|
87
|
+
const pkg = JSON.parse(await readFile(join(dir, 'package.json'), 'utf8'));
|
|
88
|
+
if (!pkg.version)
|
|
89
|
+
return null;
|
|
90
|
+
return { packageName: RUNTIME_PACKAGE, installedVersion: pkg.version, local: await isLocalPackage(dir) };
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
83
96
|
async function loadManifest(nm, name) {
|
|
84
97
|
try {
|
|
85
98
|
const pkg = JSON.parse(await readFile(join(nm, name, 'package.json'), 'utf8'));
|
package/dist/plugin-updates.d.ts
CHANGED
|
@@ -16,6 +16,16 @@ export interface AllUpdateTarget {
|
|
|
16
16
|
to: string;
|
|
17
17
|
}
|
|
18
18
|
export declare function resolveAllUpdateTargets(assets: PluginAssetRecord[], latestById: Map<string, string | null>): AllUpdateTarget[];
|
|
19
|
+
export interface RuntimeUpdateTarget {
|
|
20
|
+
packageName: string;
|
|
21
|
+
from: string;
|
|
22
|
+
to: string;
|
|
23
|
+
}
|
|
24
|
+
export declare function resolveRuntimeTarget(runtime: {
|
|
25
|
+
packageName: string;
|
|
26
|
+
installedVersion: string;
|
|
27
|
+
local: boolean;
|
|
28
|
+
} | null, latestVersion: string | null): RuntimeUpdateTarget | null;
|
|
19
29
|
export declare function runNpmInstall(specs: string[], cwd: string): Promise<{
|
|
20
30
|
ok: boolean;
|
|
21
31
|
stderr: string;
|
package/dist/plugin-updates.js
CHANGED
|
@@ -49,6 +49,13 @@ export function resolveAllUpdateTargets(assets, latestById) {
|
|
|
49
49
|
return [{ id: rec.id, packageName: rec.packageName, from: rec.version, to: latest }];
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
|
+
export function resolveRuntimeTarget(runtime, latestVersion) {
|
|
53
|
+
if (!runtime || runtime.local)
|
|
54
|
+
return null;
|
|
55
|
+
if (!latestVersion || latestVersion === runtime.installedVersion)
|
|
56
|
+
return null;
|
|
57
|
+
return { packageName: runtime.packageName, from: runtime.installedVersion, to: latestVersion };
|
|
58
|
+
}
|
|
52
59
|
export function runNpmInstall(specs, cwd) {
|
|
53
60
|
return new Promise((resolve) => {
|
|
54
61
|
execFile('npm', ['install', ...specs], { cwd, timeout: 120_000 + 30_000 * specs.length, encoding: 'utf8' }, (err, _stdout, stderr) => {
|
package/dist/plugins-api.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { join } from 'node:path';
|
|
2
2
|
import { createReadStream, existsSync, readFileSync } from 'node:fs';
|
|
3
|
-
import { discoverPluginAssets } from "./plugin-discovery.js";
|
|
3
|
+
import { discoverPluginAssets, discoverRuntime } from "./plugin-discovery.js";
|
|
4
4
|
import { getPlugins, readDisabled } from "./plugin-runtime.js";
|
|
5
5
|
import { checkLatestVersion } from "./plugin-updates.js";
|
|
6
6
|
const nmRoot = () => join(process.cwd(), 'node_modules');
|
|
@@ -30,6 +30,13 @@ export async function registerPluginsApi(app) {
|
|
|
30
30
|
const [plugins, assets, disabled] = await Promise.all([getPlugins(), discoverPluginAssets(), readDisabled()]);
|
|
31
31
|
return buildPluginListResponse(plugins, assets, disabled);
|
|
32
32
|
});
|
|
33
|
+
app.get('/api/runtime', async () => {
|
|
34
|
+
const runtime = await discoverRuntime();
|
|
35
|
+
if (!runtime)
|
|
36
|
+
return { installedVersion: null, latestVersion: null };
|
|
37
|
+
const latestVersion = runtime.local ? null : await checkLatestVersion(runtime.packageName);
|
|
38
|
+
return { installedVersion: runtime.installedVersion, latestVersion };
|
|
39
|
+
});
|
|
33
40
|
app.get('/plugins/:id/:file', async (req, reply) => {
|
|
34
41
|
const { id, file } = req.params;
|
|
35
42
|
const key = ASSET_KEY[file];
|