@ecom-micro/common 2.0.29 → 2.0.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +19 -19
  2. package/build/errors/badRequestError.d.ts +8 -8
  3. package/build/errors/badRequestError.js +15 -15
  4. package/build/errors/baseError.d.ts +8 -8
  5. package/build/errors/baseError.js +11 -11
  6. package/build/errors/notAuthorized.d.ts +8 -8
  7. package/build/errors/notAuthorized.js +15 -15
  8. package/build/errors/notFoundError.d.ts +9 -9
  9. package/build/errors/notFoundError.js +16 -16
  10. package/build/errors/requestValidationError.d.ts +11 -11
  11. package/build/errors/requestValidationError.js +18 -18
  12. package/build/events/baseListener.d.ts +18 -18
  13. package/build/events/baseListener.js +30 -30
  14. package/build/events/basePublisher.d.ts +13 -13
  15. package/build/events/basePublisher.js +20 -20
  16. package/build/events/productCreatedEvent.d.ts +11 -11
  17. package/build/events/productCreatedEvent.js +2 -2
  18. package/build/events/productDeletedEvent.d.ts +7 -7
  19. package/build/events/productDeletedEvent.js +2 -2
  20. package/build/events/productUpdatedEvent.d.ts +11 -11
  21. package/build/events/productUpdatedEvent.js +2 -2
  22. package/build/events/sellerCreatedEvent.d.ts +9 -9
  23. package/build/events/sellerCreatedEvent.js +2 -2
  24. package/build/events/sellerUpdatedEvent.d.ts +9 -9
  25. package/build/events/sellerUpdatedEvent.js +2 -2
  26. package/build/index.d.ts +13 -12
  27. package/build/index.js +33 -36
  28. package/build/logger/logger.d.ts +2 -0
  29. package/build/logger/logger.js +40 -0
  30. package/build/middleware/currentUser.d.ts +15 -15
  31. package/build/middleware/currentUser.js +20 -20
  32. package/build/middleware/errorHandler.d.ts +2 -2
  33. package/build/middleware/errorHandler.js +23 -23
  34. package/build/middleware/requestValidation.d.ts +2 -2
  35. package/build/middleware/requestValidation.js +22 -22
  36. package/build/middleware/requireAuth.d.ts +2 -2
  37. package/build/middleware/requireAuth.js +11 -11
  38. package/build/middleware/restrictTo.d.ts +2 -2
  39. package/build/middleware/restrictTo.js +13 -13
  40. package/build/queues/connection.d.ts +9 -9
  41. package/build/queues/connection.js +51 -51
  42. package/build/types/subjects.d.ts +12 -12
  43. package/build/types/subjects.js +16 -16
  44. package/package.json +34 -32
