@blizzard-api/client 0.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.cjs +97 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +57 -0
- package/dist/index.d.ts +57 -0
- package/dist/index.js +60 -0
- package/dist/index.js.map +1 -0
- package/package.json +57 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
BlizzardApiClient: () => BlizzardApiClient
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(src_exports);
|
|
36
|
+
|
|
37
|
+
// src/client.ts
|
|
38
|
+
var import_node_querystring = require("querystring");
|
|
39
|
+
var import_core = require("@blizzard-api/core");
|
|
40
|
+
var import_axios = __toESM(require("axios"), 1);
|
|
41
|
+
var BlizzardApiClient = class {
|
|
42
|
+
defaults;
|
|
43
|
+
constructor(options) {
|
|
44
|
+
const { origin, locale } = (0, import_core.getEndpoint)(options.origin, options.locale);
|
|
45
|
+
this.defaults = {
|
|
46
|
+
key: options.key,
|
|
47
|
+
secret: options.secret,
|
|
48
|
+
token: options.token,
|
|
49
|
+
origin,
|
|
50
|
+
locale
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
axios = import_axios.default.create();
|
|
54
|
+
getAccessToken = async (options) => {
|
|
55
|
+
const { key, secret, origin } = { ...this.defaults, ...options };
|
|
56
|
+
return this.axios.post(`https://${origin}.battle.net/oauth/token`, void 0, {
|
|
57
|
+
params: {
|
|
58
|
+
grant_type: "client_credentials"
|
|
59
|
+
},
|
|
60
|
+
auth: {
|
|
61
|
+
username: key,
|
|
62
|
+
password: secret
|
|
63
|
+
},
|
|
64
|
+
headers: {
|
|
65
|
+
"Content-Type": "application/json"
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
setAccessToken = (token) => {
|
|
70
|
+
this.defaults.token = token;
|
|
71
|
+
};
|
|
72
|
+
refreshAccessToken = async (options) => {
|
|
73
|
+
const response = await this.getAccessToken(options);
|
|
74
|
+
this.setAccessToken(response.data.access_token);
|
|
75
|
+
return response;
|
|
76
|
+
};
|
|
77
|
+
validateAccessToken = async (options) => {
|
|
78
|
+
const { origin, token } = { ...this.defaults, ...options };
|
|
79
|
+
if (!token) {
|
|
80
|
+
throw new Error("No token has been set previously or been passed to the validateAccessToken method.");
|
|
81
|
+
}
|
|
82
|
+
return await this.axios.post(
|
|
83
|
+
`https://${origin}.battle.net/oauth/check_token`,
|
|
84
|
+
(0, import_node_querystring.stringify)({ token }),
|
|
85
|
+
{
|
|
86
|
+
headers: {
|
|
87
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
);
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
94
|
+
0 && (module.exports = {
|
|
95
|
+
BlizzardApiClient
|
|
96
|
+
});
|
|
97
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/client.ts"],"sourcesContent":["export type { ClientOptions } from './client.js';\r\nexport { BlizzardApiClient } from './client.js';\r\n","import { stringify } from 'node:querystring';\r\nimport { getEndpoint } from '@blizzard-api/core';\r\nimport type { Origins, Locales } from '@blizzard-api/core';\r\nimport type { AxiosResponse } from 'axios';\r\nimport axios from 'axios';\r\n\r\nexport interface ClientOptions {\r\n key: string;\r\n secret: string;\r\n origin: Origins;\r\n locale?: Locales;\r\n token?: string;\r\n}\r\n\r\ninterface AccessToken {\r\n access_token: string;\r\n token_type: 'bearer';\r\n expires_in: number;\r\n sub?: string;\r\n}\r\n\r\ninterface AccessTokenRequestArguments {\r\n origin?: Origins;\r\n key?: string;\r\n secret?: string;\r\n}\r\n\r\ninterface ValidateAccessTokenArguments {\r\n origin?: Origins;\r\n token?: string;\r\n}\r\n\r\ninterface ValidateAccessTokenResponse {\r\n scope: Array<string>;\r\n account_authorities: Array<unknown>;\r\n exp: number;\r\n client_authorities: Array<unknown>;\r\n authorities: Array<string>;\r\n client_id: string;\r\n}\r\n\r\ninterface IBlizzardApiClient {\r\n getAccessToken: (options: AccessTokenRequestArguments) => Promise<AxiosResponse<AccessToken>>;\r\n setAccessToken: (token: string) => void;\r\n refreshAccessToken: (options: AccessTokenRequestArguments) => Promise<AxiosResponse<AccessToken>>;\r\n validateAccessToken: (options: ValidateAccessTokenArguments) => Promise<AxiosResponse<ValidateAccessTokenResponse>>;\r\n}\r\n\r\nexport class BlizzardApiClient implements IBlizzardApiClient {\r\n public defaults: {\r\n key: string;\r\n secret: string;\r\n origin: Origins;\r\n locale: Locales;\r\n token?: string;\r\n };\r\n\r\n constructor(options: ClientOptions) {\r\n const { origin, locale } = getEndpoint(options.origin, options.locale);\r\n this.defaults = {\r\n key: options.key,\r\n secret: options.secret,\r\n token: options.token,\r\n origin: origin,\r\n locale: locale,\r\n };\r\n }\r\n\r\n public axios = axios.create();\r\n\r\n public getAccessToken = async (options?: AccessTokenRequestArguments): Promise<AxiosResponse<AccessToken>> => {\r\n const { key, secret, origin } = { ...this.defaults, ...options };\r\n return this.axios.post<AccessToken>(`https://${origin}.battle.net/oauth/token`, undefined, {\r\n params: {\r\n grant_type: 'client_credentials',\r\n },\r\n auth: {\r\n username: key,\r\n password: secret,\r\n },\r\n headers: {\r\n 'Content-Type': 'application/json',\r\n },\r\n });\r\n };\r\n\r\n public setAccessToken = (token: string): void => {\r\n this.defaults.token = token;\r\n };\r\n\r\n public refreshAccessToken = async (options?: AccessTokenRequestArguments): Promise<AxiosResponse<AccessToken>> => {\r\n const response = await this.getAccessToken(options);\r\n this.setAccessToken(response.data.access_token);\r\n return response;\r\n };\r\n\r\n public validateAccessToken = async (\r\n options?: ValidateAccessTokenArguments,\r\n ): Promise<AxiosResponse<ValidateAccessTokenResponse>> => {\r\n const { origin, token } = { ...this.defaults, ...options };\r\n\r\n if (!token) {\r\n throw new Error('No token has been set previously or been passed to the validateAccessToken method.');\r\n }\r\n\r\n return await this.axios.post<ValidateAccessTokenResponse>(\r\n `https://${origin}.battle.net/oauth/check_token`,\r\n stringify({ token }),\r\n {\r\n headers: {\r\n 'Content-Type': 'application/x-www-form-urlencoded',\r\n },\r\n },\r\n );\r\n };\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,8BAA0B;AAC1B,kBAA4B;AAG5B,mBAAkB;AA4CX,IAAM,oBAAN,MAAsD;AAAA,EACpD;AAAA,EAQP,YAAY,SAAwB;AAClC,UAAM,EAAE,QAAQ,OAAO,QAAI,yBAAY,QAAQ,QAAQ,QAAQ,MAAM;AACrE,SAAK,WAAW;AAAA,MACd,KAAK,QAAQ;AAAA,MACb,QAAQ,QAAQ;AAAA,MAChB,OAAO,QAAQ;AAAA,MACf;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAAA,EAEO,QAAQ,aAAAA,QAAM,OAAO;AAAA,EAErB,iBAAiB,OAAO,YAA+E;AAC5G,UAAM,EAAE,KAAK,QAAQ,OAAO,IAAI,EAAE,GAAG,KAAK,UAAU,GAAG,QAAQ;AAC/D,WAAO,KAAK,MAAM,KAAkB,WAAW,MAAM,2BAA2B,QAAW;AAAA,MACzF,QAAQ;AAAA,QACN,YAAY;AAAA,MACd;AAAA,MACA,MAAM;AAAA,QACJ,UAAU;AAAA,QACV,UAAU;AAAA,MACZ;AAAA,MACA,SAAS;AAAA,QACP,gBAAgB;AAAA,MAClB;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEO,iBAAiB,CAAC,UAAwB;AAC/C,SAAK,SAAS,QAAQ;AAAA,EACxB;AAAA,EAEO,qBAAqB,OAAO,YAA+E;AAChH,UAAM,WAAW,MAAM,KAAK,eAAe,OAAO;AAClD,SAAK,eAAe,SAAS,KAAK,YAAY;AAC9C,WAAO;AAAA,EACT;AAAA,EAEO,sBAAsB,OAC3B,YACwD;AACxD,UAAM,EAAE,QAAQ,MAAM,IAAI,EAAE,GAAG,KAAK,UAAU,GAAG,QAAQ;AAEzD,QAAI,CAAC,OAAO;AACV,YAAM,IAAI,MAAM,oFAAoF;AAAA,IACtG;AAEA,WAAO,MAAM,KAAK,MAAM;AAAA,MACtB,WAAW,MAAM;AAAA,UACjB,mCAAU,EAAE,MAAM,CAAC;AAAA,MACnB;AAAA,QACE,SAAS;AAAA,UACP,gBAAgB;AAAA,QAClB;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":["axios"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as axios from 'axios';
|
|
2
|
+
import { AxiosResponse } from 'axios';
|
|
3
|
+
import { Origins, Locales } from '@blizzard-api/core';
|
|
4
|
+
|
|
5
|
+
interface ClientOptions {
|
|
6
|
+
key: string;
|
|
7
|
+
secret: string;
|
|
8
|
+
origin: Origins;
|
|
9
|
+
locale?: Locales;
|
|
10
|
+
token?: string;
|
|
11
|
+
}
|
|
12
|
+
interface AccessToken {
|
|
13
|
+
access_token: string;
|
|
14
|
+
token_type: 'bearer';
|
|
15
|
+
expires_in: number;
|
|
16
|
+
sub?: string;
|
|
17
|
+
}
|
|
18
|
+
interface AccessTokenRequestArguments {
|
|
19
|
+
origin?: Origins;
|
|
20
|
+
key?: string;
|
|
21
|
+
secret?: string;
|
|
22
|
+
}
|
|
23
|
+
interface ValidateAccessTokenArguments {
|
|
24
|
+
origin?: Origins;
|
|
25
|
+
token?: string;
|
|
26
|
+
}
|
|
27
|
+
interface ValidateAccessTokenResponse {
|
|
28
|
+
scope: Array<string>;
|
|
29
|
+
account_authorities: Array<unknown>;
|
|
30
|
+
exp: number;
|
|
31
|
+
client_authorities: Array<unknown>;
|
|
32
|
+
authorities: Array<string>;
|
|
33
|
+
client_id: string;
|
|
34
|
+
}
|
|
35
|
+
interface IBlizzardApiClient {
|
|
36
|
+
getAccessToken: (options: AccessTokenRequestArguments) => Promise<AxiosResponse<AccessToken>>;
|
|
37
|
+
setAccessToken: (token: string) => void;
|
|
38
|
+
refreshAccessToken: (options: AccessTokenRequestArguments) => Promise<AxiosResponse<AccessToken>>;
|
|
39
|
+
validateAccessToken: (options: ValidateAccessTokenArguments) => Promise<AxiosResponse<ValidateAccessTokenResponse>>;
|
|
40
|
+
}
|
|
41
|
+
declare class BlizzardApiClient implements IBlizzardApiClient {
|
|
42
|
+
defaults: {
|
|
43
|
+
key: string;
|
|
44
|
+
secret: string;
|
|
45
|
+
origin: Origins;
|
|
46
|
+
locale: Locales;
|
|
47
|
+
token?: string;
|
|
48
|
+
};
|
|
49
|
+
constructor(options: ClientOptions);
|
|
50
|
+
axios: axios.AxiosInstance;
|
|
51
|
+
getAccessToken: (options?: AccessTokenRequestArguments) => Promise<AxiosResponse<AccessToken>>;
|
|
52
|
+
setAccessToken: (token: string) => void;
|
|
53
|
+
refreshAccessToken: (options?: AccessTokenRequestArguments) => Promise<AxiosResponse<AccessToken>>;
|
|
54
|
+
validateAccessToken: (options?: ValidateAccessTokenArguments) => Promise<AxiosResponse<ValidateAccessTokenResponse>>;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export { BlizzardApiClient, type ClientOptions };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as axios from 'axios';
|
|
2
|
+
import { AxiosResponse } from 'axios';
|
|
3
|
+
import { Origins, Locales } from '@blizzard-api/core';
|
|
4
|
+
|
|
5
|
+
interface ClientOptions {
|
|
6
|
+
key: string;
|
|
7
|
+
secret: string;
|
|
8
|
+
origin: Origins;
|
|
9
|
+
locale?: Locales;
|
|
10
|
+
token?: string;
|
|
11
|
+
}
|
|
12
|
+
interface AccessToken {
|
|
13
|
+
access_token: string;
|
|
14
|
+
token_type: 'bearer';
|
|
15
|
+
expires_in: number;
|
|
16
|
+
sub?: string;
|
|
17
|
+
}
|
|
18
|
+
interface AccessTokenRequestArguments {
|
|
19
|
+
origin?: Origins;
|
|
20
|
+
key?: string;
|
|
21
|
+
secret?: string;
|
|
22
|
+
}
|
|
23
|
+
interface ValidateAccessTokenArguments {
|
|
24
|
+
origin?: Origins;
|
|
25
|
+
token?: string;
|
|
26
|
+
}
|
|
27
|
+
interface ValidateAccessTokenResponse {
|
|
28
|
+
scope: Array<string>;
|
|
29
|
+
account_authorities: Array<unknown>;
|
|
30
|
+
exp: number;
|
|
31
|
+
client_authorities: Array<unknown>;
|
|
32
|
+
authorities: Array<string>;
|
|
33
|
+
client_id: string;
|
|
34
|
+
}
|
|
35
|
+
interface IBlizzardApiClient {
|
|
36
|
+
getAccessToken: (options: AccessTokenRequestArguments) => Promise<AxiosResponse<AccessToken>>;
|
|
37
|
+
setAccessToken: (token: string) => void;
|
|
38
|
+
refreshAccessToken: (options: AccessTokenRequestArguments) => Promise<AxiosResponse<AccessToken>>;
|
|
39
|
+
validateAccessToken: (options: ValidateAccessTokenArguments) => Promise<AxiosResponse<ValidateAccessTokenResponse>>;
|
|
40
|
+
}
|
|
41
|
+
declare class BlizzardApiClient implements IBlizzardApiClient {
|
|
42
|
+
defaults: {
|
|
43
|
+
key: string;
|
|
44
|
+
secret: string;
|
|
45
|
+
origin: Origins;
|
|
46
|
+
locale: Locales;
|
|
47
|
+
token?: string;
|
|
48
|
+
};
|
|
49
|
+
constructor(options: ClientOptions);
|
|
50
|
+
axios: axios.AxiosInstance;
|
|
51
|
+
getAccessToken: (options?: AccessTokenRequestArguments) => Promise<AxiosResponse<AccessToken>>;
|
|
52
|
+
setAccessToken: (token: string) => void;
|
|
53
|
+
refreshAccessToken: (options?: AccessTokenRequestArguments) => Promise<AxiosResponse<AccessToken>>;
|
|
54
|
+
validateAccessToken: (options?: ValidateAccessTokenArguments) => Promise<AxiosResponse<ValidateAccessTokenResponse>>;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export { BlizzardApiClient, type ClientOptions };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// src/client.ts
|
|
2
|
+
import { stringify } from "querystring";
|
|
3
|
+
import { getEndpoint } from "@blizzard-api/core";
|
|
4
|
+
import axios from "axios";
|
|
5
|
+
var BlizzardApiClient = class {
|
|
6
|
+
defaults;
|
|
7
|
+
constructor(options) {
|
|
8
|
+
const { origin, locale } = getEndpoint(options.origin, options.locale);
|
|
9
|
+
this.defaults = {
|
|
10
|
+
key: options.key,
|
|
11
|
+
secret: options.secret,
|
|
12
|
+
token: options.token,
|
|
13
|
+
origin,
|
|
14
|
+
locale
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
axios = axios.create();
|
|
18
|
+
getAccessToken = async (options) => {
|
|
19
|
+
const { key, secret, origin } = { ...this.defaults, ...options };
|
|
20
|
+
return this.axios.post(`https://${origin}.battle.net/oauth/token`, void 0, {
|
|
21
|
+
params: {
|
|
22
|
+
grant_type: "client_credentials"
|
|
23
|
+
},
|
|
24
|
+
auth: {
|
|
25
|
+
username: key,
|
|
26
|
+
password: secret
|
|
27
|
+
},
|
|
28
|
+
headers: {
|
|
29
|
+
"Content-Type": "application/json"
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
setAccessToken = (token) => {
|
|
34
|
+
this.defaults.token = token;
|
|
35
|
+
};
|
|
36
|
+
refreshAccessToken = async (options) => {
|
|
37
|
+
const response = await this.getAccessToken(options);
|
|
38
|
+
this.setAccessToken(response.data.access_token);
|
|
39
|
+
return response;
|
|
40
|
+
};
|
|
41
|
+
validateAccessToken = async (options) => {
|
|
42
|
+
const { origin, token } = { ...this.defaults, ...options };
|
|
43
|
+
if (!token) {
|
|
44
|
+
throw new Error("No token has been set previously or been passed to the validateAccessToken method.");
|
|
45
|
+
}
|
|
46
|
+
return await this.axios.post(
|
|
47
|
+
`https://${origin}.battle.net/oauth/check_token`,
|
|
48
|
+
stringify({ token }),
|
|
49
|
+
{
|
|
50
|
+
headers: {
|
|
51
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
export {
|
|
58
|
+
BlizzardApiClient
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client.ts"],"sourcesContent":["import { stringify } from 'node:querystring';\r\nimport { getEndpoint } from '@blizzard-api/core';\r\nimport type { Origins, Locales } from '@blizzard-api/core';\r\nimport type { AxiosResponse } from 'axios';\r\nimport axios from 'axios';\r\n\r\nexport interface ClientOptions {\r\n key: string;\r\n secret: string;\r\n origin: Origins;\r\n locale?: Locales;\r\n token?: string;\r\n}\r\n\r\ninterface AccessToken {\r\n access_token: string;\r\n token_type: 'bearer';\r\n expires_in: number;\r\n sub?: string;\r\n}\r\n\r\ninterface AccessTokenRequestArguments {\r\n origin?: Origins;\r\n key?: string;\r\n secret?: string;\r\n}\r\n\r\ninterface ValidateAccessTokenArguments {\r\n origin?: Origins;\r\n token?: string;\r\n}\r\n\r\ninterface ValidateAccessTokenResponse {\r\n scope: Array<string>;\r\n account_authorities: Array<unknown>;\r\n exp: number;\r\n client_authorities: Array<unknown>;\r\n authorities: Array<string>;\r\n client_id: string;\r\n}\r\n\r\ninterface IBlizzardApiClient {\r\n getAccessToken: (options: AccessTokenRequestArguments) => Promise<AxiosResponse<AccessToken>>;\r\n setAccessToken: (token: string) => void;\r\n refreshAccessToken: (options: AccessTokenRequestArguments) => Promise<AxiosResponse<AccessToken>>;\r\n validateAccessToken: (options: ValidateAccessTokenArguments) => Promise<AxiosResponse<ValidateAccessTokenResponse>>;\r\n}\r\n\r\nexport class BlizzardApiClient implements IBlizzardApiClient {\r\n public defaults: {\r\n key: string;\r\n secret: string;\r\n origin: Origins;\r\n locale: Locales;\r\n token?: string;\r\n };\r\n\r\n constructor(options: ClientOptions) {\r\n const { origin, locale } = getEndpoint(options.origin, options.locale);\r\n this.defaults = {\r\n key: options.key,\r\n secret: options.secret,\r\n token: options.token,\r\n origin: origin,\r\n locale: locale,\r\n };\r\n }\r\n\r\n public axios = axios.create();\r\n\r\n public getAccessToken = async (options?: AccessTokenRequestArguments): Promise<AxiosResponse<AccessToken>> => {\r\n const { key, secret, origin } = { ...this.defaults, ...options };\r\n return this.axios.post<AccessToken>(`https://${origin}.battle.net/oauth/token`, undefined, {\r\n params: {\r\n grant_type: 'client_credentials',\r\n },\r\n auth: {\r\n username: key,\r\n password: secret,\r\n },\r\n headers: {\r\n 'Content-Type': 'application/json',\r\n },\r\n });\r\n };\r\n\r\n public setAccessToken = (token: string): void => {\r\n this.defaults.token = token;\r\n };\r\n\r\n public refreshAccessToken = async (options?: AccessTokenRequestArguments): Promise<AxiosResponse<AccessToken>> => {\r\n const response = await this.getAccessToken(options);\r\n this.setAccessToken(response.data.access_token);\r\n return response;\r\n };\r\n\r\n public validateAccessToken = async (\r\n options?: ValidateAccessTokenArguments,\r\n ): Promise<AxiosResponse<ValidateAccessTokenResponse>> => {\r\n const { origin, token } = { ...this.defaults, ...options };\r\n\r\n if (!token) {\r\n throw new Error('No token has been set previously or been passed to the validateAccessToken method.');\r\n }\r\n\r\n return await this.axios.post<ValidateAccessTokenResponse>(\r\n `https://${origin}.battle.net/oauth/check_token`,\r\n stringify({ token }),\r\n {\r\n headers: {\r\n 'Content-Type': 'application/x-www-form-urlencoded',\r\n },\r\n },\r\n );\r\n };\r\n}\r\n"],"mappings":";AAAA,SAAS,iBAAiB;AAC1B,SAAS,mBAAmB;AAG5B,OAAO,WAAW;AA4CX,IAAM,oBAAN,MAAsD;AAAA,EACpD;AAAA,EAQP,YAAY,SAAwB;AAClC,UAAM,EAAE,QAAQ,OAAO,IAAI,YAAY,QAAQ,QAAQ,QAAQ,MAAM;AACrE,SAAK,WAAW;AAAA,MACd,KAAK,QAAQ;AAAA,MACb,QAAQ,QAAQ;AAAA,MAChB,OAAO,QAAQ;AAAA,MACf;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAAA,EAEO,QAAQ,MAAM,OAAO;AAAA,EAErB,iBAAiB,OAAO,YAA+E;AAC5G,UAAM,EAAE,KAAK,QAAQ,OAAO,IAAI,EAAE,GAAG,KAAK,UAAU,GAAG,QAAQ;AAC/D,WAAO,KAAK,MAAM,KAAkB,WAAW,MAAM,2BAA2B,QAAW;AAAA,MACzF,QAAQ;AAAA,QACN,YAAY;AAAA,MACd;AAAA,MACA,MAAM;AAAA,QACJ,UAAU;AAAA,QACV,UAAU;AAAA,MACZ;AAAA,MACA,SAAS;AAAA,QACP,gBAAgB;AAAA,MAClB;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEO,iBAAiB,CAAC,UAAwB;AAC/C,SAAK,SAAS,QAAQ;AAAA,EACxB;AAAA,EAEO,qBAAqB,OAAO,YAA+E;AAChH,UAAM,WAAW,MAAM,KAAK,eAAe,OAAO;AAClD,SAAK,eAAe,SAAS,KAAK,YAAY;AAC9C,WAAO;AAAA,EACT;AAAA,EAEO,sBAAsB,OAC3B,YACwD;AACxD,UAAM,EAAE,QAAQ,MAAM,IAAI,EAAE,GAAG,KAAK,UAAU,GAAG,QAAQ;AAEzD,QAAI,CAAC,OAAO;AACV,YAAM,IAAI,MAAM,oFAAoF;AAAA,IACtG;AAEA,WAAO,MAAM,KAAK,MAAM;AAAA,MACtB,WAAW,MAAM;AAAA,MACjB,UAAU,EAAE,MAAM,CAAC;AAAA,MACnB;AAAA,QACE,SAAS;AAAA,UACP,gBAAgB;AAAA,QAClB;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@blizzard-api/client",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"author": "Putro",
|
|
6
|
+
"description": "A node.js axios client to integrate with the blizzard battle.net api.",
|
|
7
|
+
"repository": "https://github.com/Pewtro/blizzard/packages/client",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"engines": {
|
|
10
|
+
"node": ">=18 <19 || >=20"
|
|
11
|
+
},
|
|
12
|
+
"main": "./dist/index.js",
|
|
13
|
+
"exports": {
|
|
14
|
+
"import": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"require": {
|
|
19
|
+
"types": "./dist/index.d.cts",
|
|
20
|
+
"default": "./dist/index.cjs"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"keywords": [
|
|
27
|
+
"blizzard",
|
|
28
|
+
"battlenet",
|
|
29
|
+
"battle.net",
|
|
30
|
+
"bnet",
|
|
31
|
+
"api",
|
|
32
|
+
"world of warcraft",
|
|
33
|
+
"warcraft",
|
|
34
|
+
"wow",
|
|
35
|
+
"classic",
|
|
36
|
+
"retail",
|
|
37
|
+
"starcraft",
|
|
38
|
+
"sc2",
|
|
39
|
+
"diablo",
|
|
40
|
+
"d3",
|
|
41
|
+
"hs",
|
|
42
|
+
"hearthstone",
|
|
43
|
+
"ow",
|
|
44
|
+
"overwatch"
|
|
45
|
+
],
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@blizzard-api/core": "^0.0.1",
|
|
48
|
+
"axios": "1.6.8"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build": "tsup",
|
|
52
|
+
"debv": "tsup --watch",
|
|
53
|
+
"test": "vitest run",
|
|
54
|
+
"test:coverage": "pnpm test -- --coverage",
|
|
55
|
+
"test:watch": "vitest watch"
|
|
56
|
+
}
|
|
57
|
+
}
|