open-index/open-npm huggingface dataset:
npm package: @microservice/auth-token
Description: Microservice authentication tokens
Author: Doug Moscrop
Latest version: 2.0.0

# auth-token

Library for creating and encoding/decoding JWT-base auth tokens.

## Install

	$ npm install --save @microservice/auth-token

## Usage

As a factory that uses a builder style pattern to configure things:

```javascript
var Token = require('@microservice/auth-token').alg('HS512').secret('foo');
var token = Token.create();
```

This returns a plain old object that you attach the JWT claims to:

```javascript
token.foo = 'blah';

console.log(token.foo); // 'blah'
console.log(token.alg); // 'HS512'
console.log(JSON.stringify(token)); // {"foo":blah"}
console.log(token.toString()); // the token as a signed string
console.log(token.toAuthorizationHeader()) // "JWT " + toString()
console.log(token.toXsrfToken()); // etc.
```

One advantage to this is if your tokens fall in to logs somewhere, the secret is nowhere to be seen.

You can specify claims as part of `create`:

```javascript
token = Token.create({
	another: 'claim'
});

console.log(token.another); // 'claim'
```

... and decode an existing token:

```javascript
// this works because token is just an object anyway
token = Token.create(token);

// this decodes the token, or returns null if that failed
token = Token.create(token.toString());
```

You can specify the secret, and algorithm during `create`, too:

```javascript
var Factory = Token.alg('HS512').secret('secret');

// use the preconfigured secret and algorithm
one = Factory.create(incoming);

// use a different secret, but the same algorithm
two = Factory.create('other_secret', other_token);

// use a different algorithm and secret
three = Factory.create('HS256', 'other_secret', other_token);
```

You can also `decode` a token, which works like `create`:

```javascript
var A = Token.secret('secret');
var B = Token.secret('different_secret');

// create a token using 'secret'
var a = A.create({ foo: 'bar' });

// encode the token
var encoded = a.toString();

// decode the token using 'secret' and copy the claims in to a new token
// that uses 'different_secret' as configured in the factory
var b = B.decode('secret', encoded);
```

### Properties

You can configure the token factory with property aliases to give more meaningful names to things that might be terse in the token itself:

```javascript
Token = Token.secret('foo').properties({ 'tenantId': 'aud' });
token = Factory.create();

token.tenantId = 'blah';

console.log(token.tenantId); // 'blah'
console.log(token.aud); // 'blah'
console.log(JSON.stringify(token)); // {"aud":"blah"}
```
npm package: @microservice/error-handling
Description: Common error handling logic
Author: Doug Moscrop
Latest version: 1.0.0

# service-error-handling

```javascript
var errorHandling = require('service-error-handling');

express.use(errorHandling({
  mongo: false // convert (some) mongo errors to HTTP codes -- defaults to true
  development: process.env.NODE_ENV !== 'production' // use development errorHandler -- defaults to false
  title: 'My Title!' // custom title for the development-only error page
});
```

errors are rendered with basic content negotiation support (json and html)

in production errors messages are only exposed if err.expose is set to true and a status code and message are provided.
otherwise it defaults to a 500 Internal Server Error.
npm package: @microservice/koa-inject
Description: simple dependency injection for koa
Author: Doug Moscrop
Latest version: 4.0.0

# microservice / koa-inject

minimalist dependency injection for koa applications

## usage

`app = koa(), app.use(inject(function* | object))`

### example

```javascript
var inject = require('@microservice/koa-inject');

app = koa();

// pass an object in to define provider functions
app.use(inject({
  // the dependency 'foo' will be the return value of the function
  foo: function() {
    console.log(this); // the koa context
    return 'foo!';
  },
  // providers are co.wrap'd so they can return promises, etc.
  bar: function() {
    return Promise.resolve('bar!');
  }
}));

// dependency consumer functions are normal middleware
// ... but with extra injected arguments!
app.use(inject(function* (next, foo) {
  console.log(foo); // 'foo!';
  yield* next;
}));
```

## advanced

```javascript
// they can also be middleware
app.use(inject({
  // but they need to set this[key] correctly before yielding
  baz: function* (next) {
    this.biff = 'bad'; // NO!
    this.baz = 'good'; // ok
    yield* next;
  },
  // and dependency consumers, too!
  blah: function* (next, baz) {
    this.blah = 'blah...' + baz;
    yield* next;
  }
}));
```
providers in a definition object are (automagically) run in order, depending on their dependencies.
npm package: @microservice/koa-tenant
Description: Resolve tenant as koa-middleware
Author: Doug Moscrop
Latest version: 1.1.1

# @microservice/koa-tenant

Set a tenant context for a request either from context.auth or the subdomain. The configuration comes from `rc` for the time being.

## Future

Should support looking up a tenant identifier *from* the hostname, and then getting configuration from somewhere other than rc (i.e. Consul).
npm package: @microservice/koa-terminator
Description: Terminate a service as gracefully as possible on error; does not travel through time.
Author: Doug Moscrop
Latest version: 3.0.0

# microservice / terminator
shuts down the server if an error occurs. tries to be nice about it.

## usage

first, register the middleware

