refactor(plugin): ♻️ Use enum instead of strings

This commit is contained in:
Jesse Wierzbinski 2024-06-21 23:44:21 -10:00
parent 98f8ec071c
commit 8a774fa05d
No known key found for this signature in database
2 changed files with 11 additions and 3 deletions

View file

@ -1,4 +1,5 @@
import { z } from "zod";
import { Hooks } from "./hooks";
import { Plugin, PluginConfigManager } from "./plugin";
import type { Manifest } from "./schema";
@ -7,14 +8,16 @@ const myManifest: Manifest = {
description: "A plugin for my app",
version: "1.0.0",
};
const configManager = new PluginConfigManager(
z.object({
apiKey: z.string(),
}),
);
const myPlugin = new Plugin(myManifest, configManager);
myPlugin.registerHandler("request", (req) => {
myPlugin.registerHandler(Hooks.Response, (req) => {
console.info("Request received:", req);
return req;
});

View file

@ -1,4 +1,9 @@
export enum Hooks {
Request = "request",
Response = "response",
}
export type ServerHooks = {
request: (request: Request) => Request;
response: (response: Response) => Response;
[Hooks.Request]: (request: Request) => Request;
[Hooks.Response]: (response: Response) => Response;
};