open-index/open-npm huggingface dataset:
npm package: @malijs/metadata-field-auth
Description: Generic Mali metadata field authorization middleware
Author: Bojan D.
Latest version: 0.3.0

# @malijs/metadata-field-auth

Base middleware utility for metadata auth field checks for Mali

[![npm version](https://img.shields.io/npm/v/@malijs/metadata-field-auth.svg?style=flat-square)](https://www.npmjs.com/package/@malijs/metadata-field-auth)
[![build status](https://img.shields.io/travis/malijs/metadata-field-auth/master.svg?style=flat-square)](https://travis-ci.org/malijs/metadata-field-auth)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg?style=flat-square)](https://standardjs.com)
[![License](https://img.shields.io/github/license/malijs/metadata-field-auth.svg?style=flat-square)](https://raw.githubusercontent.com/malijs/metadata-field-auth/master/LICENSE)

## API

<a name="module_@malijs/metadata-field-auth"></a>

### @malijs/metadata-field-auth
Generic Mali metadata field authorization middleware
If the call has metadata with "authorization" string property with <code>"{field} {value}"</code> then specified function is called.


| Param | Type | Description |
| --- | --- | --- |
| field | <code>String</code> | Field within the authorization metadata value to look for. |
| options | <code>Options</code> |  |
| options.error | <code>String</code> \| <code>Object</code> \| <code>function</code> | optional Error creation options.                                                If <code>String</code> the message for Error to throw in case                                                authorization is not present.                                                If <code>Object</code> the error options with <code>message</code>,                                                <code>code</code>, and <code>metadata</code> properties. See <code>create-grpc-error</code>                                                module.                                                If <code>Function</code> a function with signature <code>(ctx)</code>                                                called to create an error. Must return an <code>Error</code> instanse.                                                Default: <code>"Not Authorized"</code> |
| fn | <code>function</code> | The middleware function to execute with signature <code>(key, ctx, next)</code> |

**Example**  
```js
const fieldAuth = require('@malijs/metadata-field-auth')

app.use(fieldAuth('secret', async (key, ctx, next) => {
  console.log(key)
  await next()
})
```
## License

  Apache-2.0
npm package: @malijs/param
Description: Mali request param middleware
Author: Bojan D.
Latest version: 0.3.0

# @malijs/param

Mali request param middleware

[![npm version](https://img.shields.io/npm/v/@malijs/param.svg?style=flat-square)](https://www.npmjs.com/package/@malijs/param)
[![build status](https://img.shields.io/travis/malijs/param/master.svg?style=flat-square)](https://travis-ci.org/malijs/param)

## API

<a name="module_@malijs/param"></a>

### @malijs/param
Mali param middleware. If the request object has the specified property
of specified type the middleware function is executed.
Only applies for <code>UNARY</code> and <code>RESPONSE_STREAM</code> call types.


| Param | Type | Description |
| --- | --- | --- |
| paramName | <code>String</code> | The name of the request object property |
| options | <code>Options</code> |  |
| options.type | <code>String</code> | Optional type of the param specified by <code>paramName</code> within the request.                                    Has to be one of possible values as returned by <code>typeof</code>. |
| options.truthy | <code>Boolean</code> | optional check for truthiness on the param value within the request.                                           Default: <code>false</code> |
| fn | <code>function</code> | The middleware function to execute |

**Example**  
```js
const param = require('@malijs/param')

async function appendDocType (id, ctx, next) {
  ctx.req.id = 'user::'.concat(id)
  await next()
}

app.use(param('id', { type'string', truthy: true }, appendDocType))
```
## License

  Apache-2.0
npm package: @malijs/requestid
Description: Mali request ID metadata middleware sources request ID into context
Author: Bojan D.
Latest version: 0.2.0

# @malijs/requestid

Mali request ID metadata middleware sources request ID into context

[![npm version](https://img.shields.io/npm/v/@malijs/requestid.svg?style=flat-square)](https://www.npmjs.com/package/@malijs/requestid)
[![build status](https://img.shields.io/travis/malijs/requestid/master.svg?style=flat-square)](https://travis-ci.org/malijs/requestid)

## API

<a name="module_@malijs/requestid"></a>

### @malijs/requestid
Mali request ID metadata middleware. If the call has metadata with the request ID
(or specified property) sets it into the context into target property. If request ID
is not present creates one using UUID and sets it into metadata and context.


| Param | Type | Description |
| --- | --- | --- |
| options | <code>Options</code> |  |
| options.name | <code>String</code> | Optional name of the metadata object property. Default: <code>'requestId'</code> |
| options.target | <code>String</code> \| <code>Boolean</code> | Optional name of the <code>ctx</code> property to set request id into.                                         If not provided it is equal to <code>options.name</code>. |
| options.generator | <code>function</code> | Synchronous function to generate the request id if not present.                                      Has to return a string. Default: <code>uuid</code> library. |

**Example**  
```js
const rid = require('@malijs/requestid')

app.use(rid())
app.use('myFn', async (ctx, next) => {
  console.log(ctx.requestId) // request ID from metadata
  await next()
})
```
## License

  Apache-2.0
npm package: @malijs/tojson
Description: Mali middleware that automatically calls toJSON on response
Author: Bojan D.
Latest version: 0.3.0

<a name="module_@malijs/tojson"></a>

### @malijs/tojson
Mali <code>toJSON</code> middleware. If the response object has a <code>toJSON</code> function it's executed upon
payload. Only applies for <code>UNARY</code> and <code>REQUEST_STREAM</code> call types.

**Example**  
```js
const toJSON = require('@malijs/tojson')

function handler(ctx) {
  const obj = {
    email: 'bob@gmail.com',
    password: 'mysecret'
  }

  obj.toJSON = function() {
    return {
      email: this.email
    }
  }

  ctx.res = obj // password will not be in the payload to client
}

app.use('fn', toJSON(), handler)
```
npm package: @malijs/toobject
Description: Mali middleware that automatically calls toObject on response
Author: Bojan D.
Latest version: 0.3.0

<a name="module_@malijs/toobject"></a>

### @malijs/toobject
Mali <code>toObject</code> middleware. If the response object has a <code>toObject</code> function it's executed
upon payload. Only applies for <code>UNARY</code> and <code>REQUEST_STREAM</code> call types.

**Example**  
```js
const toObject = require('@malijs/toobject')

function handler(ctx) {
  const obj = {
    email: 'bob@gmail.com',
    password: 'mysecret'
  }

  obj.toObject = function() {
    return {
      email: this.email
    }
  }

  ctx.res = obj // password will not be in the payload to client
}

app.use('fn', toObject(), handler)
```
npm package: @malijs/transform
Description: Mali response payload transform middleware
Author: Bojan D.
Latest version: 0.2.0

# @malijs/transform

Mali response payload transform middleware

[![npm version](https://img.shields.io/npm/v/@malijs/transform.svg?style=flat-square)](https://www.npmjs.com/package/@malijs/transform)
[![build status](https://img.shields.io/travis/malijs/transform/master.svg?style=flat-square)](https://travis-ci.org/malijs/transform)

## API

<a name="module_@malijs/transform"></a>

### @malijs/transform ⇒ <code>function</code>
Mali payload transform middleware. If the response object has a specified function
that function it's executed upon payload. Only applies for <code>UNARY</code> and
<code>REQUEST_STREAM</code> call types.

**Returns**: <code>function</code> - the middleware function  

| Param | Type | Description |
| --- | --- | --- |
| fn | <code>String</code> | The name of the function property to check against in the response object |

**Example**  
```js
const xform = require('@malijs/transform')

function handler(ctx) {
  const obj = {
    email: 'bob@gmail.com',
    password: 'mysecret'
  }

  obj.xform = function() {
    return {
      email: this.email
    }
  }

  ctx.res = obj // password will not be in the payload to client
}

app.use('fn', xform('xform'), handler)
```
## License

  Apache-2.0
npm package: @malijs/unless
Description: Conditionally add Mali middleware
Author: Bojan D.
Latest version: 0.2.0

# mali-unless

Conditionally add [Mali](https://github.com/malijs/mali) middleware

[![npm version](https://img.shields.io/npm/v/@malijs/unless.svg?style=flat-square)](https://www.npmjs.com/package/@malijs/unless)
[![build status](https://img.shields.io/travis/malijs/unless/master.svg?style=flat-square)](https://travis-ci.org/malijs/unless)

## Installation

```
npm install @malijs/unless
```

## API

<a name="module_@malijs/unless"></a>

### @malijs/unless ⇒ <code>function</code>
Mali unless middleware. Attach to any middleware and configure it to prevent/permit the
middleware in question to be executed.

**Returns**: <code>function</code> - middleware  

| Param | Type | Description |
| --- | --- | --- |
| options | <code>Object</code> \| <code>String</code> \| <code>RegExp</code> \| <code>function</code> | - If <code>string</code> and one of <code>Mali Call Types</code> do middleware        unless it is the specified call type        - If <code>string</code> and not a call type, assumed to be a call name, and        middleware is executed unless the call name is the name specified. Call names checks are not case sensitive.        - If <code>function</code> it's a test function that returns <code>true</code> / <code>false</code>.        If the function returns <code>true</code> for the given request, the middleware will not run.        The function will be passed the call context.        - If <code>RegExp</code> instance, if call name matches the regexp the middleware is skipped. |
| options.name | <code>String</code> \| <code>Regex</code> \| <code>Array</code> | A <code>string</code>, a <code>RegExp</code> or an array of any of those.                                          If the call name matches, the middleware will not run.                                          Call names checks are not case sensitive. |
| options.type | <code>String</code> \| <code>Array</code> | A <code>string</code> or an array of strings.                                     If the call type matches, the middleware will not run. |
| options.custom | <code>function</code> | A test function that returns <code>true</code> / <code>false</code>.        If the function returns <code>true</code> for the given request, the middleware will not run.        The function will be passed the call context. |

**Example**  
```js
const requestId = require('@malijs/requestid')
const unless = require('@malijs/unless')
const CallType = require('@malijs/call-types')
const toJSON = require('@malijs/tojson')()

const rid = requestId()
rid.unless = unless
app.use(rid.unless({ name: 'SomeMethod' }))

toJSON.unless = unless
app.use(toJSON.unless({ type: [ CallType.DUPLEX, CallType.RESPONSE_STREAM ] }))
```
## License

  Apache-2.0