npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@teyvatdev/node-sdk

v2.0.5

Published

Unofficial Genshin API Wrapper (Teyvat API)

Downloads

8

Readme

Genshin Impact API wrapper for JavaScript and Typescript

This is an SDK node-js wrapper to aid connecting with Teyvat-API, which is an API to fetch info about the game Genshin Impact, by Mihoyo

Official links: [Npm] [Github] [Website] [Support] [API support]

Installation

Using Npm

npm i @teyvatdev/node-sdk

Why Teyvat-API?

This is an actual API wrapper, unlike most npm packages that stores json databases containing character data, this fetches and caches it locally from the API real time, so if the values change, you would normally require the author of the package to manually update their database, which forces users to need to update their package. This leads to apps needed to be shutdown for upgrades and updates. Unlike those, we fetch this data dynamically and check periodically for changes in the API itself, so the only updates you'll need to do on this package are major API changes, not related to the data, which is handled internally.

Index

In Node-js (JavaScript)

const Tey = require('@teyvatdev/node-sdk');

//Constructor
const tey = new Tey.default('Token Here');

//method getCharacter(), gets a character by name
tey.getCharacter('Amber').then((data) => {
  console.log(data);
  //Expected, Amber stats
});

In Node-js (TypeScript)

import { Teyvat } from '@teyvatdev/node-sdk';

//Constructor
const tey = new Teyvat('Token Here');

//method getCharacter(), gets a character by name
tey.getCharacter('Amber').then((data) => {
  console.log(data);
  //Expected, Amber stats
});

Constructor parameters

| Parameter | Type | Optional | Description | | -------------------- | ------- | -------- | ---------------------------------------------------------------------------------- | | token | String | No | Teyvat API token, read HERE to generate one | | options | Object | Yes | Object to be passed to the constructor | | options.aggressive | Boolean | Yes | This will fetch and cache all endpoints into the client, RAM expensive, be careful. Default: false | | options.cache | Boolean | Yes | This will enable or disable caching internally. Default: true | | options.silent | Boolean | Yes | This will make it so the library does not throw any logs or errors, be carefull, this can swallow important errors. Default: false |

Methods options

Method options have been deprecated in favor of a more "begginer friendly" lib. The library is set to cache and return all data by default, it'll search for cached first, and only fetch the missing entries. This was done to prevent accidental API abuse. If you plan on using custom requests, i made the method <Teyvat>.baseRequest() public for you to use, and as of that, i assume you are good to go on your own. Intellisense will help you.

[] means optional parameter

| Method | Params | Returns | Working Example(copy paste) | | ------------------------ | --------------- | ------------------- | -------------------------------------------------------------------------------------- | | getCharacter() | name | Object, null | let Amber = await tey.getCharacter('Amber'); | | getCharacters() | | Object[array], null | let Characters = await tey.getCharacters(); | | getWeapon() | ID | Object, null | let FavoniuSword = await tey.getWeapon('10'); | | getWeapons() | | Object[array], null | let Weapons = await tey.getWeapons(); | | getRegion() | CUID | Object, null | let Mondstad = await tey.getRegion('ckifg54kg0000vf0iclar2lp6'); | | getRegions() | | Object[array], null | let Regions = await tey.getRegions(); | | getRegion() | CUID | Object, null | let Anemo = await tey.getElement('ckifg2oxf0000n30i3k0e3s7m'); | | getRegions() | | Object[array], null | let Elements = await tey.getElements(); | | getTalent() | CUID | Object, null | let Divine_Marksmanship = await tey.getTalent('ckiqng1u300210ns6clktnh3c'); | | getTalents() | | Object[array], null | let Talents = await tey.getTalents();; | | getArtifacts() | | Object[array], null | let Artifacts = await tey.getArtifacts(); | | getArtifactSets() | | Object[array], null | let ArtifactSets = await tey.getArtifactSets(); | | getCharacterProfile() | CUID | Object, null | let AmberProfile = await tey.getCharacterProfile('ckiffwvsx0000990i1z9retm4'); | | getCharacterProfiles() | | Object[array], null | let CharacterProfiles = await tey.getCharacterProfiles(); | | flushCache() | [options] | | tey.flushCache() | | cacheAll() | | boolean | tey.cacheAll() Returns true if everything has been cached, false if something failed |

How to get your token

The lib now includes a method for creating an account and getting a token. Here are some snippets. You HAVE TO ACTIVATE IT in the email you provided


const Tey = require('@teyvatdev/node-sdk');

const email = '[email protected]';
const password = 'myfancypassword';
const username = 'myusername';

Tey.createAccount(email, username, password).then(res => {
  if (res) console.log('Success, now activate it on ur mail');
  else console.log('Something wrong happened!');
});
// AFTER YOU ACTIVATED IT, DONT RUN THE REST OR IT WILL ERROR
Tey.login(email, password).then(res => {
  if (!res) console.log('Failed to login! Did u make sure to active ur account in your email?');
  else console.log(res.token);
});

Events

Observations: the event ready will be emitted AFTER the lib has cached all entries if you provided the aggressive flag in the constructor options

| Event | Emits | Working Example(copy paste) | | ------------------------ | --------------- | -------------------------------------------------------------------------------------- | | ready | true , undefined | tey.on('ready', (ret) => { if(ret) console.log('Finished startup!'); }) | | restRequest | Object[data] | tey.on('restRequest', (req) => { console.log('request sent ', req) }) | | restError | Object[error] | tey.on('restError', (err) => { console.log('request returned an error ', err) }) | | errorHandler | Object[data] | tey.on('errorHandler', (err) => { console.log('the handler handled an error ', err) }) |

Internals

The lib is shielded with 200 http request status checks, the cache and the returns will only be used when the API sends an OK status. The lib has an internal error checker to pass the request and throw the appropriate errors. (Due to the nature of objects, it is recommended to use Visual Studio Code with a .vscode config without --outputCapture flag, otherwise objects might cause spam in console as they contain the error message and a trace for debugging )

Some other note worthy mentions is a ready state that waits the library to request data to the api on its construction, a rate limiter, a queue system to prevent spam, a cache flush and a retry method.