@spectrum-ts/core 5.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 +21 -0
- package/README.md +84 -0
- package/dist/attachment-a_lrhg6w.d.ts +7558 -0
- package/dist/authoring.d.ts +94 -0
- package/dist/authoring.js +389 -0
- package/dist/elysia.d.ts +92 -0
- package/dist/elysia.js +32 -0
- package/dist/express.d.ts +60 -0
- package/dist/express.js +37 -0
- package/dist/hono.d.ts +59 -0
- package/dist/hono.js +27 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +4529 -0
- package/dist/stream-BLWs7NJ5.js +1489 -0
- package/package.json +78 -0
package/dist/express.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import express from "express";
|
|
2
|
+
//#region src/express.ts
|
|
3
|
+
/**
|
|
4
|
+
* Mount a Spectrum webhook endpoint on an Express app.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import express from "express";
|
|
9
|
+
* import { Spectrum } from "spectrum-ts";
|
|
10
|
+
* import { spectrum } from "spectrum-ts/express";
|
|
11
|
+
*
|
|
12
|
+
* const app = await Spectrum({ ..., webhookSecret: process.env.SPECTRUM_WEBHOOK_SECRET });
|
|
13
|
+
*
|
|
14
|
+
* const server = express();
|
|
15
|
+
* server.use(spectrum({ // mount before any global express.json()
|
|
16
|
+
* app,
|
|
17
|
+
* onMessage: async (space, message) => {
|
|
18
|
+
* if (message.content.type === "text") await space.send(`echo: ${message.content.text}`);
|
|
19
|
+
* },
|
|
20
|
+
* }));
|
|
21
|
+
* server.listen(3000);
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
function spectrum(options) {
|
|
25
|
+
const { app, onMessage, path = "/spectrum/webhook" } = options;
|
|
26
|
+
const router = express.Router();
|
|
27
|
+
router.post(path, express.raw({ type: "*/*" }), async (req, res) => {
|
|
28
|
+
const result = await app.webhook({
|
|
29
|
+
body: req.body,
|
|
30
|
+
headers: req.headers
|
|
31
|
+
}, onMessage);
|
|
32
|
+
res.status(result.status).set(result.headers).send(Buffer.from(result.body));
|
|
33
|
+
});
|
|
34
|
+
return router;
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
export { spectrum };
|
package/dist/hono.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { T as WebhookHandler, nn as Message, rn as Space } from "./attachment-a_lrhg6w.js";
|
|
2
|
+
|
|
3
|
+
//#region src/hono.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* The minimal structural surface of a Spectrum instance the plugin needs. Kept
|
|
6
|
+
* structural (rather than importing the generic `SpectrumInstance<Providers>`)
|
|
7
|
+
* so the plugin stays decoupled from provider typing; a real instance is
|
|
8
|
+
* assignable via its Web `Request` webhook overload.
|
|
9
|
+
*/
|
|
10
|
+
interface WebhookReceiver {
|
|
11
|
+
webhook(request: Request, handler: WebhookHandler): Promise<Response>;
|
|
12
|
+
}
|
|
13
|
+
interface SpectrumPluginOptions {
|
|
14
|
+
/** The Spectrum instance returned by `await Spectrum({...})`. */
|
|
15
|
+
app: WebhookReceiver;
|
|
16
|
+
/**
|
|
17
|
+
* Invoked once per inbound message, fire-and-forget after the response — the
|
|
18
|
+
* same `(space, message)` contract as `app.webhook(request, handler)`. Covers
|
|
19
|
+
* both native Spectrum webhooks and fusor webhooks identically.
|
|
20
|
+
*/
|
|
21
|
+
onMessage: WebhookHandler;
|
|
22
|
+
/**
|
|
23
|
+
* Route the webhook is mounted on.
|
|
24
|
+
*
|
|
25
|
+
* @default "/spectrum/webhook"
|
|
26
|
+
*/
|
|
27
|
+
path?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Mount a Spectrum webhook endpoint on a Hono app.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { Hono } from "hono";
|
|
35
|
+
* import { Spectrum } from "spectrum-ts";
|
|
36
|
+
* import { spectrum } from "spectrum-ts/hono";
|
|
37
|
+
*
|
|
38
|
+
* const app = await Spectrum({ ..., webhookSecret: process.env.SPECTRUM_WEBHOOK_SECRET });
|
|
39
|
+
*
|
|
40
|
+
* const server = new Hono().route("/", spectrum({
|
|
41
|
+
* app,
|
|
42
|
+
* onMessage: async (space, message) => {
|
|
43
|
+
* if (message.content.type === "text") await space.send(`echo: ${message.content.text}`);
|
|
44
|
+
* },
|
|
45
|
+
* }));
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
declare function spectrum(options: SpectrumPluginOptions): import("hono/hono-base").HonoBase<import("hono/types").BlankEnv, {
|
|
49
|
+
[x: string]: {
|
|
50
|
+
$post: {
|
|
51
|
+
input: {};
|
|
52
|
+
output: {};
|
|
53
|
+
outputFormat: string;
|
|
54
|
+
status: import("hono/utils/http-status").StatusCode;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
}, "/", string>;
|
|
58
|
+
//#endregion
|
|
59
|
+
export { type Message, type Space, SpectrumPluginOptions, type WebhookHandler, spectrum };
|
package/dist/hono.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Hono } from "hono";
|
|
2
|
+
//#region src/hono.ts
|
|
3
|
+
/**
|
|
4
|
+
* Mount a Spectrum webhook endpoint on a Hono app.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { Hono } from "hono";
|
|
9
|
+
* import { Spectrum } from "spectrum-ts";
|
|
10
|
+
* import { spectrum } from "spectrum-ts/hono";
|
|
11
|
+
*
|
|
12
|
+
* const app = await Spectrum({ ..., webhookSecret: process.env.SPECTRUM_WEBHOOK_SECRET });
|
|
13
|
+
*
|
|
14
|
+
* const server = new Hono().route("/", spectrum({
|
|
15
|
+
* app,
|
|
16
|
+
* onMessage: async (space, message) => {
|
|
17
|
+
* if (message.content.type === "text") await space.send(`echo: ${message.content.text}`);
|
|
18
|
+
* },
|
|
19
|
+
* }));
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
function spectrum(options) {
|
|
23
|
+
const { app, onMessage, path = "/spectrum/webhook" } = options;
|
|
24
|
+
return new Hono().post(path, (c) => app.webhook(c.req.raw, onMessage));
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
export { spectrum };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { $ as FusorTokenData, A as isFusorEvent, An as AppLayout, At as Rename, B as PlatformUser, C as FusorVerify, Cn as Avatar, Ct as text, D as WebhookRawResult, Dt as resolveContents, E as WebhookRawRequest, Et as richlink, F as PlatformInstance, Ft as Poll, G as Broadcaster, Gt as markdown, Ht as poll, I as PlatformMessage, It as PollChoice, J as mergeStreams, Jt as StreamTextSource, K as ManagedStream, Kt as DeltaExtractor, L as PlatformProviderConfig, Lt as PollChoiceInput, M as EventProducer, Mn as app, Mt as Read, N as Platform, Nn as appLayoutSchema, O as FusorEvent, Ot as Reply, P as PlatformDef, Pt as read, Q as DedicatedTokenData, Qt as group, R as PlatformRuntime, Rt as PollOption, S as FusorRespond, Sn as User, T as WebhookHandler, Tn as avatar, U as SchemaMessage, Ut as Markdown, V as ProviderMessage, Vt as option, W as SpaceNamespace, X as Store, Xt as Group, Y as stream, Yt as TextStreamOptions, Z as CloudPlatform, _ as FusorClient, _n as ContactOrg, _t as voice, a as Content, an as ReactionBuilder, at as SharedTokenData, b as FusorMessagesReturn, bn as contact, bt as Typing, c as fromVCard, ct as SpectrumCloudError, d as UnsupportedKind, dn as Contact, dt as TokenData, en as Edit, et as ImessageInfoData, f as Spectrum, fn as ContactAddress, ft as cloud, g as isFusorClient, gn as ContactName, h as fusor, hn as ContactInput, ht as Voice, i as attachment, in as Reaction, it as ProjectProfile, j as AnyPlatformDef, jn as AppUrl, jt as rename, k as fusorEvent, kn as App, kt as reply, l as toVCard, lt as SubscriptionData, m as definePlatform, mn as ContactEmail, mt as EmojiKey, n as AttachmentInput, nn as Message, nt as PlatformsData, o as ContentBuilder, ot as SlackTeamMeta, p as SpectrumInstance, pn as ContactDetails, pt as Emoji, q as broadcast, qt as StreamText, rn as Space, rt as ProjectData, s as ContentInput, sn as reaction, st as SlackTokenData, t as Attachment, tn as edit, tt as PlatformStatus, u as UnsupportedError, un as custom, ut as SubscriptionStatus, v as FusorMessages, vn as ContactPhone, vt as Unsend, w as FusorVerifyRequest, wn as AvatarInput, wt as Richlink, x as FusorReply, xn as AgentSender, xt as typing, y as FusorMessagesCtx, yt as unsend, z as PlatformSpace } from "./attachment-a_lrhg6w.js";
|
|
2
|
+
export { type AgentSender, type AnyPlatformDef, type App, type AppLayout, type AppUrl, type Attachment, type AttachmentInput, type Avatar, type AvatarInput, type Broadcaster, type CloudPlatform, type Contact, type ContactAddress, type ContactDetails, type ContactEmail, type ContactInput, type ContactName, type ContactOrg, type ContactPhone, type Content, type ContentBuilder, type ContentInput, type DedicatedTokenData, type DeltaExtractor, type Edit, Emoji, type EmojiKey, type EventProducer, type FusorClient, type FusorEvent, type FusorMessages, type FusorMessagesCtx, type FusorMessagesReturn, type FusorReply, type FusorRespond, type FusorTokenData, type FusorVerify, type FusorVerifyRequest, type Group, type ImessageInfoData, type ManagedStream, type Markdown, type Message, type Platform, type PlatformDef, type PlatformInstance, type PlatformMessage, type PlatformProviderConfig, type PlatformRuntime, type PlatformSpace, type PlatformStatus, type PlatformUser, type PlatformsData, type Poll, type PollChoice, type PollChoiceInput, type PollOption, type ProjectData, type ProjectProfile, type ProviderMessage, type Reaction, type ReactionBuilder, type Read, type Rename, type Reply, type Richlink, type SchemaMessage, type SharedTokenData, type SlackTeamMeta, type SlackTokenData, type Space, type SpaceNamespace, Spectrum, SpectrumCloudError, type SpectrumInstance, type Store, type StreamText, type StreamTextSource, type SubscriptionData, type SubscriptionStatus, type TextStreamOptions, type TokenData, type Typing, type Unsend, UnsupportedError, type UnsupportedKind, type User, type Voice, type WebhookHandler, type WebhookRawRequest, type WebhookRawResult, app, appLayoutSchema, attachment, avatar, broadcast, cloud, contact, custom, definePlatform, edit, fromVCard, fusor, fusorEvent, group, isFusorClient, isFusorEvent, markdown, mergeStreams, option, poll, reaction, read, rename, reply, resolveContents, richlink, stream, text, toVCard, typing, unsend, voice };
|