Socket
Socket
Sign inDemoInstall

@vermaysha/hoyolab-api

Package Overview
Dependencies
21
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.3.0 to 2.3.1-beta.0

dist/Cache.d.ts

120

dist/Genshin.d.ts

@@ -1,99 +0,97 @@

import { Base } from './Base';
import * as Interface from './Interfaces/Genshin';
import * as Types from './Types';
import { GenshinOption, Options } from './Interfaces';
import { DiaryMonth, DiaryType, ScheduleType } from './Enum';
/**
* Get data from Hoyolab API
*
* @category Main
*/
export declare class Genshin extends Base {
import { ICookie, LanguageEnum, IRedeemCode } from './Interfaces';
import { DiaryEnum, DiaryMonthEnum, IGenshinCharacterSummary, IGenshinCharacters, IGenshinDailyInfo, IGenshinDailyNote, IGenshinDailyReward, IGenshinDailyRewards, IGenshinDiaryDetail, IGenshinDailyClaim, IGenshinDiaryInfo, IGenshinOptions, IGenshinRecord, IGenshinSpiralAbyss, AbyssScheduleEnum } from './Interfaces/Genshin';
import { Request } from './Request';
export declare class Genshin {
readonly cookie: ICookie;
readonly request: Request;
uid: number | null;
region: string | null;
lang: LanguageEnum;
constructor(options: IGenshinOptions);
/**
* Genshin Impact UID
* Create Genshin Object
*
* @param options IGenshinOptions Options
* @returns {Promise<Genshin>}
*/
protected readonly uid: string | number;
static create(options: IGenshinOptions): Promise<Genshin>;
/**
* Genshin Impact Region
* Fetch game records
*
* @returns {Promise<IGenshinRecord>}
*/
protected readonly region: Types.Region;
records(): Promise<IGenshinRecord>;
/**
* Get Genshin Impact some in-game data through HoYoLab API.
* Fetch obtained genshin characters with artifact, weapon, level and constellation
*
* @param options Options & GenshinOption
* @throws {@link HoyoError} - if given UID or Cookie is invalid
* @returns {Promise<IGenshinCharacters>}
*/
constructor(options: Options & GenshinOption);
getAccountInfo(): Promise<Interface.AccountResponse>;
characters(): Promise<IGenshinCharacters>;
/**
* Get daily check-in event information.
* Fetch characters summary detail (name, rarity, weapon, icon)
*
* @throws {@link HoyoError} - If an error occurs
* @param characterIds number[] Characters ID
* @returns {Promise<IGenshinCharacterSummary>}
*/
getDailyInfo(): Promise<Interface.DailyInfoResponse>;
charactersSummary(characterIds: number[]): Promise<IGenshinCharacterSummary>;
/**
* Get daily check-in event all rewards.
* Fetch Spiral Abyss data
*
* @throws {@link HoyoError} - If an error occurs
* @param scheduleType AbyssScheduleEnum
* @returns {Promise<IGenshinSpiralAbyss>}
*/
getDailyRewards(): Promise<Interface.DailyRewardsResponse>;
spiralAbyss(scheduleType?: AbyssScheduleEnum): Promise<IGenshinSpiralAbyss>;
/**
* Get daily check-in event single rewards.
* Fetch daily note resources (resin, home coin, expeditions, and transformer)
*
* @param day Types.NumericRange<0, 30>
* @throws {@link HoyoError} - If an error occurs
* @returns {Promise<IGenshinDailyNote>}
*/
getDailyReward(day?: Types.NumericRange<0, 30> | null): Promise<Interface.DailyRewardResponse>;
dailyNote(): Promise<IGenshinDailyNote>;
/**
* Claim daily check-in event.
* Fetch genshin impact diary data
*
* @throws {@link HoyoError} - If an error occurs
* @param month
* @returns {Promise<IGenshinDiaryInfo>}
*/
claimDaily(): Promise<Interface.DailyClaimResponse>;
diaries(month?: DiaryMonthEnum): Promise<IGenshinDiaryInfo>;
/**
* Get all the characters owned by the user with complete information,
* such as: constellation, artefact, weapon, and skin.
* Fetch history of received resources (primogems and mora) from diary
*
* @throws {@link HoyoError} - If an error occurs
* @param type DiaryEnum
* @param month DiaryMonthEnum
* @returns {IGenshinDiaryDetail}
*/
getCharacters(): Promise<Interface.CharacterResponse>;
diaryDetail(type: DiaryEnum, month?: DiaryMonthEnum): Promise<IGenshinDiaryDetail>;
/**
* Displays a summary about the selected character.
* Fetch Daily login information
*
* @param characterIds number[]
* @throws {@link HoyoError} - If an error occurs
* @returns {Promise<IGenshinDailyInfo>}
*/
getCharactersInfo(characterIds: number[]): Promise<Interface.CharacterInfoResponse>;
dailyInfo(): Promise<IGenshinDailyInfo>;
/**
* Get daily notes from character,
* such as: resins, expeditions, transformers recovery time.
* Fetch all rewards from daily login
*
* @throws {@link HoyoError} - If an error occurs
* @returns {Promise<IGenshinDailyRewards>}
*/
getDailyNotes(): Promise<Interface.DailyNotesResponse>;
dailyRewards(): Promise<IGenshinDailyRewards>;
/**
* Get diary summary information,
* such as: current month obtained mora or primogems
* Fetch reward from daily login based on day
*
* @param month DiaryMonth
* @throws {@link HoyoError} - If an error occurs
* @param day number | null
* @returns {Promise<IGenshinDailyReward>}
*/
getDiaryInfo(month?: DiaryMonth): Promise<Interface.DiaryInfoResponse>;
dailyReward(day?: number | null): Promise<IGenshinDailyReward>;
/**
* Get detailed diary information,
* such as: primogems history and mora history.
* Claim current reward
*
* @param type DiaryType
* @param month DiaryMonth
* @throws {@link HoyoError} - If an error occurs
* @returns {Promise<IGenshinDailyClaim>}
*/
getDiaryDetail(type: DiaryType, month?: DiaryMonth): Promise<Interface.DiaryDetailResponse>;
dailyClaim(): Promise<IGenshinDailyClaim>;
/**
* Get detailed spiral abyss information,
* such as: characters, max floor, total star, timestamp, etc.
* Redeem Code
*
* @param scheduleType ScheduleType
* @param code string
* @returns {Promise<IRedeemCode>}
*/
getSpiralAbyss(scheduleType?: ScheduleType): Promise<Interface.SpiralAbyssResponse>;
redeemCode(code: string): Promise<Interface.RedeemResponse>;
redeemCode(code: string): Promise<IRedeemCode>;
}

@@ -1,292 +0,347 @@

"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var Genshin_exports = {};
__export(Genshin_exports, {
Genshin: () => Genshin
});
module.exports = __toCommonJS(Genshin_exports);
var import_HoyoError = require("./HoyoError");
var import_Base = require("./Base");
var import_Utils = require("./Utils");
var import_Enum = require("./Enum");
class Genshin extends import_Base.Base {
/**
* Genshin Impact UID
*/
uid;
/**
* Genshin Impact Region
*/
region;
/**
* Get Genshin Impact some in-game data through HoYoLab API.
*
* @param options Options & GenshinOption
* @throws {@link HoyoError} - if given UID or Cookie is invalid
*/
constructor(options) {
super(options);
this.uid = options.uid;
this.region = import_Utils.ServerRegion.determineRegion(options.uid);
}
async getAccountInfo() {
this.request.withDS();
this.request.setParams({
role_id: this.uid,
server: this.region
});
const response = await this.request.send(import_Utils.GenshinRoutes.accountInfo);
return response.data;
}
/**
* Get daily check-in event information.
*
* @throws {@link HoyoError} - If an error occurs
*/
async getDailyInfo() {
const response = await this.request.send(import_Utils.GenshinRoutes.dailyInfo);
return response.data;
}
/**
* Get daily check-in event all rewards.
*
* @throws {@link HoyoError} - If an error occurs
*/
async getDailyRewards() {
const response = await this.request.send(import_Utils.GenshinRoutes.dailyRewards);
return response.data;
}
/**
* Get daily check-in event single rewards.
*
* @param day Types.NumericRange<0, 30>
* @throws {@link HoyoError} - If an error occurs
*/
async getDailyReward(day = null) {
const response = await this.getDailyRewards();
let currentDate = 0;
if (day === null) {
const now = new Date(Number(response.now) * 1e3);
currentDate = now.getDate() - 1;
import { Cookie } from './Cookie';
import { Hoyolab } from './Hoyolab';
import { HoyolabError } from './HoyolabError';
import { GamesEnum } from './Interfaces';
import { DiaryEnum, DiaryMonthEnum, AbyssScheduleEnum, } from './Interfaces/Genshin';
import { Request } from './Request';
import { genshinRegion, parseLang } from './helpers';
import * as Route from './routes';
export class Genshin {
constructor(options) {
/* c8 ignore start */
const cookie = typeof options.cookie === 'string'
? Cookie.parseCookieString(options.cookie)
: options.cookie;
/* c8 ignore stop */
this.cookie = cookie;
if (!options.lang) {
options.lang = parseLang(cookie.mi18nLang);
}
this.request = new Request(Cookie.parseCookie(this.cookie));
this.request.setReferer(Route.GENSHIN_GAME_RECORD_REFERER);
this.request.setLang(options.lang);
/* c8 ignore start */
this.uid = options.uid ?? null;
this.region = this.uid !== null ? genshinRegion(this.uid) : null;
/* c8 ignore stop */
this.lang = options.lang;
}
if (typeof response.awards[day ?? currentDate] !== void 0) {
return {
month: response.month,
now: response.now,
resign: response.resign,
award: response.awards[day ?? currentDate]
};
/**
* Create Genshin Object
*
* @param options IGenshinOptions Options
* @returns {Promise<Genshin>}
*/
static async create(options) {
const instance = new Genshin(options);
if (instance.uid === null) {
const hoyolab = new Hoyolab({
cookie: options.cookie,
});
const game = await hoyolab.gameAccount(GamesEnum.GENSHIN_IMPACT);
const uid = parseInt(game.game_uid);
instance.uid = uid;
instance.region = genshinRegion(uid);
}
return instance;
}
throw new import_HoyoError.HoyoError("The selected day was not found !");
}
/**
* Claim daily check-in event.
*
* @throws {@link HoyoError} - If an error occurs
*/
async claimDaily() {
const response = await this.request.send(import_Utils.GenshinRoutes.dailyClaim, "post");
const info = await this.getDailyInfo();
const reward = await this.getDailyReward();
if (response.retcode === -5003) {
return {
status: "Traveller, you've already checked in today",
code: -5003,
reward,
info
};
/**
* Fetch game records
*
* @returns {Promise<IGenshinRecord>}
*/
async records() {
if (!this.region || !this.uid) {
throw new HoyolabError('UID parameter is missing or failed to be filled');
}
this.request
.setParams({
server: this.region,
role_id: this.uid,
})
.setDs(true);
const res = (await this.request.send(Route.GENSHIN_GAME_RECORD)).data;
return res;
}
if (String(
response.data.code
).toLocaleLowerCase() === "ok" && response.retcode === 0) {
return {
status: response.message,
code: 0,
reward,
info
};
/**
* Fetch obtained genshin characters with artifact, weapon, level and constellation
*
* @returns {Promise<IGenshinCharacters>}
*/
async characters() {
if (!this.region || !this.uid) {
throw new HoyolabError('UID parameter is missing or failed to be filled');
}
this.request
.setBody({
server: this.region,
role_id: this.uid,
})
.setDs(true);
const res = (await this.request.send(Route.GENSHIN_CHARACTERS_LIST, 'POST'))
.data;
return res;
}
return {
status: response.message,
code: response.retcode,
reward: null,
info
};
}
/* c8 ignore stop */
/**
* Get all the characters owned by the user with complete information,
* such as: constellation, artefact, weapon, and skin.
*
* @throws {@link HoyoError} - If an error occurs
*/
async getCharacters() {
this.request.withDS();
this.request.setBody({
role_id: this.uid,
server: this.region
});
const response = await this.request.send(import_Utils.GenshinRoutes.characters, "post");
return response.data;
}
/**
* Displays a summary about the selected character.
*
* @param characterIds number[]
* @throws {@link HoyoError} - If an error occurs
*/
async getCharactersInfo(characterIds) {
this.request.withDS();
this.request.setBody({
character_ids: characterIds,
role_id: this.uid,
server: this.region
});
const response = await this.request.send(
import_Utils.GenshinRoutes.charactersInfo,
"post"
);
return response.data;
}
/**
* Get daily notes from character,
* such as: resins, expeditions, transformers recovery time.
*
* @throws {@link HoyoError} - If an error occurs
*/
async getDailyNotes() {
this.request.setParams({
server: this.region,
role_id: this.uid
});
this.request.withDS();
const response = await this.request.send(import_Utils.GenshinRoutes.dailyNotes);
return response.data;
}
/**
* Get diary summary information,
* such as: current month obtained mora or primogems
*
* @param month DiaryMonth
* @throws {@link HoyoError} - If an error occurs
*/
async getDiaryInfo(month = import_Enum.DiaryMonth.CURRENT) {
if (Object.values(import_Enum.DiaryMonth).includes(month) === false) {
throw new import_HoyoError.HoyoError("The given month parameter is invalid !");
/**
* Fetch characters summary detail (name, rarity, weapon, icon)
*
* @param characterIds number[] Characters ID
* @returns {Promise<IGenshinCharacterSummary>}
*/
async charactersSummary(characterIds) {
if (!this.region || !this.uid) {
throw new HoyolabError('UID parameter is missing or failed to be filled');
}
this.request
.setBody({
character_ids: characterIds,
role_id: this.uid,
server: this.region,
})
.setDs();
const res = (await this.request.send(Route.GENSHIN_CHARACTERS_SUMMARY, 'POST')).data;
return res;
}
this.request.setParams({
region: this.region,
uid: this.uid,
month
});
this.request.withDS();
const response = await this.request.send(import_Utils.GenshinRoutes.diaryInfo);
return response.data;
}
/**
* Get detailed diary information,
* such as: primogems history and mora history.
*
* @param type DiaryType
* @param month DiaryMonth
* @throws {@link HoyoError} - If an error occurs
*/
async getDiaryDetail(type, month = import_Enum.DiaryMonth.CURRENT) {
if (Object.values(import_Enum.DiaryMonth).includes(month) === false) {
throw new import_HoyoError.HoyoError("The given month parameter is invalid !");
/**
* Fetch Spiral Abyss data
*
* @param scheduleType AbyssScheduleEnum
* @returns {Promise<IGenshinSpiralAbyss>}
*/
async spiralAbyss(scheduleType = AbyssScheduleEnum.CURRENT) {
if (!this.region || !this.uid) {
throw new HoyolabError('UID parameter is missing or failed to be filled');
}
if (Object.values(AbyssScheduleEnum).includes(scheduleType) === false) {
throw new HoyolabError('The given scheduleType parameter is invalid !');
}
this.request
.setParams({
server: this.region,
role_id: this.uid,
schedule_type: scheduleType,
})
.setDs();
const res = (await this.request.send(Route.GENSHIN_SPIRAL_ABYSS)).data;
return res;
}
if (Object.values(import_Enum.DiaryType).includes(type) === false) {
throw new import_HoyoError.HoyoError("The given type parameter is invalid !");
/**
* Fetch daily note resources (resin, home coin, expeditions, and transformer)
*
* @returns {Promise<IGenshinDailyNote>}
*/
async dailyNote() {
if (!this.region || !this.uid) {
throw new HoyolabError('UID parameter is missing or failed to be filled');
}
this.request
.setParams({
server: this.region,
role_id: this.uid,
})
.setDs();
const res = (await this.request.send(Route.GENSHIN_DAILY_NOTE)).data;
return res;
}
const responses = [];
let page = 1;
do {
this.request.setParams({
region: this.region,
uid: this.uid,
month,
type,
current_page: page,
page_size: 100
});
this.request.withDS();
const response2 = await this.request.send(import_Utils.GenshinRoutes.diaryDetail);
responses.push(response2.data);
page++;
} while (responses[responses.length - 1].list.length > 0);
const response = responses[0];
if (responses.length > 1) {
responses.forEach((item, i) => {
if (i < 1)
return;
response.current_page = item.current_page;
response.data_month = item.data_month;
response.list = [...response.list, ...item.list];
response.nickname = item.nickname;
response.optional_month = item.optional_month;
response.region = item.region;
response.uid = item.uid;
});
/**
* Fetch genshin impact diary data
*
* @param month
* @returns {Promise<IGenshinDiaryInfo>}
*/
async diaries(month = DiaryMonthEnum.CURRENT) {
if (!this.region || !this.uid) {
throw new HoyolabError('UID parameter is missing or failed to be filled');
}
if (Object.values(DiaryMonthEnum).includes(month) === false) {
throw new HoyolabError('The given month parameter is invalid !');
}
this.request
.setParams({
region: this.region,
uid: this.uid,
month,
})
.setDs();
const res = (await this.request.send(Route.GENSHIN_DIARY)).data;
return res;
}
response.list.sort((a, b) => {
const keyA = new Date(a.time), keyB = new Date(b.time);
if (keyA < keyB)
return -1;
if (keyA > keyB)
return 1;
return 0;
});
return response;
}
/**
* Get detailed spiral abyss information,
* such as: characters, max floor, total star, timestamp, etc.
*
* @param scheduleType ScheduleType
*/
async getSpiralAbyss(scheduleType = import_Enum.ScheduleType.CURRENT) {
if (Object.values(import_Enum.ScheduleType).includes(scheduleType) === false) {
throw new import_HoyoError.HoyoError("The given scheduleType parameter is invalid !");
/**
* Fetch history of received resources (primogems and mora) from diary
*
* @param type DiaryEnum
* @param month DiaryMonthEnum
* @returns {IGenshinDiaryDetail}
*/
async diaryDetail(type, month = DiaryMonthEnum.CURRENT) {
if (!this.region || !this.uid) {
throw new HoyolabError('UID parameter is missing or failed to be filled');
}
if (Object.values(DiaryMonthEnum).includes(month) === false) {
throw new HoyolabError('The given month parameter is invalid !');
}
if (Object.values(DiaryEnum).includes(type) === false) {
throw new HoyolabError('The given type parameter is invalid !');
}
const responses = {};
let page = 1;
let next = true;
do {
this.request
.setParams({
region: this.region,
uid: this.uid,
month,
type,
current_page: page,
page_size: 100,
})
.setDs();
const res = (await (await this.request.send(Route.GENSHIN_DIARY_DETAIL)).data);
responses.uid = res.uid;
responses.region = res.region;
responses.optional_month = res.optional_month;
responses.nickname = res.nickname;
responses.data_month = res.data_month;
responses.current_page = res.current_page;
responses.list = [...(responses.list ?? []), ...res.list];
if (res.list.length < 1) {
next = false;
}
page++;
} while (next);
/* c8 ignore start */
responses.list.sort((a, b) => {
const keyA = new Date(a.time);
const keyB = new Date(b.time);
// Compare the 2 dates
if (keyA < keyB)
return -1;
if (keyA > keyB)
return 1;
return 0;
});
/* c8 ignore stop */
return responses;
}
this.request.setParams({
server: this.region,
role_id: this.uid,
schedule_type: scheduleType
});
this.request.withDS();
const response = await this.request.send(import_Utils.GenshinRoutes.spiralAbyss);
return response.data;
}
async redeemCode(code) {
this.request.setParams({
uid: this.uid.toString().replace(/\uFFFD/g, ""),
region: this.region.replace(/\uFFFD/g, ""),
game_biz: "hk4e_global",
cdkey: code.replace(/\uFFFD/g, ""),
lang: "en",
sLangKey: "en-us"
});
const response = await this.request.send(import_Utils.HoyolabRoutes.redeem);
return response;
}
/**
* Fetch Daily login information
*
* @returns {Promise<IGenshinDailyInfo>}
*/
async dailyInfo() {
this.request
.setParams({
act_id: 'e202102251931481',
lang: this.lang,
})
.setLang(this.lang);
const res = (await this.request.send(Route.GENSHIN_DAILY_INFO)).data;
return res;
}
/**
* Fetch all rewards from daily login
*
* @returns {Promise<IGenshinDailyRewards>}
*/
async dailyRewards() {
this.request
.setParams({
act_id: 'e202102251931481',
lang: this.lang,
})
.setLang(this.lang);
const res = (await this.request.send(Route.GENSHIN_DAILY_REWARD)).data;
return res;
}
/**
* Fetch reward from daily login based on day
*
* @param day number | null
* @returns {Promise<IGenshinDailyReward>}
*/
async dailyReward(day = null) {
const response = await this.dailyRewards();
if (day === null) {
const now = new Date(Number(response.now) * 1000);
day = now.getDate();
}
const date = new Date();
const year = date.getFullYear();
const month = date.getMonth();
const daysInMonth = new Date(year, month + 1, 0).getDate();
if (!(day > 0 && day <= daysInMonth) ||
typeof response.awards[day - 1] === undefined) {
throw new HoyolabError(`${day} is not a valid date in this month.`);
}
return {
month: response.month,
now: response.now,
resign: response.resign,
award: response.awards[day - 1],
};
}
/**
* Claim current reward
*
* @returns {Promise<IGenshinDailyClaim>}
*/
async dailyClaim() {
this.request
.setParams({
act_id: 'e202102251931481',
lang: this.lang,
})
.setLang(this.lang);
const response = await this.request.send(Route.GENSHIN_DAILY_CLAIM, 'POST');
const info = await this.dailyInfo();
const reward = await this.dailyReward();
/* c8 ignore start */
if (response.retcode === -5003) {
return {
status: response.message,
code: -5003,
reward,
info,
};
}
if (String(response.data.code).toLocaleLowerCase() ===
'ok' &&
response.retcode === 0) {
return {
status: response.message,
code: 0,
reward,
info,
};
}
return {
status: response.message,
code: response.retcode,
reward: null,
info,
};
}
/* c8 ignore stop */
/**
* Redeem Code
*
* @param code string
* @returns {Promise<IRedeemCode>}
*/
async redeemCode(code) {
if (!this.region || !this.uid) {
throw new HoyolabError('UID parameter is missing or failed to be filled');
}
this.request.setParams({
uid: this.uid,
region: this.region,
game_biz: 'hk4e_global',
cdkey: code.replace(/\uFFFD/g, ''),
lang: this.lang,
sLangKey: this.lang,
});
const res = await this.request.send(Route.GENSHIN_REDEEM_CODE);
return res;
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Genshin
});

@@ -1,24 +0,23 @@

import { RecordCardResponse, GameListResponse } from './Interfaces/Hoyolab';
import { Base } from './Base';
import { Games } from './Enum';
/**
* Get data from Hoyolab API
*
* @category Main
*/
export declare class Hoyolab extends Base {
import { ICookie, LanguageEnum } from './Interfaces';
import * as Interface from './Interfaces/Hoyolab';
import { Request } from './Request';
export declare class Hoyolab {
readonly cookie: ICookie;
readonly request: Request;
lang: LanguageEnum;
constructor(options: Interface.IHoyolabOptions);
/**
* Displays a list of game accounts from mihoyo that are registered on user accounts
* Get games available accounts
*
* @throws {@link HoyoError} - If the request error caused by this library
* @throws {@link [AxiosError](https://github.com/axios/axios/blob/v1.x/lib/core/AxiosError.js)} - If the error is caused by the server
* @param game GamesEnum Selected Game
* @returns {Promise<Interface.IGame[]>}
*/
getGames(games?: Games): Promise<GameListResponse>;
gamesList(game?: Interface.GamesEnum): Promise<Interface.IGame[]>;
/**
* Displays the Game Record for each registered game
* Select one of highest level game account
*
* @throws {@link HoyoError} - If the request error caused by this library
* @throws {@link [AxiosError](https://github.com/axios/axios/blob/v1.x/lib/core/AxiosError.js)} - If the error is caused by the server
* @param game GameEnum Selected Game
* @returns {Promise<Interface.IGame>}
*/
getRecords(): Promise<RecordCardResponse>;
gameAccount(game: Interface.GamesEnum): Promise<Interface.IGame>;
}

@@ -1,70 +0,63 @@

"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var Hoyolab_exports = {};
__export(Hoyolab_exports, {
Hoyolab: () => Hoyolab
});
module.exports = __toCommonJS(Hoyolab_exports);
var import_HoyoError = require("./HoyoError");
var import_Base = require("./Base");
var import_Utils = require("./Utils");
var import_Enum = require("./Enum");
class Hoyolab extends import_Base.Base {
/**
* Displays a list of game accounts from mihoyo that are registered on user accounts
*
* @throws {@link HoyoError} - If the request error caused by this library
* @throws {@link [AxiosError](https://github.com/axios/axios/blob/v1.x/lib/core/AxiosError.js)} - If the error is caused by the server
*/
async getGames(games = import_Enum.Games.ALL) {
if (Object.values(import_Enum.Games).includes(games) === false) {
throw new import_HoyoError.HoyoError("The given games parameter is invalid !");
import { Cookie } from './Cookie';
import { HoyolabError } from './HoyolabError';
import { Request } from './Request';
import { parseLang } from './helpers';
import { GAMES_ACCOUNT } from './routes';
export class Hoyolab {
constructor(options) {
/* c8 ignore start */
const cookie = typeof options.cookie === 'string'
? Cookie.parseCookieString(options.cookie)
: options.cookie;
/* c8 ignore stop */
this.cookie = cookie;
if (!options.lang) {
options.lang = parseLang(cookie.mi18nLang);
}
this.request = new Request(Cookie.parseCookie(this.cookie));
this.request.setLang(options.lang);
this.lang = options.lang;
}
if (games !== import_Enum.Games.ALL) {
this.request.setParams({
region: games
});
/**
* Get games available accounts
*
* @param game GamesEnum Selected Game
* @returns {Promise<Interface.IGame[]>}
*/
async gamesList(game) {
if (game) {
this.request.setParams({
game_biz: game,
});
}
this.request.setParams({
uid: this.cookie.ltuid,
sLangKey: this.cookie.mi18nLang,
});
const res = await this.request.send(GAMES_ACCOUNT);
const data = res.data;
/* c8 ignore start */
if (!res.data || !data.list) {
throw new HoyolabError('There is no game account on this hoyolab account !');
}
/* c8 ignore stop */
return data.list;
}
const response = await this.request.send(import_Utils.HoyolabRoutes.gamesList);
return response.data;
}
/**
* Displays the Game Record for each registered game
*
* @throws {@link HoyoError} - If the request error caused by this library
* @throws {@link [AxiosError](https://github.com/axios/axios/blob/v1.x/lib/core/AxiosError.js)} - If the error is caused by the server
*/
async getRecords() {
if (!this.cookie.accountId) {
throw new import_HoyoError.HoyoError(
"getRecords() function requires cookie.accountId to be filled !"
);
/**
* Select one of highest level game account
*
* @param game GameEnum Selected Game
* @returns {Promise<Interface.IGame>}
*/
async gameAccount(game) {
const games = await this.gamesList(game);
/* c8 ignore start */
if (games.length < 1) {
throw new HoyolabError('There is no game account on this hoyolab account !');
}
/* c8 ignore stop */
return games.reduce((first, second) => {
return second.level > first.level ? second : first;
});
}
this.request.setParams({
uid: this.cookie.accountId
});
this.request.withDS();
const response = await this.request.send(import_Utils.HoyolabRoutes.recordsList);
return response.data;
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Hoyolab
});

@@ -1,8 +0,10 @@

export * from './HoyoError';
export * as Interface from './Interfaces';
export * as Utils from './Utils';
export * as Types from './Types';
export * as Enum from './Enum';
export * from './Hoyolab';
export * from './Genshin';
export * from './Wiki';
export * from './helpers';
export * from './Request';
export { Cache } from './Cache';
export * from './Interfaces';
export * from './Interfaces/Genshin';
export { Hoyolab } from './Hoyolab';
export * from './HoyolabError';
export { Genshin } from './Genshin';
export * from './Cookie';
export * as Route from './routes';

@@ -1,52 +0,10 @@

"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var src_exports = {};
__export(src_exports, {
Enum: () => Enum,
Interface: () => Interface,
Types: () => Types,
Utils: () => Utils
});
module.exports = __toCommonJS(src_exports);
__reExport(src_exports, require("./HoyoError"), module.exports);
var Interface = __toESM(require("./Interfaces"));
var Utils = __toESM(require("./Utils"));
var Types = __toESM(require("./Types"));
var Enum = __toESM(require("./Enum"));
__reExport(src_exports, require("./Hoyolab"), module.exports);
__reExport(src_exports, require("./Genshin"), module.exports);
__reExport(src_exports, require("./Wiki"), module.exports);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Enum,
Interface,
Types,
Utils
});
export * from './helpers';
export * from './Request';
export { Cache } from './Cache';
export * from './Interfaces';
export * from './Interfaces/Genshin';
export { Hoyolab } from './Hoyolab';
export * from './HoyolabError';
export { Genshin } from './Genshin';
export * from './Cookie';
export * as Route from './routes';

@@ -1,6 +0,9 @@

export * from './Daily';
export * from './Character';
export * from './Diary';
export * from './SpiralAbyss';
export * from './Redeem';
export * from './Account';
export type * from './IGenshinOptions';
export type * from './IGenshinRecord';
export type * from './IGenshinCharacters';
export type * from './IGenshinDailyNote';
export type * from './IGenshinSpiralAbyss';
export type * from './IGenshinDiary';
export type * from './IGenshinDaily';
export * from './AbyssScheduleEnum';
export * from './DiaryEnum';

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

"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var Genshin_exports = {};
module.exports = __toCommonJS(Genshin_exports);
__reExport(Genshin_exports, require("./Daily"), module.exports);
__reExport(Genshin_exports, require("./Character"), module.exports);
__reExport(Genshin_exports, require("./Diary"), module.exports);
__reExport(Genshin_exports, require("./SpiralAbyss"), module.exports);
__reExport(Genshin_exports, require("./Redeem"), module.exports);
__reExport(Genshin_exports, require("./Account"), module.exports);
export * from './AbyssScheduleEnum';
export * from './DiaryEnum';

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

export type { GameListResponse } from './GameListResponse';
export type { RecordCardResponse, RecordCardData, RecordCardListItem, } from './RecordCardResponse';
export type * from './IHoyolabOptions';
export type * from './IGamesList';
export * from './GamesEnum';

@@ -1,16 +0,1 @@

"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var Hoyolab_exports = {};
module.exports = __toCommonJS(Hoyolab_exports);
export * from './GamesEnum';

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

export * from './Options';
export * from './Request';
export type * from './IResponse';
export type * from './ICookie';
export type * from './BodyType';
export type * from './IRedeemCode';
export * from './LanguageEnum';
export * from './Hoyolab';
export * from './Genshin';
export * from './Cookie';
export * from './Wiki';

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

"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var Interfaces_exports = {};
module.exports = __toCommonJS(Interfaces_exports);
__reExport(Interfaces_exports, require("./Options"), module.exports);
__reExport(Interfaces_exports, require("./Request"), module.exports);
__reExport(Interfaces_exports, require("./Hoyolab"), module.exports);
__reExport(Interfaces_exports, require("./Genshin"), module.exports);
__reExport(Interfaces_exports, require("./Cookie"), module.exports);
__reExport(Interfaces_exports, require("./Wiki"), module.exports);
export * from './LanguageEnum';
export * from './Hoyolab';
{
"name": "@vermaysha/hoyolab-api",
"version": "2.3.0",
"version": "2.3.1-beta.0",
"description": "Its unofficial HoYoLab API Wrapper for getting hoyoverse some in-game data, including Genshin Impact, Honkai Impact 3rd.",
"main": "dist/index.js",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"type": "module",
"scripts": {
"format": "prettier src/**/* -w",
"lint": "eslint src/**/* --fix",
"prepare": "husky install",
"build:ts": "rimraf dist/ && tsc --build --listEmittedFiles",
"build:docs": "typedoc",
"build:tsc": "node ./script/build.js && npx tsc --emitDeclarationOnly",
"build": "npm run build:tsc && npm run build:docs",
"format": "prettier src/**/* -w",
"lint": "npx eslint src/**/* --fix",
"test": "NODE_ENV=test jest",
"prepare": "husky install"
"build": "npm run build:docs && npm run build:ts",
"test": "ava",
"test:coverage": "c8 ava"
},

@@ -24,3 +26,8 @@ "repository": {

"hoyoverse",
"api"
"api",
"hoyowiki",
"typescript",
"genshin-impact",
"genshin-api",
"honkai-api"
],

@@ -39,25 +46,43 @@ "author": {

],
"engines": {
"node": ">=14.13"
},
"lint-staged": {
"**/*.(ts,js)": [
"npm run lint",
"npm run format"
]
},
"ava": {
"files": [
"tests/**/*.test.ts"
],
"timeout": "5m",
"extensions": {
"ts": "module"
},
"nodeArguments": [
"--loader=ts-node/esm",
"--experimental-specifier-resolution=node",
"--no-warnings"
]
},
"devDependencies": {
"@jest/globals": "^29.5.0",
"@types/jest": "^29.4.0",
"@types/md5": "^2.3.2",
"@types/node": "^18.14.6",
"@types/eslint": "^8.37.0",
"@types/node": "^18.15.11",
"@types/prettier": "^2.7.2",
"@types/standard-version": "^7.0.1",
"@typescript-eslint/eslint-plugin": "^5.54.1",
"@typescript-eslint/parser": "^5.54.1",
"@typescript-eslint/eslint-plugin": "^5.57.0",
"@typescript-eslint/parser": "^5.57.0",
"ava": "^5.2.0",
"c8": "^7.13.0",
"dotenv": "^16.0.3",
"esbuild": "^0.17.12",
"eslint": "^8.35.0",
"eslint-config-prettier": "^8.7.0",
"eslint-plugin-tsdoc": "^0.2.17",
"fast-glob": "^3.2.12",
"eslint": "^8.37.0",
"eslint-config-prettier": "^8.8.0",
"husky": "^8.0.3",
"jest": "^29.5.0",
"lint-staged": "^13.1.2",
"prettier": "^2.8.4",
"rimraf": "^4.3.1",
"ts-jest": "^29.0.5",
"tsx": "^3.12.3",
"typedoc": "^0.23.26",
"lint-staged": "^13.2.0",
"prettier": "^2.8.7",
"rimraf": "^4.4.1",
"ts-node": "^10.9.1",
"tsx": "^3.12.6",
"typedoc": "^0.23.28",
"typedoc-plugin-coverage": "^2.0.0",

@@ -67,17 +92,7 @@ "typedoc-plugin-extras": "^2.3.2",

"typedoc-plugin-versions": "^0.2.3",
"typescript": "^4.9.5"
"typescript": "^5.0.3"
},
"engines": {
"node": ">=14"
},
"dependencies": {
"axios": "^1.3.4",
"md5": "^2.3.0"
},
"lint-staged": {
"**/*.ts": [
"npm run lint",
"npm run format"
]
"got": "^12.6.0"
}
}
<div align="center">
<h1>HoYoLab API - TypeScript/JavaScript HoYoLab API</h1>
<h1>HoYoLab API - TypeScript/JavaScript HoYoLab API (ESM only)</h1>
<p>
<a href="https://github.com/vermaysha/hoyolab-api/actions/workflows/build.yml">
<img src="https://img.shields.io/github/actions/workflow/status/vermaysha/hoyolab-api/build.yml?branch=master&amp;label=build&amp;style=flat-square" alt="GitHub Build Action Status">
</a>
<a href="https://github.com/vermaysha/hoyolab-api/actions/workflows/test.yml">

@@ -22,3 +19,3 @@ <img src="https://img.shields.io/github/actions/workflow/status/vermaysha/hoyolab-api/test.yml?branch=master&amp;label=test&amp;style=flat-square" alt="GitHub Test Action Status">

<p>
<a href="https://packagist.org/packages/vermaysha/hoyolab-api">
<a href="https://www.npmjs.com/package/@vermaysha/hoyolab-api">
<img src="https://img.shields.io/npm/v/@vermaysha/hoyolab-api.svg?style=flat-square" alt="Latest Version on Packagist">

@@ -44,2 +41,27 @@ </a>

\*Note: _This library only support ESM Mode_
## Features
### HoYoLab API
| Features | Status |
| ----------------------------------------------------------------------------------------------------------- | ------------------ |
| Displays a list of owned HoYoVerse game accounts | :heavy_check_mark: |
| Displays the exploration history of the HoYoVerse game account that is owned according to the selected game | :heavy_check_mark: |
### Genshin Impact API
| Features | Status |
| ----------------------------------------------------------------------------------------------------------------------------------- | ------------------ |
| Get detailed information of the selected account, including character, statistics and exploration history | :heavy_check_mark: |
| Get daily login information on the hoyolab page | :heavy_check_mark: |
| Get prize list information for daily login | :heavy_check_mark: |
| Make claims on daily login rewards | :heavy_check_mark: |
| Gets a full list of acquired characters, including weapons and artifacts used and constellations that have been acquired | :heavy_check_mark: |
| Get a list of daily resources including the daily resin that has been obtained, the status of transformation tools and teapot coins | :heavy_check_mark: |
| Get the history of obtaining primogems and mora through the Diary feature | :heavy_check_mark: |
| Obtain a complete history of the results of the current and previous Spiral Abyss challenge | :heavy_check_mark: |
| Claim the redeem code provided | :heavy_check_mark: |
## How to obtain HoYoLab Cookie

@@ -46,0 +68,0 @@

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