-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
76 lines (68 loc) · 2.28 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const axios = require('axios');
const AliasService = require('./services/alias');
const AlternativeService = require('./services/alternative');
const DomainService = require('./services/domain');
const RelayService = require('./services/relay');
const UserService = require('./services/user');
/**
* Client for the Mailu API.
*
* @param {string} endpoint Base URL of the Mailu API.
* @param {string} apiKey Authorization key for the Mailu API.
*/
class MailuClient{
/**
* Creates an instance of the MailuClient.
* @param {string} endpoint - Base URL of the Mailu API.
* @param {string} apiKey - Authorization key for the Mailu API.
*/
constructor(endpoint, apiKey){
this.apiKey = apiKey;
this.endpoint = endpoint;
/**
* Provides methods for interacting with Mailu aliases.
* @type {AliasService}
*/
this.aliasService = new AliasService(this);
/**
* Provides methods for interacting with Mailu alternative addresses.
* @type {AlternativeService}
*/
this.alternativeService = new AlternativeService(this);
/**
* Provides methods for interacting with Mailu domains.
* @type {DomainService}
*/
this.domainService = new DomainService(this);
/**
* Provides methods for interacting with Mailu relays.
* @type {RelayService}
*/
this.relayService = new RelayService(this);
/**
* Provides methods for interacting with Mailu users.
* @type {UserService}
*/
this.userService = new UserService(this);
}
/**
* Makes a request to the Mailu API using Axios.
*
* @param {string} method HTTP method ('get', 'post', 'patch', 'delete', etc.).
* @param {string} path Path of the API endpoint (e.g., '/user').
* @param {object} data (optional) Request body.
* @returns {Promise} Promise with the API response.
*/
useAxios(method, path, data){
return axios({
method,
url: this.endpoint + path,
headers: {
'Authorization': `Bearer ${this.apiKey}`,
'Content-Type': 'application/json'
},
data
})
};
};
module.exports = MailuClient;