1.0.29 • Published 2 years ago
@ngazicticketingapp/common v1.0.29
Common code shared between services
There might be differences in our TS settings between the common lib and other services. or services might not be written with TS at all. WE DON'T WANT TO DEAL WITH THAT.
That's why our common library will be written as TS and published as Java Script.
Creating organization public npm package ngazicticketingapp/common for common code reuse
- Package initialization and creation
npm init -y # initialize new npm repo, package name must start with @yourorganization/packagename
git init
git add .
git commit -m "initial commit"
npm login # insert your npm credentials
npm publish --access public
- Create TS config file:
npm install typescript del-cli --save-dev
tsc --init
- In tsconfig.json file, enable generating .d.ts and .js files separately (source js code and TS types for it):
"compilerOptions": {
...
"declaration": true # set this to true,
"outDir": "./build", # specify the build directory
Command for updating package version:
npm version patch
Take a detail look into .gitignore and package.json config file
Updating package
Run:
npm run pub # adds new code to git, increase package version, builds the new version and publishes it to NPM
In other services that use this package, run:
npm update @ngazicticketingapp/common
Library description
Errors
All errors have uniform template:
class CustomError {
statusCode: number;
serializeErrors(): { message: string; field?: string }[];
}
List of Errors:
- CustomError => parent class of all other errors
- BadRequestError => Status Code 400
- NotAuthorizedError => Status Code 401
- NotFoundError => Status Code 404
- RequestValidationError => Status Code 400
Middlewares
List
- current-user => returns current user from cookie if it exists, or do nothing if the user is null/undefined
- error-handler => main middleware for handling errors among services
- require-auth => if current user is does not exists in request, throws NotAuthorizedError(401)
- validate-request => Throws RequestValidationError (400) if there are validation errors in request (ie invalid form values)
1.0.29
2 years ago
1.0.28
2 years ago
1.0.27
2 years ago
1.0.26
2 years ago
1.0.25
2 years ago
1.0.24
2 years ago
1.0.23
2 years ago
1.0.22
2 years ago
1.0.21
2 years ago
1.0.20
2 years ago
1.0.19
2 years ago
1.0.18
2 years ago
1.0.17
2 years ago
1.0.16
2 years ago
1.0.15
2 years ago
1.0.14
2 years ago
1.0.13
2 years ago
1.0.11
2 years ago
1.0.10
2 years ago
1.0.8
2 years ago
1.0.7
2 years ago
1.0.5
2 years ago
1.0.4
2 years ago
1.0.3
2 years ago
1.0.2
2 years ago
1.0.1
2 years ago
1.0.0
2 years ago