Comparing version 2.0.4 to 2.1.0
declare type Uri = string; | ||
declare type ConstantKey = 'REGIONS' | 'LOCALES' | 'DEFAULT_LOCALES' | 'REGION_API_HOSTS' | 'SC2_REALMS' | 'OAUTH_AUTHORIZE_URIS' | 'OAUTH_TOKEN_URIS' | 'OAUTH_CHECK_TOKEN_URIS'; | ||
declare type ConstantKeys = ReadonlyArray<ConstantKey>; | ||
declare type RegionId = number; | ||
declare enum ConstantKey { | ||
REGIONS = "REGIONS", | ||
LOCALES = "LOCALES", | ||
DEFAULT_LOCALES = "DEFAULT_LOCALES", | ||
REGION_API_HOSTS = "REGION_API_HOSTS", | ||
SC2_REALMS = "SC2_REALMS", | ||
OAUTH_AUTHORIZE_URIS = "OAUTH_AUTHORIZE_URIS", | ||
OAUTH_TOKEN_URIS = "OAUTH_TOKEN_URIS", | ||
OAUTH_CHECK_TOKEN_URIS = "OAUTH_CHECK_TOKEN_URIS" | ||
} | ||
declare enum RegionName { | ||
us = "us", | ||
eu = "eu", | ||
kr = "kr", | ||
tw = "tw", | ||
cn = "cn" | ||
} | ||
declare enum RegionId { | ||
us = 1, | ||
eu = 2, | ||
kr = 3, | ||
tw = 3, | ||
cn = 5 | ||
} | ||
declare enum RegionIdAsString { | ||
us = "1", | ||
eu = "2", | ||
kr = "3", | ||
tw = "3", | ||
cn = "5" | ||
} | ||
declare type RegionIdKey = string; | ||
declare type RegionIdAsNumberOrString = RegionId | RegionIdKey; | ||
declare type RegionIdAsNumberOrString = RegionId | RegionIdAsString; | ||
declare type RegionIdArray = ReadonlyArray<RegionId>; | ||
declare type RegionName = string; | ||
declare type RegionNameArray = ReadonlyArray<RegionName>; | ||
declare type Locale = string; | ||
declare enum Locale { | ||
en_US = "en_US", | ||
es_MX = "es_MX", | ||
pt_BR = "pt_BR", | ||
en_GB = "en_GB", | ||
es_ES = "es_ES", | ||
fr_FR = "fr_FR", | ||
ru_RU = "ru_RU", | ||
de_DE = "de_DE", | ||
pt_PT = "pt_PT", | ||
it_IT = "it_IT", | ||
ko_KR = "ko_KR", | ||
zh_TW = "zh_TW", | ||
zh_CN = "zh_CN" | ||
} | ||
declare type LocaleArray = ReadonlyArray<Locale>; | ||
declare type DefaultLocaleIndex = number; | ||
declare enum DefaultLocaleIndex { | ||
us = 0, | ||
eu = 0, | ||
kr = 0, | ||
tw = 0, | ||
cn = 0 | ||
} | ||
declare type DefaultLocaleIndexArray = ReadonlyArray<DefaultLocaleIndex>; | ||
declare type Sc2Realm = number; | ||
declare enum Sc2Realm { | ||
US = 1, | ||
LatAm = 2, | ||
Europe = 1, | ||
Russia = 2, | ||
Korea = 1, | ||
Taiwan = 2, | ||
China = 1 | ||
} | ||
declare enum Sc2RealmAsString { | ||
US = "1", | ||
LatAm = "2", | ||
Europe = "1", | ||
Russia = "2", | ||
Korea = "1", | ||
Taiwan = "2", | ||
China = "1" | ||
} | ||
declare type Sc2RealmArray = ReadonlyArray<Sc2Realm>; | ||
declare type Sc2RealmList = ReadonlyArray<Sc2Realm>; | ||
declare type Sc2RealmAsNumberOrString = Sc2Realm | string; | ||
declare type Sc2RealmAsNumberOrString = Sc2Realm | Sc2RealmAsString; | ||
declare type RegionIdOrName = RegionId | RegionName; | ||
@@ -24,9 +88,49 @@ declare type MaybeRegion = RegionIdOrName | undefined; | ||
declare type Endpoint = string; | ||
declare type HttpMethod = 'GET' | 'POST'; | ||
declare enum HttpMethod { | ||
GET = "GET", | ||
POST = "POST" | ||
} | ||
declare type ValidatorFunction = (endpoint: Endpoint) => boolean; | ||
declare enum OAuthHost { | ||
us = "https://us.battle.net", | ||
eu = "https://eu.battle.net", | ||
kr = "https://apac.battle.net", | ||
tw = "https://apac.battle.net", | ||
cn = "https://www.battlenet.com.cn" | ||
} | ||
declare enum RegionHost { | ||
us = "https://us.api.blizzard.com", | ||
eu = "https://eu.api.blizzard.com", | ||
kr = "https://kr.api.blizzard.com", | ||
tw = "https://tw.api.blizzard.com", | ||
cn = "https://gateway.battlenet.com.cn" | ||
} | ||
declare enum OAuthEndpoint { | ||
authorize = "/oauth/authorize", | ||
token = "/oauth/token", | ||
checkToken = "/oauth/check_token?token=" | ||
} | ||
declare enum ApiHeaders { | ||
LastModified = "last-modified" | ||
} | ||
declare enum ErrorCode { | ||
NotAuthorized = 401 | ||
} | ||
declare enum ErrorResponseMessage { | ||
InvalidToken = "invalid_token", | ||
AccessTokenInvalid = "access_token_invalid", | ||
AccessTokenExpired = "access_token_invalid" | ||
} | ||
declare type InvalidAccessTokenError = { | ||
error: ErrorResponseMessage.AccessTokenInvalid; | ||
}; | ||
declare type ExpiredAccessTokenError = { | ||
error: ErrorResponseMessage.AccessTokenExpired; | ||
}; | ||
declare type ResponseError = InvalidAccessTokenError | ExpiredAccessTokenError; | ||
interface AccessTokenOptions { | ||
validateAccessTokenOnEachQuery?: boolean; | ||
refreshExpiredAccessToken?: boolean; | ||
onAccessTokenExpired?: Function | undefined; | ||
onAccessTokenRefresh?: Function | undefined; | ||
onAccessTokenExpired?: () => void; | ||
onAccessTokenRefresh?: (newAccessToken: string) => void; | ||
} | ||
@@ -44,15 +148,13 @@ interface QueryOptions { | ||
} | ||
interface InitOptions { | ||
region: string | number; | ||
clientId?: string; | ||
clientSecret?: string; | ||
accessToken?: string; | ||
validateAccessTokenOnEachQuery?: boolean; | ||
revalidateAccessTokenIfExpired?: boolean; | ||
onAccessTokenExpire?: Function | undefined; | ||
onAccessTokenRevalidate?: Function | undefined; | ||
interface BattleNetQueryOptions { | ||
region: RegionIdOrName; | ||
endpoint: string; | ||
clientId: string; | ||
clientSecret: string; | ||
accessToken: AccessToken; | ||
options: AccessTokenOptions & QueryOptions; | ||
} | ||
interface RegionIdProperties<Value> { | ||
readonly [regionId: string]: Value; | ||
} | ||
declare type RegionIdProperties<Value> = { | ||
readonly [key in RegionId]: Value; | ||
}; | ||
interface BlizzAPIOptions extends BattleNetOptions, AccessTokenOptions { | ||
@@ -79,3 +181,3 @@ } | ||
constructor(options: BlizzAPIOptions); | ||
query: (endpoint: Endpoint, options?: QueryOptions | undefined) => Promise<any>; | ||
query: <T = unknown>(endpoint: Endpoint, options?: QueryOptions | undefined) => Promise<ResponseError | T>; | ||
static getAllRegions: () => RegionIdProperties<RegionNameArray>; | ||
@@ -86,10 +188,10 @@ static getAllRegionIds: () => RegionIdArray; | ||
static validateRegionId: (regionId: RegionIdAsNumberOrString) => boolean; | ||
static getRegionIdByName: (regionName: string) => number; | ||
static validateRegionName: (regionName: string) => boolean; | ||
static getRegionIdByName: (regionName: RegionName) => RegionId; | ||
static validateRegionName: (regionName: RegionName) => boolean; | ||
static getAllLocales: () => RegionIdProperties<LocaleArray>; | ||
static getAllLocaleNames: () => string[]; | ||
static getLocalesByRegionId: (regionId: RegionIdAsNumberOrString) => LocaleArray; | ||
static checkIfLocaleLooksValid: (locale: string) => boolean; | ||
static validateLocale: (locale: string) => boolean; | ||
static isLocaleValidForRegionId: (locale: string, regionId: RegionIdAsNumberOrString) => boolean; | ||
static checkIfLocaleLooksValid: (locale: Locale) => boolean; | ||
static validateLocale: (locale: Locale) => boolean; | ||
static isLocaleValidForRegionId: (locale: Locale, regionId: RegionIdAsNumberOrString) => boolean; | ||
static getAllSc2Realms: () => RegionIdProperties<Sc2RealmArray>; | ||
@@ -101,6 +203,6 @@ static getAllAvailableSc2Realms: () => Sc2RealmList; | ||
static isSc2RealmValidForRegionId: (sc2Realm: Sc2RealmAsNumberOrString, regionId: RegionIdAsNumberOrString) => boolean; | ||
static getDefaultLocaleNameForRegionId: (regionId: RegionIdAsNumberOrString) => string; | ||
static getAllDefaultLocaleNames: () => RegionIdProperties<string>; | ||
static getDefaultLocaleNameForRegionId: (regionId: RegionIdAsNumberOrString) => Locale; | ||
static getAllDefaultLocaleNames: () => RegionIdProperties<Locale>; | ||
} | ||
export { AccessToken, AccessTokenOptions, BattleNetOptions, BlizzAPI, BlizzAPIOptions, ClientId, ClientSecret, ConstantKey, ConstantKeys, DefaultLocaleIndex, DefaultLocaleIndexArray, Endpoint, HttpMethod, InitOptions, Locale, LocaleArray, MaybeRegion, QueryOptions, RegionId, RegionIdArray, RegionIdAsNumberOrString, RegionIdKey, RegionIdOrName, RegionIdProperties, RegionName, RegionNameArray, Sc2Realm, Sc2RealmArray, Sc2RealmAsNumberOrString, Sc2RealmList, Uri, ValidatorFunction }; | ||
export { AccessToken, AccessTokenOptions, ApiHeaders, BattleNetOptions, BattleNetQueryOptions, BlizzAPI, BlizzAPIOptions, ClientId, ClientSecret, ConstantKey, DefaultLocaleIndex, DefaultLocaleIndexArray, Endpoint, ErrorCode, ErrorResponseMessage, ExpiredAccessTokenError, HttpMethod, InvalidAccessTokenError, Locale, LocaleArray, MaybeRegion, OAuthEndpoint, OAuthHost, QueryOptions, RegionHost, RegionId, RegionIdArray, RegionIdAsNumberOrString, RegionIdAsString, RegionIdKey, RegionIdOrName, RegionIdProperties, RegionName, RegionNameArray, ResponseError, Sc2Realm, Sc2RealmArray, Sc2RealmAsNumberOrString, Sc2RealmAsString, Sc2RealmList, Uri, ValidatorFunction }; |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var axios=require("axios");function _interopDefaultLegacy(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var axios__default=_interopDefaultLegacy(axios);const startsWithSlash=e=>e[0]==="/",isLongEnough=e=>e.length>3,validators=[startsWithSlash,isLongEnough],endpointValidator=e=>validators.every(t=>t(e)),uriValidator=e=>/(?:http[s]?:\/\/)[^\s(["<,>]*\.[^\s[",><]*/gm.test(e);var __defProp$2=Object.defineProperty,__getOwnPropSymbols$2=Object.getOwnPropertySymbols,__hasOwnProp$2=Object.prototype.hasOwnProperty,__propIsEnum$2=Object.prototype.propertyIsEnumerable,__defNormalProp$2=(e,t,o)=>t in e?__defProp$2(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,__spreadValues$2=(e,t)=>{for(var o in t||(t={}))__hasOwnProp$2.call(t,o)&&__defNormalProp$2(e,o,t[o]);if(__getOwnPropSymbols$2)for(var o of __getOwnPropSymbols$2(t))__propIsEnum$2.call(t,o)&&__defNormalProp$2(e,o,t[o]);return e},__async$5=(e,t,o)=>new Promise((s,n)=>{var c=r=>{try{a(o.next(r))}catch(i){n(i)}},l=r=>{try{a(o.throw(r))}catch(i){n(i)}},a=r=>r.done?s(r.value):Promise.resolve(r.value).then(c,l);a((o=o.apply(e,t)).next())});const fetchFromUri=e=>__async$5(this,null,function*(){const{uri:t,timeout:o,headers:s,params:n,data:c,auth:l}=e,a=e.method||"GET";if(!uriValidator(t))throw new RangeError(`'${t}' is not a valid parameter for fetchFromUri()`);const r=__spreadValues$2(__spreadValues$2(__spreadValues$2(__spreadValues$2({method:a,url:encodeURI(t),timeout:o||1e4},s&&{headers:s}),n&&{params:n}),l&&{auth:l}),c&&{data:c}),i=yield axios__default.default.request(r),d=i.headers["last-modified"]?i.headers["last-modified"]:null;return __spreadValues$2(__spreadValues$2({},i.data),d&&{lastModified:d})}),fetchAccessToken=e=>{const{oauthUri:t,clientId:o,clientSecret:s}=e;return fetchFromUri({data:"grant_type=client_credentials",auth:{username:o,password:s},uri:t,method:"POST"})},defaultLocales=Object.freeze({1:0,2:0,3:0,5:0}),locales=Object.freeze({1:Object.freeze(["en_US","es_MX","pt_BR"]),2:Object.freeze(["en_GB","es_ES","fr_FR","ru_RU","de_DE","pt_PT","it_IT"]),3:Object.freeze(["ko_KR","zh_TW"]),5:Object.freeze(["zh_CN"])}),regions=Object.freeze({1:Object.freeze(["us"]),2:Object.freeze(["eu"]),3:Object.freeze(["kr","tw"]),5:Object.freeze(["cn"])}),sc2Realms=Object.freeze({1:Object.freeze([1,2]),2:Object.freeze([1,2]),3:Object.freeze([1,2]),5:Object.freeze([1])}),hosts=Object.freeze({1:"https://us.api.blizzard.com",2:"https://eu.api.blizzard.com",3:["https://kr.api.blizzard.com","https://tw.api.blizzard.com/"],5:"https://gateway.battlenet.com.cn/"}),oAuthHosts=Object.freeze({1:"https://us.battle.net",2:"https://eu.battle.net",3:"https://apac.battle.net",5:"https://www.battlenet.com.cn"}),getRegionPropertyArray=e=>Object.freeze({1:`${oAuthHosts[1]}${e}`,2:`${oAuthHosts[2]}${e}`,3:`${oAuthHosts[3]}${e}`,5:`${oAuthHosts[5]}${e}`}),authorizeEndpoint="/oauth/authorize",tokenEndpoint="/oauth/token",checkTokenEndpoint="/oauth/check_token?token=",authorizeUris=getRegionPropertyArray(authorizeEndpoint),tokenUris=getRegionPropertyArray(tokenEndpoint),checkTokenUris=getRegionPropertyArray(checkTokenEndpoint),constants={REGIONS:regions,LOCALES:locales,DEFAULT_LOCALES:defaultLocales,SC2_REALMS:sc2Realms,REGION_API_HOSTS:hosts,OAUTH_AUTHORIZE_URIS:authorizeUris,OAUTH_TOKEN_URIS:tokenUris,OAUTH_CHECK_TOKEN_URIS:checkTokenUris},getAllRegions=()=>constants.REGIONS,getAllRegionIds=()=>Object.keys(constants.REGIONS).map(t=>parseInt(t,10)),getAllRegionNames=()=>{const e=Object.values(constants.REGIONS);return[].concat(...e).map(o=>o.toString())},getRegionNameById=e=>{const t=Object.keys(constants.REGIONS),o=e.toString();if(!t.includes(o))throw new RangeError(`${o} is not a valid parameter for getRegionNameById()`);return constants.REGIONS[o]},validateRegionId=e=>{try{return Boolean(getRegionNameById(e))}catch(t){return!1}},getRegionIdByName=e=>{const t=e.toLowerCase(),o=constants.REGIONS,n=Object.keys(o).filter(l=>o[l].includes(t)),c=Number(n[0])||!1;if(!c)throw new RangeError(`"${e}" is not a valid parameter for getRegionIdByName()`);return c},validateRegionName=e=>{try{return Boolean(getRegionIdByName(e))}catch(t){return!1}},getConstantByRegionId=(e,t)=>{const o=typeof e!="string"?e:e.toString();if(!validateRegionId(o))throw new RangeError(`${o} is not a valid parameter for getConstantByRegionId(${e}, '${t}')`);return constants[t][o]},getConstantByRegionName=(e,t)=>{if(!validateRegionName(e))throw new RangeError(`${e} is not a valid parameter for getConstantByRegionName(${e}, '${t}')`);const s=getRegionIdByName(e);return constants[t][s]},getConstantByRegion=(e,t)=>validateRegionId(e)?getConstantByRegionId(e,t):getConstantByRegionName(e.toString(),t),getAllLocales=()=>constants.LOCALES,getAllLocaleNames=()=>{const e=Object.values(constants.LOCALES);return[].concat(...e).map(s=>s.toString())},getLocalesByRegionId=e=>getConstantByRegionId(e,"LOCALES"),checkIfLocaleLooksValid=e=>/^(?:[a-z]{2}_[a-z]{2})$/gi.test(e),validateLocale=e=>{if(!checkIfLocaleLooksValid(e))throw new RangeError(`${e} is not a valid parameter for validateLocale()`);const o=getAllLocaleNames().map(n=>n.toLowerCase()),s=e.toLowerCase();return o.includes(s)},isLocaleValidForRegionId=(e,t)=>{const o=e.toLowerCase(),s=validateLocale(o)||!1,n=t.toString(),c=validateRegionId(n);if(!s)throw new RangeError(`${e} is not a valid locale parameter for isLocaleValidForRegionId()`);if(!c)throw new RangeError(`${t} is not a valid regionId parameter for isLocaleValidForRegionId()`);return getLocalesByRegionId(t).map(a=>a.toLowerCase()).includes(o)},getDefaultLocaleNameForRegionId=e=>{const t=e.toString();if(!validateRegionId(t))throw new RangeError(`${t} is not a valid parameter for getDefaultLocaleNameForRegionId()`);const s=constants.DEFAULT_LOCALES[t];return constants.LOCALES[e][s]},getAllDefaultLocaleNames=()=>{const e=getAllLocales(),t=Object.keys(e);return Object.assign({},...t.map(o=>({[o]:getDefaultLocaleNameForRegionId(o)})))},getAllSc2Realms=()=>constants.SC2_REALMS,getAllAvailableSc2Realms=()=>{const e=Object.values(constants.SC2_REALMS);return[].concat(...e).filter((o,s,n)=>s===n.indexOf(o))},getSc2RealmsByRegionId=e=>getConstantByRegionId(e,"SC2_REALMS"),checkIfSc2RealmLooksValid=e=>{const t=e.toString();return/^([1-9]{1})$/gi.test(t)},validateSc2Realm=e=>{if(!checkIfSc2RealmLooksValid(e))throw new RangeError(`${e} is not a valid parameter for validateSc2Realm()`);const o=getAllAvailableSc2Realms(),s=typeof e=="number"?e:parseInt(e,10);return o.includes(s)},isSc2RealmValidForRegionId=(e,t)=>{const o=checkIfSc2RealmLooksValid(e),s=t.toString(),n=validateRegionId(s);if(!o)throw new RangeError(`${e} is not a valid sc2Realm parameter for isSc2RealmValidForRegionId()`);if(!n)throw new RangeError(`${t} is not a valid regionId parameter for isSc2RealmValidForRegionId()`);const c=getSc2RealmsByRegionId(t),l=typeof e=="number"?e:parseInt(e,10);return c.includes(l)},getApiHostByRegion=e=>{const t=getConstantByRegion(e,"REGION_API_HOSTS");return typeof e=="string"&&e.toLowerCase()==="kr"?t[0]:typeof e=="string"&&e.toLowerCase()==="tw"?t[1]:t},getCheckTokenUriByRegion=e=>getConstantByRegion(e,"OAUTH_CHECK_TOKEN_URIS"),getTokenUriByRegion=e=>getConstantByRegion(e,"OAUTH_TOKEN_URIS");var __async$4=(e,t,o)=>new Promise((s,n)=>{var c=r=>{try{a(o.next(r))}catch(i){n(i)}},l=r=>{try{a(o.throw(r))}catch(i){n(i)}},a=r=>r.done?s(r.value):Promise.resolve(r.value).then(c,l);a((o=o.apply(e,t)).next())});const getAccessToken=e=>__async$4(this,null,function*(){const{region:t,clientId:o,clientSecret:s}=e,n=getTokenUriByRegion(t);return(yield fetchAccessToken({oauthUri:n,clientId:o,clientSecret:s})).access_token});var __async$3=(e,t,o)=>new Promise((s,n)=>{var c=r=>{try{a(o.next(r))}catch(i){n(i)}},l=r=>{try{a(o.throw(r))}catch(i){n(i)}},a=r=>r.done?s(r.value):Promise.resolve(r.value).then(c,l);a((o=o.apply(e,t)).next())});const validateAccessToken=(e,t)=>__async$3(this,null,function*(){try{const s=`${getCheckTokenUriByRegion(e)}${t}`,n=yield fetchFromUri({uri:s});return!(n.error&&n.error==="invalid_token")}catch(o){return!1}});var __defProp$1=Object.defineProperty,__getOwnPropSymbols$1=Object.getOwnPropertySymbols,__hasOwnProp$1=Object.prototype.hasOwnProperty,__propIsEnum$1=Object.prototype.propertyIsEnumerable,__defNormalProp$1=(e,t,o)=>t in e?__defProp$1(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,__spreadValues$1=(e,t)=>{for(var o in t||(t={}))__hasOwnProp$1.call(t,o)&&__defNormalProp$1(e,o,t[o]);if(__getOwnPropSymbols$1)for(var o of __getOwnPropSymbols$1(t))__propIsEnum$1.call(t,o)&&__defNormalProp$1(e,o,t[o]);return e},__async$2=(e,t,o)=>new Promise((s,n)=>{var c=r=>{try{a(o.next(r))}catch(i){n(i)}},l=r=>{try{a(o.throw(r))}catch(i){n(i)}},a=r=>r.done?s(r.value):Promise.resolve(r.value).then(c,l);a((o=o.apply(e,t)).next())});const queryWithAccessToken=(e,t)=>{const{region:o,endpoint:s,options:n}=e,{headers:c,params:l,timeout:a}=n;if(!endpointValidator(s))throw new RangeError(`${s} is not a valid endpoint.`);const d=`${getApiHostByRegion(o)}${s}`,u={Authorization:`Bearer ${t}`},f=__spreadValues$1(__spreadValues$1({},c),u);return fetchFromUri(__spreadValues$1(__spreadValues$1({uri:d,method:"GET",headers:f},l&&{params:l}),a&&{timeout:a}))},query=e=>__async$2(this,null,function*(){const{region:t,accessToken:o}=e,{validateAccessTokenOnEachQuery:s,refreshExpiredAccessToken:n,onAccessTokenExpired:c,onAccessTokenRefresh:l}=e.options;if(s&&!(yield validateAccessToken(t,o)))return{error:"access_token_invalid"};try{return yield queryWithAccessToken(e,o)}catch(a){if(a.response&&a.response.status===401){if(c==null||c(),n){const r=yield getAccessToken(e);return l==null||l(r),queryWithAccessToken(e,r)}return Promise.resolve({error:"access_token_invalid"})}throw a}});class OAuth2API{constructor(t,o){this.clientId=t,this.clientSecret=o}}var __async$1=(e,t,o)=>new Promise((s,n)=>{var c=r=>{try{a(o.next(r))}catch(i){n(i)}},l=r=>{try{a(o.throw(r))}catch(i){n(i)}},a=r=>r.done?s(r.value):Promise.resolve(r.value).then(c,l);a((o=o.apply(e,t)).next())});class BattleNetAPI extends OAuth2API{constructor(t){super(t.clientId,t.clientSecret);this.getAccessToken=()=>this.accessToken||this.setAccessToken(),this.setAccessToken=()=>__async$1(this,null,function*(){return this.accessToken=yield getAccessToken({region:this.region,clientId:this.clientId,clientSecret:this.clientSecret}),this.accessToken}),this.region=t.region,this.accessToken=t.accessToken||void 0}}BattleNetAPI.validateAccessToken=(e,t)=>validateAccessToken(e,t);var __defProp=Object.defineProperty,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(e,t,o)=>t in e?__defProp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,__spreadValues=(e,t)=>{for(var o in t||(t={}))__hasOwnProp.call(t,o)&&__defNormalProp(e,o,t[o]);if(__getOwnPropSymbols)for(var o of __getOwnPropSymbols(t))__propIsEnum.call(t,o)&&__defNormalProp(e,o,t[o]);return e},__async=(e,t,o)=>new Promise((s,n)=>{var c=r=>{try{a(o.next(r))}catch(i){n(i)}},l=r=>{try{a(o.throw(r))}catch(i){n(i)}},a=r=>r.done?s(r.value):Promise.resolve(r.value).then(c,l);a((o=o.apply(e,t)).next())});class BlizzAPI extends BattleNetAPI{constructor(t){super({region:t.region,clientId:t.clientId,clientSecret:t.clientSecret,accessToken:t.accessToken});this.query=(o,s)=>__async(this,null,function*(){return query({endpoint:o,region:this.region,clientId:this.clientId,clientSecret:this.clientSecret,accessToken:yield this.getAccessToken(),options:__spreadValues(__spreadValues({},this.options),s)})}),this.options={validateAccessTokenOnEachQuery:t.validateAccessTokenOnEachQuery||!1,refreshExpiredAccessToken:t.refreshExpiredAccessToken||!1,onAccessTokenExpired:t.onAccessTokenExpired||void 0,onAccessTokenRefresh:t.onAccessTokenRefresh||void 0}}}BlizzAPI.getAllRegions=getAllRegions,BlizzAPI.getAllRegionIds=getAllRegionIds,BlizzAPI.getAllRegionNames=getAllRegionNames,BlizzAPI.getRegionNameById=getRegionNameById,BlizzAPI.validateRegionId=validateRegionId,BlizzAPI.getRegionIdByName=getRegionIdByName,BlizzAPI.validateRegionName=validateRegionName,BlizzAPI.getAllLocales=getAllLocales,BlizzAPI.getAllLocaleNames=getAllLocaleNames,BlizzAPI.getLocalesByRegionId=getLocalesByRegionId,BlizzAPI.checkIfLocaleLooksValid=checkIfLocaleLooksValid,BlizzAPI.validateLocale=validateLocale,BlizzAPI.isLocaleValidForRegionId=isLocaleValidForRegionId,BlizzAPI.getAllSc2Realms=getAllSc2Realms,BlizzAPI.getAllAvailableSc2Realms=getAllAvailableSc2Realms,BlizzAPI.getSc2RealmsByRegionId=getSc2RealmsByRegionId,BlizzAPI.checkIfSc2RealmLooksValid=checkIfSc2RealmLooksValid,BlizzAPI.validateSc2Realm=validateSc2Realm,BlizzAPI.isSc2RealmValidForRegionId=isSc2RealmValidForRegionId,BlizzAPI.getDefaultLocaleNameForRegionId=getDefaultLocaleNameForRegionId,BlizzAPI.getAllDefaultLocaleNames=getAllDefaultLocaleNames,exports.BlizzAPI=BlizzAPI; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var ie=require("axios");function le(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var ue=le(ie),h=(e=>(e.REGIONS="REGIONS",e.LOCALES="LOCALES",e.DEFAULT_LOCALES="DEFAULT_LOCALES",e.REGION_API_HOSTS="REGION_API_HOSTS",e.SC2_REALMS="SC2_REALMS",e.OAUTH_AUTHORIZE_URIS="OAUTH_AUTHORIZE_URIS",e.OAUTH_TOKEN_URIS="OAUTH_TOKEN_URIS",e.OAUTH_CHECK_TOKEN_URIS="OAUTH_CHECK_TOKEN_URIS",e))(h||{}),_=(e=>(e.us="us",e.eu="eu",e.kr="kr",e.tw="tw",e.cn="cn",e))(_||{}),a=(e=>(e[e.us=1]="us",e[e.eu=2]="eu",e[e.kr=3]="kr",e[e.tw=3]="tw",e[e.cn=5]="cn",e))(a||{}),j=(e=>(e.us="1",e.eu="2",e.kr="3",e.tw="3",e.cn="5",e))(j||{}),f=(e=>(e.en_US="en_US",e.es_MX="es_MX",e.pt_BR="pt_BR",e.en_GB="en_GB",e.es_ES="es_ES",e.fr_FR="fr_FR",e.ru_RU="ru_RU",e.de_DE="de_DE",e.pt_PT="pt_PT",e.it_IT="it_IT",e.ko_KR="ko_KR",e.zh_TW="zh_TW",e.zh_CN="zh_CN",e))(f||{}),k=(e=>(e[e.us=0]="us",e[e.eu=0]="eu",e[e.kr=0]="kr",e[e.tw=0]="tw",e[e.cn=0]="cn",e))(k||{}),v=(e=>(e[e.US=1]="US",e[e.LatAm=2]="LatAm",e[e.Europe=1]="Europe",e[e.Russia=2]="Russia",e[e.Korea=1]="Korea",e[e.Taiwan=2]="Taiwan",e[e.China=1]="China",e))(v||{}),V=(e=>(e.US="1",e.LatAm="2",e.Europe="1",e.Russia="2",e.Korea="1",e.Taiwan="2",e.China="1",e))(V||{}),O=(e=>(e.GET="GET",e.POST="POST",e))(O||{}),A=(e=>(e.us="https://us.battle.net",e.eu="https://eu.battle.net",e.kr="https://apac.battle.net",e.tw="https://apac.battle.net",e.cn="https://www.battlenet.com.cn",e))(A||{}),g=(e=>(e.us="https://us.api.blizzard.com",e.eu="https://eu.api.blizzard.com",e.kr="https://kr.api.blizzard.com",e.tw="https://tw.api.blizzard.com",e.cn="https://gateway.battlenet.com.cn",e))(g||{}),y=(e=>(e.authorize="/oauth/authorize",e.token="/oauth/token",e.checkToken="/oauth/check_token?token=",e))(y||{}),E=(e=>(e.LastModified="last-modified",e))(E||{}),b=(e=>(e[e.NotAuthorized=401]="NotAuthorized",e))(b||{}),S=(e=>(e.InvalidToken="invalid_token",e.AccessTokenInvalid="access_token_invalid",e.AccessTokenExpired="access_token_invalid",e))(S||{});const de=e=>e[0]==="/",he=e=>e.length>3,fe=[de,he],_e=e=>fe.every(t=>t(e)),ve=e=>/(?:http[s]?:\/\/)[^\s(["<,>]*\.[^\s[",><]*/gm.test(e);var pe=Object.defineProperty,B=Object.getOwnPropertySymbols,ge=Object.prototype.hasOwnProperty,Re=Object.prototype.propertyIsEnumerable,H=(e,t,r)=>t in e?pe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,T=(e,t)=>{for(var r in t||(t={}))ge.call(t,r)&&H(e,r,t[r]);if(B)for(var r of B(t))Re.call(t,r)&&H(e,r,t[r]);return e},ke=(e,t,r)=>new Promise((o,n)=>{var l=s=>{try{c(r.next(s))}catch(i){n(i)}},u=s=>{try{c(r.throw(s))}catch(i){n(i)}},c=s=>s.done?o(s.value):Promise.resolve(s.value).then(l,u);c((r=r.apply(e,t)).next())});const P=e=>ke(exports,null,function*(){const{uri:t,timeout:r,headers:o,params:n,data:l,auth:u}=e,c=e.method||O.GET;if(!ve(t))throw new RangeError(`'${t}' is not a valid parameter for fetchFromUri()`);const s=T(T(T(T({method:c,url:encodeURI(t),timeout:r||1e4},o&&{headers:o}),n&&{params:n}),u&&{auth:u}),l&&{data:l}),i=yield ue.default.request(s),w=i.headers[E.LastModified]?i.headers[E.LastModified]:null;return T(T({},i.data),w&&{lastModified:w})}),Ae=e=>{const{oauthUri:t,clientId:r,clientSecret:o}=e;return P({data:"grant_type=client_credentials",auth:{username:r,password:o},uri:t,method:O.POST})},Te=Object.freeze({[a.us]:k.us,[a.eu]:k.eu,[a.kr]:k.kr,[a.cn]:k.cn}),me=Object.freeze({[a.us]:Object.freeze([f.en_US,f.es_MX,f.pt_BR]),[a.eu]:Object.freeze([f.en_GB,f.es_ES,f.fr_FR,f.ru_RU,f.de_DE,f.pt_PT,f.it_IT]),[a.kr]:Object.freeze([f.ko_KR,f.zh_TW]),[a.cn]:Object.freeze([f.zh_CN])}),Oe=Object.freeze({[a.us]:Object.freeze([_.us]),[a.eu]:Object.freeze([_.eu]),[a.kr]:Object.freeze([_.kr,_.tw]),[a.cn]:Object.freeze([_.cn])}),ye=Object.freeze({[a.us]:Object.freeze([v.US,v.LatAm]),[a.eu]:Object.freeze([v.Europe,v.Russia]),[a.kr]:Object.freeze([v.Korea,v.Taiwan]),[a.cn]:Object.freeze([v.China])}),Se=Object.freeze({[a.us]:g.us,[a.eu]:g.eu,[a.kr]:[g.kr,g.tw],[a.cn]:g.cn}),L=Object.freeze({[a.us]:A.us,[a.eu]:A.eu,[a.kr]:A.kr,[a.cn]:A.cn}),U=e=>Object.freeze({[a.us]:`${L[a.us]}${e}`,[a.eu]:`${L[a.eu]}${e}`,[a.kr]:`${L[a.kr]}${e}`,[a.cn]:`${L[a.cn]}${e}`}),we=U(y.authorize),Ee=U(y.token),Le=U(y.checkToken),p={[h.REGIONS]:Oe,[h.LOCALES]:me,[h.DEFAULT_LOCALES]:Te,[h.SC2_REALMS]:ye,[h.REGION_API_HOSTS]:Se,[h.OAUTH_AUTHORIZE_URIS]:we,[h.OAUTH_TOKEN_URIS]:Ee,[h.OAUTH_CHECK_TOKEN_URIS]:Le},R=p[h.REGIONS],Ie=()=>R,be=()=>Object.keys(R).map(t=>parseInt(t,10)),Pe=()=>{const e=Object.values(R);return[].concat(...e).map(r=>r.toString())},F=e=>{const t=Object.keys(R),r=e.toString();if(!t.includes(r))throw new RangeError(`${r} is not a valid parameter for getRegionNameById()`);return R[r]},m=e=>{try{return Boolean(F(e))}catch{return!1}},$=e=>{const t=e.toLowerCase(),o=Object.keys(R).filter(l=>R[l].includes(t)),n=Number(o[0])||!1;if(!n)throw new RangeError(`"${e}" is not a valid parameter for getRegionIdByName()`);return n},G=e=>{try{return Boolean($(e))}catch{return!1}},z=(e,t)=>{const r=typeof e=="string"?e:e.toString();if(!m(r))throw new RangeError(`${r} is not a valid parameter for getConstantByRegionId(${e}, '${t}')`);return p[t][e]},Ue=(e,t)=>{if(!G(e))throw new RangeError(`${e} is not a valid parameter for getConstantByRegionName(${e}, '${t}')`);const o=$(e);return p[t][o]},N=(e,t)=>m(e)?z(e,t):Ue(e.toString(),t),$e=p[h.LOCALES],K=()=>$e,M=()=>Object.keys(f).filter(r=>Number.isNaN(Number(r))).map(r=>r.toString()),x=e=>z(e,h.LOCALES),D=e=>/^(?:[a-z]{2}_[a-z]{2})$/gi.test(e),W=e=>{if(!D(e))throw new RangeError(`${e} is not a valid parameter for validateLocale()`);const r=M().map(n=>n.toLowerCase()),o=e.toLowerCase();return r.includes(o)},ze=(e,t)=>{const r=e.toLowerCase(),o=W(r)||!1,n=t.toString(),l=m(n);if(!o)throw new RangeError(`${e} is not a valid locale parameter for isLocaleValidForRegionId()`);if(!l)throw new RangeError(`${t} is not a valid regionId parameter for isLocaleValidForRegionId()`);return x(t).map(c=>c.toLowerCase()).includes(r)},Ne=p[h.DEFAULT_LOCALES],Ce=p[h.LOCALES],q=e=>{const t=e.toString();if(!m(t))throw new RangeError(`${t} is not a valid parameter for getDefaultLocaleNameForRegionId()`);const o=Ne[t];return Ce[e][o]},je=()=>{const e=K(),t=Object.keys(e);return Object.assign({},...t.map(r=>({[r]:q(r)})))},Ve=()=>p.SC2_REALMS,Q=()=>{const e=Object.values(p.SC2_REALMS);return[].concat(...e).filter((r,o,n)=>o===n.indexOf(r))},X=e=>z(e,h.SC2_REALMS),C=e=>{const t=e.toString();return/^([1-9]{1})$/gi.test(t)},Be=e=>{if(!C(e))throw new RangeError(`${e} is not a valid parameter for validateSc2Realm()`);const r=Q(),o=typeof e=="number"?e:parseInt(e,10);return r.includes(o)},He=(e,t)=>{const r=C(e),o=t.toString(),n=m(o);if(!r)throw new RangeError(`${e} is not a valid sc2Realm parameter for isSc2RealmValidForRegionId()`);if(!n)throw new RangeError(`${t} is not a valid regionId parameter for isSc2RealmValidForRegionId()`);const l=X(t),u=typeof e=="number"?e:parseInt(e,10);return l.includes(u)},Fe=e=>{const t=N(e,h.REGION_API_HOSTS);return typeof e=="string"&&e.toLowerCase()===_.kr?t[0]:typeof e=="string"&&e.toLowerCase()===_.tw?t[1]:t},Ge=e=>N(e,h.OAUTH_CHECK_TOKEN_URIS),Ke=e=>N(e,h.OAUTH_TOKEN_URIS);var Me=(e,t,r)=>new Promise((o,n)=>{var l=s=>{try{c(r.next(s))}catch(i){n(i)}},u=s=>{try{c(r.throw(s))}catch(i){n(i)}},c=s=>s.done?o(s.value):Promise.resolve(s.value).then(l,u);c((r=r.apply(e,t)).next())});const Z=e=>Me(exports,null,function*(){const{region:t,clientId:r,clientSecret:o}=e,n=Ke(t);return(yield Ae({oauthUri:n,clientId:r,clientSecret:o})).access_token});var xe=(e,t,r)=>new Promise((o,n)=>{var l=s=>{try{c(r.next(s))}catch(i){n(i)}},u=s=>{try{c(r.throw(s))}catch(i){n(i)}},c=s=>s.done?o(s.value):Promise.resolve(s.value).then(l,u);c((r=r.apply(e,t)).next())});const J=(e,t)=>xe(exports,null,function*(){try{const o=`${Ge(e)}${t}`;return(yield P({uri:o})).error!==S.InvalidToken}catch{return!1}});var De=Object.defineProperty,Y=Object.getOwnPropertySymbols,We=Object.prototype.hasOwnProperty,qe=Object.prototype.propertyIsEnumerable,ee=(e,t,r)=>t in e?De(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,I=(e,t)=>{for(var r in t||(t={}))We.call(t,r)&&ee(e,r,t[r]);if(Y)for(var r of Y(t))qe.call(t,r)&&ee(e,r,t[r]);return e},Qe=(e,t,r)=>new Promise((o,n)=>{var l=s=>{try{c(r.next(s))}catch(i){n(i)}},u=s=>{try{c(r.throw(s))}catch(i){n(i)}},c=s=>s.done?o(s.value):Promise.resolve(s.value).then(l,u);c((r=r.apply(e,t)).next())});const te=(e,t)=>{const{region:r,endpoint:o,options:n}=e,{headers:l,params:u,timeout:c}=n;if(!_e(o))throw new RangeError(`${o} is not a valid endpoint.`);const w=`${Fe(r)}${o}`,ae={Authorization:`Bearer ${t}`},ce=I(I({},l),ae);return P(I(I({uri:w,method:O.GET,headers:ce},u&&{params:u}),c&&{timeout:c}))},Xe=e=>Qe(exports,null,function*(){var t;const{region:r,accessToken:o}=e,{validateAccessTokenOnEachQuery:n,refreshExpiredAccessToken:l,onAccessTokenExpired:u,onAccessTokenRefresh:c}=e.options;if(n&&!(yield J(r,o)))return{error:S.AccessTokenInvalid};try{return yield te(e,o)}catch(s){if(((t=s.response)==null?void 0:t.status)===b.NotAuthorized){if(u==null||u(),l){const i=yield Z(e);return c==null||c(i),te(e,i)}return Promise.resolve({error:S.AccessTokenExpired})}throw s}});class Ze{constructor(t,r){this.clientId=t,this.clientSecret=r}}var Je=(e,t,r)=>new Promise((o,n)=>{var l=s=>{try{c(r.next(s))}catch(i){n(i)}},u=s=>{try{c(r.throw(s))}catch(i){n(i)}},c=s=>s.done?o(s.value):Promise.resolve(s.value).then(l,u);c((r=r.apply(e,t)).next())});class re extends Ze{constructor(t){super(t.clientId,t.clientSecret);this.getAccessToken=()=>this.accessToken||this.setAccessToken(),this.setAccessToken=()=>Je(this,null,function*(){return this.accessToken=yield Z({region:this.region,clientId:this.clientId,clientSecret:this.clientSecret}),this.accessToken}),this.region=t.region,this.accessToken=t.accessToken||void 0}}re.validateAccessToken=(e,t)=>J(e,t);var Ye=Object.defineProperty,se=Object.getOwnPropertySymbols,et=Object.prototype.hasOwnProperty,tt=Object.prototype.propertyIsEnumerable,oe=(e,t,r)=>t in e?Ye(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,ne=(e,t)=>{for(var r in t||(t={}))et.call(t,r)&&oe(e,r,t[r]);if(se)for(var r of se(t))tt.call(t,r)&&oe(e,r,t[r]);return e},rt=(e,t,r)=>new Promise((o,n)=>{var l=s=>{try{c(r.next(s))}catch(i){n(i)}},u=s=>{try{c(r.throw(s))}catch(i){n(i)}},c=s=>s.done?o(s.value):Promise.resolve(s.value).then(l,u);c((r=r.apply(e,t)).next())});class d extends re{constructor(t){super({region:t.region,clientId:t.clientId,clientSecret:t.clientSecret,accessToken:t.accessToken});this.query=(r,o)=>rt(this,null,function*(){return Xe({endpoint:r,region:this.region,clientId:this.clientId,clientSecret:this.clientSecret,accessToken:yield this.getAccessToken(),options:ne(ne({},this.options),o)})}),this.options={validateAccessTokenOnEachQuery:t.validateAccessTokenOnEachQuery||!1,refreshExpiredAccessToken:t.refreshExpiredAccessToken||!1,onAccessTokenExpired:t.onAccessTokenExpired||void 0,onAccessTokenRefresh:t.onAccessTokenRefresh||void 0}}}d.getAllRegions=Ie,d.getAllRegionIds=be,d.getAllRegionNames=Pe,d.getRegionNameById=F,d.validateRegionId=m,d.getRegionIdByName=$,d.validateRegionName=G,d.getAllLocales=K,d.getAllLocaleNames=M,d.getLocalesByRegionId=x,d.checkIfLocaleLooksValid=D,d.validateLocale=W,d.isLocaleValidForRegionId=ze,d.getAllSc2Realms=Ve,d.getAllAvailableSc2Realms=Q,d.getSc2RealmsByRegionId=X,d.checkIfSc2RealmLooksValid=C,d.validateSc2Realm=Be,d.isSc2RealmValidForRegionId=He,d.getDefaultLocaleNameForRegionId=q,d.getAllDefaultLocaleNames=je,exports.ApiHeaders=E,exports.BlizzAPI=d,exports.ConstantKey=h,exports.DefaultLocaleIndex=k,exports.ErrorCode=b,exports.ErrorResponseMessage=S,exports.HttpMethod=O,exports.Locale=f,exports.OAuthEndpoint=y,exports.OAuthHost=A,exports.RegionHost=g,exports.RegionId=a,exports.RegionIdAsString=j,exports.RegionName=_,exports.Sc2Realm=v,exports.Sc2RealmAsString=V; |
@@ -1,1 +0,1 @@ | ||
(function(f,p){typeof exports=="object"&&typeof module!="undefined"?p(exports,require("axios")):typeof define=="function"&&define.amd?define(["exports","axios"],p):(f=typeof globalThis!="undefined"?globalThis:f||self,p(f.BlizzAPI={},f.axios))})(this,function(f,p){"use strict";function M(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var q=M(p);const W=[e=>e[0]==="/",e=>e.length>3],Q=e=>W.every(t=>t(e)),X=e=>/(?:http[s]?:\/\/)[^\s(["<,>]*\.[^\s[",><]*/gm.test(e);var Z=Object.defineProperty,O=Object.getOwnPropertySymbols,J=Object.prototype.hasOwnProperty,Y=Object.prototype.propertyIsEnumerable,k=(e,t,o)=>t in e?Z(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,g=(e,t)=>{for(var o in t||(t={}))J.call(t,o)&&k(e,o,t[o]);if(O)for(var o of O(t))Y.call(t,o)&&k(e,o,t[o]);return e},ee=(e,t,o)=>new Promise((s,r)=>{var c=n=>{try{a(o.next(n))}catch(i){r(i)}},l=n=>{try{a(o.throw(n))}catch(i){r(i)}},a=n=>n.done?s(n.value):Promise.resolve(n.value).then(c,l);a((o=o.apply(e,t)).next())});const _=e=>ee(this,null,function*(){const{uri:t,timeout:o,headers:s,params:r,data:c,auth:l}=e,a=e.method||"GET";if(!X(t))throw new RangeError(`'${t}' is not a valid parameter for fetchFromUri()`);const n=g(g(g(g({method:a,url:encodeURI(t),timeout:o||1e4},s&&{headers:s}),r&&{params:r}),l&&{auth:l}),c&&{data:c}),i=yield q.default.request(n),v=i.headers["last-modified"]?i.headers["last-modified"]:null;return g(g({},i.data),v&&{lastModified:v})}),te=e=>{const{oauthUri:t,clientId:o,clientSecret:s}=e;return _({data:"grant_type=client_credentials",auth:{username:o,password:s},uri:t,method:"POST"})},oe=Object.freeze({1:0,2:0,3:0,5:0}),ne=Object.freeze({1:Object.freeze(["en_US","es_MX","pt_BR"]),2:Object.freeze(["en_GB","es_ES","fr_FR","ru_RU","de_DE","pt_PT","it_IT"]),3:Object.freeze(["ko_KR","zh_TW"]),5:Object.freeze(["zh_CN"])}),se=Object.freeze({1:Object.freeze(["us"]),2:Object.freeze(["eu"]),3:Object.freeze(["kr","tw"]),5:Object.freeze(["cn"])}),re=Object.freeze({1:Object.freeze([1,2]),2:Object.freeze([1,2]),3:Object.freeze([1,2]),5:Object.freeze([1])}),ae=Object.freeze({1:"https://us.api.blizzard.com",2:"https://eu.api.blizzard.com",3:["https://kr.api.blizzard.com","https://tw.api.blizzard.com/"],5:"https://gateway.battlenet.com.cn/"}),R=Object.freeze({1:"https://us.battle.net",2:"https://eu.battle.net",3:"https://apac.battle.net",5:"https://www.battlenet.com.cn"}),y=e=>Object.freeze({1:`${R[1]}${e}`,2:`${R[2]}${e}`,3:`${R[3]}${e}`,5:`${R[5]}${e}`}),ce="/oauth/authorize",ie="/oauth/token",le="/oauth/check_token?token=",de=y(ce),ue=y(ie),fe=y(le),u={REGIONS:se,LOCALES:ne,DEFAULT_LOCALES:oe,SC2_REALMS:re,REGION_API_HOSTS:ae,OAUTH_AUTHORIZE_URIS:de,OAUTH_TOKEN_URIS:ue,OAUTH_CHECK_TOKEN_URIS:fe},ge=()=>u.REGIONS,he=()=>Object.keys(u.REGIONS).map(t=>parseInt(t,10)),pe=()=>{const e=Object.values(u.REGIONS);return[].concat(...e).map(o=>o.toString())},w=e=>{const t=Object.keys(u.REGIONS),o=e.toString();if(!t.includes(o))throw new RangeError(`${o} is not a valid parameter for getRegionNameById()`);return u.REGIONS[o]},h=e=>{try{return Boolean(w(e))}catch(t){return!1}},S=e=>{const t=e.toLowerCase(),o=u.REGIONS,r=Object.keys(o).filter(l=>o[l].includes(t)),c=Number(r[0])||!1;if(!c)throw new RangeError(`"${e}" is not a valid parameter for getRegionIdByName()`);return c},E=e=>{try{return Boolean(S(e))}catch(t){return!1}},A=(e,t)=>{const o=typeof e!="string"?e:e.toString();if(!h(o))throw new RangeError(`${o} is not a valid parameter for getConstantByRegionId(${e}, '${t}')`);return u[t][o]},Re=(e,t)=>{if(!E(e))throw new RangeError(`${e} is not a valid parameter for getConstantByRegionName(${e}, '${t}')`);const s=S(e);return u[t][s]},I=(e,t)=>h(e)?A(e,t):Re(e.toString(),t),T=()=>u.LOCALES,b=()=>{const e=Object.values(u.LOCALES);return[].concat(...e).map(s=>s.toString())},P=e=>A(e,"LOCALES"),$=e=>/^(?:[a-z]{2}_[a-z]{2})$/gi.test(e),z=e=>{if(!$(e))throw new RangeError(`${e} is not a valid parameter for validateLocale()`);const o=b().map(r=>r.toLowerCase()),s=e.toLowerCase();return o.includes(s)},me=(e,t)=>{const o=e.toLowerCase(),s=z(o)||!1,r=t.toString(),c=h(r);if(!s)throw new RangeError(`${e} is not a valid locale parameter for isLocaleValidForRegionId()`);if(!c)throw new RangeError(`${t} is not a valid regionId parameter for isLocaleValidForRegionId()`);return P(t).map(a=>a.toLowerCase()).includes(o)},j=e=>{const t=e.toString();if(!h(t))throw new RangeError(`${t} is not a valid parameter for getDefaultLocaleNameForRegionId()`);const s=u.DEFAULT_LOCALES[t];return u.LOCALES[e][s]},ve=()=>{const e=T(),t=Object.keys(e);return Object.assign({},...t.map(o=>({[o]:j(o)})))},_e=()=>u.SC2_REALMS,V=()=>{const e=Object.values(u.SC2_REALMS);return[].concat(...e).filter((o,s,r)=>s===r.indexOf(o))},N=e=>A(e,"SC2_REALMS"),L=e=>{const t=e.toString();return/^([1-9]{1})$/gi.test(t)},ye=e=>{if(!L(e))throw new RangeError(`${e} is not a valid parameter for validateSc2Realm()`);const o=V(),s=typeof e=="number"?e:parseInt(e,10);return o.includes(s)},Se=(e,t)=>{const o=L(e),s=t.toString(),r=h(s);if(!o)throw new RangeError(`${e} is not a valid sc2Realm parameter for isSc2RealmValidForRegionId()`);if(!r)throw new RangeError(`${t} is not a valid regionId parameter for isSc2RealmValidForRegionId()`);const c=N(t),l=typeof e=="number"?e:parseInt(e,10);return c.includes(l)},Ae=e=>{const t=I(e,"REGION_API_HOSTS");return typeof e=="string"&&e.toLowerCase()==="kr"?t[0]:typeof e=="string"&&e.toLowerCase()==="tw"?t[1]:t},Ie=e=>I(e,"OAUTH_CHECK_TOKEN_URIS"),Le=e=>I(e,"OAUTH_TOKEN_URIS");var Oe=(e,t,o)=>new Promise((s,r)=>{var c=n=>{try{a(o.next(n))}catch(i){r(i)}},l=n=>{try{a(o.throw(n))}catch(i){r(i)}},a=n=>n.done?s(n.value):Promise.resolve(n.value).then(c,l);a((o=o.apply(e,t)).next())});const C=e=>Oe(this,null,function*(){const{region:t,clientId:o,clientSecret:s}=e,r=Le(t);return(yield te({oauthUri:r,clientId:o,clientSecret:s})).access_token});var ke=(e,t,o)=>new Promise((s,r)=>{var c=n=>{try{a(o.next(n))}catch(i){r(i)}},l=n=>{try{a(o.throw(n))}catch(i){r(i)}},a=n=>n.done?s(n.value):Promise.resolve(n.value).then(c,l);a((o=o.apply(e,t)).next())});const U=(e,t)=>ke(this,null,function*(){try{const s=`${Ie(e)}${t}`,r=yield _({uri:s});return!(r.error&&r.error==="invalid_token")}catch(o){return!1}});var we=Object.defineProperty,B=Object.getOwnPropertySymbols,Ee=Object.prototype.hasOwnProperty,Te=Object.prototype.propertyIsEnumerable,x=(e,t,o)=>t in e?we(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,m=(e,t)=>{for(var o in t||(t={}))Ee.call(t,o)&&x(e,o,t[o]);if(B)for(var o of B(t))Te.call(t,o)&&x(e,o,t[o]);return e},be=(e,t,o)=>new Promise((s,r)=>{var c=n=>{try{a(o.next(n))}catch(i){r(i)}},l=n=>{try{a(o.throw(n))}catch(i){r(i)}},a=n=>n.done?s(n.value):Promise.resolve(n.value).then(c,l);a((o=o.apply(e,t)).next())});const F=(e,t)=>{const{region:o,endpoint:s,options:r}=e,{headers:c,params:l,timeout:a}=r;if(!Q(s))throw new RangeError(`${s} is not a valid endpoint.`);const v=`${Ae(o)}${s}`,Ue={Authorization:`Bearer ${t}`},Be=m(m({},c),Ue);return _(m(m({uri:v,method:"GET",headers:Be},l&&{params:l}),a&&{timeout:a}))},Pe=e=>be(this,null,function*(){const{region:t,accessToken:o}=e,{validateAccessTokenOnEachQuery:s,refreshExpiredAccessToken:r,onAccessTokenExpired:c,onAccessTokenRefresh:l}=e.options;if(s&&!(yield U(t,o)))return{error:"access_token_invalid"};try{return yield F(e,o)}catch(a){if(a.response&&a.response.status===401){if(c==null||c(),r){const n=yield C(e);return l==null||l(n),F(e,n)}return Promise.resolve({error:"access_token_invalid"})}throw a}});class $e{constructor(t,o){this.clientId=t,this.clientSecret=o}}var ze=(e,t,o)=>new Promise((s,r)=>{var c=n=>{try{a(o.next(n))}catch(i){r(i)}},l=n=>{try{a(o.throw(n))}catch(i){r(i)}},a=n=>n.done?s(n.value):Promise.resolve(n.value).then(c,l);a((o=o.apply(e,t)).next())});class H extends $e{constructor(t){super(t.clientId,t.clientSecret);this.getAccessToken=()=>this.accessToken||this.setAccessToken(),this.setAccessToken=()=>ze(this,null,function*(){return this.accessToken=yield C({region:this.region,clientId:this.clientId,clientSecret:this.clientSecret}),this.accessToken}),this.region=t.region,this.accessToken=t.accessToken||void 0}}H.validateAccessToken=(e,t)=>U(e,t);var je=Object.defineProperty,G=Object.getOwnPropertySymbols,Ve=Object.prototype.hasOwnProperty,Ne=Object.prototype.propertyIsEnumerable,D=(e,t,o)=>t in e?je(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,K=(e,t)=>{for(var o in t||(t={}))Ve.call(t,o)&&D(e,o,t[o]);if(G)for(var o of G(t))Ne.call(t,o)&&D(e,o,t[o]);return e},Ce=(e,t,o)=>new Promise((s,r)=>{var c=n=>{try{a(o.next(n))}catch(i){r(i)}},l=n=>{try{a(o.throw(n))}catch(i){r(i)}},a=n=>n.done?s(n.value):Promise.resolve(n.value).then(c,l);a((o=o.apply(e,t)).next())});class d extends H{constructor(t){super({region:t.region,clientId:t.clientId,clientSecret:t.clientSecret,accessToken:t.accessToken});this.query=(o,s)=>Ce(this,null,function*(){return Pe({endpoint:o,region:this.region,clientId:this.clientId,clientSecret:this.clientSecret,accessToken:yield this.getAccessToken(),options:K(K({},this.options),s)})}),this.options={validateAccessTokenOnEachQuery:t.validateAccessTokenOnEachQuery||!1,refreshExpiredAccessToken:t.refreshExpiredAccessToken||!1,onAccessTokenExpired:t.onAccessTokenExpired||void 0,onAccessTokenRefresh:t.onAccessTokenRefresh||void 0}}}d.getAllRegions=ge,d.getAllRegionIds=he,d.getAllRegionNames=pe,d.getRegionNameById=w,d.validateRegionId=h,d.getRegionIdByName=S,d.validateRegionName=E,d.getAllLocales=T,d.getAllLocaleNames=b,d.getLocalesByRegionId=P,d.checkIfLocaleLooksValid=$,d.validateLocale=z,d.isLocaleValidForRegionId=me,d.getAllSc2Realms=_e,d.getAllAvailableSc2Realms=V,d.getSc2RealmsByRegionId=N,d.checkIfSc2RealmLooksValid=L,d.validateSc2Realm=ye,d.isSc2RealmValidForRegionId=Se,d.getDefaultLocaleNameForRegionId=j,d.getAllDefaultLocaleNames=ve,f.BlizzAPI=d,Object.defineProperty(f,"__esModule",{value:!0})}); | ||
(function(d,y){typeof exports=="object"&&typeof module!="undefined"?y(exports,require("axios")):typeof define=="function"&&define.amd?define(["exports","axios"],y):(d=typeof globalThis!="undefined"?globalThis:d||self,y(d.BlizzAPI={},d.axios))})(this,function(d,y){"use strict";function ie(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var le=ie(y),h=(e=>(e.REGIONS="REGIONS",e.LOCALES="LOCALES",e.DEFAULT_LOCALES="DEFAULT_LOCALES",e.REGION_API_HOSTS="REGION_API_HOSTS",e.SC2_REALMS="SC2_REALMS",e.OAUTH_AUTHORIZE_URIS="OAUTH_AUTHORIZE_URIS",e.OAUTH_TOKEN_URIS="OAUTH_TOKEN_URIS",e.OAUTH_CHECK_TOKEN_URIS="OAUTH_CHECK_TOKEN_URIS",e))(h||{}),v=(e=>(e.us="us",e.eu="eu",e.kr="kr",e.tw="tw",e.cn="cn",e))(v||{}),a=(e=>(e[e.us=1]="us",e[e.eu=2]="eu",e[e.kr=3]="kr",e[e.tw=3]="tw",e[e.cn=5]="cn",e))(a||{}),B=(e=>(e.us="1",e.eu="2",e.kr="3",e.tw="3",e.cn="5",e))(B||{}),_=(e=>(e.en_US="en_US",e.es_MX="es_MX",e.pt_BR="pt_BR",e.en_GB="en_GB",e.es_ES="es_ES",e.fr_FR="fr_FR",e.ru_RU="ru_RU",e.de_DE="de_DE",e.pt_PT="pt_PT",e.it_IT="it_IT",e.ko_KR="ko_KR",e.zh_TW="zh_TW",e.zh_CN="zh_CN",e))(_||{}),T=(e=>(e[e.us=0]="us",e[e.eu=0]="eu",e[e.kr=0]="kr",e[e.tw=0]="tw",e[e.cn=0]="cn",e))(T||{}),p=(e=>(e[e.US=1]="US",e[e.LatAm=2]="LatAm",e[e.Europe=1]="Europe",e[e.Russia=2]="Russia",e[e.Korea=1]="Korea",e[e.Taiwan=2]="Taiwan",e[e.China=1]="China",e))(p||{}),H=(e=>(e.US="1",e.LatAm="2",e.Europe="1",e.Russia="2",e.Korea="1",e.Taiwan="2",e.China="1",e))(H||{}),S=(e=>(e.GET="GET",e.POST="POST",e))(S||{}),m=(e=>(e.us="https://us.battle.net",e.eu="https://eu.battle.net",e.kr="https://apac.battle.net",e.tw="https://apac.battle.net",e.cn="https://www.battlenet.com.cn",e))(m||{}),R=(e=>(e.us="https://us.api.blizzard.com",e.eu="https://eu.api.blizzard.com",e.kr="https://kr.api.blizzard.com",e.tw="https://tw.api.blizzard.com",e.cn="https://gateway.battlenet.com.cn",e))(R||{}),E=(e=>(e.authorize="/oauth/authorize",e.token="/oauth/token",e.checkToken="/oauth/check_token?token=",e))(E||{}),L=(e=>(e.LastModified="last-modified",e))(L||{}),U=(e=>(e[e.NotAuthorized=401]="NotAuthorized",e))(U||{}),w=(e=>(e.InvalidToken="invalid_token",e.AccessTokenInvalid="access_token_invalid",e.AccessTokenExpired="access_token_invalid",e))(w||{});const ue=[e=>e[0]==="/",e=>e.length>3],de=e=>ue.every(t=>t(e)),fe=e=>/(?:http[s]?:\/\/)[^\s(["<,>]*\.[^\s[",><]*/gm.test(e);var he=Object.defineProperty,F=Object.getOwnPropertySymbols,_e=Object.prototype.hasOwnProperty,ve=Object.prototype.propertyIsEnumerable,G=(e,t,r)=>t in e?he(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,A=(e,t)=>{for(var r in t||(t={}))_e.call(t,r)&&G(e,r,t[r]);if(F)for(var r of F(t))ve.call(t,r)&&G(e,r,t[r]);return e},pe=(e,t,r)=>new Promise((s,o)=>{var l=n=>{try{c(r.next(n))}catch(i){o(i)}},u=n=>{try{c(r.throw(n))}catch(i){o(i)}},c=n=>n.done?s(n.value):Promise.resolve(n.value).then(l,u);c((r=r.apply(e,t)).next())});const $=e=>pe(this,null,function*(){const{uri:t,timeout:r,headers:s,params:o,data:l,auth:u}=e,c=e.method||S.GET;if(!fe(t))throw new RangeError(`'${t}' is not a valid parameter for fetchFromUri()`);const n=A(A(A(A({method:c,url:encodeURI(t),timeout:r||1e4},s&&{headers:s}),o&&{params:o}),u&&{auth:u}),l&&{data:l}),i=yield le.default.request(n),P=i.headers[L.LastModified]?i.headers[L.LastModified]:null;return A(A({},i.data),P&&{lastModified:P})}),ge=e=>{const{oauthUri:t,clientId:r,clientSecret:s}=e;return $({data:"grant_type=client_credentials",auth:{username:r,password:s},uri:t,method:S.POST})},Re=Object.freeze({[a.us]:T.us,[a.eu]:T.eu,[a.kr]:T.kr,[a.cn]:T.cn}),ke=Object.freeze({[a.us]:Object.freeze([_.en_US,_.es_MX,_.pt_BR]),[a.eu]:Object.freeze([_.en_GB,_.es_ES,_.fr_FR,_.ru_RU,_.de_DE,_.pt_PT,_.it_IT]),[a.kr]:Object.freeze([_.ko_KR,_.zh_TW]),[a.cn]:Object.freeze([_.zh_CN])}),Te=Object.freeze({[a.us]:Object.freeze([v.us]),[a.eu]:Object.freeze([v.eu]),[a.kr]:Object.freeze([v.kr,v.tw]),[a.cn]:Object.freeze([v.cn])}),me=Object.freeze({[a.us]:Object.freeze([p.US,p.LatAm]),[a.eu]:Object.freeze([p.Europe,p.Russia]),[a.kr]:Object.freeze([p.Korea,p.Taiwan]),[a.cn]:Object.freeze([p.China])}),Ae=Object.freeze({[a.us]:R.us,[a.eu]:R.eu,[a.kr]:[R.kr,R.tw],[a.cn]:R.cn}),I=Object.freeze({[a.us]:m.us,[a.eu]:m.eu,[a.kr]:m.kr,[a.cn]:m.cn}),z=e=>Object.freeze({[a.us]:`${I[a.us]}${e}`,[a.eu]:`${I[a.eu]}${e}`,[a.kr]:`${I[a.kr]}${e}`,[a.cn]:`${I[a.cn]}${e}`}),Oe=z(E.authorize),ye=z(E.token),Se=z(E.checkToken),g={[h.REGIONS]:Te,[h.LOCALES]:ke,[h.DEFAULT_LOCALES]:Re,[h.SC2_REALMS]:me,[h.REGION_API_HOSTS]:Ae,[h.OAUTH_AUTHORIZE_URIS]:Oe,[h.OAUTH_TOKEN_URIS]:ye,[h.OAUTH_CHECK_TOKEN_URIS]:Se},k=g[h.REGIONS],Ee=()=>k,we=()=>Object.keys(k).map(t=>parseInt(t,10)),Le=()=>{const e=Object.values(k);return[].concat(...e).map(r=>r.toString())},K=e=>{const t=Object.keys(k),r=e.toString();if(!t.includes(r))throw new RangeError(`${r} is not a valid parameter for getRegionNameById()`);return k[r]},O=e=>{try{return Boolean(K(e))}catch{return!1}},N=e=>{const t=e.toLowerCase(),s=Object.keys(k).filter(l=>k[l].includes(t)),o=Number(s[0])||!1;if(!o)throw new RangeError(`"${e}" is not a valid parameter for getRegionIdByName()`);return o},M=e=>{try{return Boolean(N(e))}catch{return!1}},C=(e,t)=>{const r=typeof e=="string"?e:e.toString();if(!O(r))throw new RangeError(`${r} is not a valid parameter for getConstantByRegionId(${e}, '${t}')`);return g[t][e]},Ie=(e,t)=>{if(!M(e))throw new RangeError(`${e} is not a valid parameter for getConstantByRegionName(${e}, '${t}')`);const s=N(e);return g[t][s]},j=(e,t)=>O(e)?C(e,t):Ie(e.toString(),t),be=g[h.LOCALES],W=()=>be,D=()=>Object.keys(_).filter(r=>Number.isNaN(Number(r))).map(r=>r.toString()),q=e=>C(e,h.LOCALES),Q=e=>/^(?:[a-z]{2}_[a-z]{2})$/gi.test(e),X=e=>{if(!Q(e))throw new RangeError(`${e} is not a valid parameter for validateLocale()`);const r=D().map(o=>o.toLowerCase()),s=e.toLowerCase();return r.includes(s)},Pe=(e,t)=>{const r=e.toLowerCase(),s=X(r)||!1,o=t.toString(),l=O(o);if(!s)throw new RangeError(`${e} is not a valid locale parameter for isLocaleValidForRegionId()`);if(!l)throw new RangeError(`${t} is not a valid regionId parameter for isLocaleValidForRegionId()`);return q(t).map(c=>c.toLowerCase()).includes(r)},Ue=g[h.DEFAULT_LOCALES],$e=g[h.LOCALES],Z=e=>{const t=e.toString();if(!O(t))throw new RangeError(`${t} is not a valid parameter for getDefaultLocaleNameForRegionId()`);const s=Ue[t];return $e[e][s]},ze=()=>{const e=W(),t=Object.keys(e);return Object.assign({},...t.map(r=>({[r]:Z(r)})))},Ne=()=>g.SC2_REALMS,x=()=>{const e=Object.values(g.SC2_REALMS);return[].concat(...e).filter((r,s,o)=>s===o.indexOf(r))},J=e=>C(e,h.SC2_REALMS),V=e=>{const t=e.toString();return/^([1-9]{1})$/gi.test(t)},Ce=e=>{if(!V(e))throw new RangeError(`${e} is not a valid parameter for validateSc2Realm()`);const r=x(),s=typeof e=="number"?e:parseInt(e,10);return r.includes(s)},je=(e,t)=>{const r=V(e),s=t.toString(),o=O(s);if(!r)throw new RangeError(`${e} is not a valid sc2Realm parameter for isSc2RealmValidForRegionId()`);if(!o)throw new RangeError(`${t} is not a valid regionId parameter for isSc2RealmValidForRegionId()`);const l=J(t),u=typeof e=="number"?e:parseInt(e,10);return l.includes(u)},Ve=e=>{const t=j(e,h.REGION_API_HOSTS);return typeof e=="string"&&e.toLowerCase()===v.kr?t[0]:typeof e=="string"&&e.toLowerCase()===v.tw?t[1]:t},Be=e=>j(e,h.OAUTH_CHECK_TOKEN_URIS),He=e=>j(e,h.OAUTH_TOKEN_URIS);var Fe=(e,t,r)=>new Promise((s,o)=>{var l=n=>{try{c(r.next(n))}catch(i){o(i)}},u=n=>{try{c(r.throw(n))}catch(i){o(i)}},c=n=>n.done?s(n.value):Promise.resolve(n.value).then(l,u);c((r=r.apply(e,t)).next())});const Y=e=>Fe(this,null,function*(){const{region:t,clientId:r,clientSecret:s}=e,o=He(t);return(yield ge({oauthUri:o,clientId:r,clientSecret:s})).access_token});var Ge=(e,t,r)=>new Promise((s,o)=>{var l=n=>{try{c(r.next(n))}catch(i){o(i)}},u=n=>{try{c(r.throw(n))}catch(i){o(i)}},c=n=>n.done?s(n.value):Promise.resolve(n.value).then(l,u);c((r=r.apply(e,t)).next())});const ee=(e,t)=>Ge(this,null,function*(){try{const s=`${Be(e)}${t}`;return(yield $({uri:s})).error!==w.InvalidToken}catch{return!1}});var Ke=Object.defineProperty,te=Object.getOwnPropertySymbols,Me=Object.prototype.hasOwnProperty,We=Object.prototype.propertyIsEnumerable,re=(e,t,r)=>t in e?Ke(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,b=(e,t)=>{for(var r in t||(t={}))Me.call(t,r)&&re(e,r,t[r]);if(te)for(var r of te(t))We.call(t,r)&&re(e,r,t[r]);return e},De=(e,t,r)=>new Promise((s,o)=>{var l=n=>{try{c(r.next(n))}catch(i){o(i)}},u=n=>{try{c(r.throw(n))}catch(i){o(i)}},c=n=>n.done?s(n.value):Promise.resolve(n.value).then(l,u);c((r=r.apply(e,t)).next())});const ne=(e,t)=>{const{region:r,endpoint:s,options:o}=e,{headers:l,params:u,timeout:c}=o;if(!de(s))throw new RangeError(`${s} is not a valid endpoint.`);const P=`${Ve(r)}${s}`,et={Authorization:`Bearer ${t}`},tt=b(b({},l),et);return $(b(b({uri:P,method:S.GET,headers:tt},u&&{params:u}),c&&{timeout:c}))},qe=e=>De(this,null,function*(){var t;const{region:r,accessToken:s}=e,{validateAccessTokenOnEachQuery:o,refreshExpiredAccessToken:l,onAccessTokenExpired:u,onAccessTokenRefresh:c}=e.options;if(o&&!(yield ee(r,s)))return{error:w.AccessTokenInvalid};try{return yield ne(e,s)}catch(n){if(((t=n.response)==null?void 0:t.status)===U.NotAuthorized){if(u==null||u(),l){const i=yield Y(e);return c==null||c(i),ne(e,i)}return Promise.resolve({error:w.AccessTokenExpired})}throw n}});class Qe{constructor(t,r){this.clientId=t,this.clientSecret=r}}var Xe=(e,t,r)=>new Promise((s,o)=>{var l=n=>{try{c(r.next(n))}catch(i){o(i)}},u=n=>{try{c(r.throw(n))}catch(i){o(i)}},c=n=>n.done?s(n.value):Promise.resolve(n.value).then(l,u);c((r=r.apply(e,t)).next())});class se extends Qe{constructor(t){super(t.clientId,t.clientSecret);this.getAccessToken=()=>this.accessToken||this.setAccessToken(),this.setAccessToken=()=>Xe(this,null,function*(){return this.accessToken=yield Y({region:this.region,clientId:this.clientId,clientSecret:this.clientSecret}),this.accessToken}),this.region=t.region,this.accessToken=t.accessToken||void 0}}se.validateAccessToken=(e,t)=>ee(e,t);var Ze=Object.defineProperty,oe=Object.getOwnPropertySymbols,xe=Object.prototype.hasOwnProperty,Je=Object.prototype.propertyIsEnumerable,ae=(e,t,r)=>t in e?Ze(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,ce=(e,t)=>{for(var r in t||(t={}))xe.call(t,r)&&ae(e,r,t[r]);if(oe)for(var r of oe(t))Je.call(t,r)&&ae(e,r,t[r]);return e},Ye=(e,t,r)=>new Promise((s,o)=>{var l=n=>{try{c(r.next(n))}catch(i){o(i)}},u=n=>{try{c(r.throw(n))}catch(i){o(i)}},c=n=>n.done?s(n.value):Promise.resolve(n.value).then(l,u);c((r=r.apply(e,t)).next())});class f extends se{constructor(t){super({region:t.region,clientId:t.clientId,clientSecret:t.clientSecret,accessToken:t.accessToken});this.query=(r,s)=>Ye(this,null,function*(){return qe({endpoint:r,region:this.region,clientId:this.clientId,clientSecret:this.clientSecret,accessToken:yield this.getAccessToken(),options:ce(ce({},this.options),s)})}),this.options={validateAccessTokenOnEachQuery:t.validateAccessTokenOnEachQuery||!1,refreshExpiredAccessToken:t.refreshExpiredAccessToken||!1,onAccessTokenExpired:t.onAccessTokenExpired||void 0,onAccessTokenRefresh:t.onAccessTokenRefresh||void 0}}}f.getAllRegions=Ee,f.getAllRegionIds=we,f.getAllRegionNames=Le,f.getRegionNameById=K,f.validateRegionId=O,f.getRegionIdByName=N,f.validateRegionName=M,f.getAllLocales=W,f.getAllLocaleNames=D,f.getLocalesByRegionId=q,f.checkIfLocaleLooksValid=Q,f.validateLocale=X,f.isLocaleValidForRegionId=Pe,f.getAllSc2Realms=Ne,f.getAllAvailableSc2Realms=x,f.getSc2RealmsByRegionId=J,f.checkIfSc2RealmLooksValid=V,f.validateSc2Realm=Ce,f.isSc2RealmValidForRegionId=je,f.getDefaultLocaleNameForRegionId=Z,f.getAllDefaultLocaleNames=ze,d.ApiHeaders=L,d.BlizzAPI=f,d.ConstantKey=h,d.DefaultLocaleIndex=T,d.ErrorCode=U,d.ErrorResponseMessage=w,d.HttpMethod=S,d.Locale=_,d.OAuthEndpoint=E,d.OAuthHost=m,d.RegionHost=R,d.RegionId=a,d.RegionIdAsString=B,d.RegionName=v,d.Sc2Realm=p,d.Sc2RealmAsString=H,Object.defineProperty(d,"__esModule",{value:!0})}); |
{ | ||
"name": "blizzapi", | ||
"version": "2.0.4", | ||
"description": "Flexible and feature-rich Node.js library for Blizzard Battle.net API", | ||
"version": "2.1.0", | ||
"description": "Flexible and feature-rich library for easy access to Blizzard Battle.net APIs", | ||
"homepage": "https://blizzapi.lukem.net", | ||
"main": "dist/blizzapi.js", | ||
"module": "dist/blizzapi.mjs", | ||
"browser": "dist/blizzapi.umd.js", | ||
@@ -40,21 +39,21 @@ "typings": "dist/blizzapi.d.ts", | ||
"dependencies": { | ||
"axios": "^0.23.0" | ||
"axios": "^0.24.0" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^27.0.2", | ||
"@types/node": "^16.11.1", | ||
"@typescript-eslint/eslint-plugin": "^5.1.0", | ||
"@typescript-eslint/parser": "^5.1.0", | ||
"esbuild": "^0.13.8", | ||
"eslint": "^8.0.1", | ||
"eslint-config-airbnb-typescript": "^14.0.1", | ||
"eslint-plugin-import": "^2.25.2", | ||
"eslint-plugin-jest": "^25.2.2", | ||
"jest": "^27.3.1", | ||
"@types/jest": "^27.0.3", | ||
"@types/node": "^17.0.5", | ||
"esbuild": "^0.14.8", | ||
"eslint": "^8.5.0", | ||
"eslint-config-airbnb-typescript": "^16.1.0", | ||
"eslint-config-airbnb-typescript-prettier": "^5.0.0", | ||
"eslint-plugin-import": "^2.25.3", | ||
"eslint-plugin-jest": "^25.3.2", | ||
"jest": "^27.4.5", | ||
"prettier": "^2.5.1", | ||
"rimraf": "^3.0.2", | ||
"rollup": "^2.58.0", | ||
"rollup-plugin-dts": "^4.0.0", | ||
"rollup-plugin-esbuild": "^4.6.0", | ||
"ts-jest": "^27.0.7", | ||
"typescript": "^4.4.4" | ||
"rollup": "^2.62.0", | ||
"rollup-plugin-dts": "^4.1.0", | ||
"rollup-plugin-esbuild": "^4.8.1", | ||
"ts-jest": "^27.1.2", | ||
"typescript": "^4.5.4" | ||
}, | ||
@@ -61,0 +60,0 @@ "keywords": [ |
@@ -9,3 +9,3 @@ <img src="https://raw.githubusercontent.com/blizzapi/blizzapi-docs/master/docs/.vuepress/public/logo.png" alt="BlizzAPI logo" width="200" height="200"> | ||
Flexible feature-rich library for easy access to [Battle.net API](https://develop.battle.net/). | ||
Flexible and feature-rich JavaScript / TypeScript library for easy access to [Blizzard Battle.net APIs](https://develop.battle.net/). | ||
@@ -21,3 +21,3 @@ ## Install | ||
```javascript | ||
const { BlizzAPI } = require('blizzapi'); | ||
const { BlizzAPI } = require("blizzapi"); | ||
@@ -30,11 +30,11 @@ /** | ||
const api = new BlizzAPI({ | ||
region: 'us', | ||
clientId: 'client id', | ||
clientSecret: 'client secret' | ||
region: "us", | ||
clientId: "client id", | ||
clientSecret: "client secret", | ||
}); | ||
const data = await api.query('/path/to/endpoint'); | ||
const data = await api.query("/path/to/endpoint"); | ||
console.log(data); | ||
``` | ||
``` | ||
@@ -52,8 +52,8 @@ ## Manual build | ||
* [blizzapi.lukem.net](https://blizzapi.lukem.net) - documentation | ||
* [blizzapi-docs](https://github.com/blizzapi/blizzapi-docs) - documentation repo on GitHub | ||
- [blizzapi.lukem.net](https://blizzapi.lukem.net) - documentation | ||
- [blizzapi-docs](https://github.com/blizzapi/blizzapi-docs) - documentation repo on GitHub | ||
* [blizzapi-example](https://github.com/blizzapi/blizzapi-example) - sample Express.js REST API with usage examples | ||
- [blizzapi-example](https://github.com/blizzapi/blizzapi-example) - sample Express.js REST API with usage examples | ||
* [Repositories that depend on BlizzAPI](https://github.com/blizzapi/blizzapi/network/dependents) | ||
- [Repositories that depend on BlizzAPI](https://github.com/blizzapi/blizzapi/network/dependents) | ||
@@ -66,5 +66,5 @@ ## Contributions | ||
* submiting a bug report or a feature suggestion | ||
* improving documentation either within the project itself or in the [doc site repository](https://github.com/blizzapi/blizzapi-docs) | ||
* submitting pull requests | ||
- submiting a bug report or a feature suggestion | ||
- improving documentation either within the project itself or in the [doc site repository](https://github.com/blizzapi/blizzapi-docs) | ||
- submitting pull requests | ||
@@ -71,0 +71,0 @@ Before contributing be sure to read [Contributing Guidelines](https://github.com/blizzapi/blizzapi/blob/master/CONTRIBUTING.md) and [Code of Conduct](https://github.com/blizzapi/blizzapi/blob/master/CODE_OF_CONDUCT.md). |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
294
37108
6
1
+ Addedaxios@0.24.0(transitive)
- Removedaxios@0.23.0(transitive)
Updatedaxios@^0.24.0