From 7b594d54739603875187b760e6ae376df37b4b30 Mon Sep 17 00:00:00 2001 From: Mickael Chanrion Date: Tue, 28 Jun 2022 19:45:16 +0100 Subject: [PATCH 1/8] chore: update ky --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 411d4f3..7c3a22b 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "consola": "^2.15.0", "defu": "^3.2.2", "destr": "^1.0.1", - "ky": "^0.25.1", + "ky": "^0.31.0", "node-fetch": "^2.6.1", "web-streams-polyfill": "^3.0.1" }, diff --git a/yarn.lock b/yarn.lock index 0fc6792..ca9ce7c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6973,10 +6973,10 @@ kleur@^3.0.3: resolved "https://registry.yarnpkg.com/kleur/-/kleur-3.0.3.tgz#a79c9ecc86ee1ce3fa6206d1216c501f147fc07e" integrity sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w== -ky@^0.25.1: - version "0.25.1" - resolved "https://registry.yarnpkg.com/ky/-/ky-0.25.1.tgz#0df0bd872a9cc57e31acd5dbc1443547c881bfbc" - integrity sha512-PjpCEWlIU7VpiMVrTwssahkYXX1by6NCT0fhTUX34F3DTinARlgMpriuroolugFPcMgpPWrOW4mTb984Qm1RXA== +ky@^0.31.0: + version "0.31.0" + resolved "https://registry.yarnpkg.com/ky/-/ky-0.31.0.tgz#a982dcadf695482dab464e238030edeefea9021e" + integrity sha512-C27vqDb3vuxy4mi/x1wt9P1ES0QxEJg3CbPz2t3lTaQ4AvR/hkwES06yPdqol+q3hH+DrZKb/PKD+pAQkharNg== last-call-webpack-plugin@^3.0.0: version "3.0.0" From f162917ea10cf421b317b4be146c30399adb5395 Mon Sep 17 00:00:00 2001 From: Mickael Chanrion Date: Tue, 28 Jun 2022 19:45:38 +0100 Subject: [PATCH 2/8] fix: use defu to merge options --- lib/plugin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugin.js b/lib/plugin.js index 40e93fd..5c0ed4a 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -82,7 +82,7 @@ for (let method of ['get', 'head', 'delete', 'post', 'put', 'patch']) { } } - const _options = { ...this._defaults, ...options } + const _options = defu(this._defaults, options) if (/^https?/.test(url)) { delete _options.prefixUrl From 03702ad59bfc5d8979a76a972e54e71a6a109b91 Mon Sep 17 00:00:00 2001 From: Mickael Chanrion Date: Tue, 28 Jun 2022 19:50:43 +0100 Subject: [PATCH 3/8] fix: defu wrong params order --- lib/plugin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugin.js b/lib/plugin.js index 5c0ed4a..ca69638 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -82,7 +82,7 @@ for (let method of ['get', 'head', 'delete', 'post', 'put', 'patch']) { } } - const _options = defu(this._defaults, options) + const _options = defu(options, this._defaults) if (/^https?/.test(url)) { delete _options.prefixUrl From b3ba19bf7dc2312c8d8ce35573b7cde1b4c240c6 Mon Sep 17 00:00:00 2001 From: Mickael Chanrion Date: Tue, 28 Jun 2022 19:50:53 +0100 Subject: [PATCH 4/8] fix: make queryParams inheritable --- lib/plugin.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/plugin.js b/lib/plugin.js index ca69638..ad8534d 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -57,9 +57,9 @@ class HTTP { } create(options) { - const { retry, timeout, prefixUrl, headers } = this._defaults + const { retry, timeout, prefixUrl, headers, queryParams } = this._defaults - return createHttpInstance(defu(options, { retry, timeout, prefixUrl, headers })) + return createHttpInstance(defu(options, { retry, timeout, prefixUrl, headers, queryParams })) } } From 8a696ce96dea015c6a4f58fdf8e698fb4a527941 Mon Sep 17 00:00:00 2001 From: Mickael Chanrion Date: Wed, 29 Jun 2022 11:22:19 +0100 Subject: [PATCH 5/8] fix: typo (queryParams to searchParams) --- lib/plugin.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/plugin.js b/lib/plugin.js index ad8534d..04df699 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -57,9 +57,9 @@ class HTTP { } create(options) { - const { retry, timeout, prefixUrl, headers, queryParams } = this._defaults + const { retry, timeout, prefixUrl, headers, searchParams } = this._defaults - return createHttpInstance(defu(options, { retry, timeout, prefixUrl, headers, queryParams })) + return createHttpInstance(defu(options, { retry, timeout, prefixUrl, headers, searchParams })) } } From c75d58b0bead8307ae97cb2b3c0c41fb74517eb7 Mon Sep 17 00:00:00 2001 From: Mickael Chanrion Date: Wed, 29 Jun 2022 12:05:02 +0100 Subject: [PATCH 6/8] feat(searchParams): allow merge of strings, objects and URLSearchParams instances --- lib/plugin.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/plugin.js b/lib/plugin.js index 04df699..6bb1a94 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -84,6 +84,22 @@ for (let method of ['get', 'head', 'delete', 'post', 'put', 'patch']) { const _options = defu(options, this._defaults) + // Merge searchParams (mix strings, objects, and URLSearchParams instances) + if (this._defaults.searchParams && options.searchParams) { + const params1 = new URLSearchParams(this._defaults.searchParams); + const params2 = new URLSearchParams(options.searchParams); + + for (let [key] of params2.entries()) { + // params2 overrides params1 to let's remove any param with the same key + params1.delete(key) + } + + for (let [key, val] of params2.entries()) { + params1.append(key, val); + } + _options.searchParams = params1 + } + if (/^https?/.test(url)) { delete _options.prefixUrl } else if (_options.prefixUrl && typeof url === 'string' && url.startsWith('/')) { From 39807b37863702b386e5ca48350d9c86aea54ae5 Mon Sep 17 00:00:00 2001 From: Mickael Chanrion Date: Wed, 29 Jun 2022 16:38:58 +0100 Subject: [PATCH 7/8] fix: options can be empty --- lib/plugin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugin.js b/lib/plugin.js index 6bb1a94..fe00b49 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -85,7 +85,7 @@ for (let method of ['get', 'head', 'delete', 'post', 'put', 'patch']) { const _options = defu(options, this._defaults) // Merge searchParams (mix strings, objects, and URLSearchParams instances) - if (this._defaults.searchParams && options.searchParams) { + if (this._defaults.searchParams && options && options.searchParams) { const params1 = new URLSearchParams(this._defaults.searchParams); const params2 = new URLSearchParams(options.searchParams); From 4b4fcfe105cc10d0a2d2f3f7fdd5bb54db8d20cf Mon Sep 17 00:00:00 2001 From: Mickael Chanrion Date: Sun, 18 Sep 2022 10:44:02 -0300 Subject: [PATCH 8/8] chore: update ky --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 7c3a22b..674b74a 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "consola": "^2.15.0", "defu": "^3.2.2", "destr": "^1.0.1", - "ky": "^0.31.0", + "ky": "^0.31.3", "node-fetch": "^2.6.1", "web-streams-polyfill": "^3.0.1" }, diff --git a/yarn.lock b/yarn.lock index ca9ce7c..28e1e8c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6973,10 +6973,10 @@ kleur@^3.0.3: resolved "https://registry.yarnpkg.com/kleur/-/kleur-3.0.3.tgz#a79c9ecc86ee1ce3fa6206d1216c501f147fc07e" integrity sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w== -ky@^0.31.0: - version "0.31.0" - resolved "https://registry.yarnpkg.com/ky/-/ky-0.31.0.tgz#a982dcadf695482dab464e238030edeefea9021e" - integrity sha512-C27vqDb3vuxy4mi/x1wt9P1ES0QxEJg3CbPz2t3lTaQ4AvR/hkwES06yPdqol+q3hH+DrZKb/PKD+pAQkharNg== +ky@^0.31.3: + version "0.31.3" + resolved "https://registry.yarnpkg.com/ky/-/ky-0.31.3.tgz#f00e72b9c0467ab19b0b20f15daf7dff09f67dde" + integrity sha512-YDDQKG0Lt4PFSPZGJI8WKAm5y+1ebbeA306am+4nT7riX13wjNVD5sR/QOKtgsaQaARwrdUHlv0M9kJ1qv+Jug== last-call-webpack-plugin@^3.0.0: version "3.0.0"