Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
e9c9527
Drop CALL_API alias
nason Jun 10, 2018
7bb3961
Merge pull request #193 from agraboso/drop_call_api_alias
nason Jun 10, 2018
836a3d3
update readme toc
nason Jun 10, 2018
9fbbc38
Dispatch failure FSA when fetch fails
nason Mar 3, 2018
96b0691
Update upgrading from 2.x section of readme
nason Jun 10, 2018
a0460d2
Merge pull request #175 from agraboso/failed-req-failure-fsa
nason Jun 10, 2018
585195a
Add middleware and request level response handlers
Feb 8, 2018
e932805
Add createMiddlware to top level jsdoc
nason Jun 10, 2018
900ea9f
Add docs and cleanup
nason Jun 10, 2018
7f08d36
Add error handling around RSAA.ok function
nason Jun 10, 2018
a91cd70
lint + prettier cleanup
nason Jun 10, 2018
ce5e2f3
Add a couple extra tests
nason Jun 10, 2018
8d02399
Update docs on RSAA spec to include property
nason Jun 10, 2018
3a19b1b
Merge pull request #194 from agraboso/custom-error-evaluation-docs-tests
nason Jun 10, 2018
d374151
allow non-Symbol object properties on RSAA
darthrellimnad Jun 8, 2018
8664c11
Merge pull request #192 from darthrellimnad/major/issue-188-custom-rs…
nason Jun 12, 2018
a22bcc4
3.0.0-beta.0
nason Jun 14, 2018
acd75d5
Add microbundle to build
nason Nov 28, 2017
7ebc978
switch to nyc for coverage
nason Jun 17, 2018
6ce99d2
Merge pull request #195 from agraboso/microbundle
nason Jun 17, 2018
1f156e4
3.0.0-beta.1
nason Jun 17, 2018
5c33a7c
only await if custom payload/meta is a function
ztanner Jul 12, 2018
ded83c1
Merge pull request #200 from ztanner/bugfix/async-actionwith
nason Jul 13, 2018
8701b8f
update microbundle
nason Jul 13, 2018
8e287ab
Remove lodash.isplainobject dependency
nason Jul 13, 2018
8c49f46
Merge pull request #201 from agraboso/bundle-updates
nason Jul 13, 2018
85aa8fb
3.0.0-beta.2
nason Jul 13, 2018
69c3c56
test: actionWith with payload and meta functions
nason Jul 14, 2018
004a7f3
fix: default args to empty array if none are passed
nason Jul 14, 2018
1ed4ab0
Merge pull request #202 from nason/awaitWithAsyncFnTest
nason Jul 14, 2018
0de5f00
Migrate tests to jest
nason Jul 15, 2018
4532813
update travis env
nason Jul 15, 2018
c424041
Merge pull request #203 from agraboso/test-w-jest
nason Jul 16, 2018
f0ca6fb
Update handling of failure in RSAA descriptor custom methods
nason Jul 16, 2018
cae1b2b
Merge pull request #206 from agraboso/rsaa-failure-handling-update-2
nason Jul 16, 2018
79bd843
3.0.0-beta.3
nason Jul 16, 2018
acc76bd
run new tests through prettier
nason Jul 16, 2018
bc002db
Update linter for jest, and cleanup some test linting issues
nason Jul 16, 2018
4703f34
Run tests against lib
nason Jul 17, 2018
2376c09
Bundling improvements
Jul 26, 2018
229dace
Merge pull request #207 from agraboso/test-lib
nason Jul 26, 2018
3593b9e
3.0.0-beta.4
Jul 26, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .babelrc

This file was deleted.

