# accessctrl

> AccessCtrl library to generate standard configuration based on the API resource comments to secure API access and also provide a method to verify that incoming request has the permission to access the resource or not.

Latest version **0.1.2** (published 2023-01-26) · MIT License license · 0 weekly downloads

## Install

```sh
npm install accessctrl
pnpm add accessctrl
yarn add accessctrl
bun add accessctrl
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2023-01-26 |
| First published | 2022-08-17 |
| Weekly downloads | 0 |
| License | MIT License |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 8.8 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Dinesh Vadivel |
| Maintainers | dineshhv |

## Links

- npm: https://www.npmjs.com/package/accessctrl
- Repository: https://github.com/vinmein/AccessCtrl
- Homepage: https://github.com/vinmein/AccessCtrl#readme
- Issues: https://github.com/vinmein/AccessCtrl/issues
- npm.io page: https://npm.io/package/accessctrl

## Dependencies (6)

- [fs](https://npm.io/package/fs.md) 0.0.1-security
- [buffer](https://npm.io/package/buffer.md) ^4.9.2
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [express](https://npm.io/package/express.md) ^4.18.1
- [map-files](https://npm.io/package/map-files.md) ^0.8.2
- [comment-parser](https://npm.io/package/comment-parser.md) ^1.3.1

## Recent versions

- 0.1.2 (latest) — 2023-01-26
- 0.1.1 — 2022-12-03
- 0.1.0 — 2022-08-19
- 0.0.9 — 2022-08-19
- 0.0.8 — 2022-08-19
- 0.0.7 — 2022-08-19
- 0.0.6 — 2022-08-19
- 0.0.5 — 2022-08-19
- 0.0.4 — 2022-08-19
- 0.0.3 — 2022-08-18
- 0.0.2 — 2022-08-18
- 0.0.1 — 2022-08-17

## README

# AccessCtrl
AccessCtrl library to generate standard configuration based on the API resource comments to secure API access and also provide a method to verify that incoming request has the permission to access the resource or not.



## License
[![MIT License](https://img.shields.io/badge/License-MIT-green.svg)](https://choosealicense.com/licenses/mit/)
## Features

- ACL Configuration Generator
- Resource level Access Verification


## Installation

```bash
  npm i accessctrl --save
```
    

## Usage/Examples

### Generate Access configuration JSON
```javascript
    /**
	 * @apiType POST
	 * @apiKey Create User
	 * @apiPath /api/i/user
	 * @apiGroup User
	 * @apiPermission admin
	 */
```

| Parameter | Description                |
| :-------- | :------------------------- |
| @apiType| **Required**. Methods GET, POST, PATCH, DELETE |
| @apipKey  | Unique Reference String     |
| @apiPath | **Required**. Resource Path |
| @apiGroup | **Required**. Resource Group, unique Value |
| @apiPermission | **Required**. comma seperated string e.g: admin,user,moderator|

### Usage
```javascript
    const list = accessCtrl.generateACL({
        source: "server/**/*.routes.js"  //location of the routes/controller
    });
```

### Output
```bash
  Generated Successfully
```

### Verify JSON

#### Prerequisite
Need Role priority

```javascript
  const rank = [
    { role: "user", priority: 3 },
    { role: "moderator", priority: 2 },
    { role: "admin", priority: 1 },
  ];
```

| Parameter | Description                |
| :-------- | :------------------------- |
| userRole| **Required**. ["user"] |
| requestPath  | **Required**. '/api/i/article"' Current request resource path  |
| requestMethod | **Required**. "POST" Current Request method |

### Usage
```javascript
    const accessCtrl = require("accessctrl");
    const aclConfig = require("./acl.json");

    accessCtrl.initAcl(rank, aclConfig)
    const status = accessCtrl.verifyPermission( userRole, requestPath, requestMethod);
```

### Output
```bash
  true/false
```

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