From 3fd4ac7ac04aa3a992098b22e987807f170efcc6 Mon Sep 17 00:00:00 2001 From: Chau Nguyen Date: Sat, 13 May 2017 19:22:52 -0700 Subject: [PATCH] [2.0.44] Fixed promise retries on 404s (#7) * Fixing promise retries on 404s * Version bump * README updates --- README.md | 4 ++-- dist/kindred-api.js | 13 +++++++------ dist/kindred-api.min.js | 4 ++-- package.json | 2 +- src/kindred-api.js | 13 +++++++------ 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 14d804e1..f0bb772d 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ Check out [SUMMONER-V3](https://github.com/ChauTNguyen/kindred-api/wiki/SUMMONER * All standard endpoints covered but tournament endpoints. * Supports both **callbacks** and **promises**. * **Burst/Spread** rate limiter that is **enforced per region** and **follows retry headers**. - * Retries on 429 and >= 500. (Doesn't retry on 404) + * **Retries** on 429 and >= 500 **until all calls are successful**. (Doesn't retry on 404) * Built-in **parameter checks** so you can hopefully refer to documentation less! :) * Built-in **caching** (in-memory and Redis). * **Customized expiration timers**. You can set a timer for each endpoint type. Refer to [Caching](https://github.com/ChauTNguyen/kindred-api/wiki/Caching) for more info. @@ -278,7 +278,7 @@ The difference between my site and other applications people seem to be working ## ~~Rate Limiter is not as optimized as it should be.~~ (FIXED 2.0.33) -## Promises retry on 404. +## ~~Promises retry on 404.~~ (FIXED 2.0.43) This is problematic because certain calls such as getCurrentGame, which will hit 404's often, will always retry up to 3 times. diff --git a/dist/kindred-api.js b/dist/kindred-api.js index 04500b92..5e06788f 100644 --- a/dist/kindred-api.js +++ b/dist/kindred-api.js @@ -1011,16 +1011,21 @@ } else { if (statusCode >= 500) { if (self.debug) console.log('!!! resending promise request !!!'); + setTimeout(function () { + (function () { + return resolve(tryRequest()); + }); + }, 1000); setTimeout(function () { return reject('retry'); }, 1000); } else if (statusCode === 429) { if (self.debug) console.log('!!! resending promise request !!!'); setTimeout(function () { - return reject('retry'); + return resolve(tryRequest()); }, response.headers['retry-after'] * 1000 + 50); } else if (error || statusCode >= 400) { - return reject('err:', error, statusCode); + return reject(statusMessage + ' : ' + chalk.yellow(reqUrl)); } else { if (Number.isInteger(cacheParams.ttl) && cacheParams.ttl > 0) self.cache.set({ key: reqUrl, ttl: cacheParams.ttl }, body); return resolve(JSON.parse(body)); @@ -1062,10 +1067,6 @@ }); }; - if (!cb) return tryRequest().catch(tryRequest).catch(tryRequest).catch(tryRequest).then(function (data) { - return data; - }); - return tryRequest(); } }, { diff --git a/dist/kindred-api.min.js b/dist/kindred-api.min.js index e1b4a5a5..ff23e801 100644 --- a/dist/kindred-api.min.js +++ b/dist/kindred-api.min.js @@ -1,2 +1,2 @@ -!function(e,t){if("function"==typeof define&&define.amd)define("kindred-api",["module","redis","double-ended-queue","xregexp","chalk","request","chalk","query-string"],t);else if("undefined"!=typeof exports)t(module,require("redis"),require("double-ended-queue"),require("xregexp"),require("chalk"),require("request"),require("chalk"),require("query-string"));else{var i={exports:{}};t(i,e.redis,e.doubleEndedQueue,e.xregexp,e.chalk,e.request,e.chalk,e.queryString),e.kindredApi=i.exports}}(this,function(e,t,i,n,s,r,o,a){"use strict";function u(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function d(e,t,i){return"boolean"==typeof t&&(i=t,t=void 0),new D({key:e,defaultRegion:t,debug:i,limits:R.DEV,cacheOptions:A[0]})}function g(e,t){e?console.log(e):console.log(t)}var l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},c=function(){function e(e,t){for(var i=0;ithis.cache[e.key].expires?(delete this.cache[e.key],t("expired cache key")):t(null,this.cache[e.key].value):t("cache key doesn't exist")}},{key:"set",value:function(e,t){this.cache[e.key]={expires:e.ttl?this.setExp(Date.now(),e.ttl):null,value:t}}},{key:"setExp",value:function(e,t){return e+1e3*t}}]),e}(),m=function(){function e(i){u(this,e);var n=Object.assign({},i||{},{host:"127.0.0.1",port:6379,keyPrefix:"kindredAPI-"});this.client=t.createClient(n.port,n.host),this.client.on("error",function(e){console.log("Redis error:",e)}),process.on("exit",function(){console.log("closing"),this.client.quit()}),this.prefix=n.keyPrefix}return c(e,[{key:"get",value:function(e,t){this.client.get(this.prefix+e.key,function(e,i){i?t(e,i):t(e)})}},{key:"set",value:function(e,t){this.client.setex(this.prefix+e.key,e.ttl,t)}}]),e}(),y=function(){function e(t,n){u(this,e),this.allowedRequests=t,this.seconds=n,this.madeRequests=new i}return c(e,[{key:"__reload",value:function(){for(var e=(new Date).getTime();this.madeRequests.length>0&&e-this.madeRequests.peekFront()>=50*this.seconds;)this.madeRequests.shift()}},{key:"addRequest",value:function(){this.madeRequests.push((new Date).getTime()+1e3*this.seconds)}},{key:"requestAvailable",value:function(){return this.__reload(),this.madeRequests.length0},string:function(e){return e&&Array.isArray(e)&&N.string(e)&&e.length>0}},C=function(e){var t=!0,i=!1,n=void 0;try{for(var s,r=Object.keys(_)[Symbol.iterator]();!(t=(s=r.next()).done);t=!0){var o=s.value;if(_[o]===e)return!0}}catch(e){i=!0,n=e}finally{try{!t&&r.return&&r.return()}finally{if(i)throw n}}return!1},q={400:"Bad Request",403:"Forbidden",404:"Not Found",415:"Unsupported Media Type",429:"Rate Limit Exceeded",500:"Internal Service Error",503:"Service Unavailable"},O=function(e){var t=q[e];if(t)return t},k=[200,400,500],L=function(e){return e>=k[0]&&e=k[1]&&e0&&void 0!==arguments[0]?arguments[0]:{},i=t.key,n=t.defaultRegion,s=void 0===n?_.NORTH_AMERICA:n,r=t.debug,a=void 0!==r&&r,d=t.limits,g=t.spread,c=t.cacheOptions,p=t.cacheTTL;if(u(this,e),0===arguments.length||"object"!==l(arguments[0])||"string"!=typeof i)throw new Error(""+o.red("API key not passed in!"));if(this.key=i,this.defaultRegion=C(s)?s:void 0,!this.defaultRegion)throw new Error(o.red("setRegion() by Kindred failed: "+o.yellow(s)+" is an invalid region.")+"\n"+o.red("Try importing "+o.yellow("require('./dist/kindred-api').REGIONS")+" and using one of those values instead."));if(this.debug=a,c?(c===A[0]?this.cache=new h:c===A[1]?this.cache=new m:this.cache=new c,this.CACHE_TIMERS=p?p:v):this.cache={get:function(e,t){return t(null,null)},set:function(e,t){}},this.CACHE_TIMERS||(this.CACHE_TIMERS={CHAMPION:0,CHAMPION_MASTERY:0,CURRENT_GAME:0,FEATURED_GAMES:0,GAME:0,LEAGUE:0,STATIC:0,STATUS:0,MATCH:0,MATCH_LIST:0,RUNES_MASTERIES:0,STATS:0,SUMMONER:0}),d){if(w(d))throw console.log(o.red("Initialization of Kindred failed: Invalid "+o.yellow("limits")+". Valid examples: "+o.yellow("[[10, 10], [500, 600]]"))+"."),console.log(o.red("You can also pass in one of these two strings:")+" dev/prod "),console.log(""+o.red("and Kindred will set the limits appropriately.")),new Error;this.limits={},"dev"===d&&(d=R.DEV),"prod"===d&&(d=R.PROD),this.spread=g;var f=!0,I=!1,S=void 0;try{for(var b,E=Object.keys(_)[Symbol.iterator]();!(f=(b=E.next()).done);f=!0){var M=b.value;this.limits[_[M]]=[new y(d[0][0],d[0][1]),new y(d[1][0],d[1][1]),this.spread?new y(d[0][0]/10,.5):null]}}catch(e){I=!0,S=e}finally{try{!f&&E.return&&E.return()}finally{if(I)throw S}}}this.Champion={getChampions:this.getChamps.bind(this),getAll:this.getChamps.bind(this),all:this.getChamps.bind(this),getChampion:this.getChamp.bind(this),get:this.getChamp.bind(this),list:this.listChampions.bind(this),by:{id:this.getChampionById.bind(this)}},this.ChampionMastery={getChampionMastery:this.getChampMastery.bind(this),get:this.getChampMastery.bind(this),getChampionMasteries:this.getChampMasteries.bind(this),getAll:this.getChampMasteries.bind(this),all:this.getChampMasteries.bind(this),getTotalChampionMasteryScore:this.getTotalChampMasteryScore.bind(this),getTotalScore:this.getTotalChampMasteryScore.bind(this),totalScore:this.getTotalChampMasteryScore.bind(this),total:this.getTotalChampMasteryScore.bind(this),score:this.getTotalChampMasteryScore.bind(this)},this.CurrentGame={getCurrentGame:this.getCurrentGame.bind(this),get:this.getCurrentGame.bind(this)},this.FeaturedGames={getFeaturedGames:this.getFeaturedGames.bind(this),get:this.getFeaturedGames.bind(this),list:this.listFeaturedGames.bind(this)},this.Game={getRecentGames:this.getRecentGames.bind(this),getRecent:this.getRecentGames.bind(this),recent:this.getRecentGames.bind(this),get:this.getRecentGames.bind(this)},this.League={getLeagues:this.getLeagues.bind(this),leagues:this.getLeagues.bind(this),get:this.getLeagues.bind(this),getLeaguePositions:this.getLeaguePositions.bind(this),getPositions:this.getLeaguePositions.bind(this),positions:this.getLeaguePositions.bind(this),getChallengers:this.getChallengers.bind(this),challengers:this.getChallengers.bind(this),getMasters:this.getMasters.bind(this),masters:this.getMasters.bind(this)},this.Challenger={list:this.listChallengers.bind(this)},this.Master={list:this.listMasters.bind(this)},this.Static={Champion:{list:this.getStaticChampionList.bind(this),by:{id:this.getStaticChampionById.bind(this)}},Item:{list:this.getStaticItemList.bind(this),by:{id:this.getStaticItemById.bind(this)}},LanguageString:{list:this.getStaticLanguageStringList.bind(this)},Language:{list:this.getStaticLanguageList.bind(this)},Map:{list:this.getStaticMapList.bind(this)},Mastery:{list:this.getStaticMasteryList.bind(this),by:{id:this.getStaticMasteryById.bind(this)}},ProfileIcon:{list:this.getStaticProfileIconList.bind(this)},Realm:{list:this.getStaticRealmList.bind(this)},Rune:{list:this.getStaticRuneList.bind(this),by:{id:this.getStaticRuneById.bind(this)}},SummonerSpell:{list:this.getStaticSummonerSpellList.bind(this),by:{id:this.getStaticSummonerSpellById.bind(this)}},Version:{list:this.getStaticVersionList.bind(this)},getChampions:this.getChampionList.bind(this),champions:this.getChampionList.bind(this),getChampion:this.getChampion.bind(this),champion:this.getChampion.bind(this),getItems:this.getItems.bind(this),items:this.getItems.bind(this),getItem:this.getItem.bind(this),item:this.getItem.bind(this),getLanguageStrings:this.getLanguageStrings.bind(this),languageStrings:this.getLanguageStrings.bind(this),getLanguages:this.getLanguages.bind(this),languages:this.getLanguages.bind(this),getMapData:this.getMapData.bind(this),mapData:this.getMapData.bind(this),map:this.getMapData.bind(this),maps:this.getMapData.bind(this),getMasteries:this.getMasteryList.bind(this),masteries:this.getMasteryList.bind(this),getMastery:this.getMastery.bind(this),mastery:this.getMastery.bind(this),getProfileIcons:this.getProfileIcons.bind(this),profileIcons:this.getProfileIcons.bind(this),getRealmData:this.getRealmData.bind(this),realmData:this.getRealmData.bind(this),realm:this.getRealmData.bind(this),realms:this.getRealmData.bind(this),getRunes:this.getRuneList.bind(this),runes:this.getRuneList.bind(this),getRune:this.getRune.bind(this),rune:this.getRune.bind(this),getSummonerSpells:this.getSummonerSpells.bind(this),summonerSpells:this.getSummonerSpells.bind(this),spells:this.getSummonerSpells.bind(this),getSummonerSpell:this.getSummonerSpell.bind(this),summonerSpell:this.getSummonerSpell.bind(this),spell:this.getSummonerSpell.bind(this),getVersionData:this.getVersionData.bind(this),versionData:this.getVersionData.bind(this),version:this.getVersionData.bind(this),versions:this.getVersionData.bind(this)},this.Status={getShardStatus:this.getShardStatus.bind(this),getStatus:this.getShardStatus.bind(this),get:this.getShardStatus.bind(this)},this.Match={getMatch:this.getMatch.bind(this),get:this.getMatch.bind(this),getMatchTimeline:this.getMatchTimeline.bind(this),getTimeline:this.getMatchTimeline.bind(this),timeline:this.getMatchTimeline.bind(this),by:{id:this.getMatchById.bind(this)},Timeline:{by:{id:this.getMatchTimelineById.bind(this)}}},this.Matchlist={getMatchlist:this.getMatchlist.bind(this),get:this.getMatchlist.bind(this),getRecentMatchlist:this.getRecentMatchlist.bind(this),recent:this.getRecentMatchlist.bind(this),by:{account:this.getMatchlistByAccountId.bind(this),id:this.getMatchlistById.bind(this),name:this.getMatchlistByName.bind(this)}},this.MatchHistory={},this.RunesMasteries={getRunes:this.getRunes.bind(this),runes:this.getRunes.bind(this),getMasteries:this.getMasteries.bind(this),masteries:this.getMasteries.bind(this)},this.Runes={get:this.getRunes.bind(this),by:{account:this.getRunesByAccountId.bind(this),id:this.getRunesById.bind(this),name:this.getRunesByName.bind(this)}},this.Masteries={get:this.getMasteries.bind(this),by:{account:this.getMasteriesByAccountId.bind(this),id:this.getMasteriesById.bind(this),name:this.getMasteriesByName.bind(this)}},this.Stats={getRankedStats:this.getRankedStats.bind(this),ranked:this.getRankedStats.bind(this),getStatsSummary:this.getStatsSummary.bind(this),summary:this.getStatsSummary.bind(this)},this.Summoner={getSummoner:this.getSummoner.bind(this),get:this.getSummoner.bind(this),getRunes:this.getRunes.bind(this),runes:this.getRunes.bind(this),getMasteries:this.getMasteries.bind(this),masteries:this.getMasteries.bind(this),getMatchHistory:this.getRecentMatchlist.bind(this),matchHistory:this.getRecentMatchlist.bind(this),getMatchlist:this.getMatchlist.bind(this),matchlist:this.getMatchlist.bind(this),getChampionMasteries:this.getChampMasteries.bind(this),championMasteries:this.getChampMasteries.bind(this),getTotalChampionMasteryScore:this.getTotalChampMasteryScore.bind(this),totalChampionMasteryScore:this.getTotalChampMasteryScore.bind(this),by:{account:this.getSummonerByAccountId.bind(this),id:this.getSummonerById.bind(this),name:this.getSummonerByName.bind(this)}},this.Tournament={getDTOByCode:this.getDTOByCode.bind(this),DTO:{by:{code:this.getDTOByCode.bind(this)}},getLobbyListEventsByCode:this.getLobbyListEventsByCode.bind(this),LobbyListEvents:{by:{code:this.getLobbyListEventsByCode.bind(this)}}},this.Ex={getSummonerByAccId:this.getSummonerByAccId.bind(this),getMatchlistByName:this.getMatchlistByName.bind(this),getRunesBySummonerId:this.getRunesBySummonerId.bind(this),getRunesByAccountId:this.getRunesByAccountId.bind(this),staticRuneList:this.staticRuneList.bind(this)}}return c(e,[{key:"canMakeRequest",value:function(e){return this.spread?this.limits[e][0].requestAvailable()&&this.limits[e][1].requestAvailable()&&this.limits[e][2].requestAvailable():this.limits[e][0].requestAvailable()&&this.limits[e][1].requestAvailable()}},{key:"_sanitizeName",value:function(e){if(this._validName(e))return e.replace(/\s/g,"").toLowerCase();this._logError(this._validName.name,"Name "+o.yellow(e)+" is not valid. Request failed.")}},{key:"_validName",value:function(e){return T.test(e)}},{key:"_makeUrl",value:function(e,t,i,n,s,r){var o=i?"":t+"/",a=n||s||r?"":"api/lol/"+o,u="https://"+t+".api.riotgames.com/"+a+encodeURI(e),d="https://"+I[E[t]].toLowerCase()+".api.riotgames.com/lol/"+encodeURI(e);return d.lastIndexOf("v3")==-1?u:d}},{key:"_baseRequest",value:function(e,t){var i=this,n=e.endUrl,s=e.region,u=void 0===s?this.defaultRegion:s,d=e.status,g=void 0!==d&&d,l=e.observerMode,c=void 0!==l&&l,h=e.staticReq,m=void 0!==h&&h,y=e.championMastery,p=void 0!==y&&y,f=e.options,v=void 0===f?{}:f,R=e.cacheParams,I=void 0===R?{}:R,S=function(){return new Promise(function(e,s){var d="";if(n.lastIndexOf("v3")==-1){var l=!0,h=!1,y=void 0;try{for(var f,R=Object.keys(v)[Symbol.iterator]();!(l=(f=R.next()).done);l=!0){var S=f.value;Array.isArray(v[S])&&(v[S]=v[S].join(","))}}catch(e){h=!0,y=e}finally{try{!l&&R.return&&R.return()}finally{if(h)throw y}}d=a.stringify(v).replace(/%2C/,",")}else{var b=!0,_=!1,E=void 0;try{for(var M,A=Object.keys(v)[Symbol.iterator]();!(b=(M=A.next()).done);b=!0){var T=M.value;if(Array.isArray(v[T]))for(var N=0;N=500&&(g.debug&&console.log("!!! resending request !!!"),setTimeout(function(){t.bind(g)(i)},1e3)),429===u&&(g.debug&&console.log("!!! resending request !!!"),setTimeout(function(){t.bind(g)(i)},1e3*r.headers["retry-after"]+50)),u>=400?i(d+" : "+o.yellow(C)):(Number.isInteger(I.ttl)&&I.ttl>0&&g.cache.set({key:C,ttl:I.ttl},a),i(n,JSON.parse(a)));if(u>=500)g.debug&&console.log("!!! resending promise request !!!"),setTimeout(function(){return s("retry")},1e3);else{if(429!==u)return n||u>=400?s("err:",n,u):(Number.isInteger(I.ttl)&&I.ttl>0&&g.cache.set({key:C,ttl:I.ttl},a),e(JSON.parse(a)));g.debug&&console.log("!!! resending promise request !!!"),setTimeout(function(){return s("retry")},1e3*r.headers["retry-after"]+50)}}else console.log(n,q)})):setTimeout(function(){t.bind(g)(i)},1e3)}(t)}else r({url:q},function(n,r,a){if(r){var u=i,d=r.statusCode,g=L(d);return u.debug&&P(r,g,q),"function"==typeof t?d>=400?t(g+" : "+o.yellow(C)):t(n,JSON.parse(a)):n?s("err:",n):e(JSON.parse(a))}console.log(n,C)})})})};return t?S():S().catch(S).catch(S).catch(S).then(function(e){return e})}},{key:"_championMasteryRequest",value:function(e,t){var i=e.endUrl,n=e.region,s=e.options;return this._baseRequest({endUrl:p.CHAMPION_MASTERY+"/v"+M.CHAMPION+"/"+i,region:n,options:s,championMastery:!0,cacheParams:{ttl:this.CACHE_TIMERS.CHAMPION_MASTERY}},t)}},{key:"_championRequest",value:function(e,t){var i=e.endUrl,n=e.region,s=e.options;return this._baseRequest({endUrl:p.CHAMPION+"/v"+M.CHAMPION+"/"+i,region:n,options:s,cacheParams:{ttl:this.CACHE_TIMERS.CHAMPION}},t)}},{key:"_spectatorRequest",value:function(e,t){var i=e.endUrl,n=e.region;return this._baseRequest({endUrl:p.SPECTATOR+"/v"+M.SPECTATOR+"/"+i,region:n,cacheParams:{ttl:this.CACHE_TIMERS.SPECTATOR}},t)}},{key:"_staticRequest",value:function(e,t){var i=e.endUrl,n=e.region,s=e.options;return this._baseRequest({endUrl:p.STATIC_DATA+"/v"+M.STATIC_DATA+"/"+i,staticReq:!0,region:n,options:s,cacheParams:{ttl:this.CACHE_TIMERS.STATIC}},t)}},{key:"_statusRequest",value:function(e,t){var i=e.endUrl,n=e.region,s=e.options;return this._baseRequest({endUrl:p.STATUS+"/v"+M.STATUS+"/"+i,status:!0,region:n,options:s,cacheParams:{ttl:this.CACHE_TIMERS.STATUS}},t)}},{key:"_gameRequest",value:function(e,t){var i=e.endUrl,n=e.region;return this._baseRequest({endUrl:"v"+M.GAME+"/game/"+i,region:n,cacheParams:{ttl:this.CACHE_TIMERS.GAME}},t)}},{key:"_leagueRequest",value:function(e,t){var i=e.endUrl,n=e.region,s=e.options;return this._baseRequest({endUrl:p.LEAGUE+"/v"+M.LEAGUE+"/"+i,region:n,options:s,cacheParams:{ttl:this.CACHE_TIMERS.LEAGUE}},t)}},{key:"_matchRequest",value:function(e,t){var i=e.endUrl,n=e.region,s=e.options;return this._baseRequest({endUrl:p.MATCH+"/v"+M.MATCH+"/"+i,region:n,options:s,cacheParams:{ttl:this.CACHE_TIMERS.MATCH}},t)}},{key:"_matchlistRequest",value:function(e,t){var i=e.endUrl,n=e.region,s=e.options;return this._baseRequest({endUrl:"v"+M.MATCH_LIST+"/matchlist/by-summoner/"+i,region:n,options:s,cacheParams:{ttl:this.CACHE_TIMERS.MATCH_LIST}},t)}},{key:"_runesMasteriesRequest",value:function(e,t){var i=e.endUrl,n=e.region;return this._baseRequest({endUrl:p.RUNES_MASTERIES+"/v"+M.RUNES_MASTERIES+"/"+i,region:n,cacheParams:{ttl:this.CACHE_TIMERS.RUNES_MASTERIES}},t)}},{key:"_statsRequest",value:function(e,t){var i=e.endUrl,n=e.region,s=e.options;return this._baseRequest({endUrl:"v"+M.STATS+"/stats/by-summoner/"+i,region:n,options:s,cacheParams:{ttl:this.CACHE_TIMERS.STATS}},t)}},{key:"_summonerRequest",value:function(e,t){var i=e.endUrl,n=e.region;return this._baseRequest({endUrl:p.SUMMONER+"/v"+M.SUMMONER+"/summoners/"+i,region:n,cacheParams:{ttl:this.CACHE_TIMERS.SUMMONER}},t)}},{key:"_tournamentRequest",value:function(e,t){var i=(e.endUrl,e.region);return this._baseRequest({endUrl:p.TOURNAMENT+"/v"+M.TOURNAMENT,region:i,cacheParams:{ttl:this.CACHE_TIMERS.TOURNAMENT}},t)}},{key:"_logError",value:function(e,t){throw new Error(o.bold.yellow(e)+" "+o.red("request")+" "+o.bold.red("FAILED")+o.red("; "+t))}},{key:"setRegion",value:function(e){if(this.defaultRegion=C(e)?e:void 0,!this.defaultRegion)throw new Error(o.red("setRegion() by Kindred failed: "+o.yellow(e)+" is an invalid region.")+"\n"+o.red("Try importing "+o.yellow("require('./dist/kindred-api').REGIONS")+" and using one of those values instead."))}},{key:"getChamps",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=e.options,n=arguments[1];return"function"==typeof arguments[0]&&(n=arguments[0],arguments[0]=void 0),this._championRequest({endUrl:"champions",region:t,options:i},n)}},{key:"getChamp",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=e.id,n=e.championId,s=arguments[1];return Number.isInteger(i)||Number.isInteger(n)?this._championRequest({endUrl:"champions/"+(i||n),region:t},s):this._logError(this.getChamp.name,"required params "+o.yellow("`id/championId` (int)")+" not passed in")}},{key:"getChampMastery",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=e.playerId,n=e.championId,s=e.options,r=arguments[1];return Number.isInteger(i)&&Number.isInteger(n)?this._championMasteryRequest({endUrl:"champion-masteries/by-summoner/"+i+"/by-champion/"+n,region:t,options:s},r):this._logError(this.getChampMastery.name,"required params "+o.yellow("`playerId` (int) AND `championId` (int)")+" not passed in")}},{key:"getChampMasteries",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=t.region,n=t.accountId,s=t.accId,r=t.id,a=t.summonerId,u=t.playerId,d=t.name,g=arguments[1];return Number.isInteger(n||s)?new Promise(function(t,r){return e.getSummoner({accId:n||s,region:i},function(n,s){return n?void(g?g(n):r(n)):t(e._championMasteryRequest({endUrl:"champion-masteries/by-summoner/"+s.id,region:i},g))})}):Number.isInteger(r||a||u)?this._championMasteryRequest({endUrl:"champion-masteries/by-summoner/"+(r||a||u),region:i},g):"object"===l(arguments[0])&&"string"==typeof d?new Promise(function(t,n){return e.getSummoner({name:d,region:i},function(s,r){return s?void(g?g(s):n(s)):t(e._championMasteryRequest({endUrl:"champion-masteries/by-summoner/"+r.id,region:i},g))})}):this._logError(this.getChampMasteries.name,"required params "+o.yellow("`id/summonerId/playerId` (int)")+", "+o.yellow("`accountId/accId` (int)")+", or "+o.yellow("`name` (str)")+" not passed in")}},{key:"getTotalChampMasteryScore",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=t.region,n=t.accountId,s=t.accId,r=t.id,a=t.summonerId,u=t.playerId,d=t.name,g=arguments[1];return Number.isInteger(n||s)?new Promise(function(t,r){return e.getSummoner({accId:n||s,region:i},function(n,s){return n?void(g?g(n):r(n)):t(e._championMasteryRequest({endUrl:"scores/by-summoner/"+s.id,region:i},g))})}):Number.isInteger(r||a||u)?this._championMasteryRequest({endUrl:"scores/by-summoner/"+(r||a||u),region:i},g):"object"===l(arguments[0])&&"string"==typeof d?new Promise(function(t,n){return e.getSummoner({name:d,region:i},function(s,r){return s?void(g?g(s):n(s)):t(e._championMasteryRequest({endUrl:"scores/by-summoner/"+r.id,region:i},g))})}):this._logError(this.getTotalChampMasteryScore.name,"required params "+o.yellow("`id/summonerId/playerId` (int)")+", "+o.yellow("`accountId/accId` (int)")+", or "+o.yellow("`name` (str)")+" not passed in")}},{key:"getCurrentGame",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=t.region,n=t.accountId,s=t.accId,r=t.id,a=t.summonerId,u=t.playerId,d=t.name,g=arguments[1];return Number.isInteger(n||s)?new Promise(function(t,r){return e.getSummoner({accId:n||s,region:i},function(n,s){return n?void(g?g(n):r(n)):t(e._spectatorRequest({endUrl:"active-games/by-summoner/"+s.id,region:i},g))})}):Number.isInteger(r||a||u)?this._spectatorRequest({endUrl:"active-games/by-summoner/"+(r||a||u),region:i},g):"object"===l(arguments[0])&&"string"==typeof d?new Promise(function(t,n){return e.getSummoner({name:d,region:i},function(s,r){return s?void(g?g(s):n(s)):t(e._spectatorRequest({endUrl:"active-games/by-summoner/"+r.id,region:i},g))})}):this._logError(this.getCurrentGame.name,"required params "+o.yellow("`id/summonerId/playerId` (int)")+", "+o.yellow("`accountId/accId` (int)")+", or "+o.yellow("`name` (string)")+" not passed in")}},{key:"getFeaturedGames",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=arguments[1];return"function"==typeof arguments[0]&&(i=arguments[0],arguments[0]=void 0),this._spectatorRequest({endUrl:"featured-games",region:t},i)}},{key:"getRecentGames",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=t.region,n=t.accountId,s=t.accId,r=t.id,a=t.summonerId,u=t.playerId,d=t.name,g=arguments[1];return Number.isInteger(n||s)?new Promise(function(t,r){return e.getSummoner({accId:n||s,region:i},function(n,s){return n?void(g?g(n):r(n)):t(e._gameRequest({endUrl:"by-summoner/"+s.id+"/recent",region:i},g))})}):Number.isInteger(r||a||u)?this._gameRequest({endUrl:"by-summoner/"+(r||a||u)+"/recent",region:i},g):"object"===l(arguments[0])&&"string"==typeof d?new Promise(function(t,n){return e.getSummoner({name:d,region:i},function(s,r){return s?void(g?g(s):n(s)):t(e._gameRequest({endUrl:"by-summoner/"+r.id+"/recent",region:i},g))})}):this._logError(this.getRecentGames.name,"required params "+o.yellow("`id/summonerId/playerId` (int)")+", "+o.yellow("`accountId/accId` (int)")+", or "+o.yellow("`name` (string)")+" not passed in")}},{key:"getLeagues",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=t.region,n=t.accountId,s=t.accId,r=t.id,a=t.summonerId,u=t.playerId,d=t.name,g=t.options,c=arguments[1];return Number.isInteger(n||s)?new Promise(function(t,r){return e.getSummoner({accId:n||s,region:i},function(n,s){return n?void(c?c(n):r(n)):t(e._leagueRequest({endUrl:"leagues/by-summoner/"+s.id,region:i,options:g},c))})}):Number.isInteger(r||a||u)?this._leagueRequest({endUrl:"leagues/by-summoner/"+(r||a||u),region:i,options:g},c):"object"===l(arguments[0])&&"string"==typeof d?new Promise(function(t,n){return e.getSummoner({name:d,region:i},function(s,r){return s?void(c?c(s):n(s)):t(e._leagueRequest({endUrl:"leagues/by-summoner/"+r.id,region:i,options:g},c))})}):this._logError(this.getLeagues.name,"required params "+o.yellow("`id/summonerId/playerId` (int)")+", "+o.yellow("`accountId/accId` (int)")+", or "+o.yellow("`name` (string)")+" not passed in")}},{key:"getLeaguePositions",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=t.region,n=t.accountId,s=t.accId,r=t.id,a=t.summonerId,u=t.playerId,d=t.name,g=arguments[1];return Number.isInteger(n||s)?new Promise(function(t,r){return e.getSummoner({accId:n||s,region:i},function(n,s){return n?void(g?g(n):r(n)):t(e._leagueRequest({endUrl:"positions/by-summoner/"+s.id,region:i},g))})}):Number.isInteger(r||a||u)?this._leagueRequest({endUrl:"positions/by-summoner/"+(r||a||u),region:i},g):"object"===l(arguments[0])&&"string"==typeof d?new Promise(function(t,n){return e.getSummoner({name:d,region:i},function(s,r){return s?void(g?g(s):n(s)):t(e._leagueRequest({endUrl:"positions/by-summoner/"+r.id,region:i},g))})}):void this._logError(this.getLeaguePositions.name,"required params "+o.yellow("`id/summonerId/playerId` (int)")+", "+o.yellow("`accountId/accId` (int)")+", or "+o.yellow("`name` (string)")+" not passed in")}},{key:"getChallengers",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=e.queue,n=void 0===i?"RANKED_SOLO_5x5":i,s=arguments[1];if(s="function"==typeof arguments[0]?arguments[0]:arguments[1],"string"==typeof n)return this._leagueRequest({endUrl:"challengerleagues/by-queue/"+n,region:t},s);this._logError(this.getChallengers.name,"required params "+o.yellow("`queue` (string)")+" not passed in")}},{key:"getMasters",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=e.queue,n=void 0===i?"RANKED_SOLO_5x5":i,s=arguments[1];if(s="function"==typeof arguments[0]?arguments[0]:arguments[1],"string"==typeof n)return this._leagueRequest({endUrl:"masterleagues/by-queue/"+n,region:t},s);this._logError(this.getMasters.name,"required params "+o.yellow("`queue` (string)")+" not passed in")}},{key:"getChampionList",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=e.options,n=arguments[1];return"function"==typeof arguments[0]&&(n=arguments[0],arguments[0]=void 0),this._staticRequest({endUrl:"champions",region:t,options:i},n)}},{key:"getChampion",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=e.id,n=e.championId,s=e.options,r=arguments[1];return Number.isInteger(i||n)?this._staticRequest({endUrl:"champions/"+(i||n),region:t,options:s},r):this._logError(this.getChampion.name,"required params "+o.yellow("`id/championId` (int)")+" not passed in")}},{key:"getItems",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=e.options,n=arguments[1];return"function"==typeof arguments[0]&&(n=arguments[0],arguments[0]=void 0),this._staticRequest({endUrl:"items",region:t,options:i},n)}},{key:"getItem",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=e.id,n=e.itemId,s=e.options,r=arguments[1];return Number.isInteger(i||n)?this._staticRequest({endUrl:"items/"+(i||n),region:t,options:s},r):this._logError(this.getItem.name,"required params "+o.yellow("`id/itemId` (int)")+" not passed in")}},{key:"getLanguageStrings",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=e.options,n=arguments[1];return"function"==typeof arguments[0]&&(n=arguments[0],arguments[0]=void 0),this._staticRequest({endUrl:"language-strings",region:t,options:i},n)}},{key:"getLanguages",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=arguments[1];return"function"==typeof arguments[0]&&(i=arguments[0],arguments[0]=void 0),this._staticRequest({endUrl:"languages",region:t},i)}},{key:"getMapData",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=e.options,n=arguments[1];return"function"==typeof arguments[0]&&(n=arguments[0],arguments[0]=void 0),this._staticRequest({endUrl:"maps",region:t,options:i},n)}},{ -key:"getMasteryList",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=e.options,n=arguments[1];return"function"==typeof arguments[0]&&(n=arguments[0],arguments[0]=void 0),this._staticRequest({endUrl:"masteries",region:t,options:i},n)}},{key:"getMastery",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=e.id,n=e.masteryId,s=e.options,r=arguments[1];return Number.isInteger(i||n)?this._staticRequest({endUrl:"masteries/"+(i||n),region:t,options:s},r):this._logError(this.getMastery.name,"required params "+o.yellow("`id/masteryId` (int)")+" not passed in")}},{key:"getProfileIcons",value:function(e,t){var i=e.region,n=e.options;return"function"==typeof arguments[0]&&(t=arguments[0],arguments[0]=void 0),this._staticRequest({endUrl:"profile-icons",region:i,options:n},t)}},{key:"getRealmData",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=arguments[1];return"function"==typeof arguments[0]&&(i=arguments[0],arguments[0]=void 0),this._staticRequest({endUrl:"realms",region:t},i)}},{key:"getRuneList",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=e.options,n=arguments[1];return"function"==typeof arguments[0]&&(n=arguments[0],arguments[0]=void 0),this._staticRequest({endUrl:"runes",region:t,options:i},n)}},{key:"getRune",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=e.id,n=e.runeId,s=e.options,r=arguments[1];return Number.isInteger(i||n)?this._staticRequest({endUrl:"runes/"+(i||n),region:t,options:s},r):this._logError(this.getRune.name,"required params "+o.yellow("`id/runeId` (int)")+" not passed in")}},{key:"getSummonerSpells",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=e.options,n=arguments[1];return"function"==typeof arguments[0]&&(n=arguments[0],arguments[0]=void 0),this._staticRequest({endUrl:"summoner-spells",region:t,options:i},n)}},{key:"getSummonerSpell",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=e.id,n=e.spellId,s=e.summonerSpellId,r=e.options,a=arguments[1];return Number.isInteger(i||n||s)?this._staticRequest({endUrl:"summoner-spells/"+(i||n||s),region:t,options:r},a):this._logError(this.getSummonerSpell.name,"required params "+o.yellow("`id/spellId/summonerSpellId` (int)")+" not passed in")}},{key:"getVersionData",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=e.options,n=arguments[1];return"function"==typeof arguments[0]&&(n=arguments[0],arguments[0]=void 0),this._staticRequest({endUrl:"versions",region:t,options:i},n)}},{key:"getShardStatus",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=arguments[1];return"function"==typeof arguments[0]&&(i=arguments[0],arguments[0]=void 0),"string"==typeof arguments[0]?C(arguments[0])?this._statusRequest({endUrl:"shard-data",region:arguments[0]},i):this._logError(this.getShardStatus.name,"invalid region!"):this._statusRequest({endUrl:"shard-data",region:t},i)}},{key:"getMatch",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=e.id,n=e.matchId,s=e.options,r=arguments[1];return Number.isInteger(i||n)?this._matchRequest({endUrl:"matches/"+(i||n),region:t,options:s},r):this._logError(this.getMatch.name,"required params "+o.yellow("`id/matchId` (int)")+" not passed in")}},{key:"getMatchlist",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=t.region,n=t.accountId,s=t.accId,r=t.id,a=t.summonerId,u=t.playerId,d=t.name,g=t.options,c=void 0===g?{queue:S.TEAM_BUILDER_RANKED_SOLO}:g,h=arguments[1];return Number.isInteger(n||s)?this._matchRequest({endUrl:"matchlists/by-account/"+(n||s),region:i,options:c},h):Number.isInteger(r||a||u)?new Promise(function(t,n){return e.getSummoner({id:r,region:i},function(s,r){return s?void(h?h(s):n(s)):t(e._matchRequest({endUrl:"matchlists/by-account/"+r.accountId,region:i,options:c},h))})}):"object"===l(arguments[0])&&"string"==typeof d?new Promise(function(t,n){return e.getSummoner({name:d,region:i},function(s,r){return s?void(h?h(s):n(s)):t(e._matchRequest({endUrl:"matchlists/by-account/"+r.accountId,region:i,options:c},h))})}):this._logError(this.getMatchlist.name,"required params "+o.yellow("`accountId/accId` (int)")+", "+o.yellow("`id/summonerId/playerId` (int)")+", or "+o.yellow("`name` (str)")+" not passed in")}},{key:"getRecentMatchlist",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=t.region,n=t.accountId,s=t.accId,r=t.id,a=t.summonerId,u=t.playerId,d=t.name,g=arguments[1];return Number.isInteger(n||s)?this._matchRequest({endUrl:"matchlists/by-account/"+(n||s)+"/recent",region:i},g):Number.isInteger(r||a||u)?new Promise(function(t,n){return e.getSummoner({id:r,region:i},function(s,r){return s?void(g?g(s):n(s)):t(e._matchRequest({endUrl:"matchlists/by-account/"+r.accountId+"/recent",region:i},g))})}):"object"===l(arguments[0])&&"string"==typeof d?new Promise(function(t,n){return e.getSummoner({name:d,region:i},function(s,r){return s?void(g?g(s):n(s)):t(e._matchRequest({endUrl:"matchlists/by-account/"+r.accountId+"/recent",region:i},g))})}):this._logError(this.getRecentMatchlist.name,"required params "+o.yellow("`accountId/accId` (int)")+", "+o.yellow("`id/summonerId/playerId` (int)")+", or "+o.yellow("`name` (str)")+" not passed in")}},{key:"getMatchTimeline",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=e.id,n=e.matchId,s=arguments[1];return Number.isInteger(i||n)?this._matchRequest({endUrl:"timelines/by-match/"+(i||n),region:t},s):this._logError(this.getMatchTimeline.name,"required params "+o.yellow("`id/matchId` (int)")+" not passed in")}},{key:"getRunes",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=t.region,n=t.accountId,s=t.accId,r=t.id,a=t.summonerId,u=t.playerId,d=t.name,g=arguments[1];return Number.isInteger(n||s)?new Promise(function(t,r){return e.getSummoner({accId:n||s,region:i},function(n,s){return n?void(g?g(n):r(n)):t(e._runesMasteriesRequest({endUrl:"runes/by-summoner/"+s.id,region:i},g))})}):Number.isInteger(r||a||u)?this._runesMasteriesRequest({endUrl:"runes/by-summoner/"+(r||a||u),region:i},g):"object"===l(arguments[0])&&"string"==typeof d?new Promise(function(t,n){return e.getSummoner({name:d,region:i},function(s,r){return s?void(g?g(s):n(s)):t(e._runesMasteriesRequest({endUrl:"runes/by-summoner/"+r.id,region:i},g))})}):this._logError(this.getRunes.name,"required params "+o.yellow("`id/summonerId/playerId` (int)")+", "+o.yellow("`accountId/accId` (int)")+", or "+o.yellow("`name` (str)")+" not passed in")}},{key:"getMasteries",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=t.region,n=t.accountId,s=t.accId,r=t.id,a=t.summonerId,u=t.playerId,d=t.name,g=arguments[1];return Number.isInteger(n||s)?new Promise(function(t,r){return e.getSummoner({accId:n||s,region:i},function(n,s){return n?void(g?g(n):r(n)):t(e._runesMasteriesRequest({endUrl:"masteries/by-summoner/"+s.id,region:i},g))})}):Number.isInteger(r||a||u)?this._runesMasteriesRequest({endUrl:"masteries/by-summoner/"+(r||a||u),region:i},g):"object"===l(arguments[0])&&"string"==typeof d?new Promise(function(t,n){return e.getSummoner({name:d,region:i},function(s,r){return s?void(g?g(s):n(s)):t(e._runesMasteriesRequest({endUrl:"masteries/by-summoner/"+r.id,region:i},g))})}):this._logError(this.getMasteries.name,"required params "+o.yellow("`id/summonerId/playerId` (int)")+", "+o.yellow("`accountId/accId` (int)")+", or "+o.yellow("`name` (str)")+" not passed in")}},{key:"getRankedStats",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=t.region,n=t.accountId,s=t.accId,r=t.id,a=t.summonerId,u=t.playerId,d=t.name,g=t.options,c=arguments[1];return Number.isInteger(n||s)?new Promise(function(t,r){return e.getSummoner({accId:n||s,region:i},function(n,s){return n?void(c?c(n):r(n)):t(e._statsRequest({endUrl:s.id+"/ranked",region:i,options:g},c))})}):Number.isInteger(r||a||u)?this._statsRequest({endUrl:(r||a||u)+"/ranked",region:i,options:g},c):"object"===l(arguments[0])&&"string"==typeof d?new Promise(function(t,n){return e.getSummoner({name:d,region:i},function(s,r){return s?void(c?c(s):n(s)):t(e._statsRequest({endUrl:r.id+"/ranked",region:i,options:g},c))})}):void this._logError(this.getRankedStats.name,"required params "+o.yellow("`id/summonerId/playerId` (int)")+", "+o.yellow("`accountId/accId` (int)")+", or "+o.yellow("`name` (string)")+" not passed in")}},{key:"getStatsSummary",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=t.region,n=t.accountId,s=t.accId,r=t.id,a=t.summonerId,u=t.playerId,d=t.name,g=t.options,c=arguments[1];return Number.isInteger(n||s)?new Promise(function(t,r){return e.getSummoner({accId:n||s,region:i},function(n,s){return n?void(c?c(n):r(n)):t(e._statsRequest({endUrl:s.id+"/summary",region:i,options:g},c))})}):Number.isInteger(r||a||u)?this._statsRequest({endUrl:(r||a||u)+"/summary",region:i,options:g},c):"object"===l(arguments[0])&&"string"==typeof d?new Promise(function(t,n){return e.getSummoner({name:d,region:i},function(s,r){return s?void(c?c(s):n(s)):t(e._statsRequest({endUrl:r.id+"/summary",region:i,options:g},c))})}):void this._logError(this.getStatsSummary.name,"required params "+o.yellow("`id/summonerId/playerId` (int)")+", "+o.yellow("`accountId/accId` (int)")+", or "+o.yellow("`name` (string)")+" not passed in")}},{key:"getSummoner",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=e.id,n=e.summonerId,s=e.playerId,r=e.accountId,a=e.accId,u=e.name,d=arguments[1];return Number.isInteger(i||n||s)?this._summonerRequest({endUrl:""+(i||n||s),region:t},d):"object"===l(arguments[0])&&"string"==typeof u?this._summonerRequest({endUrl:"by-name/"+this._sanitizeName(u),region:t},d):Number.isInteger(r||a)?this._summonerRequest({endUrl:"by-account/"+(r||a),region:t},d):this._logError(this.getSummoner.name,"required params "+o.yellow("`id/summonerId/playerId` (int)")+", "+o.yellow("`accountId/accId` (int)")+", or "+o.yellow("`name` (string)")+" not passed in")}},{key:"getDTOByCode",value:function(e,t){return"string"==typeof e?this._tournamentRequest({endUrl:"lobby-events/codes/"+e},t):this._logError(this.getDTOByCode.name,"required params "+o.yellow("`code` (string)")+" not passed in")}},{key:"getLobbyListEventsByCode",value:function(e,t){return"string"==typeof e?this._tournamentRequest({endUrl:"lobby-events/by-code/"+e},t):this._logError(this.getLobbyListEventsByCode.name,"required params "+o.yellow("`code` (string)")+" not passed in")}},{key:"listChampions",value:function(e,t,i){return"function"==typeof e&&(i=e,e=void 0),"function"==typeof t&&(i=t,t=void 0),"string"==typeof e&&(t=e,e=void 0),this.Champion.all({options:e,region:t},i)}},{key:"getChampionById",value:function(e,t,i){return"function"==typeof t&&(i=t,t=void 0),this.Champion.get({id:e,region:t},i)}},{key:"listFeaturedGames",value:function(e,t){return"function"==typeof e&&(t=e,e=void 0),this.FeaturedGames.get({region:e},t)}},{key:"listChallengers",value:function(e,t,i){return C(e)&&("function"==typeof t&&(i=t,t=void 0),t=e,e=void 0),"function"==typeof e&&(i=e,e=void 0),"function"==typeof t&&(i=t,t=void 0),this.League.challengers({queue:e,region:t},i)}},{key:"listMasters",value:function(e,t,i){return C(e)&&("function"==typeof t&&(i=t,t=void 0),t=e,e=void 0),"function"==typeof e&&(i=e,e=void 0),"function"==typeof t&&(i=t,t=void 0),this.League.masters({queue:e,region:t},i)}},{key:"getSummonerByAccountId",value:function(e,t,i){return"function"==typeof t&&(i=t,t=void 0),this.Summoner.get({region:t,accId:e},i)}},{key:"getSummonerById",value:function(e,t,i){return"function"==typeof t&&(i=t,t=void 0),this.Summoner.get({region:t,id:e},i)}},{key:"getSummonerByName",value:function(e,t,i){return"function"==typeof t&&(i=t,t=void 0),this.Summoner.get({region:t,name:e},i)}},{key:"getMasteriesByAccountId",value:function(e,t,i){return"function"==typeof t&&(i=t,t=void 0),this.Masteries.get({region:t,accId:e},i)}},{key:"getMasteriesById",value:function(e,t,i){return"function"==typeof t&&(i=t,t=void 0),this.Masteries.get({region:t,id:e},i)}},{key:"getMasteriesByName",value:function(e,t,i){return"function"==typeof t&&(i=t,t=void 0),this.Masteries.get({region:t,name:e},i)}},{key:"getMatchById",value:function(e,t,i){return"function"==typeof t&&(i=t,t=void 0),this.Match.get({region:t,id:e},i)}},{key:"getMatchlistByAccountId",value:function(e,t,i,n){return"function"==typeof t&&(n=t,t=void 0),"function"==typeof i&&(n=i,i=void 0),"string"==typeof t&&(i=t,t=void 0),this.Matchlist.get({region:i,accId:e},n)}},{key:"getMatchlistById",value:function(e,t,i,n){return"function"==typeof t&&(n=t,t=void 0),"function"==typeof i&&(n=i,i=void 0),"string"==typeof t&&(i=t,t=void 0),this.Matchlist.get({region:i,id:e},n)}},{key:"getMatchlistByName",value:function(e,t,i,n){return"function"==typeof t&&(n=t,t=void 0),"function"==typeof i&&(n=i,i=void 0),"string"==typeof t&&(i=t,t=void 0),this.Matchlist.get({name:e,options:t,region:i},n)}},{key:"getMatchTimelineById",value:function(e,t,i){return"function"==typeof t&&(i=t,t=void 0),this.Match.timeline({id:e,region:t},i)}},{key:"getRunesByAccountId",value:function(e,t,i){return"function"==typeof t&&(i=t,t=void 0),this.Runes.get({region:t,accId:e},i)}},{key:"getRunesById",value:function(e,t,i){return"function"==typeof t&&(i=t,t=void 0),this.Runes.get({region:t,id:e},i)}},{key:"getRunesByName",value:function(e,t,i){return"function"==typeof t&&(i=t,t=void 0),this.Runes.get({region:t,name:e},i)}},{key:"getStaticChampionList",value:function(e,t,i){return"function"==typeof e&&(i=e,e=void 0),"function"==typeof t&&(i=t,t=void 0),"string"==typeof e&&(t=e,e=void 0),this.Static.champions({region:t,options:e},i)}},{key:"getStaticChampionById",value:function(e,t,i,n){return"function"==typeof t&&(n=t,t=void 0),"function"==typeof i&&(n=i,i=void 0),"string"==typeof t&&(i=t,t=void 0),this.Static.champion({id:e,options:t,region:i},n)}},{key:"getStaticItemList",value:function(e,t,i){return"function"==typeof e&&(i=e,e=void 0),"function"==typeof t&&(i=t,t=void 0),"string"==typeof e&&(t=e,e=void 0),this.Static.items({options:e,region:t},i)}},{key:"getStaticItemById",value:function(e,t,i,n){return"function"==typeof t&&(n=t,t=void 0),"function"==typeof i&&(n=i,i=void 0),"string"==typeof t&&(i=t,t=void 0),this.Static.item({id:e,options:t,region:i},n)}},{key:"getStaticLanguageStringList",value:function(e,t,i){return"function"==typeof e&&(i=e,e=void 0),"function"==typeof t&&(i=t,t=void 0),"string"==typeof e&&(t=e,e=void 0),this.Static.languageStrings({options:e,region:t},i)}},{key:"getStaticLanguageList",value:function(e,t){return"function"==typeof e&&(t=e,e=void 0),this.Static.languages({region:e},t)}},{key:"getStaticMapList",value:function(e,t,i){return"function"==typeof e&&(i=e,e=void 0),"function"==typeof t&&(i=t,t=void 0),"string"==typeof e&&(t=e,e=void 0),this.Static.mapData({options:e,region:t},i)}},{key:"getStaticMasteryList",value:function(e,t,i){return"function"==typeof e&&(i=e,e=void 0),"function"==typeof t&&(i=t,t=void 0),"string"==typeof e&&(t=e,e=void 0),this.Static.masteries({options:e,region:t},i)}},{key:"getStaticMasteryById",value:function(e,t,i,n){return"function"==typeof t&&(n=t,t=void 0),"function"==typeof i&&(n=i,i=void 0),"string"==typeof t&&(i=t,t=void 0),this.Static.mastery({id:e,options:t,region:i},n)}},{key:"getStaticProfileIconList",value:function(e,t,i){return"function"==typeof e&&(i=e,e=void 0),"function"==typeof t&&(i=t,t=void 0),"string"==typeof e&&(t=e,e=void 0),this.Static.profileIcons({options:e,region:t},i)}},{key:"getStaticRealmList",value:function(e,t){return"function"==typeof e&&(t=e,e=void 0),this.Static.realm({region:e},t)}},{key:"getStaticRuneList",value:function(e,t,i){return"function"==typeof e&&(i=e,e=void 0),"function"==typeof t&&(i=t,t=void 0),"string"==typeof e&&(t=e,e=void 0),this.Static.runes({options:e,region:t},i)}},{key:"getStaticRuneById",value:function(e,t,i,n){return"function"==typeof t&&(n=t,t=void 0),"function"==typeof i&&(n=i,i=void 0),"string"==typeof t&&(i=t,t=void 0),this.Static.rune({id:e,options:t,region:i},n)}},{key:"getStaticSummonerSpellList",value:function(e,t,i){return"function"==typeof e&&(i=e,e=void 0),"function"==typeof t&&(i=t,t=void 0),"string"==typeof e&&(t=e,e=void 0),this.Static.spells({options:e,region:t},i)}},{key:"getStaticSummonerSpellById",value:function(e,t,i,n){return"function"==typeof t&&(n=t,t=void 0),"function"==typeof i&&(n=i,i=void 0),"string"==typeof t&&(i=t,t=void 0),this.Static.spell({id:e,options:t,region:i},n)}},{key:"getStaticVersionList",value:function(e,t){return"function"==typeof e&&(t=e,e=void 0),this.Static.versions({region:e},t)}},{key:"getSummonerByAccId",value:function(e,t,i){return this.Summoner.get({region:t,accId:e},i)}},{key:"getRunesBySummonerId",value:function(e,t,i){return this.Runes.get({region:t,id:e},i)}},{key:"staticRuneList",value:function(e,t,i){return this.Static.runes({region:e,options:t},i)}}]),e}(),B={Kindred:D,REGIONS:_,LIMITS:R,TIME_CONSTANTS:f,CACHE_TYPES:A,QUEUE_TYPES:S,QUEUE_STRINGS:b,QuickStart:d,print:g};e.exports=B}); \ No newline at end of file +!function(e,t){if("function"==typeof define&&define.amd)define("kindred-api",["module","redis","double-ended-queue","xregexp","chalk","request","chalk","query-string"],t);else if("undefined"!=typeof exports)t(module,require("redis"),require("double-ended-queue"),require("xregexp"),require("chalk"),require("request"),require("chalk"),require("query-string"));else{var i={exports:{}};t(i,e.redis,e.doubleEndedQueue,e.xregexp,e.chalk,e.request,e.chalk,e.queryString),e.kindredApi=i.exports}}(this,function(e,t,i,n,s,r,o,a){"use strict";function u(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function d(e,t,i){return"boolean"==typeof t&&(i=t,t=void 0),new D({key:e,defaultRegion:t,debug:i,limits:R.DEV,cacheOptions:A[0]})}function l(e,t){e?console.log(e):console.log(t)}var g="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},c=function(){function e(e,t){for(var i=0;ithis.cache[e.key].expires?(delete this.cache[e.key],t("expired cache key")):t(null,this.cache[e.key].value):t("cache key doesn't exist")}},{key:"set",value:function(e,t){this.cache[e.key]={expires:e.ttl?this.setExp(Date.now(),e.ttl):null,value:t}}},{key:"setExp",value:function(e,t){return e+1e3*t}}]),e}(),m=function(){function e(i){u(this,e);var n=Object.assign({},i||{},{host:"127.0.0.1",port:6379,keyPrefix:"kindredAPI-"});this.client=t.createClient(n.port,n.host),this.client.on("error",function(e){console.log("Redis error:",e)}),process.on("exit",function(){console.log("closing"),this.client.quit()}),this.prefix=n.keyPrefix}return c(e,[{key:"get",value:function(e,t){this.client.get(this.prefix+e.key,function(e,i){i?t(e,i):t(e)})}},{key:"set",value:function(e,t){this.client.setex(this.prefix+e.key,e.ttl,t)}}]),e}(),y=function(){function e(t,n){u(this,e),this.allowedRequests=t,this.seconds=n,this.madeRequests=new i}return c(e,[{key:"__reload",value:function(){for(var e=(new Date).getTime();this.madeRequests.length>0&&e-this.madeRequests.peekFront()>=50*this.seconds;)this.madeRequests.shift()}},{key:"addRequest",value:function(){this.madeRequests.push((new Date).getTime()+1e3*this.seconds)}},{key:"requestAvailable",value:function(){return this.__reload(),this.madeRequests.length0},string:function(e){return e&&Array.isArray(e)&&N.string(e)&&e.length>0}},C=function(e){var t=!0,i=!1,n=void 0;try{for(var s,r=Object.keys(_)[Symbol.iterator]();!(t=(s=r.next()).done);t=!0){var o=s.value;if(_[o]===e)return!0}}catch(e){i=!0,n=e}finally{try{!t&&r.return&&r.return()}finally{if(i)throw n}}return!1},q={400:"Bad Request",403:"Forbidden",404:"Not Found",415:"Unsupported Media Type",429:"Rate Limit Exceeded",500:"Internal Service Error",503:"Service Unavailable"},O=function(e){var t=q[e];if(t)return t},k=[200,400,500],L=function(e){return e>=k[0]&&e=k[1]&&e0&&void 0!==arguments[0]?arguments[0]:{},i=t.key,n=t.defaultRegion,s=void 0===n?_.NORTH_AMERICA:n,r=t.debug,a=void 0!==r&&r,d=t.limits,l=t.spread,c=t.cacheOptions,p=t.cacheTTL;if(u(this,e),0===arguments.length||"object"!==g(arguments[0])||"string"!=typeof i)throw new Error(""+o.red("API key not passed in!"));if(this.key=i,this.defaultRegion=C(s)?s:void 0,!this.defaultRegion)throw new Error(o.red("setRegion() by Kindred failed: "+o.yellow(s)+" is an invalid region.")+"\n"+o.red("Try importing "+o.yellow("require('./dist/kindred-api').REGIONS")+" and using one of those values instead."));if(this.debug=a,c?(c===A[0]?this.cache=new h:c===A[1]?this.cache=new m:this.cache=new c,this.CACHE_TIMERS=p?p:v):this.cache={get:function(e,t){return t(null,null)},set:function(e,t){}},this.CACHE_TIMERS||(this.CACHE_TIMERS={CHAMPION:0,CHAMPION_MASTERY:0,CURRENT_GAME:0,FEATURED_GAMES:0,GAME:0,LEAGUE:0,STATIC:0,STATUS:0,MATCH:0,MATCH_LIST:0,RUNES_MASTERIES:0,STATS:0,SUMMONER:0}),d){if(w(d))throw console.log(o.red("Initialization of Kindred failed: Invalid "+o.yellow("limits")+". Valid examples: "+o.yellow("[[10, 10], [500, 600]]"))+"."),console.log(o.red("You can also pass in one of these two strings:")+" dev/prod "),console.log(""+o.red("and Kindred will set the limits appropriately.")),new Error;this.limits={},"dev"===d&&(d=R.DEV),"prod"===d&&(d=R.PROD),this.spread=l;var f=!0,I=!1,S=void 0;try{for(var b,E=Object.keys(_)[Symbol.iterator]();!(f=(b=E.next()).done);f=!0){var M=b.value;this.limits[_[M]]=[new y(d[0][0],d[0][1]),new y(d[1][0],d[1][1]),this.spread?new y(d[0][0]/10,.5):null]}}catch(e){I=!0,S=e}finally{try{!f&&E.return&&E.return()}finally{if(I)throw S}}}this.Champion={getChampions:this.getChamps.bind(this),getAll:this.getChamps.bind(this),all:this.getChamps.bind(this),getChampion:this.getChamp.bind(this),get:this.getChamp.bind(this),list:this.listChampions.bind(this),by:{id:this.getChampionById.bind(this)}},this.ChampionMastery={getChampionMastery:this.getChampMastery.bind(this),get:this.getChampMastery.bind(this),getChampionMasteries:this.getChampMasteries.bind(this),getAll:this.getChampMasteries.bind(this),all:this.getChampMasteries.bind(this),getTotalChampionMasteryScore:this.getTotalChampMasteryScore.bind(this),getTotalScore:this.getTotalChampMasteryScore.bind(this),totalScore:this.getTotalChampMasteryScore.bind(this),total:this.getTotalChampMasteryScore.bind(this),score:this.getTotalChampMasteryScore.bind(this)},this.CurrentGame={getCurrentGame:this.getCurrentGame.bind(this),get:this.getCurrentGame.bind(this)},this.FeaturedGames={getFeaturedGames:this.getFeaturedGames.bind(this),get:this.getFeaturedGames.bind(this),list:this.listFeaturedGames.bind(this)},this.Game={getRecentGames:this.getRecentGames.bind(this),getRecent:this.getRecentGames.bind(this),recent:this.getRecentGames.bind(this),get:this.getRecentGames.bind(this)},this.League={getLeagues:this.getLeagues.bind(this),leagues:this.getLeagues.bind(this),get:this.getLeagues.bind(this),getLeaguePositions:this.getLeaguePositions.bind(this),getPositions:this.getLeaguePositions.bind(this),positions:this.getLeaguePositions.bind(this),getChallengers:this.getChallengers.bind(this),challengers:this.getChallengers.bind(this),getMasters:this.getMasters.bind(this),masters:this.getMasters.bind(this)},this.Challenger={list:this.listChallengers.bind(this)},this.Master={list:this.listMasters.bind(this)},this.Static={Champion:{list:this.getStaticChampionList.bind(this),by:{id:this.getStaticChampionById.bind(this)}},Item:{list:this.getStaticItemList.bind(this),by:{id:this.getStaticItemById.bind(this)}},LanguageString:{list:this.getStaticLanguageStringList.bind(this)},Language:{list:this.getStaticLanguageList.bind(this)},Map:{list:this.getStaticMapList.bind(this)},Mastery:{list:this.getStaticMasteryList.bind(this),by:{id:this.getStaticMasteryById.bind(this)}},ProfileIcon:{list:this.getStaticProfileIconList.bind(this)},Realm:{list:this.getStaticRealmList.bind(this)},Rune:{list:this.getStaticRuneList.bind(this),by:{id:this.getStaticRuneById.bind(this)}},SummonerSpell:{list:this.getStaticSummonerSpellList.bind(this),by:{id:this.getStaticSummonerSpellById.bind(this)}},Version:{list:this.getStaticVersionList.bind(this)},getChampions:this.getChampionList.bind(this),champions:this.getChampionList.bind(this),getChampion:this.getChampion.bind(this),champion:this.getChampion.bind(this),getItems:this.getItems.bind(this),items:this.getItems.bind(this),getItem:this.getItem.bind(this),item:this.getItem.bind(this),getLanguageStrings:this.getLanguageStrings.bind(this),languageStrings:this.getLanguageStrings.bind(this),getLanguages:this.getLanguages.bind(this),languages:this.getLanguages.bind(this),getMapData:this.getMapData.bind(this),mapData:this.getMapData.bind(this),map:this.getMapData.bind(this),maps:this.getMapData.bind(this),getMasteries:this.getMasteryList.bind(this),masteries:this.getMasteryList.bind(this),getMastery:this.getMastery.bind(this),mastery:this.getMastery.bind(this),getProfileIcons:this.getProfileIcons.bind(this),profileIcons:this.getProfileIcons.bind(this),getRealmData:this.getRealmData.bind(this),realmData:this.getRealmData.bind(this),realm:this.getRealmData.bind(this),realms:this.getRealmData.bind(this),getRunes:this.getRuneList.bind(this),runes:this.getRuneList.bind(this),getRune:this.getRune.bind(this),rune:this.getRune.bind(this),getSummonerSpells:this.getSummonerSpells.bind(this),summonerSpells:this.getSummonerSpells.bind(this),spells:this.getSummonerSpells.bind(this),getSummonerSpell:this.getSummonerSpell.bind(this),summonerSpell:this.getSummonerSpell.bind(this),spell:this.getSummonerSpell.bind(this),getVersionData:this.getVersionData.bind(this),versionData:this.getVersionData.bind(this),version:this.getVersionData.bind(this),versions:this.getVersionData.bind(this)},this.Status={getShardStatus:this.getShardStatus.bind(this),getStatus:this.getShardStatus.bind(this),get:this.getShardStatus.bind(this)},this.Match={getMatch:this.getMatch.bind(this),get:this.getMatch.bind(this),getMatchTimeline:this.getMatchTimeline.bind(this),getTimeline:this.getMatchTimeline.bind(this),timeline:this.getMatchTimeline.bind(this),by:{id:this.getMatchById.bind(this)},Timeline:{by:{id:this.getMatchTimelineById.bind(this)}}},this.Matchlist={getMatchlist:this.getMatchlist.bind(this),get:this.getMatchlist.bind(this),getRecentMatchlist:this.getRecentMatchlist.bind(this),recent:this.getRecentMatchlist.bind(this),by:{account:this.getMatchlistByAccountId.bind(this),id:this.getMatchlistById.bind(this),name:this.getMatchlistByName.bind(this)}},this.MatchHistory={},this.RunesMasteries={getRunes:this.getRunes.bind(this),runes:this.getRunes.bind(this),getMasteries:this.getMasteries.bind(this),masteries:this.getMasteries.bind(this)},this.Runes={get:this.getRunes.bind(this),by:{account:this.getRunesByAccountId.bind(this),id:this.getRunesById.bind(this),name:this.getRunesByName.bind(this)}},this.Masteries={get:this.getMasteries.bind(this),by:{account:this.getMasteriesByAccountId.bind(this),id:this.getMasteriesById.bind(this),name:this.getMasteriesByName.bind(this)}},this.Stats={getRankedStats:this.getRankedStats.bind(this),ranked:this.getRankedStats.bind(this),getStatsSummary:this.getStatsSummary.bind(this),summary:this.getStatsSummary.bind(this)},this.Summoner={getSummoner:this.getSummoner.bind(this),get:this.getSummoner.bind(this),getRunes:this.getRunes.bind(this),runes:this.getRunes.bind(this),getMasteries:this.getMasteries.bind(this),masteries:this.getMasteries.bind(this),getMatchHistory:this.getRecentMatchlist.bind(this),matchHistory:this.getRecentMatchlist.bind(this),getMatchlist:this.getMatchlist.bind(this),matchlist:this.getMatchlist.bind(this),getChampionMasteries:this.getChampMasteries.bind(this),championMasteries:this.getChampMasteries.bind(this),getTotalChampionMasteryScore:this.getTotalChampMasteryScore.bind(this),totalChampionMasteryScore:this.getTotalChampMasteryScore.bind(this),by:{account:this.getSummonerByAccountId.bind(this),id:this.getSummonerById.bind(this),name:this.getSummonerByName.bind(this)}},this.Tournament={getDTOByCode:this.getDTOByCode.bind(this),DTO:{by:{code:this.getDTOByCode.bind(this)}},getLobbyListEventsByCode:this.getLobbyListEventsByCode.bind(this),LobbyListEvents:{by:{code:this.getLobbyListEventsByCode.bind(this)}}},this.Ex={getSummonerByAccId:this.getSummonerByAccId.bind(this),getMatchlistByName:this.getMatchlistByName.bind(this),getRunesBySummonerId:this.getRunesBySummonerId.bind(this),getRunesByAccountId:this.getRunesByAccountId.bind(this),staticRuneList:this.staticRuneList.bind(this)}}return c(e,[{key:"canMakeRequest",value:function(e){return this.spread?this.limits[e][0].requestAvailable()&&this.limits[e][1].requestAvailable()&&this.limits[e][2].requestAvailable():this.limits[e][0].requestAvailable()&&this.limits[e][1].requestAvailable()}},{key:"_sanitizeName",value:function(e){if(this._validName(e))return e.replace(/\s/g,"").toLowerCase();this._logError(this._validName.name,"Name "+o.yellow(e)+" is not valid. Request failed.")}},{key:"_validName",value:function(e){return T.test(e)}},{key:"_makeUrl",value:function(e,t,i,n,s,r){var o=i?"":t+"/",a=n||s||r?"":"api/lol/"+o,u="https://"+t+".api.riotgames.com/"+a+encodeURI(e),d="https://"+I[E[t]].toLowerCase()+".api.riotgames.com/lol/"+encodeURI(e);return d.lastIndexOf("v3")==-1?u:d}},{key:"_baseRequest",value:function(e,t){var i=this,n=e.endUrl,s=e.region,u=void 0===s?this.defaultRegion:s,d=e.status,l=void 0!==d&&d,g=e.observerMode,c=void 0!==g&&g,h=e.staticReq,m=void 0!==h&&h,y=e.championMastery,p=void 0!==y&&y,f=e.options,v=void 0===f?{}:f,R=e.cacheParams,I=void 0===R?{}:R;return function e(){return new Promise(function(s,d){var g="";if(n.lastIndexOf("v3")==-1){var h=!0,y=!1,f=void 0;try{for(var R,S=Object.keys(v)[Symbol.iterator]();!(h=(R=S.next()).done);h=!0){var b=R.value;Array.isArray(v[b])&&(v[b]=v[b].join(","))}}catch(e){y=!0,f=e}finally{try{!h&&S.return&&S.return()}finally{if(y)throw f}}g=a.stringify(v).replace(/%2C/,",")}else{var _=!0,E=!1,M=void 0;try{for(var A,T=Object.keys(v)[Symbol.iterator]();!(_=(A=T.next()).done);_=!0){var N=A.value;if(Array.isArray(v[N]))for(var U=0;U=500&&(g.debug&&console.log("!!! resending request !!!"),setTimeout(function(){t.bind(g)(i)},1e3)),429===u&&(g.debug&&console.log("!!! resending request !!!"),setTimeout(function(){t.bind(g)(i)},1e3*r.headers["retry-after"]+50)),u>=400?i(l+" : "+o.yellow(q)):(Number.isInteger(I.ttl)&&I.ttl>0&&g.cache.set({key:q,ttl:I.ttl},a),i(n,JSON.parse(a)));if(u>=500)g.debug&&console.log("!!! resending promise request !!!"),setTimeout(function(){},1e3),setTimeout(function(){return d("retry")},1e3);else{if(429!==u)return n||u>=400?d(l+" : "+o.yellow(q)):(Number.isInteger(I.ttl)&&I.ttl>0&&g.cache.set({key:q,ttl:I.ttl},a),s(JSON.parse(a)));g.debug&&console.log("!!! resending promise request !!!"),setTimeout(function(){return s(e())},1e3*r.headers["retry-after"]+50)}}else console.log(n,O)})):setTimeout(function(){t.bind(g)(i)},1e3)}(t)}else r({url:O},function(e,n,r){if(n){var a=i,u=n.statusCode,l=L(u);return a.debug&&P(n,l,O),"function"==typeof t?u>=400?t(l+" : "+o.yellow(q)):t(e,JSON.parse(r)):e?d("err:",e):s(JSON.parse(r))}console.log(e,q)})})})}()}},{key:"_championMasteryRequest",value:function(e,t){var i=e.endUrl,n=e.region,s=e.options;return this._baseRequest({endUrl:p.CHAMPION_MASTERY+"/v"+M.CHAMPION+"/"+i,region:n,options:s,championMastery:!0,cacheParams:{ttl:this.CACHE_TIMERS.CHAMPION_MASTERY}},t)}},{key:"_championRequest",value:function(e,t){var i=e.endUrl,n=e.region,s=e.options;return this._baseRequest({endUrl:p.CHAMPION+"/v"+M.CHAMPION+"/"+i,region:n,options:s,cacheParams:{ttl:this.CACHE_TIMERS.CHAMPION}},t)}},{key:"_spectatorRequest",value:function(e,t){var i=e.endUrl,n=e.region;return this._baseRequest({endUrl:p.SPECTATOR+"/v"+M.SPECTATOR+"/"+i,region:n,cacheParams:{ttl:this.CACHE_TIMERS.SPECTATOR}},t)}},{key:"_staticRequest",value:function(e,t){var i=e.endUrl,n=e.region,s=e.options;return this._baseRequest({endUrl:p.STATIC_DATA+"/v"+M.STATIC_DATA+"/"+i,staticReq:!0,region:n,options:s,cacheParams:{ttl:this.CACHE_TIMERS.STATIC}},t)}},{key:"_statusRequest",value:function(e,t){var i=e.endUrl,n=e.region,s=e.options;return this._baseRequest({endUrl:p.STATUS+"/v"+M.STATUS+"/"+i,status:!0,region:n,options:s,cacheParams:{ttl:this.CACHE_TIMERS.STATUS}},t)}},{key:"_gameRequest",value:function(e,t){var i=e.endUrl,n=e.region;return this._baseRequest({endUrl:"v"+M.GAME+"/game/"+i,region:n,cacheParams:{ttl:this.CACHE_TIMERS.GAME}},t)}},{key:"_leagueRequest",value:function(e,t){var i=e.endUrl,n=e.region,s=e.options;return this._baseRequest({endUrl:p.LEAGUE+"/v"+M.LEAGUE+"/"+i,region:n,options:s,cacheParams:{ttl:this.CACHE_TIMERS.LEAGUE}},t)}},{key:"_matchRequest",value:function(e,t){var i=e.endUrl,n=e.region,s=e.options;return this._baseRequest({endUrl:p.MATCH+"/v"+M.MATCH+"/"+i,region:n,options:s,cacheParams:{ttl:this.CACHE_TIMERS.MATCH}},t)}},{key:"_matchlistRequest",value:function(e,t){var i=e.endUrl,n=e.region,s=e.options;return this._baseRequest({endUrl:"v"+M.MATCH_LIST+"/matchlist/by-summoner/"+i,region:n,options:s,cacheParams:{ttl:this.CACHE_TIMERS.MATCH_LIST}},t)}},{key:"_runesMasteriesRequest",value:function(e,t){var i=e.endUrl,n=e.region;return this._baseRequest({endUrl:p.RUNES_MASTERIES+"/v"+M.RUNES_MASTERIES+"/"+i,region:n,cacheParams:{ttl:this.CACHE_TIMERS.RUNES_MASTERIES}},t)}},{key:"_statsRequest",value:function(e,t){var i=e.endUrl,n=e.region,s=e.options;return this._baseRequest({endUrl:"v"+M.STATS+"/stats/by-summoner/"+i,region:n,options:s,cacheParams:{ttl:this.CACHE_TIMERS.STATS}},t)}},{key:"_summonerRequest",value:function(e,t){var i=e.endUrl,n=e.region;return this._baseRequest({endUrl:p.SUMMONER+"/v"+M.SUMMONER+"/summoners/"+i,region:n,cacheParams:{ttl:this.CACHE_TIMERS.SUMMONER}},t)}},{key:"_tournamentRequest",value:function(e,t){var i=(e.endUrl,e.region);return this._baseRequest({endUrl:p.TOURNAMENT+"/v"+M.TOURNAMENT,region:i,cacheParams:{ttl:this.CACHE_TIMERS.TOURNAMENT}},t)}},{key:"_logError",value:function(e,t){throw new Error(o.bold.yellow(e)+" "+o.red("request")+" "+o.bold.red("FAILED")+o.red("; "+t))}},{key:"setRegion",value:function(e){if(this.defaultRegion=C(e)?e:void 0,!this.defaultRegion)throw new Error(o.red("setRegion() by Kindred failed: "+o.yellow(e)+" is an invalid region.")+"\n"+o.red("Try importing "+o.yellow("require('./dist/kindred-api').REGIONS")+" and using one of those values instead."))}},{key:"getChamps",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=e.options,n=arguments[1];return"function"==typeof arguments[0]&&(n=arguments[0],arguments[0]=void 0),this._championRequest({endUrl:"champions",region:t,options:i},n)}},{key:"getChamp",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=e.id,n=e.championId,s=arguments[1];return Number.isInteger(i)||Number.isInteger(n)?this._championRequest({endUrl:"champions/"+(i||n),region:t},s):this._logError(this.getChamp.name,"required params "+o.yellow("`id/championId` (int)")+" not passed in")}},{key:"getChampMastery",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=e.playerId,n=e.championId,s=e.options,r=arguments[1];return Number.isInteger(i)&&Number.isInteger(n)?this._championMasteryRequest({endUrl:"champion-masteries/by-summoner/"+i+"/by-champion/"+n,region:t,options:s},r):this._logError(this.getChampMastery.name,"required params "+o.yellow("`playerId` (int) AND `championId` (int)")+" not passed in")}},{key:"getChampMasteries",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=t.region,n=t.accountId,s=t.accId,r=t.id,a=t.summonerId,u=t.playerId,d=t.name,l=arguments[1];return Number.isInteger(n||s)?new Promise(function(t,r){return e.getSummoner({accId:n||s,region:i},function(n,s){return n?void(l?l(n):r(n)):t(e._championMasteryRequest({endUrl:"champion-masteries/by-summoner/"+s.id,region:i},l))})}):Number.isInteger(r||a||u)?this._championMasteryRequest({endUrl:"champion-masteries/by-summoner/"+(r||a||u),region:i},l):"object"===g(arguments[0])&&"string"==typeof d?new Promise(function(t,n){return e.getSummoner({name:d,region:i},function(s,r){return s?void(l?l(s):n(s)):t(e._championMasteryRequest({endUrl:"champion-masteries/by-summoner/"+r.id,region:i},l))})}):this._logError(this.getChampMasteries.name,"required params "+o.yellow("`id/summonerId/playerId` (int)")+", "+o.yellow("`accountId/accId` (int)")+", or "+o.yellow("`name` (str)")+" not passed in")}},{key:"getTotalChampMasteryScore",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=t.region,n=t.accountId,s=t.accId,r=t.id,a=t.summonerId,u=t.playerId,d=t.name,l=arguments[1];return Number.isInteger(n||s)?new Promise(function(t,r){return e.getSummoner({accId:n||s,region:i},function(n,s){return n?void(l?l(n):r(n)):t(e._championMasteryRequest({endUrl:"scores/by-summoner/"+s.id,region:i},l))})}):Number.isInteger(r||a||u)?this._championMasteryRequest({endUrl:"scores/by-summoner/"+(r||a||u),region:i},l):"object"===g(arguments[0])&&"string"==typeof d?new Promise(function(t,n){return e.getSummoner({name:d,region:i},function(s,r){return s?void(l?l(s):n(s)):t(e._championMasteryRequest({endUrl:"scores/by-summoner/"+r.id,region:i},l))})}):this._logError(this.getTotalChampMasteryScore.name,"required params "+o.yellow("`id/summonerId/playerId` (int)")+", "+o.yellow("`accountId/accId` (int)")+", or "+o.yellow("`name` (str)")+" not passed in")}},{key:"getCurrentGame",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=t.region,n=t.accountId,s=t.accId,r=t.id,a=t.summonerId,u=t.playerId,d=t.name,l=arguments[1];return Number.isInteger(n||s)?new Promise(function(t,r){return e.getSummoner({accId:n||s,region:i},function(n,s){return n?void(l?l(n):r(n)):t(e._spectatorRequest({endUrl:"active-games/by-summoner/"+s.id,region:i},l))})}):Number.isInteger(r||a||u)?this._spectatorRequest({endUrl:"active-games/by-summoner/"+(r||a||u),region:i},l):"object"===g(arguments[0])&&"string"==typeof d?new Promise(function(t,n){return e.getSummoner({name:d,region:i},function(s,r){return s?void(l?l(s):n(s)):t(e._spectatorRequest({endUrl:"active-games/by-summoner/"+r.id,region:i},l))})}):this._logError(this.getCurrentGame.name,"required params "+o.yellow("`id/summonerId/playerId` (int)")+", "+o.yellow("`accountId/accId` (int)")+", or "+o.yellow("`name` (string)")+" not passed in")}},{key:"getFeaturedGames",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=arguments[1];return"function"==typeof arguments[0]&&(i=arguments[0],arguments[0]=void 0),this._spectatorRequest({endUrl:"featured-games",region:t},i)}},{key:"getRecentGames",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=t.region,n=t.accountId,s=t.accId,r=t.id,a=t.summonerId,u=t.playerId,d=t.name,l=arguments[1];return Number.isInteger(n||s)?new Promise(function(t,r){return e.getSummoner({accId:n||s,region:i},function(n,s){return n?void(l?l(n):r(n)):t(e._gameRequest({endUrl:"by-summoner/"+s.id+"/recent",region:i},l))})}):Number.isInteger(r||a||u)?this._gameRequest({endUrl:"by-summoner/"+(r||a||u)+"/recent",region:i},l):"object"===g(arguments[0])&&"string"==typeof d?new Promise(function(t,n){return e.getSummoner({name:d,region:i},function(s,r){return s?void(l?l(s):n(s)):t(e._gameRequest({endUrl:"by-summoner/"+r.id+"/recent",region:i},l))})}):this._logError(this.getRecentGames.name,"required params "+o.yellow("`id/summonerId/playerId` (int)")+", "+o.yellow("`accountId/accId` (int)")+", or "+o.yellow("`name` (string)")+" not passed in")}},{key:"getLeagues",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=t.region,n=t.accountId,s=t.accId,r=t.id,a=t.summonerId,u=t.playerId,d=t.name,l=t.options,c=arguments[1];return Number.isInteger(n||s)?new Promise(function(t,r){return e.getSummoner({accId:n||s,region:i},function(n,s){return n?void(c?c(n):r(n)):t(e._leagueRequest({endUrl:"leagues/by-summoner/"+s.id,region:i,options:l},c))})}):Number.isInteger(r||a||u)?this._leagueRequest({endUrl:"leagues/by-summoner/"+(r||a||u),region:i,options:l},c):"object"===g(arguments[0])&&"string"==typeof d?new Promise(function(t,n){return e.getSummoner({name:d,region:i},function(s,r){return s?void(c?c(s):n(s)):t(e._leagueRequest({endUrl:"leagues/by-summoner/"+r.id,region:i,options:l},c))})}):this._logError(this.getLeagues.name,"required params "+o.yellow("`id/summonerId/playerId` (int)")+", "+o.yellow("`accountId/accId` (int)")+", or "+o.yellow("`name` (string)")+" not passed in")}},{key:"getLeaguePositions",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=t.region,n=t.accountId,s=t.accId,r=t.id,a=t.summonerId,u=t.playerId,d=t.name,l=arguments[1];return Number.isInteger(n||s)?new Promise(function(t,r){return e.getSummoner({accId:n||s,region:i},function(n,s){return n?void(l?l(n):r(n)):t(e._leagueRequest({endUrl:"positions/by-summoner/"+s.id,region:i},l))})}):Number.isInteger(r||a||u)?this._leagueRequest({endUrl:"positions/by-summoner/"+(r||a||u),region:i},l):"object"===g(arguments[0])&&"string"==typeof d?new Promise(function(t,n){return e.getSummoner({name:d,region:i},function(s,r){return s?void(l?l(s):n(s)):t(e._leagueRequest({endUrl:"positions/by-summoner/"+r.id,region:i},l))})}):void this._logError(this.getLeaguePositions.name,"required params "+o.yellow("`id/summonerId/playerId` (int)")+", "+o.yellow("`accountId/accId` (int)")+", or "+o.yellow("`name` (string)")+" not passed in")}},{key:"getChallengers",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=e.queue,n=void 0===i?"RANKED_SOLO_5x5":i,s=arguments[1];if(s="function"==typeof arguments[0]?arguments[0]:arguments[1],"string"==typeof n)return this._leagueRequest({endUrl:"challengerleagues/by-queue/"+n,region:t},s);this._logError(this.getChallengers.name,"required params "+o.yellow("`queue` (string)")+" not passed in")}},{key:"getMasters",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=e.queue,n=void 0===i?"RANKED_SOLO_5x5":i,s=arguments[1];if(s="function"==typeof arguments[0]?arguments[0]:arguments[1],"string"==typeof n)return this._leagueRequest({endUrl:"masterleagues/by-queue/"+n,region:t},s);this._logError(this.getMasters.name,"required params "+o.yellow("`queue` (string)")+" not passed in")}},{key:"getChampionList",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=e.options,n=arguments[1];return"function"==typeof arguments[0]&&(n=arguments[0],arguments[0]=void 0),this._staticRequest({endUrl:"champions",region:t,options:i},n)}},{key:"getChampion",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=e.id,n=e.championId,s=e.options,r=arguments[1];return Number.isInteger(i||n)?this._staticRequest({endUrl:"champions/"+(i||n),region:t,options:s},r):this._logError(this.getChampion.name,"required params "+o.yellow("`id/championId` (int)")+" not passed in")}},{key:"getItems",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=e.options,n=arguments[1];return"function"==typeof arguments[0]&&(n=arguments[0],arguments[0]=void 0),this._staticRequest({endUrl:"items",region:t,options:i},n)}},{key:"getItem",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=e.id,n=e.itemId,s=e.options,r=arguments[1];return Number.isInteger(i||n)?this._staticRequest({endUrl:"items/"+(i||n),region:t,options:s},r):this._logError(this.getItem.name,"required params "+o.yellow("`id/itemId` (int)")+" not passed in")}},{key:"getLanguageStrings",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=e.options,n=arguments[1];return"function"==typeof arguments[0]&&(n=arguments[0],arguments[0]=void 0),this._staticRequest({endUrl:"language-strings",region:t,options:i},n)}},{key:"getLanguages",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=arguments[1];return"function"==typeof arguments[0]&&(i=arguments[0],arguments[0]=void 0),this._staticRequest({endUrl:"languages",region:t},i)}},{key:"getMapData",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=e.options,n=arguments[1];return"function"==typeof arguments[0]&&(n=arguments[0],arguments[0]=void 0),this._staticRequest({endUrl:"maps",region:t,options:i},n)}},{key:"getMasteryList", +value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=e.options,n=arguments[1];return"function"==typeof arguments[0]&&(n=arguments[0],arguments[0]=void 0),this._staticRequest({endUrl:"masteries",region:t,options:i},n)}},{key:"getMastery",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=e.id,n=e.masteryId,s=e.options,r=arguments[1];return Number.isInteger(i||n)?this._staticRequest({endUrl:"masteries/"+(i||n),region:t,options:s},r):this._logError(this.getMastery.name,"required params "+o.yellow("`id/masteryId` (int)")+" not passed in")}},{key:"getProfileIcons",value:function(e,t){var i=e.region,n=e.options;return"function"==typeof arguments[0]&&(t=arguments[0],arguments[0]=void 0),this._staticRequest({endUrl:"profile-icons",region:i,options:n},t)}},{key:"getRealmData",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=arguments[1];return"function"==typeof arguments[0]&&(i=arguments[0],arguments[0]=void 0),this._staticRequest({endUrl:"realms",region:t},i)}},{key:"getRuneList",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=e.options,n=arguments[1];return"function"==typeof arguments[0]&&(n=arguments[0],arguments[0]=void 0),this._staticRequest({endUrl:"runes",region:t,options:i},n)}},{key:"getRune",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=e.id,n=e.runeId,s=e.options,r=arguments[1];return Number.isInteger(i||n)?this._staticRequest({endUrl:"runes/"+(i||n),region:t,options:s},r):this._logError(this.getRune.name,"required params "+o.yellow("`id/runeId` (int)")+" not passed in")}},{key:"getSummonerSpells",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=e.options,n=arguments[1];return"function"==typeof arguments[0]&&(n=arguments[0],arguments[0]=void 0),this._staticRequest({endUrl:"summoner-spells",region:t,options:i},n)}},{key:"getSummonerSpell",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=e.id,n=e.spellId,s=e.summonerSpellId,r=e.options,a=arguments[1];return Number.isInteger(i||n||s)?this._staticRequest({endUrl:"summoner-spells/"+(i||n||s),region:t,options:r},a):this._logError(this.getSummonerSpell.name,"required params "+o.yellow("`id/spellId/summonerSpellId` (int)")+" not passed in")}},{key:"getVersionData",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=e.options,n=arguments[1];return"function"==typeof arguments[0]&&(n=arguments[0],arguments[0]=void 0),this._staticRequest({endUrl:"versions",region:t,options:i},n)}},{key:"getShardStatus",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=arguments[1];return"function"==typeof arguments[0]&&(i=arguments[0],arguments[0]=void 0),"string"==typeof arguments[0]?C(arguments[0])?this._statusRequest({endUrl:"shard-data",region:arguments[0]},i):this._logError(this.getShardStatus.name,"invalid region!"):this._statusRequest({endUrl:"shard-data",region:t},i)}},{key:"getMatch",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=e.id,n=e.matchId,s=e.options,r=arguments[1];return Number.isInteger(i||n)?this._matchRequest({endUrl:"matches/"+(i||n),region:t,options:s},r):this._logError(this.getMatch.name,"required params "+o.yellow("`id/matchId` (int)")+" not passed in")}},{key:"getMatchlist",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=t.region,n=t.accountId,s=t.accId,r=t.id,a=t.summonerId,u=t.playerId,d=t.name,l=t.options,c=void 0===l?{queue:S.TEAM_BUILDER_RANKED_SOLO}:l,h=arguments[1];return Number.isInteger(n||s)?this._matchRequest({endUrl:"matchlists/by-account/"+(n||s),region:i,options:c},h):Number.isInteger(r||a||u)?new Promise(function(t,n){return e.getSummoner({id:r,region:i},function(s,r){return s?void(h?h(s):n(s)):t(e._matchRequest({endUrl:"matchlists/by-account/"+r.accountId,region:i,options:c},h))})}):"object"===g(arguments[0])&&"string"==typeof d?new Promise(function(t,n){return e.getSummoner({name:d,region:i},function(s,r){return s?void(h?h(s):n(s)):t(e._matchRequest({endUrl:"matchlists/by-account/"+r.accountId,region:i,options:c},h))})}):this._logError(this.getMatchlist.name,"required params "+o.yellow("`accountId/accId` (int)")+", "+o.yellow("`id/summonerId/playerId` (int)")+", or "+o.yellow("`name` (str)")+" not passed in")}},{key:"getRecentMatchlist",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=t.region,n=t.accountId,s=t.accId,r=t.id,a=t.summonerId,u=t.playerId,d=t.name,l=arguments[1];return Number.isInteger(n||s)?this._matchRequest({endUrl:"matchlists/by-account/"+(n||s)+"/recent",region:i},l):Number.isInteger(r||a||u)?new Promise(function(t,n){return e.getSummoner({id:r,region:i},function(s,r){return s?void(l?l(s):n(s)):t(e._matchRequest({endUrl:"matchlists/by-account/"+r.accountId+"/recent",region:i},l))})}):"object"===g(arguments[0])&&"string"==typeof d?new Promise(function(t,n){return e.getSummoner({name:d,region:i},function(s,r){return s?void(l?l(s):n(s)):t(e._matchRequest({endUrl:"matchlists/by-account/"+r.accountId+"/recent",region:i},l))})}):this._logError(this.getRecentMatchlist.name,"required params "+o.yellow("`accountId/accId` (int)")+", "+o.yellow("`id/summonerId/playerId` (int)")+", or "+o.yellow("`name` (str)")+" not passed in")}},{key:"getMatchTimeline",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=e.id,n=e.matchId,s=arguments[1];return Number.isInteger(i||n)?this._matchRequest({endUrl:"timelines/by-match/"+(i||n),region:t},s):this._logError(this.getMatchTimeline.name,"required params "+o.yellow("`id/matchId` (int)")+" not passed in")}},{key:"getRunes",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=t.region,n=t.accountId,s=t.accId,r=t.id,a=t.summonerId,u=t.playerId,d=t.name,l=arguments[1];return Number.isInteger(n||s)?new Promise(function(t,r){return e.getSummoner({accId:n||s,region:i},function(n,s){return n?void(l?l(n):r(n)):t(e._runesMasteriesRequest({endUrl:"runes/by-summoner/"+s.id,region:i},l))})}):Number.isInteger(r||a||u)?this._runesMasteriesRequest({endUrl:"runes/by-summoner/"+(r||a||u),region:i},l):"object"===g(arguments[0])&&"string"==typeof d?new Promise(function(t,n){return e.getSummoner({name:d,region:i},function(s,r){return s?void(l?l(s):n(s)):t(e._runesMasteriesRequest({endUrl:"runes/by-summoner/"+r.id,region:i},l))})}):this._logError(this.getRunes.name,"required params "+o.yellow("`id/summonerId/playerId` (int)")+", "+o.yellow("`accountId/accId` (int)")+", or "+o.yellow("`name` (str)")+" not passed in")}},{key:"getMasteries",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=t.region,n=t.accountId,s=t.accId,r=t.id,a=t.summonerId,u=t.playerId,d=t.name,l=arguments[1];return Number.isInteger(n||s)?new Promise(function(t,r){return e.getSummoner({accId:n||s,region:i},function(n,s){return n?void(l?l(n):r(n)):t(e._runesMasteriesRequest({endUrl:"masteries/by-summoner/"+s.id,region:i},l))})}):Number.isInteger(r||a||u)?this._runesMasteriesRequest({endUrl:"masteries/by-summoner/"+(r||a||u),region:i},l):"object"===g(arguments[0])&&"string"==typeof d?new Promise(function(t,n){return e.getSummoner({name:d,region:i},function(s,r){return s?void(l?l(s):n(s)):t(e._runesMasteriesRequest({endUrl:"masteries/by-summoner/"+r.id,region:i},l))})}):this._logError(this.getMasteries.name,"required params "+o.yellow("`id/summonerId/playerId` (int)")+", "+o.yellow("`accountId/accId` (int)")+", or "+o.yellow("`name` (str)")+" not passed in")}},{key:"getRankedStats",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=t.region,n=t.accountId,s=t.accId,r=t.id,a=t.summonerId,u=t.playerId,d=t.name,l=t.options,c=arguments[1];return Number.isInteger(n||s)?new Promise(function(t,r){return e.getSummoner({accId:n||s,region:i},function(n,s){return n?void(c?c(n):r(n)):t(e._statsRequest({endUrl:s.id+"/ranked",region:i,options:l},c))})}):Number.isInteger(r||a||u)?this._statsRequest({endUrl:(r||a||u)+"/ranked",region:i,options:l},c):"object"===g(arguments[0])&&"string"==typeof d?new Promise(function(t,n){return e.getSummoner({name:d,region:i},function(s,r){return s?void(c?c(s):n(s)):t(e._statsRequest({endUrl:r.id+"/ranked",region:i,options:l},c))})}):void this._logError(this.getRankedStats.name,"required params "+o.yellow("`id/summonerId/playerId` (int)")+", "+o.yellow("`accountId/accId` (int)")+", or "+o.yellow("`name` (string)")+" not passed in")}},{key:"getStatsSummary",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=t.region,n=t.accountId,s=t.accId,r=t.id,a=t.summonerId,u=t.playerId,d=t.name,l=t.options,c=arguments[1];return Number.isInteger(n||s)?new Promise(function(t,r){return e.getSummoner({accId:n||s,region:i},function(n,s){return n?void(c?c(n):r(n)):t(e._statsRequest({endUrl:s.id+"/summary",region:i,options:l},c))})}):Number.isInteger(r||a||u)?this._statsRequest({endUrl:(r||a||u)+"/summary",region:i,options:l},c):"object"===g(arguments[0])&&"string"==typeof d?new Promise(function(t,n){return e.getSummoner({name:d,region:i},function(s,r){return s?void(c?c(s):n(s)):t(e._statsRequest({endUrl:r.id+"/summary",region:i,options:l},c))})}):void this._logError(this.getStatsSummary.name,"required params "+o.yellow("`id/summonerId/playerId` (int)")+", "+o.yellow("`accountId/accId` (int)")+", or "+o.yellow("`name` (string)")+" not passed in")}},{key:"getSummoner",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.region,i=e.id,n=e.summonerId,s=e.playerId,r=e.accountId,a=e.accId,u=e.name,d=arguments[1];return Number.isInteger(i||n||s)?this._summonerRequest({endUrl:""+(i||n||s),region:t},d):"object"===g(arguments[0])&&"string"==typeof u?this._summonerRequest({endUrl:"by-name/"+this._sanitizeName(u),region:t},d):Number.isInteger(r||a)?this._summonerRequest({endUrl:"by-account/"+(r||a),region:t},d):this._logError(this.getSummoner.name,"required params "+o.yellow("`id/summonerId/playerId` (int)")+", "+o.yellow("`accountId/accId` (int)")+", or "+o.yellow("`name` (string)")+" not passed in")}},{key:"getDTOByCode",value:function(e,t){return"string"==typeof e?this._tournamentRequest({endUrl:"lobby-events/codes/"+e},t):this._logError(this.getDTOByCode.name,"required params "+o.yellow("`code` (string)")+" not passed in")}},{key:"getLobbyListEventsByCode",value:function(e,t){return"string"==typeof e?this._tournamentRequest({endUrl:"lobby-events/by-code/"+e},t):this._logError(this.getLobbyListEventsByCode.name,"required params "+o.yellow("`code` (string)")+" not passed in")}},{key:"listChampions",value:function(e,t,i){return"function"==typeof e&&(i=e,e=void 0),"function"==typeof t&&(i=t,t=void 0),"string"==typeof e&&(t=e,e=void 0),this.Champion.all({options:e,region:t},i)}},{key:"getChampionById",value:function(e,t,i){return"function"==typeof t&&(i=t,t=void 0),this.Champion.get({id:e,region:t},i)}},{key:"listFeaturedGames",value:function(e,t){return"function"==typeof e&&(t=e,e=void 0),this.FeaturedGames.get({region:e},t)}},{key:"listChallengers",value:function(e,t,i){return C(e)&&("function"==typeof t&&(i=t,t=void 0),t=e,e=void 0),"function"==typeof e&&(i=e,e=void 0),"function"==typeof t&&(i=t,t=void 0),this.League.challengers({queue:e,region:t},i)}},{key:"listMasters",value:function(e,t,i){return C(e)&&("function"==typeof t&&(i=t,t=void 0),t=e,e=void 0),"function"==typeof e&&(i=e,e=void 0),"function"==typeof t&&(i=t,t=void 0),this.League.masters({queue:e,region:t},i)}},{key:"getSummonerByAccountId",value:function(e,t,i){return"function"==typeof t&&(i=t,t=void 0),this.Summoner.get({region:t,accId:e},i)}},{key:"getSummonerById",value:function(e,t,i){return"function"==typeof t&&(i=t,t=void 0),this.Summoner.get({region:t,id:e},i)}},{key:"getSummonerByName",value:function(e,t,i){return"function"==typeof t&&(i=t,t=void 0),this.Summoner.get({region:t,name:e},i)}},{key:"getMasteriesByAccountId",value:function(e,t,i){return"function"==typeof t&&(i=t,t=void 0),this.Masteries.get({region:t,accId:e},i)}},{key:"getMasteriesById",value:function(e,t,i){return"function"==typeof t&&(i=t,t=void 0),this.Masteries.get({region:t,id:e},i)}},{key:"getMasteriesByName",value:function(e,t,i){return"function"==typeof t&&(i=t,t=void 0),this.Masteries.get({region:t,name:e},i)}},{key:"getMatchById",value:function(e,t,i){return"function"==typeof t&&(i=t,t=void 0),this.Match.get({region:t,id:e},i)}},{key:"getMatchlistByAccountId",value:function(e,t,i,n){return"function"==typeof t&&(n=t,t=void 0),"function"==typeof i&&(n=i,i=void 0),"string"==typeof t&&(i=t,t=void 0),this.Matchlist.get({region:i,accId:e},n)}},{key:"getMatchlistById",value:function(e,t,i,n){return"function"==typeof t&&(n=t,t=void 0),"function"==typeof i&&(n=i,i=void 0),"string"==typeof t&&(i=t,t=void 0),this.Matchlist.get({region:i,id:e},n)}},{key:"getMatchlistByName",value:function(e,t,i,n){return"function"==typeof t&&(n=t,t=void 0),"function"==typeof i&&(n=i,i=void 0),"string"==typeof t&&(i=t,t=void 0),this.Matchlist.get({name:e,options:t,region:i},n)}},{key:"getMatchTimelineById",value:function(e,t,i){return"function"==typeof t&&(i=t,t=void 0),this.Match.timeline({id:e,region:t},i)}},{key:"getRunesByAccountId",value:function(e,t,i){return"function"==typeof t&&(i=t,t=void 0),this.Runes.get({region:t,accId:e},i)}},{key:"getRunesById",value:function(e,t,i){return"function"==typeof t&&(i=t,t=void 0),this.Runes.get({region:t,id:e},i)}},{key:"getRunesByName",value:function(e,t,i){return"function"==typeof t&&(i=t,t=void 0),this.Runes.get({region:t,name:e},i)}},{key:"getStaticChampionList",value:function(e,t,i){return"function"==typeof e&&(i=e,e=void 0),"function"==typeof t&&(i=t,t=void 0),"string"==typeof e&&(t=e,e=void 0),this.Static.champions({region:t,options:e},i)}},{key:"getStaticChampionById",value:function(e,t,i,n){return"function"==typeof t&&(n=t,t=void 0),"function"==typeof i&&(n=i,i=void 0),"string"==typeof t&&(i=t,t=void 0),this.Static.champion({id:e,options:t,region:i},n)}},{key:"getStaticItemList",value:function(e,t,i){return"function"==typeof e&&(i=e,e=void 0),"function"==typeof t&&(i=t,t=void 0),"string"==typeof e&&(t=e,e=void 0),this.Static.items({options:e,region:t},i)}},{key:"getStaticItemById",value:function(e,t,i,n){return"function"==typeof t&&(n=t,t=void 0),"function"==typeof i&&(n=i,i=void 0),"string"==typeof t&&(i=t,t=void 0),this.Static.item({id:e,options:t,region:i},n)}},{key:"getStaticLanguageStringList",value:function(e,t,i){return"function"==typeof e&&(i=e,e=void 0),"function"==typeof t&&(i=t,t=void 0),"string"==typeof e&&(t=e,e=void 0),this.Static.languageStrings({options:e,region:t},i)}},{key:"getStaticLanguageList",value:function(e,t){return"function"==typeof e&&(t=e,e=void 0),this.Static.languages({region:e},t)}},{key:"getStaticMapList",value:function(e,t,i){return"function"==typeof e&&(i=e,e=void 0),"function"==typeof t&&(i=t,t=void 0),"string"==typeof e&&(t=e,e=void 0),this.Static.mapData({options:e,region:t},i)}},{key:"getStaticMasteryList",value:function(e,t,i){return"function"==typeof e&&(i=e,e=void 0),"function"==typeof t&&(i=t,t=void 0),"string"==typeof e&&(t=e,e=void 0),this.Static.masteries({options:e,region:t},i)}},{key:"getStaticMasteryById",value:function(e,t,i,n){return"function"==typeof t&&(n=t,t=void 0),"function"==typeof i&&(n=i,i=void 0),"string"==typeof t&&(i=t,t=void 0),this.Static.mastery({id:e,options:t,region:i},n)}},{key:"getStaticProfileIconList",value:function(e,t,i){return"function"==typeof e&&(i=e,e=void 0),"function"==typeof t&&(i=t,t=void 0),"string"==typeof e&&(t=e,e=void 0),this.Static.profileIcons({options:e,region:t},i)}},{key:"getStaticRealmList",value:function(e,t){return"function"==typeof e&&(t=e,e=void 0),this.Static.realm({region:e},t)}},{key:"getStaticRuneList",value:function(e,t,i){return"function"==typeof e&&(i=e,e=void 0),"function"==typeof t&&(i=t,t=void 0),"string"==typeof e&&(t=e,e=void 0),this.Static.runes({options:e,region:t},i)}},{key:"getStaticRuneById",value:function(e,t,i,n){return"function"==typeof t&&(n=t,t=void 0),"function"==typeof i&&(n=i,i=void 0),"string"==typeof t&&(i=t,t=void 0),this.Static.rune({id:e,options:t,region:i},n)}},{key:"getStaticSummonerSpellList",value:function(e,t,i){return"function"==typeof e&&(i=e,e=void 0),"function"==typeof t&&(i=t,t=void 0),"string"==typeof e&&(t=e,e=void 0),this.Static.spells({options:e,region:t},i)}},{key:"getStaticSummonerSpellById",value:function(e,t,i,n){return"function"==typeof t&&(n=t,t=void 0),"function"==typeof i&&(n=i,i=void 0),"string"==typeof t&&(i=t,t=void 0),this.Static.spell({id:e,options:t,region:i},n)}},{key:"getStaticVersionList",value:function(e,t){return"function"==typeof e&&(t=e,e=void 0),this.Static.versions({region:e},t)}},{key:"getSummonerByAccId",value:function(e,t,i){return this.Summoner.get({region:t,accId:e},i)}},{key:"getRunesBySummonerId",value:function(e,t,i){return this.Runes.get({region:t,id:e},i)}},{key:"staticRuneList",value:function(e,t,i){return this.Static.runes({region:e,options:t},i)}}]),e}(),B={Kindred:D,REGIONS:_,LIMITS:R,TIME_CONSTANTS:f,CACHE_TYPES:A,QUEUE_TYPES:S,QUEUE_STRINGS:b,QuickStart:d,print:l};e.exports=B}); \ No newline at end of file diff --git a/package.json b/package.json index 4289007e..3e4bbc48 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "kindred-api", - "version": "2.0.43", + "version": "2.0.44", "description": "Node.js League of Legends v3 API wrapper with built-in rate-limiting (burst/spread, enforced per region), caching (in-memory, Redis), and parameter checking.", "main": "index.js", "jsnext:main": "src/index.js", diff --git a/src/kindred-api.js b/src/kindred-api.js index f6912575..1a944891 100644 --- a/src/kindred-api.js +++ b/src/kindred-api.js @@ -554,12 +554,17 @@ class Kindred { } else { if (statusCode >= 500) { if (self.debug) console.log('!!! resending promise request !!!') + setTimeout(() => { + () => resolve(tryRequest()) + }, 1000) setTimeout(() => { return reject('retry') }, 1000) } else if (statusCode === 429) { if (self.debug) console.log('!!! resending promise request !!!') - setTimeout(() => { return reject('retry') }, (response.headers['retry-after'] * 1000) + 50) + setTimeout(() => { + return resolve(tryRequest()) + }, (response.headers['retry-after'] * 1000) + 50) } else if (error || statusCode >= 400) { - return reject('err:', error, statusCode) + return reject(statusMessage + ' : ' + chalk.yellow(reqUrl)) } else { if (Number.isInteger(cacheParams.ttl) && cacheParams.ttl > 0) self.cache.set({ key: reqUrl, ttl: cacheParams.ttl }, body) @@ -605,10 +610,6 @@ class Kindred { }) } - if (!cb) return tryRequest() - .catch(tryRequest).catch(tryRequest).catch(tryRequest) - .then(data => data) - return tryRequest() }