@blizzard-api/core 1.0.0 → 1.1.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/dist/index.cjs +19 -40
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -13
- package/dist/index.d.ts +15 -13
- package/dist/index.js +18 -14
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -1,58 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var src_exports = {};
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
getBlizzardApi: () => getBlizzardApi
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(src_exports);
|
|
1
|
+
'use strict';
|
|
26
2
|
|
|
27
3
|
// src/blizzard-api.ts
|
|
28
4
|
var endpoints = {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
5
|
+
cn: {
|
|
6
|
+
defaultLocale: "zh_CN",
|
|
7
|
+
hostname: "https://gateway.battlenet.com.cn"
|
|
32
8
|
},
|
|
33
9
|
eu: {
|
|
34
|
-
|
|
35
|
-
|
|
10
|
+
defaultLocale: "en_GB",
|
|
11
|
+
hostname: "https://eu.api.blizzard.com"
|
|
36
12
|
},
|
|
37
13
|
kr: {
|
|
38
|
-
|
|
39
|
-
|
|
14
|
+
defaultLocale: "ko_KR",
|
|
15
|
+
hostname: "https://kr.api.blizzard.com"
|
|
40
16
|
},
|
|
41
17
|
tw: {
|
|
42
|
-
|
|
43
|
-
|
|
18
|
+
defaultLocale: "zh_TW",
|
|
19
|
+
hostname: "https://tw.api.blizzard.com"
|
|
20
|
+
},
|
|
21
|
+
us: {
|
|
22
|
+
defaultLocale: "en_US",
|
|
23
|
+
hostname: "https://us.api.blizzard.com"
|
|
44
24
|
}
|
|
45
25
|
};
|
|
46
26
|
function getBlizzardApi(origin, locale) {
|
|
47
27
|
const endpoint = endpoints[origin];
|
|
48
28
|
return {
|
|
49
|
-
origin,
|
|
50
29
|
hostname: endpoint.hostname,
|
|
51
|
-
locale: locale ?? endpoint.defaultLocale
|
|
30
|
+
locale: locale ?? endpoint.defaultLocale,
|
|
31
|
+
origin
|
|
52
32
|
};
|
|
53
33
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
});
|
|
34
|
+
|
|
35
|
+
exports.getBlizzardApi = getBlizzardApi;
|
|
36
|
+
//# sourceMappingURL=out.js.map
|
|
58
37
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/
|
|
1
|
+
{"version":3,"sources":["../src/blizzard-api.ts"],"names":[],"mappings":";AAqDA,IAAM,YAAiC;AAAA,EACrC,IAAI;AAAA,IACF,eAAe;AAAA,IACf,UAAU;AAAA,EACZ;AAAA,EACA,IAAI;AAAA,IACF,eAAe;AAAA,IACf,UAAU;AAAA,EACZ;AAAA,EACA,IAAI;AAAA,IACF,eAAe;AAAA,IACf,UAAU;AAAA,EACZ;AAAA,EACA,IAAI;AAAA,IACF,eAAe;AAAA,IACf,UAAU;AAAA,EACZ;AAAA,EACA,IAAI;AAAA,IACF,eAAe;AAAA,IACf,UAAU;AAAA,EACZ;AACF;AA2BO,SAAS,eACd,QACA,QAC4B;AAC5B,QAAM,WAAW,UAAU,MAAM;AAEjC,SAAO;AAAA,IACL,UAAU,SAAS;AAAA,IACnB,QAAQ,UAAU,SAAS;AAAA,IAC3B;AAAA,EACF;AACF","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 locales = {\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 locales)[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 locales)[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 locales)[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
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Possible regions for use within the Blizzard API.
|
|
3
3
|
*/
|
|
4
|
-
type Origins = '
|
|
4
|
+
type Origins = 'cn' | 'eu' | 'kr' | 'tw' | 'us';
|
|
5
5
|
/**
|
|
6
6
|
* Possible locales for use within the Blizzard API.
|
|
7
7
|
*/
|
|
8
|
-
type Locales = '
|
|
8
|
+
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';
|
|
9
9
|
/**
|
|
10
10
|
* A record of regions and their supported locales.
|
|
11
11
|
*/
|
|
12
12
|
declare const locales: {
|
|
13
|
-
readonly
|
|
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"];
|
|
16
16
|
readonly tw: ["zh_TW", "en_GB", "en_US", "multi"];
|
|
17
|
+
readonly us: ["en_US", "es_MX", "pt_BR", "multi"];
|
|
17
18
|
};
|
|
18
19
|
/**
|
|
19
20
|
* The default Blizzard API configuration for each region.
|
|
20
21
|
*/
|
|
21
22
|
interface BlizzardApiDefault<T extends Origins> {
|
|
22
|
-
hostname: `https://${T}.api.blizzard.com`;
|
|
23
23
|
defaultLocale: (typeof locales)[T][number];
|
|
24
|
+
hostname: T extends 'cn' ? 'https://gateway.battlenet.com.cn' : `https://${T}.api.blizzard.com`;
|
|
24
25
|
}
|
|
25
26
|
/**
|
|
26
27
|
* A Blizzard API configuration object.
|
|
@@ -30,9 +31,9 @@ interface BlizzardApiDefault<T extends Origins> {
|
|
|
30
31
|
* @property hostname The hostname of the Blizzard API.
|
|
31
32
|
*/
|
|
32
33
|
interface BlizzardApi<T extends Origins> {
|
|
33
|
-
origin: Origins;
|
|
34
|
-
locale: (typeof locales)[T][number];
|
|
35
34
|
hostname: BlizzardApiDefault<Origins>['hostname'];
|
|
35
|
+
locale: (typeof locales)[T][number];
|
|
36
|
+
origin: Origins;
|
|
36
37
|
}
|
|
37
38
|
/**
|
|
38
39
|
* Get the Blizzard API configuration for a given region.
|
|
@@ -52,22 +53,23 @@ declare function getBlizzardApi<T extends Origins>(origin: T, locale?: (typeof l
|
|
|
52
53
|
* Blizzard API namespaces.
|
|
53
54
|
* @see https://develop.battle.net/documentation/world-of-warcraft/guides/namespaces
|
|
54
55
|
*/
|
|
55
|
-
type BlizzardNamespaces = '
|
|
56
|
+
type BlizzardNamespaces = 'dynamic-classic' | 'dynamic-classic1x' | 'dynamic' | 'profile' | 'static-classic' | 'static-classic1x' | 'static';
|
|
56
57
|
|
|
57
58
|
/**
|
|
58
59
|
* Represents a resource that can be requested from the Blizzard API
|
|
59
60
|
* @param _Response The response type of the resource
|
|
61
|
+
* @param SearchOptions The search options that can be passed to the resource
|
|
60
62
|
* @param ProtectedResource Whether the resource requires a token to be requested
|
|
61
63
|
*/
|
|
62
64
|
type Resource<Response, SearchOptions extends object = Record<string, never>, ProtectedResource extends boolean = false> = {
|
|
63
|
-
path: string;
|
|
64
|
-
namespace?: BlizzardNamespaces;
|
|
65
|
-
parameters?: SearchOptions;
|
|
66
65
|
/**
|
|
67
66
|
* The response type of the resource
|
|
68
67
|
* @private @internal This is an internal property and should not be used as it will not be populated
|
|
69
68
|
*/
|
|
70
69
|
_responseType?: Response;
|
|
70
|
+
namespace?: BlizzardNamespaces;
|
|
71
|
+
parameters?: SearchOptions;
|
|
72
|
+
path: string;
|
|
71
73
|
} & (ProtectedResource extends true ? {
|
|
72
74
|
token: string;
|
|
73
75
|
} : unknown);
|
|
@@ -101,8 +103,8 @@ type ExtractResourceType<Type> = Type extends Resource<infer R, infer _SearchOpt
|
|
|
101
103
|
* };
|
|
102
104
|
*/
|
|
103
105
|
interface BaseSearchParameters {
|
|
104
|
-
orderby?: string | Array<string>;
|
|
105
106
|
_page?: number;
|
|
107
|
+
orderby?: Array<string> | string;
|
|
106
108
|
}
|
|
107
109
|
/**
|
|
108
110
|
* Search response
|
|
@@ -122,10 +124,10 @@ interface BaseSearchParameters {
|
|
|
122
124
|
* };
|
|
123
125
|
*/
|
|
124
126
|
interface SearchResponse<T> {
|
|
125
|
-
page: number;
|
|
126
|
-
pageSize: number;
|
|
127
127
|
maxPageSize: number;
|
|
128
|
+
page: number;
|
|
128
129
|
pageCount: number;
|
|
130
|
+
pageSize: number;
|
|
129
131
|
resultCountCapped?: boolean;
|
|
130
132
|
results: Array<T>;
|
|
131
133
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Possible regions for use within the Blizzard API.
|
|
3
3
|
*/
|
|
4
|
-
type Origins = '
|
|
4
|
+
type Origins = 'cn' | 'eu' | 'kr' | 'tw' | 'us';
|
|
5
5
|
/**
|
|
6
6
|
* Possible locales for use within the Blizzard API.
|
|
7
7
|
*/
|
|
8
|
-
type Locales = '
|
|
8
|
+
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';
|
|
9
9
|
/**
|
|
10
10
|
* A record of regions and their supported locales.
|
|
11
11
|
*/
|
|
12
12
|
declare const locales: {
|
|
13
|
-
readonly
|
|
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"];
|
|
16
16
|
readonly tw: ["zh_TW", "en_GB", "en_US", "multi"];
|
|
17
|
+
readonly us: ["en_US", "es_MX", "pt_BR", "multi"];
|
|
17
18
|
};
|
|
18
19
|
/**
|
|
19
20
|
* The default Blizzard API configuration for each region.
|
|
20
21
|
*/
|
|
21
22
|
interface BlizzardApiDefault<T extends Origins> {
|
|
22
|
-
hostname: `https://${T}.api.blizzard.com`;
|
|
23
23
|
defaultLocale: (typeof locales)[T][number];
|
|
24
|
+
hostname: T extends 'cn' ? 'https://gateway.battlenet.com.cn' : `https://${T}.api.blizzard.com`;
|
|
24
25
|
}
|
|
25
26
|
/**
|
|
26
27
|
* A Blizzard API configuration object.
|
|
@@ -30,9 +31,9 @@ interface BlizzardApiDefault<T extends Origins> {
|
|
|
30
31
|
* @property hostname The hostname of the Blizzard API.
|
|
31
32
|
*/
|
|
32
33
|
interface BlizzardApi<T extends Origins> {
|
|
33
|
-
origin: Origins;
|
|
34
|
-
locale: (typeof locales)[T][number];
|
|
35
34
|
hostname: BlizzardApiDefault<Origins>['hostname'];
|
|
35
|
+
locale: (typeof locales)[T][number];
|
|
36
|
+
origin: Origins;
|
|
36
37
|
}
|
|
37
38
|
/**
|
|
38
39
|
* Get the Blizzard API configuration for a given region.
|
|
@@ -52,22 +53,23 @@ declare function getBlizzardApi<T extends Origins>(origin: T, locale?: (typeof l
|
|
|
52
53
|
* Blizzard API namespaces.
|
|
53
54
|
* @see https://develop.battle.net/documentation/world-of-warcraft/guides/namespaces
|
|
54
55
|
*/
|
|
55
|
-
type BlizzardNamespaces = '
|
|
56
|
+
type BlizzardNamespaces = 'dynamic-classic' | 'dynamic-classic1x' | 'dynamic' | 'profile' | 'static-classic' | 'static-classic1x' | 'static';
|
|
56
57
|
|
|
57
58
|
/**
|
|
58
59
|
* Represents a resource that can be requested from the Blizzard API
|
|
59
60
|
* @param _Response The response type of the resource
|
|
61
|
+
* @param SearchOptions The search options that can be passed to the resource
|
|
60
62
|
* @param ProtectedResource Whether the resource requires a token to be requested
|
|
61
63
|
*/
|
|
62
64
|
type Resource<Response, SearchOptions extends object = Record<string, never>, ProtectedResource extends boolean = false> = {
|
|
63
|
-
path: string;
|
|
64
|
-
namespace?: BlizzardNamespaces;
|
|
65
|
-
parameters?: SearchOptions;
|
|
66
65
|
/**
|
|
67
66
|
* The response type of the resource
|
|
68
67
|
* @private @internal This is an internal property and should not be used as it will not be populated
|
|
69
68
|
*/
|
|
70
69
|
_responseType?: Response;
|
|
70
|
+
namespace?: BlizzardNamespaces;
|
|
71
|
+
parameters?: SearchOptions;
|
|
72
|
+
path: string;
|
|
71
73
|
} & (ProtectedResource extends true ? {
|
|
72
74
|
token: string;
|
|
73
75
|
} : unknown);
|
|
@@ -101,8 +103,8 @@ type ExtractResourceType<Type> = Type extends Resource<infer R, infer _SearchOpt
|
|
|
101
103
|
* };
|
|
102
104
|
*/
|
|
103
105
|
interface BaseSearchParameters {
|
|
104
|
-
orderby?: string | Array<string>;
|
|
105
106
|
_page?: number;
|
|
107
|
+
orderby?: Array<string> | string;
|
|
106
108
|
}
|
|
107
109
|
/**
|
|
108
110
|
* Search response
|
|
@@ -122,10 +124,10 @@ interface BaseSearchParameters {
|
|
|
122
124
|
* };
|
|
123
125
|
*/
|
|
124
126
|
interface SearchResponse<T> {
|
|
125
|
-
page: number;
|
|
126
|
-
pageSize: number;
|
|
127
127
|
maxPageSize: number;
|
|
128
|
+
page: number;
|
|
128
129
|
pageCount: number;
|
|
130
|
+
pageSize: number;
|
|
129
131
|
resultCountCapped?: boolean;
|
|
130
132
|
results: Array<T>;
|
|
131
133
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,31 +1,35 @@
|
|
|
1
1
|
// src/blizzard-api.ts
|
|
2
2
|
var endpoints = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
cn: {
|
|
4
|
+
defaultLocale: "zh_CN",
|
|
5
|
+
hostname: "https://gateway.battlenet.com.cn"
|
|
6
6
|
},
|
|
7
7
|
eu: {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
defaultLocale: "en_GB",
|
|
9
|
+
hostname: "https://eu.api.blizzard.com"
|
|
10
10
|
},
|
|
11
11
|
kr: {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
defaultLocale: "ko_KR",
|
|
13
|
+
hostname: "https://kr.api.blizzard.com"
|
|
14
14
|
},
|
|
15
15
|
tw: {
|
|
16
|
-
|
|
17
|
-
|
|
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"
|
|
18
22
|
}
|
|
19
23
|
};
|
|
20
24
|
function getBlizzardApi(origin, locale) {
|
|
21
25
|
const endpoint = endpoints[origin];
|
|
22
26
|
return {
|
|
23
|
-
origin,
|
|
24
27
|
hostname: endpoint.hostname,
|
|
25
|
-
locale: locale ?? endpoint.defaultLocale
|
|
28
|
+
locale: locale ?? endpoint.defaultLocale,
|
|
29
|
+
origin
|
|
26
30
|
};
|
|
27
31
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
32
|
+
|
|
33
|
+
export { getBlizzardApi };
|
|
34
|
+
//# sourceMappingURL=out.js.map
|
|
31
35
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/blizzard-api.ts"],"sourcesContent":["/**\r\n * Possible regions for use within the Blizzard API.\r\n */\r\nexport type Origins = '
|
|
1
|
+
{"version":3,"sources":["../src/blizzard-api.ts"],"names":[],"mappings":";AAqDA,IAAM,YAAiC;AAAA,EACrC,IAAI;AAAA,IACF,eAAe;AAAA,IACf,UAAU;AAAA,EACZ;AAAA,EACA,IAAI;AAAA,IACF,eAAe;AAAA,IACf,UAAU;AAAA,EACZ;AAAA,EACA,IAAI;AAAA,IACF,eAAe;AAAA,IACf,UAAU;AAAA,EACZ;AAAA,EACA,IAAI;AAAA,IACF,eAAe;AAAA,IACf,UAAU;AAAA,EACZ;AAAA,EACA,IAAI;AAAA,IACF,eAAe;AAAA,IACf,UAAU;AAAA,EACZ;AACF;AA2BO,SAAS,eACd,QACA,QAC4B;AAC5B,QAAM,WAAW,UAAU,MAAM;AAEjC,SAAO;AAAA,IACL,UAAU,SAAS;AAAA,IACnB,QAAQ,UAAU,SAAS;AAAA,IAC3B;AAAA,EACF;AACF","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 locales = {\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 locales)[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 locales)[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 locales)[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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blizzard-api/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Putro",
|
|
6
6
|
"description": "The core helpers used by all @blizzard-api/* packages.",
|
|
@@ -9,7 +9,9 @@
|
|
|
9
9
|
"engines": {
|
|
10
10
|
"node": "^18.18 || ^20.9 || ^21.1 || ^22"
|
|
11
11
|
},
|
|
12
|
-
"main": "./dist/index.
|
|
12
|
+
"main": "./dist/index.cjs",
|
|
13
|
+
"module": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
13
15
|
"exports": {
|
|
14
16
|
"import": {
|
|
15
17
|
"types": "./dist/index.d.ts",
|
|
@@ -39,9 +41,7 @@
|
|
|
39
41
|
"diablo",
|
|
40
42
|
"d3",
|
|
41
43
|
"hs",
|
|
42
|
-
"hearthstone"
|
|
43
|
-
"ow",
|
|
44
|
-
"overwatch"
|
|
44
|
+
"hearthstone"
|
|
45
45
|
],
|
|
46
46
|
"dependencies": {},
|
|
47
47
|
"devDependencies": {},
|