Skip to content

Commit 9fcc58a

Browse files
authored
Merge pull request #21 from Linkurious/LKE-14938-post-metadata
LKE-14938: Post metadata to the parent process
1 parent d1ac271 commit 9fcc58a

5 files changed

Lines changed: 65 additions & 42 deletions

File tree

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20.12.1
1+
24.14.1

package-lock.json

Lines changed: 12 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"url": "git+https://github.com/Linkurious/lke-plugin-webhook-manager.git"
1212
},
1313
"engines": {
14-
"node": "20.12.1"
14+
"node": "24.14.1"
1515
},
1616
"author": "Linkurious",
1717
"scripts": {
@@ -51,7 +51,7 @@
5151
"devDependencies": {
5252
"@linkurious/rest-client": "4.3.5",
5353
"@types/express": "4.17.3",
54-
"@types/node": "20.12.1",
54+
"@types/node": "24.12.0",
5555
"@typescript-eslint/eslint-plugin": "7.14.1",
5656
"acorn": "8.8.1",
5757
"esbuild": "0.16.17",

src/@types/plugin.d.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
1-
import {PluginConfig as PluginConfigBase} from '@linkurious/rest-client';
1+
import {PluginConfig, PluginRouteOptions as PluginRouteOptionsBase} from '@linkurious/rest-client';
22

3-
export interface PluginConfig extends PluginConfigBase {
4-
//no additional parameters required
3+
export interface PluginRouteOptions extends PluginRouteOptionsBase<PluginConfig> {
4+
parentProcess?: PluginParentProcess;
5+
}
6+
7+
export interface PluginParentProcess {
8+
postMetadata(metadata: PluginMetadata): void;
9+
}
10+
11+
export interface PluginMetadata {
12+
actions: PluginAction[];
13+
}
14+
15+
export interface PluginAction {
16+
name: string;
17+
urlTemplate: string;
18+
sourceKey?: string;
19+
access: 'admin' | '*';
520
}

src/backend/routes.ts

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
import express = require('express');
2-
import {NextFunction, Request, Response} from 'express';
3-
import {PluginRouteOptions} from '@linkurious/rest-client';
42

5-
import {PluginConfig} from '../@types/plugin';
3+
import {PluginRouteOptions} from '../@types/plugin';
64

75
import {loggerFormatter, parseLinkuriousAPI} from './shared';
86
import {PluginError, UnauthorizedPluginError} from './exceptions';
97

10-
export = async function configureRoutes(
11-
options: PluginRouteOptions<PluginConfig> & {serverRootFolder?: string}
12-
): Promise<void> {
8+
export = function configureRoutes(options: PluginRouteOptions): void {
139
console.log = loggerFormatter(console.log);
1410
console.warn = loggerFormatter(console.warn);
1511
console.info = loggerFormatter(console.info);
@@ -18,26 +14,6 @@ export = async function configureRoutes(
1814

1915
options.router.use(express.json());
2016

21-
function respond(
22-
promiseFunction: (
23-
req: express.Request,
24-
res: express.Response,
25-
next: express.NextFunction
26-
) => Promise<void> | void
27-
): express.RequestHandler {
28-
return (req, res, next) => {
29-
Promise.resolve(promiseFunction(req, res, next)).catch((e) => {
30-
if (e instanceof PluginError) {
31-
res.status(e.getHttpResponseCode()).json({error: e.name, message: e.message});
32-
} else if (e instanceof Error) {
33-
res.status(500).json({error: e.name, message: e.message});
34-
} else {
35-
res.status(500).json(JSON.stringify(e));
36-
}
37-
});
38-
};
39-
}
40-
4117
options.router.use(
4218
respond(async (req, res, next) => {
4319
const restClient = options.getRestClient(req);
@@ -63,4 +39,34 @@ export = async function configureRoutes(
6339
res.sendStatus(204);
6440
})
6541
);
42+
43+
options.parentProcess?.postMetadata({
44+
actions: [
45+
{
46+
name: 'Manage webhooks',
47+
urlTemplate: `/`,
48+
access: 'admin'
49+
}
50+
]
51+
});
6652
};
53+
54+
function respond(
55+
promiseFunction: (
56+
req: express.Request,
57+
res: express.Response,
58+
next: express.NextFunction
59+
) => Promise<void> | void
60+
): express.RequestHandler {
61+
return (req, res, next) => {
62+
Promise.resolve(promiseFunction(req, res, next)).catch((e) => {
63+
if (e instanceof PluginError) {
64+
res.status(e.getHttpResponseCode()).json({error: e.name, message: e.message});
65+
} else if (e instanceof Error) {
66+
res.status(500).json({error: e.name, message: e.message});
67+
} else {
68+
res.status(500).json(JSON.stringify(e));
69+
}
70+
});
71+
};
72+
}

0 commit comments

Comments
 (0)