ts-mailcow-api 1.2.0 → 1.3.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/LICENSE +661 -661
- package/README.md +118 -47
- package/dist/client.d.ts +3 -3
- package/dist/client.js +144 -126
- package/dist/client.js.map +1 -1
- package/dist/endpoints/address-rewriting-endpoint.d.ts +6 -2
- package/dist/endpoints/address-rewriting-endpoint.js.map +1 -1
- package/dist/endpoints/mailbox-endpoint.d.ts +2 -2
- package/dist/endpoints/mailbox-endpoint.js +2 -2
- package/dist/endpoints/mailbox-endpoint.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -1
- package/dist/request-factory.d.ts +7 -0
- package/dist/request-factory.js +23 -43
- package/dist/request-factory.js.map +1 -1
- package/dist/types.d.ts +9 -5
- package/dist/types.js +4 -0
- package/dist/types.js.map +1 -1
- package/package.json +57 -58
package/dist/request-factory.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.wrapPromiseToArray = wrapPromiseToArray;
|
|
13
4
|
const axios_1 = require("axios");
|
|
@@ -40,7 +31,6 @@ function isErrorType(type) {
|
|
|
40
31
|
* Throws a MailcowException if a definite error is detected.
|
|
41
32
|
*/
|
|
42
33
|
function checkMailcowResponse(res) {
|
|
43
|
-
// Accepts either a single object or an array
|
|
44
34
|
const arr = Array.isArray(res) ? res : [res];
|
|
45
35
|
for (const item of arr) {
|
|
46
36
|
if (isErrorType(item.type)) {
|
|
@@ -53,54 +43,44 @@ function checkMailcowResponse(res) {
|
|
|
53
43
|
* @internal
|
|
54
44
|
*/
|
|
55
45
|
class RequestFactory {
|
|
46
|
+
ctx;
|
|
56
47
|
constructor(ctx) {
|
|
57
48
|
this.ctx = ctx;
|
|
58
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Executes a request and applies Mailcow-specific error handling: a 2XX
|
|
52
|
+
* response with `type: 'danger'` or `type: 'error'` is converted into a
|
|
53
|
+
* MailcowException, and an axios error whose response body looks like a
|
|
54
|
+
* Mailcow error is unwrapped into a MailcowException as well.
|
|
55
|
+
*/
|
|
56
|
+
async request(send) {
|
|
57
|
+
try {
|
|
58
|
+
const res = await send();
|
|
59
|
+
checkMailcowResponse(res.data);
|
|
60
|
+
return res.data;
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
if (axios_1.default.isAxiosError(e) && e.response?.data) {
|
|
64
|
+
checkMailcowResponse(e.response.data);
|
|
65
|
+
throw new types_1.MailcowException('Unknown Mailcow error');
|
|
66
|
+
}
|
|
67
|
+
throw e;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
59
70
|
/**
|
|
60
71
|
* POST Request Factory
|
|
61
72
|
* @param route - The route to which to send the request.
|
|
62
73
|
* @param payload - The payload to send with the request.
|
|
63
74
|
*/
|
|
64
75
|
post(route, payload) {
|
|
65
|
-
return
|
|
66
|
-
var _a;
|
|
67
|
-
try {
|
|
68
|
-
const res = yield axios_1.default.post(this.ctx.BASE_URL + route, payload, this.ctx.AXIOS_CONFIG);
|
|
69
|
-
// Only throws if response has danger or error type
|
|
70
|
-
checkMailcowResponse(res.data);
|
|
71
|
-
return res.data;
|
|
72
|
-
}
|
|
73
|
-
catch (e) {
|
|
74
|
-
if (axios_1.default.isAxiosError(e) && ((_a = e.response) === null || _a === void 0 ? void 0 : _a.data)) {
|
|
75
|
-
// Check if the response *itself* is an error type
|
|
76
|
-
checkMailcowResponse(e.response.data);
|
|
77
|
-
// If no definite error, throw generic
|
|
78
|
-
throw new types_1.MailcowException('Unknown Mailcow error');
|
|
79
|
-
}
|
|
80
|
-
throw e;
|
|
81
|
-
}
|
|
82
|
-
});
|
|
76
|
+
return this.request(() => axios_1.default.post(this.ctx.BASE_URL + route, payload, this.ctx.AXIOS_CONFIG));
|
|
83
77
|
}
|
|
84
78
|
/**
|
|
85
79
|
* GET Request Factory
|
|
86
80
|
* @param route - The route to which to send the request.
|
|
87
81
|
*/
|
|
88
82
|
get(route) {
|
|
89
|
-
return
|
|
90
|
-
var _a;
|
|
91
|
-
try {
|
|
92
|
-
const res = yield axios_1.default.get(this.ctx.BASE_URL + route, this.ctx.AXIOS_CONFIG);
|
|
93
|
-
checkMailcowResponse(res.data);
|
|
94
|
-
return res.data;
|
|
95
|
-
}
|
|
96
|
-
catch (e) {
|
|
97
|
-
if (axios_1.default.isAxiosError(e) && ((_a = e.response) === null || _a === void 0 ? void 0 : _a.data)) {
|
|
98
|
-
checkMailcowResponse(e.response.data);
|
|
99
|
-
throw new types_1.MailcowException('Unknown Mailcow error');
|
|
100
|
-
}
|
|
101
|
-
throw e;
|
|
102
|
-
}
|
|
103
|
-
});
|
|
83
|
+
return this.request(() => axios_1.default.get(this.ctx.BASE_URL + route, this.ctx.AXIOS_CONFIG));
|
|
104
84
|
}
|
|
105
85
|
}
|
|
106
86
|
exports.default = RequestFactory;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-factory.js","sourceRoot":"","sources":["../src/request-factory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"request-factory.js","sourceRoot":"","sources":["../src/request-factory.ts"],"names":[],"mappings":";;AAkBA,gDAMC;AAxBD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{
|
|
|
219
219
|
*/
|
|
220
220
|
relay_all_recipients_int: boolean;
|
|
221
221
|
/**
|
|
222
|
-
* If the domain should only relay unknown
|
|
222
|
+
* If the domain should only relay unknown addresses.
|
|
223
223
|
*/
|
|
224
224
|
relay_unknown_only: boolean;
|
|
225
225
|
/**
|
|
@@ -318,7 +318,7 @@ export interface BaseMailboxAttributes {
|
|
|
318
318
|
/**
|
|
319
319
|
* The authentication source for this mailbox.
|
|
320
320
|
*/
|
|
321
|
-
authsource: 'mailcow' | 'ldap' | '
|
|
321
|
+
authsource: 'mailcow' | 'ldap' | 'keycloak' | 'generic-oidc';
|
|
322
322
|
}
|
|
323
323
|
/**
|
|
324
324
|
* Mailbox creation request.
|
|
@@ -567,9 +567,9 @@ export interface PushoverEditRequest {
|
|
|
567
567
|
items: string | string[];
|
|
568
568
|
}
|
|
569
569
|
/**
|
|
570
|
-
*
|
|
570
|
+
* Quarantine notification edit payload.
|
|
571
571
|
*/
|
|
572
|
-
export interface
|
|
572
|
+
export interface QuarantineEditRequest {
|
|
573
573
|
/**
|
|
574
574
|
* The attributes to edit.
|
|
575
575
|
*/
|
|
@@ -586,6 +586,10 @@ export interface QuarantaineEditRequest {
|
|
|
586
586
|
anyOf: string | string[];
|
|
587
587
|
};
|
|
588
588
|
}
|
|
589
|
+
/**
|
|
590
|
+
* @deprecated Misspelling. Use {@link QuarantineEditRequest} instead. Will be removed in 2.0.0.
|
|
591
|
+
*/
|
|
592
|
+
export type QuarantaineEditRequest = QuarantineEditRequest;
|
|
589
593
|
/**
|
|
590
594
|
* Spam score edit payload.
|
|
591
595
|
*/
|
|
@@ -1125,7 +1129,7 @@ export interface PFLog extends Log {
|
|
|
1125
1129
|
*/
|
|
1126
1130
|
export interface RLLog extends Log {
|
|
1127
1131
|
/**
|
|
1128
|
-
* From email
|
|
1132
|
+
* From email address.
|
|
1129
1133
|
*/
|
|
1130
1134
|
from: string;
|
|
1131
1135
|
/**
|
package/dist/types.js
CHANGED
|
@@ -5,6 +5,10 @@ exports.MailcowException = void 0;
|
|
|
5
5
|
* Error class used for exception handling.
|
|
6
6
|
*/
|
|
7
7
|
class MailcowException extends Error {
|
|
8
|
+
/**
|
|
9
|
+
* The error message provided by Mailcow.
|
|
10
|
+
*/
|
|
11
|
+
message;
|
|
8
12
|
}
|
|
9
13
|
exports.MailcowException = MailcowException;
|
|
10
14
|
//# sourceMappingURL=types.js.map
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AA07CA;;GAEG;AACH,MAAa,gBAAiB,SAAQ,KAAK;IACzC;;OAEG;IACH,OAAO,CAAS;CACjB;AALD,4CAKC"}
|
package/package.json
CHANGED
|
@@ -1,58 +1,57 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "ts-mailcow-api",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "TypeScript wrapper for the mailcow API.",
|
|
5
|
-
"scripts": {
|
|
6
|
-
"test": "
|
|
7
|
-
"lint": "eslint src",
|
|
8
|
-
"lint:fix": "eslint src --fix",
|
|
9
|
-
"format": "prettier --ignore-path .gitignore --check ./src/",
|
|
10
|
-
"format:fix": "prettier --ignore-path .gitignore --write ./src/",
|
|
11
|
-
"docs": "typedoc",
|
|
12
|
-
"build": "tsc",
|
|
13
|
-
"prepare": "tsc",
|
|
14
|
-
"prepublishOnly": "yarn install --frozen-lockfile && yarn build"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
"@gewis/
|
|
39
|
-
"@
|
|
40
|
-
"@types/
|
|
41
|
-
"@types/
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"ts-
|
|
48
|
-
"
|
|
49
|
-
"typedoc": "^0.
|
|
50
|
-
"typedoc-plugin-
|
|
51
|
-
"
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "ts-mailcow-api",
|
|
3
|
+
"version": "1.3.0",
|
|
4
|
+
"description": "TypeScript wrapper for the mailcow API.",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"test": "ts-mocha \"test/**/*.test.ts\"",
|
|
7
|
+
"lint": "eslint src",
|
|
8
|
+
"lint:fix": "eslint src --fix",
|
|
9
|
+
"format": "prettier --ignore-path .gitignore --check ./src/",
|
|
10
|
+
"format:fix": "prettier --ignore-path .gitignore --write ./src/",
|
|
11
|
+
"docs": "typedoc",
|
|
12
|
+
"build": "tsc",
|
|
13
|
+
"prepare": "tsc",
|
|
14
|
+
"prepublishOnly": "yarn install --frozen-lockfile && yarn build"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/JustSamuel/ts-mailcow-api.git"
|
|
19
|
+
},
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/JustSamuel/ts-mailcow-api/issues"
|
|
22
|
+
},
|
|
23
|
+
"homepage": "https://github.com/JustSamuel/ts-mailcow-api#readme",
|
|
24
|
+
"author": "Samuel",
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
28
|
+
"main": "dist/index.js",
|
|
29
|
+
"types": "dist/index.d.ts",
|
|
30
|
+
"keywords": [
|
|
31
|
+
"mailcow",
|
|
32
|
+
"typescript",
|
|
33
|
+
"API"
|
|
34
|
+
],
|
|
35
|
+
"license": "AGPL-3.0-only",
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@gewis/eslint-config-typescript": "^2.4.0",
|
|
38
|
+
"@gewis/prettier-config": "^2.2.2",
|
|
39
|
+
"@types/chai": "^4.2.18",
|
|
40
|
+
"@types/mocha": "^8.2.2",
|
|
41
|
+
"@types/node": "^24.0.0",
|
|
42
|
+
"chai": "^4.3.4",
|
|
43
|
+
"eslint": "^9.24.0",
|
|
44
|
+
"mocha": "^10.1.0",
|
|
45
|
+
"prettier": "^3.5.3",
|
|
46
|
+
"ts-mocha": "^11.1.0",
|
|
47
|
+
"ts-node": "^10.9.2",
|
|
48
|
+
"typedoc": "^0.28.5",
|
|
49
|
+
"typedoc-plugin-merge-modules": "^7.0.0",
|
|
50
|
+
"typedoc-plugin-missing-exports": "^4.0.0",
|
|
51
|
+
"typescript": "^5.8.3"
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"axios": "^1.9.0"
|
|
55
|
+
},
|
|
56
|
+
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
|
|
57
|
+
}
|