@k03mad/request 1.3.3 → 2.0.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.
- package/app/lib/request.js +17 -24
- package/package.json +1 -1
- package/.github/workflows/publish.yml +0 -41
package/app/lib/request.js
CHANGED
|
@@ -10,28 +10,23 @@ const debug = _debug('mad:request');
|
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* @param {object} opts
|
|
13
|
-
* @returns {object}
|
|
14
13
|
*/
|
|
15
14
|
const prepareRequestOpts = (opts = {}) => {
|
|
16
15
|
const UA = 'curl/8.1.2';
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (preparedOpts.dnsCache === undefined) {
|
|
21
|
-
preparedOpts.dnsCache = true;
|
|
17
|
+
if (opts.dnsCache === undefined) {
|
|
18
|
+
opts.dnsCache = true;
|
|
22
19
|
}
|
|
23
20
|
|
|
24
|
-
if (!
|
|
25
|
-
|
|
21
|
+
if (!opts.timeout) {
|
|
22
|
+
opts.timeout = {request: 15_000};
|
|
26
23
|
}
|
|
27
24
|
|
|
28
|
-
if (!
|
|
29
|
-
|
|
30
|
-
} else if (!
|
|
31
|
-
|
|
25
|
+
if (!opts.headers) {
|
|
26
|
+
opts.headers = {'user-agent': UA};
|
|
27
|
+
} else if (!opts.headers['user-agent']) {
|
|
28
|
+
opts.headers['user-agent'] = UA;
|
|
32
29
|
}
|
|
33
|
-
|
|
34
|
-
return preparedOpts;
|
|
35
30
|
};
|
|
36
31
|
|
|
37
32
|
/**
|
|
@@ -41,21 +36,21 @@ const prepareRequestOpts = (opts = {}) => {
|
|
|
41
36
|
* @returns {object}
|
|
42
37
|
*/
|
|
43
38
|
const sendRequest = async (url, opts) => {
|
|
44
|
-
|
|
39
|
+
prepareRequestOpts(opts);
|
|
45
40
|
|
|
46
41
|
try {
|
|
47
|
-
const response = await got(url,
|
|
42
|
+
const response = await got(url, opts);
|
|
48
43
|
|
|
49
|
-
if (!
|
|
44
|
+
if (!opts.responseType) {
|
|
50
45
|
try {
|
|
51
46
|
response.body = JSON.parse(response.body);
|
|
52
47
|
} catch {}
|
|
53
48
|
}
|
|
54
49
|
|
|
55
|
-
debug(getCurl(url,
|
|
50
|
+
debug(getCurl(url, opts, response));
|
|
56
51
|
return response;
|
|
57
52
|
} catch (err) {
|
|
58
|
-
debug(getCurl(url,
|
|
53
|
+
debug(getCurl(url, opts, err));
|
|
59
54
|
|
|
60
55
|
err.__pretty = {};
|
|
61
56
|
|
|
@@ -66,9 +61,7 @@ const sendRequest = async (url, opts) => {
|
|
|
66
61
|
err?.response?.ip ? `(${err.response.ip})` : '',
|
|
67
62
|
].join(' ');
|
|
68
63
|
|
|
69
|
-
|
|
70
|
-
err.__pretty.opts = opts;
|
|
71
|
-
}
|
|
64
|
+
err.__pretty.opts = opts;
|
|
72
65
|
|
|
73
66
|
if (err?.response?.body) {
|
|
74
67
|
try {
|
|
@@ -117,7 +110,7 @@ export const requestCache = (url, opts = {}, {cacheBy, expire = 43_200} = {}) =>
|
|
|
117
110
|
const queue = getQueue(new URL(url).host, opts.method);
|
|
118
111
|
|
|
119
112
|
return queue.add(async () => {
|
|
120
|
-
|
|
113
|
+
prepareRequestOpts(opts);
|
|
121
114
|
|
|
122
115
|
const cacheGotResponseKeys = [
|
|
123
116
|
'body',
|
|
@@ -128,7 +121,7 @@ export const requestCache = (url, opts = {}, {cacheBy, expire = 43_200} = {}) =>
|
|
|
128
121
|
'timings',
|
|
129
122
|
];
|
|
130
123
|
|
|
131
|
-
const cacheKey = `${url}::${JSON.stringify(cacheBy ||
|
|
124
|
+
const cacheKey = `${url}::${JSON.stringify(cacheBy || opts)}`;
|
|
132
125
|
const log = `${blue(url)}\n${dim(cacheKey)}`;
|
|
133
126
|
|
|
134
127
|
try {
|
|
@@ -151,7 +144,7 @@ export const requestCache = (url, opts = {}, {cacheBy, expire = 43_200} = {}) =>
|
|
|
151
144
|
debug(`${red('CACHE ERROR')} :: ${dim(err)} :: ${log}`);
|
|
152
145
|
}
|
|
153
146
|
|
|
154
|
-
const res = await request(url,
|
|
147
|
+
const res = await request(url, opts, {skipQueue: true});
|
|
155
148
|
|
|
156
149
|
const cachedResponse = {};
|
|
157
150
|
|
package/package.json
CHANGED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
name: Publish
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches:
|
|
6
|
-
- master
|
|
7
|
-
paths:
|
|
8
|
-
- '**.js'
|
|
9
|
-
|
|
10
|
-
jobs:
|
|
11
|
-
eslint:
|
|
12
|
-
name: Publish
|
|
13
|
-
environment: npm
|
|
14
|
-
runs-on: ubuntu-latest
|
|
15
|
-
steps:
|
|
16
|
-
- name: Checkout
|
|
17
|
-
uses: actions/checkout@v3
|
|
18
|
-
|
|
19
|
-
- name: Install NodeJS
|
|
20
|
-
uses: actions/setup-node@v3
|
|
21
|
-
with:
|
|
22
|
-
node-version-file: '.nvmrc'
|
|
23
|
-
|
|
24
|
-
- name: Install dependencies
|
|
25
|
-
run: npm ci
|
|
26
|
-
|
|
27
|
-
- name: Set credentials
|
|
28
|
-
run: git config user.email "auto@action.autoaction_1" && git config user.name "Action"
|
|
29
|
-
|
|
30
|
-
- name: Update version
|
|
31
|
-
run: npm version patch
|
|
32
|
-
|
|
33
|
-
- name: Publish version
|
|
34
|
-
uses: JS-DevTools/npm-publish@v2
|
|
35
|
-
with:
|
|
36
|
-
token: ${{ secrets.NPM_TOKEN }}
|
|
37
|
-
|
|
38
|
-
- name: Create PR
|
|
39
|
-
uses: peter-evans/create-pull-request@v5
|
|
40
|
-
with:
|
|
41
|
-
title: Patch package version
|