UNPKG

etherscan-api-e

Version:
1,686 lines (1,464 loc) 78.4 kB
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.etherscanApi = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ 'use strict'; const init = require('./lib/init'); module.exports = { init }; },{"./lib/init":6}],2:[function(require,module,exports){ const querystring = require('querystring'); module.exports = function(getRequest, apiKey) { return { /** * Returns the amount of Tokens a specific account owns. * @param {string} address - Contract address * @param {string} tokenname - Name of the token * @param {string} contractaddress - Contract address * @example * var supply = api.account.tokenbalance( * '0x4366ddc115d8cf213c564da36e64c8ebaa30cdbd', * '', * '0xe0b7927c4af23765cb51314a0e0521a9645f0e2a' // DGD contract address * ); * @returns {Promise.<object>} */ tokenbalance(address, tokenname, contractaddress) { const module = 'account'; const action = 'tokenbalance'; const tag = 'latest'; var queryObject = { module, action, apiKey, tag }; if (contractaddress) { queryObject.contractaddress = contractaddress; } if (tokenname) { queryObject.tokenname = tokenname; } if (address) { queryObject.address = address; } var query = querystring.stringify(queryObject); return getRequest(query); }, /** * Returns the balance of a sepcific account * @param {string} address - Address * @example * var balance = api.account.balance('0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae'); * @returns {Promise.<object>} */ balance(address) { const module = 'account'; let action = 'balance'; const tag = 'latest'; if (typeof address !== 'string' && address && address.length) { address = address.join(','); action = 'balancemulti'; } var query = querystring.stringify({ module, action, tag, address, apiKey }); return getRequest(query); }, /** * Get a list of internal transactions * @param {string} txhash - Transaction hash. If specified then address will be ignored * @param {string} address - Transaction address * @param {string} startblock - start looking here * @param {string} endblock - end looking there * @param {string} sort - Sort asc/desc * @example * var txlist = api.account.txlistinternal('0x40eb908387324f2b575b4879cd9d7188f69c8fc9d87c901b9e2daaea4b442170'); * @returns {Promise.<object>} */ txlistinternal(txhash, address, startblock, endblock, sort) { const module = 'account'; const action = 'txlistinternal'; var queryObject = { module, action, apiKey }; if (!startblock) { startblock = 0; } queryObject.startblock = startblock; if (!endblock) { endblock = 'latest'; } queryObject.endblock = endblock; if (!sort) { sort = 'asc'; } queryObject.sort = sort; if (txhash) { queryObject.txhash = txhash; } else { queryObject.address = address; } queryObject.txhash = txhash; return getRequest(querystring.stringify(queryObject)); }, /** * Get a list of transactions for a specfic address * @param {string} address - Transaction address * @param {string} startblock - start looking here * @param {string} endblock - end looking there * @param {number} page - Page number * @param {number} offset - Max records to return * @param {string} sort - Sort asc/desc * @example * var txlist = api.account.txlist('0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae', 1, 'latest', 1, 100, 'asc'); * @returns {Promise.<object>} */ txlist(address, startblock, endblock, page, offset, sort) { const module = 'account'; const action = 'txlist'; if (!startblock) { startblock = 0; } if (!endblock) { endblock = 'latest'; } if (!page) { page = 1; } if (!offset) { offset = 100; } if (!sort) { sort = 'asc'; } var query = querystring.stringify({ module, action, startblock, endblock, page, offset, sort, address, apiKey }); return getRequest(query); }, /** * Get a list of blocks that a specific account has mineds * @example * var txlist = api.account.getminedblocks('0x9dd134d14d1e65f84b706d6f205cd5b1cd03a46b'); * @param {string} address - Transaction hash */ getminedblocks(address) { const module = 'account'; const action = 'getminedblocks'; var query = querystring.stringify({ module, action, address, apiKey }); return getRequest(query); }, /** * [BETA] Get a list of "ERC20 - Token Transfer Events" by Address * @param {string} address - Account address * @param {string} startblock - start looking here * @param {string} endblock - end looking there * @param {number} page - Page number * @param {number} offset - Max records to return * @param {string} sort - Sort asc/desc * @param {string} contractaddress - Address of ERC20 token contract (if not specified lists transfers for all tokens) * @example * var txlist = api.account.tokentx('0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae', '0x5F988D968cb76c34C87e6924Cc1Ef1dCd4dE75da', 1, 'latest', 'asc'); * @returns {Promise.<object>} */ tokentx(address, contractaddress, startblock, endblock, page, offset, sort) { const module = 'account'; const action = 'tokentx'; if (!startblock) { startblock = 0; } if (!endblock) { endblock = 'latest'; } if (!page) { page = 1; } if (!offset) { offset = 100; } if (!sort) { sort = 'asc'; } var queryObject = { module, action, startblock, endblock, page, offset, sort, address, apiKey }; if (contractaddress) { queryObject.contractaddress = contractaddress; } return getRequest(querystring.stringify(queryObject)); } }; }; },{"querystring":40}],3:[function(require,module,exports){ const querystring = require('querystring'); module.exports = function(getRequest, apiKey) { return { /** * Find the block reward for a given address and block * @param {string} address - Address of the block * @param {string} blockno - Block number * @returns {Promise.<object>} */ getblockreward(address, blockno) { const module = 'block'; const action = 'getblockreward'; if (!blockno) { blockno = 0; } var query = querystring.stringify({ module, action, address, blockno, apiKey }); return getRequest(query); } }; }; },{"querystring":40}],4:[function(require,module,exports){ const querystring = require('querystring'); module.exports = function(getRequest, apiKey) { return { /** * Returns the ABI/Interface of a given contract * @param {string} address - Contract address * @example * api.contract * .getabi('0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359') * .at('0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359') * .memberId('0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359') * .then(console.log) * @returns {Promise.<object>} */ getabi(address) { const module = 'contract'; const action = 'getabi'; var query = querystring.stringify({ module, action, address, apiKey }); return getRequest(query); } }; }; },{"querystring":40}],5:[function(require,module,exports){ const axios = require('axios'); /** * @param {string} chain * @returns {string} */ function pickChainUrl(chain) { if (!chain || !TESTNET_API_URL_MAP[chain]) { return MAIN_API_URL; } return TESTNET_API_URL_MAP[chain]; } const MAIN_API_URL = 'https://api.etherscan.io'; const TESTNET_API_URL_MAP = { ropsten: 'https://api-ropsten.etherscan.io', kovan: 'https://api-kovan.etherscan.io', rinkeby: 'https://api-rinkeby.etherscan.io', homestead: 'https://api.etherscan.io', heco_mainnet: 'https://api.hecoinfo.com', heco_testnet: 'https://api-testnet.hecoinfo.com', bsc_mainnet: 'https://api.bscscan.com', bsc_testnet: 'https://api-testnet.bscscan.com', matic_mainnet: 'https://api.polygonscan.com', matic_mumbai: 'https://api-testnet.polygonscan.com', }; module.exports = function(chain, timeout, proxyUrl, headers) { var param = { timeout: timeout }; var baseUrl = pickChainUrl(chain); if (proxyUrl && 0 < proxyUrl.length) { if (proxyUrl.charAt(proxyUrl.length - 1) == '/') { baseUrl = proxyUrl + baseUrl; } else { baseUrl = proxyUrl + '/' + baseUrl; } } param['baseURL'] = baseUrl; if (headers) { param['headers'] = headers; } var client = axios.create(param); /** * @param query * @returns {Promise<any>} */ function getRequest(query) { return new Promise(function(resolve, reject) { client.get('/api?' + query).then(function(response) { var data = response.data; if (data.status && data.status != 1) { let returnMessage = data.message ||'NOTOK'; if (data.result && typeof data.result === 'string') { returnMessage = data.result; } else if (data.message && typeof data.message === 'string') { returnMessage = data.message; } return reject(returnMessage); } if (data.error) { var message = data.error; if(typeof data.error === 'object' && data.error.message){ message = data.error.message; } return reject(new Error(message)); } resolve(data); }).catch(function(error) { return reject(new Error(error)); }); }); } return getRequest; }; },{"axios":11}],6:[function(require,module,exports){ "use strict"; const log = require('./log'); const proxy = require('./proxy'); const stats = require('./stats'); const block = require('./block'); const transaction = require('./transaction'); const contract = require('./contract'); const account = require('./account'); /** * @module etherscan/api */ /** * @param {string} apiKey - (optional) Your Etherscan APIkey * @param {string} chain - (optional) Testnet chain keys [ropsten, rinkeby, kovan] * @param {number} timeout - (optional) Timeout in milliseconds for requests, default 10000 * @param {string} proxyUrl - (optional) The URL of proxy server to avoid CORS * @param {object} headers - (optional) The object containing custom headers */ module.exports = function(apiKey, chain, timeout, proxyUrl, headers) { if (!apiKey) { apiKey = 'YourApiKeyToken'; } if (!timeout) { timeout = 10000; } var getRequest = require('./get-request')(chain, timeout, proxyUrl, headers); /** @lends module:etherscan/api */ return { /** * @namespace */ log: log(getRequest, apiKey), /** * @namespace */ proxy: proxy(getRequest, apiKey), /** * @namespace */ stats: stats(getRequest, apiKey), /** * @namespace */ block: block(getRequest, apiKey), /** * @namespace */ transaction: transaction(getRequest, apiKey), /** * @namespace */ contract: contract(getRequest, apiKey), /** * @namespace */ account: account(getRequest, apiKey) }; }; },{"./account":2,"./block":3,"./contract":4,"./get-request":5,"./log":7,"./proxy":8,"./stats":9,"./transaction":10}],7:[function(require,module,exports){ const querystring = require('querystring'); module.exports = function(getRequest, apiKey) { return { /** * The Event Log API was designed to provide an alternative to the native eth_getLogs. */ /** * returns the status of a specific transaction hash * @param {string} fromBlock - fromBlock * @param {string} toBlock - toBlock * @param {string} topic0 - topic (32 Bytes per topic) * @param {string} topic0_1_opr - and|or between topic0 & topic1 * @param {string} topic1 - topic (32 Bytes per topic) * @param {string} topic1_2_opr - and|or between topic1 & topic2 * @param {string} topic2 - topic (32 Bytes per topic) * @param {string} topic2_3_opr - and|or between topic2 & topic3 * @param {string} topic3 - topic (32 Bytes per topic) * @param {string} topic0_2_opr - and|or between topic0 & topic2 * @example https://etherscan.io/apis#logs * @returns {Promise.<object>} */ getLogs(address, fromBlock, toBlock, topic0, topic0_1_opr, topic1, topic1_2_opr, topic2, topic2_3_opr, topic3, topic0_2_opr) { const module = 'logs'; const action = 'getLogs'; var params = { module, action, apiKey, address }; if (address) { params.address = address; } if (fromBlock) { params.fromBlock = fromBlock; } if (toBlock) { params.toBlock = toBlock; } if (topic0) { params.topic0 = topic0; } if (topic0_1_opr) { params.topic0_1_opr = topic0_1_opr; } if (topic1) { params.topic1 = topic1; } if (topic1_2_opr) { params.topic1_2_opr = topic1_2_opr; } if (topic2) { params.topic2 = topic2; } if (topic2_3_opr) { params.topic2_3_opr = topic2_3_opr; } if (topic0_2_opr) { params.topic0_2_opr = topic0_2_opr; } if (topic3) { params.topic3 = topic3; } var query = querystring.stringify(params); return getRequest(query); } }; }; },{"querystring":40}],8:[function(require,module,exports){ const querystring = require('querystring'); module.exports =function(getRequest, apiKey) { return { /** * Returns the number of most recent block * @example * var block = api.proxy.eth_blockNumber(); * @returns {Promise.<integer>} */ eth_blockNumber() { const module = 'proxy'; const action = 'eth_blockNumber'; var query = querystring.stringify({ module, action, apiKey }); return getRequest(query); }, /** * Returns information about a block by block number. * @param {string} tag - Tag to look up * @example * var blockNumber = api.proxy.eth_getBlockByNumber('0x10d4f'); * @returns {Promise.<integer>} */ eth_getBlockByNumber(tag) { const module = 'proxy'; const action = 'eth_getBlockByNumber'; const boolean = true; var query = querystring.stringify({ module, action, tag, apiKey, boolean }); return getRequest(query); }, /** * Returns information about a uncle by block number. * @param {string} tag - Tag to look up * @param {string} index - Index * @example * var res = api.proxy.eth_getUncleByBlockNumberAndIndex('0x210A9B', '0x0'); * @returns {Promise.<object>} */ eth_getUncleByBlockNumberAndIndex(tag, index) { const module = 'proxy'; const action = 'eth_getUncleByBlockNumberAndIndex'; var query = querystring.stringify({ module, action, apiKey, tag, index }); return getRequest(query); }, /** * Returns the number of transactions in a block from a block matching the given block number * @param {string} tag - Tag to look up * @example * var res = api.proxy.eth_getBlockTransactionCountByNumber('0x10FB78'); * @returns {Promise.<object>} */ eth_getBlockTransactionCountByNumber(tag) { const module = 'proxy'; const action = 'eth_getBlockTransactionCountByNumber'; var query = querystring.stringify({ module, action, apiKey, tag }); return getRequest(query); }, /** * Returns the information about a transaction requested by transaction hash * @param {string} hash - Transaction hash * @example * var res = api.proxy.eth_getTransactionByHash('0x1e2910a262b1008d0616a0beb24c1a491d78771baa54a33e66065e03b1f46bc1'); * @returns {Promise.<object>} */ eth_getTransactionByHash(txhash) { const module = 'proxy'; const action = 'eth_getTransactionByHash'; var query = querystring.stringify({ module, action, apiKey, txhash }); return getRequest(query); }, /** * Returns information about a transaction by block number and transaction index position * @param {string} tag - Tag to look up * @param {string} index - Index * @example * var res = api.proxy.eth_getTransactionByBlockNumberAndIndex('0x10d4f', '0x0'); * @returns {Promise.<object>} */ eth_getTransactionByBlockNumberAndIndex(tag, index) { const module = 'proxy'; const action = 'eth_getTransactionByBlockNumberAndIndex'; var query = querystring.stringify({ module, action, apiKey, tag, index }); return getRequest(query); }, /** * Returns the number of transactions sent from an address * @param {string} address - Address of the transaction * @example * var res = api.proxy.eth_getTransactionCount('0x2910543af39aba0cd09dbb2d50200b3e800a63d2', 'latest'); * @returns {Promise.<object>} */ eth_getTransactionCount(address) { const module = 'proxy'; const action = 'eth_getTransactionCount'; var query = querystring.stringify({ module, action, apiKey, address }); return getRequest(query); }, /** * Creates new message call transaction or a contract creation for signed transactions * @param {string} hex - Serialized Message * @example * var res = api.proxy.eth_sendRawTransaction('0xf904808000831cfde080'); * @returns {Promise.<object>} */ eth_sendRawTransaction(hex) { const module = 'proxy'; const action = 'eth_sendRawTransaction'; var query = querystring.stringify({ module, action, apiKey, hex }); return getRequest(query); }, /** * Returns the receipt of a transaction by transaction hash * @param {string} txhash - Transaction hash * @example * var ret = api.proxy.eth_getTransactionReceipt('0x1e2910a262b1008d0616a0beb24c1a491d78771baa54a33e66065e03b1f46bc1'); * @returns {Promise.<object>} */ eth_getTransactionReceipt(txhash) { const module = 'proxy'; const action = 'eth_getTransactionReceipt'; var query = querystring.stringify({ module, action, apiKey, txhash }); return getRequest(query); }, /** * Executes a new message call immediately without creating a transaction on the block chain * @param {string} to - Address to execute from * @param {string} data - Data to transfer * @param {string} tag - A tag * @example * var res = api.proxy.eth_call('0xAEEF46DB4855E25702F8237E8f403FddcaF931C0', '0x70a08231000000000000000000000000e16359506c028e51f16be38986ec5746251e9724', 'latest'); * @returns {Promise.<object>} */ eth_call(to, data, tag) { const module = 'proxy'; const action = 'eth_call'; var query = querystring.stringify({ module, action, apiKey, to, data, tag }); return getRequest(query); }, /** * Returns code at a given address * @param {string} address - Address to get code from * @param {string} tag - ?? * @example * var res = api.proxy.eth_getCode('0xf75e354c5edc8efed9b59ee9f67a80845ade7d0c', 'latest'); * @returns {Promise.<object>} */ eth_getCode(address, tag) { const module = 'proxy'; const action = 'eth_getCode'; var query = querystring.stringify({ module, action, apiKey, address, tag }); return getRequest(query); }, /** * Returns the value from a storage position at a given address. * @param {string} address - Address to get code from * @param {string} position - Storage position * @param {string} tag - ?? * @example * var res = api.proxy.eth_getStorageAt('0x6e03d9cce9d60f3e9f2597e13cd4c54c55330cfd', '0x0', 'latest'); * @returns {Promise.<object>} */ eth_getStorageAt(address, position, tag) { const module = 'proxy'; const action = 'eth_getStorageAt'; var query = querystring.stringify({ module, action, apiKey, address, position, tag }); return getRequest(query); }, /** * Returns the current price per gas in wei. * var gasprice = api.proxy.eth_gasPrice(); * @returns {Promise.<object>} */ eth_gasPrice() { const module = 'proxy'; const action = 'eth_gasPrice'; var query = querystring.stringify({ module, action, apiKey }); return getRequest(query); }, /** * Makes a call or transaction, which won't be added to the blockchain and returns the used gas, which can be used for estimating the used gas * @param {string} to - Address to get code from * @param {string} value - Storage position * @param {string} gasPrice - ?? * @param {string} gas - ?? * @xample * var res = api.proxy.eth_estimateGas( * '0xf0160428a8552ac9bb7e050d90eeade4ddd52843', * '0xff22', * '0x051da038cc', * '0xffffff' *); * @returns {Promise.<object>} */ eth_estimateGas(to, value, gasPrice, gas) { const module = 'proxy'; const action = 'eth_estimateGas'; var query = querystring.stringify({ module, action, apiKey, to, value, gasPrice, gas }); return getRequest(query); }, }; }; },{"querystring":40}],9:[function(require,module,exports){ const querystring = require('querystring'); module.exports = function(getRequest, apiKey) { return { /** * Returns the supply of Tokens * @param {string} tokenname - Name of the Token * @param {string} contractaddress - Address from token contract * @example * var supply = api.stats.tokensupply(null, '0x57d90b64a1a57749b0f932f1a3395792e12e7055'); * @returns {Promise.<object>} */ tokensupply(tokenname, contractaddress) { const module = 'stats'; const action = 'tokensupply'; let params = { module, action, apiKey }; if (tokenname) { params.tokenname = tokenname; } if (contractaddress) { params.contractaddress = contractaddress; } var query = querystring.stringify(params); return getRequest(query); }, /** * Returns total supply of ether * var supply = api.stats.ethsupply(); * @returns {Promise.<integer>} */ ethsupply() { const module = 'stats'; const action = 'ethsupply'; var query = querystring.stringify({ module, action, apiKey }); return getRequest(query); }, /** * Returns the price of ether now * @example * var price = api.stats.ethprice(); * @returns {Promise.<integer>} */ ethprice() { const module = 'stats'; const action = 'ethprice'; var query = querystring.stringify({ module, action, apiKey }); return getRequest(query); } }; }; },{"querystring":40}],10:[function(require,module,exports){ const querystring = require('querystring'); module.exports = function(getRequest, apiKey) { return { /** * returns the status of a specific transaction hash * @param {string} txhash - Transaction hash * @returns {Promise.<object>} */ getstatus(txhash) { const module = 'transaction'; const action = 'getstatus'; var query = querystring.stringify({ module, action, txhash, apiKey }); return getRequest(query); } }; }; },{"querystring":40}],11:[function(require,module,exports){ module.exports = require('./lib/axios'); },{"./lib/axios":13}],12:[function(require,module,exports){ 'use strict'; var utils = require('./../utils'); var settle = require('./../core/settle'); var buildURL = require('./../helpers/buildURL'); var parseHeaders = require('./../helpers/parseHeaders'); var isURLSameOrigin = require('./../helpers/isURLSameOrigin'); var createError = require('../core/createError'); module.exports = function xhrAdapter(config) { return new Promise(function dispatchXhrRequest(resolve, reject) { var requestData = config.data; var requestHeaders = config.headers; if (utils.isFormData(requestData)) { delete requestHeaders['Content-Type']; // Let the browser set it } var request = new XMLHttpRequest(); // HTTP basic authentication if (config.auth) { var username = config.auth.username || ''; var password = config.auth.password || ''; requestHeaders.Authorization = 'Basic ' + btoa(username + ':' + password); } request.open(config.method.toUpperCase(), buildURL(config.url, config.params, config.paramsSerializer), true); // Set the request timeout in MS request.timeout = config.timeout; // Listen for ready state request.onreadystatechange = function handleLoad() { if (!request || request.readyState !== 4) { return; } // The request errored out and we didn't get a response, this will be // handled by onerror instead // With one exception: request that using file: protocol, most browsers // will return status as 0 even though it's a successful request if (request.status === 0 && !(request.responseURL && request.responseURL.indexOf('file:') === 0)) { return; } // Prepare the response var responseHeaders = 'getAllResponseHeaders' in request ? parseHeaders(request.getAllResponseHeaders()) : null; var responseData = !config.responseType || config.responseType === 'text' ? request.responseText : request.response; var response = { data: responseData, status: request.status, statusText: request.statusText, headers: responseHeaders, config: config, request: request }; settle(resolve, reject, response); // Clean up request request = null; }; // Handle browser request cancellation (as opposed to a manual cancellation) request.onabort = function handleAbort() { if (!request) { return; } reject(createError('Request aborted', config, 'ECONNABORTED', request)); // Clean up request request = null; }; // Handle low level network errors request.onerror = function handleError() { // Real errors are hidden from us by the browser // onerror should only fire if it's a network error reject(createError('Network Error', config, null, request)); // Clean up request request = null; }; // Handle timeout request.ontimeout = function handleTimeout() { reject(createError('timeout of ' + config.timeout + 'ms exceeded', config, 'ECONNABORTED', request)); // Clean up request request = null; }; // Add xsrf header // This is only done if running in a standard browser environment. // Specifically not if we're in a web worker, or react-native. if (utils.isStandardBrowserEnv()) { var cookies = require('./../helpers/cookies'); // Add xsrf header var xsrfValue = (config.withCredentials || isURLSameOrigin(config.url)) && config.xsrfCookieName ? cookies.read(config.xsrfCookieName) : undefined; if (xsrfValue) { requestHeaders[config.xsrfHeaderName] = xsrfValue; } } // Add headers to the request if ('setRequestHeader' in request) { utils.forEach(requestHeaders, function setRequestHeader(val, key) { if (typeof requestData === 'undefined' && key.toLowerCase() === 'content-type') { // Remove Content-Type if data is undefined delete requestHeaders[key]; } else { // Otherwise add header to the request request.setRequestHeader(key, val); } }); } // Add withCredentials to request if needed if (config.withCredentials) { request.withCredentials = true; } // Add responseType to request if needed if (config.responseType) { try { request.responseType = config.responseType; } catch (e) { // Expected DOMException thrown by browsers not compatible XMLHttpRequest Level 2. // But, this can be suppressed for 'json' type as it can be parsed by default 'transformResponse' function. if (config.responseType !== 'json') { throw e; } } } // Handle progress if needed if (typeof config.onDownloadProgress === 'function') { request.addEventListener('progress', config.onDownloadProgress); } // Not all browsers support upload events if (typeof config.onUploadProgress === 'function' && request.upload) { request.upload.addEventListener('progress', config.onUploadProgress); } if (config.cancelToken) { // Handle cancellation config.cancelToken.promise.then(function onCanceled(cancel) { if (!request) { return; } request.abort(); reject(cancel); // Clean up request request = null; }); } if (requestData === undefined) { requestData = null; } // Send the request request.send(requestData); }); }; },{"../core/createError":19,"./../core/settle":23,"./../helpers/buildURL":27,"./../helpers/cookies":29,"./../helpers/isURLSameOrigin":31,"./../helpers/parseHeaders":33,"./../utils":35}],13:[function(require,module,exports){ 'use strict'; var utils = require('./utils'); var bind = require('./helpers/bind'); var Axios = require('./core/Axios'); var mergeConfig = require('./core/mergeConfig'); var defaults = require('./defaults'); /** * Create an instance of Axios * * @param {Object} defaultConfig The default config for the instance * @return {Axios} A new instance of Axios */ function createInstance(defaultConfig) { var context = new Axios(defaultConfig); var instance = bind(Axios.prototype.request, context); // Copy axios.prototype to instance utils.extend(instance, Axios.prototype, context); // Copy context to instance utils.extend(instance, context); return instance; } // Create the default instance to be exported var axios = createInstance(defaults); // Expose Axios class to allow class inheritance axios.Axios = Axios; // Factory for creating new instances axios.create = function create(instanceConfig) { return createInstance(mergeConfig(axios.defaults, instanceConfig)); }; // Expose Cancel & CancelToken axios.Cancel = require('./cancel/Cancel'); axios.CancelToken = require('./cancel/CancelToken'); axios.isCancel = require('./cancel/isCancel'); // Expose all/spread axios.all = function all(promises) { return Promise.all(promises); }; axios.spread = require('./helpers/spread'); module.exports = axios; // Allow use of default import syntax in TypeScript module.exports.default = axios; },{"./cancel/Cancel":14,"./cancel/CancelToken":15,"./cancel/isCancel":16,"./core/Axios":17,"./core/mergeConfig":22,"./defaults":25,"./helpers/bind":26,"./helpers/spread":34,"./utils":35}],14:[function(require,module,exports){ 'use strict'; /** * A `Cancel` is an object that is thrown when an operation is canceled. * * @class * @param {string=} message The message. */ function Cancel(message) { this.message = message; } Cancel.prototype.toString = function toString() { return 'Cancel' + (this.message ? ': ' + this.message : ''); }; Cancel.prototype.__CANCEL__ = true; module.exports = Cancel; },{}],15:[function(require,module,exports){ 'use strict'; var Cancel = require('./Cancel'); /** * A `CancelToken` is an object that can be used to request cancellation of an operation. * * @class * @param {Function} executor The executor function. */ function CancelToken(executor) { if (typeof executor !== 'function') { throw new TypeError('executor must be a function.'); } var resolvePromise; this.promise = new Promise(function promiseExecutor(resolve) { resolvePromise = resolve; }); var token = this; executor(function cancel(message) { if (token.reason) { // Cancellation has already been requested return; } token.reason = new Cancel(message); resolvePromise(token.reason); }); } /** * Throws a `Cancel` if cancellation has been requested. */ CancelToken.prototype.throwIfRequested = function throwIfRequested() { if (this.reason) { throw this.reason; } }; /** * Returns an object that contains a new `CancelToken` and a function that, when called, * cancels the `CancelToken`. */ CancelToken.source = function source() { var cancel; var token = new CancelToken(function executor(c) { cancel = c; }); return { token: token, cancel: cancel }; }; module.exports = CancelToken; },{"./Cancel":14}],16:[function(require,module,exports){ 'use strict'; module.exports = function isCancel(value) { return !!(value && value.__CANCEL__); }; },{}],17:[function(require,module,exports){ 'use strict'; var utils = require('./../utils'); var buildURL = require('../helpers/buildURL'); var InterceptorManager = require('./InterceptorManager'); var dispatchRequest = require('./dispatchRequest'); var mergeConfig = require('./mergeConfig'); /** * Create a new instance of Axios * * @param {Object} instanceConfig The default config for the instance */ function Axios(instanceConfig) { this.defaults = instanceConfig; this.interceptors = { request: new InterceptorManager(), response: new InterceptorManager() }; } /** * Dispatch a request * * @param {Object} config The config specific for this request (merged with this.defaults) */ Axios.prototype.request = function request(config) { /*eslint no-param-reassign:0*/ // Allow for axios('example/url'[, config]) a la fetch API if (typeof config === 'string') { config = arguments[1] || {}; config.url = arguments[0]; } else { config = config || {}; } config = mergeConfig(this.defaults, config); config.method = config.method ? config.method.toLowerCase() : 'get'; // Hook up interceptors middleware var chain = [dispatchRequest, undefined]; var promise = Promise.resolve(config); this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) { chain.unshift(interceptor.fulfilled, interceptor.rejected); }); this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) { chain.push(interceptor.fulfilled, interceptor.rejected); }); while (chain.length) { promise = promise.then(chain.shift(), chain.shift()); } return promise; }; Axios.prototype.getUri = function getUri(config) { config = mergeConfig(this.defaults, config); return buildURL(config.url, config.params, config.paramsSerializer).replace(/^\?/, ''); }; // Provide aliases for supported request methods utils.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoData(method) { /*eslint func-names:0*/ Axios.prototype[method] = function(url, config) { return this.request(utils.merge(config || {}, { method: method, url: url })); }; }); utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) { /*eslint func-names:0*/ Axios.prototype[method] = function(url, data, config) { return this.request(utils.merge(config || {}, { method: method, url: url, data: data })); }; }); module.exports = Axios; },{"../helpers/buildURL":27,"./../utils":35,"./InterceptorManager":18,"./dispatchRequest":20,"./mergeConfig":22}],18:[function(require,module,exports){ 'use strict'; var utils = require('./../utils'); function InterceptorManager() { this.handlers = []; } /** * Add a new interceptor to the stack * * @param {Function} fulfilled The function to handle `then` for a `Promise` * @param {Function} rejected The function to handle `reject` for a `Promise` * * @return {Number} An ID used to remove interceptor later */ InterceptorManager.prototype.use = function use(fulfilled, rejected) { this.handlers.push({ fulfilled: fulfilled, rejected: rejected }); return this.handlers.length - 1; }; /** * Remove an interceptor from the stack * * @param {Number} id The ID that was returned by `use` */ InterceptorManager.prototype.eject = function eject(id) { if (this.handlers[id]) { this.handlers[id] = null; } }; /** * Iterate over all the registered interceptors * * This method is particularly useful for skipping over any * interceptors that may have become `null` calling `eject`. * * @param {Function} fn The function to call for each interceptor */ InterceptorManager.prototype.forEach = function forEach(fn) { utils.forEach(this.handlers, function forEachHandler(h) { if (h !== null) { fn(h); } }); }; module.exports = InterceptorManager; },{"./../utils":35}],19:[function(require,module,exports){ 'use strict'; var enhanceError = require('./enhanceError'); /** * Create an Error with the specified message, config, error code, request and response. * * @param {string} message The error message. * @param {Object} config The config. * @param {string} [code] The error code (for example, 'ECONNABORTED'). * @param {Object} [request] The request. * @param {Object} [response] The response. * @returns {Error} The created error. */ module.exports = function createError(message, config, code, request, response) { var error = new Error(message); return enhanceError(error, config, code, request, response); }; },{"./enhanceError":21}],20:[function(require,module,exports){ 'use strict'; var utils = require('./../utils'); var transformData = require('./transformData'); var isCancel = require('../cancel/isCancel'); var defaults = require('../defaults'); var isAbsoluteURL = require('./../helpers/isAbsoluteURL'); var combineURLs = require('./../helpers/combineURLs'); /** * Throws a `Cancel` if cancellation has been requested. */ function throwIfCancellationRequested(config) { if (config.cancelToken) { config.cancelToken.throwIfRequested(); } } /** * Dispatch a request to the server using the configured adapter. * * @param {object} config The config that is to be used for the request * @returns {Promise} The Promise to be fulfilled */ module.exports = function dispatchRequest(config) { throwIfCancellationRequested(config); // Support baseURL config if (config.baseURL && !isAbsoluteURL(config.url)) { config.url = combineURLs(config.baseURL, config.url); } // Ensure headers exist config.headers = config.headers || {}; // Transform request data config.data = transformData( config.data, config.headers, config.transformRequest ); // Flatten headers config.headers = utils.merge( config.headers.common || {}, config.headers[config.method] || {}, config.headers || {} ); utils.forEach( ['delete', 'get', 'head', 'post', 'put', 'patch', 'common'], function cleanHeaderConfig(method) { delete config.headers[method]; } ); var adapter = config.adapter || defaults.adapter; return adapter(config).then(function onAdapterResolution(response) { throwIfCancellationRequested(config); // Transform response data response.data = transformData( response.data, response.headers, config.transformResponse ); return response; }, function onAdapterRejection(reason) { if (!isCancel(reason)) { throwIfCancellationRequested(config); // Transform response data if (reason && reason.response) { reason.response.data = transformData( reason.response.data, reason.response.headers, config.transformResponse ); } } return Promise.reject(reason); }); }; },{"../cancel/isCancel":16,"../defaults":25,"./../helpers/combineURLs":28,"./../helpers/isAbsoluteURL":30,"./../utils":35,"./transformData":24}],21:[function(require,module,exports){ 'use strict'; /** * Update an Error with the specified config, error code, and response. * * @param {Error} error The error to update. * @param {Object} config The config. * @param {string} [code] The error code (for example, 'ECONNABORTED'). * @param {Object} [request] The request. * @param {Object} [response] The response. * @returns {Error} The error. */ module.exports = function enhanceError(error, config, code, request, response) { error.config = config; if (code) { error.code = code; } error.request = request; error.response = response; error.isAxiosError = true; error.toJSON = function() { return { // Standard message: this.message, name: this.name, // Microsoft description: this.description, number: this.number, // Mozilla fileName: this.fileName, lineNumber: this.lineNumber, columnNumber: this.columnNumber, stack: this.stack, // Axios config: this.config, code: this.code }; }; return error; }; },{}],22:[function(require,module,exports){ 'use strict'; var utils = require('../utils'); /** * Config-specific merge-function which creates a new config-object * by merging two configuration objects together. * * @param {Object} config1 * @param {Object} config2 * @returns {Object} New object resulting from merging config2 to config1 */ module.exports = function mergeConfig(config1, config2) { // eslint-disable-next-line no-param-reassign config2 = config2 || {}; var config = {}; utils.forEach(['url', 'method', 'params', 'data'], function valueFromConfig2(prop) { if (typeof config2[prop] !== 'undefined') { config[prop] = config2[prop]; } }); utils.forEach(['headers', 'auth', 'proxy'], function mergeDeepProperties(prop) { if (utils.isObject(config2[prop])) { config[prop] = utils.deepMerge(config1[prop], config2[prop]); } else if (typeof config2[prop] !== 'undefined') { config[prop] = config2[prop]; } else if (utils.isObject(config1[prop])) { config[prop] = utils.deepMerge(config1[prop]); } else if (typeof config1[prop] !== 'undefined') { config[prop] = config1[prop]; } }); utils.forEach([ 'baseURL', 'transformRequest', 'transformResponse', 'paramsSerializer', 'timeout', 'withCredentials', 'adapter', 'responseType', 'xsrfCookieName', 'xsrfHeaderName', 'onUploadProgress', 'onDownloadProgress', 'maxContentLength', 'validateStatus', 'maxRedirects', 'httpAgent', 'httpsAgent', 'cancelToken', 'socketPath' ], function defaultToConfig2(prop) { if (typeof config2[prop] !== 'undefined') { config[prop] = config2[prop]; } else if (typeof config1[prop] !== 'undefined') { config[prop] = config1[prop]; } }); return config; }; },{"../utils":35}],23:[function(require,module,exports){ 'use strict'; var createError = require('./createError'); /** * Resolve or reject a Promise based on response status. * * @param {Function} resolve A function that resolves the promise. * @param {Function} reject A function that rejects the promise. * @param {object} response The response. */ module.exports = function settle(resolve, reject, response) { var validateStatus = response.config.validateStatus; if (!validateStatus || validateStatus(response.status)) { resolve(response); } else { reject(createError( 'Request failed with status code ' + response.status, response.config, null, response.request, response )); } }; },{"./createError":19}],24:[function(require,module,exports){ 'use strict'; var utils = require('./../utils'); /** * Transform the data for a request or a response * * @param {Object|String} data The data to be transformed * @param {Array} headers The headers for the request or response * @param {Array|Function} fns A single function or Array of functions * @returns {*} The resulting transformed data */ module.exports = function transformData(data, headers, fns) { /*eslint no-param-reassign:0*/ utils.forEach(fns, function transform(fn) { data = fn(data, headers); }); return data; }; },{"./../utils":35}],25:[function(require,module,exports){ (function (process){ 'use strict'; var utils = require('./utils'); var normalizeHeaderName = require('./helpers/normalizeHeaderName'); var DEFAULT_CONTENT_TYPE = { 'Content-Type': 'application/x-www-form-urlencoded' }; function setContentTypeIfUnset(headers, value) { if (!utils.isUndefined(headers) && utils.isUndefined(headers['Content-Type'])) { headers['Content-Type'] = value; } } function getDefaultAdapter() { var adapter; // Only Node.JS has a process variable that is of [[Class]] process if (typeof process !== 'undefined' && Object.prototype.toString.call(process) === '[object process]') { // For node use HTTP adapter adapter = require('./adapters/http'); } else if (typeof XMLHttpRequest !== 'undefined') { // For browsers use XHR adapter adapter = require('./adapters/xhr'); } return adapter; } var defaults = { adapter: getDefaultAdapter(), transformRequest: [function transformRequest(data, headers) { normalizeHeaderName(headers, 'Accept'); normalizeHeaderName(headers, 'Content-Type'); if (utils.isFormData(data) || utils.isArrayBuffer(data) || utils.isBuffer(data) || utils.isStream(data) || utils.isFile(data) || utils.isBlob(data) ) { return data; } if (utils.isArrayBufferView(data)) { return data.buffer; } if (utils.isURLSearchParams(data)) { setContentTypeIfUnset(headers, 'application/x-www-form-urlencoded;charset=utf-8'); return data.toString(); } if (utils.isObject(data)) { setContentTypeIfUnset(headers, 'application/json;charset=utf-8'); return JSON.stringify(data); } return data; }], transformResponse: [function transformResponse(data) { /*eslint no-param-reassign:0*/ if (typeof data === 'string') { try { data = JSON.parse(data); } catch (e) { /* Ignore */ } } return data; }], /** * A timeout in milliseconds to abort a request. If set to 0 (default) a * timeout is not created. */ timeout: 0, xsrfCookieName: 'XSRF-TOKEN', xsrfHeaderName: 'X-XSRF-TOKEN', maxContentLength: -1, validateStatus: function validateStatus(status) { return status >= 200 && status < 300; } }; defaults.headers = { common: { 'Accept': 'application/json, text/plain, */*' } }; utils.forEach(['delete', 'get', 'head'], function forEachMethodNoData(method) { defaults.headers[method] = {}; }); utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) { defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE); }); module.exports = defaults; }).call(this,require('_process')) },{"./adapters/http":12,"./adapters/xhr":12,"./helpers/normalizeHeaderName":32,"./utils":35,"_process":37}],26:[function(require,module,exports){ 'use strict'; module.exports = function bind(fn, thisArg) { return function wrap() { var args = new Array(arguments.length); for (var i = 0; i < args.length; i++) { args[i] = arguments[i]; } return fn.apply(thisArg, args); }; }; },{}],27:[function(require,module,exports){ 'use strict'; var utils = require('./../utils'); function encode(val) { return encodeURIComponent(val). replace(/%40/gi, '@'). replace(/%3A/gi, ':'). replace(/%24/g, '$'). replace(/%2C/gi, ','). replace(/%20/g, '+'). replace(/%5B/gi, '['). replace(/%5D/gi, ']'); } /** * Build a URL by appending params to the end * * @param {string} url The base of the url (e.g., http://www.google.com)