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

saweria

v2.0.1

Published

Node.js API Wrapper for [Saweria.co](https://saweria.co/)

Downloads

74

Readme

Saweria API

Node.js API Wrapper for Saweria.co

Check the Changelog

Installation

npm i saweria

Example

const { Client } = require("saweria");
// or
import { Client } from "saweria";

const client = new Client();

client.on("login", (user) => {
	console.log("Logged in as: ", user.username);
});

client.on("donations", (donations) => {
	console.log(donations);
});

client.login("email", "password");
// or with otp
client.login("email", "password", "otp");

or only for donation event listener

const { Client } = require("saweria");
// or
import { Client } from "saweria";

const client = new Client();

client.setStreamKey("your-stream-key");

client.on("donations", (donations) => {
	console.log(donations);
});

Client API

async login(jwt)

async login(email, password, otp = "")

Login to Saweria using JWT or email and password. If the account has no 2FA enabled, otp will be ignored.

This will set the default header authorization value for the future requests with user's JWT

Login with JWT is useful if your account has 2FA enabled and don't want to get your 2FA token every time you login. JWT generated by Saweria lasts for 72 hours, so you have to get a new JWT for your account every 72 hours. You can get your JWT by:

  1. Using this library
    1. Log in to your account using client.login(username, password)
    2. Get the account JWT from client.jwt
  2. Using the web client
    1. Go to saweria.co and login to your account
    2. Open browser developer console, and execute console.log(JSON.parse(localStorage["saweria-user-info"]).token);
  3. Sending a request to login endpoint
    1. Send a POST request to https://api.saweria.co/auth/login with these JSON body payload:
    {
    	"email": "[email protected]",
    	"password": "your-password",
    	"otp": "your otp code, optional if your account doesn't have 2FA enabled"
    }
    1. Get the JWT token from Authorization response header.

logout()

Removes authorization header from HTTP client, preventing future requests.


async setStreamKey(streamKey)

Set the client's stream key, this can be used to listen to donation event without logging in.


async getStreamKey()

Get user's stream key


async getUser()

Get user profile information


async getBalance()

Get user's balance


async getAvailableBalance()

Get user's available balance to disburse


async getTransaction(page = 1, pageSize = 15)

Get user's transaction list. Accepts these parameters:

  • page: What page of transaction to get (Default = 1)
  • pageSize: How many transactions per page (Default = 15)

async getMilestoneProgress(fromDate)

Get milestone progress from passed date with dd-mm-yyyy format until now.


async getLeaderboard(period = "all")

Get donation leaderboard from given time period.

period can be "all", "year", "month", or "week" (Default = "all")


async getVote()

Get currently active vote data


async sendFakeDonation()

Send a fake donation


on(eventName, callback)

Listen to client events and execute callback when emitted

Client Events

login

Emitted when client successfully logged in. Callback accepts User as the first parameter

Example:

client.on("login", (user) => {
	console.log("Logged in as: ", user.username);
});

donations

Emitted when client received a donation. Callback accepts array of EmittedDonation or EmittedMedia as the first parameter

Example:

client.on("donations", (donations) => {
	console.log(donations); // array of donations

	for (const donation of donations) {
		if (donation.type === "normal") {
			// normal donation
		} else if (donation.type === "media") {
			// donation with media
		}
	}
});

Normal Donation data example:

[
	{
		amount: "69420",
		donator: "Someguy",
		media: {
			src: [
				"https://media2.giphy.com/media/gw3IWyGkC0rsazTi/giphy.webp",
				"https://media2.giphy.com/media/gw3IWyGkC0rsazTi/giphy.mp4",
				"https://media2.giphy.com/media/gw3IWyGkC0rsazTi/giphy.gif",
			],
			tag: "picture",
		},
		message: "THIS IS A FAKE MESSAGE! HAVE A GOOD ONE",
		sound: {
			"1547679809default.ogg":
				"https://saweria-space.sgp1.cdn.digitaloceanspaces.com/prd/sound/836d7a85-dd70-4028-85fb-00fd785f0928-c527b4f6bd6282e21e78c85343d496fa.ogg",
		},
		tts: "...",
	},
];

Media Donation data example:

[
	{
		amount: "69420",
		donator: "Someguy",
		media: { end: 10, id: "RRKPkwBkz_0", start: 0, type: "yt" },
		message: "THIS IS A FAKE MESSAGE! HAVE A GOOD ONE",
		sound: null,
	},
];

donation

Similar to donations, but emits donation one by one when donations are received