@dpktickets/common
v1.0.12
Published
Shared utilities and middleware used across the ticketing microservices.
Readme
@dpktickets/common
Shared utilities and middleware used across the ticketing microservices.
- Exports common error classes and Express middlewares:
currentUser,errorHandler,requireAuth,validateRequest- Error classes:
BadRequestError,CustomError,DatabaseConnectionError,NotFoundError,RequestValidationError
Installation
From npm (when published):
npm install @dpktickets/common
Or use the git repo directly while developing:
npm install git+https://github.com//common.git
Notes about package format
This package ships compiled JS in the
build/folder. Consumers import the package normally:import { currentUser, errorHandler } from '@dpktickets/common';
expressis a peer dependency — the host service must installexpress.
Usage in auth service (example)
In auth/src/index.ts:
import express from 'express';
import cookieSession from 'cookie-session';
import { currentUser, errorHandler } from '@dpktickets/common';
const app = express();
app.use(express.json());
app.use(
cookieSession({ signed: false, secure: true })
);
app.use(currentUser);
// ... your routes
app.use(errorHandler);Usage in tickets service (example)
In tickets/src/app.ts:
import express from 'express';
import { currentUser, requireAuth } from '@dpktickets/common';
const app = express();
app.use(express.json());
app.use(currentUser);
app.post('/api/tickets', requireAuth, (req, res) => {
// create ticket
});Publishing
The repo contains
build/output andpackage.jsonis configured to publish the compiled files. To publish a new version:npm version patch npm run build npm publish
Development
- Make changes to
src/, runnpm run buildto producebuild/files. - Tests and consumers should use the published package or install via a git URL while iterating locally.
Contributing
- Open PRs against this repository and follow the commit style used here.
License
- ISC
