# koa-omnibus

> Base middleware for `koa` servers.

Latest version **1.0.0-rc3** (published 2021-06-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install koa-omnibus
pnpm add koa-omnibus
yarn add koa-omnibus
bun add koa-omnibus
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0-rc3 |
| Published | 2021-06-08 |
| First published | 2017-10-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8 |
| Dependencies | 12 |
| Unpacked size | 26.7 KB |
| Known vulnerabilities | 0 (+7 in 3 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Tor E Hagemann |
| Maintainers | teh |
| Keywords | koa, omnibus, middleware |

## Links

- npm: https://www.npmjs.com/package/koa-omnibus
- Repository: https://github.com/hagemt/node-koa-omnibus
- Homepage: https://github.com/hagemt/node-koa-omnibus#readme
- Issues: https://github.com/hagemt/node-koa-omnibus/issues
- npm.io page: https://npm.io/package/koa-omnibus

## Dependencies (12)

- [koa](https://npm.io/package/koa.md) 2.13.1
- [pino](https://npm.io/package/pino.md) 6.11.3
- [uuid](https://npm.io/package/uuid.md) 8.3.2
- [debug](https://npm.io/package/debug.md) 4.3.1
- [lodash](https://npm.io/package/lodash.md) 4.17.21
- [lru-cache](https://npm.io/package/lru-cache.md) 6.0.0
- [@hapi/boom](https://npm.io/package/@hapi/boom.md) 9.1.2
- [koa-router](https://npm.io/package/koa-router.md) 10.0.0
- [pino-debug](https://npm.io/package/pino-debug.md) 2.0.0
- [pino-caller](https://npm.io/package/pino-caller.md) 3.1.0
- [pino-pretty](https://npm.io/package/pino-pretty.md) 5.0.2
- [koa-pino-logger](https://npm.io/package/koa-pino-logger.md) 3.0.0

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.0.0-rc3 (latest) — 2021-06-08
- 1.0.0-rc2 — 2020-08-24
- 1.0.0-rc — 2020-07-28
- 0.9.5 — 2020-03-06
- 0.9.4 — 2018-09-19
- 0.9.3 — 2017-11-13
- 0.9.2 — 2017-10-31
- 0.9.1 — 2017-10-29
- 0.9.0 — 2017-10-28
- 0.1.1 — 2017-10-25
- 0.1.0 — 2017-10-25

## README

# koa-omnibus

[![CircleCI](https://circleci.com/gh/hagemt/node-koa-omnibus/tree/master.svg?style=shield)](https://circleci.com/gh/hagemt/node-koa-omnibus/tree/master)
[![Known Vulnerabilities](https://snyk.io/test/github/hagemt/node-koa-omnibus/badge.svg?targetFile=package.json)](https://snyk.io/test/github/hagemt/node-koa-omnibus?targetFile=package.json)
[![Maintainability](https://api.codeclimate.com/v1/badges/c5903ebb2706657b1820/maintainability)](https://codeclimate.com/github/hagemt/node-koa-omnibus/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/c5903ebb2706657b1820/test_coverage)](https://codeclimate.com/github/hagemt/node-koa-omnibus/test_coverage)

I wouldn't use this in production until it's more battle-tested. (at least v1)

It does exactly everything you want an API server to do, and nothing more.

Put this at the front of your `koa@^2` middleware chain and get hacking.

## What do you mean? I want to try before I buy.

Clone, then: `npm install && npm install koa && npm run demo` or:

Slap this in `node server.js | bunyan` after `npm install koa koa-omnibus`:

```
const omnibus = require('koa-omnibus')
omnibus.createApplication().listen()
// or: application.use(omnibus())
```

## Defaults not good enough? Okay...

All dependencies are included only for defaults; you can override anything you want.

```
omnibus({

	// simple constants: (all Numbers are in milliseconds)
	headers: { timing:String, tracing:String }, // defaults: 'X-Response-Time' and 'X-Request-ID'
	limits: Object { age:Number, max:Number, next:Number, rpm:Number }, // 60000/1000000/60000/1000
	namespace: String, // default: 'omnibus' (if set false-y, context.state decorated directly)

	// middleware factories (unary):
	limitRate: options:Object => middleware:AsyncFunction, // 429 Too Many Requests
	limitTime: options:Object => middleware:AsyncFunction, // 408 Request Timeout

	// redaction transforms (binary):
	redactedError: (options, context) => error, // do whatever transform(s) you want here
	redactedRequest: (options, context) => _.omit(context.request, ['header']), // " here
	redactedResponse: (options, context) => _.omit(context.response, ['header']), // " here

	// object factories (ternary):
	targetError: (options, context, error) => error, // not redacted (default: Boom)
	targetTracer: (options, context, string) => Object { [string]: "$(uuidgen -t)" },
	targetLogger: (options, context, object) => log, // will include tracking headers
	targetObject: (options, context, object) => object, // context[namespace || 'state']

})
```

## Oh, yeah. One more thing:

This doesn't include any of these modules, but you can `.use` them, as you wish:

* https://www.npmjs.com/package/koa-bodyparser
* https://www.npmjs.com/package/koa-compress
* https://www.npmjs.com/package/koa-etag
* https://www.npmjs.com/package/koa-favicon
* https://www.npmjs.com/package/koa-helmet
* https://www.npmjs.com/package/koa-logger
* https://www.npmjs.com/package/koa-mount
* https://www.npmjs.com/package/koa-ratelimit
* https://www.npmjs.com/package/koa-rewrite
* https://www.npmjs.com/package/koa-session
* https://www.npmjs.com/package/koa-static
* https://www.npmjs.com/package/@koa/cors

## But seriously, what is this, and how does it work?

You want your server to do a few things for you:

* If the user (tracks $max IPs for $age) has made Too Many Requests ($rpm) throw 429.
* If the middleware chain has been executing for too long ($next) 408 Request Timeout.
* It would be nice if my REST API actually produced error bodies for JSON consumers.
* It would be nice if my logging actually worked how I want it to. (see Bunyan)
* It would be nice if my logs included what I want, and none of what I don't.
* It would be nice if the defaults made sense, and nothing got in my way.
* It would be nice if I could later customize everything how I like it.

Sweet. So, how's it work? See `defaults.js`. Swish.

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