@blizzard-api/core 1.1.1 → 1.2.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/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -6
- package/dist/index.d.ts +13 -6
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/blizzard-api.ts"],"names":[],"mappings":"
|
|
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,kCAAA;AAAA,GACZ;AAAA,EACA,EAAI,EAAA;AAAA,IACF,aAAe,EAAA,OAAA;AAAA,IACf,QAAU,EAAA,6BAAA;AAAA,GACZ;AAAA,EACA,EAAI,EAAA;AAAA,IACF,aAAe,EAAA,OAAA;AAAA,IACf,QAAU,EAAA,6BAAA;AAAA,GACZ;AAAA,EACA,EAAI,EAAA;AAAA,IACF,aAAe,EAAA,OAAA;AAAA,IACf,QAAU,EAAA,6BAAA;AAAA,GACZ;AAAA,EACA,EAAI,EAAA;AAAA,IACF,aAAe,EAAA,OAAA;AAAA,IACf,QAAU,EAAA,6BAAA;AAAA,GACZ;AACF,CAAA,CAAA;AA2BO,SAAS,cAAA,CACd,QACA,MAC4B,EAAA;AAC5B,EAAM,MAAA,QAAA,GAAW,UAAU,MAAM,CAAA,CAAA;AAEjC,EAAO,OAAA;AAAA,IACL,UAAU,QAAS,CAAA,QAAA;AAAA,IACnB,MAAA,EAAQ,UAAU,QAAS,CAAA,aAAA;AAAA,IAC3B,MAAA;AAAA,GACF,CAAA;AACF","file":"index.cjs","sourcesContent":["/**\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 * 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/**\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 * 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\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\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 * @property origin The region of the Blizzard API.\r\n * @property locale The locale of the Blizzard API.\r\n * @property hostname The hostname 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"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -9,7 +9,7 @@ type Locales = 'de_DE' | 'en_GB' | 'en_US' | 'es_ES' | 'es_MX' | 'fr_FR' | 'it_I
|
|
|
9
9
|
/**
|
|
10
10
|
* A record of regions and their supported locales.
|
|
11
11
|
*/
|
|
12
|
-
declare const
|
|
12
|
+
declare const _regionLocaleMap: {
|
|
13
13
|
readonly cn: ["zh_CN"];
|
|
14
14
|
readonly eu: ["en_GB", "es_ES", "fr_FR", "ru_RU", "de_DE", "pt_PT", "it_IT", "multi"];
|
|
15
15
|
readonly kr: ["ko_KR", "en_GB", "en_US", "multi"];
|
|
@@ -20,7 +20,7 @@ declare const locales: {
|
|
|
20
20
|
* The default Blizzard API configuration for each region.
|
|
21
21
|
*/
|
|
22
22
|
interface BlizzardApiDefault<T extends Origins> {
|
|
23
|
-
defaultLocale: (typeof
|
|
23
|
+
defaultLocale: (typeof _regionLocaleMap)[T][number];
|
|
24
24
|
hostname: T extends 'cn' ? 'https://gateway.battlenet.com.cn' : `https://${T}.api.blizzard.com`;
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
@@ -32,7 +32,7 @@ interface BlizzardApiDefault<T extends Origins> {
|
|
|
32
32
|
*/
|
|
33
33
|
interface BlizzardApi<T extends Origins> {
|
|
34
34
|
hostname: BlizzardApiDefault<Origins>['hostname'];
|
|
35
|
-
locale: (typeof
|
|
35
|
+
locale: (typeof _regionLocaleMap)[T][number];
|
|
36
36
|
origin: Origins;
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
@@ -47,13 +47,13 @@ interface BlizzardApi<T extends Origins> {
|
|
|
47
47
|
* console.log(api.locale); // 'en_US'
|
|
48
48
|
* console.log(api.origin); // 'us'
|
|
49
49
|
*/
|
|
50
|
-
declare function getBlizzardApi<T extends Origins>(origin: T, locale?: (typeof
|
|
50
|
+
declare function getBlizzardApi<T extends Origins>(origin: T, locale?: (typeof _regionLocaleMap)[typeof origin][number]): BlizzardApi<typeof origin>;
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
53
|
* Blizzard API namespaces.
|
|
54
54
|
* @see https://develop.battle.net/documentation/world-of-warcraft/guides/namespaces
|
|
55
55
|
*/
|
|
56
|
-
type BlizzardNamespaces = 'dynamic
|
|
56
|
+
type BlizzardNamespaces = 'dynamic' | 'dynamic-classic' | 'dynamic-classic1x' | 'profile' | 'static' | 'static-classic' | 'static-classic1x';
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
59
|
* Represents a resource that can be requested from the Blizzard API
|
|
@@ -73,6 +73,13 @@ type Resource<Response, SearchOptions extends object = Record<string, never>, Pr
|
|
|
73
73
|
} & (ProtectedResource extends true ? {
|
|
74
74
|
token: string;
|
|
75
75
|
} : unknown);
|
|
76
|
+
/**
|
|
77
|
+
* Represents a resource that requires a token to be requested
|
|
78
|
+
* @param Response The response type of the resource
|
|
79
|
+
* @param SearchOptions The search options that can be passed to the resource
|
|
80
|
+
*
|
|
81
|
+
*/
|
|
82
|
+
type ProtectedResource<Response, SearchOptions extends object = Record<string, never>> = Resource<Response, SearchOptions, true>;
|
|
76
83
|
/**
|
|
77
84
|
* Represents the response of a resource
|
|
78
85
|
* @param T The response type of the resource
|
|
@@ -132,4 +139,4 @@ interface SearchResponse<T> {
|
|
|
132
139
|
results: Array<T>;
|
|
133
140
|
}
|
|
134
141
|
|
|
135
|
-
export { type BaseSearchParameters, type BlizzardNamespaces, type ExtractResourceType, type Locales, type Origins, type Resource, type ResourceResponse, type SearchResponse, getBlizzardApi };
|
|
142
|
+
export { type BaseSearchParameters, type BlizzardNamespaces, type ExtractResourceType, type Locales, type Origins, type ProtectedResource, type Resource, type ResourceResponse, type SearchResponse, getBlizzardApi };
|
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ type Locales = 'de_DE' | 'en_GB' | 'en_US' | 'es_ES' | 'es_MX' | 'fr_FR' | 'it_I
|
|
|
9
9
|
/**
|
|
10
10
|
* A record of regions and their supported locales.
|
|
11
11
|
*/
|
|
12
|
-
declare const
|
|
12
|
+
declare const _regionLocaleMap: {
|
|
13
13
|
readonly cn: ["zh_CN"];
|
|
14
14
|
readonly eu: ["en_GB", "es_ES", "fr_FR", "ru_RU", "de_DE", "pt_PT", "it_IT", "multi"];
|
|
15
15
|
readonly kr: ["ko_KR", "en_GB", "en_US", "multi"];
|
|
@@ -20,7 +20,7 @@ declare const locales: {
|
|
|
20
20
|
* The default Blizzard API configuration for each region.
|
|
21
21
|
*/
|
|
22
22
|
interface BlizzardApiDefault<T extends Origins> {
|
|
23
|
-
defaultLocale: (typeof
|
|
23
|
+
defaultLocale: (typeof _regionLocaleMap)[T][number];
|
|
24
24
|
hostname: T extends 'cn' ? 'https://gateway.battlenet.com.cn' : `https://${T}.api.blizzard.com`;
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
@@ -32,7 +32,7 @@ interface BlizzardApiDefault<T extends Origins> {
|
|
|
32
32
|
*/
|
|
33
33
|
interface BlizzardApi<T extends Origins> {
|
|
34
34
|
hostname: BlizzardApiDefault<Origins>['hostname'];
|
|
35
|
-
locale: (typeof
|
|
35
|
+
locale: (typeof _regionLocaleMap)[T][number];
|
|
36
36
|
origin: Origins;
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
@@ -47,13 +47,13 @@ interface BlizzardApi<T extends Origins> {
|
|
|
47
47
|
* console.log(api.locale); // 'en_US'
|
|
48
48
|
* console.log(api.origin); // 'us'
|
|
49
49
|
*/
|
|
50
|
-
declare function getBlizzardApi<T extends Origins>(origin: T, locale?: (typeof
|
|
50
|
+
declare function getBlizzardApi<T extends Origins>(origin: T, locale?: (typeof _regionLocaleMap)[typeof origin][number]): BlizzardApi<typeof origin>;
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
53
|
* Blizzard API namespaces.
|
|
54
54
|
* @see https://develop.battle.net/documentation/world-of-warcraft/guides/namespaces
|
|
55
55
|
*/
|
|
56
|
-
type BlizzardNamespaces = 'dynamic
|
|
56
|
+
type BlizzardNamespaces = 'dynamic' | 'dynamic-classic' | 'dynamic-classic1x' | 'profile' | 'static' | 'static-classic' | 'static-classic1x';
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
59
|
* Represents a resource that can be requested from the Blizzard API
|
|
@@ -73,6 +73,13 @@ type Resource<Response, SearchOptions extends object = Record<string, never>, Pr
|
|
|
73
73
|
} & (ProtectedResource extends true ? {
|
|
74
74
|
token: string;
|
|
75
75
|
} : unknown);
|
|
76
|
+
/**
|
|
77
|
+
* Represents a resource that requires a token to be requested
|
|
78
|
+
* @param Response The response type of the resource
|
|
79
|
+
* @param SearchOptions The search options that can be passed to the resource
|
|
80
|
+
*
|
|
81
|
+
*/
|
|
82
|
+
type ProtectedResource<Response, SearchOptions extends object = Record<string, never>> = Resource<Response, SearchOptions, true>;
|
|
76
83
|
/**
|
|
77
84
|
* Represents the response of a resource
|
|
78
85
|
* @param T The response type of the resource
|
|
@@ -132,4 +139,4 @@ interface SearchResponse<T> {
|
|
|
132
139
|
results: Array<T>;
|
|
133
140
|
}
|
|
134
141
|
|
|
135
|
-
export { type BaseSearchParameters, type BlizzardNamespaces, type ExtractResourceType, type Locales, type Origins, type Resource, type ResourceResponse, type SearchResponse, getBlizzardApi };
|
|
142
|
+
export { type BaseSearchParameters, type BlizzardNamespaces, type ExtractResourceType, type Locales, type Origins, type ProtectedResource, type Resource, type ResourceResponse, type SearchResponse, getBlizzardApi };
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/blizzard-api.ts"],"names":[],"mappings":";AAqDA,IAAM,
|
|
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,kCAAA;AAAA,GACZ;AAAA,EACA,EAAI,EAAA;AAAA,IACF,aAAe,EAAA,OAAA;AAAA,IACf,QAAU,EAAA,6BAAA;AAAA,GACZ;AAAA,EACA,EAAI,EAAA;AAAA,IACF,aAAe,EAAA,OAAA;AAAA,IACf,QAAU,EAAA,6BAAA;AAAA,GACZ;AAAA,EACA,EAAI,EAAA;AAAA,IACF,aAAe,EAAA,OAAA;AAAA,IACf,QAAU,EAAA,6BAAA;AAAA,GACZ;AAAA,EACA,EAAI,EAAA;AAAA,IACF,aAAe,EAAA,OAAA;AAAA,IACf,QAAU,EAAA,6BAAA;AAAA,GACZ;AACF,CAAA,CAAA;AA2BO,SAAS,cAAA,CACd,QACA,MAC4B,EAAA;AAC5B,EAAM,MAAA,QAAA,GAAW,UAAU,MAAM,CAAA,CAAA;AAEjC,EAAO,OAAA;AAAA,IACL,UAAU,QAAS,CAAA,QAAA;AAAA,IACnB,MAAA,EAAQ,UAAU,QAAS,CAAA,aAAA;AAAA,IAC3B,MAAA;AAAA,GACF,CAAA;AACF","file":"index.js","sourcesContent":["/**\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 * 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/**\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 * 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\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\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 * @property origin The region of the Blizzard API.\r\n * @property locale The locale of the Blizzard API.\r\n * @property hostname The hostname 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"]}
|