@pinta365/blizzard_api 0.4.0 → 0.5.0
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 +0 -0
- package/README.md +145 -37
- package/esm/mod.d.ts +43 -6
- package/esm/mod.js +69 -6
- package/esm/src/client.d.ts +95 -0
- package/esm/src/client.js +52 -0
- package/esm/src/diablo3/community/act.d.ts +29 -0
- package/esm/src/diablo3/community/act.js +23 -0
- package/esm/src/diablo3/community/artisan.d.ts +50 -0
- package/esm/src/diablo3/community/artisan.js +25 -0
- package/esm/src/diablo3/community/follower.d.ts +25 -0
- package/esm/src/diablo3/community/follower.js +12 -0
- package/esm/src/diablo3/community/hero.d.ts +57 -0
- package/esm/src/diablo3/community/hero.js +25 -0
- package/esm/src/diablo3/community/item.d.ts +48 -0
- package/esm/src/diablo3/community/item.js +12 -0
- package/esm/src/diablo3/community/item_type.d.ts +26 -0
- package/esm/src/diablo3/community/item_type.js +23 -0
- package/esm/src/diablo3/community/profile.d.ts +352 -0
- package/esm/src/diablo3/community/profile.js +61 -0
- package/esm/src/diablo3/game_data/d3.d.ts +127 -0
- package/esm/src/diablo3/game_data/d3.js +72 -0
- package/esm/src/diablo3/index.d.ts +8 -0
- package/esm/src/diablo3/index.js +8 -0
- package/esm/src/diablo3/types.d.ts +8 -0
- package/esm/src/diablo3/types.js +1 -0
- package/esm/src/generated/diablo3_api.d.ts +156 -0
- package/esm/src/generated/diablo3_api.js +2 -0
- package/esm/src/generated/hearthstone_api.d.ts +51 -0
- package/esm/src/generated/hearthstone_api.js +2 -0
- package/esm/src/generated/sc2_api.d.ts +139 -0
- package/esm/src/generated/sc2_api.js +2 -0
- package/esm/src/generated/wow_api.d.ts +1482 -0
- package/esm/src/generated/wow_api.js +2 -0
- package/esm/src/generated/wow_classic_api.d.ts +555 -0
- package/esm/src/generated/wow_classic_api.js +2 -0
- package/esm/src/generated/wow_classic_era_api.d.ts +418 -0
- package/esm/src/generated/wow_classic_era_api.js +2 -0
- package/esm/src/hearthstone/game_data/card_backs.d.ts +31 -0
- package/esm/src/hearthstone/game_data/card_backs.js +22 -0
- package/esm/src/hearthstone/game_data/cards.d.ts +55 -0
- package/esm/src/hearthstone/game_data/cards.js +26 -0
- package/esm/src/hearthstone/game_data/decks.d.ts +29 -0
- package/esm/src/hearthstone/game_data/decks.js +13 -0
- package/esm/src/hearthstone/game_data/metadata.d.ts +82 -0
- package/esm/src/hearthstone/game_data/metadata.js +11 -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 +21 -0
- package/esm/src/hearthstone/search.js +28 -0
- package/esm/src/hearthstone/types.d.ts +5 -0
- package/esm/src/hearthstone/types.js +1 -0
- package/esm/src/shared/bind.d.ts +14 -0
- package/esm/src/shared/bind.js +15 -0
- package/esm/src/shared/context.d.ts +163 -0
- package/esm/src/shared/context.js +304 -0
- package/esm/src/shared/errors.d.ts +53 -0
- package/esm/src/shared/errors.js +95 -0
- package/esm/src/shared/index.d.ts +4 -0
- package/esm/src/shared/index.js +2 -0
- package/esm/src/shared/types.d.ts +133 -0
- package/esm/src/shared/types.js +2 -0
- package/esm/src/starcraft2/community/account.d.ts +19 -0
- package/esm/src/starcraft2/community/account.js +15 -0
- package/esm/src/starcraft2/community/ladder.d.ts +29 -0
- package/esm/src/starcraft2/community/ladder.js +27 -0
- package/esm/src/starcraft2/community/legacy.d.ts +206 -0
- package/esm/src/starcraft2/community/legacy.js +83 -0
- package/esm/src/starcraft2/community/profile.d.ts +255 -0
- package/esm/src/starcraft2/community/profile.js +73 -0
- package/esm/src/starcraft2/game_data/league.d.ts +35 -0
- package/esm/src/starcraft2/game_data/league.js +20 -0
- package/esm/src/starcraft2/index.d.ts +5 -0
- package/esm/src/starcraft2/index.js +5 -0
- package/esm/src/starcraft2/types.d.ts +5 -0
- package/esm/src/starcraft2/types.js +1 -0
- package/esm/src/wow/game_data/achievement.d.ts +87 -0
- package/esm/src/wow/game_data/achievement.js +68 -0
- package/esm/src/wow/game_data/auction_house.d.ts +65 -0
- package/esm/src/wow/game_data/auction_house.js +33 -0
- package/esm/src/wow/game_data/azerite_essence.d.ts +50 -0
- package/esm/src/wow/game_data/azerite_essence.js +48 -0
- package/esm/src/wow/game_data/connected_realm.d.ts +62 -0
- package/esm/src/wow/game_data/connected_realm.js +35 -0
- package/esm/src/wow/game_data/covenant.d.ts +115 -0
- package/esm/src/wow/game_data/covenant.js +88 -0
- package/esm/src/wow/game_data/creature.d.ts +98 -0
- package/esm/src/wow/game_data/creature.js +99 -0
- package/esm/src/wow/game_data/guild_crest.d.ts +56 -0
- package/esm/src/wow/game_data/guild_crest.js +38 -0
- package/esm/src/wow/game_data/heirloom.d.ts +82 -0
- package/esm/src/wow/game_data/heirloom.js +25 -0
- package/esm/src/wow/game_data/housing.d.ts +111 -0
- package/esm/src/wow/game_data/housing.js +124 -0
- package/esm/src/wow/game_data/item.d.ts +183 -0
- package/esm/src/wow/game_data/item.js +100 -0
- package/esm/src/wow/game_data/item_appearance.d.ts +102 -0
- package/esm/src/wow/game_data/item_appearance.js +73 -0
- package/esm/src/wow/game_data/journal.d.ts +124 -0
- package/esm/src/wow/game_data/journal.js +98 -0
- package/esm/src/wow/game_data/keystone_affix.d.ts +39 -0
- package/esm/src/wow/game_data/keystone_affix.js +38 -0
- package/esm/src/wow/game_data/media_search.d.ts +9 -0
- package/esm/src/wow/game_data/media_search.js +10 -0
- package/esm/src/wow/game_data/modified_crafting.d.ts +65 -0
- package/esm/src/wow/game_data/modified_crafting.js +62 -0
- package/esm/src/wow/game_data/mount.d.ts +38 -0
- package/esm/src/wow/game_data/mount.js +35 -0
- package/esm/src/wow/game_data/mythic_keystone_dungeon.d.ts +92 -0
- package/esm/src/wow/game_data/mythic_keystone_dungeon.js +87 -0
- package/esm/src/wow/game_data/mythic_keystone_leaderboard.d.ts +70 -0
- package/esm/src/wow/game_data/mythic_keystone_leaderboard.js +28 -0
- package/esm/src/wow/game_data/mythic_raid_leaderboard.d.ts +36 -0
- package/esm/src/wow/game_data/mythic_raid_leaderboard.js +14 -0
- package/esm/src/wow/game_data/neighborhood.d.ts +36 -0
- package/esm/src/wow/game_data/neighborhood.js +38 -0
- package/esm/src/wow/game_data/pet.d.ts +93 -0
- package/esm/src/wow/game_data/pet.js +76 -0
- package/esm/src/wow/game_data/playable_class.d.ts +58 -0
- package/esm/src/wow/game_data/playable_class.js +51 -0
- package/esm/src/wow/game_data/playable_race.d.ts +31 -0
- package/esm/src/wow/game_data/playable_race.js +25 -0
- package/esm/src/wow/game_data/playable_specialization.d.ts +63 -0
- package/esm/src/wow/game_data/playable_specialization.js +38 -0
- package/esm/src/wow/game_data/power_type.d.ts +22 -0
- package/esm/src/wow/game_data/power_type.js +25 -0
- package/esm/src/wow/game_data/profession.d.ts +88 -0
- package/esm/src/wow/game_data/profession.js +78 -0
- package/esm/src/wow/game_data/pvp_season.d.ts +108 -0
- package/esm/src/wow/game_data/pvp_season.js +66 -0
- package/esm/src/wow/game_data/pvp_tier.d.ts +41 -0
- package/esm/src/wow/game_data/pvp_tier.js +38 -0
- package/esm/src/wow/game_data/quest.d.ts +116 -0
- package/esm/src/wow/game_data/quest.js +100 -0
- package/esm/src/wow/game_data/realm.d.ts +43 -0
- package/esm/src/wow/game_data/realm.js +35 -0
- package/esm/src/wow/game_data/region.d.ts +26 -0
- package/esm/src/wow/game_data/region.js +25 -0
- package/esm/src/wow/game_data/reputations.d.ts +57 -0
- package/esm/src/wow/game_data/reputations.js +50 -0
- package/esm/src/wow/game_data/spell.d.ts +34 -0
- package/esm/src/wow/game_data/spell.js +36 -0
- package/esm/src/wow/game_data/talent.d.ts +143 -0
- package/esm/src/wow/game_data/talent.js +89 -0
- package/esm/src/wow/game_data/tech_talent.d.ts +72 -0
- package/esm/src/wow/game_data/tech_talent.js +63 -0
- package/esm/src/wow/game_data/title.d.ts +33 -0
- package/esm/src/wow/game_data/title.js +25 -0
- package/esm/src/wow/game_data/token.d.ts +17 -0
- package/esm/src/wow/game_data/token.js +18 -0
- package/esm/src/wow/game_data/toy.d.ts +25 -0
- package/esm/src/wow/game_data/toy.js +25 -0
- package/esm/src/wow/index.d.ts +59 -0
- package/esm/src/wow/index.js +61 -0
- package/esm/src/wow/profile/account_profile.d.ts +185 -0
- package/esm/src/wow/profile/account_profile.js +132 -0
- package/esm/src/wow/profile/character_achievements.d.ts +88 -0
- package/esm/src/wow/profile/character_achievements.js +28 -0
- package/esm/src/wow/profile/character_appearance.d.ts +79 -0
- package/esm/src/wow/profile/character_appearance.js +14 -0
- package/esm/src/wow/profile/character_collections.d.ts +132 -0
- package/esm/src/wow/profile/character_collections.js +98 -0
- package/esm/src/wow/profile/character_encounters.d.ts +78 -0
- package/esm/src/wow/profile/character_encounters.js +42 -0
- package/esm/src/wow/profile/character_equipment.d.ts +177 -0
- package/esm/src/wow/profile/character_equipment.js +14 -0
- package/esm/src/wow/profile/character_house.d.ts +16 -0
- package/esm/src/wow/profile/character_house.js +17 -0
- package/esm/src/wow/profile/character_hunter_pets.d.ts +22 -0
- package/esm/src/wow/profile/character_hunter_pets.js +14 -0
- package/esm/src/wow/profile/character_media.d.ts +14 -0
- package/esm/src/wow/profile/character_media.js +14 -0
- package/esm/src/wow/profile/character_mythic_keystone_profile.d.ts +70 -0
- package/esm/src/wow/profile/character_mythic_keystone_profile.js +31 -0
- package/esm/src/wow/profile/character_professions.d.ts +29 -0
- package/esm/src/wow/profile/character_professions.js +14 -0
- package/esm/src/wow/profile/character_profile.d.ts +83 -0
- package/esm/src/wow/profile/character_profile.js +39 -0
- package/esm/src/wow/profile/character_pvp.d.ts +53 -0
- package/esm/src/wow/profile/character_pvp.js +29 -0
- package/esm/src/wow/profile/character_quests.d.ts +29 -0
- package/esm/src/wow/profile/character_quests.js +28 -0
- package/esm/src/wow/profile/character_reputations.d.ts +30 -0
- package/esm/src/wow/profile/character_reputations.js +14 -0
- package/esm/src/wow/profile/character_soulbinds.d.ts +31 -0
- package/esm/src/wow/profile/character_soulbinds.js +14 -0
- package/esm/src/wow/profile/character_specializations.d.ts +82 -0
- package/esm/src/wow/profile/character_specializations.js +14 -0
- package/esm/src/wow/profile/character_statistics.d.ts +104 -0
- package/esm/src/wow/profile/character_statistics.js +14 -0
- package/esm/src/wow/profile/character_titles.d.ts +14 -0
- package/esm/src/wow/profile/character_titles.js +14 -0
- package/esm/src/wow/profile/guild.d.ts +150 -0
- package/esm/src/wow/profile/guild.js +56 -0
- package/esm/src/wow/search.d.ts +23 -0
- package/esm/src/wow/search.js +29 -0
- package/esm/src/wow/types.d.ts +58 -0
- package/esm/src/wow/types.js +1 -0
- package/esm/src/wow_classic/auction_house.d.ts +41 -0
- package/esm/src/wow_classic/auction_house.js +31 -0
- package/esm/src/wow_classic/character_specializations.d.ts +45 -0
- package/esm/src/wow_classic/character_specializations.js +18 -0
- package/esm/src/wow_classic/era.d.ts +8 -0
- package/esm/src/wow_classic/era.js +10 -0
- package/esm/src/wow_classic/index.d.ts +15 -0
- package/esm/src/wow_classic/index.js +17 -0
- package/esm/src/wow_classic/profile_overrides.d.ts +125 -0
- package/esm/src/wow_classic/profile_overrides.js +111 -0
- package/esm/src/wow_classic/shared.d.ts +23 -0
- package/esm/src/wow_classic/shared.js +26 -0
- package/esm/src/wow_classic/types.d.ts +3 -0
- package/esm/src/wow_classic/types.js +1 -0
- package/package.json +23 -2
- package/script/mod.d.ts +43 -6
- package/script/mod.js +91 -21
- package/script/src/client.d.ts +95 -0
- package/script/src/client.js +89 -0
- package/script/src/diablo3/community/act.d.ts +29 -0
- package/script/src/diablo3/community/act.js +27 -0
- package/script/src/diablo3/community/artisan.d.ts +50 -0
- package/script/src/diablo3/community/artisan.js +29 -0
- package/script/src/diablo3/community/follower.d.ts +25 -0
- package/script/src/diablo3/community/follower.js +15 -0
- package/script/src/diablo3/community/hero.d.ts +57 -0
- package/script/src/diablo3/community/hero.js +29 -0
- package/script/src/diablo3/community/item.d.ts +48 -0
- package/script/src/diablo3/community/item.js +15 -0
- package/script/src/diablo3/community/item_type.d.ts +26 -0
- package/script/src/diablo3/community/item_type.js +27 -0
- package/script/src/diablo3/community/profile.d.ts +352 -0
- package/script/src/diablo3/community/profile.js +67 -0
- package/script/src/diablo3/game_data/d3.d.ts +127 -0
- package/script/src/diablo3/game_data/d3.js +80 -0
- package/script/src/diablo3/index.d.ts +8 -0
- package/script/src/diablo3/index.js +31 -0
- package/script/src/diablo3/types.d.ts +8 -0
- package/script/src/diablo3/types.js +2 -0
- package/script/src/generated/diablo3_api.d.ts +156 -0
- package/script/src/generated/diablo3_api.js +3 -0
- package/script/src/generated/hearthstone_api.d.ts +51 -0
- package/script/src/generated/hearthstone_api.js +3 -0
- package/script/src/generated/sc2_api.d.ts +139 -0
- package/script/src/generated/sc2_api.js +3 -0
- package/script/src/generated/wow_api.d.ts +1482 -0
- package/script/src/generated/wow_api.js +3 -0
- package/script/src/generated/wow_classic_api.d.ts +555 -0
- package/script/src/generated/wow_classic_api.js +3 -0
- package/script/src/generated/wow_classic_era_api.d.ts +418 -0
- package/script/src/generated/wow_classic_era_api.js +3 -0
- package/script/src/hearthstone/game_data/card_backs.d.ts +31 -0
- package/script/src/hearthstone/game_data/card_backs.js +26 -0
- package/script/src/hearthstone/game_data/cards.d.ts +55 -0
- package/script/src/hearthstone/game_data/cards.js +30 -0
- package/script/src/hearthstone/game_data/decks.d.ts +29 -0
- package/script/src/hearthstone/game_data/decks.js +16 -0
- package/script/src/hearthstone/game_data/metadata.d.ts +82 -0
- package/script/src/hearthstone/game_data/metadata.js +14 -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 +21 -0
- package/script/src/hearthstone/search.js +31 -0
- package/script/src/hearthstone/types.d.ts +5 -0
- package/script/src/hearthstone/types.js +2 -0
- package/script/src/shared/bind.d.ts +14 -0
- package/script/src/shared/bind.js +18 -0
- package/script/src/shared/context.d.ts +163 -0
- package/script/src/shared/context.js +312 -0
- package/script/src/shared/errors.d.ts +53 -0
- package/script/src/shared/errors.js +104 -0
- package/script/src/shared/index.d.ts +4 -0
- package/script/src/shared/index.js +10 -0
- package/script/src/shared/types.d.ts +133 -0
- package/script/src/shared/types.js +3 -0
- package/script/src/starcraft2/community/account.d.ts +19 -0
- package/script/src/starcraft2/community/account.js +18 -0
- package/script/src/starcraft2/community/ladder.d.ts +29 -0
- package/script/src/starcraft2/community/ladder.js +31 -0
- package/script/src/starcraft2/community/legacy.d.ts +206 -0
- package/script/src/starcraft2/community/legacy.js +91 -0
- package/script/src/starcraft2/community/profile.d.ts +255 -0
- package/script/src/starcraft2/community/profile.js +80 -0
- package/script/src/starcraft2/game_data/league.d.ts +35 -0
- package/script/src/starcraft2/game_data/league.js +23 -0
- package/script/src/starcraft2/index.d.ts +5 -0
- package/script/src/starcraft2/index.js +23 -0
- package/script/src/starcraft2/types.d.ts +5 -0
- package/script/src/starcraft2/types.js +2 -0
- package/script/src/wow/game_data/achievement.d.ts +87 -0
- package/script/src/wow/game_data/achievement.js +75 -0
- package/script/src/wow/game_data/auction_house.d.ts +65 -0
- package/script/src/wow/game_data/auction_house.js +37 -0
- package/script/src/wow/game_data/azerite_essence.d.ts +50 -0
- package/script/src/wow/game_data/azerite_essence.js +54 -0
- package/script/src/wow/game_data/connected_realm.d.ts +62 -0
- package/script/src/wow/game_data/connected_realm.js +40 -0
- package/script/src/wow/game_data/covenant.d.ts +115 -0
- package/script/src/wow/game_data/covenant.js +97 -0
- package/script/src/wow/game_data/creature.d.ts +98 -0
- package/script/src/wow/game_data/creature.js +109 -0
- package/script/src/wow/game_data/guild_crest.d.ts +56 -0
- package/script/src/wow/game_data/guild_crest.js +43 -0
- package/script/src/wow/game_data/heirloom.d.ts +82 -0
- package/script/src/wow/game_data/heirloom.js +29 -0
- package/script/src/wow/game_data/housing.d.ts +111 -0
- package/script/src/wow/game_data/housing.js +138 -0
- package/script/src/wow/game_data/item.d.ts +183 -0
- package/script/src/wow/game_data/item.js +110 -0
- package/script/src/wow/game_data/item_appearance.d.ts +102 -0
- package/script/src/wow/game_data/item_appearance.js +81 -0
- package/script/src/wow/game_data/journal.d.ts +124 -0
- package/script/src/wow/game_data/journal.js +108 -0
- package/script/src/wow/game_data/keystone_affix.d.ts +39 -0
- package/script/src/wow/game_data/keystone_affix.js +43 -0
- package/script/src/wow/game_data/media_search.d.ts +9 -0
- package/script/src/wow/game_data/media_search.js +13 -0
- package/script/src/wow/game_data/modified_crafting.d.ts +65 -0
- package/script/src/wow/game_data/modified_crafting.js +69 -0
- package/script/src/wow/game_data/mount.d.ts +38 -0
- package/script/src/wow/game_data/mount.js +40 -0
- package/script/src/wow/game_data/mythic_keystone_dungeon.d.ts +92 -0
- package/script/src/wow/game_data/mythic_keystone_dungeon.js +96 -0
- package/script/src/wow/game_data/mythic_keystone_leaderboard.d.ts +70 -0
- package/script/src/wow/game_data/mythic_keystone_leaderboard.js +32 -0
- package/script/src/wow/game_data/mythic_raid_leaderboard.d.ts +36 -0
- package/script/src/wow/game_data/mythic_raid_leaderboard.js +17 -0
- package/script/src/wow/game_data/neighborhood.d.ts +36 -0
- package/script/src/wow/game_data/neighborhood.js +43 -0
- package/script/src/wow/game_data/pet.d.ts +93 -0
- package/script/src/wow/game_data/pet.js +84 -0
- package/script/src/wow/game_data/playable_class.d.ts +58 -0
- package/script/src/wow/game_data/playable_class.js +57 -0
- package/script/src/wow/game_data/playable_race.d.ts +31 -0
- package/script/src/wow/game_data/playable_race.js +29 -0
- package/script/src/wow/game_data/playable_specialization.d.ts +63 -0
- package/script/src/wow/game_data/playable_specialization.js +43 -0
- package/script/src/wow/game_data/power_type.d.ts +22 -0
- package/script/src/wow/game_data/power_type.js +29 -0
- package/script/src/wow/game_data/profession.d.ts +88 -0
- package/script/src/wow/game_data/profession.js +86 -0
- package/script/src/wow/game_data/pvp_season.d.ts +108 -0
- package/script/src/wow/game_data/pvp_season.js +73 -0
- package/script/src/wow/game_data/pvp_tier.d.ts +41 -0
- package/script/src/wow/game_data/pvp_tier.js +43 -0
- package/script/src/wow/game_data/quest.d.ts +116 -0
- package/script/src/wow/game_data/quest.js +110 -0
- package/script/src/wow/game_data/realm.d.ts +43 -0
- package/script/src/wow/game_data/realm.js +40 -0
- package/script/src/wow/game_data/region.d.ts +26 -0
- package/script/src/wow/game_data/region.js +29 -0
- package/script/src/wow/game_data/reputations.d.ts +57 -0
- package/script/src/wow/game_data/reputations.js +56 -0
- package/script/src/wow/game_data/spell.d.ts +34 -0
- package/script/src/wow/game_data/spell.js +41 -0
- package/script/src/wow/game_data/talent.d.ts +143 -0
- package/script/src/wow/game_data/talent.js +98 -0
- package/script/src/wow/game_data/tech_talent.d.ts +72 -0
- package/script/src/wow/game_data/tech_talent.js +70 -0
- package/script/src/wow/game_data/title.d.ts +33 -0
- package/script/src/wow/game_data/title.js +29 -0
- package/script/src/wow/game_data/token.d.ts +17 -0
- package/script/src/wow/game_data/token.js +21 -0
- package/script/src/wow/game_data/toy.d.ts +25 -0
- package/script/src/wow/game_data/toy.js +29 -0
- package/script/src/wow/index.d.ts +59 -0
- package/script/src/wow/index.js +272 -0
- package/script/src/wow/profile/account_profile.d.ts +185 -0
- package/script/src/wow/profile/account_profile.js +143 -0
- package/script/src/wow/profile/character_achievements.d.ts +88 -0
- package/script/src/wow/profile/character_achievements.js +32 -0
- package/script/src/wow/profile/character_appearance.d.ts +79 -0
- package/script/src/wow/profile/character_appearance.js +17 -0
- package/script/src/wow/profile/character_collections.d.ts +132 -0
- package/script/src/wow/profile/character_collections.js +107 -0
- package/script/src/wow/profile/character_encounters.d.ts +78 -0
- package/script/src/wow/profile/character_encounters.js +47 -0
- package/script/src/wow/profile/character_equipment.d.ts +177 -0
- package/script/src/wow/profile/character_equipment.js +17 -0
- package/script/src/wow/profile/character_house.d.ts +16 -0
- package/script/src/wow/profile/character_house.js +20 -0
- package/script/src/wow/profile/character_hunter_pets.d.ts +22 -0
- package/script/src/wow/profile/character_hunter_pets.js +17 -0
- package/script/src/wow/profile/character_media.d.ts +14 -0
- package/script/src/wow/profile/character_media.js +17 -0
- package/script/src/wow/profile/character_mythic_keystone_profile.d.ts +70 -0
- package/script/src/wow/profile/character_mythic_keystone_profile.js +35 -0
- package/script/src/wow/profile/character_professions.d.ts +29 -0
- package/script/src/wow/profile/character_professions.js +17 -0
- package/script/src/wow/profile/character_profile.d.ts +83 -0
- package/script/src/wow/profile/character_profile.js +43 -0
- package/script/src/wow/profile/character_pvp.d.ts +53 -0
- package/script/src/wow/profile/character_pvp.js +33 -0
- package/script/src/wow/profile/character_quests.d.ts +29 -0
- package/script/src/wow/profile/character_quests.js +32 -0
- package/script/src/wow/profile/character_reputations.d.ts +30 -0
- package/script/src/wow/profile/character_reputations.js +17 -0
- package/script/src/wow/profile/character_soulbinds.d.ts +31 -0
- package/script/src/wow/profile/character_soulbinds.js +17 -0
- package/script/src/wow/profile/character_specializations.d.ts +82 -0
- package/script/src/wow/profile/character_specializations.js +17 -0
- package/script/src/wow/profile/character_statistics.d.ts +104 -0
- package/script/src/wow/profile/character_statistics.js +17 -0
- package/script/src/wow/profile/character_titles.d.ts +14 -0
- package/script/src/wow/profile/character_titles.js +17 -0
- package/script/src/wow/profile/guild.d.ts +150 -0
- package/script/src/wow/profile/guild.js +62 -0
- package/script/src/wow/search.d.ts +23 -0
- package/script/src/wow/search.js +32 -0
- package/script/src/wow/types.d.ts +58 -0
- package/script/src/wow/types.js +2 -0
- package/script/src/wow_classic/auction_house.d.ts +41 -0
- package/script/src/wow_classic/auction_house.js +35 -0
- package/script/src/wow_classic/character_specializations.d.ts +45 -0
- package/script/src/wow_classic/character_specializations.js +21 -0
- package/script/src/wow_classic/era.d.ts +8 -0
- package/script/src/wow_classic/era.js +30 -0
- package/script/src/wow_classic/index.d.ts +15 -0
- package/script/src/wow_classic/index.js +55 -0
- package/script/src/wow_classic/profile_overrides.d.ts +125 -0
- package/script/src/wow_classic/profile_overrides.js +123 -0
- package/script/src/wow_classic/shared.d.ts +23 -0
- package/script/src/wow_classic/shared.js +81 -0
- package/script/src/wow_classic/types.d.ts +3 -0
- package/script/src/wow_classic/types.js +2 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { ApiContext } from "../../shared/index.js";
|
|
2
|
+
import type { LocalizedString } from "../../shared/index.js";
|
|
3
|
+
export interface MetadataSet {
|
|
4
|
+
id: number;
|
|
5
|
+
name: LocalizedString;
|
|
6
|
+
slug: string;
|
|
7
|
+
hyped: boolean;
|
|
8
|
+
type: string;
|
|
9
|
+
collectibleCount: number;
|
|
10
|
+
collectibleRevealedCount: number;
|
|
11
|
+
nonCollectibleCount: number;
|
|
12
|
+
nonCollectibleRevealedCount: number;
|
|
13
|
+
aliasSetIds?: number[];
|
|
14
|
+
}
|
|
15
|
+
export interface MetadataSetGroup {
|
|
16
|
+
slug: string;
|
|
17
|
+
year?: number;
|
|
18
|
+
svg?: string;
|
|
19
|
+
cardSets: string[];
|
|
20
|
+
name: LocalizedString;
|
|
21
|
+
standard?: boolean;
|
|
22
|
+
yearRange?: string;
|
|
23
|
+
icon?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface MetadataType {
|
|
26
|
+
slug: string;
|
|
27
|
+
id: number;
|
|
28
|
+
name: LocalizedString;
|
|
29
|
+
gameModes: number[];
|
|
30
|
+
}
|
|
31
|
+
export interface MetadataRarity {
|
|
32
|
+
slug: string;
|
|
33
|
+
id: number;
|
|
34
|
+
craftingCost: number[];
|
|
35
|
+
dustValue: number[];
|
|
36
|
+
name: LocalizedString;
|
|
37
|
+
}
|
|
38
|
+
export interface MetadataClass {
|
|
39
|
+
slug: string;
|
|
40
|
+
id: number;
|
|
41
|
+
name: LocalizedString;
|
|
42
|
+
cardId?: number;
|
|
43
|
+
heroPowerCardId?: number;
|
|
44
|
+
alternateHeroCardIds?: number[];
|
|
45
|
+
}
|
|
46
|
+
export interface MetadataMinionType {
|
|
47
|
+
slug: string;
|
|
48
|
+
id: number;
|
|
49
|
+
name: LocalizedString;
|
|
50
|
+
gameModes: number[];
|
|
51
|
+
}
|
|
52
|
+
export interface MetadataKeyword {
|
|
53
|
+
id: number;
|
|
54
|
+
slug: string;
|
|
55
|
+
name: LocalizedString;
|
|
56
|
+
refText: LocalizedString;
|
|
57
|
+
text: LocalizedString;
|
|
58
|
+
gameModes: number[];
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The response of metadata(type) for each metadata type.
|
|
62
|
+
*/
|
|
63
|
+
export interface MetadataByType {
|
|
64
|
+
sets: MetadataSet[];
|
|
65
|
+
setGroups: MetadataSetGroup[];
|
|
66
|
+
types: MetadataType[];
|
|
67
|
+
rarities: MetadataRarity[];
|
|
68
|
+
classes: MetadataClass[];
|
|
69
|
+
minionTypes: MetadataMinionType[];
|
|
70
|
+
keywords: MetadataKeyword[];
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Any metadata response.
|
|
74
|
+
*/
|
|
75
|
+
export type Metadata = MetadataByType[keyof MetadataByType];
|
|
76
|
+
export type MetaTypes = keyof MetadataByType;
|
|
77
|
+
/**
|
|
78
|
+
* 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.
|
|
79
|
+
*
|
|
80
|
+
* @returns A promise that resolves to an object representing the Metadata.
|
|
81
|
+
*/
|
|
82
|
+
export declare function metadata<T extends MetaTypes>(ctx: ApiContext, type: T): Promise<MetadataByType[T]>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 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.
|
|
3
|
+
*
|
|
4
|
+
* @returns A promise that resolves to an object representing the Metadata.
|
|
5
|
+
*/
|
|
6
|
+
export async function metadata(ctx, type) {
|
|
7
|
+
return await ctx.request({
|
|
8
|
+
method: "GET",
|
|
9
|
+
url: `/hearthstone/metadata/${type}`,
|
|
10
|
+
});
|
|
11
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ApiContext } from "../shared/index.js";
|
|
2
|
+
export interface SearchParameters {
|
|
3
|
+
searchFields?: Record<string | symbol, string | number>;
|
|
4
|
+
page?: number;
|
|
5
|
+
pageSize?: number;
|
|
6
|
+
sort?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface Search {
|
|
9
|
+
page: number;
|
|
10
|
+
pageSize: number;
|
|
11
|
+
maxPageSize: number;
|
|
12
|
+
pageCount: number;
|
|
13
|
+
results: unknown[];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Performs a search.
|
|
17
|
+
*
|
|
18
|
+
* @param SearchParameters - Object containing search parameters.
|
|
19
|
+
* @returns A promise that resolves to an object representing details about the search.
|
|
20
|
+
*/
|
|
21
|
+
export declare function search(ctx: ApiContext, url: string, searchParameters: SearchParameters): Promise<Search>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Performs a search.
|
|
3
|
+
*
|
|
4
|
+
* @param SearchParameters - Object containing search parameters.
|
|
5
|
+
* @returns A promise that resolves to an object representing details about the search.
|
|
6
|
+
*/
|
|
7
|
+
export async function search(ctx, url, searchParameters) {
|
|
8
|
+
const searchFields = searchParameters.searchFields
|
|
9
|
+
? Object.fromEntries(Object.entries(searchParameters.searchFields).map(([key, value]) => [key, value.toString()]))
|
|
10
|
+
: undefined;
|
|
11
|
+
const qs = {
|
|
12
|
+
...searchFields,
|
|
13
|
+
};
|
|
14
|
+
if (searchParameters.sort) {
|
|
15
|
+
qs.sort = searchParameters.sort;
|
|
16
|
+
}
|
|
17
|
+
if (searchParameters.page !== undefined) {
|
|
18
|
+
qs.page = searchParameters.page;
|
|
19
|
+
}
|
|
20
|
+
if (searchParameters.pageSize !== undefined) {
|
|
21
|
+
qs.pageSize = searchParameters.pageSize;
|
|
22
|
+
}
|
|
23
|
+
return await ctx.request({
|
|
24
|
+
method: "GET",
|
|
25
|
+
url: `/hearthstone${url}`,
|
|
26
|
+
qs,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { Cardback, CardbackSearch } from "./game_data/card_backs.js";
|
|
2
|
+
export type { Card, CardSearch } from "./game_data/cards.js";
|
|
3
|
+
export type { Deck, Options } from "./game_data/decks.js";
|
|
4
|
+
export type { Metadata, MetadataByType, MetadataClass, MetadataKeyword, MetadataMinionType, MetadataRarity, MetadataSet, MetadataSetGroup, MetadataType, MetaTypes, } from "./game_data/metadata.js";
|
|
5
|
+
export type { Search, SearchParameters } from "./search.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ApiContext } from "./context.js";
|
|
2
|
+
/**
|
|
3
|
+
* Turns a module of endpoint functions `(ctx, ...args) => R` into the same functions without the context argument.
|
|
4
|
+
*/
|
|
5
|
+
export type Bound<T> = {
|
|
6
|
+
[K in keyof T as T[K] extends (ctx: ApiContext, ...args: any[]) => unknown ? K : never]: T[K] extends (ctx: ApiContext, ...args: infer A) => infer R ? (...args: A) => R : never;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Binds every endpoint function of a module to a context.
|
|
10
|
+
* @param {ApiContext} ctx - The context the endpoints will use.
|
|
11
|
+
* @param {T} endpoints - A module namespace of endpoint functions.
|
|
12
|
+
* @returns {Bound<T>} The bound endpoints.
|
|
13
|
+
*/
|
|
14
|
+
export declare function bindAll<T extends object>(ctx: ApiContext, endpoints: T): Bound<T>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Binds every endpoint function of a module to a context.
|
|
3
|
+
* @param {ApiContext} ctx - The context the endpoints will use.
|
|
4
|
+
* @param {T} endpoints - A module namespace of endpoint functions.
|
|
5
|
+
* @returns {Bound<T>} The bound endpoints.
|
|
6
|
+
*/
|
|
7
|
+
export function bindAll(ctx, endpoints) {
|
|
8
|
+
const bound = {};
|
|
9
|
+
for (const [name, value] of Object.entries(endpoints)) {
|
|
10
|
+
if (typeof value === "function") {
|
|
11
|
+
bound[name] = value.bind(undefined, ctx);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return Object.freeze(bound);
|
|
15
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import type { Locales, Regions, RequestOptions } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Represents the configuration of a client.
|
|
4
|
+
* @property {Regions} region - The target Battle.net region for API requests.
|
|
5
|
+
* @property {Locales} [locale] - The locale for localized fields. Defaults to the main locale of the region
|
|
6
|
+
* (us: en_US, eu: en_GB, kr: ko_KR, tw: zh_TW, cn: zh_CN).
|
|
7
|
+
* @property {string} clientId - The OAuth client ID.
|
|
8
|
+
* @property {string} clientSecret - The OAuth client secret.
|
|
9
|
+
*/
|
|
10
|
+
export interface ClientConfig {
|
|
11
|
+
region: Regions;
|
|
12
|
+
locale?: Locales;
|
|
13
|
+
clientId: string;
|
|
14
|
+
clientSecret: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Represents the authentication state of the client credentials token.
|
|
18
|
+
* @property {string} accessToken - The current access token.
|
|
19
|
+
* @property {number} tokenExpiration - The expiration timestamp of the access token (in milliseconds).
|
|
20
|
+
*/
|
|
21
|
+
export interface AuthConfig {
|
|
22
|
+
accessToken: string;
|
|
23
|
+
tokenExpiration: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Options for building the authorization code flow URL.
|
|
27
|
+
* @property {string} redirectUri - The redirect URI registered for the client.
|
|
28
|
+
* @property {string[]} [scope] - The requested scopes, e.g. ["wow.profile"]. "openid" is always included.
|
|
29
|
+
* @property {string} state - An opaque, unguessable value to protect against CSRF. Verify it on the redirect.
|
|
30
|
+
*/
|
|
31
|
+
export interface AuthorizeUrlOptions {
|
|
32
|
+
redirectUri: string;
|
|
33
|
+
scope?: string[];
|
|
34
|
+
state: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Options for exchanging an authorization code for a user access token.
|
|
38
|
+
* @property {string} code - The code received on the redirect URI.
|
|
39
|
+
* @property {string} redirectUri - The same redirect URI used to build the authorize URL.
|
|
40
|
+
*/
|
|
41
|
+
export interface ExchangeCodeOptions {
|
|
42
|
+
code: string;
|
|
43
|
+
redirectUri: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Represents the token response of the OAuth token endpoint.
|
|
47
|
+
*/
|
|
48
|
+
export interface TokenResponse {
|
|
49
|
+
access_token: string;
|
|
50
|
+
token_type: string;
|
|
51
|
+
expires_in: number;
|
|
52
|
+
scope?: string;
|
|
53
|
+
sub?: string;
|
|
54
|
+
id_token?: string;
|
|
55
|
+
}
|
|
56
|
+
interface ContextOptions {
|
|
57
|
+
userToken?: string;
|
|
58
|
+
namespaceVariant?: string;
|
|
59
|
+
}
|
|
60
|
+
interface TokenState extends AuthConfig {
|
|
61
|
+
pending?: Promise<string>;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Returns the locale used when none is configured. A locale is always sent, so localized fields are plain strings.
|
|
65
|
+
* @param {Regions} region - The target Battle.net region.
|
|
66
|
+
* @returns {Locales} The default locale of the region.
|
|
67
|
+
*/
|
|
68
|
+
export declare function defaultLocale(region: Regions): Locales;
|
|
69
|
+
/**
|
|
70
|
+
* Generates the OAuth base URL based on the specified region.
|
|
71
|
+
* @param {Regions} region - The target Battle.net region.
|
|
72
|
+
* @returns {string} The OAuth base URL.
|
|
73
|
+
*/
|
|
74
|
+
export declare function oauthBaseUrl(region: Regions): string;
|
|
75
|
+
/**
|
|
76
|
+
* Generates the base API URL based on the specified region.
|
|
77
|
+
* @param {Regions} region - The target Battle.net region.
|
|
78
|
+
* @returns {string} The constructed base API URL.
|
|
79
|
+
*/
|
|
80
|
+
export declare function apiBaseUrl(region: Regions): string;
|
|
81
|
+
/**
|
|
82
|
+
* Validates that a configuration has everything needed to make requests.
|
|
83
|
+
* @throws {MissingRegionError | MissingClientIdError | MissingClientSecretError}
|
|
84
|
+
*/
|
|
85
|
+
export declare function assertConfig(config: Partial<ClientConfig>): asserts config is ClientConfig;
|
|
86
|
+
/**
|
|
87
|
+
* Holds the configuration and token state of one client and performs its requests.
|
|
88
|
+
* Every endpoint function takes an ApiContext as its first argument.
|
|
89
|
+
*/
|
|
90
|
+
export declare class ApiContext {
|
|
91
|
+
#private;
|
|
92
|
+
/**
|
|
93
|
+
* @param {Partial<ClientConfig>} config - The client configuration. Shared by reference with derived contexts.
|
|
94
|
+
* @param {TokenState} [token] - Token state to share (used by derived contexts).
|
|
95
|
+
* @param {ContextOptions} [options] - User token and namespace variant.
|
|
96
|
+
*/
|
|
97
|
+
constructor(config?: Partial<ClientConfig>, token?: TokenState, options?: ContextOptions);
|
|
98
|
+
/**
|
|
99
|
+
* The current configuration (may be partial if not fully set up).
|
|
100
|
+
*/
|
|
101
|
+
get config(): Readonly<Partial<ClientConfig>>;
|
|
102
|
+
/**
|
|
103
|
+
* Merges configuration into this context. Changing the region or credentials discards the cached token.
|
|
104
|
+
* @param {Partial<ClientConfig>} config - The configuration properties to update.
|
|
105
|
+
*/
|
|
106
|
+
configure(config: Partial<ClientConfig>): void;
|
|
107
|
+
/**
|
|
108
|
+
* Returns a copy of the client credentials token state.
|
|
109
|
+
*/
|
|
110
|
+
getAuthConfig(): AuthConfig;
|
|
111
|
+
/**
|
|
112
|
+
* Returns a context that uses the given user access token for user-scoped endpoints
|
|
113
|
+
* (e.g. the WoW account profile). It shares configuration and the client credentials token with this context.
|
|
114
|
+
* @param {string} userToken - A user access token from the authorization code flow.
|
|
115
|
+
*/
|
|
116
|
+
forUser(userToken: string): ApiContext;
|
|
117
|
+
/**
|
|
118
|
+
* Returns a context for another game version: base namespaces ("static", "dynamic", "profile") get the variant
|
|
119
|
+
* inserted before the region, e.g. "classic1x" turns "static" into "static-classic1x-eu".
|
|
120
|
+
* It shares configuration, tokens and the user token with this context.
|
|
121
|
+
* @param {string} namespaceVariant - The namespace variant, e.g. "classic" or "classic1x".
|
|
122
|
+
*/
|
|
123
|
+
withNamespaceVariant(namespaceVariant: string): ApiContext;
|
|
124
|
+
/**
|
|
125
|
+
* Obtains a client credentials access token, reusing the cached one while it is valid.
|
|
126
|
+
* Concurrent callers share a single token request.
|
|
127
|
+
* @param {boolean} forceNewToken - If true, fetches a new token even if the cached one is valid.
|
|
128
|
+
* @returns {Promise<string>} The access token.
|
|
129
|
+
* @throws {MissingRegionError | MissingClientIdError | MissingClientSecretError} If the client is not configured.
|
|
130
|
+
* @throws {AuthenticationError} If there is a problem during the authentication process.
|
|
131
|
+
*/
|
|
132
|
+
authenticate(forceNewToken?: boolean): Promise<string>;
|
|
133
|
+
/**
|
|
134
|
+
* Builds the URL to send a user to for the authorization code flow.
|
|
135
|
+
* @param {AuthorizeUrlOptions} options - Redirect URI, scopes and state.
|
|
136
|
+
* @returns {string} The authorize URL.
|
|
137
|
+
*/
|
|
138
|
+
authorizeUrl(options: AuthorizeUrlOptions): string;
|
|
139
|
+
/**
|
|
140
|
+
* Exchanges an authorization code for a user access token.
|
|
141
|
+
* @param {ExchangeCodeOptions} options - The code and the redirect URI used to obtain it.
|
|
142
|
+
* @returns {Promise<TokenResponse>} The token response; pass `access_token` to forUser().
|
|
143
|
+
* @throws {AuthenticationError} If the exchange fails.
|
|
144
|
+
*/
|
|
145
|
+
exchangeCode(options: ExchangeCodeOptions): Promise<TokenResponse>;
|
|
146
|
+
/**
|
|
147
|
+
* Makes an authenticated request to the API.
|
|
148
|
+
* @param {RequestOptions} requestOptions - Method, path, namespace, query string and auth mode.
|
|
149
|
+
* @returns {Promise<unknown>} The parsed JSON response.
|
|
150
|
+
* @throws {APIError} If the response is not successful.
|
|
151
|
+
* @throws {MissingUserTokenError} If the endpoint needs a user token and this context has none.
|
|
152
|
+
*/
|
|
153
|
+
request(requestOptions: RequestOptions): Promise<unknown>;
|
|
154
|
+
/**
|
|
155
|
+
* Makes an authenticated request to a full href returned in an API response.
|
|
156
|
+
* @param {string} href - The full href URL from a Blizzard API response.
|
|
157
|
+
* @param {Record<string, string | number>} [qs] - Optional query string parameters to append.
|
|
158
|
+
* @returns {Promise<unknown>} The parsed JSON response.
|
|
159
|
+
* @throws {APIError} If the response is not successful.
|
|
160
|
+
*/
|
|
161
|
+
requestHref(href: string, qs?: Record<string, string | number>): Promise<unknown>;
|
|
162
|
+
}
|
|
163
|
+
export {};
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _ApiContext_instances, _ApiContext_config, _ApiContext_token, _ApiContext_userToken, _ApiContext_namespaceVariant, _ApiContext_namespaceHeader, _ApiContext_send, _ApiContext_requestToken;
|
|
13
|
+
import { APIError, AuthenticationError, MissingClientIdError, MissingClientSecretError, MissingRegionError, MissingUserTokenError, } from "./errors.js";
|
|
14
|
+
/**
|
|
15
|
+
* Renew the token this long before it actually expires, so in-flight requests don't race the expiry.
|
|
16
|
+
*/
|
|
17
|
+
const TOKEN_EXPIRY_MARGIN_MS = 60_000;
|
|
18
|
+
/**
|
|
19
|
+
* How often a request is retried after a 429 (Too Many Requests) response, and the base backoff between tries.
|
|
20
|
+
*/
|
|
21
|
+
const MAX_RATE_LIMIT_RETRIES = 3;
|
|
22
|
+
const RATE_LIMIT_BACKOFF_MS = 1_000;
|
|
23
|
+
/**
|
|
24
|
+
* Server errors that are retried once, after a short delay.
|
|
25
|
+
*/
|
|
26
|
+
const SERVER_ERROR_STATUSES = new Set([500, 502, 503, 504]);
|
|
27
|
+
const SERVER_ERROR_RETRY_DELAY_MS = 500;
|
|
28
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
29
|
+
function retryAfterMs(header) {
|
|
30
|
+
const seconds = header === null ? NaN : Number(header);
|
|
31
|
+
return Number.isFinite(seconds) && seconds >= 0 ? Math.min(seconds, 60) * 1000 : undefined;
|
|
32
|
+
}
|
|
33
|
+
const DEFAULT_LOCALES = {
|
|
34
|
+
us: "en_US",
|
|
35
|
+
eu: "en_GB",
|
|
36
|
+
kr: "ko_KR",
|
|
37
|
+
tw: "zh_TW",
|
|
38
|
+
cn: "zh_CN",
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Returns the locale used when none is configured. A locale is always sent, so localized fields are plain strings.
|
|
42
|
+
* @param {Regions} region - The target Battle.net region.
|
|
43
|
+
* @returns {Locales} The default locale of the region.
|
|
44
|
+
*/
|
|
45
|
+
export function defaultLocale(region) {
|
|
46
|
+
return DEFAULT_LOCALES[region];
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Generates the OAuth base URL based on the specified region.
|
|
50
|
+
* @param {Regions} region - The target Battle.net region.
|
|
51
|
+
* @returns {string} The OAuth base URL.
|
|
52
|
+
*/
|
|
53
|
+
export function oauthBaseUrl(region) {
|
|
54
|
+
return region === "cn" ? "https://oauth.battlenet.com.cn" : "https://oauth.battle.net";
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Generates the base API URL based on the specified region.
|
|
58
|
+
* @param {Regions} region - The target Battle.net region.
|
|
59
|
+
* @returns {string} The constructed base API URL.
|
|
60
|
+
*/
|
|
61
|
+
export function apiBaseUrl(region) {
|
|
62
|
+
return region === "cn" ? "https://gateway.battlenet.com.cn" : `https://${region}.api.blizzard.com`;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Validates that a configuration has everything needed to make requests.
|
|
66
|
+
* @throws {MissingRegionError | MissingClientIdError | MissingClientSecretError}
|
|
67
|
+
*/
|
|
68
|
+
export function assertConfig(config) {
|
|
69
|
+
if (!config.region)
|
|
70
|
+
throw new MissingRegionError();
|
|
71
|
+
if (!config.clientId)
|
|
72
|
+
throw new MissingClientIdError();
|
|
73
|
+
if (!config.clientSecret)
|
|
74
|
+
throw new MissingClientSecretError();
|
|
75
|
+
}
|
|
76
|
+
function toQueryParams(qs) {
|
|
77
|
+
return qs
|
|
78
|
+
? Object.fromEntries(Object.entries(qs).filter(([, value]) => value !== undefined).map(([key, value]) => [key, String(value)]))
|
|
79
|
+
: {};
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Holds the configuration and token state of one client and performs its requests.
|
|
83
|
+
* Every endpoint function takes an ApiContext as its first argument.
|
|
84
|
+
*/
|
|
85
|
+
export class ApiContext {
|
|
86
|
+
/**
|
|
87
|
+
* @param {Partial<ClientConfig>} config - The client configuration. Shared by reference with derived contexts.
|
|
88
|
+
* @param {TokenState} [token] - Token state to share (used by derived contexts).
|
|
89
|
+
* @param {ContextOptions} [options] - User token and namespace variant.
|
|
90
|
+
*/
|
|
91
|
+
constructor(config = {}, token, options = {}) {
|
|
92
|
+
_ApiContext_instances.add(this);
|
|
93
|
+
_ApiContext_config.set(this, void 0);
|
|
94
|
+
_ApiContext_token.set(this, void 0);
|
|
95
|
+
_ApiContext_userToken.set(this, void 0);
|
|
96
|
+
_ApiContext_namespaceVariant.set(this, void 0);
|
|
97
|
+
__classPrivateFieldSet(this, _ApiContext_config, config, "f");
|
|
98
|
+
__classPrivateFieldSet(this, _ApiContext_token, token ?? { accessToken: "", tokenExpiration: 0 }, "f");
|
|
99
|
+
__classPrivateFieldSet(this, _ApiContext_userToken, options.userToken, "f");
|
|
100
|
+
__classPrivateFieldSet(this, _ApiContext_namespaceVariant, options.namespaceVariant, "f");
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The current configuration (may be partial if not fully set up).
|
|
104
|
+
*/
|
|
105
|
+
get config() {
|
|
106
|
+
return __classPrivateFieldGet(this, _ApiContext_config, "f");
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Merges configuration into this context. Changing the region or credentials discards the cached token.
|
|
110
|
+
* @param {Partial<ClientConfig>} config - The configuration properties to update.
|
|
111
|
+
*/
|
|
112
|
+
configure(config) {
|
|
113
|
+
const invalidatesToken = ["region", "clientId", "clientSecret"].some((key) => key in config && config[key] !== __classPrivateFieldGet(this, _ApiContext_config, "f")[key]);
|
|
114
|
+
Object.assign(__classPrivateFieldGet(this, _ApiContext_config, "f"), config);
|
|
115
|
+
if (invalidatesToken) {
|
|
116
|
+
__classPrivateFieldGet(this, _ApiContext_token, "f").accessToken = "";
|
|
117
|
+
__classPrivateFieldGet(this, _ApiContext_token, "f").tokenExpiration = 0;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Returns a copy of the client credentials token state.
|
|
122
|
+
*/
|
|
123
|
+
getAuthConfig() {
|
|
124
|
+
return { accessToken: __classPrivateFieldGet(this, _ApiContext_token, "f").accessToken, tokenExpiration: __classPrivateFieldGet(this, _ApiContext_token, "f").tokenExpiration };
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Returns a context that uses the given user access token for user-scoped endpoints
|
|
128
|
+
* (e.g. the WoW account profile). It shares configuration and the client credentials token with this context.
|
|
129
|
+
* @param {string} userToken - A user access token from the authorization code flow.
|
|
130
|
+
*/
|
|
131
|
+
forUser(userToken) {
|
|
132
|
+
return new ApiContext(__classPrivateFieldGet(this, _ApiContext_config, "f"), __classPrivateFieldGet(this, _ApiContext_token, "f"), { userToken, namespaceVariant: __classPrivateFieldGet(this, _ApiContext_namespaceVariant, "f") });
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Returns a context for another game version: base namespaces ("static", "dynamic", "profile") get the variant
|
|
136
|
+
* inserted before the region, e.g. "classic1x" turns "static" into "static-classic1x-eu".
|
|
137
|
+
* It shares configuration, tokens and the user token with this context.
|
|
138
|
+
* @param {string} namespaceVariant - The namespace variant, e.g. "classic" or "classic1x".
|
|
139
|
+
*/
|
|
140
|
+
withNamespaceVariant(namespaceVariant) {
|
|
141
|
+
return new ApiContext(__classPrivateFieldGet(this, _ApiContext_config, "f"), __classPrivateFieldGet(this, _ApiContext_token, "f"), { userToken: __classPrivateFieldGet(this, _ApiContext_userToken, "f"), namespaceVariant });
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Obtains a client credentials access token, reusing the cached one while it is valid.
|
|
145
|
+
* Concurrent callers share a single token request.
|
|
146
|
+
* @param {boolean} forceNewToken - If true, fetches a new token even if the cached one is valid.
|
|
147
|
+
* @returns {Promise<string>} The access token.
|
|
148
|
+
* @throws {MissingRegionError | MissingClientIdError | MissingClientSecretError} If the client is not configured.
|
|
149
|
+
* @throws {AuthenticationError} If there is a problem during the authentication process.
|
|
150
|
+
*/
|
|
151
|
+
authenticate(forceNewToken = false) {
|
|
152
|
+
const config = __classPrivateFieldGet(this, _ApiContext_config, "f");
|
|
153
|
+
assertConfig(config);
|
|
154
|
+
const token = __classPrivateFieldGet(this, _ApiContext_token, "f");
|
|
155
|
+
if (!forceNewToken && token.accessToken && Date.now() < token.tokenExpiration - TOKEN_EXPIRY_MARGIN_MS) {
|
|
156
|
+
return Promise.resolve(token.accessToken);
|
|
157
|
+
}
|
|
158
|
+
if (token.pending) {
|
|
159
|
+
return token.pending;
|
|
160
|
+
}
|
|
161
|
+
token.pending = __classPrivateFieldGet(this, _ApiContext_instances, "m", _ApiContext_requestToken).call(this, config, "grant_type=client_credentials")
|
|
162
|
+
.then((data) => {
|
|
163
|
+
token.accessToken = data.access_token;
|
|
164
|
+
token.tokenExpiration = Date.now() + data.expires_in * 1000;
|
|
165
|
+
return token.accessToken;
|
|
166
|
+
})
|
|
167
|
+
.finally(() => {
|
|
168
|
+
token.pending = undefined;
|
|
169
|
+
});
|
|
170
|
+
return token.pending;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Builds the URL to send a user to for the authorization code flow.
|
|
174
|
+
* @param {AuthorizeUrlOptions} options - Redirect URI, scopes and state.
|
|
175
|
+
* @returns {string} The authorize URL.
|
|
176
|
+
*/
|
|
177
|
+
authorizeUrl(options) {
|
|
178
|
+
const config = __classPrivateFieldGet(this, _ApiContext_config, "f");
|
|
179
|
+
assertConfig(config);
|
|
180
|
+
const scope = new Set(["openid", ...(options.scope ?? [])]);
|
|
181
|
+
const params = new URLSearchParams({
|
|
182
|
+
response_type: "code",
|
|
183
|
+
client_id: config.clientId,
|
|
184
|
+
redirect_uri: options.redirectUri,
|
|
185
|
+
scope: [...scope].join(" "),
|
|
186
|
+
state: options.state,
|
|
187
|
+
});
|
|
188
|
+
return `${oauthBaseUrl(config.region)}/authorize?${params}`;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Exchanges an authorization code for a user access token.
|
|
192
|
+
* @param {ExchangeCodeOptions} options - The code and the redirect URI used to obtain it.
|
|
193
|
+
* @returns {Promise<TokenResponse>} The token response; pass `access_token` to forUser().
|
|
194
|
+
* @throws {AuthenticationError} If the exchange fails.
|
|
195
|
+
*/
|
|
196
|
+
exchangeCode(options) {
|
|
197
|
+
const config = __classPrivateFieldGet(this, _ApiContext_config, "f");
|
|
198
|
+
assertConfig(config);
|
|
199
|
+
const body = new URLSearchParams({
|
|
200
|
+
grant_type: "authorization_code",
|
|
201
|
+
code: options.code,
|
|
202
|
+
redirect_uri: options.redirectUri,
|
|
203
|
+
});
|
|
204
|
+
return __classPrivateFieldGet(this, _ApiContext_instances, "m", _ApiContext_requestToken).call(this, config, body.toString());
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Makes an authenticated request to the API.
|
|
208
|
+
* @param {RequestOptions} requestOptions - Method, path, namespace, query string and auth mode.
|
|
209
|
+
* @returns {Promise<unknown>} The parsed JSON response.
|
|
210
|
+
* @throws {APIError} If the response is not successful.
|
|
211
|
+
* @throws {MissingUserTokenError} If the endpoint needs a user token and this context has none.
|
|
212
|
+
*/
|
|
213
|
+
request(requestOptions) {
|
|
214
|
+
const config = __classPrivateFieldGet(this, _ApiContext_config, "f");
|
|
215
|
+
assertConfig(config);
|
|
216
|
+
const { url, namespace, qs, auth } = requestOptions;
|
|
217
|
+
const params = new URLSearchParams(toQueryParams({ locale: config.locale ?? defaultLocale(config.region), ...qs }));
|
|
218
|
+
const query = params.size ? `?${params}` : "";
|
|
219
|
+
const fullUrl = apiBaseUrl(config.region) + encodeURI(url) + query;
|
|
220
|
+
return __classPrivateFieldGet(this, _ApiContext_instances, "m", _ApiContext_send).call(this, fullUrl, namespace ? __classPrivateFieldGet(this, _ApiContext_instances, "m", _ApiContext_namespaceHeader).call(this, namespace, config.region) : undefined, auth === "user");
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Makes an authenticated request to a full href returned in an API response.
|
|
224
|
+
* @param {string} href - The full href URL from a Blizzard API response.
|
|
225
|
+
* @param {Record<string, string | number>} [qs] - Optional query string parameters to append.
|
|
226
|
+
* @returns {Promise<unknown>} The parsed JSON response.
|
|
227
|
+
* @throws {APIError} If the response is not successful.
|
|
228
|
+
*/
|
|
229
|
+
requestHref(href, qs) {
|
|
230
|
+
const config = __classPrivateFieldGet(this, _ApiContext_config, "f");
|
|
231
|
+
assertConfig(config);
|
|
232
|
+
const url = new URL(href);
|
|
233
|
+
for (const [key, value] of Object.entries(toQueryParams({ locale: config.locale ?? defaultLocale(config.region), ...qs }))) {
|
|
234
|
+
if (!url.searchParams.has(key))
|
|
235
|
+
url.searchParams.set(key, value);
|
|
236
|
+
}
|
|
237
|
+
// Hrefs from the API already carry their full namespace in the query string.
|
|
238
|
+
return __classPrivateFieldGet(this, _ApiContext_instances, "m", _ApiContext_send).call(this, url.toString(), undefined, url.pathname.startsWith("/profile/user/"));
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
_ApiContext_config = new WeakMap(), _ApiContext_token = new WeakMap(), _ApiContext_userToken = new WeakMap(), _ApiContext_namespaceVariant = new WeakMap(), _ApiContext_instances = new WeakSet(), _ApiContext_namespaceHeader = function _ApiContext_namespaceHeader(namespace, region) {
|
|
242
|
+
const isBase = namespace === "static" || namespace === "dynamic" || namespace === "profile";
|
|
243
|
+
return isBase && __classPrivateFieldGet(this, _ApiContext_namespaceVariant, "f")
|
|
244
|
+
? `${namespace}-${__classPrivateFieldGet(this, _ApiContext_namespaceVariant, "f")}-${region}`
|
|
245
|
+
: `${namespace}-${region}`;
|
|
246
|
+
}, _ApiContext_send = async function _ApiContext_send(url, namespaceHeader, userScoped) {
|
|
247
|
+
if (userScoped && !__classPrivateFieldGet(this, _ApiContext_userToken, "f")) {
|
|
248
|
+
throw new MissingUserTokenError();
|
|
249
|
+
}
|
|
250
|
+
const doFetch = async (forceNewToken) => {
|
|
251
|
+
const token = userScoped ? __classPrivateFieldGet(this, _ApiContext_userToken, "f") : await this.authenticate(forceNewToken);
|
|
252
|
+
const headers = { "Authorization": `Bearer ${token}` };
|
|
253
|
+
if (namespaceHeader)
|
|
254
|
+
headers["Battlenet-Namespace"] = namespaceHeader;
|
|
255
|
+
return await fetch(url, { method: "GET", headers });
|
|
256
|
+
};
|
|
257
|
+
let response = await doFetch(false);
|
|
258
|
+
if (response.status === 401 && !userScoped) {
|
|
259
|
+
// The cached token may have been revoked or expired early; retry once with a fresh one.
|
|
260
|
+
await response.body?.cancel();
|
|
261
|
+
response = await doFetch(true);
|
|
262
|
+
}
|
|
263
|
+
if (SERVER_ERROR_STATUSES.has(response.status)) {
|
|
264
|
+
// Transient gateway/server errors: requests are GETs, so retrying once is safe.
|
|
265
|
+
await response.body?.cancel();
|
|
266
|
+
await sleep(SERVER_ERROR_RETRY_DELAY_MS);
|
|
267
|
+
response = await doFetch(false);
|
|
268
|
+
}
|
|
269
|
+
for (let attempt = 1; response.status === 429 && attempt <= MAX_RATE_LIMIT_RETRIES; attempt++) {
|
|
270
|
+
// Rate limited: wait for Retry-After (seconds) if given, otherwise back off exponentially.
|
|
271
|
+
await response.body?.cancel();
|
|
272
|
+
await sleep(retryAfterMs(response.headers.get("Retry-After")) ?? RATE_LIMIT_BACKOFF_MS * 2 ** (attempt - 1));
|
|
273
|
+
response = await doFetch(false);
|
|
274
|
+
}
|
|
275
|
+
if (response.ok) {
|
|
276
|
+
return await response.json();
|
|
277
|
+
}
|
|
278
|
+
const text = await response.text();
|
|
279
|
+
let errorData = null;
|
|
280
|
+
try {
|
|
281
|
+
errorData = text ? JSON.parse(text) : null;
|
|
282
|
+
}
|
|
283
|
+
catch {
|
|
284
|
+
// Empty or non-JSON body (e.g. 404 with no body)
|
|
285
|
+
}
|
|
286
|
+
const statusCode = errorData?.code ?? response.status;
|
|
287
|
+
const errorMessage = errorData
|
|
288
|
+
? JSON.stringify(errorData)
|
|
289
|
+
: response.statusText || "Problem fetching data from API";
|
|
290
|
+
throw new APIError(errorMessage, statusCode, response.statusText);
|
|
291
|
+
}, _ApiContext_requestToken = async function _ApiContext_requestToken(config, body) {
|
|
292
|
+
const response = await fetch(`${oauthBaseUrl(config.region)}/token`, {
|
|
293
|
+
method: "POST",
|
|
294
|
+
headers: {
|
|
295
|
+
"Authorization": "Basic " + btoa(`${config.clientId}:${config.clientSecret}`),
|
|
296
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
297
|
+
},
|
|
298
|
+
body,
|
|
299
|
+
});
|
|
300
|
+
if (!response.ok) {
|
|
301
|
+
throw new AuthenticationError("Problem with Authentication", response.status, await response.text());
|
|
302
|
+
}
|
|
303
|
+
return await response.json();
|
|
304
|
+
};
|