@ulvio/client 0.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.
@@ -0,0 +1,440 @@
1
+ import { z } from 'zod';
2
+
3
+ interface UlvioConfig {
4
+ platformApiUrl?: string;
5
+ platformApiKey?: string;
6
+ htmlToPdfApiUrl?: string;
7
+ utilitiesApiUrl?: string;
8
+ }
9
+ interface RequestOptions {
10
+ body?: unknown;
11
+ }
12
+ interface RequestRawOptions {
13
+ body?: BodyInit;
14
+ contentType?: string;
15
+ headers?: Record<string, string>;
16
+ }
17
+ declare class HttpClient {
18
+ private readonly config;
19
+ constructor(config: UlvioConfig);
20
+ private requirePlatform;
21
+ private requireHtmlToPdf;
22
+ private requireUtilities;
23
+ platformRequest<T>(callerName: string, method: string, path: string, options?: RequestOptions): Promise<T>;
24
+ platformRequestRaw(callerName: string, method: string, path: string, options?: RequestRawOptions): Promise<Response>;
25
+ htmlToPdfFetch(callerName: string, path: string, init: RequestInit): Promise<Response>;
26
+ utilitiesRequest<T>(callerName: string, method: string, path: string, options?: RequestOptions): Promise<T>;
27
+ }
28
+
29
+ interface Attachment {
30
+ filename: string;
31
+ /** Base64-encoded file content. */
32
+ content: string;
33
+ content_type: string;
34
+ }
35
+ interface TransactionalMailSendRequest {
36
+ from: string;
37
+ to: string[];
38
+ subject: string;
39
+ body_html?: string;
40
+ body_text?: string;
41
+ reply_to?: string;
42
+ attachments?: Attachment[];
43
+ }
44
+ interface TransactionalMailSendResponse {
45
+ message_id: string;
46
+ }
47
+ declare class MailClient {
48
+ private readonly http;
49
+ constructor(http: HttpClient);
50
+ sendTransactional(params: TransactionalMailSendRequest): Promise<TransactionalMailSendResponse>;
51
+ }
52
+
53
+ interface MailboxSendRequest {
54
+ to: string[];
55
+ cc?: string[];
56
+ bcc?: string[];
57
+ subject: string;
58
+ body_html?: string;
59
+ body_text?: string;
60
+ /** Message ID to reply to. Threads the message correctly. */
61
+ reply_to_id?: string;
62
+ attachments?: Attachment[];
63
+ }
64
+ interface MailboxSendResponse {
65
+ message_id: string;
66
+ }
67
+ interface MailboxAttachment {
68
+ id: string;
69
+ filename: string;
70
+ content_type: string;
71
+ size_bytes: number;
72
+ }
73
+ interface MailboxMessageSummary {
74
+ id: string;
75
+ subject: string;
76
+ from: string;
77
+ to: string[];
78
+ /** First 150 characters of the body, HTML stripped. */
79
+ preview: string;
80
+ received_at: string;
81
+ has_attachments: boolean;
82
+ is_read: boolean;
83
+ is_processed: boolean;
84
+ processed_at: string | null;
85
+ }
86
+ interface MailboxMessagesListResponse {
87
+ messages: MailboxMessageSummary[];
88
+ total: number;
89
+ }
90
+ interface MailboxMessageDetail {
91
+ id: string;
92
+ subject: string;
93
+ from: string;
94
+ to: string[];
95
+ cc: string[];
96
+ bcc: string[];
97
+ body_html?: string;
98
+ body_text?: string;
99
+ received_at: string;
100
+ is_read: boolean;
101
+ is_processed: boolean;
102
+ processed_at: string | null;
103
+ attachments: MailboxAttachment[];
104
+ }
105
+ interface MailboxMarkProcessedResponse {
106
+ ok: true;
107
+ id: string;
108
+ already_processed: boolean;
109
+ processed_at: string;
110
+ }
111
+ interface MailboxConnectorStatus {
112
+ healthy: boolean;
113
+ state: 'healthy' | 'unhealthy';
114
+ /** ISO timestamp of the last state change, or null if never changed. */
115
+ changed_at: string | null;
116
+ }
117
+ declare class MailboxClient {
118
+ private readonly http;
119
+ constructor(http: HttpClient);
120
+ send(params: MailboxSendRequest): Promise<MailboxSendResponse>;
121
+ list(limit?: number): Promise<MailboxMessagesListResponse>;
122
+ get(id: string): Promise<MailboxMessageDetail>;
123
+ markProcessed(id: string): Promise<MailboxMarkProcessedResponse>;
124
+ /**
125
+ * Download a mailbox message attachment as a Buffer.
126
+ */
127
+ getAttachment(messageId: string, attachmentId: string): Promise<Buffer>;
128
+ getConnectorStatus(): Promise<MailboxConnectorStatus>;
129
+ /**
130
+ * Dev-only: toggle the mock connector's health state.
131
+ */
132
+ setConnectorStatus(healthy: boolean): Promise<MailboxConnectorStatus>;
133
+ }
134
+
135
+ interface SmsSendRequest {
136
+ /** Sender phone number in E.164 format. */
137
+ from: string;
138
+ /** Recipient phone number in E.164 format. */
139
+ to: string;
140
+ /** SMS text content. Max 1600 characters. */
141
+ body: string;
142
+ }
143
+ interface SmsSendResponse {
144
+ message_id: string;
145
+ status: 'queued';
146
+ }
147
+ declare class SmsClient {
148
+ private readonly http;
149
+ constructor(http: HttpClient);
150
+ send(params: SmsSendRequest): Promise<SmsSendResponse>;
151
+ }
152
+
153
+ interface WhatsAppParameter {
154
+ type: 'text' | 'image' | 'document' | 'video';
155
+ parameter_name?: string;
156
+ text?: string;
157
+ image?: {
158
+ link: string;
159
+ };
160
+ document?: {
161
+ link: string;
162
+ filename: string;
163
+ };
164
+ video?: {
165
+ link: string;
166
+ };
167
+ }
168
+ interface WhatsAppComponent {
169
+ type: 'header' | 'body' | 'button';
170
+ sub_type?: 'url' | 'quick_reply';
171
+ index?: number;
172
+ parameters: WhatsAppParameter[];
173
+ }
174
+ interface WhatsAppSendRequest {
175
+ /** Recipient phone number in E.164 format. */
176
+ to: string;
177
+ /** Pre-approved WhatsApp template name. */
178
+ template_name: string;
179
+ /** BCP 47 language code (e.g. "en", "nl", "fr"). */
180
+ language_code: string;
181
+ components?: WhatsAppComponent[];
182
+ }
183
+ interface WhatsAppSendResponse {
184
+ message_id: string;
185
+ status: 'queued';
186
+ }
187
+ declare class WhatsAppClient {
188
+ private readonly http;
189
+ constructor(http: HttpClient);
190
+ send(params: WhatsAppSendRequest): Promise<WhatsAppSendResponse>;
191
+ }
192
+
193
+ interface VoiceTranscribeRequest {
194
+ /** Base64-encoded audio buffer. */
195
+ file: string;
196
+ file_name: string;
197
+ /** Optional BCP-47 language code (e.g. "en", "nl"). */
198
+ language_code?: string;
199
+ }
200
+ interface VoiceTranscribeResponse {
201
+ job_id: string;
202
+ status: string;
203
+ text: string;
204
+ }
205
+ declare class VoiceClient {
206
+ private readonly http;
207
+ constructor(http: HttpClient);
208
+ transcribe(params: VoiceTranscribeRequest): Promise<VoiceTranscribeResponse>;
209
+ }
210
+
211
+ interface FileUploadResponse {
212
+ key: string;
213
+ content_type: string;
214
+ size_bytes: number;
215
+ }
216
+ interface FileListItem {
217
+ key: string;
218
+ is_folder: boolean;
219
+ content_type: string | null;
220
+ size_bytes: number;
221
+ created_at: string | null;
222
+ }
223
+ interface FileListResponse {
224
+ files: FileListItem[];
225
+ next_cursor: string | null;
226
+ }
227
+ interface PresignedUrlResponse {
228
+ url: string;
229
+ expires_in: number;
230
+ }
231
+ type FileUploadBody = Buffer | Uint8Array | ReadableStream | string;
232
+ declare class FilesClient {
233
+ private readonly http;
234
+ constructor(http: HttpClient);
235
+ upload(key: string, file: FileUploadBody, contentType?: string): Promise<FileUploadResponse>;
236
+ /**
237
+ * Download a file. Returns the raw Response for streaming.
238
+ */
239
+ get(key: string): Promise<Response>;
240
+ list(prefix?: string, limit?: number, cursor?: string): Promise<FileListResponse>;
241
+ delete(key: string): Promise<{
242
+ ok: true;
243
+ }>;
244
+ deleteMany(prefix: string): Promise<{
245
+ ok: true;
246
+ deleted: number;
247
+ }>;
248
+ /**
249
+ * Generate a time-limited download URL for a file.
250
+ * @param expiresIn TTL in seconds (default 3600, min 60, max 86400)
251
+ */
252
+ presignedDownloadUrl(key: string, expiresIn?: number): Promise<PresignedUrlResponse>;
253
+ /**
254
+ * Generate a time-limited upload URL for a file.
255
+ * @param expiresIn TTL in seconds (default 3600, min 60, max 86400)
256
+ * @param maxSize Max file size in bytes (default 50MB)
257
+ */
258
+ presignedUploadUrl(key: string, contentType: string, expiresIn?: number, maxSize?: number): Promise<PresignedUrlResponse>;
259
+ }
260
+
261
+ type Role = 'user' | 'assistant' | 'system';
262
+ interface InputMessage {
263
+ role: Role;
264
+ content: string;
265
+ }
266
+ type Input = string | InputMessage[];
267
+ interface ParseRequest<TSchema extends z.ZodType> {
268
+ /** Model identifier, e.g. "claude-opus-4-7", "claude-sonnet-4-6". */
269
+ model: string;
270
+ input: Input;
271
+ /** Zod schema describing the structured output shape. */
272
+ schema: TSchema;
273
+ }
274
+ interface ParseResponse<T> {
275
+ data: T;
276
+ }
277
+ type StreamEvent<T> = {
278
+ type: 'partial';
279
+ data: Partial<T>;
280
+ } | {
281
+ type: 'complete';
282
+ data: T;
283
+ } | {
284
+ type: 'error';
285
+ message: string;
286
+ };
287
+ declare class AiClient {
288
+ private readonly http;
289
+ constructor(http: HttpClient);
290
+ parse<TSchema extends z.ZodType>(params: ParseRequest<TSchema>): Promise<z.infer<TSchema>>;
291
+ stream<TSchema extends z.ZodType>(params: ParseRequest<TSchema>): AsyncGenerator<StreamEvent<z.infer<TSchema>>, void, void>;
292
+ }
293
+
294
+ interface PdfOptions {
295
+ format?: string;
296
+ printBackground?: boolean;
297
+ margin?: {
298
+ top?: string;
299
+ right?: string;
300
+ bottom?: string;
301
+ left?: string;
302
+ };
303
+ }
304
+ interface HtmlToPdfBase64Request {
305
+ /** Base64-encoded HTML content. Provide either `html` or `sourceUrl`. */
306
+ html?: string;
307
+ sourceUrl?: string;
308
+ outputMode: 'base64';
309
+ options?: PdfOptions;
310
+ }
311
+ interface HtmlToPdfUploadRequest {
312
+ html?: string;
313
+ sourceUrl?: string;
314
+ /** Pre-signed URL the service will PUT the rendered PDF to. */
315
+ uploadUrl: string;
316
+ options?: PdfOptions;
317
+ }
318
+ type HtmlToPdfRequest = HtmlToPdfBase64Request | HtmlToPdfUploadRequest;
319
+ interface HtmlToPdfBase64Response {
320
+ pdf: string;
321
+ }
322
+ interface HtmlToPdfUploadResponse {
323
+ uploaded: true;
324
+ bytes: number;
325
+ }
326
+ type HtmlToPdfResponse = HtmlToPdfBase64Response | HtmlToPdfUploadResponse;
327
+ interface QueuedEvent {
328
+ position: number;
329
+ }
330
+ interface ProcessingEvent {
331
+ step: string;
332
+ progress: number;
333
+ }
334
+ interface HtmlToPdfCallbacks {
335
+ onQueued?: (data: QueuedEvent) => void;
336
+ onProcessing?: (data: ProcessingEvent) => void;
337
+ }
338
+ declare class HtmlToPdfClient {
339
+ private readonly http;
340
+ constructor(http: HttpClient);
341
+ convert(params: HtmlToPdfBase64Request, callbacks?: HtmlToPdfCallbacks): Promise<HtmlToPdfBase64Response>;
342
+ convert(params: HtmlToPdfUploadRequest, callbacks?: HtmlToPdfCallbacks): Promise<HtmlToPdfUploadResponse>;
343
+ }
344
+
345
+ interface MjmlValidationError {
346
+ line: number;
347
+ message: string;
348
+ tagName: string;
349
+ formattedMessage: string;
350
+ }
351
+ interface MjmlCompileRequest {
352
+ mjml: string;
353
+ options?: {
354
+ minify?: boolean;
355
+ beautify?: boolean;
356
+ validationLevel?: 'strict' | 'soft' | 'skip';
357
+ };
358
+ }
359
+ interface MjmlCompileResponse {
360
+ html: string;
361
+ errors: MjmlValidationError[];
362
+ }
363
+ interface LiquidRenderRequest {
364
+ template: string;
365
+ data: Record<string, unknown>;
366
+ }
367
+ interface LiquidRenderResponse {
368
+ result: string;
369
+ }
370
+ interface LiquidVariablesRequest {
371
+ template: string;
372
+ }
373
+ interface LiquidVariablesResponse {
374
+ variables: string[];
375
+ }
376
+ interface MarkdownRenderRequest {
377
+ markdown: string;
378
+ }
379
+ interface MarkdownRenderResponse {
380
+ html: string;
381
+ }
382
+ interface RenderEmailRequest {
383
+ mjml: string;
384
+ data: Record<string, unknown>;
385
+ options?: {
386
+ minify?: boolean;
387
+ beautify?: boolean;
388
+ validationLevel?: 'strict' | 'soft' | 'skip';
389
+ };
390
+ }
391
+ interface RenderEmailResponse {
392
+ html: string;
393
+ errors: MjmlValidationError[];
394
+ }
395
+ declare class UtilitiesClient {
396
+ private readonly http;
397
+ constructor(http: HttpClient);
398
+ compileMjml(params: MjmlCompileRequest): Promise<MjmlCompileResponse>;
399
+ renderLiquid(params: LiquidRenderRequest): Promise<LiquidRenderResponse>;
400
+ extractLiquidVariables(params: LiquidVariablesRequest): Promise<LiquidVariablesResponse>;
401
+ renderMarkdown(params: MarkdownRenderRequest): Promise<MarkdownRenderResponse>;
402
+ renderEmail(params: RenderEmailRequest): Promise<RenderEmailResponse>;
403
+ }
404
+
405
+ interface ErrorResponseBody {
406
+ error: {
407
+ code?: string;
408
+ message: string;
409
+ };
410
+ }
411
+ declare const CONNECTOR_UNHEALTHY_CODE = "CONNECTOR_UNHEALTHY";
412
+ declare const PLATFORM_NOT_CONFIGURED_CODE = "platform_not_configured";
413
+ declare const HTML_TO_PDF_NOT_CONFIGURED_CODE = "html_to_pdf_not_configured";
414
+ declare const UTILITIES_NOT_CONFIGURED_CODE = "utilities_not_configured";
415
+ declare class UlvioError extends Error {
416
+ readonly code: string;
417
+ readonly status?: number;
418
+ readonly response?: unknown;
419
+ constructor(code: string, message: string, options?: {
420
+ status?: number;
421
+ response?: unknown;
422
+ cause?: unknown;
423
+ });
424
+ }
425
+ declare function isConnectorUnhealthyError(err: unknown): boolean;
426
+
427
+ declare class Ulvio {
428
+ readonly mail: MailClient;
429
+ readonly mailbox: MailboxClient;
430
+ readonly sms: SmsClient;
431
+ readonly whatsapp: WhatsAppClient;
432
+ readonly voice: VoiceClient;
433
+ readonly files: FilesClient;
434
+ readonly ai: AiClient;
435
+ readonly htmlToPdf: HtmlToPdfClient;
436
+ readonly utilities: UtilitiesClient;
437
+ constructor(config?: UlvioConfig);
438
+ }
439
+
440
+ export { AiClient, type Attachment, CONNECTOR_UNHEALTHY_CODE, type ErrorResponseBody, type FileListItem, type FileListResponse, type FileUploadBody, type FileUploadResponse, FilesClient, HTML_TO_PDF_NOT_CONFIGURED_CODE, type HtmlToPdfBase64Request, type HtmlToPdfBase64Response, type HtmlToPdfCallbacks, HtmlToPdfClient, type HtmlToPdfRequest, type HtmlToPdfResponse, type HtmlToPdfUploadRequest, type HtmlToPdfUploadResponse, type Input, type InputMessage, type LiquidRenderRequest, type LiquidRenderResponse, type LiquidVariablesRequest, type LiquidVariablesResponse, MailClient, type MailboxAttachment, MailboxClient, type MailboxConnectorStatus, type MailboxMarkProcessedResponse, type MailboxMessageDetail, type MailboxMessageSummary, type MailboxMessagesListResponse, type MailboxSendRequest, type MailboxSendResponse, type MarkdownRenderRequest, type MarkdownRenderResponse, type MjmlCompileRequest, type MjmlCompileResponse, type MjmlValidationError, PLATFORM_NOT_CONFIGURED_CODE, type ParseRequest, type ParseResponse, type PdfOptions, type PresignedUrlResponse, type ProcessingEvent, type QueuedEvent, type RenderEmailRequest, type RenderEmailResponse, type Role, SmsClient, type SmsSendRequest, type SmsSendResponse, type StreamEvent, type TransactionalMailSendRequest, type TransactionalMailSendResponse, UTILITIES_NOT_CONFIGURED_CODE, Ulvio, type UlvioConfig, UlvioError, UtilitiesClient, VoiceClient, type VoiceTranscribeRequest, type VoiceTranscribeResponse, WhatsAppClient, type WhatsAppComponent, type WhatsAppParameter, type WhatsAppSendRequest, type WhatsAppSendResponse, isConnectorUnhealthyError };