@tratto/angular 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,1028 @@
1
+ import * as i0 from '@angular/core';
2
+ import { InjectionToken, ModuleWithProviders, EnvironmentProviders } from '@angular/core';
3
+ import { OperatorFunction, Observable } from 'rxjs';
4
+ import * as _tratto_angular from '@tratto/angular';
5
+ import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
6
+
7
+ /**
8
+ * Configuration options for the Tratto Angular SDK.
9
+ *
10
+ * Provide it once at the root level via {@link provideTratt} (standalone apps)
11
+ * or {@link TrattoModule.forRoot} (NgModule apps).
12
+ */
13
+ interface TrattoConfig {
14
+ /**
15
+ * API key used to authenticate every request.
16
+ * Obtain one at https://app.tratto.email/settings/api-keys.
17
+ * Supports both live (`tratto_live_...`) and test (`tratto_test_...`) keys.
18
+ */
19
+ apiKey: string;
20
+ /**
21
+ * Base URL of the Tratto REST API.
22
+ * @default 'https://api.tratto.email'
23
+ */
24
+ baseUrl?: string;
25
+ }
26
+ /** DI injection token that holds the {@link TrattoConfig}. */
27
+ declare const TRATTO_CONFIG: InjectionToken<TrattoConfig>;
28
+
29
+ /**
30
+ * Provides all Tratto services for **standalone** Angular applications.
31
+ *
32
+ * Add this to your `ApplicationConfig` providers array alongside
33
+ * `provideHttpClient()`. The SDK uses `HttpClient` internally; if your app
34
+ * has not already provided it, include `provideHttpClient()` as well.
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * // app.config.ts
39
+ * import { provideHttpClient } from '@angular/common/http';
40
+ * import { provideTratt } from '@tratto/angular';
41
+ *
42
+ * export const appConfig: ApplicationConfig = {
43
+ * providers: [
44
+ * provideHttpClient(),
45
+ * provideTratt({ apiKey: 'tratto_live_...' }),
46
+ * ],
47
+ * };
48
+ * ```
49
+ */
50
+ declare function provideTratt(config: TrattoConfig): EnvironmentProviders;
51
+ /**
52
+ * Angular module that registers all Tratto services.
53
+ *
54
+ * For Angular 14+ **standalone** applications prefer {@link provideTratt}.
55
+ * For **NgModule**-based applications use `TrattoModule.forRoot()`.
56
+ *
57
+ * > **Note:** `HttpClientModule` (or `provideHttpClient()`) must be imported
58
+ * > in your application before importing `TrattoModule`.
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * // app.module.ts
63
+ * import { HttpClientModule } from '@angular/common/http';
64
+ * import { TrattoModule } from '@tratto/angular';
65
+ *
66
+ * @NgModule({
67
+ * imports: [
68
+ * HttpClientModule,
69
+ * TrattoModule.forRoot({ apiKey: 'tratto_live_...' }),
70
+ * ],
71
+ * })
72
+ * export class AppModule {}
73
+ * ```
74
+ */
75
+ declare class TrattoModule {
76
+ static forRoot(config: TrattoConfig): ModuleWithProviders<TrattoModule>;
77
+ static ɵfac: i0.ɵɵFactoryDeclaration<TrattoModule, never>;
78
+ static ɵmod: i0.ɵɵNgModuleDeclaration<TrattoModule, never, never, never>;
79
+ static ɵinj: i0.ɵɵInjectorDeclaration<TrattoModule>;
80
+ }
81
+
82
+ /**
83
+ * Abstract base class shared by all Tratto resource services.
84
+ * Provides the `HttpClient`, config injection, and auth-header helpers.
85
+ */
86
+ declare abstract class BaseService {
87
+ protected readonly http: HttpClient;
88
+ protected readonly config: _tratto_angular.TrattoConfig;
89
+ /** Root API URL without trailing slash (e.g. `https://api.tratto.email`). */
90
+ protected readonly apiBaseUrl: string;
91
+ /**
92
+ * Returns an `HttpHeaders` instance pre-populated with the `Authorization` header.
93
+ * Pass `extra` to merge additional headers (e.g. `Idempotency-Key`).
94
+ */
95
+ protected authHeaders(extra?: Record<string, string>): HttpHeaders;
96
+ /**
97
+ * Builds an `HttpParams` object from a plain object, skipping `null`/`undefined` values.
98
+ * `Date` values are serialised to ISO strings.
99
+ */
100
+ protected buildParams(params: Record<string, string | number | boolean | Date | null | undefined>): HttpParams;
101
+ /**
102
+ * RxJS operator that unwraps the `{ data: T }` envelope returned by every
103
+ * Tratto API endpoint.
104
+ */
105
+ protected unwrap<T>(): OperatorFunction<{
106
+ data: T;
107
+ }, T>;
108
+ /**
109
+ * Sends a DELETE/PATCH/POST that returns HTTP 204 (no body).
110
+ * Uses `responseType: 'text'` to avoid JSON-parse errors on an empty body.
111
+ */
112
+ protected voidRequest(method: 'DELETE' | 'PATCH' | 'POST', url: string, body?: unknown): Observable<void>;
113
+ }
114
+
115
+ /** Pagination metadata included in every list response. */
116
+ interface Pagination {
117
+ hasMore: boolean;
118
+ nextCursor: string | null;
119
+ }
120
+ /** Wrapper returned by every paginated list endpoint. */
121
+ interface PaginatedResponse<T> {
122
+ data: T[];
123
+ pagination: Pagination;
124
+ }
125
+ /** Parameters accepted by `POST /v1/emails`. */
126
+ interface SendEmailParams {
127
+ /** Sender address. Must match a verified domain. Accepts `"Name <addr>"` or plain `"addr"`. */
128
+ from: string;
129
+ /** One or more recipient email addresses. */
130
+ to: string | string[];
131
+ /** Subject line (max 998 characters). */
132
+ subject: string;
133
+ /** HTML body. At least one of `html`, `text`, or `templateId` is required. */
134
+ html?: string;
135
+ /** Plain-text body. At least one of `html`, `text`, or `templateId` is required. */
136
+ text?: string;
137
+ /** Carbon-copy recipients. */
138
+ cc?: string[];
139
+ /** Blind carbon-copy recipients. */
140
+ bcc?: string[];
141
+ /** Reply-to address. */
142
+ replyTo?: string;
143
+ /** ID of a saved template. At least one of `html`, `text`, or `templateId` is required. */
144
+ templateId?: string;
145
+ /** Variables interpolated inside the template. */
146
+ variables?: Record<string, unknown>;
147
+ /** Custom tags for filtering and analytics. */
148
+ tags?: string[];
149
+ /** Schedule the email for a future time. Sends immediately if omitted or in the past. */
150
+ scheduledAt?: Date | string;
151
+ /** Extra SMTP headers forwarded verbatim. */
152
+ headers?: Record<string, string>;
153
+ }
154
+ /** Query parameters for `GET /v1/emails`. */
155
+ interface ListEmailsParams {
156
+ after?: string;
157
+ limit?: number;
158
+ /** Comma-separated status values, e.g. `"sent,delivered"`. */
159
+ status?: string;
160
+ domainId?: string;
161
+ /** Comma-separated tag names. */
162
+ tags?: string;
163
+ dateFrom?: Date | string;
164
+ dateTo?: Date | string;
165
+ }
166
+ /** Compact email representation used in list responses. */
167
+ interface EmailSummary {
168
+ id: string;
169
+ from: string;
170
+ to: string[];
171
+ subject: string;
172
+ status: string;
173
+ createdAt: string;
174
+ sentAt: string | null;
175
+ scheduledAt: string | null;
176
+ tags?: string[];
177
+ }
178
+ /** A single delivery event recorded for an email. */
179
+ interface EmailEvent {
180
+ type: string;
181
+ occurredAt: string;
182
+ data?: Record<string, unknown>;
183
+ }
184
+ /** Full email detail including body and inline events. */
185
+ interface EmailDetail extends EmailSummary {
186
+ html?: string;
187
+ text?: string;
188
+ cc?: string[];
189
+ bcc?: string[];
190
+ replyTo?: string;
191
+ templateId?: string;
192
+ headers?: Record<string, string>;
193
+ events: EmailEvent[];
194
+ }
195
+ type ContactStatus = 'subscribed' | 'unsubscribed' | 'bounced' | 'complained';
196
+ interface Contact {
197
+ id: string;
198
+ email: string;
199
+ firstName: string;
200
+ lastName: string;
201
+ status: ContactStatus;
202
+ tags: string[];
203
+ customFields: Record<string, unknown>;
204
+ createdAt: string;
205
+ }
206
+ interface CreateContactParams {
207
+ email: string;
208
+ firstName?: string;
209
+ lastName?: string;
210
+ status?: ContactStatus;
211
+ tags?: string[];
212
+ customFields?: Record<string, unknown>;
213
+ }
214
+ interface UpdateContactParams {
215
+ firstName?: string;
216
+ lastName?: string;
217
+ status?: ContactStatus;
218
+ tags?: string[];
219
+ customFields?: Record<string, unknown>;
220
+ }
221
+ interface ListContactsParams {
222
+ status?: ContactStatus;
223
+ audienceId?: string;
224
+ tag?: string;
225
+ after?: string;
226
+ limit?: number;
227
+ }
228
+ /** Status snapshot of an async CSV import job. */
229
+ interface ImportJobStatus {
230
+ jobId: string;
231
+ status: 'processing' | 'completed' | 'failed';
232
+ totalRows: number;
233
+ processedRows: number;
234
+ failedRows: number;
235
+ errors: string[];
236
+ completedAt: string | null;
237
+ }
238
+ type AudienceRuleOperator = 'equals' | 'not_equals' | 'contains' | 'not_contains' | 'array_contains';
239
+ interface AudienceRule {
240
+ field: string;
241
+ operator: AudienceRuleOperator;
242
+ value: string | number | boolean;
243
+ }
244
+ interface Audience {
245
+ id: string;
246
+ name: string;
247
+ description: string;
248
+ contactCount: number;
249
+ rules: AudienceRule[];
250
+ createdAt: string;
251
+ }
252
+ interface CreateAudienceParams {
253
+ name: string;
254
+ description?: string;
255
+ rules?: AudienceRule[];
256
+ }
257
+ interface ListAudiencesParams {
258
+ after?: string;
259
+ limit?: number;
260
+ }
261
+ interface AddContactsToAudienceResult {
262
+ added: number;
263
+ alreadyInAudience: number;
264
+ notFound: number;
265
+ }
266
+ type CampaignStatus = 'draft' | 'sending' | 'scheduled' | 'paused' | 'completed';
267
+ interface CampaignStats {
268
+ total: number;
269
+ sent: number;
270
+ delivered: number;
271
+ opened: number;
272
+ clicked: number;
273
+ bounced: number;
274
+ }
275
+ interface Campaign {
276
+ id: string;
277
+ name: string;
278
+ status: CampaignStatus;
279
+ templateId: string;
280
+ audienceId: string;
281
+ fromName: string;
282
+ fromEmail: string;
283
+ subjectA: string;
284
+ subjectB: string | null;
285
+ scheduledAt: string | null;
286
+ sentAt: string | null;
287
+ stats: CampaignStats;
288
+ createdAt: string;
289
+ }
290
+ interface CampaignStatsDetail {
291
+ campaignId: string;
292
+ status: CampaignStatus;
293
+ stats: CampaignStats;
294
+ rates: {
295
+ deliveryRate: number;
296
+ openRate: number;
297
+ clickRate: number;
298
+ bounceRate: number;
299
+ };
300
+ }
301
+ interface CreateCampaignParams {
302
+ name: string;
303
+ templateId: string;
304
+ audienceId: string;
305
+ fromName: string;
306
+ fromEmail: string;
307
+ subjectA: string;
308
+ /** Optional subject for A/B testing. */
309
+ subjectB?: string;
310
+ }
311
+ interface ListCampaignsParams {
312
+ status?: CampaignStatus;
313
+ after?: string;
314
+ limit?: number;
315
+ }
316
+ interface SendCampaignParams {
317
+ /** Schedule the campaign for a future date. Omit to send immediately. */
318
+ scheduledAt?: Date | string;
319
+ }
320
+ type TemplateStatus = 'draft' | 'published';
321
+ interface TemplateSummary {
322
+ id: string;
323
+ name: string;
324
+ status: TemplateStatus;
325
+ version: number;
326
+ createdAt: string;
327
+ updatedAt: string;
328
+ }
329
+ interface Template extends TemplateSummary {
330
+ html: string;
331
+ }
332
+ interface CreateTemplateParams {
333
+ name: string;
334
+ /** Initial HTML content. Defaults to an empty string. */
335
+ html?: string;
336
+ }
337
+ interface UpdateTemplateParams {
338
+ name?: string;
339
+ html?: string;
340
+ status?: TemplateStatus;
341
+ }
342
+ interface ListTemplatesParams {
343
+ limit?: number;
344
+ after?: string;
345
+ status?: TemplateStatus;
346
+ }
347
+ interface TemplateVersionSummary {
348
+ version: number;
349
+ savedAt: string;
350
+ }
351
+ interface TemplateVersion extends TemplateVersionSummary {
352
+ html: string;
353
+ }
354
+ type WebhookEventType = 'sent' | 'delivered' | 'opened' | 'clicked' | 'bounced' | 'complained' | 'unsubscribed';
355
+ type WebhookStatus = 'active' | 'disabled';
356
+ type WebhookDeliveryStatus = 'success' | 'failed' | 'scheduled';
357
+ interface Webhook {
358
+ id: string;
359
+ url: string;
360
+ events: WebhookEventType[];
361
+ status: WebhookStatus;
362
+ /** First 12 characters of the signing secret followed by `…`. The full secret is never re-exposed. */
363
+ secretPrefix: string;
364
+ failureCount: number;
365
+ createdAt: string;
366
+ }
367
+ interface WebhookDelivery {
368
+ id: string;
369
+ webhookId: string;
370
+ eventType: string;
371
+ status: WebhookDeliveryStatus;
372
+ httpStatus: number | null;
373
+ responseBody: string | null;
374
+ retryCount: number;
375
+ attemptedAt: string;
376
+ }
377
+ interface CreateWebhookParams {
378
+ url: string;
379
+ events: WebhookEventType[];
380
+ }
381
+ interface ListWebhookDeliveriesParams {
382
+ after?: string;
383
+ limit?: number;
384
+ }
385
+ type DomainStatus = 'pending' | 'verified' | 'failed';
386
+ interface DomainRecord {
387
+ type: string;
388
+ host: string;
389
+ value: string;
390
+ verified: boolean;
391
+ }
392
+ interface DomainSummary {
393
+ id: string;
394
+ domain: string;
395
+ status: DomainStatus;
396
+ dkimSelector: string;
397
+ createdAt: string;
398
+ updatedAt: string;
399
+ verifiedAt: string | null;
400
+ }
401
+ interface Domain extends DomainSummary {
402
+ records: DomainRecord[];
403
+ }
404
+ interface ListDomainsParams {
405
+ after?: string;
406
+ limit?: number;
407
+ }
408
+ type ApiKeyEnv = 'live' | 'test';
409
+ interface ApiKey {
410
+ id: string;
411
+ name: string;
412
+ /** First 16 characters of the raw key followed by `...`. */
413
+ prefix: string;
414
+ env: ApiKeyEnv;
415
+ permissions: string[];
416
+ createdAt: string;
417
+ lastUsedAt: string | null;
418
+ revokedAt: string | null;
419
+ }
420
+ interface ApiKeyCreated extends ApiKey {
421
+ /** Full raw key value — returned only at creation time. Store it securely; it cannot be retrieved again. */
422
+ key: string;
423
+ }
424
+ interface CreateApiKeyParams {
425
+ name: string;
426
+ env: ApiKeyEnv;
427
+ permissions: string[];
428
+ }
429
+ interface ListApiKeysParams {
430
+ after?: string;
431
+ limit?: number;
432
+ }
433
+ type AnalyticsPeriod = '7d' | '30d' | '90d';
434
+ interface AnalyticsSummary {
435
+ period: AnalyticsPeriod;
436
+ totalSent: number;
437
+ delivered: number;
438
+ opened: number;
439
+ clicked: number;
440
+ bounced: number;
441
+ complained: number;
442
+ /** Percentage: `(delivered / totalSent) * 100`. */
443
+ deliveryRate: number;
444
+ /** Percentage: `(opened / delivered) * 100`. */
445
+ openRate: number;
446
+ /** Percentage: `(clicked / opened) * 100`. */
447
+ clickRate: number;
448
+ /** Percentage: `(bounced / totalSent) * 100`. */
449
+ bounceRate: number;
450
+ }
451
+ interface TimeseriesPoint {
452
+ /** ISO date string, e.g. `"2025-06-01"`. */
453
+ date: string;
454
+ sent: number;
455
+ delivered: number;
456
+ opened: number;
457
+ bounced: number;
458
+ }
459
+ type FlowStatus = 'draft' | 'active' | 'inactive';
460
+ type FlowTriggerType = 'contact_joins_audience' | 'contact_tag_added' | 'contact_tag_removed' | 'email_event' | 'manual';
461
+ type FlowStepType = 'send_email' | 'wait' | 'branch' | 'update_contact' | 'webhook_call';
462
+ interface FlowTrigger {
463
+ type: FlowTriggerType;
464
+ config: Record<string, string>;
465
+ }
466
+ interface FlowStep {
467
+ id: string;
468
+ type: FlowStepType;
469
+ config: Record<string, string>;
470
+ }
471
+ interface Flow {
472
+ id: string;
473
+ name: string;
474
+ status: FlowStatus;
475
+ trigger: FlowTrigger;
476
+ steps: FlowStep[];
477
+ enrollments: number;
478
+ createdAt: string;
479
+ updatedAt: string;
480
+ }
481
+ interface CreateFlowParams {
482
+ name: string;
483
+ }
484
+ interface UpdateFlowParams {
485
+ name?: string;
486
+ trigger?: FlowTrigger;
487
+ /** Max 20 steps. Cannot be changed while the flow is active — deactivate first. */
488
+ steps?: FlowStep[];
489
+ }
490
+ interface ListFlowsParams {
491
+ after?: string;
492
+ limit?: number;
493
+ }
494
+ type WorkspacePlan = 'free' | 'starter' | 'growth';
495
+ type WorkspaceMemberRole = 'owner' | 'admin' | 'member';
496
+ type WorkspaceLocale = 'it' | 'en';
497
+ interface Workspace {
498
+ id: string;
499
+ name: string;
500
+ slug: string;
501
+ timezone: string;
502
+ locale: WorkspaceLocale;
503
+ plan: WorkspacePlan;
504
+ createdAt: string;
505
+ }
506
+ interface WorkspaceMember {
507
+ userId: string;
508
+ email: string;
509
+ displayName: string | null;
510
+ role: WorkspaceMemberRole;
511
+ joinedAt: string;
512
+ }
513
+ interface WorkspacePreferences {
514
+ locale: WorkspaceLocale;
515
+ emailNotifications: {
516
+ bounces: boolean;
517
+ weeklyReport: boolean;
518
+ billingAlerts: boolean;
519
+ };
520
+ }
521
+ interface UpdateWorkspaceParams {
522
+ name?: string;
523
+ /** URL slug — lowercase letters, digits and hyphens only (2–50 chars). Must be globally unique. */
524
+ slug?: string;
525
+ timezone?: string;
526
+ locale?: WorkspaceLocale;
527
+ }
528
+ interface UpdateWorkspacePreferencesParams {
529
+ locale?: WorkspaceLocale;
530
+ emailNotifications?: {
531
+ bounces?: boolean;
532
+ weeklyReport?: boolean;
533
+ billingAlerts?: boolean;
534
+ };
535
+ }
536
+ interface InviteMemberParams {
537
+ email: string;
538
+ role: 'admin' | 'member';
539
+ }
540
+ interface UpdateMemberParams {
541
+ role: WorkspaceMemberRole;
542
+ }
543
+
544
+ /** Service for sending transactional emails and inspecting their delivery. */
545
+ declare class EmailsService extends BaseService {
546
+ private readonly url;
547
+ /**
548
+ * Send a transactional email (`POST /v1/emails`).
549
+ * At least one of `html`, `text`, or `templateId` is required.
550
+ *
551
+ * @param params Email parameters.
552
+ * @param idempotencyKey Optional key that guarantees exactly-once delivery.
553
+ * If the same key is re-used within 24 hours the original response is returned.
554
+ * @returns Observable that emits the created email `id`.
555
+ */
556
+ send(params: SendEmailParams, idempotencyKey?: string): Observable<{
557
+ id: string;
558
+ }>;
559
+ /**
560
+ * List emails with optional filters (`GET /v1/emails`).
561
+ * Results are ordered by creation date descending.
562
+ */
563
+ list(params?: ListEmailsParams): Observable<PaginatedResponse<EmailSummary>>;
564
+ /**
565
+ * Get a single email with full details and inline events (`GET /v1/emails/:id`).
566
+ */
567
+ get(id: string): Observable<EmailDetail>;
568
+ /**
569
+ * List all delivery events for a specific email (`GET /v1/emails/:id/events`).
570
+ */
571
+ listEvents(id: string): Observable<EmailEvent[]>;
572
+ static ɵfac: i0.ɵɵFactoryDeclaration<EmailsService, never>;
573
+ static ɵprov: i0.ɵɵInjectableDeclaration<EmailsService>;
574
+ }
575
+
576
+ /** Service for managing contacts and running CSV imports. */
577
+ declare class ContactsService extends BaseService {
578
+ private readonly url;
579
+ /**
580
+ * Create a single contact (`POST /v1/contacts`).
581
+ * Returns a conflict error if the email address is already registered.
582
+ */
583
+ create(params: CreateContactParams): Observable<{
584
+ id: string;
585
+ }>;
586
+ /**
587
+ * List contacts with optional filters (`GET /v1/contacts`).
588
+ * Results are ordered by creation date descending.
589
+ */
590
+ list(params?: ListContactsParams): Observable<PaginatedResponse<Contact>>;
591
+ /**
592
+ * Update a contact's details (`PATCH /v1/contacts/:id`).
593
+ * Only supplied fields are updated.
594
+ */
595
+ update(id: string, params: UpdateContactParams): Observable<{
596
+ id: string;
597
+ }>;
598
+ /**
599
+ * Start an asynchronous CSV import job (`POST /v1/contacts/import`).
600
+ *
601
+ * The CSV must have an `email` column. Optional columns:
602
+ * `first_name` / `firstname`, `last_name` / `lastname`, `status`,
603
+ * `tags` (semicolon-separated values).
604
+ *
605
+ * Maximum 50 000 rows per import. Poll {@link getImportJob} to track progress.
606
+ *
607
+ * @returns Observable that emits the new `jobId` and total row count.
608
+ */
609
+ importCsv(csvText: string): Observable<{
610
+ jobId: string;
611
+ totalRows: number;
612
+ }>;
613
+ /**
614
+ * Poll the status of a CSV import job (`GET /v1/contacts/import/:jobId`).
615
+ */
616
+ getImportJob(jobId: string): Observable<ImportJobStatus>;
617
+ static ɵfac: i0.ɵɵFactoryDeclaration<ContactsService, never>;
618
+ static ɵprov: i0.ɵɵInjectableDeclaration<ContactsService>;
619
+ }
620
+
621
+ /** Service for managing contact audiences. */
622
+ declare class AudiencesService extends BaseService {
623
+ private readonly url;
624
+ /**
625
+ * Create an audience (`POST /v1/audiences`).
626
+ * Optionally supply filter `rules` to make it a dynamic segment.
627
+ */
628
+ create(params: CreateAudienceParams): Observable<{
629
+ id: string;
630
+ }>;
631
+ /**
632
+ * List audiences (`GET /v1/audiences`).
633
+ * Results are ordered by creation date descending.
634
+ */
635
+ list(params?: ListAudiencesParams): Observable<PaginatedResponse<Audience>>;
636
+ /**
637
+ * Get a single audience by ID (`GET /v1/audiences/:id`).
638
+ */
639
+ get(id: string): Observable<Audience>;
640
+ /**
641
+ * Add contacts to an audience (`POST /v1/audiences/:id/contacts`).
642
+ * Accepts up to 500 contact IDs per call.
643
+ */
644
+ addContacts(audienceId: string, contactIds: string[]): Observable<AddContactsToAudienceResult>;
645
+ static ɵfac: i0.ɵɵFactoryDeclaration<AudiencesService, never>;
646
+ static ɵprov: i0.ɵɵInjectableDeclaration<AudiencesService>;
647
+ }
648
+
649
+ /** Service for managing and sending email campaigns. */
650
+ declare class CampaignsService extends BaseService {
651
+ private readonly url;
652
+ /**
653
+ * Create a campaign in `draft` status (`POST /v1/campaigns`).
654
+ * Call {@link send} to dispatch it.
655
+ */
656
+ create(params: CreateCampaignParams): Observable<{
657
+ id: string;
658
+ }>;
659
+ /**
660
+ * List campaigns with optional status filter (`GET /v1/campaigns`).
661
+ * Results are ordered by creation date descending.
662
+ */
663
+ list(params?: ListCampaignsParams): Observable<PaginatedResponse<Campaign>>;
664
+ /**
665
+ * Get a single campaign by ID (`GET /v1/campaigns/:id`).
666
+ */
667
+ get(id: string): Observable<Campaign>;
668
+ /**
669
+ * Get delivery statistics for a campaign (`GET /v1/campaigns/:id/stats`).
670
+ */
671
+ getStats(id: string): Observable<CampaignStatsDetail>;
672
+ /**
673
+ * Send or schedule a campaign (`POST /v1/campaigns/:id/send`).
674
+ * Only `draft` or `paused` campaigns can be sent.
675
+ *
676
+ * @param id Campaign ID.
677
+ * @param params Optional `scheduledAt` to defer sending.
678
+ * @returns Observable emitting the new campaign status.
679
+ */
680
+ send(id: string, params?: SendCampaignParams): Observable<{
681
+ status: string;
682
+ }>;
683
+ /**
684
+ * Pause a `sending` or `scheduled` campaign (`POST /v1/campaigns/:id/pause`).
685
+ */
686
+ pause(id: string): Observable<{
687
+ status: string;
688
+ }>;
689
+ /**
690
+ * Send a test email for this campaign to a specific address
691
+ * (`POST /v1/campaigns/:id/test-send`).
692
+ *
693
+ * @param id Campaign ID.
694
+ * @param to Recipient email address for the test.
695
+ * @returns Observable emitting the created test email ID.
696
+ */
697
+ testSend(id: string, to: string): Observable<{
698
+ emailId: string;
699
+ }>;
700
+ static ɵfac: i0.ɵɵFactoryDeclaration<CampaignsService, never>;
701
+ static ɵprov: i0.ɵɵInjectableDeclaration<CampaignsService>;
702
+ }
703
+
704
+ /** Service for managing email templates and their version history. */
705
+ declare class TemplatesService extends BaseService {
706
+ private readonly url;
707
+ /**
708
+ * List templates (`GET /v1/templates`).
709
+ * Results are ordered by creation date descending.
710
+ */
711
+ list(params?: ListTemplatesParams): Observable<PaginatedResponse<TemplateSummary>>;
712
+ /**
713
+ * Create a new template (`POST /v1/templates`).
714
+ * The template starts in `draft` status.
715
+ */
716
+ create(params: CreateTemplateParams): Observable<Template>;
717
+ /**
718
+ * Get a single template by ID (`GET /v1/templates/:id`).
719
+ */
720
+ get(id: string): Observable<Template>;
721
+ /**
722
+ * Update a template's name, HTML, or status (`PATCH /v1/templates/:id`).
723
+ * Changing `html` automatically creates a new version entry.
724
+ */
725
+ update(id: string, params: UpdateTemplateParams): Observable<Template>;
726
+ /**
727
+ * Permanently delete a template (`DELETE /v1/templates/:id`).
728
+ */
729
+ delete(id: string): Observable<void>;
730
+ /**
731
+ * List the version history of a template (`GET /v1/templates/:id/versions`).
732
+ * Returns up to the 20 most recent versions, newest first.
733
+ */
734
+ listVersions(id: string): Observable<TemplateVersionSummary[]>;
735
+ /**
736
+ * Get the HTML of a specific template version (`GET /v1/templates/:id/versions/:version`).
737
+ */
738
+ getVersion(id: string, version: number): Observable<TemplateVersion>;
739
+ /**
740
+ * Send a test email using this template (`POST /v1/templates/:id/test-send`).
741
+ *
742
+ * @param id Template ID.
743
+ * @param to Recipient address for the test.
744
+ * @param variables Variables to substitute inside the template.
745
+ */
746
+ testSend(id: string, to: string, variables?: Record<string, string>): Observable<{
747
+ queued: boolean;
748
+ }>;
749
+ static ɵfac: i0.ɵɵFactoryDeclaration<TemplatesService, never>;
750
+ static ɵprov: i0.ɵɵInjectableDeclaration<TemplatesService>;
751
+ }
752
+
753
+ /** Service for managing webhook endpoints and inspecting delivery history. */
754
+ declare class WebhooksService extends BaseService {
755
+ private readonly url;
756
+ /**
757
+ * Register a new webhook endpoint (`POST /v1/webhooks`).
758
+ *
759
+ * The returned `secret` is shown only once — store it securely and use it
760
+ * to verify the `X-Tratto-Signature` header on incoming events.
761
+ *
762
+ * @returns Observable emitting the new webhook `id` and HMAC signing `secret`.
763
+ */
764
+ create(params: CreateWebhookParams): Observable<{
765
+ id: string;
766
+ secret: string;
767
+ }>;
768
+ /**
769
+ * List all registered webhooks (`GET /v1/webhooks`).
770
+ * Results are ordered by creation date descending.
771
+ */
772
+ list(): Observable<Webhook[]>;
773
+ /**
774
+ * Delete a webhook endpoint (`DELETE /v1/webhooks/:id`).
775
+ */
776
+ delete(id: string): Observable<void>;
777
+ /**
778
+ * List delivery attempts for a webhook (`GET /v1/webhooks/:id/deliveries`).
779
+ * Results are ordered by attempt date descending.
780
+ */
781
+ listDeliveries(id: string, params?: ListWebhookDeliveriesParams): Observable<PaginatedResponse<WebhookDelivery>>;
782
+ /**
783
+ * Send a test event to a webhook endpoint (`POST /v1/webhooks/:id/test`).
784
+ * Useful for verifying connectivity and signature verification logic.
785
+ */
786
+ test(id: string): Observable<{
787
+ queued: boolean;
788
+ }>;
789
+ /**
790
+ * Rotate the signing secret for a webhook (`POST /v1/webhooks/:id/rotate-secret`).
791
+ * The new secret is returned once — store it securely.
792
+ * Also resets the failure counter and re-enables a disabled webhook.
793
+ */
794
+ rotateSecret(id: string): Observable<{
795
+ secret: string;
796
+ }>;
797
+ static ɵfac: i0.ɵɵFactoryDeclaration<WebhooksService, never>;
798
+ static ɵprov: i0.ɵɵInjectableDeclaration<WebhooksService>;
799
+ }
800
+
801
+ /** Service for adding and verifying sender domains. */
802
+ declare class DomainsService extends BaseService {
803
+ private readonly url;
804
+ /**
805
+ * Add a domain and generate its DKIM keypair (`POST /v1/domains`).
806
+ * The response contains the DNS records that must be published before calling {@link verify}.
807
+ *
808
+ * @param domain Bare domain name, e.g. `"mail.acme.com"`.
809
+ */
810
+ add(domain: string): Observable<Domain>;
811
+ /**
812
+ * List domains (`GET /v1/domains`).
813
+ * Results are ordered by creation date descending.
814
+ */
815
+ list(params?: ListDomainsParams): Observable<PaginatedResponse<DomainSummary>>;
816
+ /**
817
+ * Get full domain details including DNS records (`GET /v1/domains/:id`).
818
+ */
819
+ get(id: string): Observable<Domain>;
820
+ /**
821
+ * Trigger DNS verification for a domain (`POST /v1/domains/:id/verify`).
822
+ * Checks SPF, DKIM, and DMARC records in real time and updates the domain status.
823
+ * The domain must be `verified` before it can be used as a sender.
824
+ */
825
+ verify(id: string): Observable<Domain>;
826
+ /**
827
+ * Remove a domain and delete its DKIM private key (`DELETE /v1/domains/:id`).
828
+ *
829
+ * @returns Observable emitting the deleted domain `id` and `deletedAt` timestamp.
830
+ */
831
+ delete(id: string): Observable<{
832
+ id: string;
833
+ deletedAt: string;
834
+ }>;
835
+ static ɵfac: i0.ɵɵFactoryDeclaration<DomainsService, never>;
836
+ static ɵprov: i0.ɵɵInjectableDeclaration<DomainsService>;
837
+ }
838
+
839
+ /** Service for creating and revoking API keys. */
840
+ declare class ApiKeysService extends BaseService {
841
+ private readonly url;
842
+ /**
843
+ * Create a new API key (`POST /v1/api-keys`).
844
+ *
845
+ * The full raw key in the response is shown **only once** — store it securely.
846
+ *
847
+ * @param params Key name, environment and permission scopes.
848
+ * @param idempotencyKey Optional key to prevent accidental duplicates.
849
+ * @returns Observable emitting the created key including the raw token.
850
+ */
851
+ create(params: CreateApiKeyParams, idempotencyKey?: string): Observable<ApiKeyCreated>;
852
+ /**
853
+ * List API keys (without the raw token) (`GET /v1/api-keys`).
854
+ * Results are ordered by creation date descending.
855
+ */
856
+ list(params?: ListApiKeysParams): Observable<PaginatedResponse<ApiKey>>;
857
+ /**
858
+ * Revoke (soft-delete) an API key (`DELETE /v1/api-keys/:id`).
859
+ * Revoked keys are immediately rejected by the API.
860
+ *
861
+ * @returns Observable emitting the key `id` and `revokedAt` timestamp.
862
+ */
863
+ revoke(id: string): Observable<{
864
+ id: string;
865
+ revokedAt: string;
866
+ }>;
867
+ static ɵfac: i0.ɵɵFactoryDeclaration<ApiKeysService, never>;
868
+ static ɵprov: i0.ɵɵInjectableDeclaration<ApiKeysService>;
869
+ }
870
+
871
+ /** Service for querying email analytics and delivery metrics. */
872
+ declare class AnalyticsService extends BaseService {
873
+ private readonly url;
874
+ /**
875
+ * Get aggregated email metrics for a time period (`GET /v1/analytics/summary`).
876
+ * Results are cached server-side for one hour.
877
+ *
878
+ * @param period Lookback window. Defaults to `'30d'`.
879
+ */
880
+ getSummary(period?: AnalyticsPeriod): Observable<AnalyticsSummary>;
881
+ /**
882
+ * Get daily email metrics for a time period (`GET /v1/analytics/timeseries`).
883
+ * Returns one data point per day for the chosen window.
884
+ * Results are cached server-side for one hour.
885
+ *
886
+ * @param period Lookback window. Defaults to `'30d'`.
887
+ */
888
+ getTimeseries(period?: AnalyticsPeriod): Observable<TimeseriesPoint[]>;
889
+ static ɵfac: i0.ɵɵFactoryDeclaration<AnalyticsService, never>;
890
+ static ɵprov: i0.ɵɵInjectableDeclaration<AnalyticsService>;
891
+ }
892
+
893
+ /** Service for managing email automation flows. */
894
+ declare class FlowsService extends BaseService {
895
+ private readonly url;
896
+ /**
897
+ * List automation flows (`GET /v1/flows`).
898
+ * Results are ordered by creation date descending.
899
+ */
900
+ list(params?: ListFlowsParams): Observable<PaginatedResponse<Flow>>;
901
+ /**
902
+ * Create a flow in `draft` status (`POST /v1/flows`).
903
+ * Configure the trigger and steps via {@link update} before activating.
904
+ */
905
+ create(params: CreateFlowParams): Observable<{
906
+ id: string;
907
+ }>;
908
+ /**
909
+ * Get a single flow by ID (`GET /v1/flows/:id`).
910
+ */
911
+ get(id: string): Observable<Flow>;
912
+ /**
913
+ * Update a flow's name, trigger, or steps (`PATCH /v1/flows/:id`).
914
+ * Steps cannot be changed while the flow is active — call {@link deactivate} first.
915
+ */
916
+ update(id: string, params: UpdateFlowParams): Observable<Flow>;
917
+ /**
918
+ * Delete a flow (`DELETE /v1/flows/:id`).
919
+ * Only `draft` or `inactive` flows can be deleted.
920
+ */
921
+ delete(id: string): Observable<{
922
+ id: string;
923
+ }>;
924
+ /**
925
+ * Activate a flow, enabling it to enroll contacts (`POST /v1/flows/:id/activate`).
926
+ */
927
+ activate(id: string): Observable<Flow>;
928
+ /**
929
+ * Deactivate a flow (`POST /v1/flows/:id/deactivate`).
930
+ * Contacts already enrolled continue through their current steps.
931
+ * No new enrollments are accepted until the flow is re-activated.
932
+ */
933
+ deactivate(id: string): Observable<Flow>;
934
+ static ɵfac: i0.ɵɵFactoryDeclaration<FlowsService, never>;
935
+ static ɵprov: i0.ɵɵInjectableDeclaration<FlowsService>;
936
+ }
937
+
938
+ /** Service for managing workspace settings and team members. */
939
+ declare class WorkspaceService extends BaseService {
940
+ private readonly url;
941
+ /**
942
+ * Get the current workspace (`GET /v1/workspace`).
943
+ * Creates a workspace with default settings on first access if none exists.
944
+ */
945
+ get(): Observable<Workspace>;
946
+ /**
947
+ * Update workspace settings (`PATCH /v1/workspace`).
948
+ * Only supplied fields are changed.
949
+ */
950
+ update(params: UpdateWorkspaceParams): Observable<Workspace>;
951
+ /**
952
+ * Schedule the workspace for deletion (`DELETE /v1/workspace`).
953
+ * Only the workspace owner can perform this action.
954
+ */
955
+ delete(): Observable<void>;
956
+ /**
957
+ * Update workspace preferences such as locale and notification settings
958
+ * (`PATCH /v1/workspace/preferences`).
959
+ */
960
+ updatePreferences(params: UpdateWorkspacePreferencesParams): Observable<WorkspacePreferences>;
961
+ /**
962
+ * Invite a new member to the workspace (`POST /v1/workspace/members/invite`).
963
+ * The invite is accepted automatically when the user first logs in.
964
+ */
965
+ inviteMember(params: InviteMemberParams): Observable<WorkspaceMember>;
966
+ /**
967
+ * Update a member's role (`PATCH /v1/workspace/members/:userId`).
968
+ */
969
+ updateMember(userId: string, params: UpdateMemberParams): Observable<WorkspaceMember>;
970
+ /**
971
+ * Remove a member from the workspace (`DELETE /v1/workspace/members/:userId`).
972
+ * The workspace owner cannot be removed.
973
+ */
974
+ removeMember(userId: string): Observable<void>;
975
+ static ɵfac: i0.ɵɵFactoryDeclaration<WorkspaceService, never>;
976
+ static ɵprov: i0.ɵɵInjectableDeclaration<WorkspaceService>;
977
+ }
978
+
979
+ /**
980
+ * Top-level facade that aggregates all Tratto resource services.
981
+ *
982
+ * Inject `TrattoService` for a single entry-point into the SDK, or inject
983
+ * individual resource services (e.g. `EmailsService`) directly for
984
+ * better tree-shaking in large applications.
985
+ *
986
+ * @example
987
+ * ```ts
988
+ * // app.component.ts
989
+ * export class AppComponent {
990
+ * private tratto = inject(TrattoService);
991
+ *
992
+ * sendWelcome() {
993
+ * this.tratto.emails
994
+ * .send({ from: 'hello@acme.com', to: 'user@example.com', subject: 'Welcome!' })
995
+ * .subscribe(({ id }) => console.log('Sent:', id));
996
+ * }
997
+ * }
998
+ * ```
999
+ */
1000
+ declare class TrattoService {
1001
+ /** Access email sending and inspection methods. */
1002
+ readonly emails: EmailsService;
1003
+ /** Access contact management and CSV import methods. */
1004
+ readonly contacts: ContactsService;
1005
+ /** Access audience creation and membership methods. */
1006
+ readonly audiences: AudiencesService;
1007
+ /** Access campaign creation, scheduling, and statistics methods. */
1008
+ readonly campaigns: CampaignsService;
1009
+ /** Access template CRUD and version history methods. */
1010
+ readonly templates: TemplatesService;
1011
+ /** Access webhook registration and delivery history methods. */
1012
+ readonly webhooks: WebhooksService;
1013
+ /** Access domain onboarding and DNS verification methods. */
1014
+ readonly domains: DomainsService;
1015
+ /** Access API key creation and revocation methods. */
1016
+ readonly apiKeys: ApiKeysService;
1017
+ /** Access email analytics summary and time-series methods. */
1018
+ readonly analytics: AnalyticsService;
1019
+ /** Access automation flow management methods. */
1020
+ readonly flows: FlowsService;
1021
+ /** Access workspace settings and team member methods. */
1022
+ readonly workspace: WorkspaceService;
1023
+ static ɵfac: i0.ɵɵFactoryDeclaration<TrattoService, never>;
1024
+ static ɵprov: i0.ɵɵInjectableDeclaration<TrattoService>;
1025
+ }
1026
+
1027
+ export { AnalyticsService, ApiKeysService, AudiencesService, CampaignsService, ContactsService, DomainsService, EmailsService, FlowsService, TRATTO_CONFIG, TemplatesService, TrattoModule, TrattoService, WebhooksService, WorkspaceService, provideTratt };
1028
+ export type { AddContactsToAudienceResult, AnalyticsPeriod, AnalyticsSummary, ApiKey, ApiKeyCreated, ApiKeyEnv, Audience, AudienceRule, AudienceRuleOperator, Campaign, CampaignStats, CampaignStatsDetail, CampaignStatus, Contact, ContactStatus, CreateApiKeyParams, CreateAudienceParams, CreateCampaignParams, CreateContactParams, CreateFlowParams, CreateTemplateParams, CreateWebhookParams, Domain, DomainRecord, DomainStatus, DomainSummary, EmailDetail, EmailEvent, EmailSummary, Flow, FlowStatus, FlowStep, FlowStepType, FlowTrigger, FlowTriggerType, ImportJobStatus, InviteMemberParams, ListApiKeysParams, ListAudiencesParams, ListCampaignsParams, ListContactsParams, ListDomainsParams, ListEmailsParams, ListFlowsParams, ListTemplatesParams, ListWebhookDeliveriesParams, PaginatedResponse, Pagination, SendCampaignParams, SendEmailParams, Template, TemplateStatus, TemplateSummary, TemplateVersion, TemplateVersionSummary, TimeseriesPoint, TrattoConfig, UpdateContactParams, UpdateFlowParams, UpdateMemberParams, UpdateTemplateParams, UpdateWorkspaceParams, UpdateWorkspacePreferencesParams, Webhook, WebhookDelivery, WebhookDeliveryStatus, WebhookEventType, WebhookStatus, Workspace, WorkspaceLocale, WorkspaceMember, WorkspaceMemberRole, WorkspacePlan, WorkspacePreferences };