@pinta365/blizzard_api 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (281) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +61 -0
  3. package/esm/mod.d.ts +5 -0
  4. package/esm/mod.js +5 -0
  5. package/esm/package.json +3 -0
  6. package/esm/src/hearthstone/game_data/card_backs.d.ts +22 -0
  7. package/esm/src/hearthstone/game_data/card_backs.js +23 -0
  8. package/esm/src/hearthstone/game_data/cards.d.ts +37 -0
  9. package/esm/src/hearthstone/game_data/cards.js +27 -0
  10. package/esm/src/hearthstone/game_data/decks.d.ts +88 -0
  11. package/esm/src/hearthstone/game_data/decks.js +14 -0
  12. package/esm/src/hearthstone/game_data/metadata.d.ts +95 -0
  13. package/esm/src/hearthstone/game_data/metadata.js +12 -0
  14. package/esm/src/hearthstone/index.d.ts +4 -0
  15. package/esm/src/hearthstone/index.js +4 -0
  16. package/esm/src/hearthstone/search.d.ts +20 -0
  17. package/esm/src/hearthstone/search.js +29 -0
  18. package/esm/src/shared/auth.d.ts +24 -0
  19. package/esm/src/shared/auth.js +58 -0
  20. package/esm/src/shared/config.d.ts +40 -0
  21. package/esm/src/shared/config.js +48 -0
  22. package/esm/src/shared/errors.d.ts +44 -0
  23. package/esm/src/shared/errors.js +83 -0
  24. package/esm/src/shared/index.d.ts +4 -0
  25. package/esm/src/shared/index.js +3 -0
  26. package/esm/src/shared/request.d.ts +13 -0
  27. package/esm/src/shared/request.js +43 -0
  28. package/esm/src/shared/types.d.ts +120 -0
  29. package/esm/src/shared/types.js +2 -0
  30. package/esm/src/starcraft2/game_data/league.d.ts +32 -0
  31. package/esm/src/starcraft2/game_data/league.js +21 -0
  32. package/esm/src/starcraft2/index.d.ts +1 -0
  33. package/esm/src/starcraft2/index.js +1 -0
  34. package/esm/src/wow/game_data/achievement.d.ts +84 -0
  35. package/esm/src/wow/game_data/achievement.js +69 -0
  36. package/esm/src/wow/game_data/auction_house.d.ts +64 -0
  37. package/esm/src/wow/game_data/auction_house.js +34 -0
  38. package/esm/src/wow/game_data/azerite_essence.d.ts +49 -0
  39. package/esm/src/wow/game_data/azerite_essence.js +49 -0
  40. package/esm/src/wow/game_data/connected_realm.d.ts +54 -0
  41. package/esm/src/wow/game_data/connected_realm.js +36 -0
  42. package/esm/src/wow/game_data/covenant.d.ts +108 -0
  43. package/esm/src/wow/game_data/covenant.js +89 -0
  44. package/esm/src/wow/game_data/creature.d.ts +97 -0
  45. package/esm/src/wow/game_data/creature.js +100 -0
  46. package/esm/src/wow/game_data/guild_crest.d.ts +55 -0
  47. package/esm/src/wow/game_data/guild_crest.js +39 -0
  48. package/esm/src/wow/game_data/heirloom.d.ts +79 -0
  49. package/esm/src/wow/game_data/heirloom.js +26 -0
  50. package/esm/src/wow/game_data/item.d.ts +166 -0
  51. package/esm/src/wow/game_data/item.js +101 -0
  52. package/esm/src/wow/game_data/journal.d.ts +121 -0
  53. package/esm/src/wow/game_data/journal.js +99 -0
  54. package/esm/src/wow/game_data/keystone_affix.d.ts +34 -0
  55. package/esm/src/wow/game_data/keystone_affix.js +39 -0
  56. package/esm/src/wow/game_data/media_search.d.ts +8 -0
  57. package/esm/src/wow/game_data/media_search.js +10 -0
  58. package/esm/src/wow/game_data/modified_crafting.d.ts +56 -0
  59. package/esm/src/wow/game_data/modified_crafting.js +63 -0
  60. package/esm/src/wow/game_data/mount.d.ts +30 -0
  61. package/esm/src/wow/game_data/mount.js +30 -0
  62. package/esm/src/wow/game_data/mythic_keystone_dungeon.d.ts +91 -0
  63. package/esm/src/wow/game_data/mythic_keystone_dungeon.js +88 -0
  64. package/esm/src/wow/game_data/mythic_keystone_leaderboard.d.ts +58 -0
  65. package/esm/src/wow/game_data/mythic_keystone_leaderboard.js +29 -0
  66. package/esm/src/wow/game_data/mythic_raid_leaderboard.d.ts +31 -0
  67. package/esm/src/wow/game_data/mythic_raid_leaderboard.js +15 -0
  68. package/esm/src/wow/game_data/pet.d.ts +91 -0
  69. package/esm/src/wow/game_data/pet.js +77 -0
  70. package/esm/src/wow/game_data/playable_class.d.ts +57 -0
  71. package/esm/src/wow/game_data/playable_class.js +52 -0
  72. package/esm/src/wow/game_data/playable_race.d.ts +29 -0
  73. package/esm/src/wow/game_data/playable_race.js +26 -0
  74. package/esm/src/wow/game_data/power_type.d.ts +21 -0
  75. package/esm/src/wow/game_data/power_type.js +26 -0
  76. package/esm/src/wow/game_data/profession.d.ts +85 -0
  77. package/esm/src/wow/game_data/profession.js +79 -0
  78. package/esm/src/wow/game_data/pvp_season.d.ts +99 -0
  79. package/esm/src/wow/game_data/pvp_season.js +66 -0
  80. package/esm/src/wow/game_data/pvp_tier.d.ts +40 -0
  81. package/esm/src/wow/game_data/pvp_tier.js +39 -0
  82. package/esm/src/wow/game_data/quest.d.ts +114 -0
  83. package/esm/src/wow/game_data/quest.js +101 -0
  84. package/esm/src/wow/game_data/realm.d.ts +42 -0
  85. package/esm/src/wow/game_data/realm.js +36 -0
  86. package/esm/src/wow/game_data/region.d.ts +24 -0
  87. package/esm/src/wow/game_data/region.js +26 -0
  88. package/esm/src/wow/game_data/reputations.d.ts +50 -0
  89. package/esm/src/wow/game_data/reputations.js +51 -0
  90. package/esm/src/wow/game_data/spell.d.ts +33 -0
  91. package/esm/src/wow/game_data/spell.js +37 -0
  92. package/esm/src/wow/game_data/talent.d.ts +129 -0
  93. package/esm/src/wow/game_data/talent.js +90 -0
  94. package/esm/src/wow/game_data/tech_talent.d.ts +70 -0
  95. package/esm/src/wow/game_data/tech_talent.js +64 -0
  96. package/esm/src/wow/game_data/title.d.ts +25 -0
  97. package/esm/src/wow/game_data/title.js +26 -0
  98. package/esm/src/wow/game_data/token.d.ts +16 -0
  99. package/esm/src/wow/game_data/token.js +19 -0
  100. package/esm/src/wow/game_data/toy.d.ts +24 -0
  101. package/esm/src/wow/game_data/toy.js +26 -0
  102. package/esm/src/wow/index.d.ts +53 -0
  103. package/esm/src/wow/index.js +55 -0
  104. package/esm/src/wow/profile/character_achievements.d.ts +87 -0
  105. package/esm/src/wow/profile/character_achievements.js +29 -0
  106. package/esm/src/wow/profile/character_appearance.d.ts +75 -0
  107. package/esm/src/wow/profile/character_appearance.js +15 -0
  108. package/esm/src/wow/profile/character_collections.d.ts +92 -0
  109. package/esm/src/wow/profile/character_collections.js +71 -0
  110. package/esm/src/wow/profile/character_encounters.d.ts +77 -0
  111. package/esm/src/wow/profile/character_encounters.js +43 -0
  112. package/esm/src/wow/profile/character_equipment.d.ts +132 -0
  113. package/esm/src/wow/profile/character_equipment.js +15 -0
  114. package/esm/src/wow/profile/character_hunter_pets.d.ts +21 -0
  115. package/esm/src/wow/profile/character_hunter_pets.js +15 -0
  116. package/esm/src/wow/profile/character_media.d.ts +13 -0
  117. package/esm/src/wow/profile/character_media.js +15 -0
  118. package/esm/src/wow/profile/character_mythic_keystone_profile.d.ts +58 -0
  119. package/esm/src/wow/profile/character_mythic_keystone_profile.js +32 -0
  120. package/esm/src/wow/profile/character_professions.d.ts +26 -0
  121. package/esm/src/wow/profile/character_professions.js +15 -0
  122. package/esm/src/wow/profile/character_profile.d.ts +82 -0
  123. package/esm/src/wow/profile/character_profile.js +40 -0
  124. package/esm/src/wow/profile/character_pvp.d.ts +51 -0
  125. package/esm/src/wow/profile/character_pvp.js +30 -0
  126. package/esm/src/wow/profile/character_quests.d.ts +28 -0
  127. package/esm/src/wow/profile/character_quests.js +29 -0
  128. package/esm/src/wow/profile/character_reputations.d.ts +22 -0
  129. package/esm/src/wow/profile/character_reputations.js +15 -0
  130. package/esm/src/wow/profile/character_soulbinds.d.ts +30 -0
  131. package/esm/src/wow/profile/character_soulbinds.js +15 -0
  132. package/esm/src/wow/profile/character_specializations.d.ts +44 -0
  133. package/esm/src/wow/profile/character_specializations.js +15 -0
  134. package/esm/src/wow/profile/character_statistics.d.ts +116 -0
  135. package/esm/src/wow/profile/character_statistics.js +15 -0
  136. package/esm/src/wow/profile/character_titles.d.ts +13 -0
  137. package/esm/src/wow/profile/character_titles.js +15 -0
  138. package/esm/src/wow/profile/guild.d.ts +117 -0
  139. package/esm/src/wow/profile/guild.js +57 -0
  140. package/esm/src/wow/search.d.ts +21 -0
  141. package/esm/src/wow/search.js +30 -0
  142. package/package.json +36 -0
  143. package/script/mod.d.ts +5 -0
  144. package/script/mod.js +35 -0
  145. package/script/package.json +3 -0
  146. package/script/src/hearthstone/game_data/card_backs.d.ts +22 -0
  147. package/script/src/hearthstone/game_data/card_backs.js +28 -0
  148. package/script/src/hearthstone/game_data/cards.d.ts +37 -0
  149. package/script/src/hearthstone/game_data/cards.js +32 -0
  150. package/script/src/hearthstone/game_data/decks.d.ts +88 -0
  151. package/script/src/hearthstone/game_data/decks.js +18 -0
  152. package/script/src/hearthstone/game_data/metadata.d.ts +95 -0
  153. package/script/src/hearthstone/game_data/metadata.js +16 -0
  154. package/script/src/hearthstone/index.d.ts +4 -0
  155. package/script/src/hearthstone/index.js +13 -0
  156. package/script/src/hearthstone/search.d.ts +20 -0
  157. package/script/src/hearthstone/search.js +33 -0
  158. package/script/src/shared/auth.d.ts +24 -0
  159. package/script/src/shared/auth.js +63 -0
  160. package/script/src/shared/config.d.ts +40 -0
  161. package/script/src/shared/config.js +55 -0
  162. package/script/src/shared/errors.d.ts +44 -0
  163. package/script/src/shared/errors.js +91 -0
  164. package/script/src/shared/index.d.ts +4 -0
  165. package/script/src/shared/index.js +9 -0
  166. package/script/src/shared/request.d.ts +13 -0
  167. package/script/src/shared/request.js +47 -0
  168. package/script/src/shared/types.d.ts +120 -0
  169. package/script/src/shared/types.js +3 -0
  170. package/script/src/starcraft2/game_data/league.d.ts +32 -0
  171. package/script/src/starcraft2/game_data/league.js +25 -0
  172. package/script/src/starcraft2/index.d.ts +1 -0
  173. package/script/src/starcraft2/index.js +5 -0
  174. package/script/src/wow/game_data/achievement.d.ts +84 -0
  175. package/script/src/wow/game_data/achievement.js +77 -0
  176. package/script/src/wow/game_data/auction_house.d.ts +64 -0
  177. package/script/src/wow/game_data/auction_house.js +39 -0
  178. package/script/src/wow/game_data/azerite_essence.d.ts +49 -0
  179. package/script/src/wow/game_data/azerite_essence.js +56 -0
  180. package/script/src/wow/game_data/connected_realm.d.ts +54 -0
  181. package/script/src/wow/game_data/connected_realm.js +42 -0
  182. package/script/src/wow/game_data/covenant.d.ts +108 -0
  183. package/script/src/wow/game_data/covenant.js +99 -0
  184. package/script/src/wow/game_data/creature.d.ts +97 -0
  185. package/script/src/wow/game_data/creature.js +111 -0
  186. package/script/src/wow/game_data/guild_crest.d.ts +55 -0
  187. package/script/src/wow/game_data/guild_crest.js +45 -0
  188. package/script/src/wow/game_data/heirloom.d.ts +79 -0
  189. package/script/src/wow/game_data/heirloom.js +31 -0
  190. package/script/src/wow/game_data/item.d.ts +166 -0
  191. package/script/src/wow/game_data/item.js +112 -0
  192. package/script/src/wow/game_data/journal.d.ts +121 -0
  193. package/script/src/wow/game_data/journal.js +110 -0
  194. package/script/src/wow/game_data/keystone_affix.d.ts +34 -0
  195. package/script/src/wow/game_data/keystone_affix.js +45 -0
  196. package/script/src/wow/game_data/media_search.d.ts +8 -0
  197. package/script/src/wow/game_data/media_search.js +14 -0
  198. package/script/src/wow/game_data/modified_crafting.d.ts +56 -0
  199. package/script/src/wow/game_data/modified_crafting.js +71 -0
  200. package/script/src/wow/game_data/mount.d.ts +30 -0
  201. package/script/src/wow/game_data/mount.js +36 -0
  202. package/script/src/wow/game_data/mythic_keystone_dungeon.d.ts +91 -0
  203. package/script/src/wow/game_data/mythic_keystone_dungeon.js +98 -0
  204. package/script/src/wow/game_data/mythic_keystone_leaderboard.d.ts +58 -0
  205. package/script/src/wow/game_data/mythic_keystone_leaderboard.js +34 -0
  206. package/script/src/wow/game_data/mythic_raid_leaderboard.d.ts +31 -0
  207. package/script/src/wow/game_data/mythic_raid_leaderboard.js +19 -0
  208. package/script/src/wow/game_data/pet.d.ts +91 -0
  209. package/script/src/wow/game_data/pet.js +86 -0
  210. package/script/src/wow/game_data/playable_class.d.ts +57 -0
  211. package/script/src/wow/game_data/playable_class.js +59 -0
  212. package/script/src/wow/game_data/playable_race.d.ts +29 -0
  213. package/script/src/wow/game_data/playable_race.js +31 -0
  214. package/script/src/wow/game_data/power_type.d.ts +21 -0
  215. package/script/src/wow/game_data/power_type.js +31 -0
  216. package/script/src/wow/game_data/profession.d.ts +85 -0
  217. package/script/src/wow/game_data/profession.js +88 -0
  218. package/script/src/wow/game_data/pvp_season.d.ts +99 -0
  219. package/script/src/wow/game_data/pvp_season.js +74 -0
  220. package/script/src/wow/game_data/pvp_tier.d.ts +40 -0
  221. package/script/src/wow/game_data/pvp_tier.js +45 -0
  222. package/script/src/wow/game_data/quest.d.ts +114 -0
  223. package/script/src/wow/game_data/quest.js +112 -0
  224. package/script/src/wow/game_data/realm.d.ts +42 -0
  225. package/script/src/wow/game_data/realm.js +42 -0
  226. package/script/src/wow/game_data/region.d.ts +24 -0
  227. package/script/src/wow/game_data/region.js +31 -0
  228. package/script/src/wow/game_data/reputations.d.ts +50 -0
  229. package/script/src/wow/game_data/reputations.js +58 -0
  230. package/script/src/wow/game_data/spell.d.ts +33 -0
  231. package/script/src/wow/game_data/spell.js +43 -0
  232. package/script/src/wow/game_data/talent.d.ts +129 -0
  233. package/script/src/wow/game_data/talent.js +100 -0
  234. package/script/src/wow/game_data/tech_talent.d.ts +70 -0
  235. package/script/src/wow/game_data/tech_talent.js +72 -0
  236. package/script/src/wow/game_data/title.d.ts +25 -0
  237. package/script/src/wow/game_data/title.js +31 -0
  238. package/script/src/wow/game_data/token.d.ts +16 -0
  239. package/script/src/wow/game_data/token.js +23 -0
  240. package/script/src/wow/game_data/toy.d.ts +24 -0
  241. package/script/src/wow/game_data/toy.js +31 -0
  242. package/script/src/wow/index.d.ts +53 -0
  243. package/script/src/wow/index.js +228 -0
  244. package/script/src/wow/profile/character_achievements.d.ts +87 -0
  245. package/script/src/wow/profile/character_achievements.js +34 -0
  246. package/script/src/wow/profile/character_appearance.d.ts +75 -0
  247. package/script/src/wow/profile/character_appearance.js +19 -0
  248. package/script/src/wow/profile/character_collections.d.ts +92 -0
  249. package/script/src/wow/profile/character_collections.js +79 -0
  250. package/script/src/wow/profile/character_encounters.d.ts +77 -0
  251. package/script/src/wow/profile/character_encounters.js +49 -0
  252. package/script/src/wow/profile/character_equipment.d.ts +132 -0
  253. package/script/src/wow/profile/character_equipment.js +19 -0
  254. package/script/src/wow/profile/character_hunter_pets.d.ts +21 -0
  255. package/script/src/wow/profile/character_hunter_pets.js +19 -0
  256. package/script/src/wow/profile/character_media.d.ts +13 -0
  257. package/script/src/wow/profile/character_media.js +19 -0
  258. package/script/src/wow/profile/character_mythic_keystone_profile.d.ts +58 -0
  259. package/script/src/wow/profile/character_mythic_keystone_profile.js +37 -0
  260. package/script/src/wow/profile/character_professions.d.ts +26 -0
  261. package/script/src/wow/profile/character_professions.js +19 -0
  262. package/script/src/wow/profile/character_profile.d.ts +82 -0
  263. package/script/src/wow/profile/character_profile.js +45 -0
  264. package/script/src/wow/profile/character_pvp.d.ts +51 -0
  265. package/script/src/wow/profile/character_pvp.js +35 -0
  266. package/script/src/wow/profile/character_quests.d.ts +28 -0
  267. package/script/src/wow/profile/character_quests.js +34 -0
  268. package/script/src/wow/profile/character_reputations.d.ts +22 -0
  269. package/script/src/wow/profile/character_reputations.js +19 -0
  270. package/script/src/wow/profile/character_soulbinds.d.ts +30 -0
  271. package/script/src/wow/profile/character_soulbinds.js +19 -0
  272. package/script/src/wow/profile/character_specializations.d.ts +44 -0
  273. package/script/src/wow/profile/character_specializations.js +19 -0
  274. package/script/src/wow/profile/character_statistics.d.ts +116 -0
  275. package/script/src/wow/profile/character_statistics.js +19 -0
  276. package/script/src/wow/profile/character_titles.d.ts +13 -0
  277. package/script/src/wow/profile/character_titles.js +19 -0
  278. package/script/src/wow/profile/guild.d.ts +117 -0
  279. package/script/src/wow/profile/guild.js +64 -0
  280. package/script/src/wow/search.d.ts +21 -0
  281. package/script/src/wow/search.js +34 -0
