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

weverse

v0.1.4

Published

Wrapper for weverse private API

Downloads

18

Readme

Usage

Provide credentials

See MujyKun's guide on finding your Weverse access token.

import { WeverseClient } from "weverse";

const myClient = new WeverseClient({token: 'my-access-token'})
// or
const myClient = new WeverseClient({username: 'jonah', password: 'top-secret'})

Initialize

import { WeverseClient } from "weverse";

const myClient = new WeverseClient({token: 'my-access-token'})
await myClient.init({allPosts: true, allNotifications: false})

myClient.communities.forEach(community => {
    // typesafe objects with autocompletion
    const details = {
        name: community.name
        posts: community.posts.length
    }
    // do something
})

Listen for new notifications

import { WeverseClient } from "weverse";

const myClient = new WeverseClient({token: 'my-access-token'})
myClient.init({allPosts: true, allNotifications: false})

myClient.on('init', async (ready) => {
    if (ready) {
        myClient.listen({listen: true, interval: 5000})
    }
})

myClient.on('comment', (comment, post) => {
    // all objects are typed
    const commenter = myClient.artistById(comment.artist.id)
    const postAuthor = myClient.artistById(post.artist.id)
    console.log(`${commenter.name} commented on ${postAuthor.name}'s post!`)
})

myClient.on('post', (post) => {
    if (post.photos.length) {
        post.photos.forEach(photo => {
            downloadImage(photo.orgImgUrl)
        })
    }
})

Credit

All credit to MujyKun for reverse-engineering most of the Weverse endpoints used by this module.

Classes

WeverseEmitter

WeverseEmitter allows the WeverseClient to emit events and provides methods for doing so

Kind: global class

weverseEmitter.newError(err)

Kind: instance method of WeverseEmitter

| Param | Type | Description | | --- | --- | --- | | err | Error | The error to be emitted |

weverseEmitter.ready(initialized)

Kind: instance method of WeverseEmitter

| Param | Type | Description | | --- | --- | --- | | initialized | boolean | whether initialization succeeded |

weverseEmitter.newNotif(notification)

Kind: instance method of WeverseEmitter

| Param | Type | Description | | --- | --- | --- | | notification | WeverseNotification | new Notification to be emitted |

weverseEmitter.newPost(post)

Kind: instance method of WeverseEmitter

| Param | Type | Description | | --- | --- | --- | | post | WeversePost | new Post to be emitted |

weverseEmitter.newMedia(media)

Kind: instance method of WeverseEmitter

| Param | Type | Description | | --- | --- | --- | | media | WeverseMedia | new Media to be emitted |

weverseEmitter.newComment(comment, post)

Kind: instance method of WeverseEmitter

| Param | Type | Description | | --- | --- | --- | | comment | WeverseComment | the Comment that was retrieved | | post | WeversePost | the Post associated with the Comment |

weverseEmitter.loginResult(result)

Kind: instance method of WeverseEmitter

| Param | Type | Description | | --- | --- | --- | | result | boolean | boolean result of the login attempt |

weverseEmitter.polled(status)

Kind: instance method of WeverseEmitter

| Param | Type | Description | | --- | --- | --- | | status | boolean | result of the poll attempt. If true, Weverse was successfully polled |

WeverseClient

Client for the private Weverse api

Kind: global class
Emits: error, init, notification, post, media, comment, login, poll
Properties

| Name | Type | Description | | --- | --- | --- | | communities | Array.<WeverseCommunity> | The communities associated with the Weverse account | | artists | Array.<WeverseArtist> | All artists in all communities associated with the account | | notifications | ClientNotifications | Subclass handling all notifications for the account | | posts | Array.<WeversePost> | All posts that have been retrieved by this client |

new WeverseClient(authorization, verbose)

| Param | Type | Description | | --- | --- | --- | | authorization | WeverseAuthorization | either {token: string} or {username: string, password: string} | | verbose | boolean | optional; defaults to false |

weverseClient.init(options) ⇒ Promise.<void>

init options: allPosts: boolean - Whether to load all posts from each community into memory. This will be slow allNotifications: boolean - Whether to load all notifications for the Weverse account. Will be slow. allMedia: boolean - not currently implemented

Kind: instance method of WeverseClient
Access: public

| Param | Type | Description | | --- | --- | --- | | options | WeverseInitOptions | optional |

weverseClient.listen(opts)

Tells the client to start or stop listening for new notifications. Options: listen: boolean - Whether the client should be listening interval: boolean - Interval in MS to listen on process: boolean (optional) - Whether new notifications should be processed into Posts/Comments/Media

Kind: instance method of WeverseClient
Access: public

| Param | Type | | --- | --- | | opts | ListenOptions |

weverseClient.checker(process) ⇒ Promise.<void>

Method passed to setInterval if client is listening for new notifications

Kind: instance method of WeverseClient
Access: protected

| Param | Type | Description | | --- | --- | --- | | process | boolean | Whether to process new notifications into Posts/Comments/Media |

weverseClient.tryRefreshToken() ⇒ Promise.<boolean>

Attempts to use a refresh token to get a new Weverse access token

Kind: instance method of WeverseClient
Returns: Promise.<boolean> - Whether a new access token was granted
Access: public

weverseClient.login(credentials) ⇒ Promise.<void>

