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

wrapper-mojang-api

v1.0.2

Published

Javascript wrapper for the Mojang API

Downloads

5

Readme

wrapper-mojang-api

Discord License: MIT NPM

wrapper-mojang-api is a simple JavaScript wrapper for the Mojang API. The package is divided into 2 submodules: Yggdrasil for authentication, and Mojang for requests to the Mojang API. All requests are done asynchronously using the axios package.

Installation

npm install --save wrapper-mojang-api

Example

This example shows how you can change an accounts username using wrapper-mojang-api

const { Yggdrasil, Mojang } = require("wrapper-mojang-api");

const email = "[email protected]";
const password = "password";
const questions = ["answer", "answer", "answer"];
const newName = "newname";

const main = async () => {
  const { accessToken, selectedProfile } = await Yggdrasil.authenticate(email, password);

  if (await Mojang.needSecurity(accessToken)) await Mojang.answerSecurity(accessToken, questions);

  try {
    await Mojang.changeName(selectedProfile.id, password, newName, accessToken);
    console.log("Name changed to "+ newName);
  } catch (err) {
    console.log("Name change failed. Error code "+err.response.status);
  }

}

main();

Usage

Yggdrasil.authenticate(email, password, requestUser = false)

Authenticates your account, gives you accessToken.

Parameters:

  • email - email of the account
  • password - password of the account
  • requestUser - optional parameter which defaults to false. Adds user object with aditional information to the response

Response:

{
  "accessToken": "",
  "clientToken": "",
  "availableProfiles": [ { "name": "", "id": "" } ],
  "selectedProfile": { "name": "", "id": "" }
}

Yggdrasil.validate(token)

Checks if your accessToken is still valid.

Parameters:

  • token- access token obtained through authentication

Response:

  • true or false

Mojang.check()

Returns status of various Mojang services. Possible values are green (no issues), yellow (some issues), red (service unavailable).

Response:

[
  { "minecraft.net": "green" },
  { "session.minecraft.net": "green" },
  { "account.mojang.com": "green" },
  { "authserver.mojang.com": "green" },
  { "sessionserver.mojang.com": "red" },
  { "api.mojang.com": "green" },
  { "textures.minecraft.net": "green" },
  { "mojang.com": "green" }
]

Mojang.nameToUuid(names)

Returns a list of corresponding uuids to a list of given names

Parameters:

  • names - Either a username or an array of usernames

Response:

[
    {
        "id": "0d252b7218b648bfb86c2ae476954d32",
        "name": "maksimkurb",
        "legacy": true,
        "demo": true
    }
]
  • legacy(unmigrated) and demo(unpaid) only appear when true

Mojang.uuidAt(username, time = 0)

Returns the uuid of the account which had the specified username at the specified time

Parameters:

  • username - Minecraft username
  • time - Date object or unix timestamp (time in seconds since 1-1-1970). Or if it is 0 it will return the original name's owner given that the name was changed.

Response:

{
  "id": "7125ba8b1c864508b92bb5c042ccfe2b",
  "name": "KrisJelbring"
}

Mojang.nameHistory(uuid)

Returns history of usernames of an account

Parameters:

  • uuid - uuid of account

Response:

[
  {
    "name": "Gold"
  },
  {
    "name": "Diamond",
    "changedToAt": 1414059749000
  }
]

Mojang.profile(uuid)

This returns the profile of the requested user (username, skin, cape...). You can only request the same profile 1 time a minute.

Parameters:

  • uuid - uuid of account

Response:

{
    "id": "<profile identifier>",
    "name": "<player name>",
    "properties": [
        {
            "name": "textures",
            "value": "<base64 string>",
        }
    ]
}

Mojang.changeName(uuid, password, name, token)

This changes the name of the given account

Parameters:

  • uuid - the uuid of account
  • password the password of account
  • name - the desired name
  • token - access token obtained through authentication

Response:

  • 204 - Success
  • 400 - Name is unavailable
  • 401 - Unauthorized
  • 403 - Forbidden
  • 504 - Timed out

Mojang.reserveName(name, token)

Reserve name for an account for 24 hours. Also known as blocking

Parameters:

  • name - the desired name
  • token- access token obtained through authentication

Response:

  • 204 - Success
  • 400 - Name is unavailable
  • 401 - Unauthorized
  • 403 - Forbidden
  • 504 - Timed out

Mojang.needSecurity(token)

Returns whether or not you need to answer security questions for this ip address.

Parameters:

  • token- access token obtained through authentication

Response:

  • true or false

Mojang.getSecurity(token)

Returns your security questions and the answer id's that need to be sent along with the answers

Parameters:

  • token- access token obtained through authentication

Response:

[
  {
    "answer": {"id": 123},
    "question": {
      "id": 1,
      "question": "What is your favorite pet's name?"
    }
  },
  {
    "answer": {"id": 456},
    "question": {
      "id": 2,
      "question": "What is your favorite movie?"
    }
  },
  {
    "answer": {"id": 789},
    "question": {
      "id": 3,
      "question": "What is your favorite author's last name?"
    }
  }
]

Mojang.answerSecurity(token, questions)

Answers your security questions. If you do not have any (SFA alt) it skips

Parameters:

  • token- access token obtained through authentication
  • questions - an array containing the 3 answers to your security questions

Contributors

License

wrapper-mojang-api is licensed under the MIT license.