@vouchfor/sdk 1.1.22 → 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.
@@ -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;
@@ -20,7 +20,12 @@ function parseHttpHeaders(headers) {
20
20
  }, {});
21
21
  }
22
22
 
23
- function logHttpResponse({ req, res, body, result, logger }) {
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';
@@ -37,7 +42,8 @@ function logHttpResponse({ req, res, body, result, logger }) {
37
42
  const payload = binary ? `<<< ${content} content} >>>` : result;
38
43
  const response = `HTTP/${httpVersion} ${statusCode} ${statusMessage}\r\n`
39
44
  + headers.join(`\r\n`) + `\r\n\r\n` + payload + `\r\n`;
40
- logger.info(`${(protocol + ' ' + method).toUpperCase()} request to host: ${host}\n`
45
+ const action = (protocol + ' ' + method).toUpperCase();
46
+ logger.info(`${action} request to host: ${host} ++ ${elapsed}\n`
41
47
  + `>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n`
42
48
  + request
43
49
  + `<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n`
@@ -45,7 +51,8 @@ function logHttpResponse({ req, res, body, result, logger }) {
45
51
  + `>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>`);
46
52
  }
47
53
 
48
- function logHttpError({ req, err, body, logger }) {
54
+ function logHttpError({ req, err, body, start, logger }) {
55
+ const elapsed = elapsedTimeInSeconds(start);
49
56
  const { protocol, method, host, _header: header } = req._currentRequest;
50
57
  const res = { headers: parseHttpHeaders(header) };
51
58
  const get = req.type === 'GET';
@@ -53,7 +60,8 @@ function logHttpError({ req, err, body, logger }) {
53
60
  const data = (typeof body === 'object' ? JSON.stringify(body) : body || '') + '\n';
54
61
  const request = header + (get ? '' : data);
55
62
  const error = err + `\r\n`;
56
- logger.info(`${(protocol + ' ' + method).toUpperCase()} request to host: ${host}\n`
63
+ const action = (protocol + ' ' + method).toUpperCase();
64
+ logger.info(`${action} request to host: ${host} ++ ${elapsed}\n`
57
65
  + `>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n`
58
66
  + request
59
67
  + `<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n`
@@ -70,6 +78,7 @@ module.exports = {
70
78
  const { protocol, hostname, port, pathname, search = '' } = new URL(url);
71
79
 
72
80
  return new Promise((resolve, reject) => {
81
+ const start = Date.now();
73
82
  let result = '';
74
83
  const req = (protocol === 'https:' ? https : http)
75
84
  .request({
@@ -86,7 +95,7 @@ module.exports = {
86
95
  res.on('end', () => {
87
96
  try {
88
97
  if (logger) {
89
- logHttpResponse({ req, res, body, result, logger });
98
+ logHttpResponse({ req, res, body, result, start, logger });
90
99
  }
91
100
 
92
101
  if (res.statusCode >= 400) {
@@ -110,7 +119,7 @@ module.exports = {
110
119
  )
111
120
  .on('error', (err) => {
112
121
  if (logger) {
113
- logHttpError({ req, err, body, logger });
122
+ logHttpError({ req, err, body, start, logger });
114
123
  }
115
124
  reject(err);
116
125
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vouchfor/sdk",
3
- "version": "1.1.22",
3
+ "version": "1.1.23",
4
4
  "description": "Vouch API SDK",
5
5
  "main": "lib/index.js",
6
6
  "repository": {