mailpit-api 1.0.5 → 1.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,141 @@
1
+ import axios, { isAxiosError, } from "axios";
2
+ export class MailpitClient {
3
+ axiosInstance;
4
+ constructor(baseURL, auth) {
5
+ this.axiosInstance = axios.create({
6
+ baseURL,
7
+ auth,
8
+ validateStatus: function (status) {
9
+ return status === 200;
10
+ },
11
+ });
12
+ }
13
+ async handleRequest(request, options = { fullResponse: false }) {
14
+ try {
15
+ const response = await request();
16
+ return options.fullResponse ? response : response.data;
17
+ }
18
+ catch (error) {
19
+ if (isAxiosError(error)) {
20
+ const url = error.config?.url || "UNKNOWN URL";
21
+ const method = error.config?.method?.toUpperCase() || "UNKNOWN METHOD";
22
+ if (error.response) {
23
+ // Server responded with a status other than 2xx
24
+ throw new Error(`Mailpit API Error: ${error.response.status.toString()} ${error.response.statusText} at ${method} ${url}: ${JSON.stringify(error.response.data)}`);
25
+ }
26
+ else if (error.request) {
27
+ // Request was made but no response was received
28
+ throw new Error(`Mailpit API Error: No response received from server at ${method} ${url}`);
29
+ }
30
+ else {
31
+ // Something happened in setting up the request
32
+ throw new Error(`Mailpit API Error: ${error.toString()} at ${method} ${url}`);
33
+ }
34
+ }
35
+ else {
36
+ throw new Error(`Unexpected Error: ${error}`);
37
+ }
38
+ }
39
+ }
40
+ // Application
41
+ async getInfo() {
42
+ return await this.handleRequest(() => this.axiosInstance.get("/api/v1/info"));
43
+ }
44
+ async getConfiguration() {
45
+ return await this.handleRequest(() => this.axiosInstance.get("/api/v1/webui"));
46
+ }
47
+ // Message
48
+ async getMessageSummary(id = "latest") {
49
+ return await this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}`));
50
+ }
51
+ async getMessageHeaders(id = "latest") {
52
+ return await this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/headers`));
53
+ }
54
+ async getMessageAttachment(id, partID) {
55
+ const response = await this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/part/${partID}`, { responseType: "arraybuffer" }), { fullResponse: true });
56
+ return {
57
+ data: response.data,
58
+ contentType: response.headers["content-type"],
59
+ };
60
+ }
61
+ async getMessageSource(id = "latest") {
62
+ return await this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/raw`));
63
+ }
64
+ async getAttachmentThumbnail(id, partID) {
65
+ const response = await this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/part/${partID}/thumb`, {
66
+ responseType: "arraybuffer",
67
+ }), { fullResponse: true });
68
+ return {
69
+ data: response.data,
70
+ contentType: response.headers["content-type"],
71
+ };
72
+ }
73
+ async releaseMessage(id, releaseRequest) {
74
+ return await this.handleRequest(() => this.axiosInstance.post(`/api/v1/message/${id}/release`, releaseRequest));
75
+ }
76
+ async sendMessage(sendReqest) {
77
+ return await this.handleRequest(() => this.axiosInstance.post(`/api/v1/send`, sendReqest));
78
+ }
79
+ // Other
80
+ async htmlCheck(id = "latest") {
81
+ return await this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/html-check`));
82
+ }
83
+ async linkCheck(id = "latest", follow = "false") {
84
+ return await this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/link-check`, { params: { follow } }));
85
+ }
86
+ async spamAssassinCheck(id = "latest") {
87
+ return await this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/sa-check`));
88
+ }
89
+ // Messages
90
+ async listMessages(start = 0, limit = 50) {
91
+ return await this.handleRequest(() => this.axiosInstance.get(`/api/v1/messages`, { params: { start, limit } }));
92
+ }
93
+ async setReadStatus(readStatus) {
94
+ return await this.handleRequest(() => this.axiosInstance.put(`/api/v1/messages`, readStatus));
95
+ }
96
+ async deleteMessages(deleteRequest) {
97
+ return await this.handleRequest(() => this.axiosInstance.delete(`/api/v1/messages`, {
98
+ data: deleteRequest,
99
+ }));
100
+ }
101
+ // See https://mailpit.axllent.org/docs/usage/search-filters/
102
+ async searchMessages(search) {
103
+ return await this.handleRequest(() => this.axiosInstance.get(`/api/v1/search`, {
104
+ params: search,
105
+ }));
106
+ }
107
+ // See https://mailpit.axllent.org/docs/usage/search-filters/
108
+ async deleteMessagesBySearch(search) {
109
+ return await this.handleRequest(() => this.axiosInstance.delete(`/api/v1/search`, { params: search }));
110
+ }
111
+ // Tags
112
+ async getTags() {
113
+ return await this.handleRequest(() => this.axiosInstance.get(`/api/v1/tags`));
114
+ }
115
+ async setTags(request) {
116
+ return await this.handleRequest(() => this.axiosInstance.put(`/api/v1/tags`, request));
117
+ }
118
+ async renameTag(tag, newTagName) {
119
+ const encodedTag = encodeURI(tag);
120
+ return await this.handleRequest(() => this.axiosInstance.put(`/api/v1/tags/${encodedTag}`, {
121
+ Name: newTagName,
122
+ }));
123
+ }
124
+ async deleteTag(tag) {
125
+ const encodedTag = encodeURI(tag);
126
+ return await this.handleRequest(() => this.axiosInstance.delete(`/api/v1/tags/${encodedTag}`));
127
+ }
128
+ // Testing
129
+ async renderMessageHTML(id = "latest", embed) {
130
+ return await this.handleRequest(() => this.axiosInstance.get(`/view/${id}.html`, { params: { embed } }));
131
+ }
132
+ async renderMessageText(id = "latest") {
133
+ return await this.handleRequest(() => this.axiosInstance.get(`/view/${id}.txt`));
134
+ }
135
+ async getChaosTriggers() {
136
+ return await this.handleRequest(() => this.axiosInstance.get("/api/v1/chaos"));
137
+ }
138
+ async setChaosTriggers(triggers = {}) {
139
+ return await this.handleRequest(() => this.axiosInstance.put("/api/v1/chaos", triggers));
140
+ }
141
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mailpit-api",
3
- "version": "1.0.5",
3
+ "version": "1.1.0",
4
4
  "description": "A NodeJS client library, written in TypeScript, to interact with the Mailpit API.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -17,7 +17,8 @@
