# nap-service

> Node API Provider is a highly-configurable express API provider based on mongoose that support authentification and roles

Latest version **0.1.3** (published 2014-09-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install nap-service
pnpm add nap-service
yarn add nap-service
bun add nap-service
```

## 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.3 |
| Published | 2014-09-13 |
| First published | 2014-09-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Vinz243 |
| Maintainers | vinz243 |
| Keywords | express, api, restful, rest, http |

## Links

- npm: https://www.npmjs.com/package/nap-service
- Repository: https://github.com/OpenCubes/Nap
- Issues: https://github.com/OpenCubes/Nap/issues
- npm.io page: https://npm.io/package/nap-service

## Dependencies (3)

- [q](https://npm.io/package/q.md) ~1.0.1
- [q-io](https://npm.io/package/q-io.md) ~1.11.4
- [connect-multiparty](https://npm.io/package/connect-multiparty.md) ^1.2.4

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 0.1.3 (latest) — 2014-09-13
- 0.1.2 — 2014-09-13

## README

Nap
===
[![Built with Grunt](https://cdn.gruntjs.com/builtwith.png)](http://gruntjs.com/)
[![Build Status](https://travis-ci.org/OpenCubes/Nap.svg?branch=master)](https://travis-ci.org/OpenCubes/Nap)

The highly-configurable RESTful HTTP service provider made for Express framework and Mongoose

### Using it

```js

var nap = require('nap');

api = nap(globalOptions);
api.add(modelObject);
api.inject(app);
```

### `globalOptions`

  - [ ] `authGroups`: an array containing all the different groups, ordered for a
    waterfall (last groups inherits the first group autorizations) (ex: `['guest'])

  - [ ] `getRole`: a function called wth two arguments, `userId` the id string,
    number or object corresponding to the current logged user and `callback`
    a function to be called with a string corresponding to the user role

  - [ ] `canThis`: overrides the canThis middleware. Injected a `this` object:
    - `config` the passed config
    - `getRole()` a **Promise** that wraps the `getRole`specified option
    - `deny()` call it to deny access
    - `allow()` the access
    - `url` current url
    - `params` the request params
    - `method` the HTTP method

### `modelObject`

  - [ ] `model` the model name or object
  - [ ] `authorizations` an object where the value is the method (GET, PUT...)
    and the value an array of user roles (cascading). Example:
    - `get: ["guest"]` everybody, from guests to admins will be able to GET
    - `post: ["user"]` only logged users or admins will be able to POST
    - `put: ["admin"]` only admin will be able to do this
  - [ ] `authorship` used when a user PUT his own mod he might be able to edit
    it even though he doesn't have the PUT authorization (see above).
    This is the name of the field that contains the author id.
  - [ ] `indexFields` the fields selected on `GET /{model}`
  - [ ] `dontBreak` don't put the selected fields as a new model

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