@samuelaj1/eazisend-service-kit 1.0.3 → 1.0.4
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/dist/index.cjs +35 -2
- package/dist/index.d.cts +24 -1
- package/dist/index.d.ts +24 -1
- package/dist/index.js +33 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -31,6 +31,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
LogLevelTypes: () => LogLevelTypes,
|
|
34
|
+
elasticSearchRepo: () => elasticSearchRepo,
|
|
35
|
+
loggerRepo: () => loggerRepo,
|
|
34
36
|
registerErrorMiddleware: () => registerErrorMiddleware,
|
|
35
37
|
registerSecurityMiddleware: () => registerSecurityMiddleware,
|
|
36
38
|
registerStandardMiddleware: () => registerStandardMiddleware,
|
|
@@ -85,6 +87,10 @@ function registerSecurityMiddleware(app, args) {
|
|
|
85
87
|
}));
|
|
86
88
|
}
|
|
87
89
|
|
|
90
|
+
// src/repositories/logger.repo.ts
|
|
91
|
+
var import_winston = __toESM(require("winston"), 1);
|
|
92
|
+
var import_winston_elasticsearch = require("winston-elasticsearch");
|
|
93
|
+
|
|
88
94
|
// src/types/log.level.types.ts
|
|
89
95
|
var LogLevelTypes = /* @__PURE__ */ ((LogLevelTypes2) => {
|
|
90
96
|
LogLevelTypes2["DEBUG"] = "debug";
|
|
@@ -94,8 +100,6 @@ var LogLevelTypes = /* @__PURE__ */ ((LogLevelTypes2) => {
|
|
|
94
100
|
})(LogLevelTypes || {});
|
|
95
101
|
|
|
96
102
|
// src/repositories/logger.repo.ts
|
|
97
|
-
var import_winston = __toESM(require("winston"), 1);
|
|
98
|
-
var import_winston_elasticsearch = require("winston-elasticsearch");
|
|
99
103
|
var LoggerRepo = class {
|
|
100
104
|
logger;
|
|
101
105
|
esTransformer = (logData) => {
|
|
@@ -160,6 +164,33 @@ function runServer(app) {
|
|
|
160
164
|
}
|
|
161
165
|
}
|
|
162
166
|
|
|
167
|
+
// src/repositories/elasticsearch.repo.ts
|
|
168
|
+
var import_elasticsearch = require("@elastic/elasticsearch");
|
|
169
|
+
var ElasticsearchRepo = class {
|
|
170
|
+
elasticSearchClient;
|
|
171
|
+
/** Creates an Elasticsearch client using the configured cluster URL. */
|
|
172
|
+
constructor() {
|
|
173
|
+
this.elasticSearchClient = new import_elasticsearch.Client({
|
|
174
|
+
node: libConfig.ELASTIC_SEARCH_NODE_URL
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
/** Elasticsearch connection is established. */
|
|
178
|
+
async establishElasticSearchConnection(args) {
|
|
179
|
+
let isConnected = false;
|
|
180
|
+
while (!isConnected) {
|
|
181
|
+
try {
|
|
182
|
+
const health = await this.elasticSearchClient.cluster.health({});
|
|
183
|
+
console.log("debug" /* DEBUG */, `${args.serviceName} Elasticsearch health status - ${health.status}`);
|
|
184
|
+
isConnected = true;
|
|
185
|
+
} catch (error) {
|
|
186
|
+
console.log("error" /* ERROR */, "Connection to Elasticsearch failed. Retrying...");
|
|
187
|
+
console.log("error" /* ERROR */, `${args.serviceName} checkConnection() method:`, error);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
var elasticSearchRepo = new ElasticsearchRepo();
|
|
193
|
+
|
|
163
194
|
// src/middlewares/gateway.middleware.ts
|
|
164
195
|
var import_jsonwebtoken = __toESM(require("jsonwebtoken"), 1);
|
|
165
196
|
function verifyGatewayRequest(serviceId) {
|
|
@@ -194,6 +225,8 @@ function registerErrorMiddleware(app) {
|
|
|
194
225
|
// Annotate the CommonJS export names for ESM import in node:
|
|
195
226
|
0 && (module.exports = {
|
|
196
227
|
LogLevelTypes,
|
|
228
|
+
elasticSearchRepo,
|
|
229
|
+
loggerRepo,
|
|
197
230
|
registerErrorMiddleware,
|
|
198
231
|
registerSecurityMiddleware,
|
|
199
232
|
registerStandardMiddleware,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Express, Request, Response, NextFunction, Application } from 'express';
|
|
2
|
+
import { LogEntry } from 'winston';
|
|
2
3
|
|
|
3
4
|
declare function registerStandardMiddleware(app: Express): void;
|
|
4
5
|
|
|
@@ -12,10 +13,32 @@ declare enum LogLevelTypes {
|
|
|
12
13
|
ERROR = "error"
|
|
13
14
|
}
|
|
14
15
|
|
|
16
|
+
declare class LoggerRepo {
|
|
17
|
+
private logger?;
|
|
18
|
+
private esTransformer;
|
|
19
|
+
getInstance: (identifier: string, level?: LogLevelTypes) => LoggerRepo;
|
|
20
|
+
log(entry: LogEntry): void;
|
|
21
|
+
log(level: string, message: string, ...meta: unknown[]): void;
|
|
22
|
+
log(level: string, message: unknown): void;
|
|
23
|
+
}
|
|
24
|
+
declare const loggerRepo: LoggerRepo;
|
|
25
|
+
|
|
15
26
|
declare function runServer(app: Express): void;
|
|
16
27
|
|
|
28
|
+
/** Configured Elasticsearch cluster */
|
|
29
|
+
declare class ElasticsearchRepo {
|
|
30
|
+
private elasticSearchClient;
|
|
31
|
+
/** Creates an Elasticsearch client using the configured cluster URL. */
|
|
32
|
+
constructor();
|
|
33
|
+
/** Elasticsearch connection is established. */
|
|
34
|
+
establishElasticSearchConnection(args: {
|
|
35
|
+
serviceName: string;
|
|
36
|
+
}): Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
declare const elasticSearchRepo: ElasticsearchRepo;
|
|
39
|
+
|
|
17
40
|
declare function verifyGatewayRequest(serviceId: string): (req: Request, _res: Response, next: NextFunction) => void;
|
|
18
41
|
|
|
19
42
|
declare function registerErrorMiddleware(app: Application): (err: Error, _req: Request, res: Response, _next: NextFunction) => void;
|
|
20
43
|
|
|
21
|
-
export { LogLevelTypes, registerErrorMiddleware, registerSecurityMiddleware, registerStandardMiddleware, runServer, verifyGatewayRequest };
|
|
44
|
+
export { LogLevelTypes, elasticSearchRepo, loggerRepo, registerErrorMiddleware, registerSecurityMiddleware, registerStandardMiddleware, runServer, verifyGatewayRequest };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Express, Request, Response, NextFunction, Application } from 'express';
|
|
2
|
+
import { LogEntry } from 'winston';
|
|
2
3
|
|
|
3
4
|
declare function registerStandardMiddleware(app: Express): void;
|
|
4
5
|
|
|
@@ -12,10 +13,32 @@ declare enum LogLevelTypes {
|
|
|
12
13
|
ERROR = "error"
|
|
13
14
|
}
|
|
14
15
|
|
|
16
|
+
declare class LoggerRepo {
|
|
17
|
+
private logger?;
|
|
18
|
+
private esTransformer;
|
|
19
|
+
getInstance: (identifier: string, level?: LogLevelTypes) => LoggerRepo;
|
|
20
|
+
log(entry: LogEntry): void;
|
|
21
|
+
log(level: string, message: string, ...meta: unknown[]): void;
|
|
22
|
+
log(level: string, message: unknown): void;
|
|
23
|
+
}
|
|
24
|
+
declare const loggerRepo: LoggerRepo;
|
|
25
|
+
|
|
15
26
|
declare function runServer(app: Express): void;
|
|
16
27
|
|
|
28
|
+
/** Configured Elasticsearch cluster */
|
|
29
|
+
declare class ElasticsearchRepo {
|
|
30
|
+
private elasticSearchClient;
|
|
31
|
+
/** Creates an Elasticsearch client using the configured cluster URL. */
|
|
32
|
+
constructor();
|
|
33
|
+
/** Elasticsearch connection is established. */
|
|
34
|
+
establishElasticSearchConnection(args: {
|
|
35
|
+
serviceName: string;
|
|
36
|
+
}): Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
declare const elasticSearchRepo: ElasticsearchRepo;
|
|
39
|
+
|
|
17
40
|
declare function verifyGatewayRequest(serviceId: string): (req: Request, _res: Response, next: NextFunction) => void;
|
|
18
41
|
|
|
19
42
|
declare function registerErrorMiddleware(app: Application): (err: Error, _req: Request, res: Response, _next: NextFunction) => void;
|
|
20
43
|
|
|
21
|
-
export { LogLevelTypes, registerErrorMiddleware, registerSecurityMiddleware, registerStandardMiddleware, runServer, verifyGatewayRequest };
|
|
44
|
+
export { LogLevelTypes, elasticSearchRepo, loggerRepo, registerErrorMiddleware, registerSecurityMiddleware, registerStandardMiddleware, runServer, verifyGatewayRequest };
|
package/dist/index.js
CHANGED
|
@@ -40,6 +40,10 @@ function registerSecurityMiddleware(app, args) {
|
|
|
40
40
|
}));
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
// src/repositories/logger.repo.ts
|
|
44
|
+
import winston from "winston";
|
|
45
|
+
import { ElasticsearchTransformer, ElasticsearchTransport } from "winston-elasticsearch";
|
|
46
|
+
|
|
43
47
|
// src/types/log.level.types.ts
|
|
44
48
|
var LogLevelTypes = /* @__PURE__ */ ((LogLevelTypes2) => {
|
|
45
49
|
LogLevelTypes2["DEBUG"] = "debug";
|
|
@@ -49,8 +53,6 @@ var LogLevelTypes = /* @__PURE__ */ ((LogLevelTypes2) => {
|
|
|
49
53
|
})(LogLevelTypes || {});
|
|
50
54
|
|
|
51
55
|
// src/repositories/logger.repo.ts
|
|
52
|
-
import winston from "winston";
|
|
53
|
-
import { ElasticsearchTransformer, ElasticsearchTransport } from "winston-elasticsearch";
|
|
54
56
|
var LoggerRepo = class {
|
|
55
57
|
logger;
|
|
56
58
|
esTransformer = (logData) => {
|
|
@@ -115,6 +117,33 @@ function runServer(app) {
|
|
|
115
117
|
}
|
|
116
118
|
}
|
|
117
119
|
|
|
120
|
+
// src/repositories/elasticsearch.repo.ts
|
|
121
|
+
import { Client } from "@elastic/elasticsearch";
|
|
122
|
+
var ElasticsearchRepo = class {
|
|
123
|
+
elasticSearchClient;
|
|
124
|
+
/** Creates an Elasticsearch client using the configured cluster URL. */
|
|
125
|
+
constructor() {
|
|
126
|
+
this.elasticSearchClient = new Client({
|
|
127
|
+
node: libConfig.ELASTIC_SEARCH_NODE_URL
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
/** Elasticsearch connection is established. */
|
|
131
|
+
async establishElasticSearchConnection(args) {
|
|
132
|
+
let isConnected = false;
|
|
133
|
+
while (!isConnected) {
|
|
134
|
+
try {
|
|
135
|
+
const health = await this.elasticSearchClient.cluster.health({});
|
|
136
|
+
console.log("debug" /* DEBUG */, `${args.serviceName} Elasticsearch health status - ${health.status}`);
|
|
137
|
+
isConnected = true;
|
|
138
|
+
} catch (error) {
|
|
139
|
+
console.log("error" /* ERROR */, "Connection to Elasticsearch failed. Retrying...");
|
|
140
|
+
console.log("error" /* ERROR */, `${args.serviceName} checkConnection() method:`, error);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
var elasticSearchRepo = new ElasticsearchRepo();
|
|
146
|
+
|
|
118
147
|
// src/middlewares/gateway.middleware.ts
|
|
119
148
|
import jwt from "jsonwebtoken";
|
|
120
149
|
function verifyGatewayRequest(serviceId) {
|
|
@@ -148,6 +177,8 @@ function registerErrorMiddleware(app) {
|
|
|
148
177
|
}
|
|
149
178
|
export {
|
|
150
179
|
LogLevelTypes,
|
|
180
|
+
elasticSearchRepo,
|
|
181
|
+
loggerRepo,
|
|
151
182
|
registerErrorMiddleware,
|
|
152
183
|
registerSecurityMiddleware,
|
|
153
184
|
registerStandardMiddleware,
|