open-index/open-npm huggingface dataset:
npm package: @nxus/mailer
Description: A Nxus module for sending emails.
Author: mjreich
Latest version: 2.4.0-1

# @nxus/mailer

## 

[![Build Status](https://travis-ci.org/nxus/mailer.svg?branch=master)](https://travis-ci.org/nxus/mailer)

A Nxus module for sending emails through different services. 

### Installation

    > npm install @nxus/mailer --save

### Usage

#### Register a mail service

    app.get('mailer').service(myService)

Each service is expected to implement a method called `sendMessage` with the signature

    sendMessage(to, from, subject, content, opts) {
    ...
    }

#### Send an email using a service

    app.get('mailer').send('to@address', 'from@address', "My subject", "Body content", {some: opts})

##### Opts

The opts hash can be used to send service specific opts back to the mail handler.  For example:

    // Mandrill opts
    app.get('mailer').send('to@address', 'from@address', "My subject", "Body content", { async: true })

## API

* * *

## Mailer

The main Mailer class.

### service

Register a service.  See MandrillService for an example.

**Parameters**

-   `service` **[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** a Class or callable that implements a method called `sendMessage`.

## MandrillSerivce

A default service for mailing with Mandrill.
npm package: @nxus/metrics
Description: Metrics tracks arbitrary events in a Nxus application.
Author: mjreich
Latest version: 2.4.0-0

# @nxus/metrics

## 

[![Build Status](https://travis-ci.org/nxus/metrics.svg?branch=master)](https://travis-ci.org/nxus/metrics)

A module for capturing and querying arbitrary events, called metrics.

A metric has a `name`, like 'pageViews', and arbitrary `data`, which can be any object.  For example, your 'pageViews' metric might have an entry like:

```javascript
{
  name: 'pageViews',
  data: {
    browser: 'Safari',
    location: [...]
    ...
  }
}
```

### Installation

```bash
> npm install @nxus/metrics --save
```

### Usage

#### Saving a metric value

Metrics provides a method for recording new metrics.

```javascript
app.get('metrics').metric('someName', {some: 'data'});
```

#### Capturing metrics for models

You can also have Metrics capture all events from a model and save new values accordingly.

```javascript
app.get('metrics').capture('myModel')
```

Now, whenenver an instance of the model is created, updated or destroyed, there will be a corresponding metric captured.  For example, 'myModelCreated', where the data is the latest instance of the model.

## API

* * *

## Metrics

The Metrics module captures arbitrary data about events (a metric) for storage and querying later.

### capture

Captures metric data about a specified @nxus/storage Model

**Parameters**

-   `model` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The name of the model to capture. Must be a Storage/BaseModel class.
-   `events` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)=(default \['create', 'update', 'destroy'])** Optional. An array of model events to capture. Defaults to 'create', 'update', 'destroy'.

### getMetrics

Returns metrics for the specified name, optionally using the query to filter returned values.

**Parameters**

-   `name` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the name of the metrics to return
-   `query` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)=(default {})** Optional.  The Waterline compatible query object to filter results by.

Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** A promise for the result set.

### metric

Record a new metric value

**Parameters**

-   `name` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The metric name to use.
-   `data` **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** An arbitrary object to record as as the data payload for the metric.

Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** A promise that is fulfilled when the metric has been saved successfully.
npm package: @nxus/renderer
Description: Rendering framework for Nxus applications/
Author: mjreich
Latest version: 2.4.0-3

# @nxus/renderer

## 

[![Build Status](https://travis-ci.org/nxus/renderer.svg?branch=master)](https://travis-ci.org/nxus/renderer)

A rendering framework for Nxus applications.

### Installation

In your Nxus application:

    > npm install @nxus/renderer --save

### Usage

#### Defining a renderer

    app.get('renderer').renderer(type, handler);

Where `type` is usually the filename extension and `handler` returns the rendered text when called with contents to render and an optional `opts` object.

#### Rendering a string

    app.get('renderer').render(type, text).then((renderedText) => {console.log(renderedText)});

You can pass an optional arugment `opts` for options to pass to the renderer.

    app.get('renderer').render(type, text, {title: 'My Title'}).then((renderedText) => {console.log(renderedText)});

#### Rendering a file

    app.get('renderer').renderFile(type, filename).then((renderedText) => {});

You can pass an optional arugment `opts` for options to pass to the renderer.

## API

* * *

## Renderer

Renderer renders different files and content using common rendering engines, like EJS and MarkDown.

### render

Request rendered content based on type

**Parameters**

-   `type` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The type (e.g. 'html') of the content
-   `content` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The contents to render
-   `opts` **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Options for the renderer context

Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** The rendered content

### renderer

Provide a renderer for a particular type (file extension)

**Parameters**

-   `type` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The type (e.g. 'html') this renderer should handle
-   `handler` **[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** Function to receive (content, options) and return rendered content

### renderFile

Provide a renderer for a particular type (file extension)

**Parameters**

-   `filename` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Path to content to render
-   `opts` **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Options for the renderer context

Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** The rendered content
npm package: @nxus/rest-api
Description: REST API for Nxus applications
Author: mjreich
Latest version: 2.4.0-1

# @nxus/rest-api

## 

[![Build Status](https://travis-ci.org/nxus/rest-api.svg?branch=master)](https://travis-ci.org/nxus/rest-api)

Exposes Nxus Storage models as a REST API.

### Installation

In your Nxus application:

    > npm install @nxus/rest-api --save

### Usage

#### Configuration

In package.json:

     "config": {
       "restapi": {
         "url_path": "/api"
        }
     }
     

#### Routes

    GET /api/:model
    POST /api/:model
    GET /api/:model/:id
    PUT /api/:model/:id
    DELETE /api/:model/:id

## API

* * *

## RestAPI

Exposes a REST API for Nxus models
e.g. GET /api/todo, POST /api/todo, GET /api/todo/1, etc

**Examples**

```javascript
Configuration (defaults):
{restapi: {
  url_path: '/api'
}}
```
npm package: @nxus/router
Description: An express-based router for Nxus
Author: info@nxusapp.com
Latest version: 2.4.0-2

# @nxus/router

## 

[![Build Status](https://travis-ci.org/nxus/router.svg?branch=master)](https://travis-ci.org/nxus/router)

The Nxus router is an Express compatible web server and router for Nxus applications.

### Installation

In your Nxus application:

    > npm install @nxus/router --save

### Usage

#### Defining a route

    app.get('router').route('/', (req, res) => {
      res.send('Hello World')
    })

Alternatively, you can specify a HTTP method:

    app.get('router').route('GET', '/', (req, res) => {
      res.send('Hello World')
    })

#### Adding Express/connect middleware

    app.get('router').middleware((req, res) => {
      res.status(404).send('Nothing to see here');
    })

#### Adding static files/directories

    app.get('router').static("my-prefix", myPath)

For example, `myFile.txt` in `myPath` is then available at the url `/my-prefix/myFile.txt`

Sometimes its good to have a static assets folder where all your assets live. For that reason, you can use the `assets` gatherer.

## API

* * *

## Router

### constructor

Sets up the relevant gather/providers

**Parameters**

-   `app`  

### getExpressApp

Returns the Express App instance.

Returns **Instance** ExpressJs app instance.

### getRoutes

Returns the internal routing table.

Returns **[array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)** routes which have been registered

### launch

Launches the Express app. Called by the app.load event.

### setMiddleware

Adds a middleware handler to the internal routing table passed to Express. Accessed with 'middleware' gather.

**Parameters**

-   `route` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** A URL route.
-   `handler` **[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** An ExpressJs type callback to handle the route.
-   `method`   (optional, default `'use'`)

### setRoute

Adds a route to the internal routing table passed to Express. Accessed with the 'route' gather.

**Parameters**

-   `method` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Either 'get', 'post', 'put' or 'delete'.
-   `route` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** A URL route.
-   `handler` **[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** An ExpressJs type callback to handle the route.

### setStatic

Adds a path to serve static files.

**Parameters**

-   `prefix` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The path at which the static files will be accessible. For example: /js
-   `path` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** A fully resolved path.

### stop

Stops the express app. Called by the app.stop event.
npm package: @nxus/searcher
Description: A search framework for Nxus apps
Author: mjreich
Latest version: 2.4.0-3

# @nxus/searcher

## 

[![Build Status](https://travis-ci.org/nxus/searcher.svg?branch=master)](https://travis-ci.org/nxus/searcher)

The Searcher module enables easy searching of Nxus models using different adapters for Solr, ElasticSearch and others.

## Installation

    > npm install @nxus/searcher --save

## Usage

### Configuration

The Searcher module depends on @nxus/storage.  The first step is adding and configuring the search adapter you'd like to use.
For example, if we want to enable ElasticSearch, we first install the waterline-elasticsearch adapter, then setup the configuration 
options in the Storage config.

> npm install waterline-elasticsearch --save

then add to package.json

   "storage": {
     "adapters": {
       ...
       "searcher": "waterline-elasticsearch"
     },
     "connections": {
       ...
       "searcher: {
         "adapter": "searcher",
         "host": "<host address>:9200",
         "log": "warning",
         "index": "searcher"
       }
     }
   }

### Register model

Now that the correct Storage adapters are configured, you'll need to tell Searcher which models you want to enable 
search using the `searchable` method. Searchable accepts an identity for a model which has already been registered.

   app.get('searcher').searchable('user')

By default, Searcher will look for a field named `title` or `name` to use as the search field. You can specify different, or 
multiple fields to search by specifying a second options parameter, with the `fields` key:

   app.get('searcher').searchable('user', {fields: 'firstName'})
   app.get('searcher').searchable('user', {fields: ['firstName', 'lastName']})

### Routes

Based on the model identify, Searcher will create the following routes

    /users/search

which accepts a search parameter `q`. So to search for the term 'pizza':

    /users/search?q=mike

The search wil return a list of results using the views below.

### Views

You can provide search specific views to be used for search results:

1.  search-user-list: the list view for returned search results.
2.  search-user-detail: the detail view for an individual search result.

Alternatively, if no search templates are found, searcher will automatically use the `@nxus/base-ui` views for any model 
that is searchable (if they exist).

1.  view-user-list: the list view used to display search results.
2.  view-user-detail: the detail view linked to from the list view.

Finally, searcher will use default list/detail views if no other templates are found. 

## API

## Searcher

The Search class enables automated searching of models using different adapters.

### searchable

Register a model to be searchable.

**Parameters**

-   `model` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the model identity
-   `opts` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)=(default {})** An optional hash of options.
npm package: @nxus/tester
Description: A test management framework for Nxus applications, built on Mocha and Chai
Author: mjreich
Latest version: 2.4.0-1

# @nxus/tester

## 

[![Build Status](https://travis-ci.org/nxus/tester.svg?branch=master)](https://travis-ci.org/nxus/tester)

A test management framework for Nxus applications.  The tester module provides some helper functions for funtionally testing a Nxus app.

### Installation

    > npm install @nxus/tester --save-dev

### Configuration

In order to spin up the test server, add the following lines to your package.json `scripts`.

    "pretest": "./node_modules/forever/bin/forever stopall && NODE_ENV=test PORT=3001 ./node_modules/forever/bin/forever start index.js && sleep 15"

    "posttest": "./node_modules/forever/bin/forever stop index.js"

### Usage

#### Running tests

    > npm test

#### Requests

    import {request} from '@nxus/tester'

    request.get({url: '/'}, (err, res, body) => {
      res.statusCode.should.equal(200)
    })

## API

* * *
npm package: @nxus/users
Description: User management module for Nxus apps.
Author: mjreich
Latest version: 2.3.13

# @nxus/users

## 

[![Build Status](https://travis-ci.org/nxus/users.svg?branch=master)](https://travis-ci.org/nxus/users)

User management module for Nxus apps.  Users provides a complete framework for managing users, authenticating routes and sessions.

### Install

    > npm install @nxus/users --save

### Quickstart

Once Users is installed in your app, you are ready to go.  It includes the following components:

-   user/team models
-   login/logout routes
-   authentication/session middleware

### Models

Uses defines a set of common models you can use to build your application, using the @nxus/storage module (which uses Waterline to provide common ORM functionality).

#### User

Accessing the user model:

    app.get('storage').getModel('user').then((User) => {
      ...
    });

**Fields**

-   email: string
-   password: string
-   nameFirst: string
-   nameLast: string
-   position: string
-   enabled: boolean
-   admin: boolean
-   lastLogin: datetime
-   metadata: JSON
-   team: relation to Team model

**Convenience Methods**

-   name(): first + last name
-   isAdmin(): boolean if user is an Admin
-   validPassword(pass): returns true if the password is valid

### Templates

Users defines a set of common templates you can use in your app

#### login

A login form preconfigured to work with the login/logout routes. Markup supports basic Bootstrap 3 CSS.

    app.get('templater').render('users-login').then((content) => {
      ...
    }

### Routes

The Users module defines some convience routes for handling basic user functionality.

#### /login

**Params**
Expects to recieve a POSTed form with the values `username`, `password` and `redirect`. `redirect` should be a url to redirect the user to on success.  On login failure, the user will be redirected back to /login.

#### /logout

**Params**
Expects to recieve a GET request with the param `redirect`, which is a url where the user will be redirected on successful logout.

## API

* * *

## Users

The Users Module provides a complete user authentication and authorization system.
npm package: @nxus/worker-queue
Description: Nxus worker queue for background tasks
Latest version: 2.4.0-8

# @nxus/worker-queue

## 

[![Build Status](https://travis-ci.org/nxus/worker-queue.svg?branch=master)](https://travis-ci.org/nxus/worker-queue)

Using Redis for pub/sub background tasks

### Installation

    > npm install @nxus/worker-queue --save

### Usage

For each task, you need to define a unique task name.

#### Register a worker handler

    app.get('worker-queue').worker('myBackgroundTask', ({data}) => {
      this.app.log.debug("Hello", data.hi)
    })

#### Request task processing

`app.get('worker-queue').task('myBackgroundTask', {hi: world})`

#### Receive notifications of completed tasks

Register two tasks, one for processing and one for notifications, and trigger the second from within the first handler.

    app.get('worker-queue').worker('myBackgroundTask', ({data}) => {
      this.app.log.debug("Hello", data.hi)
      app.get('worker-queue').task('myBackgroundTask-complete', {result: true})
    })
    app.get('worker-queue').worker('myBackgroundTask-complete', ({data}) => {
      this.app.log.debug("Completed", data.result)
    })

`app.get('worker-queue').task('myBackgroundTask', {hi: world})`

## API

* * *

## WorkerQueue

Worker Queue module for background tasks

### clean

Cleans the current queue for the given taskName. Good idea to do this on occasion as Bull will keep all completed tasks in Redis.

**Parameters**

-   `taskName` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The name of the queue to clean. If not provided, all queues are cleaned.

### task

Request handling of a background task

**Parameters**

-   `taskName` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Name of the task (channel) to publish to
-   `message` **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Options for the task worker

**Examples**

```javascript
app.get('worker-queue').task('backgroundJob', {hi: 'world'})
```

### worker

Provide a task handler

**Parameters**

-   `taskName` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Name of the task (channel) to listen for
-   `handler` **[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** Handler for processing task requests

**Examples**

```javascript
app.get('worker-queue').worker('backgroundJob', (msg) -> {})
```