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/dist/types.js
CHANGED
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":";;;AAi1CA;;GAEG;AACH,MAAa,gBAAiB,SAAQ,KAAK;CAK1C;AALD,4CAKC"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-mailcow-api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "TypeScript wrapper for the mailcow API.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "ts-mocha ./test/**/*.test.ts",
|
|
7
|
-
"lint": "eslint --fix
|
|
7
|
+
"lint": "eslint --fix ./src/**/*.ts",
|
|
8
|
+
"quick": "ts-node ./src/custom.ts",
|
|
8
9
|
"docs": "typedoc",
|
|
9
10
|
"build": "tsc",
|
|
10
11
|
"prepare": "tsc",
|
|
@@ -2,48 +2,52 @@ import {
|
|
|
2
2
|
Alias,
|
|
3
3
|
AliasDeleteRequest,
|
|
4
4
|
AliasPostRequest,
|
|
5
|
-
|
|
5
|
+
AliasEditRequest,
|
|
6
6
|
MailcowResponse
|
|
7
7
|
} from '../types';
|
|
8
8
|
import MailcowClient from '../index';
|
|
9
9
|
import { wrapPromiseToArray } from '../request-factory';
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Interface for all Alias endpoints.
|
|
13
|
+
*/
|
|
11
14
|
export interface AliasEndpoints {
|
|
12
15
|
/**
|
|
13
16
|
* Endpoint for getting mailbox aliases in the system.
|
|
14
17
|
* @param id - The id of the alias you want to get. Use 'all' to retrieve all aliases in the system.
|
|
15
|
-
*
|
|
16
|
-
* @example Get all aliases:
|
|
17
|
-
* ```typescript
|
|
18
|
-
* mcc.aliases.get('all').then((res) => { console.log(res); });
|
|
19
|
-
* ```
|
|
20
|
-
* @example Get a single alias:
|
|
21
|
-
* ```typescript
|
|
22
|
-
* mcc.aliases.get(8).then((res) => { console.log(res); });
|
|
23
|
-
* ```
|
|
24
18
|
*/
|
|
25
|
-
get
|
|
19
|
+
get(id?: number | 'all'): Promise<Alias[]>;
|
|
26
20
|
|
|
27
21
|
/**
|
|
28
22
|
* Endpoint for creating mailbox aliases.
|
|
29
|
-
* @param payload -
|
|
23
|
+
* @param payload - The creation payload.
|
|
30
24
|
*/
|
|
31
|
-
create
|
|
25
|
+
create(payload: AliasPostRequest): Promise<MailcowResponse>;
|
|
26
|
+
|
|
32
27
|
/**
|
|
33
|
-
*
|
|
34
|
-
* @param payload -
|
|
28
|
+
* Endpoint for editing a mailbox alias.
|
|
29
|
+
* @param payload - The edit payload.
|
|
35
30
|
*/
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
edit(payload: AliasEditRequest): Promise<MailcowResponse>;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Endpoint for deleting a mailbox alias.
|
|
35
|
+
* @param payload - The deletion payload.
|
|
36
|
+
*/
|
|
37
|
+
delete(payload: AliasDeleteRequest): Promise<MailcowResponse>;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
/**
|
|
41
|
+
* Binder function between the MailcowClient class and the AliasEndpoints.
|
|
42
|
+
* @param bind - The MailcowClient to bind.
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
40
45
|
export function aliasEndpoints(bind: MailcowClient): AliasEndpoints {
|
|
41
46
|
return {
|
|
42
47
|
get(id = 'all'): Promise<Alias[]> {
|
|
43
48
|
return wrapPromiseToArray<Alias>(
|
|
44
|
-
bind.requestFactory.get<Alias[] | Alias>(
|
|
45
|
-
|
|
46
|
-
));
|
|
49
|
+
bind.requestFactory.get<Alias[] | Alias>(`/api/v1/get/alias/${id}`)
|
|
50
|
+
);
|
|
47
51
|
},
|
|
48
52
|
create: (payload: AliasPostRequest): Promise<MailcowResponse> => {
|
|
49
53
|
return bind.requestFactory.post<MailcowResponse>(
|
|
@@ -51,7 +55,7 @@ export function aliasEndpoints(bind: MailcowClient): AliasEndpoints {
|
|
|
51
55
|
payload
|
|
52
56
|
);
|
|
53
57
|
},
|
|
54
|
-
|
|
58
|
+
edit: (payload: AliasEditRequest): Promise<MailcowResponse> => {
|
|
55
59
|
return bind.requestFactory.post<MailcowResponse>(
|
|
56
60
|
'/api/v1/edit/alias',
|
|
57
61
|
payload
|
|
@@ -3,11 +3,40 @@ import {
|
|
|
3
3
|
SpamPolicyPostRequest,
|
|
4
4
|
MailcowResponse,
|
|
5
5
|
SpamPolicyGetRequest,
|
|
6
|
-
|
|
6
|
+
SpamPolicy
|
|
7
7
|
} from '../types';
|
|
8
8
|
import MailcowClient from '../index';
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Interface for all antispam policies.
|
|
12
|
+
*/
|
|
13
|
+
export interface AntiSpamEndpoints {
|
|
14
|
+
/**
|
|
15
|
+
* Endpoint for getting antispam policies.
|
|
16
|
+
* @param payload - The get payload.
|
|
17
|
+
*/
|
|
18
|
+
get(payload: SpamPolicyGetRequest): Promise<SpamPolicy[]>
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Endpoint for creating antispam policies.
|
|
22
|
+
* @param payload - The creation payload.
|
|
23
|
+
*/
|
|
24
|
+
create(payload: SpamPolicyPostRequest): Promise<MailcowResponse>
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Endpoint for deleting antispam policies.
|
|
28
|
+
* @param payload - The deletion payload.
|
|
29
|
+
*/
|
|
30
|
+
delete(payload: SpamPolicyDeleteRequest): Promise<MailcowResponse>
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Binder function between the MailcowClient class and the AntiSpamEndpoints
|
|
36
|
+
* @param bind - The MailcowClient to bind.
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
39
|
+
export function antiSpamEndpoints(bind: MailcowClient): AntiSpamEndpoints {
|
|
11
40
|
return {
|
|
12
41
|
create(payload: SpamPolicyPostRequest): Promise<MailcowResponse> {
|
|
13
42
|
return bind.requestFactory.post<MailcowResponse>(
|
|
@@ -21,8 +50,8 @@ export default function AntiSpamEndpoints(bind: MailcowClient) {
|
|
|
21
50
|
payload.prefid,
|
|
22
51
|
);
|
|
23
52
|
},
|
|
24
|
-
get(payload: SpamPolicyGetRequest): Promise<
|
|
25
|
-
return bind.requestFactory.get<
|
|
53
|
+
get(payload: SpamPolicyGetRequest): Promise<SpamPolicy[]> {
|
|
54
|
+
return bind.requestFactory.get<SpamPolicy[]>(
|
|
26
55
|
`/api/v1/get/policy_${ payload.type }_domain/${ payload.domain }`,
|
|
27
56
|
);
|
|
28
57
|
}
|
|
@@ -1,33 +1,73 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
DomainDeleteRequest,
|
|
3
|
+
DomainEditRequest,
|
|
4
|
+
DomainPostRequest,
|
|
5
|
+
Domain,
|
|
6
|
+
MailcowResponse
|
|
7
|
+
} from '../types';
|
|
2
8
|
import MailcowClient from '../index';
|
|
9
|
+
import { wrapPromiseToArray } from '../request-factory';
|
|
3
10
|
|
|
4
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Interface for all Domain endpoints.
|
|
13
|
+
*/
|
|
14
|
+
export interface DomainEndpoints {
|
|
15
|
+
/**
|
|
16
|
+
* Endpoint for getting domains.
|
|
17
|
+
* @param domain - Name of the domain to get.
|
|
18
|
+
*/
|
|
19
|
+
get(domain: string): Promise<Domain[]>;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Endpoint for creating domains.
|
|
23
|
+
* @param payload - The creation payload.
|
|
24
|
+
*/
|
|
25
|
+
create(payload: DomainPostRequest): Promise<MailcowResponse>;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Endpoint for deleting a domain.
|
|
29
|
+
* @param payload - The deletion payload.
|
|
30
|
+
*/
|
|
31
|
+
delete(payload: DomainDeleteRequest): Promise<MailcowResponse>;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Endpoint for editing a domain.
|
|
35
|
+
* @param payload - The edit payload.
|
|
36
|
+
*/
|
|
37
|
+
edit(payload: DomainEditRequest): Promise<MailcowResponse>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Binder function between the MailcowClient class and the DomainEndpoints.
|
|
42
|
+
* @param bind - The MailcowClient to bind.
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
45
|
+
export function domainEndpoints(bind: MailcowClient): DomainEndpoints {
|
|
5
46
|
return {
|
|
47
|
+
get(domain: string = 'all'): Promise<Domain[]> {
|
|
48
|
+
return wrapPromiseToArray<Domain>(
|
|
49
|
+
bind.requestFactory.get<Domain | Domain[]>(
|
|
50
|
+
`/api/v1/get/domain/${ domain }`
|
|
51
|
+
)
|
|
52
|
+
);
|
|
53
|
+
},
|
|
6
54
|
create(payload: DomainPostRequest): Promise<MailcowResponse> {
|
|
7
55
|
return bind.requestFactory.post<MailcowResponse>(
|
|
8
56
|
'/api/v1/add/domain',
|
|
9
57
|
payload
|
|
10
58
|
);
|
|
11
59
|
},
|
|
12
|
-
|
|
13
60
|
delete(payload: DomainDeleteRequest): Promise<MailcowResponse> {
|
|
14
61
|
return bind.requestFactory.post<MailcowResponse>(
|
|
15
62
|
'/api/v1/delete/domain',
|
|
16
63
|
payload.domains
|
|
17
64
|
);
|
|
18
65
|
},
|
|
19
|
-
|
|
20
66
|
edit(payload: DomainEditRequest): Promise<MailcowResponse> {
|
|
21
67
|
return bind.requestFactory.post<MailcowResponse>(
|
|
22
68
|
'/api/v1/edit/domain',
|
|
23
69
|
payload
|
|
24
70
|
);
|
|
25
|
-
},
|
|
26
|
-
|
|
27
|
-
get(domain: string = 'all'): Promise<DomainResponse | DomainResponse[]> {
|
|
28
|
-
return bind.requestFactory.get<DomainResponse>(
|
|
29
|
-
`/api/v1/get/domain/${ domain }`
|
|
30
|
-
);
|
|
31
71
|
}
|
|
32
72
|
};
|
|
33
73
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import MailcowClient from '../index';
|
|
2
|
+
import { ForwardingCreateRequest, ForwardingDeleteRequest, ForwardingHost, MailcowResponse } from '../types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Interface for all Forwarding Hosts endpoints.
|
|
6
|
+
*/
|
|
7
|
+
export interface ForwardingEndpoints {
|
|
8
|
+
/**
|
|
9
|
+
* Endpoint for deleting forwarding host.
|
|
10
|
+
* @param payload - The deletion payload
|
|
11
|
+
*/
|
|
12
|
+
delete(payload: ForwardingDeleteRequest): Promise<MailcowResponse>
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Endpoint for creating forwarding host.
|
|
16
|
+
* @param payload - The creation payload
|
|
17
|
+
*/
|
|
18
|
+
create(payload: ForwardingCreateRequest): Promise<MailcowResponse>
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Endpoint for getting all forwarding host.
|
|
22
|
+
*/
|
|
23
|
+
getAll(): Promise<ForwardingHost[]>
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Binder function between the MailcowClient class and the ForwardingEndpoints.
|
|
28
|
+
* @param bind - The MailcowClient to bind.
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
export function forwardingEndpoints(bind: MailcowClient): ForwardingEndpoints {
|
|
32
|
+
return {
|
|
33
|
+
delete(payload: ForwardingDeleteRequest): Promise<MailcowResponse> {
|
|
34
|
+
return bind.requestFactory.post<MailcowResponse>(
|
|
35
|
+
'/api/v1/delete/fwdhost',
|
|
36
|
+
payload.items
|
|
37
|
+
);
|
|
38
|
+
},
|
|
39
|
+
create(payload: ForwardingCreateRequest): Promise<MailcowResponse> {
|
|
40
|
+
return bind.requestFactory.post<MailcowResponse>(
|
|
41
|
+
'/api/v1/add/fwdhost',
|
|
42
|
+
payload
|
|
43
|
+
);
|
|
44
|
+
},
|
|
45
|
+
getAll(): Promise<ForwardingHost[]> {
|
|
46
|
+
return bind.requestFactory.get<ForwardingHost[]>(
|
|
47
|
+
'/api/v1/get/fwdhost/all'
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import MailcowClient from '../index';
|
|
2
|
+
import {
|
|
3
|
+
ACMELog,
|
|
4
|
+
ADLog,
|
|
5
|
+
APILog,
|
|
6
|
+
DCLog,
|
|
7
|
+
NFLog,
|
|
8
|
+
PFLog,
|
|
9
|
+
RLLog,
|
|
10
|
+
RSLog,
|
|
11
|
+
SGLog,
|
|
12
|
+
WDLog
|
|
13
|
+
} from '../types';
|
|
14
|
+
|
|
15
|
+
export interface LogEndpoints {
|
|
16
|
+
/**
|
|
17
|
+
* Endpoint for returning ACME Logs.
|
|
18
|
+
* @param count - The number of logs to return.
|
|
19
|
+
*/
|
|
20
|
+
acme(count: number): Promise<ACMELog[]>;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Endpoint for returning API Logs.
|
|
24
|
+
* @param count - The number of logs to return.
|
|
25
|
+
*/
|
|
26
|
+
api(count: number): Promise<APILog[]>;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Endpoint for returning Autodiscover Logs.
|
|
30
|
+
* @param count - The number of logs to return.
|
|
31
|
+
*/
|
|
32
|
+
autodiscover(count: number): Promise<ADLog[]>;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Endpoint for returning dovecot Logs.
|
|
36
|
+
* @param count - The number of logs to return.
|
|
37
|
+
*/
|
|
38
|
+
dovecot(count: number): Promise<DCLog[]>;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Endpoint for returning Netfilter Logs.
|
|
42
|
+
* @param count - The number of logs to return.
|
|
43
|
+
*/
|
|
44
|
+
netfilter(count: number): Promise<NFLog[]>;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Endpoint for returning Postfix Logs.
|
|
48
|
+
* @param count - The number of logs to return.
|
|
49
|
+
*/
|
|
50
|
+
postfix(count: number): Promise<PFLog[]>;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Endpoint for returning Rate limited Logs.
|
|
54
|
+
* @param count - The number of logs to return.
|
|
55
|
+
*/
|
|
56
|
+
ratelimited(count: number): Promise<RLLog[]>;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Endpoint for returning Rspamd Logs.
|
|
60
|
+
* @param count - The number of logs to return.
|
|
61
|
+
*/
|
|
62
|
+
rspamd(count: number): Promise<RSLog[]>;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Endpoint for returning SOGo Logs.
|
|
66
|
+
* @param count - The number of logs to return.
|
|
67
|
+
*/
|
|
68
|
+
sogo(count: number): Promise<SGLog[]>;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Endpoint for returning Watchdog Logs.
|
|
72
|
+
* @param count - The number of logs to return.
|
|
73
|
+
*/
|
|
74
|
+
watchdog(count: number): Promise<WDLog[]>;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function logEndpoints(bind: MailcowClient): LogEndpoints {
|
|
78
|
+
return {
|
|
79
|
+
acme(count: number): Promise<ACMELog[]> {
|
|
80
|
+
return bind.requestFactory.get<ACMELog[]>(
|
|
81
|
+
`/api/v1/get/logs/acme/${count}`
|
|
82
|
+
);
|
|
83
|
+
},
|
|
84
|
+
api(count: number): Promise<APILog[]> {
|
|
85
|
+
return bind.requestFactory.get<APILog[]>(
|
|
86
|
+
`/api/v1/get/logs/api/${count}`
|
|
87
|
+
);
|
|
88
|
+
},
|
|
89
|
+
autodiscover(count: number): Promise<ADLog[]> {
|
|
90
|
+
return bind.requestFactory.get<ADLog[]>(
|
|
91
|
+
`/api/v1/get/logs/autodiscover/${count}`
|
|
92
|
+
);
|
|
93
|
+
},
|
|
94
|
+
dovecot(count: number): Promise<DCLog[]> {
|
|
95
|
+
return bind.requestFactory.get<DCLog[]>(
|
|
96
|
+
`/api/v1/get/logs/dovecot/${count}`
|
|
97
|
+
);
|
|
98
|
+
},
|
|
99
|
+
netfilter(count: number): Promise<NFLog[]> {
|
|
100
|
+
return bind.requestFactory.get<NFLog[]>(
|
|
101
|
+
`/api/v1/get/logs/netfilter/${count}`
|
|
102
|
+
);
|
|
103
|
+
},
|
|
104
|
+
postfix(count: number): Promise<PFLog[]> {
|
|
105
|
+
return bind.requestFactory.get<PFLog[]>(
|
|
106
|
+
`/api/v1/get/logs/postfix/${count}`
|
|
107
|
+
);
|
|
108
|
+
},
|
|
109
|
+
ratelimited(count: number): Promise<RLLog[]> {
|
|
110
|
+
return bind.requestFactory.get<RLLog[]>(
|
|
111
|
+
`/api/v1/get/logs/ratelimited/${count}`
|
|
112
|
+
);
|
|
113
|
+
},
|
|
114
|
+
rspamd(count: number): Promise<RSLog[]> {
|
|
115
|
+
return bind.requestFactory.get<RSLog[]>(
|
|
116
|
+
`/api/v1/get/logs/rspamd-history/${count}`
|
|
117
|
+
);
|
|
118
|
+
},
|
|
119
|
+
sogo(count: number): Promise<SGLog[]> {
|
|
120
|
+
return bind.requestFactory.get<SGLog[]>(
|
|
121
|
+
`/api/v1/get/logs/sogo/${count}`
|
|
122
|
+
);
|
|
123
|
+
},
|
|
124
|
+
watchdog(count: number): Promise<WDLog[]> {
|
|
125
|
+
return bind.requestFactory.get<WDLog[]>(
|
|
126
|
+
`/api/v1/get/logs/watchdog/${count}`
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
}
|
|
@@ -3,15 +3,80 @@ import {
|
|
|
3
3
|
MailboxDeleteRequest,
|
|
4
4
|
MailboxEditRequest,
|
|
5
5
|
MailboxPostRequest,
|
|
6
|
-
|
|
6
|
+
Mailbox,
|
|
7
7
|
MailcowResponse,
|
|
8
8
|
PushoverEditRequest,
|
|
9
9
|
QuarantaineEditRequest,
|
|
10
10
|
SpamScoreEditRequest
|
|
11
11
|
} from '../types';
|
|
12
12
|
import MailcowClient from '../index';
|
|
13
|
+
import { wrapPromiseToArray } from '../request-factory';
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Interface for all Mailbox endpoints.
|
|
17
|
+
*/
|
|
18
|
+
export interface MailboxEndpoints {
|
|
19
|
+
/**
|
|
20
|
+
* Endpoint for creating a mailbox.
|
|
21
|
+
* @param payload - The creation payload.
|
|
22
|
+
*/
|
|
23
|
+
create(payload: MailboxPostRequest): Promise<MailcowResponse>;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Endpoint for deleting a mailbox.
|
|
27
|
+
* @param payload - The deletion payload.
|
|
28
|
+
*/
|
|
29
|
+
delete(payload: MailboxDeleteRequest): Promise<MailcowResponse>;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Endpoint for editing a mailbox.
|
|
33
|
+
* @param payload
|
|
34
|
+
*/
|
|
35
|
+
edit(payload: MailboxEditRequest): Promise<MailcowResponse>;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Endpoint for getting a mailbox.
|
|
39
|
+
* @param mailbox - The mailbox to get
|
|
40
|
+
*/
|
|
41
|
+
get(mailbox: string | 'all'): Promise<Mailbox[]>;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Endpoint for editing a mailbox's pushover settings.
|
|
45
|
+
* @param payload - The edit payload.
|
|
46
|
+
*/
|
|
47
|
+
editPushover(payload: PushoverEditRequest): Promise<MailcowResponse>;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Endpoint for editing a mailbox's quarantine settings.
|
|
51
|
+
* @param payload - The edit payload.
|
|
52
|
+
*/
|
|
53
|
+
editQuarantine(payload: QuarantaineEditRequest): Promise<MailcowResponse>;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Endpoint for editing a mailbox's spam score settings.
|
|
57
|
+
* @param payload - The edit payload.
|
|
58
|
+
*/
|
|
59
|
+
editSpamScore(payload: SpamScoreEditRequest): Promise<MailcowResponse>;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Endpoint for editing a mailbox's ACL settings.
|
|
63
|
+
* @param payload - The edit payload.
|
|
64
|
+
*/
|
|
65
|
+
editUserACL(payload: ACLEditRequest): Promise<MailcowResponse>;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Endpoint fot getting a mailbox's active sieve.
|
|
69
|
+
* @param mailbox - The mailbox to get.
|
|
70
|
+
*/
|
|
71
|
+
getActiveUserSieve(mailbox: string): Promise<string[]>;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Binder function between the MailcowClient class and the MailboxEndpoints
|
|
76
|
+
* @param bind - The MailcowClient to bind.
|
|
77
|
+
* @internal
|
|
78
|
+
*/
|
|
79
|
+
export function mailboxEndpoints(bind: MailcowClient): MailboxEndpoints {
|
|
15
80
|
return {
|
|
16
81
|
create(payload: MailboxPostRequest): Promise<MailcowResponse> {
|
|
17
82
|
return bind.requestFactory.post<MailcowResponse>(
|
|
@@ -23,7 +88,7 @@ export default function MailboxEndpoints(bind: MailcowClient) {
|
|
|
23
88
|
delete(payload: MailboxDeleteRequest): Promise<MailcowResponse> {
|
|
24
89
|
return bind.requestFactory.post<MailcowResponse>(
|
|
25
90
|
'/api/v1/delete/mailbox',
|
|
26
|
-
payload.
|
|
91
|
+
payload.mailboxes
|
|
27
92
|
);
|
|
28
93
|
},
|
|
29
94
|
|
|
@@ -34,9 +99,10 @@ export default function MailboxEndpoints(bind: MailcowClient) {
|
|
|
34
99
|
);
|
|
35
100
|
},
|
|
36
101
|
|
|
37
|
-
get(mailbox: string = 'all'): Promise<
|
|
38
|
-
return
|
|
39
|
-
|
|
102
|
+
get(mailbox: string = 'all'): Promise<Mailbox[]> {
|
|
103
|
+
return wrapPromiseToArray<Mailbox>(
|
|
104
|
+
bind.requestFactory.get<Mailbox[] | Mailbox>(
|
|
105
|
+
`/api/v1/get/mailbox/${ mailbox }`)
|
|
40
106
|
);
|
|
41
107
|
},
|
|
42
108
|
|
|
@@ -68,9 +134,9 @@ export default function MailboxEndpoints(bind: MailcowClient) {
|
|
|
68
134
|
);
|
|
69
135
|
},
|
|
70
136
|
|
|
71
|
-
getActiveUserSieve(
|
|
137
|
+
getActiveUserSieve(mailbox: string): Promise<string[]> {
|
|
72
138
|
return bind.requestFactory.get<string[]>(
|
|
73
|
-
`/api/v1/get/active-user-sieve/${
|
|
139
|
+
`/api/v1/get/active-user-sieve/${ mailbox }`
|
|
74
140
|
);
|
|
75
141
|
}
|
|
76
142
|
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import MailcowClient from '../index';
|
|
2
|
+
import { MailcowResponse, Syncjob, SyncjobDeleteRequest, SyncjobPostRequest, SyncjobUpdateRequest } from '../types';
|
|
3
|
+
|
|
4
|
+
export interface SyncjobEndpoints {
|
|
5
|
+
/**
|
|
6
|
+
* Endpoint for creating sync jobs.
|
|
7
|
+
* @param payload - The creation payload.
|
|
8
|
+
*/
|
|
9
|
+
create(payload: SyncjobPostRequest): Promise<MailcowResponse>
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Endpoint for editing sync jobs.
|
|
13
|
+
* @param payload - The edit payload.
|
|
14
|
+
*/
|
|
15
|
+
edit(payload: SyncjobUpdateRequest): Promise<MailcowResponse>
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Endpoint for deleting sync jobs
|
|
19
|
+
* @param payload - The deletion payload.
|
|
20
|
+
*/
|
|
21
|
+
delete(payload: SyncjobDeleteRequest): Promise<MailcowResponse>
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Endpoint for getting all sync jobs.
|
|
25
|
+
*/
|
|
26
|
+
getAll(): Promise<Syncjob[]>
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function syncjobEndpoints(bind: MailcowClient): SyncjobEndpoints {
|
|
30
|
+
return {
|
|
31
|
+
getAll(): Promise<Syncjob[]> {
|
|
32
|
+
return bind.requestFactory.get<Syncjob[]>(
|
|
33
|
+
'/api/v1/get/syncjobs/all/no_log'
|
|
34
|
+
);
|
|
35
|
+
},
|
|
36
|
+
create(payload: SyncjobPostRequest): Promise<MailcowResponse> {
|
|
37
|
+
return bind.requestFactory.post<MailcowResponse>(
|
|
38
|
+
'/api/v1/add/syncjob',
|
|
39
|
+
payload
|
|
40
|
+
);
|
|
41
|
+
},
|
|
42
|
+
edit(payload: SyncjobUpdateRequest): Promise<MailcowResponse> {
|
|
43
|
+
return bind.requestFactory.post<MailcowResponse>(
|
|
44
|
+
'/api/v1/edit/syncjob',
|
|
45
|
+
payload
|
|
46
|
+
);
|
|
47
|
+
},
|
|
48
|
+
delete(payload: SyncjobDeleteRequest): Promise<MailcowResponse> {
|
|
49
|
+
return bind.requestFactory.post<MailcowResponse>(
|
|
50
|
+
'/api/v1/delete/syncjob',
|
|
51
|
+
payload.items
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|