Skip to content

Commit 2c8f111

Browse files
committed
chore: move types to index
1 parent 98782ff commit 2c8f111

13 files changed

+136
-132
lines changed

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,5 @@ dist
117117
.yarn/build-state.yml
118118
.yarn/install-state.gz
119119
.pnp.*
120-
docs
120+
docs
121+
src

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,15 @@
2424
"homepage": "https://github.com/JustSamuel/ts-mailcow-api#readme",
2525
"author": "Samuel",
2626
"files": [
27-
"src",
28-
"dist",
29-
"index.js"
27+
"dist"
3028
],
29+
"main": "dist/index.js",
30+
"types": "dist/index.d.ts",
3131
"keywords": [
3232
"mailcow",
3333
"typescript",
3434
"API"
3535
],
36-
"typings": "./dist/index.d.ts",
3736
"license": "ISC",
3837
"devDependencies": {
3938
"@gewis/eslint-config-typescript": "^2.4.0",

src/client.ts

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/**
2+
* @module MailcowClient
3+
*/
4+
5+
import { AxiosRequestConfig } from 'axios';
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+
import RequestFactory from './request-factory';
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';
14+
import { addressRewritingEndpoints, AdressRewritingEndpoints } from './endpoints/address-rewriting-endpoint';
15+
import { Fail2BanEndpoints, fail2BanEndpoints } from './endpoints/fail2ban-endpoints';
16+
17+
/**
18+
* Class containing all the logic to interface with the Mailcow API in TypeScript.
19+
* @external
20+
*/
21+
class MailcowClient {
22+
/**
23+
* The base URL of the Mailcow API.
24+
* @internal
25+
*/
26+
readonly BASE_URL: string;
27+
28+
/**
29+
* The API key of the Mailcow API.
30+
* @internal
31+
*/
32+
readonly API_KEY: string;
33+
34+
/**
35+
* The request config used for every request.
36+
* @internal
37+
*/
38+
AXIOS_CONFIG: AxiosRequestConfig;
39+
40+
/**
41+
* Creates a MailcowClient using the given URL and API key.
42+
* @param BASE_URL - The base URL of the Mailcow API.
43+
* @param API_KEY - The API key of the Mailcow API.
44+
* @param EXTRA_AXIOS_CONFIG - Allows for setting extra Axios request config such as keep alive.
45+
*/
46+
constructor(BASE_URL: string, API_KEY: string, EXTRA_AXIOS_CONFIG?: AxiosRequestConfig) {
47+
this.BASE_URL = BASE_URL.charAt(BASE_URL.length - 1) === '/' ? BASE_URL : BASE_URL.concat('/');
48+
this.API_KEY = API_KEY;
49+
50+
// Set the correct Axios request config.
51+
this.AXIOS_CONFIG = {
52+
...EXTRA_AXIOS_CONFIG,
53+
headers: {
54+
'Content-Type': 'application/json',
55+
'X-API-Key': this.API_KEY,
56+
},
57+
};
58+
}
59+
60+
/**
61+
* Factory method pattern for creating HTTP requests.
62+
* @internal
63+
*/
64+
public requestFactory = new RequestFactory(this);
65+
66+
/**
67+
* All endpoints related to Aliases.
68+
* See {@link AliasEndpoints}
69+
*/
70+
public aliases: AliasEndpoints = aliasEndpoints(this);
71+
72+
/**
73+
* All endpoints related to Domains.
74+
* See {@link DomainEndpoints}
75+
* @external
76+
*/
77+
public domains: DomainEndpoints = domainEndpoints(this);
78+
79+
/**
80+
* All endpoints related to spam policies.
81+
* See {@link AntiSpamEndpoints}
82+
* @external
83+
*/
84+
public spamPolicy: AntiSpamEndpoints = antiSpamEndpoints(this);
85+
86+
/**
87+
* All endpoints related to mailboxes.
88+
* See {@link MailboxEndpoints}
89+
* @external
90+
*/
91+
public mailbox: MailboxEndpoints = mailboxEndpoints(this);
92+
93+
/**
94+
* All endpoints related to sync jobs.
95+
* See {@link SyncjobEndpoints}
96+
* @external
97+
*/
98+
public syncjobs: SyncjobEndpoints = syncjobEndpoints(this);
99+
100+
/**
101+
* All endpoints related to forwarding hosts.
102+
* See {@link ForwardingEndpoints}
103+
* @external
104+
*/
105+
public forwardingHosts: ForwardingEndpoints = forwardingEndpoints(this);
106+
107+
/**
108+
* All endpoints related to address rewriting.
109+
* See {@link AdressRewritingEndpoints}
110+
* @external
111+
*/
112+
public addressRewriting: AdressRewritingEndpoints = addressRewritingEndpoints(this);
113+
114+
/**
115+
* All endpoints related to logs.
116+
* See {@link LogEndpoints}
117+
* @external
118+
*/
119+
public logs: LogEndpoints = logEndpoints(this);
120+
121+
/**
122+
* All endpoints related to fail2ban.
123+
* See {@link Fail2BanEndpoints}
124+
* @external
125+
*/
126+
public fail2Ban: Fail2BanEndpoints = fail2BanEndpoints(this);
127+
}
128+
129+
export default MailcowClient;
File renamed without changes.

0 commit comments

Comments
 (0)