@blizzard-api/core 0.0.9 → 0.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.
@@ -1 +1 @@
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":[]}
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\r\n//Search\r\nexport * from './search.js';\r\n","/**\r\n * Possible regions for use within the Blizzard API.\r\n */\r\nexport type Origins = 'us' | 'eu' | 'kr' | 'tw';\r\n/**\r\n * Possible locales for use within the Blizzard API.\r\n */\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\n/**\r\n * A record of regions and their supported locales.\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\n/**\r\n * The default Blizzard API configuration for each region.\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\n/**\r\n * A record of Blizzard API configurations by region.\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\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 origin: Origins;\r\n locale: (typeof locales)[T][number];\r\n hostname: BlizzardApiDefault<Origins>['hostname'];\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 origin,\r\n hostname: endpoint.hostname,\r\n locale: locale ?? endpoint.defaultLocale,\r\n };\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACkDA,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;AA2BO,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
@@ -1,22 +1,57 @@
1
+ /**
2
+ * Possible regions for use within the Blizzard API.
3
+ */
1
4
  type Origins = 'us' | 'eu' | 'kr' | 'tw';
5
+ /**
6
+ * Possible locales for use within the Blizzard API.
7
+ */
2
8
  type Locales = 'en_US' | 'es_MX' | 'pt_BR' | 'en_GB' | 'es_ES' | 'fr_FR' | 'ru_RU' | 'de_DE' | 'pt_PT' | 'it_IT' | 'ko_KR' | 'zh_TW' | 'multi';
9
+ /**
10
+ * A record of regions and their supported locales.
11
+ */
3
12
  declare const locales: {
4
13
  readonly us: ["en_US", "es_MX", "pt_BR", "multi"];
5
14
  readonly eu: ["en_GB", "es_ES", "fr_FR", "ru_RU", "de_DE", "pt_PT", "it_IT", "multi"];
6
15
  readonly kr: ["ko_KR", "en_GB", "en_US", "multi"];
7
16
  readonly tw: ["zh_TW", "en_GB", "en_US", "multi"];
8
17
  };
18
+ /**
19
+ * The default Blizzard API configuration for each region.
20
+ */
9
21
  interface BlizzardApiDefault<T extends Origins> {
10
22
  hostname: `https://${T}.api.blizzard.com`;
11
23
  defaultLocale: (typeof locales)[T][number];
12
24
  }
25
+ /**
26
+ * A Blizzard API configuration object.
27
+ * @template T The region of the Blizzard API.
28
+ * @property origin The region of the Blizzard API.
29
+ * @property locale The locale of the Blizzard API.
30
+ * @property hostname The hostname of the Blizzard API.
31
+ */
13
32
  interface BlizzardApi<T extends Origins> {
14
33
  origin: Origins;
15
34
  locale: (typeof locales)[T][number];
16
35
  hostname: BlizzardApiDefault<Origins>['hostname'];
17
36
  }
37
+ /**
38
+ * Get the Blizzard API configuration for a given region.
39
+ * @template T The region of the Blizzard API.
40
+ * @param origin The region of the Blizzard API.
41
+ * @param locale The locale of the Blizzard API.
42
+ * @returns The Blizzard API configuration for the given region.
43
+ * @example
44
+ * const api = getBlizzardApi('us', 'en_US');
45
+ * console.log(api.hostname); // 'https://us.api.blizzard.com'
46
+ * console.log(api.locale); // 'en_US'
47
+ * console.log(api.origin); // 'us'
48
+ */
18
49
  declare function getBlizzardApi<T extends Origins>(origin: T, locale?: (typeof locales)[typeof origin][number]): BlizzardApi<typeof origin>;
19
50
 
51
+ /**
52
+ * Blizzard API namespaces.
53
+ * @see https://develop.battle.net/documentation/world-of-warcraft/guides/namespaces
54
+ */
20
55
  type BlizzardNamespaces = 'profile' | 'static' | 'dynamic' | 'static-classic' | 'dynamic-classic' | 'static-classic1x' | 'dynamic-classic1x';
21
56
 
22
57
  /**
@@ -24,10 +59,10 @@ type BlizzardNamespaces = 'profile' | 'static' | 'dynamic' | 'static-classic' |
24
59
  * @param _Response The response type of the resource
25
60
  * @param ProtectedResource Whether the resource requires a token to be requested
26
61
  */
