@ecom-micro/common 2.0.33 → 2.0.36

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.
package/build/index.d.ts CHANGED
@@ -10,6 +10,11 @@ export * from './middleware/requestValidation';
10
10
  export * from './middleware/requireAuth';
11
11
  export * from './middleware/currentUser';
12
12
  export * from './queues/connection';
13
+ export * from './queues/baseListener';
14
+ export * from './queues/basePublisher';
13
15
  export * from './logger/logger';
14
16
  export * from './types/product.types';
17
+ export * from './types/product.types';
18
+ export * from './types/routingKey.types';
19
+ export * from './types/exchange.types';
15
20
  export * from './types/subjects';
package/build/index.js CHANGED
@@ -29,8 +29,13 @@ __exportStar(require("./middleware/requireAuth"), exports);
29
29
  __exportStar(require("./middleware/currentUser"), exports);
30
30
  // RabbitMQ Service
31
31
  __exportStar(require("./queues/connection"), exports);
32
+ __exportStar(require("./queues/baseListener"), exports);
33
+ __exportStar(require("./queues/basePublisher"), exports);
32
34
  // Logger
33
35
  __exportStar(require("./logger/logger"), exports);
34
36
  // Interface
35
37
  __exportStar(require("./types/product.types"), exports);
38
+ __exportStar(require("./types/product.types"), exports);
39
+ __exportStar(require("./types/routingKey.types"), exports);
40
+ __exportStar(require("./types/exchange.types"), exports);
36
41
  __exportStar(require("./types/subjects"), exports);
@@ -1,5 +1,6 @@
1
1
  import { Channel, ConsumeMessage } from 'amqplib';
