@blizzard-api/core 2.0.0 → 2.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/dist/index.d.ts +24 -24
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Possible regions for use within the Blizzard API.
|
|
3
|
-
*/
|
|
4
|
-
type Origins = 'cn' | 'eu' | 'kr' | 'tw' | 'us';
|
|
5
1
|
/**
|
|
6
2
|
* Possible locales for use within the Blizzard API.
|
|
7
3
|
*/
|
|
8
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';
|
|
5
|
+
/**
|
|
6
|
+
* Possible regions for use within the Blizzard API.
|
|
7
|
+
*/
|
|
8
|
+
type Origins = 'cn' | 'eu' | 'kr' | 'tw' | 'us';
|
|
9
9
|
/**
|
|
10
10
|
* A record of regions and their supported locales.
|
|
11
11
|
*/
|
|
@@ -53,15 +53,32 @@ declare function getBlizzardApi<T extends Origins>(origin: T, locale?: (typeof _
|
|
|
53
53
|
* Blizzard API namespaces.
|
|
54
54
|
* @see https://develop.battle.net/documentation/world-of-warcraft/guides/namespaces
|
|
55
55
|
*/
|
|
56
|
-
type BlizzardNamespaces = 'dynamic' | 'dynamic-
|
|
56
|
+
type BlizzardNamespaces = 'dynamic' | 'dynamic-classic1x' | 'dynamic-classic' | 'profile' | 'static' | 'static-classic1x' | 'static-classic';
|
|
57
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Extracts the response type from a resource
|
|
60
|
+
* @param Type The resource type
|
|
61
|
+
* @returns The response type
|
|
62
|
+
* @example
|
|
63
|
+
* type extracted = ExtractResourceType<Resource<{ id: number }>>;
|
|
64
|
+
*/
|
|
65
|
+
type ExtractResourceType<Type> = Type extends Resource<infer R, infer _SearchOptions, infer _Protected> ? R : never;
|
|
66
|
+
/**
|
|
67
|
+
* Represents a resource that requires a token to be requested
|
|
68
|
+
* @param Response The response type of the resource
|
|
69
|
+
* @param SearchOptions The search options that can be passed to the resource
|
|
70
|
+
*
|
|
71
|
+
*/
|
|
72
|
+
type ProtectedResource<Response, SearchOptions extends object = Record<string, never>> = Resource<Response, SearchOptions, true>;
|
|
58
73
|
/**
|
|
59
74
|
* Represents a resource that can be requested from the Blizzard API
|
|
60
75
|
* @param _Response The response type of the resource
|
|
61
76
|
* @param SearchOptions The search options that can be passed to the resource
|
|
62
77
|
* @param ProtectedResource Whether the resource requires a token to be requested
|
|
63
78
|
*/
|
|
64
|
-
type Resource<Response, SearchOptions extends object = Record<string, never>,
|
|
79
|
+
type Resource<Response, SearchOptions extends object = Record<string, never>, IsProtectedResource extends boolean = false> = (IsProtectedResource extends true ? {
|
|
80
|
+
token: string;
|
|
81
|
+
} : unknown) & {
|
|
65
82
|
/**
|
|
66
83
|
* The response type of the resource
|
|
67
84
|
* @private @internal This is an internal property and should not be used as it will not be populated
|
|
@@ -70,16 +87,7 @@ type Resource<Response, SearchOptions extends object = Record<string, never>, Pr
|
|
|
70
87
|
namespace?: BlizzardNamespaces;
|
|
71
88
|
parameters?: SearchOptions;
|
|
72
89
|
path: string;
|
|
73
|
-
}
|
|
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>;
|
|
90
|
+
};
|
|
83
91
|
/**
|
|
84
92
|
* Represents the response of a resource
|
|
85
93
|
* @param T The response type of the resource
|
|
@@ -89,14 +97,6 @@ type ProtectedResource<Response, SearchOptions extends object = Record<string, n
|
|
|
89
97
|
* response.then((data) => console.log(data.id));
|
|
90
98
|
*/
|
|
91
99
|
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
100
|
|
|
101
101
|
/**
|
|
102
102
|
* Base search parameters
|
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,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
|
|
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 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 * @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"]}
|