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

shuttle-access

v3.1.1

Published

Package for use in JavaScript applications to integrate with Shuttle.Access back-end.

Downloads

4

Readme

shuttle-access

Package for use in JavaScript applications to integrate with Shuttle.Access back-end.

npm install shuttle-access

Initialization

Create a new instance of Access:

import Access from 'shuttle-access';

var access = new Access('http://access-api-url');

You may also specify an options argument containing the following:

| Option | Default | Description | | --- | --- | --- | | storage | localStorage | A storage mechanism for the username and token values used for authentication. Must contain getItem(name), setItem(name, value), and removeItem(name) functions. |

import Access from 'shuttle-access';

var access = new Access('http://access-api-url', { 
    storage: {
        getItem: function(name) {},
        setItem: function(name, value) {},
        removeItem: function(name) {}
    }
});

Next we need to initialize the istance:

access.initilize(); // returns promise

This will retrieve all the anonymous permissions from the /permissions/anonymous endpoint and add them as type anonymous. The endpoint can also return an isUserRequired property on the response. If true then there are no users registered.

Should the storage contain a token then a shuttle-access will attempt to create a session by posting the token to the /sessions endpoint.

Login

access.login(credentials); // returns promise

Performs an explicit login by using the specified credentials which should contain either username and password, or token. The session-creation will be attempted by sending a POST to the /sessions endpoint using the following JSON body:

{
    username: credentials.username,
    password: credentials.password,
    token: credentials.token
}

A login expects the following response from the POST to the /sessions endpoint:

{
	registered: (boolean), // true when session registered; else false
	username: (string), // returns the username associated with the session
	token: (string), // a session token that is specific to the server 
	permissions: ['access://permission-on', 'another', ...]
}

If registered is true then the username and token will be set on the storage for future reference. Each permission will be stored as type user. In addition the username and token properties on the access instance will also be set.

Logout

access.logout();

The username and token properties on the access as well as the storage instances.

Permissions

Permissions are unique. The permissions may be accessed using the following methods:

| Method | Arguments | Description | | --- | --- | --- | | hasPermission | permission | Returns true if the permission is in the access instance; else false | | removePermission | permission | Removes the given permission, if found, from the access instance. | | addPermission | type, permission | The type is a grouping mechanism and the permission still has to be unique. | | removePermissions | type | Remove all permissions of the given type. |

Login status

var status = access.loginStatus;

Returns:

| Value | Description | | --- | --- | | user-required | When the /permissions/anonymous called returned isUserRequired. | | not-logged-in | When there is no token value. | | logged-in | When there is a token value. |