Skip to content

Releases: elbywan/wretch

2.11.0

29 Oct 08:27
3d189ba
Compare
Choose a tag to compare

2.11.0 (2024-10-29)

🏭 New feature(s)

screen

⬆️ Version update(s)

  • Bump body-parser from 1.20.0 to 1.20.3 (598ce94)
  • Bump rollup from 4.5.0 to 4.22.4 (75f9db7)

2.10.0

13 Sep 22:05
53fb12b
Compare
Choose a tag to compare

2.10.0 (2024-09-13)

🎨 Code improvement(s)

// This should now work properly in typescript projects using a "NodeNext" configuration 
import wretch from "wretch"

⬆️ Version update(s)

  • Bump axios from 1.6.2 to 1.7.7 (4542c28)

2.9.1

06 Sep 21:13
Compare
Choose a tag to compare

2.9.1 (2024-09-06)

🎨 Code improvement(s)

  • Enhance errorType and allow disabling it (cfd45a9)
  • Replace URL.canParse with a try/catch block (f6fc851), closes #244
  • Replace tslint with eslint (661865a)

⬆️ Version update(s)

  • Bump braces from 3.0.2 to 3.0.3 (a50cdf6)
  • Bump ws and socket.io (c615396)

📝 Documentation update(s)

  • Regenerate api docs (bc1f570)
  • Replace bundlephobia badge with bundlejs (b9f27a7)

2.9.0

01 Jun 17:36
Compare
Choose a tag to compare

What's Changed

🏭 New feature(s)

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 and undefined 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)

  • 🐛 Do not jasonify FormData instances by @am1rb in #232
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

Full Changelog: 2.8.1...2.9.0

2.8.1

07 Mar 07:37
Compare
Choose a tag to compare

2.8.1 (2024-03-07)

🐛 Bug fix(es)

  • Fix error callback type missing addons extensions (99a21a8), closes #222
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

30 Dec 09:58
Compare
Choose a tag to compare

2.8.0 (2023-12-30)

🏭 New feature(s)

  • addon.resolver can now be a function (0bf9aa8), closes #212
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

19 Nov 10:35
Compare
Choose a tag to compare

2.7.1 (2023-11-19)

🐛 Bug fix(es)

  • Fix passing a HeadersInit (Header / array) argument to headers() (f32845a), closes #205
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)

  • Bump @babel/traverse from 7.19.4 to 7.23.2 (922005e)
  • Upgrade dependencies (d774826)

2.7.0

12 Sep 17:37
Compare
Choose a tag to compare

2.7.0 (2023-09-12)

🏭 New feature(s)

  • Support FileList objects in the form data addon (3582809), closes #201
<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)

  • Mention file names in the form data addon doc (411fb09), closes #197

2.6.0

28 Jun 12:10
Compare
Choose a tag to compare

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
  })

📝 Documentation update(s)

  • Update node-fetch code snippet (3b6ac7e), closes #179

2.5.2

11 Apr 06:40
Compare
Choose a tag to compare

2.5.2 (2023-04-11)

🐛 Bug fix(es)

  • Fix catcher and resolve callback argument type. (76c295f), closes #177

📝 Documentation update(s)

  • Node.js 18 section wording (b696b1c)
  • Warn to use a custom until function to avoid retrying on 4xx error (1812c73), closes #176