@tratto/email 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,562 @@
1
+ declare class TrattoError extends Error {
2
+ readonly code: string;
3
+ readonly statusCode: number;
4
+ readonly docs?: string | undefined;
5
+ constructor(message: string, code: string, statusCode: number, docs?: string | undefined);
6
+ }
7
+
8
+ interface FetchOptions {
9
+ body?: unknown;
10
+ contentType?: string;
11
+ headers?: Record<string, string>;
12
+ }
13
+ declare abstract class BaseResource {
14
+ protected readonly apiKey: string;
15
+ protected readonly baseUrl: string;
16
+ constructor(apiKey: string, baseUrl: string);
17
+ protected fetch<T>(method: string, path: string, options?: FetchOptions): Promise<T>;
18
+ protected fetchData<T>(method: string, path: string, options?: FetchOptions): Promise<T>;
19
+ protected buildQuery(params: Record<string, string | number | boolean | Date | null | undefined>): string;
20
+ }
21
+
22
+ interface Pagination {
23
+ hasMore: boolean;
24
+ nextCursor: string | null;
25
+ }
26
+ interface PaginatedResponse<T> {
27
+ data: T[];
28
+ pagination: Pagination;
29
+ }
30
+ interface SendEmailParams {
31
+ from: string;
32
+ to: string | string[];
33
+ subject: string;
34
+ html?: string;
35
+ text?: string;
36
+ cc?: string[];
37
+ bcc?: string[];
38
+ replyTo?: string;
39
+ templateId?: string;
40
+ variables?: Record<string, unknown>;
41
+ tags?: string[];
42
+ scheduledAt?: Date | string;
43
+ headers?: Record<string, string>;
44
+ }
45
+ interface ListEmailsParams {
46
+ after?: string;
47
+ limit?: number;
48
+ status?: string;
49
+ domainId?: string;
50
+ tags?: string;
51
+ dateFrom?: Date | string;
52
+ dateTo?: Date | string;
53
+ }
54
+ interface EmailSummary {
55
+ id: string;
56
+ from: string;
57
+ to: string[];
58
+ subject: string;
59
+ status: string;
60
+ createdAt: string;
61
+ sentAt: string | null;
62
+ scheduledAt: string | null;
63
+ tags?: string[];
64
+ }
65
+ interface EmailEvent {
66
+ type: string;
67
+ occurredAt: string;
68
+ data?: Record<string, unknown>;
69
+ }
70
+ interface EmailDetail extends EmailSummary {
71
+ html?: string;
72
+ text?: string;
73
+ cc?: string[];
74
+ bcc?: string[];
75
+ replyTo?: string;
76
+ templateId?: string;
77
+ headers?: Record<string, string>;
78
+ events: EmailEvent[];
79
+ }
80
+ type ContactStatus = 'subscribed' | 'unsubscribed' | 'bounced' | 'complained';
81
+ interface Contact {
82
+ id: string;
83
+ email: string;
84
+ firstName: string;
85
+ lastName: string;
86
+ status: ContactStatus;
87
+ tags: string[];
88
+ customFields: Record<string, unknown>;
89
+ createdAt: string;
90
+ }
91
+ interface CreateContactParams {
92
+ email: string;
93
+ firstName?: string;
94
+ lastName?: string;
95
+ status?: ContactStatus;
96
+ tags?: string[];
97
+ customFields?: Record<string, unknown>;
98
+ }
99
+ interface UpdateContactParams {
100
+ firstName?: string;
101
+ lastName?: string;
102
+ status?: ContactStatus;
103
+ tags?: string[];
104
+ customFields?: Record<string, unknown>;
105
+ }
106
+ interface ListContactsParams {
107
+ status?: ContactStatus;
108
+ audienceId?: string;
109
+ tag?: string;
110
+ after?: string;
111
+ limit?: number;
112
+ }
113
+ interface ImportJobStatus {
114
+ jobId: string;
115
+ status: 'processing' | 'completed' | 'failed';
116
+ totalRows: number;
117
+ processedRows: number;
118
+ failedRows: number;
119
+ errors: string[];
120
+ completedAt: string | null;
121
+ }
122
+ type AudienceRuleOperator = 'equals' | 'not_equals' | 'contains' | 'not_contains' | 'array_contains';
123
+ interface AudienceRule {
124
+ field: string;
125
+ operator: AudienceRuleOperator;
126
+ value: string | number | boolean;
127
+ }
128
+ interface Audience {
129
+ id: string;
130
+ name: string;
131
+ description: string;
132
+ contactCount: number;
133
+ rules: AudienceRule[];
134
+ createdAt: string;
135
+ }
136
+ interface CreateAudienceParams {
137
+ name: string;
138
+ description?: string;
139
+ rules?: AudienceRule[];
140
+ }
141
+ interface ListAudiencesParams {
142
+ after?: string;
143
+ limit?: number;
144
+ }
145
+ interface AddContactsToAudienceResult {
146
+ added: number;
147
+ alreadyInAudience: number;
148
+ notFound: number;
149
+ }
150
+ type CampaignStatus = 'draft' | 'sending' | 'scheduled' | 'paused' | 'completed';
151
+ interface CampaignStats {
152
+ total: number;
153
+ sent: number;
154
+ delivered: number;
155
+ opened: number;
156
+ clicked: number;
157
+ bounced: number;
158
+ }
159
+ interface Campaign {
160
+ id: string;
161
+ name: string;
162
+ status: CampaignStatus;
163
+ templateId: string;
164
+ audienceId: string;
165
+ fromName: string;
166
+ fromEmail: string;
167
+ subjectA: string;
168
+ subjectB: string | null;
169
+ scheduledAt: string | null;
170
+ sentAt: string | null;
171
+ stats: CampaignStats;
172
+ createdAt: string;
173
+ }
174
+ interface CampaignStatsDetail {
175
+ campaignId: string;
176
+ status: CampaignStatus;
177
+ stats: CampaignStats;
178
+ rates: {
179
+ deliveryRate: number;
180
+ openRate: number;
181
+ clickRate: number;
182
+ bounceRate: number;
183
+ };
184
+ }
185
+ interface CreateCampaignParams {
186
+ name: string;
187
+ templateId: string;
188
+ audienceId: string;
189
+ fromName: string;
190
+ fromEmail: string;
191
+ subjectA: string;
192
+ subjectB?: string;
193
+ }
194
+ interface ListCampaignsParams {
195
+ status?: CampaignStatus;
196
+ after?: string;
197
+ limit?: number;
198
+ }
199
+ interface SendCampaignParams {
200
+ scheduledAt?: Date | string;
201
+ }
202
+ type TemplateStatus = 'draft' | 'published';
203
+ interface TemplateSummary {
204
+ id: string;
205
+ name: string;
206
+ status: TemplateStatus;
207
+ version: number;
208
+ createdAt: string;
209
+ updatedAt: string;
210
+ }
211
+ interface Template extends TemplateSummary {
212
+ html: string;
213
+ }
214
+ interface CreateTemplateParams {
215
+ name: string;
216
+ html?: string;
217
+ }
218
+ interface UpdateTemplateParams {
219
+ name?: string;
220
+ html?: string;
221
+ status?: TemplateStatus;
222
+ }
223
+ interface ListTemplatesParams {
224
+ limit?: number;
225
+ after?: string;
226
+ status?: TemplateStatus;
227
+ }
228
+ interface TemplateVersionSummary {
229
+ version: number;
230
+ savedAt: string;
231
+ }
232
+ interface TemplateVersion extends TemplateVersionSummary {
233
+ html: string;
234
+ }
235
+ type WebhookEventType = 'sent' | 'delivered' | 'opened' | 'clicked' | 'bounced' | 'complained' | 'unsubscribed';
236
+ type WebhookStatus = 'active' | 'disabled';
237
+ type WebhookDeliveryStatus = 'success' | 'failed' | 'scheduled';
238
+ interface Webhook {
239
+ id: string;
240
+ url: string;
241
+ events: WebhookEventType[];
242
+ status: WebhookStatus;
243
+ secretPrefix: string;
244
+ failureCount: number;
245
+ createdAt: string;
246
+ }
247
+ interface WebhookDelivery {
248
+ id: string;
249
+ webhookId: string;
250
+ eventType: string;
251
+ status: WebhookDeliveryStatus;
252
+ httpStatus: number | null;
253
+ responseBody: string | null;
254
+ retryCount: number;
255
+ attemptedAt: string;
256
+ }
257
+ interface CreateWebhookParams {
258
+ url: string;
259
+ events: WebhookEventType[];
260
+ }
261
+ interface ListWebhookDeliveriesParams {
262
+ after?: string;
263
+ limit?: number;
264
+ }
265
+ type DomainStatus = 'pending' | 'verified' | 'failed';
266
+ interface DomainRecord {
267
+ type: string;
268
+ host: string;
269
+ value: string;
270
+ verified: boolean;
271
+ }
272
+ interface DomainSummary {
273
+ id: string;
274
+ domain: string;
275
+ status: DomainStatus;
276
+ dkimSelector: string;
277
+ createdAt: string;
278
+ updatedAt: string;
279
+ verifiedAt: string | null;
280
+ }
281
+ interface Domain extends DomainSummary {
282
+ records: DomainRecord[];
283
+ }
284
+ interface ListDomainsParams {
285
+ after?: string;
286
+ limit?: number;
287
+ }
288
+ type ApiKeyEnv = 'live' | 'test';
289
+ interface ApiKey {
290
+ id: string;
291
+ name: string;
292
+ prefix: string;
293
+ env: ApiKeyEnv;
294
+ permissions: string[];
295
+ createdAt: string;
296
+ lastUsedAt: string | null;
297
+ revokedAt: string | null;
298
+ }
299
+ interface ApiKeyCreated extends ApiKey {
300
+ key: string;
301
+ }
302
+ interface CreateApiKeyParams {
303
+ name: string;
304
+ env: ApiKeyEnv;
305
+ permissions: string[];
306
+ }
307
+ interface ListApiKeysParams {
308
+ after?: string;
309
+ limit?: number;
310
+ }
311
+ type AnalyticsPeriod = '7d' | '30d' | '90d';
312
+ interface AnalyticsSummary {
313
+ period: AnalyticsPeriod;
314
+ totalSent: number;
315
+ delivered: number;
316
+ opened: number;
317
+ clicked: number;
318
+ bounced: number;
319
+ complained: number;
320
+ deliveryRate: number;
321
+ openRate: number;
322
+ clickRate: number;
323
+ bounceRate: number;
324
+ }
325
+ interface TimeseriesPoint {
326
+ date: string;
327
+ sent: number;
328
+ delivered: number;
329
+ opened: number;
330
+ bounced: number;
331
+ }
332
+ type FlowStatus = 'draft' | 'active' | 'inactive';
333
+ type FlowTriggerType = 'contact_joins_audience' | 'contact_tag_added' | 'contact_tag_removed' | 'email_event' | 'manual';
334
+ type FlowStepType = 'send_email' | 'wait' | 'branch' | 'update_contact' | 'webhook_call';
335
+ interface FlowTrigger {
336
+ type: FlowTriggerType;
337
+ config: Record<string, string>;
338
+ }
339
+ interface FlowStep {
340
+ id: string;
341
+ type: FlowStepType;
342
+ config: Record<string, string>;
343
+ }
344
+ interface Flow {
345
+ id: string;
346
+ name: string;
347
+ status: FlowStatus;
348
+ trigger: FlowTrigger;
349
+ steps: FlowStep[];
350
+ enrollments: number;
351
+ createdAt: string;
352
+ updatedAt: string;
353
+ }
354
+ interface CreateFlowParams {
355
+ name: string;
356
+ }
357
+ interface UpdateFlowParams {
358
+ name?: string;
359
+ trigger?: FlowTrigger;
360
+ steps?: FlowStep[];
361
+ }
362
+ interface ListFlowsParams {
363
+ after?: string;
364
+ limit?: number;
365
+ }
366
+ type WorkspacePlan = 'free' | 'starter' | 'growth';
367
+ type WorkspaceMemberRole = 'owner' | 'admin' | 'member';
368
+ type WorkspaceLocale = 'it' | 'en';
369
+ interface Workspace {
370
+ id: string;
371
+ name: string;
372
+ slug: string;
373
+ timezone: string;
374
+ locale: WorkspaceLocale;
375
+ plan: WorkspacePlan;
376
+ createdAt: string;
377
+ }
378
+ interface WorkspaceMember {
379
+ userId: string;
380
+ email: string;
381
+ displayName: string | null;
382
+ role: WorkspaceMemberRole;
383
+ joinedAt: string;
384
+ }
385
+ interface WorkspacePreferences {
386
+ locale: WorkspaceLocale;
387
+ emailNotifications: {
388
+ bounces: boolean;
389
+ weeklyReport: boolean;
390
+ billingAlerts: boolean;
391
+ };
392
+ }
393
+ interface UpdateWorkspaceParams {
394
+ name?: string;
395
+ slug?: string;
396
+ timezone?: string;
397
+ locale?: WorkspaceLocale;
398
+ }
399
+ interface UpdateWorkspacePreferencesParams {
400
+ locale?: WorkspaceLocale;
401
+ emailNotifications?: {
402
+ bounces?: boolean;
403
+ weeklyReport?: boolean;
404
+ billingAlerts?: boolean;
405
+ };
406
+ }
407
+ interface InviteMemberParams {
408
+ email: string;
409
+ role: 'admin' | 'member';
410
+ }
411
+ interface UpdateMemberParams {
412
+ role: WorkspaceMemberRole;
413
+ }
414
+
415
+ declare class EmailsResource extends BaseResource {
416
+ send(params: SendEmailParams, idempotencyKey?: string): Promise<{
417
+ id: string;
418
+ }>;
419
+ list(params?: ListEmailsParams): Promise<PaginatedResponse<EmailSummary>>;
420
+ get(id: string): Promise<EmailDetail>;
421
+ listEvents(id: string): Promise<EmailEvent[]>;
422
+ }
423
+
424
+ declare class ContactsResource extends BaseResource {
425
+ create(params: CreateContactParams): Promise<{
426
+ id: string;
427
+ }>;
428
+ list(params?: ListContactsParams): Promise<PaginatedResponse<Contact>>;
429
+ update(id: string, params: UpdateContactParams): Promise<{
430
+ id: string;
431
+ }>;
432
+ importCsv(csvText: string): Promise<{
433
+ jobId: string;
434
+ totalRows: number;
435
+ }>;
436
+ getImportJob(jobId: string): Promise<ImportJobStatus>;
437
+ }
438
+
439
+ declare class AudiencesResource extends BaseResource {
440
+ create(params: CreateAudienceParams): Promise<{
441
+ id: string;
442
+ }>;
443
+ list(params?: ListAudiencesParams): Promise<PaginatedResponse<Audience>>;
444
+ get(id: string): Promise<Audience>;
445
+ addContacts(audienceId: string, contactIds: string[]): Promise<AddContactsToAudienceResult>;
446
+ }
447
+
448
+ declare class CampaignsResource extends BaseResource {
449
+ create(params: CreateCampaignParams): Promise<{
450
+ id: string;
451
+ }>;
452
+ list(params?: ListCampaignsParams): Promise<PaginatedResponse<Campaign>>;
453
+ get(id: string): Promise<Campaign>;
454
+ getStats(id: string): Promise<CampaignStatsDetail>;
455
+ send(id: string, params?: SendCampaignParams): Promise<{
456
+ status: string;
457
+ }>;
458
+ pause(id: string): Promise<{
459
+ status: string;
460
+ }>;
461
+ testSend(id: string, to: string): Promise<{
462
+ emailId: string;
463
+ }>;
464
+ }
465
+
466
+ declare class TemplatesResource extends BaseResource {
467
+ list(params?: ListTemplatesParams): Promise<PaginatedResponse<TemplateSummary>>;
468
+ create(params: CreateTemplateParams): Promise<Template>;
469
+ get(id: string): Promise<Template>;
470
+ update(id: string, params: UpdateTemplateParams): Promise<Template>;
471
+ delete(id: string): Promise<void>;
472
+ listVersions(id: string): Promise<TemplateVersionSummary[]>;
473
+ getVersion(id: string, version: number): Promise<TemplateVersion>;
474
+ testSend(id: string, to: string, variables?: Record<string, string>): Promise<{
475
+ queued: boolean;
476
+ }>;
477
+ }
478
+
479
+ declare class WebhooksResource extends BaseResource {
480
+ create(params: CreateWebhookParams): Promise<{
481
+ id: string;
482
+ secret: string;
483
+ }>;
484
+ list(): Promise<Webhook[]>;
485
+ delete(id: string): Promise<void>;
486
+ listDeliveries(id: string, params?: ListWebhookDeliveriesParams): Promise<PaginatedResponse<WebhookDelivery>>;
487
+ test(id: string): Promise<{
488
+ queued: boolean;
489
+ }>;
490
+ rotateSecret(id: string): Promise<{
491
+ secret: string;
492
+ }>;
493
+ }
494
+
495
+ declare class DomainsResource extends BaseResource {
496
+ add(domain: string): Promise<Domain>;
497
+ list(params?: ListDomainsParams): Promise<PaginatedResponse<DomainSummary>>;
498
+ get(id: string): Promise<Domain>;
499
+ verify(id: string): Promise<Domain>;
500
+ delete(id: string): Promise<{
501
+ id: string;
502
+ deletedAt: string;
503
+ }>;
504
+ }
505
+
506
+ declare class ApiKeysResource extends BaseResource {
507
+ create(params: CreateApiKeyParams, idempotencyKey?: string): Promise<ApiKeyCreated>;
508
+ list(params?: ListApiKeysParams): Promise<PaginatedResponse<ApiKey>>;
509
+ revoke(id: string): Promise<{
510
+ id: string;
511
+ revokedAt: string;
512
+ }>;
513
+ }
514
+
515
+ declare class AnalyticsResource extends BaseResource {
516
+ getSummary(period?: AnalyticsPeriod): Promise<AnalyticsSummary>;
517
+ getTimeseries(period?: AnalyticsPeriod): Promise<TimeseriesPoint[]>;
518
+ }
519
+
520
+ declare class FlowsResource extends BaseResource {
521
+ list(params?: ListFlowsParams): Promise<PaginatedResponse<Flow>>;
522
+ create(params: CreateFlowParams): Promise<{
523
+ id: string;
524
+ }>;
525
+ get(id: string): Promise<Flow>;
526
+ update(id: string, params: UpdateFlowParams): Promise<Flow>;
527
+ delete(id: string): Promise<{
528
+ id: string;
529
+ }>;
530
+ activate(id: string): Promise<Flow>;
531
+ deactivate(id: string): Promise<Flow>;
532
+ }
533
+
534
+ declare class WorkspaceResource extends BaseResource {
535
+ get(): Promise<Workspace>;
536
+ update(params: UpdateWorkspaceParams): Promise<Workspace>;
537
+ delete(): Promise<void>;
538
+ updatePreferences(params: UpdateWorkspacePreferencesParams): Promise<WorkspacePreferences>;
539
+ inviteMember(params: InviteMemberParams): Promise<WorkspaceMember>;
540
+ updateMember(userId: string, params: UpdateMemberParams): Promise<WorkspaceMember>;
541
+ removeMember(userId: string): Promise<void>;
542
+ }
543
+
544
+ interface TrattoOptions {
545
+ baseUrl?: string;
546
+ }
547
+ declare class Tratto {
548
+ readonly emails: EmailsResource;
549
+ readonly contacts: ContactsResource;
550
+ readonly audiences: AudiencesResource;
551
+ readonly campaigns: CampaignsResource;
552
+ readonly templates: TemplatesResource;
553
+ readonly webhooks: WebhooksResource;
554
+ readonly domains: DomainsResource;
555
+ readonly apiKeys: ApiKeysResource;
556
+ readonly analytics: AnalyticsResource;
557
+ readonly flows: FlowsResource;
558
+ readonly workspace: WorkspaceResource;
559
+ constructor(apiKey: string, options?: TrattoOptions);
560
+ }
561
+
562
+ export { type AddContactsToAudienceResult, type AnalyticsPeriod, type AnalyticsSummary, type ApiKey, type ApiKeyCreated, type ApiKeyEnv, type Audience, type AudienceRule, type AudienceRuleOperator, type Campaign, type CampaignStats, type CampaignStatsDetail, type CampaignStatus, type Contact, type ContactStatus, type CreateApiKeyParams, type CreateAudienceParams, type CreateCampaignParams, type CreateContactParams, type CreateFlowParams, type CreateTemplateParams, type CreateWebhookParams, type Domain, type DomainRecord, type DomainStatus, type DomainSummary, type EmailDetail, type EmailEvent, type EmailSummary, type Flow, type FlowStatus, type FlowStep, type FlowStepType, type FlowTrigger, type FlowTriggerType, type ImportJobStatus, type InviteMemberParams, type ListApiKeysParams, type ListAudiencesParams, type ListCampaignsParams, type ListContactsParams, type ListDomainsParams, type ListEmailsParams, type ListFlowsParams, type ListTemplatesParams, type ListWebhookDeliveriesParams, type PaginatedResponse, type Pagination, type SendCampaignParams, type SendEmailParams, type Template, type TemplateStatus, type TemplateSummary, type TemplateVersion, type TemplateVersionSummary, type TimeseriesPoint, Tratto, TrattoError, type TrattoOptions, type UpdateContactParams, type UpdateFlowParams, type UpdateMemberParams, type UpdateTemplateParams, type UpdateWorkspaceParams, type UpdateWorkspacePreferencesParams, type Webhook, type WebhookDelivery, type WebhookDeliveryStatus, type WebhookEventType, type WebhookStatus, type Workspace, type WorkspaceLocale, type WorkspaceMember, type WorkspaceMemberRole, type WorkspacePlan, type WorkspacePreferences };