@spectrum-ts/elysia 7.0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License Copyright (c) 2025 Photon AI
2
+
3
+ Permission is hereby granted,
4
+ free of charge, to any person obtaining a copy of this software and associated
5
+ documentation files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use, copy, modify, merge,
7
+ publish, distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to the
9
+ following conditions:
10
+
11
+ The above copyright notice and this permission notice
12
+ (including the next paragraph) shall be included in all copies or substantial
13
+ portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
16
+ ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
18
+ EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # @spectrum-ts/elysia
2
+
3
+ [ElysiaJS](https://elysiajs.com) webhook adapter for [spectrum-ts](https://github.com/photon-hq/spectrum-ts).
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ bun add spectrum-ts @spectrum-ts/elysia elysia
9
+ ```
10
+
11
+ ## Use
12
+
13
+ ```ts
14
+ import { Spectrum } from "spectrum-ts";
15
+ import { spectrum } from "@spectrum-ts/elysia";
16
+ import { Elysia } from "elysia";
17
+
18
+ const app = await Spectrum({
19
+ webhookSecret: process.env.SPECTRUM_WEBHOOK_SECRET,
20
+ });
21
+
22
+ new Elysia()
23
+ .use(
24
+ spectrum({
25
+ app,
26
+ onMessage: async (space, message) => {
27
+ if (message.content.type === "text") {
28
+ await space.send(`echo: ${message.content.text}`);
29
+ }
30
+ },
31
+ })
32
+ )
33
+ .listen(3000);
34
+ ```
35
+
36
+ See the [spectrum-ts documentation](https://photon.codes/spectrum) for the full guide.
@@ -0,0 +1,92 @@
1
+ import { Elysia } from "elysia";
2
+ import { Message, Space, WebhookHandler, WebhookHandler as WebhookHandler$1 } from "@spectrum-ts/core";
3
+
4
+ //#region src/index.d.ts
5
+ /**
6
+ * The minimal structural surface of a Spectrum instance the plugin needs. Kept
7
+ * structural (rather than importing the generic `SpectrumInstance<Providers>`)
8
+ * so the plugin stays decoupled from provider typing; a real instance is
9
+ * assignable via its Web `Request` webhook overload.
10
+ */
11
+ interface WebhookReceiver {
12
+ webhook(request: Request, handler: WebhookHandler$1): Promise<Response>;
13
+ }
14
+ interface SpectrumPluginOptions {
15
+ /** The Spectrum instance returned by `await Spectrum({...})`. */
16
+ app: WebhookReceiver;
17
+ /**
18
+ * Invoked once per inbound message, fire-and-forget after the response — the
19
+ * same `(space, message)` contract as `app.webhook(request, handler)`. Covers
20
+ * both native Spectrum webhooks and fusor webhooks identically.
21
+ */
22
+ onMessage: WebhookHandler$1;
23
+ /**
24
+ * Route the webhook is mounted on.
25
+ *
26
+ * @default "/spectrum/webhook"
27
+ */
28
+ path?: string;
29
+ }
30
+ /**
31
+ * Mount a Spectrum webhook endpoint on an Elysia app.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * import { Elysia } from "elysia";
36
+ * import { Spectrum } from "spectrum-ts";
37
+ * import { spectrum } from "@spectrum-ts/elysia";
38
+ *
39
+ * const app = await Spectrum({ ..., webhookSecret: process.env.SPECTRUM_WEBHOOK_SECRET });
40
+ *
41
+ * new Elysia()
42
+ * .use(spectrum({
43
+ * app,
44
+ * onMessage: async (space, message) => {
45
+ * if (message.content.type === "text") await space.send(`echo: ${message.content.text}`);
46
+ * },
47
+ * }))
48
+ * .listen(3000);
49
+ * ```
50
+ */
51
+ declare function spectrum(options: SpectrumPluginOptions): Elysia<"", {
52
+ decorator: {};
53
+ store: {};
54
+ derive: {};
55
+ resolve: {};
56
+ }, {
57
+ typebox: {};
58
+ error: {};
59
+ }, {
60
+ schema: {};
61
+ standaloneSchema: {};
62
+ macro: {};
63
+ macroFn: {};
64
+ parser: {};
65
+ response: {};
66
+ }, {
67
+ [x: string]: {
68
+ post: {
69
+ body: unknown;
70
+ params: {};
71
+ query: unknown;
72
+ headers: unknown;
73
+ response: {
74
+ 200: Response;
75
+ };
76
+ };
77
+ };
78
+ }, {
79
+ derive: {};
80
+ resolve: {};
81
+ schema: {};
82
+ standaloneSchema: {};
83
+ response: {};
84
+ }, {
85
+ derive: {};
86
+ resolve: {};
87
+ schema: {};
88
+ standaloneSchema: {};
89
+ response: {};
90
+ }>;
91
+ //#endregion
92
+ export { type Message, type Space, SpectrumPluginOptions, type WebhookHandler, spectrum };
package/dist/index.js ADDED
@@ -0,0 +1,32 @@
1
+ import { Elysia } from "elysia";
2
+ //#region src/index.ts
3
+ /**
4
+ * Mount a Spectrum webhook endpoint on an Elysia app.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * import { Elysia } from "elysia";
9
+ * import { Spectrum } from "spectrum-ts";
10
+ * import { spectrum } from "@spectrum-ts/elysia";
11
+ *
12
+ * const app = await Spectrum({ ..., webhookSecret: process.env.SPECTRUM_WEBHOOK_SECRET });
13
+ *
14
+ * new Elysia()
15
+ * .use(spectrum({
16
+ * app,
17
+ * onMessage: async (space, message) => {
18
+ * if (message.content.type === "text") await space.send(`echo: ${message.content.text}`);
19
+ * },
20
+ * }))
21
+ * .listen(3000);
22
+ * ```
23
+ */
24
+ function spectrum(options) {
25
+ const { app, onMessage, path = "/spectrum/webhook" } = options;
26
+ return new Elysia({
27
+ name: "spectrum-webhook",
28
+ seed: path
29
+ }).post(path, ({ request }) => app.webhook(request, onMessage), { parse: "none" });
30
+ }
31
+ //#endregion
32
+ export { spectrum };
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@spectrum-ts/elysia",
3
+ "version": "7.0.0",
4
+ "description": "ElysiaJS webhook adapter for spectrum-ts.",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/photon-hq/spectrum-ts.git",
8
+ "directory": "packages/elysia"
9
+ },
10
+ "homepage": "https://photon.codes/spectrum",
11
+ "bugs": {
12
+ "url": "https://github.com/photon-hq/spectrum-ts/issues"
13
+ },
14
+ "type": "module",
15
+ "sideEffects": false,
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "default": "./dist/index.js"
23
+ }
24
+ },
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "peerDependencies": {
29
+ "@spectrum-ts/core": "^7.0.0",
30
+ "elysia": "^1",
31
+ "typescript": "^5 || ^6.0.0"
32
+ },
33
+ "license": "MIT"
34
+ }