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

redux-api-middleware

Package Overview
Dependencies
Maintainers
2
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-api-middleware - npm Package Compare versions

Comparing version 2.0.0-beta.3 to 2.0.0-beta.4

1

lib/index.js

@@ -35,3 +35,2 @@ 'use strict';

* @module redux-api-middleware
* @requires isomorphic-fetch
* @requires lodash.isplainobject

@@ -38,0 +37,0 @@ * @exports {string} RSAA

106

lib/middleware.js

@@ -24,6 +24,2 @@ 'use strict';

var _lodash = require('lodash.isplainobject');
var _lodash2 = _interopRequireDefault(_lodash);
var _RSAA = require('./RSAA');

@@ -54,4 +50,4 @@

return function () {
var _ref2 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(action) {
var validationErrors, _callAPI, _requestType, callAPI, endpoint, headers, method, body, credentials, bailout, types, _normalizeTypeDescrip, _normalizeTypeDescrip2, requestType, successType, failureType, res;
var _ref2 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(action) {
var validationErrors, _callAPI, _requestType, callAPI, endpoint, headers, _callAPI$options, options, method, body, credentials, bailout, types, _normalizeTypeDescrip, _normalizeTypeDescrip2, requestType, successType, failureType, res;

@@ -99,3 +95,3 @@ return _regenerator2.default.wrap(function _callee$(_context) {

callAPI = action[_RSAA2.default];
endpoint = callAPI.endpoint, headers = callAPI.headers;
endpoint = callAPI.endpoint, headers = callAPI.headers, _callAPI$options = callAPI.options, options = _callAPI$options === undefined ? {} : _callAPI$options;
method = callAPI.method, body = callAPI.body, credentials = callAPI.credentials, bailout = callAPI.bailout, types = callAPI.types;

@@ -186,12 +182,38 @@ _normalizeTypeDescrip = (0, _util.normalizeTypeDescriptors)(types), _normalizeTypeDescrip2 = (0, _slicedToArray3.default)(_normalizeTypeDescrip, 3), requestType = _normalizeTypeDescrip2[0], successType = _normalizeTypeDescrip2[1], failureType = _normalizeTypeDescrip2[2];

case 47:
_context.t9 = next;
_context.next = 50;
if (!(typeof options === 'function')) {
_context.next = 59;
break;
}
_context.prev = 48;
options = options(getState());
_context.next = 59;
break;
case 52:
_context.prev = 52;
_context.t9 = _context['catch'](48);
_context.t10 = next;
_context.next = 57;
return (0, _util.actionWith)((0, _extends3.default)({}, requestType, {
payload: new _errors.RequestError('[RSAA].options function failed'),
error: true
}), [action, getState()]);
case 57:
_context.t11 = _context.sent;
return _context.abrupt('return', (0, _context.t10)(_context.t11));
case 59:
_context.t12 = next;
_context.next = 62;
return (0, _util.actionWith)(requestType, [action, getState()]);
case 50:
_context.t10 = _context.sent;
(0, _context.t9)(_context.t10);
_context.prev = 52;
_context.next = 55;
return fetch(endpoint, {
case 62:
_context.t13 = _context.sent;
(0, _context.t12)(_context.t13);
_context.prev = 64;
_context.next = 67;
return fetch(endpoint, (0, _extends3.default)({}, options, {
method: method,

@@ -201,40 +223,40 @@ body: body,

headers: headers || {}
});
}));
case 55:
case 67:
res = _context.sent;
_context.next = 65;
_context.next = 77;
break;
case 58:
_context.prev = 58;
_context.t11 = _context['catch'](52);
_context.t12 = next;
_context.next = 63;
case 70:
_context.prev = 70;
_context.t14 = _context['catch'](64);
_context.t15 = next;
_context.next = 75;
return (0, _util.actionWith)((0, _extends3.default)({}, requestType, {
payload: new _errors.RequestError(_context.t11.message),
payload: new _errors.RequestError(_context.t14.message),
error: true
}), [action, getState()]);
case 63:
_context.t13 = _context.sent;
return _context.abrupt('return', (0, _context.t12)(_context.t13));
case 75:
_context.t16 = _context.sent;
return _context.abrupt('return', (0, _context.t15)(_context.t16));
case 65:
case 77:
if (!res.ok) {
_context.next = 73;
_context.next = 85;
break;
}
_context.t14 = next;
_context.next = 69;
_context.t17 = next;
_context.next = 81;
return (0, _util.actionWith)(successType, [action, getState(), res]);
case 69:
_context.t15 = _context.sent;
return _context.abrupt('return', (0, _context.t14)(_context.t15));
case 81:
_context.t18 = _context.sent;
return _context.abrupt('return', (0, _context.t17)(_context.t18));
case 73:
_context.t16 = next;
_context.next = 76;
case 85:
_context.t19 = next;
_context.next = 88;
return (0, _util.actionWith)((0, _extends3.default)({}, failureType, {

@@ -244,7 +266,7 @@ error: true

case 76:
_context.t17 = _context.sent;
return _context.abrupt('return', (0, _context.t16)(_context.t17));
case 88:
_context.t20 = _context.sent;
return _context.abrupt('return', (0, _context.t19)(_context.t20));
case 78:
case 90:
case 'end':

@@ -254,3 +276,3 @@ return _context.stop();

}
}, _callee, _this, [[11, 16], [24, 28], [36, 40], [52, 58]]);
}, _callee, _this, [[11, 16], [24, 28], [36, 40], [48, 52], [64, 70]]);
}));

