spectrum-ts 4.2.0 → 5.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.
Files changed (46) hide show
  1. package/README.md +29 -67
  2. package/dist/authoring.d.ts +1 -6
  3. package/dist/authoring.js +2 -36
  4. package/dist/elysia.d.ts +1 -94
  5. package/dist/elysia.js +2 -15
  6. package/dist/express.d.ts +1 -62
  7. package/dist/express.js +2 -19
  8. package/dist/hono.d.ts +1 -64
  9. package/dist/hono.js +2 -11
  10. package/dist/index.d.ts +1 -2851
  11. package/dist/index.js +2 -3763
  12. package/dist/manifest.json +5 -5
  13. package/dist/providers/imessage/index.d.ts +1 -222
  14. package/dist/providers/imessage/index.js +2 -25
  15. package/dist/providers/index.d.ts +6 -19
  16. package/dist/providers/index.js +6 -34
  17. package/dist/providers/slack/index.d.ts +1 -46
  18. package/dist/providers/slack/index.js +2 -11
  19. package/dist/providers/telegram/index.d.ts +1 -45
  20. package/dist/providers/telegram/index.js +2 -13
  21. package/dist/providers/terminal/index.d.ts +1 -119
  22. package/dist/providers/terminal/index.js +2 -13
  23. package/dist/providers/whatsapp-business/index.d.ts +1 -27
  24. package/dist/providers/whatsapp-business/index.js +2 -14
  25. package/package.json +11 -38
  26. package/dist/attachment-CnivEhr6.d.ts +0 -29
  27. package/dist/authoring-b9AhXgPI.d.ts +0 -304
  28. package/dist/chunk-2D27WW5B.js +0 -63
  29. package/dist/chunk-34FQGGD7.js +0 -34
  30. package/dist/chunk-3GEJYGZK.js +0 -84
  31. package/dist/chunk-5XEFJBN2.js +0 -197
  32. package/dist/chunk-6UZFVXQF.js +0 -374
  33. package/dist/chunk-A37PM5N2.js +0 -91
  34. package/dist/chunk-ARL2NOBO.js +0 -887
  35. package/dist/chunk-B52VPQO3.js +0 -1379
  36. package/dist/chunk-DMPDLSFU.js +0 -864
  37. package/dist/chunk-FAIFTUV2.js +0 -139
  38. package/dist/chunk-LZXPLXZF.js +0 -35
  39. package/dist/chunk-N6THJDZV.js +0 -929
  40. package/dist/chunk-NLMQ75LH.js +0 -2980
  41. package/dist/chunk-UXAKIXVM.js +0 -409
  42. package/dist/chunk-WXLQNANA.js +0 -539
  43. package/dist/chunk-ZR3TKZMT.js +0 -129
  44. package/dist/read-C4uvozGX.d.ts +0 -53
  45. package/dist/types-CyfLJXgu.d.ts +0 -1530
  46. package/dist/types-ZgFTj5hJ.d.ts +0 -87
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "spectrum-ts",
3
- "version": "4.2.0",
4
- "description": "Bring agents to any interface — unified messaging SDK for TypeScript.",
3
+ "version": "5.1.0",
4
+ "description": "Bring agents to any interface — unified messaging SDK for TypeScript. Batteries-included: the runtime plus every official provider.",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/photon-hq/spectrum-ts.git",
@@ -49,43 +49,16 @@
49
49
  },
50
50
  "./manifest.json": "./dist/manifest.json"
51
51
  },
52
- "dependencies": {
53
- "@photon-ai/advanced-imessage": "^0.11.0",
54
- "@photon-ai/imessage-kit": "^3.0.0",
55
- "@photon-ai/otel": "^0.1.1",
56
- "@photon-ai/slack": "^0.2.0",
57
- "@photon-ai/telegram-ts": "10.0.0",
58
- "@photon-ai/whatsapp-business": "^0.1.1",
59
- "@photon-ai/proto": "^0.2.4",
60
- "@repeaterjs/repeater": "^3.0.6",
61
- "lru-cache": "^11.0.0",
62
- "marked": "^18.0.5",
63
- "mime-types": "^3.0.1",
64
- "open-graph-scraper": "^6.11.0",
65
- "type-fest": "^5.4.1",
66
- "vcf": "^2.1.2",
67
- "zod": "^4.2.1"
68
- },
69
- "peerDependencies": {
70
- "elysia": "^1",
71
- "express": "^4 || ^5",
72
- "ffmpeg-static": "^5",
73
- "hono": "^4",
74
- "typescript": "^5 || ^6.0.0"
52
+ "publishConfig": {
53
+ "access": "public"
75
54
  },
76
- "peerDependenciesMeta": {
77
- "elysia": {
78
- "optional": true
79
- },
80
- "express": {
81
- "optional": true
82
- },
83
- "ffmpeg-static": {
84
- "optional": true
85
- },
86
- "hono": {
87
- "optional": true
88
- }
55
+ "dependencies": {
56
+ "@spectrum-ts/core": "5.1.0",
57
+ "@spectrum-ts/imessage": "5.1.0",
58
+ "@spectrum-ts/slack": "5.1.0",
59
+ "@spectrum-ts/telegram": "5.1.0",
60
+ "@spectrum-ts/terminal": "5.1.0",
61
+ "@spectrum-ts/whatsapp-business": "5.1.0"
89
62
  },
90
63
  "license": "MIT"
91
64
  }
@@ -1,29 +0,0 @@
1
- import z__default from 'zod';
2
- import { C as ContentBuilder } from './types-CyfLJXgu.js';
3
-
4
- declare const attachmentSchema: z__default.ZodObject<{
5
- type: z__default.ZodLiteral<"attachment">;
6
- id: z__default.ZodString;
7
- name: z__default.ZodString;
8
- mimeType: z__default.ZodString;
9
- size: z__default.ZodOptional<z__default.ZodNumber>;
10
- read: z__default.ZodFunction<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>>>;
11
- stream: z__default.ZodFunction<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>>>;
12
- }, z__default.core.$strip>;
13
- type Attachment = z__default.infer<typeof attachmentSchema>;
14
- type AttachmentInput = string | Buffer | URL;
15
- declare const asAttachment: (input: {
16
- id?: string;
17
- name: string;
18
- mimeType: string;
19
- size?: number;
20
- read: () => Promise<Buffer>;
21
- stream?: () => Promise<ReadableStream<Uint8Array>>;
22
- }) => Attachment;
23
- declare function attachment(input: AttachmentInput, options?: {
24
- id?: string;
25
- mimeType?: string;
26
- name?: string;
27
- }): ContentBuilder;
28
-
29
- export { type Attachment as A, type AttachmentInput as a, attachment as b, asAttachment as c };
@@ -1,304 +0,0 @@
1
- import './attachment-CnivEhr6.js';
2
- import vCard from 'vcf';
3
- import z__default from 'zod';
4
- import { U as User, C as ContentBuilder, M as Message, S as Space, h as ContentInput } from './types-CyfLJXgu.js';
5
-
6
- declare const nameSchema: z__default.ZodObject<{
7
- formatted: z__default.ZodOptional<z__default.ZodString>;
8
- first: z__default.ZodOptional<z__default.ZodString>;
9
- last: z__default.ZodOptional<z__default.ZodString>;
10
- middle: z__default.ZodOptional<z__default.ZodString>;
11
- prefix: z__default.ZodOptional<z__default.ZodString>;
12
- suffix: z__default.ZodOptional<z__default.ZodString>;
13
- }, z__default.core.$strip>;
14
- declare const phoneSchema: z__default.ZodObject<{
15
- value: z__default.ZodString;
16
- type: z__default.ZodOptional<z__default.ZodEnum<{
17
- mobile: "mobile";
18
- home: "home";
19
- work: "work";
20
- other: "other";
21
- }>>;
22
- }, z__default.core.$strip>;
23
- declare const emailSchema: z__default.ZodObject<{
24
- value: z__default.ZodString;
25
- type: z__default.ZodOptional<z__default.ZodEnum<{
26
- home: "home";
27
- work: "work";
28
- other: "other";
29
- }>>;
30
- }, z__default.core.$strip>;
31
- declare const addressSchema: z__default.ZodObject<{
32
- street: z__default.ZodOptional<z__default.ZodString>;
33
- city: z__default.ZodOptional<z__default.ZodString>;
34
- region: z__default.ZodOptional<z__default.ZodString>;
35
- postalCode: z__default.ZodOptional<z__default.ZodString>;
36
- country: z__default.ZodOptional<z__default.ZodString>;
37
- type: z__default.ZodOptional<z__default.ZodEnum<{
38
- home: "home";
39
- work: "work";
40
- other: "other";
41
- }>>;
42
- }, z__default.core.$strip>;
43
- declare const orgSchema: z__default.ZodObject<{
44
- name: z__default.ZodOptional<z__default.ZodString>;
45
- title: z__default.ZodOptional<z__default.ZodString>;
46
- department: z__default.ZodOptional<z__default.ZodString>;
47
- }, z__default.core.$strip>;
48
- declare const contactSchema: z__default.ZodObject<{
49
- type: z__default.ZodLiteral<"contact">;
50
- user: z__default.ZodOptional<z__default.ZodObject<{
51
- __platform: z__default.ZodString;
52
- id: z__default.ZodString;
53
- }, z__default.core.$strip>>;
54
- name: z__default.ZodOptional<z__default.ZodObject<{
55
- formatted: z__default.ZodOptional<z__default.ZodString>;
56
- first: z__default.ZodOptional<z__default.ZodString>;
57
- last: z__default.ZodOptional<z__default.ZodString>;
58
- middle: z__default.ZodOptional<z__default.ZodString>;
59
- prefix: z__default.ZodOptional<z__default.ZodString>;
60
- suffix: z__default.ZodOptional<z__default.ZodString>;
61
- }, z__default.core.$strip>>;
62
- phones: z__default.ZodOptional<z__default.ZodArray<z__default.ZodObject<{
63
- value: z__default.ZodString;
64
- type: z__default.ZodOptional<z__default.ZodEnum<{
65
- mobile: "mobile";
66
- home: "home";
67
- work: "work";
68
- other: "other";
69
- }>>;
70
- }, z__default.core.$strip>>>;
71
- emails: z__default.ZodOptional<z__default.ZodArray<z__default.ZodObject<{
72
- value: z__default.ZodString;
73
- type: z__default.ZodOptional<z__default.ZodEnum<{
74
- home: "home";
75
- work: "work";
76
- other: "other";
77
- }>>;
78
- }, z__default.core.$strip>>>;
79
- addresses: z__default.ZodOptional<z__default.ZodArray<z__default.ZodObject<{
80
- street: z__default.ZodOptional<z__default.ZodString>;
81
- city: z__default.ZodOptional<z__default.ZodString>;
82
- region: z__default.ZodOptional<z__default.ZodString>;
83
- postalCode: z__default.ZodOptional<z__default.ZodString>;
84
- country: z__default.ZodOptional<z__default.ZodString>;
85
- type: z__default.ZodOptional<z__default.ZodEnum<{
86
- home: "home";
87
- work: "work";
88
- other: "other";
89
- }>>;
90
- }, z__default.core.$strip>>>;
91
- org: z__default.ZodOptional<z__default.ZodObject<{
92
- name: z__default.ZodOptional<z__default.ZodString>;
93
- title: z__default.ZodOptional<z__default.ZodString>;
94
- department: z__default.ZodOptional<z__default.ZodString>;
95
- }, z__default.core.$strip>>;
96
- urls: z__default.ZodOptional<z__default.ZodArray<z__default.ZodString>>;
97
- birthday: z__default.ZodOptional<z__default.ZodString>;
98
- note: z__default.ZodOptional<z__default.ZodString>;
99
- photo: z__default.ZodOptional<z__default.ZodObject<{
100
- mimeType: z__default.ZodString;
101
- read: z__default.ZodFunction<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>>>;
102
- }, z__default.core.$strip>>;
103
- raw: z__default.ZodOptional<z__default.ZodUnknown>;
104
- }, z__default.core.$strip>;
105
- type Contact = z__default.infer<typeof contactSchema>;
106
- type ContactName = z__default.infer<typeof nameSchema>;
107
- type ContactPhone = z__default.infer<typeof phoneSchema>;
108
- type ContactEmail = z__default.infer<typeof emailSchema>;
109
- type ContactAddress = z__default.infer<typeof addressSchema>;
110
- type ContactOrg = z__default.infer<typeof orgSchema>;
111
- type ContactInput = Omit<Contact, "type">;
112
- type ContactDetails = Omit<ContactInput, "user">;
113
- declare const asContact: (input: ContactInput) => Contact;
114
- declare function contact(user: User, details?: ContactDetails): ContentBuilder;
115
- declare function contact(input: string | ContactInput | vCard): ContentBuilder;
116
-
117
- declare const customSchema: z__default.ZodObject<{
118
- type: z__default.ZodLiteral<"custom">;
119
- raw: z__default.ZodUnknown;
120
- }, z__default.core.$strip>;
121
- declare const asCustom: (raw: unknown) => z__default.infer<typeof customSchema>;
122
- declare function custom(raw: unknown): ContentBuilder;
123
-
124
- /**
125
- * A `group` bundles multiple messages into one logical unit (e.g. an album
126
- * of images sent together). Each item is a full `Message` — addressable by
127
- * id, reactable via `.react()`, replyable via `.reply()`.
128
- *
129
- * Groups do not nest, and reactions cannot be group members. Enforced by the
130
- * `group()` builder; platforms may additionally reject unsupported item
131
- * content types at send time.
132
- */
133
- declare const groupSchema: z__default.ZodObject<{
134
- type: z__default.ZodLiteral<"group">;
135
- items: z__default.ZodArray<z__default.ZodCustom<Message<string, User, Space<unknown>>, Message<string, User, Space<unknown>>>>;
136
- }, z__default.core.$strip>;
137
- type Group = z__default.infer<typeof groupSchema>;
138
- declare const asGroup: (input: {
139
- items: Message[];
140
- }) => Group;
141
- declare function group(...items: [ContentInput, ContentInput, ...ContentInput[]]): ContentBuilder;
142
-
143
- /**
144
- * Maps one chunk emitted by a stream to the incremental text it carries.
145
- * Return a string to emit, or `null`/`undefined` to skip the chunk (e.g. for
146
- * control events that carry no text).
147
- */
148
- type DeltaExtractor<T> = (chunk: T) => string | null | undefined;
149
- /**
150
- * Anything the stream overloads of `text()` and `markdown()` accept as a
151
- * source. The builder normalizes all of these to an internal
152
- * `AsyncIterable<string>` of text deltas:
153
- *
154
- * - the Vercel AI SDK `streamText()` result (its `.textStream` is picked up
155
- * automatically — pass either the whole result or `.textStream` directly),
156
- * - a raw `AsyncIterable<T>` (e.g. an OpenAI / Anthropic streaming response),
157
- * - a raw `ReadableStream<T>` of chunks.
158
- */
159
- type StreamTextSource<T = unknown> = {
160
- textStream: AsyncIterable<string> | ReadableStream<string>;
161
- } | AsyncIterable<T> | ReadableStream<T>;
162
- interface TextStreamOptions<T = unknown> {
163
- /**
164
- * Map each chunk to its incremental text. Omit to rely on built-in
165
- * auto-detection of the common SDK shapes (OpenAI chat/responses, Anthropic
166
- * messages, AI SDK text streams, and plain strings).
167
- */
168
- extract?: DeltaExtractor<T>;
169
- }
170
- declare const streamTextSchema: z__default.ZodObject<{
171
- type: z__default.ZodLiteral<"streamText">;
172
- stream: z__default.ZodCustom<() => AsyncIterable<string>, () => AsyncIterable<string>>;
173
- format: z__default.ZodOptional<z__default.ZodEnum<{
174
- markdown: "markdown";
175
- plain: "plain";
176
- }>>;
177
- }, z__default.core.$strip>;
178
- type StreamText = z__default.infer<typeof streamTextSchema>;
179
-
180
- declare const pollChoiceSchema: z__default.ZodObject<{
181
- title: z__default.ZodString;
182
- }, z__default.core.$strip>;
183
- declare const pollSchema: z__default.ZodObject<{
184
- type: z__default.ZodLiteral<"poll">;
185
- title: z__default.ZodString;
186
- options: z__default.ZodArray<z__default.ZodObject<{
187
- title: z__default.ZodString;
188
- }, z__default.core.$strip>>;
189
- }, z__default.core.$strip>;
190
- declare const pollOptionSchema: z__default.ZodObject<{
191
- type: z__default.ZodLiteral<"poll_option">;
192
- option: z__default.ZodObject<{
193
- title: z__default.ZodString;
194
- }, z__default.core.$strip>;
195
- poll: z__default.ZodObject<{
196
- type: z__default.ZodLiteral<"poll">;
197
- title: z__default.ZodString;
198
- options: z__default.ZodArray<z__default.ZodObject<{
199
- title: z__default.ZodString;
200
- }, z__default.core.$strip>>;
201
- }, z__default.core.$strip>;
202
- selected: z__default.ZodBoolean;
203
- title: z__default.ZodString;
204
- }, z__default.core.$strip>;
205
- type Poll = z__default.infer<typeof pollSchema>;
206
- type PollChoice = z__default.infer<typeof pollChoiceSchema>;
207
- type PollOption = z__default.infer<typeof pollOptionSchema>;
208
- type PollChoiceInput = string | {
209
- title: string;
210
- };
211
- interface PollInput {
212
- options: PollChoice[];
213
- title: string;
214
- }
215
- declare const asPoll: (input: PollInput) => Poll;
216
- declare const asPollOption: (input: {
217
- option: PollChoice;
218
- poll: Poll;
219
- selected: boolean;
220
- }) => PollOption;
221
- declare const option: (title: string) => PollChoice;
222
- declare function poll(title: string, options: PollChoiceInput[]): ContentBuilder;
223
- declare function poll(title: string, ...options: PollChoiceInput[]): ContentBuilder;
224
-
225
- declare const richlinkSchema: z__default.ZodObject<{
226
- type: z__default.ZodLiteral<"richlink">;
227
- url: z__default.ZodURL;
228
- title: z__default.ZodFunction<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodOptional<z__default.ZodString>>>;
229
- summary: z__default.ZodFunction<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodOptional<z__default.ZodString>>>;
230
- cover: z__default.ZodFunction<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodOptional<z__default.ZodObject<{
231
- mimeType: z__default.ZodOptional<z__default.ZodString>;
232
- read: z__default.ZodFunction<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>>>;
233
- stream: z__default.ZodFunction<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>>>;
234
- }, z__default.core.$strip>>>>;
235
- }, z__default.core.$strip>;
236
- type Richlink = z__default.infer<typeof richlinkSchema>;
237
- /**
238
- * Construct a `richlink` content value.
239
- *
240
- * Accessors (`title`, `summary`, `cover`) are async and lazy: the first call
241
- * issues a single network request to the URL; subsequent calls share the
242
- * cached result. Network / parse failures resolve to `undefined` and are
243
- * cached — no retries. Callers who only need `title` / `summary` never
244
- * trigger an image download; calling `cover.read()` triggers one additional
245
- * request to fetch the image bytes.
246
- */
247
- declare const asRichlink: (input: {
248
- url: string;
249
- }) => Richlink;
250
- declare function richlink(url: string): ContentBuilder;
251
-
252
- declare const textSchema: z__default.ZodObject<{
253
- type: z__default.ZodLiteral<"text">;
254
- text: z__default.ZodString;
255
- }, z__default.core.$strip>;
256
- declare const asText: (text: string) => z__default.infer<typeof textSchema>;
257
- /**
258
- * Send plain text — a static string or a streaming LLM response.
259
- *
260
- * `text("hi")` sends one message. `text(source)` wraps a text stream so it
261
- * can be sent like any other content; delivery is platform-specific —
262
- * iMessage (remote) sends the first chunk as a real message and then edits it
263
- * in place as more text arrives; Telegram (private chats) animates a native
264
- * draft preview and persists the final text as one message. Platforms that
265
- * can't stream wait for the stream to finish and deliver the accumulated text
266
- * as one plain message.
267
- *
268
- * A stream source accepts whatever the popular SDKs return (the AI SDK
269
- * `streamText()` result, OpenAI / Anthropic streaming responses, or any
270
- * `AsyncIterable` / `ReadableStream`); pass `options.extract` for any chunk
271
- * shape the built-in detection doesn't recognize. A stream can only be sent
272
- * once. Options apply to stream sources only — they are ignored for strings.
273
- *
274
- * For text written in markdown, use `markdown()` instead.
275
- */
276
- declare function text(source: string): ContentBuilder;
277
- declare function text<T = unknown>(source: StreamTextSource<T>, options?: TextStreamOptions<T>): ContentBuilder;
278
-
279
- declare const voiceSchema: z__default.ZodObject<{
280
- type: z__default.ZodLiteral<"voice">;
281
- name: z__default.ZodOptional<z__default.ZodString>;
282
- mimeType: z__default.ZodString;
283
- duration: z__default.ZodOptional<z__default.ZodNumber>;
284
- size: z__default.ZodOptional<z__default.ZodNumber>;
285
- read: z__default.ZodFunction<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>>>;
286
- stream: z__default.ZodFunction<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>>>;
287
- }, z__default.core.$strip>;
288
- type Voice = z__default.infer<typeof voiceSchema>;
289
- type VoiceInput = string | Buffer | URL;
290
- declare const asVoice: (input: {
291
- name?: string;
292
- mimeType: string;
293
- duration?: number;
294
- size?: number;
295
- read: () => Promise<Buffer>;
296
- stream?: () => Promise<ReadableStream<Uint8Array>>;
297
- }) => Voice;
298
- declare function voice(input: VoiceInput, options?: {
299
- mimeType?: string;
300
- name?: string;
301
- duration?: number;
302
- }): ContentBuilder;
303
-
304
- export { asVoice as A, type ContactInput as C, type DeltaExtractor as D, type Group as G, type Poll as P, type Richlink as R, type StreamTextSource as S, type TextStreamOptions as T, type Voice as V, type Contact as a, type ContactAddress as b, type ContactDetails as c, type ContactEmail as d, type ContactName as e, type ContactOrg as f, type ContactPhone as g, type PollChoice as h, type PollChoiceInput as i, type PollOption as j, type StreamText as k, contact as l, custom as m, group as n, option as o, poll as p, asContact as q, richlink as r, asCustom as s, text as t, asGroup as u, voice as v, asPoll as w, asPollOption as x, asRichlink as y, asText as z };
@@ -1,63 +0,0 @@
1
- import { createRequire as __spectrumCreateRequire } from "node:module"; const require = __spectrumCreateRequire(import.meta.url);
2
-
3
- // src/content/poll.ts
4
- import z from "zod";
5
- var pollChoiceSchema = z.object({
6
- title: z.string().nonempty()
7
- });
8
- var pollSchema = z.object({
9
- type: z.literal("poll"),
10
- title: z.string().nonempty().max(300),
11
- options: z.array(pollChoiceSchema).min(2).max(10)
12
- });
13
- var pollOptionSchema = z.object({
14
- type: z.literal("poll_option"),
15
- option: pollChoiceSchema,
16
- poll: pollSchema,
17
- selected: z.boolean(),
18
- title: z.string().nonempty()
19
- }).superRefine((value, ctx) => {
20
- if (value.title !== value.option.title) {
21
- ctx.addIssue({
22
- code: "custom",
23
- message: "poll_option title must match option.title",
24
- path: ["title"]
25
- });
26
- }
27
- if (!value.poll.options.some(
28
- (pollOption) => pollOption.title === value.option.title
29
- )) {
30
- ctx.addIssue({
31
- code: "custom",
32
- message: "poll_option option must exist in poll.options",
33
- path: ["option"]
34
- });
35
- }
36
- });
37
- var asPoll = (input) => pollSchema.parse({ type: "poll", ...input });
38
- var asPollOption = (input) => pollOptionSchema.parse({
39
- type: "poll_option",
40
- ...input,
41
- title: input.option.title
42
- });
43
- var option = (title) => ({ title });
44
- var normalize = (raw) => typeof raw === "string" ? { title: raw } : { title: raw.title };
45
- var collectOptions = (args) => {
46
- const [first] = args;
47
- if (args.length === 1 && Array.isArray(first)) {
48
- return first;
49
- }
50
- return args;
51
- };
52
- function poll(title, ...rest) {
53
- return {
54
- build: async () => asPoll({ title, options: collectOptions(rest).map(normalize) })
55
- };
56
- }
57
-
58
- export {
59
- asPoll,
60
- asPollOption,
61
- option,
62
- poll
63
- };
@@ -1,34 +0,0 @@
1
- import { createRequire as __spectrumCreateRequire } from "node:module"; const require = __spectrumCreateRequire(import.meta.url);
2
-
3
- // src/fusor/event.ts
4
- var FUSOR_EVENT_BRAND = /* @__PURE__ */ Symbol.for("spectrum.fusor.event");
5
- var FUSOR_MESSAGES_CHANNEL = "messages";
6
- function fusorEvent(name, data) {
7
- return { [FUSOR_EVENT_BRAND]: true, name, data };
8
- }
9
- function isFusorEvent(value) {
10
- return typeof value === "object" && value !== null && value[FUSOR_EVENT_BRAND] === true;
11
- }
12
-
13
- // src/fusor/types.ts
14
- var FUSOR_BRAND = /* @__PURE__ */ Symbol.for("spectrum.fusor.client");
15
-
16
- // src/fusor/index.ts
17
- function fusor(platform, verify) {
18
- return {
19
- [FUSOR_BRAND]: true,
20
- platform,
21
- verify
22
- };
23
- }
24
- function isFusorClient(value) {
25
- return typeof value === "object" && value !== null && value[FUSOR_BRAND] === true;
26
- }
27
-
28
- export {
29
- FUSOR_MESSAGES_CHANNEL,
30
- fusorEvent,
31
- isFusorEvent,
32
- fusor,
33
- isFusorClient
34
- };
@@ -1,84 +0,0 @@
1
- import { createRequire as __spectrumCreateRequire } from "node:module"; const require = __spectrumCreateRequire(import.meta.url);
2
-
3
- // src/utils/cloud.ts
4
- var SPECTRUM_CLOUD_URL = process.env.SPECTRUM_CLOUD_URL ?? "https://spectrum.photon.codes";
5
- var SpectrumCloudError = class extends Error {
6
- status;
7
- code;
8
- constructor(status, code, message) {
9
- super(message);
10
- this.name = "SpectrumCloudError";
11
- this.status = status;
12
- this.code = code;
13
- }
14
- };
15
- var request = async (path, init) => {
16
- const response = await fetch(`${SPECTRUM_CLOUD_URL}${path}`, init);
17
- if (!response.ok) {
18
- const body = await response.text().catch(() => "");
19
- try {
20
- const parsed = JSON.parse(body);
21
- throw new SpectrumCloudError(
22
- response.status,
23
- parsed.code,
24
- parsed.message
25
- );
26
- } catch (error) {
27
- if (error instanceof SpectrumCloudError) {
28
- throw error;
29
- }
30
- throw new SpectrumCloudError(
31
- response.status,
32
- "UNKNOWN",
33
- body || response.statusText
34
- );
35
- }
36
- }
37
- const json = await response.json();
38
- if (!json.succeed) {
39
- throw new SpectrumCloudError(
40
- response.status,
41
- "UNKNOWN",
42
- "Server returned succeed=false"
43
- );
44
- }
45
- return json.data;
46
- };
47
- var basicAuth = (projectId, projectSecret) => `Basic ${btoa(`${projectId}:${projectSecret}`)}`;
48
- var cloud = {
49
- getProject: (projectId, projectSecret) => request(`/projects/${projectId}/`, {
50
- headers: { Authorization: basicAuth(projectId, projectSecret) }
51
- }),
52
- getSubscription: (projectId) => request(`/projects/${projectId}/billing/subscription`),
53
- issueImessageTokens: (projectId, projectSecret) => request(`/projects/${projectId}/imessage/tokens`, {
54
- method: "POST",
55
- headers: { Authorization: basicAuth(projectId, projectSecret) }
56
- }),
57
- getImessageInfo: (projectId) => request(`/projects/${projectId}/imessage/`),
58
- issueWhatsappBusinessTokens: (projectId, projectSecret) => request(`/projects/${projectId}/whatsapp-business/tokens`, {
59
- method: "POST",
60
- headers: { Authorization: basicAuth(projectId, projectSecret) }
61
- }),
62
- issueSlackTokens: (projectId, projectSecret) => request(`/projects/${projectId}/slack/tokens`, {
63
- method: "POST",
64
- headers: { Authorization: basicAuth(projectId, projectSecret) }
65
- }),
66
- issueFusorToken: (projectId, projectSecret) => request(`/projects/${projectId}/fusor/token`, {
67
- method: "POST",
68
- headers: { Authorization: basicAuth(projectId, projectSecret) }
69
- }),
70
- getPlatforms: (projectId) => request(`/projects/${projectId}/platforms/`),
71
- togglePlatform: (projectId, projectSecret, platform, enabled) => request(`/projects/${projectId}/platforms/`, {
72
- method: "PATCH",
73
- headers: {
74
- Authorization: basicAuth(projectId, projectSecret),
75
- "Content-Type": "application/json"
76
- },
77
- body: JSON.stringify({ platform, enabled })
78
- })
79
- };
80
-
81
- export {
82
- SpectrumCloudError,
83
- cloud
84
- };