Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@adeira/fetch

Package Overview
Dependencies
Maintainers
3
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@adeira/fetch - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

4

fetch/CHANGELOG.md
# Unreleased
# 1.0.4
- internal stylistic changes, dependencies bump, documentation updates
# 1.0.3

@@ -4,0 +8,0 @@

8

fetch/package.json

@@ -6,3 +6,3 @@ {

"license": "MIT",
"version": "1.0.3",
"version": "1.0.4",
"sideEffects": false,

@@ -12,5 +12,5 @@ "homepage": "https://github.com/adeira/universe/tree/master/src/fetch",

"dependencies": {
"@adeira/js": "^1.2.0",
"@babel/runtime": "^7.10.2",
"cross-fetch": "^3.0.4"
"@adeira/js": "^1.2.4",
"@babel/runtime": "^7.11.2",
"cross-fetch": "^3.0.6"
},

@@ -17,0 +17,0 @@ "devDependencies": {

@@ -1,5 +0,6 @@

This package has been extracted from the original [fbjs](https://github.com/facebook/fbjs/blob/master/packages/fbjs/src/fetch/fetchWithRetries.js) library and it exposes single `fetchWithRetries`. This function is only a wrapper for any other well known [fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API). However, this fetch also solves two common problems:
This package has been extracted from the original [fbjs](https://github.com/facebook/fbjs/blob/master/packages/fbjs/src/fetch/fetchWithRetries.js) library and it exposes single `fetchWithRetries`. This function is only a wrapper for any other well known [fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API). However, this fetch also solves these common problems:
- fetch timeouts, and
- retries
- fetch timeouts
- retries, and
- request cancellations

@@ -101,2 +102,18 @@ This makes the fetch function more suitable for real-life production usage because it doesn't hang or fail easily. In other words you are not going to have many open connections just because the API is slow (this could kill your server completely) and your fetch won't give up if the API didn't respond for the first time (just some glitch and one retry would fix it).

# Request cancellation
You can easily cancel any request via `AbortController` (https://developer.mozilla.org/en-US/docs/Web/API/AbortController) like so:
```js
const controller = new AbortController();
const signal = controller.signal;
const response = await fetchWithRetries('//localhost', {
signal,
});
// You can cancel it somewhere from your code when needed (Relay network cleanup for example).
controller.abort();
```
# Frequently Asked Questions

@@ -160,3 +177,3 @@

jest.mock('@adeira/fetch', () => {
return resource => Promise.resolve(`MODIFIED ${resource.toUpperCase()} 2`);
return (resource) => Promise.resolve(`MODIFIED ${resource.toUpperCase()} 2`);
});

@@ -170,1 +187,10 @@

Why mocking `global.fetch` doesn't work? It's because this fetch doesn't use or pollute `global` variable: it uses ponyfill instead of polyfill behind the scenes.
### Msw, an alternative to mock fetch
There is an alternative to mocking the fetch function. You can use [msw](https://mswjs.io/)
What it does is start a service worker (yes it works in node as well) and that service worker stops the network request and returns mocked data.
> "_I found MSW and was thrilled that not only could I still see the mocked responses in my DevTools, but that the mocks didn't have to be written in a Service Worker and could instead live alongside the rest of my app. This made it silly easy to adopt. The fact that I can use it for testing as well makes MSW a huge productivity booster._"
>
> – [Kent C. Dodds](https://twitter.com/kentcdodds)

@@ -47,3 +47,3 @@ "use strict";

// manually (a?.b would fail otherwise). Then we cannot assume `versions` exist.
// $FlowExpectedError: field `versions` doesn't have to exist (see Browsers env)
// $FlowExpectedError[unnecessary-optional-chain]: field `versions` doesn't have to exist (see Browsers env)
return typeof process !== 'undefined' && ((_process$versions = process.versions) === null || _process$versions === void 0 ? void 0 : _process$versions.node) !== undefined;

@@ -50,0 +50,0 @@ }

@@ -16,3 +16,3 @@ "use strict";

function ResponseError(response, message) {
var instance = new Error(message); // $FlowExpectedError: property 'error.response' is unknown in Error (but that's fine, we are extending here)
var instance = new Error(message); // $FlowExpectedError[prop-missing]: property 'error.response' is unknown in Error (but that's fine, we are extending here)

@@ -24,3 +24,3 @@ instance.response = response;

Error.captureStackTrace(instance, ResponseError);
} // $FlowExpectedError: property 'error.response' is unknown in Error (but that's fine, we are extending here)
} // $FlowExpectedError[prop-missing]: property 'error.response' is unknown in Error (but that's fine, we are extending here)

@@ -27,0 +27,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc