spectrum-ts 0.3.0 → 0.5.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/dist/chunk-UZWRB3FZ.js +624 -0
- package/dist/index.d.ts +133 -3
- package/dist/index.js +131 -16
- package/dist/providers/imessage/index.d.ts +1 -1
- package/dist/providers/imessage/index.js +349 -36
- package/dist/providers/terminal/index.d.ts +1 -1
- package/dist/providers/whatsapp-business/index.d.ts +1 -1
- package/dist/providers/whatsapp-business/index.js +275 -39
- package/dist/{types-DuE2hXuJ.d.ts → types-CfiD_00g.d.ts} +73 -7
- package/package.json +10 -3
- package/dist/chunk-V2PK557T.js +0 -73
- package/dist/chunk-ZRSCHSLZ.js +0 -44
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { C as ContentBuilder, a as ContentInput, b as Content, P as ProviderMessage, c as PlatformDef, d as Platform, e as PlatformProviderConfig, S as SpectrumLike, f as CustomEventStreams, g as Space, M as Message } from './types-
|
|
2
|
-
export { A as AnyPlatformDef, E as EventProducer, h as PlatformInstance, i as PlatformMessage, j as PlatformSpace, k as PlatformUser, l as SchemaMessage
|
|
1
|
+
import { C as ContentBuilder, U as User, a as ContentInput, b as Content, P as ProviderMessage, c as PlatformDef, d as Platform, e as PlatformProviderConfig, S as SpectrumLike, f as CustomEventStreams, g as Space, M as Message } from './types-CfiD_00g.js';
|
|
2
|
+
export { A as AnyPlatformDef, E as EventProducer, h as PlatformInstance, i as PlatformMessage, j as PlatformSpace, k as PlatformUser, l as SchemaMessage } from './types-CfiD_00g.js';
|
|
3
|
+
import vCard from 'vcf';
|
|
3
4
|
import z__default from 'zod';
|
|
4
5
|
export { M as ManagedStream, m as mergeStreams, s as stream } from './stream-DGy4geUK.js';
|
|
5
6
|
import 'hotscript';
|
|
@@ -9,12 +10,138 @@ declare function attachment(input: string | Buffer, options?: {
|
|
|
9
10
|
name?: string;
|
|
10
11
|
}): ContentBuilder;
|
|
11
12
|
|
|
13
|
+
declare const nameSchema: z__default.ZodObject<{
|
|
14
|
+
formatted: z__default.ZodOptional<z__default.ZodString>;
|
|
15
|
+
first: z__default.ZodOptional<z__default.ZodString>;
|
|
16
|
+
last: z__default.ZodOptional<z__default.ZodString>;
|
|
17
|
+
middle: z__default.ZodOptional<z__default.ZodString>;
|
|
18
|
+
prefix: z__default.ZodOptional<z__default.ZodString>;
|
|
19
|
+
suffix: z__default.ZodOptional<z__default.ZodString>;
|
|
20
|
+
}, z__default.core.$strip>;
|
|
21
|
+
declare const phoneSchema: z__default.ZodObject<{
|
|
22
|
+
value: z__default.ZodString;
|
|
23
|
+
type: z__default.ZodOptional<z__default.ZodEnum<{
|
|
24
|
+
mobile: "mobile";
|
|
25
|
+
home: "home";
|
|
26
|
+
work: "work";
|
|
27
|
+
other: "other";
|
|
28
|
+
}>>;
|
|
29
|
+
}, z__default.core.$strip>;
|
|
30
|
+
declare const emailSchema: z__default.ZodObject<{
|
|
31
|
+
value: z__default.ZodString;
|
|
32
|
+
type: z__default.ZodOptional<z__default.ZodEnum<{
|
|
33
|
+
home: "home";
|
|
34
|
+
work: "work";
|
|
35
|
+
other: "other";
|
|
36
|
+
}>>;
|
|
37
|
+
}, z__default.core.$strip>;
|
|
38
|
+
declare const addressSchema: z__default.ZodObject<{
|
|
39
|
+
street: z__default.ZodOptional<z__default.ZodString>;
|
|
40
|
+
city: z__default.ZodOptional<z__default.ZodString>;
|
|
41
|
+
region: z__default.ZodOptional<z__default.ZodString>;
|
|
42
|
+
postalCode: z__default.ZodOptional<z__default.ZodString>;
|
|
43
|
+
country: z__default.ZodOptional<z__default.ZodString>;
|
|
44
|
+
type: z__default.ZodOptional<z__default.ZodEnum<{
|
|
45
|
+
home: "home";
|
|
46
|
+
work: "work";
|
|
47
|
+
other: "other";
|
|
48
|
+
}>>;
|
|
49
|
+
}, z__default.core.$strip>;
|
|
50
|
+
declare const orgSchema: z__default.ZodObject<{
|
|
51
|
+
name: z__default.ZodOptional<z__default.ZodString>;
|
|
52
|
+
title: z__default.ZodOptional<z__default.ZodString>;
|
|
53
|
+
department: z__default.ZodOptional<z__default.ZodString>;
|
|
54
|
+
}, z__default.core.$strip>;
|
|
55
|
+
declare const contactSchema: z__default.ZodObject<{
|
|
56
|
+
type: z__default.ZodLiteral<"contact">;
|
|
57
|
+
user: z__default.ZodOptional<z__default.ZodObject<{
|
|
58
|
+
__platform: z__default.ZodString;
|
|
59
|
+
id: z__default.ZodString;
|
|
60
|
+
}, z__default.core.$strip>>;
|
|
61
|
+
name: z__default.ZodOptional<z__default.ZodObject<{
|
|
62
|
+
formatted: z__default.ZodOptional<z__default.ZodString>;
|
|
63
|
+
first: z__default.ZodOptional<z__default.ZodString>;
|
|
64
|
+
last: z__default.ZodOptional<z__default.ZodString>;
|
|
65
|
+
middle: z__default.ZodOptional<z__default.ZodString>;
|
|
66
|
+
prefix: z__default.ZodOptional<z__default.ZodString>;
|
|
67
|
+
suffix: z__default.ZodOptional<z__default.ZodString>;
|
|
68
|
+
}, z__default.core.$strip>>;
|
|
69
|
+
phones: z__default.ZodOptional<z__default.ZodArray<z__default.ZodObject<{
|
|
70
|
+
value: z__default.ZodString;
|
|
71
|
+
type: z__default.ZodOptional<z__default.ZodEnum<{
|
|
72
|
+
mobile: "mobile";
|
|
73
|
+
home: "home";
|
|
74
|
+
work: "work";
|
|
75
|
+
other: "other";
|
|
76
|
+
}>>;
|
|
77
|
+
}, z__default.core.$strip>>>;
|
|
78
|
+
emails: z__default.ZodOptional<z__default.ZodArray<z__default.ZodObject<{
|
|
79
|
+
value: z__default.ZodString;
|
|
80
|
+
type: z__default.ZodOptional<z__default.ZodEnum<{
|
|
81
|
+
home: "home";
|
|
82
|
+
work: "work";
|
|
83
|
+
other: "other";
|
|
84
|
+
}>>;
|
|
85
|
+
}, z__default.core.$strip>>>;
|
|
86
|
+
addresses: z__default.ZodOptional<z__default.ZodArray<z__default.ZodObject<{
|
|
87
|
+
street: z__default.ZodOptional<z__default.ZodString>;
|
|
88
|
+
city: z__default.ZodOptional<z__default.ZodString>;
|
|
89
|
+
region: z__default.ZodOptional<z__default.ZodString>;
|
|
90
|
+
postalCode: z__default.ZodOptional<z__default.ZodString>;
|
|
91
|
+
country: z__default.ZodOptional<z__default.ZodString>;
|
|
92
|
+
type: z__default.ZodOptional<z__default.ZodEnum<{
|
|
93
|
+
home: "home";
|
|
94
|
+
work: "work";
|
|
95
|
+
other: "other";
|
|
96
|
+
}>>;
|
|
97
|
+
}, z__default.core.$strip>>>;
|
|
98
|
+
org: z__default.ZodOptional<z__default.ZodObject<{
|
|
99
|
+
name: z__default.ZodOptional<z__default.ZodString>;
|
|
100
|
+
title: z__default.ZodOptional<z__default.ZodString>;
|
|
101
|
+
department: z__default.ZodOptional<z__default.ZodString>;
|
|
102
|
+
}, z__default.core.$strip>>;
|
|
103
|
+
urls: z__default.ZodOptional<z__default.ZodArray<z__default.ZodString>>;
|
|
104
|
+
birthday: z__default.ZodOptional<z__default.ZodString>;
|
|
105
|
+
note: z__default.ZodOptional<z__default.ZodString>;
|
|
106
|
+
photo: z__default.ZodOptional<z__default.ZodObject<{
|
|
107
|
+
mimeType: z__default.ZodString;
|
|
108
|
+
read: z__default.ZodFunction<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>>>;
|
|
109
|
+
}, z__default.core.$strip>>;
|
|
110
|
+
raw: z__default.ZodOptional<z__default.ZodUnknown>;
|
|
111
|
+
}, z__default.core.$strip>;
|
|
112
|
+
type Contact = z__default.infer<typeof contactSchema>;
|
|
113
|
+
type ContactName = z__default.infer<typeof nameSchema>;
|
|
114
|
+
type ContactPhone = z__default.infer<typeof phoneSchema>;
|
|
115
|
+
type ContactEmail = z__default.infer<typeof emailSchema>;
|
|
116
|
+
type ContactAddress = z__default.infer<typeof addressSchema>;
|
|
117
|
+
type ContactOrg = z__default.infer<typeof orgSchema>;
|
|
118
|
+
type ContactInput = Omit<Contact, "type">;
|
|
119
|
+
type ContactDetails = Omit<ContactInput, "user">;
|
|
120
|
+
declare function contact(user: User, details?: ContactDetails): ContentBuilder;
|
|
121
|
+
declare function contact(input: string | ContactInput | vCard): ContentBuilder;
|
|
122
|
+
|
|
12
123
|
declare function custom(raw: unknown): ContentBuilder;
|
|
13
124
|
|
|
14
125
|
declare const resolveContents: (items: readonly ContentInput[]) => Promise<Content[]>;
|
|
15
126
|
|
|
16
127
|
declare function text(text: string): ContentBuilder;
|
|
17
128
|
|
|
129
|
+
declare const voiceSchema: z__default.ZodObject<{
|
|
130
|
+
type: z__default.ZodLiteral<"voice">;
|
|
131
|
+
name: z__default.ZodOptional<z__default.ZodString>;
|
|
132
|
+
mimeType: z__default.ZodString;
|
|
133
|
+
duration: z__default.ZodOptional<z__default.ZodNumber>;
|
|
134
|
+
size: z__default.ZodOptional<z__default.ZodNumber>;
|
|
135
|
+
read: z__default.ZodFunction<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>>>;
|
|
136
|
+
stream: z__default.ZodFunction<z__default.ZodTuple<readonly [], null>, z__default.ZodPromise<z__default.ZodCustom<ReadableStream<unknown>, ReadableStream<unknown>>>>;
|
|
137
|
+
}, z__default.core.$strip>;
|
|
138
|
+
type Voice = z__default.infer<typeof voiceSchema>;
|
|
139
|
+
declare function voice(input: string | Buffer, options?: {
|
|
140
|
+
mimeType?: string;
|
|
141
|
+
name?: string;
|
|
142
|
+
duration?: number;
|
|
143
|
+
}): ContentBuilder;
|
|
144
|
+
|
|
18
145
|
declare function definePlatform<_Name extends string, _ConfigSchema extends z__default.ZodType<object>, _UserSchema extends z__default.ZodType<object> | undefined, _SpaceSchema extends z__default.ZodType<object> | undefined, _SpaceParamsSchema extends z__default.ZodType<object> | undefined, _Client, _ResolvedUser extends {
|
|
19
146
|
id: string;
|
|
20
147
|
}, _ResolvedSpace extends {
|
|
@@ -86,4 +213,7 @@ declare const cloud: {
|
|
|
86
213
|
togglePlatform: (projectId: string, projectSecret: string, platform: CloudPlatform, enabled: boolean) => Promise<PlatformsData>;
|
|
87
214
|
};
|
|
88
215
|
|
|
89
|
-
|
|
216
|
+
declare const fromVCard: (vcf: string) => ContactInput;
|
|
217
|
+
declare const toVCard: (contact: Contact) => Promise<string>;
|
|
218
|
+
|
|
219
|
+
export { type CloudPlatform, type Contact, type ContactAddress, type ContactDetails, type ContactEmail, type ContactInput, type ContactName, type ContactOrg, type ContactPhone, Content, ContentBuilder, ContentInput, type DedicatedTokenData, type ImessageInfoData, Message, Platform, PlatformDef, PlatformProviderConfig, type PlatformStatus, type PlatformsData, type SharedTokenData, Space, Spectrum, SpectrumCloudError, type SpectrumInstance, type SubscriptionData, type SubscriptionStatus, type TokenData, User, type Voice, attachment, cloud, contact, custom, definePlatform, fromVCard, resolveContents, text, toVCard, voice };
|
package/dist/index.js
CHANGED
|
@@ -3,21 +3,132 @@ import {
|
|
|
3
3
|
cloud
|
|
4
4
|
} from "./chunk-HXM64ENV.js";
|
|
5
5
|
import {
|
|
6
|
-
attachment
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
attachment,
|
|
7
|
+
bufferToStream,
|
|
8
|
+
contact,
|
|
9
9
|
custom,
|
|
10
|
+
fromVCard,
|
|
10
11
|
mergeStreams,
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
readSchema,
|
|
13
|
+
stream,
|
|
14
|
+
streamSchema,
|
|
15
|
+
toVCard
|
|
16
|
+
} from "./chunk-UZWRB3FZ.js";
|
|
13
17
|
import {
|
|
14
18
|
definePlatform,
|
|
15
19
|
resolveContents,
|
|
16
20
|
text
|
|
17
21
|
} from "./chunk-XEEDIGVK.js";
|
|
18
22
|
|
|
19
|
-
// src/
|
|
23
|
+
// src/content/voice.ts
|
|
24
|
+
import { createReadStream } from "fs";
|
|
25
|
+
import { readFile, stat } from "fs/promises";
|
|
26
|
+
import { basename } from "path";
|
|
27
|
+
import { Readable } from "stream";
|
|
28
|
+
import { lookup as lookupMimeType } from "mime-types";
|
|
20
29
|
import z from "zod";
|
|
30
|
+
var AUDIO_MIME_PATTERN = /^audio\//i;
|
|
31
|
+
var audioMimeSchema = z.string().nonempty().regex(AUDIO_MIME_PATTERN, "voice content requires an audio/* MIME type");
|
|
32
|
+
var voiceSchema = z.object({
|
|
33
|
+
type: z.literal("voice"),
|
|
34
|
+
name: z.string().nonempty().optional(),
|
|
35
|
+
mimeType: audioMimeSchema,
|
|
36
|
+
duration: z.number().nonnegative().optional(),
|
|
37
|
+
size: z.number().int().nonnegative().optional(),
|
|
38
|
+
read: readSchema,
|
|
39
|
+
stream: streamSchema
|
|
40
|
+
});
|
|
41
|
+
var resolveVoiceName = (input, name) => {
|
|
42
|
+
if (name) {
|
|
43
|
+
return name;
|
|
44
|
+
}
|
|
45
|
+
if (typeof input === "string") {
|
|
46
|
+
return basename(input);
|
|
47
|
+
}
|
|
48
|
+
return void 0;
|
|
49
|
+
};
|
|
50
|
+
var resolveVoiceMimeType = (name, mimeType) => {
|
|
51
|
+
if (mimeType) {
|
|
52
|
+
if (!AUDIO_MIME_PATTERN.test(mimeType)) {
|
|
53
|
+
throw new Error(
|
|
54
|
+
`voice content requires an audio/* MIME type, got "${mimeType}".`
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
return mimeType;
|
|
58
|
+
}
|
|
59
|
+
if (name) {
|
|
60
|
+
const resolved = lookupMimeType(name);
|
|
61
|
+
if (resolved && AUDIO_MIME_PATTERN.test(resolved)) {
|
|
62
|
+
return resolved;
|
|
63
|
+
}
|
|
64
|
+
if (resolved) {
|
|
65
|
+
throw new Error(
|
|
66
|
+
`Resolved non-audio MIME type "${resolved}" from name "${name}". Pass options.mimeType explicitly with an audio/* type.`
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
throw new Error(
|
|
71
|
+
"Unable to resolve MIME type for voice content. Pass options.mimeType explicitly."
|
|
72
|
+
);
|
|
73
|
+
};
|
|
74
|
+
var asVoice = (input) => {
|
|
75
|
+
let cached;
|
|
76
|
+
const read = () => {
|
|
77
|
+
cached ??= input.read().catch((err) => {
|
|
78
|
+
cached = void 0;
|
|
79
|
+
throw err;
|
|
80
|
+
});
|
|
81
|
+
return cached;
|
|
82
|
+
};
|
|
83
|
+
const stream2 = input.stream ?? (async () => bufferToStream(await read()));
|
|
84
|
+
return voiceSchema.parse({
|
|
85
|
+
type: "voice",
|
|
86
|
+
name: input.name,
|
|
87
|
+
mimeType: input.mimeType,
|
|
88
|
+
duration: input.duration,
|
|
89
|
+
size: input.size,
|
|
90
|
+
read,
|
|
91
|
+
stream: stream2
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
function voice(input, options) {
|
|
95
|
+
return {
|
|
96
|
+
build: async () => {
|
|
97
|
+
const name = resolveVoiceName(input, options?.name);
|
|
98
|
+
const mimeHint = typeof input === "string" ? basename(input) : name;
|
|
99
|
+
const mimeType = resolveVoiceMimeType(mimeHint, options?.mimeType);
|
|
100
|
+
if (typeof input === "string") {
|
|
101
|
+
const stats = await stat(input);
|
|
102
|
+
if (!stats.isFile()) {
|
|
103
|
+
throw new Error(
|
|
104
|
+
`voice content path "${input}" is not a regular file.`
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
return asVoice({
|
|
108
|
+
name,
|
|
109
|
+
mimeType,
|
|
110
|
+
duration: options?.duration,
|
|
111
|
+
size: stats.size,
|
|
112
|
+
read: () => readFile(input),
|
|
113
|
+
stream: async () => Readable.toWeb(
|
|
114
|
+
createReadStream(input)
|
|
115
|
+
)
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
return asVoice({
|
|
119
|
+
name,
|
|
120
|
+
mimeType,
|
|
121
|
+
duration: options?.duration,
|
|
122
|
+
size: input.byteLength,
|
|
123
|
+
read: async () => input,
|
|
124
|
+
stream: async () => bufferToStream(input)
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// src/spectrum.ts
|
|
131
|
+
import z2 from "zod";
|
|
21
132
|
var providerMessageCoreKeys = /* @__PURE__ */ new Set([
|
|
22
133
|
"content",
|
|
23
134
|
"id",
|
|
@@ -25,16 +136,16 @@ var providerMessageCoreKeys = /* @__PURE__ */ new Set([
|
|
|
25
136
|
"space",
|
|
26
137
|
"timestamp"
|
|
27
138
|
]);
|
|
28
|
-
var spectrumConfigSchema =
|
|
29
|
-
|
|
30
|
-
projectId:
|
|
31
|
-
projectSecret:
|
|
32
|
-
providers:
|
|
139
|
+
var spectrumConfigSchema = z2.union([
|
|
140
|
+
z2.object({
|
|
141
|
+
projectId: z2.string().min(1),
|
|
142
|
+
projectSecret: z2.string().min(1),
|
|
143
|
+
providers: z2.array(z2.custom())
|
|
33
144
|
}),
|
|
34
|
-
|
|
35
|
-
projectId:
|
|
36
|
-
projectSecret:
|
|
37
|
-
providers:
|
|
145
|
+
z2.object({
|
|
146
|
+
projectId: z2.undefined().optional(),
|
|
147
|
+
projectSecret: z2.undefined().optional(),
|
|
148
|
+
providers: z2.array(z2.custom())
|
|
38
149
|
})
|
|
39
150
|
]);
|
|
40
151
|
async function Spectrum(options) {
|
|
@@ -296,10 +407,14 @@ export {
|
|
|
296
407
|
SpectrumCloudError,
|
|
297
408
|
attachment,
|
|
298
409
|
cloud,
|
|
410
|
+
contact,
|
|
299
411
|
custom,
|
|
300
412
|
definePlatform,
|
|
413
|
+
fromVCard,
|
|
301
414
|
mergeStreams,
|
|
302
415
|
resolveContents,
|
|
303
416
|
stream,
|
|
304
|
-
text
|
|
417
|
+
text,
|
|
418
|
+
toVCard,
|
|
419
|
+
voice
|
|
305
420
|
};
|
|
@@ -3,7 +3,7 @@ import { AdvancedIMessage } from '@photon-ai/advanced-imessage';
|
|
|
3
3
|
import { IMessageSDK } from '@photon-ai/imessage-kit';
|
|
4
4
|
import * as z from 'zod';
|
|
5
5
|
import z__default from 'zod';
|
|
6
|
-
import { l as SchemaMessage, d as Platform, c as PlatformDef, P as ProviderMessage } from '../../types-
|
|
6
|
+
import { l as SchemaMessage, d as Platform, c as PlatformDef, P as ProviderMessage } from '../../types-CfiD_00g.js';
|
|
7
7
|
import * as zod_v4_core from 'zod/v4/core';
|
|
8
8
|
import 'hotscript';
|
|
9
9
|
|