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.
@@ -13,13 +13,13 @@
13
13
  "noFallthroughCasesInSwitch": true,
14
14
  "pretty": true,
15
15
  "resolveJsonModule": true,
16
- "rootDir": ".",
16
+ "rootDir": "src",
17
17
  "skipLibCheck": true,
18
18
  "strict": true,
19
19
  "traceResolution": false,
20
20
  "types": ["node", "jest"]
21
21
  },
22
22
  "compileOnSave": false,
23
- "include": ["src", "eslint.config.mjs", "test"],
24
- "exclude": ["node_modules", "dist"]
23
+ "exclude": ["node_modules", "dist", "test", "docs"],
24
+ "include": ["src"]
25
25
  }
package/typedoc.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "plugin": ["typedoc-plugin-markdown", "typedoc-github-wiki-theme"],
3
+ "out": "./docs",
4
+ "indexFormat": "table",
5
+ "parametersFormat": "table",
6
+ "interfacePropertiesFormat": "table",
7
+ "classPropertiesFormat": "table",
8
+ "enumMembersFormat": "table",
9
+ "propertyMembersFormat": "table",
10
+ "typeDeclarationFormat": "table"
11
+ }
@@ -1,2 +0,0 @@
1
- declare const _default: import("@typescript-eslint/utils/dist/ts-eslint").FlatConfig.ConfigArray;
2
- export default _default;
@@ -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 {};
@@ -1,239 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
- return new (P || (P = Promise))(function (resolve, reject) {
38
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
- step((generator = generator.apply(thisArg, _arguments || [])).next());
42
- });
43
- };
44
- Object.defineProperty(exports, "__esModule", { value: true });
45
- exports.MailpitClient = void 0;
46
- const axios_1 = __importStar(require("axios"));
47
- class MailpitClient {
48
- constructor(baseURL, auth) {
49
- this.axiosInstance = axios_1.default.create({
50
- baseURL,
51
- auth,
52
- validateStatus: function (status) {
53
- return status === 200;
54
- },
55
- });
56
- }
57
- handleRequest(request_1) {
58
- return __awaiter(this, arguments, void 0, function* (request, options = { fullResponse: false }) {
59
- var _a, _b, _c;
60
- try {
61
- const response = yield request();
62
- return options.fullResponse ? response : response.data;
63
- }
64
- catch (error) {
65
- if ((0, axios_1.isAxiosError)(error)) {
66
- const url = ((_a = error.config) === null || _a === void 0 ? void 0 : _a.url) || "UNKNOWN URL";
67
- const method = ((_c = (_b = error.config) === null || _b === void 0 ? void 0 : _b.method) === null || _c === void 0 ? void 0 : _c.toUpperCase()) || "UNKNOWN METHOD";
68
- if (error.response) {
69
- // Server responded with a status other than 2xx
70
- throw new Error(`Mailpit API Error: ${error.response.status.toString()} ${error.response.statusText} at ${method} ${url}: ${JSON.stringify(error.response.data)}`);
71
- }
72
- else if (error.request) {
73
- // Request was made but no response was received
74
- throw new Error(`Mailpit API Error: No response received from server at ${method} ${url}`);
75
- }
76
- else {
77
- // Something happened in setting up the request
78
- throw new Error(`Mailpit API Error: ${error.toString()} at ${method} ${url}`);
79
- }
80
- }
81
- else {
82
- throw new Error(`Unexpected Error: ${error}`);
83
- }
84
- }
85
- });
86
- }
87
- // Application
88
- getInfo() {
89
- return __awaiter(this, void 0, void 0, function* () {
90
- return yield this.handleRequest(() => this.axiosInstance.get("/api/v1/info"));
91
- });
92
- }
93
- getConfiguration() {
94
- return __awaiter(this, void 0, void 0, function* () {
95
- return yield this.handleRequest(() => this.axiosInstance.get("/api/v1/webui"));
96
- });
97
- }
98
- // Message
99
- getMessageSummary() {
100
- return __awaiter(this, arguments, void 0, function* (id = "latest") {
101
- return yield this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}`));
102
- });
103
- }
104
- getMessageHeaders() {
105
- return __awaiter(this, arguments, void 0, function* (id = "latest") {
106
- return yield this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/headers`));
107
- });
108
- }
109
- getMessageAttachment(id, partID) {
110
- return __awaiter(this, void 0, void 0, function* () {
111
- const response = yield this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/part/${partID}`, { responseType: "arraybuffer" }), { fullResponse: true });
112
- return {
113
- data: response.data,
114
- contentType: response.headers["content-type"],
115
- };
116
- });
117
- }
118
- getMessageSource() {
119
- return __awaiter(this, arguments, void 0, function* (id = "latest") {
120
- return yield this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/raw`));
121
- });
122
- }
123
- getAttachmentThumbnail(id, partID) {
124
- return __awaiter(this, void 0, void 0, function* () {
125
- const response = yield this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/part/${partID}/thumb`, {
126
- responseType: "arraybuffer",
127
- }), { fullResponse: true });
128
- return {
129
- data: response.data,
130
- contentType: response.headers["content-type"],
131
- };
132
- });
133
- }
134
- releaseMessage(id, releaseRequest) {
135
- return __awaiter(this, void 0, void 0, function* () {
136
- return yield this.handleRequest(() => this.axiosInstance.post(`/api/v1/message/${id}/release`, releaseRequest));
137
- });
138
- }
139
- sendMessage(sendReqest) {
140
- return __awaiter(this, void 0, void 0, function* () {
141
- return yield this.handleRequest(() => this.axiosInstance.post(`/api/v1/send`, sendReqest));
142
- });
143
- }
144
- // Other
145
- htmlCheck() {
146
- return __awaiter(this, arguments, void 0, function* (id = "latest") {
147
- return yield this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/html-check`));
148
- });
149
- }
150
- linkCheck() {
151
- return __awaiter(this, arguments, void 0, function* (id = "latest", follow = "false") {
152
- return yield this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/link-check`, { params: { follow } }));
153
- });
154
- }
155
- spamAssassinCheck() {
156
- return __awaiter(this, arguments, void 0, function* (id = "latest") {
157
- return yield this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/sa-check`));
158
- });
159
- }
160
- // Messages
161
- listMessages() {
162
- return __awaiter(this, arguments, void 0, function* (start = 0, limit = 50) {
163
- return yield this.handleRequest(() => this.axiosInstance.get(`/api/v1/messages`, { params: { start, limit } }));
164
- });
165
- }
166
- setReadStatus(readStatus) {
167
- return __awaiter(this, void 0, void 0, function* () {
168
- return yield this.handleRequest(() => this.axiosInstance.put(`/api/v1/messages`, readStatus));
169
- });
170
- }
171
- deleteMessages(deleteRequest) {
172
- return __awaiter(this, void 0, void 0, function* () {
173
- return yield this.handleRequest(() => this.axiosInstance.delete(`/api/v1/messages`, {
174
- data: deleteRequest,
175
- }));
176
- });
177
- }
178
- // See https://mailpit.axllent.org/docs/usage/search-filters/
179
- searchMessages(search) {
180
- return __awaiter(this, void 0, void 0, function* () {
181
- return yield this.handleRequest(() => this.axiosInstance.get(`/api/v1/search`, {
182
- params: search,
183
- }));
184
- });
185
- }
186
- // See https://mailpit.axllent.org/docs/usage/search-filters/
187
- deleteMessagesBySearch(search) {
188
- return __awaiter(this, void 0, void 0, function* () {
189
- return yield this.handleRequest(() => this.axiosInstance.delete(`/api/v1/search`, { params: search }));
190
- });
191
- }
192
- // Tags
193
- getTags() {
194
- return __awaiter(this, void 0, void 0, function* () {
195
- return yield this.handleRequest(() => this.axiosInstance.get(`/api/v1/tags`));
196
- });
197
- }
198
- setTags(request) {
199
- return __awaiter(this, void 0, void 0, function* () {
200
- return yield this.handleRequest(() => this.axiosInstance.put(`/api/v1/tags`, request));
201
- });
202
- }
203
- renameTag(tag, newTagName) {
204
- return __awaiter(this, void 0, void 0, function* () {
205
- const encodedTag = encodeURI(tag);
206
- return yield this.handleRequest(() => this.axiosInstance.put(`/api/v1/tags/${encodedTag}`, {
207
- Name: newTagName,
208
- }));
209
- });
210
- }
211
- deleteTag(tag) {
212
- return __awaiter(this, void 0, void 0, function* () {
213
- const encodedTag = encodeURI(tag);
214
- return yield this.handleRequest(() => this.axiosInstance.delete(`/api/v1/tags/${encodedTag}`));
215
- });
216
- }
217
- // Testing
218
- renderMessageHTML() {
219
- return __awaiter(this, arguments, void 0, function* (id = "latest", embed) {
220
- return yield this.handleRequest(() => this.axiosInstance.get(`/view/${id}.html`, { params: { embed } }));
221
- });
222
- }
223
- renderMessageText() {
224
- return __awaiter(this, arguments, void 0, function* (id = "latest") {
225
- return yield this.handleRequest(() => this.axiosInstance.get(`/view/${id}.txt`));
226
- });
227
- }
228
- getChaosTriggers() {
229
- return __awaiter(this, void 0, void 0, function* () {
230
- return yield this.handleRequest(() => this.axiosInstance.get("/api/v1/chaos"));
231
- });
232
- }
233
- setChaosTriggers() {
234
- return __awaiter(this, arguments, void 0, function* (triggers = {}) {
235
- return yield this.handleRequest(() => this.axiosInstance.put("/api/v1/chaos", triggers));
236
- });
237
- }
238
- }
239
- exports.MailpitClient = MailpitClient;
@@ -1,2 +0,0 @@
1
- declare const _default: import("@typescript-eslint/utils/dist/ts-eslint").FlatConfig.ConfigArray;
2
- export default _default;