Skip to content

Releases: elbywan/wretch

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

2.5.1

27 Feb 05:42
Compare
Choose a tag to compare

2.5.1 (2023-02-27)

🐛 Bug fix(es)

  • Update resolver.ts - Add null verification to .get("Content-Type") (a68a524)

2.5.0

20 Feb 22:56
Compare
Choose a tag to compare

2.5.0 (2023-02-20)

🏭 New feature(s)

  • Parse error type as json on proper content-type (ea9adbf), closes #171

Setting the error type as json manually using .errorType("json") should now not be necessary if the server responds with a Content-Type header set as application/json.

The response body will be deserialized and the error.json will be set accordingly.

⬆️ Version update(s)

  • Bump @fastify/multipart from 7.3.0 to 7.4.1 (e6074c9)
  • Bump @sideway/formula from 3.0.0 to 3.0.1 (8208646)
  • Bump ua-parser-js from 0.7.31 to 0.7.33 (1694fe6)

2.4.1

20 Jan 15:54
Compare
Choose a tag to compare

2.4.1 (2023-01-20)

🐛 Bug fix(es)

  • Fix abort/progress addons state isolation issue (2b3a659)

2.4.0

19 Jan 14:20
Compare
Choose a tag to compare

2.4.0 (2023-01-19)

🏭 New feature(s)

  • Add skip argument to the retry middleware (746f8c9)
wretch().middlewares([
  retry({
    skip(url, options) {
      return options.method != "GET"
    },
  })
])