@k03mad/request 5.0.0 → 5.1.0

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.
Files changed (2) hide show
  1. package/app/lib/curl.js +13 -18
  2. package/package.json +2 -2
package/app/lib/curl.js CHANGED
@@ -24,27 +24,22 @@ export default (url, {
24
24
  }, res) => {
25
25
  const msg = [];
26
26
 
27
- let urlClone = url;
28
- let resClone = structuredClone(res);
27
+ const fullUrl = searchParams
28
+ ? `${url}?${new URLSearchParams(searchParams).toString()}`
29
+ : url;
29
30
 
30
- if (resClone?.response) {
31
- resClone = resClone.response;
32
- }
33
-
34
- if (resClone?.statusCode) {
35
- msg.push(bgWhite(black(resClone.statusCode)));
36
- }
31
+ const response = res?.response || res;
37
32
 
38
- if (resClone?.timings) {
39
- msg.push(`[${resClone.timings.phases.total} ms]`);
33
+ if (response.statusCode) {
34
+ msg.push(bgWhite(black(response.statusCode)));
40
35
  }
41
36
 
42
- if (resClone?.headers?.['content-length']) {
43
- msg.push(`[${prettyBytes(Number(resClone.headers['content-length']))}]`);
37
+ if (response.timings) {
38
+ msg.push(`[${response.timings.phases.total} ms]`);
44
39
  }
45
40
 
46
- if (searchParams) {
47
- urlClone += `?${new URLSearchParams(searchParams).toString()}`;
41
+ if (response.headers?.['content-length']) {
42
+ msg.push(`[${prettyBytes(Number(response.headers['content-length']))}]`);
48
43
  }
49
44
 
50
45
  msg.push(white('curl -v -X'), green(method));
@@ -53,7 +48,7 @@ export default (url, {
53
48
  msg.push(dim(red(`-u ${username}:${password}`)));
54
49
  }
55
50
 
56
- msg.push(blue(urlClone));
51
+ msg.push(blue(fullUrl));
57
52
 
58
53
  let bodyParams;
59
54
 
@@ -77,8 +72,8 @@ export default (url, {
77
72
  msg.push(dim(yellow(bodyParams)));
78
73
  }
79
74
 
80
- if (resClone) {
81
- const message = JSON.stringify(resClone.body || resClone.message);
75
+ if (response) {
76
+ const message = JSON.stringify(response.body || response.message);
82
77
 
83
78
  if (message?.length < 1500) {
84
79
  msg.push(`\n${dim(green(message))}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@k03mad/request",
3
- "version": "5.0.0",
3
+ "version": "5.1.0",
4
4
  "description": "Request library",
5
5
  "maintainers": [
6
6
  "Kirill Molchanov <k03.mad@gmail.com"
@@ -20,7 +20,7 @@
20
20
  "pretty-bytes": "6.1.1"
21
21
  },
22
22
  "devDependencies": {
23
- "@k03mad/eslint-config": "17.10.0",
23
+ "@k03mad/eslint-config": "17.11.0",
24
24
  "eslint": "8.56.0",
25
25
  "husky": "8.0.3"
26
26
  },