```javascript
const terminator = require('@microservice/koa-terminator');

app.use(require('koa-error')); // catch errors and display error pages like normal
app.use(terminator()); // this will signal termination on uncaught errors
// everything else comes after
```

then, listen for a `terminate` event

```javascript
const server = app.listen();

process.on('terminate', () => {
  // the process will exit once existing connections are done
  server.close();
  // you could use a timeout here to force shutdown as well.
  const timer = setTimeout(() => {
    process.exit(1);
  }, 5000);
  timer.unref();
})
```
npm package: @microservice/logger
Description: Logger for koa microservices
Author: Osama Sidat
Latest version: 1.0.0

# logger

Simple bunyan-based logger for koa – intended to work with [@microservice/koa-logging](https://github.com/node-microservice/koa-logging)

## Example Usage

```javascript
const config = require('/path/to/config'),
	logging = require('@microservice/koa-logging'),
	koa = require('koa');

const logger = require('@microservice/logger')({
	name: 'some-service-name',
	environment: config.environment,
	version: require('./version')
});

const app = koa()

...

app.use(logging(logger))

...

```

## Future

Fluentd integration
npm package: @microservice/multitenant
Description: microservice/multitenant ===================
Author: Doug Moscrop
Latest version: 2.3.0

microservice/multitenant
===================

express middleware for multitenant achitecture

### Usage:
```javascript
var express = require('express');
var multitenant = require('multitenant');
var app = express();

app.use(multitenant({...})); // pass in an options object
```

### Options

##### tenants (mandatory)
It can be an object or a function, and in both case should provide the information relative to a given tenant.

The object's keys has to be the same as the tenant's ID.
```javascript
tenants: {
  foo: {...}, // tenant of ID 'foo'
  bar: {...}  // tenant of ID 'bar'
}
```
The function is has a tenant ID and a callback as arguments.
```javascript
tenants: function(tenantId, done) {
  var tenantInformation = getTenantInformation(tenantId); // some code to load the tenant information
  done(tenantInfomation);
}
```

##### tenantId (optional)

Function which parses the request object and provides a callback with the tenantId. It defaults to the subdomain.
```javascript
tenantId: function(request, done) {
  var tenantId = extractTenantIdFromRequest(request); // some code to extract the tenantId from the request
  done(tenantId);
}
```

##### onNotFound (optional)

Called when the tenant cannot be found with the given tenantId. It is the last function of the middleware chain. By default it sends a 400 error

```javascript
onNotFound: function(request, response, next) {
  response.send('some error message');
}
```

##### onNoTenantKey (optional)

Called when the tenantId cannot be determined. It is the last function of the middleware chain. By default it sends a 400 error

```javascript
onNoTenantKey: function(request, response, next) {
  response.send('some error message');
}
```

##### connectionStrategy (optional)

This is where you initialize a connection to a database. It takes two arguments: the tenant information object, and a callback. Arguments provided to the callback will be assigned to `request.tenantConnection`.
```javascript
connectionStrategy: function(tenantInformation, done) {
  var connection = initializeDatabaseConnection(tenantInformation);
  done(connection);
}
```

Alternatively, it can be an object whose values are either functions or values, which are assigned to the `req` object using their respective key.

```javascript
connectionStrategy: {
  foo: 'bar', // sets req.foo to 'bar'
  baz: function(tenant, callback) {
    callback(null, 'baz'); // sets req.baz to 'baz' - first argument is an error which will propagate to next(err)
  }
}
```
npm package: @microservice/terminator
Description: Terminate a service as gracefully as possible on error; does not travel through time.
Author: Doug Moscrop
Latest version: 1.0.0

# microservice / terminator
shuts down the server if an
 error occurs. tries to be nice about it.

## usage

as middleware:

`app.use(terminator(server[, config]))`

see the example below.

### config

#### timer

milliseconds to wait before calling `process.exit(1)`
* type: `number` (can be disabled with `false`)
* default: `5000`

#### uncaughtException

whether or not to terminate on an `uncaughtException` event
* type: `boolean`
* default: `true`

## example

```javascript
var terminator = require('@microservice/terminator');

var http = require('http');
var express = require('express');

var app = express();
var server = http.createServer(app);

app.use(terminator(server, {
  timeout: 10000,
  uncaughtException: true
});
app.use(function(req, res, next) {
  next(new Error());
});

server.listen(80);
```
npm package: @microservices-suite/config
Description: This contains common configurations for things like env files,loggers etc for easy setup of environment specific settings
Author: Gilbert Andanje
Latest version: 1.0.9

# Microservices Suite

## Configuration Package

Welcome to the Microservices Suite Configuration Package! This package, part of our monorepo, offers a centralized solution for managing configuration settings across your microservices applications. By consolidating configuration options, you ensure consistency and ease of maintenance throughout your codebase.
npm package: @microservices-suite/errors
Description: This is the global error handler for handling error messages in development and production environments
Author: Gilbert Andanje
Latest version: 1.1.6

# Microservices Suite

## Error handler package

Welcome to the Microservices Suite Error Handler Package! This package, residing within our monorepo, provides robust error handling capabilities tailored for microservices architecture. It equips you with the tools to effectively manage and respond to errors across your microservices applications, ensuring reliability and resilience.