Only used for password authentication. Attempts to login either with login given when the client was created, or with optional credentials parameter

Kind: instance method of WeverseClient
Access: public

| Param | Type | Description | | --- | --- | --- | | credentials | WeversePasswordAuthorization | optional, will override initial credentials |

weverseClient.checkLogin() ⇒ Promise.<boolean>

Force a credentials check. If login has already been converted to a token, token will be checked.

Kind: instance method of WeverseClient
Returns: Promise.<boolean> - - whether the check was successful
Access: public

weverseClient.getCommunities(opts) ⇒ Promise.<Array.<WeverseCommunity>>

Load all communities associated with this Weverse account. Returns the communities but also adds them to the cache. Options: init: boolean - Whether this method was called by the init method and should skip the login check

Kind: instance method of WeverseClient
Access: public

| Param | Type | Description | | --- | --- | --- | | opts | GetOptions | optional |

weverseClient.getCommunityArtists(c, opts) ⇒ Promise.<(Array.<WeverseArtist>|null)>

Get the artists in a community. Adds them to the cache and returns. Options: init - whether this method was called by init method and the login check should be skipped

Kind: instance method of WeverseClient
Returns: Promise.<(Array.<WeverseArtist>|null)> - returns null if failed to fetch artists

| Param | Type | Description | | --- | --- | --- | | c | WeverseCommunity | | | opts | GetOptions | optional |

weverseClient.getNotifications(pages, process) ⇒ Promise.<(Array.<WeverseNotification>|null)>

Note: If process = true, events will be emitted for new notifications AND new Posts/Comments/Media

Kind: instance method of WeverseClient
Returns: Promise.<(Array.<WeverseNotification>|null)> - - Returns only new notifications not already in cache, or null on failure

| Param | Type | Description | | --- | --- | --- | | pages | number | Optional number of pages to get; defaults to 1 | | process | boolean | Whether notifications should be processed into Posts/Comments/Media |

weverseClient.getNewNotifications(opts) ⇒ Promise.<(Array.<WeverseNotification>|null)>

Get one page of the most recent notifications

Kind: instance method of WeverseClient

| Param | Type | Description | | --- | --- | --- | | opts | NewNotifications | {process: boolean} - whether to process notifications into content |

weverseClient.getMedia(id, community) ⇒ Promise.<(WeverseMedia|null)>

Get a specific media object by id Will first check local cache, then request from Weverse

Kind: instance method of WeverseClient
Returns: Promise.<(WeverseMedia|null)> - - Returns only if media did not exist in cache

| Param | Type | | --- | --- | | id | number | | community | WeverseCommunity |

weverseClient.getComments(p, c, cId?) ⇒ Promise.<(Array.<WeverseComment>|null)>

Gets all artist comments on a given post. Returns only new comments.

Kind: instance method of WeverseClient

| Param | Type | | --- | --- | | p | WeversePost | | c | WeverseCommunity | | cId? | number |

weverseClient.getPost(id, communityId) ⇒ Promise.<(WeversePost|null)>

Get one post by id. First checks the cache, then requests from Weverse.

Kind: instance method of WeverseClient
Access: public

| Param | Type | | --- | --- | | id | number | | communityId | number |

weverseClient.processNotification(n) ⇒ Promise.<void>

Process one notification. If it refers to a post, comment, or media, attempt to add to cache

Kind: instance method of WeverseClient

| Param | Type | | --- | --- | | n | WeverseNotification |

weverseClient.createLoginPayload() ⇒ void

Encrypt provided password with Weverse public RSA key and create payload to send to login endpoint Adds the payload as a property of the client, returns void

Kind: instance method of WeverseClient

weverseClient.checkToken() ⇒ Promise.<boolean>

Check if the current token (provided or recieved from Weverse) is valid

Kind: instance method of WeverseClient

weverseClient.handleResponse(response, url) ⇒ Promise.<boolean>

If the client receives a 401 unauthorized from Weverse, will attempt to refresh credentials

Kind: instance method of WeverseClient

| Param | Type | | --- | --- | | response | AxiosResponse | | url | string |

weverseClient.log()

Log something if verbose = true

Kind: instance method of WeverseClient

| Param | Type | | --- | --- | | ...vals | any |

weverseClient.communityById(id) ⇒ WeverseCommunity | null

Check the community hashmap for a given id

Kind: instance method of WeverseClient

| Param | Type | | --- | --- | | id | number |

weverseClient.artistById(id) ⇒ WeverseArtist | null

Check the artist hashmap for a given id

Kind: instance method of WeverseClient

| Param | Type | | --- | --- | | id | number |

weverseClient.post(id)

Check the post hashmap for a given id

Kind: instance method of WeverseClient

| Param | Type | | --- | --- | | id | number |

"error"

Error event

Kind: event emitted by WeverseClient

"init"

Init event Whether initialization was successful

Kind: event emitted by WeverseClient

"notification"

Notification event New notification

Kind: event emitted by WeverseClient

"post"

Post event New post

Kind: event emitted by WeverseClient

"media"

Media event New media

Kind: event emitted by WeverseClient

"comment"

Comment event New comment. Provides comment and post.

Kind: event emitted by WeverseClient

"login"

Login event Result of login attempt.

Kind: event emitted by WeverseClient

"poll"

Poll event Result of poll attempt.

Kind: event emitted by WeverseClient