2
- import { ExchangeTypes } from '../types/subjects';
2
+ import { ExchangeTypes } from '../types/exchange.types';
3
+ import { RoutingKeyTypes } from '../types/routingKey.types';
3
4
  interface Event {
4
5
  exchange: ExchangeTypes;
5
6
  data: any;
@@ -7,7 +8,7 @@ interface Event {
7
8
  export declare abstract class BaseListener<T extends Event> {
8
9
  protected channel: Channel;
9
10
  abstract exchangeName: T['exchange'];
10
- abstract routingKey: string;
11
+ abstract routingKey: RoutingKeyTypes;
11
12
  abstract onMessage(data: T['data'], msg: ConsumeMessage): void;
12
13
  constructor(channel: Channel);
13
14
  listen(): Promise<void>;
@@ -1,5 +1,6 @@
1
1
  import { Channel } from 'amqplib';
2
- import { ExchangeTypes } from '../types/subjects';
2
+ import { ExchangeTypes } from '../types/exchange.types';
3
+ import { RoutingKeyTypes } from '../types/routingKey.types';
3
4
  interface Event {
4
5
  exchange: ExchangeTypes;
5
6
  data: any;
@@ -7,7 +8,7 @@ interface Event {
7
8
  export declare abstract class BasePublisher<T extends Event> {
8
9
  protected channel: Channel;
9
10
  abstract exchangeName: T['exchange'];
10
- abstract routingKey: string;
11
+ abstract routingKey: RoutingKeyTypes;
11
12
  constructor(channel: Channel);
12
13
  publish(data: T['data']): Promise<void>;
13
14
  }
@@ -0,0 +1,7 @@
1
+ export declare enum ExchangeTypes {
2
+ ProductService = "product-service",
3
+ AuthService = "auth-service",
4
+ CartService = "cart-service",
5
+ OrderService = "order-service",
6
+ NotificationService = "notification-service"
7
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExchangeTypes = void 0;
4
+ var ExchangeTypes;
5
+ (function (ExchangeTypes) {
6
+ ExchangeTypes["ProductService"] = "product-service";
7
+ ExchangeTypes["AuthService"] = "auth-service";
8
+ ExchangeTypes["CartService"] = "cart-service";
9
+ ExchangeTypes["OrderService"] = "order-service";
10
+ ExchangeTypes["NotificationService"] = "notification-service";
11
+ })(ExchangeTypes = exports.ExchangeTypes || (exports.ExchangeTypes = {}));
@@ -1,6 +1,8 @@
1
- import { Exchange } from '../queues/types/Exchange';
1
+ import { ExchangeTypes } from './exchange.types';
2
+ import { RoutingKeyTypes } from './routingKey.types';
2
3
  export interface ProductCreatedMessage {
3
- exchange: Exchange.ProductCreated;
4
+ exchangeName: ExchangeTypes.ProductService;
5
+ routingKey: RoutingKeyTypes.ProductCreated;
4
6
  data: {
5
7
  id: string;
6
8
  title: string;
@@ -10,7 +12,8 @@ export interface ProductCreatedMessage {
10
12
  };
11
13
  }
12
14
  export interface ProductUpdatedMessage {
13
- exchange: Exchange.ProductUpdated;
15
+ exchangeName: ExchangeTypes.ProductService;
16
+ routingKey: RoutingKeyTypes.ProductUpdated;
14
17
  data: {
15
18
  id: string;
16
19
  title: string;
@@ -20,7 +23,8 @@ export interface ProductUpdatedMessage {
20
23
  };
21
24
  }
22
25
  export interface ProductDeletedMessage {
23
- exchange: Exchange.ProductDeleted;
26
+ exchangeName: ExchangeTypes.ProductService;
27
+ routingKey: RoutingKeyTypes.ProductDeleted;
24
28
  data: {
25
29
  id: string;
26
30
  };
@@ -0,0 +1,14 @@
1
+ export declare enum RoutingKeyTypes {
2
+ UserForgotPassword = "user-forgot-password",
3
+ UserResetPassword = "user-rest-password",
4
+ SellerCreated = "seller-created",
5
+ SellerUpdated = "seller-updated",
6
+ ProductCreated = "product-created",
7
+ ProductUpdated = "product-updated",
8
+ ProductDeleted = "product-deleted",
9
+ OrderCreated = "order-created",
10
+ OrderUpdated = "order-updated",
11
+ OrderCanceled = "order-cancelled",
12
+ ProductAddedCart = "product-add-to-cart",
13
+ ProductRemoveCart = "product-remove-to-cart"
14
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RoutingKeyTypes = void 0;
4
+ var RoutingKeyTypes;
5
+ (function (RoutingKeyTypes) {
6
+ RoutingKeyTypes["UserForgotPassword"] = "user-forgot-password";
7
+ RoutingKeyTypes["UserResetPassword"] = "user-rest-password";
8
+ RoutingKeyTypes["SellerCreated"] = "seller-created";
9
+ RoutingKeyTypes["SellerUpdated"] = "seller-updated";
10
+ RoutingKeyTypes["ProductCreated"] = "product-created";
11
+ RoutingKeyTypes["ProductUpdated"] = "product-updated";
12
+ RoutingKeyTypes["ProductDeleted"] = "product-deleted";
13
+ RoutingKeyTypes["OrderCreated"] = "order-created";
14
+ RoutingKeyTypes["OrderUpdated"] = "order-updated";
15
+ RoutingKeyTypes["OrderCanceled"] = "order-cancelled";
16
+ RoutingKeyTypes["ProductAddedCart"] = "product-add-to-cart";
17
+ RoutingKeyTypes["ProductRemoveCart"] = "product-remove-to-cart";
18
+ })(RoutingKeyTypes = exports.RoutingKeyTypes || (exports.RoutingKeyTypes = {}));
@@ -10,17 +10,3 @@ export declare enum Subjects {
10
10
  ProductAddedCart = "product-add-to-cart",
11
11
  ProductRemoveCart = "product-remove-to-cart"
12
12
  }
13
- export declare enum ExchangeTypes {
14
- UserForgotPassword = "user-forgot-password",
15
- UserResetPassword = "user-rest-password",
16
- SellerCreated = "seller-created",
17
- SellerUpdated = "seller-updated",
18
- ProductCreated = "product-created",
19
- ProductUpdated = "product-updated",
20
- ProductDeleted = "product-deleted",
21
- OrderCreated = "order-created",
22
- OrderUpdated = "order-updated",
23
- OrderCanceled = "order-cancelled",
24
- ProductAddedCart = "product-add-to-cart",
25
- ProductRemoveCart = "product-remove-to-cart"
26
- }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ExchangeTypes = exports.Subjects = void 0;
3
+ exports.Subjects = void 0;
4
4
  var Subjects;
5
5
  (function (Subjects) {
6
6
  Subjects["SellerCreated"] = "seller-created";
@@ -14,18 +14,3 @@ var Subjects;
14
14
  Subjects["ProductAddedCart"] = "product-add-to-cart";
15
15
  Subjects["ProductRemoveCart"] = "product-remove-to-cart";
16
16
  })(Subjects = exports.Subjects || (exports.Subjects = {}));
17
- var ExchangeTypes;
18
- (function (ExchangeTypes) {
19
- ExchangeTypes["UserForgotPassword"] = "user-forgot-password";
20
- ExchangeTypes["UserResetPassword"] = "user-rest-password";
21
- ExchangeTypes["SellerCreated"] = "seller-created";
22
- ExchangeTypes["SellerUpdated"] = "seller-updated";
23
- ExchangeTypes["ProductCreated"] = "product-created";
24
- ExchangeTypes["ProductUpdated"] = "product-updated";
25
- ExchangeTypes["ProductDeleted"] = "product-deleted";
26
- ExchangeTypes["OrderCreated"] = "order-created";
27
- ExchangeTypes["OrderUpdated"] = "order-updated";
28
- ExchangeTypes["OrderCanceled"] = "order-cancelled";
29
- ExchangeTypes["ProductAddedCart"] = "product-add-to-cart";
30
- ExchangeTypes["ProductRemoveCart"] = "product-remove-to-cart";
31
- })(ExchangeTypes = exports.ExchangeTypes || (exports.ExchangeTypes = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecom-micro/common",
3
- "version": "2.0.33",
3
+ "version": "2.0.36",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -1,16 +0,0 @@
1
- import { Channel, ConsumeMessage } from 'amqplib';
2
- import { Exchange } from './types/Exchange';
3
- interface Event {
4
- exchangeName: Exchange;
5
- data: any;
6
- }
7
- export declare abstract class MQConsumer<T extends Event> {
8
- abstract exchangeName: T['exchangeName'];
9
- abstract routingKey: string;
10
- abstract queueName: string;
11
- protected channel: Channel;
12
- abstract onMessage(data: T['data'], msg: ConsumeMessage): void;
13
- constructor(channel: Channel);
14
- consume(): Promise<void>;
15
- }
16
- export {};
@@ -1,38 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.MQConsumer = void 0;
13
- class MQConsumer {
14
- constructor(channel) {
15
- this.channel = channel;
16
- }
17
- consume() {
18
- return __awaiter(this, void 0, void 0, function* () {
19
- this.channel.assertExchange(this.exchangeName, 'direct');
20
- // `assertQueue` will check if there is a queue exist or not to listen the messages
21
- // if present then it will not create again
22
- // if not then it will create a queue with provided name
23
- const ecomQueue = yield this.channel.assertQueue(this.queueName, {
24
- durable: true,
25
- autoDelete: false,
26
- });
27
- yield this.channel.bindQueue(ecomQueue.queue, this.exchangeName, this.routingKey);
28
- this.channel.consume(ecomQueue.queue, (msg) => __awaiter(this, void 0, void 0, function* () {
29
- console.log(`Message received: ${this.exchangeName} / ${this.queueName}`);
30
- if (msg) {
31
- const parsedData = JSON.parse(msg.content.toString());
32
- this.onMessage(parsedData, msg);
33
- }
34
- }));
35
- });
36
- }
37
- }
38
- exports.MQConsumer = MQConsumer;