27
- type Resource<Response, ProtectedResource extends boolean = false> = {
62
+ type Resource<Response, SearchOptions extends object = Record<string, never>, ProtectedResource extends boolean = false> = {
28
63
  path: string;
29
64
  namespace?: BlizzardNamespaces;
30
- parameters?: Record<string, string | number>;
65
+ parameters?: SearchOptions;
31
66
  /**
32
67
  * The response type of the resource
33
68
  * @private @internal This is an internal property and should not be used as it will not be populated
@@ -52,6 +87,46 @@ type ResourceResponse<T = unknown> = Promise<T>;
52
87
  * @example
53
88
  * type extracted = ExtractResourceType<Resource<{ id: number }>>;
54
89
  */
55
- type ExtractResourceType<Type> = Type extends Resource<infer R> ? R : never;
90
+ type ExtractResourceType<Type> = Type extends Resource<infer R, infer _SearchOptions, infer _Protected> ? R : never;
91
+
92
+ /**
93
+ * Base search parameters
94
+ * @interface BaseSearchParameters
95
+ * @property orderby The field to order results by.
96
+ * @property _page The page number to return.
97
+ * @example
98
+ * const params: BaseSearchParameters = {
99
+ * orderby: 'name',
100
+ * _page: 1,
101
+ * };
102
+ */
103
+ interface BaseSearchParameters {
104
+ orderby?: string | Array<string>;
105
+ _page?: number;
106
+ }
107
+ /**
108
+ * Search response
109
+ * @interface SearchResponse
110
+ * @property page The current page number.
111
+ * @property pageSize The number of results per page.
112
+ * @property maxPageSize The maximum number of results per page.
113
+ * @property pageCount The total number of pages.
114
+ * @property results The search results.
115
+ * @example
116
+ * const response: SearchResponse = {
117
+ * page: 1,
118
+ * pageSize: 20,
119
+ * maxPageSize: 100,
120
+ * pageCount: 10,
121
+ * results: [],
122
+ * };
123
+ */
124
+ interface SearchResponse<T> {
125
+ page: number;
126
+ pageSize: number;
127
+ maxPageSize: number;
128
+ pageCount: number;
129
+ results: Array<T>;
130
+ }
56
131
 
57
- export { type BlizzardNamespaces, type ExtractResourceType, type Locales, type Origins, type Resource, type ResourceResponse, getBlizzardApi };
132
+ export { type BaseSearchParameters, type BlizzardNamespaces, type ExtractResourceType, type Locales, type Origins, type Resource, type ResourceResponse, type SearchResponse, getBlizzardApi };
package/dist/index.d.ts CHANGED
@@ -1,22 +1,57 @@
1
+ /**
2
+ * Possible regions for use within the Blizzard API.
3
+ */
1
4
  type Origins = 'us' | 'eu' | 'kr' | 'tw';
5
+ /**
6
+ * Possible locales for use within the Blizzard API.
7
+ */
2
8
  type Locales = 'en_US' | 'es_MX' | 'pt_BR' | 'en_GB' | 'es_ES' | 'fr_FR' | 'ru_RU' | 'de_DE' | 'pt_PT' | 'it_IT' | 'ko_KR' | 'zh_TW' | 'multi';
9
+ /**
10
+ * A record of regions and their supported locales.
11
+ */
3
12
  declare const locales: {
4
13
  readonly us: ["en_US", "es_MX", "pt_BR", "multi"];
5
14
  readonly eu: ["en_GB", "es_ES", "fr_FR", "ru_RU", "de_DE", "pt_PT", "it_IT", "multi"];
6
15
  readonly kr: ["ko_KR", "en_GB", "en_US", "multi"];
7
16
  readonly tw: ["zh_TW", "en_GB", "en_US", "multi"];
8
17
  };
18
+ /**
19
+ * The default Blizzard API configuration for each region.
20
+ */
9
21
  interface BlizzardApiDefault<T extends Origins> {
10
22
  hostname: `https://${T}.api.blizzard.com`;
11
23
  defaultLocale: (typeof locales)[T][number];
12
24
  }
25
+ /**
26
+ * A Blizzard API configuration object.
27
+ * @template T The region of the Blizzard API.
28
+ * @property origin The region of the Blizzard API.
29
+ * @property locale The locale of the Blizzard API.
30
+ * @property hostname The hostname of the Blizzard API.
31
+ */
13
32
  interface BlizzardApi<T extends Origins> {
14
33
  origin: Origins;
15
34
  locale: (typeof locales)[T][number];
16
35
  hostname: BlizzardApiDefault<Origins>['hostname'];
17
36
  }
37
+ /**
38
+ * Get the Blizzard API configuration for a given region.
39
+ * @template T The region of the Blizzard API.
40
+ * @param origin The region of the Blizzard API.
41
+ * @param locale The locale of the Blizzard API.
42
+ * @returns The Blizzard API configuration for the given region.
43
+ * @example
44
+ * const api = getBlizzardApi('us', 'en_US');
45
+ * console.log(api.hostname); // 'https://us.api.blizzard.com'
46
+ * console.log(api.locale); // 'en_US'
47
+ * console.log(api.origin); // 'us'
48
+ */
18
49
  declare function getBlizzardApi<T extends Origins>(origin: T, locale?: (typeof locales)[typeof origin][number]): BlizzardApi<typeof origin>;
19
50
 
51
+ /**
52
+ * Blizzard API namespaces.
53
+ * @see https://develop.battle.net/documentation/world-of-warcraft/guides/namespaces
54
+ */
20
55
  type BlizzardNamespaces = 'profile' | 'static' | 'dynamic' | 'static-classic' | 'dynamic-classic' | 'static-classic1x' | 'dynamic-classic1x';
21
56
 
22
57
  /**
@@ -24,10 +59,10 @@ type BlizzardNamespaces = 'profile' | 'static' | 'dynamic' | 'static-classic' |
24
59
  * @param _Response The response type of the resource
25
60
  * @param ProtectedResource Whether the resource requires a token to be requested
26
61
  */
27
- type Resource<Response, ProtectedResource extends boolean = false> = {
62
+ type Resource<Response, SearchOptions extends object = Record<string, never>, ProtectedResource extends boolean = false> = {
28
63
  path: string;
29
64
  namespace?: BlizzardNamespaces;
30
- parameters?: Record<string, string | number>;
65
+ parameters?: SearchOptions;
31
66
  /**
32
67
  * The response type of the resource
33
68
  * @private @internal This is an internal property and should not be used as it will not be populated
@@ -52,6 +87,46 @@ type ResourceResponse<T = unknown> = Promise<T>;
52
87
  * @example
53
88
  * type extracted = ExtractResourceType<Resource<{ id: number }>>;
54
89
  */
55
- type ExtractResourceType<Type> = Type extends Resource<infer R> ? R : never;
90
+ type ExtractResourceType<Type> = Type extends Resource<infer R, infer _SearchOptions, infer _Protected> ? R : never;
91
+
92
+ /**
93
+ * Base search parameters
94
+ * @interface BaseSearchParameters
95
+ * @property orderby The field to order results by.
96
+ * @property _page The page number to return.
97
+ * @example
98
+ * const params: BaseSearchParameters = {
99
+ * orderby: 'name',
100
+ * _page: 1,
101
+ * };
102
+ */
103
+ interface BaseSearchParameters {
104
+ orderby?: string | Array<string>;
105
+ _page?: number;
106
+ }
107
+ /**
108
+ * Search response
109
+ * @interface SearchResponse
110
+ * @property page The current page number.
111
+ * @property pageSize The number of results per page.
112
+ * @property maxPageSize The maximum number of results per page.
113
+ * @property pageCount The total number of pages.
114
+ * @property results The search results.
115
+ * @example
116
+ * const response: SearchResponse = {
117
+ * page: 1,
118
+ * pageSize: 20,
119
+ * maxPageSize: 100,
120
+ * pageCount: 10,
121
+ * results: [],
122
+ * };
123
+ */
124
+ interface SearchResponse<T> {
125
+ page: number;
126
+ pageSize: number;
127
+ maxPageSize: number;
128
+ pageCount: number;
129
+ results: Array<T>;
130
+ }
56
131
 
57
- export { type BlizzardNamespaces, type ExtractResourceType, type Locales, type Origins, type Resource, type ResourceResponse, getBlizzardApi };
132
+ export { type BaseSearchParameters, type BlizzardNamespaces, type ExtractResourceType, type Locales, type Origins, type Resource, type ResourceResponse, type SearchResponse, getBlizzardApi };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
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":[]}
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 = 'us' | 'eu' | 'kr' | 'tw';\r\n/**\r\n * Possible locales for use within the Blizzard API.\r\n */\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\n/**\r\n * A record of regions and their supported locales.\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\n/**\r\n * The default Blizzard API configuration for each region.\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\n/**\r\n * A record of Blizzard API configurations by region.\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\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 origin: Origins;\r\n locale: (typeof locales)[T][number];\r\n hostname: BlizzardApiDefault<Origins>['hostname'];\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 origin,\r\n hostname: endpoint.hostname,\r\n locale: locale ?? endpoint.defaultLocale,\r\n };\r\n}\r\n"],"mappings":";AAkDA,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;AA2BO,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,13 +1,13 @@
1
1
  {
2
2
  "name": "@blizzard-api/core",
3
- "version": "0.0.9",
3
+ "version": "0.1.1",
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/tree/main/packages/core",
8
8
  "type": "module",
9
9
  "engines": {
10
- "node": ">=18 <19 || >=20"
10
+ "node": "^18.18 || ^20.9 || ^21.1 || ^22"
11
11
  },
12
12
  "main": "./dist/index.js",
13
13
  "exports": {