mailpit-api 1.0.5 → 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/index.js DELETED
@@ -1,184 +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
- // 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() {
65
- return __awaiter(this, arguments, void 0, function* (id = "latest") {
66
- return this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}`));
67
- });
68
- }
69
- getMessageHeaders() {
70
- return __awaiter(this, arguments, void 0, function* (id = "latest") {
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() {
80
- return __awaiter(this, arguments, void 0, function* (id = "latest") {
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() {
101
- return __awaiter(this, arguments, void 0, function* (id = "latest") {
102
- return this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/html-check`));
103
- });
104
- }
105
- linkCheck() {
106
- return __awaiter(this, arguments, void 0, function* (id = "latest", follow = "false") {
107
- return this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/link-check`, { params: { follow } }));
108
- });
109
- }
110
- spamAssassinCheck() {
111
- return __awaiter(this, arguments, void 0, function* (id = "latest") {
112
- return this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/sa-check`));
113
- });
114
- }
115
- // Messages
116
- listMessages() {
117
- return __awaiter(this, arguments, void 0, function* (start = 0, limit = 50) {
118
- return this.handleRequest(() => this.axiosInstance.get(`/api/v1/messages`, { params: { start, limit } }));
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.get(`/api/v1/search`, {
137
- params: search,
138
- }));
139
- });
140
- }
141
- // See https://mailpit.axllent.org/docs/usage/search-filters/
142
- deleteMessagesBySearch(search) {
143
- return __awaiter(this, void 0, void 0, function* () {
144
- return this.handleRequest(() => this.axiosInstance.delete(`/api/v1/search`, { params: search }));
145
- });
146
- }
147
- // Tags
148
- getTags() {
149
- return __awaiter(this, void 0, void 0, function* () {
150
- return this.handleRequest(() => this.axiosInstance.get(`/api/v1/tags`));
151
- });
152
- }
153
- setTags(request) {
154
- return __awaiter(this, void 0, void 0, function* () {
155
- return this.handleRequest(() => this.axiosInstance.put(`/api/v1/tags`, request));
156
- });
157
- }
158
- renameTag(tag, newTagName) {
159
- return __awaiter(this, void 0, void 0, function* () {
160
- const encodedTag = encodeURI(tag);
161
- return this.handleRequest(() => this.axiosInstance.put(`/api/v1/tags/${encodedTag}`, {
162
- Name: newTagName,
163
- }));
164
- });
165
- }
166
- deleteTag(tag) {
167
- return __awaiter(this, void 0, void 0, function* () {
168
- const encodedTag = encodeURI(tag);
169
- return this.handleRequest(() => this.axiosInstance.delete(`/api/v1/tags/${encodedTag}`));
170
- });
171
- }
172
- // Testing
173
- renderMessageHTML() {
174
- return __awaiter(this, arguments, void 0, function* (id = "latest") {
175
- return this.handleRequest(() => this.axiosInstance.get(`/view/${id}.html`));
176
- });
177
- }
178
- renderMessageText() {
179
- return __awaiter(this, arguments, void 0, function* (id = "latest") {
180
- return this.handleRequest(() => this.axiosInstance.get(`/view/${id}.txt`));
181
- });
182
- }
183
- }
184
- exports.MailpitClient = MailpitClient;
package/dist/mjs/index.js DELETED
@@ -1,121 +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
- // Message
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
- async getMessageSummary(id = "latest") {
45
- return this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}`));
46
- }
47
- async getMessageHeaders(id = "latest") {
48
- return this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/headers`));
49
- }
50
- async getMessageAttachment(id, partID) {
51
- return this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/part/${partID}`));
52
- }
53
- async getMessageSource(id = "latest") {
54
- return this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/raw`));
55
- }
56
- async getAttachmentThumbnail(id, partID) {
57
- return this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/part/${partID}/thumb`));
58
- }
59
- async releaseMessage(id, releaseRequest) {
60
- return this.handleRequest(() => this.axiosInstance.post(`/api/v1/message/${id}/release`, releaseRequest));
61
- }
62
- async sendMessage(sendReqest) {
63
- return this.handleRequest(() => this.axiosInstance.post(`/api/v1/send`, sendReqest));
64
- }
65
- // Other
66
- async htmlCheck(id = "latest") {
67
- return this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/html-check`));
68
- }
69
- async linkCheck(id = "latest", follow = "false") {
70
- return this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/link-check`, { params: { follow } }));
71
- }
72
- async spamAssassinCheck(id = "latest") {
73
- return this.handleRequest(() => this.axiosInstance.get(`/api/v1/message/${id}/sa-check`));
74
- }
75
- // Messages
76
- async listMessages(start = 0, limit = 50) {
77
- return this.handleRequest(() => this.axiosInstance.get(`/api/v1/messages`, { params: { start, limit } }));
78
- }
79
- async setReadStatus(readStatus) {
80
- return this.handleRequest(() => this.axiosInstance.put(`/api/v1/messages`, readStatus));
81
- }
82
- async deleteMessages(deleteRequest) {
83
- return this.handleRequest(() => this.axiosInstance.delete(`/api/v1/messages`, {
84
- data: deleteRequest,
85
- }));
86
- }
87
- // See https://mailpit.axllent.org/docs/usage/search-filters/
88
- async searchMessages(search) {
89
- return this.handleRequest(() => this.axiosInstance.get(`/api/v1/search`, {
90
- params: search,
91
- }));
92
- }
93
- // See https://mailpit.axllent.org/docs/usage/search-filters/
94
- async deleteMessagesBySearch(search) {
95
- return this.handleRequest(() => this.axiosInstance.delete(`/api/v1/search`, { params: search }));
96
- }
97
- // Tags
98
- async getTags() {
99
- return this.handleRequest(() => this.axiosInstance.get(`/api/v1/tags`));
100
- }
101
- async setTags(request) {
102
- return this.handleRequest(() => this.axiosInstance.put(`/api/v1/tags`, request));
103
- }
104
- async renameTag(tag, newTagName) {
105
- const encodedTag = encodeURI(tag);
106
- return this.handleRequest(() => this.axiosInstance.put(`/api/v1/tags/${encodedTag}`, {
107
- Name: newTagName,
108
- }));
109
- }
110
- async deleteTag(tag) {
111
- const encodedTag = encodeURI(tag);
112
- return this.handleRequest(() => this.axiosInstance.delete(`/api/v1/tags/${encodedTag}`));
113
- }
114
- // Testing
115
- async renderMessageHTML(id = "latest") {
116
- return this.handleRequest(() => this.axiosInstance.get(`/view/${id}.html`));
117
- }
118
- async renderMessageText(id = "latest") {
119
- return this.handleRequest(() => this.axiosInstance.get(`/view/${id}.txt`));
120
- }
121
- }