@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,932 @@
1
+ import * as i0 from '@angular/core';
2
+ import { InjectionToken, inject, Injectable, makeEnvironmentProviders, NgModule } from '@angular/core';
3
+ import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
4
+ import { map } from 'rxjs/operators';
5
+
6
+ /** DI injection token that holds the {@link TrattoConfig}. */
7
+ const TRATTO_CONFIG = new InjectionToken('TRATTO_CONFIG');
8
+
9
+ /**
10
+ * Abstract base class shared by all Tratto resource services.
11
+ * Provides the `HttpClient`, config injection, and auth-header helpers.
12
+ */
13
+ class BaseService {
14
+ http = inject(HttpClient);
15
+ config = inject(TRATTO_CONFIG);
16
+ /** Root API URL without trailing slash (e.g. `https://api.tratto.email`). */
17
+ apiBaseUrl = (this.config.baseUrl ?? 'https://api.tratto.email').replace(/\/$/, '');
18
+ /**
19
+ * Returns an `HttpHeaders` instance pre-populated with the `Authorization` header.
20
+ * Pass `extra` to merge additional headers (e.g. `Idempotency-Key`).
21
+ */
22
+ authHeaders(extra) {
23
+ return new HttpHeaders({ Authorization: `Bearer ${this.config.apiKey}`, ...extra });
24
+ }
25
+ /**
26
+ * Builds an `HttpParams` object from a plain object, skipping `null`/`undefined` values.
27
+ * `Date` values are serialised to ISO strings.
28
+ */
29
+ buildParams(params) {
30
+ return Object.entries(params).reduce((p, [key, val]) => {
31
+ if (val == null)
32
+ return p;
33
+ if (val instanceof Date)
34
+ return p.set(key, val.toISOString());
35
+ return p.set(key, String(val));
36
+ }, new HttpParams());
37
+ }
38
+ /**
39
+ * RxJS operator that unwraps the `{ data: T }` envelope returned by every
40
+ * Tratto API endpoint.
41
+ */
42
+ unwrap() {
43
+ return map((r) => r.data);
44
+ }
45
+ /**
46
+ * Sends a DELETE/PATCH/POST that returns HTTP 204 (no body).
47
+ * Uses `responseType: 'text'` to avoid JSON-parse errors on an empty body.
48
+ */
49
+ voidRequest(method, url, body) {
50
+ return this.http
51
+ .request(method, url, {
52
+ headers: this.authHeaders(),
53
+ responseType: 'text',
54
+ ...(body !== undefined ? { body } : {}),
55
+ })
56
+ .pipe(map(() => void 0));
57
+ }
58
+ }
59
+
60
+ /** Service for sending transactional emails and inspecting their delivery. */
61
+ class EmailsService extends BaseService {
62
+ url = `${this.apiBaseUrl}/v1/emails`;
63
+ /**
64
+ * Send a transactional email (`POST /v1/emails`).
65
+ * At least one of `html`, `text`, or `templateId` is required.
66
+ *
67
+ * @param params Email parameters.
68
+ * @param idempotencyKey Optional key that guarantees exactly-once delivery.
69
+ * If the same key is re-used within 24 hours the original response is returned.
70
+ * @returns Observable that emits the created email `id`.
71
+ */
72
+ send(params, idempotencyKey) {
73
+ const headers = this.authHeaders(idempotencyKey ? { 'Idempotency-Key': idempotencyKey } : undefined);
74
+ return this.http
75
+ .post(this.url, params, { headers })
76
+ .pipe(this.unwrap());
77
+ }
78
+ /**
79
+ * List emails with optional filters (`GET /v1/emails`).
80
+ * Results are ordered by creation date descending.
81
+ */
82
+ list(params) {
83
+ return this.http.get(this.url, {
84
+ headers: this.authHeaders(),
85
+ params: this.buildParams({
86
+ after: params?.after,
87
+ limit: params?.limit,
88
+ status: params?.status,
89
+ domainId: params?.domainId,
90
+ tags: params?.tags,
91
+ dateFrom: params?.dateFrom,
92
+ dateTo: params?.dateTo,
93
+ }),
94
+ });
95
+ }
96
+ /**
97
+ * Get a single email with full details and inline events (`GET /v1/emails/:id`).
98
+ */
99
+ get(id) {
100
+ return this.http
101
+ .get(`${this.url}/${id}`, { headers: this.authHeaders() })
102
+ .pipe(this.unwrap());
103
+ }
104
+ /**
105
+ * List all delivery events for a specific email (`GET /v1/emails/:id/events`).
106
+ */
107
+ listEvents(id) {
108
+ return this.http
109
+ .get(`${this.url}/${id}/events`, { headers: this.authHeaders() })
110
+ .pipe(this.unwrap());
111
+ }
112
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.3", ngImport: i0, type: EmailsService, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
113
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.3", ngImport: i0, type: EmailsService });
114
+ }
115
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.3", ngImport: i0, type: EmailsService, decorators: [{
116
+ type: Injectable
117
+ }] });
118
+
119
+ /** Service for managing contacts and running CSV imports. */
120
+ class ContactsService extends BaseService {
121
+ url = `${this.apiBaseUrl}/v1/contacts`;
122
+ /**
123
+ * Create a single contact (`POST /v1/contacts`).
124
+ * Returns a conflict error if the email address is already registered.
125
+ */
126
+ create(params) {
127
+ return this.http
128
+ .post(this.url, params, { headers: this.authHeaders() })
129
+ .pipe(this.unwrap());
130
+ }
131
+ /**
132
+ * List contacts with optional filters (`GET /v1/contacts`).
133
+ * Results are ordered by creation date descending.
134
+ */
135
+ list(params) {
136
+ return this.http.get(this.url, {
137
+ headers: this.authHeaders(),
138
+ params: this.buildParams({
139
+ status: params?.status,
140
+ audienceId: params?.audienceId,
141
+ tag: params?.tag,
142
+ after: params?.after,
143
+ limit: params?.limit,
144
+ }),
145
+ });
146
+ }
147
+ /**
148
+ * Update a contact's details (`PATCH /v1/contacts/:id`).
149
+ * Only supplied fields are updated.
150
+ */
151
+ update(id, params) {
152
+ return this.http
153
+ .patch(`${this.url}/${id}`, params, {
154
+ headers: this.authHeaders(),
155
+ })
156
+ .pipe(this.unwrap());
157
+ }
158
+ /**
159
+ * Start an asynchronous CSV import job (`POST /v1/contacts/import`).
160
+ *
161
+ * The CSV must have an `email` column. Optional columns:
162
+ * `first_name` / `firstname`, `last_name` / `lastname`, `status`,
163
+ * `tags` (semicolon-separated values).
164
+ *
165
+ * Maximum 50 000 rows per import. Poll {@link getImportJob} to track progress.
166
+ *
167
+ * @returns Observable that emits the new `jobId` and total row count.
168
+ */
169
+ importCsv(csvText) {
170
+ return this.http
171
+ .post(`${this.url}/import`, csvText, {
172
+ headers: new HttpHeaders({
173
+ Authorization: `Bearer ${this.config.apiKey}`,
174
+ 'Content-Type': 'text/csv',
175
+ }),
176
+ })
177
+ .pipe(this.unwrap());
178
+ }
179
+ /**
180
+ * Poll the status of a CSV import job (`GET /v1/contacts/import/:jobId`).
181
+ */
182
+ getImportJob(jobId) {
183
+ return this.http
184
+ .get(`${this.url}/import/${jobId}`, {
185
+ headers: this.authHeaders(),
186
+ })
187
+ .pipe(this.unwrap());
188
+ }
189
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.3", ngImport: i0, type: ContactsService, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
190
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.3", ngImport: i0, type: ContactsService });
191
+ }
192
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.3", ngImport: i0, type: ContactsService, decorators: [{
193
+ type: Injectable
194
+ }] });
195
+
196
+ /** Service for managing contact audiences. */
197
+ class AudiencesService extends BaseService {
198
+ url = `${this.apiBaseUrl}/v1/audiences`;
199
+ /**
200
+ * Create an audience (`POST /v1/audiences`).
201
+ * Optionally supply filter `rules` to make it a dynamic segment.
202
+ */
203
+ create(params) {
204
+ return this.http
205
+ .post(this.url, params, { headers: this.authHeaders() })
206
+ .pipe(this.unwrap());
207
+ }
208
+ /**
209
+ * List audiences (`GET /v1/audiences`).
210
+ * Results are ordered by creation date descending.
211
+ */
212
+ list(params) {
213
+ return this.http.get(this.url, {
214
+ headers: this.authHeaders(),
215
+ params: this.buildParams({ after: params?.after, limit: params?.limit }),
216
+ });
217
+ }
218
+ /**
219
+ * Get a single audience by ID (`GET /v1/audiences/:id`).
220
+ */
221
+ get(id) {
222
+ return this.http
223
+ .get(`${this.url}/${id}`, { headers: this.authHeaders() })
224
+ .pipe(this.unwrap());
225
+ }
226
+ /**
227
+ * Add contacts to an audience (`POST /v1/audiences/:id/contacts`).
228
+ * Accepts up to 500 contact IDs per call.
229
+ */
230
+ addContacts(audienceId, contactIds) {
231
+ return this.http
232
+ .post(`${this.url}/${audienceId}/contacts`, { contactIds }, { headers: this.authHeaders() })
233
+ .pipe(this.unwrap());
234
+ }
235
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.3", ngImport: i0, type: AudiencesService, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
236
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.3", ngImport: i0, type: AudiencesService });
237
+ }
238
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.3", ngImport: i0, type: AudiencesService, decorators: [{
239
+ type: Injectable
240
+ }] });
241
+
242
+ /** Service for managing and sending email campaigns. */
243
+ class CampaignsService extends BaseService {
244
+ url = `${this.apiBaseUrl}/v1/campaigns`;
245
+ /**
246
+ * Create a campaign in `draft` status (`POST /v1/campaigns`).
247
+ * Call {@link send} to dispatch it.
248
+ */
249
+ create(params) {
250
+ return this.http
251
+ .post(this.url, params, { headers: this.authHeaders() })
252
+ .pipe(this.unwrap());
253
+ }
254
+ /**
255
+ * List campaigns with optional status filter (`GET /v1/campaigns`).
256
+ * Results are ordered by creation date descending.
257
+ */
258
+ list(params) {
259
+ return this.http.get(this.url, {
260
+ headers: this.authHeaders(),
261
+ params: this.buildParams({ status: params?.status, after: params?.after, limit: params?.limit }),
262
+ });
263
+ }
264
+ /**
265
+ * Get a single campaign by ID (`GET /v1/campaigns/:id`).
266
+ */
267
+ get(id) {
268
+ return this.http
269
+ .get(`${this.url}/${id}`, { headers: this.authHeaders() })
270
+ .pipe(this.unwrap());
271
+ }
272
+ /**
273
+ * Get delivery statistics for a campaign (`GET /v1/campaigns/:id/stats`).
274
+ */
275
+ getStats(id) {
276
+ return this.http
277
+ .get(`${this.url}/${id}/stats`, {
278
+ headers: this.authHeaders(),
279
+ })
280
+ .pipe(this.unwrap());
281
+ }
282
+ /**
283
+ * Send or schedule a campaign (`POST /v1/campaigns/:id/send`).
284
+ * Only `draft` or `paused` campaigns can be sent.
285
+ *
286
+ * @param id Campaign ID.
287
+ * @param params Optional `scheduledAt` to defer sending.
288
+ * @returns Observable emitting the new campaign status.
289
+ */
290
+ send(id, params) {
291
+ const body = {};
292
+ if (params?.scheduledAt) {
293
+ body['scheduledAt'] =
294
+ params.scheduledAt instanceof Date
295
+ ? params.scheduledAt.toISOString()
296
+ : params.scheduledAt;
297
+ }
298
+ return this.http
299
+ .post(`${this.url}/${id}/send`, body, {
300
+ headers: this.authHeaders(),
301
+ })
302
+ .pipe(this.unwrap());
303
+ }
304
+ /**
305
+ * Pause a `sending` or `scheduled` campaign (`POST /v1/campaigns/:id/pause`).
306
+ */
307
+ pause(id) {
308
+ return this.http
309
+ .post(`${this.url}/${id}/pause`, {}, {
310
+ headers: this.authHeaders(),
311
+ })
312
+ .pipe(this.unwrap());
313
+ }
314
+ /**
315
+ * Send a test email for this campaign to a specific address
316
+ * (`POST /v1/campaigns/:id/test-send`).
317
+ *
318
+ * @param id Campaign ID.
319
+ * @param to Recipient email address for the test.
320
+ * @returns Observable emitting the created test email ID.
321
+ */
322
+ testSend(id, to) {
323
+ return this.http
324
+ .post(`${this.url}/${id}/test-send`, { to }, {
325
+ headers: this.authHeaders(),
326
+ })
327
+ .pipe(this.unwrap());
328
+ }
329
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.3", ngImport: i0, type: CampaignsService, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
330
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.3", ngImport: i0, type: CampaignsService });
331
+ }
332
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.3", ngImport: i0, type: CampaignsService, decorators: [{
333
+ type: Injectable
334
+ }] });
335
+
336
+ /** Service for managing email templates and their version history. */
337
+ class TemplatesService extends BaseService {
338
+ url = `${this.apiBaseUrl}/v1/templates`;
339
+ /**
340
+ * List templates (`GET /v1/templates`).
341
+ * Results are ordered by creation date descending.
342
+ */
343
+ list(params) {
344
+ return this.http.get(this.url, {
345
+ headers: this.authHeaders(),
346
+ params: this.buildParams({ limit: params?.limit, after: params?.after, status: params?.status }),
347
+ });
348
+ }
349
+ /**
350
+ * Create a new template (`POST /v1/templates`).
351
+ * The template starts in `draft` status.
352
+ */
353
+ create(params) {
354
+ return this.http
355
+ .post(this.url, params, { headers: this.authHeaders() })
356
+ .pipe(this.unwrap());
357
+ }
358
+ /**
359
+ * Get a single template by ID (`GET /v1/templates/:id`).
360
+ */
361
+ get(id) {
362
+ return this.http
363
+ .get(`${this.url}/${id}`, { headers: this.authHeaders() })
364
+ .pipe(this.unwrap());
365
+ }
366
+ /**
367
+ * Update a template's name, HTML, or status (`PATCH /v1/templates/:id`).
368
+ * Changing `html` automatically creates a new version entry.
369
+ */
370
+ update(id, params) {
371
+ return this.http
372
+ .patch(`${this.url}/${id}`, params, { headers: this.authHeaders() })
373
+ .pipe(this.unwrap());
374
+ }
375
+ /**
376
+ * Permanently delete a template (`DELETE /v1/templates/:id`).
377
+ */
378
+ delete(id) {
379
+ return this.voidRequest('DELETE', `${this.url}/${id}`);
380
+ }
381
+ /**
382
+ * List the version history of a template (`GET /v1/templates/:id/versions`).
383
+ * Returns up to the 20 most recent versions, newest first.
384
+ */
385
+ listVersions(id) {
386
+ return this.http
387
+ .get(`${this.url}/${id}/versions`, {
388
+ headers: this.authHeaders(),
389
+ })
390
+ .pipe(this.unwrap());
391
+ }
392
+ /**
393
+ * Get the HTML of a specific template version (`GET /v1/templates/:id/versions/:version`).
394
+ */
395
+ getVersion(id, version) {
396
+ return this.http
397
+ .get(`${this.url}/${id}/versions/${version}`, {
398
+ headers: this.authHeaders(),
399
+ })
400
+ .pipe(this.unwrap());
401
+ }
402
+ /**
403
+ * Send a test email using this template (`POST /v1/templates/:id/test-send`).
404
+ *
405
+ * @param id Template ID.
406
+ * @param to Recipient address for the test.
407
+ * @param variables Variables to substitute inside the template.
408
+ */
409
+ testSend(id, to, variables = {}) {
410
+ return this.http
411
+ .post(`${this.url}/${id}/test-send`, { to, variables }, { headers: this.authHeaders() })
412
+ .pipe(this.unwrap());
413
+ }
414
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.3", ngImport: i0, type: TemplatesService, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
415
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.3", ngImport: i0, type: TemplatesService });
416
+ }
417
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.3", ngImport: i0, type: TemplatesService, decorators: [{
418
+ type: Injectable
419
+ }] });
420
+
421
+ /** Service for managing webhook endpoints and inspecting delivery history. */
422
+ class WebhooksService extends BaseService {
423
+ url = `${this.apiBaseUrl}/v1/webhooks`;
424
+ /**
425
+ * Register a new webhook endpoint (`POST /v1/webhooks`).
426
+ *
427
+ * The returned `secret` is shown only once — store it securely and use it
428
+ * to verify the `X-Tratto-Signature` header on incoming events.
429
+ *
430
+ * @returns Observable emitting the new webhook `id` and HMAC signing `secret`.
431
+ */
432
+ create(params) {
433
+ return this.http
434
+ .post(this.url, params, {
435
+ headers: this.authHeaders(),
436
+ })
437
+ .pipe(this.unwrap());
438
+ }
439
+ /**
440
+ * List all registered webhooks (`GET /v1/webhooks`).
441
+ * Results are ordered by creation date descending.
442
+ */
443
+ list() {
444
+ return this.http
445
+ .get(this.url, { headers: this.authHeaders() })
446
+ .pipe(this.unwrap());
447
+ }
448
+ /**
449
+ * Delete a webhook endpoint (`DELETE /v1/webhooks/:id`).
450
+ */
451
+ delete(id) {
452
+ return this.voidRequest('DELETE', `${this.url}/${id}`);
453
+ }
454
+ /**
455
+ * List delivery attempts for a webhook (`GET /v1/webhooks/:id/deliveries`).
456
+ * Results are ordered by attempt date descending.
457
+ */
458
+ listDeliveries(id, params) {
459
+ return this.http.get(`${this.url}/${id}/deliveries`, {
460
+ headers: this.authHeaders(),
461
+ params: this.buildParams({ after: params?.after, limit: params?.limit }),
462
+ });
463
+ }
464
+ /**
465
+ * Send a test event to a webhook endpoint (`POST /v1/webhooks/:id/test`).
466
+ * Useful for verifying connectivity and signature verification logic.
467
+ */
468
+ test(id) {
469
+ return this.http
470
+ .post(`${this.url}/${id}/test`, {}, {
471
+ headers: this.authHeaders(),
472
+ })
473
+ .pipe(this.unwrap());
474
+ }
475
+ /**
476
+ * Rotate the signing secret for a webhook (`POST /v1/webhooks/:id/rotate-secret`).
477
+ * The new secret is returned once — store it securely.
478
+ * Also resets the failure counter and re-enables a disabled webhook.
479
+ */
480
+ rotateSecret(id) {
481
+ return this.http
482
+ .post(`${this.url}/${id}/rotate-secret`, {}, {
483
+ headers: this.authHeaders(),
484
+ })
485
+ .pipe(this.unwrap());
486
+ }
487
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.3", ngImport: i0, type: WebhooksService, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
488
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.3", ngImport: i0, type: WebhooksService });
489
+ }
490
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.3", ngImport: i0, type: WebhooksService, decorators: [{
491
+ type: Injectable
492
+ }] });
493
+
494
+ /** Service for adding and verifying sender domains. */
495
+ class DomainsService extends BaseService {
496
+ url = `${this.apiBaseUrl}/v1/domains`;
497
+ /**
498
+ * Add a domain and generate its DKIM keypair (`POST /v1/domains`).
499
+ * The response contains the DNS records that must be published before calling {@link verify}.
500
+ *
501
+ * @param domain Bare domain name, e.g. `"mail.acme.com"`.
502
+ */
503
+ add(domain) {
504
+ return this.http
505
+ .post(this.url, { domain }, { headers: this.authHeaders() })
506
+ .pipe(this.unwrap());
507
+ }
508
+ /**
509
+ * List domains (`GET /v1/domains`).
510
+ * Results are ordered by creation date descending.
511
+ */
512
+ list(params) {
513
+ return this.http.get(this.url, {
514
+ headers: this.authHeaders(),
515
+ params: this.buildParams({ after: params?.after, limit: params?.limit }),
516
+ });
517
+ }
518
+ /**
519
+ * Get full domain details including DNS records (`GET /v1/domains/:id`).
520
+ */
521
+ get(id) {
522
+ return this.http
523
+ .get(`${this.url}/${id}`, { headers: this.authHeaders() })
524
+ .pipe(this.unwrap());
525
+ }
526
+ /**
527
+ * Trigger DNS verification for a domain (`POST /v1/domains/:id/verify`).
528
+ * Checks SPF, DKIM, and DMARC records in real time and updates the domain status.
529
+ * The domain must be `verified` before it can be used as a sender.
530
+ */
531
+ verify(id) {
532
+ return this.http
533
+ .post(`${this.url}/${id}/verify`, {}, { headers: this.authHeaders() })
534
+ .pipe(this.unwrap());
535
+ }
536
+ /**
537
+ * Remove a domain and delete its DKIM private key (`DELETE /v1/domains/:id`).
538
+ *
539
+ * @returns Observable emitting the deleted domain `id` and `deletedAt` timestamp.
540
+ */
541
+ delete(id) {
542
+ return this.http
543
+ .delete(`${this.url}/${id}`, {
544
+ headers: this.authHeaders(),
545
+ })
546
+ .pipe(this.unwrap());
547
+ }
548
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.3", ngImport: i0, type: DomainsService, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
549
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.3", ngImport: i0, type: DomainsService });
550
+ }
551
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.3", ngImport: i0, type: DomainsService, decorators: [{
552
+ type: Injectable
553
+ }] });
554
+
555
+ /** Service for creating and revoking API keys. */
556
+ class ApiKeysService extends BaseService {
557
+ url = `${this.apiBaseUrl}/v1/api-keys`;
558
+ /**
559
+ * Create a new API key (`POST /v1/api-keys`).
560
+ *
561
+ * The full raw key in the response is shown **only once** — store it securely.
562
+ *
563
+ * @param params Key name, environment and permission scopes.
564
+ * @param idempotencyKey Optional key to prevent accidental duplicates.
565
+ * @returns Observable emitting the created key including the raw token.
566
+ */
567
+ create(params, idempotencyKey) {
568
+ const headers = this.authHeaders(idempotencyKey ? { 'Idempotency-Key': idempotencyKey } : undefined);
569
+ return this.http
570
+ .post(this.url, params, { headers })
571
+ .pipe(this.unwrap());
572
+ }
573
+ /**
574
+ * List API keys (without the raw token) (`GET /v1/api-keys`).
575
+ * Results are ordered by creation date descending.
576
+ */
577
+ list(params) {
578
+ return this.http.get(this.url, {
579
+ headers: this.authHeaders(),
580
+ params: this.buildParams({ after: params?.after, limit: params?.limit }),
581
+ });
582
+ }
583
+ /**
584
+ * Revoke (soft-delete) an API key (`DELETE /v1/api-keys/:id`).
585
+ * Revoked keys are immediately rejected by the API.
586
+ *
587
+ * @returns Observable emitting the key `id` and `revokedAt` timestamp.
588
+ */
589
+ revoke(id) {
590
+ return this.http
591
+ .delete(`${this.url}/${id}`, {
592
+ headers: this.authHeaders(),
593
+ })
594
+ .pipe(this.unwrap());
595
+ }
596
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.3", ngImport: i0, type: ApiKeysService, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
597
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.3", ngImport: i0, type: ApiKeysService });
598
+ }
599
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.3", ngImport: i0, type: ApiKeysService, decorators: [{
600
+ type: Injectable
601
+ }] });
602
+
603
+ /** Service for querying email analytics and delivery metrics. */
604
+ class AnalyticsService extends BaseService {
605
+ url = `${this.apiBaseUrl}/v1/analytics`;
606
+ /**
607
+ * Get aggregated email metrics for a time period (`GET /v1/analytics/summary`).
608
+ * Results are cached server-side for one hour.
609
+ *
610
+ * @param period Lookback window. Defaults to `'30d'`.
611
+ */
612
+ getSummary(period = '30d') {
613
+ return this.http
614
+ .get(`${this.url}/summary`, {
615
+ headers: this.authHeaders(),
616
+ params: this.buildParams({ period }),
617
+ })
618
+ .pipe(this.unwrap());
619
+ }
620
+ /**
621
+ * Get daily email metrics for a time period (`GET /v1/analytics/timeseries`).
622
+ * Returns one data point per day for the chosen window.
623
+ * Results are cached server-side for one hour.
624
+ *
625
+ * @param period Lookback window. Defaults to `'30d'`.
626
+ */
627
+ getTimeseries(period = '30d') {
628
+ return this.http
629
+ .get(`${this.url}/timeseries`, {
630
+ headers: this.authHeaders(),
631
+ params: this.buildParams({ period }),
632
+ })
633
+ .pipe(this.unwrap());
634
+ }
635
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.3", ngImport: i0, type: AnalyticsService, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
636
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.3", ngImport: i0, type: AnalyticsService });
637
+ }
638
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.3", ngImport: i0, type: AnalyticsService, decorators: [{
639
+ type: Injectable
640
+ }] });
641
+
642
+ /** Service for managing email automation flows. */
643
+ class FlowsService extends BaseService {
644
+ url = `${this.apiBaseUrl}/v1/flows`;
645
+ /**
646
+ * List automation flows (`GET /v1/flows`).
647
+ * Results are ordered by creation date descending.
648
+ */
649
+ list(params) {
650
+ return this.http.get(this.url, {
651
+ headers: this.authHeaders(),
652
+ params: this.buildParams({ after: params?.after, limit: params?.limit }),
653
+ });
654
+ }
655
+ /**
656
+ * Create a flow in `draft` status (`POST /v1/flows`).
657
+ * Configure the trigger and steps via {@link update} before activating.
658
+ */
659
+ create(params) {
660
+ return this.http
661
+ .post(this.url, params, { headers: this.authHeaders() })
662
+ .pipe(this.unwrap());
663
+ }
664
+ /**
665
+ * Get a single flow by ID (`GET /v1/flows/:id`).
666
+ */
667
+ get(id) {
668
+ return this.http
669
+ .get(`${this.url}/${id}`, { headers: this.authHeaders() })
670
+ .pipe(this.unwrap());
671
+ }
672
+ /**
673
+ * Update a flow's name, trigger, or steps (`PATCH /v1/flows/:id`).
674
+ * Steps cannot be changed while the flow is active — call {@link deactivate} first.
675
+ */
676
+ update(id, params) {
677
+ return this.http
678
+ .patch(`${this.url}/${id}`, params, { headers: this.authHeaders() })
679
+ .pipe(this.unwrap());
680
+ }
681
+ /**
682
+ * Delete a flow (`DELETE /v1/flows/:id`).
683
+ * Only `draft` or `inactive` flows can be deleted.
684
+ */
685
+ delete(id) {
686
+ return this.http
687
+ .delete(`${this.url}/${id}`, { headers: this.authHeaders() })
688
+ .pipe(this.unwrap());
689
+ }
690
+ /**
691
+ * Activate a flow, enabling it to enroll contacts (`POST /v1/flows/:id/activate`).
692
+ */
693
+ activate(id) {
694
+ return this.http
695
+ .post(`${this.url}/${id}/activate`, {}, { headers: this.authHeaders() })
696
+ .pipe(this.unwrap());
697
+ }
698
+ /**
699
+ * Deactivate a flow (`POST /v1/flows/:id/deactivate`).
700
+ * Contacts already enrolled continue through their current steps.
701
+ * No new enrollments are accepted until the flow is re-activated.
702
+ */
703
+ deactivate(id) {
704
+ return this.http
705
+ .post(`${this.url}/${id}/deactivate`, {}, { headers: this.authHeaders() })
706
+ .pipe(this.unwrap());
707
+ }
708
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.3", ngImport: i0, type: FlowsService, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
709
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.3", ngImport: i0, type: FlowsService });
710
+ }
711
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.3", ngImport: i0, type: FlowsService, decorators: [{
712
+ type: Injectable
713
+ }] });
714
+
715
+ /** Service for managing workspace settings and team members. */
716
+ class WorkspaceService extends BaseService {
717
+ url = `${this.apiBaseUrl}/v1/workspace`;
718
+ /**
719
+ * Get the current workspace (`GET /v1/workspace`).
720
+ * Creates a workspace with default settings on first access if none exists.
721
+ */
722
+ get() {
723
+ return this.http
724
+ .get(this.url, { headers: this.authHeaders() })
725
+ .pipe(this.unwrap());
726
+ }
727
+ /**
728
+ * Update workspace settings (`PATCH /v1/workspace`).
729
+ * Only supplied fields are changed.
730
+ */
731
+ update(params) {
732
+ return this.http
733
+ .patch(this.url, params, { headers: this.authHeaders() })
734
+ .pipe(this.unwrap());
735
+ }
736
+ /**
737
+ * Schedule the workspace for deletion (`DELETE /v1/workspace`).
738
+ * Only the workspace owner can perform this action.
739
+ */
740
+ delete() {
741
+ return this.voidRequest('DELETE', this.url);
742
+ }
743
+ /**
744
+ * Update workspace preferences such as locale and notification settings
745
+ * (`PATCH /v1/workspace/preferences`).
746
+ */
747
+ updatePreferences(params) {
748
+ return this.http
749
+ .patch(`${this.url}/preferences`, params, {
750
+ headers: this.authHeaders(),
751
+ })
752
+ .pipe(this.unwrap());
753
+ }
754
+ /**
755
+ * Invite a new member to the workspace (`POST /v1/workspace/members/invite`).
756
+ * The invite is accepted automatically when the user first logs in.
757
+ */
758
+ inviteMember(params) {
759
+ return this.http
760
+ .post(`${this.url}/members/invite`, params, {
761
+ headers: this.authHeaders(),
762
+ })
763
+ .pipe(this.unwrap());
764
+ }
765
+ /**
766
+ * Update a member's role (`PATCH /v1/workspace/members/:userId`).
767
+ */
768
+ updateMember(userId, params) {
769
+ return this.http
770
+ .patch(`${this.url}/members/${userId}`, params, {
771
+ headers: this.authHeaders(),
772
+ })
773
+ .pipe(this.unwrap());
774
+ }
775
+ /**
776
+ * Remove a member from the workspace (`DELETE /v1/workspace/members/:userId`).
777
+ * The workspace owner cannot be removed.
778
+ */
779
+ removeMember(userId) {
780
+ return this.voidRequest('DELETE', `${this.url}/members/${userId}`);
781
+ }
782
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.3", ngImport: i0, type: WorkspaceService, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
783
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.3", ngImport: i0, type: WorkspaceService });
784
+ }
785
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.3", ngImport: i0, type: WorkspaceService, decorators: [{
786
+ type: Injectable
787
+ }] });
788
+
789
+ /**
790
+ * Top-level facade that aggregates all Tratto resource services.
791
+ *
792
+ * Inject `TrattoService` for a single entry-point into the SDK, or inject
793
+ * individual resource services (e.g. `EmailsService`) directly for
794
+ * better tree-shaking in large applications.
795
+ *
796
+ * @example
797
+ * ```ts
798
+ * // app.component.ts
799
+ * export class AppComponent {
800
+ * private tratto = inject(TrattoService);
801
+ *
802
+ * sendWelcome() {
803
+ * this.tratto.emails
804
+ * .send({ from: 'hello@acme.com', to: 'user@example.com', subject: 'Welcome!' })
805
+ * .subscribe(({ id }) => console.log('Sent:', id));
806
+ * }
807
+ * }
808
+ * ```
809
+ */
810
+ class TrattoService {
811
+ /** Access email sending and inspection methods. */
812
+ emails = inject(EmailsService);
813
+ /** Access contact management and CSV import methods. */
814
+ contacts = inject(ContactsService);
815
+ /** Access audience creation and membership methods. */
816
+ audiences = inject(AudiencesService);
817
+ /** Access campaign creation, scheduling, and statistics methods. */
818
+ campaigns = inject(CampaignsService);
819
+ /** Access template CRUD and version history methods. */
820
+ templates = inject(TemplatesService);
821
+ /** Access webhook registration and delivery history methods. */
822
+ webhooks = inject(WebhooksService);
823
+ /** Access domain onboarding and DNS verification methods. */
824
+ domains = inject(DomainsService);
825
+ /** Access API key creation and revocation methods. */
826
+ apiKeys = inject(ApiKeysService);
827
+ /** Access email analytics summary and time-series methods. */
828
+ analytics = inject(AnalyticsService);
829
+ /** Access automation flow management methods. */
830
+ flows = inject(FlowsService);
831
+ /** Access workspace settings and team member methods. */
832
+ workspace = inject(WorkspaceService);
833
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.3", ngImport: i0, type: TrattoService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
834
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.3", ngImport: i0, type: TrattoService });
835
+ }
836
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.3", ngImport: i0, type: TrattoService, decorators: [{
837
+ type: Injectable
838
+ }] });
839
+
840
+ /** All injectable services exported by this SDK. */
841
+ const TRATTO_PROVIDERS = [
842
+ EmailsService,
843
+ ContactsService,
844
+ AudiencesService,
845
+ CampaignsService,
846
+ TemplatesService,
847
+ WebhooksService,
848
+ DomainsService,
849
+ ApiKeysService,
850
+ AnalyticsService,
851
+ FlowsService,
852
+ WorkspaceService,
853
+ TrattoService,
854
+ ];
855
+ /**
856
+ * Provides all Tratto services for **standalone** Angular applications.
857
+ *
858
+ * Add this to your `ApplicationConfig` providers array alongside
859
+ * `provideHttpClient()`. The SDK uses `HttpClient` internally; if your app
860
+ * has not already provided it, include `provideHttpClient()` as well.
861
+ *
862
+ * @example
863
+ * ```ts
864
+ * // app.config.ts
865
+ * import { provideHttpClient } from '@angular/common/http';
866
+ * import { provideTratt } from '@tratto/angular';
867
+ *
868
+ * export const appConfig: ApplicationConfig = {
869
+ * providers: [
870
+ * provideHttpClient(),
871
+ * provideTratt({ apiKey: 'tratto_live_...' }),
872
+ * ],
873
+ * };
874
+ * ```
875
+ */
876
+ function provideTratt(config) {
877
+ return makeEnvironmentProviders([
878
+ { provide: TRATTO_CONFIG, useValue: config },
879
+ ...TRATTO_PROVIDERS,
880
+ ]);
881
+ }
882
+ /**
883
+ * Angular module that registers all Tratto services.
884
+ *
885
+ * For Angular 14+ **standalone** applications prefer {@link provideTratt}.
886
+ * For **NgModule**-based applications use `TrattoModule.forRoot()`.
887
+ *
888
+ * > **Note:** `HttpClientModule` (or `provideHttpClient()`) must be imported
889
+ * > in your application before importing `TrattoModule`.
890
+ *
891
+ * @example
892
+ * ```ts
893
+ * // app.module.ts
894
+ * import { HttpClientModule } from '@angular/common/http';
895
+ * import { TrattoModule } from '@tratto/angular';
896
+ *
897
+ * @NgModule({
898
+ * imports: [
899
+ * HttpClientModule,
900
+ * TrattoModule.forRoot({ apiKey: 'tratto_live_...' }),
901
+ * ],
902
+ * })
903
+ * export class AppModule {}
904
+ * ```
905
+ */
906
+ class TrattoModule {
907
+ static forRoot(config) {
908
+ return {
909
+ ngModule: TrattoModule,
910
+ providers: [
911
+ { provide: TRATTO_CONFIG, useValue: config },
912
+ ...TRATTO_PROVIDERS,
913
+ ],
914
+ };
915
+ }
916
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.3", ngImport: i0, type: TrattoModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
917
+ static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "22.0.3", ngImport: i0, type: TrattoModule });
918
+ static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "22.0.3", ngImport: i0, type: TrattoModule });
919
+ }
920
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.3", ngImport: i0, type: TrattoModule, decorators: [{
921
+ type: NgModule,
922
+ args: [{}]
923
+ }] });
924
+
925
+ // ── Configuration ─────────────────────────────────────────────────────────────
926
+
927
+ /**
928
+ * Generated bundle index. Do not edit.
929
+ */
930
+
931
+ export { AnalyticsService, ApiKeysService, AudiencesService, CampaignsService, ContactsService, DomainsService, EmailsService, FlowsService, TRATTO_CONFIG, TemplatesService, TrattoModule, TrattoService, WebhooksService, WorkspaceService, provideTratt };
932
+ //# sourceMappingURL=tratto-angular.mjs.map