UNPKG

@blizzard-api/core

Version:

The core helpers used by all @blizzard-api/* packages.

253 lines 7.74 kB
//#region src/base.d.ts /** * The base request path for the D3 API in the Blizzard API. */ declare const d3BasePath = "d3/data"; /** * The base request path for profile APIs in the D3 API. */ declare const d3ProfileBasePath = "d3/profile"; /** * The base request path for game data APIs in the D3 API. */ declare const d3GameDataBasePath = "data/d3"; /** * The base request path for the Blizzard API for world of warcraft. */ declare const wowBasePath = "/data/wow"; /** * The base request path for the character API for Classic World of Warcraft. */ declare const wowCharacterBasePath = "profile/wow/character"; /** * The base request path for media in the Blizzard API for world of warcraft. */ declare const wowMediaBasePath: "/data/wow/media"; /** * The base request path for search in the Blizzard API for world of warcraft. */ declare const wowSearchBasePath: "/data/wow/search"; /** * Base search parameters * orderby The field to order results by. * _page The page number to return. * @example * const params: BaseSearchParameters = { * orderby: 'name', * _page: 1, * }; */ interface BaseSearchParameters { _page?: number; orderby?: Array<string> | string; } /** * The standard structure to represent a World of Warcraft Character. */ interface Character extends NameIdKey { realm: Realm; } /** * A record containing the RGBA values of a color. */ interface Color { a: number; b: number; g: number; r: number; } /** * The faction associated with a character or entity in World of Warcraft. */ interface Faction { name: string; type: Factions; } /** * The playable factions in World of Warcraft. */ type Factions = 'ALLIANCE' | 'HORDE' | 'NEUTRAL'; /** * The playable factions at max level in World of Warcraft. */ type NonNeutralFactions = 'ALLIANCE' | 'HORDE'; /** * The gender associated with a character or entity in World of Warcraft. */ interface Gender { name: string; type: 'FEMALE' | 'MALE'; } /** * The playable gender names/descriptions in World of Warcraft. */ interface GenderName { female: null | string; male: null | string; } interface Href { href: string; } /** * Base record interface containing key.href property that often appear in Blizzard API responses. */ interface KeyBase { key: Href; } /** * The media asset associated with a character or entity in World of Warcraft. */ interface MediaAsset { file_data_id?: number; key: string; value: string; } /** * Base record interface containing name and id properties that often appear together in Blizzard API responses. */ interface NameId { id: number; name: string; } /** * Base record containing both {@link KeyBase} and {@link NameId} interfaces. */ interface NameIdKey extends KeyBase, NameId {} interface NullishNameIdKey extends Omit<NameIdKey, 'name'> { name: null | string; } /** * The standard structure to represent a World of Warcraft Realm. */ interface Realm extends KeyBase { id: number; name?: string; slug: string; } /** * Base interface for Blizzard API responses. */ interface ResponseBase { _links: { self: Href; }; } //#endregion //#region src/locales.d.ts /** * Possible locales for use within the Blizzard API. */ type Locales = 'de_DE' | 'en_GB' | 'en_US' | 'es_ES' | 'es_MX' | 'fr_FR' | 'it_IT' | 'ko_KR' | 'pt_BR' | 'ru_RU' | 'zh_CN' | 'zh_TW'; /** * Possible regions for use within the Blizzard API. */ type Origins = 'cn' | 'eu' | 'kr' | 'tw' | 'us'; //#endregion //#region src/blizzard-api.d.ts /** * A record of regions and their supported locales. */ declare const _regionLocaleMap: { readonly cn: ["zh_CN"]; readonly eu: ["en_GB", "es_ES", "fr_FR", "ru_RU", "de_DE", "it_IT"]; readonly kr: ["ko_KR", "en_GB", "en_US"]; readonly tw: ["zh_TW", "en_GB", "en_US"]; readonly us: ["en_US", "es_MX", "pt_BR"]; }; /** * The default Blizzard API configuration for each region. */ interface BlizzardApiDefault<T extends Origins> { defaultLocale: (typeof _regionLocaleMap)[T][number]; hostname: T extends 'cn' ? 'https://gateway.battlenet.com.cn' : `https://${T}.api.blizzard.com`; } /** * A Blizzard API configuration object. * @template T The region of the Blizzard API. */ interface BlizzardApi<T extends Origins> { hostname: BlizzardApiDefault<Origins>['hostname']; locale: (typeof _regionLocaleMap)[T][number]; origin: Origins; } /** * Get the Blizzard API configuration for a given region. * @template T The region of the Blizzard API. * @param origin The region of the Blizzard API. * @param locale The locale of the Blizzard API. * @returns The Blizzard API configuration for the given region. * @example * const api = getBlizzardApi('us', 'en_US'); * console.log(api.hostname); // 'https://us.api.blizzard.com' * console.log(api.locale); // 'en_US' * console.log(api.origin); // 'us' */ declare function getBlizzardApi<T extends Origins>(origin: T, locale?: (typeof _regionLocaleMap)[typeof origin][number]): BlizzardApi<typeof origin>; //#endregion //#region src/namespace.d.ts /** * Blizzard API namespaces. * @see https://develop.battle.net/documentation/world-of-warcraft/guides/namespaces */ type BlizzardNamespaces = 'dynamic' | 'dynamic-classic1x' | 'dynamic-classic' | 'profile' | 'profile-classic1x' | 'profile-classic' | 'static' | 'static-classic1x' | 'static-classic'; //#endregion //#region src/resource.d.ts /** * Extracts the response type from a resource * @param Type The resource type * @returns The response type * @example * type extracted = ExtractResourceType<Resource<{ id: number }>>; */ type ExtractResourceType<Type> = Type extends Resource<infer R, infer _SearchOptions, infer _Protected> ? R : never; /** * Represents a resource that requires a token to be requested * @param Response The response type of the resource * @param SearchOptions The search options that can be passed to the resource */ type ProtectedResource<Response, SearchOptions extends object = Record<string, never>> = Resource<Response, SearchOptions, true>; /** * Represents a resource that can be requested from the Blizzard API * @param _Response The response type of the resource * @param SearchOptions The search options that can be passed to the resource * @param ProtectedResource Whether the resource requires a token to be requested */ type Resource<Response, SearchOptions extends object = Record<string, unknown>, IsProtectedResource extends boolean = false> = (IsProtectedResource extends true ? { token: string; } : unknown) & { /** * The response type of the resource * @internal */ _responseType?: Response; namespace?: BlizzardNamespaces; parameters?: SearchOptions; path: string; }; //#endregion //#region src/search.d.ts /** * Search response * page The current page number. * pageSize The number of results per page. * maxPageSize The maximum number of results per page. * pageCount The total number of pages. * results The search results. * @example * const response: SearchResponse = { * page: 1, * pageSize: 20, * maxPageSize: 100, * pageCount: 10, * }; */ interface SearchResponseWithoutResults { maxPageSize: number; page: number; pageCount: number; pageSize: number; resultCountCapped?: boolean; } //#endregion export { BaseSearchParameters, BlizzardNamespaces, Character, Color, ExtractResourceType, Faction, Factions, Gender, GenderName, Href, KeyBase, Locales, MediaAsset, NameId, NameIdKey, NonNeutralFactions, NullishNameIdKey, Origins, ProtectedResource, Realm, Resource, ResponseBase, SearchResponseWithoutResults, d3BasePath, d3GameDataBasePath, d3ProfileBasePath, getBlizzardApi, wowBasePath, wowCharacterBasePath, wowMediaBasePath, wowSearchBasePath }; //# sourceMappingURL=index.d.ts.map