@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.
- package/LICENSE +21 -0
- package/README.md +61 -0
- package/esm/mod.d.ts +5 -0
- package/esm/mod.js +5 -0
- package/esm/package.json +3 -0
- package/esm/src/hearthstone/game_data/card_backs.d.ts +22 -0
- package/esm/src/hearthstone/game_data/card_backs.js +23 -0
- package/esm/src/hearthstone/game_data/cards.d.ts +37 -0
- package/esm/src/hearthstone/game_data/cards.js +27 -0
- package/esm/src/hearthstone/game_data/decks.d.ts +88 -0
- package/esm/src/hearthstone/game_data/decks.js +14 -0
- package/esm/src/hearthstone/game_data/metadata.d.ts +95 -0
- package/esm/src/hearthstone/game_data/metadata.js +12 -0
- package/esm/src/hearthstone/index.d.ts +4 -0
- package/esm/src/hearthstone/index.js +4 -0
- package/esm/src/hearthstone/search.d.ts +20 -0
- package/esm/src/hearthstone/search.js +29 -0
- package/esm/src/shared/auth.d.ts +24 -0
- package/esm/src/shared/auth.js +58 -0
- package/esm/src/shared/config.d.ts +40 -0
- package/esm/src/shared/config.js +48 -0
- package/esm/src/shared/errors.d.ts +44 -0
- package/esm/src/shared/errors.js +83 -0
- package/esm/src/shared/index.d.ts +4 -0
- package/esm/src/shared/index.js +3 -0
- package/esm/src/shared/request.d.ts +13 -0
- package/esm/src/shared/request.js +43 -0
- package/esm/src/shared/types.d.ts +120 -0
- package/esm/src/shared/types.js +2 -0
- package/esm/src/starcraft2/game_data/league.d.ts +32 -0
- package/esm/src/starcraft2/game_data/league.js +21 -0
- package/esm/src/starcraft2/index.d.ts +1 -0
- package/esm/src/starcraft2/index.js +1 -0
- package/esm/src/wow/game_data/achievement.d.ts +84 -0
- package/esm/src/wow/game_data/achievement.js +69 -0
- package/esm/src/wow/game_data/auction_house.d.ts +64 -0
- package/esm/src/wow/game_data/auction_house.js +34 -0
- package/esm/src/wow/game_data/azerite_essence.d.ts +49 -0
- package/esm/src/wow/game_data/azerite_essence.js +49 -0
- package/esm/src/wow/game_data/connected_realm.d.ts +54 -0
- package/esm/src/wow/game_data/connected_realm.js +36 -0
- package/esm/src/wow/game_data/covenant.d.ts +108 -0
- package/esm/src/wow/game_data/covenant.js +89 -0
- package/esm/src/wow/game_data/creature.d.ts +97 -0
- package/esm/src/wow/game_data/creature.js +100 -0
- package/esm/src/wow/game_data/guild_crest.d.ts +55 -0
- package/esm/src/wow/game_data/guild_crest.js +39 -0
- package/esm/src/wow/game_data/heirloom.d.ts +79 -0
- package/esm/src/wow/game_data/heirloom.js +26 -0
- package/esm/src/wow/game_data/item.d.ts +166 -0
- package/esm/src/wow/game_data/item.js +101 -0
- package/esm/src/wow/game_data/journal.d.ts +121 -0
- package/esm/src/wow/game_data/journal.js +99 -0
- package/esm/src/wow/game_data/keystone_affix.d.ts +34 -0
- package/esm/src/wow/game_data/keystone_affix.js +39 -0
- package/esm/src/wow/game_data/media_search.d.ts +8 -0
- package/esm/src/wow/game_data/media_search.js +10 -0
- package/esm/src/wow/game_data/modified_crafting.d.ts +56 -0
- package/esm/src/wow/game_data/modified_crafting.js +63 -0
- package/esm/src/wow/game_data/mount.d.ts +30 -0
- package/esm/src/wow/game_data/mount.js +30 -0
- package/esm/src/wow/game_data/mythic_keystone_dungeon.d.ts +91 -0
- package/esm/src/wow/game_data/mythic_keystone_dungeon.js +88 -0
- package/esm/src/wow/game_data/mythic_keystone_leaderboard.d.ts +58 -0
- package/esm/src/wow/game_data/mythic_keystone_leaderboard.js +29 -0
- package/esm/src/wow/game_data/mythic_raid_leaderboard.d.ts +31 -0
- package/esm/src/wow/game_data/mythic_raid_leaderboard.js +15 -0
- package/esm/src/wow/game_data/pet.d.ts +91 -0
- package/esm/src/wow/game_data/pet.js +77 -0
- package/esm/src/wow/game_data/playable_class.d.ts +57 -0
- package/esm/src/wow/game_data/playable_class.js +52 -0
- package/esm/src/wow/game_data/playable_race.d.ts +29 -0
- package/esm/src/wow/game_data/playable_race.js +26 -0
- package/esm/src/wow/game_data/power_type.d.ts +21 -0
- package/esm/src/wow/game_data/power_type.js +26 -0
- package/esm/src/wow/game_data/profession.d.ts +85 -0
- package/esm/src/wow/game_data/profession.js +79 -0
- package/esm/src/wow/game_data/pvp_season.d.ts +99 -0
- package/esm/src/wow/game_data/pvp_season.js +66 -0
- package/esm/src/wow/game_data/pvp_tier.d.ts +40 -0
- package/esm/src/wow/game_data/pvp_tier.js +39 -0
- package/esm/src/wow/game_data/quest.d.ts +114 -0
- package/esm/src/wow/game_data/quest.js +101 -0
- package/esm/src/wow/game_data/realm.d.ts +42 -0
- package/esm/src/wow/game_data/realm.js +36 -0
- package/esm/src/wow/game_data/region.d.ts +24 -0
- package/esm/src/wow/game_data/region.js +26 -0
- package/esm/src/wow/game_data/reputations.d.ts +50 -0
- package/esm/src/wow/game_data/reputations.js +51 -0
- package/esm/src/wow/game_data/spell.d.ts +33 -0
- package/esm/src/wow/game_data/spell.js +37 -0
- package/esm/src/wow/game_data/talent.d.ts +129 -0
- package/esm/src/wow/game_data/talent.js +90 -0
- package/esm/src/wow/game_data/tech_talent.d.ts +70 -0
- package/esm/src/wow/game_data/tech_talent.js +64 -0
- package/esm/src/wow/game_data/title.d.ts +25 -0
- package/esm/src/wow/game_data/title.js +26 -0
- package/esm/src/wow/game_data/token.d.ts +16 -0
- package/esm/src/wow/game_data/token.js +19 -0
- package/esm/src/wow/game_data/toy.d.ts +24 -0
- package/esm/src/wow/game_data/toy.js +26 -0
- package/esm/src/wow/index.d.ts +53 -0
- package/esm/src/wow/index.js +55 -0
- package/esm/src/wow/profile/character_achievements.d.ts +87 -0
- package/esm/src/wow/profile/character_achievements.js +29 -0
- package/esm/src/wow/profile/character_appearance.d.ts +75 -0
- package/esm/src/wow/profile/character_appearance.js +15 -0
- package/esm/src/wow/profile/character_collections.d.ts +92 -0
- package/esm/src/wow/profile/character_collections.js +71 -0
- package/esm/src/wow/profile/character_encounters.d.ts +77 -0
- package/esm/src/wow/profile/character_encounters.js +43 -0
- package/esm/src/wow/profile/character_equipment.d.ts +132 -0
- package/esm/src/wow/profile/character_equipment.js +15 -0
- package/esm/src/wow/profile/character_hunter_pets.d.ts +21 -0
- package/esm/src/wow/profile/character_hunter_pets.js +15 -0
- package/esm/src/wow/profile/character_media.d.ts +13 -0
- package/esm/src/wow/profile/character_media.js +15 -0
- package/esm/src/wow/profile/character_mythic_keystone_profile.d.ts +58 -0
- package/esm/src/wow/profile/character_mythic_keystone_profile.js +32 -0
- package/esm/src/wow/profile/character_professions.d.ts +26 -0
- package/esm/src/wow/profile/character_professions.js +15 -0
- package/esm/src/wow/profile/character_profile.d.ts +82 -0
- package/esm/src/wow/profile/character_profile.js +40 -0
- package/esm/src/wow/profile/character_pvp.d.ts +51 -0
- package/esm/src/wow/profile/character_pvp.js +30 -0
- package/esm/src/wow/profile/character_quests.d.ts +28 -0
- package/esm/src/wow/profile/character_quests.js +29 -0
- package/esm/src/wow/profile/character_reputations.d.ts +22 -0
- package/esm/src/wow/profile/character_reputations.js +15 -0
- package/esm/src/wow/profile/character_soulbinds.d.ts +30 -0
- package/esm/src/wow/profile/character_soulbinds.js +15 -0
- package/esm/src/wow/profile/character_specializations.d.ts +44 -0
- package/esm/src/wow/profile/character_specializations.js +15 -0
- package/esm/src/wow/profile/character_statistics.d.ts +116 -0
- package/esm/src/wow/profile/character_statistics.js +15 -0
- package/esm/src/wow/profile/character_titles.d.ts +13 -0
- package/esm/src/wow/profile/character_titles.js +15 -0
- package/esm/src/wow/profile/guild.d.ts +117 -0
- package/esm/src/wow/profile/guild.js +57 -0
- package/esm/src/wow/search.d.ts +21 -0
- package/esm/src/wow/search.js +30 -0
- package/package.json +36 -0
- package/script/mod.d.ts +5 -0
- package/script/mod.js +35 -0
- package/script/package.json +3 -0
- package/script/src/hearthstone/game_data/card_backs.d.ts +22 -0
- package/script/src/hearthstone/game_data/card_backs.js +28 -0
- package/script/src/hearthstone/game_data/cards.d.ts +37 -0
- package/script/src/hearthstone/game_data/cards.js +32 -0
- package/script/src/hearthstone/game_data/decks.d.ts +88 -0
- package/script/src/hearthstone/game_data/decks.js +18 -0
- package/script/src/hearthstone/game_data/metadata.d.ts +95 -0
- package/script/src/hearthstone/game_data/metadata.js +16 -0
- package/script/src/hearthstone/index.d.ts +4 -0
- package/script/src/hearthstone/index.js +13 -0
- package/script/src/hearthstone/search.d.ts +20 -0
- package/script/src/hearthstone/search.js +33 -0
- package/script/src/shared/auth.d.ts +24 -0
- package/script/src/shared/auth.js +63 -0
- package/script/src/shared/config.d.ts +40 -0
- package/script/src/shared/config.js +55 -0
- package/script/src/shared/errors.d.ts +44 -0
- package/script/src/shared/errors.js +91 -0
- package/script/src/shared/index.d.ts +4 -0
- package/script/src/shared/index.js +9 -0
- package/script/src/shared/request.d.ts +13 -0
- package/script/src/shared/request.js +47 -0
- package/script/src/shared/types.d.ts +120 -0
- package/script/src/shared/types.js +3 -0
- package/script/src/starcraft2/game_data/league.d.ts +32 -0
- package/script/src/starcraft2/game_data/league.js +25 -0
- package/script/src/starcraft2/index.d.ts +1 -0
- package/script/src/starcraft2/index.js +5 -0
- package/script/src/wow/game_data/achievement.d.ts +84 -0
- package/script/src/wow/game_data/achievement.js +77 -0
- package/script/src/wow/game_data/auction_house.d.ts +64 -0
- package/script/src/wow/game_data/auction_house.js +39 -0
- package/script/src/wow/game_data/azerite_essence.d.ts +49 -0
- package/script/src/wow/game_data/azerite_essence.js +56 -0
- package/script/src/wow/game_data/connected_realm.d.ts +54 -0
- package/script/src/wow/game_data/connected_realm.js +42 -0
- package/script/src/wow/game_data/covenant.d.ts +108 -0
- package/script/src/wow/game_data/covenant.js +99 -0
- package/script/src/wow/game_data/creature.d.ts +97 -0
- package/script/src/wow/game_data/creature.js +111 -0
- package/script/src/wow/game_data/guild_crest.d.ts +55 -0
- package/script/src/wow/game_data/guild_crest.js +45 -0
- package/script/src/wow/game_data/heirloom.d.ts +79 -0
- package/script/src/wow/game_data/heirloom.js +31 -0
- package/script/src/wow/game_data/item.d.ts +166 -0
- package/script/src/wow/game_data/item.js +112 -0
- package/script/src/wow/game_data/journal.d.ts +121 -0
- package/script/src/wow/game_data/journal.js +110 -0
- package/script/src/wow/game_data/keystone_affix.d.ts +34 -0
- package/script/src/wow/game_data/keystone_affix.js +45 -0
- package/script/src/wow/game_data/media_search.d.ts +8 -0
- package/script/src/wow/game_data/media_search.js +14 -0
- package/script/src/wow/game_data/modified_crafting.d.ts +56 -0
- package/script/src/wow/game_data/modified_crafting.js +71 -0
- package/script/src/wow/game_data/mount.d.ts +30 -0
- package/script/src/wow/game_data/mount.js +36 -0
- package/script/src/wow/game_data/mythic_keystone_dungeon.d.ts +91 -0
- package/script/src/wow/game_data/mythic_keystone_dungeon.js +98 -0
- package/script/src/wow/game_data/mythic_keystone_leaderboard.d.ts +58 -0
- package/script/src/wow/game_data/mythic_keystone_leaderboard.js +34 -0
- package/script/src/wow/game_data/mythic_raid_leaderboard.d.ts +31 -0
- package/script/src/wow/game_data/mythic_raid_leaderboard.js +19 -0
- package/script/src/wow/game_data/pet.d.ts +91 -0
- package/script/src/wow/game_data/pet.js +86 -0
- package/script/src/wow/game_data/playable_class.d.ts +57 -0
- package/script/src/wow/game_data/playable_class.js +59 -0
- package/script/src/wow/game_data/playable_race.d.ts +29 -0
- package/script/src/wow/game_data/playable_race.js +31 -0
- package/script/src/wow/game_data/power_type.d.ts +21 -0
- package/script/src/wow/game_data/power_type.js +31 -0
- package/script/src/wow/game_data/profession.d.ts +85 -0
- package/script/src/wow/game_data/profession.js +88 -0
- package/script/src/wow/game_data/pvp_season.d.ts +99 -0
- package/script/src/wow/game_data/pvp_season.js +74 -0
- package/script/src/wow/game_data/pvp_tier.d.ts +40 -0
- package/script/src/wow/game_data/pvp_tier.js +45 -0
- package/script/src/wow/game_data/quest.d.ts +114 -0
- package/script/src/wow/game_data/quest.js +112 -0
- package/script/src/wow/game_data/realm.d.ts +42 -0
- package/script/src/wow/game_data/realm.js +42 -0
- package/script/src/wow/game_data/region.d.ts +24 -0
- package/script/src/wow/game_data/region.js +31 -0
- package/script/src/wow/game_data/reputations.d.ts +50 -0
- package/script/src/wow/game_data/reputations.js +58 -0
- package/script/src/wow/game_data/spell.d.ts +33 -0
- package/script/src/wow/game_data/spell.js +43 -0
- package/script/src/wow/game_data/talent.d.ts +129 -0
- package/script/src/wow/game_data/talent.js +100 -0
- package/script/src/wow/game_data/tech_talent.d.ts +70 -0
- package/script/src/wow/game_data/tech_talent.js +72 -0
- package/script/src/wow/game_data/title.d.ts +25 -0
- package/script/src/wow/game_data/title.js +31 -0
- package/script/src/wow/game_data/token.d.ts +16 -0
- package/script/src/wow/game_data/token.js +23 -0
- package/script/src/wow/game_data/toy.d.ts +24 -0
- package/script/src/wow/game_data/toy.js +31 -0
- package/script/src/wow/index.d.ts +53 -0
- package/script/src/wow/index.js +228 -0
- package/script/src/wow/profile/character_achievements.d.ts +87 -0
- package/script/src/wow/profile/character_achievements.js +34 -0
- package/script/src/wow/profile/character_appearance.d.ts +75 -0
- package/script/src/wow/profile/character_appearance.js +19 -0
- package/script/src/wow/profile/character_collections.d.ts +92 -0
- package/script/src/wow/profile/character_collections.js +79 -0
- package/script/src/wow/profile/character_encounters.d.ts +77 -0
- package/script/src/wow/profile/character_encounters.js +49 -0
- package/script/src/wow/profile/character_equipment.d.ts +132 -0
- package/script/src/wow/profile/character_equipment.js +19 -0
- package/script/src/wow/profile/character_hunter_pets.d.ts +21 -0
- package/script/src/wow/profile/character_hunter_pets.js +19 -0
- package/script/src/wow/profile/character_media.d.ts +13 -0
- package/script/src/wow/profile/character_media.js +19 -0
- package/script/src/wow/profile/character_mythic_keystone_profile.d.ts +58 -0
- package/script/src/wow/profile/character_mythic_keystone_profile.js +37 -0
- package/script/src/wow/profile/character_professions.d.ts +26 -0
- package/script/src/wow/profile/character_professions.js +19 -0
- package/script/src/wow/profile/character_profile.d.ts +82 -0
- package/script/src/wow/profile/character_profile.js +45 -0
- package/script/src/wow/profile/character_pvp.d.ts +51 -0
- package/script/src/wow/profile/character_pvp.js +35 -0
- package/script/src/wow/profile/character_quests.d.ts +28 -0
- package/script/src/wow/profile/character_quests.js +34 -0
- package/script/src/wow/profile/character_reputations.d.ts +22 -0
- package/script/src/wow/profile/character_reputations.js +19 -0
- package/script/src/wow/profile/character_soulbinds.d.ts +30 -0
- package/script/src/wow/profile/character_soulbinds.js +19 -0
- package/script/src/wow/profile/character_specializations.d.ts +44 -0
- package/script/src/wow/profile/character_specializations.js +19 -0
- package/script/src/wow/profile/character_statistics.d.ts +116 -0
- package/script/src/wow/profile/character_statistics.js +19 -0
- package/script/src/wow/profile/character_titles.d.ts +13 -0
- package/script/src/wow/profile/character_titles.js +19 -0
- package/script/src/wow/profile/guild.d.ts +117 -0
- package/script/src/wow/profile/guild.js +64 -0
- package/script/src/wow/search.d.ts +21 -0
- package/script/src/wow/search.js +34 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Pinta <https://github.com/Pinta365>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# BLIZZARD_API
|
|
2
|
+
|
|
3
|
+
[](https://jsr.io/@pinta365/blizzard-api)
|
|
4
|
+
|
|
5
|
+
Start of what will cover the whole Blizzard Battle.net API when its done.
|
|
6
|
+
|
|
7
|
+
Link to the module on [JSR](https://jsr.io/@pinta365/blizzard-api)
|
|
8
|
+
|
|
9
|
+
## WORK IN PROGRESS
|
|
10
|
+
|
|
11
|
+
Let me know if you want certain APIs to be prioritized. Currently only supports client credentials flow but the plan is
|
|
12
|
+
to implement authorization code flow also.
|
|
13
|
+
|
|
14
|
+
### APIs implemented
|
|
15
|
+
|
|
16
|
+
| APIs | Status | Note |
|
|
17
|
+
| --------------------------------------------- | ------ | ------------------------- |
|
|
18
|
+
| **World of Warcraft:** Game Data APIs | ✅ | |
|
|
19
|
+
| **World of Warcraft:** Profile APIs | ✅ | |
|
|
20
|
+
| | | |
|
|
21
|
+
| **World of Warcraft Classic:** Game Data APIs | | |
|
|
22
|
+
| | | |
|
|
23
|
+
| **Diablo III:** Community APIs | ✅ | Missing profile endpoints |
|
|
24
|
+
| **Diablo III:** Game Data APIs | ✅ | |
|
|
25
|
+
| | | |
|
|
26
|
+
| **Hearthstone:** Game Data APIs | ✅ | |
|
|
27
|
+
| | | |
|
|
28
|
+
| **StarCraft II:** Community APIs | | |
|
|
29
|
+
| **StarCraft II:** Game Data APIs | ✅ | |
|
|
30
|
+
|
|
31
|
+
## Example
|
|
32
|
+
|
|
33
|
+
```javascript
|
|
34
|
+
import * as blizzardAPI from "@pinta365/blizzard-api";
|
|
35
|
+
|
|
36
|
+
const clientId = "<YOUR CLIENT ID>";
|
|
37
|
+
const clientSecret = "<YOUR SECRET>";
|
|
38
|
+
|
|
39
|
+
blizzardAPI.setup({
|
|
40
|
+
clientId,
|
|
41
|
+
clientSecret,
|
|
42
|
+
region: "eu",
|
|
43
|
+
locale: "en_GB",
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
const sword = await blizzardAPI.wow.item(33791);
|
|
48
|
+
console.log(sword);
|
|
49
|
+
} catch (error) {
|
|
50
|
+
console.log(error);
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Issues
|
|
55
|
+
|
|
56
|
+
Issues or questions concerning the library can be raised at the
|
|
57
|
+
[github repository](https://github.com/Pinta365/blizzard_api/issues) page.
|
|
58
|
+
|
|
59
|
+
## License
|
|
60
|
+
|
|
61
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
package/esm/mod.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { authenticate, setup } from "./src/shared/index.js";
|
|
2
|
+
import * as wow from "./src/wow/index.js";
|
|
3
|
+
import * as hearthstone from "./src/hearthstone/index.js";
|
|
4
|
+
import * as sc2 from "./src/starcraft2/index.js";
|
|
5
|
+
export { authenticate, hearthstone, sc2, setup, wow };
|
package/esm/mod.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { authenticate, setup } from "./src/shared/index.js";
|
|
2
|
+
import * as wow from "./src/wow/index.js";
|
|
3
|
+
import * as hearthstone from "./src/hearthstone/index.js";
|
|
4
|
+
import * as sc2 from "./src/starcraft2/index.js";
|
|
5
|
+
export { authenticate, hearthstone, sc2, setup, wow };
|
package/esm/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { LocalizedString } from "../../shared/index.js";
|
|
2
|
+
import type { Search, SearchParameters } from "../search.js";
|
|
3
|
+
export interface Cardback {
|
|
4
|
+
id: number;
|
|
5
|
+
sortCategory: number;
|
|
6
|
+
text: LocalizedString;
|
|
7
|
+
name: LocalizedString;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Returns an up-to-date list of all card backs matching the search criteria.
|
|
11
|
+
*
|
|
12
|
+
* @param SearchParameters - Object containing search parameters.
|
|
13
|
+
* @returns A promise that resolves to an object representing an up-to-date list of all card backs matching the search criteria.
|
|
14
|
+
*/
|
|
15
|
+
export declare function searchCardbacks(searchParameters: SearchParameters): Promise<Search>;
|
|
16
|
+
/**
|
|
17
|
+
* Returns the card back with an ID or slug that matches the one you specify.
|
|
18
|
+
*
|
|
19
|
+
* @param idorslug - The unique identifier for the card back by slug.
|
|
20
|
+
* @returns A promise that resolves to an object representing details about a card back.
|
|
21
|
+
*/
|
|
22
|
+
export declare function fetchCardback(idorslug: string): Promise<Cardback>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { request } from "../../shared/index.js";
|
|
2
|
+
import { search } from "../search.js";
|
|
3
|
+
/**
|
|
4
|
+
* Returns an up-to-date list of all card backs matching the search criteria.
|
|
5
|
+
*
|
|
6
|
+
* @param SearchParameters - Object containing search parameters.
|
|
7
|
+
* @returns A promise that resolves to an object representing an up-to-date list of all card backs matching the search criteria.
|
|
8
|
+
*/
|
|
9
|
+
export async function searchCardbacks(searchParameters) {
|
|
10
|
+
return await search("/cardback", searchParameters);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Returns the card back with an ID or slug that matches the one you specify.
|
|
14
|
+
*
|
|
15
|
+
* @param idorslug - The unique identifier for the card back by slug.
|
|
16
|
+
* @returns A promise that resolves to an object representing details about a card back.
|
|
17
|
+
*/
|
|
18
|
+
export async function fetchCardback(idorslug) {
|
|
19
|
+
return await request({
|
|
20
|
+
method: "GET",
|
|
21
|
+
url: `/hearthstone/cardback/${idorslug}`,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { LocalizedString } from "../../shared/index.js";
|
|
2
|
+
import type { Search, SearchParameters } from "../search.js";
|
|
3
|
+
export interface Card {
|
|
4
|
+
id: number;
|
|
5
|
+
collectible: number;
|
|
6
|
+
slug: string;
|
|
7
|
+
classId: number;
|
|
8
|
+
multiClassIds: number[];
|
|
9
|
+
cardTypeId: number;
|
|
10
|
+
cardSetId: number;
|
|
11
|
+
rarityId: number;
|
|
12
|
+
artistName: string;
|
|
13
|
+
health: number;
|
|
14
|
+
attack: number;
|
|
15
|
+
manaCost: number;
|
|
16
|
+
name: LocalizedString;
|
|
17
|
+
text: LocalizedString;
|
|
18
|
+
image: string;
|
|
19
|
+
imageGold: string;
|
|
20
|
+
flavorText: LocalizedString;
|
|
21
|
+
cropImage: string;
|
|
22
|
+
keywordIds: number[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Returns an up-to-date list of all cards matching the search criteria.
|
|
26
|
+
*
|
|
27
|
+
* @param SearchParameters - Object containing search parameters.
|
|
28
|
+
* @returns A promise that resolves to an object representing an up-to-date list of all cards matching the search criteria.
|
|
29
|
+
*/
|
|
30
|
+
export declare function searchCards(searchParameters: SearchParameters): Promise<Search>;
|
|
31
|
+
/**
|
|
32
|
+
* Returns the card with an ID or slug that matches the one you specify.
|
|
33
|
+
*
|
|
34
|
+
* @param idorslug - The unique identifier for the card by slug.
|
|
35
|
+
* @returns A promise that resolves to an object representing details about a card.
|
|
36
|
+
*/
|
|
37
|
+
export declare function fetchCard(idorslug: string, gameMode?: string): Promise<Card>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { request } from "../../shared/index.js";
|
|
2
|
+
import { search } from "../search.js";
|
|
3
|
+
/**
|
|
4
|
+
* Returns an up-to-date list of all cards matching the search criteria.
|
|
5
|
+
*
|
|
6
|
+
* @param SearchParameters - Object containing search parameters.
|
|
7
|
+
* @returns A promise that resolves to an object representing an up-to-date list of all cards matching the search criteria.
|
|
8
|
+
*/
|
|
9
|
+
export async function searchCards(searchParameters) {
|
|
10
|
+
return await search("/cards", searchParameters);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Returns the card with an ID or slug that matches the one you specify.
|
|
14
|
+
*
|
|
15
|
+
* @param idorslug - The unique identifier for the card by slug.
|
|
16
|
+
* @returns A promise that resolves to an object representing details about a card.
|
|
17
|
+
*/
|
|
18
|
+
export async function fetchCard(idorslug, gameMode) {
|
|
19
|
+
const reqOptions = {
|
|
20
|
+
method: "GET",
|
|
21
|
+
url: `/hearthstone/cards/${idorslug}`,
|
|
22
|
+
};
|
|
23
|
+
if (gameMode) {
|
|
24
|
+
reqOptions["qs"] = { gameMode };
|
|
25
|
+
}
|
|
26
|
+
return await request(reqOptions);
|
|
27
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { LocalizedString } from "../../shared/index.js";
|
|
2
|
+
export interface Options {
|
|
3
|
+
code?: string;
|
|
4
|
+
ids?: string;
|
|
5
|
+
hero?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface Deck {
|
|
8
|
+
deckCode: string;
|
|
9
|
+
version: number;
|
|
10
|
+
format: string;
|
|
11
|
+
hero: {
|
|
12
|
+
id: number;
|
|
13
|
+
collectible: number;
|
|
14
|
+
slug: string;
|
|
15
|
+
classId: number;
|
|
16
|
+
multiClassIds: number[];
|
|
17
|
+
cardTypeId: number;
|
|
18
|
+
cardSetId: number;
|
|
19
|
+
rarityId: number;
|
|
20
|
+
artistName: string;
|
|
21
|
+
health: number;
|
|
22
|
+
manaCost: number;
|
|
23
|
+
name: LocalizedString;
|
|
24
|
+
text: LocalizedString;
|
|
25
|
+
image: string;
|
|
26
|
+
imageGold: string;
|
|
27
|
+
flavorText: LocalizedString;
|
|
28
|
+
cropImage: string;
|
|
29
|
+
childIds: number[];
|
|
30
|
+
};
|
|
31
|
+
heroPower: {
|
|
32
|
+
id: number;
|
|
33
|
+
collectible: number;
|
|
34
|
+
slug: string;
|
|
35
|
+
classId: number;
|
|
36
|
+
multiClassIds: number[];
|
|
37
|
+
cardTypeId: number;
|
|
38
|
+
cardSetId: number;
|
|
39
|
+
rarityId: number;
|
|
40
|
+
artistName: null;
|
|
41
|
+
manaCost: number;
|
|
42
|
+
name: LocalizedString;
|
|
43
|
+
text: LocalizedString;
|
|
44
|
+
image: string;
|
|
45
|
+
imageGold: string;
|
|
46
|
+
flavorText: LocalizedString;
|
|
47
|
+
cropImage: string;
|
|
48
|
+
parentId: number;
|
|
49
|
+
};
|
|
50
|
+
class: {
|
|
51
|
+
slug: string;
|
|
52
|
+
id: number;
|
|
53
|
+
name: LocalizedString;
|
|
54
|
+
};
|
|
55
|
+
cards: {
|
|
56
|
+
id: number;
|
|
57
|
+
collectible: number;
|
|
58
|
+
slug: string;
|
|
59
|
+
classId: number;
|
|
60
|
+
multiClassIds: number[];
|
|
61
|
+
cardTypeId: number;
|
|
62
|
+
cardSetId: number;
|
|
63
|
+
rarityId: number;
|
|
64
|
+
artistName: string;
|
|
65
|
+
health: number;
|
|
66
|
+
attack: number;
|
|
67
|
+
manaCost: number;
|
|
68
|
+
name: LocalizedString;
|
|
69
|
+
text: LocalizedString;
|
|
70
|
+
image: string;
|
|
71
|
+
imageGold: string;
|
|
72
|
+
flavorText: LocalizedString;
|
|
73
|
+
cropImage: string;
|
|
74
|
+
copyOfCardId: number;
|
|
75
|
+
duels: {
|
|
76
|
+
relevant: boolean;
|
|
77
|
+
constructed: boolean;
|
|
78
|
+
};
|
|
79
|
+
}[];
|
|
80
|
+
cardCount: number;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Returns the card with an ID or slug that matches the one you specify.
|
|
84
|
+
*
|
|
85
|
+
* @param options - find parameters fort the search.
|
|
86
|
+
* @returns A promise that resolves to an object representing details about a card.
|
|
87
|
+
*/
|
|
88
|
+
export declare function fetchDeck(options?: Options): Promise<Deck>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { request } from "../../shared/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Returns the card with an ID or slug that matches the one you specify.
|
|
4
|
+
*
|
|
5
|
+
* @param options - find parameters fort the search.
|
|
6
|
+
* @returns A promise that resolves to an object representing details about a card.
|
|
7
|
+
*/
|
|
8
|
+
export async function fetchDeck(options) {
|
|
9
|
+
return await request({
|
|
10
|
+
method: "GET",
|
|
11
|
+
url: `/hearthstone/deck`,
|
|
12
|
+
qs: options,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { LocalizedString } from "../../shared/index.js";
|
|
2
|
+
export interface Metadata {
|
|
3
|
+
sets: {
|
|
4
|
+
id: number;
|
|
5
|
+
name: LocalizedString;
|
|
6
|
+
slug: string;
|
|
7
|
+
aliasSetIds?: number[];
|
|
8
|
+
type: string;
|
|
9
|
+
collectibleCount: number;
|
|
10
|
+
collectibleRevealedCount: number;
|
|
11
|
+
nonCollectibleCount: number;
|
|
12
|
+
nonCollectibleRevealedCount: number;
|
|
13
|
+
}[];
|
|
14
|
+
setGroups: {
|
|
15
|
+
slug: string;
|
|
16
|
+
year?: number;
|
|
17
|
+
svg?: string;
|
|
18
|
+
cardSets: string[];
|
|
19
|
+
name: LocalizedString;
|
|
20
|
+
standard?: boolean;
|
|
21
|
+
yearRange?: string;
|
|
22
|
+
icon?: string;
|
|
23
|
+
}[];
|
|
24
|
+
gameModes: {
|
|
25
|
+
slug: string;
|
|
26
|
+
id: number;
|
|
27
|
+
name: LocalizedString;
|
|
28
|
+
}[];
|
|
29
|
+
arenaIds: number[];
|
|
30
|
+
types: {
|
|
31
|
+
slug: string;
|
|
32
|
+
id: number;
|
|
33
|
+
name: LocalizedString;
|
|
34
|
+
gameModes: number[];
|
|
35
|
+
}[];
|
|
36
|
+
rarities: {
|
|
37
|
+
slug: string;
|
|
38
|
+
id: number;
|
|
39
|
+
craftingCost: number[];
|
|
40
|
+
dustValue: number[];
|
|
41
|
+
name: LocalizedString;
|
|
42
|
+
}[];
|
|
43
|
+
classes: {
|
|
44
|
+
slug: string;
|
|
45
|
+
id: number;
|
|
46
|
+
name: LocalizedString;
|
|
47
|
+
cardId?: number;
|
|
48
|
+
heroPowerCardId?: number;
|
|
49
|
+
alternateHeroCardIds?: number[];
|
|
50
|
+
}[];
|
|
51
|
+
minionTypes: {
|
|
52
|
+
slug: string;
|
|
53
|
+
id: number;
|
|
54
|
+
name: LocalizedString;
|
|
55
|
+
gameModes: number[];
|
|
56
|
+
}[];
|
|
57
|
+
spellSchools: {
|
|
58
|
+
slug: string;
|
|
59
|
+
id: number;
|
|
60
|
+
name: LocalizedString;
|
|
61
|
+
}[];
|
|
62
|
+
mercenaryRoles: {
|
|
63
|
+
slug: string;
|
|
64
|
+
id: number;
|
|
65
|
+
name: LocalizedString;
|
|
66
|
+
}[];
|
|
67
|
+
mercenaryFactions: {
|
|
68
|
+
slug: string;
|
|
69
|
+
id: number;
|
|
70
|
+
name: LocalizedString;
|
|
71
|
+
}[];
|
|
72
|
+
keywords: {
|
|
73
|
+
id: number;
|
|
74
|
+
slug: string;
|
|
75
|
+
name: LocalizedString;
|
|
76
|
+
refText: LocalizedString;
|
|
77
|
+
text: LocalizedString;
|
|
78
|
+
gameModes: number[];
|
|
79
|
+
}[];
|
|
80
|
+
filterableFields: string[];
|
|
81
|
+
numericFields: string[];
|
|
82
|
+
cardBackCategories: {
|
|
83
|
+
slug: string;
|
|
84
|
+
id: number;
|
|
85
|
+
name: LocalizedString;
|
|
86
|
+
}[];
|
|
87
|
+
}
|
|
88
|
+
type MetaTypes = "sets" | "setGroups" | "types" | "rarities" | "classes" | "minionTypes" | "keywords";
|
|
89
|
+
/**
|
|
90
|
+
* Returns information about the categorization of cards. Metadata includes the card set, set group (for example, Standard or Year of the Dragon), rarity, class, card type, minion type, and keywords.
|
|
91
|
+
*
|
|
92
|
+
* @returns A promise that resolves to an object representing the Metadata.
|
|
93
|
+
*/
|
|
94
|
+
export declare function metadata(type: MetaTypes): Promise<Partial<Metadata>>;
|
|
95
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { request } from "../../shared/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Returns information about the categorization of cards. Metadata includes the card set, set group (for example, Standard or Year of the Dragon), rarity, class, card type, minion type, and keywords.
|
|
4
|
+
*
|
|
5
|
+
* @returns A promise that resolves to an object representing the Metadata.
|
|
6
|
+
*/
|
|
7
|
+
export async function metadata(type) {
|
|
8
|
+
return await request({
|
|
9
|
+
method: "GET",
|
|
10
|
+
url: `/hearthstone/metadata/${type}`,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
@@ -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,29 @@
|
|
|
1
|
+
import { request } from "../shared/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Performs a search.
|
|
4
|
+
*
|
|
5
|
+
* @param SearchParameters - Object containing search parameters.
|
|
6
|
+
* @returns A promise that resolves to an object representing details about the search.
|
|
7
|
+
*/
|
|
8
|
+
export async function search(url, searchParameters) {
|
|
9
|
+
const searchFields = searchParameters.searchFields
|
|
10
|
+
? Object.fromEntries(Object.entries(searchParameters.searchFields).map(([key, value]) => [key, value.toString()]))
|
|
11
|
+
: undefined;
|
|
12
|
+
const qs = {
|
|
13
|
+
...searchFields,
|
|
14
|
+
};
|
|
15
|
+
if (searchParameters.sort) {
|
|
16
|
+
qs.sort = searchParameters.sort;
|
|
17
|
+
}
|
|
18
|
+
if (searchParameters.page !== undefined) {
|
|
19
|
+
qs.page = searchParameters.page;
|
|
20
|
+
}
|
|
21
|
+
if (searchParameters.pageSize !== undefined) {
|
|
22
|
+
qs.pageSize = searchParameters.pageSize;
|
|
23
|
+
}
|
|
24
|
+
return await request({
|
|
25
|
+
method: "GET",
|
|
26
|
+
url: `/hearthstone${url}`,
|
|
27
|
+
qs,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
@@ -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,58 @@
|
|
|
1
|
+
//auth.ts
|
|
2
|
+
import { getSetup, tokenUrl } from "./config.js";
|
|
3
|
+
import { AuthenticationError, MissingClientIdError, MissingClientSecretError, MissingRegionError } from "./errors.js";
|
|
4
|
+
/**
|
|
5
|
+
* Global storage for authentication configuration data.
|
|
6
|
+
*/
|
|
7
|
+
const authConfig = {
|
|
8
|
+
accessToken: "",
|
|
9
|
+
tokenExpiration: 0,
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Retrieves the global authentication configuration.
|
|
13
|
+
* @returns {AuthConfig} The authentication configuration object.
|
|
14
|
+
*/
|
|
15
|
+
export function getauthConfig() {
|
|
16
|
+
return authConfig;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Handles authentication and obtains an access token if needed.
|
|
20
|
+
* @param {boolean} forceNewToken - If true, forces the retrieval of a new token, ignoring any existing one.
|
|
21
|
+
* @returns {Promise<string>} Returns the access token (string).
|
|
22
|
+
* @throws {MissingRegionError} If the region is not configured.
|
|
23
|
+
* @throws {MissingClientIdError} If the client ID is not configured.
|
|
24
|
+
* @throws {MissingClientSecretError} If the client secret is not configured.
|
|
25
|
+
* @throws {AuthenticationError} If there is a problem during the authentication process.
|
|
26
|
+
*/
|
|
27
|
+
export async function authenticate(forceNewToken = false) {
|
|
28
|
+
if (!getSetup().region) {
|
|
29
|
+
throw new MissingRegionError();
|
|
30
|
+
}
|
|
31
|
+
if (!getSetup().clientId) {
|
|
32
|
+
throw new MissingClientIdError();
|
|
33
|
+
}
|
|
34
|
+
if (!getSetup().clientSecret) {
|
|
35
|
+
throw new MissingClientSecretError();
|
|
36
|
+
}
|
|
37
|
+
if (!forceNewToken && authConfig.accessToken && authConfig.tokenExpiration &&
|
|
38
|
+
new Date() < new Date(authConfig.tokenExpiration)) {
|
|
39
|
+
return authConfig.accessToken;
|
|
40
|
+
}
|
|
41
|
+
const response = await fetch(tokenUrl(getSetup().region), {
|
|
42
|
+
method: "POST",
|
|
43
|
+
headers: {
|
|
44
|
+
"Authorization": "Basic " + btoa(`${getSetup().clientId}:${getSetup().clientSecret}`),
|
|
45
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
46
|
+
},
|
|
47
|
+
body: "grant_type=client_credentials",
|
|
48
|
+
});
|
|
49
|
+
if (response.ok) {
|
|
50
|
+
const data = await response.json();
|
|
51
|
+
authConfig.accessToken = data.access_token;
|
|
52
|
+
authConfig.tokenExpiration = Date.now() + data.expires_in * 1000;
|
|
53
|
+
return authConfig.accessToken;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
throw new AuthenticationError("Problem with Authentication", response.status, response.statusText);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -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,48 @@
|
|
|
1
|
+
import { MissingClientIdError, MissingClientSecretError, MissingRegionError } from "./errors.js";
|
|
2
|
+
/**
|
|
3
|
+
* Holds the partially loaded application configuration.
|
|
4
|
+
*/
|
|
5
|
+
let config = {};
|
|
6
|
+
/**
|
|
7
|
+
* Generates the OAuth token URL based on the specified region.
|
|
8
|
+
* @param {Regions} region - The target Battle.net region.
|
|
9
|
+
* @returns {string} The constructed token URL.
|
|
10
|
+
*/
|
|
11
|
+
export function tokenUrl(region) {
|
|
12
|
+
return region === "cn" ? "https://www.battlenet.com.cn/oauth/token" : `https://${region}.battle.net/oauth/token`;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Generates the base API URL based on the specified region.
|
|
16
|
+
* @param {Regions} region - The target Battle.net region.
|
|
17
|
+
* @returns {string} The constructed base API URL.
|
|
18
|
+
*/
|
|
19
|
+
export function apiBaseUrl(region) {
|
|
20
|
+
return region === "cn" ? "https://gateway.battlenet.com.cn" : `https://${region}.api.blizzard.com`;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Updates the application configuration and performs basic validation.
|
|
24
|
+
* @param {Partial<Config>} userConfig - An object containing configuration properties to update.
|
|
25
|
+
* @throws {MissingRegionError} If the region is not provided in the update.
|
|
26
|
+
* @throws {MissingClientIdError} If the client ID is not provided in the update.
|
|
27
|
+
* @throws {MissingClientSecretError} If the client secret is not provided in the update.
|
|
28
|
+
*/
|
|
29
|
+
export function setup(userConfig) {
|
|
30
|
+
config = { ...config, ...userConfig };
|
|
31
|
+
if (!config.region) {
|
|
32
|
+
throw new MissingRegionError();
|
|
33
|
+
}
|
|
34
|
+
if (!config.clientId) {
|
|
35
|
+
throw new MissingClientIdError();
|
|
36
|
+
}
|
|
37
|
+
if (!config.clientSecret) {
|
|
38
|
+
throw new MissingClientSecretError();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Retrieves the current application configuration.
|
|
43
|
+
* Note: The configuration may be partial if not fully setup.
|
|
44
|
+
* @returns {Config | Partial<Config>} The full or partially loaded configuration object.
|
|
45
|
+
*/
|
|
46
|
+
export function getSetup() {
|
|
47
|
+
return config;
|
|
48
|
+
}
|