Socket
Socket
Sign inDemoInstall

@vermaysha/hoyolab-api

Package Overview
Dependencies
11
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.1.2 to 3.2.0-beta.0

2310

dist/index.d.ts

@@ -1,65 +0,393 @@

interface IResponse {
retcode: number;
message: string;
data: unknown;
}
/**
* Represents a set of available languages as an enumerated type.
*/
declare enum LanguageEnum {
/**
* Simplified Chinese language code.
*/
SIMPLIFIED_CHINESE = "zh-cn",
/**
* Traditional Chinese language code.
*/
TRADIIONAL_CHINESE = "zh-tw",
/**
* German language code.
*/
GERMAN = "de-de",
/**
* English language code.
*/
ENGLISH = "en-us",
/**
* Spanish language code.
*/
SPANISH = "es-es",
/**
* French language code.
*/
FRENCH = "fr-fr",
/**
* Indonesian language code.
*/
INDONESIAN = "id-id",
/**
* Italian language code.
*/
ITALIAN = "it-it",
/**
* Japanese language code.
*/
JAPANESE = "ja-jp",
/**
* Korean language code.
*/
KOREAN = "ko-kr",
/**
* Portuguese language code.
*/
PORTUGUESE = "pt-pt",
/**
* Russian language code.
*/
RUSSIAN = "ru-ru",
/**
* Thai language code.
*/
THAI = "th-th",
/**
* Turkish language code.
*/
TURKISH = "tr-tr",
/**
* Vietnamese language code.
*/
VIETNAMESE = "vi-vn"
}
/**
* Represents a set of utility methods for working with languages.
*
* @internal
* @category Internal
* @class
*/
declare class Language {
/**
* Parses a language string into its corresponding LanguageEnum value.
*
* @param lang The language string to parse, or null/undefined to default to English.
* @returns The LanguageEnum value corresponding to the provided string, or English if the string is invalid or undefined.
*/
static parseLang(lang?: string | null): LanguageEnum;
}
/**
* Defines the structure of a cookie object.
*
* @interface
*/
interface ICookie {
/**
* The value of the "ltoken" cookie.
*/
ltoken: string;
/**
* The value of the "ltuid" cookie.
*/
ltuid: number;
/**
* The value of the "cookieToken" cookie, if it exists.
*/
cookieToken?: string | null;
/**
* The value of the "accountId" cookie, if it exists.
*/
accountId?: number;
/**
* The value of the "mi18nLang" cookie, if it exists.
* This can be either a string or a LanguageEnum value.
*/
mi18nLang?: LanguageEnum | string | null;
}
type BodyType = {
/**
* Represents a cookie object.
*
* @class
* @category Main
*/
declare class Cookie {
/**
* Parses a cookie string and returns a parsed ICookie object.
*
* @param cookieString - The cookie string to be parsed.
* @returns {string} - A parsed ICookie object.
* @throws {HoyolabError} when ltuid or ltoken keys are not found in the cookie string.
*/
static parseCookieString(cookieString: string): ICookie;
/**
* Converts an `ICookie` object into a cookie string.
* @param {ICookie} cookie - The `ICookie` object to convert.
* @returns {string} A string representing the cookie.
* @throws {HoyolabError} If the `ltuid` or `ltoken` key is missing in the `ICookie` object.
*/
static parseCookie(cookie: ICookie): string;
}
/**
* Represents the base type that can be used for properties in a request body,
* request header, or request parameter.
*/
type BaseType = {
[x: string]: string | number | boolean | null | undefined | string[] | number[] | never[];
};
interface IRedeemCode {
data: string | null;
/**
* Represents the type that can be used for the body of a request.
*/
type RequestBodyType = BaseType;
/**
* Represents the type that can be used for the headers of a request.
*/
type RequestHeaderType = BaseType;
/**
* Represents the type that can be used for the parameters of a request.
*/
type RequestParamType = BaseType;
/**
* Represents the interface for a response from the server.
*/
interface IResponse {
/**
* The status code of the response.
*/
retcode: number;
/**
* A message associated with the response.
*/
message: string;
retcode: number;
/**
* The data returned by the server.
*/
data: unknown;
}
/**
* Class for handling HTTP requests with customizable headers, body, and parameters.
*
* @class
* @internal
* @category Internal
*/
declare class Request {
private headers;
/**
* Body of the request.
*/
private body;
/**
* Query parameters for the request.
*/
private params;
/**
* The cache used for the request
*/
private cache;
/**
* Flag indicating whether Dynamic Security is used.
*/
private ds;
/**
* The number of request attempts made.
*/
private retries;
/**
* Constructor for the Request class.
*
* @param cookies - A string of cookies to be added to the request headers (default: null).
*/
constructor(cookies?: string | null);
/**
* Set Referer Headers
*
* @param url - The URL string of referer
* @returns The updated Request instance.
*/
setReferer(url: string): Request;
/**
* Set Body Parameter
*
* @param body - RequestBodyType as object containing the body parameters.
* @returns This instance of Request object.
*/
setBody(body: RequestBodyType): Request;
/**
* Sets search parameters or query parameter.
*
* @param params - An object of query parameter to be set.
* @returns {Request} - Returns this Request object.
*/
setParams(params: RequestParamType): Request;
/**
* Set to used Dynamic Security or not
*
* @param flag boolean Flag indicating whether to use dynamic security or not (default: true).
* @returns {this} The current Request instance.
*/
setDs(flag?: boolean): Request;
/**
* Set Language
*
* @param lang Language Language that used for return of API (default: Language.ENGLISH).
* @returns {this}
*/
setLang(lang?: LanguageEnum): Request;
/**
* Send the HTTP request.
*
* @param url - The URL to send the request to.
* @param method - The HTTP method to use. Defaults to 'GET'.
* @param ttl - The TTL value for the cached data in seconds.
* @returns A Promise that resolves with the response data, or rejects with a HoyolabError if an error occurs.
* @throws {HoyolabError} if an error occurs rejects with a HoyolabError
*/
send(url: string, method?: 'GET' | 'POST', ttl?: number): Promise<IResponse>;
}
type CacheKey = {
url: string;
params: object;
body: object;
method: string;
};
/**
* Represents a cache object for storing and retrieving data using a key-value pair.
*
* @class
* @internal
* @category Internal
*/
declare class Cache {
/**
* The default time-to-live (TTL) value for cached data in seconds.
*/
private stdTTL;
/**
* The NodeCache instance used to store and retrieve data.
*/
private nodeCache;
/**
* Generates a cache key based on the URL, query parameters, and body of a request.
*
* @param key - The key object containing the URL, query parameters, and body of the request.
* @returns A unique MD5 hash key generated from the key object.
*/
private generateKey;
/**
* Sets a value in the cache with a given key and TTL.
*
* @param key - The key object containing the URL, query parameters, and body of the request.
* @param value - The value to be stored in the cache.
* @param ttl - The TTL value for the cached data in seconds.
* @returns True if the value was successfully stored in the cache, false otherwise.
*/
set(key: CacheKey, value: object, ttl?: number): boolean;
/**
* Retrieves a value from the cache using a given key.
*
* @param key - The key object containing the URL, query parameters, and body of the request.
* @returns The cached value if it exists, null otherwise.
*/
get(key: CacheKey): object | null | undefined;
/**
* Checks if a key exists in the cache.
*
* @param key - The key object containing the URL, query parameters, and body of the request.
* @returns True if the key exists in the cache, false otherwise.
*/
has(key: CacheKey): boolean;
/**
* Deletes a key-value pair from the cache.
*
* @param key - The key object containing the URL, query parameters, and body of the request.
* @returns True if the key-value pair was successfully deleted from the cache, false otherwise.
*/
del(key: CacheKey): number;
}
/**
* Generates a dynamic secret (DS) string for use in the Genshin Impact API.
*
* @returns The generated DS string.
*/
declare function generateDS(): string;
/**
* Delays the execution of the code for a specified number of seconds.
* @param second - The number of seconds to delay.
* @returns A Promise that resolves after the specified number of seconds.
*/
declare function delay(second: number): Promise<void>;
/**
* Represents the options for accessing the Hoyolab API.
*
* @interface
*/
interface IHoyolabOptions {
/**
* Cookie Object
* The cookie used to authenticate the request. This can be either a string or an {@link ICookie} object.
*/
cookie: ICookie | string;
/**
* If this property is filled, it will override the value contained in cookie.mi18nLang
* The language to use for the request. This should be a value of {@link LanguageEnum}.
*/
lang?: LanguageEnum;
}
/**
* Represents a game linked to a Hoyolab account.
*
* @interface
*/
interface IGame {
/**
* The game's business type.
*/
game_biz: string;
/**
* The game's server region.
*/
region: string;
/**
* The game's unique ID.
*/
game_uid: string;
/**
* The game's nickname.
*/
nickname: string;
/**
* The game's level.
*/
level: number;
/**
* Whether the game is currently chosen as the active game.
*/
is_chosen: boolean;
/**
* The name of the game's region.
*/
region_name: string;
/**
* Whether the game is an official miHoYo game.
*/
is_official: boolean;
}
/**
* Represents a list of games linked to a Hoyolab account.
*
* @interface
*/
interface IGamesList {
/**
* The list of games linked to the account. This should be a value of {@link IGame}.
*/
list: IGame[];

@@ -75,204 +403,630 @@ }

/**
* Convert given string to camelCase
* Represents the Hoyolab API client.
*
* @param str string The string or text to convert
* @returns {string}
* @class
* @category Main
*/
declare function toCamelCase(str: string): string;
declare class Hoyolab {
/**
* The parsed ICookie object used to authenticate requests.
*/
readonly cookie: ICookie;
/**
* The underlying `Request` object used to make HTTP requests.
*/
readonly request: Request;
/**
* The language used for API responses.
*/
lang: LanguageEnum;
/**
* Creates a new instance of `Hoyolab`.
*
* @constructor
* @param {IHoyolabOptions} options - The options to initialize the `Hoyolab` instance.
* @throws {HoyolabError} If `ltuid` or `ltoken` keys are missing in the `ICookie` object.
*/
constructor(options: IHoyolabOptions);
/**
* Get the list of games on this Hoyolab account.
*
* @async
* @param {GamesEnum} [game] The optional game for which to retrieve accounts.
* @throws {HoyolabError} Thrown if there are no game accounts on this Hoyolab account.
* @returns {Promise<IGame[]>} The list of games on this Hoyolab account.
*/
gamesList(game?: GamesEnum): Promise<IGame[]>;
/**
* Get the account of a specific game from the games list.
*
* @async
* @param {GamesEnum} game - The game that the account belongs to.
* @throws {HoyolabError} If there is no game account on this hoyolab account.
* @returns {Promise<IGame>} The game account.
*/
gameAccount(game: GamesEnum): Promise<IGame>;
}
/**
* Transform camel case to snake case
*
* @param text string The string or text to convert
* @returns {string}
* Interface for redeeming a code in Genshin Impact.
*/
declare function toSnakeCase(text: string): string;
interface IRedeemCode {
/**
* The data returned from redeeming the code. It can be a string or null.
*/
data: string | null;
/**
* A message describing the result of redeeming the code.
*/
message: string;
/**
* The return code from redeeming the code. A non-zero code indicates an error occurred.
*/
retcode: number;
}
/**
* Get Server Region by UID
* Class representing the Redeem module for Genshin Impact's Hoyolab API.
*
* @param uid number UID
* @returns {string}
* @public
* @internal
* @category Module
*/
declare function getServerRegion(uid: number): string;
declare class RedeemModule {
private request;
private lang;
private game;
private region;
private uid;
/**
* Constructs a new RedeemModule object.
* @param request - The Request object used for making HTTP requests.
* @param lang - The language to use for the API response.
* @param game - The game to redeem the code for.
* @param region - The region of the user's account. If null, the API will use the default region for the game.
* @param uid - The user ID of the account. If null, the API will use the user ID associated with the provided auth cookies.
*/
constructor(request: Request, lang: LanguageEnum, game: GamesEnum, region: string | null, uid: number | null);
/**
* Redeems a code for a specific game and account.
*
* @param code - The code to redeem.
* @returns A promise that resolves to an IRedeemCode object containing information about the redemption status.
* @throws HoyolabError if the API returns an error.
* @remarks
* This method sends a request to the Genshin Impact API to get the daily note information for a user.
* The user's region and UID must be set before calling this method, otherwise an error will be thrown.
*/
claim(code: string): Promise<IRedeemCode>;
}
/**
* Parse string to LanguageEnum
*
* @param lang string | null
* @returns {LanguageEnum}
* Interface representing a daily award item.
*/
declare function parseLang(lang?: string | null): LanguageEnum;
declare class Request {
private headers;
private body;
private params;
private cache;
private ds;
constructor(cookies?: string | null);
interface IDailyAwardItem {
/**
* Set Referer Headers
*
* @param url string URL string of referer
* @returns {this}
* The icon of the award item.
*/
setReferer(url: string): this;
icon: string;
/**
* Set Body Paramter
*
* @param body Body Body Parameters as object
* @returns {this}
* The name of the award item.
*/
setBody(body: BodyType): this;
name: string;
/**
* Set SearchParams or query parameter
*
* @param params BodyType Object of query parameter
* @returns {this}
* The count of the award item.
*/
setParams(params: BodyType): this;
cnt: number;
}
/**
* Interface representing a daily information .
*/
interface IDailyInfo {
/**
* Set to used Dynamic Security or not
* The total number of days the user has signed in.
*/
total_sign_day: number;
/**
* The current date in YYYY-MM-DD format.
*/
today: string;
/**
* Whether the user has signed in today.
*/
is_sign: boolean;
/**
* Whether this is the user's first time signing in.
*/
first_bind: boolean;
/**
* Whether the user has subscribed to the game.
*/
is_sub: boolean;
/**
* The region of the user's game account.
*/
region: string;
/**
* Whether today is the last day of the current month.
*/
month_last_day: boolean;
short_sign_day: number;
sign_cnt_missed: number;
}
/**
* An object describing a daily reward.
*/
interface IDailyReward {
/**
* The month number in which the reward is available.
*/
month: number;
/**
* Whether the user can resign for the reward.
*/
resign: boolean;
/**
* The current date in string format.
*/
now: string;
/**
* The business code of the reward.
*/
biz: string;
/**
* The award item associated with the reward.
*/
award: IDailyAwardItem;
}
/**
* Represents daily rewards for a specific month.
*/
interface IDailyRewards {
/**
* Represents daily rewards for a specific month.
*/
month: number;
/**
* Represents daily rewards for a specific month.
*/
resign: boolean;
/**
* The date of the reward in miliseconds.
*/
now: string;
/**
* The business name associated with the reward.
*/
biz: string;
/**
* An array of daily award items.
*/
awards: IDailyAwardItem[];
}
/**
* Interface representing the response data for claiming daily rewards.
*/
interface IDailyClaim {
/** The status of the claim request. */
status: string;
/** The response code for the claim request. */
code: number;
/** The claimed reward, if any. */
reward: IDailyReward | null;
/** Information about the user's daily claim status. */
info: IDailyInfo;
}
/**
* DailyModule class provides methods to interact with Genshin Impact's daily module endpoints.
*
* @class
* @internal
* @category Module
*/
declare class DailyModule {
private request;
private lang;
private game;
private dailyInfoUrl;
private dailyRewardUrl;
private dailySignUrl;
constructor(request: Request, lang: LanguageEnum, game: GamesEnum);
/**
* Retrieves daily information.
*
* @param flag boolean Flag
* @returns {this}
* @returns {Promise<IDailyInfo>} A promise that resolves to an IDailyInfo object.
*/
setDs(flag?: boolean): this;
info(): Promise<IDailyInfo>;
/**
* Set Language
* Retrieve daily rewards information.
*
* @param lang Language Language that used for return of API (default: Language.ENGLISH).
* @returns {this}
* @returns {Promise<IDailyRewards>} A promise that resolves to an IDailyRewards object.
*/
setLang(lang?: LanguageEnum): this;
rewards(): Promise<IDailyRewards>;
/**
* Send Request
* Get the daily reward for a specific day or the current day
*
* @param url string URL String
* @param method GET|POST Method for request
* @returns {Promise<IResponse>}
* @param {number | null} day - The day to retrieve the reward for. If null, retrieve the reward for the current day.
* @returns {Promise<IDailyReward>} - A promise that resolves with the daily reward for the specified day or the current day
* @throws {HoyolabError} - If the specified day is not a valid date in the current month or if the reward for the specified day is undefined.
*/
send(url: string, method?: 'GET' | 'POST'): Promise<IResponse>;
reward(day?: number | null): Promise<IDailyReward>;
/**
* Generate Dynamic Security
* Claim the daily rewards.
*
* @returns {string}
* @returns {Promise<IDailyClaim>} The claim information.
*/
private generateDS;
claim(): Promise<IDailyClaim>;
}
declare class Cache<K, V> extends Map<K, V> {
/**
* Enum for diary months.
* @readonly
* @enum {number}
*/
declare enum DiaryMonthEnum {
/**
* Current month
*/
CURRENT = 3,
/**
* One month ago
*/
ONE_MONTH_AGO = 2,
/**
* Two months ago
*/
TWO_MONTH_AGO = 1
}
interface IGenshinOptions extends IHoyolabOptions {
uid?: number;
/**
* Enum for diary rewards.
* @readonly
* @enum {number}
*/
declare enum DiaryEnum {
/**
* Primogems reward
*/
PRIMOGEMS = 1,
/**
* Mora reward
*/
MORA = 2
}
interface IGenshinRecordAvatar {
id: number;
image: string;
name: string;
element: string;
fetter: number;
level: number;
rarity: number;
actived_constellation_num: number;
card_image: string;
is_chosen: boolean;
/**
* Interface representing the base structure of a Genshin diary.
*/
interface IGenshinDiaryBase {
/**
* The unique identifier of the diary.
*/
uid: number;
/**
* The region of the diary.
*/
region: string;
/**
* The nickname associated with the diary.
*/
nickname: string;
/**
* An array of optional months for the diary.
*/
optional_month: number[];
/**
* The current month's data for the diary.
*/
data_month: number;
}
interface IGenshinRecordStat {
active_day_number: number;
achievement_number: number;
anemoculus_number: number;
geoculus_number: number;
avatar_number: number;
way_point_number: number;
domain_number: number;
spiral_abyss: string;
precious_chest_number: number;
luxurious_chest_number: number;
exquisite_chest_number: number;
common_chest_number: number;
electroculus_number: number;
magic_chest_number: number;
dendroculus_number: number;
/**
* Interface representing additional information for a Genshin diary.
* @extends {IGenshinDiaryBase}
*/
interface IGenshinDiaryInfo extends IGenshinDiaryBase {
/**
* The month of the diary.
*/
month: number;
/**
* The data for the current month.
*/
month_data: {
/**
* The current number of primogems.
*/
current_primogems: number;
/**
* The current amount of mora.
*/
current_mora: number;
/**
* The number of primogems from last month.
*/
last_primogems: number;
/**
* The amount of mora from last month.
*/
last_mora: number;
/**
* The rate of primogems earned.
*/
primogem_rate: number;
/**
* The rate of mora earned.
*/
mora_rate: number;
/**
* An array of grouped actions.
*/
group_by: {
/**
* The action ID.
*/
action_id: number;
/**
* The action name.
*/
action: string;
/**
* The number of actions performed.
*/
num: number;
/**
* The percentage of actions performed.
*/
percent: number;
}[];
};
/**
* The data for the current day.
*/
day_data: {
/**
* The current number of primogems.
*/
current_primogems: number;
/**
* The current amount of mora.
*/
current_mora: number;
};
}
interface IGenshinRecordWorldExploration {
level: number;
exploration_percentage: number;
icon: string;
name: string;
type: string;
offerings: {
name: string;
level: number;
icon: string;
}[];
id: number;
parent_id: number;
map_url: string;
strategy_url: string;
background_image: string;
inner_icon: string;
cover: string;
/**
* Interface representing the history of a Genshin diary.
*/
interface IGenshinDiaryHistory {
/**
* The ID of the action.
*/
action_id: number;
/**
* The name of the action.
*/
action: string;
/**
* The time the action was performed.
*/
time: string;
/**
* The number of times the action was performed.
*/
num: number;
}
interface IGenshinRecordHome {
level: number;
visit_num: number;
comfort_num: number;
item_num: number;
name: string;
icon: string;
comfort_level_name: string;
comfort_level_icon: string;
/**
* Interface representing detailed information for a Genshin diary.
* @extends {IGenshinDiaryBase}
*/
interface IGenshinDiaryDetail extends IGenshinDiaryBase {
/**
* The current page of the diary.
*/
current_page: number;
/**
* An array of history objects.
*/
list: IGenshinDiaryHistory[];
}
interface IGenshinRecord {
role: {
AvatarUrl: string;
nickname: string;
region: string;
level: number;
};
avatars: IGenshinRecordAvatar[];
stats: IGenshinRecordStat;
world_explorations: IGenshinRecordWorldExploration[];
homes: IGenshinRecordHome[];
city_explorations: unknown[];
/**
* A module to interact with the Genshin Impact diary endpoints of the Hoyolab API
*
* @public
* @internal
* @category Module
*/
declare class DiaryModule {
private request;
private lang;
private region;
private uid;
/**
* Constructs a DiaryModule instance
*
* @param request - An instance of the Request class to make HTTP requests
* @param lang - A LanguageEnum value for the language of the user
* @param region - A string value for the region of the user
* @param uid - A number value for the UID of the user
*/
constructor(request: Request, lang: LanguageEnum, region: string | null, uid: number | null);
/**
* Returns the diary information of a given month for a user
*
* @param month - A DiaryMonthEnum value for the month of the diary information requested. Default is CURRENT.
* @returns A promise that resolves to an IGenshinDiaryInfo object
* @throws {@link HoyolabError} when the uid or region parameter is missing or invalid
* @remarks
* This method sends a request to the Genshin Impact API to get the daily note information for a user.
* The user's region and UID must be set before calling this method, otherwise an error will be thrown.
*/
diaries(month?: DiaryMonthEnum): Promise<IGenshinDiaryInfo>;
/**
* Returns the diary details of a given type and month for a user
*
* @param type - A DiaryEnum value for the type of diary details requested
* @param month - A DiaryMonthEnum value for the month of the diary details requested. Default is CURRENT.
* @returns A promise that resolves to an IGenshinDiaryDetail object
* @throws {@link HoyolabError} when the uid or region parameter is missing or invalid, or when the type or month parameter is invalid
* @remarks
* This method sends a request to the Genshin Impact API to get the daily note information for a user.
* The user's region and UID must be set before calling this method, otherwise an error will be thrown.
*/
detail(type: DiaryEnum, month?: DiaryMonthEnum): Promise<IGenshinDiaryDetail>;
}
/**
* An enum representing the schedule type for Abyss.
* @readonly
* @enum {number}
*/
declare enum AbyssScheduleEnum {
/**
* The current schedule.
*/
CURRENT = 1,
/**
* The previous schedule.
*/
PREVIOUS = 2
}
/**
* The interface for Genshin Impact character weapon information.
*/
interface IGenshinCharacterWeapon {
/**
* The ID of the weapon.
*/
id: number;
/**
* The name of the weapon.
*/
name: string;
/**
* The icon of the weapon.
*/
icon: string;
/**
* The type of the weapon.
*/
type: number;
/**
* The rarity level of the weapon.
*/
rarity: number;
/**
* The level of the weapon.
*/
level: number;
/**
* The promote level of the weapon.
*/
promote_level: number;
/**
* The type name of the weapon.
*/
type_name: string;
/**
* The description of the weapon.
*/
desc: string;
/**
* The affix level of the weapon.
*/
affix_level: number;
}
/**
* Represents a set of reliquaries that can be equipped by a character in Genshin Impact.
*/
interface IGenshinCharacterReliquariesSet {
/**
* The unique identifier of the reliquary set.
*/
id: number;
/**
* The name of the reliquary set.
*/
name: string;
/**
* The affixes of the reliquary set.
*/
affixes: IGenshinCharacterReliquariesAffix[];
}
/**
* Represents a single reliquary that can be equipped by a character in Genshin Impact.
*/
interface IGenshinCharacterReliquaries {
/**
* The unique identifier of the reliquary.
*/
id: number;
/**
* The name of the reliquary.
*/
name: string;
/**
* The icon of the reliquary.
*/
icon: string;
/**
* The position of the reliquary.
*/
pos: number;
/**
* The rarity of the reliquary.
*/
rarity: number;
/**
* The level of the reliquary.
*/
level: number;
/**
* The set of the reliquary.
*/
set: IGenshinCharacterReliquariesSet;
/**
* The name of the position of the reliquary.
*/
pos_name: string;
}
/**
* Represents a single affix of a reliquary set in the Genshin Impact game.
*/
interface IGenshinCharacterReliquariesAffix {
/**
* The activation number of the affix.
*/
activation_number: number;
/**
* The effect of the affix.
*/
effect: string;
}
/**
* Defines the shape of a Genshin Impact character constellation object.
*/
interface IGenshinCharacterConstellation {
/**
* The unique identifier of the constellation.
*/
id: number;
/**
* The name of the constellation.
*/
name: string;
/**
* The icon of the constellation.
*/
icon: string;
/**
* The effect of the constellation.
*/
effect: string;
/**
* Whether the constellation is activated.
*/
is_actived: boolean;
/**
* The position of the constellation.
*/
pos: number;

@@ -285,33 +1039,124 @@ }

}
/**
* Represents the base information of a Genshin Impact character.
*/
interface IGenshinCharacterBase {
/**
* The character ID.
*/
id: number;
/**
* The URL of the character's full image.
*/
image: string;
/**
* The URL of the character's icon.
*/
icon: string;
/**
* The name of the character.
*/
name: string;
/**
* The element of the character.
*/
element: string;
/**
* The rarity of the character.
*/
rarity: number;
}
/**
* This interface extends the IGenshinCharacterBase interface and defines an object
* representing a fully detailed character avatar in the Genshin Impact game,
* including additional properties such as the character's current level,
* equipped weapon, constellations, and costumes.
*/
interface IGenshinCharacterAvatarFull extends IGenshinCharacterBase {
/**
* The current fetter of the character
*/
fetter: number;
/**
* The current level of the character
*/
level: number;
/**
* The equipped weapon of the character
*/
weapon: IGenshinCharacterWeapon;
/**
* The list of reliquaries equipped by the character, if any
*/
reliquaries: IGenshinCharacterReliquaries[] | [];
/**
* The list of constellations of the character
*/
constellations: IGenshinCharacterConstellation[];
/**
* The number of activated constellations of the character
*/
actived_constellation_num: number;
/**
* The list of costumes of the character, if any
*/
costumes: IGenshinCharacterCostume[] | [];
/**
* An external property that can hold any type of data or null
*/
external: unknown | null;
}
/**
* Represents a character role in Genshin Impact.
*/
interface IGenshinCharacterRole {
/**
* The URL of the avatar image of the character role.
*/
AvatarUrl: string;
/**
* The nickname of the character role.
*/
nickname: string;
/**
* The region of the character role.
*/
region: string;
/**
* The level of the character role.
*/
level: number;
}
/**
* Represents a collection of Genshin Impact characters and user information
*/
interface IGenshinCharacters {
/**
* List of Genshin Impact characters
*/
avatars: IGenshinCharacterAvatarFull[];
/**
* User information associated with the characters
*/
role: IGenshinCharacterRole;
}
/**
* Interface for a summary of Genshin Impact characters, containing only basic information and weapon type.
*/
interface IGenshinCharacterSummary {
avatars: Array<IGenshinCharacterBase & {
/**
* An array of characters, containing basic information and weapon type.
*/
avatars: Array<
/**
* Basic information of a Genshin Impact character.
*/
IGenshinCharacterBase & {
/**
* The type of weapon used by the character.
*/
weapon_type: number;
/**
* The name of the weapon type used by the character.
*/
weapon_type_name: string;

@@ -321,33 +1166,123 @@ }>;

/**
* Interface for Genshin Impact daily note.
*/
interface IGenshinDailyNote {
/**
* Current resin.
*/
current_resin: number;
/**
* Maximum resin.
*/
max_resin: number;
/**
* Resin recovery time.
*/
resin_recovery_time: string;
/**
* Number of finished tasks.
*/
finished_task_num: number;
/**
* Total number of tasks.
*/
total_task_num: number;
/**
* Whether extra task reward is received or not.
*/
is_extra_task_reward_received: boolean;
/**
* Remaining resin discount number.
*/
remain_resin_discount_num: number;
/**
* Maximum resin discount number.
*/
resin_discount_num_limit: number;
/**
* Current expedition number.
*/
current_expedition_num: number;
/**
* Maximum expedition number.
*/
max_expedition_num: number;
/**
* List of expeditions.
*/
expeditions: {
/**
* Avatar side icon.
*/
avatar_side_icon: string;
/**
* Expedition status.
*/
status: 'Finished' | 'Ongoing';
/**
* Remaining time of the expedition.
*/
remained_time: string;
}[];
/**
* Current home coin.
*/
current_home_coin: number;
/**
* Maximum home coin.
*/
max_home_coin: number;
/**
* Home coin recovery time.
*/
home_coin_recovery_time: string;
/**
* URL of calendar.
*/
calendar_url: string;
/**
* Transformer information.
*/
transformer: {
/**
* Whether it is obtained or not.
*/
obtained: boolean;
/**
* Recovery time.
*/
recovery_time: {
/**
* Days.
*/
Day: number;
/**
* Hours.
*/
Hour: number;
/**
* Minutes.
*/
Minute: number;
/**
* Seconds.
*/
Second: number;
/**
* Whether recovery time is reached or not.
*/
reached: boolean;
};
/**
* URL of the wiki page.
*/
wiki: string;
/**
* Whether it is noticed or not.
*/
noticed: boolean;
/**
* Latest job ID.
*/
latest_job_id: string;

@@ -357,257 +1292,700 @@ };

/**
* Interface representing a Genshin Impact character's avatar data as recorded in the player's game data.
*/
interface IGenshinRecordAvatar {
/**
* The ID of the avatar.
*/
id: number;
/**
* The URL for the avatar's image.
*/
image: string;
/**
* The name of the avatar.
*/
name: string;
/**
* The element associated with the avatar.
*/
element: string;
/**
* The number of fetters unlocked for the avatar.
*/
fetter: number;
/**
* The level of the avatar.
*/
level: number;
/**
* The rarity of the avatar.
*/
rarity: number;
/**
* The number of constellations unlocked for the avatar.
*/
actived_constellation_num: number;
/**
* The URL for the avatar's card image.
*/
card_image: string;
/**
* Whether the avatar has been chosen as the player's current character.
*/
is_chosen: boolean;
}
/**
* Represents the statistics of a player's Genshin Impact game record.
*/
interface IGenshinRecordStat {
/**
* The number of days the player has been actively playing.
*/
active_day_number: number;
/**
* The number of achievements the player has unlocked.
*/
achievement_number: number;
/**
* The number of Anemoculi the player has found.
*/
anemoculus_number: number;
/**
* The number of Geoculi the player has found.
*/
geoculus_number: number;
/**
* The number of characters the player has obtained.
*/
avatar_number: number;
/**
* The number of waypoints the player has unlocked.
*/
way_point_number: number;
/**
* The number of domains the player has unlocked.
*/
domain_number: number;
/**
* The player's current Spiral Abyss progress.
*/
spiral_abyss: string;
/**
* The number of Precious Chests the player has opened.
*/
precious_chest_number: number;
/**
* The number of Luxurious Chests the player has opened.
*/
luxurious_chest_number: number;
/**
* The number of Exquisite Chests the player has opened.
*/
exquisite_chest_number: number;
/**
* The number of Common Chests the player has opened.
*/
common_chest_number: number;
/**
* The number of Electroculi the player has found.
*/
electroculus_number: number;
/**
* The number of Magic Chests the player has opened.
*/
magic_chest_number: number;
/**
* The number of Dendroculi the player has found.
*/
dendroculus_number: number;
}
/**
* Represents the world exploration record of a player in Genshin Impact.
* @interface
*/
interface IGenshinRecordWorldExploration {
/**
* The current level of world exploration. */
level: number;
/**
* The percentage of world exploration completion. */
exploration_percentage: number;
/**
* The URL of the icon representing the exploration region. */
icon: string;
/**
* The name of the exploration region. */
name: string;
/**
* The type of the exploration region. */
type: string;
/**
* An array of offerings available in the exploration region.
* @property {string} name - The name of the offering.
* @property {number} level - The level requirement of the offering.
* @property {string} icon - The URL of the icon representing the offering.
* */
offerings: {
name: string;
level: number;
icon: string;
}[];
/**
* The ID of the exploration region. */
id: number;
/**
* The parent ID of the exploration region. */
parent_id: number;
/**
* The URL of the map of the exploration region. */
map_url: string;
/**
* The URL of the strategy guide of the exploration region. */
strategy_url: string;
/**
* The URL of the background image of the exploration region. */
background_image: string;
/**
* The URL of the inner icon of the exploration region. */
inner_icon: string;
/**
* The URL of the cover image of the exploration region. */
cover: string;
}
/**
* Interface representing Genshin Impact player's home record information.
*/
interface IGenshinRecordHome {
/**
* The level of the player's home.
*/
level: number;
/**
* The number of times the player has visited their home.
*/
visit_num: number;
/**
* The comfort level of the player's home.
*/
comfort_num: number;
/**
* The number of items the player has placed in their home.
*/
item_num: number;
/**
* The name of the player's home.
*/
name: string;
/**
* The URL of the icon representing the player's home.
*/
icon: string;
/**
* The name of the comfort level of the player's home.
*/
comfort_level_name: string;
/**
* The URL of the icon representing the comfort level of the player's home.
*/
comfort_level_icon: string;
}
/**
* Interface representing a Genshin Impact player record.
*/
interface IGenshinRecord {
/**
* An object containing player role information.
*/
role: {
/**
* The URL of the player's avatar image.
*/
AvatarUrl: string;
/**
* The player's nickname.
*/
nickname: string;
/**
* The region of the player's game account.
*/
region: string;
/**
* The player's level.
*/
level: number;
};
/**
* An array of the player's avatars.
*/
avatars: IGenshinRecordAvatar[];
/**
* An object containing the player's statistics.
*/
stats: IGenshinRecordStat;
/**
* An array of the player's world explorations.
*/
world_explorations: IGenshinRecordWorldExploration[];
/**
* An array of the player's homes.
*/
homes: IGenshinRecordHome[];
/**
* An array of the player's city explorations.
* The structure of this array is not specified.
*/
city_explorations: unknown[];
}
/**
* Represents an avatar rank in the Spiral Abyss event in Genshin Impact.
*/
interface IGenshinSpiralAbyssRank {
/**
* The ID of the avatar.
*/
avatar_id: number;
/**
* The icon of the avatar.
*/
avatar_icon: string;
/**
* The rank value of the avatar.
*/
value: number;
/**
* The rarity of the avatar.
*/
rarity: number;
}
/**
* Represents an avatar in the Spiral Abyss event in Genshin Impact.
*/
interface IGenshinSpiralAbyssAvatar {
/**
* The ID of the avatar.
*/
id: number;
/**
* The icon of the avatar.
*/
icon: string;
/**
* The level of the avatar.
*/
level: number;
/**
* The rarity of the avatar.
*/
rarity: number;
}
/**
* Represents a battle in the Spiral Abyss event in Genshin Impact.
*/
interface IGenshinSpiralAbyssBattle {
/**
* The index of the battle.
*/
index: number;
/**
* The timestamp of the battle.
*/
timestamp: string;
/**
* The avatars involved in the battle.
*/
avatars: IGenshinSpiralAbyssAvatar[];
}
/**
* Represents a level in the Spiral Abyss event in Genshin Impact.
*/
interface IGenshinSpiralAbyssLevel {
/**
* The index of the level.
*/
index: number;
/**
* The star rating of the level.
*/
star: number;
/**
* The maximum star rating of the level.
*/
max_star: number;
/**
* The battles that occurred in the level.
*/
battles: IGenshinSpiralAbyssBattle[];
}
/**
* Represents the floor of the Spiral Abyss in Genshin Impact.
*/
interface IGenshinSpiralAbyssFloor {
/**
* The floor index.
*/
index: number;
/**
* The icon of the floor.
*/
icon: string;
/**
* Whether the floor is unlocked.
*/
is_unlock: boolean;
/**
* The time when the floor was completed and settled.
*/
settle_time: string;
/**
* The number of stars obtained in the floor.
*/
star: number;
/**
* The maximum number of stars that can be obtained in the floor.
*/
max_star: number;
/**
* The levels in the floor.
*/
levels: IGenshinSpiralAbyssLevel[];
}
/**
* Represents the Spiral Abyss in Genshin Impact.
*/
interface IGenshinSpiralAbyss {
/**
* The ID of the Spiral Abyss schedule.
*/
schedule_id: number;
/**
* The start time of the Spiral Abyss.
*/
start_time: string;
/**
* The end time of the Spiral Abyss.
*/
end_time: string;
/**
* The total number of battles fought in the Spiral Abyss.
*/
total_battle_times: number;
/**
* The total number of battles won in the Spiral Abyss.
*/
total_win_times: number;
/**
* The maximum floor reached in the Spiral Abyss.
*/
max_floor: string;
/**
* The rankings for revealing the floor in the Spiral Abyss.
*/
reveal_rank: IGenshinSpiralAbyssRank[];
/**
* The rankings for defeating the monsters in the Spiral Abyss.
*/
defeat_rank: IGenshinSpiralAbyssRank[];
/**
* The rankings for damage dealt in the Spiral Abyss.
*/
damage_rank: IGenshinSpiralAbyssRank[];
/**
* The rankings for taking damage in the Spiral Abyss.
*/
take_damage_rank: IGenshinSpiralAbyssRank[];
/**
* The rankings for using normal skills in the Spiral Abyss.
*/
normal_skill_rank: IGenshinSpiralAbyssRank[];
/**
* The rankings for using elemental burst skills in the Spiral Abyss.
*/
energy_skill_rank: IGenshinSpiralAbyssRank[];
/**
* The floors in the Spiral Abyss.
*/
floors: IGenshinSpiralAbyssFloor[];
/**
* The total number of stars obtained in the Spiral Abyss.
*/
total_star: number;
/**
* Whether the Spiral Abyss is unlocked.
*/
is_unlock: boolean;
}
interface IGenshinDiaryBase {
uid: number;
region: string;
nickname: string;
optional_month: number[];
data_month: number;
/**
* RecordModule class provides methods to interact with Genshin Impact's record module endpoints.
*
* @class
* @internal
* @category Module
*/
declare class RecordModule {
private request;
private lang;
private region;
private uid;
/**
* Creates an instance of RecordModule.
*
* @constructor
* @param {Request} request - An instance of Request class.
* @param {LanguageEnum} lang - The language code to be used in requests.
* @param {string | null} region - The server region code in which the user's account resides.
* @param {number | null} uid - The user ID of the Genshin Impact account.
*/
constructor(request: Request, lang: LanguageEnum, region: string | null, uid: number | null);
/**
* Get user's Genshin Impact record
*
* @async
* @function
* @returns {Promise<IGenshinRecord>} - User's Genshin Impact record
* @throws {HoyolabError} If UID parameter is missing or failed to be filled
* @remarks
* This method sends a request to the Genshin Impact API to get the daily note information for a user.
* The user's region and UID must be set before calling this method, otherwise an error will be thrown.
*/
records(): Promise<IGenshinRecord>;
/**
*
* Retrieves the Genshin characters of the user.
*
* @async
* @returns {Promise<IGenshinCharacters>} A Promise that contains the Genshin characters object.
* @throws {HoyolabError} If UID parameter is missing or failed to be filled.
* @remarks
* This method sends a request to the Genshin Impact API to get the daily note information for a user.
* The user's region and UID must be set before calling this method, otherwise an error will be thrown.
*/
characters(): Promise<IGenshinCharacters>;
/**
* Returns the summary information of Genshin Impact game characters.
*
* @param characterIds - An array of character IDs to retrieve the summary information for.
* @returns A Promise that resolves to an object containing the summary information of the characters.
* @throws Throws an error if the UID parameter is missing or failed to be filled.
* @remarks
* This method sends a request to the Genshin Impact API to get the daily note information for a user.
* The user's region and UID must be set before calling this method, otherwise an error will be thrown.
*/
charactersSummary(characterIds: number[]): Promise<IGenshinCharacterSummary>;
/**
* Retrieves information about the player's performance in the Spiral Abyss.
*
* @param scheduleType - The schedule type of the Abyss, either CURRENT or PREVIOUS.
* @returns A Promise that resolves with an object containing the player's Spiral Abyss data.
* @throws HoyolabError if UID parameter is missing or failed to be filled, or if the given scheduleType parameter is invalid.
* @remarks
* This method sends a request to the Genshin Impact API to get the daily note information for a user.
* The user's region and UID must be set before calling this method, otherwise an error will be thrown.
*/
spiralAbyss(scheduleType?: AbyssScheduleEnum): Promise<IGenshinSpiralAbyss>;
/**
* Retrieve the daily note information for a Genshin Impact user.
* @returns Promise<IGenshinDailyNote> The daily note information.
* @throws HoyolabError if the UID parameter is missing or failed to be filled.
* @remarks
* This method sends a request to the Genshin Impact API to get the daily note information for a user.
* The user's region and UID must be set before calling this method, otherwise an error will be thrown.
*/
dailyNote(): Promise<IGenshinDailyNote>;
}
interface IGenshinDiaryInfo extends IGenshinDiaryBase {
month: number;
month_data: {
current_primogems: number;
current_mora: number;
last_primogems: number;
last_mora: number;
primogem_rate: number;
mora_rate: number;
group_by: {
action_id: number;
action: string;
num: number;
percent: number;
}[];
};
day_data: {
current_primogems: number;
current_mora: number;
};
}
interface IGenshinDiaryHistory {
action_id: number;
action: string;
time: string;
num: number;
}
interface IGenshinDiaryDetail extends IGenshinDiaryBase {
current_page: number;
list: IGenshinDiaryHistory[];
}
interface IGenshinDailyAwardItem {
icon: string;
name: string;
cnt: number;
/**
* Genshin Impact Regions
*
* @remarks
* This enum represents the available regions in Genshin Impact game.
*
* @enum
* @readonly
*/
declare enum GenshinRegion {
/** United States */
USA = "os_usa",
/** Europe */
EUROPE = "os_euro",
/** Asia */
ASIA = "os_asia",
/** China Taiwan */
CHINA_TAIWAN = "os_cht"
}
interface IGenshinDailyInfo {
total_sign_day: number;
today: string;
is_sign: boolean;
first_bind: boolean;
is_sub: boolean;
region: string;
month_last_day: boolean;
}
interface IGenshinDailyReward {
month: number;
resign: boolean;
now: string;
award: IGenshinDailyAwardItem;
}
interface IGenshinDailyRewards {
month: number;
resign: boolean;
now: string;
awards: IGenshinDailyAwardItem[];
}
interface IGenshinDailyClaim {
status: string;
code: number;
reward: IGenshinDailyReward | null;
info: IGenshinDailyInfo;
}
declare enum AbyssScheduleEnum {
CURRENT = 1,
PREVIOUS = 2
/**
* Interface representing the options for the Genshin Impact API.
* Inherits from `IHoyolabOptions`.
*
* @interface
*/
interface IGenshinOptions extends IHoyolabOptions {
/**
* The UID of the Genshin Impact player.
*/
uid?: number;
/**
* The region of the Genshin Impact player.
*/
region?: GenshinRegion;
}
declare enum DiaryMonthEnum {
CURRENT = 3,
ONE_MONTH_AGO = 2,
TWO_MONTH_AGO = 1
}
declare enum DiaryEnum {
PRIMOGEMS = 1,
MORA = 2
}
declare class Hoyolab {
readonly cookie: ICookie;
readonly request: Request;
lang: LanguageEnum;
constructor(options: IHoyolabOptions);
/**
* The `Genshin` class provides an interface to interact with Genshin Impact-related features on the Mihoyo website.
* It contains references to various modules such as `DailyModule`, `RedeemModule`, `RecordModule`, and `DiaryModule` which allow you to perform various operations related to these features.
*
* @class
* @category Main
*/
declare class GenshinImpact {
/**
* Get games available accounts
* The `DailyModule` object provides an interface to interact with the daily check-in feature in Genshin Impact.
*
* @param game GamesEnum Selected Game
* @returns {Promise<Interface.IGame[]>}
*/
gamesList(game?: GamesEnum): Promise<IGame[]>;
readonly daily: DailyModule;
/**
* Select one of highest level game account
* The `RedeemModule` object provides an interface to interact with the code redemption feature in Genshin Impact.
*
* @param game GameEnum Selected Game
* @returns {Promise<Interface.IGame>}
*/
gameAccount(game: GamesEnum): Promise<IGame>;
}
declare class HoyolabError extends Error {
readonly name: string;
readonly message: string;
constructor(message: string);
}
declare class Genshin {
readonly redeem: RedeemModule;
/**
* The `RecordModule` object provides an interface to interact with the user record feature in Genshin Impact.
*
*/
readonly record: RecordModule;
/**
* The `DiaryModule` object provides an interface to interact with the user diary feature in Genshin Impact.
*
*/
readonly diary: DiaryModule;
/**
* The cookie object to be used in requests.
*/
readonly cookie: ICookie;
/**
* The `Request` object used to make requests.
*/
readonly request: Request;
/**
* The UID of the user, if available.
*/
uid: number | null;
/**
* The region of the user, if available.
*/
region: string | null;
/**
* The language to be used in requests.
*/
lang: LanguageEnum;
/**
* Constructs a new `Genshin` object.
* @param options The options object used to configure the object.
* @param options.cookie The cookie string or object to be used in requests.
* @param options.uid The UID of the user.
* @param options.region The region of the user.
* @param options.lang The language to be used in requests.
*/
constructor(options: IGenshinOptions);
/**
* Create Genshin Object
* Create a new instance of the GenshinImpact class asynchronously.
*
* @param options IGenshinOptions Options
* @returns {Promise<Genshin>}
* @param options The options object used to configure the object.
* @param options.cookie The cookie string or object to be used in requests.
* @param options.lang The language to be used in requests.
* @returns A promise that resolves with a new Genshin instance.
*/
static create(options: IGenshinOptions): Promise<Genshin>;
static create(options: IGenshinOptions): Promise<GenshinImpact>;
/**
* Fetch game records
* Get user's Genshin Impact record
*
* @returns {Promise<IGenshinRecord>}
* @alias {@link GenshinImpact.record | Genshin.record.records()}
* @deprecated Use through {@link GenshinImpact.record | Genshin.record.records()} instead
*/
records(): Promise<IGenshinRecord>;
/**
* Fetch obtained genshin characters with artifact, weapon, level and constellation
* Retrieves the Genshin characters of the user.
*
* @returns {Promise<IGenshinCharacters>}
* @alias {@link GenshinImpact.record | Genshin.record.characters()}
* @deprecated Use through {@link GenshinImpact.record | Genshin.record.characters()} instead
*/
characters(): Promise<IGenshinCharacters>;
/**
* Fetch characters summary detail (name, rarity, weapon, icon)
* Returns the summary information of Genshin Impact game characters
*
* @param characterIds number[] Characters ID
* @returns {Promise<IGenshinCharacterSummary>}
* @alias {@link GenshinImpact.record | Genshin.record.charactersSummary()}
* @deprecated Use through {@link GenshinImpact.record | Genshin.record.charactersSummary()} instead
*/
charactersSummary(characterIds: number[]): Promise<IGenshinCharacterSummary>;
/**
* Fetch Spiral Abyss data
* Retrieves information about the player's performance in the Spiral Abyss.
*
* @param scheduleType AbyssScheduleEnum
* @returns {Promise<IGenshinSpiralAbyss>}
* @alias {@link GenshinImpact.record | Genshin.record.spiralAbyss()}
* @deprecated Use through {@link GenshinImpact.record | Genshin.record.spiralAbyss()} instead
*/
spiralAbyss(scheduleType?: AbyssScheduleEnum): Promise<IGenshinSpiralAbyss>;
/**
* Fetch daily note resources (resin, home coin, expeditions, and transformer)
* Retrieve the daily note information for a Genshin Impact user.
*
* @returns {Promise<IGenshinDailyNote>}
* @alias {@link GenshinImpact.record | Genshin.record.dailyNote()}
* @deprecated Use through {@link GenshinImpact.record | Genshin.record.dailyNote()} instead
*/
dailyNote(): Promise<IGenshinDailyNote>;
/**
* Fetch genshin impact diary data
* Returns the diary information of a given month for a user
*
* @param month
* @returns {Promise<IGenshinDiaryInfo>}
* @alias {@link GenshinImpact.diary | Genshin.diary.diaries()}
* @deprecated Use through {@link GenshinImpact.diary | Genshin.diary.diaries()} instead
*/
diaries(month?: DiaryMonthEnum): Promise<IGenshinDiaryInfo>;
/**
* Fetch history of received resources (primogems and mora) from diary
* Returns the diary details of a given type and month for a user
*
* @param type DiaryEnum
* @param month DiaryMonthEnum
* @returns {IGenshinDiaryDetail}
* @alias {@link GenshinImpact.diary | Genshin.diary.detail()}
* @deprecated Use through {@link GenshinImpact.diary | Genshin.diary.detail()} instead
*/
diaryDetail(type: DiaryEnum, month?: DiaryMonthEnum): Promise<IGenshinDiaryDetail>;
/**
* Fetch Daily login information
* Retrieves daily information.
*
* @returns {Promise<IGenshinDailyInfo>}
* @alias {@link GenshinImpact.daily | Genshin.daily.info()}
* @deprecated Use through {@link GenshinImpact.daily | Genshin.daily.info()} instead
*/
dailyInfo(): Promise<IGenshinDailyInfo>;
dailyInfo(): Promise<IDailyInfo>;
/**
* Fetch all rewards from daily login
* Retrieve daily rewards information.
*
* @returns {Promise<IGenshinDailyRewards>}
* @alias {@link GenshinImpact.daily | Genshin.daily.rewards()}
* @deprecated Use through {@link GenshinImpact.daily | Genshin.daily.rewards()} instead
*/
dailyRewards(): Promise<IGenshinDailyRewards>;
dailyRewards(): Promise<IDailyRewards>;
/**
* Fetch reward from daily login based on day
* Get the daily reward for a specific day or the current day
*
* @param day number | null
* @returns {Promise<IGenshinDailyReward>}
* @alias {@link GenshinImpact.daily | Genshin.daily.reward()}
* @deprecated Use through {@link GenshinImpact.daily | Genshin.daily.reward()} instead
*/
dailyReward(day?: number | null): Promise<IGenshinDailyReward>;
dailyReward(day?: number | null): Promise<IDailyReward>;
/**
* Claim current reward
*
* @returns {Promise<IGenshinDailyClaim>}
* @alias {@link GenshinImpact.daily | Genshin.daily.claim()}
* @deprecated Use through {@link GenshinImpact.daily | Genshin.daily.claim()} instead
*/
dailyClaim(): Promise<IGenshinDailyClaim>;
dailyClaim(): Promise<IDailyClaim>;
/**
* Redeem Code
* Redeems a code for a specific account.
*
* @param code string
* @returns {Promise<IRedeemCode>}
* @alias {@link GenshinImpact.daily | Genshin.redeem.claim()}
* @deprecated Use through {@link GenshinImpact.daily | Genshin.redeem.claim()} instead
*/

@@ -617,71 +1995,123 @@ redeemCode(code: string): Promise<IRedeemCode>;

/**
* Get Genshin Impact region based on UID.
*
* @param uid User ID.
* @returns Region for the UID.
* @throws `HoyolabError` when the UID is invalid.
*/
declare function getGenshinRegion(uid: number): GenshinRegion;
declare enum HsrRegion {
USA = "prod_official_asia",
EUROPE = "prod_official_euro",
ASIA = "prod_official_asia",
CHINA_TAIWAN = "prod_official_cht"
}
interface IHsrOptions extends IHoyolabOptions {
uid?: number;
region?: HsrRegion;
}
interface IHsrDailyAwardItem {
icon: string;
name: string;
cnt: number;
}
interface IHsrDailyInfo {
total_sign_day: number;
today: string;
is_sign: boolean;
is_sub: boolean;
region: string;
}
interface IHsrDailyReward {
month: number;
resign: boolean;
biz: string;
award: IHsrDailyAwardItem;
}
interface IHsrDailyRewards {
month: number;
resign: boolean;
biz: string;
awards: IHsrDailyAwardItem[];
}
interface IHsrDailyClaim {
status: string;
code: number;
reward: IHsrDailyReward | null;
info: IHsrDailyInfo;
}
/**
* Class representing the Honkai Star Rail game.
*
* @public
* @class
* @category Main
*/
declare class HonkaiStarRail {
/**
* The Daily module for the Honkai Star Rail game.
*
* @public
* @readonly
*/
readonly daily: DailyModule;
/**
* The Redeem module for the Honkai Star Rail game.
*
* @public
* @readonly
*/
readonly redeem: RedeemModule;
/**
* The cookie used for authentication.
*
* @public
* @readonly
*/
readonly cookie: ICookie;
/**
* The request object used to make HTTP requests.
*
* @public
* @readonly
*/
readonly request: Request;
/**
* The UID of the Honkai Star Rail account.
*
* @public
*/
uid: number | null;
/**
* The region of the Honkai Star Rail account.
*
* @public
*/
region: string | null;
/**
* The language of the Honkai Star Rail account.
*
* @public
*/
lang: LanguageEnum;
/**
* Create a new instance of HonkaiStarRail.
*
* @public
* @constructor
* @param {IHsrOptions} options - The options for the HonkaiStarRail instance.
*/
constructor(options: IHsrOptions);
/**
* Create StarRails Object
* Create a new instance of HonkaiStarRail using a Hoyolab account.
* If `uid` is not provided in the `options`, the account with the highest level will be used.
*
* @param options IHsrOptions Options
* @returns {Promise<HonkaiStarRail>}
* @public
* @static
* @param {IHsrOptions} options - The options for the HonkaiStarRail instance.
* @returns {Promise<HonkaiStarRail>} - A promise that resolves with a new HonkaiStarRail instance.
*/
static create(options: IHsrOptions): Promise<HonkaiStarRail>;
dailyInfo(): Promise<IHsrDailyInfo>;
/**
* Fetch all rewards from daily login
* Retrieves daily information.
*
* @returns {Promise<IHsrDailyRewards>}
* @alias {@link DailyModule.info | DailyModule.info }
* @deprecated Use through { @link HonkaiStarRail.daily | HonkaiStarRail.daily.info() } instead
*/
dailyRewards(): Promise<IHsrDailyRewards>;
dailyInfo(): Promise<IDailyInfo>;
/**
*
* @alias {@link DailyModule.rewards | DailyModule.rewards }
* @deprecated Use through { @link HonkaiStarRail.daily | HonkaiStarRail.daily.rewards() } instead
*/
dailyRewards(): Promise<IDailyRewards>;
/**
* Fetch reward from daily login based on day
*
* @param day number | null
* @returns {Promise<IHsrDailyReward>}
* @alias {@link DailyModule.reward | DailyModule.reward }
* @deprecated Use through { @link HonkaiStarRail.daily | HonkaiStarRail.daily.reward() } instead
*/
dailyReward(day?: number | null): Promise<IHsrDailyReward>;
dailyReward(day?: number | null): Promise<IDailyReward>;
/**
* Claim current reward
*
* @returns {Promise<IHsrDailyClaim>}
* @alias {@link DailyModule.claim | DailyModule.claim }
* @deprecated Use through { @link HonkaiStarRail.daily | HonkaiStarRail.daily.claim() } instead
*/
dailyClaim(): Promise<IHsrDailyClaim>;
dailyClaim(): Promise<IDailyClaim>;
/**

@@ -691,3 +2121,4 @@ * Redeem Code

* @param code string
* @returns {Promise<IRedeemCode>}
* @alias {@link RedeemModule.claim | RedeemModule.claim }
* @deprecated Use through { @link HonkaiStarRail.redeem | HonkaiStarRail.redeem.claim() } instead
*/

@@ -697,73 +2128,192 @@ redeemCode(code: string): Promise<IRedeemCode>;

declare class Cookie {
/**
* Get Server Region by UID
*
* @param uid number UID
* @returns {string}
*/
declare function getHsrRegion(uid: number): HsrRegion;
/**
* An enum representing Honkai servers region.
*/
declare enum HonkaiRegion {
/** United States */
USA = "usa01",
/** Europe */
EUROPE = "eur01",
/** Asia */
ASIA = "overseas01"
}
/**
* Interface representing the options for the Honkai Impact API.
* Inherits from `IHoyolabOptions`.
*
* @interface
*/
interface IHi3Options extends IHoyolabOptions {
/**
* Parse Cookie string to ICookie Object
* The UID of the Honkai Impact player.
*/
uid?: number;
/**
* The region of the Honkai Impact player.
*/
region?: HonkaiRegion;
}
/**
* Class representing the Honkai Impact 3rd game.
*
* @public
* @class
* @category Main
*/
declare class HonkaiImpact {
/**
* The Daily module for the Honkai Impact 3rd game.
*
* @param cookieString string String cookies sourced from the hoyolab page
* @returns {ICookie}
* @public
* @readonly
*/
static parseCookieString(cookieString: string): ICookie;
readonly daily: DailyModule;
/**
* Parse Cookie object to cookie string
* The Redeem module for the Honkai Impact 3rd game.
*
* @param cookie ICookie
* @returns {string}
* @public
* @readonly
*/
static parseCookie(cookie: ICookie): string;
readonly redeem: RedeemModule;
/**
* The cookie used for authentication.
*
* @public
* @readonly
*/
readonly cookie: ICookie;
/**
* The request object used to make HTTP requests.
*
* @public
* @readonly
*/
readonly request: Request;
/**
* The UID of the Honkai Impact 3rd account.
*
* @public
*/
uid: number | null;
/**
* The region of the Honkai Impact 3rd account.
*
* @public
*/
region: string | null;
/**
* The language of the Honkai Impact 3rd account.
*
* @public
*/
lang: LanguageEnum;
/**
* Create a new instance of HonkaiImpact.
*
* @public
* @constructor
* @param {IHi3Options} options - The options for the HonkaiImpact instance.
*/
constructor(options: IHi3Options);
/**
* Create a new instance of HonkaiImpact using a Hoyolab account.
* If `uid` is not provided in the `options`, the account with the highest level will be used.
*
* @public
* @static
* @param {IHi3Options} options - The options for the HonkaiImpact instance.
* @returns {Promise<HonkaiImpact>} - A promise that resolves with a new HonkaiImpact instance.
*/
static create(options: IHi3Options): Promise<HonkaiImpact>;
/**
* Retrieves daily information.
*
* @alias {@link DailyModule.info | DailyModule.info }
* @deprecated Use through { @link HonkaiImpact.daily | HonkaiImpact.daily.info() } instead
*/
dailyInfo(): Promise<IDailyInfo>;
/**
*
* @alias {@link DailyModule.rewards | DailyModule.rewards }
* @deprecated Use through { @link HonkaiImpact.daily | HonkaiImpact.daily.rewards() } instead
*/
dailyRewards(): Promise<IDailyRewards>;
/**
* Fetch reward from daily login based on day
*
* @param day number | null
* @alias {@link DailyModule.reward | DailyModule.reward }
* @deprecated Use through { @link HonkaiImpact.daily | HonkaiImpact.daily.reward() } instead
*/
dailyReward(day?: number | null): Promise<IDailyReward>;
/**
* Claim current reward
*
* @alias {@link DailyModule.claim | DailyModule.claim }
* @deprecated Use through { @link HonkaiImpact.daily | HonkaiImpact.daily.claim() } instead
*/
dailyClaim(): Promise<IDailyClaim>;
/**
* Redeem Code
*
* @param code string
* @alias {@link RedeemModule.claim | RedeemModule.claim }
* @deprecated Use through { @link HonkaiImpact.redeem | HonkaiImpact.redeem.claim() } instead
*/
redeemCode(code: string): Promise<IRedeemCode>;
}
declare const GAMES_ACCOUNT = "https://api-account-os.hoyolab.com/account/binding/api/getUserGameRolesByCookieToken";
declare const GENSHIN_GAME_RECORD_REFERER = "https://act.hoyolab.com";
declare const GENSHIN_GAME_RECORD: string;
declare const GENSHIN_CHARACTERS_LIST: string;
declare const GENSHIN_CHARACTERS_SUMMARY: string;
declare const GENSHIN_SPIRAL_ABYSS: string;
declare const GENSHIN_DAILY_NOTE: string;
declare const GENSHIN_DIARY: string;
declare const GENSHIN_DIARY_DETAIL: string;
declare const GENSHIN_DAILY_INFO: string;
declare const GENSHIN_DAILY_REWARD: string;
declare const GENSHIN_DAILY_CLAIM: string;
declare const HSR_DAILY_INFO: string;
declare const HSR_DAILY_REWARD: string;
declare const HSR_DAILY_CLAIM: string;
declare const GENSHIN_REDEEM_CODE: string;
/**
* Gets the Honkai region from a given UID.
* @function
* @param {number} uid - The UID to get the Honkai region for.
* @returns {HonkaiRegion} - The Honkai region for the given UID.
* @throws {HoyolabError} - If the UID is invalid.
*/
declare function getHi3Region(uid: number): HonkaiRegion;
declare const routes_GAMES_ACCOUNT: typeof GAMES_ACCOUNT;
declare const routes_GENSHIN_CHARACTERS_LIST: typeof GENSHIN_CHARACTERS_LIST;
declare const routes_GENSHIN_CHARACTERS_SUMMARY: typeof GENSHIN_CHARACTERS_SUMMARY;
declare const routes_GENSHIN_DAILY_CLAIM: typeof GENSHIN_DAILY_CLAIM;
declare const routes_GENSHIN_DAILY_INFO: typeof GENSHIN_DAILY_INFO;
declare const routes_GENSHIN_DAILY_NOTE: typeof GENSHIN_DAILY_NOTE;
declare const routes_GENSHIN_DAILY_REWARD: typeof GENSHIN_DAILY_REWARD;
declare const routes_GENSHIN_DIARY: typeof GENSHIN_DIARY;
declare const routes_GENSHIN_DIARY_DETAIL: typeof GENSHIN_DIARY_DETAIL;
declare const routes_GENSHIN_GAME_RECORD: typeof GENSHIN_GAME_RECORD;
declare const routes_GENSHIN_GAME_RECORD_REFERER: typeof GENSHIN_GAME_RECORD_REFERER;
declare const routes_GENSHIN_REDEEM_CODE: typeof GENSHIN_REDEEM_CODE;
declare const routes_GENSHIN_SPIRAL_ABYSS: typeof GENSHIN_SPIRAL_ABYSS;
declare const routes_HSR_DAILY_CLAIM: typeof HSR_DAILY_CLAIM;
declare const routes_HSR_DAILY_INFO: typeof HSR_DAILY_INFO;
declare const routes_HSR_DAILY_REWARD: typeof HSR_DAILY_REWARD;
declare namespace routes {
export {
routes_GAMES_ACCOUNT as GAMES_ACCOUNT,
routes_GENSHIN_CHARACTERS_LIST as GENSHIN_CHARACTERS_LIST,
routes_GENSHIN_CHARACTERS_SUMMARY as GENSHIN_CHARACTERS_SUMMARY,
routes_GENSHIN_DAILY_CLAIM as GENSHIN_DAILY_CLAIM,
routes_GENSHIN_DAILY_INFO as GENSHIN_DAILY_INFO,
routes_GENSHIN_DAILY_NOTE as GENSHIN_DAILY_NOTE,
routes_GENSHIN_DAILY_REWARD as GENSHIN_DAILY_REWARD,
routes_GENSHIN_DIARY as GENSHIN_DIARY,
routes_GENSHIN_DIARY_DETAIL as GENSHIN_DIARY_DETAIL,
routes_GENSHIN_GAME_RECORD as GENSHIN_GAME_RECORD,
routes_GENSHIN_GAME_RECORD_REFERER as GENSHIN_GAME_RECORD_REFERER,
routes_GENSHIN_REDEEM_CODE as GENSHIN_REDEEM_CODE,
routes_GENSHIN_SPIRAL_ABYSS as GENSHIN_SPIRAL_ABYSS,
routes_HSR_DAILY_CLAIM as HSR_DAILY_CLAIM,
routes_HSR_DAILY_INFO as HSR_DAILY_INFO,
routes_HSR_DAILY_REWARD as HSR_DAILY_REWARD,
};
/**
* Represents an error that can be thrown during interactions with the Hoyolab API.
*
* @class
* @category Main
*/
declare class HoyolabError extends Error {
/**
* The name of this error.
*/
readonly name: string;
/**
* The message associated with this error.
*/
readonly message: string;
/**
* Constructs a new instance of the HoyolabError class with the specified message.
*
* @param message The message to associate with this error.
*/
constructor(message: string);
}
export { AbyssScheduleEnum, BodyType, Cache, Cookie, DiaryEnum, DiaryMonthEnum, GamesEnum, Genshin, HonkaiStarRail, Hoyolab, HoyolabError, ICookie, IGame, IGamesList, IGenshinCharacterAvatarFull, IGenshinCharacterBase, IGenshinCharacterConstellation, IGenshinCharacterCostume, IGenshinCharacterReliquaries, IGenshinCharacterReliquariesAffix, IGenshinCharacterReliquariesSet, IGenshinCharacterRole, IGenshinCharacterSummary, IGenshinCharacterWeapon, IGenshinCharacters, IGenshinDailyAwardItem, IGenshinDailyClaim, IGenshinDailyInfo, IGenshinDailyNote, IGenshinDailyReward, IGenshinDailyRewards, IGenshinDiaryBase, IGenshinDiaryDetail, IGenshinDiaryHistory, IGenshinDiaryInfo, IGenshinOptions, IGenshinRecord, IGenshinRecordAvatar, IGenshinRecordHome, IGenshinRecordStat, IGenshinRecordWorldExploration, IGenshinSpiralAbyss, IGenshinSpiralAbyssAvatar, IGenshinSpiralAbyssBattle, IGenshinSpiralAbyssFloor, IGenshinSpiralAbyssLevel, IGenshinSpiralAbyssRank, IHoyolabOptions, IRedeemCode, IResponse, LanguageEnum, Request, routes as Route, getServerRegion, parseLang, toCamelCase, toSnakeCase };
/**
* The `GenshinImpact` namespace provides a collection of methods to interact with the Genshin Impact game.
*
* @alias {@link GenshinImpact | GenshinImpact}
* @see {@link GenshinImpact | GenshinImpact}
* @category Deprecated
* @deprecated Use {@link GenshinImpact | GenshinImpact} class instead.
*/
declare class Genshin extends GenshinImpact {
}
export { AbyssScheduleEnum, BaseType, Cache, CacheKey, Cookie, DailyModule, DiaryEnum, DiaryModule, DiaryMonthEnum, GamesEnum, Genshin, GenshinImpact, GenshinRegion, HonkaiImpact, HonkaiRegion, HonkaiStarRail, Hoyolab, HoyolabError, HsrRegion, ICookie, IDailyAwardItem, IDailyClaim, IDailyInfo, IDailyReward, IDailyRewards, IGame, IGamesList, IGenshinCharacterAvatarFull, IGenshinCharacterBase, IGenshinCharacterConstellation, IGenshinCharacterCostume, IGenshinCharacterReliquaries, IGenshinCharacterReliquariesAffix, IGenshinCharacterReliquariesSet, IGenshinCharacterRole, IGenshinCharacterSummary, IGenshinCharacterWeapon, IGenshinCharacters, IGenshinDailyNote, IGenshinDiaryBase, IGenshinDiaryDetail, IGenshinDiaryHistory, IGenshinDiaryInfo, IGenshinOptions, IGenshinRecord, IGenshinRecordAvatar, IGenshinRecordHome, IGenshinRecordStat, IGenshinRecordWorldExploration, IGenshinSpiralAbyss, IGenshinSpiralAbyssAvatar, IGenshinSpiralAbyssBattle, IGenshinSpiralAbyssFloor, IGenshinSpiralAbyssLevel, IGenshinSpiralAbyssRank, IHi3Options, IHoyolabOptions, IHsrOptions, IRedeemCode, IResponse, Language, LanguageEnum, RecordModule, RedeemModule, Request, RequestBodyType, RequestHeaderType, RequestParamType, delay, generateDS, getGenshinRegion, getHi3Region, getHsrRegion };

1604

dist/index.js

@@ -36,21 +36,36 @@ "use strict";

Cookie: () => Cookie,
DailyModule: () => DailyModule,
DiaryEnum: () => DiaryEnum,
DiaryModule: () => DiaryModule,
DiaryMonthEnum: () => DiaryMonthEnum,
GamesEnum: () => GamesEnum,
Genshin: () => Genshin,
GenshinImpact: () => GenshinImpact,
GenshinRegion: () => GenshinRegion,
HonkaiImpact: () => HonkaiImpact,
HonkaiRegion: () => HonkaiRegion,
HonkaiStarRail: () => HonkaiStarRail,
Hoyolab: () => Hoyolab,
HoyolabError: () => HoyolabError,
HsrRegion: () => HsrRegion,
Language: () => Language,
LanguageEnum: () => LanguageEnum,
RecordModule: () => RecordModule,
RedeemModule: () => RedeemModule,
Request: () => Request,
Route: () => routes_exports,
getServerRegion: () => getServerRegion,
parseLang: () => parseLang,
toCamelCase: () => toCamelCase,
toSnakeCase: () => toSnakeCase
delay: () => delay,
generateDS: () => generateDS,
getGenshinRegion: () => getGenshinRegion,
getHi3Region: () => getHi3Region,
getHsrRegion: () => getHsrRegion
});
module.exports = __toCommonJS(src_exports);
// src/HoyolabError.ts
// src/utils/error.ts
var HoyolabError = class extends Error {
/**
* Constructs a new instance of the HoyolabError class with the specified message.
*
* @param message The message to associate with this error.
*/
constructor(message) {

@@ -64,31 +79,3 @@ super(message);

// src/Interfaces/LanguageEnum.ts
var LanguageEnum = /* @__PURE__ */ ((LanguageEnum4) => {
LanguageEnum4["SIMPLIFIED_CHINESE"] = "zh-cn";
LanguageEnum4["TRADIIONAL_CHINESE"] = "zh-tw";
LanguageEnum4["GERMAN"] = "de-de";
LanguageEnum4["ENGLISH"] = "en-us";
LanguageEnum4["SPANISH"] = "es-es";
LanguageEnum4["FRENCH"] = "fr-fr";
LanguageEnum4["INDONESIAN"] = "id-id";
LanguageEnum4["ITALIAN"] = "it-it";
LanguageEnum4["JAPANESE"] = "ja-jp";
LanguageEnum4["KOREAN"] = "ko-kr";
LanguageEnum4["PORTUGUESE"] = "pt-pt";
LanguageEnum4["RUSSIAN"] = "ru-ru";
LanguageEnum4["THAI"] = "th-th";
LanguageEnum4["TURKISH"] = "tr-tr";
LanguageEnum4["VIETNAMESE"] = "vi-vn";
return LanguageEnum4;
})(LanguageEnum || {});
// src/Interfaces/Hoyolab/GamesEnum.ts
var GamesEnum = /* @__PURE__ */ ((GamesEnum2) => {
GamesEnum2["GENSHIN_IMPACT"] = "hk4e_global";
GamesEnum2["HONKAI_IMPACT"] = "bh3_global";
GamesEnum2["HONKAI_STAR_RAIL"] = "hkrpg_global";
return GamesEnum2;
})(GamesEnum || {});
// src/helpers.ts
// src/cookie/cookie.helper.ts
function toCamelCase(str) {

@@ -104,38 +91,213 @@ const words = str.split("_");

}
function getServerRegion(uid) {
const server_region = Number(uid.toString().trim().slice(0, 1));
switch (server_region) {
case 6:
return "os_usa";
case 7:
return "os_euro";
case 8:
return "os_asia";
case 9:
return "os_cht";
default:
throw new HoyolabError(`Given UID ${uid} is invalid !`);
// src/language/language.interface.ts
var LanguageEnum = /* @__PURE__ */ ((LanguageEnum6) => {
LanguageEnum6["SIMPLIFIED_CHINESE"] = "zh-cn";
LanguageEnum6["TRADIIONAL_CHINESE"] = "zh-tw";
LanguageEnum6["GERMAN"] = "de-de";
LanguageEnum6["ENGLISH"] = "en-us";
LanguageEnum6["SPANISH"] = "es-es";
LanguageEnum6["FRENCH"] = "fr-fr";
LanguageEnum6["INDONESIAN"] = "id-id";
LanguageEnum6["ITALIAN"] = "it-it";
LanguageEnum6["JAPANESE"] = "ja-jp";
LanguageEnum6["KOREAN"] = "ko-kr";
LanguageEnum6["PORTUGUESE"] = "pt-pt";
LanguageEnum6["RUSSIAN"] = "ru-ru";
LanguageEnum6["THAI"] = "th-th";
LanguageEnum6["TURKISH"] = "tr-tr";
LanguageEnum6["VIETNAMESE"] = "vi-vn";
return LanguageEnum6;
})(LanguageEnum || {});
// src/language/language.ts
var Language = class {
/**
* Parses a language string into its corresponding LanguageEnum value.
*
* @param lang The language string to parse, or null/undefined to default to English.
* @returns The LanguageEnum value corresponding to the provided string, or English if the string is invalid or undefined.
*/
static parseLang(lang) {
if (!lang) {
return "en-us" /* ENGLISH */;
}
const langKeys = Object.keys(LanguageEnum);
const matchingKey = langKeys.find((key) => LanguageEnum[key] === lang);
return matchingKey ? LanguageEnum[matchingKey] : "en-us" /* ENGLISH */;
}
}
function parseLang(lang) {
if (!lang) {
return "en-us" /* ENGLISH */;
};
// src/cookie/cookie.ts
var Cookie = class {
/**
* Parses a cookie string and returns a parsed ICookie object.
*
* @param cookieString - The cookie string to be parsed.
* @returns {string} - A parsed ICookie object.
* @throws {HoyolabError} when ltuid or ltoken keys are not found in the cookie string.
*/
static parseCookieString(cookieString) {
const cookies = {};
const keys = [
"ltoken",
"ltuid",
"account_id",
"cookie_token",
"mi18nLang"
];
cookieString.split(";").forEach((cookie) => {
const [cookieKey, cookieValue] = cookie.trim().split("=");
if (keys.includes(cookieKey)) {
cookies[toCamelCase(cookieKey)] = decodeURIComponent(cookieValue);
if (cookieKey === "ltuid" || cookieKey === "account_id") {
cookies[toCamelCase(cookieKey)] = parseInt(
cookies[toCamelCase(cookieKey)],
10
);
} else if (cookieKey === "mi18nLang") {
cookies[toCamelCase(cookieKey)] = Language.parseLang(
cookies[toCamelCase(cookieKey)].toString()
);
}
}
});
if (cookies.ltuid && !cookies.accountId) {
cookies.accountId = cookies.ltuid;
} else if (!cookies.ltuid && cookies.accountId) {
cookies.ltuid = cookies.accountId;
}
if (!cookies.ltoken || !cookies.ltuid) {
throw new HoyolabError("Cookie key ltuid or ltoken doesnt exist !");
}
return cookies;
}
const langKeys = Object.keys(LanguageEnum);
const matchingKey = langKeys.find((key) => LanguageEnum[key] === lang);
return matchingKey ? LanguageEnum[matchingKey] : "en-us" /* ENGLISH */;
}
/**
* Converts an `ICookie` object into a cookie string.
* @param {ICookie} cookie - The `ICookie` object to convert.
* @returns {string} A string representing the cookie.
* @throws {HoyolabError} If the `ltuid` or `ltoken` key is missing in the `ICookie` object.
*/
static parseCookie(cookie) {
if (!cookie.accountId) {
cookie.accountId = cookie.ltuid;
}
const cookies = [];
Object.entries(cookie).forEach(([key, value]) => {
if (value) {
if (["cookieToken", "accountId"].includes(key)) {
key = toSnakeCase(key);
}
cookies.push(`${key}=${value}`);
}
});
return cookies.join("; ");
}
};
// src/Request.ts
// src/request/request.cache.ts
var import_crypto = require("crypto");
var import_node_cache = __toESM(require("node-cache"));
var Cache = class {
constructor() {
/**
* The default time-to-live (TTL) value for cached data in seconds.
*/
this.stdTTL = 30;
/**
* The NodeCache instance used to store and retrieve data.
*/
this.nodeCache = new import_node_cache.default({
stdTTL: this.stdTTL
});
}
/**
* Generates a cache key based on the URL, query parameters, and body of a request.
*
* @param key - The key object containing the URL, query parameters, and body of the request.
* @returns A unique MD5 hash key generated from the key object.
*/
generateKey(key) {
return (0, import_crypto.createHash)("md5").update(JSON.stringify(key)).digest("hex");
}
/**
* Sets a value in the cache with a given key and TTL.
*
* @param key - The key object containing the URL, query parameters, and body of the request.
* @param value - The value to be stored in the cache.
* @param ttl - The TTL value for the cached data in seconds.
* @returns True if the value was successfully stored in the cache, false otherwise.
*/
set(key, value, ttl) {
if (typeof ttl === "undefined") {
ttl = this.stdTTL;
}
return this.nodeCache.set(this.generateKey(key), value, ttl);
}
/**
* Retrieves a value from the cache using a given key.
*
* @param key - The key object containing the URL, query parameters, and body of the request.
* @returns The cached value if it exists, null otherwise.
*/
get(key) {
return this.nodeCache.get(this.generateKey(key));
}
/**
* Checks if a key exists in the cache.
*
* @param key - The key object containing the URL, query parameters, and body of the request.
* @returns True if the key exists in the cache, false otherwise.
*/
has(key) {
return this.nodeCache.has(this.generateKey(key));
}
/**
* Deletes a key-value pair from the cache.
*
* @param key - The key object containing the URL, query parameters, and body of the request.
* @returns True if the key-value pair was successfully deleted from the cache, false otherwise.
*/
del(key) {
return this.nodeCache.del(this.generateKey(key));
}
};
// src/request/request.ts
var import_axios = __toESM(require("axios"));
var import_md5 = __toESM(require("md5"));
// src/Cache.ts
var Cache = class extends Map {
};
var Cache_default = new Cache();
// src/request/request.helper.ts
var import_crypto2 = require("crypto");
function generateDS() {
const salt = "6s25p5ox5y14umn1p61aqyyvbvvl3lrt";
const date = /* @__PURE__ */ new Date();
const time = Math.floor(date.getTime() / 1e3);
let random = "";
const characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
for (let i = 0; i < 6; i++) {
const randomIndex = Math.floor(Math.random() * characters.length);
const randomChar = characters.charAt(randomIndex);
random += randomChar;
}
const hash = (0, import_crypto2.createHash)("md5").update(`salt=${salt}&t=${time}&r=${random}`).digest("hex");
return `${time},${random},${hash}`;
}
function delay(second) {
return new Promise((resolve) => {
setTimeout(resolve, second * 1e3);
});
}
// src/Request.ts
// src/request/request.ts
var Request = class {
/**
* Constructor for the Request class.
*
* @param cookies - A string of cookies to be added to the request headers (default: null).
*/
constructor(cookies = null) {
/**
* The number of request attempts made.
*/
this.retries = 1;
this.headers = {

@@ -150,3 +312,3 @@ "Content-Type": "application/json",

this.params = {};
this.cache = Cache_default;
this.cache = new Cache();
this.ds = false;

@@ -159,4 +321,4 @@ if (cookies)

*
* @param url string URL string of referer
* @returns {this}
* @param url - The URL string of referer
* @returns The updated Request instance.
*/

@@ -169,6 +331,6 @@ setReferer(url) {

/**
* Set Body Paramter
* Set Body Parameter
*
* @param body Body Body Parameters as object
* @returns {this}
* @param body - RequestBodyType as object containing the body parameters.
* @returns This instance of Request object.
*/

@@ -180,6 +342,6 @@ setBody(body) {

/**
* Set SearchParams or query parameter
* Sets search parameters or query parameter.
*
* @param params BodyType Object of query parameter
* @returns {this}
* @param params - An object of query parameter to be set.
* @returns {Request} - Returns this Request object.
*/

@@ -193,4 +355,4 @@ setParams(params) {

*
* @param flag boolean Flag
* @returns {this}
* @param flag boolean Flag indicating whether to use dynamic security or not (default: true).
* @returns {this} The current Request instance.
*/

@@ -211,13 +373,25 @@ setDs(flag = true) {

}
/* c8 ignore start */
/**
* Send Request
* Send the HTTP request.
*
* @param url string URL String
* @param method GET|POST Method for request
* @returns {Promise<IResponse>}
* @param url - The URL to send the request to.
* @param method - The HTTP method to use. Defaults to 'GET'.
* @param ttl - The TTL value for the cached data in seconds.
* @returns A Promise that resolves with the response data, or rejects with a HoyolabError if an error occurs.
* @throws {HoyolabError} if an error occurs rejects with a HoyolabError
*/
async send(url, method = "GET") {
async send(url, method = "GET", ttl) {
const cacheKey = {
url,
method,
body: this.body,
params: this.params
};
const cachedResult = this.cache.get(cacheKey);
if (cachedResult) {
console.log("Requet Cached");
return cachedResult;
}
if (this.ds) {
this.headers.DS = this.generateDS();
this.headers.DS = generateDS();
}

@@ -234,4 +408,17 @@ const config = {

try {
const request = (await (0, import_axios.default)(url, config)).data;
const result = await request;
const request = await (0, import_axios.default)(url, config);
const result = request.data;
if ([200, 201].includes(request.status) === false) {
throw new import_axios.AxiosError(
request.statusText ?? result.data,
request.status.toString()
);
}
if (result.retcode === -2016 && this.retries <= 60) {
this.retries++;
await delay(1);
return this.send(url, method);
}
this.cache.set(cacheKey, result, ttl);
this.retries = 1;
this.body = {};

@@ -241,4 +428,5 @@ return result;

if (error instanceof import_axios.AxiosError) {
console.log(error);
throw new HoyolabError(`[${error.code}] - ${error.message}`);
throw new HoyolabError(
`Request Error: [${error.code}] - ${error.message}`
);
} else {

@@ -253,153 +441,39 @@ return {

}
/**
* Generate Dynamic Security
*
* @returns {string}
*/
generateDS() {
const salt = "6s25p5ox5y14umn1p61aqyyvbvvl3lrt";
const date = /* @__PURE__ */ new Date();
const time = Math.floor(date.getTime() / 1e3);
let random = "";
const characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
for (let i = 0; i < 6; i++) {
const randomIndex = Math.floor(Math.random() * characters.length);
const randomChar = characters.charAt(randomIndex);
random += randomChar;
}
const hash = (0, import_md5.default)(`salt=${salt}&t=${time}&r=${random}`, {
encoding: "hex"
});
return `${time},${random},${hash}`;
}
/* c8 ignore stop */
};
// src/Interfaces/Genshin/AbyssScheduleEnum.ts
var AbyssScheduleEnum = /* @__PURE__ */ ((AbyssScheduleEnum2) => {
AbyssScheduleEnum2[AbyssScheduleEnum2["CURRENT"] = 1] = "CURRENT";
AbyssScheduleEnum2[AbyssScheduleEnum2["PREVIOUS"] = 2] = "PREVIOUS";
return AbyssScheduleEnum2;
})(AbyssScheduleEnum || {});
// src/Interfaces/Genshin/DiaryEnum.ts
var DiaryMonthEnum = /* @__PURE__ */ ((DiaryMonthEnum2) => {
DiaryMonthEnum2[DiaryMonthEnum2["CURRENT"] = 3] = "CURRENT";
DiaryMonthEnum2[DiaryMonthEnum2["ONE_MONTH_AGO"] = 2] = "ONE_MONTH_AGO";
DiaryMonthEnum2[DiaryMonthEnum2["TWO_MONTH_AGO"] = 1] = "TWO_MONTH_AGO";
return DiaryMonthEnum2;
})(DiaryMonthEnum || {});
var DiaryEnum = /* @__PURE__ */ ((DiaryEnum2) => {
DiaryEnum2[DiaryEnum2["PRIMOGEMS"] = 1] = "PRIMOGEMS";
DiaryEnum2[DiaryEnum2["MORA"] = 2] = "MORA";
return DiaryEnum2;
})(DiaryEnum || {});
// src/Cookie.ts
var Cookie = class {
/**
* Parse Cookie string to ICookie Object
*
* @param cookieString string String cookies sourced from the hoyolab page
* @returns {ICookie}
*/
static parseCookieString(cookieString) {
const cookies = {};
const keys = [
"ltoken",
"ltuid",
"account_id",
"cookie_token",
"mi18nLang"
];
const cookieArr = cookieString.split(";");
for (const element of cookieArr) {
const cookie = element.trim().split("=");
const cookieKey = cookie[0];
let cookieValue = decodeURIComponent(cookie[1]);
if (keys.includes(cookieKey)) {
if (["ltuid", "account_id"].includes(cookieKey)) {
cookieValue = parseInt(cookieValue);
}
if (cookieKey === "mi18nLang") {
cookieValue = parseLang(cookieValue.toString());
}
cookies[toCamelCase(cookieKey)] = cookieValue;
}
}
if (cookies.ltuid && !cookies.accountId) {
cookies.accountId = cookies.ltuid;
} else if (!cookies.ltuid && cookies.accountId) {
cookies.ltuid = cookies.accountId;
}
if (!cookies.ltoken || !cookies.ltuid) {
throw new HoyolabError("Cookie key ltuid or ltoken doesnt exist !");
}
return cookies;
// src/routes.ts
var Routes = class {
static bbs() {
return `https://bbs-api-os.hoyolab.com`;
}
/**
* Parse Cookie object to cookie string
*
* @param cookie ICookie
* @returns {string}
*/
static parseCookie(cookie) {
if (!cookie.accountId) {
cookie.accountId = cookie.ltuid;
}
const cookies = [];
Object.entries(cookie).forEach(([key, value]) => {
if (value) {
if (["cookieToken", "accountId"].includes(key)) {
key = toSnakeCase(key);
}
cookies.push(`${key}=${value}`);
}
});
return cookies.join("; ");
static apiAccount() {
return `https://api-account-os.hoyolab.com`;
}
static hke() {
return `https://sg-hk4e-api.hoyolab.com`;
}
static sgPublic() {
return `https://sg-public-api.hoyolab.com`;
}
static referer() {
return `https://act.hoyolab.com`;
}
};
// src/routes.ts
var routes_exports = {};
__export(routes_exports, {
GAMES_ACCOUNT: () => GAMES_ACCOUNT,
GENSHIN_CHARACTERS_LIST: () => GENSHIN_CHARACTERS_LIST,
GENSHIN_CHARACTERS_SUMMARY: () => GENSHIN_CHARACTERS_SUMMARY,
GENSHIN_DAILY_CLAIM: () => GENSHIN_DAILY_CLAIM,
GENSHIN_DAILY_INFO: () => GENSHIN_DAILY_INFO,
GENSHIN_DAILY_NOTE: () => GENSHIN_DAILY_NOTE,
GENSHIN_DAILY_REWARD: () => GENSHIN_DAILY_REWARD,
GENSHIN_DIARY: () => GENSHIN_DIARY,
GENSHIN_DIARY_DETAIL: () => GENSHIN_DIARY_DETAIL,
GENSHIN_GAME_RECORD: () => GENSHIN_GAME_RECORD,
GENSHIN_GAME_RECORD_REFERER: () => GENSHIN_GAME_RECORD_REFERER,
GENSHIN_REDEEM_CODE: () => GENSHIN_REDEEM_CODE,
GENSHIN_SPIRAL_ABYSS: () => GENSHIN_SPIRAL_ABYSS,
HSR_DAILY_CLAIM: () => HSR_DAILY_CLAIM,
HSR_DAILY_INFO: () => HSR_DAILY_INFO,
HSR_DAILY_REWARD: () => HSR_DAILY_REWARD
});
var GENSHIN_GAME_RECORD_URL = "https://bbs-api-os.hoyolab.com/game_record/genshin/api";
var GENSHIN_HKE_URL = "https://sg-hk4e-api.hoyolab.com";
var SG_PUBLIC_URL = "https://sg-public-api.hoyolab.com";
var GAMES_ACCOUNT = "https://api-account-os.hoyolab.com/account/binding/api/getUserGameRolesByCookieToken";
var GENSHIN_GAME_RECORD_REFERER = "https://act.hoyolab.com";
var GENSHIN_GAME_RECORD = `${GENSHIN_GAME_RECORD_URL}/index`;
var GENSHIN_CHARACTERS_LIST = `${GENSHIN_GAME_RECORD_URL}/character`;
var GENSHIN_CHARACTERS_SUMMARY = `${GENSHIN_GAME_RECORD_URL}/avatarBasicInfo`;
var GENSHIN_SPIRAL_ABYSS = `${GENSHIN_GAME_RECORD_URL}/spiralAbyss`;
var GENSHIN_DAILY_NOTE = `${GENSHIN_GAME_RECORD_URL}/dailyNote`;
var GENSHIN_DIARY = `${GENSHIN_HKE_URL}/event/ysledgeros/month_info`;
var GENSHIN_DIARY_DETAIL = `${GENSHIN_HKE_URL}/event/ysledgeros/month_detail`;
var GENSHIN_DAILY_INFO = `${GENSHIN_HKE_URL}/event/sol/info`;
var GENSHIN_DAILY_REWARD = `${GENSHIN_HKE_URL}/event/sol/home`;
var GENSHIN_DAILY_CLAIM = `${GENSHIN_HKE_URL}/event/sol/sign`;
var HSR_DAILY_INFO = `${SG_PUBLIC_URL}/event/luna/os/info`;
var HSR_DAILY_REWARD = `${SG_PUBLIC_URL}/event/luna/os/home`;
var HSR_DAILY_CLAIM = `${SG_PUBLIC_URL}/event/luna/os/sign`;
var GENSHIN_REDEEM_CODE = `${GENSHIN_HKE_URL}/common/apicdkey/api/webExchangeCdkey`;
// src/games/hoyolab/hoyolab.routes.ts
var HoyolabRoute = class {
static games() {
return `${Routes.apiAccount()}/account/binding/api/getUserGameRolesByCookieToken`;
}
};
// src/Hoyolab.ts
// src/games/hoyolab/hoyolab.ts
var Hoyolab = class {
/**
* Creates a new instance of `Hoyolab`.
*
* @constructor
* @param {IHoyolabOptions} options - The options to initialize the `Hoyolab` instance.
* @throws {HoyolabError} If `ltuid` or `ltoken` keys are missing in the `ICookie` object.
*/
constructor(options) {

@@ -409,3 +483,3 @@ const cookie = typeof options.cookie === "string" ? Cookie.parseCookieString(options.cookie) : options.cookie;

if (!options.lang) {
options.lang = parseLang(cookie.mi18nLang);
options.lang = Language.parseLang(cookie.mi18nLang);
}

@@ -417,6 +491,8 @@ this.request = new Request(Cookie.parseCookie(this.cookie));

/**
* Get games available accounts
* Get the list of games on this Hoyolab account.
*
* @param game GamesEnum Selected Game
* @returns {Promise<Interface.IGame[]>}
* @async
* @param {GamesEnum} [game] The optional game for which to retrieve accounts.
* @throws {HoyolabError} Thrown if there are no game accounts on this Hoyolab account.
* @returns {Promise<IGame[]>} The list of games on this Hoyolab account.
*/

@@ -433,3 +509,3 @@ async gamesList(game) {

});
const res = await this.request.send(GAMES_ACCOUNT);
const res = await this.request.send(HoyolabRoute.games());
const data = res.data;

@@ -444,6 +520,8 @@ if (!res.data || !data.list) {

/**
* Select one of highest level game account
* Get the account of a specific game from the games list.
*
* @param game GameEnum Selected Game
* @returns {Promise<Interface.IGame>}
* @async
* @param {GamesEnum} game - The game that the account belongs to.
* @throws {HoyolabError} If there is no game account on this hoyolab account.
* @returns {Promise<IGame>} The game account.
*/

@@ -463,41 +541,300 @@ async gameAccount(game) {

// src/Genshin.ts
var Genshin = class {
constructor(options) {
const cookie = typeof options.cookie === "string" ? Cookie.parseCookieString(options.cookie) : options.cookie;
this.cookie = cookie;
if (!options.lang) {
options.lang = parseLang(cookie.mi18nLang);
// src/games/hoyolab/hoyolab.enum.ts
var GamesEnum = /* @__PURE__ */ ((GamesEnum2) => {
GamesEnum2["GENSHIN_IMPACT"] = "hk4e_global";
GamesEnum2["HONKAI_IMPACT"] = "bh3_global";
GamesEnum2["HONKAI_STAR_RAIL"] = "hkrpg_global";
return GamesEnum2;
})(GamesEnum || {});
// src/modules/daily/daily.route.ts
var DailyRoute = class {
/** GI Daily Route */
static giDailyInfo() {
return `${this.giBase}/event/sol/info?act_id=${this.giActId}`;
}
static giDailyReward() {
return `${this.giBase}/event/sol/home?act_id=${this.giActId}`;
}
static giDailyClaim() {
return `${this.giBase}/event/sol/sign?act_id=${this.giActId}`;
}
/** HSR Daily Route */
static hsrDailyInfo() {
return `${this.hsrBase}/event/luna/os/info?act_id=${this.hsrActId}`;
}
static hsrDailyReward() {
return `${this.hsrBase}/event/luna/os/home?act_id=${this.hsrActId}`;
}
static hsrDailyClaim() {
return `${this.hsrBase}/event/luna/os/sign?act_id=${this.hsrActId}`;
}
/** HI Daily Route */
static hiDailyInfo() {
return `${this.hiBase}/event/mani/info?act_id=${this.hiActId}`;
}
static hiDailyReward() {
return `${this.hiBase}/event/mani/home?act_id=${this.hiActId}`;
}
static hiDailyClaim() {
return `${this.hiBase}/event/mani/sign?act_id=${this.hiActId}`;
}
};
DailyRoute.hsrActId = "e202303301540311";
DailyRoute.hsrBase = Routes.sgPublic();
DailyRoute.giActId = "e202102251931481";
DailyRoute.giBase = Routes.hke();
DailyRoute.hiActId = "e202110291205111";
DailyRoute.hiBase = Routes.sgPublic();
// src/modules/daily/daily.ts
var DailyModule = class {
constructor(request, lang, game) {
this.request = request;
this.lang = lang;
this.game = game;
if (this.game === "hk4e_global" /* GENSHIN_IMPACT */) {
this.dailyInfoUrl = DailyRoute.giDailyInfo();
this.dailyRewardUrl = DailyRoute.giDailyReward();
this.dailySignUrl = DailyRoute.giDailyClaim();
} else if (this.game === "hkrpg_global" /* HONKAI_STAR_RAIL */) {
this.dailyInfoUrl = DailyRoute.hsrDailyInfo();
this.dailyRewardUrl = DailyRoute.hsrDailyReward();
this.dailySignUrl = DailyRoute.hsrDailyClaim();
} else if (this.game === "bh3_global" /* HONKAI_IMPACT */) {
this.dailyInfoUrl = DailyRoute.hiDailyInfo();
this.dailyRewardUrl = DailyRoute.hiDailyReward();
this.dailySignUrl = DailyRoute.hiDailyClaim();
} else {
throw new HoyolabError("Game Paramater is invalid");
}
this.request = new Request(Cookie.parseCookie(this.cookie));
this.request.setReferer(GENSHIN_GAME_RECORD_REFERER);
this.request.setLang(options.lang);
this.uid = options.uid ?? null;
this.region = this.uid !== null ? getServerRegion(this.uid) : null;
this.lang = options.lang;
}
/**
* Create Genshin Object
* Retrieves daily information.
*
* @param options IGenshinOptions Options
* @returns {Promise<Genshin>}
* @returns {Promise<IDailyInfo>} A promise that resolves to an IDailyInfo object.
*/
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("hk4e_global" /* GENSHIN_IMPACT */);
const uid = parseInt(game.game_uid);
instance.uid = uid;
instance.region = getServerRegion(uid);
async info() {
this.request.setParams({
lang: this.lang
}).setLang(this.lang);
const res = (await this.request.send(this.dailyInfoUrl)).data;
if (typeof res.first_bind === "undefined") {
res.first_bind = false;
}
return instance;
if (typeof res.month_last_day === "undefined") {
const today = /* @__PURE__ */ new Date();
const lastDayOfMonth = new Date(
today.getFullYear(),
today.getMonth() + 1,
0
).getDate();
res.month_last_day = today.getDate() === lastDayOfMonth;
}
if (typeof res.sign_cnt_missed === "undefined") {
res.sign_cnt_missed = 0;
}
if (typeof res.short_sign_day === "undefined") {
res.short_sign_day = 0;
}
return res;
}
/**
* Fetch game records
* Retrieve daily rewards information.
*
* @returns {Promise<IGenshinRecord>}
* @returns {Promise<IDailyRewards>} A promise that resolves to an IDailyRewards object.
*/
async rewards() {
this.request.setParams({
lang: this.lang
}).setLang(this.lang);
const res = (await this.request.send(this.dailyRewardUrl)).data;
if (typeof res.now === "undefined") {
res.now = Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3).toString();
}
if (this.game === "hk4e_global" /* GENSHIN_IMPACT */) {
res.biz = "hk4e";
} else if (this.game === "bh3_global" /* HONKAI_IMPACT */) {
res.biz = "hk4e";
} else if (this.game === "hkrpg_global" /* HONKAI_STAR_RAIL */) {
res.biz = "hkrpg";
} else {
res.biz = "";
}
if (typeof res.resign === "undefined") {
res.resign = false;
}
return res;
}
/**
* Get the daily reward for a specific day or the current day
*
* @param {number | null} day - The day to retrieve the reward for. If null, retrieve the reward for the current day.
* @returns {Promise<IDailyReward>} - A promise that resolves with the daily reward for the specified day or the current day
* @throws {HoyolabError} - If the specified day is not a valid date in the current month or if the reward for the specified day is undefined.
*/
async reward(day = null) {
const response = await this.rewards();
if (day === null) {
const now = response?.now ? new Date(parseInt(response.now) * 1e3) : /* @__PURE__ */ new Date();
day = now.getDate();
}
const date = /* @__PURE__ */ 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] === void 0) {
throw new HoyolabError(`${day} is not a valid date in this month.`);
}
return {
month: response.month,
now: response.now,
biz: response.biz,
resign: response.resign,
award: response.awards[day - 1]
};
}
/**
* Claim the daily rewards.
*
* @returns {Promise<IDailyClaim>} The claim information.
*/
async claim() {
this.request.setParams({
lang: this.lang
}).setLang(this.lang);
const response = await this.request.send(this.dailySignUrl, "POST");
const info = await this.info();
const reward = await this.reward();
if (response.retcode === -5003) {
return {
status: response.message,
code: -5003,
reward,
info
};
}
if (response.data?.code.toString().toLowerCase() === "ok" && response.retcode === 0) {
return {
status: response.message,
code: 0,
reward,
info
};
}
return {
status: response.message,
code: response.retcode,
reward: null,
info
};
}
};
// src/modules/redeem/redeem.route.ts
var RedeemRoute = class {
static redeem() {
return `${Routes.hke()}/common/apicdkey/api/webExchangeCdkey`;
}
};
// src/modules/redeem/redeem.ts
var RedeemModule = class {
/**
* Constructs a new RedeemModule object.
* @param request - The Request object used for making HTTP requests.
* @param lang - The language to use for the API response.
* @param game - The game to redeem the code for.
* @param region - The region of the user's account. If null, the API will use the default region for the game.
* @param uid - The user ID of the account. If null, the API will use the user ID associated with the provided auth cookies.
*/
constructor(request, lang, game, region, uid) {
this.request = request;
this.lang = lang;
this.game = game;
this.region = region;
this.uid = uid;
}
/**
* Redeems a code for a specific game and account.
*
* @param code - The code to redeem.
* @returns A promise that resolves to an IRedeemCode object containing information about the redemption status.
* @throws HoyolabError if the API returns an error.
* @remarks
* This method sends a request to the Genshin Impact API to get the daily note information for a user.
* The user's region and UID must be set before calling this method, otherwise an error will be thrown.
*/
async claim(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: this.game,
cdkey: code.replace(/\uFFFD/g, ""),
lang: this.lang,
sLangKey: this.lang
});
const res = await this.request.send(RedeemRoute.redeem());
return res;
}
};
// src/modules/records/records.enum.ts
var AbyssScheduleEnum = /* @__PURE__ */ ((AbyssScheduleEnum2) => {
AbyssScheduleEnum2[AbyssScheduleEnum2["CURRENT"] = 1] = "CURRENT";
AbyssScheduleEnum2[AbyssScheduleEnum2["PREVIOUS"] = 2] = "PREVIOUS";
return AbyssScheduleEnum2;
})(AbyssScheduleEnum || {});
// src/modules/records/records.route.ts
var RecordRoute = class {
static index() {
return `${this.baseUrl}/index`;
}
static character() {
return `${this.baseUrl}/character`;
}
static avatarBasicInfo() {
return `${this.baseUrl}/avatarBasicInfo`;
}
static spiralAbyss() {
return `${this.baseUrl}/spiralAbyss`;
}
static dailyNote() {
return `${this.baseUrl}/dailyNote`;
}
};
RecordRoute.baseUrl = `${Routes.bbs()}/game_record/genshin/api`;
// src/modules/records/records.ts
var RecordModule = class {
/**
* Creates an instance of RecordModule.
*
* @constructor
* @param {Request} request - An instance of Request class.
* @param {LanguageEnum} lang - The language code to be used in requests.
* @param {string | null} region - The server region code in which the user's account resides.
* @param {number | null} uid - The user ID of the Genshin Impact account.
*/
constructor(request, lang, region, uid) {
this.request = request;
this.lang = lang;
this.region = region;
this.uid = uid;
}
/**
* Get user's Genshin Impact record
*
* @async
* @function
* @returns {Promise<IGenshinRecord>} - User's Genshin Impact record
* @throws {HoyolabError} If UID parameter is missing or failed to be filled
* @remarks
* This method sends a request to the Genshin Impact API to get the daily note information for a user.
* The user's region and UID must be set before calling this method, otherwise an error will be thrown.
*/
async records() {

@@ -509,11 +846,18 @@ if (!this.region || !this.uid) {

server: this.region,
role_id: this.uid
role_id: this.uid,
lang: this.lang
}).setDs(true);
const res = (await this.request.send(GENSHIN_GAME_RECORD)).data;
const res = (await this.request.send(RecordRoute.index())).data;
return res;
}
/**
* Fetch obtained genshin characters with artifact, weapon, level and constellation
*
* @returns {Promise<IGenshinCharacters>}
* Retrieves the Genshin characters of the user.
*
* @async
* @returns {Promise<IGenshinCharacters>} A Promise that contains the Genshin characters object.
* @throws {HoyolabError} If UID parameter is missing or failed to be filled.
* @remarks
* This method sends a request to the Genshin Impact API to get the daily note information for a user.
* The user's region and UID must be set before calling this method, otherwise an error will be thrown.
*/

@@ -528,10 +872,14 @@ async characters() {

}).setDs(true);
const res = (await this.request.send(GENSHIN_CHARACTERS_LIST, "POST")).data;
const res = (await this.request.send(RecordRoute.character(), "POST")).data;
return res;
}
/**
* Fetch characters summary detail (name, rarity, weapon, icon)
* Returns the summary information of Genshin Impact game characters.
*
* @param characterIds number[] Characters ID
* @returns {Promise<IGenshinCharacterSummary>}
* @param characterIds - An array of character IDs to retrieve the summary information for.
* @returns A Promise that resolves to an object containing the summary information of the characters.
* @throws Throws an error if the UID parameter is missing or failed to be filled.
* @remarks
* This method sends a request to the Genshin Impact API to get the daily note information for a user.
* The user's region and UID must be set before calling this method, otherwise an error will be thrown.
*/

@@ -547,10 +895,14 @@ async charactersSummary(characterIds) {

}).setDs();
const res = (await this.request.send(GENSHIN_CHARACTERS_SUMMARY, "POST")).data;
const res = (await this.request.send(RecordRoute.avatarBasicInfo(), "POST")).data;
return res;
}
/**
* Fetch Spiral Abyss data
* Retrieves information about the player's performance in the Spiral Abyss.
*
* @param scheduleType AbyssScheduleEnum
* @returns {Promise<IGenshinSpiralAbyss>}
* @param scheduleType - The schedule type of the Abyss, either CURRENT or PREVIOUS.
* @returns A Promise that resolves with an object containing the player's Spiral Abyss data.
* @throws HoyolabError if UID parameter is missing or failed to be filled, or if the given scheduleType parameter is invalid.
* @remarks
* This method sends a request to the Genshin Impact API to get the daily note information for a user.
* The user's region and UID must be set before calling this method, otherwise an error will be thrown.
*/

@@ -569,9 +921,12 @@ async spiralAbyss(scheduleType = 1 /* CURRENT */) {

}).setDs();
const res = (await this.request.send(GENSHIN_SPIRAL_ABYSS)).data;
const res = (await this.request.send(RecordRoute.spiralAbyss())).data;
return res;
}
/**
* Fetch daily note resources (resin, home coin, expeditions, and transformer)
*
* @returns {Promise<IGenshinDailyNote>}
* Retrieve the daily note information for a Genshin Impact user.
* @returns Promise<IGenshinDailyNote> The daily note information.
* @throws HoyolabError if the UID parameter is missing or failed to be filled.
* @remarks
* This method sends a request to the Genshin Impact API to get the daily note information for a user.
* The user's region and UID must be set before calling this method, otherwise an error will be thrown.
*/

@@ -586,11 +941,68 @@ async dailyNote() {

}).setDs();
const res = (await this.request.send(GENSHIN_DAILY_NOTE)).data;
const res = (await this.request.send(RecordRoute.dailyNote())).data;
return res;
}
};
// src/modules/diary/diary.enum.ts
var DiaryMonthEnum = /* @__PURE__ */ ((DiaryMonthEnum2) => {
DiaryMonthEnum2[DiaryMonthEnum2["CURRENT"] = 3] = "CURRENT";
DiaryMonthEnum2[DiaryMonthEnum2["ONE_MONTH_AGO"] = 2] = "ONE_MONTH_AGO";
DiaryMonthEnum2[DiaryMonthEnum2["TWO_MONTH_AGO"] = 1] = "TWO_MONTH_AGO";
return DiaryMonthEnum2;
})(DiaryMonthEnum || {});
var DiaryEnum = /* @__PURE__ */ ((DiaryEnum3) => {
DiaryEnum3[DiaryEnum3["PRIMOGEMS"] = 1] = "PRIMOGEMS";
DiaryEnum3[DiaryEnum3["MORA"] = 2] = "MORA";
return DiaryEnum3;
})(DiaryEnum || {});
// src/modules/diary/diary.route.ts
var DiaryRoute = class {
/**
* Fetch genshin impact diary data
* Returns the URL for the diary list.
* @returns {string} The URL for the diary list.
*/
static list() {
return `${this.baseUrl}/event/ysledgeros/month_info`;
}
/**
* Returns the URL for the diary detail.
* @returns {string} The URL for the diary detail.
*/
static detail() {
return `${this.baseUrl}/event/ysledgeros/month_detail`;
}
};
/**
* The base URL for the routes.
*/
DiaryRoute.baseUrl = Routes.hke();
// src/modules/diary/diary.ts
var DiaryModule = class {
/**
* Constructs a DiaryModule instance
*
* @param month
* @returns {Promise<IGenshinDiaryInfo>}
* @param request - An instance of the Request class to make HTTP requests
* @param lang - A LanguageEnum value for the language of the user
* @param region - A string value for the region of the user
* @param uid - A number value for the UID of the user
*/
constructor(request, lang, region, uid) {
this.request = request;
this.lang = lang;
this.region = region;
this.uid = uid;
}
/**
* Returns the diary information of a given month for a user
*
* @param month - A DiaryMonthEnum value for the month of the diary information requested. Default is CURRENT.
* @returns A promise that resolves to an IGenshinDiaryInfo object
* @throws {@link HoyolabError} when the uid or region parameter is missing or invalid
* @remarks
* This method sends a request to the Genshin Impact API to get the daily note information for a user.
* The user's region and UID must be set before calling this method, otherwise an error will be thrown.
*/
async diaries(month = 3 /* CURRENT */) {

@@ -608,13 +1020,17 @@ if (!this.region || !this.uid) {

}).setDs();
const res = (await this.request.send(GENSHIN_DIARY)).data;
const res = (await this.request.send(DiaryRoute.list())).data;
return res;
}
/**
* Fetch history of received resources (primogems and mora) from diary
* Returns the diary details of a given type and month for a user
*
* @param type DiaryEnum
* @param month DiaryMonthEnum
* @returns {IGenshinDiaryDetail}
* @param type - A DiaryEnum value for the type of diary details requested
* @param month - A DiaryMonthEnum value for the month of the diary details requested. Default is CURRENT.
* @returns A promise that resolves to an IGenshinDiaryDetail object
* @throws {@link HoyolabError} when the uid or region parameter is missing or invalid, or when the type or month parameter is invalid
* @remarks
* This method sends a request to the Genshin Impact API to get the daily note information for a user.
* The user's region and UID must be set before calling this method, otherwise an error will be thrown.
*/
async diaryDetail(type, month = 3 /* CURRENT */) {
async detail(type, month = 3 /* CURRENT */) {
if (!this.region || !this.uid) {

@@ -641,3 +1057,3 @@ throw new HoyolabError("UID parameter is missing or failed to be filled");

}).setDs();
const res = await (await this.request.send(GENSHIN_DIARY_DETAIL)).data;
const res = await (await this.request.send(DiaryRoute.detail())).data;
responses.uid = res.uid;

@@ -666,53 +1082,192 @@ responses.region = res.region;

}
};
// src/games/gi/gi.enum.ts
var GenshinRegion = /* @__PURE__ */ ((GenshinRegion2) => {
GenshinRegion2["USA"] = "os_usa";
GenshinRegion2["EUROPE"] = "os_euro";
GenshinRegion2["ASIA"] = "os_asia";
GenshinRegion2["CHINA_TAIWAN"] = "os_cht";
return GenshinRegion2;
})(GenshinRegion || {});
// src/games/gi/gi.helper.ts
function getGenshinRegion(uid) {
const server_region = Number(uid.toString().trim().slice(0, 1));
let key;
switch (server_region) {
case 6:
key = "USA";
break;
case 7:
key = "EUROPE";
break;
case 8:
key = "ASIA";
break;
case 9:
key = "CHINA_TAIWAN";
break;
default:
throw new HoyolabError(`Given UID ${uid} is invalid !`);
}
return GenshinRegion[key];
}
// src/games/gi/gi.ts
var GenshinImpact = class {
/**
* Fetch Daily login information
* Constructs a new `Genshin` object.
* @param options The options object used to configure the object.
* @param options.cookie The cookie string or object to be used in requests.
* @param options.uid The UID of the user.
* @param options.region The region of the user.
* @param options.lang The language to be used in requests.
*/
constructor(options) {
const cookie = typeof options.cookie === "string" ? Cookie.parseCookieString(options.cookie) : options.cookie;
this.cookie = cookie;
if (!options.lang) {
options.lang = Language.parseLang(cookie.mi18nLang);
}
this.request = new Request(Cookie.parseCookie(this.cookie));
this.request.setReferer(Routes.referer());
this.request.setLang(options.lang);
this.uid = options.uid ?? null;
this.region = this.uid !== null ? getGenshinRegion(this.uid) : null;
this.lang = options.lang;
this.daily = new DailyModule(
this.request,
this.lang,
"hk4e_global" /* GENSHIN_IMPACT */
);
this.redeem = new RedeemModule(
this.request,
this.lang,
"hk4e_global" /* GENSHIN_IMPACT */,
this.region,
this.uid
);
this.record = new RecordModule(
this.request,
this.lang,
this.region,
this.uid
);
this.diary = new DiaryModule(this.request, this.lang, this.region, this.uid);
}
/**
* Create a new instance of the GenshinImpact class asynchronously.
*
* @returns {Promise<IGenshinDailyInfo>}
* @param options The options object used to configure the object.
* @param options.cookie The cookie string or object to be used in requests.
* @param options.lang The language to be used in requests.
* @returns A promise that resolves with a new Genshin instance.
*/
async dailyInfo() {
this.request.setParams({
act_id: "e202102251931481",
lang: this.lang
}).setLang(this.lang);
const res = (await this.request.send(GENSHIN_DAILY_INFO)).data;
return res;
static async create(options) {
if (typeof options.uid === "undefined") {
const hoyolab = new Hoyolab({
cookie: options.cookie
});
const game = await hoyolab.gameAccount("hk4e_global" /* GENSHIN_IMPACT */);
options.uid = parseInt(game.game_uid);
options.region = getGenshinRegion(parseInt(game.game_uid));
}
return new GenshinImpact(options);
}
/**
* Fetch all rewards from daily login
* Get user's Genshin Impact record
*
* @returns {Promise<IGenshinDailyRewards>}
* @alias {@link GenshinImpact.record | Genshin.record.records()}
* @deprecated Use through {@link GenshinImpact.record | Genshin.record.records()} instead
*/
async dailyRewards() {
this.request.setParams({
act_id: "e202102251931481",
lang: this.lang
}).setLang(this.lang);
const res = (await this.request.send(GENSHIN_DAILY_REWARD)).data;
return res;
async records() {
return this.record.records();
}
/**
* Fetch reward from daily login based on day
* Retrieves the Genshin characters of the user.
*
* @alias {@link GenshinImpact.record | Genshin.record.characters()}
* @deprecated Use through {@link GenshinImpact.record | Genshin.record.characters()} instead
*/
async characters() {
return this.record.characters();
}
/**
* Returns the summary information of Genshin Impact game characters
*
* @param characterIds number[] Characters ID
* @alias {@link GenshinImpact.record | Genshin.record.charactersSummary()}
* @deprecated Use through {@link GenshinImpact.record | Genshin.record.charactersSummary()} instead
*/
async charactersSummary(characterIds) {
return this.record.charactersSummary(characterIds);
}
/**
* Retrieves information about the player's performance in the Spiral Abyss.
*
* @param scheduleType AbyssScheduleEnum
* @alias {@link GenshinImpact.record | Genshin.record.spiralAbyss()}
* @deprecated Use through {@link GenshinImpact.record | Genshin.record.spiralAbyss()} instead
*/
async spiralAbyss(scheduleType = 1 /* CURRENT */) {
return this.record.spiralAbyss(scheduleType);
}
/**
* Retrieve the daily note information for a Genshin Impact user.
*
* @alias {@link GenshinImpact.record | Genshin.record.dailyNote()}
* @deprecated Use through {@link GenshinImpact.record | Genshin.record.dailyNote()} instead
*/
async dailyNote() {
return this.record.dailyNote();
}
/**
* Returns the diary information of a given month for a user
*
* @param month
* @alias {@link GenshinImpact.diary | Genshin.diary.diaries()}
* @deprecated Use through {@link GenshinImpact.diary | Genshin.diary.diaries()} instead
*/
async diaries(month = 3 /* CURRENT */) {
return this.diary.diaries(month);
}
/**
* Returns the diary details of a given type and month for a user
*
* @param type DiaryEnum
* @param month DiaryMonthEnum
* @alias {@link GenshinImpact.diary | Genshin.diary.detail()}
* @deprecated Use through {@link GenshinImpact.diary | Genshin.diary.detail()} instead
*/
async diaryDetail(type, month = 3 /* CURRENT */) {
return this.diary.detail(type, month);
}
/**
* Retrieves daily information.
*
* @alias {@link GenshinImpact.daily | Genshin.daily.info()}
* @deprecated Use through {@link GenshinImpact.daily | Genshin.daily.info()} instead
*/
dailyInfo() {
return this.daily.info();
}
/**
* Retrieve daily rewards information.
*
* @alias {@link GenshinImpact.daily | Genshin.daily.rewards()}
* @deprecated Use through {@link GenshinImpact.daily | Genshin.daily.rewards()} instead
*/
dailyRewards() {
return this.daily.rewards();
}
/**
* Get the daily reward for a specific day or the current day
*
* @param day number | null
* @returns {Promise<IGenshinDailyReward>}
* @alias {@link GenshinImpact.daily | Genshin.daily.reward()}
* @deprecated Use through {@link GenshinImpact.daily | Genshin.daily.reward()} instead
*/
async dailyReward(day = null) {
const response = await this.dailyRewards();
if (day === null) {
const now = new Date(Number(response.now) * 1e3);
day = now.getDate();
}
const date = /* @__PURE__ */ 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] === void 0) {
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]
};
dailyReward(day = null) {
return this.daily.reward(day);
}

@@ -722,61 +1277,61 @@ /**

*
* @returns {Promise<IGenshinDailyClaim>}
* @alias {@link GenshinImpact.daily | Genshin.daily.claim()}
* @deprecated Use through {@link GenshinImpact.daily | Genshin.daily.claim()} instead
*/
async dailyClaim() {
this.request.setParams({
act_id: "e202102251931481",
lang: this.lang
}).setLang(this.lang);
const response = await this.request.send(GENSHIN_DAILY_CLAIM, "POST");
const info = await this.dailyInfo();
const reward = await this.dailyReward();
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
};
dailyClaim() {
return this.daily.claim();
}
/* c8 ignore stop */
/**
* Redeem Code
* Redeems a code for a specific account.
*
* @param code string
* @returns {Promise<IRedeemCode>}
* @alias {@link GenshinImpact.daily | Genshin.redeem.claim()}
* @deprecated Use through {@link GenshinImpact.daily | Genshin.redeem.claim()} instead
*/
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(GENSHIN_REDEEM_CODE);
return res;
redeemCode(code) {
return this.redeem.claim(code);
}
};
// src/HonkaiStarRail.ts
// src/games/hsr/hsr.enum.ts
var HsrRegion = /* @__PURE__ */ ((HsrRegion2) => {
HsrRegion2["USA"] = "prod_official_asia";
HsrRegion2["EUROPE"] = "prod_official_euro";
HsrRegion2["ASIA"] = "prod_official_asia";
HsrRegion2["CHINA_TAIWAN"] = "prod_official_cht";
return HsrRegion2;
})(HsrRegion || {});
// src/games/hsr/hsr.helper.ts
function getHsrRegion(uid) {
const server_region = Number(uid.toString().trim().slice(0, 1));
let key;
switch (server_region) {
case 6:
key = "USA";
break;
case 7:
key = "EUROPE";
break;
case 8:
key = "ASIA";
break;
case 9:
key = "CHINA_TAIWAN";
break;
default:
throw new HoyolabError(`Given UID ${uid} is invalid !`);
}
return HsrRegion[key];
}
// src/games/hsr/hsr.ts
var HonkaiStarRail = class {
/**
* Create a new instance of HonkaiStarRail.
*
* @public
* @constructor
* @param {IHsrOptions} options - The options for the HonkaiStarRail instance.
*/
constructor(options) {

@@ -786,20 +1341,34 @@ const cookie = typeof options.cookie === "string" ? Cookie.parseCookieString(options.cookie) : options.cookie;

if (!options.lang) {
options.lang = parseLang(cookie.mi18nLang);
options.lang = Language.parseLang(cookie.mi18nLang);
}
this.request = new Request(Cookie.parseCookie(this.cookie));
this.request.setReferer(GENSHIN_GAME_RECORD_REFERER);
this.request.setReferer(Routes.referer());
this.request.setLang(options.lang);
this.uid = options.uid ?? null;
this.region = this.uid !== null ? getServerRegion(this.uid) : null;
this.region = this.uid !== null ? getHsrRegion(this.uid) : null;
this.lang = options.lang;
this.daily = new DailyModule(
this.request,
this.lang,
"hkrpg_global" /* HONKAI_STAR_RAIL */
);
this.redeem = new RedeemModule(
this.request,
this.lang,
"hkrpg_global" /* HONKAI_STAR_RAIL */,
this.region,
this.uid
);
}
/**
* Create StarRails Object
* Create a new instance of HonkaiStarRail using a Hoyolab account.
* If `uid` is not provided in the `options`, the account with the highest level will be used.
*
* @param options IHsrOptions Options
* @returns {Promise<HonkaiStarRail>}
* @public
* @static
* @param {IHsrOptions} options - The options for the HonkaiStarRail instance.
* @returns {Promise<HonkaiStarRail>} - A promise that resolves with a new HonkaiStarRail instance.
*/
static async create(options) {
const instance = new HonkaiStarRail(options);
if (instance.uid === null) {
if (typeof options.uid === "undefined") {
const hoyolab = new Hoyolab({

@@ -809,28 +1378,23 @@ cookie: options.cookie

const game = await hoyolab.gameAccount("hkrpg_global" /* HONKAI_STAR_RAIL */);
const uid = parseInt(game.game_uid);
instance.uid = uid;
instance.region = getServerRegion(uid);
options.uid = parseInt(game.game_uid);
options.region = getHsrRegion(parseInt(game.game_uid));
}
return instance;
return new HonkaiStarRail(options);
}
async dailyInfo() {
this.request.setParams({
act_id: "e202303301540311",
lang: this.lang
}).setLang(this.lang);
const res = (await this.request.send(HSR_DAILY_INFO)).data;
return res;
/**
* Retrieves daily information.
*
* @alias {@link DailyModule.info | DailyModule.info }
* @deprecated Use through { @link HonkaiStarRail.daily | HonkaiStarRail.daily.info() } instead
*/
dailyInfo() {
return this.daily.info();
}
/**
* Fetch all rewards from daily login
*
* @returns {Promise<IHsrDailyRewards>}
* @alias {@link DailyModule.rewards | DailyModule.rewards }
* @deprecated Use through { @link HonkaiStarRail.daily | HonkaiStarRail.daily.rewards() } instead
*/
async dailyRewards() {
this.request.setParams({
act_id: "e202303301540311",
lang: this.lang
}).setLang(this.lang);
const res = (await this.request.send(HSR_DAILY_REWARD)).data;
return res;
dailyRewards() {
return this.daily.rewards();
}

@@ -841,23 +1405,7 @@ /**

* @param day number | null
* @returns {Promise<IHsrDailyReward>}
* @alias {@link DailyModule.reward | DailyModule.reward }
* @deprecated Use through { @link HonkaiStarRail.daily | HonkaiStarRail.daily.reward() } instead
*/
async dailyReward(day = null) {
const response = await this.dailyRewards();
if (day === null) {
const now = /* @__PURE__ */ new Date();
day = now.getDate();
}
const date = /* @__PURE__ */ 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] === void 0) {
throw new HoyolabError(`${day} is not a valid date in this month.`);
}
return {
month: response.month,
biz: response.biz,
resign: response.resign,
award: response.awards[day - 1]
};
dailyReward(day = null) {
return this.daily.reward(day);
}

@@ -867,58 +1415,148 @@ /**

*
* @returns {Promise<IHsrDailyClaim>}
* @alias {@link DailyModule.claim | DailyModule.claim }
* @deprecated Use through { @link HonkaiStarRail.daily | HonkaiStarRail.daily.claim() } instead
*/
async dailyClaim() {
this.request.setParams({
act_id: "e202303301540311",
lang: this.lang
}).setLang(this.lang);
const response = await this.request.send(HSR_DAILY_CLAIM, "POST");
const info = await this.dailyInfo();
const reward = await this.dailyReward();
if (response.retcode === -5003) {
return {
status: response.message,
code: -5003,
reward,
info
};
dailyClaim() {
return this.daily.claim();
}
/**
* Redeem Code
*
* @param code string
* @alias {@link RedeemModule.claim | RedeemModule.claim }
* @deprecated Use through { @link HonkaiStarRail.redeem | HonkaiStarRail.redeem.claim() } instead
*/
redeemCode(code) {
return this.redeem.claim(code);
}
};
// src/games/hi/hi.enum.ts
var HonkaiRegion = /* @__PURE__ */ ((HonkaiRegion2) => {
HonkaiRegion2["USA"] = "usa01";
HonkaiRegion2["EUROPE"] = "eur01";
HonkaiRegion2["ASIA"] = "overseas01";
return HonkaiRegion2;
})(HonkaiRegion || {});
// src/games/hi/hi.helper.ts
function getHi3Region(uid) {
let key;
if (uid > 1e7 && uid < 1e8) {
key = "ASIA";
} else if (uid > 1e8 && uid < 2e8) {
key = "USA";
} else if (uid > 2e8 && uid < 3e8) {
key = "EURO";
} else {
throw new HoyolabError(`Given UID ${uid} is invalid !`);
}
return HonkaiRegion[key];
}
// src/games/hi/hi.ts
var HonkaiImpact = class {
/**
* Create a new instance of HonkaiImpact.
*
* @public
* @constructor
* @param {IHi3Options} options - The options for the HonkaiImpact instance.
*/
constructor(options) {
const cookie = typeof options.cookie === "string" ? Cookie.parseCookieString(options.cookie) : options.cookie;
this.cookie = cookie;
if (!options.lang) {
options.lang = Language.parseLang(cookie.mi18nLang);
}
if (String(response.data.code).toLocaleLowerCase() === "ok" && response.retcode === 0) {
return {
status: response.message,
code: 0,
reward,
info
};
this.request = new Request(Cookie.parseCookie(this.cookie));
this.request.setReferer(Routes.referer());
this.request.setLang(options.lang);
this.uid = options.uid ?? null;
this.region = this.uid !== null ? getHi3Region(this.uid) : null;
this.lang = options.lang;
this.daily = new DailyModule(
this.request,
this.lang,
"bh3_global" /* HONKAI_IMPACT */
);
this.redeem = new RedeemModule(
this.request,
this.lang,
"bh3_global" /* HONKAI_IMPACT */,
this.region,
this.uid
);
}
/**
* Create a new instance of HonkaiImpact using a Hoyolab account.
* If `uid` is not provided in the `options`, the account with the highest level will be used.
*
* @public
* @static
* @param {IHi3Options} options - The options for the HonkaiImpact instance.
* @returns {Promise<HonkaiImpact>} - A promise that resolves with a new HonkaiImpact instance.
*/
static async create(options) {
if (typeof options.uid === "undefined") {
const hoyolab = new Hoyolab({
cookie: options.cookie
});
const game = await hoyolab.gameAccount("bh3_global" /* HONKAI_IMPACT */);
options.uid = parseInt(game.game_uid);
options.region = getHi3Region(parseInt(game.game_uid));
}
return {
status: response.message,
code: response.retcode,
reward: null,
info
};
return new HonkaiImpact(options);
}
/* c8 ignore stop */
/**
* Retrieves daily information.
*
* @alias {@link DailyModule.info | DailyModule.info }
* @deprecated Use through { @link HonkaiImpact.daily | HonkaiImpact.daily.info() } instead
*/
dailyInfo() {
return this.daily.info();
}
/**
*
* @alias {@link DailyModule.rewards | DailyModule.rewards }
* @deprecated Use through { @link HonkaiImpact.daily | HonkaiImpact.daily.rewards() } instead
*/
dailyRewards() {
return this.daily.rewards();
}
/**
* Fetch reward from daily login based on day
*
* @param day number | null
* @alias {@link DailyModule.reward | DailyModule.reward }
* @deprecated Use through { @link HonkaiImpact.daily | HonkaiImpact.daily.reward() } instead
*/
dailyReward(day = null) {
return this.daily.reward(day);
}
/**
* Claim current reward
*
* @alias {@link DailyModule.claim | DailyModule.claim }
* @deprecated Use through { @link HonkaiImpact.daily | HonkaiImpact.daily.claim() } instead
*/
dailyClaim() {
return this.daily.claim();
}
/**
* Redeem Code
*
* @param code string
* @returns {Promise<IRedeemCode>}
* @alias {@link RedeemModule.claim | RedeemModule.claim }
* @deprecated Use through { @link HonkaiImpact.redeem | HonkaiImpact.redeem.claim() } instead
*/
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: "hkrpg_global" /* HONKAI_STAR_RAIL */,
cdkey: code.replace(/\uFFFD/g, ""),
lang: this.lang,
sLangKey: this.lang
});
const res = await this.request.send(GENSHIN_REDEEM_CODE);
return res;
redeemCode(code) {
return this.redeem.claim(code);
}
};
// src/index.ts
var Genshin = class extends GenshinImpact {
};
// Annotate the CommonJS export names for ESM import in node:

@@ -929,16 +1567,26 @@ 0 && (module.exports = {

Cookie,
DailyModule,
DiaryEnum,
DiaryModule,
DiaryMonthEnum,
GamesEnum,
Genshin,
GenshinImpact,
GenshinRegion,
HonkaiImpact,
HonkaiRegion,
HonkaiStarRail,
Hoyolab,
HoyolabError,
HsrRegion,
Language,
LanguageEnum,
RecordModule,
RedeemModule,
Request,
Route,
getServerRegion,
parseLang,
toCamelCase,
toSnakeCase
delay,
generateDS,
getGenshinRegion,
getHi3Region,
getHsrRegion
});
{
"name": "@vermaysha/hoyolab-api",
"version": "3.1.2",
"version": "3.2.0-beta.0",
"description": "Its unofficial HoYoLab API Wrapper for getting hoyoverse some in-game data, including Genshin Impact, Honkai Impact 3rd.",

@@ -15,2 +15,4 @@ "main": "dist/index.js",

"scripts": {
"docs:dev": "cross-env NODE_OPTIONS=--openssl-legacy-provider vuepress dev docs",
"docs:build": "cross-env NODE_OPTIONS=--openssl-legacy-provider vuepress build docs",
"format": "prettier src/**/* -w",

@@ -20,6 +22,9 @@ "lint": "eslint src/**/* --fix",

"build:ts": "tsup",
"build:docs": "typedoc",
"build": "npm run build:docs && npm run build:ts",
"test": "ava",
"test:coverage": "c8 ava"
"build:all": "run-p docs:build build:ts",
"build": "run-s type-check build:all",
"test": "run-s type-check ava",
"test:coverage": "run-s type-check ava:coverage",
"ava": "ava",
"ava:coverage": "c8 ava",
"type-check": "tsc"
},

@@ -76,9 +81,11 @@ "repository": {

"@types/eslint": "^8.37.0",
"@types/md5": "^2.3.2",
"@types/node": "^18.15.11",
"@types/node": "^20.0.0",
"@types/prettier": "^2.7.2",
"@typescript-eslint/eslint-plugin": "^5.57.0",
"@typescript-eslint/parser": "^5.57.0",
"@vuepress/plugin-back-to-top": "^1.9.9",
"@vuepress/plugin-pwa": "^1.9.9",
"ava": "^5.2.0",
"c8": "^7.13.0",
"cross-env": "^7.0.3",
"dotenv": "^16.0.3",

@@ -89,2 +96,3 @@ "eslint": "^8.37.0",

"lint-staged": "^13.2.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.8.7",

@@ -95,13 +103,12 @@ "rimraf": "^5.0.0",

"tsx": "^3.12.6",
"typedoc": "^0.23.28",
"typedoc-plugin-coverage": "^2.0.0",
"typedoc-plugin-extras": "^2.3.2",
"typedoc-plugin-mdn-links": "^3.0.3",
"typedoc-plugin-versions": "^0.2.3",
"typescript": "^5.0.3"
"typedoc": "^0.24.6",
"typedoc-plugin-markdown": "^3.15.3",
"typescript": "^5.0.3",
"vuepress": "^1.9.9",
"vuepress-plugin-typedoc": "^0.12.1"
},
"dependencies": {
"axios": "^1.3.4",
"md5": "^2.3.0"
"node-cache": "^5.1.2"
}
}
<div align="center">
<h1>HoYoLab API - TypeScript/JavaScript HoYoLab API (ESM only)</h1>
<h1>HoYoLab API - TypeScript/JavaScript HoYoLab API</h1>

@@ -4,0 +4,0 @@ <p>

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