@blizzard-api/core 2.1.0 → 2.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.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ //#region src/blizzard-api.d.ts
1
2
  /**
2
3
  * Possible locales for use within the Blizzard API.
3
4
  */
@@ -10,27 +11,27 @@ type Origins = 'cn' | 'eu' | 'kr' | 'tw' | 'us';
10
11
  * A record of regions and their supported locales.
11
12
  */
12
13
  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"];
14
+ readonly cn: ["zh_CN"];
15
+ readonly eu: ["en_GB", "es_ES", "fr_FR", "ru_RU", "de_DE", "pt_PT", "it_IT", "multi"];
16
+ readonly kr: ["ko_KR", "en_GB", "en_US", "multi"];
17
+ readonly tw: ["zh_TW", "en_GB", "en_US", "multi"];
18
+ readonly us: ["en_US", "es_MX", "pt_BR", "multi"];
18
19
  };
19
20
  /**
20
21
  * The default Blizzard API configuration for each region.
21
22
  */
22
23
  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`;
24
+ defaultLocale: (typeof _regionLocaleMap)[T][number];
25
+ hostname: T extends 'cn' ? 'https://gateway.battlenet.com.cn' : `https://${T}.api.blizzard.com`;
25
26
  }
26
27
  /**
27
28
  * A Blizzard API configuration object.
28
29
  * @template T The region of the Blizzard API.
29
30
  */
30
31
  interface BlizzardApi<T extends Origins> {
31
- hostname: BlizzardApiDefault<Origins>['hostname'];
32
- locale: (typeof _regionLocaleMap)[T][number];
33
- origin: Origins;
32
+ hostname: BlizzardApiDefault<Origins>['hostname'];
33
+ locale: (typeof _regionLocaleMap)[T][number];
34
+ origin: Origins;
34
35
  }
35
36
  /**
36
37
  * Get the Blizzard API configuration for a given region.
@@ -46,12 +47,16 @@ interface BlizzardApi<T extends Origins> {
46
47
  */
47
48
  declare function getBlizzardApi<T extends Origins>(origin: T, locale?: (typeof _regionLocaleMap)[typeof origin][number]): BlizzardApi<typeof origin>;
48
49
 
50
+ //#endregion
51
+ //#region src/namespace.d.ts
49
52
  /**
50
53
  * Blizzard API namespaces.
51
54
  * @see https://develop.battle.net/documentation/world-of-warcraft/guides/namespaces
52
55
  */
53
56
  type BlizzardNamespaces = 'dynamic' | 'dynamic-classic1x' | 'dynamic-classic' | 'profile' | 'profile-classic1x' | 'profile-classic' | 'static' | 'static-classic1x' | 'static-classic';
54
57
 
58
+ //#endregion
59
+ //#region src/resource.d.ts
55
60
  /**
56
61
  * Extracts the response type from a resource
57
62
  * @param Type The resource type
@@ -72,17 +77,17 @@ type ProtectedResource<Response, SearchOptions extends object = Record<string, n
72
77
  * @param SearchOptions The search options that can be passed to the resource
73
78
  * @param ProtectedResource Whether the resource requires a token to be requested
74
79
  */