14 changes: 8 additions & 6 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
{
"parser": "babel-eslint",
"plugins": [
"babel",
"prettier"
"prettier",
"jest"
],
"extends": ["plugin:jest/recommended"],
"env": {
"browser": true,
"es6": true
"es6": true,
"jest/globals": true
},
"parserOptions": {
"ecmaVersion": 2017,
"sourceType": "module",
"ecmaFeatures": {
"experimentalObjectRestSpread": true,
"modules": true
"experimentalObjectRestSpread": true
}
},
"root": true,
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
node_modules
*.log
lib
es
coverage
.nyc_output
.idea
.DS_Store
24 changes: 24 additions & 0 deletions .size-limit
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[
{
"name": "lib/index.cjs.js (min)",
"path": "lib/index.cjs.js",
"limit": "10 KB",
"gzip": false
},
{
"name": "lib/index.cjs.js (min + gzip)",
"path": "lib/index.cjs.js",
"limit": "4 KB"
},
{
"name": "lib/index.umd.js (min)",
"path": "lib/index.umd.js",
"limit": "30 KB",
"gzip": false
},
{
"name": "lib/index.umd.js (min + gzip)",
"path": "lib/index.umd.js",
"limit": "12 KB"
}
]
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ language: node_js
node_js:
- "node"
- "lts/*"
- "6"
cache:
directories:
- "node_modules"
Expand Down
17 changes: 17 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## Prerequisites

[Node.js](http://nodejs.org/) >= v8 must be installed.

## Installation

- Running `npm install` in the module's root directory will install everything you need for development.

## Running Tests

- `npm test` will run the tests once.

## Building

- `npm run build` will build the module.

- `npm run clean` will delete built resources.
49 changes: 41 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ RSAAs are identified by the presence of an `[RSAA]` property, where [`RSAA`](#rs

- [Introduction](#introduction)
- [Breaking Changes in 2.0 Release](#breaking-changes-in-20-release)
- [Breaking Changes in 3.0 Release](#breaking-changes-in-30-release)
- [Installation](#installation)
- [configureStore.js](#configurestorejs)
- [app.js](#appjs)
Expand All @@ -40,6 +41,7 @@ RSAAs are identified by the presence of an `[RSAA]` property, where [`RSAA`](#rs
- [Exports](#exports)
- [`RSAA`](#rsaa)
- [`apiMiddleware`](#apimiddleware)
- [`createMiddleware(options)`](#createmiddlewareoptions)
- [`isRSAA(action)`](#isrsaaaction)
- [`validateRSAA(action)`](#validatersaaaction)
- [`isValidRSAA(action)`](#isvalidrsaaaction)
Expand All @@ -63,11 +65,13 @@ RSAAs are identified by the presence of an `[RSAA]` property, where [`RSAA`](#rs
- [`[RSAA].credentials`](#rsaacredentials-1)
- [`[RSAA].bailout`](#rsaabailout)
- [`[RSAA].fetch`](#rsaafetch-1)
- [`[RSAA].ok`](#rsaaok)
- [`[RSAA].types`](#rsaatypes)
- [Type descriptors](#type-descriptors)
- [History](#history)
- [Tests](#tests)
- [Upgrading from v1.0.x](#upgrading-from-v10x)
- [Upgrading from v2.0.x](#upgrading-from-v20x)
- [License](#license)
- [Projects using redux-api-middleware](#projects-using-redux-api-middleware)
- [Acknowledgements](#acknowledgements)
Expand Down Expand Up @@ -132,6 +136,10 @@ We have tiptoed around error-handling issues here. For a thorough walkthrough of

See the [2.0 Release Notes](https://github.com/agraboso/redux-api-middleware/releases/tag/v2.0.0), and [Upgrading from v1.0.x](#upgrading-from-v10x) for details on upgrading.

### Breaking Changes in 3.0 Release

See the [3.0 Release Notes](https://github.com/agraboso/redux-api-middleware/releases/tag/v3.0.0), and [Upgrading from v2.0.x](#upgrading-from-v20x) for details on upgrading.

## Installation

`redux-api-middleware` is available on [npm](https://www.npmjs.com/package/redux-api-middleware).
Expand Down Expand Up @@ -360,8 +368,8 @@ The `[RSAA].types` property controls the output of `redux-api-middleware`. The s
- `fetch` may throw an error: the RSAA definition is not strong enough to preclude that from happening (you may, for example, send in a `[RSAA].body` that is not valid according to the fetch specification — mind the SHOULDs in the [RSAA definition](#redux-standard-api-calling-actions));
- a network failure occurs (the network is unreachable, the server responds with an error,...).

If such an error occurs, a different *request* FSA will be dispatched (*instead* of the one described above). It will contain the following properties:
- `type`: the string constant in the first position of the `[RSAA].types` array;
If such an error occurs, a *failure* FSA will be dispatched containing the following properties:
- `type`: the string constant in the last position of the `[RSAA].types` array;
- `payload`: a [`RequestError`](#requesterror) object containing an error message;
- `error: true`.

Expand Down Expand Up @@ -399,7 +407,7 @@ See [the Redux docs on composition](https://github.com/reduxjs/redux-thunk#compo
export function patchAsyncExampleThunkChainedActionCreator(values) {
return async(dispatch, getState) => {
const actionResponse = await dispatch({
[CALL_API]: {
[RSAA]: {
endpoint: "...",
method: "PATCH",
body: JSON.stringify(values),
Expand Down Expand Up @@ -660,6 +668,7 @@ For example, if you want the status code and status message of a unsuccessful AP
}
}
```

By default, *failure* FSAs will not contain a `meta` property, while their `payload` property will be evaluated from
```js
(action, state, res) =>
Expand All @@ -668,6 +677,9 @@ By default, *failure* FSAs will not contain a `meta` property, while their `payl
)
```


Note that *failure* FSAs dispatched due to fetch errors will not have a `res` argument into `meta` or `payload`. The `res` parameter will exist for completed requests that have resulted in errors, but not for failed requests.

### Exports

The following objects are exported by `redux-api-middleware`.
Expand All @@ -680,6 +692,15 @@ A JavaScript `String` whose presence as a key in an action signals that `redux-a

The Redux middleware itself.

#### `createMiddleware(options)`

A function that creates an `apiMiddleware` with custom options.

The following `options` properties are used:

- `fetch` - provide a `fetch` API compatible function here to use instead of the default `window.fetch`
- `ok` - provide a function here to use as a status check in the RSAA flow instead of `(res) => res.ok`

#### `isRSAA(action)`

A function that returns `true` if `action` has an `[RSAA]` property, and `false` otherwise.
Expand Down Expand Up @@ -792,9 +813,9 @@ A *Redux Standard API-calling Action* MUST
- be a plain JavaScript object,
- have an `[RSAA]` property.

A *Redux Standard API-calling Action* MUST NOT
A *Redux Standard API-calling Action* MAY

- include properties other than `[RSAA]`.
- include properties other than `[RSAA]` (but will be ignored by redux-api-middleware).

#### `[RSAA]`

Expand All @@ -812,11 +833,12 @@ The `[RSAA]` property MAY
- have an `options` property,
- have a `credentials` property,
- have a `bailout` property,
- have a `fetch` property.
- have a `fetch` property,
- have an `ok` property.

The `[RSAA]` property MUST NOT

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

#### `[RSAA].endpoint`

Expand Down Expand Up @@ -850,7 +872,11 @@ The optional `[RSAA].bailout` property MUST be a boolean or a function.

#### `[RSAA].fetch`

The optional `[RSAA].fetch` property MUST be a function.
The optional `[RSAA].fetch` property MUST be a function that conforms to the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API).

#### `[RSAA].ok`

The optional `[RSAA].ok` property MUST be a function that accepts a response object and returns a boolean indicating if the request is a success or failure

#### `[RSAA].types`

Expand Down Expand Up @@ -889,6 +915,13 @@ $ npm install && npm test
- A new `options` config is added to pass your `fetch` implementation extra options other than `method`, `headers`, `body` and `credentials`
- `apiMiddleware` no longer returns a promise on actions without [RSAA]

## Upgrading from v2.0.x

- The `CALL_API` alias has been removed
- Error handling around failed fetches has been updated (#175)
- Previously, a failed `fetch` would dispatch a `REQUEST` FSA followed by another `REQUEST` FSA with an error flag
- Now, a failed `fetch` will dispatch a `REQUEST` FSA followed by a `FAILURE` FSA

## License

MIT
Expand Down
25 changes: 25 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = function (api) {
const env = api.cache(() => process.env.NODE_ENV);

const nodeTarget = env === 'test' ? 'current' : '8';
const envModules = env === 'test' ? 'commonjs' : false;

const presets = [
[
"@babel/preset-env", {
modules: envModules,
"useBuiltIns": "usage",
"targets": {
"node": nodeTarget
},
}
]
];

const plugins = [];

return {
presets,
plugins
};
}
13 changes: 13 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
verbose: !!process.env.CI,
automock: false,
resetMocks: true,
restoreMocks: true,
resetModules: true,
setupFiles: [
"./test/setupJest.js"
],
moduleNameMapper: {
"^redux-api-middleware$": process.env.TEST_LIB ? '..' : './index'
}
};
Loading