spectrum-ts 4.1.0 → 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.
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 -0
  5. package/dist/elysia.js +2 -0
  6. package/dist/express.d.ts +1 -0
  7. package/dist/express.js +2 -0
  8. package/dist/hono.d.ts +1 -0
  9. package/dist/hono.js +2 -0
  10. package/dist/index.d.ts +1 -2837
  11. package/dist/index.js +2 -3373
  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 +23 -26
  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-3KWFP4L2.js +0 -864
  32. package/dist/chunk-5XEFJBN2.js +0 -197
  33. package/dist/chunk-6UZFVXQF.js +0 -374
  34. package/dist/chunk-A37PM5N2.js +0 -91
  35. package/dist/chunk-B52VPQO3.js +0 -1379
  36. package/dist/chunk-DMT6BFJV.js +0 -2980
  37. package/dist/chunk-FAIFTUV2.js +0 -139
  38. package/dist/chunk-IM5ADDZS.js +0 -887
  39. package/dist/chunk-LZXPLXZF.js +0 -35
  40. package/dist/chunk-U3QQ56YZ.js +0 -929
  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-BIta6Kxi.d.ts +0 -82
  46. package/dist/types-CyfLJXgu.d.ts +0 -1530
@@ -1,197 +0,0 @@
1
- import { createRequire as __spectrumCreateRequire } from "node:module"; const require = __spectrumCreateRequire(import.meta.url);
2
-
3
- // src/utils/stream.ts
4
- import { Repeater } from "@repeaterjs/repeater";
5
- function createAsyncQueue() {
6
- const buffer = [];
7
- const resolvers = [];
8
- let closed = false;
9
- const push = (value) => {
10
- if (closed) {
11
- return;
12
- }
13
- const resolver = resolvers.shift();
14
- if (resolver) {
15
- resolver({ value, done: false });
16
- } else {
17
- buffer.push(value);
18
- }
19
- };
20
- const close = () => {
21
- if (closed) {
22
- return;
23
- }
24
- closed = true;
25
- while (resolvers.length > 0) {
26
- const resolver = resolvers.shift();
27
- resolver?.({ value: void 0, done: true });
28
- }
29
- };
30
- const iterable = {
31
- [Symbol.asyncIterator]() {
32
- return {
33
- next() {
34
- if (buffer.length > 0) {
35
- const value = buffer.shift();
36
- return Promise.resolve({ value, done: false });
37
- }
38
- if (closed) {
39
- return Promise.resolve({ value: void 0, done: true });
40
- }
41
- return new Promise((resolve) => {
42
- resolvers.push(resolve);
43
- });
44
- },
45
- return() {
46
- close();
47
- return Promise.resolve({ value: void 0, done: true });
48
- }
49
- };
50
- }
51
- };
52
- return { iterable, push, close };
53
- }
54
- var ignoreCleanupError = () => void 0;
55
- function stream(setup) {
56
- const repeater = new Repeater(async (push, stop) => {
57
- const emit = async (value) => {
58
- try {
59
- await push(value);
60
- } catch (error) {
61
- stop(error);
62
- throw error;
63
- }
64
- };
65
- const end = (error) => {
66
- stop(error);
67
- };
68
- const cleanup = await setup(emit, end);
69
- try {
70
- await stop;
71
- } finally {
72
- await cleanup?.();
73
- }
74
- });
75
- return Object.assign(repeater, {
76
- close: async () => {
77
- await repeater.return(void 0).catch(ignoreCleanupError);
78
- }
79
- });
80
- }
81
- function mergeStreams(streams) {
82
- return stream((emit, end) => {
83
- if (streams.length === 0) {
84
- end();
85
- return;
86
- }
87
- let openStreams = streams.length;
88
- const workers = streams.map(async (source) => {
89
- try {
90
- for await (const value of source) {
91
- await emit(value);
92
- }
93
- } catch (error) {
94
- end(error);
95
- } finally {
96
- openStreams -= 1;
97
- if (openStreams === 0) {
98
- end();
99
- }
100
- }
101
- });
102
- return async () => {
103
- await Promise.allSettled(streams.map((source) => source.close()));
104
- await Promise.allSettled(workers).catch(ignoreCleanupError);
105
- };
106
- });
107
- }
108
- function broadcast(source) {
109
- const consumers = /* @__PURE__ */ new Set();
110
- let pumping = false;
111
- let terminated = false;
112
- let terminalError;
113
- let pumpPromise;
114
- let closed = false;
115
- const closeConsumers = (error) => {
116
- if (consumers.size === 0) {
117
- return;
118
- }
119
- const current = Array.from(consumers);
120
- consumers.clear();
121
- for (const consumer of current) {
122
- consumer.end(error);
123
- }
124
- };
125
- const startPump = () => {
126
- if (pumping || terminated) {
127
- return;
128
- }
129
- pumping = true;
130
- pumpPromise = (async () => {
131
- try {
132
- for await (const value of source) {
133
- if (terminated) {
134
- break;
135
- }
136
- for (const consumer of Array.from(consumers)) {
137
- consumer.deliveries = consumer.deliveries.then(
138
- () => consumer.emit(value).catch(() => {
139
- })
140
- );
141
- }
142
- }
143
- if (terminated) {
144
- return;
145
- }
146
- terminated = true;
147
- await Promise.allSettled(
148
- Array.from(consumers, (consumer) => consumer.deliveries)
149
- );
150
- closeConsumers();
151
- } catch (error) {
152
- terminated = true;
153
- terminalError = error;
154
- closeConsumers(error);
155
- }
156
- })();
157
- };
158
- return {
159
- subscribe() {
160
- return stream((emit, end) => {
161
- if (terminated || closed) {
162
- end(terminalError);
163
- return;
164
- }
165
- const consumer = {
166
- emit,
167
- end,
168
- deliveries: Promise.resolve()
169
- };
170
- consumers.add(consumer);
171
- startPump();
172
- return () => {
173
- consumers.delete(consumer);
174
- };
175
- });
176
- },
177
- async close() {
178
- if (closed) {
179
- return;
180
- }
181
- closed = true;
182
- terminated = true;
183
- closeConsumers();
184
- await source.close().catch(ignoreCleanupError);
185
- if (pumpPromise) {
186
- await pumpPromise.catch(ignoreCleanupError);
187
- }
188
- }
189
- };
190
- }
191
-
192
- export {
193
- createAsyncQueue,
194
- stream,
195
- mergeStreams,
196
- broadcast
197
- };
@@ -1,374 +0,0 @@
1
- import { createRequire as __spectrumCreateRequire } from "node:module"; const require = __spectrumCreateRequire(import.meta.url);
2
-
3
- // src/utils/vcard.ts
4
- import vCard from "vcf";
5
- var asPropertyArray = (prop) => {
6
- if (!prop) {
7
- return [];
8
- }
9
- const arr = Array.isArray(prop) ? prop : [prop];
10
- return arr;
11
- };
12
- var propString = (prop) => {
13
- const [first] = asPropertyArray(prop);
14
- const value = first?.valueOf().trim();
15
- return value ? value : void 0;
16
- };
17
- var paramTypes = (prop) => {
18
- const { type } = prop;
19
- if (!type) {
20
- return [];
21
- }
22
- return (Array.isArray(type) ? type : [type]).map((t) => t.toLowerCase());
23
- };
24
- var mapPhoneType = (prop) => {
25
- const types = paramTypes(prop);
26
- if (types.some((t) => t === "cell" || t === "mobile" || t === "iphone")) {
27
- return "mobile";
28
- }
29
- if (types.includes("home")) {
30
- return "home";
31
- }
32
- if (types.includes("work")) {
33
- return "work";
34
- }
35
- if (types.length > 0) {
36
- return "other";
37
- }
38
- return;
39
- };
40
- var mapSimpleType = (prop) => {
41
- const types = paramTypes(prop);
42
- if (types.includes("home")) {
43
- return "home";
44
- }
45
- if (types.includes("work")) {
46
- return "work";
47
- }
48
- if (types.length > 0) {
49
- return "other";
50
- }
51
- return;
52
- };
53
- var splitStructured = (value) => value.split(";").map((part) => part.trim());
54
- var extractName = (card) => {
55
- const fn = propString(card.data.fn);
56
- const n = propString(card.data.n);
57
- if (!(fn || n)) {
58
- return;
59
- }
60
- const result = {};
61
- if (fn) {
62
- result.formatted = fn;
63
- }
64
- if (n) {
65
- const [last, first, middle, prefix, suffix] = splitStructured(n);
66
- if (first) {
67
- result.first = first;
68
- }
69
- if (last) {
70
- result.last = last;
71
- }
72
- if (middle) {
73
- result.middle = middle;
74
- }
75
- if (prefix) {
76
- result.prefix = prefix;
77
- }
78
- if (suffix) {
79
- result.suffix = suffix;
80
- }
81
- }
82
- return result;
83
- };
84
- var extractPhones = (card) => {
85
- const props = asPropertyArray(card.data.tel);
86
- if (props.length === 0) {
87
- return;
88
- }
89
- return props.map((p) => {
90
- const entry = { value: p.valueOf().trim() };
91
- const type = mapPhoneType(p);
92
- if (type) {
93
- entry.type = type;
94
- }
95
- return entry;
96
- });
97
- };
98
- var extractEmails = (card) => {
99
- const props = asPropertyArray(card.data.email);
100
- if (props.length === 0) {
101
- return;
102
- }
103
- return props.map((p) => {
104
- const entry = { value: p.valueOf().trim() };
105
- const type = mapSimpleType(p);
106
- if (type) {
107
- entry.type = type;
108
- }
109
- return entry;
110
- });
111
- };
112
- var extractAddresses = (card) => {
113
- const props = asPropertyArray(card.data.adr);
114
- if (props.length === 0) {
115
- return;
116
- }
117
- return props.map((p) => {
118
- const [, , street, city, region, postalCode, country] = splitStructured(
119
- p.valueOf()
120
- );
121
- const entry = {};
122
- if (street) {
123
- entry.street = street;
124
- }
125
- if (city) {
126
- entry.city = city;
127
- }
128
- if (region) {
129
- entry.region = region;
130
- }
131
- if (postalCode) {
132
- entry.postalCode = postalCode;
133
- }
134
- if (country) {
135
- entry.country = country;
136
- }
137
- const type = mapSimpleType(p);
138
- if (type) {
139
- entry.type = type;
140
- }
141
- return entry;
142
- });
143
- };
144
- var extractOrg = (card) => {
145
- const orgStr = propString(card.data.org);
146
- const title = propString(card.data.title);
147
- if (!(orgStr || title)) {
148
- return;
149
- }
150
- const result = {};
151
- if (orgStr) {
152
- const [name, department] = splitStructured(orgStr);
153
- if (name) {
154
- result.name = name;
155
- }
156
- if (department) {
157
- result.department = department;
158
- }
159
- }
160
- if (title) {
161
- result.title = title;
162
- }
163
- return result;
164
- };
165
- var extractUrls = (card) => {
166
- const props = asPropertyArray(card.data.url);
167
- if (props.length === 0) {
168
- return;
169
- }
170
- return props.map((p) => p.valueOf().trim());
171
- };
172
- var photoMimeFromType = (type) => {
173
- if (!type) {
174
- return "image/jpeg";
175
- }
176
- const lower = type.toLowerCase();
177
- if (lower.startsWith("image/")) {
178
- return lower;
179
- }
180
- return `image/${lower}`;
181
- };
182
- var DATA_URI_PATTERN = /^data:([^;,]+);base64,(.*)$/i;
183
- var extractPhoto = (card) => {
184
- const [prop] = asPropertyArray(card.data.photo);
185
- if (!prop) {
186
- return;
187
- }
188
- const value = prop.valueOf();
189
- const dataUriMatch = DATA_URI_PATTERN.exec(value);
190
- if (dataUriMatch) {
191
- const [, mimeType, base64] = dataUriMatch;
192
- const buf2 = Buffer.from(base64 ?? "", "base64");
193
- return {
194
- mimeType: mimeType ?? "image/jpeg",
195
- read: async () => buf2
196
- };
197
- }
198
- const type = Array.isArray(prop.type) ? prop.type[0] : prop.type;
199
- const buf = Buffer.from(value, "base64");
200
- return {
201
- mimeType: photoMimeFromType(type),
202
- read: async () => buf
203
- };
204
- };
205
- var normalizeVCardInput = (vcf) => {
206
- const withoutBom = vcf.charCodeAt(0) === 65279 ? vcf.slice(1) : vcf;
207
- return withoutBom.replace(/\r\n|\r|\n/g, "\r\n");
208
- };
209
- var fromVCard = (vcf) => {
210
- const [card] = vCard.parse(normalizeVCardInput(vcf));
211
- if (!card) {
212
- throw new Error("Invalid vCard: no cards parsed");
213
- }
214
- const input = { raw: vcf };
215
- const name = extractName(card);
216
- if (name) {
217
- input.name = name;
218
- }
219
- const phones = extractPhones(card);
220
- if (phones) {
221
- input.phones = phones;
222
- }
223
- const emails = extractEmails(card);
224
- if (emails) {
225
- input.emails = emails;
226
- }
227
- const addresses = extractAddresses(card);
228
- if (addresses) {
229
- input.addresses = addresses;
230
- }
231
- const org = extractOrg(card);
232
- if (org) {
233
- input.org = org;
234
- }
235
- const urls = extractUrls(card);
236
- if (urls) {
237
- input.urls = urls;
238
- }
239
- const birthday = propString(card.data.bday);
240
- if (birthday) {
241
- input.birthday = birthday;
242
- }
243
- const note = propString(card.data.note);
244
- if (note) {
245
- input.note = note;
246
- }
247
- const photo = extractPhoto(card);
248
- if (photo) {
249
- input.photo = photo;
250
- }
251
- return input;
252
- };
253
- var formattedNameFor = (name) => {
254
- if (name?.formatted) {
255
- return name.formatted;
256
- }
257
- const parts = [name?.first, name?.middle, name?.last].filter(
258
- (p) => Boolean(p)
259
- );
260
- if (parts.length > 0) {
261
- return parts.join(" ");
262
- }
263
- return "Unknown";
264
- };
265
- var phoneTypeParam = (type) => {
266
- if (type === "mobile") {
267
- return "CELL";
268
- }
269
- if (type === "home" || type === "work" || type === "other") {
270
- return type.toUpperCase();
271
- }
272
- return;
273
- };
274
- var simpleTypeParam = (type) => type ? type.toUpperCase() : void 0;
275
- var photoTypeParam = (mimeType) => {
276
- const sub = mimeType.split("/")[1] ?? "jpeg";
277
- return sub.toUpperCase();
278
- };
279
- var writeName = (card, name) => {
280
- card.set("fn", formattedNameFor(name));
281
- if (!name) {
282
- return;
283
- }
284
- if (name.first || name.last || name.middle || name.prefix || name.suffix) {
285
- card.set(
286
- "n",
287
- [
288
- name.last ?? "",
289
- name.first ?? "",
290
- name.middle ?? "",
291
- name.prefix ?? "",
292
- name.suffix ?? ""
293
- ].join(";")
294
- );
295
- }
296
- };
297
- var writePhones = (card, phones) => {
298
- for (const phone of phones ?? []) {
299
- const type = phoneTypeParam(phone.type);
300
- card.add("tel", phone.value, type ? { type } : void 0);
301
- }
302
- };
303
- var writeEmails = (card, emails) => {
304
- for (const email of emails ?? []) {
305
- const type = simpleTypeParam(email.type);
306
- card.add("email", email.value, type ? { type } : void 0);
307
- }
308
- };
309
- var writeAddresses = (card, addresses) => {
310
- for (const addr of addresses ?? []) {
311
- const value = [
312
- "",
313
- "",
314
- addr.street ?? "",
315
- addr.city ?? "",
316
- addr.region ?? "",
317
- addr.postalCode ?? "",
318
- addr.country ?? ""
319
- ].join(";");
320
- const type = simpleTypeParam(addr.type);
321
- card.add("adr", value, type ? { type } : void 0);
322
- }
323
- };
324
- var writeOrg = (card, org) => {
325
- if (!org) {
326
- return;
327
- }
328
- if (org.name || org.department) {
329
- card.set("org", [org.name ?? "", org.department ?? ""].join(";"));
330
- }
331
- if (org.title) {
332
- card.set("title", org.title);
333
- }
334
- };
335
- var writeUrls = (card, urls) => {
336
- for (const url of urls ?? []) {
337
- card.add("url", url);
338
- }
339
- };
340
- var writePhoto = async (card, photo) => {
341
- if (!photo) {
342
- return;
343
- }
344
- const buf = await photo.read();
345
- card.set("photo", buf.toString("base64"), {
346
- encoding: "b",
347
- type: photoTypeParam(photo.mimeType)
348
- });
349
- };
350
- var toVCard = async (contact) => {
351
- if (typeof contact.raw === "string" && contact.raw.startsWith("BEGIN:VCARD")) {
352
- return contact.raw;
353
- }
354
- const card = new vCard();
355
- writeName(card, contact.name);
356
- writePhones(card, contact.phones);
357
- writeEmails(card, contact.emails);
358
- writeAddresses(card, contact.addresses);
359
- writeOrg(card, contact.org);
360
- writeUrls(card, contact.urls);
361
- if (contact.birthday) {
362
- card.set("bday", contact.birthday);
363
- }
364
- if (contact.note) {
365
- card.set("note", contact.note);
366
- }
367
- await writePhoto(card, contact.photo);
368
- return card.toString();
369
- };
370
-
371
- export {
372
- fromVCard,
373
- toVCard
374
- };
@@ -1,91 +0,0 @@
1
- import { createRequire as __spectrumCreateRequire } from "node:module"; const require = __spectrumCreateRequire(import.meta.url);
2
- import {
3
- fromVCard
4
- } from "./chunk-6UZFVXQF.js";
5
- import {
6
- readSchema
7
- } from "./chunk-UXAKIXVM.js";
8
-
9
- // src/content/contact.ts
10
- import vCard from "vcf";
11
- import z from "zod";
12
- var userRefSchema = z.object({
13
- __platform: z.string(),
14
- id: z.string()
15
- });
16
- var nameSchema = z.object({
17
- formatted: z.string().optional(),
18
- first: z.string().optional(),
19
- last: z.string().optional(),
20
- middle: z.string().optional(),
21
- prefix: z.string().optional(),
22
- suffix: z.string().optional()
23
- });
24
- var phoneTypeSchema = z.enum(["mobile", "home", "work", "other"]);
25
- var emailTypeSchema = z.enum(["home", "work", "other"]);
26
- var addressTypeSchema = z.enum(["home", "work", "other"]);
27
- var phoneSchema = z.object({
28
- value: z.string(),
29
- type: phoneTypeSchema.optional()
30
- });
31
- var emailSchema = z.object({
32
- value: z.string(),
33
- type: emailTypeSchema.optional()
34
- });
35
- var addressSchema = z.object({
36
- street: z.string().optional(),
37
- city: z.string().optional(),
38
- region: z.string().optional(),
39
- postalCode: z.string().optional(),
40
- country: z.string().optional(),
41
- type: addressTypeSchema.optional()
42
- });
43
- var orgSchema = z.object({
44
- name: z.string().optional(),
45
- title: z.string().optional(),
46
- department: z.string().optional()
47
- });
48
- var photoSchema = z.object({
49
- mimeType: z.string(),
50
- read: readSchema
51
- });
52
- var contactSchema = z.object({
53
- type: z.literal("contact"),
54
- user: userRefSchema.optional(),
55
- name: nameSchema.optional(),
56
- phones: z.array(phoneSchema).optional(),
57
- emails: z.array(emailSchema).optional(),
58
- addresses: z.array(addressSchema).optional(),
59
- org: orgSchema.optional(),
60
- urls: z.array(z.string()).optional(),
61
- birthday: z.string().optional(),
62
- note: z.string().optional(),
63
- photo: photoSchema.optional(),
64
- raw: z.unknown().optional()
65
- });
66
- var asContact = (input) => contactSchema.parse({ type: "contact", ...input });
67
- var isUser = (value) => typeof value === "object" && value !== null && "__platform" in value && "id" in value && typeof value.__platform === "string" && typeof value.id === "string";
68
- function contact(input, details) {
69
- return {
70
- build: async () => {
71
- if (typeof input === "string") {
72
- return asContact(fromVCard(input));
73
- }
74
- if (input instanceof vCard) {
75
- return asContact(fromVCard(input.toString()));
76
- }
77
- if (isUser(input)) {
78
- return asContact({
79
- user: { __platform: input.__platform, id: input.id },
80
- ...details
81
- });
82
- }
83
- return asContact(input);
84
- }
85
- };
86
- }
87
-
88
- export {
89
- asContact,
90
- contact
91
- };