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

anilist-node-api

v0.0.1

Published

Node wrapper around Anilist Graphql Api.

Downloads

2

Readme

⚠ Warning

In Development 🔧

I won't recommend using it in production, yet... (Though I'm using 🙄)

🔗 Installation

# npm install anilist-node-api
yarn add anilist-node-api

⚡️ Usage

I haven't added much methods to it yet.

You can:-

  • Authenticate User.
  • Get the user's access token.
  • Run GraphQl Queries and Mutations.

🕺 Authenticating a User.

You'll need to install express (or perhaps fastify) first.

yarn add express # or fastify

You'll need this package (Obviously 😆).

yarn add anilist-node-api

Now we can actually write code.

const AniList = require("anilist-node-api").default;
// import Anilist from 'anilist-node-api'
const app = require("express")(); // Express

// Get your ClientId and ClientSecret from your Anilist Account.
const api = new AniList({
  client_id: process.env.CLIENT_ID,
  redirect_url: "Your URL" + "/callback",
  client_secret: process.env.CLIENT_SECRET,
});

app.get("/login", (req, res) => {
  res.redirect(
    // This will generate an OAuth Url and redirect the user.
    api.generateAuthUrl({
      state: "Meet You On Mars!", // This state will be available in /callback. This must be string (Life hack: JSON.stringify())
    })
  );
});

app.get("/callback", async (req, res) => {
  // This is very important... Read more here https://anilist.gitbook.io/anilist-apiv2-docs/overview/oauth/authorization-code-grant
  const code = req.query.code;

  // The state you defined while generating the Auth Url above...
  const state = req.query.state;

  try {
    // This will give you access token and refresh token.
    let {
      access_token,
      refresh_token,
      expires_in,
    } = await api.getAccessTokenFromCode(code);

    // Store them somewhere, Probably database...
    await someDb.store(access_token);

    // Or Just Set it up to the instance...(Security Issues)
    api.setAccessToken(access_token); // This way you can use Auth Queries of the API.

    // Probably some better response here :p
    res.send("OK");
  } catch (err) {
    // Incase Error wants to meet you...
    console.log(err);
    // Decide Yourself :p
    res.sendStatus(500).send("Not OK");
  }
});

// And We have this method too...
/*
 * Check for available queries
 * at:- https://anilist.co/graphiql
 *
 * Don't worry, I'll be adding direct methods too :p
 *
 */
app.get("/user/:id", async (req, res) => {
  // This query dosen't require authentication. but some do require...
  let data = await api.useGraphQL(
    `
query FavUser($id: Int!){
  User(id: $id){
    id
    name
  }
}
`,
    {
      id: 947500,
    }
  );

  res.json(data);
});

// And finally let's give express ears to listen...
app.listen(4000); // My prefered port :p

The methods used above are the only methods available right now.

These are more than enough to use it with graphql queries and mutations. Though I'll add direct methods for each query and mutations too...

🤟 Contributions

Contributions, issues and feature requests are welcome!

if you feel that something is missing, feel free to create an Issue.

❤ Support

Almost all the project I make are Open Source. To keep me supporting, consider supporting.

Do ⭐ this Project.

Well, I'll meet you on Mars.

Shinzou Wo Sasageyo ❤


Made with ❤ and TypeScript.