skyeye-svc-common-utils 1.0.39 → 1.0.41

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.
@@ -2,7 +2,6 @@
2
2
  "cSpell.words": [
3
3
  "APIKEY",
4
4
  "DELINK",
5
- "Grpc",
6
5
  "ICBSECTOR",
7
6
  "KEYVAULT",
8
7
  "NERL",
package/dist/index.d.ts CHANGED
@@ -12,6 +12,7 @@ export * from './utils/baseClass/baseController';
12
12
  export * from './utils/baseClass/baseService';
13
13
  export * from './interfaces/index';
14
14
  export * from './lib/azure/azureKeyVault';
15
+ export * from './lib/azure/azureServiceBusClient';
15
16
  export * from './lib/azure/azureStorageQueue';
16
17
  export * from './lib/azure/azureServiceBusQueue';
17
18
  export * from './lib/azure/azureTableStorage';
package/dist/index.js CHANGED
@@ -25,6 +25,7 @@ __exportStar(require("./utils/baseClass/baseController"), exports);
25
25
  __exportStar(require("./utils/baseClass/baseService"), exports);
26
26
  __exportStar(require("./interfaces/index"), exports);
27
27
  __exportStar(require("./lib/azure/azureKeyVault"), exports);
28
+ __exportStar(require("./lib/azure/azureServiceBusClient"), exports);
28
29
  __exportStar(require("./lib/azure/azureStorageQueue"), exports);
29
30
  __exportStar(require("./lib/azure/azureServiceBusQueue"), exports);
30
31
  __exportStar(require("./lib/azure/azureTableStorage"), exports);
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAkC;AAClC,mDAAiC;AACjC,sDAAoC;AACpC,8DAA4C;AAC5C,wDAAsC;AACtC,4DAAsE;AAA7D,4GAAA,OAAO,OAAgB;AAChC,iEAA+C;AAC/C,kEAAgD;AAChD,oEAAkD;AAClD,uEAAqD;AACrD,mEAAiD;AACjD,gEAA8C;AAC9C,qDAAmC;AACnC,4DAA0C;AAC1C,gEAA8C;AAC9C,mEAAiD;AACjD,gEAA8C;AAC9C,+DAA6C;AAC7C,gEAA8C;AAC9C,mDAAiC;AACjC,yDAAuC;AACvC,mEAAiD;AACjD,2CAAyB;AACzB,oDAAkC;AAClC,uDAAqC;AACrC,mEAAiD;AACjD,+DAA6C;AAC7C,4EAA0D"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAkC;AAClC,mDAAiC;AACjC,sDAAoC;AACpC,8DAA4C;AAC5C,wDAAsC;AACtC,4DAAsE;AAA7D,4GAAA,OAAO,OAAgB;AAChC,iEAA+C;AAC/C,kEAAgD;AAChD,oEAAkD;AAClD,uEAAqD;AACrD,mEAAiD;AACjD,gEAA8C;AAC9C,qDAAmC;AACnC,4DAA0C;AAC1C,oEAAkD;AAClD,gEAA8C;AAC9C,mEAAiD;AACjD,gEAA8C;AAC9C,+DAA6C;AAC7C,gEAA8C;AAC9C,mDAAiC;AACjC,yDAAuC;AACvC,mEAAiD;AACjD,2CAAyB;AACzB,oDAAkC;AAClC,uDAAqC;AACrC,mEAAiD;AACjD,+DAA6C;AAC7C,4EAA0D"}
@@ -0,0 +1,47 @@
1
+ import { ServiceBusMessage, ServiceBusReceivedMessage } from '@azure/service-bus';
2
+ export declare class ServiceBusClient {
3
+ private connection;
4
+ private queueName;
5
+ private sender;
6
+ private receiver;
7
+ constructor(connectionString: string, queueName: string);
8
+ /**
9
+ * The function closes the sender, receiver, and connection objects if they exist.
10
+ */
11
+ closeConnection(): Promise<void>;
12
+ /**
13
+ * The function "getOrCreateSender" creates a sender if it doesn't exist and returns it.
14
+ * @returns The `getOrCreateSender` function returns a Promise that resolves to the `sender`
15
+ * object.
16
+ */
17
+ private getOrCreateSender;
18
+ /**
19
+ * The function `getOrCreateReceiver` creates a receiver if it doesn't already exist and returns
20
+ * it.
21
+ * @returns The `getOrCreateReceiver` function is returning the `this.receiver` object.
22
+ */
23
+ private getOrCreateReceiver;
24
+ /**
25
+ * The function sends an array of messages using a Service Bus sender, creating a new message batch
26
+ * if the current batch is full.
27
+ * @param {ServiceBusMessage[]} messages - An array of ServiceBusMessage objects.
28
+ * @returns a Promise.
29
+ */
30
+ sendMessage(messages: ServiceBusMessage[]): Promise<void>;
31
+ /**
32
+ * The function `receiveMessage` retrieves messages from a Service Bus queue or topic subscription,
33
+ * either by receiving them or peeking at them, and returns an array of received messages.
34
+ * @param {boolean} [receiveMode=true] - The `receiveMode` parameter is a boolean flag that determines
35
+ * whether the messages should be peeked or received. When `receiveMode` is set to `false`, the method
36
+ * will peek messages from the queue without removing them. When `receiveMode` is set to `true` (or
37
+ * not provided, the method remove messages from the queue after retrieval.
38
+ * @param {number} [numMessageRequired] - The `numMessageRequired` parameter is an optional
39
+ * parameter that specifies the maximum number of messages required. If this parameter is provided,
40
+ * the function will stop receiving messages once the number of received messages reaches or
41
+ * exceeds the specified value. If this parameter is not provided, the function will continue to
42
+ * receive messages until no more message in the queue.
43
+ * @returns The function `receiveMessage` returns a promise that resolves to an array of
44
+ * `ServiceBusReceivedMessage` objects.
45
+ */
46
+ receiveMessage(receiveMode?: boolean, numMessageRequired?: number): Promise<ServiceBusReceivedMessage[]>;
47
+ }
@@ -0,0 +1,139 @@
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.ServiceBusClient = void 0;
13
+ const service_bus_1 = require("@azure/service-bus");
14
+ const appConst_1 = require("../../utils/appConst");
15
+ /* The `ServiceBusClient` class is a TypeScript class that provides methods for sending and receiving
16
+ messages using Azure Service Bus. */
17
+ class ServiceBusClient {
18
+ constructor(connectionString, queueName) {
19
+ this.connection = new service_bus_1.ServiceBusClient(connectionString);
20
+ this.queueName = queueName;
21
+ }
22
+ /**
23
+ * The function closes the sender, receiver, and connection objects if they exist.
24
+ */
25
+ closeConnection() {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ if (this.sender) {
28
+ yield this.sender.close();
29
+ }
30
+ if (this.receiver) {
31
+ yield this.receiver.close();
32
+ }
33
+ if (this.connection) {
34
+ yield this.connection.close();
35
+ }
36
+ });
37
+ }
38
+ /**
39
+ * The function "getOrCreateSender" creates a sender if it doesn't exist and returns it.
40
+ * @returns The `getOrCreateSender` function returns a Promise that resolves to the `sender`
41
+ * object.
42
+ */
43
+ getOrCreateSender() {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ if (!this.sender) {
46
+ this.sender = this.connection.createSender(this.queueName);
47
+ }
48
+ return this.sender;
49
+ });
50
+ }
51
+ /**
52
+ * The function `getOrCreateReceiver` creates a receiver if it doesn't already exist and returns
53
+ * it.
54
+ * @returns The `getOrCreateReceiver` function is returning the `this.receiver` object.
55
+ */
56
+ getOrCreateReceiver() {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ if (!this.receiver) {
59
+ this.receiver = this.connection.createReceiver(this.queueName, {
60
+ receiveMode: 'receiveAndDelete'
61
+ });
62
+ }
63
+ return this.receiver;
64
+ });
65
+ }
66
+ /**
67
+ * The function sends an array of messages using a Service Bus sender, creating a new message batch
68
+ * if the current batch is full.
69
+ * @param {ServiceBusMessage[]} messages - An array of ServiceBusMessage objects.
70
+ * @returns a Promise.
71
+ */
72
+ sendMessage(messages) {
73
+ return __awaiter(this, void 0, void 0, function* () {
74
+ if (messages.length === 0)
75
+ return;
76
+ const sender = yield this.getOrCreateSender();
77
+ try {
78
+ let batch = yield sender.createMessageBatch();
79
+ for (const message of messages) {
80
+ if (!batch.tryAddMessage(message)) {
81
+ yield sender.sendMessages(batch);
82
+ batch = yield sender.createMessageBatch();
83
+ if (!batch.tryAddMessage(message)) {
84
+ throw new Error('Message is too large.');
85
+ }
86
+ }
87
+ }
88
+ yield sender.sendMessages(batch);
89
+ }
90
+ catch (err) {
91
+ throw new Error(`serviceBusClient/sendMessage: ${err}`);
92
+ }
93
+ });
94
+ }
95
+ /**
96
+ * The function `receiveMessage` retrieves messages from a Service Bus queue or topic subscription,
97
+ * either by receiving them or peeking at them, and returns an array of received messages.
98
+ * @param {boolean} [receiveMode=true] - The `receiveMode` parameter is a boolean flag that determines
99
+ * whether the messages should be peeked or received. When `receiveMode` is set to `false`, the method
100
+ * will peek messages from the queue without removing them. When `receiveMode` is set to `true` (or
101
+ * not provided, the method remove messages from the queue after retrieval.
102
+ * @param {number} [numMessageRequired] - The `numMessageRequired` parameter is an optional
103
+ * parameter that specifies the maximum number of messages required. If this parameter is provided,
104
+ * the function will stop receiving messages once the number of received messages reaches or
105
+ * exceeds the specified value. If this parameter is not provided, the function will continue to
106
+ * receive messages until no more message in the queue.
107
+ * @returns The function `receiveMessage` returns a promise that resolves to an array of
108
+ * `ServiceBusReceivedMessage` objects.
109
+ */
110
+ receiveMessage(receiveMode = true, numMessageRequired) {
111
+ return __awaiter(this, void 0, void 0, function* () {
112
+ const receiver = yield this.getOrCreateReceiver();
113
+ try {
114
+ const result = [];
115
+ let messages;
116
+ while (true) {
117
+ messages = receiveMode ?
118
+ yield receiver.receiveMessages(appConst_1.commonAppConst.serviceBus.receiverOptions.maxMessageCount, {
119
+ maxWaitTimeInMs: appConst_1.commonAppConst.serviceBus.receiverOptions.maxWaitTimeInMs,
120
+ }) :
121
+ yield receiver.peekMessages(appConst_1.commonAppConst.serviceBus.receiverOptions.maxWaitTimeInMs);
122
+ if (messages.length === 0) {
123
+ break; // No more messages in the queue
124
+ }
125
+ result.push(...messages);
126
+ if (numMessageRequired !== undefined && result.length >= numMessageRequired) {
127
+ break;
128
+ }
129
+ }
130
+ return result.slice(0, numMessageRequired);
131
+ }
132
+ catch (err) {
133
+ throw new Error(`serviceBusClient/peekMessage: ${err}`);
134
+ }
135
+ });
136
+ }
137
+ }
138
+ exports.ServiceBusClient = ServiceBusClient;
139
+ //# sourceMappingURL=azureServiceBusClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"azureServiceBusClient.js","sourceRoot":"","sources":["../../../src/lib/azure/azureServiceBusClient.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAI4B;AAC5B,mDAAsD;AAEtD;oCACoC;AACpC,MAAa,gBAAgB;IAMzB,YAAY,gBAAwB,EAAE,SAAiB;QACnD,IAAI,CAAC,UAAU,GAAG,IAAI,8BAAqB,CAAC,gBAAgB,CAAC,CAAC;QAC9D,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC/B,CAAC;IAED;;OAEG;IACG,eAAe;;YACjB,IAAI,IAAI,CAAC,MAAM,EAAE;gBACb,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;aAC7B;YACD,IAAI,IAAI,CAAC,QAAQ,EAAE;gBACf,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;aAC/B;YACD,IAAI,IAAI,CAAC,UAAU,EAAE;gBACjB,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;aACjC;QACL,CAAC;KAAA;IAED;;;;OAIG;IACW,iBAAiB;;YAC3B,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;gBACd,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;aAC9D;YACD,OAAO,IAAI,CAAC,MAAM,CAAC;QACvB,CAAC;KAAA;IAED;;;;OAIG;IACW,mBAAmB;;YAC7B,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;gBAChB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,IAA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CAAC,eAAe,CAAC,eAAe,EACzD;4BACI,eAAe,EAAE,yBAAc,CAAC,UAAU,CAAC,eAAe,CAAC,eAAe;yBAC7E,CACJ,CAAC,CAAC;wBACH,MAAM,QAAQ,CAAC,YAAY,CAAC,yBAAc,CAAC,UAAU,CAAC,eAAe,CAAC,eAAe,CAAC,CAAC;oBAC3F,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;wBACvB,MAAM,CAAC,gCAAgC;qBAC1C;oBACD,MAAM,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAC;oBACzB,IAAI,kBAAkB,KAAK,SAAS,IAAI,MAAM,CAAC,MAAM,IAAI,kBAAkB,EAAE;wBACzE,MAAM;qBACT;iBACJ;gBACD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,kBAAkB,CAAC,CAAC;aAC9C;YAAC,OAAO,GAAG,EAAE;gBACV,MAAM,IAAI,KAAK,CAAC,iCAAiC,GAAG,EAAE,CAAC,CAAC;aAC3D;QACL,CAAC;KAAA;CACJ;AAxHD,4CAwHC"}
@@ -43,6 +43,19 @@ export declare const commonAppConst: {
43
43
  setIfNotExist: string;
44
44
  };
