Socket
Socket
Sign inDemoInstall

blizzapi

Package Overview
Dependencies
6
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.1 to 1.0.0

@interfaces/AccessTokenOptions.d.ts

8

@interfaces/index.d.ts

@@ -1,4 +0,4 @@

import InitOptions from './InitOptions';
import RegionIdProperties from './RegionIdProperties';
export { InitOptions, RegionIdProperties };
export { InitOptions } from './InitOptions';
export { RegionIdProperties } from './RegionIdProperties';
export { BattleNetOptions } from './BattleNetOptions';
export { AccessTokenOptions } from './AccessTokenOptions';

@@ -1,2 +0,2 @@

export default interface InitOptions {
export interface InitOptions {
region: string | number;

@@ -3,0 +3,0 @@ clientId?: string;

@@ -1,3 +0,3 @@

export default interface RegionIdProperties<Value> {
export interface RegionIdProperties<Value> {
readonly [regionId: string]: Value;
}

@@ -53,6 +53,6 @@ /** Common */

export type Endpoint = string;
export type Endpoints = ReadonlyArray<Endpoint>;
// export type Endpoints = ReadonlyArray<Endpoint>;
export type HttpMethod = 'GET' | 'POST';
export type Selector = string;
// export type Selector = string;
export type ValidatorFunction = (endpoint: Endpoint) => boolean;
import BlizzAPI from './lib/classes/BlizzAPI';
export default BlizzAPI;
export = BlizzAPI;
//# sourceMappingURL=index.d.ts.map

@@ -5,5 +5,4 @@ "use strict";

};
Object.defineProperty(exports, "__esModule", { value: true });
const BlizzAPI_1 = __importDefault(require("./lib/classes/BlizzAPI"));
exports.default = BlizzAPI_1.default;
module.exports = BlizzAPI_1.default;
//# sourceMappingURL=index.js.map

@@ -1,13 +0,12 @@

declare const _default: {
new (region: string | number, clientId: string, clientSecret: string, accessToken?: string | undefined): {
readonly region: string | number;
accessToken: string | undefined;
readonly getAccessToken: () => string | Promise<string>;
readonly setAccessToken: () => Promise<string>;
readonly clientId: string;
readonly clientSecret: string;
};
validateAccessToken: (region: string | number, accessToken: string | undefined) => Promise<boolean>;
};
export = _default;
import { RegionIdOrName, AccessToken } from '../../../../@types';
import OAuth2API from './OAuth2API';
import { BattleNetOptions } from '../../../../@interfaces';
export default class BattleNetAPI extends OAuth2API {
readonly region: RegionIdOrName;
accessToken: AccessToken;
constructor(options: BattleNetOptions);
getAccessToken: () => string | Promise<string>;
setAccessToken: () => Promise<string>;
static validateAccessToken: (region: string | number, accessToken: string | undefined) => Promise<boolean>;
}
//# sourceMappingURL=BattleNetAPI.d.ts.map

@@ -20,19 +20,23 @@ "use strict";

};
var _a;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const OAuth2API_1 = __importDefault(require("./OAuth2API"));
const OAuthHelpers = __importStar(require("../../helpers/oauth"));
module.exports = (_a = class BattleNetAPI extends OAuth2API_1.default {
constructor(region, clientId, clientSecret, accessToken) {
super(clientId, clientSecret);
this.getAccessToken = () => (this.accessToken ? this.accessToken : this.setAccessToken());
this.setAccessToken = () => __awaiter(this, void 0, void 0, function* () {
return (this.accessToken = yield OAuthHelpers.getAccessToken(this.region, this.clientId, this.clientSecret));
});
this.region = region;
this.accessToken = accessToken || undefined;
}
},
_a.validateAccessToken = (region, accessToken) => __awaiter(this, void 0, void 0, function* () { return OAuthHelpers.validateAccessToken(region, accessToken); }),
_a);
class BattleNetAPI extends OAuth2API_1.default {
constructor(options) {
super(options.clientId, options.clientSecret);
this.getAccessToken = () => (this.accessToken || this.setAccessToken());
this.setAccessToken = () => __awaiter(this, void 0, void 0, function* () {
return (this.accessToken = yield OAuthHelpers.getAccessToken({
region: this.region,
clientId: this.clientId,
clientSecret: this.clientSecret,
}));
});
this.region = options.region;
this.accessToken = options.accessToken || undefined;
}
}
BattleNetAPI.validateAccessToken = (region, accessToken) => OAuthHelpers.validateAccessToken(region, accessToken);
exports.default = BattleNetAPI;
;
//# sourceMappingURL=BattleNetAPI.js.map

@@ -0,6 +1,7 @@

import { ClientId, ClientSecret } from '../../../../@types';
export default class OAuth2API {
readonly clientId: string;
readonly clientSecret: string;
constructor(clientId: string, clientSecret: string);
readonly clientId: ClientId;
readonly clientSecret: ClientSecret;
constructor(clientId: ClientId, clientSecret: ClientSecret);
}
//# sourceMappingURL=OAuth2API.d.ts.map

@@ -1,21 +0,9 @@

import * as utils from '../utils';
import { RegionIdOrName } from '../../../@types';
import BattleNetAPI = require('./abstract/BattleNetAPI');
export interface BlizzAPIOptions {
validateAccessTokenOnEachQuery?: boolean;
refreshExpiredAccessToken?: boolean;
onAccessTokenExpire?: Function | undefined;
onAccessTokenRefresh?: Function | undefined;
import BattleNetAPI from './abstract/BattleNetAPI';
import { BattleNetOptions, AccessTokenOptions } from '../../../@interfaces';
interface BlizzAPIOptions extends BattleNetOptions, AccessTokenOptions {
}
export interface BattleNetOptions extends BlizzAPIOptions {
region: RegionIdOrName;
clientId: string;
clientSecret: string;
accessToken?: string;
}
export default class BlizzAPI extends BattleNetAPI {
constructor(options: BattleNetOptions);
readonly options: AccessTokenOptions;
constructor(options: BlizzAPIOptions);
query: (endpoint: string) => Promise<any>;
getAccessToken: () => Promise<string>;
validateAccessToken: (regionIdOrName: string | number, accessToken: string | undefined) => Promise<boolean>;
static getAllRegions: () => Readonly<import("../../../@interfaces").RegionIdProperties<readonly string[]>>;

@@ -35,3 +23,3 @@ static getAllRegionIds: () => readonly number[];

static getAllSc2Realms: () => Readonly<import("../../../@interfaces").RegionIdProperties<readonly number[]>>;
static getAllAvailableSc2Realms: typeof utils.getAllAvailableSc2Realms;
static getAllAvailableSc2Realms: () => readonly number[];
static getSc2RealmsByRegionId: (regionId: string | number) => readonly number[];

@@ -42,2 +30,3 @@ static checkIfSc2RealmLooksValid: (sc2Realm: string | number) => boolean;

}
export {};
//# sourceMappingURL=BlizzAPI.d.ts.map

@@ -17,12 +17,34 @@ "use strict";

};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const helpers = __importStar(require("../helpers"));
const utils = __importStar(require("../utils"));
const BattleNetAPI = require("./abstract/BattleNetAPI");
class BlizzAPI extends BattleNetAPI {
const BattleNetAPI_1 = __importDefault(require("./abstract/BattleNetAPI"));
;
class BlizzAPI extends BattleNetAPI_1.default {
constructor(options) {
super(options.region, options.clientId, options.clientSecret, options.accessToken);
this.query = (endpoint) => __awaiter(this, void 0, void 0, function* () { return helpers.query(this.region, endpoint, yield this.getAccessToken()); });
this.getAccessToken = () => __awaiter(this, void 0, void 0, function* () { return helpers.getAccessToken(this.region, this.clientId, this.clientSecret); });
this.validateAccessToken = (regionIdOrName, accessToken) => __awaiter(this, void 0, void 0, function* () { return helpers.validateAccessToken(regionIdOrName, accessToken); });
super({
region: options.region,
clientId: options.clientId,
clientSecret: options.clientSecret,
accessToken: options.accessToken,
});
this.query = (endpoint) => __awaiter(this, void 0, void 0, function* () {
return helpers.query({
endpoint,
region: this.region,
clientId: this.clientId,
clientSecret: this.clientSecret,
accessToken: yield this.getAccessToken(),
options: Object.assign({}, this.options),
});
});
this.options = {
validateAccessTokenOnEachQuery: options.validateAccessTokenOnEachQuery || false,
refreshExpiredAccessToken: options.refreshExpiredAccessToken || false,
onAccessTokenExpired: options.onAccessTokenExpired || undefined,
onAccessTokenRefresh: options.onAccessTokenRefresh || undefined,
};
}

@@ -29,0 +51,0 @@ }

@@ -1,3 +0,13 @@

declare const _default: (region: string | number, endpoint: string, accessToken: string | undefined) => Promise<any>;
import { RegionIdOrName, AccessToken } from '../../../../@types';
import { AccessTokenOptions } from '../../../../@interfaces';
interface QueryOptions {
region: RegionIdOrName;
endpoint: string;
clientId: string;
clientSecret: string;
accessToken: AccessToken;
options: AccessTokenOptions;
}
declare const _default: (queryOptions: QueryOptions) => Promise<any>;
export default _default;
//# sourceMappingURL=query.d.ts.map
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const validators_1 = require("../validators");
const oauth_1 = require("../oauth");
const api_1 = require("../../utils/api");
const fetch_1 = require("../fetch");
exports.default = (region, endpoint, accessToken) => {
const queryWithAccessToken = (queryOptions, accessToken) => {
const { region, endpoint } = queryOptions;
const validEndpoint = validators_1.endpoint(endpoint);

@@ -15,4 +25,38 @@ if (!validEndpoint)

};
return fetch_1.fetchFromUri(requestUri, 'GET', headers);
return fetch_1.fetchFromUri({
headers,
uri: requestUri,
method: 'GET',
});
};
exports.default = (queryOptions) => __awaiter(this, void 0, void 0, function* () {
const { region, accessToken } = queryOptions;
const { validateAccessTokenOnEachQuery, refreshExpiredAccessToken, onAccessTokenExpired, onAccessTokenRefresh, } = queryOptions.options;
if (validateAccessTokenOnEachQuery) {
const invalidAccessToken = !(yield oauth_1.validateAccessToken(region, accessToken));
if (invalidAccessToken) {
return {
error: 'access_token_invalid',
};
}
}
try {
const data = yield queryWithAccessToken(queryOptions, accessToken);
return data;
}
catch (error) {
if (error.response && error.response.status === 401) {
onAccessTokenExpired && onAccessTokenExpired();
if (refreshExpiredAccessToken) {
const newAccessToken = yield oauth_1.getAccessToken(queryOptions);
onAccessTokenRefresh && onAccessTokenRefresh(newAccessToken);
return queryWithAccessToken(queryOptions, newAccessToken);
}
return Promise.resolve({
error: 'access_token_invalid',
});
}
throw error;
}
});
//# sourceMappingURL=query.js.map

@@ -1,4 +0,10 @@

import { HttpMethod } from '../../../../@types';
declare const _default: (uri: string, method?: HttpMethod, headers?: object | Headers | undefined, params?: URLSearchParams | undefined) => Promise<any>;
import { Uri, HttpMethod } from '../../../../@types';
interface FetchFromUriOptions {
uri: Uri;
method?: HttpMethod;
headers?: object | Headers;
params?: URLSearchParams;
}
declare const _default: (options: FetchFromUriOptions) => Promise<any>;
export default _default;
//# sourceMappingURL=fetchFromUri.d.ts.map

@@ -16,3 +16,5 @@ "use strict";

const validators_1 = require("../validators");
exports.default = (uri, method = 'GET', headers, params) => __awaiter(this, void 0, void 0, function* () {
exports.default = (options) => __awaiter(this, void 0, void 0, function* () {
const { uri } = options;
const method = options.method || 'GET';
try {

@@ -25,6 +27,6 @@ if (!validators_1.uri(uri)) {

};
if (headers)
Object.assign(requestOptions, { headers });
if (options.headers)
Object.assign(requestOptions, { headers: options.headers });
if (method === 'POST')
Object.assign(requestOptions, { params });
Object.assign(requestOptions, { params: options.params });
const response = yield axios_1.default.get(uri, requestOptions);

@@ -31,0 +33,0 @@ return response.data;

@@ -1,3 +0,9 @@

declare const _default: (oauthUri: string, clientId: string, clientSecret: string) => Promise<any>;
import { Uri, ClientId, ClientSecret } from '../../../../@types';
interface FetchAccessTokenOptions {
oauthUri: Uri;
clientId: ClientId;
clientSecret: ClientSecret;
}
declare const _default: (options: FetchAccessTokenOptions) => Promise<any>;
export default _default;
//# sourceMappingURL=fetchAccessToken.d.ts.map

@@ -12,10 +12,16 @@ "use strict";

const fetch_1 = require("../fetch");
exports.default = (oauthUri, clientId, clientSecret) => {
exports.default = (options) => {
const { oauthUri, clientId, clientSecret } = options;
const params = new URLSearchParams();
params.append('grant_type', 'client_credentials');
const headers = {
Authorization: `Basic ${base64.encode(`${clientId}:${clientSecret}`)}`
Authorization: `Basic ${base64.encode(`${clientId}:${clientSecret}`)}`,
};
return fetch_1.fetchFromUri(oauthUri, 'POST', headers, params);
return fetch_1.fetchFromUri({
headers,
params,
uri: oauthUri,
method: 'POST',
});
};
//# sourceMappingURL=fetchAccessToken.js.map

@@ -1,3 +0,9 @@

declare const _default: (region: string | number, clientId: string, clientSecret: string) => Promise<string>;
import { ClientId, ClientSecret, RegionIdOrName } from '../../../../@types';
interface GetAccessTokenOptions {
region: RegionIdOrName;
clientId: ClientId;
clientSecret: ClientSecret;
}
declare const _default: (options: GetAccessTokenOptions) => Promise<string>;
export default _default;
//# sourceMappingURL=getAccessToken.d.ts.map

@@ -16,7 +16,8 @@ "use strict";

const utils_1 = require("../../utils");
exports.default = (region, clientId, clientSecret) => __awaiter(this, void 0, void 0, function* () {
exports.default = (options) => __awaiter(this, void 0, void 0, function* () {
const { region, clientId, clientSecret } = options;
const oauthUri = utils_1.getTokenUriByRegion(region);
const accessTokenObject = yield fetchAccessToken_1.default(oauthUri, clientId, clientSecret);
const accessTokenObject = yield fetchAccessToken_1.default({ oauthUri, clientId, clientSecret });
return accessTokenObject.access_token;
});
//# sourceMappingURL=getAccessToken.js.map

@@ -17,3 +17,3 @@ "use strict";

const requestPath = `${checkTokenUri}${accessToken}`;
const response = yield fetch_1.fetchFromUri(requestPath);
const response = yield fetch_1.fetchFromUri({ uri: requestPath });
return !(response.error && response.error === 'invalid_token');

@@ -20,0 +20,0 @@ }

@@ -11,5 +11,5 @@ "use strict";

const apiHost = common_1.getConstantByRegion(regionIdOrName, 'REGION_API_HOSTS');
return (typeof regionIdOrName === 'string' && regionIdOrName.toLowerCase() === 'kr')
return typeof regionIdOrName === 'string' && regionIdOrName.toLowerCase() === 'kr'
? apiHost[0]
: (typeof regionIdOrName === 'string' && regionIdOrName.toLowerCase() === 'tw')
: typeof regionIdOrName === 'string' && regionIdOrName.toLowerCase() === 'tw'
? apiHost[1]

@@ -16,0 +16,0 @@ : apiHost;

@@ -17,3 +17,3 @@ "use strict";

if (!isRegionIdValid) {
throw new RangeError(`${regionIdAsString} is not a valid parameter for getUriByRegionId(${regionId}, '${constantKey}')`);
throw new RangeError(`${regionIdAsString} is not a valid parameter for getConstantByRegionId(${regionId}, '${constantKey}')`);
}

@@ -20,0 +20,0 @@ return constants_1.default[constantKey][regionIdAsString];

@@ -1,4 +0,3 @@

import { Sc2RealmList } from '../../../../@types';
export declare const getAllSc2Realms: () => Readonly<import("../../../../@interfaces").RegionIdProperties<readonly number[]>>;
export declare function getAllAvailableSc2Realms(): Sc2RealmList;
export declare const getAllAvailableSc2Realms: () => readonly number[];
export declare const getSc2RealmsByRegionId: (regionId: string | number) => readonly number[];

@@ -5,0 +4,0 @@ export declare const checkIfSc2RealmLooksValid: (sc2Realm: string | number) => boolean;

@@ -10,8 +10,7 @@ "use strict";

exports.getAllSc2Realms = () => constants_1.default.SC2_REALMS;
function getAllAvailableSc2Realms() {
exports.getAllAvailableSc2Realms = () => {
const sc2Realms = Object.values(constants_1.default.SC2_REALMS);
const flattenedSc2Realms = [].concat(...sc2Realms);
return flattenedSc2Realms.filter((el, i, a) => i === a.indexOf(el));
}
exports.getAllAvailableSc2Realms = getAllAvailableSc2Realms;
};
exports.getSc2RealmsByRegionId = (regionId) => common_1.getConstantByRegionId(regionId, 'SC2_REALMS');

@@ -29,3 +28,3 @@ exports.checkIfSc2RealmLooksValid = (sc2Realm) => {

}
const sc2RealmList = getAllAvailableSc2Realms();
const sc2RealmList = exports.getAllAvailableSc2Realms();
const sc2RealmAsNumber = typeof sc2Realm === 'number' ? sc2Realm : parseInt(sc2Realm, 10);

@@ -32,0 +31,0 @@ return sc2RealmList.includes(sc2RealmAsNumber);

{
"name": "blizzapi",
"version": "0.1.1",
"description": "Feature-rich library for Blizzard Battle.net API",
"version": "1.0.0",
"description": "Flexible and feature-rich Node.js library for Blizzard Battle.net API",
"homepage": "https://blizzapi.lukem.net",

@@ -45,3 +45,3 @@ "main": "./dist/index.js",

"@types/jest": "24.0.15",
"@types/node": "12.6.2",
"@types/node": "12.6.8",
"jest": "24.8.0",

@@ -48,0 +48,0 @@ "prettier": "1.18.2",

@@ -9,4 +9,48 @@ # BlizzAPI

Feature-rich library for easy access to [Battle.net API](https://develop.battle.net/).
Flexible feature-rich library for easy access to [Battle.net API](https://develop.battle.net/).
Documentation and examples coming soon.
## Install
```bash
npm install blizzapi
```
## Quick start
```javascript
const BlizzAPI = require('blizzapi');
const api = new BlizzAPI({
region: 'us',
clientId: 'client id',
clientSecret: 'client secret'
});
const data = await api.query('/path/to/endpoint');
console.log(data);
```
## Manual build
```bash
git clone https://github.com/lukemnet/blizzapi.git
cd blizzapi
npm install
npm run build
```
## Documentation & examples
* [blizzapi.lukem.net](https://blizzapi.lukem.net) - documentation
* [blizzapi-docs](https://github.com/lukemnet/blizzapi-docs) - documentation repo on GitHub
* [blizzapi-example](https://github.com/lukemnet/blizzapi-example) - sample Express.js REST API with usage examples
## License
Licensed under MIT License. See [LICENSE](https://github.com/lukemnet/tridi/blob/master/LICENSE) for more information.
## Legal
Battle.net and Blizzard Entertainment are trademarks or registered trademarks of Blizzard Entertainment, Inc. in the U.S. and/or other countries.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc