@blizzard-api/core 2.1.0 → 3.0.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/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.d.ts CHANGED
@@ -1,36 +1,167 @@
1
+ //#region src/base.d.ts
2
+ /**
3
+ * The base request path for the D3 API in the Blizzard API.
4
+ */
5
+ declare const d3BasePath = "d3/data";
6
+ /**
7
+ * The base request path for profile APIs in the D3 API.
8
+ */
9
+ declare const d3ProfileBasePath = "d3/profile";
10
+ /**
11
+ * The base request path for game data APIs in the D3 API.
12
+ */
13
+ declare const d3GameDataBasePath = "data/d3";
14
+ /**
15
+ * The base request path for the Blizzard API for world of warcraft.
16
+ */
17
+ declare const wowBasePath = "/data/wow";
18
+ /**
19
+ * The base request path for the character API for Classic World of Warcraft.
20
+ */
21
+ declare const wowCharacterBasePath = "profile/wow/character";
22
+ /**
23
+ * The base request path for media in the Blizzard API for world of warcraft.
24
+ */
25
+ declare const wowMediaBasePath: "/data/wow/media";
26
+ /**
27
+ * The base request path for search in the Blizzard API for world of warcraft.
28
+ */
29
+ declare const wowSearchBasePath: "/data/wow/search";
30
+ /**
31
+ * Base search parameters
32
+ * orderby The field to order results by.
33
+ * _page The page number to return.
34
+ * @example
35
+ * const params: BaseSearchParameters = {
36
+ * orderby: 'name',
37
+ * _page: 1,
38
+ * };
39
+ */
40
+ interface BaseSearchParameters {
41
+ _page?: number;
42
+ orderby?: Array<string> | string;
43
+ }
44
+ /**
45
+ * The standard structure to represent a World of Warcraft Character.
46
+ */
47
+ interface Character extends NameIdKey {
48
+ realm: Realm;
49
+ }
50
+ /**
51
+ * A record containing the RGBA values of a color.
52
+ */
53
+ interface Color {
54
+ a: number;
55
+ b: number;
56
+ g: number;
57
+ r: number;
58
+ }
59
+ /**
60
+ * The faction associated with a character or entity in World of Warcraft.
61
+ */
62
+ interface Faction {
63
+ name: string;
64
+ type: Factions;
65
+ }
66
+ /**
67
+ * The playable factions in World of Warcraft.
68
+ */
69
+ type Factions = 'ALLIANCE' | 'HORDE' | 'NEUTRAL';
70
+ /**
71
+ * The gender associated with a character or entity in World of Warcraft.
72
+ */
73
+ interface Gender {
74
+ name: string;
75
+ type: 'FEMALE' | 'MALE';
76
+ }
77
+ /**
78
+ * The playable gender names/descriptions in World of Warcraft.
79
+ */
80
+ interface GenderName {
81
+ female: null | string;
82
+ male: null | string;
83
+ }
84
+ interface Href {
85
+ href: string;
86
+ }
87
+ /**
88
+ * Base record interface containing key.href property that often appear in Blizzard API responses.
89
+ */
90
+ interface KeyBase {
91
+ key: Href;
92
+ }
93
+ /**
94
+ * The media asset associated with a character or entity in World of Warcraft.
95
+ */
96
+ interface MediaAsset {
97
+ file_data_id?: number;
98
+ key: string;
99
+ value: string;
100
+ }
101
+ /**
102
+ * Base record interface containing name and id properties that often appear together in Blizzard API responses.
103
+ */
104
+ interface NameId {
105
+ id: number;
106
+ name: string;
107
+ }
108
+ /**
109
+ * Base record containing both {@link KeyBase} and {@link NameId} interfaces.
110
+ */
111
+ interface NameIdKey extends KeyBase, NameId {}
112
+ /**
113
+ * The standard structure to represent a World of Warcraft Realm.
114
+ */
115
+ interface Realm extends KeyBase {
116
+ id: number;
117
+ name?: string;
118
+ slug: string;
119
+ }
120
+ /**
121
+ * Base interface for Blizzard API responses.
122
+ */
123
+ interface ResponseBase {
124
+ _links: {
125
+ self: Href;
126
+ };
127
+ }
128
+ //#endregion
129
+ //#region src/locales.d.ts
1
130
  /**
2
131
  * Possible locales for use within the Blizzard API.
3
132
  */
4
- type Locales = 'de_DE' | 'en_GB' | 'en_US' | 'es_ES' | 'es_MX' | 'fr_FR' | 'it_IT' | 'ko_KR' | 'multi' | 'pt_BR' | 'pt_PT' | 'ru_RU' | 'zh_CN' | 'zh_TW';
133
+ 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';
5
134
  /**
6
135
  * Possible regions for use within the Blizzard API.
7
136
  */
8
137
  type Origins = 'cn' | 'eu' | 'kr' | 'tw' | 'us';
138
+ //#endregion
139
+ //#region src/blizzard-api.d.ts
9
140
  /**
10
141
  * A record of regions and their supported locales.
11
142
  */
12
143
  declare const _regionLocaleMap: {
13
- readonly cn: ["zh_CN"];
14
- readonly eu: ["en_GB", "es_ES", "fr_FR", "ru_RU", "de_DE", "pt_PT", "it_IT", "multi"];
15
- readonly kr: ["ko_KR", "en_GB", "en_US", "multi"];
16
- readonly tw: ["zh_TW", "en_GB", "en_US", "multi"];
17
- readonly us: ["en_US", "es_MX", "pt_BR", "multi"];
144
+ readonly cn: ["zh_CN"];
145
+ readonly eu: ["en_GB", "es_ES", "fr_FR", "ru_RU", "de_DE", "it_IT"];
146
+ readonly kr: ["ko_KR", "en_GB", "en_US"];
147
+ readonly tw: ["zh_TW", "en_GB", "en_US"];
148
+ readonly us: ["en_US", "es_MX", "pt_BR"];
18
149
  };
19
150
  /**
20
151
  * The default Blizzard API configuration for each region.
21
152
  */
22
153
  interface BlizzardApiDefault<T extends Origins> {
23
- defaultLocale: (typeof _regionLocaleMap)[T][number];
24
- hostname: T extends 'cn' ? 'https://gateway.battlenet.com.cn' : `https://${T}.api.blizzard.com`;
154
+ defaultLocale: (typeof _regionLocaleMap)[T][number];
155
+ hostname: T extends 'cn' ? 'https://gateway.battlenet.com.cn' : `https://${T}.api.blizzard.com`;
25
156
  }
26
157
  /**
27
158
  * A Blizzard API configuration object.
28
159
  * @template T The region of the Blizzard API.
29
160
  */
30
161
  interface BlizzardApi<T extends Origins> {
31
- hostname: BlizzardApiDefault<Origins>['hostname'];
32
- locale: (typeof _regionLocaleMap)[T][number];
33
- origin: Origins;
162
+ hostname: BlizzardApiDefault<Origins>['hostname'];
163
+ locale: (typeof _regionLocaleMap)[T][number];
164
+ origin: Origins;
34
165
  }
35
166
  /**
36
167
  * Get the Blizzard API configuration for a given region.
@@ -45,13 +176,15 @@ interface BlizzardApi<T extends Origins> {
45
176
  * console.log(api.origin); // 'us'
46
177
  */
47
178
  declare function getBlizzardApi<T extends Origins>(origin: T, locale?: (typeof _regionLocaleMap)[typeof origin][number]): BlizzardApi<typeof origin>;
48
-
179
+ //#endregion
180
+ //#region src/namespace.d.ts
49
181
  /**
50
182
  * Blizzard API namespaces.
51
183
  * @see https://develop.battle.net/documentation/world-of-warcraft/guides/namespaces
52
184
  */
53
185
  type BlizzardNamespaces = 'dynamic' | 'dynamic-classic1x' | 'dynamic-classic' | 'profile' | 'profile-classic1x' | 'profile-classic' | 'static' | 'static-classic1x' | 'static-classic';
54
-
186
+ //#endregion
187
+ //#region src/resource.d.ts
55
188
  /**
56
189
  * Extracts the response type from a resource
57
190
  * @param Type The resource type
@@ -72,17 +205,17 @@ type ProtectedResource<Response, SearchOptions extends object = Record<string, n
72
205
  * @param SearchOptions The search options that can be passed to the resource
73
206
  * @param ProtectedResource Whether the resource requires a token to be requested
74
207
  */
75
- type Resource<Response, SearchOptions extends object = Record<string, never>, IsProtectedResource extends boolean = false> = (IsProtectedResource extends true ? {
76
- token: string;
208
+ type Resource<Response, SearchOptions extends object = Record<string, unknown>, IsProtectedResource extends boolean = false> = (IsProtectedResource extends true ? {
209
+ token: string;
77
210
  } : unknown) & {
78
- /**
79
- * The response type of the resource
80
- * @internal
81
- */
82
- _responseType?: Response;
83
- namespace?: BlizzardNamespaces;
84
- parameters?: SearchOptions;
85
- path: string;
211
+ /**
212
+ * The response type of the resource
213
+ * @internal
214
+ */
215
+ _responseType?: Response;
216
+ namespace?: BlizzardNamespaces;
217
+ parameters?: SearchOptions;
218
+ path: string;
86
219
  };
87
220
  /**
88
221
  * Represents the response of a resource
@@ -93,21 +226,8 @@ type Resource<Response, SearchOptions extends object = Record<string, never>, Is
93
226
  * response.then((data) => console.log(data.id));
94
227
  */
95
228
  type ResourceResponse<T = unknown> = Promise<T>;
96
-
97
- /**
98
- * Base search parameters
99
- * orderby The field to order results by.
100
- * _page The page number to return.
101
- * @example
102
- * const params: BaseSearchParameters = {
103
- * orderby: 'name',
104
- * _page: 1,
105
- * };
106
- */
107
- interface BaseSearchParameters {
108
- _page?: number;
109
- orderby?: Array<string> | string;
110
- }
229
+ //#endregion
230
+ //#region src/search.d.ts
111
231
  /**
112
232
  * Search response
113
233
  * page The current page number.
@@ -121,16 +241,15 @@ interface BaseSearchParameters {
121
241
  * pageSize: 20,
122
242
  * maxPageSize: 100,
123
243
  * pageCount: 10,
124
- * results: [],
125
244
  * };
126
245
  */
127
- interface SearchResponse<T> {
128
- maxPageSize: number;
129
- page: number;
130
- pageCount: number;
131
- pageSize: number;
132
- resultCountCapped?: boolean;
133
- results: Array<T>;
246
+ interface SearchResponseWithoutResults {
247
+ maxPageSize: number;
248
+ page: number;
249
+ pageCount: number;
250
+ pageSize: number;
251
+ resultCountCapped?: boolean;
134
252
  }
135
-
136
- export { type BaseSearchParameters, type BlizzardNamespaces, type ExtractResourceType, type Locales, type Origins, type ProtectedResource, type Resource, type ResourceResponse, type SearchResponse, getBlizzardApi };
253
+ //#endregion
254
+ export { BaseSearchParameters, BlizzardNamespaces, Character, Color, ExtractResourceType, Faction, Factions, Gender, GenderName, Href, KeyBase, Locales, MediaAsset, NameId, NameIdKey, Origins, ProtectedResource, Realm, Resource, ResourceResponse, ResponseBase, SearchResponseWithoutResults, d3BasePath, d3GameDataBasePath, d3ProfileBasePath, getBlizzardApi, wowBasePath, wowCharacterBasePath, wowMediaBasePath, wowSearchBasePath };
255
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,35 +1,78 @@
1
- // src/blizzard-api.ts
2
- var endpoints = {
3
- cn: {
4
- defaultLocale: "zh_CN",
5
- hostname: "https://gateway.battlenet.com.cn"
6
- },
7
- eu: {
8
- defaultLocale: "en_GB",
9
- hostname: "https://eu.api.blizzard.com"
10
- },
11
- kr: {
12
- defaultLocale: "ko_KR",
13
- hostname: "https://kr.api.blizzard.com"
14
- },
15
- tw: {
16
- defaultLocale: "zh_TW",
17
- hostname: "https://tw.api.blizzard.com"
18
- },
19
- us: {
20
- defaultLocale: "en_US",
21
- hostname: "https://us.api.blizzard.com"
22
- }
1
+ //#region src/base.ts
2
+ /**
3
+ * The base request path for the D3 API in the Blizzard API.
4
+ */
5
+ const d3BasePath = "d3/data";
6
+ /**
7
+ * The base request path for profile APIs in the D3 API.
8
+ */
9
+ const d3ProfileBasePath = `d3/profile`;
10
+ /**
11
+ * The base request path for game data APIs in the D3 API.
12
+ */
13
+ const d3GameDataBasePath = `data/d3`;
14
+ /**
15
+ * The base request path for the Blizzard API for world of warcraft.
16
+ */
17
+ const wowBasePath = "/data/wow";
18
+ /**
19
+ * The base request path for the character API for Classic World of Warcraft.
20
+ */
21
+ const wowCharacterBasePath = "profile/wow/character";
22
+ /**
23
+ * The base request path for media in the Blizzard API for world of warcraft.
24
+ */
25
+ const wowMediaBasePath = `${wowBasePath}/media`;
26
+ /**
27
+ * The base request path for search in the Blizzard API for world of warcraft.
28
+ */
29
+ const wowSearchBasePath = `${wowBasePath}/search`;
30
+
31
+ //#endregion
32
+ //#region src/blizzard-api.ts
33
+ const endpoints = {
34
+ cn: {
35
+ defaultLocale: "zh_CN",
36
+ hostname: "https://gateway.battlenet.com.cn"
37
+ },
38
+ eu: {
39
+ defaultLocale: "en_GB",
40
+ hostname: "https://eu.api.blizzard.com"
41
+ },
42
+ kr: {
43
+ defaultLocale: "ko_KR",
44
+ hostname: "https://kr.api.blizzard.com"
45
+ },
46
+ tw: {
47
+ defaultLocale: "zh_TW",
48
+ hostname: "https://tw.api.blizzard.com"
49
+ },
50
+ us: {
51
+ defaultLocale: "en_US",
52
+ hostname: "https://us.api.blizzard.com"
53
+ }
23
54
  };
55
+ /**
56
+ * Get the Blizzard API configuration for a given region.
57
+ * @template T The region of the Blizzard API.
58
+ * @param origin The region of the Blizzard API.
59
+ * @param locale The locale of the Blizzard API.
60
+ * @returns The Blizzard API configuration for the given region.
61
+ * @example
62
+ * const api = getBlizzardApi('us', 'en_US');
63
+ * console.log(api.hostname); // 'https://us.api.blizzard.com'
64
+ * console.log(api.locale); // 'en_US'
65
+ * console.log(api.origin); // 'us'
66
+ */
24
67
  function getBlizzardApi(origin, locale) {
25
- const endpoint = endpoints[origin];
26
- return {
27
- hostname: endpoint.hostname,
28
- locale: locale ?? endpoint.defaultLocale,
29
- origin
30
- };
68
+ const endpoint = endpoints[origin];
69
+ return {
70
+ hostname: endpoint.hostname,
71
+ locale: locale ?? endpoint.defaultLocale,
72
+ origin
73
+ };
31
74
  }
32
75
 
33
- export { getBlizzardApi };
34
- //# sourceMappingURL=index.js.map
76
+ //#endregion
77
+ export { d3BasePath, d3GameDataBasePath, d3ProfileBasePath, getBlizzardApi, wowBasePath, wowCharacterBasePath, wowMediaBasePath, wowSearchBasePath };
35
78
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/blizzard-api.ts"],"names":[],"mappings":";AAqDA,IAAM,SAAiC,GAAA;AAAA,EACrC,EAAI,EAAA;AAAA,IACF,aAAe,EAAA,OAAA;AAAA,IACf,QAAU,EAAA;AAAA,GACZ;AAAA,EACA,EAAI,EAAA;AAAA,IACF,aAAe,EAAA,OAAA;AAAA,IACf,QAAU,EAAA;AAAA,GACZ;AAAA,EACA,EAAI,EAAA;AAAA,IACF,aAAe,EAAA,OAAA;AAAA,IACf,QAAU,EAAA;AAAA,GACZ;AAAA,EACA,EAAI,EAAA;AAAA,IACF,aAAe,EAAA,OAAA;AAAA,IACf,QAAU,EAAA;AAAA,GACZ;AAAA,EACA,EAAI,EAAA;AAAA,IACF,aAAe,EAAA,OAAA;AAAA,IACf,QAAU,EAAA;AAAA;AAEd,CAAA;AAwBO,SAAS,cAAA,CACd,QACA,MAC4B,EAAA;AAC5B,EAAM,MAAA,QAAA,GAAW,UAAU,MAAM,CAAA;AAEjC,EAAO,OAAA;AAAA,IACL,UAAU,QAAS,CAAA,QAAA;AAAA,IACnB,MAAA,EAAQ,UAAU,QAAS,CAAA,aAAA;AAAA,IAC3B;AAAA,GACF;AACF","file":"index.js","sourcesContent":["/**\r\n * Possible locales for use within the Blizzard API.\r\n */\r\nexport type Locales =\r\n | 'de_DE'\r\n | 'en_GB'\r\n | 'en_US'\r\n | 'es_ES'\r\n | 'es_MX'\r\n | 'fr_FR'\r\n | 'it_IT'\r\n | 'ko_KR'\r\n | 'multi'\r\n | 'pt_BR'\r\n | 'pt_PT'\r\n | 'ru_RU'\r\n | 'zh_CN'\r\n | 'zh_TW';\r\n/**\r\n * Possible regions for use within the Blizzard API.\r\n */\r\nexport type Origins = 'cn' | 'eu' | 'kr' | 'tw' | 'us';\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', 'pt_PT', 'it_IT', 'multi'],\r\n kr: ['ko_KR', 'en_GB', 'en_US', 'multi'],\r\n tw: ['zh_TW', 'en_GB', 'en_US', 'multi'],\r\n us: ['en_US', 'es_MX', 'pt_BR', 'multi'],\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"]}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/base.ts","../src/blizzard-api.ts"],"sourcesContent":["/**\r\n * The base request path for the D3 API in the Blizzard API.\r\n */\r\nexport const d3BasePath = 'd3/data';\r\n\r\n/**\r\n * The base request path for profile APIs in the D3 API.\r\n */\r\nexport const d3ProfileBasePath = `d3/profile`;\r\n\r\n/**\r\n * The base request path for game data APIs in the D3 API.\r\n */\r\nexport const d3GameDataBasePath = `data/d3`;\r\n\r\n/**\r\n * The base request path for the Blizzard API for world of warcraft.\r\n */\r\nexport const wowBasePath = '/data/wow';\r\n\r\n/**\r\n * The base request path for the character API for Classic World of Warcraft.\r\n */\r\nexport const wowCharacterBasePath = 'profile/wow/character';\r\n\r\n/**\r\n * The base request path for media in the Blizzard API for world of warcraft.\r\n */\r\nexport const wowMediaBasePath = `${wowBasePath}/media` as const;\r\n\r\n/**\r\n * The base request path for search in the Blizzard API for world of warcraft.\r\n */\r\nexport const wowSearchBasePath = `${wowBasePath}/search` as const;\r\n\r\n/**\r\n * Base search parameters\r\n * orderby The field to order results by.\r\n * _page The page number to return.\r\n * @example\r\n * const params: BaseSearchParameters = {\r\n * orderby: 'name',\r\n * _page: 1,\r\n * };\r\n */\r\nexport interface BaseSearchParameters {\r\n _page?: number;\r\n orderby?: Array<string> | string;\r\n}\r\n/**\r\n * The standard structure to represent a World of Warcraft Character.\r\n */\r\nexport interface Character extends NameIdKey {\r\n realm: Realm;\r\n}\r\n\r\n/**\r\n * A record containing the RGBA values of a color.\r\n */\r\nexport interface Color {\r\n a: number;\r\n b: number;\r\n g: number;\r\n r: number;\r\n}\r\n\r\n/**\r\n * The faction associated with a character or entity in World of Warcraft.\r\n */\r\nexport interface Faction {\r\n name: string;\r\n type: Factions;\r\n}\r\n\r\n/**\r\n * The playable factions in World of Warcraft.\r\n */\r\nexport type Factions = 'ALLIANCE' | 'HORDE' | 'NEUTRAL';\r\n\r\n/**\r\n * The gender associated with a character or entity in World of Warcraft.\r\n */\r\nexport interface Gender {\r\n name: string;\r\n type: 'FEMALE' | 'MALE';\r\n}\r\n\r\n/**\r\n * The playable gender names/descriptions in World of Warcraft.\r\n */\r\nexport interface GenderName {\r\n female: null | string;\r\n male: null | string;\r\n}\r\n\r\nexport interface Href {\r\n href: string;\r\n}\r\n\r\n/**\r\n * Base record interface containing key.href property that often appear in Blizzard API responses.\r\n */\r\nexport interface KeyBase {\r\n key: Href;\r\n}\r\n\r\n/**\r\n * The media asset associated with a character or entity in World of Warcraft.\r\n */\r\nexport interface MediaAsset {\r\n file_data_id?: number;\r\n key: string;\r\n value: string;\r\n}\r\n\r\n/**\r\n * Base record interface containing name and id properties that often appear together in Blizzard API responses.\r\n */\r\nexport interface NameId {\r\n id: number;\r\n name: string;\r\n}\r\n\r\n/**\r\n * Base record containing both {@link KeyBase} and {@link NameId} interfaces.\r\n */\r\nexport interface NameIdKey extends KeyBase, NameId {}\r\n\r\n/**\r\n * The standard structure to represent a World of Warcraft Realm.\r\n */\r\nexport interface Realm extends KeyBase {\r\n id: number;\r\n name?: string;\r\n slug: string;\r\n}\r\n\r\n/**\r\n * Base interface for Blizzard API responses.\r\n */\r\nexport interface ResponseBase {\r\n _links: {\r\n self: Href;\r\n };\r\n}\r\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"}
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@blizzard-api/core",
3
- "version": "2.1.0",
3
+ "version": "3.0.0",
4
4
  "license": "MIT",
5
5
  "author": "Putro",
6
6
  "description": "The core helpers used by all @blizzard-api/* packages.",
7
7
  "repository": "https://github.com/Pewtro/blizzard-api/tree/main/packages/core",
8
8
  "type": "module",
9
9
  "engines": {
10
- "node": "^18.18 || >=20.9"
10
+ "node": "^20.19.0 || ^22.13.0 || >=24"
11
11
  },
12
12
  "module": "./dist/index.js",
13
13
  "types": "./dist/index.d.ts",
@@ -42,8 +42,8 @@
42
42
  "dependencies": {},
43
43
  "devDependencies": {},
44
44
  "scripts": {
45
- "build": "tsup",
46
- "dev": "tsup --watch",
45
+ "build": "tsdown",
46
+ "dev": "tsdown --watch",
47
47
  "test": "vitest run",
48
48
  "test:coverage": "pnpm test -- --coverage",
49
49
  "test:watch": "vitest watch"