mailpit-api 1.1.0 → 1.2.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/README.md +2 -0
- package/dist/cjs/index.d.ts +744 -0
- package/dist/cjs/index.js +550 -0
- package/dist/mjs/index.d.ts +744 -0
- package/dist/mjs/index.js +452 -0
- package/package.json +13 -9
- package/src/index.ts +632 -135
- package/tsconfig-base.json +3 -3
- package/typedoc.json +11 -0
- package/dist/cjs/eslint.config.d.mts +0 -2
- package/dist/cjs/src/index.d.ts +0 -241
- package/dist/cjs/src/index.js +0 -239
- package/dist/mjs/eslint.config.d.mts +0 -2
- package/dist/mjs/src/index.d.ts +0 -241
- package/dist/mjs/src/index.js +0 -141
package/dist/mjs/src/index.d.ts
DELETED
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
interface Address {
|
|
2
|
-
Address: string;
|
|
3
|
-
Name: string;
|
|
4
|
-
}
|
|
5
|
-
interface Email {
|
|
6
|
-
Email: string;
|
|
7
|
-
Name: string;
|
|
8
|
-
}
|
|
9
|
-
interface Attachment {
|
|
10
|
-
ContentID: string;
|
|
11
|
-
ContentType: string;
|
|
12
|
-
FileName: string;
|
|
13
|
-
PartID: string;
|
|
14
|
-
Size: number;
|
|
15
|
-
}
|
|
16
|
-
interface ChaosTrigger {
|
|
17
|
-
ErrorCode: number;
|
|
18
|
-
Probability: number;
|
|
19
|
-
}
|
|
20
|
-
export interface MailpitInfoResponse {
|
|
21
|
-
Database: string;
|
|
22
|
-
DatabaseSize: number;
|
|
23
|
-
LatestVersion: string;
|
|
24
|
-
Messages: number;
|
|
25
|
-
RuntimeStats: {
|
|
26
|
-
Memory: number;
|
|
27
|
-
MessagesDeleted: number;
|
|
28
|
-
SMTPAccepted: number;
|
|
29
|
-
SMTPAcceptedSize: number;
|
|
30
|
-
SMTPIgnored: number;
|
|
31
|
-
SMTPRejected: number;
|
|
32
|
-
Uptime: number;
|
|
33
|
-
};
|
|
34
|
-
Tags: {
|
|
35
|
-
[key: string]: number;
|
|
36
|
-
};
|
|
37
|
-
Unread: number;
|
|
38
|
-
Version: string;
|
|
39
|
-
}
|
|
40
|
-
export interface MailpitConfigurationResponse {
|
|
41
|
-
DuplicatesIgnored: boolean;
|
|
42
|
-
Label: string;
|
|
43
|
-
SpamAssassin: boolean;
|
|
44
|
-
MessageRelay: {
|
|
45
|
-
AllowedRecipients: string;
|
|
46
|
-
Enabled: boolean;
|
|
47
|
-
ReturnPath: string;
|
|
48
|
-
SMTPServer: string;
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
export interface MailpitMessageSummaryResponse {
|
|
52
|
-
Attachments: Attachment[];
|
|
53
|
-
Bcc: Address[];
|
|
54
|
-
Cc: Address[];
|
|
55
|
-
Date: string;
|
|
56
|
-
From: Address;
|
|
57
|
-
HTML: string;
|
|
58
|
-
ID: string;
|
|
59
|
-
Inline: Attachment[];
|
|
60
|
-
MessageID: string;
|
|
61
|
-
ReplyTo: Address[];
|
|
62
|
-
ReturnPath: string;
|
|
63
|
-
Size: number;
|
|
64
|
-
Subject: string;
|
|
65
|
-
Tags: string[];
|
|
66
|
-
Text: string;
|
|
67
|
-
To: Address[];
|
|
68
|
-
}
|
|
69
|
-
export interface MailpitMessagesSummaryResponse {
|
|
70
|
-
messages: {
|
|
71
|
-
Attachments: number;
|
|
72
|
-
Size: number;
|
|
73
|
-
Snippet: string;
|
|
74
|
-
Subject: string;
|
|
75
|
-
Tags: string[];
|
|
76
|
-
ID: string;
|
|
77
|
-
MessageID: string;
|
|
78
|
-
Read: boolean;
|
|
79
|
-
Bcc: Address[];
|
|
80
|
-
Cc: Address[];
|
|
81
|
-
From: Address;
|
|
82
|
-
ReplyTo: Address[];
|
|
83
|
-
To: Address[];
|
|
84
|
-
}[];
|
|
85
|
-
messages_count: number;
|
|
86
|
-
start: number;
|
|
87
|
-
tags: string[];
|
|
88
|
-
total: number;
|
|
89
|
-
unread: number;
|
|
90
|
-
}
|
|
91
|
-
export interface MailpitMessageHeadersResponse {
|
|
92
|
-
[key: string]: string;
|
|
93
|
-
}
|
|
94
|
-
export interface MailpitSendRequest {
|
|
95
|
-
Attachments: {
|
|
96
|
-
Content: string;
|
|
97
|
-
Filename: string;
|
|
98
|
-
}[];
|
|
99
|
-
Bcc: string[];
|
|
100
|
-
Cc: Email[];
|
|
101
|
-
From: Email;
|
|
102
|
-
HTML: string;
|
|
103
|
-
Headers: {
|
|
104
|
-
[key: string]: string;
|
|
105
|
-
};
|
|
106
|
-
ReplyTo: Email[];
|
|
107
|
-
Subject: string;
|
|
108
|
-
Tags: string[];
|
|
109
|
-
Text: string;
|
|
110
|
-
To: Email[];
|
|
111
|
-
}
|
|
112
|
-
export interface MailpitSendMessageConfirmationResponse {
|
|
113
|
-
ID: string;
|
|
114
|
-
}
|
|
115
|
-
export interface MailpitHTMLCheckResponse {
|
|
116
|
-
Platforms: {
|
|
117
|
-
[key: string]: [string];
|
|
118
|
-
};
|
|
119
|
-
Total: {
|
|
120
|
-
Nodes: number;
|
|
121
|
-
Partial: number;
|
|
122
|
-
Supported: number;
|
|
123
|
-
Tests: number;
|
|
124
|
-
Unsupported: number;
|
|
125
|
-
};
|
|
126
|
-
Warnings: {
|
|
127
|
-
Category: "css" | "html";
|
|
128
|
-
Description: string;
|
|
129
|
-
Keywords: string;
|
|
130
|
-
NotesByNumber: {
|
|
131
|
-
[key: string]: string;
|
|
132
|
-
};
|
|
133
|
-
Results: {
|
|
134
|
-
Family: string;
|
|
135
|
-
Name: string;
|
|
136
|
-
NoteNumber: string;
|
|
137
|
-
Platform: string;
|
|
138
|
-
Support: "yes" | "no" | "partial";
|
|
139
|
-
Version: string;
|
|
140
|
-
}[];
|
|
141
|
-
Score: {
|
|
142
|
-
Found: number;
|
|
143
|
-
Partial: number;
|
|
144
|
-
Supported: number;
|
|
145
|
-
Unsupported: number;
|
|
146
|
-
};
|
|
147
|
-
Slug: string;
|
|
148
|
-
Tags: string[];
|
|
149
|
-
Title: string;
|
|
150
|
-
URL: string;
|
|
151
|
-
}[];
|
|
152
|
-
}
|
|
153
|
-
export interface MailpitLinkCheckResponse {
|
|
154
|
-
Errors: number;
|
|
155
|
-
Links: {
|
|
156
|
-
Status: string;
|
|
157
|
-
StatusCode: number;
|
|
158
|
-
URL: string;
|
|
159
|
-
}[];
|
|
160
|
-
}
|
|
161
|
-
export interface MailpitSpamAssassinResponse {
|
|
162
|
-
Errors: number;
|
|
163
|
-
IsSpam: boolean;
|
|
164
|
-
Rules: {
|
|
165
|
-
Description: string;
|
|
166
|
-
Name: string;
|
|
167
|
-
Score: number;
|
|
168
|
-
}[];
|
|
169
|
-
Score: number;
|
|
170
|
-
}
|
|
171
|
-
export interface MailpitReadStatusRequest {
|
|
172
|
-
IDs: string[];
|
|
173
|
-
Read: boolean;
|
|
174
|
-
}
|
|
175
|
-
export interface MailpitDeleteRequest {
|
|
176
|
-
IDs: string[];
|
|
177
|
-
}
|
|
178
|
-
export interface MailpitSearchRequest {
|
|
179
|
-
query: string;
|
|
180
|
-
start?: number;
|
|
181
|
-
limit?: number;
|
|
182
|
-
tz?: string;
|
|
183
|
-
}
|
|
184
|
-
export interface MailpitSearchDeleteRequest {
|
|
185
|
-
query: string;
|
|
186
|
-
tz?: string;
|
|
187
|
-
}
|
|
188
|
-
export interface MailpitSetTagsRequest {
|
|
189
|
-
IDs: string[];
|
|
190
|
-
Tags: string[];
|
|
191
|
-
}
|
|
192
|
-
export interface ChaosTriggersRequest {
|
|
193
|
-
Authentication?: ChaosTrigger;
|
|
194
|
-
Recipient?: ChaosTrigger;
|
|
195
|
-
Sender?: ChaosTrigger;
|
|
196
|
-
}
|
|
197
|
-
export interface ChaosTriggersResponse {
|
|
198
|
-
Authentication: ChaosTrigger;
|
|
199
|
-
Recipient?: ChaosTrigger;
|
|
200
|
-
Sender?: ChaosTrigger;
|
|
201
|
-
}
|
|
202
|
-
interface AttachmentResponse {
|
|
203
|
-
data: ArrayBuffer;
|
|
204
|
-
contentType: string;
|
|
205
|
-
}
|
|
206
|
-
export declare class MailpitClient {
|
|
207
|
-
private axiosInstance;
|
|
208
|
-
constructor(baseURL: string, auth?: {
|
|
209
|
-
username: string;
|
|
210
|
-
password: string;
|
|
211
|
-
});
|
|
212
|
-
private handleRequest;
|
|
213
|
-
getInfo(): Promise<MailpitInfoResponse>;
|
|
214
|
-
getConfiguration(): Promise<MailpitConfigurationResponse>;
|
|
215
|
-
getMessageSummary(id?: string): Promise<MailpitMessageSummaryResponse>;
|
|
216
|
-
getMessageHeaders(id?: string): Promise<MailpitMessageHeadersResponse>;
|
|
217
|
-
getMessageAttachment(id: string, partID: string): Promise<AttachmentResponse>;
|
|
218
|
-
getMessageSource(id?: string): Promise<string>;
|
|
219
|
-
getAttachmentThumbnail(id: string, partID: string): Promise<AttachmentResponse>;
|
|
220
|
-
releaseMessage(id: string, releaseRequest: {
|
|
221
|
-
To: string[];
|
|
222
|
-
}): Promise<string>;
|
|
223
|
-
sendMessage(sendReqest: MailpitSendRequest): Promise<MailpitSendMessageConfirmationResponse>;
|
|
224
|
-
htmlCheck(id?: string): Promise<MailpitHTMLCheckResponse>;
|
|
225
|
-
linkCheck(id?: string, follow?: "true" | "false"): Promise<MailpitLinkCheckResponse>;
|
|
226
|
-
spamAssassinCheck(id?: string): Promise<MailpitSpamAssassinResponse>;
|
|
227
|
-
listMessages(start?: number, limit?: number): Promise<MailpitMessagesSummaryResponse>;
|
|
228
|
-
setReadStatus(readStatus: MailpitReadStatusRequest): Promise<string>;
|
|
229
|
-
deleteMessages(deleteRequest?: MailpitDeleteRequest): Promise<string>;
|
|
230
|
-
searchMessages(search: MailpitSearchRequest): Promise<MailpitMessagesSummaryResponse>;
|
|
231
|
-
deleteMessagesBySearch(search: MailpitSearchDeleteRequest): Promise<string>;
|
|
232
|
-
getTags(): Promise<string[]>;
|
|
233
|
-
setTags(request: MailpitSetTagsRequest): Promise<string>;
|
|
234
|
-
renameTag(tag: string, newTagName: string): Promise<string>;
|
|
235
|
-
deleteTag(tag: string): Promise<string>;
|
|
236
|
-
renderMessageHTML(id?: string, embed?: 1): Promise<string>;
|
|
237
|
-
renderMessageText(id?: string): Promise<string>;
|
|
238
|
-
getChaosTriggers(): Promise<ChaosTriggersResponse>;
|
|
239
|
-
setChaosTriggers(triggers?: ChaosTriggersRequest): Promise<ChaosTriggersResponse>;
|
|
240
|
-
}
|
|
241
|
-
export {};
|
package/dist/mjs/src/index.js
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
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
|
-
}
|