@samuelaj1/eazisend-service-kit 1.0.3 → 1.0.5
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 +37 -2
- package/dist/index.d.cts +24 -1
- package/dist/index.d.ts +24 -1
- package/dist/index.js +35 -2
- package/package.json +3 -3
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,
|
|
@@ -58,6 +60,8 @@ var import_helmet = __toESM(require("helmet"), 1);
|
|
|
58
60
|
var import_cors = __toESM(require("cors"), 1);
|
|
59
61
|
|
|
60
62
|
// src/config.ts
|
|
63
|
+
var import_dotenv = __toESM(require("dotenv"), 1);
|
|
64
|
+
import_dotenv.default.config({ quiet: true });
|
|
61
65
|
var Config = class {
|
|
62
66
|
API_GATEWAY_URL;
|
|
63
67
|
GATEWAY_TOKEN;
|
|
@@ -85,6 +89,10 @@ function registerSecurityMiddleware(app, args) {
|
|
|
85
89
|
}));
|
|
86
90
|
}
|
|
87
91
|
|
|
92
|
+
// src/repositories/logger.repo.ts
|
|
93
|
+
var import_winston = __toESM(require("winston"), 1);
|
|
94
|
+
var import_winston_elasticsearch = require("winston-elasticsearch");
|
|
95
|
+
|
|
88
96
|
// src/types/log.level.types.ts
|
|
89
97
|
var LogLevelTypes = /* @__PURE__ */ ((LogLevelTypes2) => {
|
|
90
98
|
LogLevelTypes2["DEBUG"] = "debug";
|
|
@@ -94,8 +102,6 @@ var LogLevelTypes = /* @__PURE__ */ ((LogLevelTypes2) => {
|
|
|
94
102
|
})(LogLevelTypes || {});
|
|
95
103
|
|
|
96
104
|
// src/repositories/logger.repo.ts
|
|
97
|
-
var import_winston = __toESM(require("winston"), 1);
|
|
98
|
-
var import_winston_elasticsearch = require("winston-elasticsearch");
|
|
99
105
|
var LoggerRepo = class {
|
|
100
106
|
logger;
|
|
101
107
|
esTransformer = (logData) => {
|
|
@@ -160,6 +166,33 @@ function runServer(app) {
|
|
|
160
166
|
}
|
|
161
167
|
}
|
|
162
168
|
|
|
169
|
+
// src/repositories/elasticsearch.repo.ts
|
|
170
|
+
var import_elasticsearch = require("@elastic/elasticsearch");
|
|
171
|
+
var ElasticsearchRepo = class {
|
|
172
|
+
elasticSearchClient;
|
|
173
|
+
/** Creates an Elasticsearch client using the configured cluster URL. */
|
|
174
|
+
constructor() {
|
|
175
|
+
this.elasticSearchClient = new import_elasticsearch.Client({
|
|
176
|
+
node: libConfig.ELASTIC_SEARCH_NODE_URL
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
/** Elasticsearch connection is established. */
|
|
180
|
+
async establishElasticSearchConnection(args) {
|
|
181
|
+
let isConnected = false;
|
|
182
|
+
while (!isConnected) {
|
|
183
|
+
try {
|
|
184
|
+
const health = await this.elasticSearchClient.cluster.health({});
|
|
185
|
+
console.log("debug" /* DEBUG */, `${args.serviceName} Elasticsearch health status - ${health.status}`);
|
|
186
|
+
isConnected = true;
|
|
187
|
+
} catch (error) {
|
|
188
|
+
console.log("error" /* ERROR */, "Connection to Elasticsearch failed. Retrying...");
|
|
189
|
+
console.log("error" /* ERROR */, `${args.serviceName} checkConnection() method:`, error);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
var elasticSearchRepo = new ElasticsearchRepo();
|
|
195
|
+
|
|
163
196
|
// src/middlewares/gateway.middleware.ts
|
|
164
197
|
var import_jsonwebtoken = __toESM(require("jsonwebtoken"), 1);
|
|
165
198
|
function verifyGatewayRequest(serviceId) {
|
|
@@ -194,6 +227,8 @@ function registerErrorMiddleware(app) {
|
|
|
194
227
|
// Annotate the CommonJS export names for ESM import in node:
|
|
195
228
|
0 && (module.exports = {
|
|
196
229
|
LogLevelTypes,
|
|
230
|
+
elasticSearchRepo,
|
|
231
|
+
loggerRepo,
|
|
197
232
|
registerErrorMiddleware,
|
|
198
233
|
registerSecurityMiddleware,
|
|
199
234
|
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
|
@@ -13,6 +13,8 @@ import helmet from "helmet";
|
|
|
13
13
|
import cors from "cors";
|
|
14
14
|
|
|
15
15
|
// src/config.ts
|
|
16
|
+
import dotenv from "dotenv";
|
|
17
|
+
dotenv.config({ quiet: true });
|
|
16
18
|
var Config = class {
|
|
17
19
|
API_GATEWAY_URL;
|
|
18
20
|
GATEWAY_TOKEN;
|
|
@@ -40,6 +42,10 @@ function registerSecurityMiddleware(app, args) {
|
|
|
40
42
|
}));
|
|
41
43
|
}
|
|
42
44
|
|
|
45
|
+
// src/repositories/logger.repo.ts
|
|
46
|
+
import winston from "winston";
|
|
47
|
+
import { ElasticsearchTransformer, ElasticsearchTransport } from "winston-elasticsearch";
|
|
48
|
+
|
|
43
49
|
// src/types/log.level.types.ts
|
|
44
50
|
var LogLevelTypes = /* @__PURE__ */ ((LogLevelTypes2) => {
|
|
45
51
|
LogLevelTypes2["DEBUG"] = "debug";
|
|
@@ -49,8 +55,6 @@ var LogLevelTypes = /* @__PURE__ */ ((LogLevelTypes2) => {
|
|
|
49
55
|
})(LogLevelTypes || {});
|
|
50
56
|
|
|
51
57
|
// src/repositories/logger.repo.ts
|
|
52
|
-
import winston from "winston";
|
|
53
|
-
import { ElasticsearchTransformer, ElasticsearchTransport } from "winston-elasticsearch";
|
|
54
58
|
var LoggerRepo = class {
|
|
55
59
|
logger;
|
|
56
60
|
esTransformer = (logData) => {
|
|
@@ -115,6 +119,33 @@ function runServer(app) {
|
|
|
115
119
|
}
|
|
116
120
|
}
|
|
117
121
|
|
|
122
|
+
// src/repositories/elasticsearch.repo.ts
|
|
123
|
+
import { Client } from "@elastic/elasticsearch";
|
|
124
|
+
var ElasticsearchRepo = class {
|
|
125
|
+
elasticSearchClient;
|
|
126
|
+
/** Creates an Elasticsearch client using the configured cluster URL. */
|
|
127
|
+
constructor() {
|
|
128
|
+
this.elasticSearchClient = new Client({
|
|
129
|
+
node: libConfig.ELASTIC_SEARCH_NODE_URL
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
/** Elasticsearch connection is established. */
|
|
133
|
+
async establishElasticSearchConnection(args) {
|
|
134
|
+
let isConnected = false;
|
|
135
|
+
while (!isConnected) {
|
|
136
|
+
try {
|
|
137
|
+
const health = await this.elasticSearchClient.cluster.health({});
|
|
138
|
+
console.log("debug" /* DEBUG */, `${args.serviceName} Elasticsearch health status - ${health.status}`);
|
|
139
|
+
isConnected = true;
|
|
140
|
+
} catch (error) {
|
|
141
|
+
console.log("error" /* ERROR */, "Connection to Elasticsearch failed. Retrying...");
|
|
142
|
+
console.log("error" /* ERROR */, `${args.serviceName} checkConnection() method:`, error);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
var elasticSearchRepo = new ElasticsearchRepo();
|
|
148
|
+
|
|
118
149
|
// src/middlewares/gateway.middleware.ts
|
|
119
150
|
import jwt from "jsonwebtoken";
|
|
120
151
|
function verifyGatewayRequest(serviceId) {
|
|
@@ -148,6 +179,8 @@ function registerErrorMiddleware(app) {
|
|
|
148
179
|
}
|
|
149
180
|
export {
|
|
150
181
|
LogLevelTypes,
|
|
182
|
+
elasticSearchRepo,
|
|
183
|
+
loggerRepo,
|
|
151
184
|
registerErrorMiddleware,
|
|
152
185
|
registerSecurityMiddleware,
|
|
153
186
|
registerStandardMiddleware,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@samuelaj1/eazisend-service-kit",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"build": "tsup"
|
|
6
6
|
},
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
],
|
|
22
22
|
"repository": {
|
|
23
23
|
"type": "git",
|
|
24
|
-
"url": "git+https://github.com/
|
|
24
|
+
"url": "git+https://github.com/eazisend/shared-services-lib"
|
|
25
25
|
},
|
|
26
|
-
"homepage": "https://github.com/
|
|
26
|
+
"homepage": "https://github.com/eazisend/shared-services-lib",
|
|
27
27
|
"keywords": [],
|
|
28
28
|
"author": "samuelaj1",
|
|
29
29
|
"license": "MIT",
|