mailpit-api 1.0.2-beta.2 → 1.0.2-beta.3

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.
@@ -248,4 +248,3 @@ export declare class MailpitClient {
248
248
  renderMessageHTML(id: string): Promise<string>;
249
249
  renderMessageText(id: string): Promise<string>;
250
250
  }
251
- export default MailpitClient;
@@ -0,0 +1,182 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.MailpitClient = void 0;
16
+ const axios_1 = __importDefault(require("axios"));
17
+ class MailpitClient {
18
+ constructor(baseURL) {
19
+ this.axiosInstance = axios_1.default.create({
20
+ baseURL: baseURL,
21
+ validateStatus: function (status) {
22
+ return status === 200;
23
+ },
24
+ });
25
+ }
26
+ handleRequest(request) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ try {
29
+ const response = yield request();
30
+ return response.data;
31
+ }
32
+ catch (error) {
33
+ if (axios_1.default.isAxiosError(error)) {
34
+ if (error.response) {
35
+ // Server responded with a status other than 2xx
36
+ throw new Error(`Mailpit API Error: ${error.response.status} ${error.response.statusText}: ${JSON.stringify(error.response.data)}`);
37
+ }
38
+ else if (error.request) {
39
+ // Request was made but no response was received
40
+ throw new Error("Mailpit API Error: No response received from server.");
41
+ }
42
+ else {
43
+ // Something happened in setting up the request
44
+ throw new Error(`Mailpit API Error: ${error.message}`);
45
+ }
46
+ }
47
+ else {
48
+ throw new Error("Unexpected Error: " + error);
49
+ }
50
+ }
51
+ });
52
+ }
53
+ // Message
54
+ getInfo() {
55
+ return __awaiter(this, void 0, void 0, function* () {
56
+ return this.handleRequest(() => this.axiosInstance.get("/api/v1/info"));
57
+ });
58
+ }
59
+ getConfiguration() {
60
+ return __awaiter(this, void 0, void 0, function* () {
61
+ return this.handleRequest(() => this.axiosInstance.get("/api/v1/webui"));
62
+ });
63
+ }
64
+ getMessageSummary(id) {
65
+ return __awaiter(this, void 0, void 0, function* () {
66
+ return this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}`));
67
+ });
68
+ }
69
+ getMessageHeaders(id) {
70
+ return __awaiter(this, void 0, void 0, function* () {
71
+ return this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/headers`));
72
+ });
73
+ }
74
+ getMessageAttachment(id, partID) {
75
+ return __awaiter(this, void 0, void 0, function* () {
76
+ return this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/part/${partID}`));
77
+ });
78
+ }
79
+ getMessageSource(id) {
80
+ return __awaiter(this, void 0, void 0, function* () {
81
+ return this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/raw`));
82
+ });
83
+ }
84
+ getAttachmentThumbnail(id, partID) {
85
+ return __awaiter(this, void 0, void 0, function* () {
86
+ return this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/part/${partID}/thumb`));
87
+ });
88
+ }
89
+ releaseMessage(id, releaseRequest) {
90
+ return __awaiter(this, void 0, void 0, function* () {
91
+ return this.handleRequest(() => this.axiosInstance.post(`/api/v1/message/${id}/release`, releaseRequest));
92
+ });
93
+ }
94
+ sendMessage(sendReqest) {
95
+ return __awaiter(this, void 0, void 0, function* () {
96
+ return this.handleRequest(() => this.axiosInstance.post(`/api/v1/send`, sendReqest));
97
+ });
98
+ }
99
+ // Other
100
+ htmlCheck(id) {
101
+ return __awaiter(this, void 0, void 0, function* () {
102
+ return this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/html-check`));
103
+ });
104
+ }
105
+ linkCheck(id) {
106
+ return __awaiter(this, void 0, void 0, function* () {
107
+ return this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/link-check`));
108
+ });
109
+ }
110
+ spamAssassinCheck(id) {
111
+ return __awaiter(this, void 0, void 0, function* () {
112
+ return this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/sa-check`));
113
+ });
114
+ }
115
+ // Messages
116
+ listMessages() {
117
+ return __awaiter(this, void 0, void 0, function* () {
118
+ return this.handleRequest(() => this.axiosInstance.get(`/api/v1/messages`));
119
+ });
120
+ }
121
+ setReadStatus(readStatus) {
122
+ return __awaiter(this, void 0, void 0, function* () {
123
+ return this.handleRequest(() => this.axiosInstance.put(`/api/v1/messages`, readStatus));
124
+ });
125
+ }
126
+ deleteMessages(deleteRequest) {
127
+ return __awaiter(this, void 0, void 0, function* () {
128
+ return this.handleRequest(() => this.axiosInstance.delete(`/api/v1/messages`, {
129
+ data: deleteRequest,
130
+ }));
131
+ });
132
+ }
133
+ // See https://mailpit.axllent.org/docs/usage/search-filters/
134
+ searchMessages(search) {
135
+ return __awaiter(this, void 0, void 0, function* () {
136
+ return this.handleRequest(() => this.axiosInstance.put(`/api/v1/search`, search));
137
+ });
138
+ }
139
+ // See https://mailpit.axllent.org/docs/usage/search-filters/
140
+ deleteMessagesBySearch(search) {
141
+ return __awaiter(this, void 0, void 0, function* () {
142
+ return this.handleRequest(() => this.axiosInstance.delete(`/api/v1/search`, { data: search }));
143
+ });
144
+ }
145
+ // Tags
146
+ getTags() {
147
+ return __awaiter(this, void 0, void 0, function* () {
148
+ return this.handleRequest(() => this.axiosInstance.get(`/api/v1/tags`));
149
+ });
150
+ }
151
+ setTags(request) {
152
+ return __awaiter(this, void 0, void 0, function* () {
153
+ return this.handleRequest(() => this.axiosInstance.put(`/api/v1/tags`, request));
154
+ });
155
+ }
156
+ renameTag(tag, newTagName) {
157
+ return __awaiter(this, void 0, void 0, function* () {
158
+ const encodedTag = encodeURI(tag);
159
+ return this.handleRequest(() => this.axiosInstance.put(`/api/v1/tags/${encodedTag}`, {
160
+ Name: newTagName,
161
+ }));
162
+ });
163
+ }
164
+ deleteTag(tag) {
165
+ return __awaiter(this, void 0, void 0, function* () {
166
+ const encodedTag = encodeURI(tag);
167
+ return this.handleRequest(() => this.axiosInstance.delete(`/api/v1/tags/${encodedTag}`));
168
+ });
169
+ }
170
+ // Testing
171
+ renderMessageHTML(id) {
172
+ return __awaiter(this, void 0, void 0, function* () {
173
+ return this.handleRequest(() => this.axiosInstance.get(`/view/${id}.html`));
174
+ });
175
+ }
176
+ renderMessageText(id) {
177
+ return __awaiter(this, void 0, void 0, function* () {
178
+ return this.handleRequest(() => this.axiosInstance.get(`/view/${id}.txt`));
179
+ });
180
+ }
181
+ }
182
+ exports.MailpitClient = MailpitClient;
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,250 @@
1
+ export interface MailpitInfo {
2
+ Database: string;
3
+ DatabaseSize: number;
4
+ LatestVersion: string;
5
+ Messages: number;
6
+ RuntimeStats: {
7
+ Memory: number;
8
+ MessagesDeleted: number;
9
+ SMTPAccepted: number;
10
+ SMTPAcceptedSize: number;
11
+ SMTPIgnored: number;
12
+ SMTPRejected: number;
13
+ Uptime: number;
14
+ };
15
+ Tags: {
16
+ [key: string]: number;
17
+ };
18
+ Unread: number;
19
+ Version: string;
20
+ }
21
+ export interface MailpitConfiguration {
22
+ DuplicatesIgnored: boolean;
23
+ Label: string;
24
+ SpamAssassin: boolean;
25
+ MessageRelay: {
26
+ AllowedRecipients: string;
27
+ Enabled: boolean;
28
+ ReturnPath: string;
29
+ SMTPServer: string;
30
+ };
31
+ }
32
+ export interface MailpitMessageSummary {
33
+ Attachments: [
34
+ {
35
+ ContentID: string;
36
+ ContentType: string;
37
+ FileName: string;
38
+ PartID: string;
39
+ Size: number;
40
+ }
41
+ ];
42
+ Bcc: [
43
+ {
44
+ Address: string;
45
+ Name: string;
46
+ }
47
+ ];
48
+ Cc: [
49
+ {
50
+ Address: string;
51
+ Name: string;
52
+ }
53
+ ];
54
+ Date: string;
55
+ From: {
56
+ Address: string;
57
+ Name: string;
58
+ };
59
+ HTML: string;
60
+ ID: string;
61
+ Inline: [
62
+ {
63
+ ContentID: string;
64
+ ContentType: string;
65
+ FileName: string;
66
+ PartID: string;
67
+ Size: number;
68
+ }
69
+ ];
70
+ MessageID: string;
71
+ ReplyTo: [
72
+ {
73
+ Address: string;
74
+ Name: string;
75
+ }
76
+ ];
77
+ ReturnPath: string;
78
+ Size: number;
79
+ Subject: string;
80
+ Tags: [string];
81
+ Text: string;
82
+ To: [
83
+ {
84
+ Address: string;
85
+ Name: string;
86
+ }
87
+ ];
88
+ }
89
+ export interface MailpitMessagesSummary {
90
+ messages: [MailpitMessageSummary];
91
+ }
92
+ export interface MailpitMessageHeaders {
93
+ [key: string]: string;
94
+ }
95
+ export interface MailpitSendRequest {
96
+ Attachments: [
97
+ {
98
+ Content: string;
99
+ Filename: string;
100
+ }
101
+ ];
102
+ Bcc: [string];
103
+ Cc: [
104
+ {
105
+ Email: string;
106
+ Name: string;
107
+ }
108
+ ];
109
+ From: {
110
+ Email: string;
111
+ Name: string;
112
+ };
113
+ HTML: string;
114
+ Headers: {
115
+ [key: string]: string;
116
+ };
117
+ ReplyTo: [
118
+ {
119
+ Email: string;
120
+ Name: string;
121
+ }
122
+ ];
123
+ Subject: string;
124
+ Tags: [string];
125
+ Text: string;
126
+ To: [
127
+ {
128
+ Email: string;
129
+ Name: string;
130
+ }
131
+ ];
132
+ }
133
+ export interface MailpitSendMessageConfirmation {
134
+ ID: string;
135
+ }
136
+ export interface MailpitHTMLCheckResponse {
137
+ Platforms: {
138
+ [key: string]: [string];
139
+ };
140
+ Total: {
141
+ Nodes: number;
142
+ Partial: number;
143
+ Supported: number;
144
+ Tests: number;
145
+ Unsupported: number;
146
+ };
147
+ Warnings: [
148
+ {
149
+ Category: "css" | "html";
150
+ Description: string;
151
+ Keywords: string;
152
+ NotesByNumber: {
153
+ [key: string]: string;
154
+ };
155
+ Results: [
156
+ {
157
+ Family: string;
158
+ Name: string;
159
+ NoteNumber: string;
160
+ Platform: string;
161
+ Support: "yes" | "no" | "partial";
162
+ Version: string;
163
+ }
164
+ ];
165
+ Score: {
166
+ Found: number;
167
+ Partial: number;
168
+ Supported: number;
169
+ Unsupported: number;
170
+ };
171
+ Slug: string;
172
+ Tags: [string];
173
+ Title: string;
174
+ URL: string;
175
+ }
176
+ ];
177
+ }
178
+ export interface MailpitLinkCheckResponse {
179
+ Errors: number;
180
+ Links: [
181
+ {
182
+ Status: string;
183
+ StatusCode: number;
184
+ URL: string;
185
+ }
186
+ ];
187
+ }
188
+ export interface MailpitSpamAssassinResponse {
189
+ Errors: number;
190
+ IsSpam: boolean;
191
+ Rules: [
192
+ {
193
+ Description: string;
194
+ Name: string;
195
+ Score: number;
196
+ }
197
+ ];
198
+ Score: number;
199
+ }
200
+ export interface MailpitReadStatusRequest {
201
+ IDs: [string];
202
+ Read: boolean;
203
+ }
204
+ export interface MailpitDeleteRequest {
205
+ IDs: [string];
206
+ }
207
+ export interface MailpitSearch {
208
+ query: string;
209
+ start: number;
210
+ limit: number;
211
+ tz: string;
212
+ }
213
+ export interface MailpitSearchDelete {
214
+ query: string;
215
+ tz: string;
216
+ }
217
+ export interface MailpitSetTagsRequest {
218
+ IDs: [string];
219
+ Tags: [string];
220
+ }
221
+ export declare class MailpitClient {
222
+ private axiosInstance;
223
+ constructor(baseURL: string);
224
+ private handleRequest;
225
+ getInfo(): Promise<MailpitInfo>;
226
+ getConfiguration(): Promise<MailpitConfiguration>;
227
+ getMessageSummary(id: string): Promise<MailpitMessageSummary>;
228
+ getMessageHeaders(id: string): Promise<MailpitMessageHeaders>;
229
+ getMessageAttachment(id: string, partID: string): Promise<string>;
230
+ getMessageSource(id: string): Promise<string>;
231
+ getAttachmentThumbnail(id: string, partID: string): Promise<string>;
232
+ releaseMessage(id: string, releaseRequest: {
233
+ To: string[];
234
+ }): Promise<string>;
235
+ sendMessage(sendReqest: MailpitSendRequest): Promise<MailpitSendMessageConfirmation>;
236
+ htmlCheck(id: string): Promise<MailpitHTMLCheckResponse>;
237
+ linkCheck(id: string): Promise<MailpitLinkCheckResponse>;
238
+ spamAssassinCheck(id: string): Promise<MailpitSpamAssassinResponse>;
239
+ listMessages(): Promise<MailpitMessagesSummary>;
240
+ setReadStatus(readStatus: MailpitReadStatusRequest): Promise<string>;
241
+ deleteMessages(deleteRequest: MailpitDeleteRequest): Promise<string>;
242
+ searchMessages(search: MailpitSearch): Promise<MailpitMessagesSummary>;
243
+ deleteMessagesBySearch(search: MailpitSearchDelete): Promise<string>;
244
+ getTags(): Promise<[string]>;
245
+ setTags(request: MailpitSetTagsRequest): Promise<string>;
246
+ renameTag(tag: string, newTagName: string): Promise<string>;
247
+ deleteTag(tag: string): Promise<string>;
248
+ renderMessageHTML(id: string): Promise<string>;
249
+ renderMessageText(id: string): Promise<string>;
250
+ }
@@ -117,5 +117,3 @@ export class MailpitClient {
117
117
  return this.handleRequest(() => this.axiosInstance.get(`/view/${id}.txt`));
118
118
  }