17
17
  "scripts": {
18
18
  "test": "echo \"TODO: Add tests\" && exit 0",
19
19
  "build": "rm -fr dist/* && tsc -p tsconfig.json && tsc -p tsconfig-cjs.json && ./fixup_type",
20
- "pretty": "npx prettier . --write"
20
+ "pretty": "npx prettier . --write",
21
+ "lint": "npx eslint . --fix"
21
22
  },
22
23
  "keywords": [
23
24
  "mailpit-api",
@@ -33,19 +34,17 @@
33
34
  "author": "Matthew Spahr",
34
35
  "license": "MIT",
35
36
  "dependencies": {
36
- "axios": "^1.7.8"
37
+ "axios": "^1.7.9"
37
38
  },
38
39
  "devDependencies": {
39
- "@eslint/js": "^8.57.0",
40
+ "@eslint/js": "^8.57.1",
41
+ "@types/eslint__js": "^8.42.3",
40
42
  "@types/node": "^20.14.15",
41
- "@typescript-eslint/eslint-plugin": "^7.18.0",
42
- "@typescript-eslint/parser": "^7.18.0",
43
- "eslint": "^8.57.0",
44
- "globals": "^15.13.0",
43
+ "eslint": "^9.20.1",
45
44
  "jest": "^29.7.0",
46
45
  "prettier": "3.4.2",
47
46
  "tsx": "^4.19.2",
48
- "typescript": "^5.7.2",
49
- "typescript-eslint": "^7.18.0"
47
+ "typescript": "^5.7.3",
48
+ "typescript-eslint": "^8.24.0"
50
49
  }
51
50
  }
