Skip to content

Commit 9d8762e

Browse files
committed
Created syncjob-endpoints.ts
1 parent d10bfa3 commit 9d8762e

File tree

6 files changed

+299
-20
lines changed

6 files changed

+299
-20
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Create a new wrapper using the base url and API_KEY.
77
import MailCowClient from "./index";
88

99
// Create MailCowClient based on BASE_URL and API_KEY
10-
const mcc = new MailCowClient("https://demo.mailcow.email/api/v1", "390448-22B69F-FA37D9-19701B-6F033F");
10+
const mcc = new MailCowClient("https://demo.mailcow.email/", "390448-22B69F-FA37D9-19701B-6F033F");
1111
```
1212
Then you can use the created wrapper for promised-based API calls according to the Mailcow API specification.
1313
```ts
@@ -51,10 +51,10 @@ mcc.mailbox.get().then((e) => {
5151
- [x] Get aliases
5252

5353
### Sync Jobs
54-
- [ ] Create sync job
55-
- [ ] Delete sync job
56-
- [ ] Update sync job
57-
- [ ] Get sync jobs
54+
- [x] Create sync job
55+
- [x] Delete sync job
56+
- [x] Update sync job
57+
- [x] Get sync jobs
5858

5959
### Forwarding Hosts
6060
- [ ] Add Forward Host
@@ -144,4 +144,4 @@ mcc.mailbox.get().then((e) => {
144144
- [ ] Get mailbox ratelimits
145145
- [ ] Get domain ratelimits
146146
- [ ] Edit domain ratelimits
147-
- [ ] Edit mailbox ratelimits
147+
- [ ] Edit mailbox ratelimits

src/Endpoints/antispam-endpoints.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export interface AntiSpamEndpoints {
2121
* Endpoint for creating antispam policies.
2222
* @param payload - The creation payload.
2323
*/
24-
create(payload: SpamPolicyPostRequest): Promise<MailcowResponse>
24+
create(payload: SpamPolicyPostRequest): Promise<MailcowResponse>
2525

2626
/**
2727
* Endpoint for deleting antispam policies.

src/Endpoints/syncjob-endpoints.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

src/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { antiSpamEndpoints, AntiSpamEndpoints } from './Endpoints/antispam-endpo
88
import { mailboxEndpoints, MailboxEndpoints } from './Endpoints/mailbox-endpoint';
99
import RequestFactory from './request-factory';
1010
import { aliasEndpoints, AliasEndpoints } from './Endpoints/alias-endpoints';
11+
import { syncjobEndpoints, SyncjobEndpoints } from "./Endpoints/syncjob-endpoints";
1112

1213
/**
1314
* Class containing all the logic to interface with the Mailcow API in TypeScript.
@@ -81,6 +82,13 @@ class MailcowClient {
8182
* @external
8283
*/
8384
public mailbox: MailboxEndpoints = mailboxEndpoints(this)
85+
86+
/**
87+
* All endpoints related to sync jobs.
88+
* See {@link SyncjobEndpoints}
89+
* @external
90+
*/
91+
public syncjobs: SyncjobEndpoints = syncjobEndpoints(this)
8492
}
8593

8694
export default MailcowClient;

src/types.ts

Lines changed: 162 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ type RelayFrame = 's' | 'm' | 'h' | 'd';
5858
/**
5959
* Domain creation payload.
6060
*/
61-
export interface DomainPostRequest extends BaseDomainAttributes {
61+
export interface DomainPostRequest extends BaseDomainAttributes {
6262
/**
6363
* The domain to create.
6464
*/
@@ -92,7 +92,7 @@ export interface DomainDeleteRequest {
9292
*/
9393
export interface DomainEditAttributes extends BaseDomainAttributes {
9494
/**
95-
* Is domain global address list active or not, it enables shared contacts across domain in SOGo webmail
95+
* Is domain global address list active or not, it enables shared contacts across domain in SOGo webmail
9696
*/
9797
gal: boolean
9898
/**
@@ -156,7 +156,7 @@ export interface Domain {
156156
*/
157157
domain_name: string;
158158
/**
159-
* Is domain global address list active or not, it enables shared contacts across domain in SOGo webmail
159+
* Is domain global address list active or not, it enables shared contacts across domain in SOGo webmail
160160
*/
161161
gal: boolean;
162162
/**
@@ -366,7 +366,7 @@ export interface MailboxDeleteRequest {
366366
/**
367367
* Attributes of the mailbox you can edit.
368368
*/
369-
export interface MailboxEditAttributes extends BaseMailboxAttributes {
369+
export interface MailboxEditAttributes extends BaseMailboxAttributes {
370370
/**
371371
* List of allowed send from addresses.
372372
*/
@@ -723,7 +723,7 @@ export interface AliasEditRequest {
723723
/**
724724
* List of IDs of the aliases to update.
725725
*/
726-
items: number[];
726+
items: number | number[];
727727
/**
728728
* The attributes to set.
729729
*/
@@ -783,6 +783,163 @@ export interface Alias extends AliasAttributes {
783783
modified: string | null
784784
}
785785

786+
/**
787+
* All the attributes of a sync job.
788+
*/
789+
export interface SyncjobAttributes {
790+
/**
791+
* Your local mailcow mailbox.
792+
*/
793+
username: string;
794+
/**
795+
* The smtp server where mails should be synced from.
796+
*/
797+
host1: string;
798+
/**
799+
* The smtp port of the target mail server.
800+
*/
801+
port1: number;
802+
/**
803+
* The password of the mailbox.
804+
*/
805+
password1: string;
806+
/**
807+
* The target email account.
808+
*/
809+
user1: string,
810+
/**
811+
* The encryption method used to connect to the mailserver.
812+
*/
813+
enc1: "TLS" | "SSL" | "PLAIN";
814+
/**
815+
* The interval in which messages should be synced.
816+
*/
817+
mins_interval: number;
818+
/**
819+
* Sync into subfolder on destination (empty = do not use subfolder).
820+
*/
821+
subfolder2: string;
822+
/**
823+
* Only sync messages up to this age in days.
824+
*/
825+
maxage: number;
826+
/**
827+
* Max speed transfer limit for the sync.
828+
*/
829+
maxbytespersecond: number;
830+
/**
831+
* Timeout for connection to remote host.
832+
*/
833+
timeout1: number;
834+
/**
835+
* Timeout for connection to local host.
836+
*/
837+
timeout2: number;
838+
/**
839+
* Exclude objects (regex).
840+
*/
841+
exclude: string;
842+
/**
843+
* Custom parameters.
844+
*/
845+
custom_params: string;
846+
/**
847+
* Delete duplicates on destination (--delete2duplicates).
848+
*/
849+
delete2duplicates: boolean;
850+
/**
851+
* Delete from source when completed (--delete1).
852+
*/
853+
delete1: boolean;
854+
/**
855+
* Delete messages on destination that are not on source (--delete2).
856+
*/
857+
delete2: boolean;
858+
/**
859+
* Try to automap folders ("sent items", "sent" => "sent" etc.) (--automap).
860+
*/
861+
automap: boolean;
862+
/**
863+
* Skip duplicate messages across folders (first come, first serve) (--skipcrossduplicates).
864+
*/
865+
skipcrossduplicates: boolean;
866+
/**
867+
* Subscribe all folders (--subscribeall).
868+
*/
869+
subscribeall: boolean;
870+
/**
871+
* Enables or disables the sync job.
872+
*/
873+
active: boolean;
874+
}
875+
876+
/**
877+
* Sync job creation payload.
878+
*/
879+
export type SyncjobPostRequest = SyncjobAttributes
880+
881+
/**
882+
* Sync job delete payload.
883+
*/
884+
export interface SyncjobDeleteRequest {
885+
/**
886+
* Array of IDs to delete.
887+
*/
888+
items: number[]
889+
}
890+
891+
export type SyncjobEditAttributes = Partial<SyncjobAttributes>
892+
893+
/**
894+
* Sync job update payload.
895+
*/
896+
export interface SyncjobUpdateRequest {
897+
/**
898+
* The attributes to set.
899+
*/
900+
attr: SyncjobEditAttributes
901+
/**
902+
* List of IDs to update.
903+
*/
904+
items: number | number[]
905+
}
906+
907+
/**
908+
* Sync job as returned by the Mailcow API.
909+
*/
910+
export interface Syncjob {
911+
active: boolean,
912+
authmd51: boolean,
913+
authmech1: "TLS" | "SSL" | "PLAIN",
914+
automap: boolean,
915+
created: string,
916+
custom_params: string,
917+
delete1: boolean,
918+
delete2: boolean,
919+
delete2duplicates: boolean,
920+
domain2: string,
921+
enc1: "TLS" | "SSL" | "PLAIN",
922+
exclude: string,
923+
host1: string,
924+
id: number,
925+
is_running: boolean,
926+
last_run: string,
927+
log: string,
928+
maxage: number,
929+
maxbytespersecond: number,
930+
mins_interval: number,
931+
modified: string,
932+
port1: number,
933+
regextrans2: string,
934+
skipcrossduplicates: boolean,
935+
subfolder2: string,
936+
subscribeall: boolean
937+
timeout1: number,
938+
timeout2: number,
939+
user1: string,
940+
user2: string
941+
}
942+
786943
/**
787944
* Error class used for exception handling.
788945
*/

0 commit comments

Comments
 (0)