Releases: elbywan/wretch
Releases · elbywan/wretch
2.11.0
2.10.0
2.9.1
2.9.0
What's Changed
🏭 New feature(s)
- 🏭 Add BasicAuth addon by @BendingBender in #223
import BasicAuthAddon from "wretch/addons/basicAuth"
const user = "user"
const pass = "pass"
// Automatically sets the Authorization header to "Basic " + <base64 encoded credentials>
wretch("...").addon(BasicAuthAddon).basicAuth(user, pass).get()
// Allows using URLs with credentials in them
wretch(`https://${user}:${pass}@...`).addon(BasicAuthAddon).get()
- 🏭 Omit
null
andundefined
values from query string produced by QueryStringAddon by @dankochetov in #230
wretch('https://example.com')
.addon(QueryStringAddon)
// passing 'true' as the third argument will now ignore query parameters having undefined/null values
// the underlying url is now `https://example.com?bar=qwe` and foo is omitted
.query({ bar: 'qwe', foo: undefined }, false, true)
🐛 Bug fix(es)
const requestBody = new FormData()
requestBody.append("field1", "data 1");
requestBody.append("field2", "data 2");
// wretch will now check if the argument is an instance of `FormData` before trying to jsonify it
wretch().post(requestBody, "SERVER_URL")
⬆️ Version update(s)
- ⬆️ Bump follow-redirects from 1.15.4 to 1.15.6 by @dependabot in #224
New Contributors
- @BendingBender made their first contribution in #223
- @dankochetov made their first contribution in #230
- @am1rb made their first contribution in #232
Full Changelog: 2.8.1...2.9.0
2.8.1
2.8.1 (2024-03-07)
🐛 Bug fix(es)
export const apiClient = wretch('https://localhost:3000')
.addon(QueryStringAddon)
.resolve((chain) => {
return chain.unauthorized((_error, request) => {
// request type used to be wrong (missing .query() from the addon)
// and it would clash with what was expected by the callback definition
// now the type should be correct ✨
return request
.fetch()
.unauthorized((error) => {
throw error;
})
.json();
});
});
⬆️ Version update(s)
- Bump follow-redirects from 1.15.1 to 1.15.4 (04fada6)
2.8.0
2.8.0 (2023-12-30)
🏭 New feature(s)
const fetcher = wretch("https://jsonplaceholder.typicode.com").addon({
// resolver can now be a function and re-use the previously defined methods of the response chain:
resolver: (chain) => ['res', 'json', 'text', 'blob', 'formData', 'arrayBuffer'].reduce((acc, method) => ({
...acc,
// overrides .json, .text… methods to chain .then & .catch
[method](cb) {
return chain[method](cb)
.then(ret => (console.log('[hook] ok')))
.catch(error => {
console.error('[hook] error', error.response.url, error.response.status)
throw error
});
}
}), {})
});
(async function () {
await fetcher.get("/todos/1").json(console.log);
// { userId: 1, id: 1, title: 'delectus aut autem', completed: false }
// [hook] ok
await fetcher.get("/bad-route").notFound(error => {
console.log('handled error :)')
}).text(console.log);
// handled error :)
// [hook] ok
await fetcher.get("/bad-route").text(console.log).catch(() => console.log('unhandled error :('));
// [hook] error https://jsonplaceholder.typicode.com/bad-route 404
// unhandled error :(
})()
2.7.1
2.7.1 (2023-11-19)
🐛 Bug fix(es)
const headers1 = new Headers({ "hello": "world" });
const headers2 = new Headers({ "bonjour": "le monde" });
const headers3 = { "hola": "mundo " };
const headers4 = [["hallo", "welt"]]
let w = wretch().headers(headers1);
console.log(w._options.headers);
// Object { hello: "world" }
w = w.headers(headers2);
console.log(w._options.headers);
// Object { hello: "world", bonjour: "le monde" }
w = w.headers(headers3);
console.log(w._options.headers);
// Object { hello: "world", bonjour: "le monde", hola: "mundo " }
w = w.headers(headers4);
console.log(w._options.headers);
// Object { hello: "world", bonjour: "le monde", hola: "mundo ", hallo: "welt" }
⬆️ Version update(s)
2.7.0
2.7.0 (2023-09-12)
🏭 New feature(s)
<head>
<script type="module">
import wretch from 'https://cdn.skypack.dev/wretch';
import FormDataAddon from 'https://cdn.skypack.dev/wretch/addons/formData';
const fileInput = document.querySelector("#myfiles");
fileInput.addEventListener("change", () => {
wretch("/post-files")
.addon(FormDataAddon)
.formData({ files: fileInput.files })
.post()
.text(console.log)
});
</script>
</head>
<body>
<input id="myfiles" multiple type="file" />
</body>
📝 Documentation update(s)
2.6.0
2.6.0 (2023-06-28)
⬆️ Version update(s)
- Bump engine.io and socket.io (3ef1738)
- Bump socket.io-parser from 4.2.2 to 4.2.3 (b42aa0f)
- Upgrade dependencies (b183cf7)
🏭 New feature(s)
wretch(url)
.catcher(404, err => redirect("/routes/notfound", err.message))
.catcher(500, err => flashMessage("internal.server.error"))
// this fallback will trigger for any error except if already caught by other means (like above for 404s and 505s)
.catcherFallback(err => {
log("Uncaught error:", err)
throw err
})