Skip to content

Commit d10bfa3

Browse files
committed
Added documentation.
1 parent 985ce00 commit d10bfa3

File tree

9 files changed

+784
-94
lines changed

9 files changed

+784
-94
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "TypeScript wrapper for the mailcow API.",
55
"scripts": {
66
"test": "ts-mocha ./test/**/*.test.ts",
7-
"lint": "eslint --fix --ext .ts ./src/",
7+
"lint": "eslint --fix ./src/**/*.ts",
88
"docs": "typedoc",
99
"build": "tsc",
1010
"prepare": "tsc",

src/Endpoints/alias-endpoints.ts

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,56 +2,60 @@ import {
22
Alias,
33
AliasDeleteRequest,
44
AliasPostRequest,
5-
AliasUpdateRequest,
5+
AliasEditRequest,
66
MailcowResponse
77
} from '../types';
88
import MailcowClient from '../index';
99
import { wrapPromiseToArray } from '../request-factory';
1010

11+
/**
12+
* Interface for all Alias endpoints.
13+
*/
1114
export interface AliasEndpoints {
1215
/**
1316
* Endpoint for getting mailbox aliases in the system.
1417
* @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-
* ```
2418
*/
25-
get: (id?: number | 'all') => Promise<Alias[]>,
19+
get(id?: number | 'all'): Promise<Alias[]>;
2620

2721
/**
2822
* Endpoint for creating mailbox aliases.
29-
* @param payload - View {@link AliasAttributes} for payload parameters.
23+
* @param payload - The creation payload.
3024
*/
31-
create: (payload: AliasPostRequest) => Promise<MailcowResponse>,
25+
create(payload: AliasPostRequest): Promise<MailcowResponse>;
26+
3227
/**
33-
* Update for editing a mailbox alias.
34-
* @param payload -
28+
* Endpoint for editing a mailbox alias.
29+
* @param payload - The edit payload.
3530
*/
36-
update: (payload: AliasUpdateRequest) => Promise<MailcowResponse>,
37-
delete: (payload: AliasDeleteRequest) => Promise<MailcowResponse>,
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>;
3838
}
3939

40+
/**
41+
* Binder function between the MailcowClient class and the AliasEndpoints.
42+
* @param bind - The MailcowClient to bind.
43+
* @internal
44+
*/
4045
export function aliasEndpoints(bind: MailcowClient): AliasEndpoints {
4146
return {
4247
get(id = 'all'): Promise<Alias[]> {
4348
return wrapPromiseToArray<Alias>(
44-
bind.requestFactory.get<Alias[] | Alias>(
45-
`/api/v1/get/alias/${ id }`
46-
));
49+
bind.requestFactory.get<Alias[] | Alias>(`/api/v1/get/alias/${id}`)
50+
);
4751
},
4852
create: (payload: AliasPostRequest): Promise<MailcowResponse> => {
4953
return bind.requestFactory.post<MailcowResponse>(
5054
'/api/v1/add/alias',
5155
payload
5256
);
5357
},
54-
update: (payload: AliasUpdateRequest): Promise<MailcowResponse> => {
58+
edit: (payload: AliasEditRequest): Promise<MailcowResponse> => {
5559
return bind.requestFactory.post<MailcowResponse>(
5660
'/api/v1/edit/alias',
5761
payload

src/Endpoints/antispam-endpoints.ts

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,40 @@ import {
33
SpamPolicyPostRequest,
44
MailcowResponse,
55
SpamPolicyGetRequest,
6-
SpamPolicyResponse
6+
SpamPolicy
77
} from '../types';
88
import MailcowClient from '../index';
99

10-
export default function AntiSpamEndpoints(bind: MailcowClient) {
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 {
1140
return {
1241
create(payload: SpamPolicyPostRequest): Promise<MailcowResponse> {
1342
return bind.requestFactory.post<MailcowResponse>(
@@ -21,8 +50,8 @@ export default function AntiSpamEndpoints(bind: MailcowClient) {
2150
payload.prefid,
2251
);
2352
},
24-
get(payload: SpamPolicyGetRequest): Promise<SpamPolicyResponse[]> {
25-
return bind.requestFactory.get<SpamPolicyResponse[]>(
53+
get(payload: SpamPolicyGetRequest): Promise<SpamPolicy[]> {
54+
return bind.requestFactory.get<SpamPolicy[]>(
2655
`/api/v1/get/policy_${ payload.type }_domain/${ payload.domain }`,
2756
);
2857
}

src/Endpoints/domain-endpoints.ts

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,73 @@
1-
import { DomainDeleteRequest, DomainEditRequest, DomainPostRequest, DomainResponse, MailcowResponse } from '../types';
1+
import {
2+
DomainDeleteRequest,
3+
DomainEditRequest,
4+
DomainPostRequest,
5+
Domain,
6+
MailcowResponse
7+
} from '../types';
28
import MailcowClient from '../index';
9+
import { wrapPromiseToArray } from '../request-factory';
310

4-
export default function DomainEndpoints(bind: MailcowClient) {
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 {
546
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+
},
654
create(payload: DomainPostRequest): Promise<MailcowResponse> {
755
return bind.requestFactory.post<MailcowResponse>(
856
'/api/v1/add/domain',
957
payload
1058
);
1159
},
12-
1360
delete(payload: DomainDeleteRequest): Promise<MailcowResponse> {
1461
return bind.requestFactory.post<MailcowResponse>(
1562
'/api/v1/delete/domain',
1663
payload.domains
1764
);
1865
},
19-
2066
edit(payload: DomainEditRequest): Promise<MailcowResponse> {
2167
return bind.requestFactory.post<MailcowResponse>(
2268
'/api/v1/edit/domain',
2369
payload
2470
);
25-
},
26-
27-
get(domain: string = 'all'): Promise<DomainResponse | DomainResponse[]> {
28-
return bind.requestFactory.get<DomainResponse>(
29-
`/api/v1/get/domain/${ domain }`
30-
);
3171
}
3272
};
3373
}

src/Endpoints/mailbox-endpoint.ts

Lines changed: 74 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,80 @@ import {
33
MailboxDeleteRequest,
44
MailboxEditRequest,
55
MailboxPostRequest,
6-
MailboxResponse,
6+
Mailbox,
77
MailcowResponse,
88
PushoverEditRequest,
99
QuarantaineEditRequest,
1010
SpamScoreEditRequest
1111
} from '../types';
1212
import MailcowClient from '../index';
13+
import { wrapPromiseToArray } from "../request-factory";
1314

14-
export default function MailboxEndpoints(bind: MailcowClient) {
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 {
1580
return {
1681
create(payload: MailboxPostRequest): Promise<MailcowResponse> {
1782
return bind.requestFactory.post<MailcowResponse>(
@@ -23,7 +88,7 @@ export default function MailboxEndpoints(bind: MailcowClient) {
2388
delete(payload: MailboxDeleteRequest): Promise<MailcowResponse> {
2489
return bind.requestFactory.post<MailcowResponse>(
2590
'/api/v1/delete/mailbox',
26-
payload.domains
91+
payload.mailboxes
2792
);
2893
},
2994

@@ -34,9 +99,10 @@ export default function MailboxEndpoints(bind: MailcowClient) {
3499
);
35100
},
36101

37-
get(mailbox: string = 'all'): Promise<MailboxResponse[]> {
38-
return bind.requestFactory.get<MailboxResponse[]>(
39-
`/api/v1/get/mailbox/${ mailbox }`
102+
get(mailbox: string = 'all'): Promise<Mailbox[]> {
103+
return wrapPromiseToArray<Mailbox>(
104+
bind.requestFactory.get<Mailbox[] | Mailbox>(
105+
`/api/v1/get/mailbox/${ mailbox }`)
40106
);
41107
},
42108

@@ -68,9 +134,9 @@ export default function MailboxEndpoints(bind: MailcowClient) {
68134
);
69135
},
70136

71-
getActiveUserSieve(username: string): Promise<string[]> {
137+
getActiveUserSieve(mailbox: string): Promise<string[]> {
72138
return bind.requestFactory.get<string[]>(
73-
`/api/v1/get/active-user-sieve/${ username }`
139+
`/api/v1/get/active-user-sieve/${ mailbox }`
74140
);
75141
}
76142
};

0 commit comments

Comments
 (0)