-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (37 loc) · 1.18 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
const {Catalog} = require("./src/api");
const defaultConfig = require("./config");
const Client = require("./src/client");
const Limiter = require("./src/limiter");
function makeClient(baseUrl, apiKey, jwt, limiter, requestTimeout) {
return new Client(
baseUrl,
{
Accept: 'application/json',
'x-api-key': apiKey,
Authorization: `Bearer ${jwt}`,
},
limiter,
requestTimeout,
);
}
class StockxApi {
constructor(apiKey, jwt, config = undefined) {
this.apiKey = apiKey;
this.jwt = jwt;
this.config = config ? {...defaultConfig, ...config} : defaultConfig;
this.limiter = new Limiter(
this.config.requestRateLimitMinTime,
this.config.requestRateLimitReservoirAmount,
this.config.requestRateLimitReservoirRefreshCronExpression,
);
this.initResources(makeClient(this.config.baseUrl, this.apiKey, this.jwt, this.limiter, this.config.requestTimeout));
}
initResources(client) {
this.catalog = new Catalog(client);
}
updateJwt(jwt) {
this.jwt = jwt;
this.initResources(makeClient(this.config.baseUrl, this.apiKey, this.jwt, this.limiter, this.config.requestTimeout));
}
}
module.exports = StockxApi;