@ecom-micro/common 2.0.31 → 2.0.33

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
@@ -11,3 +11,5 @@ export * from './middleware/requireAuth';
11
11
  export * from './middleware/currentUser';
12
12
  export * from './queues/connection';
13
13
  export * from './logger/logger';
14
+ export * from './types/product.types';
15
+ export * from './types/subjects';
package/build/index.js CHANGED
@@ -31,3 +31,6 @@ __exportStar(require("./middleware/currentUser"), exports);
31
31
  __exportStar(require("./queues/connection"), exports);
32
32
  // Logger
33
33
  __exportStar(require("./logger/logger"), exports);
34
+ // Interface
35
+ __exportStar(require("./types/product.types"), exports);
36
+ __exportStar(require("./types/subjects"), exports);
@@ -0,0 +1,16 @@
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 {};
@@ -0,0 +1,38 @@
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;
@@ -0,0 +1,15 @@
1
+ import { Channel, ConsumeMessage } from 'amqplib';
2
+ import { ExchangeTypes } from '../types/subjects';
3
+ interface Event {
4
+ exchange: ExchangeTypes;
5
+ data: any;
6
+ }
7
+ export declare abstract class BaseListener<T extends Event> {
8
+ protected channel: Channel;
9
+ abstract exchangeName: T['exchange'];
10
+ abstract routingKey: string;
11
+ abstract onMessage(data: T['data'], msg: ConsumeMessage): void;
12
+ constructor(channel: Channel);
13
+ listen(): Promise<void>;
14
+ }
15
+ export {};
@@ -0,0 +1,32 @@
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.BaseListener = void 0;
13
+ class BaseListener {
14
+ constructor(channel) {
15
+ this.channel = channel;
16
+ }
17
+ listen() {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ yield this.channel.assertExchange(this.exchangeName, 'direct');
20
+ const consumeQueue = yield this.channel.assertQueue(this.routingKey);
21
+ yield this.channel.bindQueue(consumeQueue.queue, this.exchangeName, this.routingKey);
22
+ this.channel.consume(consumeQueue.queue, (msg) => __awaiter(this, void 0, void 0, function* () {
23
+ console.log(`Message received: ${this.exchangeName} / ${this.routingKey}`);
24
+ if (msg) {
25
+ const parsedData = JSON.parse(msg.content.toString());
26
+ this.onMessage(parsedData, msg);
27
+ }
28
+ }));
29
+ });
30
+ }
31
+ }
32
+ exports.BaseListener = BaseListener;
@@ -0,0 +1,14 @@
1
+ import { Channel } from 'amqplib';
2
+ import { ExchangeTypes } from '../types/subjects';
3
+ interface Event {
4
+ exchange: ExchangeTypes;
5
+ data: any;
6
+ }
7
+ export declare abstract class BasePublisher<T extends Event> {
8
+ protected channel: Channel;
9
+ abstract exchangeName: T['exchange'];
10
+ abstract routingKey: string;
11
+ constructor(channel: Channel);
12
+ publish(data: T['data']): Promise<void>;
13
+ }
14
+ export {};
@@ -0,0 +1,25 @@
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.BasePublisher = void 0;
13
+ class BasePublisher {
14
+ constructor(channel) {
15
+ this.channel = channel;
16
+ }
17
+ publish(data) {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ yield this.channel.assertExchange(this.exchangeName, 'direct');
20
+ this.channel.publish(this.exchangeName, this.routingKey, Buffer.from(data));
21
+ console.log(`Message published Exchange:${this.exchangeName} / RoutingKey: ${this.routingKey}`);
22
+ });
23
+ }
24
+ }
25
+ exports.BasePublisher = BasePublisher;
@@ -1,4 +1,4 @@
1
- import { Channel } from "amqplib";
1
+ import { Channel } from 'amqplib';
2
2
  export declare class QueueConnection {
3
3
  private readonly endPoint;
4
4
  private connection;
@@ -0,0 +1,11 @@
1
+ import { Exchange } from '../types/Exchange';
2
+ export interface ProductCreatedEvent {
3
+ subject: Exchange.ProductCreated;
4
+ data: {
5
+ id: string;
6
+ title: string;
7
+ price: number;
8
+ image: string;
9
+ sellerId: string;
10
+ };
11
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ import { Subjects } from '../../types/subjects';
2
+ export interface ProductDeletedEvent {
3
+ subject: Subjects.ProductDeleted;
4
+ data: {
5
+ id: string;
6
+ };
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,11 @@
1
+ import { Exchange } from '../types/Exchange';
2
+ export interface ProductUpdatedEvent {
3
+ subject: Exchange.ProductUpdated;
4
+ data: {
5
+ id: string;
6
+ title: string;
7
+ price: number;
8
+ image: string;
9
+ sellerId: string;
10
+ };
11
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,9 @@
1
+ import { Exchange } from '../types/Exchange';
2
+ export interface SellerCreatedEvent {
3
+ subject: Exchange.SellerCreated;
4
+ data: {
5
+ id: string;
6
+ email: string;
7
+ role: string;
8
+ };
9
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +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
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,12 @@
1
+ export declare enum Exchange {
2
+ SellerCreated = "seller-created",
3
+ SellerUpdated = "seller-updated",
4
+ ProductCreated = "product-created",
5
+ ProductUpdated = "product-updated",
6
+ ProductDeleted = "product-deleted",
7
+ OrderCreated = "order-created",
8
+ OrderUpdated = "order-updated",
9
+ OrderCanceled = "order-cancelled",
10
+ ProductAddedCart = "product-add-to-cart",
11
+ ProductRemoveCart = "product-remove-to-cart"
12
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Exchange = void 0;
4
+ var Exchange;
5
+ (function (Exchange) {
6
+ Exchange["SellerCreated"] = "seller-created";
7
+ Exchange["SellerUpdated"] = "seller-updated";
8
+ Exchange["ProductCreated"] = "product-created";
9
+ Exchange["ProductUpdated"] = "product-updated";
10
+ Exchange["ProductDeleted"] = "product-deleted";
11
+ Exchange["OrderCreated"] = "order-created";
12
+ Exchange["OrderUpdated"] = "order-updated";
13
+ Exchange["OrderCanceled"] = "order-cancelled";
14
+ Exchange["ProductAddedCart"] = "product-add-to-cart";
15
+ Exchange["ProductRemoveCart"] = "product-remove-to-cart";
16
+ })(Exchange = exports.Exchange || (exports.Exchange = {}));
@@ -0,0 +1,27 @@
1
+ import { Exchange } from '../queues/types/Exchange';
2
+ export interface ProductCreatedMessage {
3
+ exchange: Exchange.ProductCreated;
4
+ data: {
5
+ id: string;
6
+ title: string;
7
+ quantity: number;
8
+ price: number;
9
+ sellerId: string;
10
+ };
11
+ }
12
+ export interface ProductUpdatedMessage {
13
+ exchange: Exchange.ProductUpdated;
14
+ data: {
15
+ id: string;
16
+ title: string;
17
+ quantity: number;
18
+ price: number;
19
+ sellerId: string;
20
+ };
21
+ }
22
+ export interface ProductDeletedMessage {
23
+ exchange: Exchange.ProductDeleted;
24
+ data: {
25
+ id: string;
26
+ };
27
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -10,3 +10,17 @@ 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.Subjects = void 0;
3
+ exports.ExchangeTypes = exports.Subjects = void 0;
4
4
  var Subjects;
5
5
  (function (Subjects) {
6
6
  Subjects["SellerCreated"] = "seller-created";
@@ -14,3 +14,18 @@ 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.31",
3
+ "version": "2.0.33",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",