package/README.md CHANGED
@@ -1,19 +1,19 @@
1
- ### ecom-micro/common helps developer to catch production level nodejs application error easy way.
2
-
3
- `app.use(errorHandler)` function is to catch global level error. It's alternative to express error controller. You need to use it in your `app.js` or where you write your express app logic.
4
-
5
- #### Example to use any error class
6
-
7
- ```JavaScript
8
- import { BadRequestError } from '@ecom-micro/common';
9
-
10
- return next(new BadRequestError('Invalid email or password'));
11
- // OR
12
- throw new BadRequestError('Invalid email or password');
13
- ```
14
-
15
- ##### List of method
16
-
17
- ```JavaScript
18
- import { BadRequestError, NotFoundError, errorHandler } from '@ecom-micro/common';
19
- ```
1
+ ### ecom-micro/common helps developer to catch production level nodejs application error easy way.
2
+
3
+ `app.use(errorHandler)` function is to catch global level error. It's alternative to express error controller. You need to use it in your `app.js` or where you write your express app logic.
4
+
5
+ #### Example to use any error class
6
+
7
+ ```JavaScript
8
+ import { BadRequestError } from '@ecom-micro/common';
9
+
10
+ return next(new BadRequestError('Invalid email or password'));
11
+ // OR
12
+ throw new BadRequestError('Invalid email or password');
13
+ ```
14
+
15
+ ##### List of method
16
+
17
+ ```JavaScript
18
+ import { BadRequestError, NotFoundError, errorHandler } from '@ecom-micro/common';
19
+ ```
@@ -1,8 +1,8 @@
1
- import { BaseError } from './baseError';
2
- export declare class BadRequestError extends BaseError {
3
- statusCode: number;
4
- constructor(message: string);
5
- serializeErrors(): {
6
- message: string;
7
- }[];
8
- }
1
+ import { BaseError } from './baseError';
2
+ export declare class BadRequestError extends BaseError {
3
+ statusCode: number;
4
+ constructor(message: string);
5
+ serializeErrors(): {
6
+ message: string;
7
+ }[];
8
+ }
@@ -1,15 +1,15 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BadRequestError = void 0;
4
- const baseError_1 = require("./baseError");
5
- class BadRequestError extends baseError_1.BaseError {
6
- constructor(message) {
7
- super(message);
8
- this.statusCode = 400;
9
- Object.setPrototypeOf(this, BadRequestError.prototype);
10
- }
11
- serializeErrors() {
12
- return [{ message: this.message }];
13
- }
14
- }
15
- exports.BadRequestError = BadRequestError;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BadRequestError = void 0;
4
+ const baseError_1 = require("./baseError");
5
+ class BadRequestError extends baseError_1.BaseError {
6
+ constructor(message) {
7
+ super(message);
8
+ this.statusCode = 400;
9
+ Object.setPrototypeOf(this, BadRequestError.prototype);
10
+ }
11
+ serializeErrors() {
12
+ return [{ message: this.message }];
13
+ }
14
+ }
15
+ exports.BadRequestError = BadRequestError;
@@ -1,8 +1,8 @@
1
- export declare abstract class BaseError extends Error {
2
- abstract statusCode: number;
3
- constructor(message: string);
4
- abstract serializeErrors(): {
5
- message: string;
6
- field?: string;
7
- }[];
8
- }
1
+ export declare abstract class BaseError extends Error {
2
+ abstract statusCode: number;
3
+ constructor(message: string);
4
+ abstract serializeErrors(): {
5
+ message: string;
6
+ field?: string;
7
+ }[];
8
+ }
@@ -1,11 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BaseError = void 0;
4
- class BaseError extends Error {
5
- constructor(message) {
6
- super(message);
7
- this.name = this.constructor.name;
8
- Error.captureStackTrace(this, this.constructor);
9
- }
10
- }
11
- exports.BaseError = BaseError;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseError = void 0;
4
+ class BaseError extends Error {
5
+ constructor(message) {
6
+ super(message);
7
+ this.name = this.constructor.name;
8
+ Error.captureStackTrace(this, this.constructor);
9
+ }
10
+ }
11
+ exports.BaseError = BaseError;
@@ -1,8 +1,8 @@
1
- import { BaseError } from './baseError';
2
- export declare class NotAuthorizedError extends BaseError {
3
- statusCode: number;
4
- constructor();
5
- serializeErrors(): {
6
- message: string;
7
- }[];
8
- }
1
+ import { BaseError } from './baseError';
2
+ export declare class NotAuthorizedError extends BaseError {
3
+ statusCode: number;
4
+ constructor();
5
+ serializeErrors(): {
6
+ message: string;
7
+ }[];
8
+ }
@@ -1,15 +1,15 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NotAuthorizedError = void 0;
4
- const baseError_1 = require("./baseError");
5
- class NotAuthorizedError extends baseError_1.BaseError {
6
- constructor() {
7
- super('Not authorized');
8
- this.statusCode = 403;
9
- Object.setPrototypeOf(this, NotAuthorizedError.prototype);
10
- }
11
- serializeErrors() {
12
- return [{ message: 'Oops! You are not authorized to access this route' }];
13
- }
14
- }
15
- exports.NotAuthorizedError = NotAuthorizedError;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NotAuthorizedError = void 0;
4
+ const baseError_1 = require("./baseError");
5
+ class NotAuthorizedError extends baseError_1.BaseError {
6
+ constructor() {
7
+ super('Not authorized');
8
+ this.statusCode = 403;
9
+ Object.setPrototypeOf(this, NotAuthorizedError.prototype);
10
+ }
11
+ serializeErrors() {
12
+ return [{ message: 'Oops! You are not authorized to access this route' }];
13
+ }
14
+ }
15
+ exports.NotAuthorizedError = NotAuthorizedError;
@@ -1,9 +1,9 @@
1
- import { BaseError } from './baseError';
2
- export declare class NotFoundError extends BaseError {
3
- message: string;
4
- statusCode: number;
5
- constructor(message: string);
6
- serializeErrors(): {
7
- message: string;
8
- }[];
9
- }
1
+ import { BaseError } from './baseError';
2
+ export declare class NotFoundError extends BaseError {
3
+ message: string;
4
+ statusCode: number;
5
+ constructor(message: string);
6
+ serializeErrors(): {
7
+ message: string;
8
+ }[];
9
+ }
@@ -1,16 +1,16 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NotFoundError = void 0;
4
- const baseError_1 = require("./baseError");
5
- class NotFoundError extends baseError_1.BaseError {
6
- constructor(message) {
7
- super('Not found error');
8
- this.message = message;
9
- this.statusCode = 404;
10
- Object.setPrototypeOf(this, NotFoundError.prototype);
11
- }
12
- serializeErrors() {
13
- return [{ message: this.message }];
14
- }
15
- }
16
- exports.NotFoundError = NotFoundError;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NotFoundError = void 0;
4
+ const baseError_1 = require("./baseError");
5
+ class NotFoundError extends baseError_1.BaseError {
6
+ constructor(message) {
7
+ super('Not found error');
8
+ this.message = message;
9
+ this.statusCode = 404;
10
+ Object.setPrototypeOf(this, NotFoundError.prototype);
11
+ }
12
+ serializeErrors() {
13
+ return [{ message: this.message }];
14
+ }
15
+ }
16
+ exports.NotFoundError = NotFoundError;
@@ -1,11 +1,11 @@
1
- import { ValidationError } from 'express-validator';
2
- import { BaseError } from './baseError';
3
- export declare class RequestValidationError extends BaseError {
4
- error: ValidationError[];
5
- statusCode: number;
6
- constructor(error: ValidationError[]);
7
- serializeErrors(): {
8
- message: any;
9
- field: string;
10
- }[];
11
- }
1
+ import { ValidationError } from 'express-validator';
2
+ import { BaseError } from './baseError';
3
+ export declare class RequestValidationError extends BaseError {
4
+ error: ValidationError[];
5
+ statusCode: number;
6
+ constructor(error: ValidationError[]);
7
+ serializeErrors(): {
8
+ message: any;
9
+ field: string;
10
+ }[];
11
+ }
@@ -1,18 +1,18 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RequestValidationError = void 0;
4
- const baseError_1 = require("./baseError");
5
- class RequestValidationError extends baseError_1.BaseError {
6
- constructor(error) {
7
- super('Request validation error');
8
- this.error = error;
9
- this.statusCode = 400;
10
- Object.setPrototypeOf(this, RequestValidationError.prototype);
11
- }
12
- serializeErrors() {
13
- return this.error.map((err) => {
14
- return { message: err.msg, field: err.param };
15
- });
16
- }
17
- }
18
- exports.RequestValidationError = RequestValidationError;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RequestValidationError = void 0;
4
+ const baseError_1 = require("./baseError");
5
+ class RequestValidationError extends baseError_1.BaseError {
6
+ constructor(error) {
7
+ super('Request validation error');
8
+ this.error = error;
9
+ this.statusCode = 400;
10
+ Object.setPrototypeOf(this, RequestValidationError.prototype);
11
+ }
12
+ serializeErrors() {
13
+ return this.error.map((err) => {
14
+ return { message: err.msg, field: err.param };
15
+ });
16
+ }
17
+ }
18
+ exports.RequestValidationError = RequestValidationError;
@@ -1,18 +1,18 @@
1
- import { Message, Stan } from 'node-nats-streaming';
2
- import { Subjects } from '../types/subjects';
3
- interface Event {
4
- subject: Subjects;
5
- data: any;
6
- }
7
- export declare abstract class Listener<T extends Event> {
8
- abstract subject: T['subject'];
9
- abstract queueGroupName: string;
10
- abstract onMessage(data: T['data'], msg: Message): void;
11
- protected client: Stan;
12
- protected ackWait: number;
13
- constructor(client: Stan);
14
- subscriptionOptions(): import("node-nats-streaming").SubscriptionOptions;
15
- listen(): void;
16
- parseMessage(msg: Message): any;
17
- }
18
- export {};
1
+ import { Message, Stan } from 'node-nats-streaming';
2
+ import { Subjects } from '../types/subjects';
3
+ interface Event {
4
+ subject: Subjects;
5
+ data: any;
6
+ }
7
+ export declare abstract class Listener<T extends Event> {
8
+ abstract subject: T['subject'];
9
+ abstract queueGroupName: string;
10
+ abstract onMessage(data: T['data'], msg: Message): void;
11
+ protected client: Stan;
12
+ protected ackWait: number;
13
+ constructor(client: Stan);
14
+ subscriptionOptions(): import("node-nats-streaming").SubscriptionOptions;
15
+ listen(): void;
16
+ parseMessage(msg: Message): any;
17
+ }
18
+ export {};
@@ -1,30 +1,30 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Listener = void 0;
4
- class Listener {
5
- constructor(client) {
6
- this.ackWait = 5 * 1000;
7
- this.client = client;
8
- }
9
- subscriptionOptions() {
10
- return this.client
11
- .subscriptionOptions()
12
- .setDeliverAllAvailable()
13
- .setManualAckMode(true)
14
- .setAckWait(this.ackWait)
15
- .setDurableName(this.queueGroupName);
16
- }
17
- listen() {
18
- const subscription = this.client.subscribe(this.subject, this.queueGroupName, this.subscriptionOptions());
19
- subscription.on('message', (msg) => {
20
- console.log(`Message received: ${this.subject} / ${this.queueGroupName}`);
21
- const parsedData = this.parseMessage(msg);
22
- this.onMessage(parsedData, msg);
23
- });
24
- }
25
- parseMessage(msg) {
26
- const data = msg.getData();
27
- return typeof data === 'string' ? JSON.parse(data) : JSON.parse(data.toString('utf8'));
28
- }
29
- }
30
- exports.Listener = Listener;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Listener = void 0;
4
+ class Listener {
5
+ constructor(client) {
6
+ this.ackWait = 5 * 1000;
7
+ this.client = client;
8
+ }
9
+ subscriptionOptions() {
10
+ return this.client
11
+ .subscriptionOptions()
12
+ .setDeliverAllAvailable()
13
+ .setManualAckMode(true)
14
+ .setAckWait(this.ackWait)
15
+ .setDurableName(this.queueGroupName);
16
+ }
17
+ listen() {
18
+ const subscription = this.client.subscribe(this.subject, this.queueGroupName, this.subscriptionOptions());
19
+ subscription.on('message', (msg) => {
20
+ console.log(`Message received: ${this.subject} / ${this.queueGroupName}`);
21
+ const parsedData = this.parseMessage(msg);
22
+ this.onMessage(parsedData, msg);
23
+ });
24
+ }
25
+ parseMessage(msg) {
26
+ const data = msg.getData();
27
+ return typeof data === 'string' ? JSON.parse(data) : JSON.parse(data.toString('utf8'));
28
+ }
29
+ }
30
+ exports.Listener = Listener;
@@ -1,13 +1,13 @@
1
- import { Stan } from 'node-nats-streaming';
2
- import { Subjects } from '../types/subjects';
3
- interface Event {
4
- subject: Subjects;
5
- data: any;
6
- }
7
- export declare abstract class Publisher<T extends Event> {
8
- abstract subject: T['subject'];
9
- protected client: Stan;
10
- constructor(client: Stan);
11
- publish(data: T['data']): Promise<void>;
12
- }
13
- export {};
1
+ import { Stan } from 'node-nats-streaming';
2
+ import { Subjects } from '../types/subjects';
3
+ interface Event {
4
+ subject: Subjects;
5
+ data: any;
6
+ }
7
+ export declare abstract class Publisher<T extends Event> {
8
+ abstract subject: T['subject'];
9
+ protected client: Stan;
10
+ constructor(client: Stan);
11
+ publish(data: T['data']): Promise<void>;
12
+ }
13
+ export {};
@@ -1,20 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Publisher = void 0;
4
- class Publisher {
5
- constructor(client) {
6
- this.client = client;
7
- }
8
- publish(data) {
9
- return new Promise((resolve, reject) => {
10
- this.client.publish(this.subject, JSON.stringify(data), (err) => {
11
- if (err) {
12
- return reject(err);
13
- }
14
- console.log('Event published to subject', this.subject);
15
- resolve();
16
- });
17
- });
18
- }
19
- }
20
- exports.Publisher = Publisher;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Publisher = void 0;
4
+ class Publisher {
5
+ constructor(client) {
6
+ this.client = client;
7
+ }
8
+ publish(data) {
9
+ return new Promise((resolve, reject) => {
10
+ this.client.publish(this.subject, JSON.stringify(data), (err) => {
11
+ if (err) {
12
+ return reject(err);
13
+ }
14
+ console.log('Event published to subject', this.subject);
15
+ resolve();
16
+ });
17
+ });
18
+ }
19
+ }
20
+ exports.Publisher = Publisher;
@@ -1,11 +1,11 @@
1
- import { Subjects } from '../types/subjects';
2
- export interface ProductCreatedEvent {
3
- subject: Subjects.ProductCreated;
4
- data: {
5
- id: string;
6
- title: string;
7
- price: number;
8
- image: string;
9
- sellerId: string;
10
- };
11
- }
1
+ import { Subjects } from '../types/subjects';
2
+ export interface ProductCreatedEvent {
3
+ subject: Subjects.ProductCreated;
4
+ data: {
5
+ id: string;
6
+ title: string;
7
+ price: number;
8
+ image: string;
9
+ sellerId: string;
10
+ };
11
+ }
@@ -1,2 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,7 +1,7 @@
1
- import { Subjects } from '../types/subjects';
2
- export interface ProductDeletedEvent {
3
- subject: Subjects.ProductDeleted;
4
- data: {
5
- id: string;
6
- };
7
- }
1
+ import { Subjects } from '../types/subjects';
2
+ export interface ProductDeletedEvent {
3
+ subject: Subjects.ProductDeleted;
4
+ data: {
5
+ id: string;
6
+ };
7
+ }
@@ -1,2 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,11 +1,11 @@
1
- import { Subjects } from '../types/subjects';
2
- export interface ProductUpdatedEvent {
3
- subject: Subjects.ProductUpdated;
4
- data: {
5
- id: string;
6
- title: string;
7
- price: number;
8
- image: string;
9
- sellerId: string;
10
- };
11
- }
1
+ import { Subjects } from '../types/subjects';
2
+ export interface ProductUpdatedEvent {
3
+ subject: Subjects.ProductUpdated;
4
+ data: {
5
+ id: string;
6
+ title: string;
7
+ price: number;
8
+ image: string;
9
+ sellerId: string;
10
+ };
11
+ }
@@ -1,2 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,9 +1,9 @@
1
- import { Subjects } from '../types/subjects';
2
- export interface SellerCreatedEvent {
3
- subject: Subjects.SellerCreated;
4
- data: {
5
- id: string;
6
- email: string;
7
- role: string;
8
- };
9
- }
1
+ import { Subjects } from '../types/subjects';
2
+ export interface SellerCreatedEvent {
3
+ subject: Subjects.SellerCreated;
4
+ data: {
5
+ id: string;
6
+ email: string;
7
+ role: string;
8
+ };
9
+ }
@@ -1,2 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,9 +1,9 @@
1
- import { Subjects } from '../types/subjects';
2
- export interface SellerUpdatedEvent {
3
- subject: Subjects.SellerUpdated;
4
- data: {
5
- id: string;
6
- email: string;
7
- role: string;
8
- };
9
- }
1
+ import { Subjects } from '../types/subjects';
2
+ export interface SellerUpdatedEvent {
3
+ subject: Subjects.SellerUpdated;
4
+ data: {
5
+ id: string;
6
+ email: string;
7
+ role: string;
8
+ };
9
+ }
@@ -1,2 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/build/index.d.ts CHANGED
@@ -1,12 +1,13 @@
1
- export * from './errors/badRequestError';
2
- export * from './errors/baseError';
3
- export * from './errors/notAuthorized';
4
- export * from './errors/notFoundError';
5
- export * from './errors/requestValidationError';
6
- export * from './middleware/errorHandler';
7
- export * from './middleware/currentUser';
8
- export * from './middleware/restrictTo';
9
- export * from './middleware/requestValidation';
10
- export * from './middleware/requireAuth';
11
- export * from './middleware/currentUser';
12
- export * from './queues/connection';
1
+ export * from './errors/badRequestError';
2
+ export * from './errors/baseError';
3
+ export * from './errors/notAuthorized';
4
+ export * from './errors/notFoundError';
5
+ export * from './errors/requestValidationError';
6
+ export * from './middleware/errorHandler';
7
+ export * from './middleware/currentUser';
8
+ export * from './middleware/restrictTo';
9
+ export * from './middleware/requestValidation';
10
+ export * from './middleware/requireAuth';
11
+ export * from './middleware/currentUser';
12
+ export * from './queues/connection';
13
+ export * from './logger/logger';