-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsellauth.js
40 lines (35 loc) · 1.23 KB
/
sellauth.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
const axios = require('axios');
const modules = require('./src');
class SellAuthClient {
constructor({ apiKey, baseURL = 'https://api.sellauth.com' }) {
if (!apiKey) {
throw new Error('API key is required');
}
this.apiKey = apiKey;
this.baseURL = baseURL;
// Initialize each module and attach to the SellAuthClient instance
Object.keys(modules).forEach(moduleName => {
this[moduleName.toLowerCase()] = new modules[moduleName](this);
});
}
// Centralized request method
async request({ method, endpoint, data = {}, params = {} }) {
try {
const response = await axios({
method,
url: `${this.baseURL}${endpoint}`,
headers: {
'Authorization': `Bearer ${this.apiKey}`,
'Content-Type': 'application/json'
},
data,
params
});
return response.data;
} catch (error) {
console.error('Error with API request:', error.response?.data || error.message);
throw error;
}
}
}
module.exports = SellAuthClient;