@vouchfor/sdk 1.1.21 → 1.1.23
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.
|
@@ -15,8 +15,8 @@ class IntegrationService extends BaseIntegrationService {
|
|
|
15
15
|
|
|
16
16
|
authenticate({ applicationId, entityId, mappingId }) {
|
|
17
17
|
if (applicationId) {
|
|
18
|
-
const
|
|
19
|
-
return this._request({ path: `applications/${applicationId}/entity` +
|
|
18
|
+
const path = entityId ? `/${entityId}` : '';
|
|
19
|
+
return this._request({ path: `applications/${applicationId}/entity` + path });
|
|
20
20
|
} else if (entityId) {
|
|
21
21
|
return this._request({ path: `entities/${entityId}` });
|
|
22
22
|
} else if (mappingId) {
|
|
@@ -32,6 +32,14 @@ class EntityService extends BaseRestService {
|
|
|
32
32
|
media(id, apiKey) {
|
|
33
33
|
return this._request({ apiKey, path: `${id}/media` });
|
|
34
34
|
}
|
|
35
|
+
|
|
36
|
+
brand(id, apiKey) {
|
|
37
|
+
return this._request({ apiKey, path: `${id}/brand` });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
users(id, apiKey) {
|
|
41
|
+
return this._request({ apiKey, path: `${id}/users` });
|
|
42
|
+
}
|
|
35
43
|
}
|
|
36
44
|
|
|
37
45
|
module.exports = EntityService;
|
|
@@ -21,8 +21,12 @@ class VouchService extends BaseRestService {
|
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
get(id, apiKey) {
|
|
25
|
-
|
|
24
|
+
get(id, apiKey, media = false) {
|
|
25
|
+
const query = media ? '?media=true' : ''
|
|
26
|
+
return this._request({
|
|
27
|
+
apiKey,
|
|
28
|
+
path: `${id}`+ query
|
|
29
|
+
});
|
|
26
30
|
}
|
|
27
31
|
|
|
28
32
|
counts(id, apiKey) {
|
package/lib/shared/utils.js
CHANGED
|
@@ -20,12 +20,16 @@ function parseHttpHeaders(headers) {
|
|
|
20
20
|
}, {});
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
function
|
|
23
|
+
function elapsedTimeInSeconds(start) {
|
|
24
|
+
return ((Date.now() - start) / 1000).toFixed(3) + 's';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function logHttpResponse({ req, res, body, result, start, logger }) {
|
|
28
|
+
const elapsed = elapsedTimeInSeconds(start);
|
|
24
29
|
const { protocol, method, host, _header: header } = req._currentRequest;
|
|
25
30
|
const get = req.type === 'GET';
|
|
26
31
|
const type = res.headers['content-type'] ?? 'application/json';
|
|
27
|
-
const
|
|
28
|
-
const data = (json && body ? JSON.stringify(body) : body || '') + '\n';
|
|
32
|
+
const data = (typeof body === 'object' ? JSON.stringify(body) : body || '') + '\n';
|
|
29
33
|
const request = header + (get ? '' : data);
|
|
30
34
|
const { httpVersion, statusCode, statusMessage } = res;
|
|
31
35
|
const headers = [];
|
|
@@ -38,7 +42,8 @@ function logHttpResponse({ req, res, body, result, logger }) {
|
|
|
38
42
|
const payload = binary ? `<<< ${content} content} >>>` : result;
|
|
39
43
|
const response = `HTTP/${httpVersion} ${statusCode} ${statusMessage}\r\n`
|
|
40
44
|
+ headers.join(`\r\n`) + `\r\n\r\n` + payload + `\r\n`;
|
|
41
|
-
|
|
45
|
+
const action = (protocol + ' ' + method).toUpperCase();
|
|
46
|
+
logger.info(`${action} request to host: ${host} ++ ${elapsed}\n`
|
|
42
47
|
+ `>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n`
|
|
43
48
|
+ request
|
|
44
49
|
+ `<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n`
|
|
@@ -46,16 +51,17 @@ function logHttpResponse({ req, res, body, result, logger }) {
|
|
|
46
51
|
+ `>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>`);
|
|
47
52
|
}
|
|
48
53
|
|
|
49
|
-
function logHttpError({ req, err, body, logger }) {
|
|
54
|
+
function logHttpError({ req, err, body, start, logger }) {
|
|
55
|
+
const elapsed = elapsedTimeInSeconds(start);
|
|
50
56
|
const { protocol, method, host, _header: header } = req._currentRequest;
|
|
51
57
|
const res = { headers: parseHttpHeaders(header) };
|
|
52
58
|
const get = req.type === 'GET';
|
|
53
59
|
const type = res.headers['content-type'] ?? 'application/json';
|
|
54
|
-
const
|
|
55
|
-
const data = (json && body ? JSON.stringify(body) : body || '') + '\n';
|
|
60
|
+
const data = (typeof body === 'object' ? JSON.stringify(body) : body || '') + '\n';
|
|
56
61
|
const request = header + (get ? '' : data);
|
|
57
62
|
const error = err + `\r\n`;
|
|
58
|
-
|
|
63
|
+
const action = (protocol + ' ' + method).toUpperCase();
|
|
64
|
+
logger.info(`${action} request to host: ${host} ++ ${elapsed}\n`
|
|
59
65
|
+ `>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n`
|
|
60
66
|
+ request
|
|
61
67
|
+ `<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n`
|
|
@@ -72,6 +78,7 @@ module.exports = {
|
|
|
72
78
|
const { protocol, hostname, port, pathname, search = '' } = new URL(url);
|
|
73
79
|
|
|
74
80
|
return new Promise((resolve, reject) => {
|
|
81
|
+
const start = Date.now();
|
|
75
82
|
let result = '';
|
|
76
83
|
const req = (protocol === 'https:' ? https : http)
|
|
77
84
|
.request({
|
|
@@ -88,7 +95,7 @@ module.exports = {
|
|
|
88
95
|
res.on('end', () => {
|
|
89
96
|
try {
|
|
90
97
|
if (logger) {
|
|
91
|
-
logHttpResponse({ req, res, body, result, logger });
|
|
98
|
+
logHttpResponse({ req, res, body, result, start, logger });
|
|
92
99
|
}
|
|
93
100
|
|
|
94
101
|
if (res.statusCode >= 400) {
|
|
@@ -112,7 +119,7 @@ module.exports = {
|
|
|
112
119
|
)
|
|
113
120
|
.on('error', (err) => {
|
|
114
121
|
if (logger) {
|
|
115
|
-
logHttpError({ req, err, body, logger });
|
|
122
|
+
logHttpError({ req, err, body, start, logger });
|
|
116
123
|
}
|
|
117
124
|
reject(err);
|
|
118
125
|
});
|