45
45
  };
46
+ serviceBus: {
47
+ receiverOptions: {
48
+ receiveMode: string;
49
+ /**
50
+ * The maximum time to wait for the first message before returning an empty array if no messages are available.
51
+ */
52
+ maxWaitTimeInMs: number;
53
+ maxMessageCount: number;
54
+ };
55
+ senderOptions: {
56
+ contentType: string;
57
+ };
58
+ };
46
59
  user: {
47
60
  public: string;
48
61
  internal: string;
@@ -46,6 +46,19 @@ exports.commonAppConst = {
46
46
  setIfNotExist: 'nx'
47
47
  }
48
48
  },
49
+ serviceBus: {
50
+ receiverOptions: {
51
+ receiveMode: 'receiveAndDelete',
52
+ /**
53
+ * The maximum time to wait for the first message before returning an empty array if no messages are available.
54
+ */
55
+ maxWaitTimeInMs: 1000,
56
+ maxMessageCount: 100
57
+ },
58
+ senderOptions: {
59
+ contentType: "application/json"
60
+ }
61
+ },
49
62
  user: {
50
63
  public: 'public',
51
64
  internal: 'internal',
@@ -1 +1 @@
1
- {"version":3,"file":"appConst.js","sourceRoot":"","sources":["../../src/utils/appConst.ts"],"names":[],"mappings":";;;AAAa,QAAA,cAAc,GAAG;IAC7B,SAAS,EAAE,sCAAsC;IACjD,YAAY,EAAE;QACb,GAAG,EAAE,KAAK;QACV,OAAO,EAAE,SAAS;QAClB,OAAO,EAAE,SAAS;KAClB;IACD,YAAY,EAAE;QACb,IAAI,EAAE,MAAM;QACZ,GAAG,EAAE,KAAK;QACV,IAAI,EAAE,MAAM;QACZ,KAAK,EAAE,OAAO;KACd;IACD,UAAU,EAAE;QACX,GAAG,EAAE,KAAK;QACV,IAAI,EAAE,MAAM;QACZ,GAAG,EAAE,KAAK;QACV,MAAM,EAAE,QAAQ;KAChB;IACD,UAAU,EAAE;QACX,SAAS,EAAE,WAAW;QACtB,aAAa,EAAE,eAAe;QAC9B,MAAM,EAAE,QAAQ;QAChB,OAAO,EAAE,SAAS;QAChB,mBAAmB,EAAE,SAAS;QAChC,eAAe,EAAE,kBAAkB;KACnC;IACD,KAAK,EAAE;QACN,GAAG,EAAE,KAAK;QACV,IAAI,EAAE,MAAM;KACZ;IACD,cAAc,EAAE;QACf,EAAE,EAAE,IAAI;QACR,WAAW,EAAE,aAAa;QAC1B,gBAAgB,EAAE,kBAAkB;KACpC;IACD,KAAK,EAAE;QACN,UAAU,EAAE;YACX,SAAS,EAAE,IAAI;SACf;QACD,UAAU,EAAE,GAAG;QACf,OAAO,EAAE;YACR,aAAa,EAAE,IAAI;SACnB;KACD;IACD,IAAI,EAAE;QACL,MAAM,EAAE,QAAQ;QAChB,QAAQ,EAAE,UAAU;QACpB,eAAe,EAAE;YAChB,0BAA0B;YAC1B,4BAA4B;SAC5B;QACD,IAAI,EAAE;YACL,iCAAiC,EAAE,mCAAmC;YACtE,OAAO,EAAE,SAAS;SAClB;QACD,IAAI,EAAE;YACL,GAAG,EAAE,KAAK;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BAAqB;IAChC,sCAAa,CAAA;AACd,CAAC,EAFW,qBAAqB,GAArB,6BAAqB,KAArB,6BAAqB,QAEhC;AAGD,SAAgB,sBAAsB;IACrC,OAAO;QACN,cAAc,EAAE,kBAAkB;KAClC,CAAC;AACH,CAAC;AAJD,wDAIC;AAED,IAAY,UAKX;AALD,WAAY,UAAU;IACrB,+BAAiB,CAAA;IACjB,iCAAmB,CAAA;IACnB,iCAAmB,CAAA;IACnB,kCAAoB,CAAA;AACrB,CAAC,EALW,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAKrB;AAED,IAAY,0BAMX;AAND,WAAY,0BAA0B;IACrC,qFAAS,CAAA;IACT,mFAAQ,CAAA;IACR,mFAAQ,CAAA;IACR,mFAAQ,CAAA;IACR,yFAAW,CAAA;AACZ,CAAC,EANW,0BAA0B,GAA1B,kCAA0B,KAA1B,kCAA0B,QAMrC;AAED,IAAY,oBAKX;AALD,WAAY,oBAAoB;IAC/B,qEAAO,CAAA;IACP,yEAAS,CAAA;IACT,uEAAQ,CAAA;IACR,uEAAQ,CAAA;AACT,CAAC,EALW,oBAAoB,GAApB,4BAAoB,KAApB,4BAAoB,QAK/B;AAEY,QAAA,gBAAgB,GAA0B;IACtD,cAAc,EAAE,kFAAkF;IAClG,cAAc,EAAE,2CAA2C;CAC3D,CAAA"}
1
+ {"version":3,"file":"appConst.js","sourceRoot":"","sources":["../../src/utils/appConst.ts"],"names":[],"mappings":";;;AAAa,QAAA,cAAc,GAAG;IAC7B,SAAS,EAAE,sCAAsC;IACjD,YAAY,EAAE;QACb,GAAG,EAAE,KAAK;QACV,OAAO,EAAE,SAAS;QAClB,OAAO,EAAE,SAAS;KAClB;IACD,YAAY,EAAE;QACb,IAAI,EAAE,MAAM;QACZ,GAAG,EAAE,KAAK;QACV,IAAI,EAAE,MAAM;QACZ,KAAK,EAAE,OAAO;KACd;IACD,UAAU,EAAE;QACX,GAAG,EAAE,KAAK;QACV,IAAI,EAAE,MAAM;QACZ,GAAG,E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AACrB,CAAC,EALW,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAKrB;AAED,IAAY,0BAMX;AAND,WAAY,0BAA0B;IACrC,qFAAS,CAAA;IACT,mFAAQ,CAAA;IACR,mFAAQ,CAAA;IACR,mFAAQ,CAAA;IACR,yFAAW,CAAA;AACZ,CAAC,EANW,0BAA0B,GAA1B,kCAA0B,KAA1B,kCAA0B,QAMrC;AAED,IAAY,oBAKX;AALD,WAAY,oBAAoB;IAC/B,qEAAO,CAAA;IACP,yEAAS,CAAA;IACT,uEAAQ,CAAA;IACR,uEAAQ,CAAA;AACT,CAAC,EALW,oBAAoB,GAApB,4BAAoB,KAApB,4BAAoB,QAK/B;AAEY,QAAA,gBAAgB,GAA0B;IACtD,cAAc,EAAE,kFAAkF;IAClG,cAAc,EAAE,2CAA2C;CAC3D,CAAA"}
@@ -8,5 +8,4 @@ export declare abstract class BaseController {
8
8
  startTransaction(): Promise<QueryRunner>;
9
9
  endTransaction(baseControllerParameter: BaseControllerParameter): Promise<any>;
10
10
  executeRest(req: Request, res: Response, next: NextFunction): Promise<void>;
11
- executeGrpc(call: any, callback: any): Promise<any>;
12
11
  }
@@ -14,7 +14,6 @@ const commonUtils_1 = require("../commonUtils");
14
14
  const logger_1 = require("../logger/logger");
15
15
  const models_1 = require("../../models");
16
16
  const typeorm_1 = require("typeorm");
17
- const appConst_1 = require("../appConst");
18
17
  const appConfig_1 = require("../appConfig");
19
18
  const async_mutex_1 = require("async-mutex");
20
19
  class BaseController {
@@ -117,58 +116,6 @@ class BaseController {
117
116
  logger_1.logger.profile(`${req.originalUrl}`);
118
117
  });
119
118
  }