75
- type Resource<Response, SearchOptions extends object = Record<string, never>, IsProtectedResource extends boolean = false> = (IsProtectedResource extends true ? {
76
- token: string;
80
+ type Resource<Response, SearchOptions extends object = Record<string, unknown>, IsProtectedResource extends boolean = false> = (IsProtectedResource extends true ? {
81
+ token: string;
77
82
  } : unknown) & {
78
- /**
79
- * The response type of the resource
80
- * @internal
81
- */
82
- _responseType?: Response;
83
- namespace?: BlizzardNamespaces;
84
- parameters?: SearchOptions;
85
- path: string;
83
+ /**
84
+ * The response type of the resource
85
+ * @internal
86
+ */
87
+ _responseType?: Response;
88
+ namespace?: BlizzardNamespaces;
89
+ parameters?: SearchOptions;
90
+ path: string;
86
91
  };
87
92
  /**
88
93
  * Represents the response of a resource
@@ -94,6 +99,8 @@ type Resource<Response, SearchOptions extends object = Record<string, never>, Is
94
99
  */
95
100
  type ResourceResponse<T = unknown> = Promise<T>;
96
101
 
102
+ //#endregion
103
+ //#region src/search.d.ts
97
104
  /**
98
105
  * Base search parameters
99
106
  * orderby The field to order results by.
@@ -105,8 +112,8 @@ type ResourceResponse<T = unknown> = Promise<T>;
105
112
  * };
106
113
  */
107
114
  interface BaseSearchParameters {
108
- _page?: number;
109
- orderby?: Array<string> | string;
115
+ _page?: number;
116
+ orderby?: Array<string> | string;
110
117
  }
111
118
  /**
112
119
  * Search response
@@ -125,12 +132,14 @@ interface BaseSearchParameters {
125
132
  * };
126
133
  */
127
134
  interface SearchResponse<T> {
128
- maxPageSize: number;
129
- page: number;
130
- pageCount: number;
131
- pageSize: number;
132
- resultCountCapped?: boolean;
133
- results: Array<T>;
135
+ maxPageSize: number;
136
+ page: number;
137
+ pageCount: number;
138
+ pageSize: number;
139
+ resultCountCapped?: boolean;
140
+ results: Array<T>;
134
141
  }
135
142
 
136
- export { type BaseSearchParameters, type BlizzardNamespaces, type ExtractResourceType, type Locales, type Origins, type ProtectedResource, type Resource, type ResourceResponse, type SearchResponse, getBlizzardApi };
143
+ //#endregion
144
+ export { BaseSearchParameters, BlizzardNamespaces, ExtractResourceType, Locales, Origins, ProtectedResource, Resource, ResourceResponse, SearchResponse, getBlizzardApi };
145
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,35 +1,58 @@
1
- // src/blizzard-api.ts
2
- var endpoints = {
3
- cn: {
4
- defaultLocale: "zh_CN",
5
- hostname: "https://gateway.battlenet.com.cn"
6
- },
7
- eu: {
8
- defaultLocale: "en_GB",
9
- hostname: "https://eu.api.blizzard.com"
10
- },
11
- kr: {
12
- defaultLocale: "ko_KR",
13
- hostname: "https://kr.api.blizzard.com"
14
- },
15
- tw: {
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"
22
- }
1
+ //#region src/blizzard-api.ts
2
+ const endpoints = {
3
+ cn: {
4
+ defaultLocale: "zh_CN",
5
+ hostname: "https://gateway.battlenet.com.cn"
6
+ },
7
+ eu: {
8
+ defaultLocale: "en_GB",
9
+ hostname: "https://eu.api.blizzard.com"
10
+ },
11
+ kr: {
12
+ defaultLocale: "ko_KR",
13
+ hostname: "https://kr.api.blizzard.com"
14
+ },
15
+ tw: {
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"
22
+ }
23
23
  };
24
+ /**
25
+
26
+ * Get the Blizzard API configuration for a given region.
27
+
28
+ * @template T The region of the Blizzard API.
29
+
30
+ * @param origin The region of the Blizzard API.
31
+
32
+ * @param locale The locale of the Blizzard API.
33
+
34
+ * @returns The Blizzard API configuration for the given region.
35
+
36
+ * @example
37
+
38
+ * const api = getBlizzardApi('us', 'en_US');
39
+
40
+ * console.log(api.hostname); // 'https://us.api.blizzard.com'
41
+
42
+ * console.log(api.locale); // 'en_US'
43
+
44
+ * console.log(api.origin); // 'us'
45
+
46
+ */
24
47
  function getBlizzardApi(origin, locale) {
25
- const endpoint = endpoints[origin];
26
- return {
27
- hostname: endpoint.hostname,
28
- locale: locale ?? endpoint.defaultLocale,
29
- origin
30
- };
48
+ const endpoint = endpoints[origin];
49
+ return {
50
+ hostname: endpoint.hostname,
51
+ locale: locale ?? endpoint.defaultLocale,
52
+ origin
53
+ };
31
54
  }
32
55
 
56
+ //#endregion
33
57
  export { getBlizzardApi };
34
- //# sourceMappingURL=index.js.map
35
58
  //# sourceMappingURL=index.js.map
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;AAAA,GACZ;AAAA,EACA,EAAI,EAAA;AAAA,IACF,aAAe,EAAA,OAAA;AAAA,IACf,QAAU,EAAA;AAAA,GACZ;AAAA,EACA,EAAI,EAAA;AAAA,IACF,aAAe,EAAA,OAAA;AAAA,IACf,QAAU,EAAA;AAAA,GACZ;AAAA,EACA,EAAI,EAAA;AAAA,IACF,aAAe,EAAA,OAAA;AAAA,IACf,QAAU,EAAA;AAAA,GACZ;AAAA,EACA,EAAI,EAAA;AAAA,IACF,aAAe,EAAA,OAAA;AAAA,IACf,QAAU,EAAA;AAAA;AAEd,CAAA;AAwBO,SAAS,cAAA,CACd,QACA,MAC4B,EAAA;AAC5B,EAAM,MAAA,QAAA,GAAW,UAAU,MAAM,CAAA;AAEjC,EAAO,OAAA;AAAA,IACL,UAAU,QAAS,CAAA,QAAA;AAAA,IACnB,MAAA,EAAQ,UAAU,QAAS,CAAA,aAAA;AAAA,IAC3B;AAAA,GACF;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 */\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"]}
1
+ {"version":3,"file":"index.js","names":["endpoints: BlizzardApiByRegion","origin: T","locale?: (typeof _regionLocaleMap)[typeof origin][number]"],"sources":["../src/blizzard-api.ts"],"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 */\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"],"mappings":";AAqDA,MAAMA,YAAiC;CACrC,IAAI;EACF,eAAe;EACf,UAAU;CACX;CACD,IAAI;EACF,eAAe;EACf,UAAU;CACX;CACD,IAAI;EACF,eAAe;EACf,UAAU;CACX;CACD,IAAI;EACF,eAAe;EACf,UAAU;CACX;CACD,IAAI;EACF,eAAe;EACf,UAAU;CACX;AACF;;;;;;;;;;;;;;;;;;;;;;;;AAwBD,SAAgB,eACdC,QACAC,QAC4B;CAC5B,MAAM,WAAW,UAAU;AAE3B,QAAO;EACL,UAAU,SAAS;EACnB,QAAQ,UAAU,SAAS;EAC3B;CACD;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blizzard-api/core",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "license": "MIT",
5
5
  "author": "Putro",
6
6
  "description": "The core helpers used by all @blizzard-api/* packages.",
@@ -42,8 +42,8 @@
42
42
  "dependencies": {},
43
43
  "devDependencies": {},
44
44
  "scripts": {
45
- "build": "tsup",
46
- "dev": "tsup --watch",
45
+ "build": "tsdown",
46
+ "dev": "tsdown --watch",
47
47
  "test": "vitest run",
48
48
  "test:coverage": "pnpm test -- --coverage",
49
49
  "test:watch": "vitest watch"