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

axios-middleware

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

axios-middleware - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

dist/axios-middleware.common.js

386

dist/axios-middleware.js

@@ -1,88 +0,12 @@

(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define("AxiosMiddleware", [], factory);
else if(typeof exports === 'object')
exports["AxiosMiddleware"] = factory();
else
root["AxiosMiddleware"] = factory();
})(typeof self !== 'undefined' ? self : this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
/**
* axios-middleware v0.1.2
* (c) 2018 Émile Bergeron
* @license MIT
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.AxiosMiddleware = factory());
}(this, (function () { 'use strict';
"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
// CONCATENATED MODULE: ./src/middleware.js
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/* eslint-disable class-methods-use-this, no-unused-vars */

@@ -93,206 +17,140 @@

*/
var HttpMiddleware = function () {
function HttpMiddleware() {
_classCallCheck(this, HttpMiddleware);
}
var HttpMiddleware = function HttpMiddleware () {};
_createClass(HttpMiddleware, [{
key: "onRequest",
HttpMiddleware.prototype.onRequest = function onRequest (config) {
return config;
};
/**
* Default implementation is the identity function.
* @param {Object} config
* @returns {Object}
*/
value: function onRequest(config) {
return config;
}
/**
* Default implementation is a noop.
* @param error
*/
HttpMiddleware.prototype.handleRequestError = function handleRequestError (error) { };
/**
* Default implementation is a noop.
* @param error
*/
/**
* Default implementation is the identity function.
* @param {Object} response
* @returns {Object}
*/
HttpMiddleware.prototype.onResponse = function onResponse (response) {
return response;
};
}, {
key: "handleRequestError",
value: function handleRequestError(error) {}
/**
* Default implementation is a noop.
* @param error
*/
HttpMiddleware.prototype.handleResponseError = function handleResponseError (error) { };
/**
* Default implementation is the identity function.
* @param {Object} response
* @returns {Object}
*/
var HttpMiddlewareService = function HttpMiddlewareService(axios) {
this.middlewares = [];
}, {
key: "onResponse",
value: function onResponse(response) {
return response;
}
this.setHttp(axios);
};
/**
* Default implementation is a noop.
* @param error
*/
/**
*
* @param {Axios} axios
*/
HttpMiddlewareService.prototype.setHttp = function setHttp (axios) {
var this$1 = this;
}, {
key: "handleResponseError",
value: function handleResponseError(error) {}
}]);
this.unsetHttp();
return HttpMiddleware;
}();
this.http = axios;
/* harmony default export */ var middleware = (HttpMiddleware);
// CONCATENATED MODULE: ./src/service.js
var service__createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var interceptors = axios.interceptors;
function service__classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
this._requestInterceptor = interceptors.request.use(
function (config) { return this$1._onRequest(config); },
function (error) { return this$1._handleRequestError(error); }
);
this._responseInterceptor = interceptors.response.use(
function (response) { return this$1._onResponse(response); },
function (error) { return this$1._handleResponseError(error); }
);
return this;
};
var HttpMiddlewareService = function () {
function HttpMiddlewareService(axios) {
service__classCallCheck(this, HttpMiddlewareService);
this.middlewares = [];
this.setHttp(axios);
HttpMiddlewareService.prototype.unsetHttp = function unsetHttp () {
var http = this.http;
if (this.http) {
var interceptors = http.interceptors;
interceptors.request.eject(this._requestInterceptor);
interceptors.response.eject(this._responseInterceptor);
}
};
/**
*
* @param {Axios} axios
*/
/**
* @param {HttpMiddleware} middleware
* @returns {boolean} true if the middleware is already registered.
*/
HttpMiddlewareService.prototype.has = function has (middleware) {
return this.middlewares.indexOf(middleware) > -1;
};
/**
* Add a middleware or an array of middlewares to the stack.
* @param {HttpMiddleware|Array} middlewares
*/
HttpMiddlewareService.prototype.register = function register (middlewares) {
var this$1 = this;
service__createClass(HttpMiddlewareService, [{
key: 'setHttp',
value: function setHttp(axios) {
var _this = this;
// eslint-disable-next-line no-param-reassign
if (!Array.isArray(middlewares)) { middlewares = [middlewares]; }
this.unsetHttp();
this.http = axios;
var interceptors = axios.interceptors;
this._requestInterceptor = interceptors.request.use(function (config) {
return _this._onRequest(config);
}, function (error) {
return _this._handleRequestError(error);
});
this._responseInterceptor = interceptors.response.use(function (response) {
return _this._onResponse(response);
}, function (error) {
return _this._handleResponseError(error);
});
return this;
// Test if middlewares are registered more than once.
middlewares.forEach(function (middleware) {
if (this$1.has(middleware)) {
throw new Error('Middleware already registered');
}
}, {
key: 'unsetHttp',
value: function unsetHttp() {
var http = this.http;
if (this.http) {
var interceptors = http.interceptors;
interceptors.request.eject(this._requestInterceptor);
interceptors.response.eject(this._responseInterceptor);
}
}
this$1.middlewares.push(middleware);
});
};
/**
* @param {HttpMiddleware} middleware
* @returns {boolean} true if the middleware is already registered.
*/
/**
* Remove a middleware from the registered stack.
* @param {HttpMiddleware} middleware
*/
HttpMiddlewareService.prototype.unregister = function unregister (middleware) {
var index = this.middlewares.indexOf(middleware);
if (index > -1) {
this.middlewares.splice(index, 1);
}
};
}, {
key: 'has',
value: function has(middleware) {
return this.middlewares.indexOf(middleware) > -1;
}
HttpMiddlewareService.prototype.reset = function reset () {
this.middlewares.length = 0;
};
/**
* Add a middleware or an array of middlewares to the stack.
* @param {HttpMiddleware|Array} middlewares
*/
HttpMiddlewareService.prototype._onRequest = function _onRequest (config) {
return this.middlewares.reduce(
function (acc, middleware) { return middleware.onRequest(acc); },
config);
};
}, {
key: 'register',
value: function register(middlewares) {
var _this2 = this;
HttpMiddlewareService.prototype._handleRequestError = function _handleRequestError (error) {
this.middlewares.forEach(function (middleware) { return middleware.handleRequestError(error); });
return Promise.reject(error);
};
// eslint-disable-next-line no-param-reassign
if (!Array.isArray(middlewares)) middlewares = [middlewares];
HttpMiddlewareService.prototype._onResponse = function _onResponse (response) {
return this.middlewares.reduce(
function (acc, middleware) { return middleware.onResponse(acc); },
response);
};
// Test if middlewares are registered more than once.
middlewares.forEach(function (middleware) {
if (_this2.has(middleware)) {
throw new Error('Middleware already registered');
}
_this2.middlewares.push(middleware);
});
}
HttpMiddlewareService.prototype._handleResponseError = function _handleResponseError (error) {
this.middlewares.forEach(function (middleware) { return middleware.handleResponseError(error); });
return Promise.reject(error);
};
/**
* Remove a middleware from the registered stack.
* @param {HttpMiddleware} middleware
*/
var index = {
HttpMiddleware: HttpMiddleware,
HttpMiddlewareService: HttpMiddlewareService,
version: '0.1.2',
};
}, {
key: 'unregister',
value: function unregister(middleware) {
var index = this.middlewares.indexOf(middleware);
if (index > -1) {
this.middlewares.splice(index, 1);
}
}
}, {
key: 'reset',
value: function reset() {
this.middlewares.length = 0;
}
}, {
key: '_onRequest',
value: function _onRequest(config) {
return this.middlewares.reduce(function (acc, middleware) {
return middleware.onRequest(acc);
}, config);
}
}, {
key: '_handleRequestError',
value: function _handleRequestError(error) {
this.middlewares.forEach(function (middleware) {
return middleware.handleRequestError(error);
});
return Promise.reject(error);
}
}, {
key: '_onResponse',
value: function _onResponse(response) {
return this.middlewares.reduce(function (acc, middleware) {
return middleware.onResponse(acc);
}, response);
}
}, {
key: '_handleResponseError',
value: function _handleResponseError(error) {
this.middlewares.forEach(function (middleware) {
return middleware.handleResponseError(error);
});
return Promise.reject(error);
}
}]);
return index;
return HttpMiddlewareService;
}();
/* harmony default export */ var service = (HttpMiddlewareService);
// CONCATENATED MODULE: ./src/index.js
/* harmony default export */ var src = __webpack_exports__["default"] = ({
HttpMiddleware: middleware,
HttpMiddlewareService: service
});
/***/ })
/******/ ])["default"];
});
})));

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

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("AxiosMiddleware",[],t):"object"==typeof exports?exports.AxiosMiddleware=t():e.AxiosMiddleware=t()}("undefined"!=typeof self?self:this,function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:n})},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();var o=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}return n(e,[{key:"onRequest",value:function(e){return e}},{key:"handleRequestError",value:function(e){}},{key:"onResponse",value:function(e){return e}},{key:"handleResponseError",value:function(e){}}]),e}(),u=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();var i=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.middlewares=[],this.setHttp(t)}return u(e,[{key:"setHttp",value:function(e){var t=this;this.unsetHttp(),this.http=e;var r=e.interceptors;return this._requestInterceptor=r.request.use(function(e){return t._onRequest(e)},function(e){return t._handleRequestError(e)}),this._responseInterceptor=r.response.use(function(e){return t._onResponse(e)},function(e){return t._handleResponseError(e)}),this}},{key:"unsetHttp",value:function(){var e=this.http;if(this.http){var t=e.interceptors;t.request.eject(this._requestInterceptor),t.response.eject(this._responseInterceptor)}}},{key:"has",value:function(e){return this.middlewares.indexOf(e)>-1}},{key:"register",value:function(e){var t=this;Array.isArray(e)||(e=[e]),e.forEach(function(e){if(t.has(e))throw new Error("Middleware already registered");t.middlewares.push(e)})}},{key:"unregister",value:function(e){var t=this.middlewares.indexOf(e);t>-1&&this.middlewares.splice(t,1)}},{key:"reset",value:function(){this.middlewares.length=0}},{key:"_onRequest",value:function(e){return this.middlewares.reduce(function(e,t){return t.onRequest(e)},e)}},{key:"_handleRequestError",value:function(e){return this.middlewares.forEach(function(t){return t.handleRequestError(e)}),Promise.reject(e)}},{key:"_onResponse",value:function(e){return this.middlewares.reduce(function(e,t){return t.onResponse(e)},e)}},{key:"_handleResponseError",value:function(e){return this.middlewares.forEach(function(t){return t.handleResponseError(e)}),Promise.reject(e)}}]),e}();t.default={HttpMiddleware:o,HttpMiddlewareService:i}}]).default});
/**
* axios-middleware v0.1.2
* (c) 2018 Émile Bergeron
* @license MIT
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.AxiosMiddleware=t()}(this,function(){"use strict";var e=function(){};e.prototype.onRequest=function(e){return e},e.prototype.handleRequestError=function(e){},e.prototype.onResponse=function(e){return e},e.prototype.handleResponseError=function(e){};var t=function(e){this.middlewares=[],this.setHttp(e)};return t.prototype.setHttp=function(e){var t=this;this.unsetHttp(),this.http=e;var r=e.interceptors;return this._requestInterceptor=r.request.use(function(e){return t._onRequest(e)},function(e){return t._handleRequestError(e)}),this._responseInterceptor=r.response.use(function(e){return t._onResponse(e)},function(e){return t._handleResponseError(e)}),this},t.prototype.unsetHttp=function(){var e=this.http;if(this.http){var t=e.interceptors;t.request.eject(this._requestInterceptor),t.response.eject(this._responseInterceptor)}},t.prototype.has=function(e){return this.middlewares.indexOf(e)>-1},t.prototype.register=function(e){var t=this;Array.isArray(e)||(e=[e]),e.forEach(function(e){if(t.has(e))throw new Error("Middleware already registered");t.middlewares.push(e)})},t.prototype.unregister=function(e){var t=this.middlewares.indexOf(e);t>-1&&this.middlewares.splice(t,1)},t.prototype.reset=function(){this.middlewares.length=0},t.prototype._onRequest=function(e){return this.middlewares.reduce(function(e,t){return t.onRequest(e)},e)},t.prototype._handleRequestError=function(e){return this.middlewares.forEach(function(t){return t.handleRequestError(e)}),Promise.reject(e)},t.prototype._onResponse=function(e){return this.middlewares.reduce(function(e,t){return t.onResponse(e)},e)},t.prototype._handleResponseError=function(e){return this.middlewares.forEach(function(t){return t.handleResponseError(e)}),Promise.reject(e)},{HttpMiddleware:e,HttpMiddlewareService:t,version:"0.1.2"}});
{
"name": "axios-middleware",
"version": "0.1.1",
"version": "0.1.2",
"description": "Simple axios HTTP middleware service",
"author": "Emile Bergeron <ber.emile@prismalstudio.com>",
"license": "MIT",
"main": "dist/axios-middleware.js",
"main": "dist/axios-middleware.common.js",
"module": "dist/axios-middleware.esm.js",
"unpkg": "dist/axios-middleware.js",
"bugs": {
"url": "https://github.com/emileber/axios-middleware/issues"
},
"homepage": "https://github.com/emileber/axios-middleware#readme",
"homepage": "https://emileber.github.io/axios-middleware/#/",
"scripts": {

@@ -17,10 +19,10 @@ "clean": "rimraf dist",

"prepublishOnly": "npm run build",
"build": "npm run build:umd && npm run build:umd:min",
"build:umd": "webpack",
"build:umd:min": "cross-env NODE_ENV=production webpack",
"build": "node build/build.main.js",
"build:dev": "rollup -c build/rollup.dev.config.js",
"build:lint-config": "eslint -c .eslintrc.js --print-config .eslintrc.js > .eslintrc.json",
"release": "bash build/release.sh",
"test": "npm run lint && npm run test:unit",
"test:unit": "jest --config test/jest.conf.js",
"test:unit": "npm run build:dev && jest --config test/jest.conf.js",
"test:coverage": "npm run test:unit -- --coverage",
"lint": "eslint src test",
"lint": "eslint src test build",
"docs": "docsify serve ./docs"

@@ -49,10 +51,3 @@ },

"axios-mock-adapter": "^1.11.0",
"babel-core": "^6.22.1",
"babel-eslint": "^8.0.3",
"babel-jest": "^21.0.2",
"babel-loader": "^7.1.1",
"babel-plugin-syntax-trailing-function-commas": "^6.22.0",
"babel-plugin-transform-runtime": "^6.22.0",
"babel-preset-env": "^1.3.2",
"babel-preset-stage-2": "^6.22.0",
"babel-preset-env": "^1.6.1",
"cross-env": "^5.1.3",

@@ -63,3 +58,2 @@ "docsify-cli": "^4.2.0",

"eslint-friendly-formatter": "^3.0.0",
"eslint-import-resolver-webpack": "^0.8.4",
"eslint-loader": "^1.9.0",

@@ -70,10 +64,8 @@ "eslint-plugin-import": "^2.8.0",

"rimraf": "^2.6.0",
"uglifyjs-webpack-plugin": "^1.1.4",
"webpack": "^3.6.0"
},
"browserslist": [
"> 1%",
"last 2 versions",
"not ie < 11"
]
"rollup": "^0.50.0",
"rollup-plugin-buble": "^0.16.0",
"rollup-plugin-replace": "^2.0.0",
"rollup-watch": "^4.3.1",
"uglify-js": "^3.1.2"
}
}
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