@@ -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' ;
1212import 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