mailpit-api 1.0.6 → 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.6",
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",
@@ -36,16 +37,14 @@
36
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.14.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
47
  "typescript": "^5.7.3",
49
- "typescript-eslint": "^7.18.0"
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
+ }
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
+ }
2
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 {
@@ -242,41 +217,29 @@ export interface MailpitSetTagsRequest {
242
217
  }
243
218
 
244
219
  export interface ChaosTriggersRequest {
245
- Authentication?: {
246
- ErrorCode: number;
247
- Probability: number;
248
- };
249
- Recipient?: {
250
- ErrorCode: number;
251
- Probability: number;
252
- };
253
- Sender?: {
254
- ErrorCode: number;
255
- Probability: number;
256
- };
220
+ Authentication?: ChaosTrigger;
221
+ Recipient?: ChaosTrigger;
222
+ Sender?: ChaosTrigger;
257
223
  }
258
224
 
259
225
  export interface ChaosTriggersResponse {
260
- Authentication: {
261
- ErrorCode: number;
262
- Probability: number;
263
- };
264
- Recipient?: {
265
- ErrorCode: number;
266
- Probability: number;
267
- };
268
- Sender?: {
269
- ErrorCode: number;
270
- Probability: number;
271
- };
226
+ Authentication: ChaosTrigger;
227
+ Recipient?: ChaosTrigger;
228
+ Sender?: ChaosTrigger;
229
+ }
230
+
231
+ interface AttachmentResponse {
232
+ data: ArrayBuffer;
233
+ contentType: string;
272
234
  }
273
235
 
274
236
  export class MailpitClient {
275
237
  private axiosInstance: AxiosInstance;
276
238
 
277
- constructor(baseURL: string) {
239
+ constructor(baseURL: string, auth?: { username: string; password: string }) {
278
240
  this.axiosInstance = axios.create({
279
- baseURL: baseURL,
241
+ baseURL,
242
+ auth,
280
243
  validateStatus: function (status) {
281
244
  return status === 200;
282
245
  },
@@ -284,42 +247,55 @@ export class MailpitClient {
284
247
  }
285
248
 
286
249
  private async handleRequest<T>(
287
- request: () => Promise<{ data: T }>,
288
- ): 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>> {
289
261
  try {
290
262
  const response = await request();
291
- return response.data;
292
- } catch (error) {
293
- 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";
294
268
  if (error.response) {
295
269
  // Server responded with a status other than 2xx
296
270
  throw new Error(
297
- `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)}`,
298
272
  );
299
273
  } else if (error.request) {
300
274
  // Request was made but no response was received
301
275
  throw new Error(
302
- "Mailpit API Error: No response received from server.",
276
+ `Mailpit API Error: No response received from server at ${method} ${url}`,
303
277
  );
304
278
  } else {
305
279
  // Something happened in setting up the request
306
- throw new Error(`Mailpit API Error: ${error.message}`);
280
+ throw new Error(
281
+ `Mailpit API Error: ${(error as Error).toString()} at ${method} ${url}`,
282
+ );
307
283
  }
308
284
  } else {
309
- throw new Error("Unexpected Error: " + error);
285
+ throw new Error(`Unexpected Error: ${error as Error}`);
310
286
  }
311
287
  }
312
288
  }
313
289
 
314
290
  // Application
315
291
  public async getInfo(): Promise<MailpitInfoResponse> {
316
- return this.handleRequest(() =>
292
+ return await this.handleRequest(() =>
317
293
  this.axiosInstance.get<MailpitInfoResponse>("/api/v1/info"),
318
294
  );
319
295
  }
320
296
 
321
297
  public async getConfiguration(): Promise<MailpitConfigurationResponse> {
322
- return this.handleRequest(() =>
298
+ return await this.handleRequest(() =>
323
299
  this.axiosInstance.get<MailpitConfigurationResponse>("/api/v1/webui"),
324
300
  );
325
301
  }
@@ -328,7 +304,7 @@ export class MailpitClient {
328
304
  public async getMessageSummary(
329
305
  id: string = "latest",
330
306
  ): Promise<MailpitMessageSummaryResponse> {
331
- return this.handleRequest(() =>
307
+ return await this.handleRequest(() =>
332
308
  this.axiosInstance.get<MailpitMessageSummaryResponse>(
333
309
  `/api/v1/message/${id}`,
334
310
  ),
@@ -338,7 +314,7 @@ export class MailpitClient {
338
314
  public async getMessageHeaders(
339
315
  id: string = "latest",
340
316
  ): Promise<MailpitMessageHeadersResponse> {
341
- return this.handleRequest(() =>
317
+ return await this.handleRequest(() =>
342
318
  this.axiosInstance.get<MailpitMessageHeadersResponse>(
343
319
  `/api/v1/message/${id}/headers`,
344
320
  ),
@@ -348,14 +324,23 @@ export class MailpitClient {
348
324
  public async getMessageAttachment(
349
325
  id: string,
350
326
  partID: string,
351
- ): Promise<string> {
352
- return this.handleRequest(() =>
353
- 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 },
354
335
  );
336
+ return {
337
+ data: response.data,
338
+ contentType: response.headers["content-type"] as string,
339
+ };
355
340
  }
356
341
 
357
342
  public async getMessageSource(id: string = "latest"): Promise<string> {
358
- return this.handleRequest(() =>
343
+ return await this.handleRequest(() =>
359
344
  this.axiosInstance.get<string>(`/api/v1/message/${id}/raw`),
360
345
  );
361
346
  }
@@ -363,19 +348,28 @@ export class MailpitClient {
363
348
  public async getAttachmentThumbnail(
364
349
  id: string,
365
350
  partID: string,
366
- ): Promise<string> {
367
- return this.handleRequest(() =>
368
- this.axiosInstance.get<string>(
369
- `/api/v1/message/${id}/part/${partID}/thumb`,
370
- ),
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 },
371
361
  );
362
+ return {
363
+ data: response.data,
364
+ contentType: response.headers["content-type"] as string,
365
+ };
372
366
  }
373
367
 
374
368
  public async releaseMessage(
375
369
  id: string,
376
370
  releaseRequest: { To: string[] },
377
371
  ): Promise<string> {
378
- return this.handleRequest(() =>
372
+ return await this.handleRequest(() =>
379
373
  this.axiosInstance.post<string>(
380
374
  `/api/v1/message/${id}/release`,
381
375
  releaseRequest,
@@ -386,7 +380,7 @@ export class MailpitClient {
386
380
  public async sendMessage(
387
381
  sendReqest: MailpitSendRequest,
388
382
  ): Promise<MailpitSendMessageConfirmationResponse> {
389
- return this.handleRequest(() =>
383
+ return await this.handleRequest(() =>
390
384
  this.axiosInstance.post<MailpitSendMessageConfirmationResponse>(
391
385
  `/api/v1/send`,
392
386
  sendReqest,
@@ -398,7 +392,7 @@ export class MailpitClient {
398
392
  public async htmlCheck(
399
393
  id: string = "latest",
400
394
  ): Promise<MailpitHTMLCheckResponse> {
401
- return this.handleRequest(() =>
395
+ return await this.handleRequest(() =>
402
396
  this.axiosInstance.get<MailpitHTMLCheckResponse>(
403
397
  `/api/v1/message/${id}/html-check`,
404
398
  ),
@@ -409,7 +403,7 @@ export class MailpitClient {
409
403
  id: string = "latest",
410
404
  follow: "true" | "false" = "false",
411
405
  ): Promise<MailpitLinkCheckResponse> {
412
- return this.handleRequest(() =>
406
+ return await this.handleRequest(() =>
413
407
  this.axiosInstance.get<MailpitLinkCheckResponse>(
414
408
  `/api/v1/message/${id}/link-check`,
415
409
  { params: { follow } },
@@ -420,7 +414,7 @@ export class MailpitClient {
420
414
  public async spamAssassinCheck(
421
415
  id: string = "latest",
422
416
  ): Promise<MailpitSpamAssassinResponse> {
423
- return this.handleRequest(() =>
417
+ return await this.handleRequest(() =>
424
418
  this.axiosInstance.get<MailpitSpamAssassinResponse>(
425
419
  `/api/v1/message/${id}/sa-check`,
426
420
  ),
@@ -432,7 +426,7 @@ export class MailpitClient {
432
426
  start: number = 0,
433
427
  limit: number = 50,
434
428
  ): Promise<MailpitMessagesSummaryResponse> {
435
- return this.handleRequest(() =>
429
+ return await this.handleRequest(() =>
436
430
  this.axiosInstance.get<MailpitMessagesSummaryResponse>(
437
431
  `/api/v1/messages`,
438
432
  { params: { start, limit } },
@@ -443,7 +437,7 @@ export class MailpitClient {
443
437
  public async setReadStatus(
444
438
  readStatus: MailpitReadStatusRequest,
445
439
  ): Promise<string> {
446
- return this.handleRequest(() =>
440
+ return await this.handleRequest(() =>
447
441
  this.axiosInstance.put<string>(`/api/v1/messages`, readStatus),
448
442
  );
449
443
  }
@@ -451,7 +445,7 @@ export class MailpitClient {
451
445
  public async deleteMessages(
452
446
  deleteRequest?: MailpitDeleteRequest,
453
447
  ): Promise<string> {
454
- return this.handleRequest(() =>
448
+ return await this.handleRequest(() =>
455
449
  this.axiosInstance.delete<string>(`/api/v1/messages`, {
456
450
  data: deleteRequest,
457
451
  }),
@@ -462,7 +456,7 @@ export class MailpitClient {
462
456
  public async searchMessages(
463
457
  search: MailpitSearchRequest,
464
458
  ): Promise<MailpitMessagesSummaryResponse> {
465
- return this.handleRequest(() =>
459
+ return await this.handleRequest(() =>
466
460
  this.axiosInstance.get<MailpitMessagesSummaryResponse>(`/api/v1/search`, {
467
461
  params: search,
468
462
  }),
@@ -473,27 +467,27 @@ export class MailpitClient {
473
467
  public async deleteMessagesBySearch(
474
468
  search: MailpitSearchDeleteRequest,
475
469
  ): Promise<string> {
476
- return this.handleRequest(() =>
470
+ return await this.handleRequest(() =>
477
471
  this.axiosInstance.delete<string>(`/api/v1/search`, { params: search }),
478
472
  );
479
473
  }
480
474
 
481
475
  // Tags
482
476
  public async getTags(): Promise<string[]> {
483
- return this.handleRequest(() =>
477
+ return await this.handleRequest(() =>
484
478
  this.axiosInstance.get<string[]>(`/api/v1/tags`),
485
479
  );
486
480
  }
487
481
 
488
482
  public async setTags(request: MailpitSetTagsRequest): Promise<string> {
489
- return this.handleRequest(() =>
483
+ return await this.handleRequest(() =>
490
484
  this.axiosInstance.put<string>(`/api/v1/tags`, request),
491
485
  );
492
486
  }
493
487
 
494
488
  public async renameTag(tag: string, newTagName: string): Promise<string> {
495
489
  const encodedTag = encodeURI(tag);
496
- return this.handleRequest(() =>
490
+ return await this.handleRequest(() =>
497
491
  this.axiosInstance.put<string>(`/api/v1/tags/${encodedTag}`, {
498
492
  Name: newTagName,
499
493
  }),
@@ -502,26 +496,29 @@ export class MailpitClient {
502
496
 
503
497
  public async deleteTag(tag: string): Promise<string> {
504
498
  const encodedTag = encodeURI(tag);
505
- return this.handleRequest(() =>
499
+ return await this.handleRequest(() =>
506
500
  this.axiosInstance.delete<string>(`/api/v1/tags/${encodedTag}`),
507
501
  );
508
502
  }
509
503
 
510
504
  // Testing
511
- public async renderMessageHTML(id: string = "latest"): Promise<string> {
512
- return this.handleRequest(() =>
513
- 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 } }),
514
511
  );
515
512
  }
516
513
 
517
514
  public async renderMessageText(id: string = "latest"): Promise<string> {
518
- return this.handleRequest(() =>
515
+ return await this.handleRequest(() =>
519
516
  this.axiosInstance.get<string>(`/view/${id}.txt`),
520
517
  );
521
518
  }
522
519
 
523
520
  public async getChaosTriggers(): Promise<ChaosTriggersResponse> {
524
- return this.handleRequest(() =>
521
+ return await this.handleRequest(() =>
525
522
  this.axiosInstance.get<ChaosTriggersResponse>("/api/v1/chaos"),
526
523
  );
527
524
  }
@@ -529,7 +526,7 @@ export class MailpitClient {
529
526
  public async setChaosTriggers(
530
527
  triggers: ChaosTriggersRequest = {},
531
528
  ): Promise<ChaosTriggersResponse> {
532
- return this.handleRequest(() =>
529
+ return await this.handleRequest(() =>
533
530
  this.axiosInstance.put<ChaosTriggersResponse>("/api/v1/chaos", triggers),
534
531
  );
535
532
  }