@blizzard-api/core
Version:
The core helpers used by all @blizzard-api/* packages.
77 lines (76 loc) • 2.14 kB
JavaScript
//#region src/base.ts
/**
* The base request path for the D3 API in the Blizzard API.
*/
const d3BasePath = "d3/data";
/**
* The base request path for profile APIs in the D3 API.
*/
const d3ProfileBasePath = `d3/profile`;
/**
* The base request path for game data APIs in the D3 API.
*/
const d3GameDataBasePath = `data/d3`;
/**
* The base request path for the Blizzard API for world of warcraft.
*/
const wowBasePath = "/data/wow";
/**
* The base request path for the character API for Classic World of Warcraft.
*/
const wowCharacterBasePath = "profile/wow/character";
/**
* The base request path for media in the Blizzard API for world of warcraft.
*/
const wowMediaBasePath = `${wowBasePath}/media`;
/**
* The base request path for search in the Blizzard API for world of warcraft.
*/
const wowSearchBasePath = `${wowBasePath}/search`;
//#endregion
//#region src/blizzard-api.ts
const endpoints = {
cn: {
defaultLocale: "zh_CN",
hostname: "https://gateway.battlenet.com.cn"
},
eu: {
defaultLocale: "en_GB",
hostname: "https://eu.api.blizzard.com"
},
kr: {
defaultLocale: "ko_KR",
hostname: "https://kr.api.blizzard.com"
},
tw: {
defaultLocale: "zh_TW",
hostname: "https://tw.api.blizzard.com"
},
us: {
defaultLocale: "en_US",
hostname: "https://us.api.blizzard.com"
}
};
/**
* Get the Blizzard API configuration for a given region.
* @template T The region of the Blizzard API.
* @param origin The region of the Blizzard API.
* @param locale The locale of the Blizzard API.
* @returns The Blizzard API configuration for the given region.
* @example
* const api = getBlizzardApi('us', 'en_US');
* console.log(api.hostname); // 'https://us.api.blizzard.com'
* console.log(api.locale); // 'en_US'
* console.log(api.origin); // 'us'
*/
function getBlizzardApi(origin, locale) {
const endpoint = endpoints[origin];
return {
hostname: endpoint.hostname,
locale: locale ?? endpoint.defaultLocale,
origin
};
}
//#endregion
export { d3BasePath, d3GameDataBasePath, d3ProfileBasePath, getBlizzardApi, wowBasePath, wowCharacterBasePath, wowMediaBasePath, wowSearchBasePath };
//# sourceMappingURL=index.js.map