@nxtedition/lib 14.1.8 → 14.1.10
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/package.json +2 -1
- package/rxjs/firstValueFrom.js +5 -0
- package/undici.js +21 -4
- package/util/template/index.js +3 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxtedition/lib",
|
|
3
|
-
"version": "14.1.
|
|
3
|
+
"version": "14.1.10",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Robert Nagy <robert.nagy@boffins.se>",
|
|
6
6
|
"files": [
|
|
@@ -82,6 +82,7 @@
|
|
|
82
82
|
"nconf": "^0.12.0",
|
|
83
83
|
"nested-error-stacks": "^2.1.1",
|
|
84
84
|
"object-hash": "^3.0.0",
|
|
85
|
+
"omit-empty": "^1.0.0",
|
|
85
86
|
"pino-std-serializers": "^6.2.2",
|
|
86
87
|
"qs": "^6.11.1",
|
|
87
88
|
"request-target": "^1.0.2",
|
package/rxjs/firstValueFrom.js
CHANGED
|
@@ -5,11 +5,16 @@ const { AbortError } = require('../errors')
|
|
|
5
5
|
module.exports = function firstValueFrom(x$, config) {
|
|
6
6
|
const hasConfig = config && typeof config === 'object'
|
|
7
7
|
const signal = hasConfig ? config.signal : undefined
|
|
8
|
+
const timeout = hasConfig ? config.timeout : undefined
|
|
8
9
|
|
|
9
10
|
if (signal) {
|
|
10
11
|
x$ = signal.aborted ? rxjs.EMPTY : x$.pipe(rx.takeUntil(rxjs.fromEvent(signal, 'abort')))
|
|
11
12
|
x$ = x$.pipe(rx.throwIfEmpty(() => new AbortError()))
|
|
12
13
|
}
|
|
13
14
|
|
|
15
|
+
if (timeout) {
|
|
16
|
+
x$ = x$.pipe(rx.timeout(timeout))
|
|
17
|
+
}
|
|
18
|
+
|
|
14
19
|
return x$.pipe(rx.first(hasConfig ? config.defaultValue : undefined)).toPromise()
|
|
15
20
|
}
|
package/undici.js
CHANGED
|
@@ -4,14 +4,16 @@ const xuid = require('xuid')
|
|
|
4
4
|
const { isReadableNodeStream } = require('./stream')
|
|
5
5
|
const undici = require('undici')
|
|
6
6
|
const stream = require('stream')
|
|
7
|
+
const omitEmpty = require('omit-empty')
|
|
7
8
|
|
|
8
9
|
module.exports.request = async function request(
|
|
9
10
|
url,
|
|
10
11
|
{
|
|
11
12
|
logger,
|
|
12
13
|
id = xuid(),
|
|
13
|
-
retry
|
|
14
|
-
|
|
14
|
+
retry,
|
|
15
|
+
maxRedirections: _maxRedirections,
|
|
16
|
+
redirect,
|
|
15
17
|
dispatcher,
|
|
16
18
|
signal,
|
|
17
19
|
headersTimeout,
|
|
@@ -23,15 +25,30 @@ module.exports.request = async function request(
|
|
|
23
25
|
headers,
|
|
24
26
|
}
|
|
25
27
|
) {
|
|
28
|
+
if (retry === false) {
|
|
29
|
+
retry = { count: 0 }
|
|
30
|
+
} else if (typeof retry === 'number') {
|
|
31
|
+
retry = { count: retry }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (redirect === false) {
|
|
35
|
+
redirect = { count: 0 }
|
|
36
|
+
} else if (typeof redirect === 'number') {
|
|
37
|
+
redirect = { count: redirect }
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const { count: maxRedirections = _maxRedirections ?? 3 } = redirect ?? {}
|
|
41
|
+
const { count: maxRetries = 8, status = [] } = retry ?? {}
|
|
42
|
+
|
|
26
43
|
const ureq = {
|
|
27
44
|
url,
|
|
28
45
|
method,
|
|
29
46
|
body,
|
|
30
|
-
headers: {
|
|
47
|
+
headers: omitEmpty({
|
|
31
48
|
'request-id': id,
|
|
32
49
|
'user-agent': userAgent,
|
|
33
50
|
...headers,
|
|
34
|
-
},
|
|
51
|
+
}),
|
|
35
52
|
}
|
|
36
53
|
|
|
37
54
|
const upstreamLogger = logger?.child({ ureq })
|
package/util/template/index.js
CHANGED
|
@@ -6,6 +6,7 @@ const getJavascriptCompiler = require('./javascript')
|
|
|
6
6
|
const JSON5 = require('json5')
|
|
7
7
|
const objectHash = require('object-hash')
|
|
8
8
|
const weakCache = require('../../weakCache')
|
|
9
|
+
const firstValueFrom = require('../../rxjs/firstValueFrom')
|
|
9
10
|
|
|
10
11
|
module.exports = ({ ds, proxify }) => {
|
|
11
12
|
const compiler = {
|
|
@@ -226,8 +227,8 @@ module.exports = ({ ds, proxify }) => {
|
|
|
226
227
|
return hash ? compileTemplateCache(template, hash) : null
|
|
227
228
|
}
|
|
228
229
|
|
|
229
|
-
async function resolveTemplate(template, args
|
|
230
|
-
return
|
|
230
|
+
async function resolveTemplate(template, args$, options) {
|
|
231
|
+
return firstValueFrom(onResolveTemplate(template, args$), options)
|
|
231
232
|
}
|
|
232
233
|
|
|
233
234
|
function onResolveTemplate(template, args$) {
|