# shuttle-access

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

Latest version **3.1.1** (published 2022-04-20) · ISC license · 0 weekly downloads

## Install

```sh
npm install shuttle-access
pnpm add shuttle-access
yarn add shuttle-access
bun add shuttle-access
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.1.1 |
| Published | 2022-04-20 |
| First published | 2018-03-08 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 19.3 KB |
| Known vulnerabilities | 0 (+23 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Eben Roux |
| Maintainers | ebenroux |
| Keywords | shuttle, shuttle-access, identity, access-control, iam |

## Links

- npm: https://www.npmjs.com/package/shuttle-access
- Repository: https://github.com/shuttle-npm/shuttle-access
- Homepage: https://github.com/shuttle-npm/shuttle-access#readme
- Issues: https://github.com/shuttle-npm/shuttle-access/issues
- npm.io page: https://npm.io/package/shuttle-access

## Dependencies (2)

- [axios](https://npm.io/package/axios.md) ^0.26.1
- [shuttle-guard](https://npm.io/package/shuttle-guard.md) ^1.0.1

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 3.1.1 (latest) — 2022-04-20
- 3.1.0 — 2021-04-10
- 3.0.5 — 2021-03-28
- 3.0.4 — 2021-01-11
- 3.0.3 — 2021-01-03
- 3.0.2 — 2021-01-03
- 3.0.1 — 2021-01-03
- 3.0.0 — 2021-01-03
- 2.0.6 — 2020-09-07
- 2.0.5 — 2020-08-28
- 2.0.4 — 2020-08-02
- 2.0.3 — 2020-07-30
- 2.0.2 — 2020-07-30
- 2.0.1 — 2020-07-29
- 1.0.3 — 2019-06-06
- … 3 more at https://npm.io/package/shuttle-access/versions

## 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. |

---
_Source: https://npm.io/package/shuttle-access · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
