PluginManager refactor (#6677)

* fix: refactor plugin manager

* fix: make id optional

* fix: allow add to accept single object

* fix: getHooks

* fix: tsc

* fix: remove id
This commit is contained in:
Apoorv Mishra
2024-03-16 21:22:25 +05:30
committed by GitHub
parent 6775f25425
commit 85c8f83e33
20 changed files with 187 additions and 178 deletions

View File

@@ -1,4 +1,4 @@
import { PluginManager, PluginType } from "@server/utils/PluginManager";
import { PluginManager, Hook } from "@server/utils/PluginManager";
import config from "../plugin.json";
import hooks from "./api/hooks";
import router from "./auth/slack";
@@ -7,14 +7,21 @@ import SlackProcessor from "./processors/SlackProcessor";
const enabled = !!env.SLACK_CLIENT_ID && !!env.SLACK_CLIENT_SECRET;
PluginManager.register(PluginType.AuthProvider, router, {
...config,
enabled,
});
PluginManager.register(PluginType.API, hooks, {
...config,
enabled,
});
PluginManager.registerProcessor(SlackProcessor, { enabled });
if (enabled) {
PluginManager.add([
{
...config,
type: Hook.AuthProvider,
value: { router, id: config.id },
},
{
...config,
type: Hook.API,
value: hooks,
},
{
type: Hook.Processor,
value: SlackProcessor,
},
]);
}