@@ -0,0 +1,20 @@
1
+ export interface SearchParameters {
2
+ searchFields?: Record<string | symbol, string | number>;
3
+ page?: number;
4
+ pageSize?: number;
5
+ sort?: string;
6
+ }
7
+ export interface Search {
8
+ page: number;
9
+ pageSize: number;
10
+ maxPageSize: number;
11
+ pageCount: number;
12
+ results: unknown[];
13
+ }
14
+ /**
15
+ * Performs a search.
16
+ *
17
+ * @param SearchParameters - Object containing search parameters.
18
+ * @returns A promise that resolves to an object representing details about the search.
19
+ */
20
+ export declare function search(url: string, searchParameters: SearchParameters): Promise<Search>;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.search = void 0;
4
+ const index_js_1 = require("../shared/index.js");
5
+ /**
6
+ * Performs a search.
7
+ *
8
+ * @param SearchParameters - Object containing search parameters.
9
+ * @returns A promise that resolves to an object representing details about the search.
10
+ */
11
+ async function search(url, searchParameters) {
12
+ const searchFields = searchParameters.searchFields
13
+ ? Object.fromEntries(Object.entries(searchParameters.searchFields).map(([key, value]) => [key, value.toString()]))
14
+ : undefined;
15
+ const qs = {
16
+ ...searchFields,
17
+ };
18
+ if (searchParameters.sort) {
19
+ qs.sort = searchParameters.sort;
20
+ }
21
+ if (searchParameters.page !== undefined) {
22
+ qs.page = searchParameters.page;
23
+ }
24
+ if (searchParameters.pageSize !== undefined) {
25
+ qs.pageSize = searchParameters.pageSize;
26
+ }
27
+ return await (0, index_js_1.request)({
28
+ method: "GET",
29
+ url: `/hearthstone${url}`,
30
+ qs,
31
+ });
32
+ }
33
+ exports.search = search;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Represents the configuration data for authentication.
3
+ * @property {string} accessToken - The current access token.
4
+ * @property {number} tokenExpiration - The expiration timestamp of the access token (in milliseconds).
5
+ */
6
+ export interface AuthConfig {
7
+ accessToken: string;
8
+ tokenExpiration: number;
9
+ }
10
+ /**
11
+ * Retrieves the global authentication configuration.
12
+ * @returns {AuthConfig} The authentication configuration object.
13
+ */
14
+ export declare function getauthConfig(): AuthConfig;
15
+ /**
16
+ * Handles authentication and obtains an access token if needed.
17
+ * @param {boolean} forceNewToken - If true, forces the retrieval of a new token, ignoring any existing one.
18
+ * @returns {Promise<string>} Returns the access token (string).
19
+ * @throws {MissingRegionError} If the region is not configured.
20
+ * @throws {MissingClientIdError} If the client ID is not configured.
21
+ * @throws {MissingClientSecretError} If the client secret is not configured.
22
+ * @throws {AuthenticationError} If there is a problem during the authentication process.
23
+ */
24
+ export declare function authenticate(forceNewToken?: boolean): Promise<string>;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.authenticate = exports.getauthConfig = void 0;
4
+ //auth.ts
5
+ const config_js_1 = require("./config.js");
6
+ const errors_js_1 = require("./errors.js");
7
+ /**
8
+ * Global storage for authentication configuration data.
9
+ */
10
+ const authConfig = {
11
+ accessToken: "",
12
+ tokenExpiration: 0,
13
+ };
14
+ /**
15
+ * Retrieves the global authentication configuration.
16
+ * @returns {AuthConfig} The authentication configuration object.
17
+ */
18
+ function getauthConfig() {
19
+ return authConfig;
20
+ }
21
+ exports.getauthConfig = getauthConfig;
22
+ /**
23
+ * Handles authentication and obtains an access token if needed.
24
+ * @param {boolean} forceNewToken - If true, forces the retrieval of a new token, ignoring any existing one.
25
+ * @returns {Promise<string>} Returns the access token (string).
26
+ * @throws {MissingRegionError} If the region is not configured.
27
+ * @throws {MissingClientIdError} If the client ID is not configured.
28
+ * @throws {MissingClientSecretError} If the client secret is not configured.
29
+ * @throws {AuthenticationError} If there is a problem during the authentication process.
30
+ */
31
+ async function authenticate(forceNewToken = false) {
32
+ if (!(0, config_js_1.getSetup)().region) {
33
+ throw new errors_js_1.MissingRegionError();
34
+ }
35
+ if (!(0, config_js_1.getSetup)().clientId) {
36
+ throw new errors_js_1.MissingClientIdError();
37
+ }
38
+ if (!(0, config_js_1.getSetup)().clientSecret) {
39
+ throw new errors_js_1.MissingClientSecretError();
40
+ }
41
+ if (!forceNewToken && authConfig.accessToken && authConfig.tokenExpiration &&
42
+ new Date() < new Date(authConfig.tokenExpiration)) {
43
+ return authConfig.accessToken;
44
+ }
45
+ const response = await fetch((0, config_js_1.tokenUrl)((0, config_js_1.getSetup)().region), {
46
+ method: "POST",
47
+ headers: {
48
+ "Authorization": "Basic " + btoa(`${(0, config_js_1.getSetup)().clientId}:${(0, config_js_1.getSetup)().clientSecret}`),
49
+ "Content-Type": "application/x-www-form-urlencoded",
50
+ },
51
+ body: "grant_type=client_credentials",
52
+ });
53
+ if (response.ok) {
54
+ const data = await response.json();
55
+ authConfig.accessToken = data.access_token;
56
+ authConfig.tokenExpiration = Date.now() + data.expires_in * 1000;
57
+ return authConfig.accessToken;
58
+ }
59
+ else {
60
+ throw new errors_js_1.AuthenticationError("Problem with Authentication", response.status, response.statusText);
61
+ }
62
+ }
63
+ exports.authenticate = authenticate;
@@ -0,0 +1,40 @@
1
+ import type { Locales, Regions } from "./types.js";
2
+ /**
3
+ * Represents the required application configuration.
4
+ * @property {Regions} region - The target Battle.net region for API requests.
5
+ * @property {Locales} locale - The desired locale for data.
6
+ * @property {string} clientId - The OAuth client ID.
7
+ * @property {string} clientSecret - The OAuth client secret.
8
+ */
9
+ export interface Config {
10
+ region: Regions;
11
+ locale: Locales;
12
+ clientId: string;
13
+ clientSecret: string;
14
+ }
15
+ /**
16
+ * Generates the OAuth token URL based on the specified region.
17
+ * @param {Regions} region - The target Battle.net region.
18
+ * @returns {string} The constructed token URL.
19
+ */
20
+ export declare function tokenUrl(region: Regions): string;
21
+ /**
22
+ * Generates the base API URL based on the specified region.
23
+ * @param {Regions} region - The target Battle.net region.
24
+ * @returns {string} The constructed base API URL.
25
+ */
26
+ export declare function apiBaseUrl(region: Regions): string;
27
+ /**
28
+ * Updates the application configuration and performs basic validation.
29
+ * @param {Partial<Config>} userConfig - An object containing configuration properties to update.
30
+ * @throws {MissingRegionError} If the region is not provided in the update.
31
+ * @throws {MissingClientIdError} If the client ID is not provided in the update.
32
+ * @throws {MissingClientSecretError} If the client secret is not provided in the update.
33
+ */
34
+ export declare function setup(userConfig: Partial<Config>): void;
35
+ /**
36
+ * Retrieves the current application configuration.
37
+ * Note: The configuration may be partial if not fully setup.
38
+ * @returns {Config | Partial<Config>} The full or partially loaded configuration object.
39
+ */
40
+ export declare function getSetup(): Config | Partial<Config>;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSetup = exports.setup = exports.apiBaseUrl = exports.tokenUrl = void 0;
4
+ const errors_js_1 = require("./errors.js");
5
+ /**
6
+ * Holds the partially loaded application configuration.
7
+ */
8
+ let config = {};
9
+ /**
10
+ * Generates the OAuth token URL based on the specified region.
11
+ * @param {Regions} region - The target Battle.net region.
12
+ * @returns {string} The constructed token URL.
13
+ */
14
+ function tokenUrl(region) {
15
+ return region === "cn" ? "https://www.battlenet.com.cn/oauth/token" : `https://${region}.battle.net/oauth/token`;
16
+ }
17
+ exports.tokenUrl = tokenUrl;
18
+ /**
19
+ * Generates the base API URL based on the specified region.
20
+ * @param {Regions} region - The target Battle.net region.
21
+ * @returns {string} The constructed base API URL.
22
+ */
23
+ function apiBaseUrl(region) {
24
+ return region === "cn" ? "https://gateway.battlenet.com.cn" : `https://${region}.api.blizzard.com`;
25
+ }
26
+ exports.apiBaseUrl = apiBaseUrl;
27
+ /**
28
+ * Updates the application configuration and performs basic validation.
29
+ * @param {Partial<Config>} userConfig - An object containing configuration properties to update.
30
+ * @throws {MissingRegionError} If the region is not provided in the update.
31
+ * @throws {MissingClientIdError} If the client ID is not provided in the update.
32
+ * @throws {MissingClientSecretError} If the client secret is not provided in the update.
33
+ */
34
+ function setup(userConfig) {
35
+ config = { ...config, ...userConfig };
36
+ if (!config.region) {
37
+ throw new errors_js_1.MissingRegionError();
38
+ }
39
+ if (!config.clientId) {
40
+ throw new errors_js_1.MissingClientIdError();
41
+ }
42
+ if (!config.clientSecret) {
43
+ throw new errors_js_1.MissingClientSecretError();
44
+ }
45
+ }
46
+ exports.setup = setup;
47
+ /**
48
+ * Retrieves the current application configuration.
49
+ * Note: The configuration may be partial if not fully setup.
50
+ * @returns {Config | Partial<Config>} The full or partially loaded configuration object.
51
+ */
52
+ function getSetup() {
53
+ return config;
54
+ }
55
+ exports.getSetup = getSetup;
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Custom error class representing an API error.
3
+ * @class
4
+ * @extends {Error}
5
+ */
6
+ export declare class APIError extends Error {
7
+ statusCode: number;
8
+ responseBody: string;
9
+ constructor(message: string, statusCode: number, responseBody: string);
10
+ }
11
+ /**
12
+ * Custom error class representing an Authentication error.
13
+ * @class
14
+ * @extends {Error}
15
+ */
16
+ export declare class AuthenticationError extends Error {
17
+ statusCode: number;
18
+ responseBody: string;
19
+ constructor(message: string, statusCode: number, responseBody: string);
20
+ }
21
+ /**
22
+ * Custom error class representing a missing client id error.
23
+ * @class
24
+ * @extends {Error}
25
+ */
26
+ export declare class MissingClientIdError extends Error {
27
+ constructor();
28
+ }
29
+ /**
30
+ * Custom error class representing a missing client secret error.
31
+ * @class
32
+ * @extends {Error}
33
+ */
34
+ export declare class MissingClientSecretError extends Error {
35
+ constructor();
36
+ }
37
+ /**
38
+ * Custom error class representing a missing api region error.
39
+ * @class
40
+ * @extends {Error}
41
+ */
42
+ export declare class MissingRegionError extends Error {
43
+ constructor();
44
+ }
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MissingRegionError = exports.MissingClientSecretError = exports.MissingClientIdError = exports.AuthenticationError = exports.APIError = void 0;
4
+ /**
5
+ * Custom error class representing an API error.
6
+ * @class
7
+ * @extends {Error}
8
+ */
9
+ class APIError extends Error {
10
+ constructor(message, statusCode, responseBody) {
11
+ super(message);
12
+ Object.defineProperty(this, "statusCode", {
13
+ enumerable: true,
14
+ configurable: true,
15
+ writable: true,
16
+ value: void 0
17
+ });
18
+ Object.defineProperty(this, "responseBody", {
19
+ enumerable: true,
20
+ configurable: true,
21
+ writable: true,
22
+ value: void 0
23
+ });
24
+ this.name = "APIError";
25
+ this.statusCode = statusCode;
26
+ this.responseBody = responseBody;
27
+ }
28
+ }
29
+ exports.APIError = APIError;
30
+ /**
31
+ * Custom error class representing an Authentication error.
32
+ * @class
33
+ * @extends {Error}
34
+ */
35
+ class AuthenticationError extends Error {
36
+ constructor(message, statusCode, responseBody) {
37
+ super(message);
38
+ Object.defineProperty(this, "statusCode", {
39
+ enumerable: true,
40
+ configurable: true,
41
+ writable: true,
42
+ value: void 0
43
+ });
44
+ Object.defineProperty(this, "responseBody", {
45
+ enumerable: true,
46
+ configurable: true,
47
+ writable: true,
48
+ value: void 0
49
+ });
50
+ this.name = "AuthenticationError";
51
+ this.statusCode = statusCode;
52
+ this.responseBody = responseBody;
53
+ }
54
+ }
55
+ exports.AuthenticationError = AuthenticationError;
56
+ /**
57
+ * Custom error class representing a missing client id error.
58
+ * @class
59
+ * @extends {Error}
60
+ */
61
+ class MissingClientIdError extends Error {
62
+ constructor() {
63
+ super("Client Id must be setup. Check documentation");
64
+ this.name = "MissingClientIdError";
65
+ }
66
+ }
67
+ exports.MissingClientIdError = MissingClientIdError;
68
+ /**
69
+ * Custom error class representing a missing client secret error.
70
+ * @class
71
+ * @extends {Error}
72
+ */
73
+ class MissingClientSecretError extends Error {
74
+ constructor() {
75
+ super("Client Secret must be setup. Check documentation");
76
+ this.name = "MissingClientSecretError";
77
+ }
78
+ }
79
+ exports.MissingClientSecretError = MissingClientSecretError;
80
+ /**
81
+ * Custom error class representing a missing api region error.
82
+ * @class
83
+ * @extends {Error}
84
+ */
85
+ class MissingRegionError extends Error {
86
+ constructor() {
87
+ super("Api region must be setup. Check documentation");
88
+ this.name = "MissingRegionError";
89
+ }
90
+ }
91
+ exports.MissingRegionError = MissingRegionError;
@@ -0,0 +1,4 @@
1
+ export { setup } from "./config.js";
2
+ export { authenticate } from "./auth.js";
3
+ export { request } from "./request.js";
4
+ export type { Asset, Character, Href, KeyId, KeyName, KeyNameId, LinkSelfHref, LocalizedString, NameId, Namespaces, RequestOptions, TypeName, } from "./types.js";
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.request = exports.authenticate = exports.setup = void 0;
4
+ var config_js_1 = require("./config.js");
5
+ Object.defineProperty(exports, "setup", { enumerable: true, get: function () { return config_js_1.setup; } });
6
+ var auth_js_1 = require("./auth.js");
7
+ Object.defineProperty(exports, "authenticate", { enumerable: true, get: function () { return auth_js_1.authenticate; } });
8
+ var request_js_1 = require("./request.js");
9
+ Object.defineProperty(exports, "request", { enumerable: true, get: function () { return request_js_1.request; } });
@@ -0,0 +1,13 @@
1
+ import type { RequestOptions } from "./types.js";
2
+ /**
3
+ * Makes an authenticated request to the API and handles potential errors.
4
+ * @param {RequestOptions} requestOptions - An object containing the following:
5
+ * * method: The HTTP method (e.g., "GET", "POST")
6
+ * * url: The API endpoint path.
7
+ * * namespace (optional): The Battlenet namespace for the request.
8
+ * * qs (optional): An object representing query string parameters.
9
+ * @returns {Promise<any>} The parsed JSON response from the API.
10
+ * @throws {APIError} If there is a problem fetching or the response is not successful.
11
+ * @throws {AuthenticationError} (Potentially) If authentication fails during the process.
12
+ */
13
+ export declare function request(requestOptions: RequestOptions): Promise<unknown>;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.request = void 0;
4
+ const config_js_1 = require("./config.js");
5
+ const auth_js_1 = require("./auth.js");
6
+ const errors_js_1 = require("./errors.js");
7
+ /**
8
+ * Makes an authenticated request to the API and handles potential errors.
9
+ * @param {RequestOptions} requestOptions - An object containing the following:
10
+ * * method: The HTTP method (e.g., "GET", "POST")
11
+ * * url: The API endpoint path.
12
+ * * namespace (optional): The Battlenet namespace for the request.
13
+ * * qs (optional): An object representing query string parameters.
14
+ * @returns {Promise<any>} The parsed JSON response from the API.
15
+ * @throws {APIError} If there is a problem fetching or the response is not successful.
16
+ * @throws {AuthenticationError} (Potentially) If authentication fails during the process.
17
+ */
18
+ async function request(requestOptions) {
19
+ if (!(0, auth_js_1.getauthConfig)().accessToken || ((0, auth_js_1.getauthConfig)().accessToken && (0, auth_js_1.getauthConfig)().tokenExpiration &&
20
+ new Date() < new Date((0, auth_js_1.getauthConfig)().tokenExpiration))) {
21
+ await (0, auth_js_1.authenticate)(true);
22
+ }
23
+ const { method, url, namespace } = requestOptions;
24
+ let { qs } = requestOptions;
25
+ if ((0, config_js_1.getSetup)().locale) {
26
+ qs = { ...{ locale: (0, config_js_1.getSetup)().locale }, ...qs };
27
+ }
28
+ const qsString = qs
29
+ ? Object.fromEntries(Object.entries(qs).filter(([, value]) => value !== undefined).map(([key, value]) => [key, value.toString()]))
30
+ : {};
31
+ const params = new URLSearchParams(qsString);
32
+ const headers = {
33
+ "Authorization": "Bearer " + (0, auth_js_1.getauthConfig)().accessToken,
34
+ };
35
+ if (namespace) {
36
+ headers["Battlenet-Namespace"] = `${namespace}-${(0, config_js_1.getSetup)().region}`;
37
+ }
38
+ const response = await fetch((0, config_js_1.apiBaseUrl)((0, config_js_1.getSetup)().region) + encodeURI(url) + (qsString ? "?" + params.toString() : ""), {
39
+ method: method,
40
+ headers: headers,
41
+ });
42
+ if (response.ok) {
43
+ return await response.json();
44
+ }
45
+ throw new errors_js_1.APIError("Problem fetching data from API", response.status, response.statusText);
46
+ }
47
+ exports.request = request;
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Represents the configuration options for an API request.
3
+ * @property {string} method - The HTTP method to use (currently restricted to "GET").
4
+ * @property {string} url - The API endpoint path.
5
+ * @property {Namespaces} [namespace] - The optional Battle.net namespace for the request.
6
+ * @property {Record<string, string | number>} [qs] - An optional object for query string parameters.
7
+ */
8
+ export interface RequestOptions {
9
+ method: "GET";
10
+ url: string;
11
+ namespace?: Namespaces;
12
+ qs?: Record<string, string | number>;
13
+ }
14
+ /**
15
+ * Supported Battle.net regions.
16
+ */
17
+ export type Regions = "us" | "eu" | "kr" | "tw" | "cn";
18
+ /**
19
+ * Supported locales for data.
20
+ */
21
+ export type Locales = "en_US" | "es_MX" | "pt_BR" | "en_GB" | "es_ES" | "fr_FR" | "ru_RU" | "de_DE" | "pt_PT" | "it_IT" | "ko_KR" | "zh_TW" | "zh_CN";
22
+ /**
23
+ * Available Battle.net namespaces.
24
+ */
25
+ export type Namespaces = "static" | "dynamic" | "profile";
26
+ /**
27
+ * Represents a reference (link) with a URL.
28
+ */
29
+ export interface Href {
30
+ /**
31
+ * The URL or address of the reference.
32
+ */
33
+ href: string;
34
+ }
35
+ /**
36
+ * Represents a self-referential link structure commonly found in API responses.
37
+ */
38
+ export interface LinkSelfHref {
39
+ self: Href;
40
+ }
41
+ /**
42
+ * Represents localized text. It can be either a string (if no locale was used) or a key-value object for multiple locales.
43
+ */
44
+ export interface LocalizedString {
45
+ name: string | Record<Locales, string>;
46
+ }
47
+ /**
48
+ * Represents an object with a key (link), ID and LocalizedString name.
49
+ */
50
+ export interface KeyNameId {
51
+ key: {
52
+ href: string;
53
+ };
54
+ name: LocalizedString;
55
+ id: number;
56
+ }
57
+ /**
58
+ * Represents an object with a key (link) and LocalizedString name.
59
+ */
60
+ export interface KeyName {
61
+ key: {
62
+ href: string;
63
+ };
64
+ name: LocalizedString;
65
+ }
66
+ /**
67
+ * Represents an object with a key (link) and ID.
68
+ */
69
+ export interface KeyId {
70
+ key: {
71
+ href: string;
72
+ };
73
+ id: number;
74
+ }
75
+ /**
76
+ * Represents an object with LocalizedString name and ID.
77
+ */
78
+ export interface NameId {
79
+ name: LocalizedString;
80
+ id: number;
81
+ }
82
+ /**
83
+ * Represents an object with a type and a LocalizedString name.
84
+ */
85
+ export interface TypeName {
86
+ type: string;
87
+ name: LocalizedString;
88
+ }
89
+ /**
90
+ * Represents a character profile.
91
+ */
92
+ export interface Character {
93
+ key?: {
94
+ href: string;
95
+ };
96
+ name: string;
97
+ id: number;
98
+ realm: {
99
+ key: {
100
+ href: string;
101
+ };
102
+ name: LocalizedString;
103
+ id: number;
104
+ slug: string;
105
+ };
106
+ level?: number;
107
+ playable_class?: KeyId;
108
+ playable_race?: KeyId;
109
+ }
110
+ /**
111
+ * Represents a generic asset within a system.
112
+ * @property {string} key - A unique identifier for the asset.
113
+ * @property {string} value - The value associated with the asset.
114
+ * @property {number} [file_data_id] - (Optional) The ID of the file data associated with the asset (if any).
115
+ */
116
+ export interface Asset {
117
+ key: string;
118
+ value: string;
119
+ file_data_id?: number;
120
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ //types.ts
3
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,32 @@
1
+ import type { LinkSelfHref } from "../../shared/index.js";
2
+ export interface League extends LinkSelfHref {
3
+ key: {
4
+ league_id: number;
5
+ season_id: number;
6
+ queue_id: number;
7
+ team_type: number;
8
+ };
9
+ tier: {
10
+ id: number;
11
+ division: {
12
+ id: number;
13
+ ladder_id: number;
14
+ member_count: number;
15
+ }[];
16
+ }[];
17
+ }
18
+ /**
19
+ * Returns data for the specified season, queue, team, and league.
20
+ *
21
+ * Notes from the battle.net docs:
22
+ * queueId: the standard available queueIds are: 1=WoL 1v1, 2=WoL 2v2, 3=WoL 3v3, 4=WoL 4v4, 101=HotS 1v1, 102=HotS 2v2, 103=HotS 3v3, 104=HotS 4v4, 201=LotV 1v1, 202=LotV 2v2, 203=LotV 3v3, 204=LotV 4v4, 206=LotV Archon. Note that other available queues may not be listed here.
23
+ * teamType: there are two available teamTypes: 0=arranged, 1=random.
24
+ * leagueId: available leagueIds are: 0=Bronze, 1=Silver, 2=Gold, 3=Platinum, 4=Diamond, 5=Master, 6=Grandmaster.
25
+ *
26
+ * @param seasonId - The season ID of the data to retrieve.
27
+ * @param queueId - The queue ID of the data to retrieve.
28
+ * @param teamType - The team type of the data to retrieve.
29
+ * @param leagueId - The league ID of the data to retrieve.
30
+ * @returns A promise that resolves to an object representing the data for a league.
31
+ */
32
+ export declare function leagueData(seasonId: number, queueId: number, teamType: number, leagueId: number): Promise<League>;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.leagueData = void 0;
4
+ const index_js_1 = require("../../shared/index.js");
5
+ /**
6
+ * Returns data for the specified season, queue, team, and league.
7
+ *
8
+ * Notes from the battle.net docs:
9
+ * queueId: the standard available queueIds are: 1=WoL 1v1, 2=WoL 2v2, 3=WoL 3v3, 4=WoL 4v4, 101=HotS 1v1, 102=HotS 2v2, 103=HotS 3v3, 104=HotS 4v4, 201=LotV 1v1, 202=LotV 2v2, 203=LotV 3v3, 204=LotV 4v4, 206=LotV Archon. Note that other available queues may not be listed here.
10
+ * teamType: there are two available teamTypes: 0=arranged, 1=random.
11
+ * leagueId: available leagueIds are: 0=Bronze, 1=Silver, 2=Gold, 3=Platinum, 4=Diamond, 5=Master, 6=Grandmaster.
12
+ *
13
+ * @param seasonId - The season ID of the data to retrieve.
14
+ * @param queueId - The queue ID of the data to retrieve.
15
+ * @param teamType - The team type of the data to retrieve.
16
+ * @param leagueId - The league ID of the data to retrieve.
17
+ * @returns A promise that resolves to an object representing the data for a league.
18
+ */
19
+ async function leagueData(seasonId, queueId, teamType, leagueId) {
20
+ return await (0, index_js_1.request)({
21
+ method: "GET",
22
+ url: `/data/sc2/league/${seasonId}/${queueId}/${teamType}/${leagueId}`,
23
+ });
24
+ }
25
+ exports.leagueData = leagueData;
@@ -0,0 +1 @@
1
+ export { leagueData } from "./game_data/league.js";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.leagueData = void 0;
4
+ var league_js_1 = require("./game_data/league.js");
5
+ Object.defineProperty(exports, "leagueData", { enumerable: true, get: function () { return league_js_1.leagueData; } });