# @alexhelloworld/common

> [Microservices ticketing project](https://github.com/AnimalInstinct/microservices-ticketing)

Latest version **1.0.5** (published 2020-08-30) · ISC license · 0 weekly downloads

## Install

```sh
npm install @alexhelloworld/common
pnpm add @alexhelloworld/common
yarn add @alexhelloworld/common
bun add @alexhelloworld/common
```

## 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.5 |
| Published | 2020-08-30 |
| First published | 2020-08-28 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 8 |
| Unpacked size | 17 KB |
| Known vulnerabilities | 0 (+3 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | animalinstinct |

## Links

- npm: https://www.npmjs.com/package/@alexhelloworld/common
- npm.io page: https://npm.io/package/@alexhelloworld/common

## Dependencies (8)

- [err](https://npm.io/package/err.md) ^2.1.12
- [express](https://npm.io/package/express.md) ^4.17.1
- [jsonwebtoken](https://npm.io/package/jsonwebtoken.md) ^8.5.1
- [@types/express](https://npm.io/package/@types/express.md) ^4.17.7
- [cookie-session](https://npm.io/package/cookie-session.md) ^1.4.0
- [express-validator](https://npm.io/package/express-validator.md) ^6.6.1
- [@types/jsonwebtoken](https://npm.io/package/@types/jsonwebtoken.md) ^8.5.0
- [@types/cookie-session](https://npm.io/package/@types/cookie-session.md) ^2.0.41

## Recent versions

- 1.0.5 (latest) — 2020-08-30
- 1.0.4 — 2020-08-29
- 1.0.3 — 2020-08-28
- 1.0.2 — 2020-08-28
- 1.0.1 — 2020-08-28
- 1.0.0 — 2020-08-28

## README

# Cross-service requests validation and errors handling library for the microservices ticketing project.

[Microservices ticketing project](https://github.com/AnimalInstinct/microservices-ticketing)

## Installation

```bash
npm i --save @alexhelloworld/common
```

[packaje on npmjs.com](https://www.npmjs.com/package/@alexhelloworld/common)

## Using:

To get current user logged in:

```js
import { currentUser } from '@alexhelloworld/common'
const user = currentUser
```

Middleware For the request validation and throw Bad Request Error in case of any errors:

```js
import { validateRequest } from '@alexhelloworld/common'

router.post(
  '/api/users/signin',
  [
    body('email').isEmail().withMessage('Email must be valid'),
    body('password').trim().notEmpty().withMessage('Password is required'),
  ],
  validateRequest,
  async (req: Request, res: Response) => {
    //Sign in code should be here
  }
)
```

##### Error handler and Errors templates

Error handler middleware to serialize all errors to the for understanfing between all the Microservices

```js
import { errorHandler } from '@alexhelloworld/common'
const app = express()
app.use(errorHandler)
```

Errors reusable:

```js
import { BadRequestError } from '@alexhelloworld/common'
import { NotFoundError } from '@alexhelloworld/common'
// 400
if (!passwordsMatch) {
  throw new BadRequestError('Invalid credentials')
}
// 404
app.get('*', () => {
  throw new NotFoundError()
})
```

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