119
119
  }
120
- export default MailpitClient;
121
- //# sourceMappingURL=MailpitClient.js.map
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
package/package.json CHANGED
@@ -1,16 +1,22 @@
1
1
  {
2
2
  "name": "mailpit-api",
3
- "version": "1.0.2-beta.2",
3
+ "version": "1.0.2-beta.3",
4
4
  "description": "A NodeJS client library, written in TypeScript, to interact with the Mailpit API.",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/mpspahr/mailpit-api.git"
8
8
  },
9
- "main": "dist/index.js",
10
- "types": "dist/index.d.ts",
9
+ "main": "dist/cjs/index.js",
10
+ "module": "dist/mjs/index.js",
11
+ "exports": {
12
+ ".": {
13
+ "import": "./dist/mjs/index.js",
14
+ "require": "./dist/cjs/index.js"
15
+ }
16
+ },
11
17
  "scripts": {
12
18
  "test": "echo \"TODO: Add tests\" && exit 0",
13
- "build": "tsc"
19
+ "build": "rm -fr dist/* && tsc -p tsconfig.json && tsc -p tsconfig-cjs.json && ./fixup_type"
14
20
  },
15
21
  "keywords": [
16
22
  "mailpit-api",
@@ -29,14 +35,16 @@
29
35
  "axios": "^1.7.2"
30
36
  },
31
37
  "devDependencies": {
32
- "@typescript-eslint/eslint-plugin": "^7.18.0",
33
- "@typescript-eslint/parser": "^7.18.0",
34
- "typescript-eslint": "^7.18.0",
35
38
  "@eslint/js": "^8.57.0",
36
39
  "@types/node": "^20.14.10",
40
+ "@typescript-eslint/eslint-plugin": "^7.18.0",
41
+ "@typescript-eslint/parser": "^7.18.0",
37
42
  "eslint": "^8.57.0",
38
43
  "globals": "^15.8.0",
44
+ "jest": "^29.7.0",
39
45
  "prettier": "3.3.3",
40
- "tsx": "^4.16.2"
46
+ "tsx": "^4.16.2",
47
+ "typescript": "^5.5.4",
48
+ "typescript-eslint": "^7.18.0"
41
49
  }
42
50
  }