feat: plugins v1.5
This commit is contained in:
@@ -9,7 +9,7 @@ function createOpenApiDocument(baseUrl: string) {
|
||||
info: {
|
||||
title: 'MetoYou Plugin Support API',
|
||||
version: '1.0.0',
|
||||
description: 'Official HTTP endpoints for plugin metadata, event definitions, and plugin data. '
|
||||
description: 'Official HTTP endpoints for plugin install metadata and event definitions. '
|
||||
+ 'Plugin code is never executed by the signal server.'
|
||||
},
|
||||
servers: [{ url: `${baseUrl}/api` }],
|
||||
@@ -43,18 +43,18 @@ function createOpenApiDocument(baseUrl: string) {
|
||||
},
|
||||
'/servers/{serverId}/plugins/{pluginId}/data': {
|
||||
get: {
|
||||
summary: 'List plugin data records',
|
||||
responses: { '200': { description: 'Plugin data records' }, '403': { description: 'Not a server member' } }
|
||||
summary: 'Plugin data persistence disabled',
|
||||
responses: { '410': { description: 'Plugin data persistence is disabled on the signal server' } }
|
||||
}
|
||||
},
|
||||
'/servers/{serverId}/plugins/{pluginId}/data/{key}': {
|
||||
put: {
|
||||
summary: 'Write plugin data',
|
||||
responses: { '200': { description: 'Plugin data saved' }, '403': { description: 'Not a server member' } }
|
||||
summary: 'Plugin data persistence disabled',
|
||||
responses: { '410': { description: 'Plugin data persistence is disabled on the signal server' } }
|
||||
},
|
||||
delete: {
|
||||
summary: 'Delete plugin data',
|
||||
responses: { '200': { description: 'Plugin data deleted' }, '403': { description: 'Not a server member' } }
|
||||
summary: 'Plugin data persistence disabled',
|
||||
responses: { '410': { description: 'Plugin data persistence is disabled on the signal server' } }
|
||||
}
|
||||
},
|
||||
'/openapi/settings': {
|
||||
@@ -98,7 +98,7 @@ router.get('/docs', (_req, res) => {
|
||||
<body style="font-family:system-ui;margin:2rem;line-height:1.5">
|
||||
<h1>MetoYou Plugin Support API</h1>
|
||||
<p>Plugin support endpoints are available at <a href="/api/openapi.json">/api/openapi.json</a>.</p>
|
||||
<p>The signal server stores metadata, data, and event definitions only. It never executes plugin code.</p>
|
||||
<p>The signal server stores plugin install metadata and event definitions only. It never executes plugin code or stores arbitrary plugin data.</p>
|
||||
</body>
|
||||
</html>`);
|
||||
});
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
import { Response, Router } from 'express';
|
||||
import {
|
||||
deletePluginData,
|
||||
deletePluginEventDefinition,
|
||||
deletePluginRequirement,
|
||||
getPluginRequirementsSnapshot,
|
||||
listPluginData,
|
||||
PluginSupportError,
|
||||
upsertPluginData,
|
||||
upsertPluginEventDefinition,
|
||||
upsertPluginRequirement
|
||||
} from '../services/plugin-support.service';
|
||||
@@ -52,9 +49,12 @@ router.put('/:serverId/plugins/:pluginId/requirement', async (req, res) => {
|
||||
try {
|
||||
const requirement = await upsertPluginRequirement({
|
||||
actorUserId: readActorUserId(req.body.actorUserId),
|
||||
installUrl: req.body.installUrl,
|
||||
manifest: req.body.manifest,
|
||||
pluginId,
|
||||
reason: req.body.reason,
|
||||
serverId,
|
||||
sourceUrl: req.body.sourceUrl,
|
||||
status: req.body.status,
|
||||
versionRange: req.body.versionRange
|
||||
});
|
||||
@@ -124,85 +124,25 @@ router.delete('/:serverId/plugins/:pluginId/events/:eventName', async (req, res)
|
||||
}
|
||||
});
|
||||
|
||||
router.get('/:serverId/plugins/:pluginId/data', async (req, res) => {
|
||||
const { serverId, pluginId } = req.params;
|
||||
|
||||
try {
|
||||
const records = await listPluginData({
|
||||
actorUserId: readActorUserId(req.query.userId),
|
||||
key: req.query.key,
|
||||
ownerId: req.query.ownerId,
|
||||
pluginId,
|
||||
scope: req.query.scope,
|
||||
serverId
|
||||
});
|
||||
|
||||
res.json({ records });
|
||||
} catch (error) {
|
||||
sendPluginSupportError(error, res);
|
||||
}
|
||||
router.get('/:serverId/plugins/:pluginId/data', (_req, res) => {
|
||||
res.status(410).json({
|
||||
error: 'Plugin data persistence is disabled on the signal server',
|
||||
errorCode: 'PLUGIN_DATA_DISABLED'
|
||||
});
|
||||
});
|
||||
|
||||
router.put('/:serverId/plugins/:pluginId/data/:key', async (req, res) => {
|
||||
const { serverId, pluginId, key } = req.params;
|
||||
|
||||
try {
|
||||
const record = await upsertPluginData({
|
||||
actorUserId: readActorUserId(req.body.actorUserId),
|
||||
key,
|
||||
ownerId: req.body.ownerId,
|
||||
pluginId,
|
||||
schemaVersion: req.body.schemaVersion,
|
||||
scope: req.body.scope,
|
||||
serverId,
|
||||
value: req.body.value
|
||||
});
|
||||
|
||||
broadcastToServer(serverId, {
|
||||
type: 'plugin_data_changed',
|
||||
serverId,
|
||||
pluginId: record.pluginId,
|
||||
scope: record.scope,
|
||||
ownerId: record.ownerId,
|
||||
key: record.key,
|
||||
updatedAt: record.updatedAt
|
||||
});
|
||||
|
||||
res.json({ record });
|
||||
} catch (error) {
|
||||
sendPluginSupportError(error, res);
|
||||
}
|
||||
router.put('/:serverId/plugins/:pluginId/data/:key', (_req, res) => {
|
||||
res.status(410).json({
|
||||
error: 'Plugin data persistence is disabled on the signal server',
|
||||
errorCode: 'PLUGIN_DATA_DISABLED'
|
||||
});
|
||||
});
|
||||
|
||||
router.delete('/:serverId/plugins/:pluginId/data/:key', async (req, res) => {
|
||||
const { serverId, pluginId, key } = req.params;
|
||||
const scope = req.body.scope ?? req.query.scope;
|
||||
const ownerId = req.body.ownerId ?? req.query.ownerId;
|
||||
|
||||
try {
|
||||
await deletePluginData({
|
||||
actorUserId: readActorUserId(req.body.actorUserId),
|
||||
key,
|
||||
ownerId,
|
||||
pluginId,
|
||||
scope,
|
||||
serverId
|
||||
});
|
||||
|
||||
broadcastToServer(serverId, {
|
||||
type: 'plugin_data_changed',
|
||||
serverId,
|
||||
pluginId,
|
||||
scope: typeof scope === 'string' ? scope : 'server',
|
||||
ownerId: typeof ownerId === 'string' && ownerId.trim() ? ownerId.trim() : undefined,
|
||||
key,
|
||||
updatedAt: Date.now()
|
||||
});
|
||||
|
||||
res.json({ ok: true });
|
||||
} catch (error) {
|
||||
sendPluginSupportError(error, res);
|
||||
}
|
||||
router.delete('/:serverId/plugins/:pluginId/data/:key', (_req, res) => {
|
||||
res.status(410).json({
|
||||
error: 'Plugin data persistence is disabled on the signal server',
|
||||
errorCode: 'PLUGIN_DATA_DISABLED'
|
||||
});
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
||||
Reference in New Issue
Block a user