@blizzard-api/core 0.0.7 → 0.0.9
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 +25 -0
- package/dist/index.cjs +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -6
- package/dist/index.d.ts +11 -6
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +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
|
+
```
|
package/dist/index.cjs
CHANGED
|
@@ -20,11 +20,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var src_exports = {};
|
|
22
22
|
__export(src_exports, {
|
|
23
|
-
|
|
23
|
+
getBlizzardApi: () => getBlizzardApi
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(src_exports);
|
|
26
26
|
|
|
27
|
-
// src/
|
|
27
|
+
// src/blizzard-api.ts
|
|
28
28
|
var endpoints = {
|
|
29
29
|
us: {
|
|
30
30
|
hostname: "https://us.api.blizzard.com",
|
|
@@ -43,7 +43,7 @@ var endpoints = {
|
|
|
43
43
|
defaultLocale: "zh_TW"
|
|
44
44
|
}
|
|
45
45
|
};
|
|
46
|
-
function
|
|
46
|
+
function getBlizzardApi(origin, locale) {
|
|
47
47
|
const endpoint = endpoints[origin];
|
|
48
48
|
return {
|
|
49
49
|
origin,
|
|
@@ -53,6 +53,6 @@ function getEndpoint(origin, locale) {
|
|
|
53
53
|
}
|
|
54
54
|
// Annotate the CommonJS export names for ESM import in node:
|
|
55
55
|
0 && (module.exports = {
|
|
56
|
-
|
|
56
|
+
getBlizzardApi
|
|
57
57
|
});
|
|
58
58
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/blizzard-api.ts"],"sourcesContent":["//Blizzard API\r\nexport * from './blizzard-api.js';\r\n\r\n//Namespace\r\nexport * from './namespace.js';\r\n\r\n//Resource\r\nexport * from './resource.js';\r\n","export type Origins = 'us' | 'eu' | 'kr' | 'tw';\r\nexport type Locales =\r\n | 'en_US'\r\n | 'es_MX'\r\n | 'pt_BR'\r\n | 'en_GB'\r\n | 'es_ES'\r\n | 'fr_FR'\r\n | 'ru_RU'\r\n | 'de_DE'\r\n | 'pt_PT'\r\n | 'it_IT'\r\n | 'ko_KR'\r\n | 'zh_TW'\r\n | 'multi';\r\n\r\nconst locales = {\r\n us: ['en_US', 'es_MX', 'pt_BR', 'multi'],\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} as const satisfies Record<Origins, Array<Locales>>;\r\n\r\ninterface BlizzardApiDefault<T extends Origins> {\r\n hostname: `https://${T}.api.blizzard.com`;\r\n defaultLocale: (typeof locales)[T][number];\r\n}\r\n\r\ninterface BlizzardApiByRegion {\r\n us: BlizzardApiDefault<'us'>;\r\n eu: BlizzardApiDefault<'eu'>;\r\n kr: BlizzardApiDefault<'kr'>;\r\n tw: BlizzardApiDefault<'tw'>;\r\n}\r\n\r\nconst endpoints: BlizzardApiByRegion = {\r\n us: {\r\n hostname: 'https://us.api.blizzard.com',\r\n defaultLocale: 'en_US',\r\n },\r\n eu: {\r\n hostname: 'https://eu.api.blizzard.com',\r\n defaultLocale: 'en_GB',\r\n },\r\n kr: {\r\n hostname: 'https://kr.api.blizzard.com',\r\n defaultLocale: 'ko_KR',\r\n },\r\n tw: {\r\n hostname: 'https://tw.api.blizzard.com',\r\n defaultLocale: 'zh_TW',\r\n },\r\n};\r\n\r\ninterface BlizzardApi<T extends Origins> {\r\n origin: Origins;\r\n locale: (typeof locales)[T][number];\r\n hostname: BlizzardApiDefault<Origins>['hostname'];\r\n}\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 origin,\r\n hostname: endpoint.hostname,\r\n locale: locale ?? endpoint.defaultLocale,\r\n };\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACmCA,IAAM,YAAiC;AAAA,EACrC,IAAI;AAAA,IACF,UAAU;AAAA,IACV,eAAe;AAAA,EACjB;AAAA,EACA,IAAI;AAAA,IACF,UAAU;AAAA,IACV,eAAe;AAAA,EACjB;AAAA,EACA,IAAI;AAAA,IACF,UAAU;AAAA,IACV,eAAe;AAAA,EACjB;AAAA,EACA,IAAI;AAAA,IACF,UAAU;AAAA,IACV,eAAe;AAAA,EACjB;AACF;AAQO,SAAS,eACd,QACA,QAC4B;AAC5B,QAAM,WAAW,UAAU,MAAM;AAEjC,SAAO;AAAA,IACL;AAAA,IACA,UAAU,SAAS;AAAA,IACnB,QAAQ,UAAU,SAAS;AAAA,EAC7B;AACF;","names":[]}
|
package/dist/index.d.cts
CHANGED
|
@@ -6,16 +6,16 @@ declare const locales: {
|
|
|
6
6
|
readonly kr: ["ko_KR", "en_GB", "en_US", "multi"];
|
|
7
7
|
readonly tw: ["zh_TW", "en_GB", "en_US", "multi"];
|
|
8
8
|
};
|
|
9
|
-
interface
|
|
9
|
+
interface BlizzardApiDefault<T extends Origins> {
|
|
10
10
|
hostname: `https://${T}.api.blizzard.com`;
|
|
11
11
|
defaultLocale: (typeof locales)[T][number];
|
|
12
12
|
}
|
|
13
|
-
interface
|
|
13
|
+
interface BlizzardApi<T extends Origins> {
|
|
14
14
|
origin: Origins;
|
|
15
15
|
locale: (typeof locales)[T][number];
|
|
16
|
-
hostname:
|
|
16
|
+
hostname: BlizzardApiDefault<Origins>['hostname'];
|
|
17
17
|
}
|
|
18
|
-
declare function
|
|
18
|
+
declare function getBlizzardApi<T extends Origins>(origin: T, locale?: (typeof locales)[typeof origin][number]): BlizzardApi<typeof origin>;
|
|
19
19
|
|
|
20
20
|
type BlizzardNamespaces = 'profile' | 'static' | 'dynamic' | 'static-classic' | 'dynamic-classic' | 'static-classic1x' | 'dynamic-classic1x';
|
|
21
21
|
|
|
@@ -24,10 +24,15 @@ type BlizzardNamespaces = 'profile' | 'static' | 'dynamic' | 'static-classic' |
|
|
|
24
24
|
* @param _Response The response type of the resource
|
|
25
25
|
* @param ProtectedResource Whether the resource requires a token to be requested
|
|
26
26
|
*/
|
|
27
|
-
type Resource<
|
|
27
|
+
type Resource<Response, ProtectedResource extends boolean = false> = {
|
|
28
28
|
path: string;
|
|
29
29
|
namespace?: BlizzardNamespaces;
|
|
30
30
|
parameters?: Record<string, string | number>;
|
|
31
|
+
/**
|
|
32
|
+
* The response type of the resource
|
|
33
|
+
* @private @internal This is an internal property and should not be used as it will not be populated
|
|
34
|
+
*/
|
|
35
|
+
_responseType?: Response;
|
|
31
36
|
} & (ProtectedResource extends true ? {
|
|
32
37
|
token: string;
|
|
33
38
|
} : unknown);
|
|
@@ -49,4 +54,4 @@ type ResourceResponse<T = unknown> = Promise<T>;
|
|
|
49
54
|
*/
|
|
50
55
|
type ExtractResourceType<Type> = Type extends Resource<infer R> ? R : never;
|
|
51
56
|
|
|
52
|
-
export { type BlizzardNamespaces, type ExtractResourceType, type Locales, type Origins, type Resource, type ResourceResponse,
|
|
57
|
+
export { type BlizzardNamespaces, type ExtractResourceType, type Locales, type Origins, type Resource, type ResourceResponse, getBlizzardApi };
|
package/dist/index.d.ts
CHANGED
|
@@ -6,16 +6,16 @@ declare const locales: {
|
|
|
6
6
|
readonly kr: ["ko_KR", "en_GB", "en_US", "multi"];
|
|
7
7
|
readonly tw: ["zh_TW", "en_GB", "en_US", "multi"];
|
|
8
8
|
};
|
|
9
|
-
interface
|
|
9
|
+
interface BlizzardApiDefault<T extends Origins> {
|
|
10
10
|
hostname: `https://${T}.api.blizzard.com`;
|
|
11
11
|
defaultLocale: (typeof locales)[T][number];
|
|
12
12
|
}
|
|
13
|
-
interface
|
|
13
|
+
interface BlizzardApi<T extends Origins> {
|
|
14
14
|
origin: Origins;
|
|
15
15
|
locale: (typeof locales)[T][number];
|
|
16
|
-
hostname:
|
|
16
|
+
hostname: BlizzardApiDefault<Origins>['hostname'];
|
|
17
17
|
}
|
|
18
|
-
declare function
|
|
18
|
+
declare function getBlizzardApi<T extends Origins>(origin: T, locale?: (typeof locales)[typeof origin][number]): BlizzardApi<typeof origin>;
|
|
19
19
|
|
|
20
20
|
type BlizzardNamespaces = 'profile' | 'static' | 'dynamic' | 'static-classic' | 'dynamic-classic' | 'static-classic1x' | 'dynamic-classic1x';
|
|
21
21
|
|
|
@@ -24,10 +24,15 @@ type BlizzardNamespaces = 'profile' | 'static' | 'dynamic' | 'static-classic' |
|
|
|
24
24
|
* @param _Response The response type of the resource
|
|
25
25
|
* @param ProtectedResource Whether the resource requires a token to be requested
|
|
26
26
|
*/
|
|
27
|
-
type Resource<
|
|
27
|
+
type Resource<Response, ProtectedResource extends boolean = false> = {
|
|
28
28
|
path: string;
|
|
29
29
|
namespace?: BlizzardNamespaces;
|
|
30
30
|
parameters?: Record<string, string | number>;
|
|
31
|
+
/**
|
|
32
|
+
* The response type of the resource
|
|
33
|
+
* @private @internal This is an internal property and should not be used as it will not be populated
|
|
34
|
+
*/
|
|
35
|
+
_responseType?: Response;
|
|
31
36
|
} & (ProtectedResource extends true ? {
|
|
32
37
|
token: string;
|
|
33
38
|
} : unknown);
|
|
@@ -49,4 +54,4 @@ type ResourceResponse<T = unknown> = Promise<T>;
|
|
|
49
54
|
*/
|
|
50
55
|
type ExtractResourceType<Type> = Type extends Resource<infer R> ? R : never;
|
|
51
56
|
|
|
52
|
-
export { type BlizzardNamespaces, type ExtractResourceType, type Locales, type Origins, type Resource, type ResourceResponse,
|
|
57
|
+
export { type BlizzardNamespaces, type ExtractResourceType, type Locales, type Origins, type Resource, type ResourceResponse, getBlizzardApi };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// src/
|
|
1
|
+
// src/blizzard-api.ts
|
|
2
2
|
var endpoints = {
|
|
3
3
|
us: {
|
|
4
4
|
hostname: "https://us.api.blizzard.com",
|
|
@@ -17,7 +17,7 @@ var endpoints = {
|
|
|
17
17
|
defaultLocale: "zh_TW"
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
|
-
function
|
|
20
|
+
function getBlizzardApi(origin, locale) {
|
|
21
21
|
const endpoint = endpoints[origin];
|
|
22
22
|
return {
|
|
23
23
|
origin,
|
|
@@ -26,6 +26,6 @@ function getEndpoint(origin, locale) {
|
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
28
|
export {
|
|
29
|
-
|
|
29
|
+
getBlizzardApi
|
|
30
30
|
};
|
|
31
31
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/
|
|
1
|
+
{"version":3,"sources":["../src/blizzard-api.ts"],"sourcesContent":["export type Origins = 'us' | 'eu' | 'kr' | 'tw';\r\nexport type Locales =\r\n | 'en_US'\r\n | 'es_MX'\r\n | 'pt_BR'\r\n | 'en_GB'\r\n | 'es_ES'\r\n | 'fr_FR'\r\n | 'ru_RU'\r\n | 'de_DE'\r\n | 'pt_PT'\r\n | 'it_IT'\r\n | 'ko_KR'\r\n | 'zh_TW'\r\n | 'multi';\r\n\r\nconst locales = {\r\n us: ['en_US', 'es_MX', 'pt_BR', 'multi'],\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} as const satisfies Record<Origins, Array<Locales>>;\r\n\r\ninterface BlizzardApiDefault<T extends Origins> {\r\n hostname: `https://${T}.api.blizzard.com`;\r\n defaultLocale: (typeof locales)[T][number];\r\n}\r\n\r\ninterface BlizzardApiByRegion {\r\n us: BlizzardApiDefault<'us'>;\r\n eu: BlizzardApiDefault<'eu'>;\r\n kr: BlizzardApiDefault<'kr'>;\r\n tw: BlizzardApiDefault<'tw'>;\r\n}\r\n\r\nconst endpoints: BlizzardApiByRegion = {\r\n us: {\r\n hostname: 'https://us.api.blizzard.com',\r\n defaultLocale: 'en_US',\r\n },\r\n eu: {\r\n hostname: 'https://eu.api.blizzard.com',\r\n defaultLocale: 'en_GB',\r\n },\r\n kr: {\r\n hostname: 'https://kr.api.blizzard.com',\r\n defaultLocale: 'ko_KR',\r\n },\r\n tw: {\r\n hostname: 'https://tw.api.blizzard.com',\r\n defaultLocale: 'zh_TW',\r\n },\r\n};\r\n\r\ninterface BlizzardApi<T extends Origins> {\r\n origin: Origins;\r\n locale: (typeof locales)[T][number];\r\n hostname: BlizzardApiDefault<Origins>['hostname'];\r\n}\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 origin,\r\n hostname: endpoint.hostname,\r\n locale: locale ?? endpoint.defaultLocale,\r\n };\r\n}\r\n"],"mappings":";AAmCA,IAAM,YAAiC;AAAA,EACrC,IAAI;AAAA,IACF,UAAU;AAAA,IACV,eAAe;AAAA,EACjB;AAAA,EACA,IAAI;AAAA,IACF,UAAU;AAAA,IACV,eAAe;AAAA,EACjB;AAAA,EACA,IAAI;AAAA,IACF,UAAU;AAAA,IACV,eAAe;AAAA,EACjB;AAAA,EACA,IAAI;AAAA,IACF,UAAU;AAAA,IACV,eAAe;AAAA,EACjB;AACF;AAQO,SAAS,eACd,QACA,QAC4B;AAC5B,QAAM,WAAW,UAAU,MAAM;AAEjC,SAAO;AAAA,IACL;AAAA,IACA,UAAU,SAAS;AAAA,IACnB,QAAQ,UAAU,SAAS;AAAA,EAC7B;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blizzard-api/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Putro",
|
|
6
6
|
"description": "The core helpers used by all @blizzard-api/* packages.",
|
|
7
|
-
"repository": "https://github.com/Pewtro/blizzard/packages/core",
|
|
7
|
+
"repository": "https://github.com/Pewtro/blizzard/tree/main/packages/core",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"engines": {
|
|
10
10
|
"node": ">=18 <19 || >=20"
|