@vintr/node-sdk 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.d.ts +1 -1
- package/dist/client.js +19 -13
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
package/dist/client.js
CHANGED
|
@@ -1,28 +1,33 @@
|
|
|
1
|
-
import https from
|
|
1
|
+
import https from "https";
|
|
2
2
|
export class VintrClient {
|
|
3
3
|
constructor(apiKey) {
|
|
4
|
-
this.baseUrl =
|
|
4
|
+
this.baseUrl = "https://api.vintr.xyz";
|
|
5
5
|
this.apiKey = apiKey;
|
|
6
6
|
}
|
|
7
7
|
async request(path, headers) {
|
|
8
8
|
return new Promise((resolve, reject) => {
|
|
9
9
|
const url = new URL(path, this.baseUrl);
|
|
10
10
|
const defaultHeaders = {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
12
|
+
"Content-Type": "application/json",
|
|
13
|
+
};
|
|
14
|
+
const allHeaders = {
|
|
15
|
+
...defaultHeaders,
|
|
16
|
+
...headers,
|
|
13
17
|
};
|
|
14
|
-
const allHeaders = { ...defaultHeaders, ...headers };
|
|
15
18
|
const options = {
|
|
16
19
|
hostname: url.hostname,
|
|
17
20
|
port: url.port || 443,
|
|
18
21
|
path: url.pathname + url.search,
|
|
19
|
-
method:
|
|
22
|
+
method: "GET",
|
|
20
23
|
headers: allHeaders,
|
|
21
24
|
};
|
|
22
25
|
const req = https.request(options, (res) => {
|
|
23
|
-
let data =
|
|
24
|
-
res.on(
|
|
25
|
-
|
|
26
|
+
let data = "";
|
|
27
|
+
res.on("data", (chunk) => {
|
|
28
|
+
data += chunk;
|
|
29
|
+
});
|
|
30
|
+
res.on("end", () => {
|
|
26
31
|
try {
|
|
27
32
|
if (res.statusCode === 200) {
|
|
28
33
|
resolve(JSON.parse(data));
|
|
@@ -31,18 +36,19 @@ export class VintrClient {
|
|
|
31
36
|
reject(new Error(`HTTP ${res.statusCode}: ${data}`));
|
|
32
37
|
}
|
|
33
38
|
}
|
|
34
|
-
catch
|
|
39
|
+
catch {
|
|
35
40
|
reject(new Error(`Failed to parse response: ${data}`));
|
|
36
41
|
}
|
|
37
42
|
});
|
|
38
43
|
});
|
|
39
|
-
req.on(
|
|
44
|
+
req.on("error", reject);
|
|
40
45
|
req.end();
|
|
41
46
|
});
|
|
42
47
|
}
|
|
43
48
|
async resolveAlias(params) {
|
|
44
49
|
const url = new URL(`/${params.alias}`, this.baseUrl);
|
|
45
|
-
url.
|
|
46
|
-
|
|
50
|
+
return this.request(url.pathname, {
|
|
51
|
+
"X-Code": params.code,
|
|
52
|
+
});
|
|
47
53
|
}
|
|
48
54
|
}
|