@samuelaj1/eazisend-service-kit 1.0.1
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 +170 -0
- package/dist/index.d.cts +28 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +129 -0
- package/package.json +53 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
LogLevelTypes: () => LogLevelTypes,
|
|
34
|
+
enforceSecurityMiddleware: () => enforceSecurityMiddleware,
|
|
35
|
+
enforceStandardMiddleware: () => enforceStandardMiddleware,
|
|
36
|
+
listenToServer: () => listenToServer,
|
|
37
|
+
loggerRepo: () => loggerRepo
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(index_exports);
|
|
40
|
+
|
|
41
|
+
// src/middlewares/standard.middleware.ts
|
|
42
|
+
var import_express = require("express");
|
|
43
|
+
var import_compression = __toESM(require("compression"), 1);
|
|
44
|
+
function enforceStandardMiddleware(app) {
|
|
45
|
+
app.use((0, import_compression.default)());
|
|
46
|
+
app.use((0, import_express.json)({ limit: "200mb" }));
|
|
47
|
+
app.use((0, import_express.urlencoded)({ extended: true, limit: "200mb" }));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// src/middlewares/security.middleware.ts
|
|
51
|
+
var import_hpp = __toESM(require("hpp"), 1);
|
|
52
|
+
var import_helmet = __toESM(require("helmet"), 1);
|
|
53
|
+
var import_cors = __toESM(require("cors"), 1);
|
|
54
|
+
|
|
55
|
+
// src/config.ts
|
|
56
|
+
var Config = class {
|
|
57
|
+
API_GATEWAY_URL;
|
|
58
|
+
ELASTIC_SEARCH_NODE_URL;
|
|
59
|
+
PORT;
|
|
60
|
+
constructor() {
|
|
61
|
+
if (!process.env.API_GATEWAY_URL) {
|
|
62
|
+
throw new Error("Missing API_GATEWAY_URL in environment variables");
|
|
63
|
+
}
|
|
64
|
+
if (!process.env.ELASTIC_SEARCH_NODE_URL) {
|
|
65
|
+
throw new Error("Missing ELASTIC_SEARCH_NODE_URL in environment variables");
|
|
66
|
+
}
|
|
67
|
+
if (!process.env.PORT) {
|
|
68
|
+
throw new Error("Missing PORT in environment variables");
|
|
69
|
+
}
|
|
70
|
+
this.API_GATEWAY_URL = process.env.API_GATEWAY_URL;
|
|
71
|
+
this.ELASTIC_SEARCH_NODE_URL = process.env.ELASTIC_SEARCH_NODE_URL;
|
|
72
|
+
this.PORT = process.env.PORT;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
var libConfig = new Config();
|
|
76
|
+
|
|
77
|
+
// src/middlewares/security.middleware.ts
|
|
78
|
+
function enforceSecurityMiddleware(app, args) {
|
|
79
|
+
const { origin } = args ? args : {};
|
|
80
|
+
app.set("trust proxy", true);
|
|
81
|
+
app.use((0, import_hpp.default)());
|
|
82
|
+
app.use((0, import_helmet.default)());
|
|
83
|
+
app.use((0, import_cors.default)({
|
|
84
|
+
origin: origin ?? libConfig.API_GATEWAY_URL,
|
|
85
|
+
credentials: true,
|
|
86
|
+
methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"]
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// src/repositories/logger.repo.ts
|
|
91
|
+
var import_winston = __toESM(require("winston"), 1);
|
|
92
|
+
var import_winston_elasticsearch = require("winston-elasticsearch");
|
|
93
|
+
|
|
94
|
+
// src/types/log.level.types.ts
|
|
95
|
+
var LogLevelTypes = /* @__PURE__ */ ((LogLevelTypes2) => {
|
|
96
|
+
LogLevelTypes2["DEBUG"] = "debug";
|
|
97
|
+
LogLevelTypes2["INFO"] = "info";
|
|
98
|
+
LogLevelTypes2["ERROR"] = "error";
|
|
99
|
+
return LogLevelTypes2;
|
|
100
|
+
})(LogLevelTypes || {});
|
|
101
|
+
|
|
102
|
+
// src/repositories/logger.repo.ts
|
|
103
|
+
var LoggerRepo = class {
|
|
104
|
+
logger;
|
|
105
|
+
esTransformer = (logData) => {
|
|
106
|
+
return (0, import_winston_elasticsearch.ElasticsearchTransformer)(logData);
|
|
107
|
+
};
|
|
108
|
+
getInstance = (identifier, level = "debug" /* DEBUG */) => {
|
|
109
|
+
const elasticsearchNode = libConfig.ELASTIC_SEARCH_NODE_URL;
|
|
110
|
+
const options = {
|
|
111
|
+
console: {
|
|
112
|
+
level,
|
|
113
|
+
handleExceptions: true,
|
|
114
|
+
json: false,
|
|
115
|
+
colorize: true
|
|
116
|
+
},
|
|
117
|
+
elasticsearch: {
|
|
118
|
+
level,
|
|
119
|
+
transformer: this.esTransformer,
|
|
120
|
+
clientOpts: {
|
|
121
|
+
node: elasticsearchNode,
|
|
122
|
+
log: level,
|
|
123
|
+
maxRetries: 2,
|
|
124
|
+
requestTimeout: 1e4,
|
|
125
|
+
sniffOnStart: false
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
const esTransport = new import_winston_elasticsearch.ElasticsearchTransport(options.elasticsearch);
|
|
130
|
+
this.logger = import_winston.default.createLogger({
|
|
131
|
+
exitOnError: false,
|
|
132
|
+
defaultMeta: { service: identifier },
|
|
133
|
+
transports: [new import_winston.default.transports.Console(options.console), esTransport]
|
|
134
|
+
});
|
|
135
|
+
return this;
|
|
136
|
+
};
|
|
137
|
+
log(levelOrEntry, message, ...meta) {
|
|
138
|
+
if (!this.logger) {
|
|
139
|
+
throw new Error("No Instance Created For logger");
|
|
140
|
+
}
|
|
141
|
+
if (typeof levelOrEntry === "string") {
|
|
142
|
+
if (typeof message === "string") {
|
|
143
|
+
this.logger.log(levelOrEntry, message, ...meta);
|
|
144
|
+
} else {
|
|
145
|
+
this.logger.log(levelOrEntry, message);
|
|
146
|
+
}
|
|
147
|
+
} else {
|
|
148
|
+
this.logger.log(levelOrEntry);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
var loggerRepo = new LoggerRepo();
|
|
153
|
+
|
|
154
|
+
// src/processes/server.process.ts
|
|
155
|
+
function listenToServer(app) {
|
|
156
|
+
try {
|
|
157
|
+
app.listen(libConfig.PORT, () => {
|
|
158
|
+
});
|
|
159
|
+
} catch (error) {
|
|
160
|
+
process.exit(1);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
164
|
+
0 && (module.exports = {
|
|
165
|
+
LogLevelTypes,
|
|
166
|
+
enforceSecurityMiddleware,
|
|
167
|
+
enforceStandardMiddleware,
|
|
168
|
+
listenToServer,
|
|
169
|
+
loggerRepo
|
|
170
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Express } from 'express';
|
|
2
|
+
import { LogEntry } from 'winston';
|
|
3
|
+
|
|
4
|
+
declare function enforceStandardMiddleware(app: Express): void;
|
|
5
|
+
|
|
6
|
+
declare function enforceSecurityMiddleware(app: Express, args?: {
|
|
7
|
+
origin?: string;
|
|
8
|
+
}): void;
|
|
9
|
+
|
|
10
|
+
declare enum LogLevelTypes {
|
|
11
|
+
DEBUG = "debug",
|
|
12
|
+
INFO = "info",
|
|
13
|
+
ERROR = "error"
|
|
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
|
+
|
|
26
|
+
declare function listenToServer(app: Express): void;
|
|
27
|
+
|
|
28
|
+
export { LogLevelTypes, enforceSecurityMiddleware, enforceStandardMiddleware, listenToServer, loggerRepo };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Express } from 'express';
|
|
2
|
+
import { LogEntry } from 'winston';
|
|
3
|
+
|
|
4
|
+
declare function enforceStandardMiddleware(app: Express): void;
|
|
5
|
+
|
|
6
|
+
declare function enforceSecurityMiddleware(app: Express, args?: {
|
|
7
|
+
origin?: string;
|
|
8
|
+
}): void;
|
|
9
|
+
|
|
10
|
+
declare enum LogLevelTypes {
|
|
11
|
+
DEBUG = "debug",
|
|
12
|
+
INFO = "info",
|
|
13
|
+
ERROR = "error"
|
|
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
|
+
|
|
26
|
+
declare function listenToServer(app: Express): void;
|
|
27
|
+
|
|
28
|
+
export { LogLevelTypes, enforceSecurityMiddleware, enforceStandardMiddleware, listenToServer, loggerRepo };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// src/middlewares/standard.middleware.ts
|
|
2
|
+
import { json, urlencoded } from "express";
|
|
3
|
+
import compression from "compression";
|
|
4
|
+
function enforceStandardMiddleware(app) {
|
|
5
|
+
app.use(compression());
|
|
6
|
+
app.use(json({ limit: "200mb" }));
|
|
7
|
+
app.use(urlencoded({ extended: true, limit: "200mb" }));
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// src/middlewares/security.middleware.ts
|
|
11
|
+
import hpp from "hpp";
|
|
12
|
+
import helmet from "helmet";
|
|
13
|
+
import cors from "cors";
|
|
14
|
+
|
|
15
|
+
// src/config.ts
|
|
16
|
+
var Config = class {
|
|
17
|
+
API_GATEWAY_URL;
|
|
18
|
+
ELASTIC_SEARCH_NODE_URL;
|
|
19
|
+
PORT;
|
|
20
|
+
constructor() {
|
|
21
|
+
if (!process.env.API_GATEWAY_URL) {
|
|
22
|
+
throw new Error("Missing API_GATEWAY_URL in environment variables");
|
|
23
|
+
}
|
|
24
|
+
if (!process.env.ELASTIC_SEARCH_NODE_URL) {
|
|
25
|
+
throw new Error("Missing ELASTIC_SEARCH_NODE_URL in environment variables");
|
|
26
|
+
}
|
|
27
|
+
if (!process.env.PORT) {
|
|
28
|
+
throw new Error("Missing PORT in environment variables");
|
|
29
|
+
}
|
|
30
|
+
this.API_GATEWAY_URL = process.env.API_GATEWAY_URL;
|
|
31
|
+
this.ELASTIC_SEARCH_NODE_URL = process.env.ELASTIC_SEARCH_NODE_URL;
|
|
32
|
+
this.PORT = process.env.PORT;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
var libConfig = new Config();
|
|
36
|
+
|
|
37
|
+
// src/middlewares/security.middleware.ts
|
|
38
|
+
function enforceSecurityMiddleware(app, args) {
|
|
39
|
+
const { origin } = args ? args : {};
|
|
40
|
+
app.set("trust proxy", true);
|
|
41
|
+
app.use(hpp());
|
|
42
|
+
app.use(helmet());
|
|
43
|
+
app.use(cors({
|
|
44
|
+
origin: origin ?? libConfig.API_GATEWAY_URL,
|
|
45
|
+
credentials: true,
|
|
46
|
+
methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"]
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// src/repositories/logger.repo.ts
|
|
51
|
+
import winston from "winston";
|
|
52
|
+
import { ElasticsearchTransformer, ElasticsearchTransport } from "winston-elasticsearch";
|
|
53
|
+
|
|
54
|
+
// src/types/log.level.types.ts
|
|
55
|
+
var LogLevelTypes = /* @__PURE__ */ ((LogLevelTypes2) => {
|
|
56
|
+
LogLevelTypes2["DEBUG"] = "debug";
|
|
57
|
+
LogLevelTypes2["INFO"] = "info";
|
|
58
|
+
LogLevelTypes2["ERROR"] = "error";
|
|
59
|
+
return LogLevelTypes2;
|
|
60
|
+
})(LogLevelTypes || {});
|
|
61
|
+
|
|
62
|
+
// src/repositories/logger.repo.ts
|
|
63
|
+
var LoggerRepo = class {
|
|
64
|
+
logger;
|
|
65
|
+
esTransformer = (logData) => {
|
|
66
|
+
return ElasticsearchTransformer(logData);
|
|
67
|
+
};
|
|
68
|
+
getInstance = (identifier, level = "debug" /* DEBUG */) => {
|
|
69
|
+
const elasticsearchNode = libConfig.ELASTIC_SEARCH_NODE_URL;
|
|
70
|
+
const options = {
|
|
71
|
+
console: {
|
|
72
|
+
level,
|
|
73
|
+
handleExceptions: true,
|
|
74
|
+
json: false,
|
|
75
|
+
colorize: true
|
|
76
|
+
},
|
|
77
|
+
elasticsearch: {
|
|
78
|
+
level,
|
|
79
|
+
transformer: this.esTransformer,
|
|
80
|
+
clientOpts: {
|
|
81
|
+
node: elasticsearchNode,
|
|
82
|
+
log: level,
|
|
83
|
+
maxRetries: 2,
|
|
84
|
+
requestTimeout: 1e4,
|
|
85
|
+
sniffOnStart: false
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
const esTransport = new ElasticsearchTransport(options.elasticsearch);
|
|
90
|
+
this.logger = winston.createLogger({
|
|
91
|
+
exitOnError: false,
|
|
92
|
+
defaultMeta: { service: identifier },
|
|
93
|
+
transports: [new winston.transports.Console(options.console), esTransport]
|
|
94
|
+
});
|
|
95
|
+
return this;
|
|
96
|
+
};
|
|
97
|
+
log(levelOrEntry, message, ...meta) {
|
|
98
|
+
if (!this.logger) {
|
|
99
|
+
throw new Error("No Instance Created For logger");
|
|
100
|
+
}
|
|
101
|
+
if (typeof levelOrEntry === "string") {
|
|
102
|
+
if (typeof message === "string") {
|
|
103
|
+
this.logger.log(levelOrEntry, message, ...meta);
|
|
104
|
+
} else {
|
|
105
|
+
this.logger.log(levelOrEntry, message);
|
|
106
|
+
}
|
|
107
|
+
} else {
|
|
108
|
+
this.logger.log(levelOrEntry);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
var loggerRepo = new LoggerRepo();
|
|
113
|
+
|
|
114
|
+
// src/processes/server.process.ts
|
|
115
|
+
function listenToServer(app) {
|
|
116
|
+
try {
|
|
117
|
+
app.listen(libConfig.PORT, () => {
|
|
118
|
+
});
|
|
119
|
+
} catch (error) {
|
|
120
|
+
process.exit(1);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
export {
|
|
124
|
+
LogLevelTypes,
|
|
125
|
+
enforceSecurityMiddleware,
|
|
126
|
+
enforceStandardMiddleware,
|
|
127
|
+
listenToServer,
|
|
128
|
+
loggerRepo
|
|
129
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@samuelaj1/eazisend-service-kit",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"scripts": {
|
|
5
|
+
"build": "tsup"
|
|
6
|
+
},
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"require": {
|
|
14
|
+
"types": "./dist/index.d.cts",
|
|
15
|
+
"default": "./dist/index.cjs"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/samuelaj1/eazisend-service-kit"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://github.com/samuelaj1/eazisend-service-kit",
|
|
27
|
+
"keywords": [],
|
|
28
|
+
"author": "samuelaj1",
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"type": "module",
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/express": "^5.0.6",
|
|
33
|
+
"@types/jsonwebtoken": "^9.0.10",
|
|
34
|
+
"tsup": "^8.5.1",
|
|
35
|
+
"typescript": "^6.0.3",
|
|
36
|
+
"@types/cors": "^2.8.19",
|
|
37
|
+
"@types/hpp": "^0.2.7",
|
|
38
|
+
"@types/compression": "^1.8.1"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@elastic/elasticsearch": "^9.4.2",
|
|
42
|
+
"dotenv": "^17.4.2",
|
|
43
|
+
"express": "^5.2.1",
|
|
44
|
+
"http-status-codes": "^2.3.0",
|
|
45
|
+
"jsonwebtoken": "^9.0.3",
|
|
46
|
+
"winston": "^3.19.0",
|
|
47
|
+
"winston-elasticsearch": "^0.19.0",
|
|
48
|
+
"helmet": "^8.3.0",
|
|
49
|
+
"hpp": "^0.2.3",
|
|
50
|
+
"cors": "^2.8.6",
|
|
51
|
+
"compression": "^1.8.1"
|
|
52
|
+
}
|
|
53
|
+
}
|