120
- executeGrpc(call, callback) {
121
- return __awaiter(this, void 0, void 0, function* () {
122
- let baseControllerParameter = new models_1.BaseControllerParameter();
123
- baseControllerParameter.serviceResponse = { isSuccess: false, message: undefined, data: undefined, totalCount: undefined };
124
- try {
125
- baseControllerParameter.userInfo = undefined;
126
- const authorization = call.metadata.get(appConst_1.commonAppConst.httpHeader.AUTHORIZATION);
127
- if (!!authorization && authorization.length) {
128
- const headerInfo = authorization[0].split(' ');
129
- if (headerInfo.length === 2 && headerInfo[0] === appConst_1.commonAppConst.httpHeader.BEARER) {
130
- baseControllerParameter.userInfo = yield commonUtils_1.verifyJWT(headerInfo[1]);
131
- }
132
- }
133
- if (appConfig_1.commonAppConfig.SqlEnable) {
134
- BaseController.mutex.runExclusive(() => __awaiter(this, void 0, void 0, function* () {
135
- this.startTransaction().then((queryRunner) => {
136
- baseControllerParameter.queryRunner = queryRunner;
137
- return this.executeImpl(call.request, baseControllerParameter);
138
- }).then(() => {
139
- return this.endTransaction(baseControllerParameter);
140
- }).then(() => {
141
- return callback(null, baseControllerParameter.serviceResponse);
142
- }).catch((err) => {
143
- baseControllerParameter.serviceResponse.isSuccess = false;
144
- baseControllerParameter.serviceResponse.error = true;
145
- baseControllerParameter.serviceResponse.message = err.message;
146
- this.endTransaction(baseControllerParameter).then(() => {
147
- throw err;
148
- });
149
- });
150
- ;
151
- }));
152
- }
153
- else {
154
- this.executeImpl(call.request, baseControllerParameter).then(() => {
155
- return callback(null, baseControllerParameter.serviceResponse);
156
- }).catch((err) => {
157
- baseControllerParameter.serviceResponse.isSuccess = false;
158
- baseControllerParameter.serviceResponse.error = true;
159
- baseControllerParameter.serviceResponse.message = err.message;
160
- throw err;
161
- });
162
- }
163
- }
164
- catch (err) {
165
- logger_1.logger.error(`BaseController/executeGrpc: ${err}`);
166
- baseControllerParameter.serviceResponse.isSuccess = false;
167
- baseControllerParameter.serviceResponse.error = true;
168
- return callback(null, baseControllerParameter.serviceResponse);
169
- }
170
- });
171
- }
172
119
  }
