@konplit-services/common 1.0.90 → 1.0.96

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.
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * @module Publisher
8
8
  */
9
- import { JetStreamClient } from "nats";
9
+ import { JetStreamClient, NatsConnection } from "nats";
10
10
  import { StreamEvent, StreamName } from "../subjects";
11
11
  /**
12
12
  * Event Interface
@@ -32,6 +32,7 @@ interface Event {
32
32
  */
33
33
  export declare abstract class Publisher<T extends Event> {
34
34
  private client;
35
+ private nc?;
35
36
  private jc;
36
37
  /**
37
38
  * The subject associated with the event.
@@ -53,7 +54,7 @@ export declare abstract class Publisher<T extends Event> {
53
54
  *
54
55
  * @param {JetStreamClient} client - The NATS JetStream client
55
56
  */
56
- constructor(client: JetStreamClient);
57
+ constructor(client: JetStreamClient, nc?: NatsConnection);
57
58
  /**
58
59
  * Publishes data to the NATS JetStream.
59
60
  *
@@ -61,6 +62,14 @@ export declare abstract class Publisher<T extends Event> {
61
62
  * @returns {Promise<void>} - Resolves when the data is published successfully
62
63
  */
63
64
  publish(data: T["data"]): Promise<void>;
65
+ /**
66
+ * Sends a request to another service and waits for a reply.
67
+ *
68
+ * @param {T["data"]} data - The data to be sent in the request
69
+ * @param {number} timeout - The timeout duration to wait for a response
70
+ * @returns {Promise<any>} - Resolves with the reply data from the responding service
71
+ */
72
+ request(data: T["data"], timeout?: number): Promise<any>;
64
73
  /**
65
74
  * Ensures the stream exists in the NATS JetStream.
66
75
  * Creates the stream if it does not exist.
@@ -35,9 +35,10 @@ class Publisher {
35
35
  *
36
36
  * @param {JetStreamClient} client - The NATS JetStream client
37
37
  */
38
- constructor(client) {
38
+ constructor(client, nc) {
39
39
  this.jc = (0, nats_1.JSONCodec)();
40
40
  this.client = client;
41
+ this.nc = nc;
41
42
  }
42
43
  /**
43
44
  * Publishes data to the NATS JetStream.
@@ -62,6 +63,33 @@ class Publisher {
62
63
  }));
63
64
  });
64
65
  }
66
+ /**
67
+ * Sends a request to another service and waits for a reply.
68
+ *
69
+ * @param {T["data"]} data - The data to be sent in the request
70
+ * @param {number} timeout - The timeout duration to wait for a response
71
+ * @returns {Promise<any>} - Resolves with the reply data from the responding service
72
+ */
73
+ request(data, timeout = 1000) {
74
+ var _a;
75
+ return __awaiter(this, void 0, void 0, function* () {
76
+ try {
77
+ // Send request and wait for the response
78
+ const response = yield ((_a = this.nc) === null || _a === void 0 ? void 0 : _a.request(this.subject, this.jc.encode(data), { timeout } // Timeout for the response
79
+ ));
80
+ if (!response) {
81
+ throw new Error("Failed to get Response");
82
+ }
83
+ const replyData = this.jc.decode(response.data);
84
+ console.log("Received Reply:", replyData);
85
+ return replyData;
86
+ }
87
+ catch (err) {
88
+ console.error("Error sending request:", err);
89
+ throw err;
90
+ }
91
+ });
92
+ }
65
93
  /**
66
94
  * Ensures the stream exists in the NATS JetStream.
67
95
  * Creates the stream if it does not exist.
@@ -2,5 +2,6 @@ export * from "./subjects";
2
2
  export * from "./accounts-events/interfaces";
3
3
  export * from "./logs-events/interfaces";
4
4
  export * from "./notification-events/interfaces";
5
+ export * from "./wallets/interfaces";
5
6
  export * from "./base-events";
6
7
  export * from "./types";
@@ -18,5 +18,6 @@ __exportStar(require("./subjects"), exports);
18
18
  __exportStar(require("./accounts-events/interfaces"), exports);
19
19
  __exportStar(require("./logs-events/interfaces"), exports);
20
20
  __exportStar(require("./notification-events/interfaces"), exports);
21
+ __exportStar(require("./wallets/interfaces"), exports);
21
22
  __exportStar(require("./base-events"), exports);
22
23
  __exportStar(require("./types"), exports);
@@ -22,5 +22,8 @@ export declare enum Subjects {
22
22
  NotificationSmsCreated = "events.sms.created",
23
23
  NotificationEmailCreated = "events.email.created",
24
24
  UserRoleUpdated = "events.user.role.updated",
25
- AdminLogCreated = "events.admin.log.created"
25
+ AdminLogCreated = "events.admin.log.created",
26
+ WalletCreated = "events.wallet.created",
27
+ WalletCredited = "events.wallet.credited",
28
+ WalletDebited = "events.wallet.debited"
26
29
  }
@@ -36,4 +36,8 @@ var Subjects;
36
36
  // Roles
37
37
  Subjects["UserRoleUpdated"] = "events.user.role.updated";
38
38
  Subjects["AdminLogCreated"] = "events.admin.log.created";
39
+ //Wallets
40
+ Subjects["WalletCreated"] = "events.wallet.created";
41
+ Subjects["WalletCredited"] = "events.wallet.credited";
42
+ Subjects["WalletDebited"] = "events.wallet.debited";
39
43
  })(Subjects = exports.Subjects || (exports.Subjects = {}));
@@ -0,0 +1,3 @@
1
+ export * from "./wallet-created.interface";
2
+ export * from "./wallet-credited.interface";
3
+ export * from "./wallet-debited.interface";
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./wallet-created.interface"), exports);
18
+ __exportStar(require("./wallet-credited.interface"), exports);
19
+ __exportStar(require("./wallet-debited.interface"), exports);
@@ -0,0 +1,11 @@
1
+ import { CURRENCY_TYPE } from "../../../helper";
2
+ import { StreamEvent, StreamName, Subjects } from "../../subjects";
3
+ export interface WalletCreatedEvent {
4
+ subject: Subjects.WalletCreated;
5
+ streamName: StreamName.name;
6
+ streamEvents: StreamEvent.Event;
7
+ data: {
8
+ merchantId: string;
9
+ currencyType?: CURRENCY_TYPE;
10
+ };
11
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,12 @@
1
+ import { CURRENCY_TYPE } from "../../../helper";
2
+ import { StreamEvent, StreamName, Subjects } from "../../subjects";
3
+ export interface WalletCreditedEvent {
4
+ subject: Subjects.WalletCreated;
5
+ streamName: StreamName.name;
6
+ streamEvents: StreamEvent.Event;
7
+ data: {
8
+ merchantId: string;
9
+ amount: number;
10
+ currencyType?: CURRENCY_TYPE;
11
+ };
12
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,12 @@
1
+ import { CURRENCY_TYPE } from "../../../helper";
2
+ import { StreamEvent, StreamName, Subjects } from "../../subjects";
3
+ export interface WalletDebitedEvent {
4
+ subject: Subjects.WalletDebited;
5
+ streamName: StreamName.name;
6
+ streamEvents: StreamEvent.Event;
7
+ data: {
8
+ merchantId: string;
9
+ amount: number;
10
+ currencyType?: CURRENCY_TYPE;
11
+ };
12
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -5,8 +5,8 @@ export declare enum BUSINESS_CATEGORY {
5
5
  EVENT = "EVENT_ACCOUNT"
6
6
  }
7
7
  export declare enum INDIVIDUAL_REQUIRED_TYPE {
8
- driver_license = "DRIVER_LICENSE",
9
- nin = "NIN",
10
- internation_passport = "INTERNATIONAL_PASSPORT",
11
- voter_card = "VOTER_CARD"
8
+ DRIVER_LICENSE = "DRIVER_LICENSE",
9
+ NIN = "NIN",
10
+ INTERNATIONAL_PASSPORT = "INTERNATIONAL_PASSPORT",
11
+ VOTER_CARD = "VOTER_CARD"
12
12
  }
@@ -10,8 +10,8 @@ var BUSINESS_CATEGORY;
10
10
  })(BUSINESS_CATEGORY = exports.BUSINESS_CATEGORY || (exports.BUSINESS_CATEGORY = {}));
11
11
  var INDIVIDUAL_REQUIRED_TYPE;
12
12
  (function (INDIVIDUAL_REQUIRED_TYPE) {
13
- INDIVIDUAL_REQUIRED_TYPE["driver_license"] = "DRIVER_LICENSE";
14
- INDIVIDUAL_REQUIRED_TYPE["nin"] = "NIN";
15
- INDIVIDUAL_REQUIRED_TYPE["internation_passport"] = "INTERNATIONAL_PASSPORT";
16
- INDIVIDUAL_REQUIRED_TYPE["voter_card"] = "VOTER_CARD";
13
+ INDIVIDUAL_REQUIRED_TYPE["DRIVER_LICENSE"] = "DRIVER_LICENSE";
14
+ INDIVIDUAL_REQUIRED_TYPE["NIN"] = "NIN";
15
+ INDIVIDUAL_REQUIRED_TYPE["INTERNATIONAL_PASSPORT"] = "INTERNATIONAL_PASSPORT";
16
+ INDIVIDUAL_REQUIRED_TYPE["VOTER_CARD"] = "VOTER_CARD";
17
17
  })(INDIVIDUAL_REQUIRED_TYPE = exports.INDIVIDUAL_REQUIRED_TYPE || (exports.INDIVIDUAL_REQUIRED_TYPE = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@konplit-services/common",
3
- "version": "1.0.90",
3
+ "version": "1.0.96",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",