@nxtedition/nxt-undici 6.2.36 → 6.3.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/lib/index.js CHANGED
@@ -6,6 +6,7 @@ import { SqliteCacheStore } from './sqlite-cache-store.js'
6
6
  const dispatcherCache = new WeakMap()
7
7
 
8
8
  export const interceptors = {
9
+ query: (await import('./interceptor/query.js')).default,
9
10
  requestBodyFactory: (await import('./interceptor/request-body-factory.js')).default,
10
11
  responseError: (await import('./interceptor/response-error.js')).default,
11
12
  responseRetry: (await import('./interceptor/response-retry.js')).default,
@@ -92,6 +93,7 @@ function wrapDispatch(dispatcher) {
92
93
  interceptors.log({ bindings: { intercept: 'downstream' } }),
93
94
  interceptors.requestId(),
94
95
  interceptors.responseError(),
96
+ interceptors.query(),
95
97
  (dispatch) => (opts, handler) => {
96
98
  const headers = parseHeaders(opts.headers)
97
99
 
@@ -0,0 +1,25 @@
1
+ import { stringify } from 'fast-querystring'
2
+
3
+ export default () => (dispatch) => (opts, handler) => {
4
+ if (!opts.query) {
5
+ return dispatch(opts, handler)
6
+ }
7
+
8
+ const { query, path, ...rest } = opts
9
+
10
+ dispatch({ ...rest, path: serializePathWithQuery(path, query) })
11
+ }
12
+
13
+ function serializePathWithQuery(url, queryParams) {
14
+ if (url.includes('?') || url.includes('#')) {
15
+ throw new Error('Query params cannot be passed when url already contains "?" or "#".')
16
+ }
17
+
18
+ const stringified = stringify(queryParams)
19
+
20
+ if (stringified) {
21
+ url += '?' + stringified
22
+ }
23
+
24
+ return url
25
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/nxt-undici",
3
- "version": "6.2.36",
3
+ "version": "6.3.0",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "main": "lib/index.js",
@@ -11,6 +11,7 @@
11
11
  "dependencies": {
12
12
  "@nxtedition/undici": "^11.0.0",
13
13
  "cache-control-parser": "^2.0.6",
14
+ "fast-querystring": "^1.1.2",
14
15
  "http-errors": "^2.0.0"
15
16
  },
16
17
  "devDependencies": {