package/src/index.ts CHANGED
@@ -1,5 +1,34 @@
1
- import axios, { AxiosInstance } from "axios";
1
+ import axios, {
2
+ type AxiosInstance,
3
+ type AxiosResponse,
4
+ isAxiosError,
5
+ } from "axios";
6
+
7
+ // Common types
8
+ interface Address {
9
+ Address: string;
10
+ Name: string;
11
+ }
12
+
13
+ interface Email {
14
+ Email: string;
15
+ Name: string;
16
+ }
2
17
 
18
+ interface Attachment {
19
+ ContentID: string;
20
+ ContentType: string;
21
+ FileName: string;
22
+ PartID: string;
23
+ Size: number;
24
+ }
25
+
26
+ interface ChaosTrigger {
27
+ ErrorCode: number;
28
+ Probability: number;
29
+ }
30
+
31
+ // Responses and Requests
3
32
  export interface MailpitInfoResponse {
4
33
  Database: string;
5
34
  DatabaseSize: number;
@@ -34,49 +63,22 @@ export interface MailpitConfigurationResponse {
34
63
  }
35
64
 
36
65
  export interface MailpitMessageSummaryResponse {
37
- Attachments: {
38
- ContentID: string;
39
- ContentType: string;
40
- FileName: string;
41
- PartID: string;
42
- Size: number;
43
- }[];
44
- Bcc: {
45
- Address: string;
46
- Name: string;
47
- }[];
48
- Cc: {
49
- Address: string;
50
- Name: string;
51
- }[];
66
+ Attachments: Attachment[];
67
+ Bcc: Address[];
68
+ Cc: Address[];
52
69
  Date: string;
53
- From: {
54
- Address: string;
55
- Name: string;
56
- };
70
+ From: Address;
57
71
  HTML: string;
58
72
  ID: string;
59
- Inline: {
60
- ContentID: string;
61
- ContentType: string;
62
- FileName: string;
63
- PartID: string;
64
- Size: number;
65
- }[];
73
+ Inline: Attachment[];
66
74
  MessageID: string;
67
- ReplyTo: {
68
- Address: string;
69
- Name: string;
70
- }[];
75
+ ReplyTo: Address[];
71
76
  ReturnPath: string;
72
77
  Size: number;
73
78
  Subject: string;
74
79
  Tags: string[];
75
80
  Text: string;
76
- To: {
77
- Address: string;
78
- Name: string;
79
- }[];
81
+ To: Address[];
80
82
  }
81
83
 
82
84
  export interface MailpitMessagesSummaryResponse {
@@ -89,26 +91,11 @@ export interface MailpitMessagesSummaryResponse {
89
91
  ID: string;
90
92
  MessageID: string;
91
93
  Read: boolean;
92
- Bcc: {
93
- Address: string;
94
- Name: string;
95
- }[];
96
- Cc: {
97
- Address: string;
98
- Name: string;
99
- }[];
100
- From: {
101
- Address: string;
102
- Name: string;
103
- };
104
- ReplyTo: {
105
- Address: string;
106
- Name: string;
107
- }[];
108
- To: {
109
- Address: string;
110
- Name: string;
111
- }[];
94
+ Bcc: Address[];
95
+ Cc: Address[];
96
+ From: Address;
97
+ ReplyTo: Address[];
98
+ To: Address[];
112
99
  }[];
113
100
  messages_count: number;
114
101
  start: number;
@@ -127,29 +114,17 @@ export interface MailpitSendRequest {
127
114
  Filename: string;
128
115
  }[];
129
116
  Bcc: string[];
130
- Cc: {
131
- Email: string;
132
- Name: string;
133
- }[];
134
- From: {
135
- Email: string;
136
- Name: string;
137
- };
117
+ Cc: Email[];
118
+ From: Email;
138
119
  HTML: string;
139
120
  Headers: {
140
121
  [key: string]: string;
141
122
  };
142
- ReplyTo: {
143
- Email: string;
144
- Name: string;
145
- }[];
123
+ ReplyTo: Email[];
146
124
  Subject: string;
147
125
  Tags: string[];
148
126
  Text: string;
149
- To: {
150
- Email: string;
151
- Name: string;
152
- }[];
127
+ To: Email[];
153
128
  }
154
129
 
155
130
  export interface MailpitSendMessageConfirmationResponse {
@@ -241,12 +216,30 @@ export interface MailpitSetTagsRequest {
241
216
  Tags: string[];
242
217
  }
243
218
 
219
+ export interface ChaosTriggersRequest {
220
+ Authentication?: ChaosTrigger;
221
+ Recipient?: ChaosTrigger;
222
+ Sender?: ChaosTrigger;
223
+ }
224
+
225
+ export interface ChaosTriggersResponse {
226
+ Authentication: ChaosTrigger;
227
+ Recipient?: ChaosTrigger;
228
+ Sender?: ChaosTrigger;
229
+ }
230
+
231
+ interface AttachmentResponse {
232
+ data: ArrayBuffer;
233
+ contentType: string;
234
+ }
235
+
244
236
  export class MailpitClient {
245
237
  private axiosInstance: AxiosInstance;
246
238
 
247
- constructor(baseURL: string) {
239
+ constructor(baseURL: string, auth?: { username: string; password: string }) {
248
240
  this.axiosInstance = axios.create({
249
- baseURL: baseURL,
241
+ baseURL,
242
+ auth,
250
243
  validateStatus: function (status) {
251
244
  return status === 200;
252
245
  },
@@ -254,50 +247,64 @@ export class MailpitClient {
254
247
  }
255
248
 
256
249
  private async handleRequest<T>(
257
- request: () => Promise<{ data: T }>,
258
- ): Promise<T> {
250
+ request: () => Promise<AxiosResponse<T>>,
251
+ options: { fullResponse: true },
252
+ ): Promise<AxiosResponse<T>>;
253
+ private async handleRequest<T>(
254
+ request: () => Promise<AxiosResponse<T>>,
255
+ options?: { fullResponse?: false },
256
+ ): Promise<T>;
257
+ private async handleRequest<T>(
258
+ request: () => Promise<AxiosResponse<T>>,
259
+ options: { fullResponse?: boolean } = { fullResponse: false },
260
+ ): Promise<T | AxiosResponse<T>> {
259
261
  try {
260
262
  const response = await request();
261
- return response.data;
262
- } catch (error) {
263
- if (axios.isAxiosError(error)) {
263
+ return options.fullResponse ? response : response.data;
264
+ } catch (error: unknown) {
265
+ if (isAxiosError(error)) {
266
+ const url = error.config?.url || "UNKNOWN URL";
267
+ const method = error.config?.method?.toUpperCase() || "UNKNOWN METHOD";
264
268
  if (error.response) {
265
269
  // Server responded with a status other than 2xx
266
270
  throw new Error(
267
- `Mailpit API Error: ${error.response.status} ${error.response.statusText}: ${JSON.stringify(error.response.data)}`,
271
+ `Mailpit API Error: ${error.response.status.toString()} ${error.response.statusText} at ${method} ${url}: ${JSON.stringify(error.response.data)}`,
268
272
  );
269
273
  } else if (error.request) {
270
274
  // Request was made but no response was received
271
275
  throw new Error(
272
- "Mailpit API Error: No response received from server.",
276
+ `Mailpit API Error: No response received from server at ${method} ${url}`,
273
277
  );
274
278
  } else {
275
279
  // Something happened in setting up the request
276
- throw new Error(`Mailpit API Error: ${error.message}`);
280
+ throw new Error(
281
+ `Mailpit API Error: ${(error as Error).toString()} at ${method} ${url}`,
282
+ );
277
283
  }
278
284
  } else {
279
- throw new Error("Unexpected Error: " + error);
285
+ throw new Error(`Unexpected Error: ${error as Error}`);
280
286
  }
281
287
  }
282
288
  }
283
289
 
284
- // Message
290
+ // Application
285
291
  public async getInfo(): Promise<MailpitInfoResponse> {
286
- return this.handleRequest(() =>
292
+ return await this.handleRequest(() =>
287
293
  this.axiosInstance.get<MailpitInfoResponse>("/api/v1/info"),
288
294
  );
289
295
  }
290
296
 
291
297
  public async getConfiguration(): Promise<MailpitConfigurationResponse> {
292
- return this.handleRequest(() =>
298
+ return await this.handleRequest(() =>
293
299
  this.axiosInstance.get<MailpitConfigurationResponse>("/api/v1/webui"),
294
300
  );
295
301
  }
296
302
 
303
+ // Message
297
304
  public async getMessageSummary(
298
305
  id: string = "latest",
299
306
  ): Promise<MailpitMessageSummaryResponse> {
300
- return this.handleRequest(() =>
307
+ return await this.handleRequest(() =>
301
308
  this.axiosInstance.get<MailpitMessageSummaryResponse>(
302
309
  `/api/v1/message/${id}`,
303
310
  ),
@@ -307,7 +314,7 @@ export class MailpitClient {
307
314
  public async getMessageHeaders(
308
315
  id: string = "latest",
309
316
  ): Promise<MailpitMessageHeadersResponse> {
310
- return this.handleRequest(() =>
317
+ return await this.handleRequest(() =>
311
318
  this.axiosInstance.get<MailpitMessageHeadersResponse>(
312
319
  `/api/v1/message/${id}/headers`,
313
320
  ),
@@ -317,14 +324,23 @@ export class MailpitClient {
317
324
  public async getMessageAttachment(
318
325
  id: string,
319
326
  partID: string,
320
- ): Promise<string> {
321
- return this.handleRequest(() =>
322
- this.axiosInstance.get<string>(`/api/v1/message/${id}/part/${partID}`),
327
+ ): Promise<AttachmentResponse> {
328
+ const response = await this.handleRequest(
329
+ () =>
330
+ this.axiosInstance.get<ArrayBuffer>(
331
+ `/api/v1/message/${id}/part/${partID}`,
332
+ { responseType: "arraybuffer" },
333
+ ),
334
+ { fullResponse: true },
323
335
  );
336
+ return {
337
+ data: response.data,
338
+ contentType: response.headers["content-type"] as string,
339
+ };
324
340
  }
325
341
 
326
342
  public async getMessageSource(id: string = "latest"): Promise<string> {
327
- return this.handleRequest(() =>
343
+ return await this.handleRequest(() =>
328
344
  this.axiosInstance.get<string>(`/api/v1/message/${id}/raw`),
329
345
  );
330
346
  }
@@ -332,19 +348,28 @@ export class MailpitClient {
332
348
  public async getAttachmentThumbnail(
333
349
  id: string,
334
350
  partID: string,
335
- ): Promise<string> {
336
- return this.handleRequest(() =>
337
- this.axiosInstance.get<string>(
338
- `/api/v1/message/${id}/part/${partID}/thumb`,
339
- ),
351
+ ): Promise<AttachmentResponse> {
352
+ const response = await this.handleRequest(
353
+ () =>
354
+ this.axiosInstance.get<ArrayBuffer>(
355
+ `/api/v1/message/${id}/part/${partID}/thumb`,
356
+ {
357
+ responseType: "arraybuffer",
358
+ },
359
+ ),
360
+ { fullResponse: true },
340
361
  );
362
+ return {
363
+ data: response.data,
364
+ contentType: response.headers["content-type"] as string,
365
+ };
341
366
  }
342
367
 
343
368
  public async releaseMessage(
344
369
  id: string,
345
370
  releaseRequest: { To: string[] },
346
371
  ): Promise<string> {
347
- return this.handleRequest(() =>
372
+ return await this.handleRequest(() =>
348
373
  this.axiosInstance.post<string>(
349
374
  `/api/v1/message/${id}/release`,
350
375
  releaseRequest,
@@ -355,7 +380,7 @@ export class MailpitClient {
355
380
  public async sendMessage(
356
381
  sendReqest: MailpitSendRequest,
357
382
  ): Promise<MailpitSendMessageConfirmationResponse> {
358
- return this.handleRequest(() =>
383
+ return await this.handleRequest(() =>
359
384
  this.axiosInstance.post<MailpitSendMessageConfirmationResponse>(
360
385
  `/api/v1/send`,
361
386
  sendReqest,
@@ -367,7 +392,7 @@ export class MailpitClient {
367
392
  public async htmlCheck(
368
393
  id: string = "latest",
369
394
  ): Promise<MailpitHTMLCheckResponse> {
370
- return this.handleRequest(() =>
395
+ return await this.handleRequest(() =>
371
396
  this.axiosInstance.get<MailpitHTMLCheckResponse>(
372
397
  `/api/v1/message/${id}/html-check`,
373
398
  ),
@@ -378,7 +403,7 @@ export class MailpitClient {
378
403
  id: string = "latest",
379
404
  follow: "true" | "false" = "false",
380
405
  ): Promise<MailpitLinkCheckResponse> {
381
- return this.handleRequest(() =>
406
+ return await this.handleRequest(() =>
382
407
  this.axiosInstance.get<MailpitLinkCheckResponse>(
383
408
  `/api/v1/message/${id}/link-check`,
384
409
  { params: { follow } },
@@ -389,7 +414,7 @@ export class MailpitClient {
389
414
  public async spamAssassinCheck(
390
415
  id: string = "latest",
391
416
  ): Promise<MailpitSpamAssassinResponse> {
392
- return this.handleRequest(() =>
417
+ return await this.handleRequest(() =>
393
418
  this.axiosInstance.get<MailpitSpamAssassinResponse>(
394
419
  `/api/v1/message/${id}/sa-check`,
395
420
  ),
@@ -401,7 +426,7 @@ export class MailpitClient {
401
426
  start: number = 0,
402
427
  limit: number = 50,
403
428
  ): Promise<MailpitMessagesSummaryResponse> {
404
- return this.handleRequest(() =>
429
+ return await this.handleRequest(() =>
405
430
  this.axiosInstance.get<MailpitMessagesSummaryResponse>(
406
431
  `/api/v1/messages`,
407
432
  { params: { start, limit } },
@@ -412,7 +437,7 @@ export class MailpitClient {
412
437
  public async setReadStatus(
413
438
  readStatus: MailpitReadStatusRequest,
414
439
  ): Promise<string> {
415
- return this.handleRequest(() =>
440
+ return await this.handleRequest(() =>
416
441
  this.axiosInstance.put<string>(`/api/v1/messages`, readStatus),
417
442
  );
418
443
  }
@@ -420,7 +445,7 @@ export class MailpitClient {
420
445
  public async deleteMessages(
421
446
  deleteRequest?: MailpitDeleteRequest,
422
447
  ): Promise<string> {
423
- return this.handleRequest(() =>
448
+ return await this.handleRequest(() =>
424
449
  this.axiosInstance.delete<string>(`/api/v1/messages`, {
425
450
  data: deleteRequest,
426
451
  }),
@@ -431,7 +456,7 @@ export class MailpitClient {
431
456
  public async searchMessages(
432
457
  search: MailpitSearchRequest,
433
458
  ): Promise<MailpitMessagesSummaryResponse> {
434
- return this.handleRequest(() =>
459
+ return await this.handleRequest(() =>
435
460
  this.axiosInstance.get<MailpitMessagesSummaryResponse>(`/api/v1/search`, {
436
461
  params: search,
437
462
  }),
@@ -442,27 +467,27 @@ export class MailpitClient {
442
467
  public async deleteMessagesBySearch(
443
468
  search: MailpitSearchDeleteRequest,
444
469
  ): Promise<string> {
445
- return this.handleRequest(() =>
470
+ return await this.handleRequest(() =>
446
471
  this.axiosInstance.delete<string>(`/api/v1/search`, { params: search }),
447
472
  );
448
473
  }
449
474
 
450
475
  // Tags
451
476
  public async getTags(): Promise<string[]> {
452
- return this.handleRequest(() =>
477
+ return await this.handleRequest(() =>
453
478
  this.axiosInstance.get<string[]>(`/api/v1/tags`),
454
479
  );
455
480
  }
456
481
 
457
482
  public async setTags(request: MailpitSetTagsRequest): Promise<string> {
458
- return this.handleRequest(() =>
483
+ return await this.handleRequest(() =>
459
484
  this.axiosInstance.put<string>(`/api/v1/tags`, request),
460
485
  );
461
486
  }
462
487
 
463
488
  public async renameTag(tag: string, newTagName: string): Promise<string> {
464
489
  const encodedTag = encodeURI(tag);
465
- return this.handleRequest(() =>
490
+ return await this.handleRequest(() =>
466
491
  this.axiosInstance.put<string>(`/api/v1/tags/${encodedTag}`, {
467
492
  Name: newTagName,
468
493
  }),
@@ -471,21 +496,38 @@ export class MailpitClient {
471
496
 
472
497
  public async deleteTag(tag: string): Promise<string> {
473
498
  const encodedTag = encodeURI(tag);
474
- return this.handleRequest(() =>
499
+ return await this.handleRequest(() =>
475
500
  this.axiosInstance.delete<string>(`/api/v1/tags/${encodedTag}`),
476
501
  );
477
502
  }
478
503
 
479
504
  // Testing
480
- public async renderMessageHTML(id: string = "latest"): Promise<string> {
481
- return this.handleRequest(() =>
482
- this.axiosInstance.get<string>(`/view/${id}.html`),
505
+ public async renderMessageHTML(
506
+ id: string = "latest",
507
+ embed?: 1,
508
+ ): Promise<string> {
509
+ return await this.handleRequest(() =>
510
+ this.axiosInstance.get<string>(`/view/${id}.html`, { params: { embed } }),
483
511
  );
484
512
  }
485
513
 
486
514
  public async renderMessageText(id: string = "latest"): Promise<string> {
487
- return this.handleRequest(() =>
515
+ return await this.handleRequest(() =>
488
516
  this.axiosInstance.get<string>(`/view/${id}.txt`),
489
517
  );
490
518
  }
519
+
520
+ public async getChaosTriggers(): Promise<ChaosTriggersResponse> {
521
+ return await this.handleRequest(() =>
522
+ this.axiosInstance.get<ChaosTriggersResponse>("/api/v1/chaos"),
523
+ );
524
+ }
525
+
526
+ public async setChaosTriggers(
527
+ triggers: ChaosTriggersRequest = {},
528
+ ): Promise<ChaosTriggersResponse> {
529
+ return await this.handleRequest(() =>
530
+ this.axiosInstance.put<ChaosTriggersResponse>("/api/v1/chaos", triggers),
531
+ );
532
+ }
491
533
  }
@@ -13,13 +13,13 @@
13
13
  "noFallthroughCasesInSwitch": true,
14
14
  "pretty": true,
15
15
  "resolveJsonModule": true,
16
- "rootDir": "src",
16
+ "rootDir": ".",
17
17
  "skipLibCheck": true,
18
18
  "strict": true,
19
19
  "traceResolution": false,
20
20
  "types": ["node", "jest"]
21
21
  },
22
22
  "compileOnSave": false,
23
- "exclude": ["node_modules", "dist"],
24
- "include": ["src"]
23
+ "include": ["src", "eslint.config.mjs", "test"],
24
+ "exclude": ["node_modules", "dist"]
25
25
  }