@@ -257,0 +279,0 @@

@@ -45,3 +45,3 @@ 'use strict';

var getJSON = function () {
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(res) {
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(res) {
var contentType, emptyCodes;

@@ -107,3 +107,3 @@ return _regenerator2.default.wrap(function _callee$(_context) {

var actionWith = function () {
var _ref2 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee2(descriptor, args) {
var _ref2 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2(descriptor, args) {
return _regenerator2.default.wrap(function _callee2$(_context2) {

@@ -110,0 +110,0 @@ while (1) {

@@ -77,3 +77,3 @@ 'use strict';

var validationErrors = [];
var validCallAPIKeys = ['endpoint', 'method', 'body', 'headers', 'credentials', 'bailout', 'types'];
var validCallAPIKeys = ['endpoint', 'options', 'method', 'body', 'headers', 'credentials', 'bailout', 'types'];
var validMethods = ['GET', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'];

@@ -106,2 +106,3 @@ var validCredentials = ['omit', 'same-origin', 'include'];

headers = callAPI.headers,
options = callAPI.options,
credentials = callAPI.credentials,

@@ -127,2 +128,5 @@ types = callAPI.types,

}
if (typeof options !== 'undefined' && !(0, _lodash2.default)(options) && typeof options !== 'function') {
validationErrors.push('[RSAA].options property must be undefined, a plain JavaScript object, or a function');
}
if (typeof credentials !== 'undefined') {

@@ -129,0 +133,0 @@ if (typeof credentials !== 'string') {

{
"name": "redux-api-middleware",
"version": "2.0.0-beta.3",
"version": "2.0.0-beta.4",
"description": "Redux middleware for calling an API.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -147,3 +147,3 @@ redux-api-middleware

`redux-api-middleware` uses the [`Fetch API`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) to make the API call. `[RSAA].body` should hence be a valid body according to the the [fetch specification](https://fetch.spec.whatwg.org). In most cases, this will be a JSON-encoded string or a [`FormData`](https://developer.mozilla.org/en/docs/Web/API/FormData) object.
`redux-api-middleware` uses the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) to make the API call. `[RSAA].body` should hence be a valid body according to the [fetch specification](https://fetch.spec.whatwg.org). In most cases, this will be a JSON-encoded string or a [`FormData`](https://developer.mozilla.org/en/docs/Web/API/FormData) object.

@@ -168,2 +168,21 @@ #### `[RSAA].headers`

#### `[RSAA].options`
The fetch options for the API call. What options are available depends on what fetch implementation is in use. See [MDN fetch](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch) or [node-fetch](https://github.com/bitinn/node-fetch#options) for more information.
It is usually an object with the options keys/values. For example, you can specify a network timeout for node.js code
in the following way.
```js
{
[RSAA]: {
...
options: { timeout: 3000 }
...
}
}
```
It may also be a function taking the state of your Redux store as its argument, and returning an object of options as above.
#### `[RSAA].credentials`

@@ -545,2 +564,3 @@

- have a `headers` property,
- have an `options` property,
- have a `credentials` property,

@@ -551,3 +571,3 @@ - have a `bailout` property.

- include properties other than `endpoint`, `method`, `types`, `body`, `headers`, `credentials`, and `bailout`.
- include properties other than `endpoint`, `method`, `types`, `body`, `headers`, `options`, `credentials`, and `bailout`.

@@ -564,3 +584,3 @@ #### `[RSAA].endpoint`

The optional `[RSAA].body` property SHOULD be a valid body according to the the [fetch specification](https://fetch.spec.whatwg.org).
The optional `[RSAA].body` property SHOULD be a valid body according to the [fetch specification](https://fetch.spec.whatwg.org).

@@ -571,2 +591,8 @@ #### `[RSAA].headers`

#### `[RSAA].options`
The optional `[RSAA].options` property MUST be a plain JavaScript object or a function. In the second case, the function SHOULD return a plain JavaScript object.
The options object can contain any options supported by the effective fetch implementation.
See [MDN fetch](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch) or [node-fetch](https://github.com/bitinn/node-fetch#options).
#### `[RSAA].credentials`

@@ -573,0 +599,0 @@

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