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.
- package/dist/cjs/eslint.config.d.mts +2 -0
- package/dist/cjs/{index.d.ts → src/index.d.ts} +53 -98
- package/dist/cjs/src/index.js +239 -0
- package/dist/mjs/eslint.config.d.mts +2 -0
- package/dist/mjs/{index.d.ts → src/index.d.ts} +53 -98
- package/dist/mjs/src/index.js +141 -0
- package/package.json +7 -8
- package/src/index.ts +136 -139
- package/tsconfig-base.json +3 -3
- package/dist/cjs/index.js +0 -195
- package/dist/mjs/index.js +0 -128
package/tsconfig-base.json
CHANGED
|
@@ -13,13 +13,13 @@
|
|
|
13
13
|
"noFallthroughCasesInSwitch": true,
|
|
14
14
|
"pretty": true,
|
|
15
15
|
"resolveJsonModule": true,
|
|
16
|
-
"rootDir": "
|
|
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
|
-
"
|
|
24
|
-
"
|
|
23
|
+
"include": ["src", "eslint.config.mjs", "test"],
|
|
24
|
+
"exclude": ["node_modules", "dist"]
|
|
25
25
|
}
|
package/dist/cjs/index.js
DELETED
|
@@ -1,195 +0,0 @@
|
|
|
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
|
-
// Application
|
|
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
|
-
// Message
|
|
65
|
-
getMessageSummary() {
|
|
66
|
-
return __awaiter(this, arguments, void 0, function* (id = "latest") {
|
|
67
|
-
return this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}`));
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
getMessageHeaders() {
|
|
71
|
-
return __awaiter(this, arguments, void 0, function* (id = "latest") {
|
|
72
|
-
return this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/headers`));
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
getMessageAttachment(id, partID) {
|
|
76
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
-
return this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/part/${partID}`));
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
getMessageSource() {
|
|
81
|
-
return __awaiter(this, arguments, void 0, function* (id = "latest") {
|
|
82
|
-
return this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/raw`));
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
getAttachmentThumbnail(id, partID) {
|
|
86
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
-
return this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/part/${partID}/thumb`));
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
releaseMessage(id, releaseRequest) {
|
|
91
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
-
return this.handleRequest(() => this.axiosInstance.post(`/api/v1/message/${id}/release`, releaseRequest));
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
sendMessage(sendReqest) {
|
|
96
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
-
return this.handleRequest(() => this.axiosInstance.post(`/api/v1/send`, sendReqest));
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
// Other
|
|
101
|
-
htmlCheck() {
|
|
102
|
-
return __awaiter(this, arguments, void 0, function* (id = "latest") {
|
|
103
|
-
return this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/html-check`));
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
linkCheck() {
|
|
107
|
-
return __awaiter(this, arguments, void 0, function* (id = "latest", follow = "false") {
|
|
108
|
-
return this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/link-check`, { params: { follow } }));
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
spamAssassinCheck() {
|
|
112
|
-
return __awaiter(this, arguments, void 0, function* (id = "latest") {
|
|
113
|
-
return this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/sa-check`));
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
// Messages
|
|
117
|
-
listMessages() {
|
|
118
|
-
return __awaiter(this, arguments, void 0, function* (start = 0, limit = 50) {
|
|
119
|
-
return this.handleRequest(() => this.axiosInstance.get(`/api/v1/messages`, { params: { start, limit } }));
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
setReadStatus(readStatus) {
|
|
123
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
124
|
-
return this.handleRequest(() => this.axiosInstance.put(`/api/v1/messages`, readStatus));
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
deleteMessages(deleteRequest) {
|
|
128
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
129
|
-
return this.handleRequest(() => this.axiosInstance.delete(`/api/v1/messages`, {
|
|
130
|
-
data: deleteRequest,
|
|
131
|
-
}));
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
// See https://mailpit.axllent.org/docs/usage/search-filters/
|
|
135
|
-
searchMessages(search) {
|
|
136
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
137
|
-
return this.handleRequest(() => this.axiosInstance.get(`/api/v1/search`, {
|
|
138
|
-
params: search,
|
|
139
|
-
}));
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
// See https://mailpit.axllent.org/docs/usage/search-filters/
|
|
143
|
-
deleteMessagesBySearch(search) {
|
|
144
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
145
|
-
return this.handleRequest(() => this.axiosInstance.delete(`/api/v1/search`, { params: search }));
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
// Tags
|
|
149
|
-
getTags() {
|
|
150
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
151
|
-
return this.handleRequest(() => this.axiosInstance.get(`/api/v1/tags`));
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
setTags(request) {
|
|
155
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
156
|
-
return this.handleRequest(() => this.axiosInstance.put(`/api/v1/tags`, request));
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
renameTag(tag, newTagName) {
|
|
160
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
161
|
-
const encodedTag = encodeURI(tag);
|
|
162
|
-
return this.handleRequest(() => this.axiosInstance.put(`/api/v1/tags/${encodedTag}`, {
|
|
163
|
-
Name: newTagName,
|
|
164
|
-
}));
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
deleteTag(tag) {
|
|
168
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
169
|
-
const encodedTag = encodeURI(tag);
|
|
170
|
-
return this.handleRequest(() => this.axiosInstance.delete(`/api/v1/tags/${encodedTag}`));
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
// Testing
|
|
174
|
-
renderMessageHTML() {
|
|
175
|
-
return __awaiter(this, arguments, void 0, function* (id = "latest") {
|
|
176
|
-
return this.handleRequest(() => this.axiosInstance.get(`/view/${id}.html`));
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
renderMessageText() {
|
|
180
|
-
return __awaiter(this, arguments, void 0, function* (id = "latest") {
|
|
181
|
-
return this.handleRequest(() => this.axiosInstance.get(`/view/${id}.txt`));
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
getChaosTriggers() {
|
|
185
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
186
|
-
return this.handleRequest(() => this.axiosInstance.get("/api/v1/chaos"));
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
setChaosTriggers() {
|
|
190
|
-
return __awaiter(this, arguments, void 0, function* (triggers = {}) {
|
|
191
|
-
return this.handleRequest(() => this.axiosInstance.put("/api/v1/chaos", triggers));
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
exports.MailpitClient = MailpitClient;
|
package/dist/mjs/index.js
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
|
-
export class MailpitClient {
|
|
3
|
-
axiosInstance;
|
|
4
|
-
constructor(baseURL) {
|
|
5
|
-
this.axiosInstance = axios.create({
|
|
6
|
-
baseURL: baseURL,
|
|
7
|
-
validateStatus: function (status) {
|
|
8
|
-
return status === 200;
|
|
9
|
-
},
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
async handleRequest(request) {
|
|
13
|
-
try {
|
|
14
|
-
const response = await request();
|
|
15
|
-
return response.data;
|
|
16
|
-
}
|
|
17
|
-
catch (error) {
|
|
18
|
-
if (axios.isAxiosError(error)) {
|
|
19
|
-
if (error.response) {
|
|
20
|
-
// Server responded with a status other than 2xx
|
|
21
|
-
throw new Error(`Mailpit API Error: ${error.response.status} ${error.response.statusText}: ${JSON.stringify(error.response.data)}`);
|
|
22
|
-
}
|
|
23
|
-
else if (error.request) {
|
|
24
|
-
// Request was made but no response was received
|
|
25
|
-
throw new Error("Mailpit API Error: No response received from server.");
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
// Something happened in setting up the request
|
|
29
|
-
throw new Error(`Mailpit API Error: ${error.message}`);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
throw new Error("Unexpected Error: " + error);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
// Application
|
|
38
|
-
async getInfo() {
|
|
39
|
-
return this.handleRequest(() => this.axiosInstance.get("/api/v1/info"));
|
|
40
|
-
}
|
|
41
|
-
async getConfiguration() {
|
|
42
|
-
return this.handleRequest(() => this.axiosInstance.get("/api/v1/webui"));
|
|
43
|
-
}
|
|
44
|
-
// Message
|
|
45
|
-
async getMessageSummary(id = "latest") {
|
|
46
|
-
return this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}`));
|
|
47
|
-
}
|
|
48
|
-
async getMessageHeaders(id = "latest") {
|
|
49
|
-
return this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/headers`));
|
|
50
|
-
}
|
|
51
|
-
async getMessageAttachment(id, partID) {
|
|
52
|
-
return this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/part/${partID}`));
|
|
53
|
-
}
|
|
54
|
-
async getMessageSource(id = "latest") {
|
|
55
|
-
return this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/raw`));
|
|
56
|
-
}
|
|
57
|
-
async getAttachmentThumbnail(id, partID) {
|
|
58
|
-
return this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/part/${partID}/thumb`));
|
|
59
|
-
}
|
|
60
|
-
async releaseMessage(id, releaseRequest) {
|
|
61
|
-
return this.handleRequest(() => this.axiosInstance.post(`/api/v1/message/${id}/release`, releaseRequest));
|
|
62
|
-
}
|
|
63
|
-
async sendMessage(sendReqest) {
|
|
64
|
-
return this.handleRequest(() => this.axiosInstance.post(`/api/v1/send`, sendReqest));
|
|
65
|
-
}
|
|
66
|
-
// Other
|
|
67
|
-
async htmlCheck(id = "latest") {
|
|
68
|
-
return this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/html-check`));
|
|
69
|
-
}
|
|
70
|
-
async linkCheck(id = "latest", follow = "false") {
|
|
71
|
-
return this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/link-check`, { params: { follow } }));
|
|
72
|
-
}
|
|
73
|
-
async spamAssassinCheck(id = "latest") {
|
|
74
|
-
return this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/sa-check`));
|
|
75
|
-
}
|
|
76
|
-
// Messages
|
|
77
|
-
async listMessages(start = 0, limit = 50) {
|
|
78
|
-
return this.handleRequest(() => this.axiosInstance.get(`/api/v1/messages`, { params: { start, limit } }));
|
|
79
|
-
}
|
|
80
|
-
async setReadStatus(readStatus) {
|
|
81
|
-
return this.handleRequest(() => this.axiosInstance.put(`/api/v1/messages`, readStatus));
|
|
82
|
-
}
|
|
83
|
-
async deleteMessages(deleteRequest) {
|
|
84
|
-
return this.handleRequest(() => this.axiosInstance.delete(`/api/v1/messages`, {
|
|
85
|
-
data: deleteRequest,
|
|
86
|
-
}));
|
|
87
|
-
}
|
|
88
|
-
// See https://mailpit.axllent.org/docs/usage/search-filters/
|
|
89
|
-
async searchMessages(search) {
|
|
90
|
-
return this.handleRequest(() => this.axiosInstance.get(`/api/v1/search`, {
|
|
91
|
-
params: search,
|
|
92
|
-
}));
|
|
93
|
-
}
|
|
94
|
-
// See https://mailpit.axllent.org/docs/usage/search-filters/
|
|
95
|
-
async deleteMessagesBySearch(search) {
|
|
96
|
-
return this.handleRequest(() => this.axiosInstance.delete(`/api/v1/search`, { params: search }));
|
|
97
|
-
}
|
|
98
|
-
// Tags
|
|
99
|
-
async getTags() {
|
|
100
|
-
return this.handleRequest(() => this.axiosInstance.get(`/api/v1/tags`));
|
|
101
|
-
}
|
|
102
|
-
async setTags(request) {
|
|
103
|
-
return this.handleRequest(() => this.axiosInstance.put(`/api/v1/tags`, request));
|
|
104
|
-
}
|
|
105
|
-
async renameTag(tag, newTagName) {
|
|
106
|
-
const encodedTag = encodeURI(tag);
|
|
107
|
-
return this.handleRequest(() => this.axiosInstance.put(`/api/v1/tags/${encodedTag}`, {
|
|
108
|
-
Name: newTagName,
|
|
109
|
-
}));
|
|
110
|
-
}
|
|
111
|
-
async deleteTag(tag) {
|
|
112
|
-
const encodedTag = encodeURI(tag);
|
|
113
|
-
return this.handleRequest(() => this.axiosInstance.delete(`/api/v1/tags/${encodedTag}`));
|
|
114
|
-
}
|
|
115
|
-
// Testing
|
|
116
|
-
async renderMessageHTML(id = "latest") {
|
|
117
|
-
return this.handleRequest(() => this.axiosInstance.get(`/view/${id}.html`));
|
|
118
|
-
}
|
|
119
|
-
async renderMessageText(id = "latest") {
|
|
120
|
-
return this.handleRequest(() => this.axiosInstance.get(`/view/${id}.txt`));
|
|
121
|
-
}
|
|
122
|
-
async getChaosTriggers() {
|
|
123
|
-
return this.handleRequest(() => this.axiosInstance.get("/api/v1/chaos"));
|
|
124
|
-
}
|
|
125
|
-
async setChaosTriggers(triggers = {}) {
|
|
126
|
-
return this.handleRequest(() => this.axiosInstance.put("/api/v1/chaos", triggers));
|
|
127
|
-
}
|
|
128
|
-
}
|