173
120
  exports.BaseController = BaseController;
174
121
  BaseController.mutex = new async_mutex_1.Mutex();
@@ -1 +1 @@
1
- {"version":3,"file":"baseController.js","sourceRoot":"","sources":["../../../src/utils/baseClass/baseController.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,gDAAsE;AACtE,6CAA0C;AAE1C,yCAAuD;AACvD,qCAAqD;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AE,IAAI,EAAE,uBAAuB,CAAC,eAAe,CAAC,CAAC;wBAC5E,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAU,EAAE,EAAE;4BACpB,uBAAuB,CAAC,eAAe,CAAC,SAAS,GAAG,KAAK,CAAC;4BAC1D,IAAI,CAAC,cAAc,CAAC,uBAAuB,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE;gCACnD,IAAI,CAAC,GAAG,CAAC,CAAC;4BACd,CAAC,CAAC,CAAC;wBACP,CAAC,CAAC,CAAC;wBAAA,CAAC;oBACR,CAAC,CAAA,CAAC,CAAC;iBACN;qBAAM;oBACH,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,EAAE,uBAAuB,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE;wBAC1D,OAAO,0BAAY,CAAC,GAAG,EAAE,IAAI,EAAE,uBAAuB,CAAC,eAAe,CAAC,CAAC;oBAC5E,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAU,EAAE,EAAE;wBACpB,uBAAuB,CAAC,eAAe,CAAC,SAAS,GAAG,KAAK,CAAC;wBAC1D,IAAI,CAAC,GAAG,CAAC,CAAC;oBACd,CAAC,CAAC,CAAC;iBACN;aACJ;YAAC,OAAO,GAAG,EAAE;gBACV,IAAI,CAAC,GAAG,CAAC,CAAC;aACb;YAED,eAAM,CAAC,OAAO,CAAC,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC;QACzC,CAAC;KAAA;;AAhGL,wCAiGC;AA/FU,oBAAK,GAAU,IAAI,mBAAK,EAAE,CAAC;AA+FrC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "skyeye-svc-common-utils",
3
- "version": "1.0.39",
3
+ "version": "1.0.41",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -26,8 +26,6 @@
26
26
  "@azure/service-bus": "^7.1.0",
27
27
  "@azure/storage-blob": "^12.1.2",
28
28
  "@azure/storage-queue": "^12.0.2",
29
- "@grpc/proto-loader": "^0.5.3",
30
- "@improbable-eng/grpc-web": "^0.12.0",
31
29
  "@sendgrid/mail": "^7.7.0",
32
30
  "@types/chai": "^4.2.11",
33
31
  "@types/express": "4.17.14",
@@ -46,7 +44,6 @@
46
44
  "dotenv": "^8.2.0",
47
45
  "elastic-apm-node": "^3.5.0",
48
46
  "express": "^4.17.1",
49
- "grpc": "^1.24.2",
50
47
  "http-errors": "^1.7.3",
51
48
  "https": "^1.0.0",
52
49
  "ioredis": "^4.27.6",
@@ -57,7 +54,7 @@
57
54
  "node-fetch": "^2.6.0",
58
55
  "nyc": "^15.1.0",
59
56
  "rotating-file-stream": "^1.4.6",
60
- "skyeye-common-const": "1.0.28",
57
+ "skyeye-common-const": "1.0.30",
61
58
  "swagger-jsdoc": "^3.5.0",
62
59
  "swagger-ui-express": "^4.1.3",
63
60
  "ts-node": "^9.0.0",
@@ -5,7 +5,7 @@ Before submitting this PR, please make sure:
5
5
  - [ ] You are using approved terminology
6
6
  - [ ] You have added unit tests
7
7
  - [ ] You have updated documentation
8
- - [ ] You have checked related services are updated (eg. gRPC)
8
+ - [ ] You have checked related services are updated
9
9
 
10
10
  You may delete the sections as necessary.
11
11
 
package/src/index.ts CHANGED
@@ -12,6 +12,7 @@ export * from './utils/baseClass/baseController';
12
12
  export * from './utils/baseClass/baseService';
13
13
  export * from './interfaces/index';
14
14
  export * from './lib/azure/azureKeyVault';
15
+ export * from './lib/azure/azureServiceBusClient';
15
16
  export * from './lib/azure/azureStorageQueue';
16
17
  export * from './lib/azure/azureServiceBusQueue';
17
18
  export * from './lib/azure/azureTableStorage';
@@ -0,0 +1,130 @@
1
+ import {
2
+ ServiceBusClient as AzureServiceBusClient, ServiceBusSender,
3
+ ServiceBusReceiver, ServiceBusMessage, ServiceBusMessageBatch,
4
+ ServiceBusReceivedMessage
5
+ } from '@azure/service-bus';
6
+ import { commonAppConst } from '../../utils/appConst';
7
+
8
+ /* The `ServiceBusClient` class is a TypeScript class that provides methods for sending and receiving
9
+ messages using Azure Service Bus. */
10
+ export class ServiceBusClient {
11
+ private connection: AzureServiceBusClient;
12
+ private queueName: string;
13
+ private sender: ServiceBusSender;
14
+ private receiver: ServiceBusReceiver;
15
+
16
+ constructor(connectionString: string, queueName: string) {
17
+ this.connection = new AzureServiceBusClient(connectionString);
18
+ this.queueName = queueName;
19
+ }
20
+
21
+ /**
22
+ * The function closes the sender, receiver, and connection objects if they exist.
23
+ */
24
+ async closeConnection() {
25
+ if (this.sender) {
26
+ await this.sender.close();
27
+ }
28
+ if (this.receiver) {
29
+ await this.receiver.close();
30
+ }
31
+ if (this.connection) {
32
+ await this.connection.close();
33
+ }
34
+ }
35
+
36
+ /**
37
+ * The function "getOrCreateSender" creates a sender if it doesn't exist and returns it.
38
+ * @returns The `getOrCreateSender` function returns a Promise that resolves to the `sender`
39
+ * object.
40
+ */
41
+ private async getOrCreateSender() {
42
+ if (!this.sender) {
43
+ this.sender = this.connection.createSender(this.queueName);
44
+ }
45
+ return this.sender;
46
+ }
47
+
48
+ /**
49
+ * The function `getOrCreateReceiver` creates a receiver if it doesn't already exist and returns
50
+ * it.
51
+ * @returns The `getOrCreateReceiver` function is returning the `this.receiver` object.
52
+ */
53
+ private async getOrCreateReceiver() {
54
+ if (!this.receiver) {
55
+ this.receiver = this.connection.createReceiver(this.queueName, {
56
+ receiveMode: 'receiveAndDelete'
57
+ });
58
+ }
59
+ return this.receiver;
60
+ }
61
+
62
+ /**
63
+ * The function sends an array of messages using a Service Bus sender, creating a new message batch
64
+ * if the current batch is full.
65
+ * @param {ServiceBusMessage[]} messages - An array of ServiceBusMessage objects.
66
+ * @returns a Promise.
67
+ */
68
+ async sendMessage(messages: ServiceBusMessage[]) {
69
+ if (messages.length === 0) return;
70
+ const sender = await this.getOrCreateSender();
71
+ try {
72
+ let batch: ServiceBusMessageBatch = await sender.createMessageBatch();
73
+ for (const message of messages) {
74
+ if (!batch.tryAddMessage(message)) {
75
+ await sender.sendMessages(batch);
76
+ batch = await sender.createMessageBatch();
77
+ if (!batch.tryAddMessage(message)) {
78
+ throw new Error('Message is too large.');
79
+ }
80
+ }
81
+ }
82
+ await sender.sendMessages(batch);
83
+ } catch (err) {
84
+ throw new Error(`serviceBusClient/sendMessage: ${err}`);
85
+ }
86
+ }
87
+
88
+ /**
89
+ * The function `receiveMessage` retrieves messages from a Service Bus queue or topic subscription,
90
+ * either by receiving them or peeking at them, and returns an array of received messages.
91
+ * @param {boolean} [receiveMode=true] - The `receiveMode` parameter is a boolean flag that determines
92
+ * whether the messages should be peeked or received. When `receiveMode` is set to `false`, the method
93
+ * will peek messages from the queue without removing them. When `receiveMode` is set to `true` (or
94
+ * not provided, the method remove messages from the queue after retrieval.
95
+ * @param {number} [numMessageRequired] - The `numMessageRequired` parameter is an optional
96
+ * parameter that specifies the maximum number of messages required. If this parameter is provided,
97
+ * the function will stop receiving messages once the number of received messages reaches or
98
+ * exceeds the specified value. If this parameter is not provided, the function will continue to
99
+ * receive messages until no more message in the queue.
100
+ * @returns The function `receiveMessage` returns a promise that resolves to an array of
101
+ * `ServiceBusReceivedMessage` objects.
102
+ */
103
+ async receiveMessage(receiveMode: boolean = true, numMessageRequired?: number): Promise<ServiceBusReceivedMessage[]> {
104
+ const receiver = await this.getOrCreateReceiver();
105
+ try {
106
+ const result: ServiceBusReceivedMessage[] = [];
107
+ let messages: ServiceBusReceivedMessage[];
108
+ while(true) {
109
+ messages = receiveMode ?
110
+ await receiver.receiveMessages(
111
+ commonAppConst.serviceBus.receiverOptions.maxMessageCount,
112
+ {
113
+ maxWaitTimeInMs: commonAppConst.serviceBus.receiverOptions.maxWaitTimeInMs,
114
+ }
115
+ ) :
116
+ await receiver.peekMessages(commonAppConst.serviceBus.receiverOptions.maxWaitTimeInMs);
117
+ if (messages.length === 0) {
118
+ break; // No more messages in the queue
119
+ }
120
+ result.push(...messages);
121
+ if (numMessageRequired !== undefined && result.length >= numMessageRequired) {
122
+ break;
123
+ }
124
+ }
125
+ return result.slice(0, numMessageRequired);
126
+ } catch (err) {
127
+ throw new Error(`serviceBusClient/peekMessage: ${err}`);
128
+ }
129
+ }
130
+ }
@@ -42,7 +42,20 @@ export const commonAppConst = {
42
42
  setMode: {
43
43
  setIfNotExist: 'nx'
44
44
  }
45
- },
45
+ },
46
+ serviceBus: {
47
+ receiverOptions: {
48
+ receiveMode: 'receiveAndDelete',
49
+ /**
50
+ * The maximum time to wait for the first message before returning an empty array if no messages are available.
51
+ */
52
+ maxWaitTimeInMs: 1000,
53
+ maxMessageCount: 100
54
+ },
55
+ senderOptions: {
56
+ contentType: "application/json"
57
+ }
58
+ },
46
59
  user: {
47
60
  public: 'public',
48
61
  internal: 'internal',
@@ -106,57 +106,4 @@ export abstract class BaseController {
106
106
 
107
107
  logger.profile(`${req.originalUrl}`);
108
108
  }
109
-
110
- public async executeGrpc(call: any, callback: any): Promise<any> {
111
- let baseControllerParameter: BaseControllerParameter = new BaseControllerParameter();
112
- baseControllerParameter.serviceResponse = { isSuccess: false, message: undefined, data: undefined, totalCount: undefined };
113
-
114
- try {
115
- baseControllerParameter.userInfo = undefined;
116
-
117
- const authorization: string = call.metadata.get(commonAppConst.httpHeader.AUTHORIZATION);
118
- if (!!authorization && authorization.length) {
119
- const headerInfo: string[] = authorization[0].split(' ');
120
- if (headerInfo.length === 2 && headerInfo[0] === commonAppConst.httpHeader.BEARER) {
121
- baseControllerParameter.userInfo = await verifyJWT (headerInfo[1]);
122
- }
123
- }
124
-
125
- if (commonAppConfig.SqlEnable) {
126
- BaseController.mutex.runExclusive(async () => {
127
- this.startTransaction().then((queryRunner: QueryRunner) => {
128
- baseControllerParameter.queryRunner = queryRunner;
129
- return this.executeImpl(call.request, baseControllerParameter);
130
- }).then(() => {
131
- return this.endTransaction(baseControllerParameter);
132
- }).then(() => {
133
- return callback(null, baseControllerParameter.serviceResponse);
134
- }).catch((err: Error) => {
135
- baseControllerParameter.serviceResponse.isSuccess = false;
136
- baseControllerParameter.serviceResponse.error = true;
137
- baseControllerParameter.serviceResponse.message = err.message;
138
-
139
- this.endTransaction(baseControllerParameter).then(() => {
140
- throw err;
141
- });
142
- });;
143
- });
144
- } else {
145
- this.executeImpl(call.request, baseControllerParameter).then(() => {
146
- return callback(null, baseControllerParameter.serviceResponse);
147
- }).catch((err: Error) => {
148
- baseControllerParameter.serviceResponse.isSuccess = false;
149
- baseControllerParameter.serviceResponse.error = true;
150
- baseControllerParameter.serviceResponse.message = err.message;
151
-
152
- throw err;
153
- });
154
- }
155
- } catch (err) {
156
- logger.error(`BaseController/executeGrpc: ${err}`);
157
- baseControllerParameter.serviceResponse.isSuccess = false;
158
- baseControllerParameter.serviceResponse.error = true;
159
- return callback(null, baseControllerParameter.serviceResponse);
160
- }
161
- }
162
109
  };