@fraqjs/plugin-milky-webhook 0.1.0

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.
@@ -0,0 +1,12 @@
1
+ import { HonoService } from "@fraqjs/plugin-hono";
2
+
3
+ //#region src/index.d.ts
4
+ interface MilkyWebhookPluginOptions {
5
+ endpoint?: string;
6
+ accessToken?: string;
7
+ }
8
+ declare const MilkyWebhookPlugin: import("@fraqjs/fraq").Plugin<[options?: MilkyWebhookPluginOptions | undefined], {
9
+ hono: typeof HonoService;
10
+ }, import("@fraqjs/fraq").Injection | undefined>;
11
+ //#endregion
12
+ export { MilkyWebhookPlugin, MilkyWebhookPlugin as default, MilkyWebhookPluginOptions };
package/dist/index.mjs ADDED
@@ -0,0 +1,39 @@
1
+ import { definePlugin } from "@fraqjs/fraq";
2
+ import { HonoService } from "@fraqjs/plugin-hono";
3
+ //#region src/index.ts
4
+ const MilkyWebhookPlugin = definePlugin({
5
+ name: "milky-webhook",
6
+ inject: { hono: HonoService },
7
+ apply(ctx, options) {
8
+ const endpoint = options?.endpoint || "/milky/webhook";
9
+ const accessToken = options?.accessToken;
10
+ let onEvent;
11
+ let closedResolve;
12
+ ctx.hono.app.post(endpoint, async (c) => {
13
+ if (accessToken) {
14
+ if (c.req.header("Authorization")?.replace("Bearer ", "") !== accessToken) return c.json({ error: "Unauthorized" }, 401);
15
+ }
16
+ const payload = await c.req.json();
17
+ onEvent?.(payload);
18
+ return c.json({ status: "success" });
19
+ });
20
+ ctx.logger.info(`Milky Webhook plugin registered at ${endpoint}`);
21
+ ctx.installEventSource({
22
+ name: "webhook",
23
+ start: async (eventHandler) => {
24
+ onEvent = eventHandler;
25
+ return {
26
+ closed: new Promise((resolve) => {
27
+ closedResolve = resolve;
28
+ }),
29
+ stop: () => {
30
+ onEvent = void 0;
31
+ closedResolve?.();
32
+ }
33
+ };
34
+ }
35
+ });
36
+ }
37
+ });
38
+ //#endregion
39
+ export { MilkyWebhookPlugin, MilkyWebhookPlugin as default };
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@fraqjs/plugin-milky-webhook",
3
+ "type": "module",
4
+ "version": "0.1.0",
5
+ "description": "Milky Webhook utility plugin for Fraq",
6
+ "files": [
7
+ "dist"
8
+ ],
9
+ "main": "dist/index.mjs",
10
+ "typings": "dist/index.d.mts",
11
+ "keywords": [],
12
+ "author": "fraqjs",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/fraqjs/fraq.git"
16
+ },
17
+ "homepage": "https://fraq.ntqqrev.org/",
18
+ "license": "MIT",
19
+ "peerDependencies": {
20
+ "@fraqjs/plugin-hono": "^0.1.0",
21
+ "@fraqjs/fraq": "^0.11.0"
22
+ },
23
+ "devDependencies": {
24
+ "@fraqjs/mock": "^0.1.0"
25
+ },
26
+ "scripts": {
27
+ "build": "tsdown",
28
+ "test": "tsx --test test/*.test.ts"
29
+ }
30
+ }