@blizzard-api/core 3.0.0 → 3.0.1
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/README.md +25 -25
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
# @blizzard-api/core
|
|
2
|
-
|
|
3
|
-
This package provides core functionality to the other `@blizzard-api/*` packages.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```sh
|
|
8
|
-
npm i @blizzard-api/core
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Usage
|
|
12
|
-
|
|
13
|
-
The package includes a series of types that define values that are allowed to be passed to Battle.net API.
|
|
14
|
-
|
|
15
|
-
```ts
|
|
16
|
-
import type { BlizzardNamespaces, Locales, Origins } from '@blizzard-api/core';
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
It also includes a helper function to get the origin, hostname and locale easily accessible based off a single origin.
|
|
20
|
-
|
|
21
|
-
```ts
|
|
22
|
-
import type { getBlizzardApi } from '@blizzard-api/core';
|
|
23
|
-
|
|
24
|
-
const { origin, hostname, locale } = getBlizzardApi('eu'); // "kr" | "tw" | "us"
|
|
25
|
-
```
|
|
1
|
+
# @blizzard-api/core
|
|
2
|
+
|
|
3
|
+
This package provides core functionality to the other `@blizzard-api/*` packages.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm i @blizzard-api/core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
The package includes a series of types that define values that are allowed to be passed to Battle.net API.
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import type { BlizzardNamespaces, Locales, Origins } from '@blizzard-api/core';
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
It also includes a helper function to get the origin, hostname and locale easily accessible based off a single origin.
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import type { getBlizzardApi } from '@blizzard-api/core';
|
|
23
|
+
|
|
24
|
+
const { origin, hostname, locale } = getBlizzardApi('eu'); // "kr" | "tw" | "us"
|
|
25
|
+
```
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/base.ts","../src/blizzard-api.ts"],"sourcesContent":["/**\
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/base.ts","../src/blizzard-api.ts"],"sourcesContent":["/**\n * The base request path for the D3 API in the Blizzard API.\n */\nexport const d3BasePath = 'd3/data';\n\n/**\n * The base request path for profile APIs in the D3 API.\n */\nexport const d3ProfileBasePath = `d3/profile`;\n\n/**\n * The base request path for game data APIs in the D3 API.\n */\nexport const d3GameDataBasePath = `data/d3`;\n\n/**\n * The base request path for the Blizzard API for world of warcraft.\n */\nexport const wowBasePath = '/data/wow';\n\n/**\n * The base request path for the character API for Classic World of Warcraft.\n */\nexport const wowCharacterBasePath = 'profile/wow/character';\n\n/**\n * The base request path for media in the Blizzard API for world of warcraft.\n */\nexport const wowMediaBasePath = `${wowBasePath}/media` as const;\n\n/**\n * The base request path for search in the Blizzard API for world of warcraft.\n */\nexport const wowSearchBasePath = `${wowBasePath}/search` as const;\n\n/**\n * Base search parameters\n * orderby The field to order results by.\n * _page The page number to return.\n * @example\n * const params: BaseSearchParameters = {\n * orderby: 'name',\n * _page: 1,\n * };\n */\nexport interface BaseSearchParameters {\n _page?: number;\n orderby?: Array<string> | string;\n}\n/**\n * The standard structure to represent a World of Warcraft Character.\n */\nexport interface Character extends NameIdKey {\n realm: Realm;\n}\n\n/**\n * A record containing the RGBA values of a color.\n */\nexport interface Color {\n a: number;\n b: number;\n g: number;\n r: number;\n}\n\n/**\n * The faction associated with a character or entity in World of Warcraft.\n */\nexport interface Faction {\n name: string;\n type: Factions;\n}\n\n/**\n * The playable factions in World of Warcraft.\n */\nexport type Factions = 'ALLIANCE' | 'HORDE' | 'NEUTRAL';\n\n/**\n * The gender associated with a character or entity in World of Warcraft.\n */\nexport interface Gender {\n name: string;\n type: 'FEMALE' | 'MALE';\n}\n\n/**\n * The playable gender names/descriptions in World of Warcraft.\n */\nexport interface GenderName {\n female: null | string;\n male: null | string;\n}\n\nexport interface Href {\n href: string;\n}\n\n/**\n * Base record interface containing key.href property that often appear in Blizzard API responses.\n */\nexport interface KeyBase {\n key: Href;\n}\n\n/**\n * The media asset associated with a character or entity in World of Warcraft.\n */\nexport interface MediaAsset {\n file_data_id?: number;\n key: string;\n value: string;\n}\n\n/**\n * Base record interface containing name and id properties that often appear together in Blizzard API responses.\n */\nexport interface NameId {\n id: number;\n name: string;\n}\n\n/**\n * Base record containing both {@link KeyBase} and {@link NameId} interfaces.\n */\nexport interface NameIdKey extends KeyBase, NameId {}\n\n/**\n * The standard structure to represent a World of Warcraft Realm.\n */\nexport interface Realm extends KeyBase {\n id: number;\n name?: string;\n slug: string;\n}\n\n/**\n * Base interface for Blizzard API responses.\n */\nexport interface ResponseBase {\n _links: {\n self: Href;\n };\n}\n","import type { Locales, Origins } from './locales';\r\n\r\n/**\r\n * A record of regions and their supported locales.\r\n */\r\nconst _regionLocaleMap = {\r\n cn: ['zh_CN'],\r\n eu: ['en_GB', 'es_ES', 'fr_FR', 'ru_RU', 'de_DE', 'it_IT'],\r\n kr: ['ko_KR', 'en_GB', 'en_US'],\r\n tw: ['zh_TW', 'en_GB', 'en_US'],\r\n us: ['en_US', 'es_MX', 'pt_BR'],\r\n} as const satisfies Record<Origins, Array<Locales>>;\r\n\r\n/**\r\n * A record of Blizzard API configurations by region.\r\n */\r\ninterface BlizzardApiByRegion {\r\n cn: BlizzardApiDefault<'cn'>;\r\n eu: BlizzardApiDefault<'eu'>;\r\n kr: BlizzardApiDefault<'kr'>;\r\n tw: BlizzardApiDefault<'tw'>;\r\n us: BlizzardApiDefault<'us'>;\r\n}\r\n\r\n/**\r\n * The default Blizzard API configuration for each region.\r\n */\r\ninterface BlizzardApiDefault<T extends Origins> {\r\n defaultLocale: (typeof _regionLocaleMap)[T][number];\r\n hostname: T extends 'cn' ? 'https://gateway.battlenet.com.cn' : `https://${T}.api.blizzard.com`;\r\n}\r\n\r\nconst endpoints: BlizzardApiByRegion = {\r\n cn: {\r\n defaultLocale: 'zh_CN',\r\n hostname: 'https://gateway.battlenet.com.cn',\r\n },\r\n eu: {\r\n defaultLocale: 'en_GB',\r\n hostname: 'https://eu.api.blizzard.com',\r\n },\r\n kr: {\r\n defaultLocale: 'ko_KR',\r\n hostname: 'https://kr.api.blizzard.com',\r\n },\r\n tw: {\r\n defaultLocale: 'zh_TW',\r\n hostname: 'https://tw.api.blizzard.com',\r\n },\r\n us: {\r\n defaultLocale: 'en_US',\r\n hostname: 'https://us.api.blizzard.com',\r\n },\r\n};\r\n\r\n/**\r\n * A Blizzard API configuration object.\r\n * @template T The region of the Blizzard API.\r\n */\r\ninterface BlizzardApi<T extends Origins> {\r\n hostname: BlizzardApiDefault<Origins>['hostname'];\r\n locale: (typeof _regionLocaleMap)[T][number];\r\n origin: Origins;\r\n}\r\n\r\n/**\r\n * Get the Blizzard API configuration for a given region.\r\n * @template T The region of the Blizzard API.\r\n * @param origin The region of the Blizzard API.\r\n * @param locale The locale of the Blizzard API.\r\n * @returns The Blizzard API configuration for the given region.\r\n * @example\r\n * const api = getBlizzardApi('us', 'en_US');\r\n * console.log(api.hostname); // 'https://us.api.blizzard.com'\r\n * console.log(api.locale); // 'en_US'\r\n * console.log(api.origin); // 'us'\r\n */\r\nexport function getBlizzardApi<T extends Origins>(\r\n origin: T,\r\n locale?: (typeof _regionLocaleMap)[typeof origin][number],\r\n): BlizzardApi<typeof origin> {\r\n const endpoint = endpoints[origin];\r\n\r\n return {\r\n hostname: endpoint.hostname,\r\n locale: locale ?? endpoint.defaultLocale,\r\n origin,\r\n };\r\n}\r\n"],"mappings":";;;;AAGA,MAAa,aAAa;;;;AAK1B,MAAa,oBAAoB;;;;AAKjC,MAAa,qBAAqB;;;;AAKlC,MAAa,cAAc;;;;AAK3B,MAAa,uBAAuB;;;;AAKpC,MAAa,mBAAmB,GAAG,YAAY;;;;AAK/C,MAAa,oBAAoB,GAAG,YAAY;;;;ACDhD,MAAM,YAAiC;CACrC,IAAI;EACF,eAAe;EACf,UAAU;EACX;CACD,IAAI;EACF,eAAe;EACf,UAAU;EACX;CACD,IAAI;EACF,eAAe;EACf,UAAU;EACX;CACD,IAAI;EACF,eAAe;EACf,UAAU;EACX;CACD,IAAI;EACF,eAAe;EACf,UAAU;EACX;CACF;;;;;;;;;;;;;AAwBD,SAAgB,eACd,QACA,QAC4B;CAC5B,MAAM,WAAW,UAAU;AAE3B,QAAO;EACL,UAAU,SAAS;EACnB,QAAQ,UAAU,SAAS;EAC3B;EACD"}
|