ts-mailcow-api 0.6.2 → 0.8.1
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 +147 -147
- package/dist/Endpoints/alias-endpoints.d.ts +20 -17
- package/dist/Endpoints/alias-endpoints.js +6 -1
- package/dist/Endpoints/alias-endpoints.js.map +1 -1
- package/dist/Endpoints/antispam-endpoints.d.ts +25 -4
- package/dist/Endpoints/antispam-endpoints.js +8 -2
- package/dist/Endpoints/antispam-endpoints.js.map +1 -1
- package/dist/Endpoints/domain-endpoints.d.ts +29 -4
- package/dist/Endpoints/domain-endpoints.js +12 -5
- package/dist/Endpoints/domain-endpoints.js.map +1 -1
- package/dist/Endpoints/forwarding-endpoints.d.ts +27 -0
- package/dist/Endpoints/forwarding-endpoints.js +23 -0
- package/dist/Endpoints/forwarding-endpoints.js.map +1 -0
- package/dist/Endpoints/log-endpoints.d.ts +55 -0
- package/dist/Endpoints/log-endpoints.js +39 -0
- package/dist/Endpoints/log-endpoints.js.map +1 -0
- package/dist/Endpoints/mailbox-endpoint.d.ts +50 -5
- package/dist/Endpoints/mailbox-endpoint.js +13 -6
- package/dist/Endpoints/mailbox-endpoint.js.map +1 -1
- package/dist/Endpoints/syncjob-endpoints.d.ts +24 -0
- package/dist/Endpoints/syncjob-endpoints.js +21 -0
- package/dist/Endpoints/syncjob-endpoints.js.map +1 -0
- package/dist/index.d.ts +54 -23
- package/dist/index.js +46 -4
- package/dist/index.js.map +1 -1
- package/dist/request-factory.d.ts +5 -0
- package/dist/request-factory.js +10 -0
- package/dist/request-factory.js.map +1 -1
- package/dist/types.d.ts +1102 -47
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -1
- package/package.json +3 -2
- package/src/Endpoints/alias-endpoints.ts +25 -21
- package/src/Endpoints/antispam-endpoints.ts +33 -4
- package/src/Endpoints/domain-endpoints.ts +50 -10
- package/src/Endpoints/forwarding-endpoints.ts +51 -0
- package/src/Endpoints/log-endpoints.ts +130 -0
- package/src/Endpoints/mailbox-endpoint.ts +74 -8
- package/src/Endpoints/syncjob-endpoints.ts +55 -0
- package/src/index.ts +58 -9
- package/src/request-factory.ts +10 -0
- package/src/types.ts +1149 -57
package/src/index.ts
CHANGED
|
@@ -3,11 +3,14 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { AxiosRequestConfig } from 'axios';
|
|
6
|
-
import domainEndpoints from './Endpoints/domain-endpoints';
|
|
7
|
-
import antiSpamEndpoints from './Endpoints/antispam-endpoints';
|
|
8
|
-
import mailboxEndpoints from './Endpoints/mailbox-endpoint';
|
|
6
|
+
import { domainEndpoints, DomainEndpoints } from './Endpoints/domain-endpoints';
|
|
7
|
+
import { antiSpamEndpoints, AntiSpamEndpoints } from './Endpoints/antispam-endpoints';
|
|
8
|
+
import { mailboxEndpoints, MailboxEndpoints } from './Endpoints/mailbox-endpoint';
|
|
9
9
|
import RequestFactory from './request-factory';
|
|
10
10
|
import { aliasEndpoints, AliasEndpoints } from './Endpoints/alias-endpoints';
|
|
11
|
+
import { syncjobEndpoints, SyncjobEndpoints } from './Endpoints/syncjob-endpoints';
|
|
12
|
+
import { forwardingEndpoints, ForwardingEndpoints } from './Endpoints/forwarding-endpoints';
|
|
13
|
+
import { logEndpoints, LogEndpoints } from './Endpoints/log-endpoints';
|
|
11
14
|
|
|
12
15
|
/**
|
|
13
16
|
* Class containing all the logic to interface with the Mailcow API in TypeScript.
|
|
@@ -24,7 +27,11 @@ class MailcowClient {
|
|
|
24
27
|
*/
|
|
25
28
|
readonly API_KEY: string;
|
|
26
29
|
|
|
27
|
-
|
|
30
|
+
/**
|
|
31
|
+
* The headers used for every request.
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
HEADERS: AxiosRequestConfig;
|
|
28
35
|
|
|
29
36
|
/**
|
|
30
37
|
* Creates a MailcowClient using the given URL and API key.
|
|
@@ -32,7 +39,7 @@ class MailcowClient {
|
|
|
32
39
|
* @param API_KEY - The API key of the Mailcow API.
|
|
33
40
|
*/
|
|
34
41
|
constructor(BASE_URL: string, API_KEY: string) {
|
|
35
|
-
this.BASE_URL = BASE_URL;
|
|
42
|
+
this.BASE_URL = BASE_URL.charAt(BASE_URL.length - 1) === '/' ? BASE_URL : BASE_URL.concat('/');
|
|
36
43
|
this.API_KEY = API_KEY;
|
|
37
44
|
|
|
38
45
|
// Set the correct Axios headers.
|
|
@@ -41,21 +48,63 @@ class MailcowClient {
|
|
|
41
48
|
'Content-Type': 'application/json',
|
|
42
49
|
'X-API-Key': this.API_KEY
|
|
43
50
|
}
|
|
44
|
-
}
|
|
51
|
+
};
|
|
45
52
|
}
|
|
46
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Factory method pattern for creating HTTP requests.
|
|
56
|
+
* @internal
|
|
57
|
+
*/
|
|
47
58
|
public requestFactory = new RequestFactory(this)
|
|
48
59
|
|
|
49
60
|
/**
|
|
50
61
|
* All endpoints related to Aliases.
|
|
62
|
+
* See {@link AliasEndpoints}
|
|
63
|
+
* @external
|
|
51
64
|
*/
|
|
52
65
|
public aliases: AliasEndpoints = aliasEndpoints(this)
|
|
53
66
|
|
|
54
|
-
|
|
67
|
+
/**
|
|
68
|
+
* All endpoints related to Domains.
|
|
69
|
+
* See {@link DomainEndpoints}
|
|
70
|
+
* @external
|
|
71
|
+
*/
|
|
72
|
+
public domains: DomainEndpoints = domainEndpoints(this)
|
|
55
73
|
|
|
56
|
-
|
|
74
|
+
/**
|
|
75
|
+
* All endpoints related to spam policies.
|
|
76
|
+
* See {@link AntiSpamEndpoints}
|
|
77
|
+
* @external
|
|
78
|
+
*/
|
|
79
|
+
public spamPolicy: AntiSpamEndpoints = antiSpamEndpoints(this)
|
|
57
80
|
|
|
58
|
-
|
|
81
|
+
/**
|
|
82
|
+
* All endpoints related to mailboxes.
|
|
83
|
+
* See {@link MailboxEndpoints}
|
|
84
|
+
* @external
|
|
85
|
+
*/
|
|
86
|
+
public mailbox: MailboxEndpoints = mailboxEndpoints(this)
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* All endpoints related to sync jobs.
|
|
90
|
+
* See {@link SyncjobEndpoints}
|
|
91
|
+
* @external
|
|
92
|
+
*/
|
|
93
|
+
public syncjobs: SyncjobEndpoints = syncjobEndpoints(this)
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* All endpoints related to forwarding hosts.
|
|
97
|
+
* See {@link ForwardingEndpoints}
|
|
98
|
+
* @external
|
|
99
|
+
*/
|
|
100
|
+
public forwardingHosts: ForwardingEndpoints = forwardingEndpoints(this)
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* All endpoints related to logs.
|
|
104
|
+
* See {@link LogEndpoints}
|
|
105
|
+
* @external
|
|
106
|
+
*/
|
|
107
|
+
public logs: LogEndpoints = logEndpoints(this)
|
|
59
108
|
}
|
|
60
109
|
|
|
61
110
|
export default MailcowClient;
|
package/src/request-factory.ts
CHANGED
|
@@ -2,10 +2,20 @@ import axios, { AxiosError, AxiosResponse } from 'axios';
|
|
|
2
2
|
import { MailcowErrorResponse, MailcowException, Payload } from './types';
|
|
3
3
|
import MailcowClient from './index';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Ensures output is an array.
|
|
7
|
+
* @param item
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
5
10
|
function wrapToArray<T>(item: T | T[]): T[] {
|
|
6
11
|
return Array.isArray(item) ? item : [item];
|
|
7
12
|
}
|
|
8
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Function that wraps T | T[] to T[]
|
|
16
|
+
* @internal
|
|
17
|
+
* @param promise - The promise of which the output to wrap.
|
|
18
|
+
*/
|
|
9
19
|
export function wrapPromiseToArray<T>(promise: Promise<T|T[]>): Promise<T[]> {
|
|
10
20
|
return new Promise<T[]>((resolve, reject) => {
|
|
11
21
|
promise
|