This package contains multiple middlewares allowing to customize and optimize Botify SDK's behaviour. Including local storage caching, request dedupling, api result post processing.
npm install --save botify-sdk-middlewares
You’ll also need the Botify SDK (core).
npm install --save botify-sdk
An UMD bundle is available in dist/botify-sdk-middlewares.min.js
. It means you can use the lib with any module loader, including Browserify and RequireJS.
It exposes the global variable BotifySDKMiddlewares
.
<script src="https://github.com/botify-labs/botify-sdk-js-middlewares/raw/master/node_modules/botify-sdk-middlewares/dist/botify-sdk-middlewares.min.js"></script>
Use applyMiddleware
function to apply middlewares you need.
import { applyMiddleware, apiErrorMiddleware, lscacheMiddleware } from 'botify-sdk-middlewares';
import baseSdk from 'botify-sdk';
const sdk = applyMiddleware(
apiErrorMiddleware,
lscacheMiddleware()
)(baseSdk);
<!> Becareful: order maters. (read middleware's documentation requirement section).
Note: examples are written with ES6 syntax but nothing prevents you to use this lib (and create middlewares) with plain old school JavaScript.
npm run lint
: lint sources and tests using ESlint.npm test
: launch testsnpm run test:watch
: watch files and execute the tests whenever sources or tests change.The middleware pattern used in this package has been greatly inspired by Redux middlewares.