@egodigital/microservices
Advanced tools
Comparing version 0.1.4 to 0.2.0
# Change Log (@egodigital/microservices) | ||
## 0.2.0 | ||
* add functions, that hashes passwords with bcrypt | ||
* add JWT helper functions | ||
## 0.1.4 | ||
* initial release |
@@ -18,2 +18,6 @@ /** | ||
/** | ||
* The number of rounds for bcrypt hashing. | ||
*/ | ||
export declare const BCRYPT_ROUNDS: string | undefined; | ||
/** | ||
* The secret for signing and validating JWT. | ||
@@ -20,0 +24,0 @@ */ |
@@ -18,25 +18,29 @@ "use strict"; | ||
*/ | ||
var _a, _b, _c, _d, _e; | ||
var _a, _b, _c, _d, _e, _f; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.POD_NAME = exports.NATS_URL = exports.NATS_GROUP = exports.NATS_CLUSTER_ID = exports.JWT_SECRET = void 0; | ||
exports.POD_NAME = exports.NATS_URL = exports.NATS_GROUP = exports.NATS_CLUSTER_ID = exports.JWT_SECRET = exports.BCRYPT_ROUNDS = void 0; | ||
/** | ||
* The number of rounds for bcrypt hashing. | ||
*/ | ||
exports.BCRYPT_ROUNDS = (_a = process.env.BCRYPT_ROUNDS) === null || _a === void 0 ? void 0 : _a.trim(); | ||
/** | ||
* The secret for signing and validating JWT. | ||
*/ | ||
exports.JWT_SECRET = (_a = process.env.JWT_SECRET) === null || _a === void 0 ? void 0 : _a.trim(); | ||
exports.JWT_SECRET = (_b = process.env.JWT_SECRET) === null || _b === void 0 ? void 0 : _b.trim(); | ||
/** | ||
* The name of the cluster, that contains this and the other microservices. | ||
*/ | ||
exports.NATS_CLUSTER_ID = (_b = process.env.NATS_CLUSTER_ID) === null || _b === void 0 ? void 0 : _b.trim(); | ||
exports.NATS_CLUSTER_ID = (_c = process.env.NATS_CLUSTER_ID) === null || _c === void 0 ? void 0 : _c.trim(); | ||
/** | ||
* The name of the pod group / kubernetes deployment. | ||
*/ | ||
exports.NATS_GROUP = (_c = process.env.NATS_GROUP) === null || _c === void 0 ? void 0 : _c.trim(); | ||
exports.NATS_GROUP = (_d = process.env.NATS_GROUP) === null || _d === void 0 ? void 0 : _d.trim(); | ||
/** | ||
* The URL to the NATS server. | ||
*/ | ||
exports.NATS_URL = (_d = process.env.NATS_URL) === null || _d === void 0 ? void 0 : _d.trim(); | ||
exports.NATS_URL = (_e = process.env.NATS_URL) === null || _e === void 0 ? void 0 : _e.trim(); | ||
/** | ||
* The name of the POD, which is used as client ID for NATS, e.g. | ||
*/ | ||
exports.POD_NAME = (_e = process.env.POD_NAME) === null || _e === void 0 ? void 0 : _e.trim(); | ||
exports.POD_NAME = (_f = process.env.POD_NAME) === null || _f === void 0 ? void 0 : _f.trim(); | ||
//# sourceMappingURL=constants.js.map |
@@ -18,4 +18,4 @@ /// <reference path="../index.d.ts" /> | ||
*/ | ||
export * from './auth'; | ||
export * from './constants'; | ||
export * from './express'; | ||
export * from './nats'; |
@@ -31,5 +31,5 @@ "use strict"; | ||
/// <reference path="../index.d.ts" /> | ||
__exportStar(require("./auth"), exports); | ||
__exportStar(require("./constants"), exports); | ||
__exportStar(require("./express"), exports); | ||
__exportStar(require("./nats"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -0,1 +1,17 @@ | ||
/** | ||
* This file is part of the @egodigital/microservices distribution. | ||
* Copyright (c) e.GO Digital GmbH, Aachen, Germany (https://www.e-go-digital.com/) | ||
* | ||
* @egodigital/microservices is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation, version 3. | ||
* | ||
* @egodigital/microservices is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
import { Stan } from 'node-nats-streaming'; | ||
@@ -2,0 +18,0 @@ /** |
@@ -47,10 +47,13 @@ "use strict"; | ||
connect() { | ||
if (!(constants_1.NATS_URL === null || constants_1.NATS_URL === void 0 ? void 0 : constants_1.NATS_URL.length)) { | ||
throw new Error('No NATS_URL defined'); | ||
} | ||
if (!(constants_1.NATS_CLUSTER_ID === null || constants_1.NATS_CLUSTER_ID === void 0 ? void 0 : constants_1.NATS_CLUSTER_ID.length)) { | ||
throw new Error('No NATS_CLUSTER_ID defined'); | ||
} | ||
if (!(constants_1.POD_NAME === null || constants_1.POD_NAME === void 0 ? void 0 : constants_1.POD_NAME.length)) { | ||
throw new Error('No POD_NAME defined'); | ||
} | ||
return new Promise((resolve, reject) => { | ||
try { | ||
if (!(constants_1.NATS_CLUSTER_ID === null || constants_1.NATS_CLUSTER_ID === void 0 ? void 0 : constants_1.NATS_CLUSTER_ID.length)) { | ||
throw new Error('No NATS_CLUSTER_ID defined'); | ||
} | ||
if (!(constants_1.POD_NAME === null || constants_1.POD_NAME === void 0 ? void 0 : constants_1.POD_NAME.length)) { | ||
throw new Error('No POD_NAME defined'); | ||
} | ||
const newClient = node_nats_streaming_1.default.connect(constants_1.NATS_CLUSTER_ID, constants_1.POD_NAME, { | ||
@@ -79,2 +82,3 @@ url: constants_1.NATS_URL | ||
this.client.once('close', () => process.exit()); | ||
// try to close connection, if process closes | ||
process.once('exit', () => this.tryClose()); | ||
@@ -81,0 +85,0 @@ process.once('SIGINT', () => this.tryClose()); |
@@ -20,4 +20,4 @@ "use strict"; | ||
exports.NatsListener = void 0; | ||
const client_1 = require("./client"); | ||
const constants_1 = require("../constants"); | ||
const client_1 = require("./client"); | ||
/** | ||
@@ -24,0 +24,0 @@ * A NATS listener. |
{ | ||
"name": "@egodigital/microservices", | ||
"version": "0.1.4", | ||
"version": "0.2.0", | ||
"description": "Shared library for microservices, written for Node.js", | ||
@@ -36,4 +36,6 @@ "author": "e.GO Digital GmbH, Aachen, Germany", | ||
"@egodigital/types": "^1.2.0", | ||
"@types/bcryptjs": "^2.4.2", | ||
"@types/express": "^4.17.11", | ||
"@types/jsonwebtoken": "^8.5.0", | ||
"bcryptjs": "^2.4.3", | ||
"express": "^4.17.1", | ||
@@ -40,0 +42,0 @@ "jsonwebtoken": "^8.5.1", |
@@ -17,17 +17,35 @@ [![npm](https://img.shields.io/npm/v/@egodigital/microservices.svg)](https://www.npmjs.com/package/@egodigital/microservices) | ||
#### Constants | ||
### Auth | ||
| Name | Description | Example | | ||
|-------------------|-----------------------------------------------------------------------------|------------------------------------| | ||
| `JWT_SECRET` | The secret for signing and validating JWT. | `mySecretJWTSecret` | | ||
| `NATS_CLUSTER_ID` | The name of the cluster, that contains this and the other microservices. | `ego-microservice-cluster` | | ||
| `NATS_GROUP` | The name of the pod group / kubernetes deployment. | `my-service-or-deployment` | | ||
| `NATS_URL` | The URL to the NATS server. | `http://my-nats-service:4222` | | ||
| `POD_NAME` | The name of the pod. This should come as imported metadata from Kubernetes. | `my-service-or-deployment-XCSGBxV` | | ||
#### Passwords | ||
### Express | ||
```typescript | ||
import { checkPassword, checkPasswordSync, hashPassword, hashPasswordSync } from '@egodigital/microservices'; | ||
const hash1 = await hashPassword('test'); | ||
const matches2 = await checkPassword('test', hash1); | ||
const hash2 = hashPasswordSync('test'); | ||
const matches2 = checkPasswordSync('test', hash2); | ||
``` | ||
#### JWT | ||
```typescript | ||
import { signJWT, verifyJWT } from '@egodigital/microservices'; | ||
interface IUserToken { | ||
uuid: string; | ||
} | ||
const jwt = signJWT({ | ||
uuid: 'cb246b52-b8cd-4916-bfad-6bfc43845597' | ||
}); | ||
const decodedToken = verifyJWT<IUserToken>(jwt); | ||
``` | ||
##### Express | ||
```typescript | ||
import express from 'express'; | ||
@@ -48,2 +66,13 @@ import { withJWT } from '@egodigital/microservices'; | ||
### Constants | ||
| Name | Description | Example | | ||
|-------------------|-----------------------------------------------------------------------------|------------------------------------| | ||
| `BCRYPT_ROUNDS` | The number of rounds for bcrypt hashing. Default: `10` | `12` | | ||
| `JWT_SECRET` | The secret for signing and validating JWT. | `mySecretJWTSecret` | | ||
| `NATS_CLUSTER_ID` | The name of the cluster, that contains all microservices. | `my-cluster` | | ||
| `NATS_GROUP` | The name of the pod group / Kubernetes deployment. | `my-service-or-deployment` | | ||
| `NATS_URL` | The URL to the NATS server. | `http://my-nats-service:4222` | | ||
| `POD_NAME` | The name of the pod. This should come as imported metadata from Kubernetes. | `my-service-or-deployment-xcsgbxv` | | ||
### NATS | ||
@@ -50,0 +79,0 @@ |
50327
23
989
124
8
+ Added@types/bcryptjs@^2.4.2
+ Addedbcryptjs@^2.4.3
+ Added@types/bcryptjs@2.4.6(transitive)
+ Addedbcryptjs@2.4.3(transitive)