@blizzard-api/core 1.2.1 → 2.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/package.json +3 -7
- package/dist/index.cjs +0 -37
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -142
package/package.json
CHANGED
|
@@ -1,25 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blizzard-api/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.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 ||
|
|
10
|
+
"node": "^18.18 || >=20.9"
|
|
11
11
|
},
|
|
12
|
-
"main": "./dist/index.cjs",
|
|
13
12
|
"module": "./dist/index.js",
|
|
14
13
|
"types": "./dist/index.d.ts",
|
|
15
14
|
"exports": {
|
|
16
15
|
"import": {
|
|
16
|
+
"@blizzard-api/core-local": "./src/index.ts",
|
|
17
17
|
"types": "./dist/index.d.ts",
|
|
18
18
|
"default": "./dist/index.js"
|
|
19
|
-
},
|
|
20
|
-
"require": {
|
|
21
|
-
"types": "./dist/index.d.cts",
|
|
22
|
-
"default": "./dist/index.cjs"
|
|
23
19
|
}
|
|
24
20
|
},
|
|
25
21
|
"files": [
|
package/dist/index.cjs
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// src/blizzard-api.ts
|
|
4
|
-
var endpoints = {
|
|
5
|
-
cn: {
|
|
6
|
-
defaultLocale: "zh_CN",
|
|
7
|
-
hostname: "https://gateway.battlenet.com.cn"
|
|
8
|
-
},
|
|
9
|
-
eu: {
|
|
10
|
-
defaultLocale: "en_GB",
|
|
11
|
-
hostname: "https://eu.api.blizzard.com"
|
|
12
|
-
},
|
|
13
|
-
kr: {
|
|
14
|
-
defaultLocale: "ko_KR",
|
|
15
|
-
hostname: "https://kr.api.blizzard.com"
|
|
16
|
-
},
|
|
17
|
-
tw: {
|
|
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"
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
function getBlizzardApi(origin, locale) {
|
|
27
|
-
const endpoint = endpoints[origin];
|
|
28
|
-
return {
|
|
29
|
-
hostname: endpoint.hostname,
|
|
30
|
-
locale: locale ?? endpoint.defaultLocale,
|
|
31
|
-
origin
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
exports.getBlizzardApi = getBlizzardApi;
|
|
36
|
-
//# sourceMappingURL=index.cjs.map
|
|
37
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Possible regions for use within the Blizzard API.
|
|
3
|
-
*/
|
|
4
|
-
type Origins = 'cn' | 'eu' | 'kr' | 'tw' | 'us';
|
|
5
|
-
/**
|
|
6
|
-
* Possible locales for use within the Blizzard API.
|
|
7
|
-
*/
|
|
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
|
-
/**
|
|
10
|
-
* A record of regions and their supported locales.
|
|
11
|
-
*/
|
|
12
|
-
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"];
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* The default Blizzard API configuration for each region.
|
|
21
|
-
*/
|
|
22
|
-
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`;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* A Blizzard API configuration object.
|
|
28
|
-
* @template T The region of the Blizzard API.
|
|
29
|
-
* @property origin The region of the Blizzard API.
|
|
30
|
-
* @property locale The locale of the Blizzard API.
|
|
31
|
-
* @property hostname The hostname of the Blizzard API.
|
|
32
|
-
*/
|
|
33
|
-
interface BlizzardApi<T extends Origins> {
|
|
34
|
-
hostname: BlizzardApiDefault<Origins>['hostname'];
|
|
35
|
-
locale: (typeof _regionLocaleMap)[T][number];
|
|
36
|
-
origin: Origins;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Get the Blizzard API configuration for a given region.
|
|
40
|
-
* @template T The region of the Blizzard API.
|
|
41
|
-
* @param origin The region of the Blizzard API.
|
|
42
|
-
* @param locale The locale of the Blizzard API.
|
|
43
|
-
* @returns The Blizzard API configuration for the given region.
|
|
44
|
-
* @example
|
|
45
|
-
* const api = getBlizzardApi('us', 'en_US');
|
|
46
|
-
* console.log(api.hostname); // 'https://us.api.blizzard.com'
|
|
47
|
-
* console.log(api.locale); // 'en_US'
|
|
48
|
-
* console.log(api.origin); // 'us'
|
|
49
|
-
*/
|
|
50
|
-
declare function getBlizzardApi<T extends Origins>(origin: T, locale?: (typeof _regionLocaleMap)[typeof origin][number]): BlizzardApi<typeof origin>;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Blizzard API namespaces.
|
|
54
|
-
* @see https://develop.battle.net/documentation/world-of-warcraft/guides/namespaces
|
|
55
|
-
*/
|
|
56
|
-
type BlizzardNamespaces = 'dynamic' | 'dynamic-classic' | 'dynamic-classic1x' | 'profile' | 'static' | 'static-classic' | 'static-classic1x';
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Represents a resource that can be requested from the Blizzard API
|
|
60
|
-
* @param _Response The response type of the resource
|
|
61
|
-
* @param SearchOptions The search options that can be passed to the resource
|
|
62
|
-
* @param ProtectedResource Whether the resource requires a token to be requested
|
|
63
|
-
*/
|
|
64
|
-
type Resource<Response, SearchOptions extends object = Record<string, never>, ProtectedResource extends boolean = false> = {
|
|
65
|
-
/**
|
|
66
|
-
* The response type of the resource
|
|
67
|
-
* @private @internal This is an internal property and should not be used as it will not be populated
|
|
68
|
-
*/
|
|
69
|
-
_responseType?: Response;
|
|
70
|
-
namespace?: BlizzardNamespaces;
|
|
71
|
-
parameters?: SearchOptions;
|
|
72
|
-
path: string;
|
|
73
|
-
} & (ProtectedResource extends true ? {
|
|
74
|
-
token: string;
|
|
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>;
|
|
83
|
-
/**
|
|
84
|
-
* Represents the response of a resource
|
|
85
|
-
* @param T The response type of the resource
|
|
86
|
-
* @example
|
|
87
|
-
* type response = ResourceResponse<{ id: number }>;
|
|
88
|
-
* const response: response = Promise.resolve({ id: 1 });
|
|
89
|
-
* response.then((data) => console.log(data.id));
|
|
90
|
-
*/
|
|
91
|
-
type ResourceResponse<T = unknown> = Promise<T>;
|
|
92
|
-
/**
|
|
93
|
-
* Extracts the response type from a resource
|
|
94
|
-
* @param Type The resource type
|
|
95
|
-
* @returns The response type
|
|
96
|
-
* @example
|
|
97
|
-
* type extracted = ExtractResourceType<Resource<{ id: number }>>;
|
|
98
|
-
*/
|
|
99
|
-
type ExtractResourceType<Type> = Type extends Resource<infer R, infer _SearchOptions, infer _Protected> ? R : never;
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Base search parameters
|
|
103
|
-
* @interface BaseSearchParameters
|
|
104
|
-
* @property orderby The field to order results by.
|
|
105
|
-
* @property _page The page number to return.
|
|
106
|
-
* @example
|
|
107
|
-
* const params: BaseSearchParameters = {
|
|
108
|
-
* orderby: 'name',
|
|
109
|
-
* _page: 1,
|
|
110
|
-
* };
|
|
111
|
-
*/
|
|
112
|
-
interface BaseSearchParameters {
|
|
113
|
-
_page?: number;
|
|
114
|
-
orderby?: Array<string> | string;
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Search response
|
|
118
|
-
* @interface SearchResponse
|
|
119
|
-
* @property page The current page number.
|
|
120
|
-
* @property pageSize The number of results per page.
|
|
121
|
-
* @property maxPageSize The maximum number of results per page.
|
|
122
|
-
* @property pageCount The total number of pages.
|
|
123
|
-
* @property results The search results.
|
|
124
|
-
* @example
|
|
125
|
-
* const response: SearchResponse = {
|
|
126
|
-
* page: 1,
|
|
127
|
-
* pageSize: 20,
|
|
128
|
-
* maxPageSize: 100,
|
|
129
|
-
* pageCount: 10,
|
|
130
|
-
* results: [],
|
|
131
|
-
* };
|
|
132
|
-
*/
|
|
133
|
-
interface SearchResponse<T> {
|
|
134
|
-
maxPageSize: number;
|
|
135
|
-
page: number;
|
|
136
|
-
pageCount: number;
|
|
137
|
-
pageSize: number;
|
|
138
|
-
resultCountCapped?: boolean;
|
|
139
|
-
results: Array<T>;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export { type BaseSearchParameters, type BlizzardNamespaces, type ExtractResourceType, type Locales, type Origins, type ProtectedResource, type Resource, type ResourceResponse, type SearchResponse, getBlizzardApi };
|