# @flexfactory/policy

> A policy library for use within Hotelflex services

Latest version **4.1.3** (published 2020-05-04) · UNLICENSED license · 0 weekly downloads

## Install

```sh
npm install @flexfactory/policy
pnpm add @flexfactory/policy
yarn add @flexfactory/policy
bun add @flexfactory/policy
```

## 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 | 4.1.3 |
| Published | 2020-05-04 |
| First published | 2019-09-12 |
| Weekly downloads | 0 |
| License | UNLICENSED |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 24.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Hotelflex Limited |
| Maintainers | richturnbull |

## Links

- npm: https://www.npmjs.com/package/@flexfactory/policy
- npm.io page: https://npm.io/package/@flexfactory/policy

## Recent versions

- 4.1.3 (latest) — 2020-05-04
- 4.1.2 — 2020-03-27
- 4.1.1 — 2020-03-26
- 4.1.0 — 2020-03-23
- 4.0.0 — 2020-03-23
- 2.0.1 — 2020-03-19
- 2.0.0 — 2020-03-18
- 1.1.8 — 2019-10-02
- 1.1.7 — 2019-09-27
- 1.1.6 — 2019-09-27
- 1.1.5 — 2019-09-26
- 1.1.4 — 2019-09-25
- 1.1.3 — 2019-09-25
- 1.1.2 — 2019-09-24
- 1.1.1 — 2019-09-20
- … 3 more at https://npm.io/package/@flexfactory/policy/versions

## README

# policy

## Install
```
npm i --save @flexfactory/policy
```

## Usage
Securing an endpoint
```javascript
const { Session } = require('@flexfactory/policy');

if(!ctx.session) {
  throw Boom.unauthorized();
}

const session = new Session(ctx.session);
const hasAccess = session.hasAccess({
  actions: ['read'],
  resources: ['svc:auth:accounts']
});

if(!hasAccess) {
  throw Boom.forbidden();
}

```
Checking token permissions
```javascript
const { Token } = require('@flexfactory/policy');

if(!tokenData) {
  throw Boom.unauthorized();
}

const token = new Token(tokenData);
const hasAccess = token.hasAccess({
  actions: ['read'],
  resources: ['svc:auth:accounts']
});

if(!hasAccess) {
  throw Boom.forbidden();
}

```

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